Blame Extras/phpBB/3.0.4/includes/acp/acp_language.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package acp
4c79b5
* @version $Id: acp_language.php 8780 2008-08-22 12:52:48Z acydburn $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* @package acp
4c79b5
*/
4c79b5
class acp_language
4c79b5
{
4c79b5
	var $u_action;
4c79b5
	var $main_files;
4c79b5
	var $language_header = '';
4c79b5
	var $lang_header = '';
4c79b5
4c79b5
	var $language_file = '';
4c79b5
	var $language_directory = '';
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $config, $db, $user, $auth, $template, $cache;
4c79b5
		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
4c79b5
		global $safe_mode, $file_uploads;
4c79b5
4c79b5
		include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
		$this->default_variables();
4c79b5
4c79b5
		// Check and set some common vars
4c79b5
4c79b5
		$action		= (isset($_POST['update_details'])) ? 'update_details' : '';
4c79b5
		$action		= (isset($_POST['download_file'])) ? 'download_file' : $action;
4c79b5
		$action		= (isset($_POST['upload_file'])) ? 'upload_file' : $action;
4c79b5
		$action		= (isset($_POST['upload_data'])) ? 'upload_data' : $action;
4c79b5
		$action		= (isset($_POST['submit_file'])) ? 'submit_file' : $action;
4c79b5
		$action		= (isset($_POST['remove_store'])) ? 'details' : $action;
4c79b5
4c79b5
		$submit = (empty($action) && !isset($_POST['update']) && !isset($_POST['test_connection'])) ? false : true;
4c79b5
		$action = (empty($action)) ? request_var('action', '') : $action;
4c79b5
4c79b5
		$form_name = 'acp_lang';
4c79b5
		add_form_key('acp_lang');
4c79b5
4c79b5
		$lang_id = request_var('id', 0);
4c79b5
		if (isset($_POST['missing_file']))
4c79b5
		{
4c79b5
			$missing_file = request_var('missing_file', array('' => 0));
4c79b5
			list($_REQUEST['language_file'], ) = array_keys($missing_file);
4c79b5
		}
4c79b5
4c79b5
		$selected_lang_file = request_var('language_file', '|common.' . $phpEx);
4c79b5
4c79b5
		list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);
4c79b5
4c79b5
		$this->language_directory = basename($this->language_directory);
4c79b5
		$this->language_file = basename($this->language_file);
4c79b5
4c79b5
		$user->add_lang('acp/language');
4c79b5
		$this->tpl_name = 'acp_language';
4c79b5
		$this->page_title = 'ACP_LANGUAGE_PACKS';
4c79b5
4c79b5
		if ($submit && $action == 'upload_data' && request_var('test_connection', ''))
4c79b5
		{
4c79b5
			$test_connection = false;
4c79b5
			$action = 'upload_file';
4c79b5
			$method = request_var('method', '');
4c79b5
4c79b5
			include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
4c79b5
4c79b5
			switch ($method)
4c79b5
			{
4c79b5
				case 'ftp':
4c79b5
					$transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
4c79b5
				break;
4c79b5
4c79b5
				case 'ftp_fsock':
4c79b5
					$transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
4c79b5
				break;
4c79b5
4c79b5
				default:
4c79b5
					trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
4c79b5
				break;
4c79b5
			}
4c79b5
4c79b5
			$test_connection = $transfer->open_session();
4c79b5
			$transfer->close_session();
4c79b5
		}
4c79b5
4c79b5
		switch ($action)
4c79b5
		{
4c79b5
			case 'upload_file':
4c79b5
4c79b5
				include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
4c79b5
4c79b5
				$method = request_var('method', '');
4c79b5
4c79b5
				if (!class_exists($method))
4c79b5
				{
4c79b5
					trigger_error('Method does not exist.', E_USER_ERROR);
4c79b5
				}
4c79b5
4c79b5
				$requested_data = call_user_func(array($method, 'data'));
4c79b5
				foreach ($requested_data as $data => $default)
4c79b5
				{
4c79b5
					$template->assign_block_vars('data', array(
4c79b5
						'DATA'		=> $data,
4c79b5
						'NAME'		=> $user->lang[strtoupper($method . '_' . $data)],
4c79b5
						'EXPLAIN'	=> $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'],
4c79b5
						'DEFAULT'	=> (!empty($_REQUEST[$data])) ? request_var($data, '') : $default
4c79b5
					));
4c79b5
				}
4c79b5
4c79b5
				$hidden_data = build_hidden_fields(array(
4c79b5
					'file'			=> $this->language_file,
4c79b5
					'dir'			=> $this->language_directory,
4c79b5
					'language_file'	=> $selected_lang_file,
4c79b5
					'method'		=> $method)
4c79b5
				);
4c79b5
4c79b5
				$hidden_data .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_UPLOAD'	=> true,
4c79b5
					'NAME'		=> $method,
4c79b5
					'U_ACTION'	=> $this->u_action . "&id=$lang_id&action=upload_data",
4c79b5
					'U_BACK'	=> $this->u_action . "&id=$lang_id&action=details&language_file=" . urlencode($selected_lang_file),
4c79b5
					'HIDDEN'	=> $hidden_data,
4c79b5
4c79b5
					'S_CONNECTION_SUCCESS'		=> (request_var('test_connection', '') && $test_connection === true) ? true : false,
4c79b5
					'S_CONNECTION_FAILED'		=> (request_var('test_connection', '') && $test_connection !== true) ? true : false
4c79b5
				));
4c79b5
			break;
4c79b5
4c79b5
			case 'update_details':
4c79b5
4c79b5
				if (!$submit || !check_form_key($form_name))
4c79b5
				{
4c79b5
					trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (!$lang_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . LANG_TABLE . "
4c79b5
					WHERE lang_id = $lang_id";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$row = $db->sql_fetchrow($result);
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$sql_ary	= array(
4c79b5
					'lang_english_name'		=> request_var('lang_english_name', $row['lang_english_name']),
4c79b5
					'lang_local_name'		=> utf8_normalize_nfc(request_var('lang_local_name', $row['lang_local_name'], true)),
4c79b5
					'lang_author'			=> utf8_normalize_nfc(request_var('lang_author', $row['lang_author'], true)),
4c79b5
				);
4c79b5
4c79b5
				$db->sql_query('UPDATE ' . LANG_TABLE . '
4c79b5
					SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
4c79b5
					WHERE lang_id = ' . $lang_id);
4c79b5
4c79b5
				add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']);
4c79b5
4c79b5
				trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));
4c79b5
			break;
4c79b5
4c79b5
			case 'submit_file':
4c79b5
			case 'download_file':
4c79b5
			case 'upload_data':
4c79b5
4c79b5
				if (!$submit || !check_form_key($form_name))
4c79b5
				{
4c79b5
					trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (!$lang_id || empty($_POST['entry']))
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if ($this->language_directory != 'email' && !is_array($_POST['entry']))
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (!$this->language_file || (!$this->language_directory && !in_array($this->language_file, $this->main_files)))
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . LANG_TABLE . "
4c79b5
					WHERE lang_id = $lang_id";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$row = $db->sql_fetchrow($result);
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				if (!$row)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				// Before we attempt to write anything let's check if the admin really chose a correct filename
4c79b5
				switch ($this->language_directory)
4c79b5
				{
4c79b5
					case 'email':
4c79b5
						// Get email templates
4c79b5
						$email_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
4c79b5
						$email_files = $email_files['email/'];
4c79b5
4c79b5
						if (!in_array($this->language_file, $email_files))
4c79b5
						{
4c79b5
							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
4c79b5
						}
4c79b5
					break;
4c79b5
4c79b5
					case 'acp':
4c79b5
						// Get acp files
4c79b5
						$acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
4c79b5
						$acp_files = $acp_files['acp/'];
4c79b5
4c79b5
						if (!in_array($this->language_file, $acp_files))
4c79b5
						{
4c79b5
							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
4c79b5
						}
4c79b5
					break;
4c79b5
4c79b5
					case 'mods':
4c79b5
						// Get mod files
4c79b5
						$mods_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
4c79b5
						$mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
4c79b5
4c79b5
						if (!in_array($this->language_file, $mods_files))
4c79b5
						{
4c79b5
							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
4c79b5
						}
4c79b5
					break;
4c79b5
4c79b5
					default:
4c79b5
						if (!in_array($this->language_file, $this->main_files))
4c79b5
						{
4c79b5
							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
4c79b5
						}
4c79b5
					break;
4c79b5
				}
4c79b5
4c79b5
				if (!$safe_mode)
4c79b5
				{
4c79b5
					$mkdir_ary = array('language', 'language/' . $row['lang_iso']);
4c79b5
4c79b5
					if ($this->language_directory)
4c79b5
					{
4c79b5
						$mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory;
4c79b5
					}
4c79b5
4c79b5
					foreach ($mkdir_ary as $dir)
4c79b5
					{
4c79b5
						$dir = $phpbb_root_path . 'store/' . $dir;
4c79b5
4c79b5
						if (!is_dir($dir))
4c79b5
						{
4c79b5
							if (!@mkdir($dir, 0777))
4c79b5
							{
4c79b5
								trigger_error("Could not create directory $dir", E_USER_ERROR);
4c79b5
							}
4c79b5
							@chmod($dir, 0777);
4c79b5
						}
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				// Get target filename for storage folder
4c79b5
				$filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true);
4c79b5
				$fp = @fopen($phpbb_root_path . $filename, 'wb');
4c79b5
4c79b5
				if (!$fp)
4c79b5
				{
4c79b5
					trigger_error(sprintf($user->lang['UNABLE_TO_WRITE_FILE'], $filename) . adm_back_link($this->u_action . '&id=' . $lang_id . '&action=details&language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if ($this->language_directory == 'email')
4c79b5
				{
4c79b5
					// Email Template
4c79b5
					$entry = $this->prepare_lang_entry($_POST['entry'], false);
4c79b5
					fwrite($fp, $entry);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$name = (($this->language_directory) ? $this->language_directory . '_' : '') . $this->language_file;
4c79b5
					$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);
4c79b5
4c79b5
					if (strpos($this->language_file, 'help_') === 0)
4c79b5
					{
4c79b5
						// Help File
4c79b5
						$header .= '$help = array(' . "\n";
4c79b5
						fwrite($fp, $header);
4c79b5
4c79b5
						foreach ($_POST['entry'] as $key => $value)
4c79b5
						{
4c79b5
							if (!is_array($value))
4c79b5
							{
4c79b5
								continue;
4c79b5
							}
4c79b5
4c79b5
							$entry = "\tarray(\n";
4c79b5
4c79b5
							foreach ($value as $_key => $_value)
4c79b5
							{
4c79b5
								$entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n";
4c79b5
							}
4c79b5
4c79b5
							$entry .= "\t),\n";
4c79b5
							fwrite($fp, $entry);
4c79b5
						}
4c79b5
4c79b5
						$footer = ");\n\n?>";
4c79b5
						fwrite($fp, $footer);
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						// Language File
4c79b5
						$header .= $this->lang_header;
4c79b5
						fwrite($fp, $header);
4c79b5
4c79b5
						foreach ($_POST['entry'] as $key => $value)
4c79b5
						{
4c79b5
							$entry = $this->format_lang_array($key, $value);
4c79b5
							fwrite($fp, $entry);
4c79b5
						}
4c79b5
4c79b5
						$footer = "));\n\n?>";
4c79b5
						fwrite($fp, $footer);
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				fclose($fp);
4c79b5
4c79b5
				if ($action == 'download_file')
4c79b5
				{
4c79b5
					header('Pragma: no-cache');
4c79b5
					header('Content-Type: application/octetstream; name="' . $this->language_file . '"');
4c79b5
					header('Content-disposition: attachment; filename=' . $this->language_file);
4c79b5
4c79b5
					$fp = @fopen($phpbb_root_path . $filename, 'rb');
4c79b5
					while ($buffer = fread($fp, 1024))
4c79b5
					{
4c79b5
						echo $buffer;
4c79b5
					}
4c79b5
					fclose($fp);
4c79b5
4c79b5
					add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
4c79b5
4c79b5
					exit;
4c79b5
				}
4c79b5
				else if ($action == 'upload_data')
4c79b5
				{
4c79b5
					$sql = 'SELECT lang_iso
4c79b5
						FROM ' . LANG_TABLE . "
4c79b5
						WHERE lang_id = $lang_id";
4c79b5
					$result = $db->sql_query($sql);
4c79b5
					$row = $db->sql_fetchrow($result);
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					$file = request_var('file', '');
4c79b5
					$dir = request_var('dir', '');
4c79b5
4c79b5
					$selected_lang_file = $dir . '|' . $file;
4c79b5
4c79b5
					$old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true);
4c79b5
					$lang_path = 'language/' . $row['lang_iso'] . '/' . (($dir) ? $dir . '/' : '');
4c79b5
4c79b5
					include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
4c79b5
					$method = request_var('method', '');
4c79b5
4c79b5
					if ($method != 'ftp' && $method != 'ftp_fsock')
4c79b5
					{
4c79b5
						trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
4c79b5
					}
4c79b5
4c79b5
					$transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
4c79b5
4c79b5
					if (($result = $transfer->open_session()) !== true)
4c79b5
					{
4c79b5
						trigger_error($user->lang[$result] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					$transfer->rename($lang_path . $file, $lang_path . $file . '.bak');
4c79b5
					$result = $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file);
4c79b5
4c79b5
					if ($result === false)
4c79b5
					{
4c79b5
						// If failed, try to rename again and print error out...
4c79b5
						$transfer->delete_file($lang_path . $file);
4c79b5
						$transfer->rename($lang_path . $file . '.bak', $lang_path . $file);
4c79b5
4c79b5
						trigger_error($user->lang['UPLOAD_FAILED'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					$transfer->close_session();
4c79b5
4c79b5
					// Remove from storage folder
4c79b5
					if (file_exists($phpbb_root_path . 'store/' . $lang_path . $file))
4c79b5
					{
4c79b5
						@unlink($phpbb_root_path . 'store/' . $lang_path . $file);
4c79b5
					}
4c79b5
4c79b5
					add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file);
4c79b5
4c79b5
					trigger_error($user->lang['UPLOAD_COMPLETED'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file)));
4c79b5
				}
4c79b5
4c79b5
				add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
4c79b5
				$action = 'details';
4c79b5
4c79b5
			// no break;
4c79b5
4c79b5
			case 'details':
4c79b5
4c79b5
				if (!$lang_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$this->page_title = 'LANGUAGE_PACK_DETAILS';
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . LANG_TABLE . '
4c79b5
					WHERE lang_id = ' . $lang_id;
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$lang_entries = $db->sql_fetchrow($result);
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$lang_iso = $lang_entries['lang_iso'];
4c79b5
				$missing_vars = $missing_files = array();
4c79b5
4c79b5
				// Get email templates
4c79b5
				$email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt');
4c79b5
				$email_files = $email_files['email/'];
4c79b5
4c79b5
				// Get acp files
4c79b5
				$acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx);
4c79b5
				$acp_files = $acp_files['acp/'];
4c79b5
4c79b5
				// Get mod files
4c79b5
				$mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx);
4c79b5
				$mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
4c79b5
4c79b5
				// Check if our current filename matches the files
4c79b5
				switch ($this->language_directory)
4c79b5
				{
4c79b5
					case 'email':
4c79b5
						if (!in_array($this->language_file, $email_files))
4c79b5
						{
4c79b5
							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
4c79b5
						}
4c79b5
					break;
4c79b5
4c79b5
					case 'acp':
4c79b5
						if (!in_array($this->language_file, $acp_files))
4c79b5
						{
4c79b5
							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
4c79b5
						}
4c79b5
					break;
4c79b5
4c79b5
					case 'mods':
4c79b5
						if (!in_array($this->language_file, $mods_files))
4c79b5
						{
4c79b5
							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
4c79b5
						}
4c79b5
					break;
4c79b5
4c79b5
					default:
4c79b5
						if (!in_array($this->language_file, $this->main_files))
4c79b5
						{
4c79b5
							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
4c79b5
						}
4c79b5
				}
4c79b5
4c79b5
				if (isset($_POST['remove_store']))
4c79b5
				{
4c79b5
					$store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true);
4c79b5
4c79b5
					if (file_exists($phpbb_root_path . $store_filename))
4c79b5
					{
4c79b5
						@unlink($phpbb_root_path . $store_filename);
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
4c79b5
4c79b5
				$methods = transfer::methods();
4c79b5
4c79b5
				foreach ($methods as $method)
4c79b5
				{
4c79b5
					$template->assign_block_vars('buttons', array(
4c79b5
						'VALUE' => $method
4c79b5
					));
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_DETAILS'			=> true,
4c79b5
					'U_ACTION'			=> $this->u_action . "&action=details&id=$lang_id",
4c79b5
					'U_BACK'			=> $this->u_action,
4c79b5
					'LANG_LOCAL_NAME'	=> $lang_entries['lang_local_name'],
4c79b5
					'LANG_ENGLISH_NAME'	=> $lang_entries['lang_english_name'],
4c79b5
					'LANG_ISO'			=> $lang_entries['lang_iso'],
4c79b5
					'LANG_AUTHOR'		=> $lang_entries['lang_author'],
4c79b5
					'ALLOW_UPLOAD'		=> sizeof($methods)
4c79b5
					)
4c79b5
				);
4c79b5
4c79b5
				// If current lang is different from the default lang, then first try to grab missing/additional vars
4c79b5
				if ($lang_iso != $config['default_lang'])
4c79b5
				{
4c79b5
					$is_missing_var = false;
4c79b5
4c79b5
					foreach ($this->main_files as $file)
4c79b5
					{
4c79b5
						if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file)))
4c79b5
						{
4c79b5
							$missing_vars[$file] = $this->compare_language_files($config['default_lang'], $lang_iso, '', $file);
4c79b5
4c79b5
							if (sizeof($missing_vars[$file]))
4c79b5
							{
4c79b5
								$is_missing_var = true;
4c79b5
							}
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							$missing_files[] = $this->get_filename($lang_iso, '', $file);
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					// Now go through acp/mods directories
4c79b5
					foreach ($acp_files as $file)
4c79b5
					{
4c79b5
						if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'acp', $file)))
4c79b5
						{
4c79b5
							$missing_vars['acp/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'acp', $file);
4c79b5
4c79b5
							if (sizeof($missing_vars['acp/' . $file]))
4c79b5
							{
4c79b5
								$is_missing_var = true;
4c79b5
							}
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							$missing_files[] = $this->get_filename($lang_iso, 'acp', $file);
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					if (sizeof($mods_files))
4c79b5
					{
4c79b5
						foreach ($mods_files as $file)
4c79b5
						{
4c79b5
							if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'mods', $file)))
4c79b5
							{
4c79b5
								$missing_vars['mods/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'mods', $file);
4c79b5
4c79b5
								if (sizeof($missing_vars['mods/' . $file]))
4c79b5
								{
4c79b5
									$is_missing_var = true;
4c79b5
								}
4c79b5
							}
4c79b5
							else
4c79b5
							{
4c79b5
								$missing_files[] = $this->get_filename($lang_iso, 'mods', $file);
4c79b5
							}
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					// More missing files... for example email templates?
4c79b5
					foreach ($email_files as $file)
4c79b5
					{
4c79b5
						if (!file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'email', $file)))
4c79b5
						{
4c79b5
							$missing_files[] = $this->get_filename($lang_iso, 'email', $file);
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					if (sizeof($missing_files))
4c79b5
					{
4c79b5
						$template->assign_vars(array(
4c79b5
							'S_MISSING_FILES'		=> true,
4c79b5
							'L_MISSING_FILES'		=> sprintf($user->lang['THOSE_MISSING_LANG_FILES'], $lang_entries['lang_local_name']),
4c79b5
							'MISSING_FILES'			=> implode('
', $missing_files))
4c79b5
						);
4c79b5
					}
4c79b5
4c79b5
					if ($is_missing_var)
4c79b5
					{
4c79b5
						$template->assign_vars(array(
4c79b5
							'S_MISSING_VARS'			=> true,
4c79b5
							'L_MISSING_VARS_EXPLAIN'	=> sprintf($user->lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries['lang_local_name']),
4c79b5
							'U_MISSING_ACTION'			=> $this->u_action . "&action=$action&id=$lang_id")
4c79b5
						);
4c79b5
4c79b5
						foreach ($missing_vars as $file => $vars)
4c79b5
						{
4c79b5
							if (!sizeof($vars))
4c79b5
							{
4c79b5
								continue;
4c79b5
							}
4c79b5
4c79b5
							$template->assign_block_vars('missing', array(
4c79b5
								'FILE'			=> $file,
4c79b5
								'TPL'			=> $this->print_language_entries($vars, '', false),
4c79b5
								'KEY'			=> (strpos($file, '/') === false) ? '|' . $file : str_replace('/', '|', $file))
4c79b5
							);
4c79b5
						}
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				// Main language files
4c79b5
				$s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['LANGUAGE_FILES'] . '</option>';
4c79b5
				foreach ($this->main_files as $file)
4c79b5
				{
4c79b5
					if (strpos($file, 'help_') === 0)
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					$prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
4c79b5
4c79b5
					$selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
4c79b5
					$s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
4c79b5
				}
4c79b5
4c79b5
				// Help Files
4c79b5
				$s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['HELP_FILES'] . '</option>';
4c79b5
				foreach ($this->main_files as $file)
4c79b5
				{
4c79b5
					if (strpos($file, 'help_') !== 0)
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					$prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
4c79b5
4c79b5
					$selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
4c79b5
					$s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
4c79b5
				}
4c79b5
4c79b5
				// Now every other language directory
4c79b5
				$check_files = array('email', 'acp', 'mods');
4c79b5
4c79b5
				foreach ($check_files as $check)
4c79b5
				{
4c79b5
					if (!sizeof(${$check . '_files'}))
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					$s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang[strtoupper($check) . '_FILES'] . '</option>';
4c79b5
4c79b5
					foreach (${$check . '_files'} as $file)
4c79b5
					{
4c79b5
						$prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $check, $file, true, true))) ? '* ' : '';
4c79b5
4c79b5
						$selected = ($this->language_directory == $check && $this->language_file == $file) ? ' selected="selected"' : '';
4c79b5
						$s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				// Get Language Entries - if saved within store folder, we take this one (with the option to remove it)
4c79b5
				$lang = array();
4c79b5
4c79b5
				$is_email_file = ($this->language_directory == 'email') ? true : false;
4c79b5
				$is_help_file = (strpos($this->language_file, 'help_') === 0) ? true : false;
4c79b5
4c79b5
				$file_from_store = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true))) ? true : false;
4c79b5
				$no_store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file);
4c79b5
4c79b5
				if (!$file_from_store && !file_exists($phpbb_root_path . $no_store_filename))
4c79b5
				{
4c79b5
					$print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $no_store_filename);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					if ($is_email_file)
4c79b5
					{
4c79b5
						$lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$help = array();
4c79b5
						include($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
4c79b5
4c79b5
						if ($is_help_file)
4c79b5
						{
4c79b5
							$lang = $help;
4c79b5
							unset($help);
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					$print_message = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
4c79b5
				}
4c79b5
4c79b5
				// Normal language pack entries
4c79b5
				$template->assign_vars(array(
4c79b5
					'U_ENTRY_ACTION'		=> $this->u_action . "&action=details&id=$lang_id#entries",
4c79b5
					'S_EMAIL_FILE'			=> $is_email_file,
4c79b5
					'S_FROM_STORE'			=> $file_from_store,
4c79b5
					'S_LANG_OPTIONS'		=> $s_lang_options,
4c79b5
					'PRINT_MESSAGE'			=> $print_message,
4c79b5
					)
4c79b5
				);
4c79b5
4c79b5
				if (!$is_email_file)
4c79b5
				{
4c79b5
					$tpl = '';
4c79b5
					$name = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
4c79b5
4c79b5
					if (isset($missing_vars[$name]) && sizeof($missing_vars[$name]))
4c79b5
					{
4c79b5
						$tpl .= $this->print_language_entries($missing_vars[$name], '* ');
4c79b5
					}
4c79b5
4c79b5
					$tpl .= $this->print_language_entries($lang);
4c79b5
4c79b5
					$template->assign_var('TPL', $tpl);
4c79b5
					unset($tpl);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$template->assign_vars(array(
4c79b5
						'LANG'		=> $lang)
4c79b5
					);
4c79b5
4c79b5
					unset($lang);
4c79b5
				}
4c79b5
4c79b5
				return;
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'delete':
4c79b5
4c79b5
				if (!$lang_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . LANG_TABLE . '
4c79b5
					WHERE lang_id = ' . $lang_id;
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$row = $db->sql_fetchrow($result);
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				if ($row['lang_iso'] == $config['default_lang'])
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
4c79b5
4c79b5
				$sql = 'UPDATE ' . USERS_TABLE . "
4c79b5
					SET user_lang = '" . $db->sql_escape($config['default_lang']) . "'
4c79b5
					WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
4c79b5
				$db->sql_query($sql);
4c79b5
4c79b5
				// We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
4c79b5
				$sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
4c79b5
				$db->sql_query($sql);
4c79b5
4c79b5
				$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
4c79b5
				$db->sql_query($sql);
4c79b5
4c79b5
				$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
4c79b5
4c79b5
				add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']);
4c79b5
4c79b5
				trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
4c79b5
			break;
4c79b5
4c79b5
			case 'install':
4c79b5
				$lang_iso = request_var('iso', '');
4c79b5
				$lang_iso = basename($lang_iso);
4c79b5
4c79b5
				if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt"))
4c79b5
				{
4c79b5
					trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$file = file("{$phpbb_root_path}language/$lang_iso/iso.txt");
4c79b5
4c79b5
				$lang_pack = array(
4c79b5
					'iso'		=> $lang_iso,
4c79b5
					'name'		=> trim(htmlspecialchars($file[0])),
4c79b5
					'local_name'=> trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')),
4c79b5
					'author'	=> trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))
4c79b5
				);
4c79b5
				unset($file);
4c79b5
4c79b5
				$sql = 'SELECT lang_iso
4c79b5
					FROM ' . LANG_TABLE . "
4c79b5
					WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$row = $db->sql_fetchrow($result);
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				if ($row)
4c79b5
				{
4c79b5
					trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (!$lang_pack['name'] || !$lang_pack['local_name'])
4c79b5
				{
4c79b5
					trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				// Add language pack
4c79b5
				$sql_ary = array(
4c79b5
					'lang_iso'			=> $lang_pack['iso'],
4c79b5
					'lang_dir'			=> $lang_pack['iso'],
4c79b5
					'lang_english_name'	=> $lang_pack['name'],
4c79b5
					'lang_local_name'	=> $lang_pack['local_name'],
4c79b5
					'lang_author'		=> $lang_pack['author']
4c79b5
				);
4c79b5
4c79b5
				$db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
4c79b5
				$lang_id = $db->sql_nextid();
4c79b5
4c79b5
				$valid_localized = array(
4c79b5
					'icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply',
4c79b5
				);
4c79b5
4c79b5
				$sql_ary = array();
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . STYLES_IMAGESET_TABLE;
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				while ($imageset_row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg"))
4c79b5
					{
4c79b5
						$cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg");
4c79b5
						foreach ($cfg_data_imageset_data as $image_name => $value)
4c79b5
						{
4c79b5
							if (strpos($value, '*') !== false)
4c79b5
							{
4c79b5
								if (substr($value, -1, 1) === '*')
4c79b5
								{
4c79b5
									list($image_filename, $image_height) = explode('*', $value);
4c79b5
									$image_width = 0;
4c79b5
								}
4c79b5
								else
4c79b5
								{
4c79b5
									list($image_filename, $image_height, $image_width) = explode('*', $value);
4c79b5
								}
4c79b5
							}
4c79b5
							else
4c79b5
							{
4c79b5
								$image_filename = $value;
4c79b5
								$image_height = $image_width = 0;
4c79b5
							}
4c79b5
4c79b5
							if (strpos($image_name, 'img_') === 0 && $image_filename)
4c79b5
							{
4c79b5
								$image_name = substr($image_name, 4);
4c79b5
								if (in_array($image_name, $valid_localized))
4c79b5
								{
4c79b5
									$sql_ary[] = array(
4c79b5
										'image_name'		=> (string) $image_name,
4c79b5
										'image_filename'	=> (string) $image_filename,
4c79b5
										'image_height'		=> (int) $image_height,
4c79b5
										'image_width'		=> (int) $image_width,
4c79b5
										'imageset_id'		=> (int) $imageset_row['imageset_id'],
4c79b5
										'image_lang'		=> (string) $lang_pack['iso'],
4c79b5
									);
4c79b5
								}
4c79b5
							}
4c79b5
						}
4c79b5
					}
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				if (sizeof($sql_ary))
4c79b5
				{
4c79b5
					$db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
4c79b5
					$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
4c79b5
				}
4c79b5
4c79b5
				// Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier.
4c79b5
				$sql = 'SELECT lang_id
4c79b5
					FROM ' . LANG_TABLE . "
4c79b5
					WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$default_lang_id = (int) $db->sql_fetchfield('lang_id');
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				// From the mysql documentation:
4c79b5
				// Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
4c79b5
				// Due to this we stay on the safe side if we do the insertion "the manual way"
4c79b5
4c79b5
				$sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value
4c79b5
					FROM ' . PROFILE_LANG_TABLE . '
4c79b5
					WHERE lang_id = ' . $default_lang_id;
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$row['lang_id'] = $lang_id;
4c79b5
					$db->sql_query('INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$sql = 'SELECT field_id, option_id, field_type, lang_value
4c79b5
					FROM ' . PROFILE_FIELDS_LANG_TABLE . '
4c79b5
					WHERE lang_id = ' . $default_lang_id;
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$row['lang_id'] = $lang_id;
4c79b5
					$db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']);
4c79b5
4c79b5
				trigger_error(sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']) . adm_back_link($this->u_action));
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'download':
4c79b5
4c79b5
				if (!$lang_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . LANG_TABLE . '
4c79b5
					WHERE lang_id = ' . $lang_id;
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$row = $db->sql_fetchrow($result);
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$use_method = request_var('use_method', '');
4c79b5
				$methods = array('.tar');
4c79b5
4c79b5
				$available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
4c79b5
				foreach ($available_methods as $type => $module)
4c79b5
				{
4c79b5
					if (!@extension_loaded($module))
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					$methods[] = $type;
4c79b5
				}
4c79b5
4c79b5
				// Let the user decide in which format he wants to have the pack
4c79b5
				if (!$use_method)
4c79b5
				{
4c79b5
					$this->page_title = 'SELECT_DOWNLOAD_FORMAT';
4c79b5
4c79b5
					$radio_buttons = '';
4c79b5
					foreach ($methods as $method)
4c79b5
					{
4c79b5
						$radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>';
4c79b5
					}
4c79b5
4c79b5
					$template->assign_vars(array(
4c79b5
						'S_SELECT_METHOD'		=> true,
4c79b5
						'U_BACK'				=> $this->u_action,
4c79b5
						'U_ACTION'				=> $this->u_action . "&action=$action&id=$lang_id",
4c79b5
						'RADIO_BUTTONS'			=> $radio_buttons)
4c79b5
					);
4c79b5
4c79b5
					return;
4c79b5
				}
4c79b5
4c79b5
				if (!in_array($use_method, $methods))
4c79b5
				{
4c79b5
					$use_method = '.tar';
4c79b5
				}
4c79b5
4c79b5
				include_once($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
4c79b5
4c79b5
				if ($use_method == '.zip')
4c79b5
				{
4c79b5
					$compress = new compress_zip('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$compress = new compress_tar('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method, $use_method);
4c79b5
				}
4c79b5
4c79b5
				// Get email templates
4c79b5
				$email_templates = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
4c79b5
				$email_templates = $email_templates['email/'];
4c79b5
4c79b5
				// Get acp files
4c79b5
				$acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
4c79b5
				$acp_files = $acp_files['acp/'];
4c79b5
4c79b5
				// Get mod files
4c79b5
				$mod_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
4c79b5
				$mod_files = (isset($mod_files['mods/'])) ? $mod_files['mods/'] : array();
4c79b5
4c79b5
				// Add main files
4c79b5
				$this->add_to_archive($compress, $this->main_files, $row['lang_iso']);
4c79b5
4c79b5
				// Add search files if they exist...
4c79b5
				if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_ignore_words.' . $phpEx))
4c79b5
				{
4c79b5
					$this->add_to_archive($compress, array("search_ignore_words.$phpEx"), $row['lang_iso']);
4c79b5
				}
4c79b5
4c79b5
				if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_synonyms.' . $phpEx))
4c79b5
				{
4c79b5
					$this->add_to_archive($compress, array("search_synonyms.$phpEx"), $row['lang_iso']);
4c79b5
				}
4c79b5
4c79b5
				// Write files in folders
4c79b5
				$this->add_to_archive($compress, $email_templates, $row['lang_iso'], 'email');
4c79b5
				$this->add_to_archive($compress, $acp_files, $row['lang_iso'], 'acp');
4c79b5
				$this->add_to_archive($compress, $mod_files, $row['lang_iso'], 'mods');
4c79b5
4c79b5
				// Write ISO File
4c79b5
				$iso_src = htmlspecialchars_decode($row['lang_english_name']) . "\n";
4c79b5
				$iso_src .= htmlspecialchars_decode($row['lang_local_name']) . "\n";
4c79b5
				$iso_src .= htmlspecialchars_decode($row['lang_author']);
4c79b5
				$compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt');
4c79b5
4c79b5
				// index.html files
4c79b5
				$compress->add_data('', 'language/' . $row['lang_iso'] . '/index.html');
4c79b5
				$compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.html');
4c79b5
				$compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.html');
4c79b5
4c79b5
				if (sizeof($mod_files))
4c79b5
				{
4c79b5
					$compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.html');
4c79b5
				}
4c79b5
4c79b5
				$compress->close();
4c79b5
4c79b5
				$compress->download('lang_' . $row['lang_iso']);
4c79b5
				@unlink($phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
4c79b5
4c79b5
				exit;
4c79b5
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		$sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count
4c79b5
			FROM ' . USERS_TABLE . '
4c79b5
			GROUP BY user_lang';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		$lang_count = array();
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$lang_count[$row['user_lang']] = $row['lang_count'];
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$sql = 'SELECT *
4c79b5
			FROM ' . LANG_TABLE . '
4c79b5
			ORDER BY lang_english_name';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		$installed = array();
4c79b5
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$installed[] = $row['lang_iso'];
4c79b5
			$tagstyle = ($row['lang_iso'] == $config['default_lang']) ? '*' : '';
4c79b5
4c79b5
			$template->assign_block_vars('lang', array(
4c79b5
				'U_DETAILS'			=> $this->u_action . "&action=details&id={$row['lang_id']}",
4c79b5
				'U_DOWNLOAD'		=> $this->u_action . "&action=download&id={$row['lang_id']}",
4c79b5
				'U_DELETE'			=> $this->u_action . "&action=delete&id={$row['lang_id']}",
4c79b5
4c79b5
				'ENGLISH_NAME'		=> $row['lang_english_name'],
4c79b5
				'TAG'				=> $tagstyle,
4c79b5
				'LOCAL_NAME'		=> $row['lang_local_name'],
4c79b5
				'ISO'				=> $row['lang_iso'],
4c79b5
				'USED_BY'			=> (isset($lang_count[$row['lang_iso']])) ? $lang_count[$row['lang_iso']] : 0,
4c79b5
			));
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$new_ary = $iso = array();
4c79b5
		$dp = @opendir("{$phpbb_root_path}language");
4c79b5
4c79b5
		if ($dp)
4c79b5
		{
4c79b5
			while (($file = readdir($dp)) !== false)
4c79b5
			{
4c79b5
				if ($file[0] != '.' && file_exists("{$phpbb_root_path}language/$file/iso.txt"))
4c79b5
				{
4c79b5
					if (!in_array($file, $installed))
4c79b5
					{
4c79b5
						if ($iso = file("{$phpbb_root_path}language/$file/iso.txt"))
4c79b5
						{
4c79b5
							if (sizeof($iso) == 3)
4c79b5
							{
4c79b5
								$new_ary[$file] = array(
4c79b5
									'iso'		=> $file,
4c79b5
									'name'		=> trim($iso[0]),
4c79b5
									'local_name'=> trim($iso[1]),
4c79b5
									'author'	=> trim($iso[2])
4c79b5
								);
4c79b5
							}
4c79b5
						}
4c79b5
					}
4c79b5
				}
4c79b5
			}
4c79b5
			closedir($dp);
4c79b5
		}
4c79b5
4c79b5
		unset($installed);
4c79b5
4c79b5
		if (sizeof($new_ary))
4c79b5
		{
4c79b5
			foreach ($new_ary as $iso => $lang_ary)
4c79b5
			{
4c79b5
				$template->assign_block_vars('notinst', array(
4c79b5
					'ISO'			=> htmlspecialchars($lang_ary['iso']),
4c79b5
					'LOCAL_NAME'	=> htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'),
4c79b5
					'NAME'			=> htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'),
4c79b5
					'U_INSTALL'		=> $this->u_action . '&action=install&iso=' . urlencode($lang_ary['iso']))
4c79b5
				);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		unset($new_ary);
4c79b5
	}
4c79b5
4c79b5
4c79b5
	/**
4c79b5
	* Set default language variables/header
4c79b5
	*/
4c79b5
	function default_variables()
4c79b5
	{
4c79b5
		global $phpEx;
4c79b5
4c79b5
		$this->language_file_header = '
4c79b5
/**
4c79b5
*
4c79b5
* {FILENAME} [{LANG_NAME}]
4c79b5
*
4c79b5
* @package language
4c79b5
* @version $' . 'Id: ' . '$
4c79b5
* @copyright (c) ' . date('Y') . ' phpBB Group
4c79b5
* @author {CHANGED} - {AUTHOR}
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* DO NOT CHANGE
4c79b5
*/
4c79b5
if (!defined(\'IN_PHPBB\'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
if (empty($lang) || !is_array($lang))
4c79b5
{
4c79b5
	$lang = array();
4c79b5
}
4c79b5
4c79b5
// DEVELOPERS PLEASE NOTE
4c79b5
//
4c79b5
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
4c79b5
//
4c79b5
// Placeholders can now contain order information, e.g. instead of
4c79b5
// \'Page %s of %s\' you can (and should) write \'Page %1$s of %2$s\', this allows
4c79b5
// translators to re-order the output of data while ensuring it remains correct
4c79b5
//
4c79b5
// You do not need this where single placeholders are used, e.g. \'Message %d\' is fine
4c79b5
// equally where a string contains only two placeholders which are used to wrap text
4c79b5
// in a url you again do not need to specify an order e.g., \'Click %sHERE%s\' is fine
4c79b5
';
4c79b5
4c79b5
		$this->lang_header = '
4c79b5
$lang = array_merge($lang, array(
4c79b5
';
4c79b5
4c79b5
		// Language files in language root directory
4c79b5
		$this->main_files = array("common.$phpEx", "groups.$phpEx", "install.$phpEx", "mcp.$phpEx", "memberlist.$phpEx", "posting.$phpEx", "search.$phpEx", "ucp.$phpEx", "viewforum.$phpEx", "viewtopic.$phpEx", "help_bbcode.$phpEx", "help_faq.$phpEx");
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Get filename/location of language file
4c79b5
	*/
4c79b5
	function get_filename($lang_iso, $directory, $filename, $check_store = false, $only_return_filename = false)
4c79b5
	{
4c79b5
		global $phpbb_root_path, $safe_mode;
4c79b5
4c79b5
		$check_filename = "language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
4c79b5
4c79b5
		if ($check_store)
4c79b5
		{
4c79b5
			$check_store_filename = ($safe_mode) ? "store/langfile_{$lang_iso}" . (($directory) ? '_' . $directory : '') . "_{$filename}" : "store/language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
4c79b5
4c79b5
			if (!$only_return_filename && file_exists($phpbb_root_path . $check_store_filename))
4c79b5
			{
4c79b5
				return $check_store_filename;
4c79b5
			}
4c79b5
			else if ($only_return_filename)
4c79b5
			{
4c79b5
				return $check_store_filename;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		return $check_filename;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Add files to archive
4c79b5
	*/
4c79b5
	function add_to_archive(&$compress, $filelist, $lang_iso, $directory = '')
4c79b5
	{
4c79b5
		global $phpbb_root_path;
4c79b5
4c79b5
		foreach ($filelist as $file)
4c79b5
		{
4c79b5
			// Get source filename
4c79b5
			$source = $this->get_filename($lang_iso, $directory, $file, true);
4c79b5
			$destination = 'language/' . $lang_iso . '/' . (($directory) ? $directory . '/' : '') . $file;
4c79b5
4c79b5
			// Add file to archive
4c79b5
			$compress->add_custom_file($phpbb_root_path . $source, $destination);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Little helper to add some hardcoded template bits
4c79b5
	*/
4c79b5
	function add_input_field()
4c79b5
	{
4c79b5
		$keys = func_get_args();
4c79b5
4c79b5
		$non_static		= array_shift($keys);
4c79b5
		$value			= array_shift($keys);
4c79b5
4c79b5
		if (!$non_static)
4c79b5
		{
4c79b5
			return '' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '';
4c79b5
		}
4c79b5
4c79b5
		// If more then 270 characters, then we present a textarea, else an input field
4c79b5
		$textarea = (utf8_strlen($value) > 270) ? true : false;
4c79b5
		$tpl = '';
4c79b5
4c79b5
		$tpl .= ($textarea) ? '
4c79b5
		$tpl .= 'entry[' . implode('][', array_map('utf8_htmlspecialchars', $keys)) . ']"';
4c79b5
4c79b5
		$tpl .= ($textarea) ? ' cols="80" rows="5" class="langvalue">' : ' class="langvalue" value="';
4c79b5
		$tpl .= htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
4c79b5
		$tpl .= ($textarea) ? '</textarea>' : '" />';
4c79b5
4c79b5
		return $tpl;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Print language entries
4c79b5
	*/
4c79b5
	function print_language_entries(&$lang_ary, $key_prefix = '', $input_field = true)
4c79b5
	{
4c79b5
		$tpl = '';
4c79b5
4c79b5
		foreach ($lang_ary as $key => $value)
4c79b5
		{
4c79b5
			if (is_array($value))
4c79b5
			{
4c79b5
				// Write key
4c79b5
				$tpl .= '
4c79b5
				
4c79b5
					' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '
4c79b5
				';
4c79b5
4c79b5
				foreach ($value as $_key => $_value)
4c79b5
				{
4c79b5
					if (is_array($_value))
4c79b5
					{
4c79b5
						// Write key
4c79b5
						$tpl .= '
4c79b5
							
4c79b5
								' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '   ' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '
4c79b5
							';
4c79b5
4c79b5
						foreach ($_value as $__key => $__value)
4c79b5
						{
4c79b5
							// Write key
4c79b5
							$tpl .= '
4c79b5
								
4c79b5
									' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '' . htmlspecialchars($__key, ENT_COMPAT, 'UTF-8') . '
4c79b5
									';
4c79b5
4c79b5
							$tpl .= $this->add_input_field($input_field, $__value, $key, $_key, $__key);
4c79b5
4c79b5
							$tpl .= '
4c79b5
								';
4c79b5
						}
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						// Write key
4c79b5
						$tpl .= '
4c79b5
							
4c79b5
								' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '
4c79b5
								';
4c79b5
4c79b5
						$tpl .= $this->add_input_field($input_field, $_value, $key, $_key);
4c79b5
4c79b5
						$tpl .= '
4c79b5
							';
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$tpl .= '
4c79b5
				
4c79b5
					 
4c79b5
				';
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				// Write key
4c79b5
				$tpl .= '
4c79b5
				
4c79b5
					' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '
4c79b5
					';
4c79b5
4c79b5
				$tpl .= $this->add_input_field($input_field, $value, $key);
4c79b5
4c79b5
				$tpl .= '
4c79b5
					';
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		return $tpl;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Compare two language files
4c79b5
	*/
4c79b5
	function compare_language_files($source_lang, $dest_lang, $directory, $file)
4c79b5
	{
4c79b5
		global $phpbb_root_path, $phpEx;
4c79b5
4c79b5
		$return_ary = array();
4c79b5
4c79b5
		$lang = array();
4c79b5
		include("{$phpbb_root_path}language/{$source_lang}/" . (($directory) ? $directory . '/' : '') . $file);
4c79b5
		$lang_entry_src = $lang;
4c79b5
4c79b5
		$lang = array();
4c79b5
4c79b5
		if (!file_exists($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true)))
4c79b5
		{
4c79b5
			return array();
4c79b5
		}
4c79b5
4c79b5
		include($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true));
4c79b5
4c79b5
		$lang_entry_dst = $lang;
4c79b5
4c79b5
		unset($lang);
4c79b5
4c79b5
		$diff_array_keys = array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst));
4c79b5
		unset($lang_entry_dst);
4c79b5
4c79b5
		foreach ($diff_array_keys as $key)
4c79b5
		{
4c79b5
			$return_ary[$key] = $lang_entry_src[$key];
4c79b5
		}
4c79b5
4c79b5
		unset($lang_entry_src);
4c79b5
4c79b5
		return $return_ary;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Return language string value for storage
4c79b5
	*/
4c79b5
	function prepare_lang_entry($text, $store = true)
4c79b5
	{
4c79b5
		$text = (STRIP) ? stripslashes($text) : $text;
4c79b5
4c79b5
		// Adjust for storage...
4c79b5
		if ($store)
4c79b5
		{
4c79b5
			$text = str_replace("'", "\\'", str_replace('\\', '\\\\', $text));
4c79b5
		}
4c79b5
4c79b5
		return $text;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Format language array for storage
4c79b5
	*/
4c79b5
	function format_lang_array($key, $value, $tabs = "\t")
4c79b5
	{
4c79b5
		$entry = '';
4c79b5
4c79b5
		if (!is_array($value))
4c79b5
		{
4c79b5
			$entry .= "{$tabs}'" . $this->prepare_lang_entry($key) . "'\t=> '" . $this->prepare_lang_entry($value) . "',\n";
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$_tabs = $tabs . "\t";
4c79b5
			$entry .= "\n{$tabs}'" . $this->prepare_lang_entry($key) . "'\t=> array(\n";
4c79b5
4c79b5
			foreach ($value as $_key => $_value)
4c79b5
			{
4c79b5
				$entry .= $this->format_lang_array($_key, $_value, $_tabs);
4c79b5
			}
4c79b5
4c79b5
			$entry .= "{$tabs}),\n\n";
4c79b5
		}
4c79b5
4c79b5
		return $entry;
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>