public function execute(&$param_pool) { $result = new XMLElement($this->dsParamROOTELEMENT); $type_sql = $parent_sql = null; if (trim($this->dsParamFILTERS['type']) != '') { $type_sql = $this->__processNavigationTypeFilter($this->dsParamFILTERS['type'], $this->__determineFilterType($this->dsParamFILTERS['type'])); } if (trim($this->dsParamFILTERS['parent']) != '') { $parent_sql = $this->__processNavigationParentFilter($this->dsParamFILTERS['parent']); } $query_fields = ""; $qf = ""; foreach (FLang::getLangs() as $lc) { $qf .= "`plh_t-{$lc}`,"; $qf .= "`plh_h-{$lc}`,"; } // Build the Query appending the Parent and/or Type WHERE clauses $query = sprintf("\n\t\t\t\t\tSELECT DISTINCT {$qf}p.id, p.title, p.handle, (SELECT COUNT(id) FROM `tbl_pages` WHERE parent = p.id) AS children\n\t\t\t\t\tFROM `tbl_pages` AS p\n\t\t\t\t\tLEFT JOIN `tbl_pages_types` AS pt ON (p.id = pt.page_id)\n\t\t\t\t\tWHERE 1 = 1\n\t\t\t\t\t%s\n\t\t\t\t\t%s\n\t\t\t\t\tORDER BY p.`sortorder` ASC\n\t\t\t\t", !is_null($parent_sql) ? $parent_sql : " AND p.parent IS NULL ", !is_null($type_sql) ? $type_sql : ""); $pages = Symphony::Database()->fetch($query); if (!is_array($pages) || empty($pages)) { if ($this->dsParamREDIRECTONEMPTY == 'yes') { throw new FrontendPageNotFoundException(); } $result->appendChild($this->__noRecordsFound()); } else { // Build an array of all the types so that the page's don't have to do // individual lookups. $page_types = PageManager::fetchAllPagesPageTypes(); foreach ($pages as $page) { $result->appendChild($this->__buildPageXML($page, $page_types, $qf)); } } return $result; }
public function grab(&$param_pool = null) { $result = new XMLElement('plh-page'); $langs = FLang::getLangs(); $fields = array('id', 'handle', 'parent'); foreach ($langs as $lc) { $fields[] = "`plh_t-{$lc}`"; $fields[] = "`plh_h-{$lc}`"; } $pages = array(); foreach (PageManager::fetch(null, $fields) as $page) { $pages[$page['id']] = $page; } $this->appendPage($pages, $this->_env['param']['current-page-id'], $langs, $result); return $result; }
/** * Process the data so it can be imported into the entry. * @param $value The value to import * @param $entry_id If a duplicate is found, an entry ID will be provided. * @return The data returned by the field object */ public function import($value, $entry_id = null) { // $languageCodes = $this->field->getSupportedLanguageCodes(); $languageCodes = FLang::getLangs(); $dataArr = unserialize($value); if ($dataArr == false) { // Content was not serialized, use this content for every language: $dataArr = array(); foreach ($languageCodes as $code) { $dataArr[$code] = $value; } } $newValue = array(); foreach ($languageCodes as $code) { if (isset($dataArr[$code])) { $newValue[$code] = $dataArr[$code]; } } $data = $this->field->processRawFieldData($newValue, $status, $message, false, $entry_id); return $data; }
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; }
public function enable() { return $this->__updateRewriteRules('create') && $this->__updateRewriteRules('edit', FLang::getLangs()); }
/** * 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; }
/** * 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; }