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