/** * Override this to do your representation of the tree. * * @param string $title * @param int $level 0-based level of the element * @param boolean $hasChilds are there children of this element? if yes, they will be processed in the subsequent calls. * @param int $lang language id * @param string $path path to this element, e.g. '/CatA/CatB' * @param boolean $current if a $currentPage has been specified, this will be set to true if either a parent element of the current element or the current element itself is rendered. * * @return string your string representation of the element. */ protected function renderElement($title, $level, $hasChilds, $lang, $path, $current, $page) { $url = (string) \Cx\Core\Routing\NodePlaceholder::fromNode($page->getNode(), null, array()); $pages = $page->getNode()->getPages(); $titles = array(); foreach ($pages as $page) { $titles[\FWLanguage::getLanguageCodeById($page->getLang())] = $page->getTitle(); } $this->return[] = array('click' => "javascript:{setUrl('{$url}',null,null,'" . \FWLanguage::getLanguageCodeById(BACKEND_LANG_ID) . $path . "','page')}", 'name' => $titles, 'extension' => 'Html', 'level' => $level - 1, 'url' => $path, 'node' => $url); }
/** * Resolves cmd. If it's a node placeholder, search is limited to the node's * branch * @param \Cx\Core\ContentManager\Model\Entity\Page $page Current page */ public function __construct($page = null) { if (!$page) { $page = \Cx\Core\Core\Controller\Cx::instanciate()->getPage(); } if (!empty($page->getCmd())) { // Try to resolve node placeholder try { $nodePlaceholder = \Cx\Core\Routing\NodePlaceholder::fromPlaceholder($page->getCmd()); $this->rootPage = $nodePlaceholder->getPage(); } catch (\Cx\Core\Routing\NodePlaceholderException $e) { } } }
protected function insertFixtures() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $root = $nodeRepo->getRoot(); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n2 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n3 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n4 = new \Cx\Core\ContentManager\Model\Entity\Node(); //redirection $n5 = new \Cx\Core\ContentManager\Model\Entity\Node(); //alias $n1->setParent($root); $n2->setParent($n1); $n3->setParent($n2); $n4->setParent($root); $n5->setParent($root); $root->addChildren($n1); $n1->addChildren($n2); $n2->addChildren($n3); $root->addChildren($n4); $root->addChildren($n4); self::$em->persist($n1); self::$em->persist($n2); self::$em->persist($n3); self::$em->persist($n4); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(1); $p1->setTitle('resolver testpage1'); $p1->setNode($n1); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); $p4 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p4->setLang(1); $p4->setTitle('testpage1_child'); $p4->setNode($n2); $p4->setNodeIdShadowed($n2->getId()); $p4->setUseCustomContentForAllChannels(''); $p4->setUseCustomApplicationTemplateForAllChannels(''); $p4->setUseSkinForAllChannels(''); $p4->setCmd(''); $p4->setActive(1); self::$em->persist($n1); self::$em->persist($n2); self::$em->persist($p1); self::$em->persist($p4); self::$em->flush(); self::$em->refresh($n1); self::$em->refresh($n2); $p5 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p5->setLang(1); $p5->setTitle('subtreeTest_target'); $p5->setNode($n3); $p5->setNodeIdShadowed($n3->getId()); $p5->setUseCustomContentForAllChannels(''); $p5->setUseCustomApplicationTemplateForAllChannels(''); $p5->setUseSkinForAllChannels(''); $p5->setCmd(''); $p5->setActive(1); $p6 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p6->setLang(0); $p6->setTitle('testalias'); $p6->setNode($n5); $p6->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_ALIAS); $p6->setTarget($p4->getId() . '|1'); $p6->setNodeIdShadowed($n5->getId()); $p6->setUseCustomContentForAllChannels(''); $p6->setUseCustomApplicationTemplateForAllChannels(''); $p6->setUseSkinForAllChannels(''); $p6->setCmd(''); $p6->setActive(1); self::$em->persist($n3); self::$em->persist($n5); self::$em->persist($p5); self::$em->persist($p6); self::$em->flush(); self::$em->refresh($n3); self::$em->refresh($n5); $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_REDIRECT); $p2->setTitle('redirection'); $p2->setNode($n4); $p2->setTarget(\Cx\Core\Routing\NodePlaceholder::fromNode($n2, 1, array('foo' => 'test'))->getPlaceholder()); $p2->setNodeIdShadowed($n4->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->persist($p2); self::$em->flush(); self::$em->refresh($n4); self::$em->refresh($p2); }
/** * @todo Use param $page (to update a page without prividing an id per GET) */ function _modifyAlias($array, $page = null) { global $_ARRAYLANG, $_CONFIG; $objCx = \ContrexxJavascript::getInstance(); $objCx->setVariable(array('regExpUriProtocol' => \FWValidator::REGEX_URI_PROTO, 'contrexxPathOffset' => ASCMS_PATH_OFFSET, 'contrexxBaseUrl' => ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET), 'alias'); $aliasId = !empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; // search for existing alias if (!($alias = $this->_getAlias($aliasId))) { $alias = $this->_createTemporaryAlias(); $aliasId = 0; } // handle form submit if (isset($array['alias_save'])) { if (!empty($array['alias_target']) && !empty($array['alias_target_protocol'])) { $array['alias_target'] = $array['alias_target_protocol'] . $array['alias_target']; } // set target and -type $newtype = preg_match('/\\[\\[' . \Cx\Core\ContentManager\Model\Entity\Page::NODE_URL_PCRE . '\\]\\](\\S*)?/ix', $array['alias_target']) ? 'local' : 'url'; $newtarget = !empty($array['alias_target']) ? trim(contrexx_stripslashes($array['alias_target'])) : ''; // handle existing slugs pointing to the target $aliases = array(); if (!empty($array['alias_aliases']) && is_array($array['alias_aliases'])) { $nr = 0; foreach ($array['alias_aliases'] as $sourceId => $aliasSource) { if (!empty($aliasSource)) { $aliases[intval($sourceId)] = $aliasSource; } $nr++; } } // delete removed $sources = $this->_getAliasesWithSameTarget($alias); foreach ($sources as $sourceAlias) { if (!isset($aliases[$sourceAlias->getNode()->getId()])) { // alias is no longer listet in POST: delete it $this->_delete($sourceAlias->getNode()->getId()); } } // handle enw slugs pointing to the target $newaliases = array(); if (!empty($array['alias_aliases_new']) && is_array($array['alias_aliases_new'])) { foreach ($array['alias_aliases_new'] as $id => $newAliasSource) { if (!empty($newAliasSource)) { $newaliases[] = $newAliasSource; } } } // save information if (!empty($newtarget)) { if (count($aliases) || count($newaliases)) { $error = false; if ($newtype == 'local') { $placeholder = \Cx\Core\Routing\NodePlaceholder::fromPlaceholder($newtarget); // when creating a new alias //if (($aliasId === 0) && !$placeholder->hasLang()) { // make sure language is specified in placeholder $placeholder->setLang(FRONTEND_LANG_ID); //} // force usage of node ID $newtarget = $placeholder->getPlaceholder(true); } foreach ($aliases as $id => $slug) { if (($message = $this->_saveAlias($slug, $newtarget, $newtype == 'local', $id)) !== true) { $error = true; if ($message !== false) { $this->arrStatusMsg['error'][] = $message; } else { $this->arrStatusMsg['error'][] = $aliasId ? $_ARRAYLANG['TXT_ALIAS_ALIAS_UPDATE_FAILED'] : $_ARRAYLANG['TXT_ALIAS_ALIAS_ADD_FAILED']; $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_RETRY_OPERATION']; } break; } } if (!$error) { foreach ($newaliases as $id => $slug) { if (($message = $this->_saveAlias($slug, $newtarget, $newtype == 'local')) !== true) { $error = true; if ($message !== false) { $this->arrStatusMsg['error'][] = $message; } else { $this->arrStatusMsg['error'][] = $aliasId ? $_ARRAYLANG['TXT_ALIAS_ALIAS_UPDATE_FAILED'] : $_ARRAYLANG['TXT_ALIAS_ALIAS_ADD_FAILED']; $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_RETRY_OPERATION']; } break; } } } if (!$error) { $this->arrStatusMsg['ok'][] = $aliasId ? $_ARRAYLANG['TXT_ALIAS_ALIAS_SUCCESSFULLY_UPDATED'] : $_ARRAYLANG['TXT_ALIAS_ALIAS_SUCCESSFULLY_ADDED']; } $_REQUEST['act'] = ''; // For the navigation return $this->_list(); } else { $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_ONE_ALIAS_REQUIRED_MSG']; } } else { if ($newtype == 'local') { $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_PAGE_REQUIRED_MSG']; } else { $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_URL_REQUIRED_MSG']; } } } $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser(); $mediaBrowser->setOptions(array('type' => 'button', 'data-cx-mb-views' => 'sitestructure')); $mediaBrowser->setCallback('aliasSetUrl'); // prepare template $this->_objTpl->loadTemplateFile('module_alias_modify.html'); $this->_pageTitle = $aliasId ? $_ARRAYLANG['TXT_ALIAS_MODIFY_ALIAS'] : $_ARRAYLANG['TXT_ALIAS_ADD_ALIAS']; $this->_objTpl->setVariable(array('TXT_ALIAS_TARGET_PAGE' => $_ARRAYLANG['TXT_ALIAS_TARGET_PAGE'], 'ALIAS_MEDIABROWSER_BUTTON' => $mediaBrowser->getXHtml($_ARRAYLANG['TXT_ALIAS_BROWSE']), 'TXT_ALIAS_ALIAS_ES' => $_ARRAYLANG['TXT_ALIAS_ALIAS_ES'], 'TXT_ALIAS_DELETE' => $_ARRAYLANG['TXT_ALIAS_DELETE'], 'TXT_ALIAS_CONFIRM_REMOVE_ALIAS' => $_ARRAYLANG['TXT_ALIAS_CONFIRM_REMOVE_ALIAS'], 'TXT_ALIAS_ADD_ANOTHER_ALIAS' => $_ARRAYLANG['TXT_ALIAS_ADD_ANOTHER_ALIAS'], 'TXT_ALIAS_CANCEL' => $_ARRAYLANG['TXT_ALIAS_CANCEL'], 'TXT_ALIAS_SAVE' => $_ARRAYLANG['TXT_ALIAS_SAVE'], 'TXT_ALIAS_STANDARD_RADIOBUTTON' => $_ARRAYLANG['TXT_ALIAS_STANDARD_RADIOBUTTON'], 'TXT_ALIAS_INTERNAL' => $_ARRAYLANG['TXT_INTERNAL'])); $this->_objTpl->setGlobalVariable(array('TXT_ALIAS_DELETE' => $_ARRAYLANG['TXT_ALIAS_DELETE'], 'ALIAS_DOMAIN_URL' => 'http://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/', 'TXT_ALIAS_STANDARD_RADIOBUTTON' => $_ARRAYLANG['TXT_ALIAS_STANDARD_RADIOBUTTON'])); $target = $alias->getTarget(); $targetURL = ''; $is_local = $this->_isLocalAliasTarget($alias); if ($is_local) { // alias points to a local webpage $targetPage = $this->_fetchTarget($alias); if ($targetPage) { preg_match('/\\[\\[' . \Cx\Core\ContentManager\Model\Entity\Page::NODE_URL_PCRE . '\\]\\](\\S*)?/ix', $target, $matches); $targetURL = ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . $this->_getURL($targetPage) . $matches[6]; } } else { $targetURL = $target; } $this->_objTpl->setVariable(array('ALIAS_ID' => $aliasId, 'ALIAS_TITLE_TXT' => $this->_pageTitle, 'ALIAS_TARGET' => htmlentities($target, ENT_QUOTES, CONTREXX_CHARSET), 'ALIAS_TARGET_TEXT' => htmlentities($targetURL, ENT_QUOTES, CONTREXX_CHARSET))); $nr = 0; $sources = $this->_getAliasesWithSameTarget($alias); if (is_array($sources) && count($sources)) { foreach ($sources as $sourceAlias) { $url = $sourceAlias->getSlug(); $this->_objTpl->setVariable(array('ALIAS_DOMAIN_URL' => 'http://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/', 'ALIAS_ALIAS_ID' => $sourceAlias->getNode()->getId(), 'ALIAS_ALIAS_NR' => $nr++, 'ALIAS_ALIAS_PREFIX' => '', 'ALIAS_ALIAS_URL' => stripslashes(htmlentities($url, ENT_QUOTES, CONTREXX_CHARSET)))); $this->_objTpl->parse('alias_list'); } } $this->_objTpl->setVariable(array('ALIAS_DOMAIN_URL' => 'http://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/', 'ALIAS_ALIAS_PREFIX' => '_new')); $this->_objTpl->parse('alias_list'); }
/** * Checks if the passed page or its redirect target page is broken. * * @param array $arguments * @return boolean */ public function isBroken($arguments) { if (isset($arguments['get']['pageId'])) { if (!\Env::get('em')->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page')->find($arguments['get']['pageId'])) { return true; } } if (isset($arguments['get']['pageRedirectPlaceholder'])) { try { if (!\Cx\Core\Routing\NodePlaceholder::fromPlaceholder($arguments['get']['pageRedirectPlaceholder'])->getPage()) { return true; } } catch (\Cx\Core\Routing\NodePlaceholderException $e) { return true; } } return false; }
/** * Checks if the passed page or its redirect target page is broken. * * @param array $arguments * @return boolean */ public function isBroken($arguments) { if (isset($arguments['get']['pageId'])) { if (!\Env::get('em')->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page')->find($arguments['get']['pageId'])) { return true; } } if (isset($arguments['get']['pageRedirectPlaceholder'])) { $filePath = \Env::get('cx')->getClassLoader()->getFilePath($arguments['get']['pageRedirectPlaceholder']); //do not break the page, if the redirection shows to a valid file if (is_file($filePath)) { return false; } try { //break the page, when the file or the placeholder does not exist if (!\Cx\Core\Routing\NodePlaceholder::fromPlaceholder($arguments['get']['pageRedirectPlaceholder'])->getPage()) { return true; } } catch (\Cx\Core\Routing\NodePlaceholderException $e) { return true; } } return false; }