diff -r 8d0e3a5a6990 -r 66732bd4532c plugins/admin/LangManager.php --- a/plugins/admin/LangManager.php Thu Jan 24 22:14:40 2008 -0500 +++ b/plugins/admin/LangManager.php Sat Jan 26 11:51:19 2008 -0500 @@ -26,21 +26,35 @@ if ( isset($_POST['action']) ) { $action =& $_POST['action']; + // Parse parameters if ( strpos($action, ';') ) { + // Parameter section $parms = substr($action, strpos($action, ';') + 1); + + // Action name section $action = substr($action, 0, strpos($action, ';')); + + // Match all parameters preg_match_all('/([a-z0-9_]+)=(.+?)(;|$)/', $parms, $matches); $parms = array(); + + // For each full parameter, assign $parms an associative value foreach ( $matches[0] as $i => $_ ) { - $parms[$matches[1][$i]] = $matches[2][$i]; + $parm = $matches[2][$i]; + + // Is this parameter in the form of an integer? + // (designed to ease validation later) + if ( preg_match('/^[0-9]+$/', $parm) ) + // Yes, run intval(), this enabling is_int()-ish checks + $parm = intval($parm); + + $parms[$matches[1][$i]] = $parm; } } switch ( $action ) { - case 'edit_language': - break; case 'install_language': $lang_list = list_available_languages(); // Verify that we have this language's metadata @@ -55,9 +69,16 @@ { // Language installed. Import the language files. $lang_local = new Language($lang_code); - foreach ( array('core', 'admin', 'tools', 'user') as $file ) + if ( file_exists(ENANO_ROOT . "/language/{$lang_data['dir']}/backup.json") ) { - $lang_local->import(ENANO_ROOT . "/language/{$lang_data['dir']}/$file.json"); + $lang_local->import(ENANO_ROOT . "/language/{$lang_data['dir']}/backup.json"); + } + else + { + foreach ( array('core', 'admin', 'tools', 'user') as $file ) + { + $lang_local->import(ENANO_ROOT . "/language/{$lang_data['dir']}/$file.json"); + } } unset($lang_local); @@ -65,9 +86,462 @@ } } break; + case 'modify_language': + $lang_id =& $parms['lang_id']; + if ( !is_int($lang_id) ) + { + echo 'Hacking attempt'; + break; + } + + if ( isset($parms['finish']) && !empty($_POST['lang_name_native']) && !empty($_POST['lang_name_english']) ) + { + // We just did validation above, it's safe to save. + $name_native = $db->escape($_POST['lang_name_native']); + $name_english = $db->escape($_POST['lang_name_english']); + + $q = $db->sql_query('UPDATE ' . table_prefix . "language SET lang_name_native = '$name_native', lang_name_default = '$name_english' WHERE lang_id = $lang_id;"); + if ( !$q ) + $db->_die(); + + echo '
+ get('acplm_th_lang_basic'); + ?> + | +|
---|---|
+ get('acplm_field_lang_name_native')); + ?> + | ++ + | +
+ get('acplm_field_lang_name_english'); + ?> + | ++ + | +
+ get('acplm_field_lang_code') . ' ' + . '' . $lang->get('acplm_field_lang_code_hint') . ''; + ?> + |
+ + + | +
+ + | +
get('acplm_msg_edit_strings_portal_intro'); ?>
+ ++ + lang_id == $lang_id ) + { + $lang_local =& $lang; + } + else + { + $lang_local = new Language($lang_id); + $lang_local->fetch(); + } + + $categories_loc = array(); + + // Using the & here ensures that a reference is created, thus avoiding wasting memory + foreach ( $lang_local->strings as $cat => &$_ ) + { + unset($_); + $categories_loc[$cat] = htmlspecialchars($lang->get("meta_$cat")); + } + + asort($categories_loc); + + echo ''; + + ?> + +
+ +get('acplm_msg_reimport_portal_intro'); ?>
+ ++ +
+ + + + ' . $lang->get('acplm_heading_backup') . ''; + echo '' . $lang->get('acplm_backup_intro') . '
'; + + echo ''; + + return true; + case 'edit_strings': + + $cat_id = @$_POST['cat_id']; + if ( !preg_match('/^[a-z0-9]+$/', $cat_id) || !is_int(@$parms['lang_id']) ) + break; + + $lang_id =& $parms['lang_id']; + + if ( isset($parms['save']) ) + { + // Grab a Language object + if ( $lang->lang_id == $lang_id ) + { + $lang_local =& $lang; + } + else + { + $lang_local = new Language($lang_id); + } + // Main save loop + // Trying to minimize queries as much as possible here, but you know how that goes. + $count_upd = 0; + foreach ( $_POST['string'] as $string_id => $user_content ) + { + $curr_content = $lang_local->get_uncensored("{$cat_id}_{$string_id}"); + if ( $curr_content != $user_content ) + { + $count_upd++; + $user_content = $db->escape($user_content); + $string_id = $db->escape($string_id); + $q = $db->sql_query('UPDATE ' . table_prefix . "language_strings SET string_content = '$user_content' WHERE lang_id = $lang_id AND string_category = '$cat_id' AND string_name = '$string_id';"); + if ( !$q ) + $db->_die(); + } + } + if ( $count_upd > 0 ) + { + // Update the cache + $lang_local->regen_caches(); + + // Update modification time + $q = $db->sql_query('UPDATE ' . table_prefix . "language SET last_changed = " . time() . " WHERE lang_id = $lang_id;"); + if ( !$q ) + $db->_die(); + } + + echo 'get('acplm_editor_col_string_name'); ?> | +get('acplm_editor_col_string_content'); ?> | +
---|---|
'; + + echo ''; + + // Button: save + echo ' '; + // Button: revert + echo ' '; + // Button: cancel + echo ''; + + echo ' | +
' . $lang->get('acplm_uninstall_confirm_body') . '
'; + + echo ''; + echo '
'; + + echo ''; + return true; } } + acp_start_form(); + + // Select current languages + $q = $db->sql_query('SELECT lang_code, lang_name_native, lang_name_default, lang_id FROM ' . table_prefix . "language ORDER BY lang_id ASC;"); + if ( !$q ) + $db->_die(); + + // Language properties/edit/delete portal table + echo '' . $lang->get('acplm_col_lang_id') . ' | +' . $lang->get('acplm_col_lang_code') . ' | +' . $lang->get('acplm_col_lang_name') . ' | +' . $lang->get('acplm_col_lang_name_eng') . ' | ++ |
---|---|---|---|---|
{$row['lang_id']} | "; + echo "{$lang_code} | "; + echo "{$lang_name_native} | "; + echo "{$lang_name_english} | "; + echo ""; + + echo ' |