⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acp_language.php

📁 这些都是我以前学习是用到的源码
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php/** ** @package acp* @version $Id: acp_language.php,v 1.34 2006/11/15 15:34:32 acydburn Exp $* @copyright (c) 2005 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License **//*** @package acp*/class acp_language{	var $u_action;	var $main_files;	var $language_header = '';	var $lang_header = '';	var $language_file = '';	var $language_directory = '';	function main($id, $mode)	{		global $config, $db, $user, $auth, $template, $cache;		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;		global $safe_mode, $file_uploads;		include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);		$this->default_variables();		// Check and set some common vars		$action		= request_var('action', '');		$action		= (isset($_POST['update_details'])) ? 'update_details' : $action;		$action		= (isset($_POST['download_file'])) ? 'download_file' : $action;		$action		= (isset($_POST['upload_file'])) ? 'upload_file' : $action;		$action		= (isset($_POST['upload_data'])) ? 'upload_data' : $action;		$action		= (isset($_POST['submit_file'])) ? 'submit_file' : $action;		$action		= (isset($_POST['remove_store'])) ? 'details' : $action;		$lang_id = request_var('id', 0);		if (isset($_POST['missing_file']))		{			$missing_file = request_var('missing_file', array('' => 0));			list($_REQUEST['language_file'], ) = array_keys($missing_file);		}		$selected_lang_file = request_var('language_file', '|common.' . $phpEx);		list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);		$this->language_directory = basename($this->language_directory);		$this->language_file = basename($this->language_file);		$user->add_lang('acp/language');		$this->tpl_name = 'acp_language';		$this->page_title = 'ACP_LANGUAGE_PACKS';		if ($action == 'upload_data' && request_var('test_connection', ''))		{			$test_connection = false;			$action = 'upload_file';			$method = request_var('method', '');			include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);			switch ($method)			{				case 'ftp':					$transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));				break;				case 'ftp_fsock':					$transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));				break;				default:					trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);				break;			}			$test_connection = $transfer->open_session();			$transfer->close_session();		}		switch ($action)		{			case 'upload_file':				include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);				$method = request_var('method', '');				$requested_data = call_user_func(array($method, 'data'));				foreach ($requested_data as $data => $default)				{					$template->assign_block_vars('data', array(						'DATA'		=> $data,						'NAME'		=> $user->lang[strtoupper($method . '_' . $data)],						'EXPLAIN'	=> $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'],						'DEFAULT'	=> (!empty($_REQUEST[$data])) ? request_var($data, '') : $default					));				}				$hidden_data = build_hidden_fields(array(					'file'		=> $this->language_file,					'dir'		=> $this->language_directory,					'method'	=> $method)				);				$hidden_data .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP);				$template->assign_vars(array(					'S_UPLOAD'	=> true,					'NAME'		=> $method,					'U_ACTION'	=> $this->u_action . "&amp;id=$lang_id&amp;action=upload_data",					'HIDDEN'	=> $hidden_data,					'S_CONNECTION_SUCCESS'		=> (request_var('test_connection', '') && $test_connection === true) ? true : false,					'S_CONNECTION_FAILED'		=> (request_var('test_connection', '') && $test_connection !== true) ? true : false				));			break;			case 'update_details':				if (!$lang_id)				{					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);				}				$sql = 'SELECT *					FROM ' . LANG_TABLE . "					WHERE lang_id = $lang_id";				$result = $db->sql_query($sql);				$row = $db->sql_fetchrow($result);				$db->sql_freeresult($result);				$sql_ary	= array(					'lang_english_name'		=> request_var('lang_english_name', $row['lang_english_name']),					'lang_local_name'		=> request_var('lang_local_name', $row['lang_local_name'], true),					'lang_author'			=> request_var('lang_author', $row['lang_author'], true),				);				$db->sql_query('UPDATE ' . LANG_TABLE . ' 					SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '					WHERE lang_id = ' . $lang_id);									add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']);				trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));			break;			case 'submit_file':			case 'download_file':			case 'upload_data':				if (!$lang_id || empty($_POST['entry']))				{					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);				}				if (!$this->language_file || (!$this->language_directory && !in_array($this->language_file, $this->main_files)))				{					trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);				}				$sql = 'SELECT *					FROM ' . LANG_TABLE . "					WHERE lang_id = $lang_id";				$result = $db->sql_query($sql);				$row = $db->sql_fetchrow($result);				$db->sql_freeresult($result);				if (!$safe_mode)				{					$mkdir_ary = array('language', 'language/' . $row['lang_iso']);										if ($this->language_directory)					{						$mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory;					}									foreach ($mkdir_ary as $dir)					{						$dir = $phpbb_root_path . 'store/' . $dir;									if (!is_dir($dir))						{							if (!@mkdir($dir, 0777))							{								trigger_error("Could not create directory $dir", E_USER_ERROR);							}							@chmod($dir, 0777);						}					}				}				// Get target filename for storage folder				$filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true);				$fp = fopen($phpbb_root_path . $filename, 'wb');				if (!$fp)				{					trigger_error(sprintf($user->lang['UNABLE_TO_WRITE_FILE'], $filename) . adm_back_link($this->u_action . '&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);				}				if ($this->language_directory == 'email')				{					// Email Template					$entry = $this->prepare_lang_entry($_POST['entry'], false);					fwrite($fp, $entry);				}				else				{					$name = (($this->language_directory) ? $this->language_directory . '_' : '') . $this->language_file;					$header = str_replace(array('{FILENAME}', '{LANG_NAME}', '{CHANGED}', '{AUTHOR}'), array($name, $row['lang_english_name'], date('Y-m-d', time()), $row['lang_author']), $this->language_file_header);					if (strpos($this->language_file, 'help_') === 0)					{						// Help File						$header .= '$help = array(' . "\n";						fwrite($fp, $header);						foreach ($_POST['entry'] as $key => $value)						{							if (!is_array($value))							{								continue;							}							$entry = "\tarray(\n";														foreach ($value as $_key => $_value)							{								$entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n";							}							$entry .= "\t),\n";							fwrite($fp, $entry);						}					}					else					{						// Language File						$header .= $this->lang_header;						fwrite($fp, $header);						foreach ($_POST['entry'] as $key => $value)						{							$entry = $this->format_lang_array($key, $value);							fwrite($fp, $entry);						}					}					$footer = "));\n\n?>";					fwrite($fp, $footer);				}				fclose($fp);				if ($action == 'download_file')				{					header('Pragma: no-cache');					header('Content-Type: application/octetstream; name="' . $this->language_file . '"');					header('Content-disposition: attachment; filename=' . $this->language_file);					$fp = fopen($phpbb_root_path . $filename, 'rb');					while ($buffer = fread($fp, 1024))					{						echo $buffer;					}					fclose($fp);										exit;				}				else if ($action == 'upload_data')				{					$sql = 'SELECT lang_iso						FROM ' . LANG_TABLE . "						WHERE lang_id = $lang_id";					$result = $db->sql_query($sql);					$row = $db->sql_fetchrow($result);					$db->sql_freeresult($result);					$file = request_var('file', '');					$dir = request_var('dir', '');					$selected_lang_file = $dir . '|' . $file;					$old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true);					$lang_path = 'language/' . $row['lang_iso'] . '/' . (($dir) ? $dir . '/' : '');					include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);					$method = request_var('method', '');					switch ($method)					{						case 'ftp':							$transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));						break;						case 'ftp_fsock':							$transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));						break;						default:							trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);						break;					}					if (($result = $transfer->open_session()) !== true)					{						trigger_error($user->lang[$result] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);					}					$transfer->rename($lang_path . $file, $lang_path . $file . '.bak');					$transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file);					$transfer->close_session();					// Remove from storage folder					@unlink($phpbb_root_path . 'store/' . $lang_path . $file);					add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file);					trigger_error($user->lang['UPLOAD_COMPLETED'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)));				}							$action = 'details';			// no break;			case 'details':				if (!$lang_id)				{					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);				}								$this->page_title = 'LANGUAGE_PACK_DETAILS';				$sql = 'SELECT *					FROM ' . LANG_TABLE . '					WHERE lang_id = ' . $lang_id;				$result = $db->sql_query($sql);				$lang_entries = $db->sql_fetchrow($result);				$db->sql_freeresult($result);								$lang_iso = $lang_entries['lang_iso'];				$missing_vars = $missing_files = array();				// Get email templates				$email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt');				$email_files = $email_files['email/'];				// Get acp files				$acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx);				$acp_files = $acp_files['acp/'];				// Get mod files				$mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx);				$mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();				// Check if our current filename matches the files				switch ($this->language_directory)				{					case 'email':						if (!in_array($this->language_file, $email_files))						{							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);						}					break;					case 'acp':						if (!in_array($this->language_file, $acp_files))						{							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);						}					break;					case 'mods':						if (!in_array($this->language_file, $mods_files))						{							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);						}					break;					default:						if (!in_array($this->language_file, $this->main_files))						{							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);						}				}								if (isset($_POST['remove_store']))				{					$store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true);					@unlink($phpbb_root_path . $store_filename);				}				include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);				$methods = transfer::methods();				foreach ($methods as $method)				{					$template->assign_block_vars('buttons', array(						'VALUE' => $method					));				}				$template->assign_vars(array(					'S_DETAILS'			=> true,					'U_ACTION'			=> $this->u_action . "&amp;action=details&amp;id=$lang_id",					'U_BACK'			=> $this->u_action,					'LANG_LOCAL_NAME'	=> $lang_entries['lang_local_name'],					'LANG_ENGLISH_NAME'	=> $lang_entries['lang_english_name'],					'LANG_ISO'			=> $lang_entries['lang_iso'],					'LANG_AUTHOR'		=> $lang_entries['lang_author'],					'ALLOW_UPLOAD'		=> sizeof($methods)					)				);				// If current lang is different from the default lang, then first try to grab missing/additional vars

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -