/** * Returns the URL object for a page * @param \Cx\Core\ContentManager\Model\Entity\Page $page Page to get the URL to * @param array $parameters (optional) HTTP GET parameters to append * @param string $protocol (optional) The protocol to use * @return \Cx\Core\Routing\Url Url object for the supplied page */ public static function fromPage($page, $parameters = array(), $protocol = '') { if ($protocol == '') { $protocol = ASCMS_PROTOCOL; } $host = \Env::get('config')['domainUrl']; $offset = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteOffsetPath(); $path = $page->getPath(); $langDir = \FWLanguage::getLanguageCodeById($page->getLang()); $getParams = ''; if (count($parameters)) { $paramArray = array(); foreach ($parameters as $key => $value) { $paramArray[] = $key . '=' . $value; } $getParams = '?' . implode('&', $paramArray); } return new Url($protocol . '://' . $host . $offset . '/' . $langDir . $path . $getParams, true); }
/** * Generates a list of pages pointing to $page * @param \Cx\Core\ContentManager\Model\Entity\Page $page Page to get referencing pages for * @param array $subPages (optional, by reference) Do not use, internal * @return array List of pages (ID as key, page object as value) */ protected function getPagesPointingTo($page, &$subPages = array()) { $cx = \Cx\Core\Core\Controller\Cx::instanciate(); $em = $cx->getDb()->getEntityManager(); $pageRepo = $em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $fallback_lang_codes = \FWLanguage::getFallbackLanguageArray(); $active_langs = \FWLanguage::getActiveFrontendLanguages(); // get all active languages and their fallbacks // $fallbacks[<langId>] = <fallsBackToLangId> // if <langId> has no fallback <fallsBackToLangId> will be null $fallbacks = array(); foreach ($active_langs as $lang) { $fallbacks[\FWLanguage::getLanguageCodeById($lang['id'])] = array_key_exists($lang['id'], $fallback_lang_codes) ? \FWLanguage::getLanguageCodeById($fallback_lang_codes[$lang['id']]) : null; } // get all symlinks and fallbacks to it $query = ' SELECT p FROM Cx\\Core\\ContentManager\\Model\\Entity\\Page p WHERE ( p.type = ?1 AND ( p.target LIKE ?2'; if ($page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION) { $query .= ' OR p.target LIKE ?3'; } $query .= ' ) ) OR ( p.type = ?4 AND p.node = ' . $page->getNode()->getId() . ' ) '; $q = $em->createQuery($query); $q->setParameter(1, 'symlink'); $q->setParameter('2', '%NODE_' . $page->getNode()->getId() . '%'); if ($page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION) { $q->setParameter('3', '%NODE_' . strtoupper($page->getModule()) . '%'); } $q->setParameter(4, 'fallback'); $result = $q->getResult(); if (!$result) { return $subPages; } foreach ($result as $subPage) { if ($subPage->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_SYMLINK) { $subPages[$subPage->getId()] = $subPage; } else { if ($subPage->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_FALLBACK) { // check if $subPage is a fallback to $page $targetLang = \FWLanguage::getLanguageCodeById($page->getLang()); $currentLang = \FWLanguage::getLanguageCodeById($subPage->getLang()); while ($currentLang && $currentLang != $targetLang) { $currentLang = $fallbacks[$currentLang]; } if ($currentLang && !isset($subPages[$subPage->getId()])) { $subPages[$subPage->getId()] = $subPage; // recurse! $this->getPagesPointingTo($subPage, $subPages); } } } } return $subPages; }
/** * Returns the type of the page as string. * * @param \Cx\Core\ContentManager\Model\Entity\Page $page * @return string $type */ public function getTypeByPage($page) { global $_CORELANG; switch ($page->getType()) { case \Cx\Core\ContentManager\Model\Entity\Page::TYPE_REDIRECT: $criteria = array('nodeIdShadowed' => $page->getTargetNodeId(), 'lang' => $page->getLang()); $targetPage = $this->findOneBy($criteria); $targetTitle = $targetPage ? $targetPage->getTitle() : $page->getTarget(); $type = $_CORELANG['TXT_CORE_CM_TYPE_REDIRECT'] . ': '; $type .= $targetTitle; break; case \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION: $type = $_CORELANG['TXT_CORE_CM_TYPE_APPLICATION'] . ': '; $type .= $page->getModule(); $type .= $page->getCmd() != '' ? ' | ' . $page->getCmd() : ''; break; case \Cx\Core\ContentManager\Model\Entity\Page::TYPE_FALLBACK: $fallbackLangId = \FWLanguage::getFallbackLanguageIdById($page->getLang()); if ($fallbackLangId == 0) { $fallbackLangId = \FWLanguage::getDefaultLangId(); } $type = $_CORELANG['TXT_CORE_CM_TYPE_FALLBACK'] . ' '; $type .= \FWLanguage::getLanguageCodeById($fallbackLangId); break; default: $type = $_CORELANG['TXT_CORE_CM_TYPE_CONTENT']; } return $type; }
/** * Fetch the application template of a content page. * @param \Cx\Core\ContentManager\Model\Entity\Page $page The page object of which to fetch the application template from * @param String $component Optional argument to specify the component to load the template from, instead of using the page's module-attribute * @param String $themeType Optional argument to specify the output channel * @return String The content of the application template */ public static function getContentTemplateOfPage($page, $component = null, $themeType = \Cx\Core\View\Model\Entity\Theme::THEME_TYPE_WEB) { try { $component = empty($component) ? $page->getModule() : $component; $cmd = !$page->getCmd() ? 'Default' : ucfirst($page->getCmd()); $customAppTemplate = !$page->getApplicationTemplate() ? $cmd . '.html' : $page->getApplicationTemplate(); $moduleFolderName = contrexx_isCoreModule($page->getModule()) ? 'core_modules' : 'modules'; $themeFolderName = \Env::get('init')->getCurrentThemesPath(); // use application template for all output channels if ($page->getUseCustomApplicationTemplateForAllChannels() && $page->getSkin()) { $themeRepo = new \Cx\Core\View\Model\Repository\ThemeRepository(); $themeFolderName = $themeRepo->findById($page->getSkin())->getFoldername(); } // use default theme in case a custom set theme is no longer available if (empty($themeFolderName)) { $themeRepo = new \Cx\Core\View\Model\Repository\ThemeRepository(); $themeFolderName = $themeRepo->getDefaultTheme($themeType, $page->getLang())->getFoldername(); } $cx = \Cx\Core\Core\Controller\Cx::instanciate(); // load custom application template from page's theme $themePath = $cx->getClassLoader()->getFilePath($cx->getWebsiteThemesPath() . '/' . $themeFolderName . '/' . $moduleFolderName . '/' . $component . '/Template/Frontend/' . $customAppTemplate); if ($themePath) { return file_get_contents($themePath); } // load default application template from page's theme if ($customAppTemplate != $cmd . '.html') { $themePath = $cx->getClassLoader()->getFilePath($cx->getWebsiteThemesPath() . '/' . $themeFolderName . '/' . $moduleFolderName . '/' . $component . '/Template/Frontend/' . $cmd . '.html'); if ($themePath) { return file_get_contents($themePath); } } // load default application template from component $modulePath = $cx->getClassLoader()->getFilePath($cx->getCodeBaseDocumentRootPath() . '/' . $moduleFolderName . '/' . $component . '/View/Template/Frontend/' . $cmd . '.html'); if ($modulePath) { return file_get_contents($modulePath); } return; } catch (\Exception $e) { throw new \Exception('Error fetching the content template:' . $e); } }
/** * Create a placeholder for a page object * @param \Cx\Core\ContentManager\Model\Entity\Page $page Page to get placeholder for * @param array $arguments (optional) Query arguments in the form array($key=>$value) * @return \Cx\Core\Routing\NodePlaceholder */ public static function fromPage(\Cx\Core\ContentManager\Model\Entity\Page $page, array $arguments = array()) { return new static($page->getNode(), $page->getLang(), $arguments); }
public function getLang() { $this->_load(); return parent::getLang(); }