Ejemplo n.º 1
0
function XML_unserialize($xml)
{
    $xml_parser = new xml();
    $data = $xml_parser->parse($xml);
    $xml_parser->destruct();
    return $data;
}
Ejemplo n.º 2
0
 static function parse($node, $allow = null, $deny = null)
 {
     $find = array();
     $replace = array();
     foreach (self::$find as $n => $rule) {
         list($code, $expression) = $rule;
         $allowed = !$allow || $allow && in_array($code, $allow);
         $denied = $deny && in_array($code, $deny);
         if ($allowed && !$denied) {
             $find[] = $expression;
             $replace[] = self::$replace[$n];
         }
     }
     $xml = new xml();
     foreach ($node->children() as $child) {
         $xml->append($xml->import($child));
     }
     foreach ($xml->query('//text()') as $text) {
         $parent = $text->parent();
         $bbcode = preg_replace($find, $replace, $text->value());
         $bbcode = xml::parse("<?xml version=\"1.0\" encoding=\"utf-8\" ?><bbcode>{$bbcode}</bbcode>");
         foreach ($bbcode->query('/bbcode/* | /bbcode/text()') as $child) {
             $parent->insert($xml->import($child), $text);
         }
         $parent->remove($text);
     }
     return $xml;
 }
Ejemplo n.º 3
0
 private function to_xml($result)
 {
     switch ($this->content_type) {
         case 'xml':
             return xml::parse($result);
         case 'json':
             return xml::json($this->root[0], $result);
         default:
             runtime_error('Unknown HTTP procedure content type: ' . $this->content_type);
     }
 }
Ejemplo n.º 4
0
 public static function clean($xml, $allowed = FALSE, $debug = FALSE)
 {
     if (!($tree = xml::parse("<wrapper>{$xml}</wrapper>"))) {
         return FALSE;
     }
     if (!$allowed) {
         $allowed = array('a' => array('attributes' => array('href' => 'URL', 'title' => '/^([ \\-_a-zA-Z0-9\\.\\/\\!]+)$/')), 'img' => array('attributes' => array('src' => 'URL', 'title' => 'ANY', 'alt' => 'ANY')), 'b' => array('transform' => 'strong'), 'i' => array('transform' => 'em'), 'strong' => array(), 'em' => array(), 'p' => array());
     }
     if (is_array($tree)) {
         $tree = self::clean_childnodes($tree, $allowed);
         // If not in debug mode return XML
         if (!$debug) {
             return xml::build($tree);
         } else {
             return $tree;
         }
     } else {
         return FALSE;
     }
 }
Ejemplo n.º 5
0
        xml_set_object($this->parser, $this);
        xml_set_element_handler($this->parser, "tag_open", "tag_close");
        xml_set_character_data_handler($this->parser, "cdata");
    }
    function parse($data)
    {
        xml_parse($this->parser, $data);
    }
    function tag_open($parser, $tag, $attributes)
    {
        var_dump($parser, $tag, $attributes);
    }
    function cdata($parser, $cdata)
    {
        var_dump($parser, $cdata);
    }
    function tag_close($parser, $tag)
    {
        var_dump($parser, $tag);
    }
}
// end of class xml
$xml_parser = new xml();
$xml_parser->parse("<A ID='hallo'>PHP</A>");
?>
</pre>
<?php 
require_once '../../includes/footer.php';
?>

Ejemplo n.º 6
0
 function IPplanIPTemplate($name, $cust = 0, $netaddr = FALSE)
 {
     $filename = $this->__findtemp($name, $cust, $netaddr);
     if ($filename == FALSE) {
         return;
     }
     // suppress errors when loading file
     if (!($data = @file($filename))) {
         $this->error = TRUE;
         $this->errmsg = "Error reading template file";
         if (DEBUG) {
             echo $this->errmsg;
         }
         return;
     }
     $input = implode("", $data);
     require_once "../xmllib.php";
     $xml_parser = new xml("FIELD");
     if (!$xml_parser->parser) {
         $this->error = TRUE;
         $this->errmsg = "Error opening XML parser";
         if (DEBUG) {
             echo $this->errmsg;
         }
         return 1;
         // parser not initialized - XML probably not compiled in
     }
     $output = $xml_parser->parse($input);
     if (!$output) {
         $this->error = TRUE;
         $this->errmsg = "Error parsing XML file";
         if (DEBUG) {
             echo $this->errmsg;
         }
         return 1;
         // not XML format
     }
     // turn on line below for debugging
     //echo "<pre>"; var_dump($output); echo "</pre>";
     foreach ($output as $key => $value) {
         $field = $value["DEFINITION"]["NAME"];
         // field names must be alpha numeric with no spaces etc, else row is ignored!
         if (!empty($field) and preg_match("/^[a-zA-Z0-9]+\$/", $field)) {
             $this->userfld["{$field}"]["descrip"] = isset($value["DEFINITION"]["DESCRIP"]) ? $value["DEFINITION"]["DESCRIP"] : "Field: " . $field;
             // selectbox?
             if ($this->__selectbox($value, $field)) {
                 continue;
             }
             // checkbox?
             //else if ($this->__checkbox($value, $field)) {
             //    continue;
             //}
             // use default type of character - all bogus fields are converted to character
             $this->__character($value, $field);
         }
     }
     //echo "<pre>";var_dump($this->userfld);echo "</pre>";
     return;
 }
Ejemplo n.º 7
0
 private function xml($xml, $name, $value)
 {
     return $xml->import(xml::parse("<?xml version=\"1.0\" encoding=\"utf-8\" ?><{$name}>{$value}</{$name}>")->root());
 }
    /**********************************************************/
    /* Web service internals */
    /**********************************************************/
    function callService($methodCall)
    {
        // PHP 4 version requires PEAR
        //		require_once "HTTP/Request.php";
        //		$req =& new HTTP_Request($this->apiNode.'?apikey='.rawurlencode($this->apiKey).'&method='.$methodCall);
        //		$req->addHeader("User-Agent", $this->userAgent);
        //		$response = $req->sendRequest();
        try {
            $handle = fopen($this->apiNode . '?v=' . rawurlencode($this->version) . '&apikey=' . rawurlencode($this->apiKey) . '&method=' . $methodCall . '&cloudid=' . SITE_CLOUDID, "rb");
            $resp = stream_get_contents($handle);
            /*	PHP 4.x version
			$resp = '';
			while (!feof($handle)) {
			  $resp .= fread($handle, 8192);
			}
			*/
            fclose($handle);
        } catch (Exception $e) {
            echo 'Caught exception: ', $e->getMessage(), "\n";
            return false;
        }
        //		if (PEAR::isError($response)) {
        //			return FALSE;
        //		} else {
        // $resp=$req->getResponseBody();
        require_once 'xml.php';
        $xml_parser = new xml(false, true, true);
        $parsed_response = $xml_parser->parse($resp);
        $temp = new stdClass();
        if ($parsed_response['response']['result'] == 'ok') {
            $temp->result = true;
        } else {
            $temp->result = false;
            $temp->message = $parsed_response['response']['message'];
            $this->db->log('API error: ' . $methodCall . ' returned ' . $temp->message);
        }
        $temp->response = $parsed_response['response'];
        $this->final = array();
        $callback[] =& $this;
Ejemplo n.º 9
0
class xml
{
    var $parser;
    function xml()
    {
        $this->parser = xml_parser_create();
        xml_set_object($this->parser, $this);
        xml_set_element_handler($this->parser, 'tag_open', 'tag_close');
        xml_set_character_data_handler($this->parser, 'cdata');
    }
    function parse($data)
    {
        xml_parse($this->parser, $data);
    }
    function tag_open($parser, $tag, $attributes)
    {
        var_dump($tag, $attributes);
    }
    function cdata($parser, $cdata)
    {
        var_dump($cdata);
    }
    function tag_close($parser, $tag)
    {
        var_dump($tag);
    }
}
$xml_parser = new xml();
$xml_parser->parse('<A ID="hallo">PHP</A>');
Ejemplo n.º 10
0
 /**
  * Parses a string by a set of available methods
  *
  * Available methods:
  * - json
  * - xml
  * - url
  * - query
  * - php
  *
  * <code>
  *
  * str::parse('{"test":"cool","super":"genious"}');
  * // output: array(
  * //  'test' => 'cool',
  * //  'super' => 'genious'
  * // );
  *
  * str::parse('<xml><entries><cool>nice</cool></entries></xml>', 'xml');
  * // output: array(
  * //    'entries' => array(
  * //        'cool' => 'nice'
  * //    )
  * // );
  *
  * </code>
  *
  * @param  string  $string
  * @param  string  $mode
  * @return string
  */
 public static function parse($string, $mode = 'json')
 {
     if (is_array($string) or is_object($string)) {
         return $string;
     }
     switch ($mode) {
         case 'json':
             return (array) @json_decode($string, true);
             break;
         case 'xml':
             return xml::parse($string);
             break;
         case 'url':
             return (array) @parse_url($string);
             break;
         case 'php':
             return @unserialize($string);
             break;
         default:
             return $string;
             break;
     }
 }
Ejemplo n.º 11
0
$data = '<document>
   <bank name="Kazkommertsbank JSC">
      <customer name="John Cardholder" mail="*****@*****.**" phone="223322">
         <merchant cert_id="7269C18D00010000005E" name="Shop Name">
            <order order_id="000282" amount="3100" currency="398">
               <department merchant_id="90028101" amount="1300" rl=ASDFG" />
            </order>
         </merchant>
         <merchant_sign type="RSA/">
      </customer>
      <customer_sign type="SSL">
         4817C411000100000084
         </customer_sign>
      <results timestamp="2006-11-22 12:20:30 ">
         <payment merchant_id="90050801" amount="320.50" reference="109600746891" approval_code="730190" response_code="00" Secure="No" card_bin="KAZ" c_hash="6A2D7673A8EEF25A2C33D67CB5AAD091"/>
      </results>
   </bank>
   <bank_sign cert_id="14276668000100000028" type="SHA/RSA">
      JI3RZMEvexNlDmKsOQhe0pzHuKijnbhvnLu99qh7h+Ju8HvSfGNbEJxXUL58M94tXvu7w0BXSY7M
      HePGqz32JuMLAncuzyMwq845linW/sH/WvbZ+6SSYfxDMnvgX0S/pKxbhSXs7lGVBngXOwq7Bhsk
      8GcDUkWAM5UAsKpEKoI=
   </bank_sign>
</document>';
include "/home/majesty/projects/kolesa.kz/lib/kkb/kkb.utils.php";
$parser = new xml();
$result = $parser->parse($data);
var_dump($result);
if (in_array("DOCUMENT", $result)) {
    var_export(split_sign($data, "BANK"));
}
Ejemplo n.º 12
0
function returnParsedXMLPost($docURL, $postVars)
{
    $url = $docURL;
    $user_agent = "Mozilla/5.0 (Macintosh; U; PPC Mac OSX; en-us)";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars);
    $xmlResults = curl_exec($ch);
    curl_close($ch);
    $xml_parser = new xml(false, true, true);
    $parsed_response = $xml_parser->parse($xmlResults);
    return $parsed_response;
}