/**
  * Test {@link urltitle_validate()}
  */
 function test_urltitle_validate()
 {
     global $current_locale;
     if (!can_convert_charsets('ISO-8859-1', 'UTF-8')) {
         echo 'Skipping tests (cannot convert charsets)...<br />', "\n";
         return;
     }
     $this->MockDB->returns('get_results', array());
     // Make sure all locales are loaded
     locales_load_available_defs();
     $saved_current_locale = $current_locale;
     // For ISO-8859-1:
     $this->change_global('evo_charset', 'ISO-8859-1');
     // this will trigger "ä" => "ae".. (since iconv appears to handle "ä" in latin1 different to "ä" in utf8 - for locale "en-US")
     foreach (array(array('  ', ' :: çà c\'est "VRAIMENT" tôa! ', 'ca-c-est-vraiment-toa'), array('  ', ' :: çà c\'est_tôa! ', 'ca-c-est_toa'), array('  ', ' :: çà * c\'est_tôa! * *', 'ca-c-est_toa'), array('', 'La différence entre abbr...-452', 'la-difference-entre-abbr-452'), array('', 'La différence entre abbr_452', 'la-difference-entre-abbr-452'), array('', 'La subtile différence abbr..._452', 'la-subtile-difference-abbr-452'), array('', 'Äöüùé', 'aeoeueue')) as $test) {
         $this->assertEqual(urltitle_validate($test[0], convert_charset($test[1], 'ISO-8859-1', 'UTF-8')), $test[2]);
     }
     // For UTF-8:
     $this->change_global('evo_charset', 'UTF-8');
     foreach (array(array('', 'Äöüùé', 0, false, 'post_urltitle', 'post_ID', 'T_items__item', 'de-DE', 'aeoeueue'), array('', 'Založte si svůj vlastní blog za pomoci TextPattern', 'zalozte-si-svuj-vlastni-blog'), array('', 'Zalo&#382;te si sv&#367;j vlastní blog za pomoci TextPattern', 'zalozte-si-svuj-vlastni-blog'), array('', 'русский текст   в ссылках', 'russkij-tekst-v-ssylkax', 'ru-RU'), array('', 'Äöüùé', 'aouue')) as $test) {
         if (isset($test[4])) {
             // Special case for de-DE locale
             // This test is broken
             //$this->assertEqual( call_user_func_array( 'urltitle_validate', array_slice( $test, 0, -1 ) ), array_pop( $test ) );
         } else {
             if (isset($test[3])) {
                 // Check transliteration for specified locale
                 $current_locale = $test[3];
             }
             $this->assertEqual(urltitle_validate($test[0], $test[1]), $test[2]);
             $current_locale = $saved_current_locale;
             // restore
         }
     }
 }
Beispiel #2
0
     if (!isset($locales[$current_locale])) {
         // activate default locale
         locale_activate($default_locale);
     }
     // reset default_locale
     $Settings->set('default_locale', $default_locale);
     $Settings->dbupdate();
     // Reload locales from files:
     unset($locales);
     include $conf_path . '_locales.php';
     if (file_exists($conf_path . '_overrides_TEST.php')) {
         // also overwrite settings again (just in case we override some local erelated things):
         include $conf_path . '_overrides_TEST.php';
     }
     // Load all available locale defintions from locale folders:
     locales_load_available_defs();
     // Reenable default locale
     locale_insert_default();
     $Messages->add(T_('Locale definitions reset to defaults. (<code>/conf/_locales.php</code>)'), 'success');
     // Redirect so that a reload doesn't write to the DB twice:
     header_redirect('?ctrl=locales' . ($loc_transinfo ? '&loc_transinfo=1' : ''), 303);
     // Will EXIT
     // We have EXITed already at this point!!
     break;
 case 'extract':
     // EXTRACT locale
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('locales');
     // Check permission:
     $current_User->check_perm('options', 'edit', true);
     // Get PO file for that edit_locale:
Beispiel #3
0
/**
 * load locales from DB into $locales array. Also sets $default_locale.
 *
 * @return mixed new default locale on succes, false on failure
 */
function locale_overwritefromDB()
{
    global $DB, $locales, $default_locale, $Settings, $Debuglog, $Messages;
    // Load all locales from disk to get 'charset' insrtad of DB
    locales_load_available_defs();
    $usedprios = array();
    // remember which priorities are used already.
    $priocounter = 0;
    $query = 'SELECT
						loc_locale, loc_datefmt, loc_timefmt, loc_shorttimefmt, loc_startofweek,
						loc_name, loc_messages, loc_priority, loc_transliteration_map, loc_enabled
						FROM T_locales ORDER BY loc_priority';
    $ctrl = isset($_GET['ctrl']) ? $_GET['ctrl'] : '';
    $priocounter_max = 0;
    $wrong_locales = array();
    $wrong_default_locale = '';
    foreach ($DB->get_results($query, ARRAY_A) as $row) {
        // Loop through loaded locales:
        if ($row['loc_priority'] == $priocounter) {
            // priority conflict (the same)
            $priocounter++;
        } else {
            $priocounter = $row['loc_priority'];
        }
        $priocounter_max = $priocounter;
        //remember that we used this
        $usedprios[] = $priocounter;
        $transliteration_map = '';
        // Try to unserialize the value
        if (($r = @unserialize(@base64_decode($row['loc_transliteration_map']))) !== false) {
            $transliteration_map = $r;
        }
        if (isset($locales[$row['loc_locale']], $locales[$row['loc_locale']]['charset'])) {
            // Use charset from locale file if such file exists on disk
            $loc_charset = $locales[$row['loc_locale']]['charset'];
        } else {
            // Use charset from DB
            $loc_charset = 'utf-8';
        }
        if (($ctrl == 'locales' || $ctrl == 'regional') && $row['loc_enabled'] && $loc_charset != 'utf-8') {
            // Check wrong non utf-8 locales in order to deactivate them
            $Messages->add(sprintf(T_('The locale %s has been deactivated because it\'s not UTF-8'), '<b>' . $row['loc_locale'] . '</b>'));
            if ($Settings->get('default_locale') == $row['loc_locale'] && $default_locale != $row['loc_locale']) {
                // Change main locale to default
                $wrong_default_locale = $row['loc_locale'];
                $Messages->add(sprintf(T_('The main locale was no longer valid and has been set to %s.'), '<b>' . $default_locale . '</b>'));
            }
            $wrong_locales[] = $row['loc_locale'];
            $row['loc_enabled'] = 0;
        }
        $locales[$row['loc_locale']] = array('charset' => $loc_charset, 'datefmt' => $row['loc_datefmt'], 'timefmt' => $row['loc_timefmt'], 'shorttimefmt' => $row['loc_shorttimefmt'], 'startofweek' => $row['loc_startofweek'], 'name' => $row['loc_name'], 'messages' => $row['loc_messages'], 'transliteration_map' => $transliteration_map, 'priority' => $priocounter, 'enabled' => $row['loc_enabled'], 'fromdb' => 1);
    }
    if (count($wrong_locales)) {
        // Deactivate locales that have wrong charset
        $DB->query('UPDATE T_locales
			  SET loc_enabled = 0
			WHERE loc_locale IN( ' . $DB->quote($wrong_locales) . ' )');
        if (!empty($wrong_default_locale)) {
            // If main locale is wring we sgould updated it to default and use this for all users and blogs that used this wrong locale
            $Settings->set('default_locale', $default_locale);
            $Settings->dbupdate();
            $DB->query('UPDATE T_users
				  SET user_locale = ' . $DB->quote($default_locale) . '
				WHERE user_locale = ' . $DB->quote($wrong_default_locale));
            $DB->query('UPDATE T_blogs
				  SET blog_locale = ' . $DB->quote($default_locale) . '
				WHERE blog_locale = ' . $DB->quote($wrong_default_locale));
        }
    }
    foreach ($locales as $l_ley => $locale) {
        // Change priority of non-db locales to put them at the end of list
        if (empty($locale['fromdb']) && $locale['priority'] < $priocounter_max) {
            $locales[$l_ley]['priority'] = $priocounter_max + $locale['priority'];
        }
    }
    // set default priorities, if nothing was set in DB.
    // Missing "priority gaps" will get filled here.
    if ($DB->num_rows != count($locales)) {
        // we have locales from conf file that need a priority
        $priocounter = 1;
        foreach ($locales as $lkey => $lval) {
            // Loop through memory locales:
            if (!isset($lval['priority'])) {
                // Found one that has no assigned priority
                while (in_array($priocounter, $usedprios)) {
                    $priocounter++;
                }
                // Priocounter has max value
                $locales[$lkey]['priority'] = $priocounter;
                $usedprios[] = $priocounter;
            }
        }
    }
    // sort by priority
    uasort($locales, 'locale_priosort');
    // overwrite default_locale from DB settings - if enabled.
    // Checks also if previous $default_locale is enabled. Defaults to en-EU, even if not enabled.
    $locale_fromdb = $Settings->get('default_locale');
    if ($locale_fromdb) {
        if (!isset($locales[$locale_fromdb])) {
            $Debuglog->add('Default locale [' . $locale_fromdb . '] from general settings is not available.', 'locale');
            return false;
        } else {
            $default_locale = $locale_fromdb;
            return $default_locale;
        }
    }
}