From 61fbde5a72a26a8dd964a529720bdae6e3e14577 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 23 Jan 2005 23:07:26 +0000 Subject: [PATCH] here we go, a new admin file, only first draft. git-svn-id: file:///svn/phpbb/trunk@5075 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/adm/admin_language.php | 1019 ++++++++++++++++++++++++++++++++++ 1 file changed, 1019 insertions(+) create mode 100644 phpBB/adm/admin_language.php diff --git a/phpBB/adm/admin_language.php b/phpBB/adm/admin_language.php new file mode 100644 index 0000000000..0054e18d16 --- /dev/null +++ b/phpBB/adm/admin_language.php @@ -0,0 +1,1019 @@ +acl_get('a_server')) + { + return; + } + + $module['LANGUAGE']['LANGUAGE_PACKS'] = basename(__FILE__) . "$SID&mode=manage"; + + return; +} + +define('IN_PHPBB', 1); +// Include files +$phpbb_root_path = '../'; +$phpEx = substr(strrchr(__FILE__, '.'), 1); +require('pagestart.' . $phpEx); +include($phpbb_root_path . 'includes/functions_user.'.$phpEx); + +// Do we have general permissions? +if (!$auth->acl_get('a_server')) +{ + trigger_error($user->lang['NO_ADMIN']); +} + +// Check and set some common vars +$mode = request_var('mode', ''); +$confirm = (isset($_POST['confirm'])) ? true : false; +$cancel = (isset($_POST['cancel'])) ? true : false; +$action = request_var('action', ''); + +$action = (isset($_POST['update_details'])) ? 'update_details' : $action; +$action = (isset($_POST['download_file'])) ? 'download_file' : $action; +$action = (isset($_POST['submit_file'])) ? 'submit_file' : $action; +$action = (isset($_POST['remove_store'])) ? 'details' : $action; + +$lang_id = request_var('id', 0); +$cur_file = request_var('cur_file', 'common'); + +if (is_array($cur_file)) +{ + list($cur_file, ) = array_keys($cur_file); +} + +$cur_file = (strpos($cur_file, 'email/') !== false) ? 'email/' . basename($cur_file) : basename($cur_file) . '.' . $phpEx; + +if (!$mode) +{ + trigger_error('NO_MODE'); +} + +$user->lang += array( + 'LANGUAGE_PACKS_EXPLAIN' => 'Here you are able to install/remove language packs', + 'LANGUAGE_PACK_NAME' => 'Name', + 'LANGUAGE_PACK_LOCALNAME' => 'Local name', + 'LANGUAGE_PACK_ISO' => 'ISO', + 'LANGUAGE_PACK_USED_BY' => 'Used by', + 'INSTALLED_LANGUAGE_PACKS' => 'Installed language packs', + 'UNINSTALLED_LANGUAGE_PACKS'=> 'Uninstalled language packs', + 'NO_UNINSTALLED_LANGUAGE_PACKS' => 'No uninstalled language packs', + 'NO_LANG_ID' => 'You haven\'t specified a language pack', + 'NO_REMOVE_DEFAULT_LANG' => 'You are not able to remove the default language pack.
If you want to remove this language pack, change your boards default language first.', + 'LANGUAGE_PACK_DELETED' => 'The language pack %s has been removed successfully. All users using this language have been resetted to the boards default language.', + 'LANGUAGE_PACK_NOT_EXIST' => 'The selected language pack does not exist.', + 'LANGUAGE_PACK_ALREADY_INSTALLED' => 'This language pack is already installed.', + 'INVALID_LANGUAGE_PACK' => 'The selected language pack seems to be not valid. Please verify the language pack and upload it again if necessary.', + 'LANGUAGE_PACK_INSTALLED' => 'The language pack %s has been successfully installed.', + 'LANGUAGE_PACK_DETAILS' => 'Language Pack Details', + 'WRONG_LANGUAGE_FILE' => 'Selected language file is invalid', + 'LANGUAGE_DETAILS_UPDATED' => 'Language details successfully updated', + + 'LANG_ENGLISH_NAME' => 'English name', + 'LANG_LOCAL_NAME' => 'Local name', + 'LANG_ISO_CODE' => 'ISO Code', + 'LANG_AUTHOR' => 'Language Pack Author', + + 'MISSING_LANGUAGE_FILE' => 'Missing Language File: %s', + 'THOSE_MISSING_LANG_FILES' => 'The following language files are missing from the %s language folder', + 'MISSING_LANG_VARIABLES' => 'Missing Language Variables', + 'THOSE_MISSING_LANG_VARIABLES' => 'The following language variables are missing from the %s language pack', + + 'LANGUAGE_KEY' => 'Language Key', + 'LANGUAGE_VARIABLE' => 'Language Variable', + 'LANGUAGE_FILES' => 'Language Files', + 'HELP_FILES' => 'Help Files', + 'EMAIL_TEMPLATES' => 'Email Templates', + + 'LANGUAGE_ENTRIES' => 'Language Entries', + 'LANGUAGE_ENTRIES_EXPLAIN' => 'Here you are able to change existing language pack entries or not already translated ones.', + 'REMOVE_FROM_STORAGE_FOLDER'=> 'Remove from storage folder', + 'FILE_CONTENTS' => 'File Contents', + 'FILE_FROM_STORAGE' => 'File from storage folder', + 'SUBMIT_AND_DOWNLOAD' => 'Submit and Download File', + 'SELECT_DOWNLOAD_FORMAT' => 'Select download format', + 'DOWNLOAD_AS' => 'Download as', + 'DOWNLOAD' => 'Download', +); + +switch ($action) +{ + case 'update_details': + + if (!$lang_id) + { + trigger_error('NO_LANGUAGE_PACK_DEFINED'); + } + + $sql = 'SELECT * FROM ' . LANG_TABLE . " + WHERE lang_id = $lang_id"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $sql_ary['lang_english_name'] = request_var('lang_english_name', $row['lang_english_name']); + $sql_ary['lang_local_name'] = request_var('lang_local_name', $row['lang_local_name']); + $sql_ary['lang_author'] = request_var('lang_author', $row['lang_author']); + + $db->sql_query('UPDATE ' . LANG_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE lang_id = ' . $lang_id); + + add_log('admin', 'LOG_UPDATE_LANG_DETAILS', $sql_ary['lang_english_name']); + + trigger_error('LANGUAGE_DETAILS_UPDATED'); + break; + + case 'submit_file': + case 'download_file': + + if (!$lang_id) + { + trigger_error('NO_LANGUAGE_PACK_DEFINED'); + } + + if (!$cur_file) + { + trigger_error('NO_FILE_SELECTED'); + } + + $sql = 'SELECT * FROM ' . LANG_TABLE . " + WHERE lang_id = $lang_id"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $mkdir_ary = array('language', 'language/' . $row['lang_iso']); + if (strpos($cur_file, 'email/') !== false) + { + $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/email'; + } + + foreach ($mkdir_ary as $dir) + { + $dir = $phpbb_root_path . 'store/' . $dir; + + if (!is_dir($dir)) + { + if (!@mkdir($dir, 0777)) + { + trigger_error("Could not create directory $dir"); + } + @chmod($dir, 0777); + } + } + + $filename = "{$phpbb_root_path}store/language/{$row['lang_iso']}/{$cur_file}"; + $fp = fopen($filename, 'wb'); + + if (strpos($cur_file, 'email/') !== false) + { + fwrite($fp, (STRIP) ? stripslashes($_POST['entry']) : $_POST['entry']); + } + else if (strpos($cur_file, 'help_') === 0) + { + $header = ' $value) + { + if (!is_array($value)) + { + } + else + { + $entry = "\tarray(\n"; + + foreach ($value as $_key => $_value) + { + $_value = (STRIP) ? stripslashes($_value) : $_value; + $entry .= "\t\t" . (int) $_key . "\t=> '" . str_replace("'", "\\'", $_value) . "',\n"; + } + + $entry .= "\t),\n"; + } + + fwrite($fp, $entry); + } + + $footer = ");\n\n?>"; + fwrite($fp, $footer); + } + else + { + $header = ' $value) + { + if (!is_array($value)) + { + $value = (STRIP) ? stripslashes($value) : $value; + $entry = "\t'" . $key . "'\t=> '" . str_replace("'", "\\'", $value) . "',\n"; + } + else + { + $entry = "\n\t'" . $key . "'\t=> array(\n"; + + foreach ($value as $_key => $_value) + { + $_value = (STRIP) ? stripslashes($_value) : $_value; + $entry .= "\t\t'" . $_key . "'\t=> '" . str_replace("'", "\\'", $_value) . "',\n"; + } + + $entry .= "\t),\n\n"; + } + + fwrite($fp, $entry); + } + + $footer = ");\n\n?>"; + fwrite($fp, $footer); + } + + fclose($fp); + + if ($action == 'download_file') + { + $name = basename($cur_file); + + header('Pragma: no-cache'); + header('Content-Type: application/octetstream; name="' . $name . '"'); + header('Content-disposition: attachment; filename=' . $name); + + $fp = fopen($filename, 'rb'); + while ($buffer = fread($fp, 1024)) + { + echo $buffer; + } + fclose($fp); + + exit; + } + + $action = 'details'; + + case 'details': + adm_page_header($user->lang['LANGUAGE_PACK_DETAILS']); + + if (!$lang_id) + { + trigger_error('NO_LANGUAGE_PACK_DEFINED'); + } + + $sql = 'SELECT * FROM ' . LANG_TABLE . " + WHERE lang_id = $lang_id + OR lang_iso = '{$config['default_lang']}'"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $lang_entries[$row['lang_id']] = $row; + } + $db->sql_freeresult($result); + + $lang_iso = $lang_entries[$lang_id]['lang_iso']; + + $language_files = array('common', 'groups', 'mcp', 'memberlist', 'posting', 'search', 'ucp', 'viewforum', 'viewtopic', 'admin'); + $help_files = array('help_bbcode', 'help_faq'); + + $email_templates = filelist($phpbb_root_path . 'language/' . $lang_iso, 'email', 'txt'); + $email_templates = $email_templates['email/']; + + $missing_vars = $missing_files = array(); + + if (!in_array(str_replace(".{$phpEx}", '', $cur_file), $language_files) && !in_array(str_replace(".{$phpEx}", '', $cur_file), $help_files) && !in_array(basename($cur_file), $email_templates)) + { + trigger_error('WRONG_LANGUAGE_FILE'); + } + + if (isset($_POST['remove_store'])) + { + @unlink($phpbb_root_path . 'store/language/' . $lang_iso . '/' . $cur_file); + } + +?> +

lang['LANGUAGE_PACK_DETAILS']; ?>

+ +
"> + + + + + + + + + + + + + + + + + + + + + + + +
lang['LANG_ENGLISH_NAME']; ?>:
lang['LANG_LOCAL_NAME']; ?>:
lang['LANG_ISO_CODE']; ?>:
lang['LANG_AUTHOR']; ?>:
+

+
+ +

lang['THOSE_MISSING_LANG_FILES'], $lang_entries[$lang_id]['lang_local_name']); ?>

+ +

', $missing_files); ?>

+ +

+ +

lang['MISSING_LANG_VARIABLES']; ?>

+ +

lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries[$lang_id]['lang_local_name']); ?>

+ +
"> + + + + + + $vars) + { +?> + + + + + + + + +
lang['LANGUAGE_KEY']; ?>lang['LANGUAGE_VARIABLE']; ?>
]" value="lang['SELECT']; ?>" class="btnmain" />
+

+
+' . $user->lang['LANGUAGE_FILES'] . ''; + foreach ($language_files as $file) + { + $prefix = (file_exists($phpbb_root_path . 'store/language/' . $lang_iso . '/' . $file . '.' . $phpEx)) ? '* ' : ''; + + $selected = ($cur_file == $file . '.' . $phpEx) ? ' selected="selected"' : ''; + $s_lang_options .= ''; + } + + $s_lang_options .= ''; + foreach ($help_files as $file) + { + $prefix = (file_exists($phpbb_root_path . 'store/language/' . $lang_iso . '/' . $file . '.' . $phpEx)) ? '* ' : ''; + + $selected = ($cur_file == $file . '.' . $phpEx) ? ' selected="selected"' : ''; + $s_lang_options .= ''; + } + + $s_lang_options .= ''; + foreach ($email_templates as $file) + { + $prefix = (file_exists($phpbb_root_path . 'store/language/' . $lang_iso . '/email/' . $file)) ? '* ' : ''; + + $selected = ($cur_file == 'email/' . $file) ? ' selected="selected"' : ''; + $s_lang_options .= ''; + } + + // Get Language Entries - if saved within store folder, we take this one (with the option to remove it) + $lang = array(); + $filename = "language/{$lang_iso}/{$cur_file}"; + $is_email_file = (strpos($cur_file, 'email/') !== false) ? true : false; + $is_help_file = (strpos($cur_file, 'help_') === 0) ? true : false; + $file_from_store = (file_exists("{$phpbb_root_path}store/{$filename}")) ? true : false; + + if (!$file_from_store && !file_exists("{$phpbb_root_path}{$filename}")) + { + $print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $cur_file); + } + else + { + if ($is_email_file) + { + $lang = implode('', file($phpbb_root_path . (($file_from_store) ? 'store/' : '') . $filename)); + } + else + { + include($phpbb_root_path . (($file_from_store) ? 'store/' : '') . $filename); + + if ($is_help_file) + { + $lang = $help; + unset($help); + } + } + $print_message = $cur_file; + } + + // Normal language pack entries +?> + +

lang['LANGUAGE_ENTRIES']; ?>

+ +

lang['LANGUAGE_ENTRIES_EXPLAIN']; ?>

+ +
"> + + + + +
+  
+
+ + + + + + + + + + + + + + + + + + + + + + + +
lang['FILE_CONTENTS']; ?>
lang['LANGUAGE_KEY']; ?>lang['LANGUAGE_VARIABLE']; ?>
' . $user->lang['FILE_FROM_STORAGE'] . '' : ''); ?>  
  
+

+
+sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($row['lang_iso'] == $config['default_lang']) + { + trigger_error('NO_REMOVE_DEFAULT_LANG'); + } + + $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id); + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_lang = '{$config['default_lang']}' + WHERE user_lang = '{$row['lang_iso']}'"; + $db->sql_query($sql); + + add_log('admin', 'LOG_DELETE_LANGUAGE_PACK', $row['lang_english_name']); + + trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name'])); + + break; + + case 'install': + $lang_iso = request_var('iso', ''); + $lang_iso = basename($lang_iso); + + if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt")) + { + trigger_error('LANGUAGE_PACK_NOT_EXIST'); + } + + $file = file("{$phpbb_root_path}language/$lang_iso/iso.txt"); + $lang_pack = array(); + + $lang_pack = array( + 'iso' => htmlspecialchars($lang_iso), + 'name' => trim(htmlspecialchars($file[0])), + 'local_name'=> trim(htmlspecialchars($file[1])), + 'author' => trim(htmlspecialchars($file[2])) + ); + unset($file); + + $sql = 'SELECT lang_iso FROM ' . LANG_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'"; + $result = $db->sql_query($sql); + if ($row = $db->sql_fetchrow($result)) + { + trigger_error('LANGUAGE_PACK_ALREADY_INSTALLED'); + } + $db->sql_freeresult($result); + + if (!$lang_pack['name'] || !$lang_pack['local_name']) + { + trigger_error('INVALID_LANGUAGE_PACK'); + } + + // Add language pack + $sql_ary = array( + 'lang_iso' => $lang_pack['iso'], + 'lang_dir' => $lang_pack['iso'], + 'lang_english_name' => $lang_pack['name'], + 'lang_local_name' => $lang_pack['local_name'], + 'lang_author' => $lang_pack['author'] + ); + + $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + + add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']); + + trigger_error(sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name'])); + + break; + + case 'download': + + if (!$lang_id) + { + trigger_error('NO_LANGUAGE_PACK_DEFINED'); + } + + $sql = 'SELECT * FROM ' . LANG_TABLE . ' + WHERE lang_id = ' . $lang_id; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $use_method = request_var('use_method', ''); + + $methods = array('tar'); + + foreach (array('tar.gz' => 'zlib', 'tar.bz2' => 'bz2', 'zip' => 'zlib') as $type => $module) + { + if (!@extension_loaded($module)) + { + break; + } + $methods[] = $type; + } + + if (!in_array($use_method, $methods)) + { + $use_method = ''; + } + + // Let the user decide in which format he wants to have the pack + if (!$use_method) + { + adm_page_header($user->lang['SELECT_DOWNLOAD_FORMAT']); + +?> +

lang['SELECT_DOWNLOAD_FORMAT']; ?>

+ +
"> + + + + + + + + + +
lang['DOWNLOAD_AS']; ?> +
+ ' . $method . ' '; + } +?> +
+
+

+add_file('store/' . $src_path . $file . '.' . $phpEx, 'store/'); + } + else + { + $compress->add_file($src_path . $file . '.' . $phpEx); + } + } + + foreach ($help_files as $file) + { + if (file_exists($phpbb_root_path . 'store/' . $src_path . $file . '.' . $phpEx)) + { + $compress->add_file('store/' . $src_path . $file . '.' . $phpEx, 'store/'); + } + else + { + $compress->add_file($src_path . $file . '.' . $phpEx); + } + } + + foreach ($email_templates as $file) + { + if (file_exists($phpbb_root_path . 'store/' . $src_path . 'email/' . $file)) + { + $compress->add_file('store/' . $src_path . 'email/' . $file, 'store/'); + } + else + { + $compress->add_file($src_path . 'email/' . $file); + } + } + + // Write ISO File + $iso_src = strtr($row['lang_english_name'], array_flip(get_html_translation_table(HTML_ENTITIES))) . "\n"; + $iso_src .= strtr($row['lang_local_name'], array_flip(get_html_translation_table(HTML_ENTITIES))) . "\n"; + $iso_src .= strtr($row['lang_author'], array_flip(get_html_translation_table(HTML_ENTITIES))); + $compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt'); + + // index.html files + $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.html'); + $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.html'); + $compress->close(); + + $compress->download('lang_pack_' . $row['lang_iso']); + @unlink($phpbb_root_path . 'store/lang_pack_' . $row['lang_iso'] . '.' . $use_method); + exit; + + break; + + default: + // Output list of themes + adm_page_header($user->lang['LANGUAGE_PACKS']); +?> +

lang['LANGUAGE_PACKS']; ?>

+ +

lang['LANGUAGE_PACKS_EXPLAIN']; ?>

+ + + + + + + + + + + + +sql_query($sql); + + $lang_count = array(); + while ($row = $db->sql_fetchrow($result)) + { + $lang_count[$row['user_lang']] = $row['lang_count']; + } + $db->sql_freeresult($result); + + $sql = 'SELECT * + FROM ' . LANG_TABLE; + $result = $db->sql_query($sql); + + $installed = array(); + $row_class = ''; + while ($row = $db->sql_fetchrow($result)) + { + $installed[] = $row['lang_iso']; + $row_class = ($row_class != 'row1') ? 'row1' : 'row2'; + $tagstyle = ($row['lang_iso'] == $config['default_lang']) ? '*' : ''; + +?> + + + + + + + +sql_freeresult($result); + +?> + + + + $file, + 'name' => trim($iso[0]), + 'local_name'=> trim($iso[1]), + 'author' => trim($iso[2]) + ); + } + } + } + } + unset($installed); + @closedir($dp); + + if (sizeof($new_ary)) + { + $row_class = ''; + foreach ($new_ary as $iso => $lang_ary) + { + $row_class = ($row_class != 'row1') ? 'row1' : 'row2'; + +?> + + + + + + + + + + + +
lang['LANGUAGE_PACK_NAME']; ?>lang['LANGUAGE_PACK_LOCALNAME']; ?>lang['LANGUAGE_PACK_ISO']; ?>lang['LANGUAGE_PACK_USED_BY']; ?>lang['OPTIONS']; ?>
lang['INSTALLED_LANGUAGE_PACKS']; ?>
">  ">lang['DOWNLOAD']; ?> | ">lang['DELETE']; ?>
lang['UNINSTALLED_LANGUAGE_PACKS']; ?>
">lang['INSTALL']; ?>
lang['NO_UNINSTALLED_LANGUAGE_PACKS']; ?>
+

+ $value) + { +?> + + + + +   + + $_value) + { +?> + + + + + + + + \ No newline at end of file