|
@@ -0,0 +1,1363 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+ * This file handles the administration of languages tasks.
|
|
|
+ *
|
|
|
+ * Simple Machines Forum (SMF)
|
|
|
+ *
|
|
|
+ * @package SMF
|
|
|
+ * @author Simple Machines
|
|
|
+ *
|
|
|
+ * @copyright 2011 Simple Machines
|
|
|
+ * @license http:
|
|
|
+ *
|
|
|
+ * @version 2.0
|
|
|
+ */
|
|
|
+
|
|
|
+if (!defined('SMF'))
|
|
|
+ die('Hacking attempt...');
|
|
|
+
|
|
|
+
|
|
|
+ * This is the main function for the languages area.
|
|
|
+ * It dispatches the requests.
|
|
|
+ * Loads the ManageLanguages template. (sub-actions will use it)
|
|
|
+ * @todo lazy loading.
|
|
|
+ *
|
|
|
+ * @uses ManageSettings language file
|
|
|
+ */
|
|
|
+function ManageLanguages()
|
|
|
+{
|
|
|
+ global $context, $txt, $scripturl, $modSettings;
|
|
|
+
|
|
|
+ loadTemplate('ManageLanguages');
|
|
|
+ loadLanguage('ManageSettings');
|
|
|
+
|
|
|
+ $context['page_title'] = $txt['edit_languages'];
|
|
|
+ $context['sub_template'] = 'show_settings';
|
|
|
+
|
|
|
+ $subActions = array(
|
|
|
+ 'edit' => 'ModifyLanguages',
|
|
|
+ 'add' => 'AddLanguage',
|
|
|
+ 'settings' => 'ModifyLanguageSettings',
|
|
|
+ 'downloadlang' => 'DownloadLanguage',
|
|
|
+ 'editlang' => 'ModifyLanguage',
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'edit';
|
|
|
+ $context['sub_action'] = $_REQUEST['sa'];
|
|
|
+
|
|
|
+
|
|
|
+ $context[$context['admin_menu_name']]['tab_data'] = array(
|
|
|
+ 'title' => $txt['language_configuration'],
|
|
|
+ 'description' => $txt['language_description'],
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ $subActions[$_REQUEST['sa']]();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * Interface for adding a new language
|
|
|
+ *
|
|
|
+ * @uses ManageLanguages template, add_language sub-template.
|
|
|
+ */
|
|
|
+function AddLanguage()
|
|
|
+{
|
|
|
+ global $context, $sourcedir, $forum_version, $boarddir, $txt, $smcFunc, $scripturl;
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($_POST['smf_add_sub']))
|
|
|
+ {
|
|
|
+
|
|
|
+ require_once($sourcedir . '/Subs-Package.php');
|
|
|
+
|
|
|
+ $context['smf_search_term'] = htmlspecialchars(trim($_POST['smf_add']));
|
|
|
+
|
|
|
+
|
|
|
+ $url = 'http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => '')));
|
|
|
+
|
|
|
+
|
|
|
+ loadClassFile('Class-Package.php');
|
|
|
+ $language_list = new xmlArray(fetch_web_data($url), true);
|
|
|
+
|
|
|
+
|
|
|
+ if (!$language_list->exists('languages'))
|
|
|
+ $context['smf_error'] = 'no_response';
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $language_list = $language_list->path('languages[0]');
|
|
|
+ $lang_files = $language_list->set('language');
|
|
|
+ $context['smf_languages'] = array();
|
|
|
+ foreach ($lang_files as $file)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ $context['smf_languages'][] = array(
|
|
|
+ 'id' => $file->fetch('id'),
|
|
|
+ 'name' => $smcFunc['ucwords']($file->fetch('name')),
|
|
|
+ 'version' => $file->fetch('version'),
|
|
|
+ 'utf8' => $file->fetch('utf8'),
|
|
|
+ 'description' => $file->fetch('description'),
|
|
|
+ 'link' => $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'],
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (empty($context['smf_languages']))
|
|
|
+ $context['smf_error'] = 'no_files';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $context['sub_template'] = 'add_language';
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * Download a language file from the Simple Machines website.
|
|
|
+ * Requires a valid download ID ("did") in the URL.
|
|
|
+ * Also handles installing language files.
|
|
|
+ * Attempts to chmod things as needed.
|
|
|
+ * Uses a standard list to display information about all the files and where they'll be put.
|
|
|
+ *
|
|
|
+ * @uses ManageLanguages template, download_language sub-template.
|
|
|
+ * @uses Admin template, show_list sub-template.
|
|
|
+ */
|
|
|
+function DownloadLanguage()
|
|
|
+{
|
|
|
+ global $context, $sourcedir, $forum_version, $boarddir, $txt, $smcFunc, $scripturl, $modSettings;
|
|
|
+
|
|
|
+ loadLanguage('ManageSettings');
|
|
|
+ require_once($sourcedir . '/Subs-Package.php');
|
|
|
+
|
|
|
+
|
|
|
+ if (!isset($_GET['did']))
|
|
|
+ fatal_lang_error('no_access', false);
|
|
|
+
|
|
|
+
|
|
|
+ $context['download_id'] = $_GET['did'];
|
|
|
+ $context['sub_template'] = 'download_language';
|
|
|
+ $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'add';
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($_POST['do_install']) && !empty($_POST['copy_file']))
|
|
|
+ {
|
|
|
+ checkSession('get');
|
|
|
+
|
|
|
+ $chmod_files = array();
|
|
|
+ $install_files = array();
|
|
|
+
|
|
|
+ foreach ($_POST['copy_file'] as $file)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (strpos($file, '..') !== false || (substr($file, 0, 6) != 'Themes' && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file)))
|
|
|
+ fatal_error($txt['languages_download_illegal_paths']);
|
|
|
+
|
|
|
+ $chmod_files[] = $boarddir . '/' . $file;
|
|
|
+ $install_files[] = $file;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $file_status = create_chmod_control($chmod_files);
|
|
|
+ $files_left = $file_status['files']['notwritable'];
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($files_left))
|
|
|
+ $context['error_message'] = $txt['languages_download_not_chmod'];
|
|
|
+
|
|
|
+ elseif (!empty($install_files))
|
|
|
+ {
|
|
|
+ $archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), $boarddir, false, true, $install_files);
|
|
|
+
|
|
|
+ package_flush_cache();
|
|
|
+ $context['install_complete'] = sprintf($txt['languages_download_complete_desc'], $scripturl . '?action=admin;area=languages');
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!isset($archive_content))
|
|
|
+ $archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
|
|
|
+
|
|
|
+ if (empty($archive_content))
|
|
|
+ fatal_error($txt['add_language_error_no_response']);
|
|
|
+
|
|
|
+
|
|
|
+ $context['files'] = array(
|
|
|
+ 'lang' => array(),
|
|
|
+ 'other' => array(),
|
|
|
+ );
|
|
|
+ $context['make_writable'] = array();
|
|
|
+ foreach ($archive_content as $file)
|
|
|
+ {
|
|
|
+ $dirname = dirname($file['filename']);
|
|
|
+ $filename = basename($file['filename']);
|
|
|
+ $extension = substr($filename, strrpos($filename, '.') + 1);
|
|
|
+
|
|
|
+
|
|
|
+ if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt')))
|
|
|
+ continue;
|
|
|
+
|
|
|
+
|
|
|
+ $context_data = array(
|
|
|
+ 'name' => $filename,
|
|
|
+ 'destination' => $boarddir . '/' . $file['filename'],
|
|
|
+ 'generaldest' => $file['filename'],
|
|
|
+ 'size' => $file['size'],
|
|
|
+
|
|
|
+ 'writable' => false,
|
|
|
+
|
|
|
+ 'default_copy' => true,
|
|
|
+
|
|
|
+ 'exists' => false,
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ if (file_exists($boarddir . '/' . $file['filename']))
|
|
|
+ {
|
|
|
+ if (is_writable($boarddir . '/' . $file['filename']))
|
|
|
+ $context_data['writable'] = true;
|
|
|
+
|
|
|
+
|
|
|
+ if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename']))
|
|
|
+ {
|
|
|
+ $context_data['exists'] = 'same';
|
|
|
+ $context_data['default_copy'] = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($file['md5'] == md5(preg_replace("~[\r]?\n~", "\r\n", file_get_contents($boarddir . '/' . $file['filename']))))
|
|
|
+ {
|
|
|
+ $context_data['exists'] = 'same';
|
|
|
+ $context_data['default_copy'] = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ $context_data['exists'] = 'different';
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ if (is_writable($boarddir . '/' . $dirname))
|
|
|
+ $context_data['writable'] = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($extension == 'php' && preg_match('~\w+\.\w+(?:-utf8)?\.php~', $filename))
|
|
|
+ {
|
|
|
+ $context_data += array(
|
|
|
+ 'version' => '??',
|
|
|
+ 'cur_version' => false,
|
|
|
+ 'version_compare' => 'newer',
|
|
|
+ );
|
|
|
+
|
|
|
+ list ($name, $language) = explode('.', $filename);
|
|
|
+
|
|
|
+
|
|
|
+ if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1)
|
|
|
+ $context_data['version'] = $match[1];
|
|
|
+
|
|
|
+
|
|
|
+ if (file_exists($boarddir . '/' . $file['filename']))
|
|
|
+ {
|
|
|
+
|
|
|
+ $fp = fopen($boarddir . '/' . $file['filename'], 'rb');
|
|
|
+ $header = fread($fp, 768);
|
|
|
+ fclose($fp);
|
|
|
+
|
|
|
+
|
|
|
+ if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1)
|
|
|
+ {
|
|
|
+ $context_data['cur_version'] = $match[1];
|
|
|
+
|
|
|
+
|
|
|
+ if ($context_data['cur_version'] == $context_data['version'])
|
|
|
+ $context_data['version_compare'] = 'same';
|
|
|
+ elseif ($context_data['cur_version'] > $context_data['version'])
|
|
|
+ $context_data['version_compare'] = 'older';
|
|
|
+
|
|
|
+
|
|
|
+ if ($context_data['version_compare'] != 'newer')
|
|
|
+ $context_data['default_copy'] = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $context['files']['lang'][] = $context_data;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ if (substr($dirname, 0, 6) == 'Themes' && preg_match('~Themes[\\/]([^\\/]+)[\\/]~', $dirname, $match))
|
|
|
+ $theme_name = $match[1];
|
|
|
+ else
|
|
|
+ $theme_name = 'misc';
|
|
|
+
|
|
|
+
|
|
|
+ $context['files']['images'][$theme_name][] = $context_data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!$context_data['writable'])
|
|
|
+ $context['make_writable'][] = $context_data['destination'];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $theme_indexes = array();
|
|
|
+ foreach ($context['files']['images'] as $k => $dummy)
|
|
|
+ $indexes[] = $k;
|
|
|
+
|
|
|
+ $context['theme_names'] = array();
|
|
|
+ if (!empty($indexes))
|
|
|
+ {
|
|
|
+ $value_data = array(
|
|
|
+ 'query' => array(),
|
|
|
+ 'params' => array(),
|
|
|
+ );
|
|
|
+
|
|
|
+ foreach ($indexes as $k => $index)
|
|
|
+ {
|
|
|
+ $value_data['query'][] = 'value LIKE {string:value_' . $k . '}';
|
|
|
+ $value_data['params']['value_' . $k] = '%' . $index;
|
|
|
+ }
|
|
|
+
|
|
|
+ $request = $smcFunc['db_query']('', '
|
|
|
+ SELECT id_theme, value
|
|
|
+ FROM {db_prefix}themes
|
|
|
+ WHERE id_member = {int:no_member}
|
|
|
+ AND variable = {string:theme_dir}
|
|
|
+ AND (' . implode(' OR ', $value_data['query']) . ')',
|
|
|
+ array_merge($value_data['params'], array(
|
|
|
+ 'no_member' => 0,
|
|
|
+ 'theme_dir' => 'theme_dir',
|
|
|
+ 'index_compare_explode' => 'value LIKE \'%' . implode('\' OR value LIKE \'%', $indexes) . '\'',
|
|
|
+ ))
|
|
|
+ );
|
|
|
+ $themes = array();
|
|
|
+ while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
|
+ {
|
|
|
+
|
|
|
+ foreach ($indexes as $index)
|
|
|
+ if (strpos($row['value'], $index) !== false)
|
|
|
+ $themes[$row['id_theme']] = $index;
|
|
|
+ }
|
|
|
+ $smcFunc['db_free_result']($request);
|
|
|
+
|
|
|
+ if (!empty($themes))
|
|
|
+ {
|
|
|
+
|
|
|
+ $request = $smcFunc['db_query']('', '
|
|
|
+ SELECT id_theme, value
|
|
|
+ FROM {db_prefix}themes
|
|
|
+ WHERE id_member = {int:no_member}
|
|
|
+ AND variable = {string:name}
|
|
|
+ AND id_theme IN ({array_int:theme_list})',
|
|
|
+ array(
|
|
|
+ 'theme_list' => array_keys($themes),
|
|
|
+ 'no_member' => 0,
|
|
|
+ 'name' => 'name',
|
|
|
+ )
|
|
|
+ );
|
|
|
+ while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
|
+ {
|
|
|
+
|
|
|
+ $context['theme_names'][$themes[$row['id_theme']]] = $row['value'];
|
|
|
+ }
|
|
|
+ $smcFunc['db_free_result']($request);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($context['make_writable']))
|
|
|
+ {
|
|
|
+
|
|
|
+ $file_status = create_chmod_control($context['make_writable']);
|
|
|
+ $context['still_not_writable'] = $file_status['files']['notwritable'];
|
|
|
+
|
|
|
+
|
|
|
+ foreach ($context['files'] as $type => $data)
|
|
|
+ {
|
|
|
+ if ($type == 'lang')
|
|
|
+ {
|
|
|
+ foreach ($data as $k => $file)
|
|
|
+ if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
|
|
|
+ $context['files'][$type][$k]['writable'] = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach ($data as $theme => $files)
|
|
|
+ foreach ($files as $k => $file)
|
|
|
+ if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
|
|
|
+ $context['files'][$type][$theme][$k]['writable'] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($context['still_not_writable']))
|
|
|
+ loadLanguage('Packages');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $listOptions = array(
|
|
|
+ 'id' => 'lang_main_files_list',
|
|
|
+ 'title' => $txt['languages_download_main_files'],
|
|
|
+ 'get_items' => array(
|
|
|
+ 'function' => create_function('', '
|
|
|
+ global $context;
|
|
|
+ return $context[\'files\'][\'lang\'];
|
|
|
+ '),
|
|
|
+ ),
|
|
|
+ 'columns' => array(
|
|
|
+ 'name' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_download_filename'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'function' => create_function('$rowData', '
|
|
|
+ global $context, $txt;
|
|
|
+
|
|
|
+ return \'<strong>\' . $rowData[\'name\'] . \'</strong><br /><span class="smalltext">\' . $txt[\'languages_download_dest\'] . \': \' . $rowData[\'destination\'] . \'</span>\' . ($rowData[\'version_compare\'] == \'older\' ? \'<br />\' . $txt[\'languages_download_older\'] : \'\');
|
|
|
+ '),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'writable' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_download_writable'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'function' => create_function('$rowData', '
|
|
|
+ global $txt;
|
|
|
+
|
|
|
+ return \'<span style="color: \' . ($rowData[\'writable\'] ? \'green\' : \'red\') . \';">\' . ($rowData[\'writable\'] ? $txt[\'yes\'] : $txt[\'no\']) . \'</span>\';
|
|
|
+ '),
|
|
|
+ 'style' => 'text-align: center',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'version' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_download_version'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'function' => create_function('$rowData', '
|
|
|
+ global $txt;
|
|
|
+
|
|
|
+ return \'<span style="color: \' . ($rowData[\'version_compare\'] == \'older\' ? \'red\' : ($rowData[\'version_compare\'] == \'same\' ? \'orange\' : \'green\')) . \';">\' . $rowData[\'version\'] . \'</span>\';
|
|
|
+ '),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'exists' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_download_exists'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'function' => create_function('$rowData', '
|
|
|
+ global $txt;
|
|
|
+
|
|
|
+ return $rowData[\'exists\'] ? ($rowData[\'exists\'] == \'same\' ? $txt[\'languages_download_exists_same\'] : $txt[\'languages_download_exists_different\']) : $txt[\'no\'];
|
|
|
+ '),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'copy' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_download_copy'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'function' => create_function('$rowData', '
|
|
|
+ return \'<input type="checkbox" name="copy_file[]" value="\' . $rowData[\'generaldest\'] . \'" \' . ($rowData[\'default_copy\'] ? \'checked="checked"\' : \'\') . \' class="input_check" />\';
|
|
|
+ '),
|
|
|
+ 'style' => 'text-align: center; width: 4%;',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($modSettings['cache_enable']))
|
|
|
+ {
|
|
|
+ cache_put_data('known_languages', null, !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
|
|
|
+ cache_put_data('known_languages_all', null, !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
|
|
|
+ }
|
|
|
+
|
|
|
+ require_once($sourcedir . '/Subs-List.php');
|
|
|
+ createList($listOptions);
|
|
|
+
|
|
|
+ $context['default_list'] = 'lang_main_files_list';
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * This lists all the current languages and allows editing of them.
|
|
|
+ */
|
|
|
+function ModifyLanguages()
|
|
|
+{
|
|
|
+ global $txt, $context, $scripturl;
|
|
|
+ global $user_info, $smcFunc, $sourcedir, $language, $boarddir, $forum_version;
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($_POST['set_default']) && !empty($_POST['def_language']))
|
|
|
+ {
|
|
|
+ checkSession();
|
|
|
+
|
|
|
+ if ($_POST['def_language'] != $language)
|
|
|
+ {
|
|
|
+ require_once($sourcedir . '/Subs-Admin.php');
|
|
|
+ updateSettingsFile(array('language' => '\'' . $_POST['def_language'] . '\''));
|
|
|
+ $language = $_POST['def_language'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $listOptions = array(
|
|
|
+ 'id' => 'language_list',
|
|
|
+ 'items_per_page' => 20,
|
|
|
+ 'base_href' => $scripturl . '?action=admin;area=languages',
|
|
|
+ 'title' => $txt['edit_languages'],
|
|
|
+ 'get_items' => array(
|
|
|
+ 'function' => 'list_getLanguages',
|
|
|
+ ),
|
|
|
+ 'get_count' => array(
|
|
|
+ 'function' => 'list_getNumLanguages',
|
|
|
+ ),
|
|
|
+ 'columns' => array(
|
|
|
+ 'default' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_default'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'function' => create_function('$rowData', '
|
|
|
+ return \'<input type="radio" name="def_language" value="\' . $rowData[\'id\'] . \'" \' . ($rowData[\'default\'] ? \'checked="checked"\' : \'\') . \' onclick="highlightSelected(\\\'list_language_list_\' . $rowData[\'id\'] . \'\\\');" class="input_radio" />\';
|
|
|
+ '),
|
|
|
+ 'style' => 'text-align: center; width: 8%;',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'name' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_lang_name'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'function' => create_function('$rowData', '
|
|
|
+ global $scripturl, $context;
|
|
|
+
|
|
|
+ return sprintf(\'<a href="%1$s?action=admin;area=languages;sa=editlang;lid=%2$s">%3$s</a>\', $scripturl, $rowData[\'id\'], $rowData[\'name\']);
|
|
|
+ '),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'character_set' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_character_set'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'db_htmlsafe' => 'char_set',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'count' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_users'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'db_htmlsafe' => 'count',
|
|
|
+ 'style' => 'text-align: center',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'locale' => array(
|
|
|
+ 'header' => array(
|
|
|
+ 'value' => $txt['languages_locale'],
|
|
|
+ ),
|
|
|
+ 'data' => array(
|
|
|
+ 'db_htmlsafe' => 'locale',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'form' => array(
|
|
|
+ 'href' => $scripturl . '?action=admin;area=languages',
|
|
|
+ ),
|
|
|
+ 'additional_rows' => array(
|
|
|
+ array(
|
|
|
+ 'position' => 'below_table_data',
|
|
|
+ 'value' => '<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" /><input type="submit" name="set_default" value="' . $txt['save'] . '"' . (is_writable($boarddir . '/Settings.php') ? '' : ' disabled="disabled"') . ' class="button_submit" />',
|
|
|
+ 'style' => 'text-align: right;',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+
|
|
|
+ 'javascript' => '
|
|
|
+ var prevClass = "";
|
|
|
+ var prevDiv = "";
|
|
|
+ function highlightSelected(box)
|
|
|
+ {
|
|
|
+ if (prevClass != "")
|
|
|
+ prevDiv.className = prevClass;
|
|
|
+
|
|
|
+ prevDiv = document.getElementById(box);
|
|
|
+ prevClass = prevDiv.className;
|
|
|
+
|
|
|
+ prevDiv.className = "highlight2";
|
|
|
+ }
|
|
|
+ highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language). '");
|
|
|
+ ',
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ if (!is_writable($boarddir . '/Settings.php'))
|
|
|
+ $listOptions['additional_rows'][] = array(
|
|
|
+ 'position' => 'after_title',
|
|
|
+ 'value' => $txt['language_settings_writable'],
|
|
|
+ 'class' => 'smalltext alert',
|
|
|
+ );
|
|
|
+
|
|
|
+ require_once($sourcedir . '/Subs-List.php');
|
|
|
+ createList($listOptions);
|
|
|
+
|
|
|
+ $context['sub_template'] = 'show_list';
|
|
|
+ $context['default_list'] = 'language_list';
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * How many languages?
|
|
|
+ * Callback for the list in ManageLanguageSettings().
|
|
|
+ */
|
|
|
+function list_getNumLanguages()
|
|
|
+{
|
|
|
+ global $settings;
|
|
|
+
|
|
|
+
|
|
|
+ return count(getLanguages(true, false));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * Fetch the actual language information.
|
|
|
+ * Callback for $listOptions['get_items']['function'] in ManageLanguageSettings.
|
|
|
+ * Determines which languages are available by looking for the "index.{language}.php" file.
|
|
|
+ * Also figures out how many users are using a particular language.
|
|
|
+ */
|
|
|
+function list_getLanguages()
|
|
|
+{
|
|
|
+ global $settings, $smcFunc, $language, $context, $txt;
|
|
|
+
|
|
|
+ $languages = array();
|
|
|
+
|
|
|
+ $old_txt = $txt;
|
|
|
+ $backup_actual_theme_dir = $settings['actual_theme_dir'];
|
|
|
+ $backup_base_theme_dir = !empty($settings['base_theme_dir']) ? $settings['base_theme_dir'] : '';
|
|
|
+
|
|
|
+
|
|
|
+ $settings['actual_theme_dir'] = $settings['base_theme_dir'] = $settings['default_theme_dir'];
|
|
|
+ getLanguages(true, false);
|
|
|
+
|
|
|
+
|
|
|
+ $settings['actual_theme_dir'] = $backup_actual_theme_dir;
|
|
|
+ if (!empty($backup_base_theme_dir))
|
|
|
+ $settings['base_theme_dir'] = $backup_base_theme_dir;
|
|
|
+ else
|
|
|
+ unset($settings['base_theme_dir']);
|
|
|
+
|
|
|
+
|
|
|
+ foreach ($context['languages'] as $lang)
|
|
|
+ {
|
|
|
+
|
|
|
+ require($settings['default_theme_dir'] . '/languages/index.' . $lang['filename'] . '.php');
|
|
|
+
|
|
|
+ $languages[$lang['filename']] = array(
|
|
|
+ 'id' => $lang['filename'],
|
|
|
+ 'count' => 0,
|
|
|
+ 'char_set' => $txt['lang_character_set'],
|
|
|
+ 'default' => $language == $lang['filename'] || ($language == '' && $lang['filename'] == 'english'),
|
|
|
+ 'locale' => $txt['lang_locale'],
|
|
|
+ 'name' => $smcFunc['ucwords'](strtr($lang['filename'], array('_' => ' ', '-utf8' => ''))),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $request = $smcFunc['db_query']('', '
|
|
|
+ SELECT lngfile, COUNT(*) AS num_users
|
|
|
+ FROM {db_prefix}members
|
|
|
+ GROUP BY lngfile',
|
|
|
+ array(
|
|
|
+ )
|
|
|
+ );
|
|
|
+ while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
|
+ {
|
|
|
+
|
|
|
+ if (empty($row['lngfile']) || !isset($languages[$row['lngfile']]))
|
|
|
+ $row['lngfile'] = $language;
|
|
|
+
|
|
|
+ if (!isset($languages[$row['lngfile']]) && isset($languages['english']))
|
|
|
+ $languages['english']['count'] += $row['num_users'];
|
|
|
+ elseif (isset($languages[$row['lngfile']]))
|
|
|
+ $languages[$row['lngfile']]['count'] += $row['num_users'];
|
|
|
+ }
|
|
|
+ $smcFunc['db_free_result']($request);
|
|
|
+
|
|
|
+
|
|
|
+ $txt = $old_txt;
|
|
|
+
|
|
|
+
|
|
|
+ return $languages;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * Edit language related settings.
|
|
|
+ *
|
|
|
+ * @param bool $return_config = false
|
|
|
+ */
|
|
|
+function ModifyLanguageSettings($return_config = false)
|
|
|
+{
|
|
|
+ global $scripturl, $context, $txt, $boarddir, $settings, $smcFunc, $sourcedir;
|
|
|
+
|
|
|
+
|
|
|
+ require_once $sourcedir . '/ManageServer.php';
|
|
|
+
|
|
|
+
|
|
|
+ $settings_not_writable = !is_writable($boarddir . '/Settings.php');
|
|
|
+ $settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
|
|
|
+
|
|
|
+
|
|
|
+ For each option:
|
|
|
+ variable name, description, type (constant), size/possible values, helptext.
|
|
|
+ OR an empty string for a horizontal rule.
|
|
|
+ OR a string for a titled section. */
|
|
|
+ $config_vars = array(
|
|
|
+ 'language' => array('language', $txt['default_language'], 'file', 'select', array(), null, 'disabled' => $settings_not_writable),
|
|
|
+ array('userLanguage', $txt['userLanguage'], 'db', 'check', null, 'userLanguage'),
|
|
|
+ );
|
|
|
+
|
|
|
+ if ($return_config)
|
|
|
+ return $config_vars;
|
|
|
+
|
|
|
+
|
|
|
+ getLanguages(false, false);
|
|
|
+ foreach ($context['languages'] as $lang)
|
|
|
+ $config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)')));
|
|
|
+
|
|
|
+
|
|
|
+ if (isset($_REQUEST['save']))
|
|
|
+ {
|
|
|
+ checkSession();
|
|
|
+ saveSettings($config_vars);
|
|
|
+ redirectexit('action=admin;area=languages;sa=settings');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $context['post_url'] = $scripturl . '?action=admin;area=languages;sa=settings;save';
|
|
|
+ $context['settings_title'] = $txt['language_settings'];
|
|
|
+ $context['save_disabled'] = $settings_not_writable;
|
|
|
+
|
|
|
+ if ($settings_not_writable)
|
|
|
+ $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br />';
|
|
|
+ elseif ($settings_backup_fail)
|
|
|
+ $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br />';
|
|
|
+
|
|
|
+
|
|
|
+ prepareServerSettingsContext($config_vars);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * Edit a particular set of language entries.
|
|
|
+ *
|
|
|
+ */
|
|
|
+function ModifyLanguage()
|
|
|
+{
|
|
|
+ global $settings, $context, $smcFunc, $txt, $modSettings, $boarddir, $sourcedir, $language;
|
|
|
+
|
|
|
+ loadLanguage('ManageSettings');
|
|
|
+
|
|
|
+
|
|
|
+ $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'edit';
|
|
|
+ $context['page_title'] = $txt['edit_languages'];
|
|
|
+ $context['sub_template'] = 'modify_language_entries';
|
|
|
+
|
|
|
+ $context['lang_id'] = $_GET['lid'];
|
|
|
+ list($theme_id, $file_id) = empty($_REQUEST['tfid']) || strpos($_REQUEST['tfid'], '+') === false ? array(1, '') : explode('+', $_REQUEST['tfid']);
|
|
|
+
|
|
|
+
|
|
|
+ preg_match('~([A-Za-z0-9_-]+)~', $context['lang_id'], $matches);
|
|
|
+ $context['lang_id'] = $matches[1];
|
|
|
+
|
|
|
+
|
|
|
+ $request = $smcFunc['db_query']('', '
|
|
|
+ SELECT id_theme, variable, value
|
|
|
+ FROM {db_prefix}themes
|
|
|
+ WHERE id_theme != {int:default_theme}
|
|
|
+ AND id_member = {int:no_member}
|
|
|
+ AND variable IN ({string:name}, {string:theme_dir})',
|
|
|
+ array(
|
|
|
+ 'default_theme' => 1,
|
|
|
+ 'no_member' => 0,
|
|
|
+ 'name' => 'name',
|
|
|
+ 'theme_dir' => 'theme_dir',
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $themes = array(
|
|
|
+ 1 => array(
|
|
|
+ 'name' => $txt['dvc_default'],
|
|
|
+ 'theme_dir' => $settings['default_theme_dir'],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
|
+ $themes[$row['id_theme']][$row['variable']] = $row['value'];
|
|
|
+ $smcFunc['db_free_result']($request);
|
|
|
+
|
|
|
+
|
|
|
+ $lang_dirs = array();
|
|
|
+
|
|
|
+ foreach ($themes as $id => $data)
|
|
|
+ {
|
|
|
+ if (count($data) != 2)
|
|
|
+ unset($themes[$id]);
|
|
|
+ elseif (is_dir($data['theme_dir'] . '/languages'))
|
|
|
+ $lang_dirs[$id] = $data['theme_dir'] . '/languages';
|
|
|
+
|
|
|
+
|
|
|
+ if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id']))
|
|
|
+ $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
|
|
|
+
|
|
|
+
|
|
|
+ $context['possible_files'] = array();
|
|
|
+ foreach ($lang_dirs as $theme => $theme_dir)
|
|
|
+ {
|
|
|
+
|
|
|
+ $dir = dir($theme_dir);
|
|
|
+ while ($entry = $dir->read())
|
|
|
+ {
|
|
|
+
|
|
|
+ if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0)
|
|
|
+ continue;
|
|
|
+
|
|
|
+
|
|
|
+ if ($matches[1] == 'EmailTemplates')
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (!isset($context['possible_files'][$theme]))
|
|
|
+ $context['possible_files'][$theme] = array(
|
|
|
+ 'id' => $theme,
|
|
|
+ 'name' => $themes[$theme]['name'],
|
|
|
+ 'files' => array(),
|
|
|
+ );
|
|
|
+
|
|
|
+ $context['possible_files'][$theme]['files'][] = array(
|
|
|
+ 'id' => $matches[1],
|
|
|
+ 'name' => isset($txt['lang_file_desc_' . $matches[1]]) ? $txt['lang_file_desc_' . $matches[1]] : $matches[1],
|
|
|
+ 'selected' => $theme_id == $theme && $file_id == $matches[1],
|
|
|
+ );
|
|
|
+ }
|
|
|
+ $dir->close();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($_POST['delete_main']) && $context['lang_id'] != 'english')
|
|
|
+ {
|
|
|
+ checkSession();
|
|
|
+
|
|
|
+
|
|
|
+ require_once($sourcedir . '/Subs-Package.php');
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($modSettings['package_make_backups']) && (!isset($_SESSION['last_backup_for']) || $_SESSION['last_backup_for'] != $context['lang_id'] . '$$$'))
|
|
|
+ {
|
|
|
+ $_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
|
|
|
+ package_create_backup('backup_lang_' . $context['lang_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ foreach ($lang_dirs as $curPath)
|
|
|
+ {
|
|
|
+ foreach ($context['possible_files'][1]['files'] as $lang)
|
|
|
+ if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
|
|
|
+ unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
|
|
|
+
|
|
|
+
|
|
|
+ if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'))
|
|
|
+ unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt'))
|
|
|
+ unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
|
|
|
+
|
|
|
+
|
|
|
+ foreach ($images_dirs as $curPath)
|
|
|
+ if (is_dir($curPath))
|
|
|
+ deltree($curPath);
|
|
|
+
|
|
|
+
|
|
|
+ $smcFunc['db_query']('', '
|
|
|
+ UPDATE {db_prefix}members
|
|
|
+ SET lngfile = {string:empty_string}
|
|
|
+ WHERE lngfile = {string:current_language}',
|
|
|
+ array(
|
|
|
+ 'empty_string' => '',
|
|
|
+ 'current_language' => $context['lang_id'],
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($modSettings['cache_enable']))
|
|
|
+ {
|
|
|
+ cache_put_data('known_languages', null, !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
|
|
|
+ cache_put_data('known_languages_all', null, !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($context['lang_id'] == $language)
|
|
|
+ {
|
|
|
+ require_once($sourcedir . '/Subs-Admin.php');
|
|
|
+ $language = 'english';
|
|
|
+ updateSettingsFile(array('language' => '\'' . $language . '\''));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ redirectexit('action=admin;area=languages;sa=edit;' . $context['session_var'] . '=' . $context['session_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $madeSave = false;
|
|
|
+ if (!empty($_POST['save_main']) && !$current_file)
|
|
|
+ {
|
|
|
+ checkSession();
|
|
|
+
|
|
|
+
|
|
|
+ $current_data = implode('', file($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php'));
|
|
|
+
|
|
|
+ $replace_array = array(
|
|
|
+ '~\$txt\[\'lang_character_set\'\]\s=\s(\'|")[^\r\n]+~' => '$txt[\'lang_character_set\'] = \'' . addslashes($_POST['character_set']) . '\';',
|
|
|
+ '~\$txt\[\'lang_locale\'\]\s=\s(\'|")[^\r\n]+~' => '$txt[\'lang_locale\'] = \'' . addslashes($_POST['locale']) . '\';',
|
|
|
+ '~\$txt\[\'lang_dictionary\'\]\s=\s(\'|")[^\r\n]+~' => '$txt[\'lang_dictionary\'] = \'' . addslashes($_POST['dictionary']) . '\';',
|
|
|
+ '~\$txt\[\'lang_spelling\'\]\s=\s(\'|")[^\r\n]+~' => '$txt[\'lang_spelling\'] = \'' . addslashes($_POST['spelling']) . '\';',
|
|
|
+ '~\$txt\[\'lang_rtl\'\]\s=\s[A-Za-z0-9]+;~' => '$txt[\'lang_rtl\'] = ' . (!empty($_POST['rtl']) ? 'true' : 'false') . ';',
|
|
|
+ );
|
|
|
+ $current_data = preg_replace(array_keys($replace_array), array_values($replace_array), $current_data);
|
|
|
+ $fp = fopen($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php', 'w+');
|
|
|
+ fwrite($fp, $current_data);
|
|
|
+ fclose($fp);
|
|
|
+
|
|
|
+ $madeSave = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $old_txt = $txt;
|
|
|
+ require($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php');
|
|
|
+ $context['lang_file_not_writable_message'] = is_writable($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php') ? '' : sprintf($txt['lang_file_not_writable'], $settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php');
|
|
|
+
|
|
|
+ $context['primary_settings'] = array(
|
|
|
+ 'name' => $smcFunc['ucwords'](strtr($context['lang_id'], array('_' => ' ', '-utf8' => ''))),
|
|
|
+ 'character_set' => $txt['lang_character_set'],
|
|
|
+ 'locale' => $txt['lang_locale'],
|
|
|
+ 'dictionary' => $txt['lang_dictionary'],
|
|
|
+ 'spelling' => $txt['lang_spelling'],
|
|
|
+ 'rtl' => $txt['lang_rtl'],
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ $txt = $old_txt;
|
|
|
+
|
|
|
+
|
|
|
+ $save_strings = array();
|
|
|
+ if (isset($_POST['save_entries']) && !empty($_POST['entry']))
|
|
|
+ {
|
|
|
+ checkSession();
|
|
|
+
|
|
|
+
|
|
|
+ foreach ($_POST['entry'] as $k => $v)
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($_POST['entry'][$k] != $_POST['comp'][$k])
|
|
|
+ $save_strings[$k] = cleanLangString($v, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($current_file)
|
|
|
+ {
|
|
|
+ $context['entries_not_writable_message'] = is_writable($current_file) ? '' : sprintf($txt['lang_entries_not_writable'], $current_file);
|
|
|
+
|
|
|
+ $entries = array();
|
|
|
+
|
|
|
+ $multiline_cache = '';
|
|
|
+ foreach (file($current_file) as $line)
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($line[0] == '$' && !empty($multiline_cache))
|
|
|
+ {
|
|
|
+ preg_match('~\$(helptxt|txt)\[\'(.+)\'\]\s=\s(.+);~', strtr($multiline_cache, array("\n" => '', "\t" => '')), $matches);
|
|
|
+ if (!empty($matches[3]))
|
|
|
+ {
|
|
|
+ $entries[$matches[2]] = array(
|
|
|
+ 'type' => $matches[1],
|
|
|
+ 'full' => $matches[0],
|
|
|
+ 'entry' => $matches[3],
|
|
|
+ );
|
|
|
+ $multiline_cache = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $multiline_cache .= $line . "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($multiline_cache)
|
|
|
+ {
|
|
|
+ preg_match('~\$(helptxt|txt)\[\'(.+)\'\]\s=\s(.+);~', strtr($multiline_cache, array("\n" => '', "\t" => '')), $matches);
|
|
|
+ if (!empty($matches[3]))
|
|
|
+ $entries[$matches[2]] = array(
|
|
|
+ 'type' => $matches[1],
|
|
|
+ 'full' => $matches[0],
|
|
|
+ 'entry' => $matches[3],
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $final_saves = array();
|
|
|
+
|
|
|
+ $context['file_entries'] = array();
|
|
|
+ foreach ($entries as $entryKey => $entryValue)
|
|
|
+ {
|
|
|
+
|
|
|
+ $ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl');
|
|
|
+ if (in_array($entryKey, $ignore_files))
|
|
|
+ continue;
|
|
|
+
|
|
|
+
|
|
|
+ $arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short');
|
|
|
+ if (in_array($entryKey, $arrays))
|
|
|
+ {
|
|
|
+
|
|
|
+ $entryValue['entry'] = substr($entryValue['entry'], strpos($entryValue['entry'], '(') + 1, strrpos($entryValue['entry'], ')') - strpos($entryValue['entry'], '('));
|
|
|
+ $entryValue['entry'] = explode(',', strtr($entryValue['entry'], array(' ' => '')));
|
|
|
+
|
|
|
+
|
|
|
+ $cur_index = 0;
|
|
|
+ $save_cache = array(
|
|
|
+ 'enabled' => false,
|
|
|
+ 'entries' => array(),
|
|
|
+ );
|
|
|
+ foreach ($entryValue['entry'] as $id => $subValue)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (preg_match('~^(\d+)~', $subValue, $matches))
|
|
|
+ {
|
|
|
+ $cur_index = $matches[1];
|
|
|
+ $subValue = substr($subValue, strpos($subValue, '\''));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $subValue = strtr($subValue, array('"' => '', '\'' => '', ')' => ''));
|
|
|
+
|
|
|
+
|
|
|
+ if (isset($save_strings[$entryKey . '-+- ' . $cur_index]))
|
|
|
+ {
|
|
|
+ $save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => ''));
|
|
|
+ $save_cache['enabled'] = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ $save_cache['entries'][$cur_index] = $subValue;
|
|
|
+
|
|
|
+ $context['file_entries'][] = array(
|
|
|
+ 'key' => $entryKey . '-+- ' . $cur_index,
|
|
|
+ 'value' => $subValue,
|
|
|
+ 'rows' => 1,
|
|
|
+ );
|
|
|
+ $cur_index++;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($save_cache['enabled'])
|
|
|
+ {
|
|
|
+
|
|
|
+ $items = array();
|
|
|
+ $cur_index = 0;
|
|
|
+ foreach ($save_cache['entries'] as $k2 => $v2)
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($k2 != $cur_index)
|
|
|
+ {
|
|
|
+ $items[] = $k2 . ' => \'' . $v2 . '\'';
|
|
|
+ $cur_index = $k2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ $items[] = '\'' . $v2 . '\'';
|
|
|
+
|
|
|
+ $cur_index++;
|
|
|
+ }
|
|
|
+
|
|
|
+ $final_saves[$entryKey] = array(
|
|
|
+ 'find' => $entryValue['full'],
|
|
|
+ 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');',
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry'])
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($save_strings[$entryKey] == '')
|
|
|
+ $save_strings[$entryKey] = '\'\'';
|
|
|
+
|
|
|
+
|
|
|
+ $entryValue['entry'] = $save_strings[$entryKey];
|
|
|
+
|
|
|
+ $final_saves[$entryKey] = array(
|
|
|
+ 'find' => $entryValue['full'],
|
|
|
+ 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = ' . $save_strings[$entryKey] . ';',
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $editing_string = cleanLangString($entryValue['entry'], true);
|
|
|
+ $context['file_entries'][] = array(
|
|
|
+ 'key' => $entryKey,
|
|
|
+ 'value' => $editing_string,
|
|
|
+ 'rows' => (int) (strlen($editing_string) / 38) + substr_count($editing_string, "\n") + 1,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($final_saves))
|
|
|
+ {
|
|
|
+ checkSession();
|
|
|
+
|
|
|
+ $file_contents = implode('', file($current_file));
|
|
|
+ foreach ($final_saves as $save)
|
|
|
+ $file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
|
|
|
+
|
|
|
+
|
|
|
+ $fp = fopen($current_file, 'w+');
|
|
|
+ fwrite($fp, $file_contents);
|
|
|
+ fclose($fp);
|
|
|
+
|
|
|
+ $madeSave = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $txt = $old_txt;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($madeSave)
|
|
|
+ redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * This function cleans language entries to/from display.
|
|
|
+ * @todo This function could be two functions?
|
|
|
+ *
|
|
|
+ * @param $string
|
|
|
+ * @param $to_display
|
|
|
+ */
|
|
|
+function cleanLangString($string, $to_display = true)
|
|
|
+{
|
|
|
+ global $smcFunc;
|
|
|
+
|
|
|
+
|
|
|
+ $new_string = '';
|
|
|
+ if ($to_display)
|
|
|
+ {
|
|
|
+
|
|
|
+ $in_string = 0;
|
|
|
+ $is_escape = false;
|
|
|
+ for ($i = 0; $i < strlen($string); $i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($string{$i} == '\\')
|
|
|
+ {
|
|
|
+
|
|
|
+ $is_escape = !$is_escape;
|
|
|
+
|
|
|
+ if ($is_escape)
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
|
|
|
+ {
|
|
|
+
|
|
|
+ $new_string .= $string{$i} == 'n' ? "\n" : "\t";
|
|
|
+ $is_escape = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($string{$i} == '\'')
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($in_string != 2 && ($in_string != 1 || !$is_escape))
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($in_string == 1)
|
|
|
+ $in_string = 0;
|
|
|
+
|
|
|
+ else
|
|
|
+ $in_string = 1;
|
|
|
+
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($string{$i} == '"')
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($in_string != 1 && ($in_string != 2 || !$is_escape))
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($in_string == 2)
|
|
|
+ $in_string = 0;
|
|
|
+
|
|
|
+ else
|
|
|
+ $in_string = 2;
|
|
|
+
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ elseif ($in_string == 0 && $string{$i} == '$')
|
|
|
+ {
|
|
|
+
|
|
|
+ preg_match('~([\$A-Za-z0-9\'\[\]_-]+)~', substr($string, $i), $matches);
|
|
|
+ if (!empty($matches[1]))
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ $new_string .= '{%' . $matches[1] . '%}';
|
|
|
+
|
|
|
+
|
|
|
+ $i += strlen($matches[1]) - 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($in_string == 0)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $new_string .= $string{$i};
|
|
|
+
|
|
|
+ $is_escape = false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $new_string = htmlspecialchars(un_htmlspecialchars($new_string));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ $in_string = 0;
|
|
|
+
|
|
|
+ $in_html = false;
|
|
|
+ for ($i = 0; $i < strlen($string); $i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($string{$i} == "\n" || $string{$i} == "\t")
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($in_string == 1)
|
|
|
+ {
|
|
|
+
|
|
|
+ $new_string .= '\' . "\\' . ($string{$i} == "\n" ? 'n' : 't');
|
|
|
+ $in_string = 2;
|
|
|
+ }
|
|
|
+ elseif ($in_string == 2)
|
|
|
+ $new_string .= '\\' . ($string{$i} == "\n" ? 'n' : 't');
|
|
|
+
|
|
|
+ else
|
|
|
+ $new_string .= ($new_string ? ' . ' : '') . '"\\' . ($string{$i} == "\n" ? 'n' : 't');
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($in_string == 2)
|
|
|
+ {
|
|
|
+ $in_string = 0;
|
|
|
+ $new_string .= '"';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($in_string != 1)
|
|
|
+ {
|
|
|
+ $in_string = 1;
|
|
|
+ $new_string .= ($new_string ? ' . ' : '') . '\'';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($string{$i} == '{' && $string{$i + 1} == '%' && $string{$i + 2} == '$')
|
|
|
+ {
|
|
|
+
|
|
|
+ preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches);
|
|
|
+ if (!empty($matches[1]))
|
|
|
+ {
|
|
|
+ if ($in_string == 1)
|
|
|
+ $new_string .= '\' . ';
|
|
|
+ elseif ($new_string)
|
|
|
+ $new_string .= ' . ';
|
|
|
+
|
|
|
+ $new_string .= $matches[1];
|
|
|
+ $i += strlen($matches[1]) + 3;
|
|
|
+ $in_string = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($string{$i} == '<')
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($string{$i + 1} != ' ')
|
|
|
+ $in_html = true;
|
|
|
+
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $new_string .= '<';
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($string{$i} == '>')
|
|
|
+ {
|
|
|
+
|
|
|
+ if ($in_html)
|
|
|
+ $in_html = false;
|
|
|
+
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $new_string .= '>';
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($string{$i} == '\\')
|
|
|
+ $new_string .= '\\';
|
|
|
+
|
|
|
+ elseif ($string{$i} == '"')
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!$in_html)
|
|
|
+ {
|
|
|
+ $new_string .= '"';
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ elseif ($string{$i} == '\'')
|
|
|
+ {
|
|
|
+
|
|
|
+ $new_string .= '\\';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $new_string .= $string{$i};
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($in_string == 1)
|
|
|
+ $new_string .= '\'';
|
|
|
+ elseif ($in_string == 2)
|
|
|
+ $new_string .= '"';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $new_string;
|
|
|
+}
|
|
|
+
|
|
|
+?>
|