/** * Gets a tag representation instance * * @param CMS_XMLTag $tag The xml tag from which to build the representation * @param array(mixed) $args The arguments needed to build * @return object The module tag representation instance * @access public */ function getTagRepresentation($tag, $args) { switch ($tag->getName()) { case "atm-clientspace": if ($tag->getAttribute("type")) { $clientSpaceClassName = 'CMS_moduleClientspace_' . $this->getCodename(); $instance = new $clientSpaceClassName($tag->getAttributes()); return $instance; } else { return false; } break; } }
/** * Constructor. * * @param string $name The name of the tag * @param array(string) $attributes The tag attributes. * @return void * @access public */ function __construct($name, $attributes, $children, $parameters) { if (isset($parameters['context']) && $parameters['context']) { $this->_context = $parameters['context']; } parent::__construct($name, $attributes, $children, $parameters); }
/** * Test to see if a page passes the condition * * @param CMS_page $page The parsed page : the one which contains the linx tag * @param CMS_page $page The page to test * @param boolean $publicTree Is the test conducted inside the public or edited tree ? * @param integer $rank The rank of the page in the pre-condition targets * @return boolean true if the page passes the condition, false otherwise * @access public */ function pagePasses(&$parsedPage, &$page, $publicTree, $rank) { //set the condition value if ($this->_valueIsScalar) { $condition_value = $this->_valueScalar; } else { $condition_target = $this->_valueNodespec->getTarget($parsedPage, $publicTree); $condition_value = $this->_getPageProperty($condition_target, $this->_valueNodespecProperty, $publicTree); } if (is_null($condition_value)) { return false; } //build the body of the test function if ($this->_pageProperty == "rank") { $func_body = sprintf('return (\'%s\' %s \'%s\');', $rank, $this->_operator, $condition_value); } else { $page_value = $this->_getPageProperty($page, $this->_pageProperty, $publicTree); if (is_null($page_value)) { return false; } $func_body = sprintf('return (\'%s\' %s \'%s\');', $page_value, $this->_operator, $condition_value); } $func = @create_function('', $func_body); if (!$func) { return false; } return @$func(); }
/** * Constructor. * * @param string $name The name of the tag * @param array(string) $attributes The tag attributes. * @return void * @access public */ function __construct($name, $attributes, $children, $parameters) { parent::__construct($name, $attributes, $children, $parameters); //check tags requirements if (!$this->checkTagRequirements(array('for' => 'alphanum'))) { return; } }
/** * Constructor. * * @param string $name The name of the tag * @param array(string) $attributes The tag attributes. * @return void * @access public */ function __construct($name, $attributes, $children, $parameters) { parent::__construct($name, $attributes, $children, $parameters); //check tags requirements if (!$this->checkTagRequirements(array('varname' => 'alphanum', 'vartype' => 'request|session|var'))) { return; } }
/** * Gets a tag representation instance * * @param CMS_XMLTag $tag The xml tag from which to build the representation * @param array(mixed) $args The arguments needed to build * @return object The module tag representation instance * @access public */ function getTagRepresentation($tag, $args) { switch ($tag->getName()) { case "block": //try to guess the class to instanciate $class_name = "CMS_block_cms_forms"; if (class_exists($class_name)) { $instance = new $class_name(); } else { $this->raiseError("Unknown block type : CMS_block_cms_forms"); return false; } $instance->initializeFromTag($tag->getAttributes(), $tag->getInnerContent()); return $instance; break; case "atm-clientspace": if ($tag->getAttribute("type")) { $instance = new CMS_moduleClientspace($tag->getAttributes()); return $instance; } else { return false; } break; } }
/** * Constructor. * * @param string $name The name of the tag * @param array(string) $attributes The tag attributes. * @return void * @access public */ function __construct($name, $attributes, $children, $parameters) { parent::__construct($name, $attributes, $children, $parameters); //check tags requirements if (!$this->checkTagRequirements(array('what' => true))) { return; } if (isset($this->_attributes['name']) && $this->_attributes['name']) { if (!$this->checkTagRequirements(array('name' => 'alphanum'))) { return; } } }
/** * Constructor. * * @param string $name The name of the tag * @param array(string) $attributes The tag attributes. * @return void * @access public */ function __construct($name, $attributes, $children, $parameters) { parent::__construct($name, $attributes, $children, $parameters); //check tags requirements if (!$this->checkTagRequirements(array('url' => 'alphanum'))) { return; } if (isset($this->_attributes['type']) && $this->_attributes['type']) { if (!$this->checkTagRequirements(array('type' => 'alphanum', 'vartype' => '301|302'))) { 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 ''; }
/** * Compute an atm-object-link tag * * @param array $tag : the reference atm-object-link tag to compute * @return string the PHP / HTML content computed * @access private */ protected function _linkObject(&$tag) { if (!$this->checkTagRequirements($tag, array('field' => 'field', 'objectId' => true))) { return; } $uniqueID = CMS_XMLTag::getUniqueID(); $return = ' //OBJECT-LINK TAG START ' . $uniqueID . ' $error_' . $uniqueID . ' = false; if (strtolower(get_class("' . $tag['attributes']['field'] . '")) != \'cms_multi_poly_object\') { CMS_grandFather::raiseError("Malformed atm-object-link tag : field attribute must be a valid multi object field"); $error_' . $uniqueID . ' = true; } if (!io::isPositiveInteger("' . $tag['attributes']['objectId'] . '")) { CMS_grandFather::raiseError("Malformed atm-object-link tag : objectId attribute must be a valid object Id : ' . $tag['attributes']['objectId'] . '"); $error_' . $uniqueID . ' = true; } //load object to add $object_' . $uniqueID . ' = CMS_poly_object_catalog::getObjectByID("' . $tag['attributes']['objectId'] . '"); if (!is_object($object_' . $uniqueID . ') || $object_' . $uniqueID . '->hasError() || !$object_' . $uniqueID . '->getID()) { CMS_grandFather::raiseError("Malformed atm-object-link tag : objectId attribute must be a valid object Id : ' . $tag['attributes']['objectId'] . '"); $error_' . $uniqueID . ' = true; } //check object type and field object type if (!$error_' . $uniqueID . ' && "' . $tag['attributes']['field'] . '"->getObjectID() != $object_' . $uniqueID . '->getObjectID()) { CMS_grandFather::raiseError("Malformed atm-object-link tag : field object type ("."' . $tag['attributes']['field'] . '"->getObjectID().") and objectId type (".$object_' . $uniqueID . '->getObjectID().") does not match ..."); $error_' . $uniqueID . ' = true; } //if no error append object into field ids if (!$error_' . $uniqueID . ') { $ids_' . $uniqueID . ' = "' . $tag['attributes']['field'] . '"->getValue(\'ids\'); //$ids_' . $uniqueID . '[$object_' . $uniqueID . '->getID()] = $object_' . $uniqueID . '->getID(); array_unshift($ids_' . $uniqueID . ', $object_' . $uniqueID . '->getID()); "' . $tag['attributes']['field'] . '"->setValues(array(\'list\'."' . $tag['attributes']['field'] . '"->getValue(\'fieldID\').\'_0\' => implode(\';\', $ids_' . $uniqueID . ')), \'\'); $object[CMS_poly_object_catalog::getObjectIDForField("' . $tag['attributes']['field'] . '"->getValue(\'fieldID\'))]->writeToPersistence(); unset($ids_' . $uniqueID . '); } else { return false; } unset($error_' . $uniqueID . '); unset($object_' . $uniqueID . '); //OBJECT-LINK TAG END ' . $uniqueID . ' '; return $return; }
/** * Constructor. * initializes the linx. * * @param string $type The linx type * @param string $tagContent The tag content. * @param CMS_page $page The page we're parsing * @param boolean $publicTree Does the linx must be calculated in the public or edited tree ? * @return void * @access public */ function __construct($type, $tagContent, $page, $publicTree = false, $args = array()) { if (!SensitiveIO::isInSet($type, CMS_linxesCatalog::getAllTypes())) { $this->raiseError("Constructor has an unknown type : " . $type); return; } elseif (!is_a($page, "CMS_page")) { $this->raiseError("Constructor was not given a valid CMS_page"); return; } else { $this->_args = $args; $this->_type = $type; //Hack for shorthand writing of atm-linx //<atm-linx type="direct" node="pageID"> ... </atm-linx> //<atm-linx type="direct" codename="pageCodename"> ... </atm-linx> if ((isset($this->_args['node']) || isset($this->_args['codename'])) && $this->_type == 'direct') { $tag = new CMS_XMLTag('atm-linx', $this->_args); $tag->setTextContent($tagContent); $tagContent = '<atm-linx type="direct">' . '<selection ' . (isset($this->_args['crosswebsite']) ? ' crosswebsite="' . $this->_args['crosswebsite'] . '"' : '') . '>'; if (isset($this->_args['node'])) { $tagContent .= '<start><nodespec type="node" value="' . $this->_args['node'] . '" /></start>'; //remove useless node argument unset($this->_args['node']); } else { $tagContent .= '<start><nodespec type="codename" value="' . $this->_args['codename'] . '" /></start>'; //remove useless node argument unset($this->_args['codename']); } $tagContent .= '</selection>' . '<display>' . '<htmltemplate>' . $tag->getInnerContent() . '</htmltemplate>' . '</display>' . '</atm-linx>'; } $this->_page = $page; $this->_publicTree = $publicTree; $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML($tagContent); } catch (DOMException $e) { $this->raiseError('Malformed atm-linx content in page ' . $page->getID() . ' : ' . $e->getMessage() . "\n" . $tagContent, true); return false; } $selections = $domdocument->getElementsByTagName('selection'); if ($selections->length > 0) { $selection = $selections->item(0); //parse the selection for nodespecs and condition if (!$this->_parseSelection($selection)) { $this->raiseError(); return; } } $noselections = $domdocument->getElementsByTagName('noselection'); if ($noselections->length > 0) { $this->_noselection = $noselections->item(0); } $displays = $domdocument->getElementsByTagName('display'); //get the displays objects $unsortedDisplays = array(); foreach ($displays as $display) { $unsortedDisplays[] = new CMS_linxDisplay($display); } //put the default display (the one with no condition) at the end of the array $default = false; foreach ($unsortedDisplays as $dsp) { if ($dsp->hasCondition() && !$default) { $this->_displays[] = $dsp; } else { $default = $dsp; } } if ($default) { $this->_displays[] = $default; } } }
function toXML(&$definition, $part = false, $replaceVars = false) { //return back xml $result = ""; if (!$definition && is_object($this)) { $definition = $this->_arrOutput; } if (!$definition) { parent::raiseError("No definition found"); return ''; } $c = 0; while (isset($definition[$c])) { //assign node value if (isset($definition[$c]["textnode"])) { //replacements on text nodes if ($replaceVars) { $dummyTag = new CMS_XMLTag('html', array(), array(), array('context' => CMS_XMLTag::HTML_CONTEXT)); $result .= $dummyTag->replaceVars((string) $definition[$c]["textnode"]); } else { $result .= (string) $definition[$c]["textnode"]; } } elseif (isset($definition[$c]["phpnode"])) { //replacements on text nodes if ($replaceVars) { $dummyTag = new CMS_XMLTag('html', array(), array(), array('context' => CMS_XMLTag::HTML_TAG_CONTEXT)); $result .= '<?php ' . $dummyTag->replaceVars($definition[$c]["phpnode"]) . ' ?>'; } else { $result .= '<?php ' . $definition[$c]["phpnode"] . ' ?>'; } } else { $autoclosed = in_array($definition[$c]["nodename"], CMS_xml2Array::$autoClosedTagsList) || substr($definition[$c]["nodename"], 0, 3) == 'atm' && !isset($definition[$c]["childrens"]); if (!$part || $part == self::ARRAY2XML_START_TAG) { $tagOpening = '<' . $definition[$c]["nodename"]; if (is_array($definition[$c]["attributes"])) { while (list($key, $value) = each($definition[$c]["attributes"])) { $tagOpening .= ' ' . $key . '="' . $value . '"'; } } $tagOpening .= $autoclosed ? ' />' : '>'; $tagOpenReplaced = false; if ($replaceVars) { $dummyTag = new CMS_XMLTag('html', array(), array(), array('context' => CMS_XMLTag::HTML_TAG_CONTEXT)); $prepared = addcslashes($tagOpening, '"'); $replaced = $dummyTag->replaceVars($prepared); if ($replaced != $prepared) { $tagOpening = '<?php echo "' . $replaced . '"; ?>'; $tagOpenReplaced = true; } } $result .= $tagOpening; } if (!$part) { if (isset($definition[$c]["childrens"])) { $result .= $this->toXML($definition[$c]["childrens"], $part); } } if ((!$part || $part == self::ARRAY2XML_END_TAG) && !$autoclosed) { $tagClose = '</' . $definition[$c]["nodename"] . '>'; if (isset($tagOpenReplaced) && $tagOpenReplaced) { $tagClose = '<?php echo "' . $tagClose . '"; ?>'; } $result .= $tagClose; } } $c++; } return $result; }
/** * Gets a tag representation instance * * @param CMS_XMLTag $tag The xml tag from which to build the representation * @param array(mixed) $args The arguments needed to build * @return object The module tag representation instance * @access public */ function getTagRepresentation($tag, $args) { switch ($tag->getName()) { case "block": //try to guess the class to instanciate $class_name = "CMS_block_polymod"; if (class_exists($class_name)) { $instance = new $class_name(); } else { $this->raiseError("Unknown block type : CMS_block_polymod"); return false; } //pr(io::htmlspecialchars($tag->getInnerContent())); $instance->initializeFromTag($tag->getAttributes(), $tag->getInnerContent()); return $instance; break; } }
/** * 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; }
/** * Gets a tag representation instance * * @param CMS_XMLTag $tag The xml tag from which to build the representation * @param array(mixed) $args The arguments needed to build * @return object The module tag representation instance * @access public */ function getTagRepresentation($tag, $args) { switch ($tag->getName()) { case "atm-clientspace": if ($args["template"] && $tag->getAttribute("id")) { $args["editedMode"] = isset($args["editedMode"]) ? $args["editedMode"] : null; $instance = new CMS_moduleClientspace_standard($args["template"], $tag->getAttribute("id"), $args["editedMode"]); return $instance; } else { return false; } break; case "block": if ($tag->getAttribute("type")) { //try to guess the class to instanciate $class_name = "CMS_block_" . $tag->getAttribute("type"); if (class_exists($class_name)) { $instance = new $class_name(); } else { //not found. Place here block types requiring special attention switch ($tag->getAttribute("type")) { default: $this->raiseError("Unknown block type : " . $tag->getAttribute("type")); return false; break; } } $instance->initializeFromTag($tag->getAttributes(), $tag->getInnerContent()); return $instance; } else { return false; } break; } }