Example #1
0
function _l10n_make_textpattern_name($full_code)
{
    if (is_string($full_code)) {
        $code = $full_code;
    } else {
        if (isset($full_code['long'])) {
            $code = $full_code['long'];
        } elseif (isset($full_code['short'])) {
            $code = $full_code['short'];
        } else {
            $error = "_l10n_make_textpattern_name() given an invalid input value {$full_code}";
            trigger_error($error, E_USER_ERROR);
        }
    }
    if (strlen($code) < 2) {
        trigger_error("{$code} is too short!", E_USER_ERROR);
    }
    $result = _l10n_clean_sql_name(L10N_RENDITION_TABLE_PREFIX . $code);
    return $result;
}
 function prefs_save_cb($event = '', $step = '')
 {
     #
     #	Update the set of translation tables based on any changes made to the site
     # languages...
     #
     $langs = MLPLanguageHandler::get_site_langs();
     $tables = getThings('show tables like \'' . PFX . L10N_RENDITION_TABLE_PREFIX . '%\'');
     #
     #	Expand language names to match translation table name format...
     #
     $names = array();
     if (count($langs)) {
         foreach ($langs as $name) {
             $name = PFX . L10N_RENDITION_TABLE_PREFIX . $name;
             $names[] = _l10n_clean_sql_name($name);
         }
     }
     #
     #	Perform the diffs and detect additions/deletions needed...
     #
     $diff_names_tables = array_diff($names, $tables);
     $diff_tables_names = array_diff($tables, $names);
     $add_count = count($diff_names_tables);
     $del_count = count($diff_tables_names);
     if ($add_count) {
         foreach ($diff_names_tables as $full_name) {
             #
             #	Get the language code...
             #
             $lang = str_replace(PFX . L10N_RENDITION_TABLE_PREFIX, '', $full_name);
             $lang = strtr($lang, array('_' => '-'));
             if (!MLPLanguageHandler::is_valid_code($lang)) {
                 continue;
             }
             #
             #	Add language tables as needed and populate them as far as possible...
             #
             $indexes = "(PRIMARY KEY  (`ID`), KEY `categories_idx` (`Category1`(10),`Category2`(10)), KEY `Posted` (`Posted`), FULLTEXT KEY `searching` (`Title`,`Body`))";
             $sql = "create table `{$full_name}` {$indexes} ENGINE=MyISAM select * from `" . PFX . "textpattern` where " . L10N_COL_LANG . "='{$lang}'";
             $ok = @safe_query($sql);
             #
             #	Add fields for this language...
             #
             _l10n_walk_mappings(array(&$this, 'add_field'), $lang);
             #
             #	Conditionally extend the snip-site_slogan to include the new language...
             #
             global $prefs;
             $exists = @safe_row('*', 'txp_lang', "`lang`='{$lang}' AND `name`='snip-site_slogan'");
             $exists = !empty($exists);
             if (!$exists and @$prefs['site_slogan'] === 'My pithy slogan') {
                 $langname = MLPLanguageHandler::get_native_name_of_lang($lang);
                 MLPStrings::store_translation_of_string('snip-site_slogan', 'public', $lang, $langname);
             }
         }
     }
     if ($del_count) {
         foreach ($diff_tables_names as $full_name) {
             #
             #	Drop language tables that are no longer needed...
             #
             $sql = 'drop table `' . $full_name . '`';
             $ok = @safe_query($sql);
             #
             #	Get the language code...
             #
             $lang = str_replace(PFX . L10N_RENDITION_TABLE_PREFIX, '', $full_name);
             $lang = strtr($lang, array('_' => '-'));
             if (!MLPLanguageHandler::is_valid_code($lang)) {
                 continue;
             }
             #
             #	Remove fields for this language...
             #
             _l10n_walk_mappings(array(&$this, 'drop_field'), $lang);
         }
     }
     #
     #	Process the new default language ... copy fields as needed...
     #
     _l10n_walk_mappings(array(&$this, 'copy_defaults'), $langs[0]);
 }