Example #1
0
 /**
  * Constructor.
  * initializes the linx.
  *
  * @param string $type The linx type
  * @param string $tagContent The tag content.
  * @param CMS_page $page The page we're parsing
  * @param boolean $publicTree Does the linx must be calculated in the public or edited tree ?
  * @return void
  * @access public
  */
 function __construct($type, $tagContent, $page, $publicTree = false, $args = array())
 {
     if (!SensitiveIO::isInSet($type, CMS_linxesCatalog::getAllTypes())) {
         $this->raiseError("Constructor has an unknown type : " . $type);
         return;
     } elseif (!is_a($page, "CMS_page")) {
         $this->raiseError("Constructor was not given a valid CMS_page");
         return;
     } else {
         $this->_args = $args;
         $this->_type = $type;
         //Hack for shorthand writing of atm-linx
         //<atm-linx type="direct" node="pageID"> ... </atm-linx>
         //<atm-linx type="direct" codename="pageCodename"> ... </atm-linx>
         if ((isset($this->_args['node']) || isset($this->_args['codename'])) && $this->_type == 'direct') {
             $tag = new CMS_XMLTag('atm-linx', $this->_args);
             $tag->setTextContent($tagContent);
             $tagContent = '<atm-linx type="direct">' . '<selection ' . (isset($this->_args['crosswebsite']) ? ' crosswebsite="' . $this->_args['crosswebsite'] . '"' : '') . '>';
             if (isset($this->_args['node'])) {
                 $tagContent .= '<start><nodespec type="node" value="' . $this->_args['node'] . '" /></start>';
                 //remove useless node argument
                 unset($this->_args['node']);
             } else {
                 $tagContent .= '<start><nodespec type="codename" value="' . $this->_args['codename'] . '" /></start>';
                 //remove useless node argument
                 unset($this->_args['codename']);
             }
             $tagContent .= '</selection>' . '<display>' . '<htmltemplate>' . $tag->getInnerContent() . '</htmltemplate>' . '</display>' . '</atm-linx>';
         }
         $this->_page = $page;
         $this->_publicTree = $publicTree;
         $domdocument = new CMS_DOMDocument();
         try {
             $domdocument->loadXML($tagContent);
         } catch (DOMException $e) {
             $this->raiseError('Malformed atm-linx content in page ' . $page->getID() . ' : ' . $e->getMessage() . "\n" . $tagContent, true);
             return false;
         }
         $selections = $domdocument->getElementsByTagName('selection');
         if ($selections->length > 0) {
             $selection = $selections->item(0);
             //parse the selection for nodespecs and condition
             if (!$this->_parseSelection($selection)) {
                 $this->raiseError();
                 return;
             }
         }
         $noselections = $domdocument->getElementsByTagName('noselection');
         if ($noselections->length > 0) {
             $this->_noselection = $noselections->item(0);
         }
         $displays = $domdocument->getElementsByTagName('display');
         //get the displays objects
         $unsortedDisplays = array();
         foreach ($displays as $display) {
             $unsortedDisplays[] = new CMS_linxDisplay($display);
         }
         //put the default display (the one with no condition) at the end of the array
         $default = false;
         foreach ($unsortedDisplays as $dsp) {
             if ($dsp->hasCondition() && !$default) {
                 $this->_displays[] = $dsp;
             } else {
                 $default = $dsp;
             }
         }
         if ($default) {
             $this->_displays[] = $default;
         }
     }
 }