public function onContentPrepare($context, &$row, &$params, $page = 0) { $modifyTime = $row->modified; // pokud chybi XML deklarace, koncime if (substr($row->text, 0, 5) != '<?xml') { if (isset($_GET['debug'])) { echo "<font color=red>Xml declaration missing. Transformation terminated</font><br />"; echo "<pre>{$row->text}</pre>"; die; } return; } $GLOBALS['xml_path'] = $this->_xslts->getRoot() . DS; $rules = array(); $styles = array(); $key = 0; $pocet = 0; $config = $this->_magic->getListMagic(); foreach ($config as $rule) { $rule = trim($rule); if (!empty($rule)) { $pocet++; if ($pocet % 3 == 0) { $modified[] = $rule; } else { if (isXsltExt($rule)) { $styles[$key][] = $rule; } else { $key++; $rules[$key] = $rule; $styles[$key] = array(); } } } } $xml_result = $row->text; $xml = new DOMDocument(); $res = $xml->loadXML($xml_result); $xpath = new DOMXPath($xml); $found = false; $message = "no rule found"; $GLOBALS['xmlerrmsg'] = ''; $GLOBALS['xmlinfomsg'] = ''; $message .= $GLOBALS['xml_path']; set_error_handler('handle_xml_error'); foreach ($rules as $key => $rule) { if (!$found) { if (isXsdExt($rule)) { $GLOBALS['xmlinfomsg'] .= "Trying XSD schema <em>{$rule}</em>\n"; // zkusime validaci XML schmema if ($xml->schemaValidate($GLOBALS['xml_path'] . $rule)) { $GLOBALS['xmlinfomsg'] .= "Found XML schema <em>{$rule}</em>\n"; $found = true; $xml_result = applyTransformation($xml, $styles[$key], $modifyTime, $modified[$key - 1]); } } else { if (isRngExt($rule)) { $GLOBALS['xmlinfomsg'] .= "Trying RNG <em>{$rule}</em>\n"; // zkusime validaci relax NG if ($xml_document->relaxNGValidate($GLOBALS['xml_path'] . $rule)) { $GLOBALS['xmlinfomsg'] .= "Found RNG <em>{$rule}</em>\n"; $found = true; $xml_result = applyTransformation($xml, $styles[$key], $modifyTime, $modified[$key - 1]); } } else { $GLOBALS['xmlinfomsg'] .= "Trying XPATH <em>{$rule}</em>\n"; // zkusime XPATH 1.0 vyraz $result = $xpath->evaluate($rule); //if (($result!=false)&&(@$result->length>0)){ if (is_object($result) && $result->length > 0 || $result === true) { $GLOBALS['xmlinfomsg'] .= "Found XPATH <em>{$rule}</em>\n"; $found = true; $xml_result = applyTransformation($xml, $styles[$key], $modifyTime, $modified[$key - 1]); } } } } restore_error_handler(); $message = ""; /* if (get_parameter('xml_msg') && !$found){ $message .= "<strong style='color: white; background-color: red; font-weight: bold;padding: 2px;border-color: black; border-style: solid;'>".get_parameter('xml_msg')."</strong>"; } */ if (isset($_REQUEST['debug'])) { if (!$found) { $GLOBALS['xmlinfomsg'] .= "No transformation found"; } if (!empty($GLOBALS['xmlinfomsg'])) { $message .= "<fieldset><legend style='color: blue'>Transformation details</legend><ul><li>" . implode("</li><li>", explode("\n", trim($GLOBALS['xmlinfomsg']))) . "</li></ul></fieldset>"; } if (!empty($GLOBALS['xmlerrmsg'])) { $message .= "<fieldset><legend style='color: red'>Troubles occured :-(</legend><ul><li>" . implode("</li><li>", explode("\n", trim($GLOBALS['xmlerrmsg']))) . "</li></ul></fieldset>"; } } $row->text = $message . $xml_result; if (isset($_GET['yoy'])) { $row->text = substr($row->text, 0, $_GET['yoy']); } if (isset($_GET['die'])) { die($row->text); } } }
public function onPrepareContent(&$row, &$params, $page = 0) { // pokud chybi XML deklarace, koncime if (substr($row->text, 0, 5) != '<?xml') { if (isset($_GET['debug'])) { echo "<font color=red>Xml declaration missing. Transformation terminated</font><br />"; echo "<pre>{$row->text}</pre>"; die; } return; } $config = explode("\n", get_parameter('config')); $GLOBALS['xml_path'] = get_parameter('xml_path'); if (JPATH_BASE == JPATH_ADMINISTRATOR) { //zjistíme, jestli jsme v administraci a pokud ano, převedeme cestu na adresování frontendu $GLOBALS['xml_path'] = '../' . $GLOBALS['xml_path']; } $rules = array(); $styles = array(); $key = 0; foreach ($config as $rule) { $rule = trim($rule); if (!empty($rule)) { if (substr($rule, 0, 1) == "#") { //comment } else { if (isXsltExt($rule)) { $styles[$key][] = $rule; } else { $key++; $rules[$key] = $rule; $styles[$key] = array(); } } } } $xml_result = $row->text; $xml = new DOMDocument(); $xml->loadXML($row->text); $xpath = new DOMXPath($xml); $found = false; $message = "no rule found"; $GLOBALS['xmlerrmsg'] = ''; $GLOBALS['xmlinfomsg'] = ''; $message .= $GLOBALS['xml_path']; set_error_handler('handle_xml_error'); foreach ($rules as $key => $rule) { if (!$found) { if (isXsdExt($rule)) { $GLOBALS['xmlinfomsg'] .= "Trying XSD schema <em>{$rule}</em>\n"; // zkusime validaci XML schmema if ($xml->schemaValidate($GLOBALS['xml_path'] . $rule)) { $GLOBALS['xmlinfomsg'] .= "Found XML schema <em>{$rule}</em>\n"; $found = true; $xml_result = applyTransformation($xml, $styles[$key]); } } else { if (isRngExt($rule)) { $GLOBALS['xmlinfomsg'] .= "Trying RNG <em>{$rule}</em>\n"; // zkusime validaci relax NG if ($xml_document->relaxNGValidate($GLOBALS['xml_path'] . $rule)) { $GLOBALS['xmlinfomsg'] .= "Found RNG <em>{$rule}</em>\n"; $found = true; $xml_result = applyTransformation($xml, $styles[$key]); } } else { $GLOBALS['xmlinfomsg'] .= "Trying XPATH <em>{$rule}</em>\n"; // zkusime XPATH 1.0 vyraz $result = $xpath->evaluate($rule); if (!empty($result)) { $GLOBALS['xmlinfomsg'] .= "Found XPATH <em>{$rule}</em>\n"; $found = true; $xml_result = applyTransformation($xml, $styles[$key]); } } } } } restore_error_handler(); $message = ""; if (get_parameter('xml_msg') && !$found) { $message .= "<strong style='color: white; background-color: red; font-weight: bold;padding: 2px;border-color: black; border-style: solid;'>" . get_parameter('xml_msg') . "</strong>"; } if (isset($_REQUEST['debug'])) { if (!$found) { $GLOBALS['xmlinfomsg'] .= "No transformation found"; } if (!empty($GLOBALS['xmlinfomsg'])) { $message .= "<fieldset><legend style='color: blue'>Transformation details</legend><ul><li>" . implode("</li><li>", explode("\n", trim($GLOBALS['xmlinfomsg']))) . "</li></ul></fieldset>"; } if (!empty($GLOBALS['xmlerrmsg'])) { $message .= "<fieldset><legend style='color: red'>Troubles occured :-(</legend><ul><li>" . implode("</li><li>", explode("\n", trim($GLOBALS['xmlerrmsg']))) . "</li></ul></fieldset>"; } } $row->text = $message . $xml_result; if (isset($_GET['yoy'])) { $row->text = substr($row->text, 0, $_GET['yoy']); } if (isset($_GET['die'])) { die($row->text); } }