• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/openid/Services/Yadis/XML.php

Go to the documentation of this file.
00001 <?php
00002 
00021 class Services_Yadis_XMLParser {
00033     function init($xml_string, $namespace_map)
00034     {
00035         if (!$this->setXML($xml_string)) {
00036             return false;
00037         }
00038 
00039         foreach ($namespace_map as $prefix => $uri) {
00040             if (!$this->registerNamespace($prefix, $uri)) {
00041                 return false;
00042             }
00043         }
00044 
00045         return true;
00046     }
00047 
00061     function registerNamespace($prefix, $uri)
00062     {
00063         // Not implemented.
00064     }
00065 
00076     function setXML($xml_string)
00077     {
00078         // Not implemented.
00079     }
00080 
00094     function evalXPath($xpath, $node = null)
00095     {
00096         // Not implemented.
00097     }
00098 
00107     function content($node)
00108     {
00109         // Not implemented.
00110     }
00111 
00121     function attributes($node)
00122     {
00123         // Not implemented.
00124     }
00125 }
00126 
00136 class Services_Yadis_domxml extends Services_Yadis_XMLParser {
00137     function Services_Yadis_domxml()
00138     {
00139         $this->xml = null;
00140         $this->doc = null;
00141         $this->xpath = null;
00142         $this->errors = array();
00143     }
00144 
00145     function setXML($xml_string)
00146     {
00147         $this->xml = $xml_string;
00148         $this->doc = @domxml_open_mem($xml_string, DOMXML_LOAD_PARSING,
00149                                       $this->errors);
00150 
00151         if (!$this->doc) {
00152             return false;
00153         }
00154 
00155         $this->xpath = $this->doc->xpath_new_context();
00156 
00157         return true;
00158     }
00159 
00160     function registerNamespace($prefix, $uri)
00161     {
00162         return xpath_register_ns($this->xpath, $prefix, $uri);
00163     }
00164 
00165     function &evalXPath($xpath, $node = null)
00166     {
00167         if ($node) {
00168             $result = @$this->xpath->xpath_eval($xpath, $node);
00169         } else {
00170             $result = @$this->xpath->xpath_eval($xpath);
00171         }
00172 
00173         if (!$result->nodeset) {
00174             $n = array();
00175             return $n;
00176         }
00177 
00178         return $result->nodeset;
00179     }
00180 
00181     function content($node)
00182     {
00183         if ($node) {
00184             return $node->get_content();
00185         }
00186     }
00187 
00188     function attributes($node)
00189     {
00190         if ($node) {
00191             $arr = $node->attributes();
00192             $result = array();
00193 
00194             if ($arr) {
00195                 foreach ($arr as $attrnode) {
00196                     $result[$attrnode->name] = $attrnode->value;
00197                 }
00198             }
00199 
00200             return $result;
00201         }
00202     }
00203 }
00204 
00214 class Services_Yadis_dom extends Services_Yadis_XMLParser {
00215     function Services_Yadis_dom()
00216     {
00217         $this->xml = null;
00218         $this->doc = null;
00219         $this->xpath = null;
00220         $this->errors = array();
00221     }
00222 
00223     function setXML($xml_string)
00224     {
00225         $this->xml = $xml_string;
00226         $this->doc = new DOMDocument;
00227 
00228         if (!$this->doc) {
00229             return false;
00230         }
00231 
00232         if (!@$this->doc->loadXML($xml_string)) {
00233             return false;
00234         }
00235 
00236         $this->xpath = new DOMXPath($this->doc);
00237 
00238         if ($this->xpath) {
00239             return true;
00240         } else {
00241             return false;
00242         }
00243     }
00244 
00245     function registerNamespace($prefix, $uri)
00246     {
00247         return $this->xpath->registerNamespace($prefix, $uri);
00248     }
00249 
00250     function &evalXPath($xpath, $node = null)
00251     {
00252         if ($node) {
00253             $result = @$this->xpath->evaluate($xpath, $node);
00254         } else {
00255             $result = @$this->xpath->evaluate($xpath);
00256         }
00257 
00258         $n = array();
00259 
00260         for ($i = 0; $i < $result->length; $i++) {
00261             $n[] = $result->item($i);
00262         }
00263 
00264         return $n;
00265     }
00266 
00267     function content($node)
00268     {
00269         if ($node) {
00270             return $node->textContent;
00271         }
00272     }
00273 
00274     function attributes($node)
00275     {
00276         if ($node) {
00277             $arr = $node->attributes;
00278             $result = array();
00279 
00280             if ($arr) {
00281                 for ($i = 0; $i < $arr->length; $i++) {
00282                     $node = $arr->item($i);
00283                     $result[$node->nodeName] = $node->nodeValue;
00284                 }
00285             }
00286 
00287             return $result;
00288         }
00289     }
00290 }
00291 
00292 $__Services_Yadis_defaultParser = null;
00293 
00303 function Services_Yadis_setDefaultParser(&$parser)
00304 {
00305     global $__Services_Yadis_defaultParser;
00306     $__Services_Yadis_defaultParser =& $parser;
00307 }
00308 
00309 $__Services_Yadis_xml_extensions = array(
00310     'dom' => 'Services_Yadis_dom',
00311     'domxml' => 'Services_Yadis_domxml'
00312     );
00313 
00320 function &Services_Yadis_getXMLParser()
00321 {
00322     global $__Services_Yadis_defaultParser,
00323         $__Services_Yadis_xml_extensions;
00324 
00325     if ($__Services_Yadis_defaultParser) {
00326         return $__Services_Yadis_defaultParser;
00327     }
00328 
00329     $p = null;
00330 
00331     // Return a wrapper for the resident implementation, if any.
00332     foreach ($__Services_Yadis_xml_extensions as $name => $cls) {
00333         if (extension_loaded($name) ||
00334             @dl($name . '.so')) {
00335             // First create a dummy variable because PHP doesn't let
00336             // you return things by reference unless they're
00337             // variables.  Feh.
00338             $p = new $cls();
00339             return $p;
00340         }
00341     }
00342 
00343     return null;
00344 }
00345 
00346 ?>

Generated on Sun Jan 2 2011 04:55:32 for Pragyan CMS by  doxygen 1.7.1