Esempio n. 1
0
    /**
     * 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;
    }
Esempio n. 2
0
 public static function DOMElementToString($domelement, $contentOnly = false)
 {
     if (!is_a($domelement, "DOMElement")) {
         CMS_grandFather::raiseError('Domelement is not a DOMElement instance');
         return false;
     }
     static $autoClosedTagsList;
     if (!$autoClosedTagsList) {
         $xml2Array = new CMS_xml2Array();
         $tagsList = $xml2Array->getAutoClosedTagsList();
         $autoClosedTagsList = implode($tagsList, '|');
     }
     $output = '';
     if ($contentOnly) {
         $output = '';
         foreach ($domelement->childNodes as $node) {
             $output .= $node->ownerDocument->saveXML($node, LIBXML_NOEMPTYTAG);
         }
     } else {
         $output = $domNode->ownerDocument->saveXML($domNode, LIBXML_NOEMPTYTAG);
     }
     //convert output encoding if needed
     if (io::isUTF8($output)) {
         if (io::strtolower(APPLICATION_DEFAULT_ENCODING) != 'utf-8') {
             $output = utf8_decode($output);
         }
     } else {
         if (io::strtolower(APPLICATION_DEFAULT_ENCODING) == 'utf-8') {
             $output = utf8_encode($output);
         }
     }
     //to correct a bug in libXML < 2.6.27
     if (LIBXML_VERSION < 20627 && strpos($output, '&#x') !== false) {
         $output = preg_replace_callback('/(&#x[0-9A-Z]+;)/U', create_function('$matches', 'return io::decodeEntities($matches[0]);'), $output);
     }
     //replace tags like <br></br> by auto closed tags and strip cariage return arround entities
     $output = preg_replace(array('#\\n(&[a-z]+;)\\n#U', '#<(' . $autoClosedTagsList . ')([^>]*)></\\1>#U'), array('\\1', '<\\1\\2/>'), $output);
     return $output;
 }
Esempio n. 3
0
    /**
     * 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 '';
    }
Esempio n. 4
0
 /**
  * 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('&' => '&amp;');
                 //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('&' => '&amp;');
                 //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;
     }
 }
 /**
  * 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;
 }
Esempio n. 6
0
 /**
  * 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 .= '&amp;' . $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;
 }
Esempio n. 7
0
 /**
  * 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;
 }
 /**
  * Return a list of all pages (for atm-search tag)
  *
  * @param array $values : parameters values array(parameterName => parameterValue) in :
  * 	maxpages : the numer of pages
  *		currentpage : the current page number
  * @param multidimentionnal array $tags : xml2Array content of atm-function tag
  * 	<pages>...{n}...</pages>
  *		<currentpage>...{n}...</currentpage>
  * @return string : the page list
  * @access public
  * @static
  */
 static function pages($values, $tags)
 {
     if (!sensitiveIO::isPositiveInteger($values['maxpages'])) {
         //no pages to display so return
         return '';
     }
     $xml2Array = new CMS_xml2Array();
     $pagesPattern = $xml2Array->getXMLInTag($tags, 'pages');
     $currentPagePattern = $xml2Array->getXMLInTag($tags, 'currentpage');
     $startPagePattern = $xml2Array->getXMLInTag($tags, 'start');
     $endPagePattern = $xml2Array->getXMLInTag($tags, 'end');
     $nextPagePattern = $xml2Array->getXMLInTag($tags, 'next');
     $previousPagePattern = $xml2Array->getXMLInTag($tags, 'previous');
     /*if (!$pagesPattern) {
     			CMS_grandFather::raiseError("No 'pages' tag found or tag empty");
     			return false;
     		}*/
     if (!$currentPagePattern) {
         $currentPagePattern = $pagesPattern;
     }
     $return = '';
     //add start and previous content if any
     if ($values['currentpage'] != 1) {
         if ($startPagePattern) {
             $replace = array('{n}' => 1);
             $return .= str_replace(array_keys($replace), $replace, $startPagePattern);
         }
         if ($previousPagePattern) {
             $replace = array('{n}' => $values['currentpage'] - 1);
             $return .= str_replace(array_keys($replace), $replace, $previousPagePattern);
         }
     }
     //get pages to and from to loop on
     if (!isset($values['displayedpage']) || !sensitiveIO::isPositiveInteger($values['displayedpage'])) {
         $from = 1;
         $to = $values['maxpages'];
     } else {
         //remove current page
         $values['displayedpage'] = $values['displayedpage'] - 1;
         $half = round($values['displayedpage'] / 2);
         if ($values['currentpage'] - $half < 1) {
             $from = 1;
         } else {
             $from = $values['currentpage'] - $half;
         }
         if ($values['displayedpage'] + $from > $values['maxpages']) {
             $to = $values['maxpages'];
         } else {
             $to = $values['displayedpage'] + $from;
         }
         while ($to - $from < $values['displayedpage'] && $from > 1) {
             $from--;
         }
     }
     //loop on pages to display
     for ($i = $from; $i <= $to; $i++) {
         $replace = array('{n}' => $i);
         if ($i == $values['currentpage']) {
             $return .= str_replace(array_keys($replace), $replace, $currentPagePattern);
         } else {
             $return .= str_replace(array_keys($replace), $replace, $pagesPattern);
         }
     }
     //add next and end content if any
     if ($values['currentpage'] != $values['maxpages']) {
         if ($nextPagePattern) {
             $replace = array('{n}' => $values['currentpage'] + 1);
             $return .= str_replace(array_keys($replace), $replace, $nextPagePattern);
         }
         if ($endPagePattern) {
             $replace = array('{n}' => $values['maxpages']);
             $return .= str_replace(array_keys($replace), $replace, $endPagePattern);
         }
     }
     return $return;
 }
Esempio n. 9
0
 /**
  * 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;
 }