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;
 }
Example #2
0
 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;
 }
 /**
  * Save options from Preferences page
  *
  * @param array $context
  */
 public function dSave($context)
 {
     $new_language_codes = FLang::instance()->ld()->getSavedLanguages($context);
     $fields = Symphony::Database()->fetch('SELECT `field_id` FROM `tbl_fields_multilingualupload`');
     if ($fields) {
         // Foreach field check multilanguage values foreach language
         foreach ($fields as $field) {
             $entries_table = 'tbl_entries_data_' . $field["field_id"];
             $show_columns = Symphony::Database()->fetch("SHOW COLUMNS FROM `{$entries_table}` LIKE 'file-%'");
             $columns = array();
             if ($show_columns) {
                 foreach ($show_columns as $column) {
                     $language_code = substr($column['Field'], strlen($column['Field']) - 2);
                     // If not consolidate option AND column language_code not in supported languages codes -> Drop Column
                     if ($_POST['settings']['multilingual_upload']['consolidate'] !== 'yes' && !in_array($language_code, $new_language_codes)) {
                         Symphony::Database()->query("ALTER TABLE  `{$entries_table}` DROP COLUMN `file-{$language_code}`");
                         Symphony::Database()->query("ALTER TABLE  `{$entries_table}` DROP COLUMN `size-{$language_code}`");
                         Symphony::Database()->query("ALTER TABLE  `{$entries_table}` DROP COLUMN `mimetype-{$language_code}`");
                         Symphony::Database()->query("ALTER TABLE  `{$entries_table}` DROP COLUMN `meta-{$language_code}`");
                     } else {
                         $columns[] = $column['Field'];
                     }
                 }
             }
             // Add new fields
             foreach ($new_language_codes as $language_code) {
                 // If columna language_code dosen't exist in the laguange drop columns
                 if (!in_array('file-' . $language_code, $columns)) {
                     Symphony::Database()->query("ALTER TABLE  `{$entries_table}` ADD COLUMN `file-{$language_code}` varchar(255) default NULL");
                     Symphony::Database()->query("ALTER TABLE  `{$entries_table}` ADD COLUMN `size-{$language_code}` int(11) unsigned NULL");
                     Symphony::Database()->query("ALTER TABLE  `{$entries_table}` ADD COLUMN `mimetype-{$language_code}` varchar(50) default NULL");
                     Symphony::Database()->query("ALTER TABLE  `{$entries_table}` ADD COLUMN `meta-{$language_code}` varchar(255) default NULL");
                 }
             }
         }
     }
 }
 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;
 }
 /**
  * Set language codes
  *
  * @param $langs
  *
  * @return boolean
  */
 public static function setLangs($langs)
 {
     $langs = explode(',', General::sanitize($langs));
     // if no language codes, return false
     if ($langs === false || !is_array($langs)) {
         return false;
     }
     $langs = self::cleanLanguageCodes($langs);
     if (count($langs) === 0) {
         return false;
     }
     $new_codes = array();
     $all_codes = array_keys(Languages::all()->listAll());
     // only valid language codes are preserved
     foreach ($langs as $lc) {
         if (in_array($lc, $all_codes)) {
             $new_codes[] = $lc;
         }
     }
     // if no valid language codes, return false
     if (empty($new_codes)) {
         return false;
     }
     // store the new language codes
     self::$_langs = $new_codes;
     return true;
 }
 private function _getUniqueFilename($filename, $language_code = null)
 {
     if (empty($language_code) || !is_string($language_code)) {
         $language_code = FLang::instance()->referenceLanguage();
     }
     // since unix timestamp is 10 digits, the unique filename will be limited to ($crop+1+10) characters;
     $crop = '150';
     return preg_replace("/(.*)(\\.[^\\.]+)/e", "substr('\$1', 0, {$crop}).'-'.{$language_code}.'\$2'", $filename);
 }
 /**
  * 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();
     }
 }