Ejemplo n.º 1
0
 public static function internalLinkCallback($oIdentifier)
 {
     $aValue = explode('/', $oIdentifier->getValue());
     $iId = array_shift($aValue);
     $oPage = PageQuery::create()->findPk($iId);
     if ($oPage) {
         $mManager = Manager::getManagerClassNormalized();
         if ($mManager !== "PreviewManager") {
             $mManager = "FrontendManager";
         }
         $sLink = self::getLink(array_merge($oPage->getFullPathArray(), $aValue), $mManager);
         return self::writeTagForIdentifier("a", array('href' => $sLink, 'title' => $oPage->getPageTitle(), 'rel' => 'internal', 'class' => 'internal_link'), $oIdentifier, null, $oPage);
     }
 }
Ejemplo n.º 2
0
 public static function link($mPath = false, $mManager = null, $aParameters = array(), $mLanguage = null, $bIncludeLanguage = null)
 {
     if ($mPath === null) {
         // Respect null-links
         return null;
     }
     if (!$mPath) {
         $mPath = array();
     }
     if (!is_array($mPath)) {
         $mPath = explode("/", $mPath);
     }
     $mManager = Manager::getManagerClassNormalized($mManager);
     $sPrefix = Manager::getPrefixForManager($mManager);
     if ($mLanguage === true || $mLanguage === false) {
         $bIncludeLanguage = $mLanguage;
         $mLanguage = null;
     }
     if ($bIncludeLanguage === null) {
         $bIncludeLanguage = $mManager::shouldIncludeLanguageInLink();
     }
     if ($bIncludeLanguage) {
         if ($mLanguage === null) {
             $mLanguage = Session::language(true);
         }
         if ($mLanguage instanceof Language) {
             array_unshift($mPath, $mLanguage->getPathPrefix());
         } else {
             if (is_string($mLanguage)) {
                 $mLanguage = LanguageQuery::create()->findPk($mLanguage)->getPathPrefix();
                 array_unshift($mPath, $mLanguage);
             }
         }
     }
     foreach ($mPath as $iKey => $sValue) {
         if ($sValue === null || $sValue === "") {
             unset($mPath[$iKey]);
         } else {
             $mPath[$iKey] = rawurlencode($sValue);
         }
     }
     if ($sPrefix !== null && $sPrefix !== "") {
         $sPrefix .= "/";
     } else {
         $sPrefix = '';
     }
     return MAIN_DIR_FE_PHP . $sPrefix . implode('/', $mPath) . self::prepareLinkParameters($aParameters);
 }
Ejemplo n.º 3
0
 /**
  * @param main template
  * description:
  * - @see config.yml section language_chooser
  * - use parameter replaced in method
  * @return Template The rendered language chooser
  */
 public static function getLanguageChooser($oMainTemplate)
 {
     $oTemplate = new Template(TemplateIdentifier::constructIdentifier('languages'), null, true);
     $oLanguageTemplate = new Template(Settings::getSetting("language_chooser", 'template', 'language'), array(DIRNAME_TEMPLATES, DIRNAME_NAVIGATION));
     $sLinkSeparator = Settings::getSetting("language_chooser", 'link_separator', ' | ');
     $oLanguageActiveTemplate = null;
     $bShowActiveLanguage = Settings::getSetting("language_chooser", 'show_active_language', false);
     $bIsPreview = Manager::getCurrentManager() instanceof PreviewManager;
     if ($bShowActiveLanguage) {
         if (Settings::getSetting("language_chooser", 'template_active', false) !== false) {
             $oLanguageActiveTemplate = new Template(Settings::getSetting("language_chooser", 'template_active', 'language_active'), array(DIRNAME_TEMPLATES, DIRNAME_NAVIGATION));
         } else {
             $oLanguageActiveTemplate = clone $oLanguageTemplate;
         }
     }
     // Find request variables
     $aParameters = array_diff_assoc($_REQUEST, $_COOKIE);
     unset($aParameters['path']);
     unset($aParameters['content_language']);
     // Check whether manager needs language to be included
     $bCurrentPathIncludesLanguage = call_user_func(array(Manager::getManagerClassNormalized(null), 'shouldIncludeLanguageInLink'));
     $aRequestPath = explode("/", Manager::getRequestedPath());
     $aLanguages = LanguageQuery::create()->filterByIsActive(true)->exclude($bShowActiveLanguage ? false : ($bIsPreview ? 'edit' : 'current'))->orderBySort()->find();
     foreach ($aLanguages as $i => $oLanguage) {
         $oLangTemplate = null;
         $oPageString = null;
         if ($oLanguage->getId() === Session::language()) {
             $oLangTemplate = $oLanguageActiveTemplate;
             $oLangTemplate->replaceIdentifier('class', 'active');
         } else {
             $oPageString = PageStringQuery::create()->filterByPage(FrontendManager::$CURRENT_PAGE)->filterByLanguageId($oLanguage->getId())->filterByIsInactive(false)->findOne();
             if ($oPageString === null) {
                 continue;
             }
             $oLangTemplate = clone $oLanguageTemplate;
         }
         // If language is included, replace it by language id and set include_language param to false
         if ($bCurrentPathIncludesLanguage) {
             $aRequestPath[0] = $oLanguage->getPathPrefix();
             $sLink = LinkUtil::link($aRequestPath, null, $aParameters, false);
         } else {
             $sLink = LinkUtil::link($aRequestPath, null, array_merge($aParameters, array('content_language' => $oLanguage->getId())));
         }
         $oLangTemplate->replaceIdentifier('link', $sLink);
         // Add alternate language links
         if ($oPageString) {
             ResourceIncluder::metaIncluder()->addCustomResource(array('template' => 'link', 'rel' => 'alternate', 'lang' => $oLanguage->getId(), 'location' => $sLink, 'title' => $oPageString->getPageTitle()));
         }
         $oLangTemplate->replaceIdentifier('id', $oLanguage->getId());
         $oLangTemplate->replaceIdentifier('name', $oLanguage->getLanguageName($oLanguage->getId()));
         $oLangTemplate->replaceIdentifier('name_in_current_lang', $oLanguage->getLanguageName());
         $oTemplate->replaceIdentifierMultiple('languages', $oLangTemplate, null, Template::NO_NEWLINE);
         if ($i + 1 < count($aLanguages)) {
             $oTemplate->replaceIdentifierMultiple('languages', $sLinkSeparator, null, Template::NO_HTML_ESCAPE | Template::NO_NEWLINE);
         }
     }
     return $oTemplate;
 }