/** * Recursive function to Build the targets tree (recursivelinks) * then apply the selection to the builded targets * Uses the websites catalog to exclude (for desclinks and sublinks) pages that are not part of the current website * * @return multidimensionnal array : array("recursiveTree" => tree of page id, "targets" => cms_page objects); * @access private */ protected function _buildRecursiveTargets($pageID, $level = 0) { $targets = array(); $recursiveTargets = array(); $targets_temp = CMS_tree::getSiblings($pageID, $this->_publicTree, false); if ($targets_temp && is_array($targets_temp)) { foreach ($targets_temp as $aTarget_temp) { if ($this->_crosswebsite || !CMS_websitesCatalog::isWebsiteRoot($aTarget_temp)) { //construct targets array $targets[$aTarget_temp] = $aTarget_temp; if ($this->_selectionCondition === false || $this->_selectionCondition->levelPasses($level + 1)) { //construct recursive targets array and array of cms_pages objects $returnedDatas = $this->_buildRecursiveTargets($aTarget_temp, $level + 1); $targets = $targets + $returnedDatas["targets"]; //add this page to father watches if (sizeof($returnedDatas["targets"])) { $this->_fatherWatches[] = $aTarget_temp; } $recursiveTargets[$aTarget_temp] = $returnedDatas["recursiveTree"]; } } } } return array("recursiveTree" => $recursiveTargets, "targets" => $targets); }
function getBigTree(&$user, &$lines, $page, $offset, $link, $pageProperty = false, $father) { global $cms_language; global $hideMenu; global $pageProperty; global $title; global $backLink; global $pageLink; global $onClick; global $heading; global $frame; global $lineage; global $startRoot; global $linkTarget; global $cms_user; static $haveRootInDisplay; if (!$father) { $father = $page; } $stop = '1'; $sign = 'plus'; //get siblings $sibs = CMS_tree::getSiblings($page, false, false); //si pas de fils : // => on affiche aucun signe // => on sort if (!$sibs || !sizeof($sibs)) { $sign = ''; } elseif (in_array($page->getID(), $lineage)) { $stop = '0'; $sign = 'minus'; } $status = $page->getStatus(); if ($link && strpos($link, "%s") !== false) { $link_final = sprintf($link, $page->getID()); } elseif ($link == 'false' && $onClick) { $link_final = "#"; $link_onClick = ' onClick="' . sprintf($onClick, $page->getID()) . 'return false;"'; $linkTarget = "_self"; } else { $link_final = $link; } $pageTitle = PAGE_LINK_NAME_IN_TREE ? $page->getLinkTitle() : $page->getTitle(); if ($link_final) { $link_final = '<a href="' . $link_final . '"' . $link_onClick . ' name="n' . $page->getID() . '" target="' . $linkTarget . '" class="admin_tree_page">' . htmlspecialchars($pageTitle) . '</a>'; } else { $link_final = htmlspecialchars($pageTitle); } //page cell display $cell_display = '<a name="page_' . $page->getID() . '"></a> <table border="0" cellpadding="2" cellspacing="0"> <tr>'; $size = "0"; for ($i = 0; $i < $offset; $i++) { $size = $size + 20; } if ($page->getID() == APPLICATION_ROOT_PAGE_ID || $haveRootInDisplay) { $size = $size - 20; $haveRootInDisplay = true; } if ($size > 0) { $cell_display .= '<td width="1"><img src="' . PATH_ADMIN_IMAGES_WR . '/../v3/img/pix_trans.gif" width="' . $size . '" height="2" border="0" /></td>'; } switch ($sign) { case '': $cell_display .= '<td width="20"><img src="' . PATH_ADMIN_IMAGES_WR . '/../v3/img/pix_trans.gif" width="20" height="2" border="0" /></td>'; break; case 'minus': if ($page->getID() != APPLICATION_ROOT_PAGE_ID) { $cell_display .= '<td width="20" align="center"><img src="' . PATH_ADMIN_IMAGES_WR . '/../v3/img/pix_trans.gif" width="20" height="1" border="0" /><br /><a href="' . $_SERVER["SCRIPT_NAME"] . '?root=' . $father->getID() . '&pageProperty=' . $pageProperty . '&hideMenu=' . $hideMenu . '&title=' . $title . '&backLink=' . $backLink . '&frame=' . $frame . '&heading=' . $heading . '&encodedPageLink=' . base64_encode($pageLink) . '&encodedOnClick=' . base64_encode($onClick) . '&linkTarget=' . $linkTarget . '#page_' . $page->getID() . '" class="admin_tree_sign">-</a></td>'; } break; case 'plus': $cell_display .= '<td width="20" align="center"><img src="' . PATH_ADMIN_IMAGES_WR . '/../v3/img/pix_trans.gif" width="20" height="1" border="0" /><br /><a href="' . $_SERVER["SCRIPT_NAME"] . '?root=' . $page->getID() . '&pageProperty=' . $pageProperty . '&hideMenu=' . $hideMenu . '&title=' . $title . '&backLink=' . $backLink . '&frame=' . $frame . '&heading=' . $heading . '&encodedPageLink=' . base64_encode($pageLink) . '&encodedOnClick=' . base64_encode($onClick) . '&linkTarget=' . $linkTarget . '#page_' . $page->getID() . '" class="admin_tree_sign">+</a></td>'; break; } //property display if ($pageProperty) { switch ($pageProperty) { case "last_creation_date": $lng = $user->getLanguage(); $date = $page->getLastFileCreationDate(); if (is_a($date, "CMS_date")) { $date->setFormat($lng->getDateFormat()); $property_display = $date->getLocalizedDate(); } break; case "template": $tmp = $page->getTemplate(); $property_display = is_a($tmp, "CMS_pageTemplate") ? $tmp->getLabel() : '???'; break; } } else { $property_display = $page->getID(); } $cell_display .= ' <td class="admin">' . $status->getHTML(true, $cms_user, MOD_STANDARD_CODENAME, $page->getID()) . '</td> <td class="admin_tree_page" nowrap="nowrap">' . $link_final . ' (' . $property_display . ')</td> </tr> </table> '; $bgcolor = $page->getID() == $startRoot ? ' bgcolor="#DDDAD9"' : ''; //add the line $lines .= '<tr onMouseOver="changeColor(this,\'DDDAD9\');" onMouseOut="changeColor(this,\'\');"> <td' . $bgcolor . ' nowrap="nowrap"> ' . $cell_display . ' </td> </tr>' . "\n"; if ($stop) { return $lines; } //on traite les fils $sibs = CMS_tree::getSiblings($page); foreach ($sibs as $sib) { if ($user->hasPageClearance($sib->getID(), CLEARANCE_PAGE_VIEW)) { getBigTree($user, $lines, $sib, $offset + 1, $link, $pageProperty, $page); } } }
function duplicatePage($user, $page, $pageToAttachTo) { global $pageDuplicated, $duplicatedCodenames, $cms_user; if (is_a($page, "CMS_page") && is_a($pageToAttachTo, "CMS_page") && $page->getTemplate()) { //check codename duplication $removeCodename = false; if ($page->getCodename()) { //if codename already exists in website destination, then we must remove it if (CMS_tree::getPageByCodename($page->getCodename(), $pageToAttachTo->getWebsite(), false, false)) { $removeCodename = true; } } //Duplicate page template $tpl = $page->getTemplate(); $tpl_copy = CMS_pageTemplatesCatalog::getCloneFromID($tpl->getID(), false, true, false, $tpl->getID()); $_tplID = $tpl_copy->getID(); //Create copy of given page $newPage = $page->duplicate($user, $_tplID); if ($removeCodename) { $newPage->setCodename('', $cms_user); $newPage->writeToPersistence(); $duplicatedCodenames[] = $page->getCodename(); } //Move to destination in tree if (is_null($newPage) || !CMS_tree::attachPageToTree($newPage, $pageToAttachTo)) { return null; } $pageDuplicated[] = $newPage->getID(); //Proceed with siblings $sibs = CMS_tree::getSiblings($page); if (!$sibs || !sizeof($sibs)) { return $pageToAttachTo; } else { $pageToAttachTo = $newPage; } foreach ($sibs as $sib) { if ($user->hasPageClearance($sib->getID(), CLEARANCE_PAGE_EDIT) && !in_array($sib->getID(), $pageDuplicated)) { duplicatePage($user, $sib, $pageToAttachTo); } } } }
//check current level number $lineage = CMS_tree::getLineage($rootId, $nodeId, false); if ($maxlevel && sizeof($lineage) >= $maxlevel) { $maxlevelReached = true; } } $siblings = CMS_tree::getSiblings($node); } elseif (isset($_REQUEST['node']) && io::strpos($_REQUEST['node'], 'root') === 0) { //load website root $node = CMS_tree::getPageByID($rootId); //check for users rights if ($showRoot && $cms_user->hasPageClearance($node->getID(), $editable ? CLEARANCE_PAGE_EDIT : CLEARANCE_PAGE_VIEW)) { $siblings = array($node); unset($node); } else { $siblings = CMS_tree::getSiblings($node); } if ($maxlevel == 1) { $maxlevelReached = true; } } //remove unused siblings foreach ($siblings as $key => $sibling) { if (!$cms_user->hasPageClearance($sibling->getID(), $editable ? CLEARANCE_PAGE_EDIT : CLEARANCE_PAGE_VIEW)) { unset($siblings[$key]); } } //if node is root, then get all orphan tree pages and append them to siblings if (isset($node) && $node->getID() == $rootId) { //get all clearances root pages $roots = $editable ? $cms_user->getEditablePageClearanceRoots() : $cms_user->getViewablePageClearanceRoots();
/** * Recursive function to build items tree. * * @param mixed $items : current category or page * @param integer $count, to determine item in-tree depth * @param integer $parent_clearance, immediate parent item clearance * @return string HTML formated */ function build_items_tree(&$item, $count, $parent_clearance) { global $moduleCodename, $cms_language, $cms_user, $profileId, $hash; //current user environment global $items_ids; //reference to all displayed items global $modules_clearances, $stack_clearances; //all clearances types available global $maxDepth, $clearance_colors; //displaying options global $disableFields; //disable status $s = ''; $count++; // Current category clearance $i_default_clearance = $stack_clearances->getElementValueFromKey($item->getID()); // Thig hidden but sets current category clearance identical // to its parent's one, used to hide some checkboxes $i_current_clearance = $i_default_clearance !== false ? (int) $i_default_clearance : $parent_clearance; if ($i_default_clearance !== false) { $bgColor = ' style="background-color:' . $clearance_colors[$i_default_clearance] . ';"'; } elseif (!$i_default_clearance && $item->isRoot()) { $bgColor = ' style="background-color:' . $clearance_colors[CLEARANCE_MODULE_NONE] . ';"'; } else { $bgColor = ''; } $items_ids[] = $item->getID(); if (is_a($item, 'CMS_moduleCategory')) { $hasSiblings = $item->hasSiblings(); } else { $hasSiblings = CMS_tree::hasSiblings($item); } //Link to sub categories if ($hasSiblings) { if ($count < $maxDepth) { $thumbnail = ''; } else { $thumbnail = '<a href="#" onclick="Automne.categories.open(' . $item->getID() . ', \'' . $hash . '\', this);return false;" title="ID : ' . $item->getID() . '">+</a>'; } } else { $thumbnail = ''; } //disabled checkboxes if needed if ($disableFields) { $disabled = ' disabled="disabled"'; } else { //check if user has edition rights on item if (is_a($item, 'CMS_moduleCategory')) { $disabled = $cms_user->hasModuleCategoryClearance($item->getID(), CLEARANCE_MODULE_MANAGE) ? '' : ' disabled="disabled"'; } else { $disabled = $cms_user->hasPageClearance($item->getId(), CLEARANCE_PAGE_EDIT) ? '' : ' disabled="disabled"'; } } $label = is_a($item, 'CMS_moduleCategory') ? $item->getLabel() : $item->getTitle(); $label = $disabled ? '<span style="color:grey;">' . $label . '</span>' : $label; // Get title and form actions $s .= ' <li' . $bgColor . ' id="li-' . $hash . '-' . $item->getID() . '"> <table border="0" cellpadding="0" cellspacing="0"' . $bgColor . ' onMouseOver="Automne.categories.onRow(this);" onMouseOut="Automne.categories.outRow(this);"> <tr> <td width="100%"> ' . $thumbnail . '<span title="ID : ' . $item->getID() . '">' . $label . '</span></td> <td width="120"> <table width="120" border="0" cellpadding="0" cellspacing="0" id="checkboxes-' . $hash . '-' . $item->getID() . '"> <tr>'; @reset($modules_clearances); while (list($msg, $value) = @each($modules_clearances)) { $sel = ''; //check if user has edition rights on item if ($disableFields) { $disabled = ' disabled="disabled"'; } else { if (is_a($item, 'CMS_moduleCategory')) { $disabled = $cms_user->hasModuleCategoryClearance($item->getID(), CLEARANCE_MODULE_MANAGE) ? '' : ' disabled="disabled"'; } else { $disabled = $cms_user->hasPageClearance($item->getId(), CLEARANCE_PAGE_EDIT) ? '' : ' disabled="disabled"'; } } if ($item->isRoot() || !$item->isRoot() && $parent_clearance !== $value) { // If none clearance defined yet, access is denied to any root category if (!$i_default_clearance && $value === CLEARANCE_MODULE_NONE && $item->isRoot() || $i_default_clearance !== false && (int) $i_default_clearance === $value) { $sel = ' checked="checked"'; } $s .= '<td width="30" align="center"><input type="checkbox"' . $disabled . ' onclick="Automne.categories.unselectOthers(\'' . $item->getID() . '\',\'' . $value . '\', \'' . $count . '\', \'' . $hash . '\');" id="check-' . $hash . '-' . $item->getID() . '_' . $value . '" name="cat' . $item->getID() . '" value="' . $value . '"' . $sel . $disabled . ' /></td>'; } else { $s .= '<td width="30" align="center"><input type="checkbox"' . $disabled . ' onclick="Automne.categories.unselectOthers(\'' . $item->getID() . '\',\'' . $value . '\', \'' . $count . '\', \'' . $hash . '\');" id="check-' . $hash . '-' . $item->getID() . '_' . $value . '" name="cat' . $item->getID() . '" value="' . $value . '" style="display:none;"' . $disabled . ' /></td>'; } } $s .= ' </tr> </table> </td> </tr> </table>'; // Print siblings tree recursivly if ($hasSiblings) { if ($count < $maxDepth) { //get siblings if (is_a($item, 'CMS_moduleCategory')) { $attrs = array("module" => $moduleCodename, "language" => $cms_language, "level" => $item->getID(), "root" => false, "attrs" => false, "cms_user" => &$cms_user); $siblings = CMS_module::getModuleCategories($attrs); } else { $siblings = CMS_tree::getSiblings($item); } // Prepare form actions here if (is_array($siblings) && $siblings) { $s .= '<ul id="ul-' . $hash . '-' . $item->getID() . '">'; foreach ($siblings as $aSibling) { if (is_a($item, 'CMS_moduleCategory')) { $aSibling->setAttribute('language', $cms_language); } $s .= build_items_tree($aSibling, $count, $i_current_clearance); } $s .= '</ul>'; } } } $s .= '</li>'; return $s; }
/** * Get the tree string needed by the text edition applet * format is : * pageID/roottitle/subroottitle/pagetitle:::[SAME AS BEFORE...] * where ::: is the separator passed as argument * Static function. * Recursive function * * @param string $separator The pages separator. * @return string the tree string * @access public */ static function getTreeString(&$user, $pageID, $separator, &$treeString) { static $treeStringInfos; $root = CMS_tree::getRoot(); $lineage = CMS_tree::getLineage($root->getID(), $pageID, false); $treeString .= $pageID; //add ancestors if (is_array($lineage) && $lineage) { foreach ($lineage as $ancestor) { //to reduce the total time of the function (really long on big websites). if (!$treeStringInfos[$ancestor]) { $ancestor = CMS_tree::getPageByID($ancestor); $ancestorTitle = $treeStringInfos[$ancestor->getID()] = $ancestor->getTitle(); } else { $ancestorTitle = $treeStringInfos[$ancestor]; } //test the presence of the separator in the sibling title if (io::strpos($ancestorTitle, $separator) !== false) { CMS_grandFather::raiseError("Page has the separator in its title (transformed) : " . $ancestorTitle); $title = str_replace($separator, "[SEPARATOR]", $ancestorTitle); } else { $title = $ancestorTitle; } $treeString .= "/" . addslashes($title); } } $treeString .= $separator; //get siblings and recursively show them $sibs = CMS_tree::getSiblings($pageID, false, false); if (!$sibs) { return $treeString; } foreach ($sibs as $sib) { CMS_tree::getTreeString($user, $sib, $separator, $treeString); } }