/** * 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 ''; }
/** * Constructor. * initialize object. * * @param string $definition the definition to parse * @param boolean $parse : completely parse the given definition (default is true) or only replace values in it * @param constant $mode : the current parsing mode in : * self::PARSE_MODE : Parse definition (default) * self::CHECK_PARSING_MODE : Check for definition parsing errors * self::BLOCK_PARAM_MODE : Get definition block parameters form * @param string $module : the current module codename which use this definition. this parameter is optionnal but it can enforce definition parsing requirements (used to verify specific modules languages for now). * @param integer $visualizationMode The current visualization mode (see constants in cms_rc.php for accepted values). * @return void * @access public */ function __construct($definition, $parse = true, $mode = self::PARSE_MODE, $module = false, $visualizationMode = PAGE_VISUALMODE_HTML_PUBLIC) { if (!trim($definition)) { return; } if ($module) { $this->_parameters['module'] = $module; } $this->_parameters['visualization'] = $visualizationMode; $this->_mode = $mode; if ($parse || $mode == self::BLOCK_PARAM_MODE) { //get all tags handled by modules $modules = CMS_modulesCatalog::getAll("id"); foreach ($modules as $codename => $aModule) { $moduleTreatments = $aModule->getWantedTags(MODULE_TREATMENT_PAGECONTENT_TAGS, $this->_parameters['visualization']); if (is_array($moduleTreatments) && $moduleTreatments) { //if module return tags, save them. foreach ($moduleTreatments as $tagName => $parameters) { if (isset($parameters['class']) && !isset($this->_tagsCallBack[$tagName])) { $this->_tagsCallBack[$tagName] = $parameters; } } } } //parse definiton $this->_parser = new CMS_xml2Array($definition, CMS_xml2Array::XML_ENCLOSE | CMS_xml2Array::XML_PROTECT_ENTITIES); $this->_definitionArray = $this->_parser->getParsedArray(); //compute definition $this->_definition = $this->computeTags($this->_definitionArray); if ($mode != self::BLOCK_PARAM_MODE) { //clean some useless codes $this->_definition = CMS_XMLTag::cleanComputedDefinition($this->_definition); } } else { $this->_definition = $this->preReplaceVars(str_replace('"', '"', $definition), false, true); } }
/** * Recursive method to add input tags in XHTML source * * @param multidimentionnal array &definition : the XML definition to treat (by reference) * @param CMS_forms_field $field, the field to replace * @access private * @return void */ protected function _addField(&$definition, &$field) { if (is_array($definition) && is_array($definition[0])) { //loop on subtags foreach (array_keys($definition) as $key) { if (isset($definition[$key]['textnode']) && $definition[$key]['textnode'] == '{{field}}') { //recreate XHTML code for field list($label, $input) = $field->getFieldXHTML($this->_language); $replace = array('&' => '&'); //transform XHTML code to XML definition $xmlArray = new CMS_xml2Array($input, CMS_xml2Array::XML_ENCLOSE | CMS_xml2Array::XML_PROTECT_ENTITIES); //then replace field definition into current definition tag $fieldDefinition = $xmlArray->getParsedArray(); // Default : add the first tag $definition[$key] = $fieldDefinition[0]; // Check other tags if ($fieldDefinition) { foreach ($fieldDefinition as $subFieldTagKey => $subFieldTag) { if (isset($subFieldTag['attributes']['class']) && $subFieldTag['attributes']['class'] == 'inputHelp') { $definition[] = $subFieldTag; } } } $definition[$key] = $fieldDefinition[0]; } elseif (isset($definition[$key]['textnode']) && $definition[$key]['textnode'] == '{{label}}') { //recreate XHTML code for field list($label, $input) = $field->getFieldXHTML($this->_language); $replace = array('&' => '&'); //transform XHTML code to XML definition $xmlArray = new CMS_xml2Array($label, CMS_xml2Array::XML_ENCLOSE | CMS_xml2Array::XML_PROTECT_ENTITIES); //then replace field definition into current definition tag $fieldDefinition = $xmlArray->getParsedArray(); $definition[$key] = $fieldDefinition[0]; } if (is_array($definition[$key]) && sizeof($definition[$key]['childrens'])) { $this->_addField($definition[$key]['childrens'], $field); } } } else { $this->raiseError("Malformed definition to compute : " . print_r($definition, true)); return false; } }
/** * Import module datas * * @param mixed $datas, the import datas * @param string $format, the import format in : php (default), xml * @param CMS_language $cms_language, the current cms_language to use. Passed by reference to temporary overwrite it with import language * @param string $infos (reference), the returned import infos * @return boolean : the import status */ function import($datas, $format = 'php', &$cms_language, &$infos) { $infos = ''; $return = true; switch ($format) { case 'xml': //convert XML to PHP array $xml2Array = new CMS_xml2Array($datas, CMS_xml2Array::XML_ARRAY2XML_FORMAT); $importedArray = $xml2Array->getParsedArray(); break; case 'php': //try to eval PHP Array if (!is_array($datas)) { $infos .= 'Error : PHP datas must be a valid PHP array ... ' . "\n"; return false; } else { $importedArray = $datas; } break; default: $infos .= 'Error : Unknown import format ... ' . $format . "\n"; return false; break; } if (!isset($importedArray) || !is_array($importedArray)) { $infos .= 'Error : no datas to import or incorrect datas ...' . "\n"; return false; } if (isset($importedArray['version'])) { $version = $importedArray['version']; unset($importedArray['version']); } else { $version = ''; } //Check for version compliance if ($version && version_compare(AUTOMNE_VERSION, $version, '<')) { $infos .= 'Error: Automne version below the version of imported datas' . "\n"; return false; } if (isset($importedArray['language'])) { //force import language to overwrite user language because imported datas refer to this language $oldLanguage = $cms_language->getCode(); $cms_language = CMS_languagesCatalog::getByCode($importedArray['language']); if (!$cms_language || $cms_language->hasError()) { //reload user language $cms_language = CMS_languagesCatalog::getByCode($oldLanguage); } unset($importedArray['language']); } //return import description if exists if (isset($importedArray['description']) && $importedArray['description']) { $infos .= '--------------------------------------------------------------------------------------------------------' . "\n"; $infos .= 'Import description: ' . "\n"; $infos .= io::htmlspecialchars($importedArray['description']) . "\n"; $infos .= '--------------------------------------------------------------------------------------------------------' . "\n"; unset($importedArray['description']); } foreach ($importedArray as $type => $data) { switch ($type) { case 'modules': $idsRelation = array(); $importInfos = ''; if (CMS_modulesCatalog::fromArray($data, $this->_parameters, $cms_language, $idsRelation, $importInfos)) { $infos .= 'Import completed successfully' . ($importInfos ? ': ' . "\n" . $importInfos : '') . "\n"; } else { $infos .= 'Error: ' . "\n" . $importInfos . "\n"; $return &= false; } break; default: $infos .= 'Error: Unknown data type to import : ' . $type . "\n"; $return &= false; break; } } if (isset($importedArray['language'])) { //reload user language $cms_language = CMS_languagesCatalog::getByCode($oldLanguage); } return $return; }