Example #1
0
 /**
  * Computes the target of the tag.
  *
  * @param CMS_page $page The page where the linx tag is.
  * @param string $publicTree Is the calculus made in the public or edited tree ?
  * @return CMS_page The target page, of false if no target.
  * @access public
  */
 function getTarget(&$page, $publicTree)
 {
     $pg = false;
     switch ($this->_type) {
         case "node":
             $pg = CMS_tree::getPageByID($this->_value);
             if ($pg && !$pg->hasError()) {
                 return $pg;
             } else {
                 return false;
             }
             break;
         case "codename":
             if ($this->_website) {
                 $website = CMS_websitesCatalog::getByCodename($this->_website);
                 if ($website) {
                     $pg = CMS_tree::getPageByCodename($this->_value, $website, $publicTree, true);
                 }
             } else {
                 if ($this->_crosswebsite) {
                     return CMS_tree::getPagesByCodename($this->_value, $publicTree, true);
                 } else {
                     $pg = CMS_tree::getPageByCodename($this->_value, $page->getWebsite(), $publicTree, true);
                 }
             }
             if ($pg && !$pg->hasError()) {
                 return $pg;
             } else {
                 return false;
             }
             break;
         case "relative":
             switch ($this->_value) {
                 case "root":
                     if ($this->_website) {
                         $website = CMS_websitesCatalog::getByCodename($this->_website);
                         if ($website) {
                             $pg = $website->getRoot();
                         }
                     } else {
                         $offset = abs($this->_relativeOffset) * -1;
                         $pg = CMS_tree::getAncestor($page, $offset, !$this->_crosswebsite, false);
                         //here we do not want to use public tree because, in public tree, some page may be unpublished or in this case, it break the lineage and root page cannot be found
                     }
                     break;
                 case "father":
                     $offset = abs($this->_relativeOffset);
                     $pg = CMS_tree::getAncestor($page, $offset, !$this->_crosswebsite, $publicTree);
                     break;
                 case "self":
                     $pg = $page;
                     break;
                 case "brother":
                     $pg = CMS_tree::getBrother($page, $this->_relativeOffset, $publicTree);
                     break;
             }
             if ($this->_website && is_a($pg, 'CMS_page') && !$pg->hasError()) {
                 if ($pg->getCodename()) {
                     $website = CMS_websitesCatalog::getByCodename($this->_website);
                     $pg = $website ? CMS_tree::getPageByCodename($pg->getCodename(), $website, $publicTree, true) : false;
                 } else {
                     $pg = false;
                 }
             }
             if (is_a($pg, 'CMS_page') && !$pg->hasError()) {
                 return $pg;
             } else {
                 return false;
             }
             break;
     }
 }