1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/acp/acp_language.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1465 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* @package acp
1.24 +*/
1.25 +class acp_language
1.26 +{
1.27 + var $u_action;
1.28 + var $main_files;
1.29 + var $language_header = '';
1.30 + var $lang_header = '';
1.31 +
1.32 + var $language_file = '';
1.33 + var $language_directory = '';
1.34 +
1.35 + function main($id, $mode)
1.36 + {
1.37 + global $config, $db, $user, $auth, $template, $cache;
1.38 + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
1.39 + global $safe_mode, $file_uploads;
1.40 +
1.41 + include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1.42 +
1.43 + $this->default_variables();
1.44 +
1.45 + // Check and set some common vars
1.46 +
1.47 + $action = (isset($_POST['update_details'])) ? 'update_details' : '';
1.48 + $action = (isset($_POST['download_file'])) ? 'download_file' : $action;
1.49 + $action = (isset($_POST['upload_file'])) ? 'upload_file' : $action;
1.50 + $action = (isset($_POST['upload_data'])) ? 'upload_data' : $action;
1.51 + $action = (isset($_POST['submit_file'])) ? 'submit_file' : $action;
1.52 + $action = (isset($_POST['remove_store'])) ? 'details' : $action;
1.53 +
1.54 + $submit = (empty($action) && !isset($_POST['update']) && !isset($_POST['test_connection'])) ? false : true;
1.55 + $action = (empty($action)) ? request_var('action', '') : $action;
1.56 +
1.57 + $form_name = 'acp_lang';
1.58 + add_form_key('acp_lang');
1.59 +
1.60 + $lang_id = request_var('id', 0);
1.61 + if (isset($_POST['missing_file']))
1.62 + {
1.63 + $missing_file = request_var('missing_file', array('' => 0));
1.64 + list($_REQUEST['language_file'], ) = array_keys($missing_file);
1.65 + }
1.66 +
1.67 + $selected_lang_file = request_var('language_file', '|common.' . $phpEx);
1.68 +
1.69 + list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);
1.70 +
1.71 + $this->language_directory = basename($this->language_directory);
1.72 + $this->language_file = basename($this->language_file);
1.73 +
1.74 + $user->add_lang('acp/language');
1.75 + $this->tpl_name = 'acp_language';
1.76 + $this->page_title = 'ACP_LANGUAGE_PACKS';
1.77 +
1.78 + if ($submit && $action == 'upload_data' && request_var('test_connection', ''))
1.79 + {
1.80 + $test_connection = false;
1.81 + $action = 'upload_file';
1.82 + $method = request_var('method', '');
1.83 +
1.84 + include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
1.85 +
1.86 + switch ($method)
1.87 + {
1.88 + case 'ftp':
1.89 + $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
1.90 + break;
1.91 +
1.92 + case 'ftp_fsock':
1.93 + $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
1.94 + break;
1.95 +
1.96 + default:
1.97 + trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
1.98 + break;
1.99 + }
1.100 +
1.101 + $test_connection = $transfer->open_session();
1.102 + $transfer->close_session();
1.103 + }
1.104 +
1.105 + switch ($action)
1.106 + {
1.107 + case 'upload_file':
1.108 +
1.109 + include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
1.110 +
1.111 + $method = request_var('method', '');
1.112 +
1.113 + if (!class_exists($method))
1.114 + {
1.115 + trigger_error('Method does not exist.', E_USER_ERROR);
1.116 + }
1.117 +
1.118 + $requested_data = call_user_func(array($method, 'data'));
1.119 + foreach ($requested_data as $data => $default)
1.120 + {
1.121 + $template->assign_block_vars('data', array(
1.122 + 'DATA' => $data,
1.123 + 'NAME' => $user->lang[strtoupper($method . '_' . $data)],
1.124 + 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'],
1.125 + 'DEFAULT' => (!empty($_REQUEST[$data])) ? request_var($data, '') : $default
1.126 + ));
1.127 + }
1.128 +
1.129 + $hidden_data = build_hidden_fields(array(
1.130 + 'file' => $this->language_file,
1.131 + 'dir' => $this->language_directory,
1.132 + 'language_file' => $selected_lang_file,
1.133 + 'method' => $method)
1.134 + );
1.135 +
1.136 + $hidden_data .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP);
1.137 +
1.138 + $template->assign_vars(array(
1.139 + 'S_UPLOAD' => true,
1.140 + 'NAME' => $method,
1.141 + 'U_ACTION' => $this->u_action . "&id=$lang_id&action=upload_data",
1.142 + 'U_BACK' => $this->u_action . "&id=$lang_id&action=details&language_file=" . urlencode($selected_lang_file),
1.143 + 'HIDDEN' => $hidden_data,
1.144 +
1.145 + 'S_CONNECTION_SUCCESS' => (request_var('test_connection', '') && $test_connection === true) ? true : false,
1.146 + 'S_CONNECTION_FAILED' => (request_var('test_connection', '') && $test_connection !== true) ? true : false
1.147 + ));
1.148 + break;
1.149 +
1.150 + case 'update_details':
1.151 +
1.152 + if (!$submit || !check_form_key($form_name))
1.153 + {
1.154 + trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
1.155 + }
1.156 +
1.157 + if (!$lang_id)
1.158 + {
1.159 + trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.160 + }
1.161 +
1.162 + $sql = 'SELECT *
1.163 + FROM ' . LANG_TABLE . "
1.164 + WHERE lang_id = $lang_id";
1.165 + $result = $db->sql_query($sql);
1.166 + $row = $db->sql_fetchrow($result);
1.167 + $db->sql_freeresult($result);
1.168 +
1.169 + $sql_ary = array(
1.170 + 'lang_english_name' => request_var('lang_english_name', $row['lang_english_name']),
1.171 + 'lang_local_name' => utf8_normalize_nfc(request_var('lang_local_name', $row['lang_local_name'], true)),
1.172 + 'lang_author' => utf8_normalize_nfc(request_var('lang_author', $row['lang_author'], true)),
1.173 + );
1.174 +
1.175 + $db->sql_query('UPDATE ' . LANG_TABLE . '
1.176 + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
1.177 + WHERE lang_id = ' . $lang_id);
1.178 +
1.179 + add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']);
1.180 +
1.181 + trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));
1.182 + break;
1.183 +
1.184 + case 'submit_file':
1.185 + case 'download_file':
1.186 + case 'upload_data':
1.187 +
1.188 + if (!$submit || !check_form_key($form_name))
1.189 + {
1.190 + trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
1.191 + }
1.192 +
1.193 + if (!$lang_id || empty($_POST['entry']))
1.194 + {
1.195 + trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.196 + }
1.197 +
1.198 + if ($this->language_directory != 'email' && !is_array($_POST['entry']))
1.199 + {
1.200 + trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.201 + }
1.202 +
1.203 + if (!$this->language_file || (!$this->language_directory && !in_array($this->language_file, $this->main_files)))
1.204 + {
1.205 + trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
1.206 + }
1.207 +
1.208 + $sql = 'SELECT *
1.209 + FROM ' . LANG_TABLE . "
1.210 + WHERE lang_id = $lang_id";
1.211 + $result = $db->sql_query($sql);
1.212 + $row = $db->sql_fetchrow($result);
1.213 + $db->sql_freeresult($result);
1.214 +
1.215 + if (!$row)
1.216 + {
1.217 + trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.218 + }
1.219 +
1.220 + // Before we attempt to write anything let's check if the admin really chose a correct filename
1.221 + switch ($this->language_directory)
1.222 + {
1.223 + case 'email':
1.224 + // Get email templates
1.225 + $email_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
1.226 + $email_files = $email_files['email/'];
1.227 +
1.228 + if (!in_array($this->language_file, $email_files))
1.229 + {
1.230 + trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
1.231 + }
1.232 + break;
1.233 +
1.234 + case 'acp':
1.235 + // Get acp files
1.236 + $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
1.237 + $acp_files = $acp_files['acp/'];
1.238 +
1.239 + if (!in_array($this->language_file, $acp_files))
1.240 + {
1.241 + trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
1.242 + }
1.243 + break;
1.244 +
1.245 + case 'mods':
1.246 + // Get mod files
1.247 + $mods_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
1.248 + $mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
1.249 +
1.250 + if (!in_array($this->language_file, $mods_files))
1.251 + {
1.252 + trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
1.253 + }
1.254 + break;
1.255 +
1.256 + default:
1.257 + if (!in_array($this->language_file, $this->main_files))
1.258 + {
1.259 + trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
1.260 + }
1.261 + break;
1.262 + }
1.263 +
1.264 + if (!$safe_mode)
1.265 + {
1.266 + $mkdir_ary = array('language', 'language/' . $row['lang_iso']);
1.267 +
1.268 + if ($this->language_directory)
1.269 + {
1.270 + $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory;
1.271 + }
1.272 +
1.273 + foreach ($mkdir_ary as $dir)
1.274 + {
1.275 + $dir = $phpbb_root_path . 'store/' . $dir;
1.276 +
1.277 + if (!is_dir($dir))
1.278 + {
1.279 + if (!@mkdir($dir, 0777))
1.280 + {
1.281 + trigger_error("Could not create directory $dir", E_USER_ERROR);
1.282 + }
1.283 + @chmod($dir, 0777);
1.284 + }
1.285 + }
1.286 + }
1.287 +
1.288 + // Get target filename for storage folder
1.289 + $filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true);
1.290 + $fp = @fopen($phpbb_root_path . $filename, 'wb');
1.291 +
1.292 + if (!$fp)
1.293 + {
1.294 + 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);
1.295 + }
1.296 +
1.297 + if ($this->language_directory == 'email')
1.298 + {
1.299 + // Email Template
1.300 + $entry = $this->prepare_lang_entry($_POST['entry'], false);
1.301 + fwrite($fp, $entry);
1.302 + }
1.303 + else
1.304 + {
1.305 + $name = (($this->language_directory) ? $this->language_directory . '_' : '') . $this->language_file;
1.306 + $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);
1.307 +
1.308 + if (strpos($this->language_file, 'help_') === 0)
1.309 + {
1.310 + // Help File
1.311 + $header .= '$help = array(' . "\n";
1.312 + fwrite($fp, $header);
1.313 +
1.314 + foreach ($_POST['entry'] as $key => $value)
1.315 + {
1.316 + if (!is_array($value))
1.317 + {
1.318 + continue;
1.319 + }
1.320 +
1.321 + $entry = "\tarray(\n";
1.322 +
1.323 + foreach ($value as $_key => $_value)
1.324 + {
1.325 + $entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n";
1.326 + }
1.327 +
1.328 + $entry .= "\t),\n";
1.329 + fwrite($fp, $entry);
1.330 + }
1.331 +
1.332 + $footer = ");\n\n?>";
1.333 + fwrite($fp, $footer);
1.334 + }
1.335 + else
1.336 + {
1.337 + // Language File
1.338 + $header .= $this->lang_header;
1.339 + fwrite($fp, $header);
1.340 +
1.341 + foreach ($_POST['entry'] as $key => $value)
1.342 + {
1.343 + $entry = $this->format_lang_array($key, $value);
1.344 + fwrite($fp, $entry);
1.345 + }
1.346 +
1.347 + $footer = "));\n\n?>";
1.348 + fwrite($fp, $footer);
1.349 + }
1.350 + }
1.351 +
1.352 + fclose($fp);
1.353 +
1.354 + if ($action == 'download_file')
1.355 + {
1.356 + header('Pragma: no-cache');
1.357 + header('Content-Type: application/octetstream; name="' . $this->language_file . '"');
1.358 + header('Content-disposition: attachment; filename=' . $this->language_file);
1.359 +
1.360 + $fp = @fopen($phpbb_root_path . $filename, 'rb');
1.361 + while ($buffer = fread($fp, 1024))
1.362 + {
1.363 + echo $buffer;
1.364 + }
1.365 + fclose($fp);
1.366 +
1.367 + add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
1.368 +
1.369 + exit;
1.370 + }
1.371 + else if ($action == 'upload_data')
1.372 + {
1.373 + $sql = 'SELECT lang_iso
1.374 + FROM ' . LANG_TABLE . "
1.375 + WHERE lang_id = $lang_id";
1.376 + $result = $db->sql_query($sql);
1.377 + $row = $db->sql_fetchrow($result);
1.378 + $db->sql_freeresult($result);
1.379 +
1.380 + $file = request_var('file', '');
1.381 + $dir = request_var('dir', '');
1.382 +
1.383 + $selected_lang_file = $dir . '|' . $file;
1.384 +
1.385 + $old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true);
1.386 + $lang_path = 'language/' . $row['lang_iso'] . '/' . (($dir) ? $dir . '/' : '');
1.387 +
1.388 + include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
1.389 + $method = request_var('method', '');
1.390 +
1.391 + if ($method != 'ftp' && $method != 'ftp_fsock')
1.392 + {
1.393 + trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
1.394 + }
1.395 +
1.396 + $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
1.397 +
1.398 + if (($result = $transfer->open_session()) !== true)
1.399 + {
1.400 + 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);
1.401 + }
1.402 +
1.403 + $transfer->rename($lang_path . $file, $lang_path . $file . '.bak');
1.404 + $result = $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file);
1.405 +
1.406 + if ($result === false)
1.407 + {
1.408 + // If failed, try to rename again and print error out...
1.409 + $transfer->delete_file($lang_path . $file);
1.410 + $transfer->rename($lang_path . $file . '.bak', $lang_path . $file);
1.411 +
1.412 + 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);
1.413 + }
1.414 +
1.415 + $transfer->close_session();
1.416 +
1.417 + // Remove from storage folder
1.418 + if (file_exists($phpbb_root_path . 'store/' . $lang_path . $file))
1.419 + {
1.420 + @unlink($phpbb_root_path . 'store/' . $lang_path . $file);
1.421 + }
1.422 +
1.423 + add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file);
1.424 +
1.425 + trigger_error($user->lang['UPLOAD_COMPLETED'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file)));
1.426 + }
1.427 +
1.428 + add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
1.429 + $action = 'details';
1.430 +
1.431 + // no break;
1.432 +
1.433 + case 'details':
1.434 +
1.435 + if (!$lang_id)
1.436 + {
1.437 + trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.438 + }
1.439 +
1.440 + $this->page_title = 'LANGUAGE_PACK_DETAILS';
1.441 +
1.442 + $sql = 'SELECT *
1.443 + FROM ' . LANG_TABLE . '
1.444 + WHERE lang_id = ' . $lang_id;
1.445 + $result = $db->sql_query($sql);
1.446 + $lang_entries = $db->sql_fetchrow($result);
1.447 + $db->sql_freeresult($result);
1.448 +
1.449 + $lang_iso = $lang_entries['lang_iso'];
1.450 + $missing_vars = $missing_files = array();
1.451 +
1.452 + // Get email templates
1.453 + $email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt');
1.454 + $email_files = $email_files['email/'];
1.455 +
1.456 + // Get acp files
1.457 + $acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx);
1.458 + $acp_files = $acp_files['acp/'];
1.459 +
1.460 + // Get mod files
1.461 + $mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx);
1.462 + $mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
1.463 +
1.464 + // Check if our current filename matches the files
1.465 + switch ($this->language_directory)
1.466 + {
1.467 + case 'email':
1.468 + if (!in_array($this->language_file, $email_files))
1.469 + {
1.470 + trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
1.471 + }
1.472 + break;
1.473 +
1.474 + case 'acp':
1.475 + if (!in_array($this->language_file, $acp_files))
1.476 + {
1.477 + trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
1.478 + }
1.479 + break;
1.480 +
1.481 + case 'mods':
1.482 + if (!in_array($this->language_file, $mods_files))
1.483 + {
1.484 + trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
1.485 + }
1.486 + break;
1.487 +
1.488 + default:
1.489 + if (!in_array($this->language_file, $this->main_files))
1.490 + {
1.491 + trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING);
1.492 + }
1.493 + }
1.494 +
1.495 + if (isset($_POST['remove_store']))
1.496 + {
1.497 + $store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true);
1.498 +
1.499 + if (file_exists($phpbb_root_path . $store_filename))
1.500 + {
1.501 + @unlink($phpbb_root_path . $store_filename);
1.502 + }
1.503 + }
1.504 +
1.505 + include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
1.506 +
1.507 + $methods = transfer::methods();
1.508 +
1.509 + foreach ($methods as $method)
1.510 + {
1.511 + $template->assign_block_vars('buttons', array(
1.512 + 'VALUE' => $method
1.513 + ));
1.514 + }
1.515 +
1.516 + $template->assign_vars(array(
1.517 + 'S_DETAILS' => true,
1.518 + 'U_ACTION' => $this->u_action . "&action=details&id=$lang_id",
1.519 + 'U_BACK' => $this->u_action,
1.520 + 'LANG_LOCAL_NAME' => $lang_entries['lang_local_name'],
1.521 + 'LANG_ENGLISH_NAME' => $lang_entries['lang_english_name'],
1.522 + 'LANG_ISO' => $lang_entries['lang_iso'],
1.523 + 'LANG_AUTHOR' => $lang_entries['lang_author'],
1.524 + 'ALLOW_UPLOAD' => sizeof($methods)
1.525 + )
1.526 + );
1.527 +
1.528 + // If current lang is different from the default lang, then first try to grab missing/additional vars
1.529 + if ($lang_iso != $config['default_lang'])
1.530 + {
1.531 + $is_missing_var = false;
1.532 +
1.533 + foreach ($this->main_files as $file)
1.534 + {
1.535 + if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file)))
1.536 + {
1.537 + $missing_vars[$file] = $this->compare_language_files($config['default_lang'], $lang_iso, '', $file);
1.538 +
1.539 + if (sizeof($missing_vars[$file]))
1.540 + {
1.541 + $is_missing_var = true;
1.542 + }
1.543 + }
1.544 + else
1.545 + {
1.546 + $missing_files[] = $this->get_filename($lang_iso, '', $file);
1.547 + }
1.548 + }
1.549 +
1.550 + // Now go through acp/mods directories
1.551 + foreach ($acp_files as $file)
1.552 + {
1.553 + if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'acp', $file)))
1.554 + {
1.555 + $missing_vars['acp/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'acp', $file);
1.556 +
1.557 + if (sizeof($missing_vars['acp/' . $file]))
1.558 + {
1.559 + $is_missing_var = true;
1.560 + }
1.561 + }
1.562 + else
1.563 + {
1.564 + $missing_files[] = $this->get_filename($lang_iso, 'acp', $file);
1.565 + }
1.566 + }
1.567 +
1.568 + if (sizeof($mods_files))
1.569 + {
1.570 + foreach ($mods_files as $file)
1.571 + {
1.572 + if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'mods', $file)))
1.573 + {
1.574 + $missing_vars['mods/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'mods', $file);
1.575 +
1.576 + if (sizeof($missing_vars['mods/' . $file]))
1.577 + {
1.578 + $is_missing_var = true;
1.579 + }
1.580 + }
1.581 + else
1.582 + {
1.583 + $missing_files[] = $this->get_filename($lang_iso, 'mods', $file);
1.584 + }
1.585 + }
1.586 + }
1.587 +
1.588 + // More missing files... for example email templates?
1.589 + foreach ($email_files as $file)
1.590 + {
1.591 + if (!file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'email', $file)))
1.592 + {
1.593 + $missing_files[] = $this->get_filename($lang_iso, 'email', $file);
1.594 + }
1.595 + }
1.596 +
1.597 + if (sizeof($missing_files))
1.598 + {
1.599 + $template->assign_vars(array(
1.600 + 'S_MISSING_FILES' => true,
1.601 + 'L_MISSING_FILES' => sprintf($user->lang['THOSE_MISSING_LANG_FILES'], $lang_entries['lang_local_name']),
1.602 + 'MISSING_FILES' => implode('<br />', $missing_files))
1.603 + );
1.604 + }
1.605 +
1.606 + if ($is_missing_var)
1.607 + {
1.608 + $template->assign_vars(array(
1.609 + 'S_MISSING_VARS' => true,
1.610 + 'L_MISSING_VARS_EXPLAIN' => sprintf($user->lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries['lang_local_name']),
1.611 + 'U_MISSING_ACTION' => $this->u_action . "&action=$action&id=$lang_id")
1.612 + );
1.613 +
1.614 + foreach ($missing_vars as $file => $vars)
1.615 + {
1.616 + if (!sizeof($vars))
1.617 + {
1.618 + continue;
1.619 + }
1.620 +
1.621 + $template->assign_block_vars('missing', array(
1.622 + 'FILE' => $file,
1.623 + 'TPL' => $this->print_language_entries($vars, '', false),
1.624 + 'KEY' => (strpos($file, '/') === false) ? '|' . $file : str_replace('/', '|', $file))
1.625 + );
1.626 + }
1.627 + }
1.628 + }
1.629 +
1.630 + // Main language files
1.631 + $s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['LANGUAGE_FILES'] . '</option>';
1.632 + foreach ($this->main_files as $file)
1.633 + {
1.634 + if (strpos($file, 'help_') === 0)
1.635 + {
1.636 + continue;
1.637 + }
1.638 +
1.639 + $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
1.640 +
1.641 + $selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
1.642 + $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
1.643 + }
1.644 +
1.645 + // Help Files
1.646 + $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['HELP_FILES'] . '</option>';
1.647 + foreach ($this->main_files as $file)
1.648 + {
1.649 + if (strpos($file, 'help_') !== 0)
1.650 + {
1.651 + continue;
1.652 + }
1.653 +
1.654 + $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
1.655 +
1.656 + $selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
1.657 + $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
1.658 + }
1.659 +
1.660 + // Now every other language directory
1.661 + $check_files = array('email', 'acp', 'mods');
1.662 +
1.663 + foreach ($check_files as $check)
1.664 + {
1.665 + if (!sizeof(${$check . '_files'}))
1.666 + {
1.667 + continue;
1.668 + }
1.669 +
1.670 + $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang[strtoupper($check) . '_FILES'] . '</option>';
1.671 +
1.672 + foreach (${$check . '_files'} as $file)
1.673 + {
1.674 + $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $check, $file, true, true))) ? '* ' : '';
1.675 +
1.676 + $selected = ($this->language_directory == $check && $this->language_file == $file) ? ' selected="selected"' : '';
1.677 + $s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
1.678 + }
1.679 + }
1.680 +
1.681 + // Get Language Entries - if saved within store folder, we take this one (with the option to remove it)
1.682 + $lang = array();
1.683 +
1.684 + $is_email_file = ($this->language_directory == 'email') ? true : false;
1.685 + $is_help_file = (strpos($this->language_file, 'help_') === 0) ? true : false;
1.686 +
1.687 + $file_from_store = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true))) ? true : false;
1.688 + $no_store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file);
1.689 +
1.690 + if (!$file_from_store && !file_exists($phpbb_root_path . $no_store_filename))
1.691 + {
1.692 + $print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $no_store_filename);
1.693 + }
1.694 + else
1.695 + {
1.696 + if ($is_email_file)
1.697 + {
1.698 + $lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
1.699 + }
1.700 + else
1.701 + {
1.702 + $help = array();
1.703 + include($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
1.704 +
1.705 + if ($is_help_file)
1.706 + {
1.707 + $lang = $help;
1.708 + unset($help);
1.709 + }
1.710 + }
1.711 +
1.712 + $print_message = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
1.713 + }
1.714 +
1.715 + // Normal language pack entries
1.716 + $template->assign_vars(array(
1.717 + 'U_ENTRY_ACTION' => $this->u_action . "&action=details&id=$lang_id#entries",
1.718 + 'S_EMAIL_FILE' => $is_email_file,
1.719 + 'S_FROM_STORE' => $file_from_store,
1.720 + 'S_LANG_OPTIONS' => $s_lang_options,
1.721 + 'PRINT_MESSAGE' => $print_message,
1.722 + )
1.723 + );
1.724 +
1.725 + if (!$is_email_file)
1.726 + {
1.727 + $tpl = '';
1.728 + $name = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
1.729 +
1.730 + if (isset($missing_vars[$name]) && sizeof($missing_vars[$name]))
1.731 + {
1.732 + $tpl .= $this->print_language_entries($missing_vars[$name], '* ');
1.733 + }
1.734 +
1.735 + $tpl .= $this->print_language_entries($lang);
1.736 +
1.737 + $template->assign_var('TPL', $tpl);
1.738 + unset($tpl);
1.739 + }
1.740 + else
1.741 + {
1.742 + $template->assign_vars(array(
1.743 + 'LANG' => $lang)
1.744 + );
1.745 +
1.746 + unset($lang);
1.747 + }
1.748 +
1.749 + return;
1.750 +
1.751 + break;
1.752 +
1.753 + case 'delete':
1.754 +
1.755 + if (!$lang_id)
1.756 + {
1.757 + trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.758 + }
1.759 +
1.760 + $sql = 'SELECT *
1.761 + FROM ' . LANG_TABLE . '
1.762 + WHERE lang_id = ' . $lang_id;
1.763 + $result = $db->sql_query($sql);
1.764 + $row = $db->sql_fetchrow($result);
1.765 + $db->sql_freeresult($result);
1.766 +
1.767 + if ($row['lang_iso'] == $config['default_lang'])
1.768 + {
1.769 + trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action), E_USER_WARNING);
1.770 + }
1.771 +
1.772 + if (confirm_box(true))
1.773 + {
1.774 + $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
1.775 +
1.776 + $sql = 'UPDATE ' . USERS_TABLE . "
1.777 + SET user_lang = '" . $db->sql_escape($config['default_lang']) . "'
1.778 + WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
1.779 + $db->sql_query($sql);
1.780 +
1.781 + // We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
1.782 + $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
1.783 + $db->sql_query($sql);
1.784 +
1.785 + $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
1.786 + $db->sql_query($sql);
1.787 +
1.788 + $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
1.789 + $result = $db->sql_query($sql);
1.790 +
1.791 + $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
1.792 +
1.793 + add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']);
1.794 +
1.795 + trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
1.796 + }
1.797 + else
1.798 + {
1.799 + $s_hidden_fields = array(
1.800 + 'i' => $id,
1.801 + 'mode' => $mode,
1.802 + 'action' => $action,
1.803 + 'id' => $lang_id,
1.804 + );
1.805 + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
1.806 + }
1.807 + break;
1.808 +
1.809 + case 'install':
1.810 + $lang_iso = request_var('iso', '');
1.811 + $lang_iso = basename($lang_iso);
1.812 +
1.813 + if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt"))
1.814 + {
1.815 + trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
1.816 + }
1.817 +
1.818 + $file = file("{$phpbb_root_path}language/$lang_iso/iso.txt");
1.819 +
1.820 + $lang_pack = array(
1.821 + 'iso' => $lang_iso,
1.822 + 'name' => trim(htmlspecialchars($file[0])),
1.823 + 'local_name'=> trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')),
1.824 + 'author' => trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))
1.825 + );
1.826 + unset($file);
1.827 +
1.828 + $sql = 'SELECT lang_iso
1.829 + FROM ' . LANG_TABLE . "
1.830 + WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'";
1.831 + $result = $db->sql_query($sql);
1.832 + $row = $db->sql_fetchrow($result);
1.833 + $db->sql_freeresult($result);
1.834 +
1.835 + if ($row)
1.836 + {
1.837 + trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING);
1.838 + }
1.839 +
1.840 + if (!$lang_pack['name'] || !$lang_pack['local_name'])
1.841 + {
1.842 + trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING);
1.843 + }
1.844 +
1.845 + // Add language pack
1.846 + $sql_ary = array(
1.847 + 'lang_iso' => $lang_pack['iso'],
1.848 + 'lang_dir' => $lang_pack['iso'],
1.849 + 'lang_english_name' => $lang_pack['name'],
1.850 + 'lang_local_name' => $lang_pack['local_name'],
1.851 + 'lang_author' => $lang_pack['author']
1.852 + );
1.853 +
1.854 + $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1.855 + $lang_id = $db->sql_nextid();
1.856 +
1.857 + $valid_localized = array(
1.858 + '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',
1.859 + );
1.860 +
1.861 + $sql_ary = array();
1.862 +
1.863 + $sql = 'SELECT *
1.864 + FROM ' . STYLES_IMAGESET_TABLE;
1.865 + $result = $db->sql_query($sql);
1.866 + while ($imageset_row = $db->sql_fetchrow($result))
1.867 + {
1.868 + if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg"))
1.869 + {
1.870 + $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg");
1.871 + foreach ($cfg_data_imageset_data as $image_name => $value)
1.872 + {
1.873 + if (strpos($value, '*') !== false)
1.874 + {
1.875 + if (substr($value, -1, 1) === '*')
1.876 + {
1.877 + list($image_filename, $image_height) = explode('*', $value);
1.878 + $image_width = 0;
1.879 + }
1.880 + else
1.881 + {
1.882 + list($image_filename, $image_height, $image_width) = explode('*', $value);
1.883 + }
1.884 + }
1.885 + else
1.886 + {
1.887 + $image_filename = $value;
1.888 + $image_height = $image_width = 0;
1.889 + }
1.890 +
1.891 + if (strpos($image_name, 'img_') === 0 && $image_filename)
1.892 + {
1.893 + $image_name = substr($image_name, 4);
1.894 + if (in_array($image_name, $valid_localized))
1.895 + {
1.896 + $sql_ary[] = array(
1.897 + 'image_name' => (string) $image_name,
1.898 + 'image_filename' => (string) $image_filename,
1.899 + 'image_height' => (int) $image_height,
1.900 + 'image_width' => (int) $image_width,
1.901 + 'imageset_id' => (int) $imageset_row['imageset_id'],
1.902 + 'image_lang' => (string) $lang_pack['iso'],
1.903 + );
1.904 + }
1.905 + }
1.906 + }
1.907 + }
1.908 + }
1.909 + $db->sql_freeresult($result);
1.910 +
1.911 + if (sizeof($sql_ary))
1.912 + {
1.913 + $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
1.914 + $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
1.915 + }
1.916 +
1.917 + // Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier.
1.918 + $sql = 'SELECT lang_id
1.919 + FROM ' . LANG_TABLE . "
1.920 + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
1.921 + $result = $db->sql_query($sql);
1.922 + $default_lang_id = (int) $db->sql_fetchfield('lang_id');
1.923 + $db->sql_freeresult($result);
1.924 +
1.925 + // We want to notify the admin that custom profile fields need to be updated for the new language.
1.926 + $notify_cpf_update = false;
1.927 +
1.928 + // From the mysql documentation:
1.929 + // 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.
1.930 + // Due to this we stay on the safe side if we do the insertion "the manual way"
1.931 +
1.932 + $sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value
1.933 + FROM ' . PROFILE_LANG_TABLE . '
1.934 + WHERE lang_id = ' . $default_lang_id;
1.935 + $result = $db->sql_query($sql);
1.936 +
1.937 + while ($row = $db->sql_fetchrow($result))
1.938 + {
1.939 + $row['lang_id'] = $lang_id;
1.940 + $db->sql_query('INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
1.941 + $notify_cpf_update = true;
1.942 + }
1.943 + $db->sql_freeresult($result);
1.944 +
1.945 + $sql = 'SELECT field_id, option_id, field_type, lang_value
1.946 + FROM ' . PROFILE_FIELDS_LANG_TABLE . '
1.947 + WHERE lang_id = ' . $default_lang_id;
1.948 + $result = $db->sql_query($sql);
1.949 +
1.950 + while ($row = $db->sql_fetchrow($result))
1.951 + {
1.952 + $row['lang_id'] = $lang_id;
1.953 + $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
1.954 + $notify_cpf_update = true;
1.955 + }
1.956 + $db->sql_freeresult($result);
1.957 +
1.958 + add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']);
1.959 +
1.960 + $message = sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']);
1.961 + $message .= ($notify_cpf_update) ? '<br /><br />' . $user->lang['LANGUAGE_PACK_CPF_UPDATE'] : '';
1.962 + trigger_error($message . adm_back_link($this->u_action));
1.963 +
1.964 + break;
1.965 +
1.966 + case 'download':
1.967 +
1.968 + if (!$lang_id)
1.969 + {
1.970 + trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.971 + }
1.972 +
1.973 + $sql = 'SELECT *
1.974 + FROM ' . LANG_TABLE . '
1.975 + WHERE lang_id = ' . $lang_id;
1.976 + $result = $db->sql_query($sql);
1.977 + $row = $db->sql_fetchrow($result);
1.978 + $db->sql_freeresult($result);
1.979 +
1.980 + $use_method = request_var('use_method', '');
1.981 + $methods = array('.tar');
1.982 +
1.983 + $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
1.984 + foreach ($available_methods as $type => $module)
1.985 + {
1.986 + if (!@extension_loaded($module))
1.987 + {
1.988 + continue;
1.989 + }
1.990 +
1.991 + $methods[] = $type;
1.992 + }
1.993 +
1.994 + // Let the user decide in which format he wants to have the pack
1.995 + if (!$use_method)
1.996 + {
1.997 + $this->page_title = 'SELECT_DOWNLOAD_FORMAT';
1.998 +
1.999 + $radio_buttons = '';
1.1000 + foreach ($methods as $method)
1.1001 + {
1.1002 + $radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>';
1.1003 + }
1.1004 +
1.1005 + $template->assign_vars(array(
1.1006 + 'S_SELECT_METHOD' => true,
1.1007 + 'U_BACK' => $this->u_action,
1.1008 + 'U_ACTION' => $this->u_action . "&action=$action&id=$lang_id",
1.1009 + 'RADIO_BUTTONS' => $radio_buttons)
1.1010 + );
1.1011 +
1.1012 + return;
1.1013 + }
1.1014 +
1.1015 + if (!in_array($use_method, $methods))
1.1016 + {
1.1017 + $use_method = '.tar';
1.1018 + }
1.1019 +
1.1020 + include_once($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
1.1021 +
1.1022 + if ($use_method == '.zip')
1.1023 + {
1.1024 + $compress = new compress_zip('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
1.1025 + }
1.1026 + else
1.1027 + {
1.1028 + $compress = new compress_tar('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method, $use_method);
1.1029 + }
1.1030 +
1.1031 + // Get email templates
1.1032 + $email_templates = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
1.1033 + $email_templates = $email_templates['email/'];
1.1034 +
1.1035 + // Get acp files
1.1036 + $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
1.1037 + $acp_files = $acp_files['acp/'];
1.1038 +
1.1039 + // Get mod files
1.1040 + $mod_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
1.1041 + $mod_files = (isset($mod_files['mods/'])) ? $mod_files['mods/'] : array();
1.1042 +
1.1043 + // Add main files
1.1044 + $this->add_to_archive($compress, $this->main_files, $row['lang_iso']);
1.1045 +
1.1046 + // Add search files if they exist...
1.1047 + if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_ignore_words.' . $phpEx))
1.1048 + {
1.1049 + $this->add_to_archive($compress, array("search_ignore_words.$phpEx"), $row['lang_iso']);
1.1050 + }
1.1051 +
1.1052 + if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_synonyms.' . $phpEx))
1.1053 + {
1.1054 + $this->add_to_archive($compress, array("search_synonyms.$phpEx"), $row['lang_iso']);
1.1055 + }
1.1056 +
1.1057 + // Write files in folders
1.1058 + $this->add_to_archive($compress, $email_templates, $row['lang_iso'], 'email');
1.1059 + $this->add_to_archive($compress, $acp_files, $row['lang_iso'], 'acp');
1.1060 + $this->add_to_archive($compress, $mod_files, $row['lang_iso'], 'mods');
1.1061 +
1.1062 + // Write ISO File
1.1063 + $iso_src = htmlspecialchars_decode($row['lang_english_name']) . "\n";
1.1064 + $iso_src .= htmlspecialchars_decode($row['lang_local_name']) . "\n";
1.1065 + $iso_src .= htmlspecialchars_decode($row['lang_author']);
1.1066 + $compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt');
1.1067 +
1.1068 + // index.htm files
1.1069 + $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.htm');
1.1070 + $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.htm');
1.1071 + $compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.htm');
1.1072 +
1.1073 + if (sizeof($mod_files))
1.1074 + {
1.1075 + $compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.htm');
1.1076 + }
1.1077 +
1.1078 + $compress->close();
1.1079 +
1.1080 + $compress->download('lang_' . $row['lang_iso']);
1.1081 + @unlink($phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
1.1082 +
1.1083 + exit;
1.1084 +
1.1085 + break;
1.1086 + }
1.1087 +
1.1088 + $sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count
1.1089 + FROM ' . USERS_TABLE . '
1.1090 + GROUP BY user_lang';
1.1091 + $result = $db->sql_query($sql);
1.1092 +
1.1093 + $lang_count = array();
1.1094 + while ($row = $db->sql_fetchrow($result))
1.1095 + {
1.1096 + $lang_count[$row['user_lang']] = $row['lang_count'];
1.1097 + }
1.1098 + $db->sql_freeresult($result);
1.1099 +
1.1100 + $sql = 'SELECT *
1.1101 + FROM ' . LANG_TABLE . '
1.1102 + ORDER BY lang_english_name';
1.1103 + $result = $db->sql_query($sql);
1.1104 +
1.1105 + $installed = array();
1.1106 +
1.1107 + while ($row = $db->sql_fetchrow($result))
1.1108 + {
1.1109 + $installed[] = $row['lang_iso'];
1.1110 + $tagstyle = ($row['lang_iso'] == $config['default_lang']) ? '*' : '';
1.1111 +
1.1112 + $template->assign_block_vars('lang', array(
1.1113 + 'U_DETAILS' => $this->u_action . "&action=details&id={$row['lang_id']}",
1.1114 + 'U_DOWNLOAD' => $this->u_action . "&action=download&id={$row['lang_id']}",
1.1115 + 'U_DELETE' => $this->u_action . "&action=delete&id={$row['lang_id']}",
1.1116 +
1.1117 + 'ENGLISH_NAME' => $row['lang_english_name'],
1.1118 + 'TAG' => $tagstyle,
1.1119 + 'LOCAL_NAME' => $row['lang_local_name'],
1.1120 + 'ISO' => $row['lang_iso'],
1.1121 + 'USED_BY' => (isset($lang_count[$row['lang_iso']])) ? $lang_count[$row['lang_iso']] : 0,
1.1122 + ));
1.1123 + }
1.1124 + $db->sql_freeresult($result);
1.1125 +
1.1126 + $new_ary = $iso = array();
1.1127 + $dp = @opendir("{$phpbb_root_path}language");
1.1128 +
1.1129 + if ($dp)
1.1130 + {
1.1131 + while (($file = readdir($dp)) !== false)
1.1132 + {
1.1133 + if ($file[0] == '.' || !is_dir($phpbb_root_path . 'language/' . $file))
1.1134 + {
1.1135 + continue;
1.1136 + }
1.1137 +
1.1138 + if (file_exists("{$phpbb_root_path}language/$file/iso.txt"))
1.1139 + {
1.1140 + if (!in_array($file, $installed))
1.1141 + {
1.1142 + if ($iso = file("{$phpbb_root_path}language/$file/iso.txt"))
1.1143 + {
1.1144 + if (sizeof($iso) == 3)
1.1145 + {
1.1146 + $new_ary[$file] = array(
1.1147 + 'iso' => $file,
1.1148 + 'name' => trim($iso[0]),
1.1149 + 'local_name'=> trim($iso[1]),
1.1150 + 'author' => trim($iso[2])
1.1151 + );
1.1152 + }
1.1153 + }
1.1154 + }
1.1155 + }
1.1156 + }
1.1157 + closedir($dp);
1.1158 + }
1.1159 +
1.1160 + unset($installed);
1.1161 +
1.1162 + if (sizeof($new_ary))
1.1163 + {
1.1164 + foreach ($new_ary as $iso => $lang_ary)
1.1165 + {
1.1166 + $template->assign_block_vars('notinst', array(
1.1167 + 'ISO' => htmlspecialchars($lang_ary['iso']),
1.1168 + 'LOCAL_NAME' => htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'),
1.1169 + 'NAME' => htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'),
1.1170 + 'U_INSTALL' => $this->u_action . '&action=install&iso=' . urlencode($lang_ary['iso']))
1.1171 + );
1.1172 + }
1.1173 + }
1.1174 +
1.1175 + unset($new_ary);
1.1176 + }
1.1177 +
1.1178 +
1.1179 + /**
1.1180 + * Set default language variables/header
1.1181 + */
1.1182 + function default_variables()
1.1183 + {
1.1184 + global $phpEx;
1.1185 +
1.1186 + $this->language_file_header = '<?php
1.1187 +/**
1.1188 +*
1.1189 +* {FILENAME} [{LANG_NAME}]
1.1190 +*
1.1191 +* @package language
1.1192 +* @version $' . 'Id: ' . '$
1.1193 +* @copyright (c) ' . date('Y') . ' phpBB Group
1.1194 +* @author {CHANGED} - {AUTHOR}
1.1195 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.1196 +*
1.1197 +*/
1.1198 +
1.1199 +/**
1.1200 +* DO NOT CHANGE
1.1201 +*/
1.1202 +if (!defined(\'IN_PHPBB\'))
1.1203 +{
1.1204 + exit;
1.1205 +}
1.1206 +
1.1207 +if (empty($lang) || !is_array($lang))
1.1208 +{
1.1209 + $lang = array();
1.1210 +}
1.1211 +
1.1212 +// DEVELOPERS PLEASE NOTE
1.1213 +//
1.1214 +// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
1.1215 +//
1.1216 +// Placeholders can now contain order information, e.g. instead of
1.1217 +// \'Page %s of %s\' you can (and should) write \'Page %1$s of %2$s\', this allows
1.1218 +// translators to re-order the output of data while ensuring it remains correct
1.1219 +//
1.1220 +// You do not need this where single placeholders are used, e.g. \'Message %d\' is fine
1.1221 +// equally where a string contains only two placeholders which are used to wrap text
1.1222 +// in a url you again do not need to specify an order e.g., \'Click %sHERE%s\' is fine
1.1223 +';
1.1224 +
1.1225 + $this->lang_header = '
1.1226 +$lang = array_merge($lang, array(
1.1227 +';
1.1228 +
1.1229 + // Language files in language root directory
1.1230 + $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");
1.1231 + }
1.1232 +
1.1233 + /**
1.1234 + * Get filename/location of language file
1.1235 + */
1.1236 + function get_filename($lang_iso, $directory, $filename, $check_store = false, $only_return_filename = false)
1.1237 + {
1.1238 + global $phpbb_root_path, $safe_mode;
1.1239 +
1.1240 + $check_filename = "language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
1.1241 +
1.1242 + if ($check_store)
1.1243 + {
1.1244 + $check_store_filename = ($safe_mode) ? "store/langfile_{$lang_iso}" . (($directory) ? '_' . $directory : '') . "_{$filename}" : "store/language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
1.1245 +
1.1246 + if (!$only_return_filename && file_exists($phpbb_root_path . $check_store_filename))
1.1247 + {
1.1248 + return $check_store_filename;
1.1249 + }
1.1250 + else if ($only_return_filename)
1.1251 + {
1.1252 + return $check_store_filename;
1.1253 + }
1.1254 + }
1.1255 +
1.1256 + return $check_filename;
1.1257 + }
1.1258 +
1.1259 + /**
1.1260 + * Add files to archive
1.1261 + */
1.1262 + function add_to_archive(&$compress, $filelist, $lang_iso, $directory = '')
1.1263 + {
1.1264 + global $phpbb_root_path;
1.1265 +
1.1266 + foreach ($filelist as $file)
1.1267 + {
1.1268 + // Get source filename
1.1269 + $source = $this->get_filename($lang_iso, $directory, $file, true);
1.1270 + $destination = 'language/' . $lang_iso . '/' . (($directory) ? $directory . '/' : '') . $file;
1.1271 +
1.1272 + // Add file to archive
1.1273 + $compress->add_custom_file($phpbb_root_path . $source, $destination);
1.1274 + }
1.1275 + }
1.1276 +
1.1277 + /**
1.1278 + * Little helper to add some hardcoded template bits
1.1279 + */
1.1280 + function add_input_field()
1.1281 + {
1.1282 + $keys = func_get_args();
1.1283 +
1.1284 + $non_static = array_shift($keys);
1.1285 + $value = utf8_normalize_nfc(array_shift($keys));
1.1286 +
1.1287 + if (!$non_static)
1.1288 + {
1.1289 + return '<strong>' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '</strong>';
1.1290 + }
1.1291 +
1.1292 + // If more then 270 characters, then we present a textarea, else an input field
1.1293 + $textarea = (utf8_strlen($value) > 270) ? true : false;
1.1294 + $tpl = '';
1.1295 +
1.1296 + $tpl .= ($textarea) ? '<textarea name="' : '<input type="text" name="';
1.1297 + $tpl .= 'entry[' . implode('][', array_map('utf8_htmlspecialchars', $keys)) . ']"';
1.1298 +
1.1299 + $tpl .= ($textarea) ? ' cols="80" rows="5" class="langvalue">' : ' class="langvalue" value="';
1.1300 + $tpl .= htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
1.1301 + $tpl .= ($textarea) ? '</textarea>' : '" />';
1.1302 +
1.1303 + return $tpl;
1.1304 + }
1.1305 +
1.1306 + /**
1.1307 + * Print language entries
1.1308 + */
1.1309 + function print_language_entries(&$lang_ary, $key_prefix = '', $input_field = true)
1.1310 + {
1.1311 + $tpl = '';
1.1312 +
1.1313 + foreach ($lang_ary as $key => $value)
1.1314 + {
1.1315 + if (is_array($value))
1.1316 + {
1.1317 + // Write key
1.1318 + $tpl .= '
1.1319 + <tr>
1.1320 + <td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1.1321 + </tr>';
1.1322 +
1.1323 + foreach ($value as $_key => $_value)
1.1324 + {
1.1325 + if (is_array($_value))
1.1326 + {
1.1327 + // Write key
1.1328 + $tpl .= '
1.1329 + <tr>
1.1330 + <td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . ' <strong>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1.1331 + </tr>';
1.1332 +
1.1333 + foreach ($_value as $__key => $__value)
1.1334 + {
1.1335 + // Write key
1.1336 + $tpl .= '
1.1337 + <tr>
1.1338 + <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($__key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1.1339 + <td class="row2">';
1.1340 +
1.1341 + $tpl .= $this->add_input_field($input_field, $__value, $key, $_key, $__key);
1.1342 +
1.1343 + $tpl .= '</td>
1.1344 + </tr>';
1.1345 + }
1.1346 + }
1.1347 + else
1.1348 + {
1.1349 + // Write key
1.1350 + $tpl .= '
1.1351 + <tr>
1.1352 + <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1.1353 + <td class="row2">';
1.1354 +
1.1355 + $tpl .= $this->add_input_field($input_field, $_value, $key, $_key);
1.1356 +
1.1357 + $tpl .= '</td>
1.1358 + </tr>';
1.1359 + }
1.1360 + }
1.1361 +
1.1362 + $tpl .= '
1.1363 + <tr>
1.1364 + <td class="spacer" colspan="2"> </td>
1.1365 + </tr>';
1.1366 + }
1.1367 + else
1.1368 + {
1.1369 + // Write key
1.1370 + $tpl .= '
1.1371 + <tr>
1.1372 + <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1.1373 + <td class="row2">';
1.1374 +
1.1375 + $tpl .= $this->add_input_field($input_field, $value, $key);
1.1376 +
1.1377 + $tpl .= '</td>
1.1378 + </tr>';
1.1379 + }
1.1380 + }
1.1381 +
1.1382 + return $tpl;
1.1383 + }
1.1384 +
1.1385 + /**
1.1386 + * Compare two language files
1.1387 + */
1.1388 + function compare_language_files($source_lang, $dest_lang, $directory, $file)
1.1389 + {
1.1390 + global $phpbb_root_path, $phpEx;
1.1391 +
1.1392 + $return_ary = array();
1.1393 +
1.1394 + $lang = array();
1.1395 + include("{$phpbb_root_path}language/{$source_lang}/" . (($directory) ? $directory . '/' : '') . $file);
1.1396 + $lang_entry_src = $lang;
1.1397 +
1.1398 + $lang = array();
1.1399 +
1.1400 + if (!file_exists($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true)))
1.1401 + {
1.1402 + return array();
1.1403 + }
1.1404 +
1.1405 + include($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true));
1.1406 +
1.1407 + $lang_entry_dst = $lang;
1.1408 +
1.1409 + unset($lang);
1.1410 +
1.1411 + $diff_array_keys = array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst));
1.1412 + unset($lang_entry_dst);
1.1413 +
1.1414 + foreach ($diff_array_keys as $key)
1.1415 + {
1.1416 + $return_ary[$key] = $lang_entry_src[$key];
1.1417 + }
1.1418 +
1.1419 + unset($lang_entry_src);
1.1420 +
1.1421 + return $return_ary;
1.1422 + }
1.1423 +
1.1424 + /**
1.1425 + * Return language string value for storage
1.1426 + */
1.1427 + function prepare_lang_entry($text, $store = true)
1.1428 + {
1.1429 + $text = (STRIP) ? stripslashes($text) : $text;
1.1430 +
1.1431 + // Adjust for storage...
1.1432 + if ($store)
1.1433 + {
1.1434 + $text = str_replace("'", "\\'", str_replace('\\', '\\\\', $text));
1.1435 + }
1.1436 +
1.1437 + return $text;
1.1438 + }
1.1439 +
1.1440 + /**
1.1441 + * Format language array for storage
1.1442 + */
1.1443 + function format_lang_array($key, $value, $tabs = "\t")
1.1444 + {
1.1445 + $entry = '';
1.1446 +
1.1447 + if (!is_array($value))
1.1448 + {
1.1449 + $entry .= "{$tabs}'" . $this->prepare_lang_entry($key) . "'\t=> '" . $this->prepare_lang_entry($value) . "',\n";
1.1450 + }
1.1451 + else
1.1452 + {
1.1453 + $_tabs = $tabs . "\t";
1.1454 + $entry .= "\n{$tabs}'" . $this->prepare_lang_entry($key) . "'\t=> array(\n";
1.1455 +
1.1456 + foreach ($value as $_key => $_value)
1.1457 + {
1.1458 + $entry .= $this->format_lang_array($_key, $_value, $_tabs);
1.1459 + }
1.1460 +
1.1461 + $entry .= "{$tabs}),\n\n";
1.1462 + }
1.1463 +
1.1464 + return $entry;
1.1465 + }
1.1466 +}
1.1467 +
1.1468 +?>
1.1469 \ No newline at end of file