# HG changeset patch # User Dan # Date 1201366279 18000 # Node ID 66732bd4532c27dc346acacb44089a5635b82969 # Parent 8d0e3a5a6990fee36417ca1a9c5479985b85189e Finished (or nearly finished) the admin language CP diff -r 8d0e3a5a6990 -r 66732bd4532c includes/functions.php --- a/includes/functions.php Thu Jan 24 22:14:40 2008 -0500 +++ b/includes/functions.php Sat Jan 26 11:51:19 2008 -0500 @@ -4075,6 +4075,36 @@ // Might as well start the profiler, it has no external dependencies except from this file. profiler_start(); +/** + * Returns the number of times a character occurs in a given string. + * @param string Haystack + * @param string Needle + * @return int + */ + +function get_char_count($string, $char) +{ + $char = substr($char, 0, 1); + $count = 0; + for ( $i = 0; $i < strlen($string); $i++ ) + { + if ( $string{$i} == $char ) + $count++; + } + return $count; +} + +/** + * Returns the number of lines in a string. + * @param string String to check + * @return int + */ + +function get_line_count($string) +{ + return ( get_char_count($string, "\n") ) + 1; +} + //die('
Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'
'); ?> diff -r 8d0e3a5a6990 -r 66732bd4532c includes/lang.php --- a/includes/lang.php Thu Jan 24 22:14:40 2008 -0500 +++ b/includes/lang.php Sat Jan 26 11:51:19 2008 -0500 @@ -456,6 +456,22 @@ function get($string_id, $substitutions = false) { + if ( !is_array($substitutions) ) + $substitutions = array(); + return $this->substitute($this->get_uncensored($string_id), $substitutions); + } + + /** + * The same as get(), but does not perform any substitution or filtering. Used in get() (of course) and in the admin panel, where + * strings are updated only if they were changed. + * + * @param string ID of the string to fetch. This will always be in the format of category_stringid. + * @param array Optional. Associative array of substitutions. + * @return string + */ + + function get_uncensored($string_id, $substitutions = false) + { // Extract the category and string ID $category = substr($string_id, 0, ( strpos($string_id, '_') )); $string_name = substr($string_id, ( strpos($string_id, '_') + 1 )); @@ -486,7 +502,7 @@ { if ( !is_object($this->default) ) $this->default = new Language($lang_default); - return $this->default->get($string_id, $substitutions); + return $this->default->get_uncensored($string_id); } } } @@ -496,12 +512,7 @@ return $string_id; } // Found it! - // Perform substitutions. - // if ( is_array($substitutions) ) - // die('
' . print_r($substitutions, true) . '
'); - if ( !is_array($substitutions) ) - $substitutions = array(); - return $this->substitute($string, $substitutions); + return $string; } /** diff -r 8d0e3a5a6990 -r 66732bd4532c index.php --- a/index.php Thu Jan 24 22:14:40 2008 -0500 +++ b/index.php Sat Jan 26 11:51:19 2008 -0500 @@ -19,7 +19,7 @@ define('ENANO_INTERFACE_INDEX', ''); // For the mighty and brave. - define('ENANO_DEBUG', ''); + // define('ENANO_DEBUG', ''); // Set up gzip encoding before any output is sent diff -r 8d0e3a5a6990 -r 66732bd4532c language/english/admin.json --- a/language/english/admin.json Thu Jan 24 22:14:40 2008 -0500 +++ b/language/english/admin.json Sat Jan 26 11:51:19 2008 -0500 @@ -443,12 +443,60 @@ btn_create_backup: 'Create backup', }, acplm: { + // Language installation heading_install: 'Languages available for installation', - col_lang_code: 'ID', + col_lang_id: 'ID', + col_lang_code: 'Shorthand code', col_lang_name: 'Language name (native)', col_lang_name_eng: 'Language name (English)', btn_install_language: 'Install', msg_lang_install_success: 'The language pack %lang_name% has been installed.', + + // Editor portal + heading_editor_portal: 'Edit installed languages', + portal_btn_edit: 'Modify', + portal_btn_unin: 'Uninstall', + + // Properties table + heading_modify: 'Edit language info', + th_lang_basic: 'Basic language properties', + field_lang_name_native: 'Language name (native):', + field_lang_name_english: 'Language name (in English):', + field_lang_code: 'Shorthand code:', + field_lang_code_hint: 'You can\'t change this because it needs to be compliant with ISO 639-3.', + msg_basic_save_success: 'Changes saved.', + + // String editor portal + heading_edit_strings_portal: 'Edit strings', + msg_edit_strings_portal_intro: 'You can edit the actual language strings used in this language. Be sure to preserve any variables (in the format of %variable_name%) even if you\'re translating a language. If you\'re translating all of Enano into a new language, you should edit the JSON files instead of using this console, so that comments in the language files can be preserved.', + btn_edit_strings_portal: 'Edit strings »', + + // Re-import button and explanation + heading_reimport_portal: 'Re-import this language', + msg_reimport_portal_intro: 'If you accidentally changed a lot of strings, you can re-import this language from the original language files. This will destroy any modifications you have made to the default set of strings, but any strings you\'ve added will be preserved. This is almost the same effect as re-installing the language. Don\'t stop this process while it\'s running, the re-import can take a long time.', + btn_reimport: 'Re-import language', + msg_reimport_success: 'The language was re-imported successfully. All Enano preset strings for this language have been restored.', + + // String editor + editor_heading: 'Editing category: %cat_name%', + editor_col_string_name: 'String name', + editor_col_string_content: 'String', + editor_btn_revert: 'Revert', + editor_btn_cancel: 'Cancel', + msg_string_save_success: 'Your changes have been saved.', + + // Backup interface + heading_backup: 'Backup language', + backup_intro: 'You can back up this language to make preserving custom strings easier if you ever migrate your Enano installation or re-install. Backed-up language files can be restored by using FTP or equivalent to copy the backup file to the language\'s folder and renaming it to "backup.json".', + btn_create_backup: 'Download backup', + + // Uninstaller + uninstall_confirm_title: 'Confirm uninstallation of language', + uninstall_confirm_body: 'Do you really want to uninstall this language? If you continue, all users that have selected this language will be reset to use the default. It is recommended that you create a backup of this language before you uninstall it if you have changed any strings.', + btn_uninstall_confirm: 'Confirm uninstallation', + btn_uninstall_cancel: 'Cancel', + err_cant_uninstall_default: 'You cannot uninstall the default language.', + msg_uninstall_success: 'The language has been uninstalled.', }, acppg: { // Main menu diff -r 8d0e3a5a6990 -r 66732bd4532c language/english/core.json --- a/language/english/core.json Thu Jan 24 22:14:40 2008 -0500 +++ b/language/english/core.json Sat Jan 26 11:51:19 2008 -0500 @@ -21,6 +21,7 @@ ], strings: { meta: { + meta: 'Category names and basic metadata', page: 'Page creation and control', comment: 'Comment display', onpage: 'On-page buttons and controls', diff -r 8d0e3a5a6990 -r 66732bd4532c language/english/install.json --- a/language/english/install.json Thu Jan 24 22:14:40 2008 -0500 +++ b/language/english/install.json Sat Jan 26 11:51:19 2008 -0500 @@ -196,21 +196,7 @@ modetitle_long: 'Website information', header_blurb: 'The next step is to enter some information about your website. You can always change this information later, using the administration panel.', - field_name_title: 'Website name', - field_name_body: 'The display name of your website. Allowed characters are uppercase and lowercase letters, numerals, and spaces. This must not be blank or "Enano".', - field_desc_title: 'Website description', - field_desc_body: 'This text will be shown below the name of your website.', - field_copyright_title: 'Copyright info', - field_copyright_body: 'This should be a one-line legal notice that will appear at the bottom of all your pages.', - field_wikimode_title: 'Wiki mode', - field_wikimode_body: 'This feature allows people to create and edit pages on your site. Enano keeps a history of all page modifications, and you can protect pages to prevent editing.', - field_wikimode_checkbox: 'Yes, make my website a wiki.', - field_urlscheme_title: 'URL scheme', - field_urlscheme_body: 'Choose how the page URLs will look. Depending on your server configuration, you may need to select the first option. If you don\'t know, select the first option, and you can always change it later.', - field_urlscheme_ugly: 'Standard URLs - compatible with any web server (www.example.com/index.php?title=Page_name)', - field_urlscheme_short: 'Short URLs - requires Apache with a PHP module (www.example.com/index.php/Page_name)', - field_urlscheme_tiny: 'Tiny URLs - requires Apache on Linux/Unix/BSD with PHP module and mod_rewrite enabled (www.example.com/Page_name)', - field_urlscheme_helplink: 'Which URL scheme should I choose?', + // Need l10n objective_verify: 'Verify that your site information is correct. Again, all of the above settings can be changed from the administration panel.', }, @@ -219,16 +205,7 @@ header_blurb: 'Next, enter your desired username and password. The account you create here will be used to administer your site.', modetitle_long: 'Administration login', - field_username_title: 'Administration username', - field_username_body: 'The administration username you will use to log into your site.
This cannot be "anonymous" or in the form of an IP address.', - field_password_title: 'Administration password:', - field_password_confirm: 'Enter it again to confirm:', - field_email_title: 'Your e-mail address:', - field_allowphp_title: 'Allow administrators to embed PHP code into pages:', - field_allowphp_body: 'Do not under any circumstances enable this option without reading these %important_notes%.', - field_allowphp_isi: 'important security implications', - field_allowphp_disabled: 'Disabled', - field_allowphp_enabled: 'Enabled', + // Need l10n aes_blurb: 'If your browser supports Javascript, the password you enter here will be encrypted with AES before it is sent to the server.', diff -r 8d0e3a5a6990 -r 66732bd4532c plugins/SpecialAdmin.php --- a/plugins/SpecialAdmin.php Thu Jan 24 22:14:40 2008 -0500 +++ b/plugins/SpecialAdmin.php Sat Jan 26 11:51:19 2008 -0500 @@ -48,6 +48,13 @@ require(ENANO_ROOT . '/plugins/admin/UserManager.php'); require(ENANO_ROOT . '/plugins/admin/LangManager.php'); +// For convenience and nothing more. +function acp_start_form() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + echo '
'; +} + // function names are IMPORTANT!!! The name pattern is: page__ function page_Admin_Home() { @@ -951,7 +958,7 @@ setConfig('max_file_size', $max_upload.''); } } - echo ''; + acp_start_form(); ?>

get('acpup_heading_main'); ?>

@@ -1051,7 +1058,7 @@

get('acpft_heading_main'); ?>

get('acpft_hint'); ?>

nslist['Special'].'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&' : '') .'module='.$paths->cpage['module']).'" method="post">'; + acp_start_form(); $c = -1; $t = -1; $cl = 'row1'; @@ -1458,7 +1465,7 @@ if(!$s) die('Error selecting name value: '.$db->get_error().'
SQL:
'.$q); $r = $db->fetchrow_num($s); $db->free_result(); - echo(''); + acp_start_form(); echo('
Theme name displayed to users:

Default stylesheet: + + + + + 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'); ?>