/**
  * provides default parameters for the FileFinder::find() method
  *
  * @see FileFinder::find()
  * @return An array with the new locales found in the disk
  */
 function find()
 {
     // first find the new ones
     parent::find(Locales::getAvailableLocales(), "locale_*.php");
     // and then return them, if any
     return $this->getNew();
 }
 /**
  * Tries to match the prefered language out of the http_accept_language string 
  * with one of the available languages.
  *
  * @private
  * @param httpAcceptLanguage the value of $_SERVER['HTTP_ACCEPT_LANGUAGE']
  * @return Returns returns prefered language or false if no language matched.
  */
 function _matchHttpAcceptLanguages(&$httpAcceptLanguage)
 {
     $acceptedLanguages = explode(',', $httpAcceptLanguage);
     $availableLanguages =& Locales::getAvailableLocales();
     $primaryLanguageMatch = '';
     // we iterate through the array of languages sent by the UA and test every single
     // one against the array of available languages
     foreach ($acceptedLanguages as $acceptedLang) {
         // clean the string and strip it down to the language value (remove stuff like ";q=0.3")
         $acceptedLang = substr($acceptedLang, 0, strcspn($acceptedLang, ';'));
         if (strlen($acceptedLang) > 2) {
             // cut to primary language
             $primaryAcceptedLang = substr($acceptedLang, 0, 2);
         } else {
             $primaryAcceptedLang = $acceptedLang;
         }
         // this is where we start to iterate through available languages
         foreach ($availableLanguages as $availableLang) {
             if (stristr($availableLang, $acceptedLang) !== false) {
                 // we have a exact language match
                 return $availableLang;
             } elseif (stristr($availableLang, $primaryAcceptedLang) !== false && $primaryLanguageMatch == '') {
                 // we found the first primary language match!
                 $primaryLanguageMatch = $availableLang;
             }
         }
     }
     // foreach
     if ($primaryLanguageMatch != '') {
         return $primaryLanguageMatch;
     } else {
         return false;
     }
 }
 /**
  * @private
  */
 function _deleteLocales()
 {
     $locales = new Locales();
     // if there is only one locale available in the system, we should
     // not allow to remove it either
     if (count($locales->getAvailableLocales()) == 1) {
         $this->_view = new AdminSiteLocalesListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_deleting_only_locale"));
         $this->setCommonData();
         return false;
     }
     // keep the value of the default locale because plog should not allow
     // to remove the default one
     $defaultLocale = $this->_config->getValue("default_locale");
     $errorMessage = "";
     $successMessage = "";
     $totalOk = 0;
     foreach ($this->_localeIds as $localeId) {
         if ($localeId != $defaultLocale) {
             if ($locales->removeLocale($localeId)) {
                 $totalOk++;
                 if ($totalOk < 2) {
                     $successMessage = $this->_locale->pr("locale_deleted_ok", $localeId);
                 } else {
                     $successMessage = $this->_locale->pr("locales_deleted_ok", $totalOk);
                 }
             } else {
                 $errorMessage .= $this->_locale->pr("error_deleting_locale", $localeId) . "<br/>";
             }
         } else {
             $errorMessage .= $this->_locale->pr("error_locale_is_default", $localeId) . "<br/>";
         }
     }
     $this->_view = new AdminSiteLocalesListView($this->_blogInfo);
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     return true;
 }
 function validate()
 {
     // all the seettings come from a very nice array from the html form
     $this->_newConfigOpts = array();
     $this->_newConfigOpts = $this->_request->getValue("config");
     // the xmlrpc_ping_hosts requires special treatment, since we need to
     // split the input returned from the textbox into an array
     if (isset($this->_newConfigOpts["xmlrpc_ping_hosts"])) {
         $array = array();
         foreach (explode("\r\n", $this->_newConfigOpts["xmlrpc_ping_hosts"]) as $host) {
             trim($host);
             if ($host != "" && $host != "\r\n" && $host != "\r" && $host != "\n") {
                 array_push($array, $host);
             }
         }
         $this->_newConfigOpts["xmlrpc_ping_hosts"] = $array;
     }
     // the 'locales' and 'arrays' settings are not coming from the request
     $configOpts = $this->_config->getAsArray();
     $locales = new Locales();
     $this->_newConfigOpts["locales"] = $locales->getAvailableLocales();
     $this->_newConfigOpts["templates"] = $configOpts["templates"];
     return true;
 }
예제 #5
0
 /**
  * Returns an array with all the locales available in the system.
  *
  * This is quite memory and disk-intensive since we are loading a lot of lines
  * from possibly a lot of files!!!
  *
  * @return Returns an array of Locale objects, which represent *all* the locales
  * that have been installed in this system.
  * @static
  */
 function getLocales()
 {
     $localeCodes = Locales::getAvailableLocales();
     $locales = array();
     foreach ($localeCodes as $code) {
         array_push($locales, new Locale($code));
     }
     return $locales;
 }