コード例 #1
0
ファイル: I18nl10n.php プロジェクト: verstaerker/i18nl10n
 /**
  * Replace i18nl10n insert tags
  *
  * @param string $strTag
  * @param bool   $blnCache
  *
  * @return bool|string
  */
 public static function replaceI18nl10nInsertTags($strTag, $blnCache = true)
 {
     global $objPage;
     $arrArguments = explode('::', $strTag);
     if ($arrArguments[0] === 'i18nl10n' && $arrArguments[1] === 'link') {
         $objNextPage = I18nl10n::getInstance()->findL10nWithDetails($arrArguments[2], $GLOBALS['TL_LANGUAGE']);
         if ($objNextPage === null) {
             return false;
         }
         switch ($objNextPage->type) {
             case 'redirect':
                 $strUrl = parent::replaceInsertTags($objNextPage->url);
                 if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
                     $strUrl = \String::encodeEmail($strUrl);
                 }
                 break;
             case 'forward':
                 $intForwardId = $objNextPage->jumpTo ?: \PageModel::findFirstPublishedByPid($objNextPage->id)->current()->id;
                 $objNext = \PageModel::findWithDetails($intForwardId);
                 if ($objNext !== null) {
                     $strUrl = self::generateFrontendUrl($objNext->row(), null, '');
                     break;
                 }
                 // no break
             // no break
             default:
                 $strUrl = self::generateFrontendUrl($objNextPage->row(), null, '');
                 break;
         }
         $strName = $objNextPage->title;
         $strTarget = $objNextPage->target ? $objPage->outputFormat == 'xhtml' ? LINK_NEW_WINDOW : ' target="_blank"' : '';
         $strTitle = $objNextPage->pageTitle ?: $objNextPage->title;
         return sprintf('<a href="%s" title="%s"%s>%s</a>', $strUrl, specialchars($strTitle), $strTarget, specialchars($strName));
     }
     return false;
 }
コード例 #2
0
ファイル: I18nl10nHook.php プロジェクト: verstaerker/i18nl10n
 /**
  * replaceInsertTags hook
  *
  * @param $strTag
  *
  * @return bool|string
  */
 public function replaceInsertTags($strTag)
 {
     return I18nl10n::replaceI18nl10nInsertTags($strTag);
 }
コード例 #3
0
 /**
  * Replace title and pageTitle with translated equivalents
  * just before display them as menu.
  *
  * @param   Array   $items              The menu items on the current menu level
  * @param   Bool    [$blnUseFallback]   Keep original item if no translation found
  * @return  Array   $i18n_items
  */
 public function i18nl10nNavItems(array $items, $blnUseFallback = false)
 {
     if (empty($items)) {
         return false;
     }
     /**
      * Info:
      * Be aware that Contao 3.4.0 supports 'isActive' only for start pages
      * with the alias 'index'. See ticket #7562 (https://github.com/contao/core/issues/7562)
      */
     $arrLanguages = I18nl10n::getInstance()->getLanguagesByDomain();
     //get item ids
     $item_ids = array();
     foreach ($items as $row) {
         $item_ids[] = $row['id'];
     }
     $arrI18nItems = array();
     if ($GLOBALS['TL_LANGUAGE'] !== $arrLanguages['default']) {
         $time = time();
         $fields = 'alias,pid,title,pageTitle,description,url,language';
         $sqlPublishedCondition = $blnUseFallback || BE_USER_LOGGED_IN ? '' : " AND (start='' OR start < {$time}) AND (stop='' OR stop > {$time}) AND i18nl10n_published = 1 ";
         $sql = "\n                SELECT {$fields}\n                FROM tl_page_i18nl10n\n                WHERE\n                    " . $this->Database->findInSet('pid', $item_ids) . '
                 AND language = ?
                 ' . $sqlPublishedCondition;
         $arrLocalizedPages = $this->Database->prepare($sql)->limit(1000)->execute($GLOBALS['TL_LANGUAGE'])->fetchAllassoc();
         foreach ($items as $item) {
             $foundItem = false;
             foreach ($arrLocalizedPages as $row) {
                 // Update navigation items with localization values
                 if ($row['pid'] === $item['id']) {
                     $foundItem = true;
                     $alias = $row['alias'] ?: $item['alias'];
                     $item['alias'] = $alias;
                     $row['alias'] = $alias;
                     $item['language'] = $row['language'];
                     switch ($item['type']) {
                         case 'forward':
                             $intForwardId = $item['jumpTo'] ?: \PageModel::findFirstPublishedByPid($item['id'])->current()->id;
                             $arrPage = \PageModel::findWithDetails($intForwardId)->row();
                             $item['href'] = $this->generateFrontendUrl($arrPage);
                             break;
                         case 'redirect':
                             if ($row['url']) {
                                 $item['href'] = $row['url'];
                             }
                             break;
                         default:
                             $item['href'] = $this->generateFrontendUrl($item);
                             break;
                     }
                     $item['pageTitle'] = specialchars($row['pageTitle'], true);
                     $item['title'] = specialchars($row['title'], true);
                     $item['link'] = $item['title'];
                     $item['description'] = str_replace(array('\\n', '\\r'), array(' ', ''), specialchars($row['description']));
                     array_push($arrI18nItems, $item);
                 }
             }
             if ($blnUseFallback && !$foundItem) {
                 array_push($arrI18nItems, $item);
             }
         }
     } else {
         foreach ($items as $item) {
             if (!$blnUseFallback && $item['i18nl10n_published'] == '') {
                 continue;
             }
             array_push($arrI18nItems, $item);
         }
     }
     return $arrI18nItems;
 }