function __construct($xml = '', $params = self::XML_ENCLOSE) { $this->_params = $params; if ($xml) { if ($this->_params & self::XML_ARRAY2XML_FORMAT) { $domDocument = new CMS_DOMDocument(); $domDocument->loadXML($xml, 0, false, false); $this->_arrOutput = $this->_xml2Array($domDocument->documentElement, $domDocument->encoding); } else { $parser = xml_parser_create(APPLICATION_DEFAULT_ENCODING); xml_set_object($parser, $this); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_set_element_handler($parser, "_tagOpen", "_tagClosed"); xml_set_character_data_handler($parser, "_charData"); xml_set_processing_instruction_handler($parser, "_piData"); xml_set_default_handler($parser, "_tagData"); //enclose with html tag if ($this->_params & self::XML_ENCLOSE) { $xml = '<html>' . $xml . '</html>'; } //add encoding declaration if ($this->_params ^ self::XML_DONT_ADD_XMLDECL) { $xml = '<?xml version="1.0" encoding="' . APPLICATION_DEFAULT_ENCODING . '"?>' . "\n" . $xml; } if ($this->_params & self::XML_PROTECT_ENTITIES) { $xml = $this->_codeEntities($xml); } if (!xml_parse($parser, $xml)) { $this->_parsingError = sprintf("Parse error %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); if ($this->_params & ~self::XML_DONT_THROW_ERROR) { $this->raiseError($this->_parsingError . " :\n" . $xml, true); } } xml_parser_free($parser); unset($parser); } } }
/** * Get the HTML form given the block HTML example data. * * @param CMS_language &$language The language of the administration frontend * @param CMS_page &$page The page which contains the client space * @param CMS_clientSpace &$clientSpace The client space which contains the row * @param CMS_row &$row The row which contains the block * @param integer $blockID The tag ID of the block * @param string $data The data to show as example * @return string The HTML form which can send to the page that will modify the block * @access private */ protected function _getHTMLForm($language, &$page, &$clientSpace, &$row, $blockID, $data) { global $cms_user; //append atm-block class and block-id to all first level tags found in block datas $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<block>' . $data . '</block>'); } catch (DOMException $e) { $this->raiseError('Parse error for ' . get_class($this) . ' : Page ' . $page->getID() . ' - Row "' . $row->getTagID() . '" - Block "' . $blockID . '" : ' . $e->getMessage()); $data = '<div class="atm-error-block atm-block-helper">' . $language->getMessage(self::MESSAGE_BLOCK_CONTENT_ERROR) . '</div>'; $domdocument = new CMS_DOMDocument(); $domdocument->loadXML('<block>' . $data . '</block>'); } $blockNodes = $domdocument->getElementsByTagName('block'); if ($blockNodes->length == 1) { $blockXML = $blockNodes->item(0); } //check for valid tags nodes inside current block tag $hasNode = false; foreach ($blockXML->childNodes as $blockChildNode) { //scripts tags and p tags are not correctly handled by javascript if (is_a($blockChildNode, 'DOMElement') && $blockChildNode->tagName != 'script') { $hasNode = true; } } foreach ($blockXML->childNodes as $blockChildNode) { //scripts tags and p tags are not correctly handled by javascript if (is_a($blockChildNode, 'DOMElement') && ($blockChildNode->tagName != 'p' || io::substr($blockChildNode->tagName, 0, 4) != 'atm-')) { $hasNode = false; } } if (!$hasNode) { //append div with atm-empty-block class around datas $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<block><div class="atm-empty-block atm-block-helper">' . $data . '</div></block>'); } catch (DOMException $e) { $this->raiseError('Parse error for block : ' . $e->getMessage() . " :\n" . $data, true); return ''; } $blockNodes = $domdocument->getElementsByTagName('block'); if ($blockNodes->length == 1) { $blockXML = $blockNodes->item(0); } } $elements = array(); $uniqueId = 'block-' . md5(mt_rand() . microtime()); foreach ($blockXML->childNodes as $blockChildNode) { if (is_a($blockChildNode, 'DOMElement') && $blockChildNode->tagName != 'script' && $blockChildNode->tagName != 'p' && io::substr($blockChildNode->tagName, 0, 4) != 'atm-') { if ($blockChildNode->hasAttribute('class')) { $blockChildNode->setAttribute('class', $blockChildNode->getAttribute('class') . ' atm-block ' . $uniqueId); } else { $blockChildNode->setAttribute('class', 'atm-block ' . $uniqueId); } $elementId = 'el-' . md5(mt_rand() . microtime()); $blockChildNode->setAttribute('id', $elementId); $elements[] = $elementId; } } $data = CMS_DOMDocument::DOMElementToString($blockXML, true); //add block JS specification $data = ' <script type="text/javascript"> atmBlocksDatas[\'' . $uniqueId . '\'] = { page: \'' . $page->getID() . '\', document: document, clientSpaceTagID: \'' . $clientSpace->getTagID() . '\', row: \'' . $row->getTagID() . '\', id: \'' . $blockID . '\', jsBlockClass: \'' . $this->_jsBlockClass . '\', hasContent: \'' . $this->_hasContent . '\', editable: \'' . $this->_editable . '\', administrable: \'' . $this->_administrable . '\', options: ' . io::jsonEncode($this->_options) . ', value: ' . (is_array($this->_value) ? sensitiveIO::jsonEncode($this->_value) : '\'' . sensitiveIO::sanitizeJSString($this->_value) . '\'') . ', elements: [' . ($elements ? '\'' . implode('\',\'', $elements) . '\'' : '') . '] }; </script> ' . $data; return $data; }
/** * Search items by xml definition. Return XML * * @access public * @param string $searchConditions XML definition to search with * @return string XML definition of results IDs */ function soapSearch($searchConditions = '') { $xml = ''; if ($searchConditions) { $myXML = new CMS_DOMDocument(); $myXML->loadXML($searchConditions, 0, false); // Conditions tag must be the root tag $conditionsTags = $myXML->getElementsByTagName('conditions'); if (count($conditionsTags) == 1) { $conditionTags = $myXML->getElementsByTagName('condition'); foreach ($conditionTags as $conditionTag) { $type = $conditionTag->getAttribute('type'); $operator = $conditionTag->getAttribute('operator'); $value = $conditionTag->nodeValue; $this->addWhereCondition($type, $value, $operator); } } } $items = $this->search(CMS_object_search::POLYMOD_SEARCH_RETURN_IDS); if ($items) { $xml .= '<results count="' . count($items) . '">' . "\n"; foreach ($items as $itemID) { $xml .= '<result>' . $itemID . '</result>' . "\n"; } $xml .= '</results>'; } return $xml; }
/** * Analyse a form xhtml code to create all CMS_forms_field and return it * * @access public * @param string $postValues the form xhtml code to analyse and some other values like current form id * @return array of CMS_forms_field objects */ function analyseForm($postValues) { $formCode = $postValues["formCode"]; //get form ID in xhtml code $status = preg_match('#<form[^>]* id="cms_forms_(\\d*)"#iU', $formCode, $formId); $formId = array_map("trim", $formId); if ($status) { $formIdXHTML = $formId[1]; } //get form Id form POST if ($postValues["formId"]) { $formIdPost = $postValues["formId"]; } if (isset($formIdXHTML) && isset($formIdPost) && $formIdXHTML != $formIdPost) { CMS_grandFather::raiseError("Can't use another form code pasted into XHTML source code"); return false; } else { $formId = $formIdPost ? $formIdPost : $formIdXHTML; } if (!sensitiveIO::isPositiveInteger($formId)) { CMS_grandFather::raiseError("Must have a valid form ID"); return false; } //parse form content $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<html>' . $formCode . '</html>'); } catch (DOMException $e) { CMS_grandFather::raiseError("Parse error : " . $e->getMessage()); return false; } $tagLists['input'] = $domdocument->getElementsByTagName('input'); $tagLists['textarea'] = $domdocument->getElementsByTagName('textarea'); $tagLists['select'] = $domdocument->getElementsByTagName('select'); $tagLists['label'] = $domdocument->getElementsByTagName('label'); $tags = array(); foreach ($tagLists as $tagList) { if ($tagList->length > 0) { foreach ($tagList as $aTag) { $tags[] = $aTag; } } } if ($tags) { $formTags = array(); //then launch tags analysis foreach ($tags as $aTag) { //get field type datas and ID if ($aTag->tagName == 'label') { $fieldIDDatas = CMS_forms_field::decodeFieldIdDatas($aTag->getAttribute('for')); $fieldId = CMS_forms_field::extractEncodedID($aTag->getAttribute('for')); } else { $fieldIDDatas = CMS_forms_field::decodeFieldIdDatas($aTag->getAttribute('id')); $fieldId = CMS_forms_field::extractEncodedID($aTag->getAttribute('id')); } //create CMS_forms_fields objects if ($aTag->getAttribute('id')) { if (!isset($formTags[$aTag->getAttribute('id')]) || !is_a($formTags[$aTag->getAttribute('id')], "CMS_forms_field")) { $formTags[$aTag->getAttribute('id')] = new CMS_forms_field($fieldId, $formId); } } elseif ($aTag->getAttribute('for')) { if (!is_a($formTags[$aTag->getAttribute('for')], "CMS_forms_field")) { $formTags[$aTag->getAttribute('for')] = new CMS_forms_field($fieldId, $formId); } } //get inputs and set CMS_forms_field object values if ($aTag->tagName == 'input') { $formTags[$aTag->getAttribute('id')]->setAttribute("name", $aTag->getAttribute('name')); if ($aTag->getAttribute('type') != 'checkbox') { $formTags[$aTag->getAttribute('id')]->setAttribute("value", $aTag->getAttribute('value')); } else { //do not update field value for checkbox } if ($aTag->getAttribute('type') == 'text' || !$aTag->getAttribute('type')) { if (in_array('email', $fieldIDDatas)) { $formTags[$aTag->getAttribute('id')]->setAttribute("type", 'email'); } elseif (in_array('integer', $fieldIDDatas)) { $formTags[$aTag->getAttribute('id')]->setAttribute("type", 'integer'); } elseif (in_array('url', $fieldIDDatas)) { $formTags[$aTag->getAttribute('id')]->setAttribute("type", 'url'); } else { $formTags[$aTag->getAttribute('id')]->setAttribute("type", $aTag->getAttribute('type')); } } elseif ($aTag->getAttribute('type') == 'submit') { $formTags[$aTag->getAttribute('id')]->setAttribute("label", $aTag->getAttribute('value')); $formTags[$aTag->getAttribute('id')]->setAttribute("type", $aTag->getAttribute('type')); } elseif ($aTag->getAttribute('type') == 'password') { $formTags[$aTag->getAttribute('id')]->setAttribute("type", 'pass'); } else { $formTags[$aTag->getAttribute('id')]->setAttribute("type", $aTag->getAttribute('type')); } } elseif ($aTag->tagName == 'textarea') { $formTags[$aTag->getAttribute('id')]->setAttribute("name", $aTag->getAttribute('name')); $formTags[$aTag->getAttribute('id')]->setAttribute("type", 'textarea'); $formTags[$aTag->getAttribute('id')]->setAttribute("value", CMS_DOMDocument::DOMElementToString($aTag, true)); } elseif ($aTag->tagName == 'select') { $formTags[$aTag->getAttribute('id')]->setAttribute("name", $aTag->getAttribute('name')); $formTags[$aTag->getAttribute('id')]->setAttribute("type", 'select'); $optionTags = $aTag->getElementsByTagName('option'); $options = array(); foreach ($optionTags as $anOptionTag) { $options[$anOptionTag->getAttribute('value')] = CMS_DOMDocument::DOMElementToString($anOptionTag, true); if ($anOptionTag->getAttribute('selected') == 'selected') { $formTags[$aTag->getAttribute('id')]->setAttribute("value", $anOptionTag->getAttribute('value')); } } $formTags[$aTag->getAttribute('id')]->setAttribute("options", $options); } elseif ($aTag->tagName == 'label') { $formTags[$aTag->getAttribute('for')]->setAttribute("label", str_replace("\n", "", CMS_DOMDocument::DOMElementToString($aTag, true))); } //is field required ? if (in_array('req', $fieldIDDatas)) { if ($aTag->tagName == 'label') { $formTags[$aTag->getAttribute('for')]->setAttribute('required', true); } else { $formTags[$aTag->getAttribute('id')]->setAttribute('required', true); } } } } if ($formTags) { foreach ($formTags as $field) { $field->writeToPersistence(); } } //add form object $formTags = array(); $formTags['form'] = new CMS_forms_formular($formId); //compare DB form fields if any and add missing ones $dbFields = $formTags['form']->getFields(true); foreach ($formTags as $formTag) { if (is_a($formTag, 'CMS_forms_field') && in_array($formTag->getID(), array_keys($dbFields))) { unset($dbFields[$formTag->getID()]); } } if ($dbFields) { foreach ($dbFields as $field) { $formTags[$field->generateFieldIdDatas()] = $field; } } return $formTags; }
/** * Get the HTML display for a page, if it passes the condition of course. * * @param CMS_page $parsedPage The page in which the linx tag is * @param CMS_page $page The page to get the display of * @param boolean $public Is the page data to show the public or edited one ? * @param integer $rank The rank of the page in the linx targets * @param boolean $noerror : Hide all link error (default : false) * @return string The html or false if page fails to pass the condition * @access public */ function getOutput(&$parsedPage, &$page, $public, $rank, $noerror = false, $noselection = false) { if (!is_a($page, "CMS_page")) { if (!$noerror) { $tpl = $parsedPage->getTemplate(); if (is_a($tpl, 'CMS_pageTemplate')) { $tplName = $tpl->getID() . "\t : " . $tpl->getLabel(); } else { $tplName = 'No template set !'; } $this->raiseError("Page parameter not defined\n - Page : " . $parsedPage->getID() . "\n - Template : " . $tplName . "\n"); } return false; } if (!$this->hasCondition() || $this->pagePassesConditions($parsedPage, $page, $public, $rank)) { //get pages infos $linkTitle = $page->getLinkTitle($public); $title = $page->getTitle($public); $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, "{{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 $lineage = CMS_tree::getLineage($page->getID(), $parsedPage->getID(), false, $public); $replace['class="{{isParent}}"'] = is_array($lineage) && in_array($parsedPage->getID(), $lineage) ? 'class="CMS_parent"' : ""; $replace['{{isParent}}'] = is_array($lineage) && in_array($parsedPage->getID(), $lineage) ? 'CMS_parent' : ""; $replace['id="{{isParent}}"'] = is_array($lineage) && in_array($parsedPage->getID(), $lineage) ? '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); } $html = str_replace(array_keys($replace), $replace, $this->_htmlTemplate); if (APPLICATION_ENFORCES_ACCESS_CONTROL && $public) { $html = $this->_addSlashAroundPHPContent($html); //pr($html); $replace = array("<?php" => "';", "?>" => "echo '"); $html = str_replace(array_keys($replace), $replace, $html); //if link has noselection flag, use alternative when user has no right on linked page if (is_object($noselection)) { $noSelectionContent = $this->_addSlashAroundPHPContent(CMS_DOMDocument::DOMElementToString($noselection, true)); $html = '<?php if ($cms_user->hasPageClearance(' . $page->getID() . ', CLEARANCE_PAGE_VIEW)) {' . "\n" . 'echo \'' . $html . '\';' . "\n" . '} else {' . "\n" . 'echo \'' . $noSelectionContent . '\';' . "\n" . '}' . "\n" . '?>'; } else { $html = '<?php if ($cms_user->hasPageClearance(' . $page->getID() . ', CLEARANCE_PAGE_VIEW)) {' . "\n" . 'echo \'' . $html . '\';' . "\n" . '}' . "\n" . '?>'; } } return $html; } else { return false; } }
/** * Get the HTML output * * @return string The HTML * @access public */ function getOutput($register = false) { if ($this->hasError()) { return ''; } //computes the targets (from selection) $this->_targets = $this->_buildTargets(); //set output $output = ''; if ($this->_type == 'recursivelinks') { $root = CMS_tree::getRoot(); $lineage = CMS_tree::getLineage($root->getID(), $this->_page->getID(), false, $this->_publicTree); if (is_array($this->_displays)) { foreach ($this->_displays as $display) { $html = $display->getRecursiveOutput($this->_page, 0, $this->_recursiveTargets, $this->_targets, $this->_publicTree, $lineage); if ($html) { $output .= $html; break; } } } } else { if (is_array($this->_displays)) { foreach ($this->_displays as $display) { $displayOutput = ''; if (is_array($this->_targets) && $this->_targets) { $sizeofTargets = sizeof($this->_targets); for ($i = 0; $i < $sizeofTargets; $i++) { $target = $this->_targets[$i]; $displayOutput .= $display->getOutput($this->_page, $target, $this->_publicTree, $i + 1, $this->_noerror, $this->_noselection); } $output .= $display->getSubLevelOutput($displayOutput); } elseif (is_object($this->_noselection)) { $output .= CMS_DOMDocument::DOMElementToString($this->_noselection, true); } } } } if ($register) { $this->_register(); } //append args to generated linx code if ($this->_args) { //append atm-row class and row-id to all first level tags found in row datas $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<linx>' . $output . '</linx>'); } catch (DOMException $e) { $this->raiseError('Parse error for linx : ' . $e->getMessage() . " :\n" . io::htmlspecialchars($output)); return ''; } $rowNodes = $domdocument->getElementsByTagName('linx'); if ($rowNodes->length == 1) { $rowXML = $rowNodes->item(0); } $elements = array(); if (isset($rowXML)) { foreach ($rowXML->childNodes as $rowChildNode) { if (is_a($rowChildNode, 'DOMElement') && $rowChildNode->tagName != 'script') { if ($this->_args['class'] !== false) { if ($rowChildNode->hasAttribute('class')) { $rowChildNode->setAttribute('class', $rowChildNode->getAttribute('class') . ' ' . $this->_args['class']); } else { $rowChildNode->setAttribute('class', $this->_args['class']); } } if ($this->_args['id'] !== false) { $rowChildNode->setAttribute('id', $this->_args['id']); } } } $output = CMS_DOMDocument::DOMElementToString($rowXML, true); } else { $output = ''; } } return $output; }
/** * Gets the data, using the specified visualization mode. * The data is taken from the blocks and reintroduced into the definition file which may itself contain HTML instructions. * * @param CMS_language &$language The language of the administration frontend * @param CMS_page &$page the page parsed * @param CMS_clientSpace &$clientSpace the client space parsed * @param integer $visualizationMode the visualization mode * @param boolean $templateHasPages, set to true will die access to up/down buttons * @param boolean $rowCanBeEdited determine we can edit it this page (Display form) * @return string the data from the blocks and the definition file. * @access public */ function getData(&$language, &$page, &$clientSpace, $visualizationMode, $templateHasPages = false, $rowCanBeEdited = true) { global $cms_user; $modulesTreatment = new CMS_modulesTags(MODULE_TREATMENT_BLOCK_TAGS, $visualizationMode, $this); $modulesTreatment->setTreatmentParameters(array("page" => $page, "language" => $language, "clientSpace" => $clientSpace)); if (!$this->_parseDefinitionFile($modulesTreatment)) { //here we expect a false (otherwise, it is an error) $data = $modulesTreatment->treatContent(); //if $visualizationMode is CLIENTSPACES_FORM and //no page uses the template calling this row, add the form here if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM || $visualizationMode == PAGE_VISUALMODE_FORM) { //append atm-row class and row-id to all first level tags found in row datas $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<row>' . $data . '</row>'); } catch (DOMException $e) { //$this->raiseError('Parse error for row : Page '.$page->getID().' - Row "'.$this->getTagID().'" : '.$e->getMessage()); //$data = '<div class="atm-error-block atm-block-helper">'.$language->getMessage(self::MESSAGE_BLOCK_CONTENT_ERROR).'</div>'; //$domdocument = new CMS_DOMDocument(); //$domdocument->loadXML('<row>'.$data.'</row>'); $this->raiseError('Parse error for row : ' . $e->getMessage() . " :\n" . $data, true); return ''; } $rowNodes = $domdocument->getElementsByTagName('row'); if ($rowNodes->length == 1) { $rowXML = $rowNodes->item(0); } //search for valid tags $hasNode = false; foreach ($rowXML->childNodes as $rowChildNode) { //scripts tags and p tags are not correctly handled by javascript if (is_a($rowChildNode, 'DOMElement') && $rowChildNode->tagName != 'script') { $hasNode = true; } } foreach ($rowXML->childNodes as $rowChildNode) { //scripts tags and p tags are not correctly handled by javascript if (is_a($rowChildNode, 'DOMElement') && ($rowChildNode->tagName != 'p' || io::substr($rowChildNode->tagName, 0, 4) != 'atm-')) { $hasNode = false; } } if (!$hasNode) { //append atm-row class and row-id to all first level tags found in row datas $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<row><div class="atm-dummy-row-tag">' . $data . '</div></row>'); } catch (DOMException $e) { $this->raiseError('Parse error for row : ' . $e->getMessage() . " :\n" . $data, true); return ''; } $rowNodes = $domdocument->getElementsByTagName('row'); if ($rowNodes->length == 1) { $rowXML = $rowNodes->item(0); } } $elements = array(); $rowId = 'row-' . $this->_tagID; foreach ($rowXML->childNodes as $rowChildNode) { if (is_a($rowChildNode, 'DOMElement') && $rowChildNode->tagName != 'script' && $rowChildNode->tagName != 'p' && io::substr($rowChildNode->tagName, 0, 4) != 'atm-') { if ($rowChildNode->hasAttribute('id')) { $elementId = $rowChildNode->getAttribute('id'); } else { $elementId = 'el-' . md5(mt_rand() . microtime()); $rowChildNode->setAttribute('id', $elementId); } $elements[] = $elementId; } } $data = CMS_DOMDocument::DOMElementToString($rowXML, true); //add row specification $data = ' <script type="text/javascript"> atmRowsDatas[\'' . $rowId . '\'] = { id: \'' . $rowId . '\', template: \'' . $clientSpace->getTemplateID() . '\', clientSpaceTagID: \'' . $clientSpace->getTagID() . '\', rowTagID: \'' . $this->_tagID . '\', rowType: \'' . $this->_id . '\', label: \'' . sensitiveIO::sanitizeJSString($this->getLabel()) . '\', userRight: \'' . $this->hasUserRight($cms_user) . '\', visualMode: \'' . $visualizationMode . '\', document: document, elements: [' . ($elements ? '\'' . implode('\',\'', $elements) . '\'' : '') . '] }; </script> ' . $data; //decode brackets encoded in CMS_block_text::_getHTMLForm $replace = array('||bo||' => '{', '||bc||' => '}'); $data = str_replace(array_keys($replace), $replace, $data); } $data = '<?php /* Start row [' . $this->getLabel() . ' - ' . $this->getDefinitionFileName() . '] */?>' . $data . '<?php /* End row [' . $this->getLabel() . ' - ' . $this->getDefinitionFileName() . '] */?>'; return $data; } else { $this->raiseError('Can not use row template file ' . $this->_definitionFile); return false; } }
/** * Look if this block can have or must have parameters to been set ? (search parameters for now) * * @return boolean true * @access private */ private function _lookForBlockParameters() { if ($this->_canhasParameters !== null && $this->_musthaveParameters !== null) { return true; } $this->_canhasParameters = false; $this->_musthaveParameters = false; $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<dummy>' . $this->_definition . '</dummy>'); } catch (DOMException $e) { $this->raiseError('Parse error during search for blocks parameters : ' . $e->getMessage() . " :\n" . io::htmlspecialchars($this->_definition)); return true; } $searchTags = $domdocument->getElementsByTagName('atm-search'); if ($searchTags->length) { foreach ($searchTags as $searchTag) { $paramTags = array(); $paramTags[] = $searchTag->getElementsByTagName('atm-search-param'); $paramTags[] = $searchTag->getElementsByTagName('atm-search-limit'); $paramTags[] = $searchTag->getElementsByTagName('atm-search-page'); $paramTags[] = $searchTag->getElementsByTagName('atm-search-order'); foreach ($paramTags as $paramTagType) { foreach ($paramTagType as $paramTag) { if ($paramTag->hasAttribute('value') && $paramTag->getAttribute('value') == 'block') { $this->_canhasParameters = true; //check for mandatory block parameter value (all are mandatory except for atm-search-param which is explicitely defined) if ($paramTag->getAttribute('mandatory') == 'true' && $paramTag->tagName == 'atm-search-param' || $paramTag->tagName != 'atm-search-param') { $this->_musthaveParameters = true; return true; } } } } } } // if we are here it means that no search mandatory atm-search-param was found // Let's check for atm-blockvar elements $blockVarsTags = $domdocument->getElementsByTagName('atm-blockvar'); if ($blockVarsTags->length) { // at least one atm-blockvar was found, so the tag can have parameters $this->_canhasParameters = true; foreach ($blockVarsTags as $blockVarTag) { if ($blockVarTag->getAttribute('mandatory') == 'true') { // a mandatory value was found, no need to continue the loop $this->_musthaveParameters = true; return true; } } } return true; }
/** * Get the module parameters. Search for a file name "CODENAME_rc.xml" in PATH_MODULES_FS * * @param string $onlyOne The name of a single parameter wanted * @return array(string=>string) The parameters from the file, or false if no file found * @access public */ function getParameters($onlyOne = false, $withType = false, $reset = false) { if ($this->_hasParameters) { if ($reset) { unset($moduleParameters); } if (!isset($moduleParameters[$this->_codename])) { $filename = PATH_MODULES_FS . "/" . $this->_codename . "_rc.xml"; if (file_exists($filename)) { $paramsFileContent = @file_get_contents(realpath($filename)); $moduleParameters[$this->_codename] = array(); if ($paramsFileContent) { $file = new CMS_DOMDocument(); $file->loadXML($paramsFileContent); $paramTags = $file->getElementsByTagName('param'); foreach ($paramTags as $paramTag) { $value = io::strtolower(APPLICATION_DEFAULT_ENCODING) != 'utf-8' ? utf8_decode(trim($paramTag->nodeValue)) : trim($paramTag->nodeValue); if ($withType && $paramTag->hasAttribute("type")) { $moduleParameters[$this->_codename][$paramTag->getAttribute("name")] = array($value, $paramTag->getAttribute("type")); } else { $moduleParameters[$this->_codename][$paramTag->getAttribute("name")] = trim($value); } } } } else { $this->raiseError('Malformed definition file : ' . PATH_MODULES_FS . '/' . $this->_codename . '_rc.xml'); $moduleParameters[$this->_codename] = array(); } } //return all or only one of the parameters if ($onlyOne && isset($moduleParameters[$this->_codename][$onlyOne])) { return $moduleParameters[$this->_codename][$onlyOne]; } elseif ($onlyOne) { return ''; } else { return $moduleParameters[$this->_codename]; } } else { return false; } }
/** * Parse the content of a template for module parameters and returns the content. * Usually used by the getData() function to handle template files and feed them with module parameters * * @param string $filename The filename of the template, located in the templates directory * @return string the data from the rows. * @access private */ protected function _parseTemplateForParameters($filename) { $module = CMS_modulesCatalog::getByCodename($this->_attributes["module"]); if (!$module instanceof CMS_module) { $this->raiseError("No module defined for the clientspace"); return false; } $parameters = $module->getParameters(); $templateFile = new CMS_file(PATH_TEMPLATES_FS . "/" . $filename); if ($templateFile->exists()) { $cdata = $templateFile->getContent(); //no need to be complicated if no parameters if (!$parameters) { return $cdata; } //"parse" template for parameters. No XML parsing (PHP code produces strange results) //MUST wipe out the linefeeds, because pcre's stop at them !!! $cdata_pcre = str_replace("\n", "§§", $cdata); while (true) { unset($regs); preg_match('/(.*)(<module-param [^>]*\\/>)(.*)/', $cdata_pcre, $regs); if (isset($regs[2])) { $param_value = ''; $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<dummy>' . $regs[2] . '</dummy>'); } catch (DOMException $e) { $this->raiseError('Parse error during search for module-param parameters : ' . $e->getMessage() . " :\n" . io::htmlspecialchars($regs[2])); return false; } $paramsTags = $domdocument->getElementsByTagName('module-param'); foreach ($paramsTags as $paramTag) { $param_value = str_replace("\n", "§§", $parameters[$paramTag->getAttribute("name")]); } $cdata_pcre = $regs[1] . $param_value . $regs[3]; } else { break; } } $cdata = str_replace("§§", "\n", $cdata_pcre); return $cdata; } else { $this->raiseError("Template " . $filename . " isn't readable"); return false; } }
} if ($pagesIds) { CMS_tree::submitToRegenerator($pagesIds, true); } $cms_message = $cms_language->getMessage(MESSAGE_ACTION_XML_UPDATED) . ($pagesIds ? ',<br />' . $cms_language->getMessage(MESSAGE_ACTION_N_PAGES_REGEN, array(sizeof($pagesIds))) : '.'); } else { $cms_message = $cms_language->getMessage(MESSAGE_ACTION_XML_UPDATED); } $view->setContent($content); } else { $cms_message = $cms_language->getMessage(MESSAGE_ERROR_WRITE_TEMPLATE); } } } elseif (isset($templateFile) && is_a($templateFile, "CMS_file") && $templateFile->exists()) { //definition parsing test $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML($definition); } catch (DOMException $e) { $cms_message = $e->getMessage(); } if (!$cms_message) { $templateFile->setContent($definition); $templateFile->writeToPersistence(); $log = new CMS_log(); $log->logMiscAction(CMS_log::LOG_ACTION_TEMPLATE_EDIT, $cms_user, "Template : Print template"); $content = array('success' => true); $cms_message = $cms_language->getMessage(MESSAGE_ACTION_SAVE_PRINT_DONE); $view->setContent($content); } else { $cms_message = $cms_language->getMessage(MESSAGE_PAGE_MALFORMED_DEFINITION_FILE) . "\n\n" . $cms_message;
/** * Do patch installation * * @param array of install command to do, view documentation for format * This array MUST be checked before by checkInstall method to ensure it format is as correct as possible * @param array of excluded commands * @return void * @access public */ function doInstall(&$array, $excludeCommand = array(), $stopOnErrors = true) { if (is_array($array)) { foreach ($array as $line => $aInstallCheck) { $line++; //to have the correct line number $installParams = array_map("trim", explode("\t", $aInstallCheck)); if ($installParams[0] != 'ex') { $originalFile = isset($installParams[1]) ? PATH_REALROOT_FS . $installParams[1] : PATH_REALROOT_FS; $patchFile = isset($installParams[1]) ? PATH_TMP_FS . $installParams[1] : PATH_TMP_FS; } if (!in_array($installParams[0], $excludeCommand)) { //launch installation request switch ($installParams[0]) { case ">": //add or update a file or folder //copy file or folder if (CMS_FILE::copyTo($patchFile, $originalFile)) { $this->_verbose(' -> File ' . $patchFile . ' successfully copied to ' . $originalFile); } else { $this->_report('Error during copy of ' . $patchFile . ' to ' . $originalFile, true); if ($stopOnErrors) { return; } } if (!isset($installParams[2])) { break; } case "ch": //execute chmod $filesNOK = $this->applyChmod($installParams[2], $originalFile); if (!$filesNOK) { switch ($installParams[2]) { case 'r': $this->_verbose(' -> File(s) ' . $originalFile . ' are readable.'); break; case 'w': $this->_verbose(' -> File(s) ' . $originalFile . ' are writable.'); break; case 'x': $this->_verbose(' -> File(s) ' . $originalFile . ' are executable.'); break; default: $this->_verbose(' -> File(s) ' . $originalFile . ' successfully chmoded with value ' . $installParams[2]); break; } } else { $this->_report('Error during chmod operation of ' . $originalFile . '. Can\'t apply chmod value \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true); //do not stop on chmod error : only report them //if ($stopOnErrors) return; } break; case "<": //delete a file or folder (recursively) if (file_exists($originalFile) && CMS_FILE::deleteFile($originalFile)) { $this->_verbose(' -> File ' . $originalFile . ' successfully deleted'); } else { $this->_verbose(' -> Cannot delete ' . $originalFile . '. It does not exists.'); } break; case "+": //concatenate module xml file //load destination module parameters $module = CMS_modulesCatalog::getByCodename($installParams[2]); $moduleParameters = $module->getParameters(false, true); //load the XML data of the source the files $sourceXML = new CMS_file($patchFile); $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML($sourceXML->readContent("string")); } catch (DOMException $e) { } $paramsTags = $domdocument->getElementsByTagName('param'); $sourceParameters = array(); foreach ($paramsTags as $aTag) { $name = $aTag->hasAttribute('name') ? $aTag->getAttribute('name') : ''; $type = $aTag->hasAttribute('type') ? $aTag->getAttribute('type') : ''; $sourceParameters[$name] = array(CMS_DOMDocument::DOMElementToString($aTag, true), $type); } //merge the two tables of parameters $resultParameters = array_merge($sourceParameters, $moduleParameters); //set new parameters to the module if ($module->setAndWriteParameters($resultParameters)) { $this->_verbose(' -> File ' . $patchFile . ' successfully merged with module ' . $installParams[2] . ' parameters'); } else { $this->_report('Error during merging of ' . $patchFile . ' with module ' . $installParams[2] . ' parameters', true); if ($stopOnErrors) { return; } } break; case "x": //execute SQL or PHP file //exec sql script with help of some phpMyAdmin classes if (io::substr($patchFile, -4, 4) == '.sql') { if ($this->executeSqlScript($patchFile)) { $this->_verbose(' -> File ' . $patchFile . ' successfully executed'); } else { $this->_report('Error during execution of ' . $patchFile, true); if ($stopOnErrors) { return; } } } elseif (io::substr($patchFile, -4, 4) == '.php') { //exec php script $executionReturn = $this->executePhpScript($patchFile); if ($executionReturn === false) { $this->_report('Error during execution of ' . $patchFile, true); if ($stopOnErrors) { return; } } else { $executionReturn = $executionReturn ? ' -> Return :<br /><div style="border:1px;background-color:#000080;color:#C0C0C0;padding:5px;">' . $executionReturn . '</div><br />' : ''; $this->_report(' -> File ' . $patchFile . ' executed<br />' . $executionReturn); } } break; case "co": //execute change owner $filesNOK = $this->changeOwner($installParams[2], $originalFile); if (!$filesNOK) { $this->_verbose(' -> Owner of file(s) ' . $originalFile . ' successfully changed to ' . $installParams[2]); } else { $this->_report('Error during operation on ' . $originalFile . '. Can\'t change owner to \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true); if ($stopOnErrors) { return; } } break; case "cg": //execute change group $filesNOK = $this->changeGroup($installParams[2], $originalFile); if (!$filesNOK) { $this->_verbose(' -> Group of file(s) ' . $originalFile . ' successfully changed to ' . $installParams[2]); } else { $this->_report('Error during operation on ' . $originalFile . '. Can\'t change group to \'' . $installParams[2] . '\' on files :<br />' . $filesNOK . '<br />', true); if ($stopOnErrors) { return; } } break; case "rc": $this->automneGeneralScript(); break; case "htaccess": $installParams[1] = io::substr($installParams[1], -1) == '/' ? io::substr($installParams[1], 0, -1) : $installParams[1]; $pathes = glob(PATH_REALROOT_FS . $installParams[1]); if ($pathes) { foreach ($pathes as $path) { if ($installParams[2] == 'root' && file_exists($path . '/.htaccess')) { //for root file, if already exists, only replace ErrorDocument instructions to set correct path $htaccessFile = new CMS_file($path . '/.htaccess'); $lines = $htaccessFile->readContent('array', ''); foreach ($lines as $key => $line) { if (substr($line, 0, 13) == 'ErrorDocument') { list($errorDoc, $code, $file) = preg_split("/[\\s]+/", $line); if ($code == '404') { $lines[$key] = 'ErrorDocument 404 ' . PATH_REALROOT_WR . '/404.php' . "\n"; } elseif ($code == '403') { $lines[$key] = 'ErrorDocument 403 ' . PATH_REALROOT_WR . '/403.php' . "\n"; } } } $htaccessFile->setContent(implode('', $lines), false); if ($htaccessFile->writeToPersistence()) { $this->_report('File ' . $path . '/.htaccess (' . $installParams[2] . ') successfully updated'); } else { $this->_report('Error during operation on ' . $path . '/.htaccess. Can\'t write file.<br />', true); } } else { if (is_dir($path) && CMS_file::makeWritable($path)) { if (CMS_file::copyTo(PATH_HTACCESS_FS . '/htaccess_' . $installParams[2], $path . '/.htaccess')) { CMS_file::chmodFile(FILES_CHMOD, $path . '/.htaccess'); $this->_report('File ' . $path . '/.htaccess (' . $installParams[2] . ') successfully writen'); } else { $this->_report('Error during operation on ' . $path . '/.htaccess. Can\'t write file.<br />', true); if ($stopOnErrors) { return; } } } else { $this->_report('Error during operation. ' . $path . ' must be a writable directory.<br />', true); if ($stopOnErrors) { return; } } } } } break; default: if (io::substr($installParams[0], 0, 1) != '#') { $this->raiseError("Unknown parameter : " . $installParams[0]); return false; } break; } } else { $this->_report('Error during operation of "' . $aInstallCheck . '". Command execution is not allowed.<br />', true); if ($stopOnErrors) { return; } } } } else { $this->raiseError("Param must be an array"); return false; } //at end of any patch process, update Automne subversion to force reload of JS and CSS cache from client if (@file_put_contents(PATH_MAIN_FS . "/SUBVERSION", time()) !== false) { CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . "/SUBVERSION"); } }
} else { $item->setAttribute('name', $_POST["name"]); } //check for copy-pasted code if (!$item->checkFormCode($_POST["source_" . $item->getID()])) { $cms_message .= $cms_language->getMessage(MESSAGE_FORM_ERROR_COPY_PASTED_CODE, false, MOD_CMS_FORMS_CODENAME); } $public = $_POST["public"] > -1 ? true : false; $item->setAttribute('public', $public); $item->setAttribute("responses", (int) $_POST["responses"]); // If new item set current user as media owner if ($item->getAttribute('ownerID') <= 0) { $item->setAttribute('ownerID', $cms_user->getUserID()); } // Validate XHTML source $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML("<dummy>" . $_POST["source_" . $item->getID()] . "</dummy>"); } catch (DOMException $e) { $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_ERROR_INVALID_XHTML, false, MOD_CMS_FORMS_CODENAME) . " : " . $e->getMessage(); } if (!$cms_message) { //check inputs tags (sometimes, IE remove type="text" ...) //then save source $item->setAttribute('source', $item->checkInputs($_POST["source_" . $item->getID()])); } // Categories // Write item relations with categories $ids = $_POST["ids"] ? @array_unique(@explode(';', $_POST["ids"])) : array(); if (!$cms_message && $item->writeToPersistence()) { $item_relations = new CMS_forms_formularCategories($item);
/** * Search users by xml definition. Return XML * * @access public * @param string $searchConditions XML definition to search with ('id','login','firstName','lastName','contactData','profile','language') * @return string XML definition of users IDs */ static function soapSearch($searchConditions = '') { $xml = ''; $attrs = array(); if ($searchConditions) { $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML($searchConditions, 0, false); } catch (DOMException $e) { CMS_profile_usersCatalog::raiseError('Parse error for xml : ' . $e->getMessage() . " :\n" . $xml); return $xml; } // Conditions tag must be the root tag $conditionsTags = $domdocument->getElementsByTagName('conditions'); if (count($conditionsTags) == 1) { $conditionTags = $domdocument->getElementsByTagName('condition'); foreach ($conditionTags as $conditionTag) { $type = $conditionTag->getAttribute('type'); $value = $conditionTag->nodeValue; $attrs[$type . '_pru'] = $value; } } } $items = CMS_profile_usersCatalog::getAll(true, false, false, $attrs); if ($items) { $xml .= '<results count="' . count($items) . '">' . "\n"; foreach ($items as $itemID) { $xml .= '<result>' . $itemID . '</result>' . "\n"; } $xml .= '</results>'; } return $xml; }
/** * Parse the content looking for some special XML tags that will be interpretad : * - dialog-title : a title rendered with an image * - dialog-pages : a pages navigation row * * @param string $body xml that will be parsed * @return void * @access public */ protected function _parseContent($body) { if ($this->_dontParse) { return $this->_content; } $datas = str_replace("\n", '§§', $body); //dialog-title while (true) { $regs = array(); preg_match('/<dialog-title [^>]*>.*<\\/dialog-title>/U', $datas, $regs); if (isset($regs[0]) && $regs[0]) { $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<dummy>' . $regs[0] . '</dummy>'); } catch (DOMException $e) { $this->raiseError('Parse error during search for module-param parameters : ' . $e->getMessage() . " :\n" . io::htmlspecialchars($regs[2])); return $this->_content; } $paramsTags = $domdocument->getElementsByTagName('dialog-title'); foreach ($paramsTags as $paramTag) { if (strtolower(APPLICATION_DEFAULT_ENCODING) != 'utf-8') { $param_value = $this->_getTitleDesign(utf8_decode($paramTag->textContent), $paramTag->getAttribute("type")); } else { $param_value = $this->_getTitleDesign($paramTag->textContent, $paramTag->getAttribute("type")); } } $datas = str_replace($regs[0], $param_value, $datas); } else { break; } } //dialog-pages /* Exemple : <dialog-pages maxPages="22" boomarkName="rowsBookmark"> <dialog-pages-param name="currentOnglet" value="1" /> </dialog-pages> */ while (true) { $regs = array(); preg_match('/<dialog-pages [^>]*>.*?<\\/dialog-pages>/', $datas, $regs); if (isset($regs[0])) { $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<dummy>' . $regs[0] . '</dummy>'); } catch (DOMException $e) { $this->raiseError('Parse error during search for dialog-pages parameters : ' . $e->getMessage() . " :\n" . io::htmlspecialchars($regs[2])); return $this->_content; } $paramsTags = $domdocument->getElementsByTagName('dialog-pages'); foreach ($paramsTags as $paramTag) { $maxPages = (int) $paramTag->getAttribute("maxPages") ? (int) $paramTag->getAttribute("maxPages") : 1; $boomarkName = $paramTag->getAttribute("boomarkName") ? $paramTag->getAttribute("boomarkName") : 'bookmark'; } $paramsTags = $domdocument->getElementsByTagName('dialog-pages-param'); $extra = ''; foreach ($paramsTags as $paramTag) { $extra .= '&' . $paramTag->getAttribute("name") . '=' . $paramTag->getAttribute("value"); } $links = '<b>'; // Loop through and create page links for ($i = 0; $i < $maxPages; $i++) { $currentBookmark = $boomarkName != 'bookmark' ? $this->_context->getSessionVar($boomarkName) : $this->_context->getBookmark(); if ($i + 1 == $currentBookmark) { $links .= ' <span class="admin_current">' . ($i + 1) . '</span> '; } else { $links .= '<a class="admin" href=' . $_SERVER['SCRIPT_NAME'] . '?' . $boomarkName . '=' . ($i + 1); if ($extra) { $links .= $extra; } $links .= '>' . ($i + 1); $links .= '</a> '; } } $links .= '</b>'; $user = $this->_context->getUser(); $language = $user->getLanguage(); $tagReplacement = ' <table border="0" cellpadding="3" cellspacing="0"> <tr> <td class="admin"> ' . $language->getMessage(282) . ' : ' . $links . ' </td> </tr> </table> '; $datas = str_replace($regs[0], $tagReplacement, $datas); } else { break; } } $datas = str_replace("§§", "\n", $datas); return $datas; }
/** * Treat given content tag by this module for the specified treatment mode, visualization mode and object. * * @param string $tag The CMS_XMLTag. * @param string $tagContent previous tag content. * @param integer $treatmentMode The current treatment mode (see constants on top of CMS_modulesTags class for accepted values). * @param integer $visualizationMode The current visualization mode (see constants on top of cms_page class for accepted values). * @param object $treatedObject The reference object to treat. * @param array $treatmentParameters : optionnal parameters used for the treatment. Usually an array of objects. * @return string the tag content treated. * @access public */ function treatWantedTag(&$tag, $tagContent, $treatmentMode, $visualizationMode, &$treatedObject, $treatmentParameters) { switch ($treatmentMode) { case MODULE_TREATMENT_BLOCK_TAGS: if (!$treatedObject instanceof CMS_row) { $this->raiseError('$treatedObject must be a CMS_row object'); return false; } if (!$treatmentParameters["page"] instanceof CMS_page) { $this->raiseError('$treatmentParameters["page"] must be a CMS_page object'); return false; } if (!$treatmentParameters["language"] instanceof CMS_language) { $this->raiseError('$treatmentParameters["language"] must be a CMS_language object'); return false; } if (!$treatmentParameters["clientSpace"] instanceof CMS_moduleClientspace) { $this->raiseError('$treatmentParameters["clientSpace"] must be a CMS_moduleClientspace object'); return false; } if ($tag->getName() == 'row') { //replace {{pageID}} tag in all page content. return str_replace('{{pageID}}', $treatmentParameters["page"]->getID(), $tag->getInnerContent()); } else { //create the block data $block = $tag->getRepresentationInstance(); return $block->getData($treatmentParameters["language"], $treatmentParameters["page"], $treatmentParameters["clientSpace"], $treatedObject, $visualizationMode); } break; case MODULE_TREATMENT_CLIENTSPACE_TAGS: if (!$treatedObject instanceof CMS_pageTemplate) { $this->raiseError('$treatedObject must be a CMS_pageTemplate object'); return false; } if (!$treatmentParameters["page"] instanceof CMS_page) { $this->raiseError('$treatmentParameters["page"] must be a CMS_page object'); return false; } if (!$treatmentParameters["language"] instanceof CMS_language) { $this->raiseError('$treatmentParameters["language"] must be a CMS_language object'); return false; } $args = array("template" => $treatedObject->getID()); if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM || $visualizationMode == PAGE_VISUALMODE_HTML_EDITION || $visualizationMode == PAGE_VISUALMODE_FORM) { $args["editedMode"] = true; } //load CS datas switch ($tag->getName()) { case 'atm-clientspace': default: $client_space = $tag->getRepresentationInstance($args); switch ($visualizationMode) { case PAGE_VISUALMODE_PRINT: $data = ""; $clientSpacesData = array(); $csTagID = $tag->getAttribute("id"); $printingCS = $treatedObject->getPrintingClientSpaces(); if (in_array($csTagID, $printingCS)) { $clientSpacesData[$csTagID] = $client_space->getData($treatmentParameters["language"], $treatmentParameters["page"], $visualizationMode, $treatedObject->hasPages()); } foreach ($printingCS as $cs) { if (isset($clientSpacesData[$cs])) { $data .= $clientSpacesData[$cs] . '<br />'; } } return $data; break; default: if (is_object($client_space)) { return $client_space->getData($treatmentParameters["language"], $treatmentParameters["page"], $visualizationMode, false); } else { return ''; } break; } break; } break; case MODULE_TREATMENT_LINXES_TAGS: switch ($tag->getName()) { case "atm-linx": //linx are visible only if target pages are published (public tree) $linx_args = array("page" => $treatedObject, "publicTree" => true); $linx = $tag->getRepresentationInstance($linx_args); return $linx->getOutput(true); break; } return ''; break; case MODULE_TREATMENT_PAGECONTENT_TAGS: if (!$treatedObject instanceof CMS_page) { $this->raiseError('$treatedObject must be a CMS_page object'); return false; } switch ($tag->getName()) { case "atm-main-url": return CMS_websitesCatalog::getMainURL(); break; case "atm-keywords": return '<meta name="keywords" content="' . SensitiveIO::sanitizeHTMLString($treatedObject->getKeywords($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC)) . '" />'; break; case "atm-description": return '<meta name="description" content="' . SensitiveIO::sanitizeHTMLString($treatedObject->getDescription($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC)) . '" />'; break; case "atm-last-update": $lastlog = CMS_log_catalog::getByResourceAction(MOD_STANDARD_CODENAME, $treatedObject->getID(), array(CMS_log::LOG_ACTION_RESOURCE_SUBMIT_DRAFT, CMS_log::LOG_ACTION_RESOURCE_DIRECT_VALIDATION), 1); if (!$lastlog || !is_object($lastlog[0])) { return ''; } $user = $lastlog[0]->getUser(); $date = $lastlog[0]->getDateTime(); $dateformat = $tag->getAttribute("format") ? $tag->getAttribute("format") : 'Y-m-d'; $replace = array('{{date}}' => date($dateformat, $date->getTimestamp()), '{{firstname}}' => $user->getFirstName(), '{{lastname}}' => $user->getLastName()); return str_replace(array_keys($replace), $replace, $tag->getInnerContent()); break; case "atm-print-link": if ($treatedObject->getPrintStatus()) { $template = $tag->getInnerContent(); if ($tag->getAttribute("keeprequest") == 'true') { return '<?php echo \'' . str_replace("{{href}}", $treatedObject->getURL(true) . '\'.($_SERVER["QUERY_STRING"] ? \'?\'.$_SERVER["QUERY_STRING"] : \'\').\'', str_replace("\\\\'", "\\'", str_replace("'", "\\'", $template))) . '\' ?>'; } else { return str_replace("{{href}}", $treatedObject->getURL(true), $template); } } return ''; break; case "atm-constant": $const = SensitiveIO::stripPHPTags(io::strtoupper($tag->getAttribute("name"))); if (defined($const)) { return constant($const); } return ''; break; case "head": $headCode = '<?php' . "\n" . '$atmHost = null;' . "\n" . '$atmPort = null;' . "\n" . 'if(isset($_SERVER["HTTP_HOST"])) {' . "\n" . ' $atmHost = @parse_url($_SERVER["HTTP_HOST"], PHP_URL_HOST) ? @parse_url($_SERVER["HTTP_HOST"], PHP_URL_HOST) : $_SERVER["HTTP_HOST"];' . "\n" . ' $atmPort = @parse_url($_SERVER[\'HTTP_HOST\'], PHP_URL_PORT) ? \':\'.@parse_url($_SERVER[\'HTTP_HOST\'], PHP_URL_PORT) : \'\';' . "\n" . '}' . "\n" . 'echo "\\t".\'<base href="//\'.$atmHost.$atmPort.PATH_REALROOT_WR.\'/" />\'."\\n";' . "\n" . ' ?>'; //Append base code return preg_replace('#<head([^>]*)>#', '<head\\1>' . "\n" . $headCode, $tag->getContent()); break; case "body": $statsCode = '<?php if (SYSTEM_DEBUG && STATS_DEBUG) {echo CMS_stats::view();} ?>'; //Append stats code return preg_replace('#</body>$#', $statsCode . "\n" . '</body>', $tag->getContent()); break; case "html": //Append DTD return '<?php if (defined(\'APPLICATION_XHTML_DTD\')) echo APPLICATION_XHTML_DTD."\\n"; ?>' . "\n" . $tag->getContent(); break; } return ''; break; case MODULE_TREATMENT_PAGEHEADER_TAGS: if (!$treatedObject instanceof CMS_page) { $this->raiseError('$treatedObject must be a CMS_page object'); return false; } switch ($tag->getName()) { case "atm-linx": if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM || $visualizationMode == PAGE_VISUALMODE_FORM) { //direct linx are visible even if target pages are not published (edited tree) //all other linx are only visible if they are published (public tree) $linx_args = array("page" => $treatedObject, "publicTree" => !($tag->getAttribute('type') == 'direct' || !$tag->getAttribute('type'))); $linx = $tag->getRepresentationInstance($linx_args); $linx->setDebug(false); $linx->setLog(false); return $linx->getOutput(); } else { //for public and print visualmode, this treatment is done by MODULE_TREATMENT_LINXES_TAGS mode during page file linx treatment if ($visualizationMode != PAGE_VISUALMODE_HTML_PUBLIC && $visualizationMode != PAGE_VISUALMODE_PRINT) { //linx are visible only if target pages are published (public tree) $linx_args = array("page" => $treatedObject, "publicTree" => true); $linx = $tag->getRepresentationInstance($linx_args); return $linx->getOutput(); } } break; case "atm-js-tags": case "atm-css-tags": $usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename); $tagFiles = $tag->getAttribute('files'); $tagFiles = array_map('trim', explode(',', $tagFiles)); //only if current page use a block of this module if ($tagFiles) { //save in global var the page ID who use this tag CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array($tag->getName() => true)); $return = ''; //overwrite previous modules return to append files of this module //save new modules files switch ($tag->getName()) { case "atm-js-tags": //get old files for this tag already needed by other modules $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags"); $files = is_array($files) ? $files : array(); //append module js files $files = array_merge($files, $tagFiles); //append CMS_function.js file if (!isset($usage['js-files']) && file_exists(PATH_JS_FS . '/CMS_functions.js')) { $file = str_replace(PATH_REALROOT_FS . '/', '', PATH_JS_FS . '/CMS_functions.js'); $files = array_merge($files, array($file)); } //append swfobject for block flash if (is_array($usage) && isset($usage['blockflash']) && $usage['blockflash'] == true) { $files[] = 'swfobject'; } //save files CMS_module::moduleUsage($treatedObject->getID(), $tag->getName(), $files, true); break; case "atm-css-tags": //get old files for this tag already needed by other modules $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags"); $files = is_array($files) ? $files : array(); $media = $tag->getAttribute('media') ? $tag->getAttribute('media') : 'all'; //append module css files if (!isset($files[$media])) { $files[$media] = array(); } $files[$media] = array_merge($files[$media], $tagFiles); //save files CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags", $files, true); break; } //Create return for all saved modules files switch ($tag->getName()) { case "atm-js-tags": //get old files for this tag already needed by other modules $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags"); //add files from atm-js-add tag $filesAdd = CMS_module::moduleUsage($treatedObject->getID(), "atm-js-tags-add"); $filesAdd = is_array($filesAdd) ? $filesAdd : array(); $files = array_merge($files, $filesAdd); $return .= '<?php echo CMS_view::getJavascript(array(\'' . implode('\',\'', array_unique($files)) . '\')); ?>' . "\n"; break; case "atm-css-tags": $media = $tag->getAttribute('media') ? $tag->getAttribute('media') : 'all'; //get old files for this tag already needed by other modules $files = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags"); //add files from atm-css-add tag $filesAdd = CMS_module::moduleUsage($treatedObject->getID(), "atm-css-tags-add"); $filesAdd = is_array($filesAdd) ? $filesAdd : array(); if (isset($files[$media])) { if (isset($filesAdd[$media])) { $files[$media] = array_merge($files[$media], $filesAdd[$media]); } $return .= '<?php echo CMS_view::getCSS(array(\'' . implode('\',\'', array_unique($files[$media])) . '\'), \'' . $media . '\'); ?>' . "\n"; } break; } return $return; } break; case "atm-meta-tags": $attributes = array(); //normalize values for attributes if ($tag->getAttributes()) { $attributes = $tag->getAttributes(); foreach ($attributes as $tagName => $value) { if ($attributes == '1' || $value == 'true') { $attributes[$tagName] = true; } elseif ($value == '0' || $value == 'false') { $attributes[$tagName] = false; } if ($attributes[$tagName] !== false && $attributes[$tagName] !== true) { unset($attributes[$tagName]); } } } $metaDatas = $treatedObject->getMetaTags($visualizationMode == PAGE_VISUALMODE_HTML_PUBLIC, $attributes); $usage = CMS_module::moduleUsage($treatedObject->getID(), $this->_codename); //if page template already use atm-js-tags tag, no need to add JS again if (!is_array($usage) || !isset($usage['atm-js-tags'])) { $metaDatas .= ' <script type="text/javascript" src="' . PATH_REALROOT_WR . '/js/CMS_functions.js"></script>' . "\n"; //save JS handled CMS_module::moduleUsage($treatedObject->getID(), $this->_codename, array('js-files' => true)); } if ($visualizationMode == PAGE_VISUALMODE_FORM) { global $cms_user; $isValidator = is_object($cms_user) && $cms_user->hasPageClearance($treatedObject->getID(), CLEARANCE_PAGE_EDIT) && $cms_user->hasValidationClearance(MOD_STANDARD_CODENAME) ? 'true' : 'false'; //add needed javascripts $metaDatas .= '<script type="text/javascript">' . "\n" . 'var atmRowsDatas = {};' . "\n" . 'var atmBlocksDatas = {};' . "\n" . 'var atmCSDatas = {};' . "\n" . 'var atmIsValidator = ' . $isValidator . ';' . "\n" . 'var atmIsValidable = true;' . "\n" . 'var atmHasPreview = true;' . "\n" . 'var atmHasPreview = true;' . "\n" . 'var CKEDITOR_BASEPATH = \'' . PATH_MAIN_WR . '/ckeditor/\';' . "\n" . '</script>'; //append JS from current view instance $view = CMS_view::getInstance(); $metaDatas .= $view->getJavascript(); $metaDatas .= CMS_view::getCSS(array('edit')); } else { if ($visualizationMode == PAGE_VISUALMODE_CLIENTSPACES_FORM) { //add needed javascripts $metaDatas .= '<script type="text/javascript">' . "\n" . 'var atmRowsDatas = {};' . "\n" . 'var atmBlocksDatas = {};' . "\n" . 'var atmCSDatas = {};' . "\n" . 'var atmIsValidator = false;' . "\n" . 'var atmIsValidable = false;' . "\n" . 'var atmHasPreview = false;' . "\n" . 'var CKEDITOR_BASEPATH = \'' . PATH_MAIN_WR . '/ckeditor/\';' . "\n" . '</script>'; //append JS from current view instance $view = CMS_view::getInstance(); $metaDatas .= $view->getJavascript(); $metaDatas .= CMS_view::getCSS(array('edit')); } } //if page template already use atm-js-tags tag, no need to add JS again if (!is_array($usage) || !isset($usage['atm-js-tags'])) { //if this page use a row block of this module then add the header code to the page if (is_array($usage) && isset($usage['blockflash']) && $usage['blockflash'] == true) { $metaDatas .= '<script type="text/javascript" src="' . PATH_MAIN_WR . '/swfobject/swfobject.js"></script>' . "\n"; } } return $metaDatas; break; } return ''; break; case MODULE_TREATMENT_WYSIWYG_INNER_TAGS: if ($tag->getName() == 'atm-linx') { //linx from standard module $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<html>' . $tag->getContent() . '</html>'); } catch (DOMException $e) { $this->raiseError('Parse error for atm-linx : ' . $e->getMessage() . " :\n" . io::htmlspecialchars($tag->getContent())); return ''; } $nodespecs = $domdocument->getElementsByTagName('nodespec'); if ($nodespecs->length == 1) { $nodespec = $nodespecs->item(0); } $htmltemplates = $domdocument->getElementsByTagName('htmltemplate'); if ($htmltemplates->length == 1) { $htmltemplate = $htmltemplates->item(0); } $noselections = $domdocument->getElementsByTagName('noselection'); if ($noselections->length == 1) { $noselection = $noselections->item(0); } if ($nodespec && $htmltemplate) { //if ($paramsTags[0]->getName() == "nodespec" && $paramsTags[1]->getName() == "noselection" && $paramsTags[2]->getName() == "htmltemplate") { if (isset($noselection)) { // case noselection tag $pageID = $nodespec->getAttribute("value"); $link = CMS_DOMDocument::DOMElementToString($htmltemplate, true); $treatedLink = str_replace('href', 'noselection="true" href', str_replace('{{href}}', '{{' . $pageID . '}}', $link)); } else { $pageID = $nodespec->getAttribute("value"); $link = CMS_DOMDocument::DOMElementToString($htmltemplate, true); $treatedLink = str_replace('{{href}}', '{{' . $pageID . '}}', $link); } } } elseif ($tag->getName() == 'span') { //linx from other module $ids = explode('-', $tag->getAttribute('id')); $selectedPageID = (int) $ids[1]; $noselection = $ids[2]; //then create the code to paste for the current selected object if any if (sensitiveIO::isPositiveInteger($selectedPageID) && ($noselection == 'true' || $noselection == 'false')) { $pattern = "/(.*)<a([^>]*)'\\.CMS_tree.*, 'url'\\)\\.'(.*)\\<\\/a>(.*)<\\/span>/U"; if ($noselection == 'true') { $replacement = '<a noselection="true"\\2{{' . $selectedPageID . '}}\\3</a>'; } else { $replacement = '<a\\2{{' . $selectedPageID . '}}\\3</a>'; } $treatedLink = str_replace("\\'", "'", preg_replace($pattern, $replacement, $tag->getContent())); } } return $treatedLink; case MODULE_TREATMENT_WYSIWYG_OUTER_TAGS: //Anchor if (preg_match('/^#([a-zA-Z0-9._{}:-]*)$/i', $tag->getAttribute('href')) > 0) { //instanciate anchor tag $anchor = new CMS_XMLTag_anchor($tag->getName(), $tag->getAttributes(), $tag->getChildren(), $tag->getParameters()); return $anchor->compute(array('mode' => $treatmentMode, 'visualization' => $visualizationMode, 'object' => $treatedObject, 'parameters' => $treatmentParameters)); } elseif (preg_match('/^.*\\{\\{(\\d+)\\}\\}.*$/i', $tag->getAttribute('href')) > 0) { //internal links /* Pattern explanation : * * \<a([^>]*) : start with "<a" and any characters after except a ">". Content found into the "()" (first parameters of the link) is the first variable : "\\1" * {{(\d+)}} : some numbers only into "{{" and "}}". Content found into the "()" (the page number) is the second variable : "\\2" * (.*)\<\/a> : any characters after followed by "</a>". Content found into the "()" (last parameters of the link and link content) is the third variable : "\\3" * /U : PCRE_UNGREEDY stop to the first finded occurence. */ $pattern = "/<a([^>]*){{(\\d+)}}(.*)\\<\\/a>/Us"; if ($tag->getName() == 'a' && $treatmentParameters['module'] == MOD_STANDARD_CODENAME) { if ($tag->getAttribute('noselection') == 'true') { $replacement = "<atm-linx type=\"direct\"><selection><start><nodespec type=\"node\" value=\"\\2\"/></start></selection><noselection>" . $tag->getInnerContent() . "</noselection><display><htmltemplate><a\\1{{href}}\\3</a></htmltemplate></display></atm-linx>"; $treatedLink = preg_replace($pattern, $replacement, str_replace('noselection="true"', '', $tag->getContent())); } else { $replacement = "<atm-linx type=\"direct\"><selection><start><nodespec type=\"node\" value=\"\\2\"/></start></selection><display><htmltemplate><a\\1{{href}}\\3</a></htmltemplate></display></atm-linx>"; $treatedLink = preg_replace($pattern, $replacement, $tag->getContent()); } } elseif ($tag->getName() == 'a' && $treatmentParameters['module'] != MOD_STANDARD_CODENAME) { if ($tag->getAttribute('noselection') == 'true') { $replacement = '<span id="' . MOD_STANDARD_CODENAME . '-\\2-true"><?php if (CMS_tree::pageExistsForUser(\\2)) { echo \'<a\\1\'.CMS_tree::getPageValue(\\2, \'url\').\'\\3</a>\';} else { echo ' . var_export($tag->getInnerContent(), true) . ';} ?><!--{elements:' . base64_encode(serialize(array('module' => array(0 => MOD_STANDARD_CODENAME)))) . '}--></span>'; $treatedLink = preg_replace($pattern, $replacement, str_replace(array('noselection="true"', "'"), array('', "\\'"), $tag->getContent())); } else { $replacement = '<span id="' . MOD_STANDARD_CODENAME . '-\\2-false"><?php if (CMS_tree::pageExistsForUser(\\2)) { echo \'<a\\1\'.CMS_tree::getPageValue(\\2, \'url\').\'\\3</a>\';} ?><!--{elements:' . base64_encode(serialize(array('module' => array(0 => MOD_STANDARD_CODENAME)))) . '}--></span>'; $treatedLink = preg_replace($pattern, $replacement, str_replace("'", "\\'", $tag->getContent())); } } return $treatedLink; } break; } //in case of no tag treatment, simply return it return $tag->getContent(); }