Ejemplo n.º 1
0
 /**
  * Generate file i18nl10n meta wizard
  *
  * @return string
  */
 public function generate()
 {
     $strForm = parent::generate();
     $arrAvailableLanguages = I18nl10n::getInstance()->getAvailableLanguages(true, true);
     $arrLanguages = array_intersect_key($this->getLanguages(), array_flip($arrAvailableLanguages));
     preg_match_all('@data-language="(.*?)"@', $strForm, $arrMatchTaken);
     $options = array('<option value="">-</option>');
     $taken = array();
     // Parse used languages
     foreach ($arrMatchTaken as $k => $v) {
         if ($k) {
             $taken[] = $v[0];
         }
     }
     // Set language options
     foreach ($arrLanguages as $k => $v) {
         $options[] = '<option value="' . $k . '"' . (in_array($k, $taken) ? ' disabled' : '') . '>' . $v . '</option>';
     }
     // Replace language select options
     $strForm = preg_replace('@(<select.*?>)(.*?)(<\\/select>)@', '${1}' . implode('', $options) . '${3}', $strForm);
     return $strForm;
 }
 /**
  * Generate the module
  *
  * @hooks ModuleI18nl10nLanguageSelection manipulate translation options
  */
 protected function compile()
 {
     global $objPage;
     $time = time();
     $items = array();
     $langNative = I18nl10n::getInstance()->getNativeLanguageNames();
     $sqlPublishedCondition = BE_USER_LOGGED_IN ? '' : " AND (start = '' OR start < {$time}) AND (stop = '' OR stop > {$time}) AND i18nl10n_published = 1 ";
     // Get all possible languages for this page tree
     $arrLanguages = I18nl10n::getInstance()->getLanguagesByRootId($objPage->rootId);
     $sql = "\n            SELECT *\n            FROM tl_page_i18nl10n\n            WHERE\n                pid = ?\n                AND language IN ( '" . implode("', '", $arrLanguages['languages']) . "' )\n               " . $sqlPublishedCondition;
     $arrTranslations = \Database::getInstance()->prepare($sql)->execute($objPage->id)->fetchAllassoc();
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['i18nl10nLanguageSelection']) && is_array($GLOBALS['TL_HOOKS']['i18nl10nLanguageSelection'])) {
         foreach ($GLOBALS['TL_HOOKS']['i18nl10nLanguageSelection'] as $callback) {
             $this->import($callback[0]);
             $arrTranslations = $this->{$callback}[0]->{$callback}[1]($arrTranslations);
         }
     }
     if (!empty($arrTranslations)) {
         $this->loadLanguageFile('languages');
         // Add default language
         if ($objPage->i18nl10n_published) {
             array_unshift($arrTranslations, array('id' => $objPage->id, 'language' => $objPage->rootLanguage, 'title' => $objPage->title, 'pageTitle' => $objPage->pageTitle, 'alias' => $objPage->alias));
         }
         // keep the order in $i18nl10nLanguages and assign to $items
         // only if page translation is found in database
         foreach ($arrLanguages['languages'] as $language) {
             // check if current language has not to be shown
             if ($language === $GLOBALS['TL_LANGUAGE'] && $this->i18nl10n_langHide === 1) {
                 continue;
             }
             // loop translations
             foreach ($arrTranslations as $row) {
                 // check if language is needed
                 if ($row['language'] === $language) {
                     array_push($items, array('id' => empty($row['pid']) ? $objPage->id : $row['pid'], 'alias' => empty($row['alias']) ? $objPage->alias : $row['alias'], 'title' => empty($row['title']) ? $objPage->title : $row['title'], 'pageTitle' => empty($row['pageTitle']) ? $objPage->pageTitle : $row['pageTitle'], 'language' => $language, 'isActive' => $language === $GLOBALS['TL_LANGUAGE'], 'forceRowLanguage' => true));
                     break;
                 }
             }
         }
         // Add classes first and last
         $last = count($items) - 1;
         $items[0]['class'] = trim($items[0]['class'] . ' first');
         $items[$last]['class'] = trim($items[$last]['class'] . ' last');
         $objTemplate = new \BackendTemplate($this->i18nl10n_langTpl);
         $objTemplate->type = get_class($this);
         $objTemplate->items = $items;
         $objTemplate->languages = $langNative;
     }
     // Add stylesheets
     if ($this->i18nl10n_langStyle !== 'disable') {
         $assetsUrl = 'system/modules/i18nl10n/assets/';
         // Add global and selected style
         $GLOBALS['TL_CSS'][] = $assetsUrl . 'css/i18nl10n_lang.css';
         // Add additional styles if needed
         if (in_array($this->i18nl10n_langStyle, array('text', 'image', 'iso'))) {
             $GLOBALS['TL_CSS'][] = $assetsUrl . 'css/i18nl10n_lang_' . $this->i18nl10n_langStyle . '.css';
         }
     }
     // Create URI params
     $strUriParams = '';
     foreach ($_GET as $key => $value) {
         if ($key === 'id') {
             continue;
         }
         $strUriParams .= '/' . $key . '/' . \Input::get($key);
     }
     $this->Template->items = !empty($items) && isset($objTemplate) ? $objTemplate->parse() : '';
     $this->Template->uriParams = $strUriParams;
 }
Ejemplo n.º 3
0
 /**
  * Add alternative language links to page head
  *
  * @param   \PageModel  $objPage
  */
 private function addAlternativeLanguageLinks($objPage)
 {
     $arrPages = I18nl10n::getInstance()->getLanguageAlternativesByPage($objPage);
     $links = array();
     foreach ($arrPages as $page) {
         $page['forceRowLanguage'] = true;
         $strUrl = \Controller::generateFrontendUrl($page);
         $links[] = "<link rel=\"alternate\" href=\"/{$strUrl}\" hreflang=\"{$page['language']}\" title=\"{$page['title']}\" />";
     }
     // Append alternative links to page header
     $GLOBALS['TL_HEAD'] = array_merge((array) $GLOBALS['TL_HEAD'], $links);
 }
Ejemplo n.º 4
0
 /**
  * Set dns field eval to mandatory
  *
  * @see DC_File::__construct
  */
 public function setDnsMandatory()
 {
     if (I18nl10n::getInstance()->countRootPages() > 1) {
         // If there is already a root page, a domain name must be set
         $GLOBALS['TL_DCA']['tl_page']['fields']['dns']['eval']['mandatory'] = true;
     }
 }
Ejemplo n.º 5
0
 /**
  * Get available languages by content element id
  *
  * - Filter by permission
  * - Add a blank option (by permission)
  *
  * @param   integer     $id
  * @param   string      $strParentTable
  *
  * @return  array
  */
 private function getLanguageOptionsByContentId($id, $strParentTable = 'tl_article')
 {
     if ($strParentTable === 'tl_article') {
         $arrPageId = $this->Database->prepare("SELECT pid as id FROM tl_article WHERE id = (SELECT pid FROM tl_content WHERE id = ?)")->limit(1)->execute($id)->fetchAssoc();
         $i18nl10nLanguages = I18nl10n::getInstance()->getLanguagesByPageId($arrPageId['id'], 'tl_page');
         $strIdentifier = $i18nl10nLanguages['rootId'] . '::';
         // Create base and add neutral (*) language if admin or has permission
         $arrOptions = $this->User->isAdmin || in_array($strIdentifier . '*', (array) $this->User->i18nl10n_languages) ? array('') : array();
         // Add languages based on permissions
         if ($this->User->isAdmin) {
             array_insert($arrOptions, 1, $i18nl10nLanguages['languages']);
         } else {
             foreach ($i18nl10nLanguages['languages'] as $language) {
                 if (in_array($strIdentifier . $language, (array) $this->User->i18nl10n_languages)) {
                     $arrOptions[] = $language;
                 }
             }
         }
     } else {
         $arrOptions = I18nl10n::getInstance()->getAvailableLanguages(true, true);
         // Add neutral option if available
         // @todo: move to method
         if ($this->User->isAdmin || strpos(implode((array) $this->User->i18nl10n_languages), '::*') !== false) {
             array_unshift($arrOptions, '');
         }
     }
     return $arrOptions;
 }
Ejemplo n.º 6
0
 /**
  * Create language options based on root page, already used languages and user permissions
  *
  * @param DataContainer $dc
  *
  * @return array
  */
 public function languageOptions(DataContainer $dc)
 {
     // Create identifier string for permission test
     $objFallbackPage = \PageModel::findWithDetails($dc->activeRecord->pid);
     $rootId = $objFallbackPage->rootId;
     $strIdentifier = $rootId . '::';
     // Set variables
     $arrLanguages = $GLOBALS['TL_LANG']['LNG'];
     $arrOptions = array();
     $id = $dc->activeRecord->id;
     $i18nl10nLanguages = I18nl10n::getInstance()->getLanguagesByPageId($id, 'tl_page_i18nl10n', false);
     // Get already used languages
     $arrSiblingLanguages = $this->Database->prepare('SELECT GROUP_CONCAT(language) as language FROM tl_page_i18nl10n WHERE pid = ? && id != ?')->execute($dc->activeRecord->pid, $id)->fetchAssoc();
     $arrSiblingLanguages = explode(',', $arrSiblingLanguages['language']);
     // Create options array base on root page languages and user permission
     foreach ($i18nl10nLanguages['localizations'] as $language) {
         if (!in_array($language, $arrSiblingLanguages) && ($this->User->isAdmin || in_array($strIdentifier . $language, (array) $this->User->i18nl10n_languages))) {
             $arrOptions[$language] = $arrLanguages[$language];
         }
     }
     return $arrOptions;
 }