123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- <?php
- class Auth_Yadis_XMLParser {
-
- function init($xml_string, $namespace_map)
- {
- if (!$this->setXML($xml_string)) {
- return false;
- }
- foreach ($namespace_map as $prefix => $uri) {
- if (!$this->registerNamespace($prefix, $uri)) {
- return false;
- }
- }
- return true;
- }
-
- function registerNamespace($prefix, $uri)
- {
-
- }
-
- function setXML($xml_string)
- {
-
- }
-
- function &evalXPath($xpath, $node = null)
- {
-
- }
-
- function content($node)
- {
-
- }
-
- function attributes($node)
- {
-
- }
- }
- class Auth_Yadis_domxml extends Auth_Yadis_XMLParser {
- function Auth_Yadis_domxml()
- {
- $this->xml = null;
- $this->doc = null;
- $this->xpath = null;
- $this->errors = array();
- }
- function setXML($xml_string)
- {
- $this->xml = $xml_string;
- $this->doc = @domxml_open_mem($xml_string, DOMXML_LOAD_PARSING,
- $this->errors);
- if (!$this->doc) {
- return false;
- }
- $this->xpath = $this->doc->xpath_new_context();
- return true;
- }
- function registerNamespace($prefix, $uri)
- {
- return xpath_register_ns($this->xpath, $prefix, $uri);
- }
- function &evalXPath($xpath, $node = null)
- {
- if ($node) {
- $result = @$this->xpath->xpath_eval($xpath, $node);
- } else {
- $result = @$this->xpath->xpath_eval($xpath);
- }
- if (!$result) {
- $n = array();
- return $n;
- }
- if (!$result->nodeset) {
- $n = array();
- return $n;
- }
- return $result->nodeset;
- }
- function content($node)
- {
- if ($node) {
- return $node->get_content();
- }
- }
- function attributes($node)
- {
- if ($node) {
- $arr = $node->attributes();
- $result = array();
- if ($arr) {
- foreach ($arr as $attrnode) {
- $result[$attrnode->name] = $attrnode->value;
- }
- }
- return $result;
- }
- }
- }
- class Auth_Yadis_dom extends Auth_Yadis_XMLParser {
- function Auth_Yadis_dom()
- {
- $this->xml = null;
- $this->doc = null;
- $this->xpath = null;
- $this->errors = array();
- }
- function setXML($xml_string)
- {
- $this->xml = $xml_string;
- $this->doc = new DOMDocument;
- if (!$this->doc) {
- return false;
- }
-
- if (function_exists('libxml_disable_entity_loader') && function_exists('libxml_use_internal_errors')) {
-
- $loader = libxml_disable_entity_loader(true);
- $errors = libxml_use_internal_errors(true);
- $parse_result = @$this->doc->loadXML($xml_string);
- libxml_disable_entity_loader($loader);
- libxml_use_internal_errors($errors);
- } else {
- $parse_result = @$this->doc->loadXML($xml_string);
- }
- if (!$parse_result) {
- return false;
- }
- $this->xpath = new DOMXPath($this->doc);
- if ($this->xpath) {
- return true;
- } else {
- return false;
- }
- }
- function registerNamespace($prefix, $uri)
- {
- return $this->xpath->registerNamespace($prefix, $uri);
- }
- function &evalXPath($xpath, $node = null)
- {
- if ($node) {
- $result = @$this->xpath->query($xpath, $node);
- } else {
- $result = @$this->xpath->query($xpath);
- }
- $n = array();
- if (!$result) {
- return $n;
- }
- for ($i = 0; $i < $result->length; $i++) {
- $n[] = $result->item($i);
- }
- return $n;
- }
- function content($node)
- {
- if ($node) {
- return $node->textContent;
- }
- }
- function attributes($node)
- {
- if ($node) {
- $arr = $node->attributes;
- $result = array();
- if ($arr) {
- for ($i = 0; $i < $arr->length; $i++) {
- $node = $arr->item($i);
- $result[$node->nodeName] = $node->nodeValue;
- }
- }
- return $result;
- }
- }
- }
- global $__Auth_Yadis_defaultParser;
- $__Auth_Yadis_defaultParser = null;
- function Auth_Yadis_setDefaultParser($parser)
- {
- global $__Auth_Yadis_defaultParser;
- $__Auth_Yadis_defaultParser = $parser;
- }
- function Auth_Yadis_getSupportedExtensions()
- {
- return array('dom' => 'Auth_Yadis_dom',
- 'domxml' => 'Auth_Yadis_domxml');
- }
- function Auth_Yadis_getXMLParser()
- {
- global $__Auth_Yadis_defaultParser;
-
- if (isset($__Auth_Yadis_defaultParser)) {
- return $__Auth_Yadis_defaultParser;
- }
-
- foreach(Auth_Yadis_getSupportedExtensions() as $extension => $classname)
- {
- if (extension_loaded($extension))
- {
- $p = new $classname();
- Auth_Yadis_setDefaultParser($p);
- return $p;
- }
- }
-
- return false;
- }
|