/** toggle content element state (active / disabled) */ function toggleContentElement() { global $option; $ce_name = JRequest::getVar('cename', ''); $return_to = "index2.php?option={$option}&controller=utilities&task=showce"; if (!($ce = getContentElementByName($ce_name, true))) { return $this->setRedirect($return_to, "{$ce} Error, wrong content element name."); } if (!($xml = $ce->xml)) { $this->setRedirect($return_to, "Error, no XML file."); } require_once JPATH_SITE . "/includes/domit/xml_domit_lite_include.php"; $xmlDoc = new DOMIT_lite_Document(); $xmlDoc->resolveErrors(true); if ($xmlDoc->loadXML($xml, false, true)) { $element =& $xmlDoc->documentElement; if ($element->getTagName() == 'contentelement') { if ($element->hasAttribute("active")) { $curr_state = $element->getAttribute("active"); $element->setAttribute("active", $curr_state == 0 ? '1' : '0'); $xmlDoc->saveXML($xml, true); } } } $this->setRedirect($return_to, "Done"); }
/** class constructor * @param xmlfile $xml path to the XML file * @param boolean $load_inactive load inactive content elements, default false * @return the content element object or the default 'content' CE if XML file is not given * */ function cpContentElement($xml = null, $load_inactive = false) { if ($xml == null) { $this->loadDefault(); return; } else { //XML library require_once JPATH_ROOT . DS . "includes" . DS . "domit" . DS . "xml_domit_lite_include.php"; $xmlDoc = new DOMIT_lite_Document(); $xmlDoc->resolveErrors(true); if ($xmlDoc->loadXML($xml, false, true)) { $element =& $xmlDoc->documentElement; if ($element->getTagName() == 'contentelement') { $this->xml = $xml; if ($element->hasAttribute("active")) { // content element is not active if ($element->getAttribute("active") == '0') { $this->active = '0'; if (!$load_inactive) { return; } } if ($element->getAttribute("active") == '1') { $this->active = '1'; } } if ($element->hasAttribute("ordering")) { $this->ce_ordering = $element->getAttribute("ordering"); } else { $this->ce_ordering = 999; } //TODO check required fields //TODO author and such //$info =& $element->getElementsByPath('author'); $info =& $element->getElementsByTagName('name'); if ($info != null) { $currNode =& $info->item(0); $table_name = trim($currNode->getText()); if ($table_name != null) { $this->name = $table_name; } else { $this->loadDefault(); return; } } else { $this->loadDefault(); return; } // content table name $table =& $element->getElementsByPath('content_table/table'); if ($table != null) { $currNode =& $table->item(0); $table_name = trim($currNode->getText()); if ($table_name != null) { $this->table = $table_name; } else { $this->loadDefault(); return; } // fields $table =& $element->getElementsByPath('content_table/field'); if ($table != null) { $total = $table->getLength(); for ($i = 0; $i < $total; $i++) { $currNode =& $table->item($i); $prop_name = trim($currNode->getAttribute('name')); $prop_val = trim($currNode->getText()); if ($prop_val != "") { $this->{$prop_name} = $prop_val; } } } else { $this->loadDefault(); return; } } else { $this->loadDefault(); return; } // CATEGORIES table name - optional $table =& $element->getElementsByPath('category/table'); if ($table != null) { $currNode =& $table->item(0); $table_name = trim($currNode->getText()); if ($table_name != null) { $this->cat_table = $table_name; } // fields $table =& $element->getElementsByPath('category/field'); if ($table != null) { $total = $table->getLength(); for ($i = 0; $i < $total; $i++) { $currNode =& $table->item($i); $prop_name = trim($currNode->getAttribute('name')); $prop_val = trim($currNode->getText()); if ($prop_val != "") { $this->{$prop_name} = $prop_val; } } } } // SECTIONS table name - optional $table =& $element->getElementsByPath('section/table'); if ($table != null) { $currNode =& $table->item(0); $table_name = trim($currNode->getText()); if ($table_name != null) { $this->sec_table = $table_name; } // fields $table =& $element->getElementsByPath('section/field'); if ($table != null) { $total = $table->getLength(); for ($i = 0; $i < $total; $i++) { $currNode =& $table->item($i); $prop_name = trim($currNode->getAttribute('name')); $prop_val = trim($currNode->getText()); if ($prop_val != "") { $this->{$prop_name} = $prop_val; } } } } } else { $this->loadDefault(); return; } } else { $this->loadDefault(); return; } } }