Example #1
0
 /**
  * Creates a XML_CSSML error object, extending the PEAR_Error class
  *
  * @param int   $code the xpath error code
  * @param int   $mode (optional) the reaction either return, die or trigger/callback
  * @param int   $level (optional) intensity of the error (PHP error code)
  * @param mixed $debuginfo (optional) information that can inform user as to nature of error
  *
  * @access private
  */
 function XML_CSSML_Error($code = XML_CSSML_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null)
 {
     if (is_int($code)) {
         $this->PEAR_Error(XML_CSSML::errorMessage($code), $code, $mode, $level, $debuginfo);
     } else {
         $this->PEAR_Error("Invalid error code: {$code}", XML_CSSML_ERROR, $mode, $level, $debuginfo);
     }
 }
 function load($in_CSSML, $in_type = 'string')
 {
     if (parent::isError($load = parent::load())) {
         return $load;
     }
     if ($in_type == 'file' && @file_exists($in_CSSML)) {
         $this->CSSMLDoc = $in_CSSML;
     } elseif ($in_type == 'string' && is_string($in_CSSML)) {
         $this->CSSMLDoc = 'arg:/_xml';
         $this->arguments = array('/_xml' => $in_CSSML);
     } else {
         return PEAR::raiseError(null, XML_CSSML_INVALID_DATA, null, E_USER_WARNING, "Request data: {$in_CSSML}", 'XML_CSSML_Error', true);
     }
     $this->loaded = true;
 }
 function load($in_CSSML, $in_type = 'string')
 {
     if (parent::isError($load = parent::load())) {
         return $load;
     }
     // If the CSSML data is already a DOM object (can tell by checking for root)
     if ($in_type == 'object' && get_class($in_CSSML) == 'DomDocument') {
         $this->CSSMLDoc = $in_CSSML;
     } elseif ($in_type == 'file' && @file_exists($in_CSSML)) {
         $this->CSSMLDoc = domxml_open_file($in_CSSML);
     } elseif ($in_type == 'string' && is_string($in_CSSML)) {
         $this->CSSMLDoc = domxml_open_mem($in_CSSML);
     } else {
         return PEAR::raiseError(null, XML_CSSML_INVALID_DATA, null, E_USER_WARNING, "Request data: {$in_CSSML}", 'XML_CSSML_Error', true);
     }
     if (get_class($this->CSSMLDoc) != 'DomDocument') {
         return PEAR::raiseError(null, XML_CSSML_INVALID_DOCUMENT, null, E_USER_WARNING, "Request data: {$in_CSSML}", 'XML_CSSML_Error', true);
     }
     $this->loaded = true;
 }
Example #4
0
<?php

require_once '../CSSML.php';
error_reporting(E_ALL);
$cssml = '<cssml:CSSML xmlns:cssml="http://pear.php.net/cssml/1.0">
  <style browserInclude="not(gecko)" filterInclude="admin">
    <selector>p</selector>
    <declaration property="color">text</declaration>
  </style>
</cssml:CSSML>';
$cssml = new XML_CSSML('libxslt', $cssml, 'string', array('browser' => 'ns4', 'filter' => 'admin', 'comment' => 'hello there!', 'output' => 'foo.css'));
//print_r($cssml);
//echo $cssml->process();
$cssml->process();
 /**
  * Return a textual error message for an XML_CSSML error code.
  *
  * @param  int $in_value error code
  *
  * @access public
  * @return string error message, or false if not error code
  */
 function errorMessage($in_value)
 {
     // make the variable static so that it only has to do the defining on the first call
     static $errorMessages;
     // define the varies error messages
     if (!isset($errorMessages)) {
         $errorMessages = array(XML_CSSML_OK => 'no error', XML_CSSML_ERROR => 'unknown error', XML_CSSML_ALREADY_EXISTS => 'cssml document already loaded', XML_CSSML_NOT_LOADED => 'cssml document has not been loaded', XML_CSSML_INVALID_DATA => 'invalid cssml data to parse', XML_CSSML_INVALID_DOCUMENT => 'cssml domdocument could not be created', XML_CSSML_INVALID_FILE => 'output file does not exist');
     }
     // If this is an error object, then grab the corresponding error code
     if (XML_CSSML::isError($in_value)) {
         $in_value = $in_value->getCode();
     }
     // return the textual error message corresponding to the code
     return isset($errorMessages[$in_value]) ? $errorMessages[$in_value] : $errorMessages[XML_CSSML_ERROR];
 }