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 '
' . $lang->get('acplm_msg_basic_save_success') . '
'; + } + + // Select language data + $q = $db->sql_query('SELECT lang_name_native, lang_name_default, lang_code FROM ' . table_prefix . "language WHERE lang_id = $lang_id;"); + if ( !$q ) + $db->_die(); + + list($name_native, $name_english, $lang_code) = $db->fetchrow_num(); + + // Output properties table + echo '

' . $lang->get('acplm_heading_modify') . '

'; + + acp_start_form(); + + ?> +
+ + + + + + + + + + + + + + + + + + + +
+ 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_heading_edit_strings_portal'); ?>

+

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_heading_reimport_portal'); ?>

+

get('acplm_msg_reimport_portal_intro'); ?>

+ +

+ +

+ + + + ' . $lang->get('acplm_heading_backup') . ''; + echo '

' . $lang->get('acplm_backup_intro') . '

'; + + echo '
'; + echo ''; + 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 '
' . $lang->get('acplm_msg_string_save_success') . '
'; + } + + acp_start_form(); + + $cat_name = $lang->get("meta_$cat_id"); + echo '

' . $lang->get('acplm_editor_heading', array('cat_name' => $cat_name)) . '

'; + + // Fetch all strings + // This is more efficient than iterating through $lang->strings, I think. + $q = $db->sql_query('SELECT string_id, string_name, string_content FROM ' . table_prefix . "language_strings WHERE string_category = '$cat_id' AND lang_id = $lang_id;"); + if ( !$q ) + $db->_die(); + + ?> +
+ + + + + + fetchrow_num() ) + { + list($string_id, $string_name, $string_content) = $row; + unset($row); + + echo ''; + + if ( strpos($string_content, "\n") ) + { + $editor = '
get('acplm_editor_col_string_name'); ?>get('acplm_editor_col_string_content'); ?>