public function legacyResolve($url, $section, $command) { global $sessionObj; $objFWUser = \FWUser::getFWUserObject(); /* The Resolver couldn't find a page. We're looking at one of the following situations, which are treated in the listed order: a) Request for the 'home' page b) Legacy request with section / cmd c) Request for inexistant page We try to locate a module page via cmd and section (if provided). If that doesn't work, an error is shown. */ // a: 'home' page $urlPointsToHome = $url->getSuggestedTargetPath() == 'index.php' || $url->getSuggestedTargetPath() == ''; // user probably tried requesting the home-page if (!$section && $urlPointsToHome) { $section = 'Home'; } $this->setSection($section, $command); // b(, a): fallback if section and cmd are specified if ($section) { if ($section == 'logout') { if (empty($sessionObj)) { $sessionObj = \cmsSession::getInstance(); } if ($objFWUser->objUser->login()) { $objFWUser->logout(); } } $pageRepo = \Env::get('em')->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); // If the database uses a case insensitive collation, $section needn't be the exact component name to find a page $this->page = $pageRepo->findOneByModuleCmdLang($section, $command, FRONTEND_LANG_ID); //fallback content if (!$this->page) { return; } // make legacy-requests case insensitive works only if database-collation is case insensitive as well $this->setSection($this->page->getModule(), $this->page->getCmd()); $this->checkPageFrontendProtection($this->page); $this->handleFallbackContent($this->page); } // c: inexistant page gets catched below. }
/** * DO NOT CALL THIS METHOD! USE copyToLang() OR copyToNode() INSTEAD! * Copies data from another Page. * @param boolean $includeContent Whether to copy content. Defaults to true. * @param boolean $includeModuleAndCmd Whether to copy module and cmd. Defaults to true. * @param boolean $includeName Wheter to copy title, content title and slug. Defaults to true. * @param boolean $includeMetaData Wheter to copy meta data. Defaults to true. * @param boolean $includeProtection Wheter to copy protection. Defaults to true. * @param boolean $followRedirects Wheter to return a redirection page or the page its pointing at. Defaults to false, which returns the redirection page * @param boolean $followFallbacks Wheter to return a fallback page or the page its pointing at. Defaults to false, witch returns the fallback page * @param \Cx\Core\ContentManager\Model\Entity\Page Page to use as target * @return \Cx\Core\ContentManager\Model\Entity\Page The copy of $this or null on error */ public function copy($includeContent = true, $includeModuleAndCmd = true, $includeName = true, $includeMetaData = true, $includeProtection = true, $followRedirects = false, $followFallbacks = false, $page = null) { $targetPage = null; if ($followRedirects && $this->getType() == self::TYPE_REDIRECT) { $targetPage = $this->getTargetNodeId()->getPage($this->getTargetLangId()); } if ($followFallbacks && $this->getType() == self::TYPE_FALLBACK) { $fallbackLanguage = \FWLanguage::getFallbackLanguageIdById($this->getLang()); $targetPage = $this->getNode()->getPage($fallbackLanguage); } if ($targetPage) { return $targetPage->copy($includeContent, $includeModuleAndCmd, $includeName, $includeMetaData, $includeProtection, $followRedirects, $followFallbacks); } if (!$page) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); } if ($includeName) { $page->setContentTitle($this->getContentTitle()); $page->setTitle($this->getTitle()); $page->setSlug($this->getSlug()); } $newType = $this->getType(); if ($includeContent) { $page->setContent($this->getContent()); } else { $newType = self::TYPE_FALLBACK; } if ($includeModuleAndCmd) { $page->setModule($this->getModule()); $page->setCmd($this->getCmd()); } else { $page->setCmd(''); } if ($includeMetaData) { $page->setMetatitle($this->getMetatitle()); $page->setMetadesc($this->getMetadesc()); $page->setMetakeys($this->getMetakeys()); $page->setMetarobots($this->getMetarobots()); } $page->setNode($this->getNode()); $page->setActive($this->getActive()); $page->setDisplay($this->getDisplay()); $page->setLang($this->getLang()); $page->setType($newType); $page->setCaching($this->getCaching()); $page->setCustomContent($this->getCustomContent()); $page->setCssName($this->getCssName()); $page->setCssNavName($this->getCssNavName()); $page->setSkin($this->getSkin()); $page->setStart($this->getStart()); $page->setEnd($this->getEnd()); $page->setEditingStatus($this->getEditingStatus()); $page->setTarget($this->getTarget()); $page->setLinkTarget($this->getLinkTarget()); $page->setUpdatedBy(\FWUser::getFWUserObject()->objUser->getUsername()); if ($includeProtection) { if (!$this->copyProtection($page, true) || !$this->copyProtection($page, false)) { return null; } } return $page; }
public function testGetPathToPage() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n1->setParent($nodeRepo->getRoot()); $nodeRepo->getRoot()->addChildren($n1); $n2 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n2->setParent($n1); $n1->addChildren($n2); self::$em->persist($n1); self::$em->persist($n2); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(1); $p1->setTitle('root'); $p1->setNode($n1); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setTitle('child page'); $p2->setNode($n2); $p2->setNodeIdShadowed($n2->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->persist($n1); self::$em->persist($n2); self::$em->persist($p1); self::$em->persist($p2); self::$em->flush(); $pageId = $p2->getId(); \Env::get('em')->refresh($n1); //make sure we re-fetch a correct state self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node')->verify(); $pageRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $page = $pageRepo->findOneById($pageId); $this->assertEquals('root/child-page', $pageRepo->getPath($page)); }
/** * Gets the search results. * * @return mixed Parsed content. */ public function getSearchResults() { global $_ARRAYLANG; $this->template->addBlockfile('ADMIN_CONTENT', 'search', 'Default.html'); if (!empty($this->term)) { $pages = $this->getSearchedPages(); $countPages = $this->countSearchedPages(); usort($pages, array($this, 'sortPages')); if ($countPages > 0) { $parameter = '&cmd=Search' . (empty($this->term) ? '' : '&term=' . contrexx_raw2encodedUrl($this->term)); $paging = \Paging::get($parameter, '', $countPages, 0, true, null, 'pos'); $this->template->setVariable(array('TXT_SEARCH_RESULTS_COMMENT' => sprintf($_ARRAYLANG['TXT_SEARCH_RESULTS_COMMENT'], $this->term, $countPages), 'TXT_SEARCH_TITLE' => $_ARRAYLANG['TXT_NAVIGATION_TITLE'], 'TXT_SEARCH_CONTENT_TITLE' => $_ARRAYLANG['TXT_PAGETITLE'], 'TXT_SEARCH_SLUG' => $_ARRAYLANG['TXT_CORE_CM_SLUG'], 'TXT_SEARCH_LANG' => $_ARRAYLANG['TXT_LANGUAGE'], 'SEARCH_PAGING' => $paging)); foreach ($pages as $page) { // used for alias pages, because they have no language if ($page->getLang() == "") { $languages = ""; foreach (\FWLanguage::getIdArray('frontend') as $langId) { $languages[] = \FWLanguage::getLanguageCodeById($langId); } } else { $languages = array(\FWLanguage::getLanguageCodeById($page->getLang())); } $aliasLanguages = implode(', ', $languages); $originalPage = $page; $link = 'index.php?cmd=ContentManager&page=' . $page->getId(); if ($page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_ALIAS) { $pageRepo = \Env::get('em')->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); if ($originalPage->isTargetInternal()) { // is internal target, get target page $originalPage = $pageRepo->getTargetPage($page); } else { // is an external target, set the link to the external targets url $originalPage = new \Cx\Core\ContentManager\Model\Entity\Page(); $originalPage->setTitle($page->getTarget()); $link = $page->getTarget(); } } $this->template->setVariable(array('SEARCH_RESULT_BACKEND_LINK' => $link, 'SEARCH_RESULT_TITLE' => $originalPage->getTitle(), 'SEARCH_RESULT_CONTENT_TITLE' => $originalPage->getContentTitle(), 'SEARCH_RESULT_SLUG' => substr($page->getPath(), 1), 'SEARCH_RESULT_LANG' => $aliasLanguages, 'SEARCH_RESULT_FRONTEND_LINK' => \Cx\Core\Routing\Url::fromPage($page))); $this->template->parse('search_result_row'); } } else { $this->template->setVariable(array('TXT_SEARCH_NO_RESULTS' => sprintf($_ARRAYLANG['TXT_SEARCH_NO_RESULTS'], $this->term))); } } else { $this->template->setVariable(array('TXT_SEARCH_NO_TERM' => $_ARRAYLANG['TXT_SEARCH_NO_TERM'])); } }
function showEntry() { global $_ARRAYLANG, $_CORELANG; $this->_objTpl->setTemplate($this->pageContent, true, true); //get ids $intCategoryId = isset($_GET['cid']) ? intval($_GET['cid']) : 0; $intLevelId = isset($_GET['lid']) ? intval($_GET['lid']) : 0; $intEntryId = isset($_GET['eid']) ? intval($_GET['eid']) : 0; // load source code if cmd value is integer if ($this->_objTpl->placeholderExists('APPLICATION_DATA')) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setVirtual(true); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('MediaDir'); $page->setCmd('detail'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $this->_objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } //get navtree if ($this->_objTpl->blockExists($this->moduleNameLC . 'Navtree') && ($intCategoryId != 0 || $intLevelId != 0)) { $this->getNavtree($intCategoryId, $intLevelId); } if ($intEntryId != 0 && $this->_objTpl->blockExists($this->moduleNameLC . 'EntryList')) { $objEntry = new MediaDirectoryEntry($this->moduleName); $objEntry->getEntries($intEntryId, $intLevelId, $intCategoryId, null, null, null, 1, null, 1); $objEntry->listEntries($this->_objTpl, 2); $objEntry->updateHits($intEntryId); //set meta attributes $entries = new MediaDirectoryEntry($this->moduleName); $entries->getEntries($intEntryId, $intLevelId, $intCategoryId, null, null, null, 1, null, 1); $entry = $entries->arrEntries[$intEntryId]; $objInputfields = new MediaDirectoryInputfield($entry['entryFormId'], false, $entry['entryTranslationStatus'], $this->moduleName); $inputFields = $objInputfields->getInputfields(); $titleChanged = false; $contentChanged = false; foreach ($inputFields as $arrInputfield) { $contextType = isset($arrInputfield['context_type']) ? $arrInputfield['context_type'] : ''; if (!in_array($contextType, array('title', 'content', 'image'))) { continue; } $strType = isset($arrInputfield['type_name']) ? $arrInputfield['type_name'] : ''; $strInputfieldClass = "\\Cx\\Modules\\MediaDir\\Model\\Entity\\MediaDirectoryInputfield" . ucfirst($strType); try { $objInputfield = safeNew($strInputfieldClass, $this->moduleName); $arrTranslationStatus = contrexx_input2int($arrInputfield['type_multi_lang']) == 1 ? $entry['entryTranslationStatus'] : null; $arrInputfieldContent = $objInputfield->getContent($entry['entryId'], $arrInputfield, $arrTranslationStatus); switch ($contextType) { case 'title': $inputfieldValue = $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE']; if ($inputfieldValue) { $this->metaTitle .= ' - ' . $inputfieldValue; $this->pageTitle = $inputfieldValue; } $titleChanged = true; break; case 'content': $inputfieldValue = $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE']; if ($inputfieldValue) { $this->metaDescription = $inputfieldValue; } $contentChanged = true; break; case 'image': $inputfieldValue = $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE_SRC']; if ($inputfieldValue) { $this->metaImage = $inputfieldValue; } break; default: break; } } catch (\Exception $e) { \DBG::log($e->getMessage()); continue; } } $firstInputfieldValue = $entries->arrEntries[$intEntryId]['entryFields'][0]; if (!$titleChanged && $firstInputfieldValue) { $this->pageTitle = $firstInputfieldValue; $this->metaTitle = $firstInputfieldValue; } if (!$contentChanged && $firstInputfieldValue) { $this->metaDescription = $firstInputfieldValue; } if (empty($objEntry->arrEntries)) { $this->_objTpl->hideBlock($this->moduleNameLC . 'EntryList'); $this->_objTpl->clearVariables(); header("Location: index.php?section=" . $this->moduleName); exit; } } else { header("Location: index.php?section=" . $this->moduleName); exit; } }
function showEntry() { global $_ARRAYLANG, $_CORELANG; $this->_objTpl->setTemplate($this->pageContent, true, true); //get ids $intCategoryId = isset($_GET['cid']) ? intval($_GET['cid']) : 0; $intLevelId = isset($_GET['lid']) ? intval($_GET['lid']) : 0; $intEntryId = isset($_GET['eid']) ? intval($_GET['eid']) : 0; // load source code if cmd value is integer if ($this->_objTpl->placeholderExists('APPLICATION_DATA')) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setVirtual(true); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('MediaDir'); $page->setCmd('detail'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $this->_objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } //get navtree if ($this->_objTpl->blockExists($this->moduleNameLC . 'Navtree') && ($intCategoryId != 0 || $intLevelId != 0)) { $this->getNavtree($intCategoryId, $intLevelId); } if ($intEntryId != 0 && $this->_objTpl->blockExists($this->moduleNameLC . 'EntryList')) { $objEntry = new MediaDirectoryEntry($this->moduleName); $objEntry->getEntries($intEntryId, $intLevelId, $intCategoryId, null, null, null, 1, null, 1); $objEntry->listEntries($this->_objTpl, 2); $objEntry->updateHits($intEntryId); //set meta title $this->metaTitle .= " - " . $objEntry->arrEntries[$intEntryId]['entryFields'][0]; $this->pageTitle = $objEntry->arrEntries[$intEntryId]['entryFields'][0]; if (empty($objEntry->arrEntries)) { $this->_objTpl->hideBlock($this->moduleNameLC . 'EntryList'); $this->_objTpl->clearVariables(); header("Location: index.php?section=" . $this->moduleName); exit; } } else { header("Location: index.php?section=" . $this->moduleName); exit; } }
/** * set the placeholders for the category view * * @return null */ function showCategoryView() { global $_ARRAYLANG, $_CORELANG; $this->_objTpl->setTemplate($this->pageContent, true, true); // load source code if cmd value is integer if ($this->_objTpl->placeholderExists('APPLICATION_DATA')) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setVirtual(true); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('Calendar'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $this->_objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } $objCategoryManager = new \Cx\Modules\Calendar\Controller\CalendarCategoryManager(true); $objCategoryManager->getCategoryList(); $this->_objTpl->setGlobalVariable(array('TXT_' . $this->moduleLangVar . '_SEARCH_TERM' => $_ARRAYLANG['TXT_CALENDAR_KEYWORD'], 'TXT_' . $this->moduleLangVar . '_FROM' => $_ARRAYLANG['TXT_CALENDAR_FROM'], 'TXT_' . $this->moduleLangVar . '_TILL' => $_ARRAYLANG['TXT_CALENDAR_TILL'], 'TXT_' . $this->moduleLangVar . '_CATEGORY' => $_ARRAYLANG['TXT_CALENDAR_CAT'], 'TXT_' . $this->moduleLangVar . '_SEARCH' => $_ARRAYLANG['TXT_CALENDAR_SEARCH'], 'TXT_' . $this->moduleLangVar . '_OCLOCK' => $_ARRAYLANG['TXT_CALENDAR_OCLOCK'], $this->moduleLangVar . '_SEARCH_TERM' => isset($_GET['term']) ? contrexx_input2xhtml($_GET['term']) : '', $this->moduleLangVar . '_SEARCH_FROM' => isset($_GET['from']) ? contrexx_input2xhtml($_GET['from']) : '', $this->moduleLangVar . '_SEARCH_TILL' => isset($_GET['till']) ? contrexx_input2xhtml($_GET['till']) : '', $this->moduleLangVar . '_SEARCH_CATEGORIES' => $objCategoryManager->getCategoryDropdown(isset($_GET['catid']) ? intval($_GET['catid']) : 0, 1))); if (isset($this->categoryId)) { $objCategory = new \Cx\Modules\Calendar\Controller\CalendarCategory($this->categoryId); $this->_objTpl->setGlobalVariable(array($this->moduleLangVar . '_CATEGORY_NAME' => $objCategory->name)); $this->objEventManager->showEventList($this->_objTpl); $this->_objTpl->parse('categoryList'); } else { foreach ($objCategoryManager->categoryList as $key => $objCategory) { $objEventManager = new \Cx\Modules\Calendar\Controller\CalendarEventManager($this->startDate, $this->endDate, $objCategory->id, $this->searchTerm, true, $this->needAuth, true, $this->startPos, $this->numEvents); $objEventManager->getEventList(); $objEventManager->showEventList($this->_objTpl); $this->_objTpl->setGlobalVariable(array($this->moduleLangVar . '_CATEGORY_NAME' => $objCategory->name)); $this->_objTpl->parse('categoryList'); } } }
function _saveAlias($slug, $target, $is_local, $id = '') { if ($slug == '') { return false; } // is internal target if ($is_local) { // get target page $temp_page = new \Cx\Core\ContentManager\Model\Entity\Page(); $temp_page->setTarget($target); $existing_aliases = $this->_getAliasesWithSameTarget($temp_page); // if alias already exists -> fail foreach ($existing_aliases as $existing_alias) { if (($id == '' || $existing_alias->getNode()->getId() != $id) && $slug == $existing_alias->getSlug()) { return false; } } } if ($id == '') { // create new node $node = new \Cx\Core\ContentManager\Model\Entity\Node(); $node->setParent($this->nodeRepository->getRoot()); $this->em->persist($node); // add a page $page = $this->_createTemporaryAlias(); $page->setNode($node); } else { $node = $this->nodeRepository->find($id); if (!$node) { return false; } $pages = $node->getPages(true); if (count($pages) != 1) { return false; } $page = $pages->first(); // we won't change anything on non aliases if ($page->getType() != \Cx\Core\ContentManager\Model\Entity\Page::TYPE_ALIAS) { return false; } } // set page attributes $page->setSlug($slug); $page->setTarget($target); $page->setTitle($page->getSlug()); // sanitize slug while (file_exists(ASCMS_PATH . '/' . $page->getSlug())) { $page->nextSlug(); } // save try { $page->validate(); } catch (\Cx\Core\ContentManager\Model\Entity\PageException $e) { return $e->getUserMessage(); } $this->em->persist($page); $this->em->flush(); $this->em->refresh($node); $this->em->refresh($page); return true; }
/** * Returns an array with the log entries of the given action with a limiter for the paging. It is used for the content workflow overview. * The log entries are filtered by the page object. * * @param string $action * @param int $offset * @param int $limit * * @return array $result */ public function getLogs($action = '', $offset, $limit) { $result = array(); $qb = $this->em->createQueryBuilder(); $sqb = $this->em->createQueryBuilder(); $qb->select('l.objectId, l.action, l.loggedAt, l.version, l.username')->from('Cx\\Core\\ContentManager\\Model\\Entity\\LogEntry', 'l')->where('l.action = :action')->andWhere('l.objectClass = :objectClass')->andWhere($qb->expr()->eq('l.version', '(' . $sqb->select('MAX(sl.version) AS version')->from('Cx\\Core\\ContentManager\\Model\\Entity\\LogEntry', 'sl')->where($sqb->expr()->eq('l.objectId', 'sl.objectId'))->getDQL() . ')'))->orderBy('l.loggedAt', 'DESC')->setParameter('objectClass', 'Cx\\Core\\ContentManager\\Model\\Entity\\Page'); switch ($action) { case 'deleted': $qb->setParameter('action', 'remove'); break; case 'unvalidated': $editingStatus = 'hasDraftWaiting'; $qb->orWhere('l.action = :orAction')->setParameter('action', 'create')->setParameter('orAction', 'update'); break; case 'updated': $editingStatus = ''; $qb->setParameter('action', 'update'); break; default: // create $editingStatus = ''; $qb->setParameter('action', 'create'); } switch ($action) { case 'deleted': $qb->setFirstResult($offset)->setMaxResults($limit); $logs = $qb->getQuery()->getResult(); $logsByNodeId = array(); // Structure the logs by node id and language foreach ($logs as $log) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setId($log['objectId']); $this->revert($page, $log['version'] - 1); $result[$page->getNodeIdShadowed()][$page->getLang()] = $log; } break; default: // create, update and unvalidated // If setFirstResult() is called, setMaxResult must be also called. Otherwise there is a fatal error. // The parameter for setMaxResult() method is a custom value set to 999999, because we need all pages. $qb->setFirstResult($offset)->setMaxResults(999999); $logs = $qb->getQuery()->getResult(); $i = 0; foreach ($logs as $log) { $page = $this->pageRepo->findOneById($log['objectId']); if (!$page) { continue; } if ($page->getEditingStatus() == $editingStatus) { $result[] = $log; $i++; } if ($i >= $limit) { break; } } } return $result; }
/** * Shows the Overview of categories * * @global ADONewConnection * @global array * @global array * @param var $intParentId */ function showCategoryOverview($intParentId = 0) { global $objDatabase, $_ARRAYLANG, $_CONFIG, $_CORELANG; $intParentId = intval($intParentId); $this->_objTpl->setTemplate($this->pageContent, true, true); // load source code if cmd value is integer if ($this->_objTpl->placeholderExists('APPLICATION_DATA')) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setVirtual(true); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('Gallery'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $this->_objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } $categoryProtected = $this->categoryIsProtected($intParentId); if ($categoryProtected > 0) { if (!\Permission::checkAccess($categoryProtected, 'dynamic', true)) { $link = base64_encode($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']); \Cx\Core\Csrf\Controller\Csrf::header("Location: " . CONTREXX_DIRECTORY_INDEX . "?section=Login&cmd=noaccess&redirect=" . $link); exit; } } // hide image detail block // $this->_objTpl->hideBlock('galleryImage'); if ($this->arrSettings['header_type'] == 'hierarchy') { $this->_objTpl->setVariable(array('GALLERY_CATEGORY_TREE' => $this->getCategoryTree(), 'TXT_GALLERY_CATEGORY_HINT' => $_ARRAYLANG['TXT_GALLERY_CATEGORY_HINT_HIERARCHY'])); } else { $this->_objTpl->setVariable(array('GALLERY_CATEGORY_TREE' => $this->getSiblingList(), 'TXT_GALLERY_CATEGORY_HINT' => $_ARRAYLANG['TXT_GALLERY_CATEGORY_HINT_FLAT'])); } $objResult = $objDatabase->Execute("SELECT id, catid, path FROM " . DBPREFIX . "module_gallery_pictures " . "ORDER BY catimg ASC, sorting ASC, id ASC"); $showImageSizeOverview = $this->arrSettings['show_image_size'] == 'on'; while (!$objResult->EOF) { $arrImageSizes[$objResult->fields['catid']][$objResult->fields['id']] = $showImageSizeOverview ? round(filesize($this->strImagePath . $objResult->fields['path']) / 1024, 2) : ''; $arrstrImagePaths[$objResult->fields['catid']][$objResult->fields['id']] = $this->strThumbnailWebPath . $objResult->fields['path']; $objResult->MoveNext(); } if (isset($arrImageSizes) && isset($arrstrImagePaths)) { foreach ($arrImageSizes as $keyCat => $valueCat) { $arrCategorySizes[$keyCat] = 0; foreach ($valueCat as $valueImageSize) { $arrCategorySizes[$keyCat] = $arrCategorySizes[$keyCat] + $valueImageSize; } } foreach ($arrstrImagePaths as $keyCat => $valueCat) { $arrCategoryImages[$keyCat] = 0; $arrCategoryImageCounter[$keyCat] = 0; foreach ($valueCat as $valuestrImagePath) { $arrCategoryImages[$keyCat] = $valuestrImagePath; $arrCategoryImageCounter[$keyCat] = $arrCategoryImageCounter[$keyCat] + 1; } } } //$arrCategorySizes -> Sizes of all Categories //$arrCategoryImages -> The First Picture of each category //$arrCategoryImageCounter -> Counts all images in one group //begin category-paging $intPos = isset($_GET['pos']) ? intval($_GET['pos']) : 0; $objResult = $objDatabase->Execute('SELECT count(id) AS countValue FROM ' . DBPREFIX . 'module_gallery_categories WHERE pid=' . $intParentId . ' AND status="1" '); $this->_objTpl->setVariable(array('GALLERY_CATEGORY_PAGING' => getPaging($objResult->fields['countValue'], $intPos, '§ion=Gallery&cid=' . $intParentId . $this->strCmd, '<b>' . $_ARRAYLANG['TXT_GALLERY'] . '</b>', false, intval($_CONFIG['corePagingLimit'])))); //end category-paging $objResult = $objDatabase->SelectLimit('SELECT * FROM ' . DBPREFIX . 'module_gallery_categories WHERE pid=' . $intParentId . ' AND status="1" ORDER BY sorting ASC', intval($_CONFIG['corePagingLimit']), $intPos); if ($objResult->RecordCount() == 0) { // no categories in the database, hide the output //$this->_objTpl->hideBlock('galleryCategoryList'); } else { $i = 1; while (!$objResult->EOF) { $objSubResult = $objDatabase->Execute("SELECT name, value FROM " . DBPREFIX . "module_gallery_language " . "WHERE gallery_id=" . $objResult->fields['id'] . " AND " . "lang_id=" . intval($this->langId) . " ORDER BY name ASC"); unset($arrCategoryLang); while (!$objSubResult->EOF) { $arrCategoryLang[$objSubResult->fields['name']] = $objSubResult->fields['value']; $objSubResult->MoveNext(); } if (empty($arrCategoryImages[$objResult->fields['id']])) { // no pictures in this gallery, show the empty-image $strName = $arrCategoryLang['name']; $strDesc = $arrCategoryLang['desc']; $strImage = '<a href="' . CONTREXX_DIRECTORY_INDEX . '?section=Gallery&cid=' . $objResult->fields['id'] . $this->strCmd . '" target="_self">'; $strImage .= '<img border="0" alt="' . $arrCategoryLang['name'] . '" src="modules/Gallery/View/Media/no_images.gif" /></a>'; $strInfo = $_ARRAYLANG['TXT_IMAGE_COUNT'] . ': 0'; $strInfo .= $showImageSizeOverview ? '<br />' . $_CORELANG['TXT_SIZE'] . ': 0kB' : ''; } else { $strName = $arrCategoryLang['name']; $strDesc = $arrCategoryLang['desc']; $strImage = '<a href="' . CONTREXX_DIRECTORY_INDEX . '?section=Gallery&cid=' . $objResult->fields['id'] . $this->strCmd . '" target="_self">'; $strImage .= '<img border="0" alt="' . $arrCategoryLang['name'] . '" src="' . $arrCategoryImages[$objResult->fields['id']] . '" /></a>'; $strInfo = $_ARRAYLANG['TXT_IMAGE_COUNT'] . ': ' . $arrCategoryImageCounter[$objResult->fields['id']]; $strInfo .= $showImageSizeOverview ? '<br />' . $_CORELANG['TXT_SIZE'] . ': ' . $arrCategorySizes[$objResult->fields['id']] . 'kB' : ''; } $this->_objTpl->setVariable(array('GALLERY_STYLE' => $i % 2 + 1, 'GALLERY_CATEGORY_NAME' => $strName, 'GALLERY_CATEGORY_IMAGE' => $strImage, 'GALLERY_CATEGORY_INFO' => $strInfo, 'GALLERY_CATEGORY_DESCRIPTION' => nl2br($strDesc))); $this->_objTpl->parse('galleryCategoryList'); $i++; $objResult->MoveNext(); } } //images $this->_objTpl->setVariable(array('GALLERY_JAVASCRIPT' => $this->getJavascript())); $objResult = $objDatabase->Execute("SELECT value FROM " . DBPREFIX . "module_gallery_language " . "WHERE gallery_id={$intParentId} AND lang_id={$this->langId} AND name='desc'"); $strCategoryComment = nl2br($objResult->fields['value']); $objResult = $objDatabase->Execute("SELECT comment,voting FROM " . DBPREFIX . "module_gallery_categories " . "WHERE id=" . intval($intParentId)); $boolComment = $objResult->fields['comment']; $boolVoting = $objResult->fields['voting']; // paging $intPos = isset($_GET['pos']) ? intval($_GET['pos']) : 0; $objResult = $objDatabase->Execute("SELECT id, path, link, size_show FROM " . DBPREFIX . "module_gallery_pictures " . "WHERE status='1' AND validated='1' AND catid={$intParentId} " . "ORDER BY sorting"); $intCount = $objResult->RecordCount(); $this->_objTpl->setVariable(array('GALLERY_PAGING' => getPaging($intCount, $intPos, '§ion=Gallery&cid=' . $intParentId . $this->strCmd, '<b>' . $_ARRAYLANG['TXT_IMAGES'] . '</b>', false, intval($this->arrSettings["paging"])))); // end paging $objResult = $objDatabase->SelectLimit("SELECT id, path, link, size_show FROM " . DBPREFIX . "module_gallery_pictures " . "WHERE status='1' AND validated='1' AND catid={$intParentId} " . "ORDER BY sorting", intval($this->arrSettings["paging"]), $intPos); if ($objResult->RecordCount() == 0) { // No images in the category if (empty($strCategoryComment)) { $this->_objTpl->hideBlock('galleryImageBlock'); } else { $this->_objTpl->setVariable(array('GALLERY_CATEGORY_COMMENT' => $strCategoryComment)); } } else { $this->_objTpl->setVariable(array('GALLERY_CATEGORY_COMMENT' => $strCategoryComment)); $intFillLastRow = 1; while (!$objResult->EOF) { $imageVotingOutput = ''; $imageCommentOutput = ''; $objSubResult = $objDatabase->Execute("SELECT p.name, p.desc FROM " . DBPREFIX . "module_gallery_language_pics p " . "WHERE picture_id=" . $objResult->fields['id'] . " AND lang_id={$this->langId} LIMIT 1"); // Never used // $imageReso = getimagesize($this->strImagePath.$objResult->fields['path']); $strImagePath = $this->strImageWebPath . $objResult->fields['path']; $imageThumbPath = $this->strThumbnailWebPath . $objResult->fields['path']; $imageFileName = $this->arrSettings['show_file_name'] == 'on' ? $objResult->fields['path'] : ''; $imageName = $this->arrSettings['show_names'] == 'on' ? $objSubResult->fields['name'] : ''; $imageTitle = $this->arrSettings['show_names'] == 'on' ? $objSubResult->fields['name'] : ($this->arrSettings['show_file_name'] == 'on' ? $objResult->fields['path'] : ''); $imageLinkName = $objSubResult->fields['desc']; $imageLink = $objResult->fields['link']; $showImageSize = $this->arrSettings['show_image_size'] == 'on' && $objResult->fields['size_show']; $imageFileSize = $showImageSize ? round(filesize($this->strImagePath . $objResult->fields['path']) / 1024, 2) : ''; $imageLinkOutput = ''; $imageSizeOutput = ''; $imageTitleTag = ''; // chop the file extension if the settings tell us to do so if ($this->arrSettings['show_ext'] == 'off') { $imageFileName = substr($imageFileName, 0, strrpos($imageFileName, '.')); } if ($this->arrSettings['slide_show'] == 'slideshow') { $optionValue = "slideshowDelay:" . $this->arrSettings['slide_show_seconds']; } else { $optionValue = "counterType:'skip',continuous:true,animSequence:'sync'"; } //calculation starts here $numberOfChars = "60"; if ($imageLinkName != "") { if (strlen($imageLinkName) > $numberOfChars) { $descriptionString = " " . substr($imageLinkName, 0, $numberOfChars); $descriptionString .= " ..."; } else { $descriptionString = " " . $imageLinkName; } } else { $descriptionString = ""; } //Ends here if ($this->arrSettings['show_names'] == 'on' || $this->arrSettings['show_file_name'] == 'on') { $imageSizeOutput = $imageName; $imageTitleTag = $imageName; if ($this->arrSettings['show_file_name'] == 'on' || $showImageSize) { $imageData = array(); if ($this->arrSettings['show_file_name'] == 'on') { if ($this->arrSettings['show_names'] == 'off') { $imageSizeOutput .= $imageFileName; $imageTitleTag .= $imageFileName; } else { $imageData[] = $imageFileName; } } if (!empty($imageData)) { $imageTitleTag .= ' (' . join(' ', $imageData) . ')'; } if ($showImageSize) { // the size of the file has to be shown $imageData[] = $imageFileSize . ' kB'; } if (!empty($imageData)) { $imageSizeOutput .= ' (' . join(' ', $imageData) . ')<br />'; } } } if ($this->arrSettings['enable_popups'] == "on") { $strImageOutput = '<a rel="shadowbox[' . $intParentId . '];options={' . $optionValue . '}" title="' . $imageTitleTag . '" href="' . $strImagePath . '"><img title="' . $imageTitleTag . '" src="' . $imageThumbPath . '" alt="' . $imageTitleTag . '" /></a>'; /* $strImageOutput = '<a rel="shadowbox['.$intParentId.'];options={'.$optionValue. '}" description="'.$imageLinkName.'" title="'.$titleLink.'" href="'. $strImagePath.'"><img title="'.$imageName.'" src="'. $imageThumbPath.'" alt="'.$imageName.'" /></a>'; */ } else { $strImageOutput = '<a href="' . CONTREXX_DIRECTORY_INDEX . '?section=Gallery' . $this->strCmd . '&cid=' . $intParentId . '&pId=' . $objResult->fields['id'] . '">' . '<img title="' . $imageTitleTag . '" src="' . $imageThumbPath . '"' . 'alt="' . $imageTitleTag . '" /></a>'; } if ($this->arrSettings['show_comments'] == 'on' && $boolComment) { $objSubResult = $objDatabase->Execute("SELECT id FROM " . DBPREFIX . "module_gallery_comments " . "WHERE picid=" . $objResult->fields['id']); if ($objSubResult->RecordCount() > 0) { if ($objSubResult->RecordCount() == 1) { $imageCommentOutput = '1 ' . $_ARRAYLANG['TXT_COMMENTS_ADD_TEXT'] . '<br />'; } else { $imageCommentOutput = $objSubResult->RecordCount() . ' ' . $_ARRAYLANG['TXT_COMMENTS_ADD_COMMENTS'] . '<br />'; } } } if ($this->arrSettings['show_voting'] == 'on' && $boolVoting) { $objSubResult = $objDatabase->Execute("SELECT mark FROM " . DBPREFIX . "module_gallery_votes " . "WHERE picid=" . $objResult->fields["id"]); if ($objSubResult->RecordCount() > 0) { $intMark = 0; while (!$objSubResult->EOF) { $intMark = $intMark + $objSubResult->fields['mark']; $objSubResult->MoveNext(); } $imageVotingOutput = $_ARRAYLANG['TXT_VOTING_SCORE'] . ' Ø' . number_format(round($intMark / $objSubResult->RecordCount(), 1), 1, '.', '\'') . '<br />'; } } if (!empty($imageLinkName)) { if (!empty($imageLink)) { $imageLinkOutput = '<a href="' . $imageLink . '" target="_blank">' . $imageLinkName . '</a>'; } else { $imageLinkOutput = $imageLinkName; } } else { if (!empty($imageLink)) { $imageLinkOutput = '<a href="' . $imageLink . '" target="_blank">' . $imageLink . '</a>'; } } $this->_objTpl->setVariable(array('GALLERY_IMAGE_LINK' . $intFillLastRow => $imageSizeOutput . $imageCommentOutput . $imageVotingOutput . $imageLinkOutput, 'GALLERY_IMAGE' . $intFillLastRow => $strImageOutput)); if ($intFillLastRow == 3) { // Parse the data after every third image $this->_objTpl->parse('galleryShowImages'); $intFillLastRow = 1; } else { $intFillLastRow++; } $objResult->MoveNext(); } if ($intFillLastRow == 2) { $this->_objTpl->setVariable(array('GALLERY_IMAGE' . $intFillLastRow => '', 'GALLERY_IMAGE_LINK' . $intFillLastRow => '')); $intFillLastRow++; } if ($intFillLastRow == 3) { $this->_objTpl->setVariable(array('GALLERY_IMAGE' . $intFillLastRow => '', 'GALLERY_IMAGE_LINK' . $intFillLastRow => '')); $this->_objTpl->parse('galleryShowImages'); } } $this->_objTpl->parse('galleryCategories'); }
public function getPage($pos, $page_content) { global $_CONFIG, $_ARRAYLANG; $objTpl = new \Cx\Core\Html\Sigma('.'); \Cx\Core\Csrf\Controller\Csrf::add_placeholder($objTpl); $objTpl->setErrorHandling(PEAR_ERROR_DIE); $objTpl->setTemplate($page_content); $objTpl->setGlobalVariable($_ARRAYLANG); // Load main template even if we have a cmd set if ($objTpl->placeholderExists('APPLICATION_DATA')) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setVirtual(true); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('Search'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } $term = isset($_REQUEST['term']) ? trim(contrexx_input2raw($_REQUEST['term'])) : ''; if (strlen($term) >= 3) { $term = trim(contrexx_input2raw($_REQUEST['term'])); $this->setTerm($term); $eventHandlerInstance = \Env::get('cx')->getEvents(); $eventHandlerInstance->triggerEvent('SearchFindContent', array($this)); if ($this->result->size() == 1) { $arraySearchResults[] = $this->result->toArray(); } else { $arraySearchResults = $this->result->toArray(); } usort($arraySearchResults, function ($a, $b) { if ($a['Score'] == $b['Score']) { if (isset($a['Date'])) { if ($a['Date'] == $b['Date']) { return 0; } if ($a['Date'] > $b['Date']) { return -1; } return 1; } return 0; } if ($a['Score'] > $b['Score']) { return -1; } return 1; }); $countResults = sizeof($arraySearchResults); if (!is_numeric($pos)) { $pos = 0; } $paging = getPaging($countResults, $pos, '&section=Search&term=' . contrexx_raw2encodedUrl($term), '<b>' . $_ARRAYLANG['TXT_SEARCH_RESULTS'] . '</b>', true); $objTpl->setVariable('SEARCH_PAGING', $paging); $objTpl->setVariable('SEARCH_TERM', contrexx_raw2xhtml($term)); if ($countResults > 0) { $searchComment = sprintf($_ARRAYLANG['TXT_SEARCH_RESULTS_ORDER_BY_RELEVANCE'], contrexx_raw2xhtml($term), $countResults); $objTpl->setVariable('SEARCH_TITLE', $searchComment); $arraySearchOut = array_slice($arraySearchResults, $pos, $_CONFIG['corePagingLimit']); foreach ($arraySearchOut as $details) { // append search term to result link $link = $details['Link']; if (strpos($link, '?') === false) { $link .= '?'; } else { $link .= '&'; } $link .= 'searchTerm=' . urlencode($term); // parse result into template $objTpl->setVariable(array('COUNT_MATCH' => $_ARRAYLANG['TXT_RELEVANCE'] . ' ' . $details['Score'] . '%', 'LINK' => '<b><a href="' . $link . '" title="' . contrexx_raw2xhtml($details['Title']) . '">' . contrexx_raw2xhtml($details['Title']) . '</a></b>', 'SHORT_CONTENT' => contrexx_raw2xhtml($details['Content']))); $objTpl->parse('search_result'); } return $objTpl->get(); } } $noresult = $term != '' ? sprintf($_ARRAYLANG['TXT_NO_SEARCH_RESULTS'], $term) : $_ARRAYLANG['TXT_PLEASE_ENTER_SEARCHTERM']; $objTpl->setVariable('SEARCH_TITLE', $noresult); return $objTpl->get(); }
/** * @expectedException \Cx\Model\Base\ValidationException */ public function testValidationException() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $n = new \Cx\Core\ContentManager\Model\Entity\Node(); $n->setParent($nodeRepo->getRoot()); $nodeRepo->getRoot()->addChildren($n); self::$em->persist($n); self::$em->flush(); $p = new \Cx\Core\ContentManager\Model\Entity\Page(); $p->setNode($n); $p->setLang(1); $p->setTitle('validation testpage'); $p->setNodeIdShadowed($n->getId()); $p->setUseCustomContentForAllChannels(''); $p->setUseCustomApplicationTemplateForAllChannels(''); $p->setUseSkinForAllChannels(''); $p->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $p->setActive(1); //set disallowed module name $p->setModule('1|@f2'); $p->setCmd(''); self::$em->persist($n); self::$em->persist($p); //should raise exception self::$em->flush(); }
private function revertPage($pageId) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setId($pageId); $logs = $this->logRepo->getLogEntries($page); $this->logRepo->revert($page, $logs[1]->getVersion()); $page->setId(0); return array('page' => $page, 'logs' => $logs); }
/** * Returns the page path of the given target (node placeholder). * If the target page doesn't exist, the path of the error page will be returned. * * @param array $arguments * @return string $path */ public function getPathByTarget($arguments) { global $_CONFIG; $target = contrexx_input2raw($arguments['get']['target']); if (!\FWValidator::hasProto($target)) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setTarget($target); if ($page->isTargetInternal()) { $target = str_replace(array('[[', ']]'), array('{', '}'), $target); \LinkGenerator::parseTemplate($target); } elseif (ASCMS_PATH_OFFSET == '' || strpos($target, ASCMS_PATH_OFFSET) === false) { if (!isset($target[0]) || $target[0] !== '/') { $target = '/' . $target; } $target = ASCMS_PATH_OFFSET . $target; } $target = ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . $target; } return $target; }
function _handleContentPage($formId = 0) { if (!$formId) { return; } $objDatabase = \Env::get('db'); $objFWUser = \FWUser::getFWUserObject(); $pageRepo = $this->em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $pages = array(); foreach ($pageRepo->findBy(array('module' => 'Contact', 'cmd' => $formId)) as $page) { if ($page) { $pages[$page->getLang()] = $page; } } $frontendLangIds = array_keys(\FWLanguage::getActiveFrontendLanguages()); $selectedLangIds = array_keys($this->arrForms[$formId]['lang']); // filter out only those languages that are active in the frontent. // we do want to create/update only the content pages of those languages. $selectedLangIds = array_intersect($selectedLangIds, $frontendLangIds); // Maybe there will already be a fallback page if we activate a new language. // So we use the fallback page to prevent the creation of a new page. foreach ($selectedLangIds as $selectedLangId) { if (!isset($pages[$selectedLangId])) { $fallbackPage = $pageRepo->findOneByModuleCmdLang('Contact', $formId, $selectedLangId); if (!empty($fallbackPage)) { $pages[$selectedLangId] = $fallbackPage; } } } $presentLangIds = array_keys($pages); // define which languages of the content pages have to be updated // $updateLangIds = array_intersect($selectedLangIds, $presentLangIds); // define which languages of the content pages have to be created // $newLangIds = array_diff($selectedLangIds, $updateLangIds); // define which languages of the content pages have to be removed $deleteLangIds = array_diff($presentLangIds, $selectedLangIds); $langIdsOfAssociatedPagesOfPageNode = array(); foreach ($presentLangIds as $langId) { $langIdsOfAssociatedPagesOfPageNode[$pages[$langId]->getId()] = array_keys($pages[$langId]->getNode()->getPagesByLang()); } foreach ($selectedLangIds as $langId) { $page = null; $node = null; if (isset($pages[$langId])) { // Content page already exists, so we will update this very page $page = $pages[$langId]; \DBG::msg("Page in lang {$langId} exists -> Update()"); } else { // Content page of the frontend language $langId doesn't exist yet. // Therefore we will either have to create a new node or we will have to // find a node to which we can attach our new page. // We will prefer the latter. \DBG::msg("Page doesn't exist in lang {$langId} -> Create()"); // Check if there exists already a content page to who's node we could attach our new page if (count($pages)) { if ($langId != \FWLanguage::getDefaultLangId() && isset($pages[\FWLanguage::getDefaultLangId()]) && !in_array($langId, $langIdsOfAssociatedPagesOfPageNode[$pages[\FWLanguage::getDefaultLangId()]->getId()])) { // if that is the case, we will attach our new page to this node $node = $pages[\FWLanguage::getDefaultLangId()]->getNode(); \DBG::msg("Page does exists in the default language"); \DBG::msg("Attach page to node {$node->getId()} of the page of the lang " . \FWLanguage::getDefaultLangId()); } else { foreach ($pages as $langIdOfPage => $page) { // Skip the page of the default frontend language - we just checked this page's node before if ($langIdOfPage == \FWLanguage::getDefaultLangId()) { continue; } // Check if there exists a node of the pages in the other languages that don't // have an associated page in the language we're going to create a new page if (!in_array($langId, $langIdsOfAssociatedPagesOfPageNode[$pages[$langIdOfPage]->getId()])) { $node = $pages[$langIdOfPage]->getNode(); \DBG::msg("Attach page to node {$node->getId()} of the page of the lang {$langIdOfPage}"); break; } } } } if ($node === null) { \DBG::msg("No node found -> Create()"); $root = $this->em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node')->getRoot(); // Create a new node $node = new \Cx\Core\ContentManager\Model\Entity\Node(); $node->setParent($root); $this->em->persist($node); } // Create a new Page $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setNode($node); // Set the following attributes only on new pages $page->setTitle($this->arrForms[$formId]['lang'][$langId]['name']); $page->setDisplay(false); $page->setActive(true); $page->setLang($langId); } $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('Contact'); $page->setCmd($formId); $content = $page->getContent(); //if the content is missing the placeholder {APPLICATION_DATA}, append the placeholder to the page's content. if (!preg_match_all('/\\{APPLICATION_DATA\\}/xi', $content, $matches)) { $content .= '{APPLICATION_DATA}'; } $page->setContent($content); $page->setSourceMode(true); $this->em->persist($page); // Remember newly created pages. We will need this for the creating of other new pages above in this method. if (!isset($pages[$langId])) { $pages[$langId] = $page; $langIdsOfAssociatedPagesOfPageNode[$pages[$langId]->getId()] = array($langId); } } //$this->em->flush(); // Delete those content pages of those languages that had been deactivated foreach ($deleteLangIds as $langId) { $page = $pages[$langId]; $node = $page->getNode(); \DBG::msg("Delete page: {$langId}"); //DBG::dump(count($node->getPages())); $this->em->remove($page); //$this->em->persist($page); //$this->em->flush(); //DBG::dump(count($node->getPages())); // TODO: Delete empty nodes } $this->em->flush(); }
private function overview() { global $_LANGID; // load source code if cmd value is integer if ($this->objTemplate->placeholderExists('APPLICATION_DATA')) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setVirtual(true); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('Downloads'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $this->objTemplate->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } $objDownload = new Download(); $objCategory = Category::getCategory($this->categoryId); if ($objCategory->getId()) { // check access permissions to selected category if (!\Permission::checkAccess(143, 'static', true) && $objCategory->getReadAccessId() && !\Permission::checkAccess($objCategory->getReadAccessId(), 'dynamic', true) && $objCategory->getOwnerId() != $this->userId) { // TODO: might we have to add a soft noAccess handler in case the output is meant for a regular page (not section=Downloads) \Permission::noAccess(base64_encode(CONTREXX_SCRIPT_PATH . $this->moduleParamsJs . '&category=' . $objCategory->getId())); } // parse crumbtrail $this->parseCrumbtrail($objCategory); if ($objDownload->load(!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0) && (!$objDownload->getExpirationDate() || $objDownload->getExpirationDate() > time()) && $objDownload->getActiveStatus()) { /* DOWNLOAD DETAIL PAGE */ $this->pageTitle = contrexx_raw2xhtml($objDownload->getName(FRONTEND_LANG_ID)); $metakeys = $objDownload->getMetakeys(FRONTEND_LANG_ID); if ($this->arrConfig['use_attr_metakeys'] && !empty($metakeys)) { \Env::get('cx')->getPage()->setMetakeys($metakeys); } $this->parseRelatedCategories($objDownload); $this->parseRelatedDownloads($objDownload, $objCategory->getId()); $this->parseDownload($objDownload, $objCategory->getId()); // hide unwanted blocks on the detail page if ($this->objTemplate->blockExists('downloads_category')) { $this->objTemplate->hideBlock('downloads_category'); } if ($this->objTemplate->blockExists('downloads_subcategory_list')) { $this->objTemplate->hideBlock('downloads_subcategory_list'); } if ($this->objTemplate->blockExists('downloads_file_list')) { $this->objTemplate->hideBlock('downloads_file_list'); } if ($this->objTemplate->blockExists('downloads_simple_file_upload')) { $this->objTemplate->hideBlock('downloads_simple_file_upload'); } if ($this->objTemplate->blockExists('downloads_advanced_file_upload')) { $this->objTemplate->hideBlock('downloads_advanced_file_upload'); } } else { /* CATEGORY DETAIL PAGE */ $this->pageTitle = htmlentities($objCategory->getName($_LANGID), ENT_QUOTES, CONTREXX_CHARSET); // process create directory $this->processCreateDirectory($objCategory); // parse selected category $this->parseCategory($objCategory); // parse subcategories $this->parseCategories($objCategory, array('downloads_subcategory_list', 'downloads_subcategory'), null, 'SUB'); // parse downloads of selected category $this->parseDownloads($objCategory); // parse upload form $this->parseUploadForm($objCategory); // parse create directory form $this->parseCreateCategoryForm($objCategory); // hide unwanted blocks on the category page if ($this->objTemplate->blockExists('downloads_download')) { $this->objTemplate->hideBlock('downloads_download'); } if ($this->objTemplate->blockExists('downloads_file_detail')) { $this->objTemplate->hideBlock('downloads_file_detail'); } } // hide unwanted blocks on the category/detail page if ($this->objTemplate->blockExists('downloads_overview')) { $this->objTemplate->hideBlock('downloads_overview'); } if ($this->objTemplate->blockExists('downloads_most_viewed_file_list')) { $this->objTemplate->hideBlock('downloads_most_viewed_file_list'); } if ($this->objTemplate->blockExists('downloads_most_downloaded_file_list')) { $this->objTemplate->hideBlock('downloads_most_downloaded_file_list'); } if ($this->objTemplate->blockExists('downloads_most_popular_file_list')) { $this->objTemplate->hideBlock('downloads_most_popular_file_list'); } if ($this->objTemplate->blockExists('downloads_newest_file_list')) { $this->objTemplate->hideBlock('downloads_newest_file_list'); } if ($this->objTemplate->blockExists('downloads_updated_file_list')) { $this->objTemplate->hideBlock('downloads_updated_file_list'); } } else { /* CATEGORY OVERVIEW PAGE */ $this->parseCategories($objCategory, array('downloads_overview', 'downloads_overview_category'), null, null, 'downloads_overview_row', array('downloads_overview_subcategory_list', 'downloads_overview_subcategory'), $this->arrConfig['overview_max_subcats']); if (!empty($this->searchKeyword)) { $this->parseDownloads($objCategory); } else { if ($this->objTemplate->blockExists('downloads_file_list')) { $this->objTemplate->hideBlock('downloads_file_list'); } } /* PARSE MOST VIEWED DOWNLOADS */ $this->parseSpecialDownloads(array('downloads_most_viewed_file_list', 'downloads_most_viewed_file'), array('is_active' => true, 'expiration' => array('=' => 0, '>' => time())), array('views' => 'desc'), $this->arrConfig['most_viewed_file_count']); /* PARSE MOST DOWNLOADED DOWNLOADS */ $this->parseSpecialDownloads(array('downloads_most_downloaded_file_list', 'downloads_most_downloaded_file'), array('is_active' => true, 'expiration' => array('=' => 0, '>' => time())), array('download_count' => 'desc'), $this->arrConfig['most_downloaded_file_count']); /* PARSE MOST POPULAR DOWNLOADS */ // TODO: Rating system has to be implemented first! //$this->parseSpecialDownloads(array('downloads_most_popular_file_list', 'downloads_most_popular_file'), null, array('rating' => 'desc'), $this->arrConfig['most_popular_file_count']); /* PARSE RECENTLY UPDATED DOWNLOADS */ $filter = array('ctime' => array('>=' => time() - $this->arrConfig['new_file_time_limit']), 'expiration' => array('=' => 0, '>' => time())); $this->parseSpecialDownloads(array('downloads_newest_file_list', 'downloads_newest_file'), $filter, array('ctime' => 'desc'), $this->arrConfig['newest_file_count']); // parse recently updated downloads $filter = array('mtime' => array('>=' => time() - $this->arrConfig['updated_file_time_limit']), 'ctime' => array('<' => time() - $this->arrConfig['new_file_time_limit']), 'expiration' => array('=' => 0, '>' => time())); $this->parseSpecialDownloads(array('downloads_updated_file_list', 'downloads_updated_file'), $filter, array('mtime' => 'desc'), $this->arrConfig['updated_file_count']); // hide unwanted blocks on the overview page if ($this->objTemplate->blockExists('downloads_category')) { $this->objTemplate->hideBlock('downloads_category'); } if ($this->objTemplate->blockExists('downloads_crumbtrail')) { $this->objTemplate->hideBlock('downloads_crumbtrail'); } if ($this->objTemplate->blockExists('downloads_subcategory_list')) { $this->objTemplate->hideBlock('downloads_subcategory_list'); } if ($this->objTemplate->blockExists('downloads_file_detail')) { $this->objTemplate->hideBlock('downloads_file_detail'); } if ($this->objTemplate->blockExists('downloads_simple_file_upload')) { $this->objTemplate->hideBlock('downloads_simple_file_upload'); } if ($this->objTemplate->blockExists('downloads_advanced_file_upload')) { $this->objTemplate->hideBlock('downloads_advanced_file_upload'); } } $this->parseGlobalStuff($objCategory); }
public function testSlugReleasing() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $root = $nodeRepo->getRoot(); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n1->setParent($root); $root->addChildren($n1); $n2 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n2->setParent($root); $root->addChildren($n2); self::$em->persist($n1); self::$em->persist($n2); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(1); $p1->setTitle('slug release testpage'); $p1->setNode($n1); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); self::$em->persist($root); self::$em->persist($n1); self::$em->persist($n2); self::$em->persist($p1); self::$em->flush(); $idp1 = $p1->getId(); $idn2 = $n2->getId(); self::$em->refresh($n1); self::$em->refresh($n2); $this->assertEquals('slug-release-testpage', $p1->getSlug()); $p1 = self::$em->find('Cx\\Core\\ContentManager\\Model\\Entity\\Page', $idp1); $n2 = self::$em->find('Cx\\Core\\ContentManager\\Model\\Entity\\Node', $idn2); //shouldn't provocate a slug conflict, since we delete the other page below $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setTitle('slug release testpage'); $p2->setNode($n2); $p2->setNodeIdShadowed($n2->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->remove($p1); self::$em->flush(); self::$em->persist($p2); self::$em->flush(); $this->assertEquals('slug-release-testpage', $p2->getSlug()); }
/** * Creates a page with the given parameters. * * This should be a constructor of Page. Since PHP does not support method * overloading and doctrine needs a constructor without parameters, it's * located here. * @param \Cx\Core\ContentManager\Model\Entity\Node $parentNode * @param int $lang Language id * @param string $title Page title * @param string $type Page type (fallback, content, application) * @param string $module Module name * @param string $cmd Module cmd * @param boolean $display Is page shown in navigation? * @param string $content HTML content * @return \Cx\Core\ContentManager\Model\Entity\Page Newly created page */ public function createPage($parentNode, $lang, $title, $type, $module, $cmd, $display, $content) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setNode($parentNode); $page->setNodeIdShadowed($parentNode->getId()); $page->setLang($lang); $page->setTitle($title); $page->setType($type); $page->setModule($module); $page->setCmd($cmd); $page->setActive(true); $page->setDisplay($display); $page->setContent($content); $page->setMetatitle($title); $page->setMetadesc($title); $page->setMetakeys($title); $page->setMetarobots('index'); $page->setMetatitle($title); $page->setUpdatedBy(\FWUser::getFWUserObject()->objUser->getUsername()); return $page; }
/** * Gets the list with the headlines * * @global array * @global ADONewConnection * @global array * @return string parsed content */ private function getHeadlines() { global $_CONFIG, $objDatabase, $_ARRAYLANG, $_LANGID; // load source code if cmd value is integer if ($this->_objTpl->placeholderExists('APPLICATION_DATA')) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setVirtual(true); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('News'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $this->_objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } $validToShowList = true; $newsCategories = array(); $menuCategories = array(); $parameters = array(); $selectedCat = ''; $selectedType = ''; $selectedPublisher = ''; $selectedAuthor = ''; $newsfilter = ''; $paging = ''; $pos = 0; $i = 0; if (isset($_GET['pos'])) { $pos = intval($_GET['pos']); } $catFromCmd = !empty($_REQUEST['cmd']) ? explode(',', $_REQUEST['cmd']) : array(); $catFromReq = !empty($_REQUEST['category']) ? explode(',', $_REQUEST['category']) : array(); if (!empty($catFromCmd)) { $menuCategories = $this->getCatIdsFromNestedSetArray($this->getNestedSetCategories($catFromCmd)); if ($this->_objTpl->placeholderExists('NEWS_CMD')) { $this->_objTpl->setVariable('NEWS_CMD', $_REQUEST['cmd']); } } $newsCategories = $categories = !empty($catFromReq) ? $catFromReq : (!empty($catFromCmd) ? $catFromCmd : array()); if (count($newsCategories) == 1 && $this->categoryExists($newsCategories[0])) { $selectedCat = intval($newsCategories[0]); } if (empty($newsCategories)) { $newsCategories[] = $this->nestedSetRootId; } $newsCategories = $this->getCatIdsFromNestedSetArray($this->getNestedSetCategories($newsCategories)); if (!empty($newsCategories)) { $newsfilter .= ' AND (`nc`.`category_id` IN (' . implode(',', $newsCategories) . '))'; } if ($this->_objTpl->placeholderExists('NEWS_CAT_DROPDOWNMENU')) { $catMenu = '<select onchange="this.form.submit()" name="category">' . "\n"; $catMenu .= '<option value="">' . $_ARRAYLANG['TXT_CATEGORY'] . '</option>' . "\n"; $catMenu .= $this->getCategoryMenu(!empty($menuCategories) ? $menuCategories : array(), array($selectedCat)) . "\n"; $catMenu .= '</select>' . "\n"; $this->_objTpl->setVariable('NEWS_CAT_DROPDOWNMENU', $catMenu); } //Filter by types if ($this->arrSettings['news_use_types'] == 1) { if (!empty($_REQUEST['type'])) { $arrTypes = explode(',', $_REQUEST['type']); if (!empty($arrTypes)) { $newsfilter .= ' AND (`n`.`typeid` IN (' . implode(', ', contrexx_input2int($arrTypes)) . '))'; } $selectedType = current($arrTypes); } if ($this->_objTpl->placeholderExists('NEWS_TYPE_DROPDOWNMENU')) { $typeMenu = '<select onchange="this.form.submit()" name="type">' . "\n"; $typeMenu .= '<option value="" selected="selected">' . $_ARRAYLANG['TXT_TYPE'] . '</option>' . "\n"; $typeMenu .= $this->getTypeMenu($selectedType) . "\n"; $typeMenu .= '</select>' . "\n"; $this->_objTpl->setVariable('NEWS_TYPE_DROPDOWNMENU', $typeMenu); } } //Filter by publisher if (!empty($_REQUEST['publisher'])) { $parameters['filterPublisher'] = $publisher = contrexx_input2raw($_REQUEST['publisher']); $arrPublishers = explode(',', $publisher); if (!empty($arrPublishers)) { $newsfilter .= ' AND (`n`.`publisher_id` IN (' . implode(', ', contrexx_input2int($arrPublishers)) . '))'; } $selectedPublisher = current($arrPublishers); } if ($this->_objTpl->placeholderExists('NEWS_PUBLISHER_DROPDOWNMENU')) { $publisherMenu = '<select onchange="window.location=\'' . \Cx\Core\Routing\Url::fromModuleAndCmd('News', intval($_REQUEST['cmd'])) . '&publisher=\'+this.value" name="publisher">' . "\n"; $publisherMenu .= '<option value="" selected="selected">' . $_ARRAYLANG['TXT_NEWS_PUBLISHER'] . '</option>' . "\n"; $publisherMenu .= $this->getPublisherMenu($selectedPublisher, $selectedCat) . "\n"; $publisherMenu .= '</select>' . "\n"; $this->_objTpl->setVariable('NEWS_PUBLISHER_DROPDOWNMENU', $publisherMenu); } //Filter by Author if (!empty($_REQUEST['author'])) { $parameters['filterAuthor'] = $author = contrexx_input2raw($_REQUEST['author']); $arrAuthors = explode(',', $author); if (!empty($arrAuthors)) { $newsfilter .= ' AND (`n`.`author_id` IN (' . implode(', ', contrexx_input2int($arrAuthors)) . '))'; } $selectedAuthor = current($arrAuthors); } if ($this->_objTpl->placeholderExists('NEWS_AUTHOR_DROPDOWNMENU')) { $authorMenu = '<select onchange="this.form.submit()" name="author">' . "\n"; $authorMenu .= '<option value="" selected="selected">' . $_ARRAYLANG['TXT_NEWS_AUTHOR'] . '</option>' . "\n"; $authorMenu .= $this->getAuthorMenu($selectedAuthor) . "\n"; $authorMenu .= '</select>' . "\n"; $this->_objTpl->setVariable('NEWS_AUTHOR_DROPDOWNMENU', $authorMenu); } //Filter by tag if (!empty($_REQUEST['tag'])) { $parameters['filterTag'] = $searchTag = contrexx_input2raw($_REQUEST['tag']); $searchedTag = $this->getNewsTags(null, $searchTag); $searchedTagId = current(array_keys($searchedTag['tagList'])); if (!empty($searchedTag['newsIds'])) { $this->incrementViewingCount($searchedTagId); $newsfilter .= ' AND n.`id` IN (' . implode(',', $searchedTag['newsIds']) . ')'; $this->_objTpl->setVariable(array('NEWS_FILTER_TAG_ID' => $searchedTagId, 'NEWS_FILTER_TAG_NAME' => ucfirst(current($searchedTag['tagList'])))); if ($this->_objTpl->blockExists('tagFilterCont')) { $this->_objTpl->parse('tagFilterCont'); } } else { $validToShowList = false; } } $this->_objTpl->setVariable(array('TXT_PERFORM' => $_ARRAYLANG['TXT_PERFORM'], 'TXT_CATEGORY' => $_ARRAYLANG['TXT_CATEGORY'], 'TXT_TYPE' => $this->arrSettings['news_use_types'] == 1 ? $_ARRAYLANG['TXT_TYPE'] : '', 'TXT_DATE' => $_ARRAYLANG['TXT_DATE'], 'TXT_TITLE' => $_ARRAYLANG['TXT_TITLE'], 'TXT_NEWS_MESSAGE' => $_ARRAYLANG['TXT_NEWS_MESSAGE'])); $query = ' SELECT n.id AS newsid, n.userid AS newsuid, n.date AS newsdate, n.teaser_image_path, n.teaser_image_thumbnail_path, n.redirect, n.publisher, n.publisher_id, n.author, n.author_id, n.allow_comments AS commentactive, n.enable_tags, nl.title AS newstitle, nl.text NOT REGEXP \'^(<br type="_moz" />)?$\' AS newscontent, nl.teaser_text FROM ' . DBPREFIX . 'module_news AS n INNER JOIN ' . DBPREFIX . 'module_news_locale AS nl ON nl.news_id = n.id INNER JOIN ' . DBPREFIX . 'module_news_rel_categories AS nc ON nc.news_id = n.id WHERE status = 1 AND nl.is_active=1 AND nl.lang_id=' . FRONTEND_LANG_ID . ' AND (n.startdate<=\'' . date('Y-m-d H:i:s') . '\' OR n.startdate="0000-00-00 00:00:00") AND (n.enddate>=\'' . date('Y-m-d H:i:s') . '\' OR n.enddate="0000-00-00 00:00:00") ' . $newsfilter . ($this->arrSettings['news_message_protection'] == '1' && !\Permission::hasAllAccess() ? ($objFWUser = \FWUser::getFWUserObject()) && $objFWUser->objUser->login() ? " AND (frontend_access_id IN (" . implode(',', array_merge(array(0), $objFWUser->objUser->getDynamicPermissionIds())) . ") OR userid = " . $objFWUser->objUser->getId() . ") " : " AND frontend_access_id=0 " : '') . ' GROUP BY newsid ' . ' ORDER BY newsdate DESC'; /***start paging ****/ $objResult = $objDatabase->Execute($query); $count = $objResult->RecordCount(); $category = ''; if (!empty($_REQUEST['cmd'])) { $parameters['filterCategory'] = contrexx_input2raw($_REQUEST['cmd']); $category .= '&cmd=' . $_REQUEST['cmd']; } if (!empty($_REQUEST['category'])) { $parameters['filterCategory'] = contrexx_input2raw($_REQUEST['category']); $category .= '&category=' . $_REQUEST['category']; } $type = ''; if (!empty($_REQUEST['type'])) { $parameters['filterType'] = contrexx_input2raw($_REQUEST['type']); $type = '&type=' . $selectedType; } if ($count > intval($_CONFIG['corePagingLimit'])) { $paging = getPaging($count, $pos, '§ion=News' . $category . $type, $_ARRAYLANG['TXT_NEWS_MESSAGES'], true); } $this->_objTpl->setVariable('NEWS_PAGING', $paging); $objResult = $objDatabase->SelectLimit($query, $_CONFIG['corePagingLimit'], $pos); /*** end paging ***/ if ($count >= 1 && $validToShowList) { while (!$objResult->EOF) { $newsid = $objResult->fields['newsid']; $newstitle = $objResult->fields['newstitle']; $newsCommentActive = $objResult->fields['commentactive']; $arrNewsCategories = $this->getCategoriesByNewsId($newsid); $parameters['newsid'] = $newsid; $newsUrl = empty($objResult->fields['redirect']) ? empty($objResult->fields['newscontent']) ? '' : \Cx\Core\Routing\Url::fromModuleAndCmd('News', $this->findCmdById('details', self::sortCategoryIdByPriorityId(array_keys($arrNewsCategories), $categories)), FRONTEND_LANG_ID, $parameters) : $objResult->fields['redirect']; $htmlLink = self::parseLink($newsUrl, $newstitle, contrexx_raw2xhtml('[' . $_ARRAYLANG['TXT_NEWS_MORE'] . '...]')); $htmlLinkTitle = self::parseLink($newsUrl, $newstitle, contrexx_raw2xhtml($newstitle)); // in case that the message is a stub, we shall just display the news title instead of a html-a-tag with no href target if (empty($htmlLinkTitle)) { $htmlLinkTitle = contrexx_raw2xhtml($newstitle); } list($image, $htmlLinkImage, $imageSource) = self::parseImageThumbnail($objResult->fields['teaser_image_path'], $objResult->fields['teaser_image_thumbnail_path'], $newstitle, $newsUrl); $author = \FWUser::getParsedUserTitle($objResult->fields['author_id'], $objResult->fields['author']); $publisher = \FWUser::getParsedUserTitle($objResult->fields['publisher_id'], $objResult->fields['publisher']); $objSubResult = $objDatabase->Execute('SELECT count(`id`) AS `countComments` FROM `' . DBPREFIX . 'module_news_comments` WHERE `newsid` = ' . $objResult->fields['newsid']); if (empty($arrNewsCategories) && $this->_objTpl->blockExists('newsCategories')) { $this->_objTpl->hideBlock('newsCategories'); } $this->_objTpl->setVariable(array('NEWS_ID' => $newsid, 'NEWS_CSS' => 'row' . ($i % 2 + 1), 'NEWS_TEASER' => nl2br($objResult->fields['teaser_text']), 'NEWS_TITLE' => contrexx_raw2xhtml($newstitle), 'NEWS_LONG_DATE' => date(ASCMS_DATE_FORMAT, $objResult->fields['newsdate']), 'NEWS_DATE' => date(ASCMS_DATE_FORMAT_DATE, $objResult->fields['newsdate']), 'NEWS_TIME' => date(ASCMS_DATE_FORMAT_TIME, $objResult->fields['newsdate']), 'NEWS_LINK_TITLE' => $htmlLinkTitle, 'NEWS_LINK' => $htmlLink, 'NEWS_LINK_URL' => contrexx_raw2xhtml($newsUrl), 'NEWS_CATEGORY' => implode(', ', contrexx_raw2xhtml($arrNewsCategories)), 'NEWS_PUBLISHER' => contrexx_raw2xhtml($publisher), 'NEWS_AUTHOR' => contrexx_raw2xhtml($author), 'NEWS_COUNT_COMMENTS' => contrexx_raw2xhtml($objSubResult->fields['countComments'] . ' ' . $_ARRAYLANG['TXT_NEWS_COMMENTS']))); if (!$newsCommentActive || !$this->arrSettings['news_comments_activated']) { if ($this->_objTpl->blockExists('news_comments_count')) { $this->_objTpl->hideBlock('news_comments_count'); } } if (!empty($image)) { $this->_objTpl->setVariable(array('NEWS_IMAGE' => $image, 'NEWS_IMAGE_SRC' => contrexx_raw2xhtml($imageSource), 'NEWS_IMAGE_ALT' => contrexx_raw2xhtml($newstitle), 'NEWS_IMAGE_LINK' => $htmlLinkImage)); if ($this->_objTpl->blockExists('news_image')) { $this->_objTpl->parse('news_image'); } } else { if ($this->_objTpl->blockExists('news_image')) { $this->_objTpl->hideBlock('news_image'); } } self::parseImageBlock($this->_objTpl, $objResult->fields['teaser_image_thumbnail_path'], $newstitle, $newsUrl, 'image_thumbnail'); self::parseImageBlock($this->_objTpl, $objResult->fields['teaser_image_path'], $newstitle, $newsUrl, 'image_detail'); if (!empty($this->arrSettings['news_use_tags']) && !empty($objResult->fields['enable_tags'])) { $this->parseNewsTags($this->_objTpl, $newsid); } $this->_objTpl->parse('newsrow'); $i++; $objResult->MoveNext(); } if ($this->_objTpl->blockExists('news_list')) { $this->_objTpl->parse('news_list'); } if ($this->_objTpl->blockExists('news_menu')) { $this->_objTpl->parse('news_menu'); } if ($this->_objTpl->blockExists('news_status_message')) { $this->_objTpl->hideBlock('news_status_message'); } } else { $this->_objTpl->setVariable('TXT_NEWS_NO_NEWS_FOUND', $_ARRAYLANG['TXT_NEWS_NO_NEWS_FOUND']); if ($this->_objTpl->blockExists('news_status_message')) { $this->_objTpl->parse('news_status_message'); } if ($this->_objTpl->blockExists('news_menu')) { $this->_objTpl->parse('news_menu'); } if ($this->_objTpl->blockExists('news_list')) { $this->_objTpl->hideBlock('news_list'); } } return $this->_objTpl->get(); }
public function testPagesByLang() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $node = new \Cx\Core\ContentManager\Model\Entity\Node(); $node->setParent($nodeRepo->getRoot()); $nodeRepo->getRoot()->addChildren($node); self::$em->persist($node); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setNode($node); $p2->setNode($node); $p1->setLang(1); $p1->setTitle('testpage'); $p1->setNodeIdShadowed($node->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); $p2->setLang(2); $p2->setTitle('testpage2'); $p2->setNodeIdShadowed($node->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->persist($node); self::$em->persist($p1); self::$em->persist($p2); self::$em->flush(); self::$em->refresh($node); // Refreshes the state of the given entity from the database, overwriting local changes. $id = $p1->getId(); $r = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $p = $r->find($id); $pages = $p->getNode()->getPagesByLang(); $this->assertArrayHasKey(2, $pages); $this->assertArrayHasKey(1, $pages); $this->assertEquals('testpage', $pages[1]->getTitle()); $this->assertEquals('testpage2', $pages[2]->getTitle()); }
/** * Get page * * Get the livecam page * * @access public * @return string */ function getPage() { $this->_objTpl->setTemplate($this->pageContent); // load source code if cmd value is integer if ($this->_objTpl->placeholderExists('APPLICATION_DATA')) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setVirtual(true); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('Livecam'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $this->_objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } $this->_objTpl->setVariable(array("CMD" => $this->cam)); $this->_objTpl->setGlobalVariable('LIVECAM_DATE', $this->date); switch ($this->_action) { case 'today': $this->_objTpl->hideBlock('livecamPicture'); $this->_showArchive($this->date); break; case 'archive': $this->_objTpl->hideBlock('livecamPicture'); $this->_showArchive($this->date); break; default: $this->_objTpl->hideBlock('livecamArchive'); $this->_showPicture(); break; } if (isset($this->statusMessage)) { $this->_objTpl->setVariable('LIVECAM_STATUS_MESSAGE', $this->statusMessage); } return $this->_objTpl->get(); }
public function testTranslate() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $pageRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n1->setParent($nodeRepo->getRoot()); $nodeRepo->getRoot()->addChildren($n1); $n2 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n2->setParent($n1); self::$em->persist($n1); self::$em->persist($n2); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(1); $p1->setTitle('test translate root'); $p1->setNode($n1); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setTitle('child page'); $p2->setNode($n2); $p2->setNodeIdShadowed($n1->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->persist($n1); self::$em->persist($n2); self::$em->persist($p1); self::$em->persist($p2); self::$em->flush(); $pageId = $p2->getId(); self::$em->refresh($n1); self::$em->refresh($n2); $pageToTranslate = $pageRepo->findOneById($pageId); // copy page following redirects $page = $pageToTranslate->copyToLang(2, true, true, true, true, true, false, true); $page->setActive(1); $pageToTranslate->setupPath(2); $page->setNodeIdShadowed($pageToTranslate->getId()); self::$em->persist($page); self::$em->flush(); $pageId = $page->getId(); // Translated page id self::$em->refresh($n1); self::$em->refresh($n2); $page = $pageRepo->findOneById($pageId); // Translated page $this->assertEquals('/test-translate-root/child-page', $page->getPath()); $this->assertEquals(2, $page->getLang()); //see if the parent node is really, really there. $parentPages = $page->getNode()->getParent()->getPagesByLang(); $this->assertArrayHasKey(2, $parentPages); $this->assertEquals('test translate root', $parentPages[2]->getTitle()); }
protected function getResolvedFallbackPage() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $root = $nodeRepo->getRoot(); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n1->setParent($root); $root->addChildren($n1); self::$em->persist($n1); self::$em->flush(); //test if requesting this page... $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setTitle('pageThatsFallingBack'); $p2->setNode($n1); $p2->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_FALLBACK); $p2->setNodeIdShadowed($n1->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); //... will yield contents of this page as result. $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(2); $p1->setTitle('pageThatHoldsTheContent'); $p1->setNode($n1); $p1->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_CONTENT); $p1->setContent('fallbackContent'); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); self::$em->persist($n1); self::$em->persist($p1); self::$em->persist($p2); self::$em->flush(); self::$em->refresh($n1); return false; $url = new Url('http://example.com/pageThatsFallingBack/'); $resolver = new Resolver($url, 1, self::$em, '', $this->mockFallbackLanguages, true); $resolver->resolve(); $p = $resolver->getPage(); return $p; }
/** * Does the resolving work, extends $this->url with targetPath and params. */ public function resolvePage($internal = false) { // Abort here in case we're handling a legacy request. // The legacy request will be handled by $this->legacyResolve(). // Important: We must check for $internal == FALSE here, to abort the resolving process // only when we're resolving the initial (original) request. // Internal resolving requests might be called by $this->legacyResolve() // and shall therefore be processed. if (!$internal && isset($_REQUEST['section'])) { throw new ResolverException('Legacy request'); } $path = $this->url->getSuggestedTargetPath(); if (!$this->page || $internal) { if ($this->pagePreview) { if (!empty($this->sessionPage) && !empty($this->sessionPage['pageId'])) { $this->getPreviewPage(); } } //(I) see what the model has for us $result = $this->pageRepo->getPagesAtPath($this->url->getLangDir() . '/' . $path, null, $this->lang, false, \Cx\Core\ContentManager\Model\Repository\PageRepository::SEARCH_MODE_PAGES_ONLY); if (isset($result['page']) && $result['page'] && $this->pagePreview) { if (empty($this->sessionPage)) { if (\Permission::checkAccess(6, 'static', true)) { $result['page']->setActive(true); $result['page']->setDisplay(true); if ($result['page']->getEditingStatus() == 'hasDraft' || $result['page']->getEditingStatus() == 'hasDraftWaiting') { $logEntries = $this->logRepo->getLogEntries($result['page']); $this->logRepo->revert($result['page'], $logEntries[1]->getVersion()); } } } } //(II) sort out errors if (!$result) { throw new ResolverException('Unable to locate page (tried path ' . $path . ').'); } if (!$result['page']) { throw new ResolverException('Unable to locate page for this language. (tried path ' . $path . ').'); } if (!$result['page']->isActive()) { throw new ResolverException('Page found, but it is not active.'); } // if user has no rights to see this page, we redirect to login $this->checkPageFrontendProtection($result['page']); // If an older revision was requested, revert to that in-place: if (!empty($this->historyId) && \Permission::checkAccess(6, 'static', true)) { $this->logRepo->revert($result['page'], $this->historyId); } //(III) extend our url object with matched path / params $this->url->setTargetPath($result['matchedPath'] . $result['unmatchedPath']); $this->url->setParams($this->url->getSuggestedParams()); $this->page = $result['page']; } /* the page we found could be a redirection. in this case, the URL object is overwritten with the target details and resolving starts over again. */ $target = $this->page->getTarget(); $isRedirection = $this->page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_REDIRECT; $isAlias = $this->page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_ALIAS; //handles alias redirections internal / disables external redirection $this->forceInternalRedirection = $this->forceInternalRedirection || $isAlias; if ($target && ($isRedirection || $isAlias)) { // Check if page is a internal redirection and if so handle it if ($this->page->isTargetInternal()) { //TODO: add check for endless/circular redirection (a -> b -> a -> b ... and more complex) $nId = $this->page->getTargetNodeId(); $lId = $this->page->getTargetLangId(); $module = $this->page->getTargetModule(); $cmd = $this->page->getTargetCmd(); $qs = $this->page->getTargetQueryString(); $langId = $lId ? $lId : $this->lang; // try to find the redirection target page if ($nId) { $targetPage = $this->pageRepo->findOneBy(array('node' => $nId, 'lang' => $langId)); // revert to default language if we could not retrieve the specified langauge by the redirection. // so lets try to load the redirection of the current language if (!$targetPage) { if ($langId != 0) { //make sure we weren't already retrieving the default language $targetPage = $this->pageRepo->findOneBy(array('node' => $nId, 'lang' => $this->lang)); $langId = $this->lang; } } } else { $targetPage = $this->pageRepo->findOneByModuleCmdLang($module, $cmd, $langId); // in case we were unable to find the requested page, this could mean that we are // trying to retrieve a module page that uses a string with an ID (STRING_ID) as CMD. // therefore, lets try to find the module by using the string in $cmd and INT in $langId as CMD. // in case $langId is really the requested CMD then we will have to set the // resolved language back to our original language $this->lang. if (!$targetPage) { $targetPage = $this->pageRepo->findOneBymoduleCmdLang($module, $cmd . '_' . $langId, $this->lang); if ($targetPage) { $langId = $this->lang; } } // try to retrieve a module page that uses only an ID as CMD. // lets try to find the module by using the INT in $langId as CMD. // in case $langId is really the requested CMD then we will have to set the // resolved language back to our original language $this->lang. if (!$targetPage) { $targetPage = $this->pageRepo->findOneByModuleCmdLang($module, $langId, $this->lang); $langId = $this->lang; } // revert to default language if we could not retrieve the specified langauge by the redirection. // so lets try to load the redirection of the current language if (!$targetPage) { if ($langId != 0) { //make sure we weren't already retrieving the default language $targetPage = $this->pageRepo->findOneByModuleCmdLang($module, $cmd, $this->lang); $langId = $this->lang; } } } //check whether we have a page now. if (!$targetPage) { $this->page = null; return; } // the redirection page is located within a different language. // therefore, we must set $this->lang to the target's language of the redirection. // this is required because we will next try to resolve the redirection target if ($langId != $this->lang) { $this->lang = $langId; $this->url->setLangDir(\FWLanguage::getLanguageCodeById($langId)); $this->pathOffset = ASCMS_INSTANCE_OFFSET; } $targetPath = substr($targetPage->getPath(), 1); $this->url->setTargetPath($targetPath . $qs); $this->url->setPath($targetPath . $qs); $this->isRedirection = true; $this->resolvePage(true); } else { //external target - redirect via HTTP 302 if (\FWValidator::isUri($target)) { header('Location: ' . $target); exit; } else { if ($target[0] == '/') { $target = substr($target, 1); } $langDir = ''; if (!file_exists(ASCMS_INSTANCE_PATH . ASCMS_INSTANCE_OFFSET . '/' . $target)) { $langCode = \FWLanguage::getLanguageCodeById($this->lang); if (!empty($langCode)) { $langDir = '/' . $langCode; } } header('Location: ' . ASCMS_INSTANCE_OFFSET . $langDir . '/' . $target); exit; } } } //if we followed one or more redirections, the user shall be redirected by 302. if ($this->isRedirection && !$this->forceInternalRedirection) { $params = $this->url->getSuggestedParams(); header('Location: ' . $this->page->getURL($this->pathOffset, $params)); exit; } // in case the requested page is of type fallback, we will now handle/load this page $this->handleFallbackContent($this->page, !$internal); // set legacy <section> and <cmd> in case the requested page is an application if ($this->page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION || $this->page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_FALLBACK) { $this->command = $this->page->getCmd(); $this->section = $this->page->getModule(); } }