/** * Compute the tag * * @return string the PHP / HTML content computed * @access private */ protected function _compute() { //return code $return = $this->_computeChilds(); $strict = isset($this->_attributes['strict']) && ($this->_attributes['strict'] == 'true' || $this->_attributes['strict'] == true || $this->_attributes['strict'] == 1) ? true : false; //Ajax code $ajaxCode = ' if(io::request(\'out\') == \'xml\') { $xmlCondition = CMS_polymod_definition_parsing::replaceVars("' . $this->replaceVars($this->_attributes['what'], false, false, array($this, 'encloseWithPrepareVar')) . '", $replace); if ($xmlCondition) { $func = create_function("","return (".$xmlCondition.");"); if ($func && $func()) { $cms_view = CMS_view::getInstance(); $content = $replace = \'\';'; if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) { $ajaxCode .= 'ob_start();'; $xml = new CMS_xml2Array($return); $ajaxCode .= $xml->toXML($xml->getParsedArray(), false, true) . '<?php '; $ajaxCode .= '$content = ob_get_contents(); ob_end_clean(); $replace=array();'; } else { $ajaxCode .= $return; } $ajaxCode .= '$content = CMS_polymod_definition_parsing::replaceVars($content, $replace); $cms_view->setDisplayMode(' . ($strict ? 'CMS_view::SHOW_XML' : 'CMS_view::SHOW_RAW') . '); $cms_view->setContent($content); //output empty XML response unset($content); unset($replace); $cms_view->setContentTag(\'data\'); $cms_view->show(); } } unset($xmlCondition); }'; if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) { $code = array('code' => CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($this->_returnComputedDatas($ajaxCode)))); CMS_module::moduleUsage($this->_computeParams['object']->getID(), MOD_STANDARD_CODENAME, array('headCallback' => array($code))); } else { $this->_tagHeaderCode = array('code' => CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($ajaxCode))); } return $return; }
/** * Compute the tag * * @return string the PHP / HTML content computed * @access private */ protected function _compute() { $headCode = ''; if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) { $headCode .= 'ob_start();'; $xml = new CMS_xml2Array($this->_computeChilds()); $headCode .= $xml->toXML($xml->getParsedArray(), false, true) . '<?php '; $headCode .= '$content = ob_get_contents(); ob_end_clean(); $replace=array();'; $footcode = 'if (trim($content)) {echo $content;}' . "\n"; } else { $headCode .= $this->_computeChilds() . ' if (trim($content)) {echo $content;}'; } if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) { $code = array('code' => CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($this->_returnComputedDatas($headCode)))); CMS_module::moduleUsage($this->_computeParams['object']->getID(), MOD_STANDARD_CODENAME, array('headCallback' => array($code))); } else { $this->_tagHeaderCode = array('code' => CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($headCode))); } return ''; }
/** * Add a field in form code * * @param string $source, the xhtml source to check * @param CMS_forms_field $field, the field to replace * @access public * @return string, the xhtml source checked */ function addField($source, $field) { //and add already selected values (from $_POST global values) $replace = array('&' => '&'); $xml2Array = new CMS_xml2Array($source, CMS_xml2Array::XML_ENCLOSE | CMS_xml2Array::XML_PROTECT_ENTITIES); //parse XHTML form content $xmlArray = $xml2Array->getParsedArray(); //replace field $this->_addField($xmlArray, $field); //add already selected values $this->_checkInputs($xmlArray); //then convert back into XHTML $source = $xml2Array->toXML($xmlArray); return $source; }
/** * Compute recursively all parsed definition tags * and send them to callback methods (according to $this->_tagsCallBack) * * @param multidimentionnal array $definition : the definition to compute * @param integer $level : the current level of recursion (default : 0) * @return string the PHP / HTML content computed * @access public */ function computeTags($definition, $level = 0) { $code = ''; if ($level == 0) { $code .= '$content .="'; } if (is_array($definition) && isset($definition[0]) && is_array($definition[0])) { //loop on subtags foreach (array_keys($definition) as $key) { if (isset($definition[$key]['nodename']) && isset($this->_tagsCallBack[$definition[$key]['nodename']])) { if (!is_array($this->_tagsCallBack[$definition[$key]['nodename']]) && method_exists($this, $this->_tagsCallBack[$definition[$key]['nodename']])) { $code .= '";' . "\n"; $code = CMS_polymod_definition_parsing::preReplaceVars($code); $code .= $this->{$this->_tagsCallBack[$definition[$key]['nodename']]}($definition[$key]); $code .= '$content .="'; } elseif (is_array($this->_tagsCallBack[$definition[$key]['nodename']]) && class_exists($this->_tagsCallBack[$definition[$key]['nodename']]['class'])) { //check for parameters requirements if any $match = true; foreach ($this->_tagsCallBack[$definition[$key]['nodename']]['parameters'] as $aParameter => $value) { $match = isset($definition[$key]['attributes'][$aParameter]) && ($definition[$key]['attributes'][$aParameter] == $value || preg_match('/^' . $value . '$/i', $definition[$key]['attributes'][$aParameter]) > 0) ? $match : false; } if ($match) { $code .= '";' . "\n"; $code = CMS_polymod_definition_parsing::preReplaceVars($code); $oTag = new $this->_tagsCallBack[$definition[$key]['nodename']]['class']($definition[$key]['nodename'], $definition[$key]['attributes'], isset($definition[$key]['childrens']) ? $definition[$key]['childrens'] : array(), array('context' => CMS_XMLTag::PHP_CONTEXT, 'module' => isset($this->_parameters['module']) ? $this->_parameters['module'] : false, 'childrenCallback' => array($this, 'computeTags'))); if ($this->_mode == self::CHECK_PARSING_MODE) { $this->_parsingError .= $oTag->getTagError() ? "\n" . $oTag->getTagError() : ''; } else { $code .= $oTag->compute(array('mode' => $this->_mode, 'visualization' => $this->_parameters['visualization'])); $this->_elements = array_merge_recursive((array) $this->_elements, (array) $oTag->getTagReferences()); //get header code if any if ($oTag->getHeaderCode()) { $this->_headCallBack['tagsCallback'][] = $oTag->getHeaderCode(); } } $code .= '$content .="'; } else { if (isset($definition[$key]['childrens'])) { //compute subtags $childrens = $definition[$key]['childrens']; //append computed tags as code $xml = array($definition[$key]); $code .= str_replace('"', '\\"', $this->_parser->toXML($xml, CMS_xml2Array::ARRAY2XML_START_TAG)); $code .= $this->computeTags($definition[$key]['childrens'], $level + 1); $code .= str_replace('"', '\\"', $this->_parser->toXML($xml, CMS_xml2Array::ARRAY2XML_END_TAG)); } else { $xml = array($definition[$key]); $code .= str_replace('"', '\\"', $this->_parser->toXML($xml)); } } } else { $this->raiseError('Unknown compute callback method : ' . $this->_tagsCallBack[$definition[$key]['nodename']] . ' for tag ' . $definition[$key]['nodename']); return false; } } elseif (isset($definition[$key]['phpnode'])) { //store usage of phpnode in definition $this->_elements['phpnode'] = true; //append php code $code .= '";' . "\n"; $code = CMS_polymod_definition_parsing::preReplaceVars($code); $code .= 'eval(sensitiveIO::sanitizeExecCommand(CMS_polymod_definition_parsing::replaceVars(\'' . str_replace("'", "\\'", str_replace("\\'", "\\\\'", CMS_polymod_definition_parsing::preReplaceVars($definition[$key]['phpnode'], false, false, false))) . '\', $replace)));' . "\n"; $code .= '$content .="'; } elseif (isset($definition[$key]['childrens'])) { //compute subtags $childrens = $definition[$key]['childrens']; //append computed tags as code $xml = array($definition[$key]); $code .= str_replace('"', '\\"', $this->_parser->toXML($xml, CMS_xml2Array::ARRAY2XML_START_TAG)); $code .= $this->computeTags($definition[$key]['childrens'], $level + 1); $code .= str_replace('"', '\\"', $this->_parser->toXML($xml, CMS_xml2Array::ARRAY2XML_END_TAG)); } else { $xml = array($definition[$key]); $code .= str_replace('"', '\\"', $this->_parser->toXML($xml)); } } } else { if ($this->_mode == self::CHECK_PARSING_MODE) { $this->_parsingError .= "\n" . 'Malformed definition to compute'; return false; } else { $this->raiseError("Malformed definition to compute : " . print_r($definition, true)); return false; } } if ($level == 0) { $code .= '";' . "\n"; $code = CMS_polymod_definition_parsing::preReplaceVars($code); } return $code; }
/** * Return given RSS feed informations * * @param array $values : parameters values array(parameterName => parameterValue) in : * selected : the selected rss ID * @param multidimentionnal array $tags : xml2Array content of atm-function tag * ... {url} ... {label} ... {description} ... * @return string : the RSS feed informations * @access public */ function rss($values, $tags) { global $cms_language; if (!sensitiveIO::isPositiveInteger($values['selected'])) { $this->raiseError("Selected value parameter must be a valid RSS Feed ID : " . $values['selected']); return false; } $RSSDefinition = new CMS_poly_rss_definitions($values['selected']); if ($RSSDefinition->hasError()) { $this->raiseError("Selected value parameter must be a valid RSS Feed ID : " . $values['selected']); return false; } $linkParameters = ''; if (sizeof($values) > 1) { foreach ($values as $key => $value) { if ($key != 'selected') { $linkParameters .= '&' . $key . '=' . io::htmlspecialchars($value); } } } $replace = array('{url}' => PATH_REALROOT_WR . '/rss/rss' . (!STRIP_PHP_EXTENSION ? '.php' : '') . '?id=' . $RSSDefinition->getID() . $linkParameters, '{label}' => $RSSDefinition->getLabel($cms_language), '{description}' => $RSSDefinition->getDescription($cms_language)); $xml2Array = new CMS_xml2Array($tags); $return = $xml2Array->toXML($tags); $return = str_replace(array_keys($replace), $replace, $return); return $return; }
/** * Get the content, which is the text content including the tag definition. * * @return string the XML * @access public */ function getContent() { if (!$this->_textContent || $this->_textContentInvalid) { $xml = array('nodename' => $this->_name, 'attributes' => $this->_attributes); if ($this->_children) { $xml['childrens'] = $this->_children; } $xml = array($xml); $parser = new CMS_xml2Array(); $this->_textContent = $parser->toXML($xml); $this->_textContentInvalid = false; } return $this->_textContent; }