includes/acp/acp_language.php
changeset 0 ceef6d64c21d
equal deleted inserted replaced
-1:000000000000 0:ceef6d64c21d
       
     1 <?php
       
     2 /**
       
     3 *
       
     4 * @package acp
       
     5 * @version $Id$
       
     6 * @copyright (c) 2005 phpBB Group
       
     7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
       
     8 *
       
     9 */
       
    10 
       
    11 /**
       
    12 * @ignore
       
    13 */
       
    14 if (!defined('IN_PHPBB'))
       
    15 {
       
    16 	exit;
       
    17 }
       
    18 
       
    19 /**
       
    20 * @package acp
       
    21 */
       
    22 class acp_language
       
    23 {
       
    24 	var $u_action;
       
    25 	var $main_files;
       
    26 	var $language_header = '';
       
    27 	var $lang_header = '';
       
    28 
       
    29 	var $language_file = '';
       
    30 	var $language_directory = '';
       
    31 
       
    32 	function main($id, $mode)
       
    33 	{
       
    34 		global $config, $db, $user, $auth, $template, $cache;
       
    35 		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
       
    36 		global $safe_mode, $file_uploads;
       
    37 
       
    38 		include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
       
    39 
       
    40 		$this->default_variables();
       
    41 
       
    42 		// Check and set some common vars
       
    43 
       
    44 		$action		= (isset($_POST['update_details'])) ? 'update_details' : '';
       
    45 		$action		= (isset($_POST['download_file'])) ? 'download_file' : $action;
       
    46 		$action		= (isset($_POST['upload_file'])) ? 'upload_file' : $action;
       
    47 		$action		= (isset($_POST['upload_data'])) ? 'upload_data' : $action;
       
    48 		$action		= (isset($_POST['submit_file'])) ? 'submit_file' : $action;
       
    49 		$action		= (isset($_POST['remove_store'])) ? 'details' : $action;
       
    50 
       
    51 		$submit = (empty($action) && !isset($_POST['update']) && !isset($_POST['test_connection'])) ? false : true;
       
    52 		$action = (empty($action)) ? request_var('action', '') : $action;
       
    53 
       
    54 		$form_name = 'acp_lang';
       
    55 		add_form_key('acp_lang');
       
    56 
       
    57 		$lang_id = request_var('id', 0);
       
    58 		if (isset($_POST['missing_file']))
       
    59 		{
       
    60 			$missing_file = request_var('missing_file', array('' => 0));
       
    61 			list($_REQUEST['language_file'], ) = array_keys($missing_file);
       
    62 		}
       
    63 
       
    64 		$selected_lang_file = request_var('language_file', '|common.' . $phpEx);
       
    65 
       
    66 		list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);
       
    67 
       
    68 		$this->language_directory = basename($this->language_directory);
       
    69 		$this->language_file = basename($this->language_file);
       
    70 
       
    71 		$user->add_lang('acp/language');
       
    72 		$this->tpl_name = 'acp_language';
       
    73 		$this->page_title = 'ACP_LANGUAGE_PACKS';
       
    74 
       
    75 		if ($submit && $action == 'upload_data' && request_var('test_connection', ''))
       
    76 		{
       
    77 			$test_connection = false;
       
    78 			$action = 'upload_file';
       
    79 			$method = request_var('method', '');
       
    80 
       
    81 			include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
       
    82 
       
    83 			switch ($method)
       
    84 			{
       
    85 				case 'ftp':
       
    86 					$transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
       
    87 				break;
       
    88 
       
    89 				case 'ftp_fsock':
       
    90 					$transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
       
    91 				break;
       
    92 
       
    93 				default:
       
    94 					trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
       
    95 				break;
       
    96 			}
       
    97 
       
    98 			$test_connection = $transfer->open_session();
       
    99 			$transfer->close_session();
       
   100 		}
       
   101 
       
   102 		switch ($action)
       
   103 		{
       
   104 			case 'upload_file':
       
   105 
       
   106 				include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
       
   107 
       
   108 				$method = request_var('method', '');
       
   109 
       
   110 				if (!class_exists($method))
       
   111 				{
       
   112 					trigger_error('Method does not exist.', E_USER_ERROR);
       
   113 				}
       
   114 
       
   115 				$requested_data = call_user_func(array($method, 'data'));
       
   116 				foreach ($requested_data as $data => $default)
       
   117 				{
       
   118 					$template->assign_block_vars('data', array(
       
   119 						'DATA'		=> $data,
       
   120 						'NAME'		=> $user->lang[strtoupper($method . '_' . $data)],
       
   121 						'EXPLAIN'	=> $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'],
       
   122 						'DEFAULT'	=> (!empty($_REQUEST[$data])) ? request_var($data, '') : $default
       
   123 					));
       
   124 				}
       
   125 
       
   126 				$hidden_data = build_hidden_fields(array(
       
   127 					'file'			=> $this->language_file,
       
   128 					'dir'			=> $this->language_directory,
       
   129 					'language_file'	=> $selected_lang_file,
       
   130 					'method'		=> $method)
       
   131 				);
       
   132 
       
   133 				$hidden_data .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP);
       
   134 
       
   135 				$template->assign_vars(array(
       
   136 					'S_UPLOAD'	=> true,
       
   137 					'NAME'		=> $method,
       
   138 					'U_ACTION'	=> $this->u_action . "&amp;id=$lang_id&amp;action=upload_data",
       
   139 					'U_BACK'	=> $this->u_action . "&amp;id=$lang_id&amp;action=details&amp;language_file=" . urlencode($selected_lang_file),
       
   140 					'HIDDEN'	=> $hidden_data,
       
   141 
       
   142 					'S_CONNECTION_SUCCESS'		=> (request_var('test_connection', '') && $test_connection === true) ? true : false,
       
   143 					'S_CONNECTION_FAILED'		=> (request_var('test_connection', '') && $test_connection !== true) ? true : false
       
   144 				));
       
   145 			break;
       
   146 
       
   147 			case 'update_details':
       
   148 
       
   149 				if (!$submit || !check_form_key($form_name))
       
   150 				{
       
   151 					trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
       
   152 				}
       
   153 
       
   154 				if (!$lang_id)
       
   155 				{
       
   156 					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   157 				}
       
   158 
       
   159 				$sql = 'SELECT *
       
   160 					FROM ' . LANG_TABLE . "
       
   161 					WHERE lang_id = $lang_id";
       
   162 				$result = $db->sql_query($sql);
       
   163 				$row = $db->sql_fetchrow($result);
       
   164 				$db->sql_freeresult($result);
       
   165 
       
   166 				$sql_ary	= array(
       
   167 					'lang_english_name'		=> request_var('lang_english_name', $row['lang_english_name']),
       
   168 					'lang_local_name'		=> utf8_normalize_nfc(request_var('lang_local_name', $row['lang_local_name'], true)),
       
   169 					'lang_author'			=> utf8_normalize_nfc(request_var('lang_author', $row['lang_author'], true)),
       
   170 				);
       
   171 
       
   172 				$db->sql_query('UPDATE ' . LANG_TABLE . '
       
   173 					SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
       
   174 					WHERE lang_id = ' . $lang_id);
       
   175 
       
   176 				add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']);
       
   177 
       
   178 				trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));
       
   179 			break;
       
   180 
       
   181 			case 'submit_file':
       
   182 			case 'download_file':
       
   183 			case 'upload_data':
       
   184 
       
   185 				if (!$submit || !check_form_key($form_name))
       
   186 				{
       
   187 					trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
       
   188 				}
       
   189 
       
   190 				if (!$lang_id || empty($_POST['entry']))
       
   191 				{
       
   192 					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   193 				}
       
   194 
       
   195 				if ($this->language_directory != 'email' && !is_array($_POST['entry']))
       
   196 				{
       
   197 					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   198 				}
       
   199 
       
   200 				if (!$this->language_file || (!$this->language_directory && !in_array($this->language_file, $this->main_files)))
       
   201 				{
       
   202 					trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   203 				}
       
   204 
       
   205 				$sql = 'SELECT *
       
   206 					FROM ' . LANG_TABLE . "
       
   207 					WHERE lang_id = $lang_id";
       
   208 				$result = $db->sql_query($sql);
       
   209 				$row = $db->sql_fetchrow($result);
       
   210 				$db->sql_freeresult($result);
       
   211 
       
   212 				if (!$row)
       
   213 				{
       
   214 					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   215 				}
       
   216 
       
   217 				// Before we attempt to write anything let's check if the admin really chose a correct filename
       
   218 				switch ($this->language_directory)
       
   219 				{
       
   220 					case 'email':
       
   221 						// Get email templates
       
   222 						$email_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
       
   223 						$email_files = $email_files['email/'];
       
   224 
       
   225 						if (!in_array($this->language_file, $email_files))
       
   226 						{
       
   227 							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
       
   228 						}
       
   229 					break;
       
   230 
       
   231 					case 'acp':
       
   232 						// Get acp files
       
   233 						$acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
       
   234 						$acp_files = $acp_files['acp/'];
       
   235 
       
   236 						if (!in_array($this->language_file, $acp_files))
       
   237 						{
       
   238 							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
       
   239 						}
       
   240 					break;
       
   241 
       
   242 					case 'mods':
       
   243 						// Get mod files
       
   244 						$mods_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
       
   245 						$mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
       
   246 
       
   247 						if (!in_array($this->language_file, $mods_files))
       
   248 						{
       
   249 							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
       
   250 						}
       
   251 					break;
       
   252 
       
   253 					default:
       
   254 						if (!in_array($this->language_file, $this->main_files))
       
   255 						{
       
   256 							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
       
   257 						}
       
   258 					break;
       
   259 				}
       
   260 
       
   261 				if (!$safe_mode)
       
   262 				{
       
   263 					$mkdir_ary = array('language', 'language/' . $row['lang_iso']);
       
   264 
       
   265 					if ($this->language_directory)
       
   266 					{
       
   267 						$mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory;
       
   268 					}
       
   269 
       
   270 					foreach ($mkdir_ary as $dir)
       
   271 					{
       
   272 						$dir = $phpbb_root_path . 'store/' . $dir;
       
   273 
       
   274 						if (!is_dir($dir))
       
   275 						{
       
   276 							if (!@mkdir($dir, 0777))
       
   277 							{
       
   278 								trigger_error("Could not create directory $dir", E_USER_ERROR);
       
   279 							}
       
   280 							@chmod($dir, 0777);
       
   281 						}
       
   282 					}
       
   283 				}
       
   284 
       
   285 				// Get target filename for storage folder
       
   286 				$filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true);
       
   287 				$fp = @fopen($phpbb_root_path . $filename, 'wb');
       
   288 
       
   289 				if (!$fp)
       
   290 				{
       
   291 					trigger_error(sprintf($user->lang['UNABLE_TO_WRITE_FILE'], $filename) . adm_back_link($this->u_action . '&amp;id=' . $lang_id . '&amp;action=details&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
       
   292 				}
       
   293 
       
   294 				if ($this->language_directory == 'email')
       
   295 				{
       
   296 					// Email Template
       
   297 					$entry = $this->prepare_lang_entry($_POST['entry'], false);
       
   298 					fwrite($fp, $entry);
       
   299 				}
       
   300 				else
       
   301 				{
       
   302 					$name = (($this->language_directory) ? $this->language_directory . '_' : '') . $this->language_file;
       
   303 					$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);
       
   304 
       
   305 					if (strpos($this->language_file, 'help_') === 0)
       
   306 					{
       
   307 						// Help File
       
   308 						$header .= '$help = array(' . "\n";
       
   309 						fwrite($fp, $header);
       
   310 
       
   311 						foreach ($_POST['entry'] as $key => $value)
       
   312 						{
       
   313 							if (!is_array($value))
       
   314 							{
       
   315 								continue;
       
   316 							}
       
   317 
       
   318 							$entry = "\tarray(\n";
       
   319 
       
   320 							foreach ($value as $_key => $_value)
       
   321 							{
       
   322 								$entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n";
       
   323 							}
       
   324 
       
   325 							$entry .= "\t),\n";
       
   326 							fwrite($fp, $entry);
       
   327 						}
       
   328 
       
   329 						$footer = ");\n\n?>";
       
   330 						fwrite($fp, $footer);
       
   331 					}
       
   332 					else
       
   333 					{
       
   334 						// Language File
       
   335 						$header .= $this->lang_header;
       
   336 						fwrite($fp, $header);
       
   337 
       
   338 						foreach ($_POST['entry'] as $key => $value)
       
   339 						{
       
   340 							$entry = $this->format_lang_array($key, $value);
       
   341 							fwrite($fp, $entry);
       
   342 						}
       
   343 
       
   344 						$footer = "));\n\n?>";
       
   345 						fwrite($fp, $footer);
       
   346 					}
       
   347 				}
       
   348 
       
   349 				fclose($fp);
       
   350 
       
   351 				if ($action == 'download_file')
       
   352 				{
       
   353 					header('Pragma: no-cache');
       
   354 					header('Content-Type: application/octetstream; name="' . $this->language_file . '"');
       
   355 					header('Content-disposition: attachment; filename=' . $this->language_file);
       
   356 
       
   357 					$fp = @fopen($phpbb_root_path . $filename, 'rb');
       
   358 					while ($buffer = fread($fp, 1024))
       
   359 					{
       
   360 						echo $buffer;
       
   361 					}
       
   362 					fclose($fp);
       
   363 
       
   364 					add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
       
   365 
       
   366 					exit;
       
   367 				}
       
   368 				else if ($action == 'upload_data')
       
   369 				{
       
   370 					$sql = 'SELECT lang_iso
       
   371 						FROM ' . LANG_TABLE . "
       
   372 						WHERE lang_id = $lang_id";
       
   373 					$result = $db->sql_query($sql);
       
   374 					$row = $db->sql_fetchrow($result);
       
   375 					$db->sql_freeresult($result);
       
   376 
       
   377 					$file = request_var('file', '');
       
   378 					$dir = request_var('dir', '');
       
   379 
       
   380 					$selected_lang_file = $dir . '|' . $file;
       
   381 
       
   382 					$old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true);
       
   383 					$lang_path = 'language/' . $row['lang_iso'] . '/' . (($dir) ? $dir . '/' : '');
       
   384 
       
   385 					include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
       
   386 					$method = request_var('method', '');
       
   387 
       
   388 					if ($method != 'ftp' && $method != 'ftp_fsock')
       
   389 					{
       
   390 						trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
       
   391 					}
       
   392 
       
   393 					$transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
       
   394 
       
   395 					if (($result = $transfer->open_session()) !== true)
       
   396 					{
       
   397 						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);
       
   398 					}
       
   399 
       
   400 					$transfer->rename($lang_path . $file, $lang_path . $file . '.bak');
       
   401 					$result = $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file);
       
   402 
       
   403 					if ($result === false)
       
   404 					{
       
   405 						// If failed, try to rename again and print error out...
       
   406 						$transfer->delete_file($lang_path . $file);
       
   407 						$transfer->rename($lang_path . $file . '.bak', $lang_path . $file);
       
   408 
       
   409 						trigger_error($user->lang['UPLOAD_FAILED'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
       
   410 					}
       
   411 
       
   412 					$transfer->close_session();
       
   413 
       
   414 					// Remove from storage folder
       
   415 					if (file_exists($phpbb_root_path . 'store/' . $lang_path . $file))
       
   416 					{
       
   417 						@unlink($phpbb_root_path . 'store/' . $lang_path . $file);
       
   418 					}
       
   419 
       
   420 					add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file);
       
   421 
       
   422 					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)));
       
   423 				}
       
   424 
       
   425 				add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
       
   426 				$action = 'details';
       
   427 
       
   428 			// no break;
       
   429 
       
   430 			case 'details':
       
   431 
       
   432 				if (!$lang_id)
       
   433 				{
       
   434 					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   435 				}
       
   436 
       
   437 				$this->page_title = 'LANGUAGE_PACK_DETAILS';
       
   438 
       
   439 				$sql = 'SELECT *
       
   440 					FROM ' . LANG_TABLE . '
       
   441 					WHERE lang_id = ' . $lang_id;
       
   442 				$result = $db->sql_query($sql);
       
   443 				$lang_entries = $db->sql_fetchrow($result);
       
   444 				$db->sql_freeresult($result);
       
   445 
       
   446 				$lang_iso = $lang_entries['lang_iso'];
       
   447 				$missing_vars = $missing_files = array();
       
   448 
       
   449 				// Get email templates
       
   450 				$email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt');
       
   451 				$email_files = $email_files['email/'];
       
   452 
       
   453 				// Get acp files
       
   454 				$acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx);
       
   455 				$acp_files = $acp_files['acp/'];
       
   456 
       
   457 				// Get mod files
       
   458 				$mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx);
       
   459 				$mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
       
   460 
       
   461 				// Check if our current filename matches the files
       
   462 				switch ($this->language_directory)
       
   463 				{
       
   464 					case 'email':
       
   465 						if (!in_array($this->language_file, $email_files))
       
   466 						{
       
   467 							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
       
   468 						}
       
   469 					break;
       
   470 
       
   471 					case 'acp':
       
   472 						if (!in_array($this->language_file, $acp_files))
       
   473 						{
       
   474 							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
       
   475 						}
       
   476 					break;
       
   477 
       
   478 					case 'mods':
       
   479 						if (!in_array($this->language_file, $mods_files))
       
   480 						{
       
   481 							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
       
   482 						}
       
   483 					break;
       
   484 
       
   485 					default:
       
   486 						if (!in_array($this->language_file, $this->main_files))
       
   487 						{
       
   488 							trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
       
   489 						}
       
   490 				}
       
   491 
       
   492 				if (isset($_POST['remove_store']))
       
   493 				{
       
   494 					$store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true);
       
   495 
       
   496 					if (file_exists($phpbb_root_path . $store_filename))
       
   497 					{
       
   498 						@unlink($phpbb_root_path . $store_filename);
       
   499 					}
       
   500 				}
       
   501 
       
   502 				include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
       
   503 
       
   504 				$methods = transfer::methods();
       
   505 
       
   506 				foreach ($methods as $method)
       
   507 				{
       
   508 					$template->assign_block_vars('buttons', array(
       
   509 						'VALUE' => $method
       
   510 					));
       
   511 				}
       
   512 
       
   513 				$template->assign_vars(array(
       
   514 					'S_DETAILS'			=> true,
       
   515 					'U_ACTION'			=> $this->u_action . "&amp;action=details&amp;id=$lang_id",
       
   516 					'U_BACK'			=> $this->u_action,
       
   517 					'LANG_LOCAL_NAME'	=> $lang_entries['lang_local_name'],
       
   518 					'LANG_ENGLISH_NAME'	=> $lang_entries['lang_english_name'],
       
   519 					'LANG_ISO'			=> $lang_entries['lang_iso'],
       
   520 					'LANG_AUTHOR'		=> $lang_entries['lang_author'],
       
   521 					'ALLOW_UPLOAD'		=> sizeof($methods)
       
   522 					)
       
   523 				);
       
   524 
       
   525 				// If current lang is different from the default lang, then first try to grab missing/additional vars
       
   526 				if ($lang_iso != $config['default_lang'])
       
   527 				{
       
   528 					$is_missing_var = false;
       
   529 
       
   530 					foreach ($this->main_files as $file)
       
   531 					{
       
   532 						if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file)))
       
   533 						{
       
   534 							$missing_vars[$file] = $this->compare_language_files($config['default_lang'], $lang_iso, '', $file);
       
   535 
       
   536 							if (sizeof($missing_vars[$file]))
       
   537 							{
       
   538 								$is_missing_var = true;
       
   539 							}
       
   540 						}
       
   541 						else
       
   542 						{
       
   543 							$missing_files[] = $this->get_filename($lang_iso, '', $file);
       
   544 						}
       
   545 					}
       
   546 
       
   547 					// Now go through acp/mods directories
       
   548 					foreach ($acp_files as $file)
       
   549 					{
       
   550 						if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'acp', $file)))
       
   551 						{
       
   552 							$missing_vars['acp/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'acp', $file);
       
   553 
       
   554 							if (sizeof($missing_vars['acp/' . $file]))
       
   555 							{
       
   556 								$is_missing_var = true;
       
   557 							}
       
   558 						}
       
   559 						else
       
   560 						{
       
   561 							$missing_files[] = $this->get_filename($lang_iso, 'acp', $file);
       
   562 						}
       
   563 					}
       
   564 
       
   565 					if (sizeof($mods_files))
       
   566 					{
       
   567 						foreach ($mods_files as $file)
       
   568 						{
       
   569 							if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'mods', $file)))
       
   570 							{
       
   571 								$missing_vars['mods/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'mods', $file);
       
   572 
       
   573 								if (sizeof($missing_vars['mods/' . $file]))
       
   574 								{
       
   575 									$is_missing_var = true;
       
   576 								}
       
   577 							}
       
   578 							else
       
   579 							{
       
   580 								$missing_files[] = $this->get_filename($lang_iso, 'mods', $file);
       
   581 							}
       
   582 						}
       
   583 					}
       
   584 
       
   585 					// More missing files... for example email templates?
       
   586 					foreach ($email_files as $file)
       
   587 					{
       
   588 						if (!file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'email', $file)))
       
   589 						{
       
   590 							$missing_files[] = $this->get_filename($lang_iso, 'email', $file);
       
   591 						}
       
   592 					}
       
   593 
       
   594 					if (sizeof($missing_files))
       
   595 					{
       
   596 						$template->assign_vars(array(
       
   597 							'S_MISSING_FILES'		=> true,
       
   598 							'L_MISSING_FILES'		=> sprintf($user->lang['THOSE_MISSING_LANG_FILES'], $lang_entries['lang_local_name']),
       
   599 							'MISSING_FILES'			=> implode('<br />', $missing_files))
       
   600 						);
       
   601 					}
       
   602 
       
   603 					if ($is_missing_var)
       
   604 					{
       
   605 						$template->assign_vars(array(
       
   606 							'S_MISSING_VARS'			=> true,
       
   607 							'L_MISSING_VARS_EXPLAIN'	=> sprintf($user->lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries['lang_local_name']),
       
   608 							'U_MISSING_ACTION'			=> $this->u_action . "&amp;action=$action&amp;id=$lang_id")
       
   609 						);
       
   610 
       
   611 						foreach ($missing_vars as $file => $vars)
       
   612 						{
       
   613 							if (!sizeof($vars))
       
   614 							{
       
   615 								continue;
       
   616 							}
       
   617 
       
   618 							$template->assign_block_vars('missing', array(
       
   619 								'FILE'			=> $file,
       
   620 								'TPL'			=> $this->print_language_entries($vars, '', false),
       
   621 								'KEY'			=> (strpos($file, '/') === false) ? '|' . $file : str_replace('/', '|', $file))
       
   622 							);
       
   623 						}
       
   624 					}
       
   625 				}
       
   626 
       
   627 				// Main language files
       
   628 				$s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['LANGUAGE_FILES'] . '</option>';
       
   629 				foreach ($this->main_files as $file)
       
   630 				{
       
   631 					if (strpos($file, 'help_') === 0)
       
   632 					{
       
   633 						continue;
       
   634 					}
       
   635 
       
   636 					$prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
       
   637 
       
   638 					$selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
       
   639 					$s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
       
   640 				}
       
   641 
       
   642 				// Help Files
       
   643 				$s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['HELP_FILES'] . '</option>';
       
   644 				foreach ($this->main_files as $file)
       
   645 				{
       
   646 					if (strpos($file, 'help_') !== 0)
       
   647 					{
       
   648 						continue;
       
   649 					}
       
   650 
       
   651 					$prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
       
   652 
       
   653 					$selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
       
   654 					$s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
       
   655 				}
       
   656 
       
   657 				// Now every other language directory
       
   658 				$check_files = array('email', 'acp', 'mods');
       
   659 
       
   660 				foreach ($check_files as $check)
       
   661 				{
       
   662 					if (!sizeof(${$check . '_files'}))
       
   663 					{
       
   664 						continue;
       
   665 					}
       
   666 
       
   667 					$s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang[strtoupper($check) . '_FILES'] . '</option>';
       
   668 
       
   669 					foreach (${$check . '_files'} as $file)
       
   670 					{
       
   671 						$prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $check, $file, true, true))) ? '* ' : '';
       
   672 
       
   673 						$selected = ($this->language_directory == $check && $this->language_file == $file) ? ' selected="selected"' : '';
       
   674 						$s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
       
   675 					}
       
   676 				}
       
   677 
       
   678 				// Get Language Entries - if saved within store folder, we take this one (with the option to remove it)
       
   679 				$lang = array();
       
   680 
       
   681 				$is_email_file = ($this->language_directory == 'email') ? true : false;
       
   682 				$is_help_file = (strpos($this->language_file, 'help_') === 0) ? true : false;
       
   683 
       
   684 				$file_from_store = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true))) ? true : false;
       
   685 				$no_store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file);
       
   686 
       
   687 				if (!$file_from_store && !file_exists($phpbb_root_path . $no_store_filename))
       
   688 				{
       
   689 					$print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $no_store_filename);
       
   690 				}
       
   691 				else
       
   692 				{
       
   693 					if ($is_email_file)
       
   694 					{
       
   695 						$lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
       
   696 					}
       
   697 					else
       
   698 					{
       
   699 						$help = array();
       
   700 						include($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
       
   701 
       
   702 						if ($is_help_file)
       
   703 						{
       
   704 							$lang = $help;
       
   705 							unset($help);
       
   706 						}
       
   707 					}
       
   708 
       
   709 					$print_message = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
       
   710 				}
       
   711 
       
   712 				// Normal language pack entries
       
   713 				$template->assign_vars(array(
       
   714 					'U_ENTRY_ACTION'		=> $this->u_action . "&amp;action=details&amp;id=$lang_id#entries",
       
   715 					'S_EMAIL_FILE'			=> $is_email_file,
       
   716 					'S_FROM_STORE'			=> $file_from_store,
       
   717 					'S_LANG_OPTIONS'		=> $s_lang_options,
       
   718 					'PRINT_MESSAGE'			=> $print_message,
       
   719 					)
       
   720 				);
       
   721 
       
   722 				if (!$is_email_file)
       
   723 				{
       
   724 					$tpl = '';
       
   725 					$name = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
       
   726 
       
   727 					if (isset($missing_vars[$name]) && sizeof($missing_vars[$name]))
       
   728 					{
       
   729 						$tpl .= $this->print_language_entries($missing_vars[$name], '* ');
       
   730 					}
       
   731 
       
   732 					$tpl .= $this->print_language_entries($lang);
       
   733 
       
   734 					$template->assign_var('TPL', $tpl);
       
   735 					unset($tpl);
       
   736 				}
       
   737 				else
       
   738 				{
       
   739 					$template->assign_vars(array(
       
   740 						'LANG'		=> $lang)
       
   741 					);
       
   742 
       
   743 					unset($lang);
       
   744 				}
       
   745 
       
   746 				return;
       
   747 
       
   748 			break;
       
   749 
       
   750 			case 'delete':
       
   751 
       
   752 				if (!$lang_id)
       
   753 				{
       
   754 					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   755 				}
       
   756 
       
   757 				$sql = 'SELECT *
       
   758 					FROM ' . LANG_TABLE . '
       
   759 					WHERE lang_id = ' . $lang_id;
       
   760 				$result = $db->sql_query($sql);
       
   761 				$row = $db->sql_fetchrow($result);
       
   762 				$db->sql_freeresult($result);
       
   763 
       
   764 				if ($row['lang_iso'] == $config['default_lang'])
       
   765 				{
       
   766 					trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   767 				}
       
   768 
       
   769 				if (confirm_box(true))
       
   770 				{
       
   771 					$db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
       
   772 
       
   773 					$sql = 'UPDATE ' . USERS_TABLE . "
       
   774 						SET user_lang = '" . $db->sql_escape($config['default_lang']) . "'
       
   775 						WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
       
   776 					$db->sql_query($sql);
       
   777 
       
   778 					// We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
       
   779 					$sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
       
   780 					$db->sql_query($sql);
       
   781 
       
   782 					$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
       
   783 					$db->sql_query($sql);
       
   784 
       
   785 					$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
       
   786 					$result = $db->sql_query($sql);
       
   787 
       
   788 					$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
       
   789 
       
   790 					add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']);
       
   791 
       
   792 					trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
       
   793 				}
       
   794 				else
       
   795 				{
       
   796 					$s_hidden_fields = array(
       
   797 						'i'			=> $id,
       
   798 						'mode'		=> $mode,
       
   799 						'action'	=> $action,
       
   800 						'id'		=> $lang_id,
       
   801 					);
       
   802 					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
       
   803 				}
       
   804 			break;
       
   805 
       
   806 			case 'install':
       
   807 				$lang_iso = request_var('iso', '');
       
   808 				$lang_iso = basename($lang_iso);
       
   809 
       
   810 				if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt"))
       
   811 				{
       
   812 					trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   813 				}
       
   814 
       
   815 				$file = file("{$phpbb_root_path}language/$lang_iso/iso.txt");
       
   816 
       
   817 				$lang_pack = array(
       
   818 					'iso'		=> $lang_iso,
       
   819 					'name'		=> trim(htmlspecialchars($file[0])),
       
   820 					'local_name'=> trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')),
       
   821 					'author'	=> trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))
       
   822 				);
       
   823 				unset($file);
       
   824 
       
   825 				$sql = 'SELECT lang_iso
       
   826 					FROM ' . LANG_TABLE . "
       
   827 					WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'";
       
   828 				$result = $db->sql_query($sql);
       
   829 				$row = $db->sql_fetchrow($result);
       
   830 				$db->sql_freeresult($result);
       
   831 
       
   832 				if ($row)
       
   833 				{
       
   834 					trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   835 				}
       
   836 
       
   837 				if (!$lang_pack['name'] || !$lang_pack['local_name'])
       
   838 				{
       
   839 					trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   840 				}
       
   841 
       
   842 				// Add language pack
       
   843 				$sql_ary = array(
       
   844 					'lang_iso'			=> $lang_pack['iso'],
       
   845 					'lang_dir'			=> $lang_pack['iso'],
       
   846 					'lang_english_name'	=> $lang_pack['name'],
       
   847 					'lang_local_name'	=> $lang_pack['local_name'],
       
   848 					'lang_author'		=> $lang_pack['author']
       
   849 				);
       
   850 
       
   851 				$db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
       
   852 				$lang_id = $db->sql_nextid();
       
   853 
       
   854 				$valid_localized = array(
       
   855 					'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',
       
   856 				);
       
   857 
       
   858 				$sql_ary = array();
       
   859 
       
   860 				$sql = 'SELECT *
       
   861 					FROM ' . STYLES_IMAGESET_TABLE;
       
   862 				$result = $db->sql_query($sql);
       
   863 				while ($imageset_row = $db->sql_fetchrow($result))
       
   864 				{
       
   865 					if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg"))
       
   866 					{
       
   867 						$cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg");
       
   868 						foreach ($cfg_data_imageset_data as $image_name => $value)
       
   869 						{
       
   870 							if (strpos($value, '*') !== false)
       
   871 							{
       
   872 								if (substr($value, -1, 1) === '*')
       
   873 								{
       
   874 									list($image_filename, $image_height) = explode('*', $value);
       
   875 									$image_width = 0;
       
   876 								}
       
   877 								else
       
   878 								{
       
   879 									list($image_filename, $image_height, $image_width) = explode('*', $value);
       
   880 								}
       
   881 							}
       
   882 							else
       
   883 							{
       
   884 								$image_filename = $value;
       
   885 								$image_height = $image_width = 0;
       
   886 							}
       
   887 
       
   888 							if (strpos($image_name, 'img_') === 0 && $image_filename)
       
   889 							{
       
   890 								$image_name = substr($image_name, 4);
       
   891 								if (in_array($image_name, $valid_localized))
       
   892 								{
       
   893 									$sql_ary[] = array(
       
   894 										'image_name'		=> (string) $image_name,
       
   895 										'image_filename'	=> (string) $image_filename,
       
   896 										'image_height'		=> (int) $image_height,
       
   897 										'image_width'		=> (int) $image_width,
       
   898 										'imageset_id'		=> (int) $imageset_row['imageset_id'],
       
   899 										'image_lang'		=> (string) $lang_pack['iso'],
       
   900 									);
       
   901 								}
       
   902 							}
       
   903 						}
       
   904 					}
       
   905 				}
       
   906 				$db->sql_freeresult($result);
       
   907 
       
   908 				if (sizeof($sql_ary))
       
   909 				{
       
   910 					$db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
       
   911 					$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
       
   912 				}
       
   913 
       
   914 				// Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier.
       
   915 				$sql = 'SELECT lang_id
       
   916 					FROM ' . LANG_TABLE . "
       
   917 					WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
       
   918 				$result = $db->sql_query($sql);
       
   919 				$default_lang_id = (int) $db->sql_fetchfield('lang_id');
       
   920 				$db->sql_freeresult($result);
       
   921 
       
   922 				// We want to notify the admin that custom profile fields need to be updated for the new language.
       
   923 				$notify_cpf_update = false;
       
   924 
       
   925 				// From the mysql documentation:
       
   926 				// 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.
       
   927 				// Due to this we stay on the safe side if we do the insertion "the manual way"
       
   928 
       
   929 				$sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value
       
   930 					FROM ' . PROFILE_LANG_TABLE . '
       
   931 					WHERE lang_id = ' . $default_lang_id;
       
   932 				$result = $db->sql_query($sql);
       
   933 
       
   934 				while ($row = $db->sql_fetchrow($result))
       
   935 				{
       
   936 					$row['lang_id'] = $lang_id;
       
   937 					$db->sql_query('INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
       
   938 					$notify_cpf_update = true;
       
   939 				}
       
   940 				$db->sql_freeresult($result);
       
   941 
       
   942 				$sql = 'SELECT field_id, option_id, field_type, lang_value
       
   943 					FROM ' . PROFILE_FIELDS_LANG_TABLE . '
       
   944 					WHERE lang_id = ' . $default_lang_id;
       
   945 				$result = $db->sql_query($sql);
       
   946 
       
   947 				while ($row = $db->sql_fetchrow($result))
       
   948 				{
       
   949 					$row['lang_id'] = $lang_id;
       
   950 					$db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
       
   951 					$notify_cpf_update = true;
       
   952 				}
       
   953 				$db->sql_freeresult($result);
       
   954 
       
   955 				add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']);
       
   956 
       
   957 				$message = sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']);
       
   958 				$message .= ($notify_cpf_update) ? '<br /><br />' . $user->lang['LANGUAGE_PACK_CPF_UPDATE'] : '';
       
   959 				trigger_error($message . adm_back_link($this->u_action));
       
   960 
       
   961 			break;
       
   962 
       
   963 			case 'download':
       
   964 
       
   965 				if (!$lang_id)
       
   966 				{
       
   967 					trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
       
   968 				}
       
   969 
       
   970 				$sql = 'SELECT *
       
   971 					FROM ' . LANG_TABLE . '
       
   972 					WHERE lang_id = ' . $lang_id;
       
   973 				$result = $db->sql_query($sql);
       
   974 				$row = $db->sql_fetchrow($result);
       
   975 				$db->sql_freeresult($result);
       
   976 
       
   977 				$use_method = request_var('use_method', '');
       
   978 				$methods = array('.tar');
       
   979 
       
   980 				$available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
       
   981 				foreach ($available_methods as $type => $module)
       
   982 				{
       
   983 					if (!@extension_loaded($module))
       
   984 					{
       
   985 						continue;
       
   986 					}
       
   987 
       
   988 					$methods[] = $type;
       
   989 				}
       
   990 
       
   991 				// Let the user decide in which format he wants to have the pack
       
   992 				if (!$use_method)
       
   993 				{
       
   994 					$this->page_title = 'SELECT_DOWNLOAD_FORMAT';
       
   995 
       
   996 					$radio_buttons = '';
       
   997 					foreach ($methods as $method)
       
   998 					{
       
   999 						$radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>';
       
  1000 					}
       
  1001 
       
  1002 					$template->assign_vars(array(
       
  1003 						'S_SELECT_METHOD'		=> true,
       
  1004 						'U_BACK'				=> $this->u_action,
       
  1005 						'U_ACTION'				=> $this->u_action . "&amp;action=$action&amp;id=$lang_id",
       
  1006 						'RADIO_BUTTONS'			=> $radio_buttons)
       
  1007 					);
       
  1008 
       
  1009 					return;
       
  1010 				}
       
  1011 
       
  1012 				if (!in_array($use_method, $methods))
       
  1013 				{
       
  1014 					$use_method = '.tar';
       
  1015 				}
       
  1016 
       
  1017 				include_once($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
       
  1018 
       
  1019 				if ($use_method == '.zip')
       
  1020 				{
       
  1021 					$compress = new compress_zip('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
       
  1022 				}
       
  1023 				else
       
  1024 				{
       
  1025 					$compress = new compress_tar('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method, $use_method);
       
  1026 				}
       
  1027 
       
  1028 				// Get email templates
       
  1029 				$email_templates = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
       
  1030 				$email_templates = $email_templates['email/'];
       
  1031 
       
  1032 				// Get acp files
       
  1033 				$acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
       
  1034 				$acp_files = $acp_files['acp/'];
       
  1035 
       
  1036 				// Get mod files
       
  1037 				$mod_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
       
  1038 				$mod_files = (isset($mod_files['mods/'])) ? $mod_files['mods/'] : array();
       
  1039 
       
  1040 				// Add main files
       
  1041 				$this->add_to_archive($compress, $this->main_files, $row['lang_iso']);
       
  1042 
       
  1043 				// Add search files if they exist...
       
  1044 				if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_ignore_words.' . $phpEx))
       
  1045 				{
       
  1046 					$this->add_to_archive($compress, array("search_ignore_words.$phpEx"), $row['lang_iso']);
       
  1047 				}
       
  1048 
       
  1049 				if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_synonyms.' . $phpEx))
       
  1050 				{
       
  1051 					$this->add_to_archive($compress, array("search_synonyms.$phpEx"), $row['lang_iso']);
       
  1052 				}
       
  1053 
       
  1054 				// Write files in folders
       
  1055 				$this->add_to_archive($compress, $email_templates, $row['lang_iso'], 'email');
       
  1056 				$this->add_to_archive($compress, $acp_files, $row['lang_iso'], 'acp');
       
  1057 				$this->add_to_archive($compress, $mod_files, $row['lang_iso'], 'mods');
       
  1058 
       
  1059 				// Write ISO File
       
  1060 				$iso_src = htmlspecialchars_decode($row['lang_english_name']) . "\n";
       
  1061 				$iso_src .= htmlspecialchars_decode($row['lang_local_name']) . "\n";
       
  1062 				$iso_src .= htmlspecialchars_decode($row['lang_author']);
       
  1063 				$compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt');
       
  1064 
       
  1065 				// index.htm files
       
  1066 				$compress->add_data('', 'language/' . $row['lang_iso'] . '/index.htm');
       
  1067 				$compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.htm');
       
  1068 				$compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.htm');
       
  1069 
       
  1070 				if (sizeof($mod_files))
       
  1071 				{
       
  1072 					$compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.htm');
       
  1073 				}
       
  1074 
       
  1075 				$compress->close();
       
  1076 
       
  1077 				$compress->download('lang_' . $row['lang_iso']);
       
  1078 				@unlink($phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
       
  1079 
       
  1080 				exit;
       
  1081 
       
  1082 			break;
       
  1083 		}
       
  1084 
       
  1085 		$sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count
       
  1086 			FROM ' . USERS_TABLE . '
       
  1087 			GROUP BY user_lang';
       
  1088 		$result = $db->sql_query($sql);
       
  1089 
       
  1090 		$lang_count = array();
       
  1091 		while ($row = $db->sql_fetchrow($result))
       
  1092 		{
       
  1093 			$lang_count[$row['user_lang']] = $row['lang_count'];
       
  1094 		}
       
  1095 		$db->sql_freeresult($result);
       
  1096 
       
  1097 		$sql = 'SELECT *
       
  1098 			FROM ' . LANG_TABLE . '
       
  1099 			ORDER BY lang_english_name';
       
  1100 		$result = $db->sql_query($sql);
       
  1101 
       
  1102 		$installed = array();
       
  1103 
       
  1104 		while ($row = $db->sql_fetchrow($result))
       
  1105 		{
       
  1106 			$installed[] = $row['lang_iso'];
       
  1107 			$tagstyle = ($row['lang_iso'] == $config['default_lang']) ? '*' : '';
       
  1108 
       
  1109 			$template->assign_block_vars('lang', array(
       
  1110 				'U_DETAILS'			=> $this->u_action . "&amp;action=details&amp;id={$row['lang_id']}",
       
  1111 				'U_DOWNLOAD'		=> $this->u_action . "&amp;action=download&amp;id={$row['lang_id']}",
       
  1112 				'U_DELETE'			=> $this->u_action . "&amp;action=delete&amp;id={$row['lang_id']}",
       
  1113 
       
  1114 				'ENGLISH_NAME'		=> $row['lang_english_name'],
       
  1115 				'TAG'				=> $tagstyle,
       
  1116 				'LOCAL_NAME'		=> $row['lang_local_name'],
       
  1117 				'ISO'				=> $row['lang_iso'],
       
  1118 				'USED_BY'			=> (isset($lang_count[$row['lang_iso']])) ? $lang_count[$row['lang_iso']] : 0,
       
  1119 			));
       
  1120 		}
       
  1121 		$db->sql_freeresult($result);
       
  1122 
       
  1123 		$new_ary = $iso = array();
       
  1124 		$dp = @opendir("{$phpbb_root_path}language");
       
  1125 
       
  1126 		if ($dp)
       
  1127 		{
       
  1128 			while (($file = readdir($dp)) !== false)
       
  1129 			{
       
  1130 				if ($file[0] == '.' || !is_dir($phpbb_root_path . 'language/' . $file))
       
  1131 				{
       
  1132 					continue;
       
  1133 				}
       
  1134 
       
  1135 				if (file_exists("{$phpbb_root_path}language/$file/iso.txt"))
       
  1136 				{
       
  1137 					if (!in_array($file, $installed))
       
  1138 					{
       
  1139 						if ($iso = file("{$phpbb_root_path}language/$file/iso.txt"))
       
  1140 						{
       
  1141 							if (sizeof($iso) == 3)
       
  1142 							{
       
  1143 								$new_ary[$file] = array(
       
  1144 									'iso'		=> $file,
       
  1145 									'name'		=> trim($iso[0]),
       
  1146 									'local_name'=> trim($iso[1]),
       
  1147 									'author'	=> trim($iso[2])
       
  1148 								);
       
  1149 							}
       
  1150 						}
       
  1151 					}
       
  1152 				}
       
  1153 			}
       
  1154 			closedir($dp);
       
  1155 		}
       
  1156 
       
  1157 		unset($installed);
       
  1158 
       
  1159 		if (sizeof($new_ary))
       
  1160 		{
       
  1161 			foreach ($new_ary as $iso => $lang_ary)
       
  1162 			{
       
  1163 				$template->assign_block_vars('notinst', array(
       
  1164 					'ISO'			=> htmlspecialchars($lang_ary['iso']),
       
  1165 					'LOCAL_NAME'	=> htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'),
       
  1166 					'NAME'			=> htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'),
       
  1167 					'U_INSTALL'		=> $this->u_action . '&amp;action=install&amp;iso=' . urlencode($lang_ary['iso']))
       
  1168 				);
       
  1169 			}
       
  1170 		}
       
  1171 
       
  1172 		unset($new_ary);
       
  1173 	}
       
  1174 
       
  1175 
       
  1176 	/**
       
  1177 	* Set default language variables/header
       
  1178 	*/
       
  1179 	function default_variables()
       
  1180 	{
       
  1181 		global $phpEx;
       
  1182 
       
  1183 		$this->language_file_header = '<?php
       
  1184 /**
       
  1185 *
       
  1186 * {FILENAME} [{LANG_NAME}]
       
  1187 *
       
  1188 * @package language
       
  1189 * @version $' . 'Id: ' . '$
       
  1190 * @copyright (c) ' . date('Y') . ' phpBB Group
       
  1191 * @author {CHANGED} - {AUTHOR}
       
  1192 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
       
  1193 *
       
  1194 */
       
  1195 
       
  1196 /**
       
  1197 * DO NOT CHANGE
       
  1198 */
       
  1199 if (!defined(\'IN_PHPBB\'))
       
  1200 {
       
  1201 	exit;
       
  1202 }
       
  1203 
       
  1204 if (empty($lang) || !is_array($lang))
       
  1205 {
       
  1206 	$lang = array();
       
  1207 }
       
  1208 
       
  1209 // DEVELOPERS PLEASE NOTE
       
  1210 //
       
  1211 // All language files should use UTF-8 as their encoding and the files must not contain a BOM.
       
  1212 //
       
  1213 // Placeholders can now contain order information, e.g. instead of
       
  1214 // \'Page %s of %s\' you can (and should) write \'Page %1$s of %2$s\', this allows
       
  1215 // translators to re-order the output of data while ensuring it remains correct
       
  1216 //
       
  1217 // You do not need this where single placeholders are used, e.g. \'Message %d\' is fine
       
  1218 // equally where a string contains only two placeholders which are used to wrap text
       
  1219 // in a url you again do not need to specify an order e.g., \'Click %sHERE%s\' is fine
       
  1220 ';
       
  1221 
       
  1222 		$this->lang_header = '
       
  1223 $lang = array_merge($lang, array(
       
  1224 ';
       
  1225 
       
  1226 		// Language files in language root directory
       
  1227 		$this->main_files = array("captcha_qa.$phpEx", "captcha_recaptcha.$phpEx", "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");
       
  1228 	}
       
  1229 
       
  1230 	/**
       
  1231 	* Get filename/location of language file
       
  1232 	*/
       
  1233 	function get_filename($lang_iso, $directory, $filename, $check_store = false, $only_return_filename = false)
       
  1234 	{
       
  1235 		global $phpbb_root_path, $safe_mode;
       
  1236 
       
  1237 		$check_filename = "language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
       
  1238 
       
  1239 		if ($check_store)
       
  1240 		{
       
  1241 			$check_store_filename = ($safe_mode) ? "store/langfile_{$lang_iso}" . (($directory) ? '_' . $directory : '') . "_{$filename}" : "store/language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
       
  1242 
       
  1243 			if (!$only_return_filename && file_exists($phpbb_root_path . $check_store_filename))
       
  1244 			{
       
  1245 				return $check_store_filename;
       
  1246 			}
       
  1247 			else if ($only_return_filename)
       
  1248 			{
       
  1249 				return $check_store_filename;
       
  1250 			}
       
  1251 		}
       
  1252 
       
  1253 		return $check_filename;
       
  1254 	}
       
  1255 
       
  1256 	/**
       
  1257 	* Add files to archive
       
  1258 	*/
       
  1259 	function add_to_archive(&$compress, $filelist, $lang_iso, $directory = '')
       
  1260 	{
       
  1261 		global $phpbb_root_path;
       
  1262 
       
  1263 		foreach ($filelist as $file)
       
  1264 		{
       
  1265 			// Get source filename
       
  1266 			$source = $this->get_filename($lang_iso, $directory, $file, true);
       
  1267 			$destination = 'language/' . $lang_iso . '/' . (($directory) ? $directory . '/' : '') . $file;
       
  1268 
       
  1269 			// Add file to archive
       
  1270 			$compress->add_custom_file($phpbb_root_path . $source, $destination);
       
  1271 		}
       
  1272 	}
       
  1273 
       
  1274 	/**
       
  1275 	* Little helper to add some hardcoded template bits
       
  1276 	*/
       
  1277 	function add_input_field()
       
  1278 	{
       
  1279 		$keys = func_get_args();
       
  1280 
       
  1281 		$non_static		= array_shift($keys);
       
  1282 		$value			= utf8_normalize_nfc(array_shift($keys));
       
  1283 
       
  1284 		if (!$non_static)
       
  1285 		{
       
  1286 			return '<strong>' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '</strong>';
       
  1287 		}
       
  1288 
       
  1289 		// If more then 270 characters, then we present a textarea, else an input field
       
  1290 		$textarea = (utf8_strlen($value) > 270) ? true : false;
       
  1291 		$tpl = '';
       
  1292 
       
  1293 		$tpl .= ($textarea) ? '<textarea name="' : '<input type="text" name="';
       
  1294 		$tpl .= 'entry[' . implode('][', array_map('utf8_htmlspecialchars', $keys)) . ']"';
       
  1295 
       
  1296 		$tpl .= ($textarea) ? ' cols="80" rows="5" class="langvalue">' : ' class="langvalue" value="';
       
  1297 		$tpl .= htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
       
  1298 		$tpl .= ($textarea) ? '</textarea>' : '" />';
       
  1299 
       
  1300 		return $tpl;
       
  1301 	}
       
  1302 
       
  1303 	/**
       
  1304 	* Print language entries
       
  1305 	*/
       
  1306 	function print_language_entries(&$lang_ary, $key_prefix = '', $input_field = true)
       
  1307 	{
       
  1308 		$tpl = '';
       
  1309 
       
  1310 		foreach ($lang_ary as $key => $value)
       
  1311 		{
       
  1312 			if (is_array($value))
       
  1313 			{
       
  1314 				// Write key
       
  1315 				$tpl .= '
       
  1316 				<tr>
       
  1317 					<td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</strong></td>
       
  1318 				</tr>';
       
  1319 
       
  1320 				foreach ($value as $_key => $_value)
       
  1321 				{
       
  1322 					if (is_array($_value))
       
  1323 					{
       
  1324 						// Write key
       
  1325 						$tpl .= '
       
  1326 							<tr>
       
  1327 								<td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '&nbsp; &nbsp;<strong>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</strong></td>
       
  1328 							</tr>';
       
  1329 
       
  1330 						foreach ($_value as $__key => $__value)
       
  1331 						{
       
  1332 							// Write key
       
  1333 							$tpl .= '
       
  1334 								<tr>
       
  1335 									<td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($__key, ENT_COMPAT, 'UTF-8') . '</strong></td>
       
  1336 									<td class="row2">';
       
  1337 
       
  1338 							$tpl .= $this->add_input_field($input_field, $__value, $key, $_key, $__key);
       
  1339 
       
  1340 							$tpl .= '</td>
       
  1341 								</tr>';
       
  1342 						}
       
  1343 					}
       
  1344 					else
       
  1345 					{
       
  1346 						// Write key
       
  1347 						$tpl .= '
       
  1348 							<tr>
       
  1349 								<td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</strong></td>
       
  1350 								<td class="row2">';
       
  1351 
       
  1352 						$tpl .= $this->add_input_field($input_field, $_value, $key, $_key);
       
  1353 
       
  1354 						$tpl .= '</td>
       
  1355 							</tr>';
       
  1356 					}
       
  1357 				}
       
  1358 
       
  1359 				$tpl .= '
       
  1360 				<tr>
       
  1361 					<td class="spacer" colspan="2">&nbsp;</td>
       
  1362 				</tr>';
       
  1363 			}
       
  1364 			else
       
  1365 			{
       
  1366 				// Write key
       
  1367 				$tpl .= '
       
  1368 				<tr>
       
  1369 					<td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</strong></td>
       
  1370 					<td class="row2">';
       
  1371 
       
  1372 				$tpl .= $this->add_input_field($input_field, $value, $key);
       
  1373 
       
  1374 				$tpl .= '</td>
       
  1375 					</tr>';
       
  1376 			}
       
  1377 		}
       
  1378 
       
  1379 		return $tpl;
       
  1380 	}
       
  1381 
       
  1382 	/**
       
  1383 	* Compare two language files
       
  1384 	*/
       
  1385 	function compare_language_files($source_lang, $dest_lang, $directory, $file)
       
  1386 	{
       
  1387 		global $phpbb_root_path, $phpEx;
       
  1388 
       
  1389 		$return_ary = array();
       
  1390 
       
  1391 		$lang = array();
       
  1392 		include("{$phpbb_root_path}language/{$source_lang}/" . (($directory) ? $directory . '/' : '') . $file);
       
  1393 		$lang_entry_src = $lang;
       
  1394 
       
  1395 		$lang = array();
       
  1396 
       
  1397 		if (!file_exists($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true)))
       
  1398 		{
       
  1399 			return array();
       
  1400 		}
       
  1401 
       
  1402 		include($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true));
       
  1403 
       
  1404 		$lang_entry_dst = $lang;
       
  1405 
       
  1406 		unset($lang);
       
  1407 
       
  1408 		$diff_array_keys = array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst));
       
  1409 		unset($lang_entry_dst);
       
  1410 
       
  1411 		foreach ($diff_array_keys as $key)
       
  1412 		{
       
  1413 			$return_ary[$key] = $lang_entry_src[$key];
       
  1414 		}
       
  1415 
       
  1416 		unset($lang_entry_src);
       
  1417 
       
  1418 		return $return_ary;
       
  1419 	}
       
  1420 
       
  1421 	/**
       
  1422 	* Return language string value for storage
       
  1423 	*/
       
  1424 	function prepare_lang_entry($text, $store = true)
       
  1425 	{
       
  1426 		$text = (STRIP) ? stripslashes($text) : $text;
       
  1427 
       
  1428 		// Adjust for storage...
       
  1429 		if ($store)
       
  1430 		{
       
  1431 			$text = str_replace("'", "\\'", str_replace('\\', '\\\\', $text));
       
  1432 		}
       
  1433 
       
  1434 		return $text;
       
  1435 	}
       
  1436 
       
  1437 	/**
       
  1438 	* Format language array for storage
       
  1439 	*/
       
  1440 	function format_lang_array($key, $value, $tabs = "\t")
       
  1441 	{
       
  1442 		$entry = '';
       
  1443 
       
  1444 		if (!is_array($value))
       
  1445 		{
       
  1446 			$entry .= "{$tabs}'" . $this->prepare_lang_entry($key) . "'\t=> '" . $this->prepare_lang_entry($value) . "',\n";
       
  1447 		}
       
  1448 		else
       
  1449 		{
       
  1450 			$_tabs = $tabs . "\t";
       
  1451 			$entry .= "\n{$tabs}'" . $this->prepare_lang_entry($key) . "'\t=> array(\n";
       
  1452 
       
  1453 			foreach ($value as $_key => $_value)
       
  1454 			{
       
  1455 				$entry .= $this->format_lang_array($_key, $_value, $_tabs);
       
  1456 			}
       
  1457 
       
  1458 			$entry .= "{$tabs}),\n\n";
       
  1459 		}
       
  1460 
       
  1461 		return $entry;
       
  1462 	}
       
  1463 }
       
  1464 
       
  1465 ?>