/** * 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 ''; }
/** * Compute an atm-form-callback tag * * @param array $tag : the reference atm-form-callback tag to compute * @return void * @access private */ protected function _formCallback(&$tag) { //check tags requirements if (!$this->checkTagRequirements($tag, array('form' => 'alphanum'))) { return; } //check for tag callback content if (isset($tag['childrens'])) { //callback code $formCallback = $this->computeTags($tag['childrens']); //add reference to this form to header callback $this->_headCallBack['formsCallback'][$tag['attributes']['form']]['form'] = CMS_XMLTag::indentPHP(CMS_XMLTag::cleanComputedDefinition($formCallback)); } }
/** * Replace vars like {object:field:type} or {var|session|request|page:name:type}. Called during definition compilation * * @param string $text : the text which need to be replaced * @param boolean reverse : reverse single and double quotes useage (default is false : double quotes) * @param boolean $cleanNotMatches : remove vars without matches * @param mixed $matchCallback : function name or array(object classname, object method) which represent a valid callback function to execute on matches * @return text : the text replaced * @access public * @static */ function replaceVars($text, $reverse = false, $cleanNotMatches = false, $matchCallback = null, $returnMatchedVarsArray = false) { static $replacements; $enclosePHP = false; if ($matchCallback === null) { $matchCallback = array($this, 'encloseString'); if ($this->_context == self::HTML_CONTEXT && $this->_parameters['context'] != self::HTML_TAG_CONTEXT) { $enclosePHP = true; } } //if no text => return if (!$text || !trim($text)) { return $text; } //substitute simple replacement values $preReplaceCount = 0; $text = preg_replace("#{([a-zA-Z]+)}#", '@@@\\1@@@', $text, -1, $preReplaceCount); $count = 1; //loop on text for vars to replace if any while (preg_match_all("#{[^{}\n]+}#", $text, $matches) && $count) { $matches = array_unique($matches[0]); //get all tags handled by modules if (!$replacements) { //create replacement array $replacements = array(); $modules = CMS_modulesCatalog::getAll("id"); foreach ($modules as $codename => $aModule) { $moduleReplacements = $aModule->getModuleReplacements(); if (is_array($moduleReplacements) && $moduleReplacements) { foreach ($moduleReplacements as $pattern => $replacement) { $replacements[$pattern] = $replacement; } } } } $replace = $replacements; if ($reverse) { $reversedReplace = array(); foreach ($replace as $key => $value) { $reversedReplace[str_replace("'", "\\\\'", $key)] = $value; } $replace = $reversedReplace; } $count = 0; $matchesValues = preg_replace(array_keys($replace), $replace, $matches, -1, $count); //create vars conversion table $replace = array(); if ($matchesValues) { if (isset($this->_parameters['module'])) { $externalReferences = CMS_poly_object_catalog::getFieldsReferencesUsage($this->_parameters['module']); } else { $externalReferences = CMS_poly_object_catalog::getFieldsReferencesUsage(); } foreach ($matches as $key => $match) { //record external references for cache reference if ($externalReferences) { foreach ($externalReferences as $id => $type) { if (strpos($match, '[\'fields\'][' . $id . ']') !== false || strpos($match, '[\\\'fields\\\'][' . $id . ']') !== false) { //CMS_grandFather::log(print_r($this->_tagReferences, true)); $this->_tagReferences = array_merge_recursive($type, (array) $this->_tagReferences); //CMS_grandFather::log(print_r($this->_tagReferences, true)); } } } //record used pages for cache reference if (strpos($match, '{page:') !== false) { $this->_tagReferences['module'][] = MOD_STANDARD_CODENAME; } //record used users for cache reference if (strpos($match, '{user:'******'resource'][] = 'users'; } if ($match != $matchesValues[$key]) { $matchValue = $matchesValues[$key]; } else { $matchValue = null; } //apply callback if any to value if (isset($matchValue)) { if ($matchCallback) { if (is_callable($matchCallback)) { $replace[$match] = call_user_func($matchCallback, $matchValue, $reverse); } else { CMS_grandFather::raiseError("Unknown callback function : " . $matchCallback); return false; } } else { $replace[$match] = $matchValue; } } elseif ($cleanNotMatches) { $replace[$match] = ''; } } } //return matched vars if needed if ($returnMatchedVarsArray) { //substitute simple replacement values if ($preReplaceCount) { $replace = preg_replace("#\\@\\@\\@([a-zA-Z]+)\\@\\@\\@#", '{\\1}', $replace); } return $replace; } else { //then replace variables in text and return it $text = str_replace(array_keys($replace), $replace, $text); if ($enclosePHP && $replace) { //save last replacements $lastReplace = $replace; } } } if ($enclosePHP && isset($lastReplace) && $lastReplace) { //use last replacements to enclose replacement values with php tags $replace = array(); foreach ($lastReplace as $replacement) { $replace[$replacement] = '<?php echo "' . $replacement . '"; ?>'; } $text = CMS_XMLTag::cleanComputedDefinition(str_replace(array_keys($replace), $replace, $text)); } //substitute simple replacement values if ($preReplaceCount) { $text = preg_replace("#\\@\\@\\@([a-zA-Z]+)\\@\\@\\@#", '{\\1}', $text); } return $text; }
/** * 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; }