/** * Copies the content from the other page given. * @param \Cx\Core\ContentManager\Model\Entity\Page $page */ public function getFallbackContentFrom($page) { $this->isVirtual = true; $this->content = $page->getContent(); $this->module = $page->getModule(); $this->cmd = $page->getCmd(); $this->skin = $page->getSkin(); $this->customContent = $page->getCustomContent(); $this->cssName = $page->getCssName(); $this->cssNavName = $page->getCssNavName(); $this->type = $page->getType(); $this->target = $page->getTarget(); }
/** * 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; }
/** * sort function * * @param \Cx\Core\ContentManager\Model\Entity\Page $pageA * @param \Cx\Core\ContentManager\Model\Entity\Page $pageB * @return int */ private function sortPages($pageA, $pageB) { $pageATermOnlyInContent = preg_match('#(' . $this->term . ')#i', $pageA->getContent()) && !preg_match('#(' . $this->term . ')#i', $pageA->getTitle()) && !preg_match('#(' . $this->term . ')#i', $pageA->getContentTitle()) && !preg_match('#(' . $this->term . ')#i', $pageA->getSlug()) && !preg_match('#(' . $this->term . ')#i', $pageA->getModule()) && !preg_match('#(' . $this->term . ')#i', $pageA->getCmd()); $pageBTermOnlyInContent = preg_match('#(' . $this->term . ')#i', $pageB->getContent()) && !preg_match('#(' . $this->term . ')#i', $pageB->getTitle()) && !preg_match('#(' . $this->term . ')#i', $pageB->getContentTitle()) && !preg_match('#(' . $this->term . ')#i', $pageB->getSlug()) && !preg_match('#(' . $this->term . ')#i', $pageB->getModule()) && !preg_match('#(' . $this->term . ')#i', $pageB->getCmd()); if ($pageATermOnlyInContent == $pageBTermOnlyInContent) { return 0; } if ($pageATermOnlyInContent && !$pageBTermOnlyInContent) { return 1; } return -1; }
/** * 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); } }
/** * Copies the content from the other page given. * @param \Cx\Core\ContentManager\Model\Entity\Page $page * @param boolean $includeThemeOptions (optional) Wheter to adopt theme options as well (default false) */ public function setContentOf($page, $includeThemeOptions = false) { $this->isVirtual = true; $this->content = $page->getContent(); $this->module = $page->getModule(); $this->cmd = $page->getCmd(); if ($includeThemeOptions) { $this->skin = $page->getSkin(); $this->customContent = $page->getCustomContent(); $this->applicationTemplate = $page->getApplicationTemplate(); $this->cssName = $page->getCssName(); } $this->cssNavName = $page->getCssNavName(); $this->type = $page->getType(); $this->target = $page->getTarget(); }
public function getModule() { $this->_load(); return parent::getModule(); }