/** * Get the recursive HTML display for a recursivelinks, if it passes the condition of course. * * @param CMS_page $parsedPage The page in which the linx tag is * @param integer $level The current level of recursivity * @param multidimentionnal array $recursiveTree The tree to display * @param array $pages array of pages objects (indexed by id) * @param boolean $public Is the page data to show the public or edited one ? * @param array $lineage The lineage of the pages (used to see wich recursions need to be done in closed link display mode) * @return string The html of the recursive link * @access public */ function getRecursiveOutput(&$parsedPage, $level = 0, $recursiveTree, &$pages, $public, $lineage = array()) { $html = ''; if (is_array($recursiveTree) && $recursiveTree) { $rank = 1; $levelhtml = ''; foreach ($recursiveTree as $pageID => $subPages) { //get Page Object $page = $pages[$pageID]; //instanciate page if not exists as object if (!is_object($page) && sensitiveIO::isPositiveInteger($page)) { $page = CMS_tree::getPageByID($page); } $pagehtml = ''; //check if page pass the condition if (is_object($page) && (!$this->hasCondition() || $this->pagePassesConditions($parsedPage, $page, $public, $rank)) && (!$public || $public && $page->isUseable() && $page->getPublication() == RESOURCE_PUBLICATION_PUBLIC)) { //get pages infos $linkTitle = $page->getLinkTitle($public); $title = $page->getTitle($public); //set pages infos in html template $replace = array("{{title}}" => io::sanitizeHTMLString($linkTitle), "{{jstitle}}" => io::sanitizeHTMLString($linkTitle), "{{pagetitle}}" => io::sanitizeHTMLString($title), "{{jspagetitle}}" => io::sanitizeHTMLString($title), "{{desc}}" => io::sanitizeHTMLString($page->getDescription($public)), "{{href}}" => $page->getURL(), "{{id}}" => $page->getID(), "{{codename}}" => $page->getCodename($public), "{{number}}" => $rank - 1, "{{modulo}}" => ($rank - 1) % 2, "{{lvlClass}}" => "CMS_lvl" . ($level + 1), "{{currentClass}}" => $parsedPage->getID() == $page->getID() ? "CMS_current" : "", 'id="{{currentID}}"' => $parsedPage->getID() == $page->getID() ? 'id="CMS_current"' : ""); if (io::strpos($this->_htmlTemplate, '{{isParent}}') !== false) { //only if needed because getLineage require a lot of query $pagelineage = CMS_tree::getLineage($page->getID(), $parsedPage->getID(), false); $replace['class="{{isParent}}"'] = is_array($pagelineage) && in_array($parsedPage->getID(), $pagelineage) ? 'class="CMS_parent"' : ""; $replace['{{isParent}}'] = is_array($pagelineage) && in_array($parsedPage->getID(), $pagelineage) ? 'CMS_parent' : ""; $replace['id="{{isParent}}"'] = is_array($pagelineage) && in_array($parsedPage->getID(), $pagelineage) ? 'id="CMS_parent"' : ""; } if (io::strpos($this->_htmlTemplate, '{{website') !== false) { //only if needed because getWebsite require a lot of query $website = $page->getWebsite(); $replace['{{websitetitle}}'] = $website->getLabel(); $replace['{{websitecodename}}'] = $website->getCodename($public); } $pagehtml = str_replace(array_keys($replace), $replace, $this->_htmlTemplate); if ($level == 0 && ($this->_root === 'false' || !$this->_root)) { $pagehtml = str_replace(array_keys($replace), $replace, $this->getRecursiveOutput($parsedPage, $level + 1, $subPages, $pages, $public, $lineage)); } else { //check if link is in open or closed mode if ($this->_mode == "open") { //if it is open mode recurse indefinitely (until end of tree) //then mark info of sublevels or not $replace = array("{{typeClass}}" => $subPages ? "CMS_sub" : "CMS_nosub", "{{sublevel}}" => $this->getRecursiveOutput($parsedPage, $level + 1, $subPages, $pages, $public)); $pagehtml = str_replace(array_keys($replace), $replace, $pagehtml); } else { //if it is 'close' mode recurse only for pages in current lineage $recurse = false; if (is_array($lineage)) { $recurse = in_array($page->getID(), $lineage) ? true : false; } //then mark info of sublevels or not and if level is open or not $sub = $recurse ? "CMS_open" : "CMS_sub"; $replace = array("{{typeClass}}" => $subPages ? $sub : "CMS_nosub", "{{sublevel}}" => $recurse ? $this->getRecursiveOutput($parsedPage, $level + 1, $subPages, $pages, $public, $lineage) : ""); if (!$recurse) { //needed to update link targets which is used after to register watched links $it = new RecursiveArrayIterator($subPages); foreach ($it as $pageID => $element) { unset($pages[$pageID]); } } $pagehtml = str_replace(array_keys($replace), $replace, $pagehtml); } } //add APPLICATION_ENFORCES_ACCESS_CONTROL php access checking if (APPLICATION_ENFORCES_ACCESS_CONTROL && $public) { $pagehtml = $this->_addSlashAroundPHPContent($pagehtml); $replace = array("<?php" => "';", "?>" => "echo '"); $pagehtml = str_replace(array_keys($replace), $replace, $pagehtml); $pagehtml = '<?php if ($cms_user->hasPageClearance(' . $page->getID() . ', CLEARANCE_PAGE_VIEW)) {' . "\n" . 'echo \'' . $pagehtml . '\';' . "\n" . '}' . "\n" . '?>'; } $rank++; } else { //needed to update link targets which is used after to register watched links unset($pages[$pageID]); } $levelhtml .= $pagehtml; } if ($level == 0 && ($this->_root === 'false' || !$this->_root)) { $html = $levelhtml; } else { if ($levelhtml && io::strpos($this->_subleveltemplate, "{{sublevel}}") !== false) { $replace = array("{{sublevel}}" => $levelhtml, "{{lvlClass}}" => "CMS_lvl" . ($level + 1)); $html = str_replace(array_keys($replace), $replace, $this->_subleveltemplate); } else { $html = $levelhtml; } } } return $html; }