public function execute(array &$param_pool = null)
 {
     $result = new XMLElement('fl-languages');
     $main_lang = FLang::getMainLang();
     $crt_lc = FLang::getLangCode();
     $lang_names = Languages::all()->listAll();
     $langs = FLang::getLangs();
     $current_language_xml = new XMLElement('current-language', $lang_names[$crt_lc] ? $lang_names[$crt_lc]['name'] : $crt_lc);
     $current_language_xml->setAttribute('handle', $crt_lc);
     $current_language_xml->setAttribute('language', FLang::getLang());
     $current_language_xml->setAttribute('region', FLang::getReg());
     $result->appendChild($current_language_xml);
     $supported_languages_xml = new XMLElement('supported-languages');
     foreach ($langs as $lc) {
         $lang_xml = new XMLElement('item', $lang_names[$lc] ? $lang_names[$lc]['name'] : $lc);
         $lang_xml->setAttribute('handle', $lc);
         if ($lc === $main_lang) {
             $lang_xml->setAttribute('main', 'yes');
         }
         $supported_languages_xml->appendChild($lang_xml);
     }
     $result->appendChild($supported_languages_xml);
     return $result;
 }
 /**
  * Save options from Preferences page
  *
  * @param array $context
  *
  * @return boolean
  */
 public function dSave(array $context)
 {
     $valid = true;
     $data =& $context['settings']['frontend_localisation'];
     $errors = array();
     if (!$this->meetDependencies(true)) {
         return $valid;
     }
     /* Language codes */
     $old_langs = FLang::getLangs();
     if (!FLang::setLangs($data['langs'])) {
         $valid = false;
         $errors['langs'] = __('Please fill at least one valid language code.');
     }
     $new_langs = FLang::getLangs();
     unset($data['langs']);
     Symphony::Configuration()->set('langs', implode(',', $new_langs), 'frontend_localisation');
     /**
      * When saving Preferences, supplies the old_languages and new_languages arrays.
      *
      * @delegate FLSavePreferences
      * @since    1.4
      *
      * @param string $context   - '/extensions/frontend_localisation/'
      * @param array  $context   - the original context from @delegate Save
      * @param array  $old_langs - old language codes
      * @param array  $new_langs - new language codes
      */
     Symphony::ExtensionManager()->notifyMembers('FLSavePreferences', '/extensions/frontend_localisation/', array('context' => $context, 'old_lang' => $old_langs, 'new_langs' => $new_langs));
     /* Main language */
     if (!FLang::setMainLang($data['main_lang'])) {
         if (!empty($old_langs) || !(isset($new_langs[0]) && FLang::setMainLang($new_langs[0]))) {
             $valid = false;
             $errors['main_lang'] = __('Invalid language code.');
         }
     }
     $main_lang = FLang::getMainLang();
     unset($data['main_lang']);
     Symphony::Configuration()->set('main_lang', $main_lang, 'frontend_localisation');
     Symphony::Configuration()->write();
     if (!empty($errors)) {
         $context['errors']['frontend_localisation'] = $errors;
     }
     return $valid;
 }
Ejemplo n.º 3
0
 /**
  * For all Pages, fill the new added columns with the page_data from $reference_language.
  *
  * @param array $langs - languages to set data for.
  *
  * @return boolean
  */
 private function _insertTestTitlesAndHandles($langs = array())
 {
     if (empty($langs)) {
         $langs = FLang::getLangs();
         // languages codes must exist
         if (empty($langs)) {
             return true;
         }
     }
     $main_lang = FLang::getMainLang();
     $pages_IDs = Symphony::Database()->fetchCol('id', 'SELECT `id` FROM `tbl_pages`');
     $query_fields = "`handle`,`title`,";
     foreach ($langs as $lc) {
         $query_fields .= "`plh_t-{$lc}`,";
         $query_fields .= "`plh_h-{$lc}`,";
     }
     foreach ($pages_IDs as $page_id) {
         $page_data = Symphony::Database()->fetch(sprintf("SELECT %s FROM `%s` WHERE `id` = '%s'", trim($query_fields, ','), self::DB_TABLE, $page_id));
         $title = $page_data[0]["title"];
         $handle = $page_data[0]["handle"];
         unset($page_data[0]["handle"], $page_data[0]["title"]);
         $fields = '';
         foreach ($page_data[0] as $key => $value) {
             if (empty($value)) {
                 $lc = substr($key, 6) !== $main_lang ? substr($key, 6) : '';
                 $new_value = strpos($key, '_t-') === false ? $lc . $handle : strtoupper($lc) . $title;
                 $fields .= " `{$key}` = '{$new_value}',";
             }
         }
         if (!empty($fields)) {
             $this->_query(sprintf("UPDATE `%s` SET %s WHERE `id` = '%s';", self::DB_TABLE, trim($fields, ','), $page_id));
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Sets a valid language code
  *
  * @static
  *
  * @param &$lang_code
  */
 private static function _setLangCode(&$lang_code)
 {
     if (empty($lang_code) || FLang::validateLangCode($lang_code) === false) {
         $lang_code = FLang::getMainLang();
     }
 }