]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/extlib/CAS/domxml-php4-php5.php
Update line endings
[quix0rs-gnu-social.git] / plugins / CasAuthentication / extlib / CAS / domxml-php4-php5.php
1 <?php
2 /**
3  * @file domxml-php4-php5.php
4  * Require PHP5, uses built-in DOM extension.
5  * To be used in PHP4 scripts using DOMXML extension.
6  * Allows PHP4/DOMXML scripts to run on PHP5/DOM.
7  * (Requires PHP5/XSL extension for domxml_xslt functions)
8  *
9  * Typical use:
10  * <pre>
11  * {
12  *  if (version_compare(PHP_VERSION,'5','>='))
13  *   require_once('domxml-php4-to-php5.php');
14  * }
15  * </pre>
16  *
17  * Version 1.5.5, 2005-01-18, http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/
18  *
19  * ------------------------------------------------------------------<br>
20  * Written by Alexandre Alapetite, http://alexandre.alapetite.net/cv/
21  *
22  * Copyright 2004, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR),
23  * http://creativecommons.org/licenses/by-sa/2.0/fr/
24  * http://alexandre.alapetite.net/divers/apropos/#by-sa
25  * - Attribution. You must give the original author credit
26  * - Share Alike. If you alter, transform, or build upon this work,
27  *   you may distribute the resulting work only under a license identical to this one
28  * - The French law is authoritative
29  * - Any of these conditions can be waived if you get permission from Alexandre Alapetite
30  * - Please send to Alexandre Alapetite the modifications you make,
31  *   in order to improve this file for the benefit of everybody
32  *
33  * If you want to distribute this code, please do it as a link to:
34  * http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/
35  */
36
37 function domxml_new_doc($version) {return new php4DOMDocument('');}
38 function domxml_open_file($filename) {return new php4DOMDocument($filename);}
39 function domxml_open_mem($str)
40 {
41  $dom=new php4DOMDocument('');
42  $dom->myDOMNode->loadXML($str);
43  return $dom;
44 }
45 function xpath_eval($xpath_context,$eval_str,$contextnode=null) {return $xpath_context->query($eval_str,$contextnode);}
46 function xpath_new_context($dom_document) {return new php4DOMXPath($dom_document);}
47
48 class php4DOMAttr extends php4DOMNode
49 {
50  function php4DOMAttr($aDOMAttr) {$this->myDOMNode=$aDOMAttr;}
51  function Name() {return $this->myDOMNode->name;}
52  function Specified() {return $this->myDOMNode->specified;}
53  function Value() {return $this->myDOMNode->value;}
54 }
55
56 class php4DOMDocument extends php4DOMNode
57 {
58  function php4DOMDocument($filename='')
59  {
60   $this->myDOMNode=new DOMDocument();
61   if ($filename!='') $this->myDOMNode->load($filename);
62  }
63  function create_attribute($name,$value)
64  {
65   $myAttr=$this->myDOMNode->createAttribute($name);
66   $myAttr->value=$value;
67   return new php4DOMAttr($myAttr,$this);
68  }
69  function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);}
70  function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);}
71  function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);}
72  function create_text_node($content) {return new php4DOMNode($this->myDOMNode->createTextNode($content),$this);}
73  function document_element() {return new php4DOMElement($this->myDOMNode->documentElement,$this);}
74  function dump_file($filename,$compressionmode=false,$format=false) {return $this->myDOMNode->save($filename);}
75  function dump_mem($format=false,$encoding=false) {return $this->myDOMNode->saveXML();}
76  function get_element_by_id($id) {return new php4DOMElement($this->myDOMNode->getElementById($id),$this);}
77  function get_elements_by_tagname($name)
78  {
79   $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
80   $nodeSet=array();
81   $i=0;
82   if (isset($myDOMNodeList))
83    while ($node=$myDOMNodeList->item($i))
84    {
85     $nodeSet[]=new php4DOMElement($node,$this);
86     $i++;
87    }
88   return $nodeSet;
89  }
90  function html_dump_mem() {return $this->myDOMNode->saveHTML();}
91  function root() {return new php4DOMElement($this->myDOMNode->documentElement,$this);}
92 }
93
94 class php4DOMElement extends php4DOMNode
95 {
96  function get_attribute($name) {return $this->myDOMNode->getAttribute($name);}
97  function get_elements_by_tagname($name)
98  {
99   $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
100   $nodeSet=array();
101   $i=0;
102   if (isset($myDOMNodeList))
103    while ($node=$myDOMNodeList->item($i))
104    {
105     $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
106     $i++;
107    }
108   return $nodeSet;
109  }
110  function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);}
111  function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);}
112  function set_attribute($name,$value) {return $this->myDOMNode->setAttribute($name,$value);}
113  function tagname() {return $this->myDOMNode->tagName;}
114 }
115
116 class php4DOMNode
117 {
118  var $myDOMNode;
119  var $myOwnerDocument;
120  function php4DOMNode($aDomNode,$aOwnerDocument)
121  {
122   $this->myDOMNode=$aDomNode;
123   $this->myOwnerDocument=$aOwnerDocument;
124  }
125  function __get($name)
126  {
127   if ($name=='type') return $this->myDOMNode->nodeType;
128   elseif ($name=='tagname') return $this->myDOMNode->tagName;
129   elseif ($name=='content') return $this->myDOMNode->textContent;
130   else
131   {
132    $myErrors=debug_backtrace();
133    trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE);
134    return false;
135   }
136  }
137  function append_child($newnode) {return new php4DOMElement($this->myDOMNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);}
138  function append_sibling($newnode) {return new php4DOMElement($this->myDOMNode->parentNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);}
139  function attributes()
140  {
141   $myDOMNodeList=$this->myDOMNode->attributes;
142   $nodeSet=array();
143   $i=0;
144   if (isset($myDOMNodeList))
145    while ($node=$myDOMNodeList->item($i))
146    {
147     $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument);
148     $i++;
149    }
150   return $nodeSet;
151  }
152  function child_nodes()
153  {
154   $myDOMNodeList=$this->myDOMNode->childNodes;
155   $nodeSet=array();
156   $i=0;
157   if (isset($myDOMNodeList))
158    while ($node=$myDOMNodeList->item($i))
159    {
160     $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
161     $i++;
162    }
163   return $nodeSet;
164  }
165  function children() {return $this->child_nodes();}
166  function clone_node($deep=false) {return new php4DOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);}
167  function first_child() {return new php4DOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);}
168  function get_content() {return $this->myDOMNode->textContent;}
169  function has_attributes() {return $this->myDOMNode->hasAttributes();}
170  function has_child_nodes() {return $this->myDOMNode->hasChildNodes();}
171  function insert_before($newnode,$refnode) {return new php4DOMElement($this->myDOMNode->insertBefore($newnode->myDOMNode,$refnode->myDOMNode),$this->myOwnerDocument);}
172  function is_blank_node()
173  {
174   $myDOMNodeList=$this->myDOMNode->childNodes;
175   $i=0;
176   if (isset($myDOMNodeList))
177    while ($node=$myDOMNodeList->item($i))
178    {
179     if (($node->nodeType==XML_ELEMENT_NODE)||
180         (($node->nodeType==XML_TEXT_NODE)&&!ereg('^([[:cntrl:]]|[[:space:]])*$',$node->nodeValue)))
181      return false;
182     $i++;
183    }
184   return true;
185  }
186  function last_child() {return new php4DOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);}
187  function new_child($name,$content)
188  {
189   $mySubNode=$this->myDOMNode->ownerDocument->createElement($name);
190   $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($content));
191   $this->myDOMNode->appendChild($mySubNode);
192   return new php4DOMElement($mySubNode,$this->myOwnerDocument);
193  }
194  function next_sibling() {return new php4DOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);}
195  function node_name() {return $this->myDOMNode->localName;}
196  function node_type() {return $this->myDOMNode->nodeType;}
197  function node_value() {return $this->myDOMNode->nodeValue;}
198  function owner_document() {return $this->myOwnerDocument;}
199  function parent_node() {return new php4DOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);}
200  function prefix() {return $this->myDOMNode->prefix;}
201  function previous_sibling() {return new php4DOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);}
202  function remove_child($oldchild) {return new php4DOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);}
203  function replace_child($oldnode,$newnode) {return new php4DOMElement($this->myDOMNode->replaceChild($oldnode->myDOMNode,$newnode->myDOMNode),$this->myOwnerDocument);}
204  function set_content($text)
205  {
206   if (($this->myDOMNode->hasChildNodes())&&($this->myDOMNode->firstChild->nodeType==XML_TEXT_NODE))
207    $this->myDOMNode->removeChild($this->myDOMNode->firstChild);
208   return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($text));
209  }
210 }
211
212 class php4DOMNodelist
213 {
214  var $myDOMNodelist;
215  var $nodeset;
216  function php4DOMNodelist($aDOMNodelist,$aOwnerDocument)
217  {
218   $this->myDOMNodelist=$aDOMNodelist;
219   $this->nodeset=array();
220   $i=0;
221   if (isset($this->myDOMNodelist))
222    while ($node=$this->myDOMNodelist->item($i))
223    {
224     $this->nodeset[]=new php4DOMElement($node,$aOwnerDocument);
225     $i++;
226    }
227  }
228 }
229
230 class php4DOMXPath
231 {
232  var $myDOMXPath;
233  var $myOwnerDocument;
234  function php4DOMXPath($dom_document)
235  {
236   $this->myOwnerDocument=$dom_document;
237   $this->myDOMXPath=new DOMXPath($dom_document->myDOMNode);
238  }
239  function query($eval_str,$contextnode)
240  {
241   if (isset($contextnode)) return new php4DOMNodelist($this->myDOMXPath->query($eval_str,$contextnode->myDOMNode),$this->myOwnerDocument);
242   else return new php4DOMNodelist($this->myDOMXPath->query($eval_str),$this->myOwnerDocument);
243  }
244  function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);}
245 }
246
247 if (extension_loaded('xsl'))
248 {//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/
249  function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));}
250  function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);}
251  function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));}
252  class php4DomXsltStylesheet
253  {
254   var $myxsltProcessor;
255   function php4DomXsltStylesheet($dom_document)
256   {
257    $this->myxsltProcessor=new xsltProcessor();
258    $this->myxsltProcessor->importStyleSheet($dom_document);
259   }
260   function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false)
261   {
262    foreach ($xslt_parameters as $param=>$value)
263     $this->myxsltProcessor->setParameter('',$param,$value);
264    $myphp4DOMDocument=new php4DOMDocument();
265    $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode);
266    return $myphp4DOMDocument;
267   }
268   function result_dump_file($dom_document,$filename)
269   {
270    $html=$dom_document->myDOMNode->saveHTML();
271    file_put_contents($filename,$html);
272    return $html;
273   }
274   function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();}
275  }
276 }
277 ?>