@@ -457,6 +457,10 @@ discard block |
||
457 | 457 | $this->myOwnerDocument=$dom_document->myOwnerDocument; |
458 | 458 | $this->myDOMXPath=new DOMXPath($this->myOwnerDocument->myDOMNode); |
459 | 459 | } |
460 | + |
|
461 | + /** |
|
462 | + * @param string $eval_str |
|
463 | + */ |
|
460 | 464 | function xpath_eval($eval_str,$contextnode=null) |
461 | 465 | { |
462 | 466 | if (method_exists($this->myDOMXPath,'evaluate')) $xp=isset($contextnode) ? $this->myDOMXPath->evaluate($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->evaluate($eval_str); |
@@ -464,6 +468,11 @@ discard block |
||
464 | 468 | $xp=new php4DOMNodelist($xp,$this->myOwnerDocument); |
465 | 469 | return ($xp->type===XPATH_UNDEFINED) ? false : $xp; |
466 | 470 | } |
471 | + |
|
472 | + /** |
|
473 | + * @param string $prefix |
|
474 | + * @param string $namespaceURI |
|
475 | + */ |
|
467 | 476 | function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);} |
468 | 477 | } |
469 | 478 |
@@ -53,36 +53,36 @@ discard block |
||
53 | 53 | function domxml_new_xmldoc($version) {return new php4DOMDocument();} |
54 | 54 | function domxml_open_file($filename,$mode=DOMXML_LOAD_PARSING,&$error=null) |
55 | 55 | { |
56 | - $dom=new php4DOMDocument($mode); |
|
57 | - $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); |
|
58 | - if ($errorMode) libxml_use_internal_errors(true); |
|
59 | - if (!$dom->myDOMNode->load($filename)) $dom=null; |
|
60 | - if ($errorMode) |
|
61 | - { |
|
62 | - $error=array_map('_error_report',libxml_get_errors()); |
|
63 | - libxml_clear_errors(); |
|
64 | - } |
|
65 | - return $dom; |
|
56 | + $dom=new php4DOMDocument($mode); |
|
57 | + $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); |
|
58 | + if ($errorMode) libxml_use_internal_errors(true); |
|
59 | + if (!$dom->myDOMNode->load($filename)) $dom=null; |
|
60 | + if ($errorMode) |
|
61 | + { |
|
62 | + $error=array_map('_error_report',libxml_get_errors()); |
|
63 | + libxml_clear_errors(); |
|
64 | + } |
|
65 | + return $dom; |
|
66 | 66 | } |
67 | 67 | function domxml_open_mem($str,$mode=DOMXML_LOAD_PARSING,&$error=null) |
68 | 68 | { |
69 | - $dom=new php4DOMDocument($mode); |
|
70 | - $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); |
|
71 | - if ($errorMode) libxml_use_internal_errors(true); |
|
72 | - if (!$dom->myDOMNode->loadXML($str)) $dom=null; |
|
73 | - if ($errorMode) |
|
74 | - { |
|
75 | - $error=array_map('_error_report',libxml_get_errors()); |
|
76 | - libxml_clear_errors(); |
|
77 | - } |
|
78 | - return $dom; |
|
69 | + $dom=new php4DOMDocument($mode); |
|
70 | + $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); |
|
71 | + if ($errorMode) libxml_use_internal_errors(true); |
|
72 | + if (!$dom->myDOMNode->loadXML($str)) $dom=null; |
|
73 | + if ($errorMode) |
|
74 | + { |
|
75 | + $error=array_map('_error_report',libxml_get_errors()); |
|
76 | + libxml_clear_errors(); |
|
77 | + } |
|
78 | + return $dom; |
|
79 | 79 | } |
80 | 80 | function html_doc($html_doc,$from_file=false) |
81 | 81 | { |
82 | - $dom=new php4DOMDocument(); |
|
83 | - if ($from_file) $result=$dom->myDOMNode->loadHTMLFile($html_doc); |
|
84 | - else $result=$dom->myDOMNode->loadHTML($html_doc); |
|
85 | - return $result ? $dom : null; |
|
82 | + $dom=new php4DOMDocument(); |
|
83 | + if ($from_file) $result=$dom->myDOMNode->loadHTMLFile($html_doc); |
|
84 | + else $result=$dom->myDOMNode->loadHTML($html_doc); |
|
85 | + return $result ? $dom : null; |
|
86 | 86 | } |
87 | 87 | function html_doc_file($filename) {return html_doc($filename,true);} |
88 | 88 | function xmldoc($str) {return domxml_open_mem($str);} |
@@ -95,314 +95,314 @@ discard block |
||
95 | 95 | |
96 | 96 | class php4DOMAttr extends php4DOMNode |
97 | 97 | { |
98 | - function __get($name) |
|
99 | - { |
|
100 | - if ($name==='name') return $this->myDOMNode->name; |
|
101 | - else return parent::__get($name); |
|
102 | - } |
|
103 | - function name() {return $this->myDOMNode->name;} |
|
104 | - function set_content($text) {} |
|
105 | - //function set_value($content) {return $this->myDOMNode->value=htmlspecialchars($content,ENT_QUOTES);} |
|
106 | - function specified() {return $this->myDOMNode->specified;} |
|
107 | - function value() {return $this->myDOMNode->value;} |
|
98 | + function __get($name) |
|
99 | + { |
|
100 | + if ($name==='name') return $this->myDOMNode->name; |
|
101 | + else return parent::__get($name); |
|
102 | + } |
|
103 | + function name() {return $this->myDOMNode->name;} |
|
104 | + function set_content($text) {} |
|
105 | + //function set_value($content) {return $this->myDOMNode->value=htmlspecialchars($content,ENT_QUOTES);} |
|
106 | + function specified() {return $this->myDOMNode->specified;} |
|
107 | + function value() {return $this->myDOMNode->value;} |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | class php4DOMDocument extends php4DOMNode |
111 | 111 | { |
112 | - function php4DOMDocument($mode=DOMXML_LOAD_PARSING) |
|
113 | - { |
|
114 | - $this->myDOMNode=new DOMDocument(); |
|
115 | - $this->myOwnerDocument=$this; |
|
116 | - if ($mode & DOMXML_LOAD_VALIDATING) $this->myDOMNode->validateOnParse=true; |
|
117 | - if ($mode & DOMXML_LOAD_RECOVERING) $this->myDOMNode->recover=true; |
|
118 | - if ($mode & DOMXML_LOAD_SUBSTITUTE_ENTITIES) $this->myDOMNode->substituteEntities=true; |
|
119 | - if ($mode & DOMXML_LOAD_DONT_KEEP_BLANKS) $this->myDOMNode->preserveWhiteSpace=false; |
|
120 | - } |
|
121 | - function add_root($name) |
|
122 | - { |
|
123 | - if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
|
124 | - return new php4DOMElement($this->myDOMNode->appendChild($this->myDOMNode->createElement($name)),$this->myOwnerDocument); |
|
125 | - } |
|
126 | - function create_attribute($name,$value) |
|
127 | - { |
|
128 | - $myAttr=$this->myDOMNode->createAttribute($name); |
|
129 | - $myAttr->value=htmlspecialchars($value,ENT_QUOTES); |
|
130 | - return new php4DOMAttr($myAttr,$this); |
|
131 | - } |
|
132 | - function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);} |
|
133 | - function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);} |
|
134 | - function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);} |
|
135 | - function create_element_ns($uri,$name,$prefix=null) |
|
136 | - { |
|
137 | - if ($prefix==null) $prefix=$this->myDOMNode->lookupPrefix($uri); |
|
138 | - if (($prefix==null)&&(($this->myDOMNode->documentElement==null)||(!$this->myDOMNode->documentElement->isDefaultNamespace($uri)))) $prefix='a'.sprintf('%u',crc32($uri)); |
|
139 | - return new php4DOMElement($this->myDOMNode->createElementNS($uri,$prefix==null ? $name : $prefix.':'.$name),$this); |
|
140 | - } |
|
141 | - function create_entity_reference($content) {return new php4DOMNode($this->myDOMNode->createEntityReference($content),$this);} //By Walter Ebert 2007-01-22 |
|
142 | - function create_processing_instruction($target,$data=''){return new php4DomProcessingInstruction($this->myDOMNode->createProcessingInstruction($target,$data),$this);} |
|
143 | - function create_text_node($content) {return new php4DOMText($this->myDOMNode->createTextNode($content),$this);} |
|
144 | - function document_element() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);} |
|
145 | - function dump_file($filename,$compressionmode=false,$format=false) |
|
146 | - { |
|
147 | - $format0=$this->myDOMNode->formatOutput; |
|
148 | - $this->myDOMNode->formatOutput=$format; |
|
149 | - $res=$this->myDOMNode->save($filename); |
|
150 | - $this->myDOMNode->formatOutput=$format0; |
|
151 | - return $res; |
|
152 | - } |
|
153 | - function dump_mem($format=false,$encoding=false) |
|
154 | - { |
|
155 | - $format0=$this->myDOMNode->formatOutput; |
|
156 | - $this->myDOMNode->formatOutput=$format; |
|
157 | - $encoding0=$this->myDOMNode->encoding; |
|
158 | - if ($encoding) $this->myDOMNode->encoding=$encoding; |
|
159 | - $dump=$this->myDOMNode->saveXML(); |
|
160 | - $this->myDOMNode->formatOutput=$format0; |
|
161 | - if ($encoding) $this->myDOMNode->encoding= $encoding0=='' ? 'UTF-8' : $encoding0; //UTF-8 is XML default encoding |
|
162 | - return $dump; |
|
163 | - } |
|
164 | - function free() |
|
165 | - { |
|
166 | - if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
|
167 | - $this->myDOMNode=null; |
|
168 | - $this->myOwnerDocument=null; |
|
169 | - } |
|
170 | - function get_element_by_id($id) {return parent::_newDOMElement($this->myDOMNode->getElementById($id),$this);} |
|
171 | - function get_elements_by_tagname($name) |
|
172 | - { |
|
173 | - $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); |
|
174 | - $nodeSet=array(); |
|
175 | - $i=0; |
|
176 | - if (isset($myDOMNodeList)) |
|
177 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this); |
|
178 | - return $nodeSet; |
|
179 | - } |
|
180 | - function html_dump_mem() {return $this->myDOMNode->saveHTML();} |
|
181 | - function root() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);} |
|
182 | - function xinclude() {return $this->myDOMNode->xinclude();} |
|
183 | - function xpath_new_context() {return new php4DOMXPath($this);} |
|
112 | + function php4DOMDocument($mode=DOMXML_LOAD_PARSING) |
|
113 | + { |
|
114 | + $this->myDOMNode=new DOMDocument(); |
|
115 | + $this->myOwnerDocument=$this; |
|
116 | + if ($mode & DOMXML_LOAD_VALIDATING) $this->myDOMNode->validateOnParse=true; |
|
117 | + if ($mode & DOMXML_LOAD_RECOVERING) $this->myDOMNode->recover=true; |
|
118 | + if ($mode & DOMXML_LOAD_SUBSTITUTE_ENTITIES) $this->myDOMNode->substituteEntities=true; |
|
119 | + if ($mode & DOMXML_LOAD_DONT_KEEP_BLANKS) $this->myDOMNode->preserveWhiteSpace=false; |
|
120 | + } |
|
121 | + function add_root($name) |
|
122 | + { |
|
123 | + if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
|
124 | + return new php4DOMElement($this->myDOMNode->appendChild($this->myDOMNode->createElement($name)),$this->myOwnerDocument); |
|
125 | + } |
|
126 | + function create_attribute($name,$value) |
|
127 | + { |
|
128 | + $myAttr=$this->myDOMNode->createAttribute($name); |
|
129 | + $myAttr->value=htmlspecialchars($value,ENT_QUOTES); |
|
130 | + return new php4DOMAttr($myAttr,$this); |
|
131 | + } |
|
132 | + function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);} |
|
133 | + function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);} |
|
134 | + function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);} |
|
135 | + function create_element_ns($uri,$name,$prefix=null) |
|
136 | + { |
|
137 | + if ($prefix==null) $prefix=$this->myDOMNode->lookupPrefix($uri); |
|
138 | + if (($prefix==null)&&(($this->myDOMNode->documentElement==null)||(!$this->myDOMNode->documentElement->isDefaultNamespace($uri)))) $prefix='a'.sprintf('%u',crc32($uri)); |
|
139 | + return new php4DOMElement($this->myDOMNode->createElementNS($uri,$prefix==null ? $name : $prefix.':'.$name),$this); |
|
140 | + } |
|
141 | + function create_entity_reference($content) {return new php4DOMNode($this->myDOMNode->createEntityReference($content),$this);} //By Walter Ebert 2007-01-22 |
|
142 | + function create_processing_instruction($target,$data=''){return new php4DomProcessingInstruction($this->myDOMNode->createProcessingInstruction($target,$data),$this);} |
|
143 | + function create_text_node($content) {return new php4DOMText($this->myDOMNode->createTextNode($content),$this);} |
|
144 | + function document_element() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);} |
|
145 | + function dump_file($filename,$compressionmode=false,$format=false) |
|
146 | + { |
|
147 | + $format0=$this->myDOMNode->formatOutput; |
|
148 | + $this->myDOMNode->formatOutput=$format; |
|
149 | + $res=$this->myDOMNode->save($filename); |
|
150 | + $this->myDOMNode->formatOutput=$format0; |
|
151 | + return $res; |
|
152 | + } |
|
153 | + function dump_mem($format=false,$encoding=false) |
|
154 | + { |
|
155 | + $format0=$this->myDOMNode->formatOutput; |
|
156 | + $this->myDOMNode->formatOutput=$format; |
|
157 | + $encoding0=$this->myDOMNode->encoding; |
|
158 | + if ($encoding) $this->myDOMNode->encoding=$encoding; |
|
159 | + $dump=$this->myDOMNode->saveXML(); |
|
160 | + $this->myDOMNode->formatOutput=$format0; |
|
161 | + if ($encoding) $this->myDOMNode->encoding= $encoding0=='' ? 'UTF-8' : $encoding0; //UTF-8 is XML default encoding |
|
162 | + return $dump; |
|
163 | + } |
|
164 | + function free() |
|
165 | + { |
|
166 | + if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
|
167 | + $this->myDOMNode=null; |
|
168 | + $this->myOwnerDocument=null; |
|
169 | + } |
|
170 | + function get_element_by_id($id) {return parent::_newDOMElement($this->myDOMNode->getElementById($id),$this);} |
|
171 | + function get_elements_by_tagname($name) |
|
172 | + { |
|
173 | + $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); |
|
174 | + $nodeSet=array(); |
|
175 | + $i=0; |
|
176 | + if (isset($myDOMNodeList)) |
|
177 | + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this); |
|
178 | + return $nodeSet; |
|
179 | + } |
|
180 | + function html_dump_mem() {return $this->myDOMNode->saveHTML();} |
|
181 | + function root() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);} |
|
182 | + function xinclude() {return $this->myDOMNode->xinclude();} |
|
183 | + function xpath_new_context() {return new php4DOMXPath($this);} |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | class php4DOMElement extends php4DOMNode |
187 | 187 | { |
188 | - function add_namespace($uri,$prefix) |
|
189 | - { |
|
190 | - if ($this->myDOMNode->hasAttributeNS('http://www.w3.org/2000/xmlns/',$prefix)) return false; |
|
191 | - else |
|
192 | - { |
|
193 | - $this->myDOMNode->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$prefix,$uri); //By Daniel Walker 2006-09-08 |
|
194 | - return true; |
|
195 | - } |
|
196 | - } |
|
197 | - function get_attribute($name) {return $this->myDOMNode->getAttribute($name);} |
|
198 | - function get_attribute_node($name) {return parent::_newDOMElement($this->myDOMNode->getAttributeNode($name),$this->myOwnerDocument);} |
|
199 | - function get_elements_by_tagname($name) |
|
200 | - { |
|
201 | - $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); |
|
202 | - $nodeSet=array(); |
|
203 | - $i=0; |
|
204 | - if (isset($myDOMNodeList)) |
|
205 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument); |
|
206 | - return $nodeSet; |
|
207 | - } |
|
208 | - function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);} |
|
209 | - function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);} |
|
210 | - function set_attribute($name,$value) |
|
211 | - { |
|
212 | - //return $this->myDOMNode->setAttribute($name,$value); //Does not return a DomAttr |
|
213 | - $myAttr=$this->myDOMNode->ownerDocument->createAttribute($name); |
|
214 | - $myAttr->value=htmlspecialchars($value,ENT_QUOTES); //Entity problem reported by AL-DesignWorks 2007-09-07 |
|
215 | - $this->myDOMNode->setAttributeNode($myAttr); |
|
216 | - return new php4DOMAttr($myAttr,$this->myOwnerDocument); |
|
217 | - } |
|
218 | - /*function set_attribute_node($attr) |
|
188 | + function add_namespace($uri,$prefix) |
|
189 | + { |
|
190 | + if ($this->myDOMNode->hasAttributeNS('http://www.w3.org/2000/xmlns/',$prefix)) return false; |
|
191 | + else |
|
192 | + { |
|
193 | + $this->myDOMNode->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$prefix,$uri); //By Daniel Walker 2006-09-08 |
|
194 | + return true; |
|
195 | + } |
|
196 | + } |
|
197 | + function get_attribute($name) {return $this->myDOMNode->getAttribute($name);} |
|
198 | + function get_attribute_node($name) {return parent::_newDOMElement($this->myDOMNode->getAttributeNode($name),$this->myOwnerDocument);} |
|
199 | + function get_elements_by_tagname($name) |
|
200 | + { |
|
201 | + $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); |
|
202 | + $nodeSet=array(); |
|
203 | + $i=0; |
|
204 | + if (isset($myDOMNodeList)) |
|
205 | + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument); |
|
206 | + return $nodeSet; |
|
207 | + } |
|
208 | + function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);} |
|
209 | + function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);} |
|
210 | + function set_attribute($name,$value) |
|
211 | + { |
|
212 | + //return $this->myDOMNode->setAttribute($name,$value); //Does not return a DomAttr |
|
213 | + $myAttr=$this->myDOMNode->ownerDocument->createAttribute($name); |
|
214 | + $myAttr->value=htmlspecialchars($value,ENT_QUOTES); //Entity problem reported by AL-DesignWorks 2007-09-07 |
|
215 | + $this->myDOMNode->setAttributeNode($myAttr); |
|
216 | + return new php4DOMAttr($myAttr,$this->myOwnerDocument); |
|
217 | + } |
|
218 | + /*function set_attribute_node($attr) |
|
219 | 219 | { |
220 | 220 | $this->myDOMNode->setAttributeNode($this->_importNode($attr)); |
221 | 221 | return $attr; |
222 | 222 | }*/ |
223 | - function set_name($name) |
|
224 | - { |
|
225 | - if ($this->myDOMNode->prefix=='') $newNode=$this->myDOMNode->ownerDocument->createElement($name); |
|
226 | - else $newNode=$this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI,$this->myDOMNode->prefix.':'.$name); |
|
227 | - $myDOMNodeList=$this->myDOMNode->attributes; |
|
228 | - $i=0; |
|
229 | - if (isset($myDOMNodeList)) |
|
230 | - while ($node=$myDOMNodeList->item($i++)) |
|
231 | - if ($node->namespaceURI=='') $newNode->setAttribute($node->name,$node->value); |
|
232 | - else $newNode->setAttributeNS($node->namespaceURI,$node->nodeName,$node->value); |
|
233 | - $myDOMNodeList=$this->myDOMNode->childNodes; |
|
234 | - if (isset($myDOMNodeList)) |
|
235 | - while ($node=$myDOMNodeList->item(0)) $newNode->appendChild($node); |
|
236 | - $this->myDOMNode->parentNode->replaceChild($newNode,$this->myDOMNode); |
|
237 | - $this->myDOMNode=$newNode; |
|
238 | - return true; |
|
239 | - } |
|
240 | - function tagname() {return $this->tagname;} |
|
223 | + function set_name($name) |
|
224 | + { |
|
225 | + if ($this->myDOMNode->prefix=='') $newNode=$this->myDOMNode->ownerDocument->createElement($name); |
|
226 | + else $newNode=$this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI,$this->myDOMNode->prefix.':'.$name); |
|
227 | + $myDOMNodeList=$this->myDOMNode->attributes; |
|
228 | + $i=0; |
|
229 | + if (isset($myDOMNodeList)) |
|
230 | + while ($node=$myDOMNodeList->item($i++)) |
|
231 | + if ($node->namespaceURI=='') $newNode->setAttribute($node->name,$node->value); |
|
232 | + else $newNode->setAttributeNS($node->namespaceURI,$node->nodeName,$node->value); |
|
233 | + $myDOMNodeList=$this->myDOMNode->childNodes; |
|
234 | + if (isset($myDOMNodeList)) |
|
235 | + while ($node=$myDOMNodeList->item(0)) $newNode->appendChild($node); |
|
236 | + $this->myDOMNode->parentNode->replaceChild($newNode,$this->myDOMNode); |
|
237 | + $this->myDOMNode=$newNode; |
|
238 | + return true; |
|
239 | + } |
|
240 | + function tagname() {return $this->tagname;} |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | class php4DOMNode |
244 | 244 | { |
245 | - public $myDOMNode; |
|
246 | - public $myOwnerDocument; |
|
247 | - function php4DOMNode($aDomNode,$aOwnerDocument) |
|
248 | - { |
|
249 | - $this->myDOMNode=$aDomNode; |
|
250 | - $this->myOwnerDocument=$aOwnerDocument; |
|
251 | - } |
|
252 | - function __get($name) |
|
253 | - { |
|
254 | - switch ($name) |
|
255 | - { |
|
256 | - case 'type': return $this->myDOMNode->nodeType; |
|
257 | - case 'tagname': return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->tagName; //Avoid namespace prefix for DOMElement |
|
258 | - case 'content': return $this->myDOMNode->textContent; |
|
259 | - case 'value': return $this->myDOMNode->value; |
|
260 | - default: |
|
261 | - $myErrors=debug_backtrace(); |
|
262 | - trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE); |
|
263 | - return false; |
|
264 | - } |
|
265 | - } |
|
266 | - function add_child($newnode) {return append_child($newnode);} |
|
267 | - function add_namespace($uri,$prefix) {return false;} |
|
268 | - function append_child($newnode) {return self::_newDOMElement($this->myDOMNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);} |
|
269 | - function append_sibling($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);} |
|
270 | - function attributes() |
|
271 | - { |
|
272 | - $myDOMNodeList=$this->myDOMNode->attributes; |
|
273 | - if (!(isset($myDOMNodeList)&&$this->myDOMNode->hasAttributes())) return null; |
|
274 | - $nodeSet=array(); |
|
275 | - $i=0; |
|
276 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument); |
|
277 | - return $nodeSet; |
|
278 | - } |
|
279 | - function child_nodes() |
|
280 | - { |
|
281 | - $myDOMNodeList=$this->myDOMNode->childNodes; |
|
282 | - $nodeSet=array(); |
|
283 | - $i=0; |
|
284 | - if (isset($myDOMNodeList)) |
|
285 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=self::_newDOMElement($node,$this->myOwnerDocument); |
|
286 | - return $nodeSet; |
|
287 | - } |
|
288 | - function children() {return $this->child_nodes();} |
|
289 | - function clone_node($deep=false) {return self::_newDOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);} |
|
290 | - //dump_node($node) should only be called on php4DOMDocument |
|
291 | - function dump_node($node=null) {return $node==null ? $this->myOwnerDocument->myDOMNode->saveXML($this->myDOMNode) : $this->myOwnerDocument->myDOMNode->saveXML($node->myDOMNode);} |
|
292 | - function first_child() {return self::_newDOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);} |
|
293 | - function get_content() {return $this->myDOMNode->textContent;} |
|
294 | - function has_attributes() {return $this->myDOMNode->hasAttributes();} |
|
295 | - function has_child_nodes() {return $this->myDOMNode->hasChildNodes();} |
|
296 | - function insert_before($newnode,$refnode) {return self::_newDOMElement($this->myDOMNode->insertBefore($this->_importNode($newnode),$refnode==null?null:$refnode->myDOMNode),$this->myOwnerDocument);} |
|
297 | - function is_blank_node() {return ($this->myDOMNode->nodeType===XML_TEXT_NODE)&&preg_match('%^\s*$%',$this->myDOMNode->nodeValue);} |
|
298 | - function last_child() {return self::_newDOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);} |
|
299 | - function new_child($name,$content) |
|
300 | - { |
|
301 | - $mySubNode=$this->myDOMNode->ownerDocument->createElement($name); |
|
302 | - $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($content))); |
|
303 | - $this->myDOMNode->appendChild($mySubNode); |
|
304 | - return new php4DOMElement($mySubNode,$this->myOwnerDocument); |
|
305 | - } |
|
306 | - function next_sibling() {return self::_newDOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);} |
|
307 | - function node_name() {return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->nodeName;} //Avoid namespace prefix for DOMElement |
|
308 | - function node_type() {return $this->myDOMNode->nodeType;} |
|
309 | - function node_value() {return $this->myDOMNode->nodeValue;} |
|
310 | - function owner_document() {return $this->myOwnerDocument;} |
|
311 | - function parent_node() {return self::_newDOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);} |
|
312 | - function prefix() {return $this->myDOMNode->prefix;} |
|
313 | - function previous_sibling() {return self::_newDOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);} |
|
314 | - function remove_child($oldchild) {return self::_newDOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);} |
|
315 | - function replace_child($newnode,$oldnode) {return self::_newDOMElement($this->myDOMNode->replaceChild($this->_importNode($newnode),$oldnode->myDOMNode),$this->myOwnerDocument);} |
|
316 | - function replace_node($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->replaceChild($this->_importNode($newnode),$this->myDOMNode),$this->myOwnerDocument);} |
|
317 | - function set_content($text) {return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($text)));} //Entity problem reported by AL-DesignWorks 2007-09-07 |
|
318 | - //function set_name($name) {return $this->myOwnerDocument->renameNode($this->myDOMNode,$this->myDOMNode->namespaceURI,$name);} |
|
319 | - function set_namespace($uri,$prefix=null) |
|
320 | - {//Contributions by Daniel Walker 2006-09-08 |
|
321 | - $nsprefix=$this->myDOMNode->lookupPrefix($uri); |
|
322 | - if ($nsprefix==null) |
|
323 | - { |
|
324 | - $nsprefix= $prefix==null ? $nsprefix='a'.sprintf('%u',crc32($uri)) : $prefix; |
|
325 | - if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) |
|
326 | - { |
|
327 | - if (($prefix!=null)&&$this->myDOMNode->ownerElement->hasAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)&& |
|
328 | - ($this->myDOMNode->ownerElement->getAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)!=$uri)) |
|
329 | - {//Remove namespace |
|
330 | - $parent=$this->myDOMNode->ownerElement; |
|
331 | - $parent->removeAttributeNode($this->myDOMNode); |
|
332 | - $parent->setAttribute($this->myDOMNode->localName,$this->myDOMNode->nodeValue); |
|
333 | - $this->myDOMNode=$parent->getAttributeNode($this->myDOMNode->localName); |
|
334 | - return; |
|
335 | - } |
|
336 | - $this->myDOMNode->ownerElement->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$nsprefix,$uri); |
|
337 | - } |
|
338 | - } |
|
339 | - if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) |
|
340 | - { |
|
341 | - $parent=$this->myDOMNode->ownerElement; |
|
342 | - $parent->removeAttributeNode($this->myDOMNode); |
|
343 | - $parent->setAttributeNS($uri,$nsprefix.':'.$this->myDOMNode->localName,$this->myDOMNode->nodeValue); |
|
344 | - $this->myDOMNode=$parent->getAttributeNodeNS($uri,$this->myDOMNode->localName); |
|
345 | - } |
|
346 | - elseif ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) |
|
347 | - { |
|
348 | - $NewNode=$this->myDOMNode->ownerDocument->createElementNS($uri,$nsprefix.':'.$this->myDOMNode->localName); |
|
349 | - foreach ($this->myDOMNode->attributes as $n) $NewNode->appendChild($n->cloneNode(true)); |
|
350 | - foreach ($this->myDOMNode->childNodes as $n) $NewNode->appendChild($n->cloneNode(true)); |
|
351 | - $xpath=new DOMXPath($this->myDOMNode->ownerDocument); |
|
352 | - $myDOMNodeList=$xpath->query('namespace::*[name()!="xml"]',$this->myDOMNode); //Add old namespaces |
|
353 | - foreach ($myDOMNodeList as $n) $NewNode->setAttributeNS('http://www.w3.org/2000/xmlns/',$n->nodeName,$n->nodeValue); |
|
354 | - $this->myDOMNode->parentNode->replaceChild($NewNode,$this->myDOMNode); |
|
355 | - $this->myDOMNode=$NewNode; |
|
356 | - } |
|
357 | - } |
|
358 | - function unlink_node() |
|
359 | - { |
|
360 | - if ($this->myDOMNode->parentNode!=null) |
|
361 | - { |
|
362 | - if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) $this->myDOMNode->parentNode->removeAttributeNode($this->myDOMNode); |
|
363 | - else $this->myDOMNode->parentNode->removeChild($this->myDOMNode); |
|
364 | - } |
|
365 | - } |
|
366 | - protected function _importNode($newnode) {return $this->myOwnerDocument===$newnode->myOwnerDocument ? $newnode->myDOMNode : $this->myOwnerDocument->myDOMNode->importNode($newnode->myDOMNode,true);} //To import DOMNode from another DOMDocument |
|
367 | - static function _newDOMElement($aDOMNode,$aOwnerDocument) |
|
368 | - {//Check the PHP5 DOMNode before creating a new associated PHP4 DOMNode wrapper |
|
369 | - if ($aDOMNode==null) return null; |
|
370 | - switch ($aDOMNode->nodeType) |
|
371 | - { |
|
372 | - case XML_ELEMENT_NODE: return new php4DOMElement($aDOMNode,$aOwnerDocument); |
|
373 | - case XML_TEXT_NODE: return new php4DOMText($aDOMNode,$aOwnerDocument); |
|
374 | - case XML_ATTRIBUTE_NODE: return new php4DOMAttr($aDOMNode,$aOwnerDocument); |
|
375 | - case XML_PI_NODE: return new php4DomProcessingInstruction($aDOMNode,$aOwnerDocument); |
|
376 | - default: return new php4DOMNode($aDOMNode,$aOwnerDocument); |
|
377 | - } |
|
378 | - } |
|
245 | + public $myDOMNode; |
|
246 | + public $myOwnerDocument; |
|
247 | + function php4DOMNode($aDomNode,$aOwnerDocument) |
|
248 | + { |
|
249 | + $this->myDOMNode=$aDomNode; |
|
250 | + $this->myOwnerDocument=$aOwnerDocument; |
|
251 | + } |
|
252 | + function __get($name) |
|
253 | + { |
|
254 | + switch ($name) |
|
255 | + { |
|
256 | + case 'type': return $this->myDOMNode->nodeType; |
|
257 | + case 'tagname': return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->tagName; //Avoid namespace prefix for DOMElement |
|
258 | + case 'content': return $this->myDOMNode->textContent; |
|
259 | + case 'value': return $this->myDOMNode->value; |
|
260 | + default: |
|
261 | + $myErrors=debug_backtrace(); |
|
262 | + trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE); |
|
263 | + return false; |
|
264 | + } |
|
265 | + } |
|
266 | + function add_child($newnode) {return append_child($newnode);} |
|
267 | + function add_namespace($uri,$prefix) {return false;} |
|
268 | + function append_child($newnode) {return self::_newDOMElement($this->myDOMNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);} |
|
269 | + function append_sibling($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);} |
|
270 | + function attributes() |
|
271 | + { |
|
272 | + $myDOMNodeList=$this->myDOMNode->attributes; |
|
273 | + if (!(isset($myDOMNodeList)&&$this->myDOMNode->hasAttributes())) return null; |
|
274 | + $nodeSet=array(); |
|
275 | + $i=0; |
|
276 | + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument); |
|
277 | + return $nodeSet; |
|
278 | + } |
|
279 | + function child_nodes() |
|
280 | + { |
|
281 | + $myDOMNodeList=$this->myDOMNode->childNodes; |
|
282 | + $nodeSet=array(); |
|
283 | + $i=0; |
|
284 | + if (isset($myDOMNodeList)) |
|
285 | + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=self::_newDOMElement($node,$this->myOwnerDocument); |
|
286 | + return $nodeSet; |
|
287 | + } |
|
288 | + function children() {return $this->child_nodes();} |
|
289 | + function clone_node($deep=false) {return self::_newDOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);} |
|
290 | + //dump_node($node) should only be called on php4DOMDocument |
|
291 | + function dump_node($node=null) {return $node==null ? $this->myOwnerDocument->myDOMNode->saveXML($this->myDOMNode) : $this->myOwnerDocument->myDOMNode->saveXML($node->myDOMNode);} |
|
292 | + function first_child() {return self::_newDOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);} |
|
293 | + function get_content() {return $this->myDOMNode->textContent;} |
|
294 | + function has_attributes() {return $this->myDOMNode->hasAttributes();} |
|
295 | + function has_child_nodes() {return $this->myDOMNode->hasChildNodes();} |
|
296 | + function insert_before($newnode,$refnode) {return self::_newDOMElement($this->myDOMNode->insertBefore($this->_importNode($newnode),$refnode==null?null:$refnode->myDOMNode),$this->myOwnerDocument);} |
|
297 | + function is_blank_node() {return ($this->myDOMNode->nodeType===XML_TEXT_NODE)&&preg_match('%^\s*$%',$this->myDOMNode->nodeValue);} |
|
298 | + function last_child() {return self::_newDOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);} |
|
299 | + function new_child($name,$content) |
|
300 | + { |
|
301 | + $mySubNode=$this->myDOMNode->ownerDocument->createElement($name); |
|
302 | + $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($content))); |
|
303 | + $this->myDOMNode->appendChild($mySubNode); |
|
304 | + return new php4DOMElement($mySubNode,$this->myOwnerDocument); |
|
305 | + } |
|
306 | + function next_sibling() {return self::_newDOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);} |
|
307 | + function node_name() {return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->nodeName;} //Avoid namespace prefix for DOMElement |
|
308 | + function node_type() {return $this->myDOMNode->nodeType;} |
|
309 | + function node_value() {return $this->myDOMNode->nodeValue;} |
|
310 | + function owner_document() {return $this->myOwnerDocument;} |
|
311 | + function parent_node() {return self::_newDOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);} |
|
312 | + function prefix() {return $this->myDOMNode->prefix;} |
|
313 | + function previous_sibling() {return self::_newDOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);} |
|
314 | + function remove_child($oldchild) {return self::_newDOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);} |
|
315 | + function replace_child($newnode,$oldnode) {return self::_newDOMElement($this->myDOMNode->replaceChild($this->_importNode($newnode),$oldnode->myDOMNode),$this->myOwnerDocument);} |
|
316 | + function replace_node($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->replaceChild($this->_importNode($newnode),$this->myDOMNode),$this->myOwnerDocument);} |
|
317 | + function set_content($text) {return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($text)));} //Entity problem reported by AL-DesignWorks 2007-09-07 |
|
318 | + //function set_name($name) {return $this->myOwnerDocument->renameNode($this->myDOMNode,$this->myDOMNode->namespaceURI,$name);} |
|
319 | + function set_namespace($uri,$prefix=null) |
|
320 | + {//Contributions by Daniel Walker 2006-09-08 |
|
321 | + $nsprefix=$this->myDOMNode->lookupPrefix($uri); |
|
322 | + if ($nsprefix==null) |
|
323 | + { |
|
324 | + $nsprefix= $prefix==null ? $nsprefix='a'.sprintf('%u',crc32($uri)) : $prefix; |
|
325 | + if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) |
|
326 | + { |
|
327 | + if (($prefix!=null)&&$this->myDOMNode->ownerElement->hasAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)&& |
|
328 | + ($this->myDOMNode->ownerElement->getAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)!=$uri)) |
|
329 | + {//Remove namespace |
|
330 | + $parent=$this->myDOMNode->ownerElement; |
|
331 | + $parent->removeAttributeNode($this->myDOMNode); |
|
332 | + $parent->setAttribute($this->myDOMNode->localName,$this->myDOMNode->nodeValue); |
|
333 | + $this->myDOMNode=$parent->getAttributeNode($this->myDOMNode->localName); |
|
334 | + return; |
|
335 | + } |
|
336 | + $this->myDOMNode->ownerElement->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$nsprefix,$uri); |
|
337 | + } |
|
338 | + } |
|
339 | + if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) |
|
340 | + { |
|
341 | + $parent=$this->myDOMNode->ownerElement; |
|
342 | + $parent->removeAttributeNode($this->myDOMNode); |
|
343 | + $parent->setAttributeNS($uri,$nsprefix.':'.$this->myDOMNode->localName,$this->myDOMNode->nodeValue); |
|
344 | + $this->myDOMNode=$parent->getAttributeNodeNS($uri,$this->myDOMNode->localName); |
|
345 | + } |
|
346 | + elseif ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) |
|
347 | + { |
|
348 | + $NewNode=$this->myDOMNode->ownerDocument->createElementNS($uri,$nsprefix.':'.$this->myDOMNode->localName); |
|
349 | + foreach ($this->myDOMNode->attributes as $n) $NewNode->appendChild($n->cloneNode(true)); |
|
350 | + foreach ($this->myDOMNode->childNodes as $n) $NewNode->appendChild($n->cloneNode(true)); |
|
351 | + $xpath=new DOMXPath($this->myDOMNode->ownerDocument); |
|
352 | + $myDOMNodeList=$xpath->query('namespace::*[name()!="xml"]',$this->myDOMNode); //Add old namespaces |
|
353 | + foreach ($myDOMNodeList as $n) $NewNode->setAttributeNS('http://www.w3.org/2000/xmlns/',$n->nodeName,$n->nodeValue); |
|
354 | + $this->myDOMNode->parentNode->replaceChild($NewNode,$this->myDOMNode); |
|
355 | + $this->myDOMNode=$NewNode; |
|
356 | + } |
|
357 | + } |
|
358 | + function unlink_node() |
|
359 | + { |
|
360 | + if ($this->myDOMNode->parentNode!=null) |
|
361 | + { |
|
362 | + if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) $this->myDOMNode->parentNode->removeAttributeNode($this->myDOMNode); |
|
363 | + else $this->myDOMNode->parentNode->removeChild($this->myDOMNode); |
|
364 | + } |
|
365 | + } |
|
366 | + protected function _importNode($newnode) {return $this->myOwnerDocument===$newnode->myOwnerDocument ? $newnode->myDOMNode : $this->myOwnerDocument->myDOMNode->importNode($newnode->myDOMNode,true);} //To import DOMNode from another DOMDocument |
|
367 | + static function _newDOMElement($aDOMNode,$aOwnerDocument) |
|
368 | + {//Check the PHP5 DOMNode before creating a new associated PHP4 DOMNode wrapper |
|
369 | + if ($aDOMNode==null) return null; |
|
370 | + switch ($aDOMNode->nodeType) |
|
371 | + { |
|
372 | + case XML_ELEMENT_NODE: return new php4DOMElement($aDOMNode,$aOwnerDocument); |
|
373 | + case XML_TEXT_NODE: return new php4DOMText($aDOMNode,$aOwnerDocument); |
|
374 | + case XML_ATTRIBUTE_NODE: return new php4DOMAttr($aDOMNode,$aOwnerDocument); |
|
375 | + case XML_PI_NODE: return new php4DomProcessingInstruction($aDOMNode,$aOwnerDocument); |
|
376 | + default: return new php4DOMNode($aDOMNode,$aOwnerDocument); |
|
377 | + } |
|
378 | + } |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | class php4DomProcessingInstruction extends php4DOMNode |
382 | 382 | { |
383 | - function data() {return $this->myDOMNode->data;} |
|
384 | - function target() {return $this->myDOMNode->target;} |
|
383 | + function data() {return $this->myDOMNode->data;} |
|
384 | + function target() {return $this->myDOMNode->target;} |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | class php4DOMText extends php4DOMNode |
388 | 388 | { |
389 | - function __get($name) |
|
390 | - { |
|
391 | - if ($name==='tagname') return '#text'; |
|
392 | - else return parent::__get($name); |
|
393 | - } |
|
394 | - function tagname() {return '#text';} |
|
395 | - function set_content($text) {$this->myDOMNode->nodeValue=$text; return true;} |
|
389 | + function __get($name) |
|
390 | + { |
|
391 | + if ($name==='tagname') return '#text'; |
|
392 | + else return parent::__get($name); |
|
393 | + } |
|
394 | + function tagname() {return '#text';} |
|
395 | + function set_content($text) {$this->myDOMNode->nodeValue=$text; return true;} |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | if (!defined('XPATH_NODESET')) |
399 | 399 | { |
400 | - define('XPATH_UNDEFINED',0); |
|
401 | - define('XPATH_NODESET',1); |
|
402 | - define('XPATH_BOOLEAN',2); |
|
403 | - define('XPATH_NUMBER',3); |
|
404 | - define('XPATH_STRING',4); |
|
405 | - /*define('XPATH_POINT',5); |
|
400 | + define('XPATH_UNDEFINED',0); |
|
401 | + define('XPATH_NODESET',1); |
|
402 | + define('XPATH_BOOLEAN',2); |
|
403 | + define('XPATH_NUMBER',3); |
|
404 | + define('XPATH_STRING',4); |
|
405 | + /*define('XPATH_POINT',5); |
|
406 | 406 | define('XPATH_RANGE',6); |
407 | 407 | define('XPATH_LOCATIONSET',7); |
408 | 408 | define('XPATH_USERS',8); |
@@ -411,89 +411,89 @@ discard block |
||
411 | 411 | |
412 | 412 | class php4DOMNodelist |
413 | 413 | { |
414 | - private $myDOMNodelist; |
|
415 | - public $nodeset; |
|
416 | - public $type=XPATH_UNDEFINED; |
|
417 | - public $value; |
|
418 | - function php4DOMNodelist($aDOMNodelist,$aOwnerDocument) |
|
419 | - { |
|
420 | - if (!isset($aDOMNodelist)) return; |
|
421 | - elseif (is_object($aDOMNodelist)||is_array($aDOMNodelist)) |
|
422 | - { |
|
423 | - if ($aDOMNodelist->length>0) |
|
424 | - { |
|
425 | - $this->myDOMNodelist=$aDOMNodelist; |
|
426 | - $this->nodeset=array(); |
|
427 | - $this->type=XPATH_NODESET; |
|
428 | - $i=0; |
|
429 | - while ($node=$this->myDOMNodelist->item($i++)) $this->nodeset[]=php4DOMNode::_newDOMElement($node,$aOwnerDocument); |
|
430 | - } |
|
431 | - } |
|
432 | - elseif (is_int($aDOMNodelist)||is_float($aDOMNodelist)) |
|
433 | - { |
|
434 | - $this->type=XPATH_NUMBER; |
|
435 | - $this->value=$aDOMNodelist; |
|
436 | - } |
|
437 | - elseif (is_bool($aDOMNodelist)) |
|
438 | - { |
|
439 | - $this->type=XPATH_BOOLEAN; |
|
440 | - $this->value=$aDOMNodelist; |
|
441 | - } |
|
442 | - elseif (is_string($aDOMNodelist)) |
|
443 | - { |
|
444 | - $this->type=XPATH_STRING; |
|
445 | - $this->value=$aDOMNodelist; |
|
446 | - } |
|
447 | - } |
|
414 | + private $myDOMNodelist; |
|
415 | + public $nodeset; |
|
416 | + public $type=XPATH_UNDEFINED; |
|
417 | + public $value; |
|
418 | + function php4DOMNodelist($aDOMNodelist,$aOwnerDocument) |
|
419 | + { |
|
420 | + if (!isset($aDOMNodelist)) return; |
|
421 | + elseif (is_object($aDOMNodelist)||is_array($aDOMNodelist)) |
|
422 | + { |
|
423 | + if ($aDOMNodelist->length>0) |
|
424 | + { |
|
425 | + $this->myDOMNodelist=$aDOMNodelist; |
|
426 | + $this->nodeset=array(); |
|
427 | + $this->type=XPATH_NODESET; |
|
428 | + $i=0; |
|
429 | + while ($node=$this->myDOMNodelist->item($i++)) $this->nodeset[]=php4DOMNode::_newDOMElement($node,$aOwnerDocument); |
|
430 | + } |
|
431 | + } |
|
432 | + elseif (is_int($aDOMNodelist)||is_float($aDOMNodelist)) |
|
433 | + { |
|
434 | + $this->type=XPATH_NUMBER; |
|
435 | + $this->value=$aDOMNodelist; |
|
436 | + } |
|
437 | + elseif (is_bool($aDOMNodelist)) |
|
438 | + { |
|
439 | + $this->type=XPATH_BOOLEAN; |
|
440 | + $this->value=$aDOMNodelist; |
|
441 | + } |
|
442 | + elseif (is_string($aDOMNodelist)) |
|
443 | + { |
|
444 | + $this->type=XPATH_STRING; |
|
445 | + $this->value=$aDOMNodelist; |
|
446 | + } |
|
447 | + } |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | class php4DOMXPath |
451 | 451 | { |
452 | - public $myDOMXPath; |
|
453 | - private $myOwnerDocument; |
|
454 | - function php4DOMXPath($dom_document) |
|
455 | - { |
|
456 | - //TODO: If $dom_document is a DomElement, make that default $contextnode and modify XPath. Ex: '/test' |
|
457 | - $this->myOwnerDocument=$dom_document->myOwnerDocument; |
|
458 | - $this->myDOMXPath=new DOMXPath($this->myOwnerDocument->myDOMNode); |
|
459 | - } |
|
460 | - function xpath_eval($eval_str,$contextnode=null) |
|
461 | - { |
|
462 | - if (method_exists($this->myDOMXPath,'evaluate')) $xp=isset($contextnode) ? $this->myDOMXPath->evaluate($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->evaluate($eval_str); |
|
463 | - else $xp=isset($contextnode) ? $this->myDOMXPath->query($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->query($eval_str); |
|
464 | - $xp=new php4DOMNodelist($xp,$this->myOwnerDocument); |
|
465 | - return ($xp->type===XPATH_UNDEFINED) ? false : $xp; |
|
466 | - } |
|
467 | - function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);} |
|
452 | + public $myDOMXPath; |
|
453 | + private $myOwnerDocument; |
|
454 | + function php4DOMXPath($dom_document) |
|
455 | + { |
|
456 | + //TODO: If $dom_document is a DomElement, make that default $contextnode and modify XPath. Ex: '/test' |
|
457 | + $this->myOwnerDocument=$dom_document->myOwnerDocument; |
|
458 | + $this->myDOMXPath=new DOMXPath($this->myOwnerDocument->myDOMNode); |
|
459 | + } |
|
460 | + function xpath_eval($eval_str,$contextnode=null) |
|
461 | + { |
|
462 | + if (method_exists($this->myDOMXPath,'evaluate')) $xp=isset($contextnode) ? $this->myDOMXPath->evaluate($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->evaluate($eval_str); |
|
463 | + else $xp=isset($contextnode) ? $this->myDOMXPath->query($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->query($eval_str); |
|
464 | + $xp=new php4DOMNodelist($xp,$this->myOwnerDocument); |
|
465 | + return ($xp->type===XPATH_UNDEFINED) ? false : $xp; |
|
466 | + } |
|
467 | + function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);} |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | if (extension_loaded('xsl')) |
471 | 471 | {//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/ |
472 | - function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));} |
|
473 | - function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);} |
|
474 | - function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));} |
|
475 | - class php4DomXsltStylesheet |
|
476 | - { |
|
477 | - private $myxsltProcessor; |
|
478 | - function php4DomXsltStylesheet($dom_document) |
|
479 | - { |
|
480 | - $this->myxsltProcessor=new xsltProcessor(); |
|
481 | - $this->myxsltProcessor->importStyleSheet($dom_document); |
|
482 | - } |
|
483 | - function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false) |
|
484 | - { |
|
485 | - foreach ($xslt_parameters as $param=>$value) $this->myxsltProcessor->setParameter('',$param,$value); |
|
486 | - $myphp4DOMDocument=new php4DOMDocument(); |
|
487 | - $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode); |
|
488 | - return $myphp4DOMDocument; |
|
489 | - } |
|
490 | - function result_dump_file($dom_document,$filename) |
|
491 | - { |
|
492 | - $html=$dom_document->myDOMNode->saveHTML(); |
|
493 | - file_put_contents($filename,$html); |
|
494 | - return $html; |
|
495 | - } |
|
496 | - function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();} |
|
497 | - } |
|
472 | + function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));} |
|
473 | + function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);} |
|
474 | + function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));} |
|
475 | + class php4DomXsltStylesheet |
|
476 | + { |
|
477 | + private $myxsltProcessor; |
|
478 | + function php4DomXsltStylesheet($dom_document) |
|
479 | + { |
|
480 | + $this->myxsltProcessor=new xsltProcessor(); |
|
481 | + $this->myxsltProcessor->importStyleSheet($dom_document); |
|
482 | + } |
|
483 | + function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false) |
|
484 | + { |
|
485 | + foreach ($xslt_parameters as $param=>$value) $this->myxsltProcessor->setParameter('',$param,$value); |
|
486 | + $myphp4DOMDocument=new php4DOMDocument(); |
|
487 | + $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode); |
|
488 | + return $myphp4DOMDocument; |
|
489 | + } |
|
490 | + function result_dump_file($dom_document,$filename) |
|
491 | + { |
|
492 | + $html=$dom_document->myDOMNode->saveHTML(); |
|
493 | + file_put_contents($filename,$html); |
|
494 | + return $html; |
|
495 | + } |
|
496 | + function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();} |
|
497 | + } |
|
498 | 498 | } |
499 | 499 | ?> |
@@ -42,178 +42,178 @@ discard block |
||
42 | 42 | http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/ |
43 | 43 | */ |
44 | 44 | |
45 | -define('DOMXML_LOAD_PARSING',0); |
|
46 | -define('DOMXML_LOAD_VALIDATING',1); |
|
47 | -define('DOMXML_LOAD_RECOVERING',2); |
|
48 | -define('DOMXML_LOAD_SUBSTITUTE_ENTITIES',4); |
|
45 | +define('DOMXML_LOAD_PARSING', 0); |
|
46 | +define('DOMXML_LOAD_VALIDATING', 1); |
|
47 | +define('DOMXML_LOAD_RECOVERING', 2); |
|
48 | +define('DOMXML_LOAD_SUBSTITUTE_ENTITIES', 4); |
|
49 | 49 | //define('DOMXML_LOAD_COMPLETE_ATTRS',8); |
50 | -define('DOMXML_LOAD_DONT_KEEP_BLANKS',16); |
|
50 | +define('DOMXML_LOAD_DONT_KEEP_BLANKS', 16); |
|
51 | 51 | |
52 | -function domxml_new_doc($version) {return new php4DOMDocument();} |
|
53 | -function domxml_new_xmldoc($version) {return new php4DOMDocument();} |
|
54 | -function domxml_open_file($filename,$mode=DOMXML_LOAD_PARSING,&$error=null) |
|
52 | +function domxml_new_doc($version) {return new php4DOMDocument(); } |
|
53 | +function domxml_new_xmldoc($version) {return new php4DOMDocument(); } |
|
54 | +function domxml_open_file($filename, $mode = DOMXML_LOAD_PARSING, &$error = null) |
|
55 | 55 | { |
56 | - $dom=new php4DOMDocument($mode); |
|
57 | - $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); |
|
56 | + $dom = new php4DOMDocument($mode); |
|
57 | + $errorMode = (func_num_args() > 2) && defined('LIBXML_VERSION'); |
|
58 | 58 | if ($errorMode) libxml_use_internal_errors(true); |
59 | - if (!$dom->myDOMNode->load($filename)) $dom=null; |
|
59 | + if (!$dom->myDOMNode->load($filename)) $dom = null; |
|
60 | 60 | if ($errorMode) |
61 | 61 | { |
62 | - $error=array_map('_error_report',libxml_get_errors()); |
|
62 | + $error = array_map('_error_report', libxml_get_errors()); |
|
63 | 63 | libxml_clear_errors(); |
64 | 64 | } |
65 | 65 | return $dom; |
66 | 66 | } |
67 | -function domxml_open_mem($str,$mode=DOMXML_LOAD_PARSING,&$error=null) |
|
67 | +function domxml_open_mem($str, $mode = DOMXML_LOAD_PARSING, &$error = null) |
|
68 | 68 | { |
69 | - $dom=new php4DOMDocument($mode); |
|
70 | - $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); |
|
69 | + $dom = new php4DOMDocument($mode); |
|
70 | + $errorMode = (func_num_args() > 2) && defined('LIBXML_VERSION'); |
|
71 | 71 | if ($errorMode) libxml_use_internal_errors(true); |
72 | - if (!$dom->myDOMNode->loadXML($str)) $dom=null; |
|
72 | + if (!$dom->myDOMNode->loadXML($str)) $dom = null; |
|
73 | 73 | if ($errorMode) |
74 | 74 | { |
75 | - $error=array_map('_error_report',libxml_get_errors()); |
|
75 | + $error = array_map('_error_report', libxml_get_errors()); |
|
76 | 76 | libxml_clear_errors(); |
77 | 77 | } |
78 | 78 | return $dom; |
79 | 79 | } |
80 | -function html_doc($html_doc,$from_file=false) |
|
80 | +function html_doc($html_doc, $from_file = false) |
|
81 | 81 | { |
82 | - $dom=new php4DOMDocument(); |
|
83 | - if ($from_file) $result=$dom->myDOMNode->loadHTMLFile($html_doc); |
|
84 | - else $result=$dom->myDOMNode->loadHTML($html_doc); |
|
82 | + $dom = new php4DOMDocument(); |
|
83 | + if ($from_file) $result = $dom->myDOMNode->loadHTMLFile($html_doc); |
|
84 | + else $result = $dom->myDOMNode->loadHTML($html_doc); |
|
85 | 85 | return $result ? $dom : null; |
86 | 86 | } |
87 | -function html_doc_file($filename) {return html_doc($filename,true);} |
|
88 | -function xmldoc($str) {return domxml_open_mem($str);} |
|
89 | -function xmldocfile($filename) {return domxml_open_file($filename);} |
|
90 | -function xpath_eval($xpath_context,$eval_str,$contextnode=null) {return $xpath_context->xpath_eval($eval_str,$contextnode);} |
|
91 | -function xpath_new_context($dom_document) {return new php4DOMXPath($dom_document);} |
|
92 | -function xpath_register_ns($xpath_context,$prefix,$namespaceURI) {return $xpath_context->myDOMXPath->registerNamespace($prefix,$namespaceURI);} |
|
93 | -function _entityDecode($text) {return html_entity_decode(strtr($text,array('''=>'\'')),ENT_QUOTES,'UTF-8');} |
|
94 | -function _error_report($error) {return array('errormessage'=>$error->message,'nodename'=>'','line'=>$error->line,'col'=>$error->column)+($error->file==''?array():array('directory'=>dirname($error->file),'file'=>basename($error->file)));} |
|
87 | +function html_doc_file($filename) {return html_doc($filename, true); } |
|
88 | +function xmldoc($str) {return domxml_open_mem($str); } |
|
89 | +function xmldocfile($filename) {return domxml_open_file($filename); } |
|
90 | +function xpath_eval($xpath_context, $eval_str, $contextnode = null) {return $xpath_context->xpath_eval($eval_str, $contextnode); } |
|
91 | +function xpath_new_context($dom_document) {return new php4DOMXPath($dom_document); } |
|
92 | +function xpath_register_ns($xpath_context, $prefix, $namespaceURI) {return $xpath_context->myDOMXPath->registerNamespace($prefix, $namespaceURI); } |
|
93 | +function _entityDecode($text) {return html_entity_decode(strtr($text, array('''=>'\'')), ENT_QUOTES, 'UTF-8'); } |
|
94 | +function _error_report($error) {return array('errormessage'=>$error->message, 'nodename'=>'', 'line'=>$error->line, 'col'=>$error->column) + ($error->file == '' ? array() : array('directory'=>dirname($error->file), 'file'=>basename($error->file))); } |
|
95 | 95 | |
96 | 96 | class php4DOMAttr extends php4DOMNode |
97 | 97 | { |
98 | 98 | function __get($name) |
99 | 99 | { |
100 | - if ($name==='name') return $this->myDOMNode->name; |
|
100 | + if ($name === 'name') return $this->myDOMNode->name; |
|
101 | 101 | else return parent::__get($name); |
102 | 102 | } |
103 | - function name() {return $this->myDOMNode->name;} |
|
103 | + function name() {return $this->myDOMNode->name; } |
|
104 | 104 | function set_content($text) {} |
105 | 105 | //function set_value($content) {return $this->myDOMNode->value=htmlspecialchars($content,ENT_QUOTES);} |
106 | - function specified() {return $this->myDOMNode->specified;} |
|
107 | - function value() {return $this->myDOMNode->value;} |
|
106 | + function specified() {return $this->myDOMNode->specified; } |
|
107 | + function value() {return $this->myDOMNode->value; } |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | class php4DOMDocument extends php4DOMNode |
111 | 111 | { |
112 | - function php4DOMDocument($mode=DOMXML_LOAD_PARSING) |
|
112 | + function php4DOMDocument($mode = DOMXML_LOAD_PARSING) |
|
113 | 113 | { |
114 | - $this->myDOMNode=new DOMDocument(); |
|
115 | - $this->myOwnerDocument=$this; |
|
116 | - if ($mode & DOMXML_LOAD_VALIDATING) $this->myDOMNode->validateOnParse=true; |
|
117 | - if ($mode & DOMXML_LOAD_RECOVERING) $this->myDOMNode->recover=true; |
|
118 | - if ($mode & DOMXML_LOAD_SUBSTITUTE_ENTITIES) $this->myDOMNode->substituteEntities=true; |
|
119 | - if ($mode & DOMXML_LOAD_DONT_KEEP_BLANKS) $this->myDOMNode->preserveWhiteSpace=false; |
|
114 | + $this->myDOMNode = new DOMDocument(); |
|
115 | + $this->myOwnerDocument = $this; |
|
116 | + if ($mode & DOMXML_LOAD_VALIDATING) $this->myDOMNode->validateOnParse = true; |
|
117 | + if ($mode & DOMXML_LOAD_RECOVERING) $this->myDOMNode->recover = true; |
|
118 | + if ($mode & DOMXML_LOAD_SUBSTITUTE_ENTITIES) $this->myDOMNode->substituteEntities = true; |
|
119 | + if ($mode & DOMXML_LOAD_DONT_KEEP_BLANKS) $this->myDOMNode->preserveWhiteSpace = false; |
|
120 | 120 | } |
121 | 121 | function add_root($name) |
122 | 122 | { |
123 | 123 | if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
124 | - return new php4DOMElement($this->myDOMNode->appendChild($this->myDOMNode->createElement($name)),$this->myOwnerDocument); |
|
124 | + return new php4DOMElement($this->myDOMNode->appendChild($this->myDOMNode->createElement($name)), $this->myOwnerDocument); |
|
125 | 125 | } |
126 | - function create_attribute($name,$value) |
|
126 | + function create_attribute($name, $value) |
|
127 | 127 | { |
128 | - $myAttr=$this->myDOMNode->createAttribute($name); |
|
129 | - $myAttr->value=htmlspecialchars($value,ENT_QUOTES); |
|
130 | - return new php4DOMAttr($myAttr,$this); |
|
128 | + $myAttr = $this->myDOMNode->createAttribute($name); |
|
129 | + $myAttr->value = htmlspecialchars($value, ENT_QUOTES); |
|
130 | + return new php4DOMAttr($myAttr, $this); |
|
131 | 131 | } |
132 | - function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);} |
|
133 | - function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);} |
|
134 | - function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);} |
|
135 | - function create_element_ns($uri,$name,$prefix=null) |
|
132 | + function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content), $this); } |
|
133 | + function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data), $this); } |
|
134 | + function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name), $this); } |
|
135 | + function create_element_ns($uri, $name, $prefix = null) |
|
136 | 136 | { |
137 | - if ($prefix==null) $prefix=$this->myDOMNode->lookupPrefix($uri); |
|
138 | - if (($prefix==null)&&(($this->myDOMNode->documentElement==null)||(!$this->myDOMNode->documentElement->isDefaultNamespace($uri)))) $prefix='a'.sprintf('%u',crc32($uri)); |
|
139 | - return new php4DOMElement($this->myDOMNode->createElementNS($uri,$prefix==null ? $name : $prefix.':'.$name),$this); |
|
137 | + if ($prefix == null) $prefix = $this->myDOMNode->lookupPrefix($uri); |
|
138 | + if (($prefix == null) && (($this->myDOMNode->documentElement == null) || (!$this->myDOMNode->documentElement->isDefaultNamespace($uri)))) $prefix = 'a'.sprintf('%u', crc32($uri)); |
|
139 | + return new php4DOMElement($this->myDOMNode->createElementNS($uri, $prefix == null ? $name : $prefix.':'.$name), $this); |
|
140 | 140 | } |
141 | - function create_entity_reference($content) {return new php4DOMNode($this->myDOMNode->createEntityReference($content),$this);} //By Walter Ebert 2007-01-22 |
|
142 | - function create_processing_instruction($target,$data=''){return new php4DomProcessingInstruction($this->myDOMNode->createProcessingInstruction($target,$data),$this);} |
|
143 | - function create_text_node($content) {return new php4DOMText($this->myDOMNode->createTextNode($content),$this);} |
|
144 | - function document_element() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);} |
|
145 | - function dump_file($filename,$compressionmode=false,$format=false) |
|
141 | + function create_entity_reference($content) {return new php4DOMNode($this->myDOMNode->createEntityReference($content), $this); } //By Walter Ebert 2007-01-22 |
|
142 | + function create_processing_instruction($target, $data = '') {return new php4DomProcessingInstruction($this->myDOMNode->createProcessingInstruction($target, $data), $this); } |
|
143 | + function create_text_node($content) {return new php4DOMText($this->myDOMNode->createTextNode($content), $this); } |
|
144 | + function document_element() {return parent::_newDOMElement($this->myDOMNode->documentElement, $this); } |
|
145 | + function dump_file($filename, $compressionmode = false, $format = false) |
|
146 | 146 | { |
147 | - $format0=$this->myDOMNode->formatOutput; |
|
148 | - $this->myDOMNode->formatOutput=$format; |
|
149 | - $res=$this->myDOMNode->save($filename); |
|
150 | - $this->myDOMNode->formatOutput=$format0; |
|
147 | + $format0 = $this->myDOMNode->formatOutput; |
|
148 | + $this->myDOMNode->formatOutput = $format; |
|
149 | + $res = $this->myDOMNode->save($filename); |
|
150 | + $this->myDOMNode->formatOutput = $format0; |
|
151 | 151 | return $res; |
152 | 152 | } |
153 | - function dump_mem($format=false,$encoding=false) |
|
153 | + function dump_mem($format = false, $encoding = false) |
|
154 | 154 | { |
155 | - $format0=$this->myDOMNode->formatOutput; |
|
156 | - $this->myDOMNode->formatOutput=$format; |
|
157 | - $encoding0=$this->myDOMNode->encoding; |
|
158 | - if ($encoding) $this->myDOMNode->encoding=$encoding; |
|
159 | - $dump=$this->myDOMNode->saveXML(); |
|
160 | - $this->myDOMNode->formatOutput=$format0; |
|
161 | - if ($encoding) $this->myDOMNode->encoding= $encoding0=='' ? 'UTF-8' : $encoding0; //UTF-8 is XML default encoding |
|
155 | + $format0 = $this->myDOMNode->formatOutput; |
|
156 | + $this->myDOMNode->formatOutput = $format; |
|
157 | + $encoding0 = $this->myDOMNode->encoding; |
|
158 | + if ($encoding) $this->myDOMNode->encoding = $encoding; |
|
159 | + $dump = $this->myDOMNode->saveXML(); |
|
160 | + $this->myDOMNode->formatOutput = $format0; |
|
161 | + if ($encoding) $this->myDOMNode->encoding = $encoding0 == '' ? 'UTF-8' : $encoding0; //UTF-8 is XML default encoding |
|
162 | 162 | return $dump; |
163 | 163 | } |
164 | 164 | function free() |
165 | 165 | { |
166 | 166 | if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
167 | - $this->myDOMNode=null; |
|
168 | - $this->myOwnerDocument=null; |
|
167 | + $this->myDOMNode = null; |
|
168 | + $this->myOwnerDocument = null; |
|
169 | 169 | } |
170 | - function get_element_by_id($id) {return parent::_newDOMElement($this->myDOMNode->getElementById($id),$this);} |
|
170 | + function get_element_by_id($id) {return parent::_newDOMElement($this->myDOMNode->getElementById($id), $this); } |
|
171 | 171 | function get_elements_by_tagname($name) |
172 | 172 | { |
173 | - $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); |
|
174 | - $nodeSet=array(); |
|
175 | - $i=0; |
|
173 | + $myDOMNodeList = $this->myDOMNode->getElementsByTagName($name); |
|
174 | + $nodeSet = array(); |
|
175 | + $i = 0; |
|
176 | 176 | if (isset($myDOMNodeList)) |
177 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this); |
|
177 | + while ($node = $myDOMNodeList->item($i++)) $nodeSet[] = new php4DOMElement($node, $this); |
|
178 | 178 | return $nodeSet; |
179 | 179 | } |
180 | - function html_dump_mem() {return $this->myDOMNode->saveHTML();} |
|
181 | - function root() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);} |
|
182 | - function xinclude() {return $this->myDOMNode->xinclude();} |
|
183 | - function xpath_new_context() {return new php4DOMXPath($this);} |
|
180 | + function html_dump_mem() {return $this->myDOMNode->saveHTML(); } |
|
181 | + function root() {return parent::_newDOMElement($this->myDOMNode->documentElement, $this); } |
|
182 | + function xinclude() {return $this->myDOMNode->xinclude(); } |
|
183 | + function xpath_new_context() {return new php4DOMXPath($this); } |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | class php4DOMElement extends php4DOMNode |
187 | 187 | { |
188 | - function add_namespace($uri,$prefix) |
|
188 | + function add_namespace($uri, $prefix) |
|
189 | 189 | { |
190 | - if ($this->myDOMNode->hasAttributeNS('http://www.w3.org/2000/xmlns/',$prefix)) return false; |
|
190 | + if ($this->myDOMNode->hasAttributeNS('http://www.w3.org/2000/xmlns/', $prefix)) return false; |
|
191 | 191 | else |
192 | 192 | { |
193 | - $this->myDOMNode->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$prefix,$uri); //By Daniel Walker 2006-09-08 |
|
193 | + $this->myDOMNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:'.$prefix, $uri); //By Daniel Walker 2006-09-08 |
|
194 | 194 | return true; |
195 | 195 | } |
196 | 196 | } |
197 | - function get_attribute($name) {return $this->myDOMNode->getAttribute($name);} |
|
198 | - function get_attribute_node($name) {return parent::_newDOMElement($this->myDOMNode->getAttributeNode($name),$this->myOwnerDocument);} |
|
197 | + function get_attribute($name) {return $this->myDOMNode->getAttribute($name); } |
|
198 | + function get_attribute_node($name) {return parent::_newDOMElement($this->myDOMNode->getAttributeNode($name), $this->myOwnerDocument); } |
|
199 | 199 | function get_elements_by_tagname($name) |
200 | 200 | { |
201 | - $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); |
|
202 | - $nodeSet=array(); |
|
203 | - $i=0; |
|
201 | + $myDOMNodeList = $this->myDOMNode->getElementsByTagName($name); |
|
202 | + $nodeSet = array(); |
|
203 | + $i = 0; |
|
204 | 204 | if (isset($myDOMNodeList)) |
205 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument); |
|
205 | + while ($node = $myDOMNodeList->item($i++)) $nodeSet[] = new php4DOMElement($node, $this->myOwnerDocument); |
|
206 | 206 | return $nodeSet; |
207 | 207 | } |
208 | - function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);} |
|
209 | - function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);} |
|
210 | - function set_attribute($name,$value) |
|
208 | + function has_attribute($name) {return $this->myDOMNode->hasAttribute($name); } |
|
209 | + function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name); } |
|
210 | + function set_attribute($name, $value) |
|
211 | 211 | { |
212 | 212 | //return $this->myDOMNode->setAttribute($name,$value); //Does not return a DomAttr |
213 | - $myAttr=$this->myDOMNode->ownerDocument->createAttribute($name); |
|
214 | - $myAttr->value=htmlspecialchars($value,ENT_QUOTES); //Entity problem reported by AL-DesignWorks 2007-09-07 |
|
213 | + $myAttr = $this->myDOMNode->ownerDocument->createAttribute($name); |
|
214 | + $myAttr->value = htmlspecialchars($value, ENT_QUOTES); //Entity problem reported by AL-DesignWorks 2007-09-07 |
|
215 | 215 | $this->myDOMNode->setAttributeNode($myAttr); |
216 | - return new php4DOMAttr($myAttr,$this->myOwnerDocument); |
|
216 | + return new php4DOMAttr($myAttr, $this->myOwnerDocument); |
|
217 | 217 | } |
218 | 218 | /*function set_attribute_node($attr) |
219 | 219 | { |
@@ -222,186 +222,186 @@ discard block |
||
222 | 222 | }*/ |
223 | 223 | function set_name($name) |
224 | 224 | { |
225 | - if ($this->myDOMNode->prefix=='') $newNode=$this->myDOMNode->ownerDocument->createElement($name); |
|
226 | - else $newNode=$this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI,$this->myDOMNode->prefix.':'.$name); |
|
227 | - $myDOMNodeList=$this->myDOMNode->attributes; |
|
228 | - $i=0; |
|
225 | + if ($this->myDOMNode->prefix == '') $newNode = $this->myDOMNode->ownerDocument->createElement($name); |
|
226 | + else $newNode = $this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI, $this->myDOMNode->prefix.':'.$name); |
|
227 | + $myDOMNodeList = $this->myDOMNode->attributes; |
|
228 | + $i = 0; |
|
229 | 229 | if (isset($myDOMNodeList)) |
230 | - while ($node=$myDOMNodeList->item($i++)) |
|
231 | - if ($node->namespaceURI=='') $newNode->setAttribute($node->name,$node->value); |
|
232 | - else $newNode->setAttributeNS($node->namespaceURI,$node->nodeName,$node->value); |
|
233 | - $myDOMNodeList=$this->myDOMNode->childNodes; |
|
230 | + while ($node = $myDOMNodeList->item($i++)) |
|
231 | + if ($node->namespaceURI == '') $newNode->setAttribute($node->name, $node->value); |
|
232 | + else $newNode->setAttributeNS($node->namespaceURI, $node->nodeName, $node->value); |
|
233 | + $myDOMNodeList = $this->myDOMNode->childNodes; |
|
234 | 234 | if (isset($myDOMNodeList)) |
235 | - while ($node=$myDOMNodeList->item(0)) $newNode->appendChild($node); |
|
236 | - $this->myDOMNode->parentNode->replaceChild($newNode,$this->myDOMNode); |
|
237 | - $this->myDOMNode=$newNode; |
|
235 | + while ($node = $myDOMNodeList->item(0)) $newNode->appendChild($node); |
|
236 | + $this->myDOMNode->parentNode->replaceChild($newNode, $this->myDOMNode); |
|
237 | + $this->myDOMNode = $newNode; |
|
238 | 238 | return true; |
239 | 239 | } |
240 | - function tagname() {return $this->tagname;} |
|
240 | + function tagname() {return $this->tagname; } |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | class php4DOMNode |
244 | 244 | { |
245 | 245 | public $myDOMNode; |
246 | 246 | public $myOwnerDocument; |
247 | - function php4DOMNode($aDomNode,$aOwnerDocument) |
|
247 | + function php4DOMNode($aDomNode, $aOwnerDocument) |
|
248 | 248 | { |
249 | - $this->myDOMNode=$aDomNode; |
|
250 | - $this->myOwnerDocument=$aOwnerDocument; |
|
249 | + $this->myDOMNode = $aDomNode; |
|
250 | + $this->myOwnerDocument = $aOwnerDocument; |
|
251 | 251 | } |
252 | 252 | function __get($name) |
253 | 253 | { |
254 | 254 | switch ($name) |
255 | 255 | { |
256 | 256 | case 'type': return $this->myDOMNode->nodeType; |
257 | - case 'tagname': return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->tagName; //Avoid namespace prefix for DOMElement |
|
257 | + case 'tagname': return ($this->myDOMNode->nodeType === XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->tagName; //Avoid namespace prefix for DOMElement |
|
258 | 258 | case 'content': return $this->myDOMNode->textContent; |
259 | 259 | case 'value': return $this->myDOMNode->value; |
260 | 260 | default: |
261 | - $myErrors=debug_backtrace(); |
|
262 | - trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE); |
|
261 | + $myErrors = debug_backtrace(); |
|
262 | + trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']', E_USER_NOTICE); |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 | } |
266 | - function add_child($newnode) {return append_child($newnode);} |
|
267 | - function add_namespace($uri,$prefix) {return false;} |
|
268 | - function append_child($newnode) {return self::_newDOMElement($this->myDOMNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);} |
|
269 | - function append_sibling($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);} |
|
266 | + function add_child($newnode) {return append_child($newnode); } |
|
267 | + function add_namespace($uri, $prefix) {return false; } |
|
268 | + function append_child($newnode) {return self::_newDOMElement($this->myDOMNode->appendChild($this->_importNode($newnode)), $this->myOwnerDocument); } |
|
269 | + function append_sibling($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->appendChild($this->_importNode($newnode)), $this->myOwnerDocument); } |
|
270 | 270 | function attributes() |
271 | 271 | { |
272 | - $myDOMNodeList=$this->myDOMNode->attributes; |
|
273 | - if (!(isset($myDOMNodeList)&&$this->myDOMNode->hasAttributes())) return null; |
|
274 | - $nodeSet=array(); |
|
275 | - $i=0; |
|
276 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument); |
|
272 | + $myDOMNodeList = $this->myDOMNode->attributes; |
|
273 | + if (!(isset($myDOMNodeList) && $this->myDOMNode->hasAttributes())) return null; |
|
274 | + $nodeSet = array(); |
|
275 | + $i = 0; |
|
276 | + while ($node = $myDOMNodeList->item($i++)) $nodeSet[] = new php4DOMAttr($node, $this->myOwnerDocument); |
|
277 | 277 | return $nodeSet; |
278 | 278 | } |
279 | 279 | function child_nodes() |
280 | 280 | { |
281 | - $myDOMNodeList=$this->myDOMNode->childNodes; |
|
282 | - $nodeSet=array(); |
|
283 | - $i=0; |
|
281 | + $myDOMNodeList = $this->myDOMNode->childNodes; |
|
282 | + $nodeSet = array(); |
|
283 | + $i = 0; |
|
284 | 284 | if (isset($myDOMNodeList)) |
285 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=self::_newDOMElement($node,$this->myOwnerDocument); |
|
285 | + while ($node = $myDOMNodeList->item($i++)) $nodeSet[] = self::_newDOMElement($node, $this->myOwnerDocument); |
|
286 | 286 | return $nodeSet; |
287 | 287 | } |
288 | - function children() {return $this->child_nodes();} |
|
289 | - function clone_node($deep=false) {return self::_newDOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);} |
|
288 | + function children() {return $this->child_nodes(); } |
|
289 | + function clone_node($deep = false) {return self::_newDOMElement($this->myDOMNode->cloneNode($deep), $this->myOwnerDocument); } |
|
290 | 290 | //dump_node($node) should only be called on php4DOMDocument |
291 | - function dump_node($node=null) {return $node==null ? $this->myOwnerDocument->myDOMNode->saveXML($this->myDOMNode) : $this->myOwnerDocument->myDOMNode->saveXML($node->myDOMNode);} |
|
292 | - function first_child() {return self::_newDOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);} |
|
293 | - function get_content() {return $this->myDOMNode->textContent;} |
|
294 | - function has_attributes() {return $this->myDOMNode->hasAttributes();} |
|
295 | - function has_child_nodes() {return $this->myDOMNode->hasChildNodes();} |
|
296 | - function insert_before($newnode,$refnode) {return self::_newDOMElement($this->myDOMNode->insertBefore($this->_importNode($newnode),$refnode==null?null:$refnode->myDOMNode),$this->myOwnerDocument);} |
|
297 | - function is_blank_node() {return ($this->myDOMNode->nodeType===XML_TEXT_NODE)&&preg_match('%^\s*$%',$this->myDOMNode->nodeValue);} |
|
298 | - function last_child() {return self::_newDOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);} |
|
299 | - function new_child($name,$content) |
|
291 | + function dump_node($node = null) {return $node == null ? $this->myOwnerDocument->myDOMNode->saveXML($this->myDOMNode) : $this->myOwnerDocument->myDOMNode->saveXML($node->myDOMNode); } |
|
292 | + function first_child() {return self::_newDOMElement($this->myDOMNode->firstChild, $this->myOwnerDocument); } |
|
293 | + function get_content() {return $this->myDOMNode->textContent; } |
|
294 | + function has_attributes() {return $this->myDOMNode->hasAttributes(); } |
|
295 | + function has_child_nodes() {return $this->myDOMNode->hasChildNodes(); } |
|
296 | + function insert_before($newnode, $refnode) {return self::_newDOMElement($this->myDOMNode->insertBefore($this->_importNode($newnode), $refnode == null ? null : $refnode->myDOMNode), $this->myOwnerDocument); } |
|
297 | + function is_blank_node() {return ($this->myDOMNode->nodeType === XML_TEXT_NODE) && preg_match('%^\s*$%', $this->myDOMNode->nodeValue); } |
|
298 | + function last_child() {return self::_newDOMElement($this->myDOMNode->lastChild, $this->myOwnerDocument); } |
|
299 | + function new_child($name, $content) |
|
300 | 300 | { |
301 | - $mySubNode=$this->myDOMNode->ownerDocument->createElement($name); |
|
301 | + $mySubNode = $this->myDOMNode->ownerDocument->createElement($name); |
|
302 | 302 | $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($content))); |
303 | 303 | $this->myDOMNode->appendChild($mySubNode); |
304 | - return new php4DOMElement($mySubNode,$this->myOwnerDocument); |
|
304 | + return new php4DOMElement($mySubNode, $this->myOwnerDocument); |
|
305 | 305 | } |
306 | - function next_sibling() {return self::_newDOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);} |
|
307 | - function node_name() {return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->nodeName;} //Avoid namespace prefix for DOMElement |
|
308 | - function node_type() {return $this->myDOMNode->nodeType;} |
|
309 | - function node_value() {return $this->myDOMNode->nodeValue;} |
|
310 | - function owner_document() {return $this->myOwnerDocument;} |
|
311 | - function parent_node() {return self::_newDOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);} |
|
312 | - function prefix() {return $this->myDOMNode->prefix;} |
|
313 | - function previous_sibling() {return self::_newDOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);} |
|
314 | - function remove_child($oldchild) {return self::_newDOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);} |
|
315 | - function replace_child($newnode,$oldnode) {return self::_newDOMElement($this->myDOMNode->replaceChild($this->_importNode($newnode),$oldnode->myDOMNode),$this->myOwnerDocument);} |
|
316 | - function replace_node($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->replaceChild($this->_importNode($newnode),$this->myDOMNode),$this->myOwnerDocument);} |
|
317 | - function set_content($text) {return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($text)));} //Entity problem reported by AL-DesignWorks 2007-09-07 |
|
306 | + function next_sibling() {return self::_newDOMElement($this->myDOMNode->nextSibling, $this->myOwnerDocument); } |
|
307 | + function node_name() {return ($this->myDOMNode->nodeType === XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->nodeName; } //Avoid namespace prefix for DOMElement |
|
308 | + function node_type() {return $this->myDOMNode->nodeType; } |
|
309 | + function node_value() {return $this->myDOMNode->nodeValue; } |
|
310 | + function owner_document() {return $this->myOwnerDocument; } |
|
311 | + function parent_node() {return self::_newDOMElement($this->myDOMNode->parentNode, $this->myOwnerDocument); } |
|
312 | + function prefix() {return $this->myDOMNode->prefix; } |
|
313 | + function previous_sibling() {return self::_newDOMElement($this->myDOMNode->previousSibling, $this->myOwnerDocument); } |
|
314 | + function remove_child($oldchild) {return self::_newDOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode), $this->myOwnerDocument); } |
|
315 | + function replace_child($newnode, $oldnode) {return self::_newDOMElement($this->myDOMNode->replaceChild($this->_importNode($newnode), $oldnode->myDOMNode), $this->myOwnerDocument); } |
|
316 | + function replace_node($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->replaceChild($this->_importNode($newnode), $this->myDOMNode), $this->myOwnerDocument); } |
|
317 | + function set_content($text) {return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(_entityDecode($text))); } //Entity problem reported by AL-DesignWorks 2007-09-07 |
|
318 | 318 | //function set_name($name) {return $this->myOwnerDocument->renameNode($this->myDOMNode,$this->myDOMNode->namespaceURI,$name);} |
319 | - function set_namespace($uri,$prefix=null) |
|
319 | + function set_namespace($uri, $prefix = null) |
|
320 | 320 | {//Contributions by Daniel Walker 2006-09-08 |
321 | - $nsprefix=$this->myDOMNode->lookupPrefix($uri); |
|
322 | - if ($nsprefix==null) |
|
321 | + $nsprefix = $this->myDOMNode->lookupPrefix($uri); |
|
322 | + if ($nsprefix == null) |
|
323 | 323 | { |
324 | - $nsprefix= $prefix==null ? $nsprefix='a'.sprintf('%u',crc32($uri)) : $prefix; |
|
325 | - if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) |
|
324 | + $nsprefix = $prefix == null ? $nsprefix = 'a'.sprintf('%u', crc32($uri)) : $prefix; |
|
325 | + if ($this->myDOMNode->nodeType === XML_ATTRIBUTE_NODE) |
|
326 | 326 | { |
327 | - if (($prefix!=null)&&$this->myDOMNode->ownerElement->hasAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)&& |
|
328 | - ($this->myDOMNode->ownerElement->getAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)!=$uri)) |
|
327 | + if (($prefix != null) && $this->myDOMNode->ownerElement->hasAttributeNS('http://www.w3.org/2000/xmlns/', $nsprefix) && |
|
328 | + ($this->myDOMNode->ownerElement->getAttributeNS('http://www.w3.org/2000/xmlns/', $nsprefix) != $uri)) |
|
329 | 329 | {//Remove namespace |
330 | - $parent=$this->myDOMNode->ownerElement; |
|
330 | + $parent = $this->myDOMNode->ownerElement; |
|
331 | 331 | $parent->removeAttributeNode($this->myDOMNode); |
332 | - $parent->setAttribute($this->myDOMNode->localName,$this->myDOMNode->nodeValue); |
|
333 | - $this->myDOMNode=$parent->getAttributeNode($this->myDOMNode->localName); |
|
332 | + $parent->setAttribute($this->myDOMNode->localName, $this->myDOMNode->nodeValue); |
|
333 | + $this->myDOMNode = $parent->getAttributeNode($this->myDOMNode->localName); |
|
334 | 334 | return; |
335 | 335 | } |
336 | - $this->myDOMNode->ownerElement->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$nsprefix,$uri); |
|
336 | + $this->myDOMNode->ownerElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:'.$nsprefix, $uri); |
|
337 | 337 | } |
338 | 338 | } |
339 | - if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) |
|
339 | + if ($this->myDOMNode->nodeType === XML_ATTRIBUTE_NODE) |
|
340 | 340 | { |
341 | - $parent=$this->myDOMNode->ownerElement; |
|
341 | + $parent = $this->myDOMNode->ownerElement; |
|
342 | 342 | $parent->removeAttributeNode($this->myDOMNode); |
343 | - $parent->setAttributeNS($uri,$nsprefix.':'.$this->myDOMNode->localName,$this->myDOMNode->nodeValue); |
|
344 | - $this->myDOMNode=$parent->getAttributeNodeNS($uri,$this->myDOMNode->localName); |
|
343 | + $parent->setAttributeNS($uri, $nsprefix.':'.$this->myDOMNode->localName, $this->myDOMNode->nodeValue); |
|
344 | + $this->myDOMNode = $parent->getAttributeNodeNS($uri, $this->myDOMNode->localName); |
|
345 | 345 | } |
346 | - elseif ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) |
|
346 | + elseif ($this->myDOMNode->nodeType === XML_ELEMENT_NODE) |
|
347 | 347 | { |
348 | - $NewNode=$this->myDOMNode->ownerDocument->createElementNS($uri,$nsprefix.':'.$this->myDOMNode->localName); |
|
348 | + $NewNode = $this->myDOMNode->ownerDocument->createElementNS($uri, $nsprefix.':'.$this->myDOMNode->localName); |
|
349 | 349 | foreach ($this->myDOMNode->attributes as $n) $NewNode->appendChild($n->cloneNode(true)); |
350 | 350 | foreach ($this->myDOMNode->childNodes as $n) $NewNode->appendChild($n->cloneNode(true)); |
351 | - $xpath=new DOMXPath($this->myDOMNode->ownerDocument); |
|
352 | - $myDOMNodeList=$xpath->query('namespace::*[name()!="xml"]',$this->myDOMNode); //Add old namespaces |
|
353 | - foreach ($myDOMNodeList as $n) $NewNode->setAttributeNS('http://www.w3.org/2000/xmlns/',$n->nodeName,$n->nodeValue); |
|
354 | - $this->myDOMNode->parentNode->replaceChild($NewNode,$this->myDOMNode); |
|
355 | - $this->myDOMNode=$NewNode; |
|
351 | + $xpath = new DOMXPath($this->myDOMNode->ownerDocument); |
|
352 | + $myDOMNodeList = $xpath->query('namespace::*[name()!="xml"]', $this->myDOMNode); //Add old namespaces |
|
353 | + foreach ($myDOMNodeList as $n) $NewNode->setAttributeNS('http://www.w3.org/2000/xmlns/', $n->nodeName, $n->nodeValue); |
|
354 | + $this->myDOMNode->parentNode->replaceChild($NewNode, $this->myDOMNode); |
|
355 | + $this->myDOMNode = $NewNode; |
|
356 | 356 | } |
357 | 357 | } |
358 | 358 | function unlink_node() |
359 | 359 | { |
360 | - if ($this->myDOMNode->parentNode!=null) |
|
360 | + if ($this->myDOMNode->parentNode != null) |
|
361 | 361 | { |
362 | - if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) $this->myDOMNode->parentNode->removeAttributeNode($this->myDOMNode); |
|
362 | + if ($this->myDOMNode->nodeType === XML_ATTRIBUTE_NODE) $this->myDOMNode->parentNode->removeAttributeNode($this->myDOMNode); |
|
363 | 363 | else $this->myDOMNode->parentNode->removeChild($this->myDOMNode); |
364 | 364 | } |
365 | 365 | } |
366 | - protected function _importNode($newnode) {return $this->myOwnerDocument===$newnode->myOwnerDocument ? $newnode->myDOMNode : $this->myOwnerDocument->myDOMNode->importNode($newnode->myDOMNode,true);} //To import DOMNode from another DOMDocument |
|
367 | - static function _newDOMElement($aDOMNode,$aOwnerDocument) |
|
366 | + protected function _importNode($newnode) {return $this->myOwnerDocument === $newnode->myOwnerDocument ? $newnode->myDOMNode : $this->myOwnerDocument->myDOMNode->importNode($newnode->myDOMNode, true); } //To import DOMNode from another DOMDocument |
|
367 | + static function _newDOMElement($aDOMNode, $aOwnerDocument) |
|
368 | 368 | {//Check the PHP5 DOMNode before creating a new associated PHP4 DOMNode wrapper |
369 | - if ($aDOMNode==null) return null; |
|
369 | + if ($aDOMNode == null) return null; |
|
370 | 370 | switch ($aDOMNode->nodeType) |
371 | 371 | { |
372 | - case XML_ELEMENT_NODE: return new php4DOMElement($aDOMNode,$aOwnerDocument); |
|
373 | - case XML_TEXT_NODE: return new php4DOMText($aDOMNode,$aOwnerDocument); |
|
374 | - case XML_ATTRIBUTE_NODE: return new php4DOMAttr($aDOMNode,$aOwnerDocument); |
|
375 | - case XML_PI_NODE: return new php4DomProcessingInstruction($aDOMNode,$aOwnerDocument); |
|
376 | - default: return new php4DOMNode($aDOMNode,$aOwnerDocument); |
|
372 | + case XML_ELEMENT_NODE: return new php4DOMElement($aDOMNode, $aOwnerDocument); |
|
373 | + case XML_TEXT_NODE: return new php4DOMText($aDOMNode, $aOwnerDocument); |
|
374 | + case XML_ATTRIBUTE_NODE: return new php4DOMAttr($aDOMNode, $aOwnerDocument); |
|
375 | + case XML_PI_NODE: return new php4DomProcessingInstruction($aDOMNode, $aOwnerDocument); |
|
376 | + default: return new php4DOMNode($aDOMNode, $aOwnerDocument); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
381 | 381 | class php4DomProcessingInstruction extends php4DOMNode |
382 | 382 | { |
383 | - function data() {return $this->myDOMNode->data;} |
|
384 | - function target() {return $this->myDOMNode->target;} |
|
383 | + function data() {return $this->myDOMNode->data; } |
|
384 | + function target() {return $this->myDOMNode->target; } |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | class php4DOMText extends php4DOMNode |
388 | 388 | { |
389 | 389 | function __get($name) |
390 | 390 | { |
391 | - if ($name==='tagname') return '#text'; |
|
391 | + if ($name === 'tagname') return '#text'; |
|
392 | 392 | else return parent::__get($name); |
393 | 393 | } |
394 | - function tagname() {return '#text';} |
|
395 | - function set_content($text) {$this->myDOMNode->nodeValue=$text; return true;} |
|
394 | + function tagname() {return '#text'; } |
|
395 | + function set_content($text) {$this->myDOMNode->nodeValue = $text; return true; } |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | if (!defined('XPATH_NODESET')) |
399 | 399 | { |
400 | - define('XPATH_UNDEFINED',0); |
|
401 | - define('XPATH_NODESET',1); |
|
402 | - define('XPATH_BOOLEAN',2); |
|
403 | - define('XPATH_NUMBER',3); |
|
404 | - define('XPATH_STRING',4); |
|
400 | + define('XPATH_UNDEFINED', 0); |
|
401 | + define('XPATH_NODESET', 1); |
|
402 | + define('XPATH_BOOLEAN', 2); |
|
403 | + define('XPATH_NUMBER', 3); |
|
404 | + define('XPATH_STRING', 4); |
|
405 | 405 | /*define('XPATH_POINT',5); |
406 | 406 | define('XPATH_RANGE',6); |
407 | 407 | define('XPATH_LOCATIONSET',7); |
@@ -413,36 +413,36 @@ discard block |
||
413 | 413 | { |
414 | 414 | private $myDOMNodelist; |
415 | 415 | public $nodeset; |
416 | - public $type=XPATH_UNDEFINED; |
|
416 | + public $type = XPATH_UNDEFINED; |
|
417 | 417 | public $value; |
418 | - function php4DOMNodelist($aDOMNodelist,$aOwnerDocument) |
|
418 | + function php4DOMNodelist($aDOMNodelist, $aOwnerDocument) |
|
419 | 419 | { |
420 | 420 | if (!isset($aDOMNodelist)) return; |
421 | - elseif (is_object($aDOMNodelist)||is_array($aDOMNodelist)) |
|
421 | + elseif (is_object($aDOMNodelist) || is_array($aDOMNodelist)) |
|
422 | 422 | { |
423 | - if ($aDOMNodelist->length>0) |
|
423 | + if ($aDOMNodelist->length > 0) |
|
424 | 424 | { |
425 | - $this->myDOMNodelist=$aDOMNodelist; |
|
426 | - $this->nodeset=array(); |
|
427 | - $this->type=XPATH_NODESET; |
|
428 | - $i=0; |
|
429 | - while ($node=$this->myDOMNodelist->item($i++)) $this->nodeset[]=php4DOMNode::_newDOMElement($node,$aOwnerDocument); |
|
425 | + $this->myDOMNodelist = $aDOMNodelist; |
|
426 | + $this->nodeset = array(); |
|
427 | + $this->type = XPATH_NODESET; |
|
428 | + $i = 0; |
|
429 | + while ($node = $this->myDOMNodelist->item($i++)) $this->nodeset[] = php4DOMNode::_newDOMElement($node, $aOwnerDocument); |
|
430 | 430 | } |
431 | 431 | } |
432 | - elseif (is_int($aDOMNodelist)||is_float($aDOMNodelist)) |
|
432 | + elseif (is_int($aDOMNodelist) || is_float($aDOMNodelist)) |
|
433 | 433 | { |
434 | - $this->type=XPATH_NUMBER; |
|
435 | - $this->value=$aDOMNodelist; |
|
434 | + $this->type = XPATH_NUMBER; |
|
435 | + $this->value = $aDOMNodelist; |
|
436 | 436 | } |
437 | 437 | elseif (is_bool($aDOMNodelist)) |
438 | 438 | { |
439 | - $this->type=XPATH_BOOLEAN; |
|
440 | - $this->value=$aDOMNodelist; |
|
439 | + $this->type = XPATH_BOOLEAN; |
|
440 | + $this->value = $aDOMNodelist; |
|
441 | 441 | } |
442 | 442 | elseif (is_string($aDOMNodelist)) |
443 | 443 | { |
444 | - $this->type=XPATH_STRING; |
|
445 | - $this->value=$aDOMNodelist; |
|
444 | + $this->type = XPATH_STRING; |
|
445 | + $this->value = $aDOMNodelist; |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | } |
@@ -454,46 +454,46 @@ discard block |
||
454 | 454 | function php4DOMXPath($dom_document) |
455 | 455 | { |
456 | 456 | //TODO: If $dom_document is a DomElement, make that default $contextnode and modify XPath. Ex: '/test' |
457 | - $this->myOwnerDocument=$dom_document->myOwnerDocument; |
|
458 | - $this->myDOMXPath=new DOMXPath($this->myOwnerDocument->myDOMNode); |
|
457 | + $this->myOwnerDocument = $dom_document->myOwnerDocument; |
|
458 | + $this->myDOMXPath = new DOMXPath($this->myOwnerDocument->myDOMNode); |
|
459 | 459 | } |
460 | - function xpath_eval($eval_str,$contextnode=null) |
|
460 | + function xpath_eval($eval_str, $contextnode = null) |
|
461 | 461 | { |
462 | - if (method_exists($this->myDOMXPath,'evaluate')) $xp=isset($contextnode) ? $this->myDOMXPath->evaluate($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->evaluate($eval_str); |
|
463 | - else $xp=isset($contextnode) ? $this->myDOMXPath->query($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->query($eval_str); |
|
464 | - $xp=new php4DOMNodelist($xp,$this->myOwnerDocument); |
|
465 | - return ($xp->type===XPATH_UNDEFINED) ? false : $xp; |
|
462 | + if (method_exists($this->myDOMXPath, 'evaluate')) $xp = isset($contextnode) ? $this->myDOMXPath->evaluate($eval_str, $contextnode->myDOMNode) : $this->myDOMXPath->evaluate($eval_str); |
|
463 | + else $xp = isset($contextnode) ? $this->myDOMXPath->query($eval_str, $contextnode->myDOMNode) : $this->myDOMXPath->query($eval_str); |
|
464 | + $xp = new php4DOMNodelist($xp, $this->myOwnerDocument); |
|
465 | + return ($xp->type === XPATH_UNDEFINED) ? false : $xp; |
|
466 | 466 | } |
467 | - function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);} |
|
467 | + function xpath_register_ns($prefix, $namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix, $namespaceURI); } |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | if (extension_loaded('xsl')) |
471 | 471 | {//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/ |
472 | - function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));} |
|
473 | - function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);} |
|
474 | - function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));} |
|
472 | + function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring)); } |
|
473 | + function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document); } |
|
474 | + function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile)); } |
|
475 | 475 | class php4DomXsltStylesheet |
476 | 476 | { |
477 | 477 | private $myxsltProcessor; |
478 | 478 | function php4DomXsltStylesheet($dom_document) |
479 | 479 | { |
480 | - $this->myxsltProcessor=new xsltProcessor(); |
|
480 | + $this->myxsltProcessor = new xsltProcessor(); |
|
481 | 481 | $this->myxsltProcessor->importStyleSheet($dom_document); |
482 | 482 | } |
483 | - function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false) |
|
483 | + function process($dom_document, $xslt_parameters = array(), $param_is_xpath = false) |
|
484 | 484 | { |
485 | - foreach ($xslt_parameters as $param=>$value) $this->myxsltProcessor->setParameter('',$param,$value); |
|
486 | - $myphp4DOMDocument=new php4DOMDocument(); |
|
487 | - $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode); |
|
485 | + foreach ($xslt_parameters as $param=>$value) $this->myxsltProcessor->setParameter('', $param, $value); |
|
486 | + $myphp4DOMDocument = new php4DOMDocument(); |
|
487 | + $myphp4DOMDocument->myDOMNode = $this->myxsltProcessor->transformToDoc($dom_document->myDOMNode); |
|
488 | 488 | return $myphp4DOMDocument; |
489 | 489 | } |
490 | - function result_dump_file($dom_document,$filename) |
|
490 | + function result_dump_file($dom_document, $filename) |
|
491 | 491 | { |
492 | - $html=$dom_document->myDOMNode->saveHTML(); |
|
493 | - file_put_contents($filename,$html); |
|
492 | + $html = $dom_document->myDOMNode->saveHTML(); |
|
493 | + file_put_contents($filename, $html); |
|
494 | 494 | return $html; |
495 | 495 | } |
496 | - function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();} |
|
496 | + function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML(); } |
|
497 | 497 | } |
498 | 498 | } |
499 | 499 | ?> |
@@ -55,8 +55,12 @@ discard block |
||
55 | 55 | { |
56 | 56 | $dom=new php4DOMDocument($mode); |
57 | 57 | $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); |
58 | - if ($errorMode) libxml_use_internal_errors(true); |
|
59 | - if (!$dom->myDOMNode->load($filename)) $dom=null; |
|
58 | + if ($errorMode) { |
|
59 | + libxml_use_internal_errors(true); |
|
60 | + } |
|
61 | + if (!$dom->myDOMNode->load($filename)) { |
|
62 | + $dom=null; |
|
63 | + } |
|
60 | 64 | if ($errorMode) |
61 | 65 | { |
62 | 66 | $error=array_map('_error_report',libxml_get_errors()); |
@@ -68,8 +72,12 @@ discard block |
||
68 | 72 | { |
69 | 73 | $dom=new php4DOMDocument($mode); |
70 | 74 | $errorMode=(func_num_args()>2)&&defined('LIBXML_VERSION'); |
71 | - if ($errorMode) libxml_use_internal_errors(true); |
|
72 | - if (!$dom->myDOMNode->loadXML($str)) $dom=null; |
|
75 | + if ($errorMode) { |
|
76 | + libxml_use_internal_errors(true); |
|
77 | + } |
|
78 | + if (!$dom->myDOMNode->loadXML($str)) { |
|
79 | + $dom=null; |
|
80 | + } |
|
73 | 81 | if ($errorMode) |
74 | 82 | { |
75 | 83 | $error=array_map('_error_report',libxml_get_errors()); |
@@ -80,8 +88,11 @@ discard block |
||
80 | 88 | function html_doc($html_doc,$from_file=false) |
81 | 89 | { |
82 | 90 | $dom=new php4DOMDocument(); |
83 | - if ($from_file) $result=$dom->myDOMNode->loadHTMLFile($html_doc); |
|
84 | - else $result=$dom->myDOMNode->loadHTML($html_doc); |
|
91 | + if ($from_file) { |
|
92 | + $result=$dom->myDOMNode->loadHTMLFile($html_doc); |
|
93 | + } else { |
|
94 | + $result=$dom->myDOMNode->loadHTML($html_doc); |
|
95 | + } |
|
85 | 96 | return $result ? $dom : null; |
86 | 97 | } |
87 | 98 | function html_doc_file($filename) {return html_doc($filename,true);} |
@@ -97,8 +108,11 @@ discard block |
||
97 | 108 | { |
98 | 109 | function __get($name) |
99 | 110 | { |
100 | - if ($name==='name') return $this->myDOMNode->name; |
|
101 | - else return parent::__get($name); |
|
111 | + if ($name==='name') { |
|
112 | + return $this->myDOMNode->name; |
|
113 | + } else { |
|
114 | + return parent::__get($name); |
|
115 | + } |
|
102 | 116 | } |
103 | 117 | function name() {return $this->myDOMNode->name;} |
104 | 118 | function set_content($text) {} |
@@ -113,14 +127,24 @@ discard block |
||
113 | 127 | { |
114 | 128 | $this->myDOMNode=new DOMDocument(); |
115 | 129 | $this->myOwnerDocument=$this; |
116 | - if ($mode & DOMXML_LOAD_VALIDATING) $this->myDOMNode->validateOnParse=true; |
|
117 | - if ($mode & DOMXML_LOAD_RECOVERING) $this->myDOMNode->recover=true; |
|
118 | - if ($mode & DOMXML_LOAD_SUBSTITUTE_ENTITIES) $this->myDOMNode->substituteEntities=true; |
|
119 | - if ($mode & DOMXML_LOAD_DONT_KEEP_BLANKS) $this->myDOMNode->preserveWhiteSpace=false; |
|
130 | + if ($mode & DOMXML_LOAD_VALIDATING) { |
|
131 | + $this->myDOMNode->validateOnParse=true; |
|
132 | + } |
|
133 | + if ($mode & DOMXML_LOAD_RECOVERING) { |
|
134 | + $this->myDOMNode->recover=true; |
|
135 | + } |
|
136 | + if ($mode & DOMXML_LOAD_SUBSTITUTE_ENTITIES) { |
|
137 | + $this->myDOMNode->substituteEntities=true; |
|
138 | + } |
|
139 | + if ($mode & DOMXML_LOAD_DONT_KEEP_BLANKS) { |
|
140 | + $this->myDOMNode->preserveWhiteSpace=false; |
|
141 | + } |
|
120 | 142 | } |
121 | 143 | function add_root($name) |
122 | 144 | { |
123 | - if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
|
145 | + if ($this->myDOMNode->hasChildNodes()) { |
|
146 | + $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
|
147 | + } |
|
124 | 148 | return new php4DOMElement($this->myDOMNode->appendChild($this->myDOMNode->createElement($name)),$this->myOwnerDocument); |
125 | 149 | } |
126 | 150 | function create_attribute($name,$value) |
@@ -134,8 +158,12 @@ discard block |
||
134 | 158 | function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);} |
135 | 159 | function create_element_ns($uri,$name,$prefix=null) |
136 | 160 | { |
137 | - if ($prefix==null) $prefix=$this->myDOMNode->lookupPrefix($uri); |
|
138 | - if (($prefix==null)&&(($this->myDOMNode->documentElement==null)||(!$this->myDOMNode->documentElement->isDefaultNamespace($uri)))) $prefix='a'.sprintf('%u',crc32($uri)); |
|
161 | + if ($prefix==null) { |
|
162 | + $prefix=$this->myDOMNode->lookupPrefix($uri); |
|
163 | + } |
|
164 | + if (($prefix==null)&&(($this->myDOMNode->documentElement==null)||(!$this->myDOMNode->documentElement->isDefaultNamespace($uri)))) { |
|
165 | + $prefix='a'.sprintf('%u',crc32($uri)); |
|
166 | + } |
|
139 | 167 | return new php4DOMElement($this->myDOMNode->createElementNS($uri,$prefix==null ? $name : $prefix.':'.$name),$this); |
140 | 168 | } |
141 | 169 | function create_entity_reference($content) {return new php4DOMNode($this->myDOMNode->createEntityReference($content),$this);} //By Walter Ebert 2007-01-22 |
@@ -155,15 +183,22 @@ discard block |
||
155 | 183 | $format0=$this->myDOMNode->formatOutput; |
156 | 184 | $this->myDOMNode->formatOutput=$format; |
157 | 185 | $encoding0=$this->myDOMNode->encoding; |
158 | - if ($encoding) $this->myDOMNode->encoding=$encoding; |
|
186 | + if ($encoding) { |
|
187 | + $this->myDOMNode->encoding=$encoding; |
|
188 | + } |
|
159 | 189 | $dump=$this->myDOMNode->saveXML(); |
160 | 190 | $this->myDOMNode->formatOutput=$format0; |
161 | - if ($encoding) $this->myDOMNode->encoding= $encoding0=='' ? 'UTF-8' : $encoding0; //UTF-8 is XML default encoding |
|
191 | + if ($encoding) { |
|
192 | + $this->myDOMNode->encoding= $encoding0=='' ? 'UTF-8' : $encoding0; |
|
193 | + } |
|
194 | + //UTF-8 is XML default encoding |
|
162 | 195 | return $dump; |
163 | 196 | } |
164 | 197 | function free() |
165 | 198 | { |
166 | - if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
|
199 | + if ($this->myDOMNode->hasChildNodes()) { |
|
200 | + $this->myDOMNode->removeChild($this->myDOMNode->firstChild); |
|
201 | + } |
|
167 | 202 | $this->myDOMNode=null; |
168 | 203 | $this->myOwnerDocument=null; |
169 | 204 | } |
@@ -173,8 +208,9 @@ discard block |
||
173 | 208 | $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); |
174 | 209 | $nodeSet=array(); |
175 | 210 | $i=0; |
176 | - if (isset($myDOMNodeList)) |
|
177 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this); |
|
211 | + if (isset($myDOMNodeList)) { |
|
212 | + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this); |
|
213 | + } |
|
178 | 214 | return $nodeSet; |
179 | 215 | } |
180 | 216 | function html_dump_mem() {return $this->myDOMNode->saveHTML();} |
@@ -187,8 +223,9 @@ discard block |
||
187 | 223 | { |
188 | 224 | function add_namespace($uri,$prefix) |
189 | 225 | { |
190 | - if ($this->myDOMNode->hasAttributeNS('http://www.w3.org/2000/xmlns/',$prefix)) return false; |
|
191 | - else |
|
226 | + if ($this->myDOMNode->hasAttributeNS('http://www.w3.org/2000/xmlns/',$prefix)) { |
|
227 | + return false; |
|
228 | + } else |
|
192 | 229 | { |
193 | 230 | $this->myDOMNode->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$prefix,$uri); //By Daniel Walker 2006-09-08 |
194 | 231 | return true; |
@@ -201,8 +238,9 @@ discard block |
||
201 | 238 | $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); |
202 | 239 | $nodeSet=array(); |
203 | 240 | $i=0; |
204 | - if (isset($myDOMNodeList)) |
|
205 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument); |
|
241 | + if (isset($myDOMNodeList)) { |
|
242 | + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument); |
|
243 | + } |
|
206 | 244 | return $nodeSet; |
207 | 245 | } |
208 | 246 | function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);} |
@@ -222,17 +260,23 @@ discard block |
||
222 | 260 | }*/ |
223 | 261 | function set_name($name) |
224 | 262 | { |
225 | - if ($this->myDOMNode->prefix=='') $newNode=$this->myDOMNode->ownerDocument->createElement($name); |
|
226 | - else $newNode=$this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI,$this->myDOMNode->prefix.':'.$name); |
|
263 | + if ($this->myDOMNode->prefix=='') { |
|
264 | + $newNode=$this->myDOMNode->ownerDocument->createElement($name); |
|
265 | + } else { |
|
266 | + $newNode=$this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI,$this->myDOMNode->prefix.':'.$name); |
|
267 | + } |
|
227 | 268 | $myDOMNodeList=$this->myDOMNode->attributes; |
228 | 269 | $i=0; |
229 | - if (isset($myDOMNodeList)) |
|
230 | - while ($node=$myDOMNodeList->item($i++)) |
|
270 | + if (isset($myDOMNodeList)) { |
|
271 | + while ($node=$myDOMNodeList->item($i++)) |
|
231 | 272 | if ($node->namespaceURI=='') $newNode->setAttribute($node->name,$node->value); |
232 | - else $newNode->setAttributeNS($node->namespaceURI,$node->nodeName,$node->value); |
|
273 | + } else { |
|
274 | + $newNode->setAttributeNS($node->namespaceURI,$node->nodeName,$node->value); |
|
275 | + } |
|
233 | 276 | $myDOMNodeList=$this->myDOMNode->childNodes; |
234 | - if (isset($myDOMNodeList)) |
|
235 | - while ($node=$myDOMNodeList->item(0)) $newNode->appendChild($node); |
|
277 | + if (isset($myDOMNodeList)) { |
|
278 | + while ($node=$myDOMNodeList->item(0)) $newNode->appendChild($node); |
|
279 | + } |
|
236 | 280 | $this->myDOMNode->parentNode->replaceChild($newNode,$this->myDOMNode); |
237 | 281 | $this->myDOMNode=$newNode; |
238 | 282 | return true; |
@@ -270,10 +314,14 @@ discard block |
||
270 | 314 | function attributes() |
271 | 315 | { |
272 | 316 | $myDOMNodeList=$this->myDOMNode->attributes; |
273 | - if (!(isset($myDOMNodeList)&&$this->myDOMNode->hasAttributes())) return null; |
|
317 | + if (!(isset($myDOMNodeList)&&$this->myDOMNode->hasAttributes())) { |
|
318 | + return null; |
|
319 | + } |
|
274 | 320 | $nodeSet=array(); |
275 | 321 | $i=0; |
276 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument); |
|
322 | + while ($node=$myDOMNodeList->item($i++)) { |
|
323 | + $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument); |
|
324 | + } |
|
277 | 325 | return $nodeSet; |
278 | 326 | } |
279 | 327 | function child_nodes() |
@@ -281,8 +329,9 @@ discard block |
||
281 | 329 | $myDOMNodeList=$this->myDOMNode->childNodes; |
282 | 330 | $nodeSet=array(); |
283 | 331 | $i=0; |
284 | - if (isset($myDOMNodeList)) |
|
285 | - while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=self::_newDOMElement($node,$this->myOwnerDocument); |
|
332 | + if (isset($myDOMNodeList)) { |
|
333 | + while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=self::_newDOMElement($node,$this->myOwnerDocument); |
|
334 | + } |
|
286 | 335 | return $nodeSet; |
287 | 336 | } |
288 | 337 | function children() {return $this->child_nodes();} |
@@ -342,15 +391,20 @@ discard block |
||
342 | 391 | $parent->removeAttributeNode($this->myDOMNode); |
343 | 392 | $parent->setAttributeNS($uri,$nsprefix.':'.$this->myDOMNode->localName,$this->myDOMNode->nodeValue); |
344 | 393 | $this->myDOMNode=$parent->getAttributeNodeNS($uri,$this->myDOMNode->localName); |
345 | - } |
|
346 | - elseif ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) |
|
394 | + } elseif ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) |
|
347 | 395 | { |
348 | 396 | $NewNode=$this->myDOMNode->ownerDocument->createElementNS($uri,$nsprefix.':'.$this->myDOMNode->localName); |
349 | - foreach ($this->myDOMNode->attributes as $n) $NewNode->appendChild($n->cloneNode(true)); |
|
350 | - foreach ($this->myDOMNode->childNodes as $n) $NewNode->appendChild($n->cloneNode(true)); |
|
397 | + foreach ($this->myDOMNode->attributes as $n) { |
|
398 | + $NewNode->appendChild($n->cloneNode(true)); |
|
399 | + } |
|
400 | + foreach ($this->myDOMNode->childNodes as $n) { |
|
401 | + $NewNode->appendChild($n->cloneNode(true)); |
|
402 | + } |
|
351 | 403 | $xpath=new DOMXPath($this->myDOMNode->ownerDocument); |
352 | 404 | $myDOMNodeList=$xpath->query('namespace::*[name()!="xml"]',$this->myDOMNode); //Add old namespaces |
353 | - foreach ($myDOMNodeList as $n) $NewNode->setAttributeNS('http://www.w3.org/2000/xmlns/',$n->nodeName,$n->nodeValue); |
|
405 | + foreach ($myDOMNodeList as $n) { |
|
406 | + $NewNode->setAttributeNS('http://www.w3.org/2000/xmlns/',$n->nodeName,$n->nodeValue); |
|
407 | + } |
|
354 | 408 | $this->myDOMNode->parentNode->replaceChild($NewNode,$this->myDOMNode); |
355 | 409 | $this->myDOMNode=$NewNode; |
356 | 410 | } |
@@ -359,14 +413,19 @@ discard block |
||
359 | 413 | { |
360 | 414 | if ($this->myDOMNode->parentNode!=null) |
361 | 415 | { |
362 | - if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) $this->myDOMNode->parentNode->removeAttributeNode($this->myDOMNode); |
|
363 | - else $this->myDOMNode->parentNode->removeChild($this->myDOMNode); |
|
416 | + if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) { |
|
417 | + $this->myDOMNode->parentNode->removeAttributeNode($this->myDOMNode); |
|
418 | + } else { |
|
419 | + $this->myDOMNode->parentNode->removeChild($this->myDOMNode); |
|
420 | + } |
|
364 | 421 | } |
365 | 422 | } |
366 | 423 | protected function _importNode($newnode) {return $this->myOwnerDocument===$newnode->myOwnerDocument ? $newnode->myDOMNode : $this->myOwnerDocument->myDOMNode->importNode($newnode->myDOMNode,true);} //To import DOMNode from another DOMDocument |
367 | 424 | static function _newDOMElement($aDOMNode,$aOwnerDocument) |
368 | 425 | {//Check the PHP5 DOMNode before creating a new associated PHP4 DOMNode wrapper |
369 | - if ($aDOMNode==null) return null; |
|
426 | + if ($aDOMNode==null) { |
|
427 | + return null; |
|
428 | + } |
|
370 | 429 | switch ($aDOMNode->nodeType) |
371 | 430 | { |
372 | 431 | case XML_ELEMENT_NODE: return new php4DOMElement($aDOMNode,$aOwnerDocument); |
@@ -388,8 +447,11 @@ discard block |
||
388 | 447 | { |
389 | 448 | function __get($name) |
390 | 449 | { |
391 | - if ($name==='tagname') return '#text'; |
|
392 | - else return parent::__get($name); |
|
450 | + if ($name==='tagname') { |
|
451 | + return '#text'; |
|
452 | + } else { |
|
453 | + return parent::__get($name); |
|
454 | + } |
|
393 | 455 | } |
394 | 456 | function tagname() {return '#text';} |
395 | 457 | function set_content($text) {$this->myDOMNode->nodeValue=$text; return true;} |
@@ -417,8 +479,9 @@ discard block |
||
417 | 479 | public $value; |
418 | 480 | function php4DOMNodelist($aDOMNodelist,$aOwnerDocument) |
419 | 481 | { |
420 | - if (!isset($aDOMNodelist)) return; |
|
421 | - elseif (is_object($aDOMNodelist)||is_array($aDOMNodelist)) |
|
482 | + if (!isset($aDOMNodelist)) { |
|
483 | + return; |
|
484 | + } elseif (is_object($aDOMNodelist)||is_array($aDOMNodelist)) |
|
422 | 485 | { |
423 | 486 | if ($aDOMNodelist->length>0) |
424 | 487 | { |
@@ -426,20 +489,19 @@ discard block |
||
426 | 489 | $this->nodeset=array(); |
427 | 490 | $this->type=XPATH_NODESET; |
428 | 491 | $i=0; |
429 | - while ($node=$this->myDOMNodelist->item($i++)) $this->nodeset[]=php4DOMNode::_newDOMElement($node,$aOwnerDocument); |
|
492 | + while ($node=$this->myDOMNodelist->item($i++)) { |
|
493 | + $this->nodeset[]=php4DOMNode::_newDOMElement($node,$aOwnerDocument); |
|
494 | + } |
|
430 | 495 | } |
431 | - } |
|
432 | - elseif (is_int($aDOMNodelist)||is_float($aDOMNodelist)) |
|
496 | + } elseif (is_int($aDOMNodelist)||is_float($aDOMNodelist)) |
|
433 | 497 | { |
434 | 498 | $this->type=XPATH_NUMBER; |
435 | 499 | $this->value=$aDOMNodelist; |
436 | - } |
|
437 | - elseif (is_bool($aDOMNodelist)) |
|
500 | + } elseif (is_bool($aDOMNodelist)) |
|
438 | 501 | { |
439 | 502 | $this->type=XPATH_BOOLEAN; |
440 | 503 | $this->value=$aDOMNodelist; |
441 | - } |
|
442 | - elseif (is_string($aDOMNodelist)) |
|
504 | + } elseif (is_string($aDOMNodelist)) |
|
443 | 505 | { |
444 | 506 | $this->type=XPATH_STRING; |
445 | 507 | $this->value=$aDOMNodelist; |
@@ -459,8 +521,11 @@ discard block |
||
459 | 521 | } |
460 | 522 | function xpath_eval($eval_str,$contextnode=null) |
461 | 523 | { |
462 | - if (method_exists($this->myDOMXPath,'evaluate')) $xp=isset($contextnode) ? $this->myDOMXPath->evaluate($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->evaluate($eval_str); |
|
463 | - else $xp=isset($contextnode) ? $this->myDOMXPath->query($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->query($eval_str); |
|
524 | + if (method_exists($this->myDOMXPath,'evaluate')) { |
|
525 | + $xp=isset($contextnode) ? $this->myDOMXPath->evaluate($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->evaluate($eval_str); |
|
526 | + } else { |
|
527 | + $xp=isset($contextnode) ? $this->myDOMXPath->query($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->query($eval_str); |
|
528 | + } |
|
464 | 529 | $xp=new php4DOMNodelist($xp,$this->myOwnerDocument); |
465 | 530 | return ($xp->type===XPATH_UNDEFINED) ? false : $xp; |
466 | 531 | } |
@@ -482,7 +547,9 @@ discard block |
||
482 | 547 | } |
483 | 548 | function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false) |
484 | 549 | { |
485 | - foreach ($xslt_parameters as $param=>$value) $this->myxsltProcessor->setParameter('',$param,$value); |
|
550 | + foreach ($xslt_parameters as $param=>$value) { |
|
551 | + $this->myxsltProcessor->setParameter('',$param,$value); |
|
552 | + } |
|
486 | 553 | $myphp4DOMDocument=new php4DOMDocument(); |
487 | 554 | $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode); |
488 | 555 | return $myphp4DOMDocument; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * This method returns the PEAR DB URL to use to connect to the database. |
64 | 64 | * |
65 | - * @return a PEAR DB URL |
|
65 | + * @return string PEAR DB URL |
|
66 | 66 | * |
67 | 67 | * @private |
68 | 68 | */ |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | /** |
106 | 106 | * This method returns the name of the table where PGT's are stored. |
107 | 107 | * |
108 | - * @return the name of a table. |
|
108 | + * @return string name of a table. |
|
109 | 109 | * |
110 | 110 | * @private |
111 | 111 | */ |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * This method returns an informational string giving the type of storage |
123 | 123 | * used by the object (used for debugging purposes). |
124 | 124 | * |
125 | - * @return an informational string. |
|
125 | + * @return string informational string. |
|
126 | 126 | * @public |
127 | 127 | */ |
128 | 128 | function getStorageType() |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | /** |
149 | 149 | * The class constructor, called by CASClient::SetPGTStorageDB(). |
150 | 150 | * |
151 | - * @param $cas_parent the CASClient instance that creates the object. |
|
151 | + * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
152 | 152 | * @param $user the user to access the data with |
153 | 153 | * @param $password the user's password |
154 | 154 | * @param $database_type the type of the database hosting the data |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @hideinitializer |
58 | 58 | * @private |
59 | 59 | */ |
60 | - var $_url=''; |
|
60 | + var $_url = ''; |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * This method returns the PEAR DB URL to use to connect to the database. |
@@ -159,18 +159,18 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @public |
161 | 161 | */ |
162 | - function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) |
|
162 | + function PGTStorageDB($cas_parent, $user, $password, $database_type, $hostname, $port, $database, $table) |
|
163 | 163 | { |
164 | 164 | phpCAS::traceBegin(); |
165 | 165 | |
166 | 166 | // call the ancestor's constructor |
167 | 167 | $this->PGTStorage($cas_parent); |
168 | 168 | |
169 | - if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | - if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | - if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | - if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | - if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
169 | + if (empty($database_type)) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | + if (empty($hostname)) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | + if ($port == 0) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | + if (empty($database)) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | + if (empty($table)) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
174 | 174 | |
175 | 175 | // build and store the PEAR DB URL |
176 | 176 | $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | { |
193 | 193 | phpCAS::traceBegin(); |
194 | 194 | // if the storage has already been initialized, return immediatly |
195 | - if ( $this->isInitialized() ) |
|
195 | + if ($this->isInitialized()) |
|
196 | 196 | return; |
197 | 197 | // call the ancestor's method (mark as initialized) |
198 | 198 | parent::init(); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | |
206 | 206 | // try to connect to the database |
207 | 207 | $this->_link = DB::connect($this->getURL()); |
208 | - if ( DB::isError($this->_link) ) { |
|
208 | + if (DB::isError($this->_link)) { |
|
209 | 209 | phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); |
210 | 210 | } |
211 | 211 | var_dump($this->_link); |
@@ -166,11 +166,21 @@ discard block |
||
166 | 166 | // call the ancestor's constructor |
167 | 167 | $this->PGTStorage($cas_parent); |
168 | 168 | |
169 | - if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | - if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | - if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | - if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | - if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
169 | + if ( empty($database_type) ) { |
|
170 | + $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
171 | + } |
|
172 | + if ( empty($hostname) ) { |
|
173 | + $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
174 | + } |
|
175 | + if ( $port==0 ) { |
|
176 | + $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
177 | + } |
|
178 | + if ( empty($database) ) { |
|
179 | + $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
180 | + } |
|
181 | + if ( empty($table) ) { |
|
182 | + $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
183 | + } |
|
174 | 184 | |
175 | 185 | // build and store the PEAR DB URL |
176 | 186 | $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; |
@@ -192,8 +202,9 @@ discard block |
||
192 | 202 | { |
193 | 203 | phpCAS::traceBegin(); |
194 | 204 | // if the storage has already been initialized, return immediatly |
195 | - if ( $this->isInitialized() ) |
|
196 | - return; |
|
205 | + if ( $this->isInitialized() ) { |
|
206 | + return; |
|
207 | + } |
|
197 | 208 | // call the ancestor's method (mark as initialized) |
198 | 209 | parent::init(); |
199 | 210 |
@@ -45,175 +45,175 @@ |
||
45 | 45 | |
46 | 46 | class PGTStorageDB extends PGTStorage |
47 | 47 | { |
48 | - /** |
|
49 | - * @addtogroup internalPGTStorageDB |
|
50 | - * @{ |
|
51 | - */ |
|
52 | - |
|
53 | - /** |
|
54 | - * a string representing a PEAR DB URL to connect to the database. Written by |
|
55 | - * PGTStorageDB::PGTStorageDB(), read by getURL(). |
|
56 | - * |
|
57 | - * @hideinitializer |
|
58 | - * @private |
|
59 | - */ |
|
60 | - var $_url=''; |
|
61 | - |
|
62 | - /** |
|
63 | - * This method returns the PEAR DB URL to use to connect to the database. |
|
64 | - * |
|
65 | - * @return a PEAR DB URL |
|
66 | - * |
|
67 | - * @private |
|
68 | - */ |
|
69 | - function getURL() |
|
48 | + /** |
|
49 | + * @addtogroup internalPGTStorageDB |
|
50 | + * @{ |
|
51 | + */ |
|
52 | + |
|
53 | + /** |
|
54 | + * a string representing a PEAR DB URL to connect to the database. Written by |
|
55 | + * PGTStorageDB::PGTStorageDB(), read by getURL(). |
|
56 | + * |
|
57 | + * @hideinitializer |
|
58 | + * @private |
|
59 | + */ |
|
60 | + var $_url=''; |
|
61 | + |
|
62 | + /** |
|
63 | + * This method returns the PEAR DB URL to use to connect to the database. |
|
64 | + * |
|
65 | + * @return a PEAR DB URL |
|
66 | + * |
|
67 | + * @private |
|
68 | + */ |
|
69 | + function getURL() |
|
70 | 70 | { |
71 | - return $this->_url; |
|
71 | + return $this->_url; |
|
72 | 72 | } |
73 | 73 | |
74 | - /** |
|
75 | - * The handle of the connection to the database where PGT's are stored. Written by |
|
76 | - * PGTStorageDB::init(), read by getLink(). |
|
77 | - * |
|
78 | - * @hideinitializer |
|
79 | - * @private |
|
80 | - */ |
|
81 | - var $_link = null; |
|
82 | - |
|
83 | - /** |
|
84 | - * This method returns the handle of the connection to the database where PGT's are |
|
85 | - * stored. |
|
86 | - * |
|
87 | - * @return a handle of connection. |
|
88 | - * |
|
89 | - * @private |
|
90 | - */ |
|
91 | - function getLink() |
|
74 | + /** |
|
75 | + * The handle of the connection to the database where PGT's are stored. Written by |
|
76 | + * PGTStorageDB::init(), read by getLink(). |
|
77 | + * |
|
78 | + * @hideinitializer |
|
79 | + * @private |
|
80 | + */ |
|
81 | + var $_link = null; |
|
82 | + |
|
83 | + /** |
|
84 | + * This method returns the handle of the connection to the database where PGT's are |
|
85 | + * stored. |
|
86 | + * |
|
87 | + * @return a handle of connection. |
|
88 | + * |
|
89 | + * @private |
|
90 | + */ |
|
91 | + function getLink() |
|
92 | 92 | { |
93 | - return $this->_link; |
|
93 | + return $this->_link; |
|
94 | 94 | } |
95 | 95 | |
96 | - /** |
|
97 | - * The name of the table where PGT's are stored. Written by |
|
98 | - * PGTStorageDB::PGTStorageDB(), read by getTable(). |
|
99 | - * |
|
100 | - * @hideinitializer |
|
101 | - * @private |
|
102 | - */ |
|
103 | - var $_table = ''; |
|
104 | - |
|
105 | - /** |
|
106 | - * This method returns the name of the table where PGT's are stored. |
|
107 | - * |
|
108 | - * @return the name of a table. |
|
109 | - * |
|
110 | - * @private |
|
111 | - */ |
|
112 | - function getTable() |
|
96 | + /** |
|
97 | + * The name of the table where PGT's are stored. Written by |
|
98 | + * PGTStorageDB::PGTStorageDB(), read by getTable(). |
|
99 | + * |
|
100 | + * @hideinitializer |
|
101 | + * @private |
|
102 | + */ |
|
103 | + var $_table = ''; |
|
104 | + |
|
105 | + /** |
|
106 | + * This method returns the name of the table where PGT's are stored. |
|
107 | + * |
|
108 | + * @return the name of a table. |
|
109 | + * |
|
110 | + * @private |
|
111 | + */ |
|
112 | + function getTable() |
|
113 | 113 | { |
114 | - return $this->_table; |
|
114 | + return $this->_table; |
|
115 | 115 | } |
116 | 116 | |
117 | - // ######################################################################## |
|
118 | - // DEBUGGING |
|
119 | - // ######################################################################## |
|
117 | + // ######################################################################## |
|
118 | + // DEBUGGING |
|
119 | + // ######################################################################## |
|
120 | 120 | |
121 | - /** |
|
122 | - * This method returns an informational string giving the type of storage |
|
123 | - * used by the object (used for debugging purposes). |
|
124 | - * |
|
125 | - * @return an informational string. |
|
126 | - * @public |
|
127 | - */ |
|
128 | - function getStorageType() |
|
121 | + /** |
|
122 | + * This method returns an informational string giving the type of storage |
|
123 | + * used by the object (used for debugging purposes). |
|
124 | + * |
|
125 | + * @return an informational string. |
|
126 | + * @public |
|
127 | + */ |
|
128 | + function getStorageType() |
|
129 | 129 | { |
130 | - return "database"; |
|
130 | + return "database"; |
|
131 | 131 | } |
132 | 132 | |
133 | - /** |
|
134 | - * This method returns an informational string giving informations on the |
|
135 | - * parameters of the storage.(used for debugging purposes). |
|
136 | - * |
|
137 | - * @public |
|
138 | - */ |
|
139 | - function getStorageInfo() |
|
133 | + /** |
|
134 | + * This method returns an informational string giving informations on the |
|
135 | + * parameters of the storage.(used for debugging purposes). |
|
136 | + * |
|
137 | + * @public |
|
138 | + */ |
|
139 | + function getStorageInfo() |
|
140 | 140 | { |
141 | - return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\''; |
|
141 | + return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\''; |
|
142 | 142 | } |
143 | 143 | |
144 | - // ######################################################################## |
|
145 | - // CONSTRUCTOR |
|
146 | - // ######################################################################## |
|
144 | + // ######################################################################## |
|
145 | + // CONSTRUCTOR |
|
146 | + // ######################################################################## |
|
147 | 147 | |
148 | - /** |
|
149 | - * The class constructor, called by CASClient::SetPGTStorageDB(). |
|
150 | - * |
|
151 | - * @param $cas_parent the CASClient instance that creates the object. |
|
152 | - * @param $user the user to access the data with |
|
153 | - * @param $password the user's password |
|
154 | - * @param $database_type the type of the database hosting the data |
|
155 | - * @param $hostname the server hosting the database |
|
156 | - * @param $port the port the server is listening on |
|
157 | - * @param $database the name of the database |
|
158 | - * @param $table the name of the table storing the data |
|
159 | - * |
|
160 | - * @public |
|
161 | - */ |
|
162 | - function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) |
|
148 | + /** |
|
149 | + * The class constructor, called by CASClient::SetPGTStorageDB(). |
|
150 | + * |
|
151 | + * @param $cas_parent the CASClient instance that creates the object. |
|
152 | + * @param $user the user to access the data with |
|
153 | + * @param $password the user's password |
|
154 | + * @param $database_type the type of the database hosting the data |
|
155 | + * @param $hostname the server hosting the database |
|
156 | + * @param $port the port the server is listening on |
|
157 | + * @param $database the name of the database |
|
158 | + * @param $table the name of the table storing the data |
|
159 | + * |
|
160 | + * @public |
|
161 | + */ |
|
162 | + function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) |
|
163 | 163 | { |
164 | - phpCAS::traceBegin(); |
|
164 | + phpCAS::traceBegin(); |
|
165 | 165 | |
166 | - // call the ancestor's constructor |
|
167 | - $this->PGTStorage($cas_parent); |
|
166 | + // call the ancestor's constructor |
|
167 | + $this->PGTStorage($cas_parent); |
|
168 | 168 | |
169 | - if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | - if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | - if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | - if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | - if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
169 | + if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | + if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | + if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | + if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | + if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
174 | 174 | |
175 | - // build and store the PEAR DB URL |
|
176 | - $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; |
|
175 | + // build and store the PEAR DB URL |
|
176 | + $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; |
|
177 | 177 | |
178 | - // XXX should use setURL and setTable |
|
179 | - phpCAS::traceEnd(); |
|
178 | + // XXX should use setURL and setTable |
|
179 | + phpCAS::traceEnd(); |
|
180 | 180 | } |
181 | 181 | |
182 | - // ######################################################################## |
|
183 | - // INITIALIZATION |
|
184 | - // ######################################################################## |
|
182 | + // ######################################################################## |
|
183 | + // INITIALIZATION |
|
184 | + // ######################################################################## |
|
185 | 185 | |
186 | - /** |
|
187 | - * This method is used to initialize the storage. Halts on error. |
|
188 | - * |
|
189 | - * @public |
|
190 | - */ |
|
191 | - function init() |
|
186 | + /** |
|
187 | + * This method is used to initialize the storage. Halts on error. |
|
188 | + * |
|
189 | + * @public |
|
190 | + */ |
|
191 | + function init() |
|
192 | 192 | { |
193 | - phpCAS::traceBegin(); |
|
194 | - // if the storage has already been initialized, return immediatly |
|
195 | - if ( $this->isInitialized() ) |
|
196 | - return; |
|
197 | - // call the ancestor's method (mark as initialized) |
|
198 | - parent::init(); |
|
193 | + phpCAS::traceBegin(); |
|
194 | + // if the storage has already been initialized, return immediatly |
|
195 | + if ( $this->isInitialized() ) |
|
196 | + return; |
|
197 | + // call the ancestor's method (mark as initialized) |
|
198 | + parent::init(); |
|
199 | 199 | |
200 | - //include phpDB library (the test was introduced in release 0.4.8 for |
|
201 | - //the integration into Tikiwiki). |
|
202 | - if (!class_exists('DB')) { |
|
203 | - include_once('DB.php'); |
|
204 | - } |
|
205 | - |
|
206 | - // try to connect to the database |
|
207 | - $this->_link = DB::connect($this->getURL()); |
|
208 | - if ( DB::isError($this->_link) ) { |
|
209 | - phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); |
|
210 | - } |
|
211 | - // Dump into trace |
|
212 | - var_dump($this->_link); |
|
213 | - phpCAS::traceBEnd(); |
|
200 | + //include phpDB library (the test was introduced in release 0.4.8 for |
|
201 | + //the integration into Tikiwiki). |
|
202 | + if (!class_exists('DB')) { |
|
203 | + include_once('DB.php'); |
|
204 | + } |
|
205 | + |
|
206 | + // try to connect to the database |
|
207 | + $this->_link = DB::connect($this->getURL()); |
|
208 | + if ( DB::isError($this->_link) ) { |
|
209 | + phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); |
|
210 | + } |
|
211 | + // Dump into trace |
|
212 | + var_dump($this->_link); |
|
213 | + phpCAS::traceBEnd(); |
|
214 | 214 | } |
215 | 215 | |
216 | - /** @} */ |
|
216 | + /** @} */ |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | ?> |
220 | 220 | \ No newline at end of file |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * This method returns an informational string giving the type of storage |
99 | 99 | * used by the object (used for debugging purposes). |
100 | 100 | * |
101 | - * @return an informational string. |
|
101 | + * @return string informational string. |
|
102 | 102 | * @public |
103 | 103 | */ |
104 | 104 | function getStorageType() |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * This method returns an informational string giving informations on the |
111 | 111 | * parameters of the storage.(used for debugging purposes). |
112 | 112 | * |
113 | - * @return an informational string. |
|
113 | + * @return string informational string. |
|
114 | 114 | * @public |
115 | 115 | */ |
116 | 116 | function getStorageInfo() |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | /** |
126 | 126 | * The class constructor, called by CASClient::SetPGTStorageFile(). |
127 | 127 | * |
128 | - * @param $cas_parent the CASClient instance that creates the object. |
|
129 | - * @param $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | - * @param $path the path where the PGT's should be stored |
|
128 | + * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
129 | + * @param string $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | + * @param string $path the path where the PGT's should be stored |
|
131 | 131 | * |
132 | 132 | * @public |
133 | 133 | */ |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @param $pgt_iou the PGT iou. |
204 | 204 | * |
205 | - * @return a filename |
|
205 | + * @return string filename |
|
206 | 206 | * @private |
207 | 207 | */ |
208 | 208 | function getPGTIouFilename($pgt_iou) |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @param $pgt_iou the PGT iou |
245 | 245 | * |
246 | - * @return the corresponding PGT, or FALSE on error |
|
246 | + * @return false|string corresponding PGT, or FALSE on error |
|
247 | 247 | * |
248 | 248 | * @public |
249 | 249 | */ |
@@ -163,12 +163,12 @@ |
||
163 | 163 | $this->_path = $path; |
164 | 164 | // check the format and store it |
165 | 165 | switch ($format) { |
166 | - case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
167 | - case CAS_PGT_STORAGE_FILE_FORMAT_XML: |
|
168 | - $this->_format = $format; |
|
169 | - break; |
|
170 | - default: |
|
171 | - phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
166 | + case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
167 | + case CAS_PGT_STORAGE_FILE_FORMAT_XML: |
|
168 | + $this->_format = $format; |
|
169 | + break; |
|
170 | + default: |
|
171 | + phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | 172 | } |
173 | 173 | phpCAS::traceEnd(); |
174 | 174 | } |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @public |
133 | 133 | */ |
134 | - function PGTStorageFile($cas_parent,$format,$path) |
|
134 | + function PGTStorageFile($cas_parent, $format, $path) |
|
135 | 135 | { |
136 | 136 | phpCAS::traceBegin(); |
137 | 137 | // call the ancestor's constructor |
138 | 138 | $this->PGTStorage($cas_parent); |
139 | 139 | |
140 | - if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | - if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
140 | + if (empty($format)) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | + if (empty($path)) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
142 | 142 | |
143 | 143 | // check that the path is an absolute path |
144 | - if (getenv("OS")=="Windows_NT"){ |
|
144 | + if (getenv("OS") == "Windows_NT") { |
|
145 | 145 | |
146 | 146 | if (!preg_match('`^[a-zA-Z]:`', $path)) { |
147 | 147 | phpCAS::error('an absolute path is needed for PGT storage to file'); |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | else |
152 | 152 | { |
153 | 153 | |
154 | - if ( $path[0] != '/' ) { |
|
154 | + if ($path[0] != '/') { |
|
155 | 155 | phpCAS::error('an absolute path is needed for PGT storage to file'); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // store the path (with a leading and trailing '/') |
159 | - $path = preg_replace('|[/]*$|','/',$path); |
|
160 | - $path = preg_replace('|^[/]*|','/',$path); |
|
159 | + $path = preg_replace('|[/]*$|', '/', $path); |
|
160 | + $path = preg_replace('|^[/]*|', '/', $path); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | $this->_path = $path; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | { |
187 | 187 | phpCAS::traceBegin(); |
188 | 188 | // if the storage has already been initialized, return immediatly |
189 | - if ( $this->isInitialized() ) |
|
189 | + if ($this->isInitialized()) |
|
190 | 190 | return; |
191 | 191 | // call the ancestor's method (mark as initialized) |
192 | 192 | parent::init(); |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @public |
224 | 224 | */ |
225 | - function write($pgt,$pgt_iou) |
|
225 | + function write($pgt, $pgt_iou) |
|
226 | 226 | { |
227 | 227 | phpCAS::traceBegin(); |
228 | 228 | $fname = $this->getPGTIouFilename($pgt_iou); |
229 | - if ( $f=fopen($fname,"w") ) { |
|
230 | - if ( fputs($f,$pgt) === FALSE ) { |
|
229 | + if ($f = fopen($fname, "w")) { |
|
230 | + if (fputs($f, $pgt) === FALSE) { |
|
231 | 231 | phpCAS::error('could not write PGT to `'.$fname.'\''); |
232 | 232 | } |
233 | 233 | fclose($f); |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | phpCAS::traceBegin(); |
253 | 253 | $pgt = FALSE; |
254 | 254 | $fname = $this->getPGTIouFilename($pgt_iou); |
255 | - if ( !($f=fopen($fname,"r")) ) { |
|
255 | + if (!($f = fopen($fname, "r"))) { |
|
256 | 256 | phpCAS::trace('could not open `'.$fname.'\''); |
257 | 257 | } else { |
258 | - if ( ($pgt=fgets($f)) === FALSE ) { |
|
258 | + if (($pgt = fgets($f)) === FALSE) { |
|
259 | 259 | phpCAS::trace('could not read PGT from `'.$fname.'\''); |
260 | 260 | } |
261 | 261 | fclose($f); |
@@ -137,8 +137,12 @@ discard block |
||
137 | 137 | // call the ancestor's constructor |
138 | 138 | $this->PGTStorage($cas_parent); |
139 | 139 | |
140 | - if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | - if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
140 | + if (empty($format) ) { |
|
141 | + $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
142 | + } |
|
143 | + if (empty($path) ) { |
|
144 | + $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
145 | + } |
|
142 | 146 | |
143 | 147 | // check that the path is an absolute path |
144 | 148 | if (getenv("OS")=="Windows_NT"){ |
@@ -147,8 +151,7 @@ discard block |
||
147 | 151 | phpCAS::error('an absolute path is needed for PGT storage to file'); |
148 | 152 | } |
149 | 153 | |
150 | - } |
|
151 | - else |
|
154 | + } else |
|
152 | 155 | { |
153 | 156 | |
154 | 157 | if ( $path[0] != '/' ) { |
@@ -186,8 +189,9 @@ discard block |
||
186 | 189 | { |
187 | 190 | phpCAS::traceBegin(); |
188 | 191 | // if the storage has already been initialized, return immediatly |
189 | - if ( $this->isInitialized() ) |
|
190 | - return; |
|
192 | + if ( $this->isInitialized() ) { |
|
193 | + return; |
|
194 | + } |
|
191 | 195 | // call the ancestor's method (mark as initialized) |
192 | 196 | parent::init(); |
193 | 197 | phpCAS::traceEnd(); |
@@ -44,231 +44,231 @@ |
||
44 | 44 | |
45 | 45 | class PGTStorageFile extends PGTStorage |
46 | 46 | { |
47 | - /** |
|
48 | - * @addtogroup internalPGTStorageFile |
|
49 | - * @{ |
|
50 | - */ |
|
47 | + /** |
|
48 | + * @addtogroup internalPGTStorageFile |
|
49 | + * @{ |
|
50 | + */ |
|
51 | 51 | |
52 | - /** |
|
53 | - * a string telling where PGT's should be stored on the filesystem. Written by |
|
54 | - * PGTStorageFile::PGTStorageFile(), read by getPath(). |
|
55 | - * |
|
56 | - * @private |
|
57 | - */ |
|
58 | - var $_path; |
|
52 | + /** |
|
53 | + * a string telling where PGT's should be stored on the filesystem. Written by |
|
54 | + * PGTStorageFile::PGTStorageFile(), read by getPath(). |
|
55 | + * |
|
56 | + * @private |
|
57 | + */ |
|
58 | + var $_path; |
|
59 | 59 | |
60 | - /** |
|
61 | - * This method returns the name of the directory where PGT's should be stored |
|
62 | - * on the filesystem. |
|
63 | - * |
|
64 | - * @return the name of a directory (with leading and trailing '/') |
|
65 | - * |
|
66 | - * @private |
|
67 | - */ |
|
68 | - function getPath() |
|
60 | + /** |
|
61 | + * This method returns the name of the directory where PGT's should be stored |
|
62 | + * on the filesystem. |
|
63 | + * |
|
64 | + * @return the name of a directory (with leading and trailing '/') |
|
65 | + * |
|
66 | + * @private |
|
67 | + */ |
|
68 | + function getPath() |
|
69 | 69 | { |
70 | - return $this->_path; |
|
70 | + return $this->_path; |
|
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * a string telling the format to use to store PGT's (plain or xml). Written by |
|
75 | - * PGTStorageFile::PGTStorageFile(), read by getFormat(). |
|
76 | - * |
|
77 | - * @private |
|
78 | - */ |
|
79 | - var $_format; |
|
73 | + /** |
|
74 | + * a string telling the format to use to store PGT's (plain or xml). Written by |
|
75 | + * PGTStorageFile::PGTStorageFile(), read by getFormat(). |
|
76 | + * |
|
77 | + * @private |
|
78 | + */ |
|
79 | + var $_format; |
|
80 | 80 | |
81 | - /** |
|
82 | - * This method returns the format to use when storing PGT's on the filesystem. |
|
83 | - * |
|
84 | - * @return a string corresponding to the format used (plain or xml). |
|
85 | - * |
|
86 | - * @private |
|
87 | - */ |
|
88 | - function getFormat() |
|
81 | + /** |
|
82 | + * This method returns the format to use when storing PGT's on the filesystem. |
|
83 | + * |
|
84 | + * @return a string corresponding to the format used (plain or xml). |
|
85 | + * |
|
86 | + * @private |
|
87 | + */ |
|
88 | + function getFormat() |
|
89 | 89 | { |
90 | - return $this->_format; |
|
90 | + return $this->_format; |
|
91 | 91 | } |
92 | 92 | |
93 | - // ######################################################################## |
|
94 | - // DEBUGGING |
|
95 | - // ######################################################################## |
|
93 | + // ######################################################################## |
|
94 | + // DEBUGGING |
|
95 | + // ######################################################################## |
|
96 | 96 | |
97 | - /** |
|
98 | - * This method returns an informational string giving the type of storage |
|
99 | - * used by the object (used for debugging purposes). |
|
100 | - * |
|
101 | - * @return an informational string. |
|
102 | - * @public |
|
103 | - */ |
|
104 | - function getStorageType() |
|
97 | + /** |
|
98 | + * This method returns an informational string giving the type of storage |
|
99 | + * used by the object (used for debugging purposes). |
|
100 | + * |
|
101 | + * @return an informational string. |
|
102 | + * @public |
|
103 | + */ |
|
104 | + function getStorageType() |
|
105 | 105 | { |
106 | - return "file"; |
|
106 | + return "file"; |
|
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * This method returns an informational string giving informations on the |
|
111 | - * parameters of the storage.(used for debugging purposes). |
|
112 | - * |
|
113 | - * @return an informational string. |
|
114 | - * @public |
|
115 | - */ |
|
116 | - function getStorageInfo() |
|
109 | + /** |
|
110 | + * This method returns an informational string giving informations on the |
|
111 | + * parameters of the storage.(used for debugging purposes). |
|
112 | + * |
|
113 | + * @return an informational string. |
|
114 | + * @public |
|
115 | + */ |
|
116 | + function getStorageInfo() |
|
117 | 117 | { |
118 | - return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\''; |
|
118 | + return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\''; |
|
119 | 119 | } |
120 | 120 | |
121 | - // ######################################################################## |
|
122 | - // CONSTRUCTOR |
|
123 | - // ######################################################################## |
|
121 | + // ######################################################################## |
|
122 | + // CONSTRUCTOR |
|
123 | + // ######################################################################## |
|
124 | 124 | |
125 | - /** |
|
126 | - * The class constructor, called by CASClient::SetPGTStorageFile(). |
|
127 | - * |
|
128 | - * @param $cas_parent the CASClient instance that creates the object. |
|
129 | - * @param $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | - * @param $path the path where the PGT's should be stored |
|
131 | - * |
|
132 | - * @public |
|
133 | - */ |
|
134 | - function PGTStorageFile($cas_parent,$format,$path) |
|
125 | + /** |
|
126 | + * The class constructor, called by CASClient::SetPGTStorageFile(). |
|
127 | + * |
|
128 | + * @param $cas_parent the CASClient instance that creates the object. |
|
129 | + * @param $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | + * @param $path the path where the PGT's should be stored |
|
131 | + * |
|
132 | + * @public |
|
133 | + */ |
|
134 | + function PGTStorageFile($cas_parent,$format,$path) |
|
135 | 135 | { |
136 | - phpCAS::traceBegin(); |
|
137 | - // call the ancestor's constructor |
|
138 | - $this->PGTStorage($cas_parent); |
|
136 | + phpCAS::traceBegin(); |
|
137 | + // call the ancestor's constructor |
|
138 | + $this->PGTStorage($cas_parent); |
|
139 | 139 | |
140 | - if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | - if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
140 | + if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | + if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
142 | 142 | |
143 | - // check that the path is an absolute path |
|
144 | - if (getenv("OS")=="Windows_NT"){ |
|
143 | + // check that the path is an absolute path |
|
144 | + if (getenv("OS")=="Windows_NT"){ |
|
145 | 145 | |
146 | - if (!preg_match('`^[a-zA-Z]:`', $path)) { |
|
147 | - phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
148 | - } |
|
146 | + if (!preg_match('`^[a-zA-Z]:`', $path)) { |
|
147 | + phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
148 | + } |
|
149 | 149 | |
150 | - } |
|
151 | - else |
|
152 | - { |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
153 | 153 | |
154 | - if ( $path[0] != '/' ) { |
|
155 | - phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
156 | - } |
|
154 | + if ( $path[0] != '/' ) { |
|
155 | + phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
156 | + } |
|
157 | 157 | |
158 | - // store the path (with a leading and trailing '/') |
|
159 | - $path = preg_replace('|[/]*$|','/',$path); |
|
160 | - $path = preg_replace('|^[/]*|','/',$path); |
|
161 | - } |
|
158 | + // store the path (with a leading and trailing '/') |
|
159 | + $path = preg_replace('|[/]*$|','/',$path); |
|
160 | + $path = preg_replace('|^[/]*|','/',$path); |
|
161 | + } |
|
162 | 162 | |
163 | - $this->_path = $path; |
|
164 | - // check the format and store it |
|
165 | - switch ($format) { |
|
166 | - case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
163 | + $this->_path = $path; |
|
164 | + // check the format and store it |
|
165 | + switch ($format) { |
|
166 | + case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
167 | 167 | case CAS_PGT_STORAGE_FILE_FORMAT_XML: |
168 | - $this->_format = $format; |
|
169 | - break; |
|
170 | - default: |
|
171 | - phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | - } |
|
173 | - phpCAS::traceEnd(); |
|
168 | + $this->_format = $format; |
|
169 | + break; |
|
170 | + default: |
|
171 | + phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | + } |
|
173 | + phpCAS::traceEnd(); |
|
174 | 174 | } |
175 | 175 | |
176 | - // ######################################################################## |
|
177 | - // INITIALIZATION |
|
178 | - // ######################################################################## |
|
176 | + // ######################################################################## |
|
177 | + // INITIALIZATION |
|
178 | + // ######################################################################## |
|
179 | 179 | |
180 | - /** |
|
181 | - * This method is used to initialize the storage. Halts on error. |
|
182 | - * |
|
183 | - * @public |
|
184 | - */ |
|
185 | - function init() |
|
180 | + /** |
|
181 | + * This method is used to initialize the storage. Halts on error. |
|
182 | + * |
|
183 | + * @public |
|
184 | + */ |
|
185 | + function init() |
|
186 | 186 | { |
187 | - phpCAS::traceBegin(); |
|
188 | - // if the storage has already been initialized, return immediatly |
|
189 | - if ( $this->isInitialized() ) |
|
190 | - return; |
|
191 | - // call the ancestor's method (mark as initialized) |
|
192 | - parent::init(); |
|
193 | - phpCAS::traceEnd(); |
|
187 | + phpCAS::traceBegin(); |
|
188 | + // if the storage has already been initialized, return immediatly |
|
189 | + if ( $this->isInitialized() ) |
|
190 | + return; |
|
191 | + // call the ancestor's method (mark as initialized) |
|
192 | + parent::init(); |
|
193 | + phpCAS::traceEnd(); |
|
194 | 194 | } |
195 | 195 | |
196 | - // ######################################################################## |
|
197 | - // PGT I/O |
|
198 | - // ######################################################################## |
|
196 | + // ######################################################################## |
|
197 | + // PGT I/O |
|
198 | + // ######################################################################## |
|
199 | 199 | |
200 | - /** |
|
201 | - * This method returns the filename corresponding to a PGT Iou. |
|
202 | - * |
|
203 | - * @param $pgt_iou the PGT iou. |
|
204 | - * |
|
205 | - * @return a filename |
|
206 | - * @private |
|
207 | - */ |
|
208 | - function getPGTIouFilename($pgt_iou) |
|
200 | + /** |
|
201 | + * This method returns the filename corresponding to a PGT Iou. |
|
202 | + * |
|
203 | + * @param $pgt_iou the PGT iou. |
|
204 | + * |
|
205 | + * @return a filename |
|
206 | + * @private |
|
207 | + */ |
|
208 | + function getPGTIouFilename($pgt_iou) |
|
209 | 209 | { |
210 | - phpCAS::traceBegin(); |
|
211 | - $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat(); |
|
212 | - phpCAS::traceEnd($filename); |
|
213 | - return $filename; |
|
210 | + phpCAS::traceBegin(); |
|
211 | + $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat(); |
|
212 | + phpCAS::traceEnd($filename); |
|
213 | + return $filename; |
|
214 | 214 | } |
215 | 215 | |
216 | - /** |
|
217 | - * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a |
|
218 | - * warning on error. |
|
219 | - * |
|
220 | - * @param $pgt the PGT |
|
221 | - * @param $pgt_iou the PGT iou |
|
222 | - * |
|
223 | - * @public |
|
224 | - */ |
|
225 | - function write($pgt,$pgt_iou) |
|
216 | + /** |
|
217 | + * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a |
|
218 | + * warning on error. |
|
219 | + * |
|
220 | + * @param $pgt the PGT |
|
221 | + * @param $pgt_iou the PGT iou |
|
222 | + * |
|
223 | + * @public |
|
224 | + */ |
|
225 | + function write($pgt,$pgt_iou) |
|
226 | 226 | { |
227 | - phpCAS::traceBegin(); |
|
228 | - $fname = $this->getPGTIouFilename($pgt_iou); |
|
229 | - if ( $f=fopen($fname,"w") ) { |
|
230 | - if ( fputs($f,$pgt) === FALSE ) { |
|
231 | - phpCAS::error('could not write PGT to `'.$fname.'\''); |
|
232 | - } |
|
233 | - fclose($f); |
|
234 | - } else { |
|
235 | - phpCAS::error('could not open `'.$fname.'\''); |
|
236 | - } |
|
237 | - phpCAS::traceEnd(); |
|
227 | + phpCAS::traceBegin(); |
|
228 | + $fname = $this->getPGTIouFilename($pgt_iou); |
|
229 | + if ( $f=fopen($fname,"w") ) { |
|
230 | + if ( fputs($f,$pgt) === FALSE ) { |
|
231 | + phpCAS::error('could not write PGT to `'.$fname.'\''); |
|
232 | + } |
|
233 | + fclose($f); |
|
234 | + } else { |
|
235 | + phpCAS::error('could not open `'.$fname.'\''); |
|
236 | + } |
|
237 | + phpCAS::traceEnd(); |
|
238 | 238 | } |
239 | 239 | |
240 | - /** |
|
241 | - * This method reads a PGT corresponding to a PGT Iou and deletes the |
|
242 | - * corresponding file. |
|
243 | - * |
|
244 | - * @param $pgt_iou the PGT iou |
|
245 | - * |
|
246 | - * @return the corresponding PGT, or FALSE on error |
|
247 | - * |
|
248 | - * @public |
|
249 | - */ |
|
250 | - function read($pgt_iou) |
|
240 | + /** |
|
241 | + * This method reads a PGT corresponding to a PGT Iou and deletes the |
|
242 | + * corresponding file. |
|
243 | + * |
|
244 | + * @param $pgt_iou the PGT iou |
|
245 | + * |
|
246 | + * @return the corresponding PGT, or FALSE on error |
|
247 | + * |
|
248 | + * @public |
|
249 | + */ |
|
250 | + function read($pgt_iou) |
|
251 | 251 | { |
252 | - phpCAS::traceBegin(); |
|
253 | - $pgt = FALSE; |
|
254 | - $fname = $this->getPGTIouFilename($pgt_iou); |
|
255 | - if ( !($f=fopen($fname,"r")) ) { |
|
256 | - phpCAS::trace('could not open `'.$fname.'\''); |
|
257 | - } else { |
|
258 | - if ( ($pgt=fgets($f)) === FALSE ) { |
|
259 | - phpCAS::trace('could not read PGT from `'.$fname.'\''); |
|
260 | - } |
|
261 | - fclose($f); |
|
262 | - } |
|
252 | + phpCAS::traceBegin(); |
|
253 | + $pgt = FALSE; |
|
254 | + $fname = $this->getPGTIouFilename($pgt_iou); |
|
255 | + if ( !($f=fopen($fname,"r")) ) { |
|
256 | + phpCAS::trace('could not open `'.$fname.'\''); |
|
257 | + } else { |
|
258 | + if ( ($pgt=fgets($f)) === FALSE ) { |
|
259 | + phpCAS::trace('could not read PGT from `'.$fname.'\''); |
|
260 | + } |
|
261 | + fclose($f); |
|
262 | + } |
|
263 | 263 | |
264 | - // delete the PGT file |
|
265 | - @unlink($fname); |
|
264 | + // delete the PGT file |
|
265 | + @unlink($fname); |
|
266 | 266 | |
267 | - phpCAS::traceEnd($pgt); |
|
268 | - return $pgt; |
|
267 | + phpCAS::traceEnd($pgt); |
|
268 | + return $pgt; |
|
269 | 269 | } |
270 | 270 | |
271 | - /** @} */ |
|
271 | + /** @} */ |
|
272 | 272 | |
273 | 273 | } |
274 | 274 |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * This method returns an error message set by PGTStorage::setErrorMessage(). |
128 | 128 | * |
129 | - * @return an error message when set by PGTStorage::setErrorMessage(), FALSE |
|
129 | + * @return boolean error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | 130 | * otherwise. |
131 | 131 | * |
132 | 132 | * @public |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * This method tells if the storage has already been intialized. |
155 | 155 | * |
156 | - * @return a boolean |
|
156 | + * @return boolean boolean |
|
157 | 157 | * |
158 | 158 | * @protected |
159 | 159 | */ |
@@ -44,167 +44,167 @@ |
||
44 | 44 | |
45 | 45 | class PGTStorage |
46 | 46 | { |
47 | - /** |
|
48 | - * @addtogroup internalPGTStorage |
|
49 | - * @{ |
|
50 | - */ |
|
51 | - |
|
52 | - // ######################################################################## |
|
53 | - // CONSTRUCTOR |
|
54 | - // ######################################################################## |
|
47 | + /** |
|
48 | + * @addtogroup internalPGTStorage |
|
49 | + * @{ |
|
50 | + */ |
|
51 | + |
|
52 | + // ######################################################################## |
|
53 | + // CONSTRUCTOR |
|
54 | + // ######################################################################## |
|
55 | 55 | |
56 | - /** |
|
57 | - * The constructor of the class, should be called only by inherited classes. |
|
58 | - * |
|
59 | - * @param $cas_parent the CASclient instance that creates the current object. |
|
60 | - * |
|
61 | - * @protected |
|
62 | - */ |
|
63 | - function PGTStorage($cas_parent) |
|
56 | + /** |
|
57 | + * The constructor of the class, should be called only by inherited classes. |
|
58 | + * |
|
59 | + * @param $cas_parent the CASclient instance that creates the current object. |
|
60 | + * |
|
61 | + * @protected |
|
62 | + */ |
|
63 | + function PGTStorage($cas_parent) |
|
64 | 64 | { |
65 | - phpCAS::traceBegin(); |
|
66 | - if ( !$cas_parent->isProxy() ) { |
|
67 | - phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
|
68 | - } |
|
69 | - phpCAS::traceEnd(); |
|
65 | + phpCAS::traceBegin(); |
|
66 | + if ( !$cas_parent->isProxy() ) { |
|
67 | + phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
|
68 | + } |
|
69 | + phpCAS::traceEnd(); |
|
70 | 70 | } |
71 | 71 | |
72 | - // ######################################################################## |
|
73 | - // DEBUGGING |
|
74 | - // ######################################################################## |
|
72 | + // ######################################################################## |
|
73 | + // DEBUGGING |
|
74 | + // ######################################################################## |
|
75 | 75 | |
76 | - /** |
|
77 | - * This virtual method returns an informational string giving the type of storage |
|
78 | - * used by the object (used for debugging purposes). |
|
79 | - * |
|
80 | - * @public |
|
81 | - */ |
|
82 | - function getStorageType() |
|
76 | + /** |
|
77 | + * This virtual method returns an informational string giving the type of storage |
|
78 | + * used by the object (used for debugging purposes). |
|
79 | + * |
|
80 | + * @public |
|
81 | + */ |
|
82 | + function getStorageType() |
|
83 | 83 | { |
84 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
84 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
85 | 85 | } |
86 | 86 | |
87 | - /** |
|
88 | - * This virtual method returns an informational string giving informations on the |
|
89 | - * parameters of the storage.(used for debugging purposes). |
|
90 | - * |
|
91 | - * @public |
|
92 | - */ |
|
93 | - function getStorageInfo() |
|
87 | + /** |
|
88 | + * This virtual method returns an informational string giving informations on the |
|
89 | + * parameters of the storage.(used for debugging purposes). |
|
90 | + * |
|
91 | + * @public |
|
92 | + */ |
|
93 | + function getStorageInfo() |
|
94 | 94 | { |
95 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
95 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
96 | 96 | } |
97 | 97 | |
98 | - // ######################################################################## |
|
99 | - // ERROR HANDLING |
|
100 | - // ######################################################################## |
|
98 | + // ######################################################################## |
|
99 | + // ERROR HANDLING |
|
100 | + // ######################################################################## |
|
101 | 101 | |
102 | - /** |
|
103 | - * string used to store an error message. Written by PGTStorage::setErrorMessage(), |
|
104 | - * read by PGTStorage::getErrorMessage(). |
|
105 | - * |
|
106 | - * @hideinitializer |
|
107 | - * @private |
|
108 | - * @deprecated not used. |
|
109 | - */ |
|
110 | - var $_error_message=FALSE; |
|
111 | - |
|
112 | - /** |
|
113 | - * This method sets en error message, which can be read later by |
|
114 | - * PGTStorage::getErrorMessage(). |
|
115 | - * |
|
116 | - * @param $error_message an error message |
|
117 | - * |
|
118 | - * @protected |
|
119 | - * @deprecated not used. |
|
120 | - */ |
|
121 | - function setErrorMessage($error_message) |
|
102 | + /** |
|
103 | + * string used to store an error message. Written by PGTStorage::setErrorMessage(), |
|
104 | + * read by PGTStorage::getErrorMessage(). |
|
105 | + * |
|
106 | + * @hideinitializer |
|
107 | + * @private |
|
108 | + * @deprecated not used. |
|
109 | + */ |
|
110 | + var $_error_message=FALSE; |
|
111 | + |
|
112 | + /** |
|
113 | + * This method sets en error message, which can be read later by |
|
114 | + * PGTStorage::getErrorMessage(). |
|
115 | + * |
|
116 | + * @param $error_message an error message |
|
117 | + * |
|
118 | + * @protected |
|
119 | + * @deprecated not used. |
|
120 | + */ |
|
121 | + function setErrorMessage($error_message) |
|
122 | 122 | { |
123 | - $this->_error_message = $error_message; |
|
123 | + $this->_error_message = $error_message; |
|
124 | 124 | } |
125 | 125 | |
126 | - /** |
|
127 | - * This method returns an error message set by PGTStorage::setErrorMessage(). |
|
128 | - * |
|
129 | - * @return an error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | - * otherwise. |
|
131 | - * |
|
132 | - * @public |
|
133 | - * @deprecated not used. |
|
134 | - */ |
|
135 | - function getErrorMessage() |
|
126 | + /** |
|
127 | + * This method returns an error message set by PGTStorage::setErrorMessage(). |
|
128 | + * |
|
129 | + * @return an error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | + * otherwise. |
|
131 | + * |
|
132 | + * @public |
|
133 | + * @deprecated not used. |
|
134 | + */ |
|
135 | + function getErrorMessage() |
|
136 | 136 | { |
137 | - return $this->_error_message; |
|
137 | + return $this->_error_message; |
|
138 | 138 | } |
139 | 139 | |
140 | - // ######################################################################## |
|
141 | - // INITIALIZATION |
|
142 | - // ######################################################################## |
|
143 | - |
|
144 | - /** |
|
145 | - * a boolean telling if the storage has already been initialized. Written by |
|
146 | - * PGTStorage::init(), read by PGTStorage::isInitialized(). |
|
147 | - * |
|
148 | - * @hideinitializer |
|
149 | - * @private |
|
150 | - */ |
|
151 | - var $_initialized = FALSE; |
|
152 | - |
|
153 | - /** |
|
154 | - * This method tells if the storage has already been intialized. |
|
155 | - * |
|
156 | - * @return a boolean |
|
157 | - * |
|
158 | - * @protected |
|
159 | - */ |
|
160 | - function isInitialized() |
|
140 | + // ######################################################################## |
|
141 | + // INITIALIZATION |
|
142 | + // ######################################################################## |
|
143 | + |
|
144 | + /** |
|
145 | + * a boolean telling if the storage has already been initialized. Written by |
|
146 | + * PGTStorage::init(), read by PGTStorage::isInitialized(). |
|
147 | + * |
|
148 | + * @hideinitializer |
|
149 | + * @private |
|
150 | + */ |
|
151 | + var $_initialized = FALSE; |
|
152 | + |
|
153 | + /** |
|
154 | + * This method tells if the storage has already been intialized. |
|
155 | + * |
|
156 | + * @return a boolean |
|
157 | + * |
|
158 | + * @protected |
|
159 | + */ |
|
160 | + function isInitialized() |
|
161 | 161 | { |
162 | - return $this->_initialized; |
|
162 | + return $this->_initialized; |
|
163 | 163 | } |
164 | 164 | |
165 | - /** |
|
166 | - * This virtual method initializes the object. |
|
167 | - * |
|
168 | - * @protected |
|
169 | - */ |
|
170 | - function init() |
|
165 | + /** |
|
166 | + * This virtual method initializes the object. |
|
167 | + * |
|
168 | + * @protected |
|
169 | + */ |
|
170 | + function init() |
|
171 | 171 | { |
172 | - $this->_initialized = TRUE; |
|
172 | + $this->_initialized = TRUE; |
|
173 | 173 | } |
174 | 174 | |
175 | - // ######################################################################## |
|
176 | - // PGT I/O |
|
177 | - // ######################################################################## |
|
178 | - |
|
179 | - /** |
|
180 | - * This virtual method stores a PGT and its corresponding PGT Iuo. |
|
181 | - * @note Should never be called. |
|
182 | - * |
|
183 | - * @param $pgt the PGT |
|
184 | - * @param $pgt_iou the PGT iou |
|
185 | - * |
|
186 | - * @protected |
|
187 | - */ |
|
188 | - function write($pgt,$pgt_iou) |
|
175 | + // ######################################################################## |
|
176 | + // PGT I/O |
|
177 | + // ######################################################################## |
|
178 | + |
|
179 | + /** |
|
180 | + * This virtual method stores a PGT and its corresponding PGT Iuo. |
|
181 | + * @note Should never be called. |
|
182 | + * |
|
183 | + * @param $pgt the PGT |
|
184 | + * @param $pgt_iou the PGT iou |
|
185 | + * |
|
186 | + * @protected |
|
187 | + */ |
|
188 | + function write($pgt,$pgt_iou) |
|
189 | 189 | { |
190 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
190 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
194 | - * This virtual method reads a PGT corresponding to a PGT Iou and deletes |
|
195 | - * the corresponding storage entry. |
|
196 | - * @note Should never be called. |
|
197 | - * |
|
198 | - * @param $pgt_iou the PGT iou |
|
199 | - * |
|
200 | - * @protected |
|
201 | - */ |
|
202 | - function read($pgt_iou) |
|
193 | + /** |
|
194 | + * This virtual method reads a PGT corresponding to a PGT Iou and deletes |
|
195 | + * the corresponding storage entry. |
|
196 | + * @note Should never be called. |
|
197 | + * |
|
198 | + * @param $pgt_iou the PGT iou |
|
199 | + * |
|
200 | + * @protected |
|
201 | + */ |
|
202 | + function read($pgt_iou) |
|
203 | 203 | { |
204 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
204 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
205 | 205 | } |
206 | 206 | |
207 | - /** @} */ |
|
207 | + /** @} */ |
|
208 | 208 | |
209 | 209 | } |
210 | 210 |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | function PGTStorage($cas_parent) |
64 | 64 | { |
65 | 65 | phpCAS::traceBegin(); |
66 | - if ( !$cas_parent->isProxy() ) { |
|
66 | + if (!$cas_parent->isProxy()) { |
|
67 | 67 | phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
68 | 68 | } |
69 | 69 | phpCAS::traceEnd(); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @private |
108 | 108 | * @deprecated not used. |
109 | 109 | */ |
110 | - var $_error_message=FALSE; |
|
110 | + var $_error_message = FALSE; |
|
111 | 111 | |
112 | 112 | /** |
113 | 113 | * This method sets en error message, which can be read later by |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @protected |
187 | 187 | */ |
188 | - function write($pgt,$pgt_iou) |
|
188 | + function write($pgt, $pgt_iou) |
|
189 | 189 | { |
190 | 190 | phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
191 | 191 | } |
@@ -33,6 +33,7 @@ discard block |
||
33 | 33 | * render to courses_list view |
34 | 34 | * @param string action |
35 | 35 | * @param string confirmation message(optional) |
36 | + * @param string $action |
|
36 | 37 | */ |
37 | 38 | public function courses_list($action, $message = '') |
38 | 39 | { |
@@ -79,7 +80,7 @@ discard block |
||
79 | 80 | /** |
80 | 81 | * It's used for listing courses with categories, |
81 | 82 | * render to courses_categories view |
82 | - * @param $action |
|
83 | + * @param string $action |
|
83 | 84 | * @param string $category_code |
84 | 85 | * @param string $message |
85 | 86 | * @param string $error |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param string $message confirmation message(optional) |
62 | 62 | * @param string $error error message(optional) |
63 | 63 | */ |
64 | - public function categories_list($action, $message='', $error='') |
|
64 | + public function categories_list($action, $message = '', $error = '') |
|
65 | 65 | { |
66 | 66 | $data = array(); |
67 | 67 | $data['user_course_categories'] = $this->model->get_user_course_categories(); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | // we need only the course codes as these will be used to match against the courses of the category |
118 | 118 | if ($user_courses != '') { |
119 | - foreach($user_courses as $key => $value) { |
|
119 | + foreach ($user_courses as $key => $value) { |
|
120 | 120 | $user_coursecodes[] = $value['code']; |
121 | 121 | } |
122 | 122 | } |
@@ -385,13 +385,13 @@ discard block |
||
385 | 385 | $html .= '</strong>'; |
386 | 386 | } else { |
387 | 387 | if (!empty($categoryCourses)) { |
388 | - $html .= '<a href="' . getCourseCategoryUrl( |
|
388 | + $html .= '<a href="'.getCourseCategoryUrl( |
|
389 | 389 | 1, |
390 | 390 | $limit['length'], |
391 | 391 | $categoryCode, |
392 | 392 | $hiddenLinks, |
393 | 393 | $action |
394 | - ) . '">'; |
|
394 | + ).'">'; |
|
395 | 395 | $html .= "$categoryName ($categoryCourses)"; |
396 | 396 | $html .= '</a>'; |
397 | 397 | } else { |
@@ -412,13 +412,13 @@ discard block |
||
412 | 412 | if ($code == $subCategory1Code) { |
413 | 413 | $html .= "<strong>$subCategory1Name ($subCategory1Courses)</strong>"; |
414 | 414 | } else { |
415 | - $html .= '<a href="' . getCourseCategoryUrl( |
|
415 | + $html .= '<a href="'.getCourseCategoryUrl( |
|
416 | 416 | 1, |
417 | 417 | $limit['length'], |
418 | 418 | $categoryCode, |
419 | 419 | $hiddenLinks, |
420 | 420 | $action |
421 | - ) . '">'; |
|
421 | + ).'">'; |
|
422 | 422 | $html .= "$subCategory1Name ($subCategory1Courses)"; |
423 | 423 | $html .= '</a>'; |
424 | 424 | } |
@@ -436,13 +436,13 @@ discard block |
||
436 | 436 | if ($code == $subCategory2Code) { |
437 | 437 | $html .= "<strong>$subCategory2Name ($subCategory2Courses)</strong>"; |
438 | 438 | } else { |
439 | - $html .= '<a href="' . getCourseCategoryUrl( |
|
439 | + $html .= '<a href="'.getCourseCategoryUrl( |
|
440 | 440 | 1, |
441 | 441 | $limit['length'], |
442 | 442 | $categoryCode, |
443 | 443 | $hiddenLinks, |
444 | 444 | $action |
445 | - ) . '">'; |
|
445 | + ).'">'; |
|
446 | 446 | $html .= "$subCategory2Name ($subCategory2Courses)"; |
447 | 447 | $html .= '</a>'; |
448 | 448 | } |
@@ -460,13 +460,13 @@ discard block |
||
460 | 460 | if ($code == $subCategory3Code) { |
461 | 461 | $html .= "<strong>$subCategory3Name ($subCategory3Courses)</strong>"; |
462 | 462 | } else { |
463 | - $html .= '<a href="' . getCourseCategoryUrl( |
|
463 | + $html .= '<a href="'.getCourseCategoryUrl( |
|
464 | 464 | 1, |
465 | 465 | $limit['length'], |
466 | 466 | $categoryCode, |
467 | 467 | $hiddenLinks, |
468 | 468 | $action |
469 | - ) . '">'; |
|
469 | + ).'">'; |
|
470 | 470 | $html .= "$subCategory3Name ($subCategory3Courses)"; |
471 | 471 | $html .= '</a>'; |
472 | 472 | } |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | $icon = '<em class="fa fa-smile-o"></em>'; |
594 | 594 | |
595 | 595 | return Display::div( |
596 | - $icon . ' ' . get_lang("AlreadyRegisteredToSession"), |
|
596 | + $icon.' '.get_lang("AlreadyRegisteredToSession"), |
|
597 | 597 | array('class' => 'info-catalog') |
598 | 598 | ); |
599 | 599 | } |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | */ |
606 | 606 | public function getSessionIcon($sessionName) |
607 | 607 | { |
608 | - return Display::return_icon('window_list.png', $sessionName, null,ICON_SIZE_MEDIUM); |
|
608 | + return Display::return_icon('window_list.png', $sessionName, null, ICON_SIZE_MEDIUM); |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | /** |
@@ -626,8 +626,7 @@ discard block |
||
626 | 626 | $pageTotal = intval(ceil(intval($countSessions) / $limit['length'])); |
627 | 627 | // Do NOT show pagination if only one page or less |
628 | 628 | $cataloguePagination = $pageTotal > 1 ? |
629 | - getCataloguePagination($limit['current'], $limit['length'], $pageTotal) : |
|
630 | - ''; |
|
629 | + getCataloguePagination($limit['current'], $limit['length'], $pageTotal) : ''; |
|
631 | 630 | $sessionsBlocks = $this->getFormatedSessionsBlock($sessions); |
632 | 631 | |
633 | 632 | // Get session list catalogue URL |
@@ -638,13 +637,13 @@ discard block |
||
638 | 637 | $tpl = new Template(); |
639 | 638 | $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses()); |
640 | 639 | $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions()); |
641 | - $tpl->assign('show_tutor', (api_get_setting('show_session_coach')==='true' ? true : false)); |
|
640 | + $tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false)); |
|
642 | 641 | $tpl->assign('course_url', $courseUrl); |
643 | 642 | $tpl->assign('catalog_pagination', $cataloguePagination); |
644 | 643 | $tpl->assign('hidden_links', $hiddenLinks); |
645 | 644 | $tpl->assign('search_token', Security::get_token()); |
646 | 645 | $tpl->assign('search_date', $date); |
647 | - $tpl->assign('web_session_courses_ajax_url', api_get_path(WEB_AJAX_PATH) . 'course.ajax.php'); |
|
646 | + $tpl->assign('web_session_courses_ajax_url', api_get_path(WEB_AJAX_PATH).'course.ajax.php'); |
|
648 | 647 | $tpl->assign('sessions', $sessionsBlocks); |
649 | 648 | $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel()); |
650 | 649 | |
@@ -671,7 +670,7 @@ discard block |
||
671 | 670 | |
672 | 671 | $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses()); |
673 | 672 | $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions()); |
674 | - $tpl->assign('show_tutor', (api_get_setting('show_session_coach')==='true' ? true : false)); |
|
673 | + $tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false)); |
|
675 | 674 | $tpl->assign('course_url', $courseUrl); |
676 | 675 | $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel()); |
677 | 676 | $tpl->assign('hidden_links', $hiddenLinks); |
@@ -702,7 +701,7 @@ discard block |
||
702 | 701 | $tpl = new Template(); |
703 | 702 | $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses()); |
704 | 703 | $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions()); |
705 | - $tpl->assign('show_tutor', (api_get_setting('show_session_coach')==='true' ? true : false)); |
|
704 | + $tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false)); |
|
706 | 705 | $tpl->assign('course_url', $courseUrl); |
707 | 706 | $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel()); |
708 | 707 | $tpl->assign('hidden_links', $hiddenLinks); |
@@ -62,6 +62,7 @@ discard block |
||
62 | 62 | * @param string $accessToken |
63 | 63 | * @param int $expiresAt |
64 | 64 | * @param string|null machineId |
65 | + * @param string $machineId |
|
65 | 66 | */ |
66 | 67 | public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
67 | 68 | { |
@@ -97,7 +98,7 @@ discard block |
||
97 | 98 | /** |
98 | 99 | * Getter for machineId. |
99 | 100 | * |
100 | - * @return string|null |
|
101 | + * @return string |
|
101 | 102 | */ |
102 | 103 | public function getMachineId() |
103 | 104 | { |
@@ -191,11 +192,11 @@ discard block |
||
191 | 192 | /** |
192 | 193 | * Get a valid code from an access token. |
193 | 194 | * |
194 | - * @param AccessToken|string $accessToken |
|
195 | + * @param AccessToken $accessToken |
|
195 | 196 | * @param string|null $appId |
196 | 197 | * @param string|null $appSecret |
197 | 198 | * |
198 | - * @return AccessToken |
|
199 | + * @return string |
|
199 | 200 | */ |
200 | 201 | public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
201 | 202 | { |
@@ -35,119 +35,119 @@ discard block |
||
35 | 35 | class AccessToken |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * The access token. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $accessToken; |
|
44 | - |
|
45 | - /** |
|
46 | - * A unique ID to identify a client. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $machineId; |
|
51 | - |
|
52 | - /** |
|
53 | - * Date when token expires. |
|
54 | - * |
|
55 | - * @var \DateTime|null |
|
56 | - */ |
|
57 | - protected $expiresAt; |
|
58 | - |
|
59 | - /** |
|
60 | - * Create a new access token entity. |
|
61 | - * |
|
62 | - * @param string $accessToken |
|
63 | - * @param int $expiresAt |
|
64 | - * @param string|null machineId |
|
65 | - */ |
|
66 | - public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
|
67 | - { |
|
38 | + /** |
|
39 | + * The access token. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $accessToken; |
|
44 | + |
|
45 | + /** |
|
46 | + * A unique ID to identify a client. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $machineId; |
|
51 | + |
|
52 | + /** |
|
53 | + * Date when token expires. |
|
54 | + * |
|
55 | + * @var \DateTime|null |
|
56 | + */ |
|
57 | + protected $expiresAt; |
|
58 | + |
|
59 | + /** |
|
60 | + * Create a new access token entity. |
|
61 | + * |
|
62 | + * @param string $accessToken |
|
63 | + * @param int $expiresAt |
|
64 | + * @param string|null machineId |
|
65 | + */ |
|
66 | + public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
|
67 | + { |
|
68 | 68 | $this->accessToken = $accessToken; |
69 | 69 | if ($expiresAt) { |
70 | - $this->setExpiresAtFromTimeStamp($expiresAt); |
|
70 | + $this->setExpiresAtFromTimeStamp($expiresAt); |
|
71 | 71 | } |
72 | 72 | $this->machineId = $machineId; |
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Setter for expires_at. |
|
77 | - * |
|
78 | - * @param int $timeStamp |
|
79 | - */ |
|
80 | - protected function setExpiresAtFromTimeStamp($timeStamp) |
|
81 | - { |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Setter for expires_at. |
|
77 | + * |
|
78 | + * @param int $timeStamp |
|
79 | + */ |
|
80 | + protected function setExpiresAtFromTimeStamp($timeStamp) |
|
81 | + { |
|
82 | 82 | $dt = new \DateTime(); |
83 | 83 | $dt->setTimestamp($timeStamp); |
84 | 84 | $this->expiresAt = $dt; |
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Getter for expiresAt. |
|
89 | - * |
|
90 | - * @return \DateTime|null |
|
91 | - */ |
|
92 | - public function getExpiresAt() |
|
93 | - { |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Getter for expiresAt. |
|
89 | + * |
|
90 | + * @return \DateTime|null |
|
91 | + */ |
|
92 | + public function getExpiresAt() |
|
93 | + { |
|
94 | 94 | return $this->expiresAt; |
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Getter for machineId. |
|
99 | - * |
|
100 | - * @return string|null |
|
101 | - */ |
|
102 | - public function getMachineId() |
|
103 | - { |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Getter for machineId. |
|
99 | + * |
|
100 | + * @return string|null |
|
101 | + */ |
|
102 | + public function getMachineId() |
|
103 | + { |
|
104 | 104 | return $this->machineId; |
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Determines whether or not this is a long-lived token. |
|
109 | - * |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isLongLived() |
|
113 | - { |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Determines whether or not this is a long-lived token. |
|
109 | + * |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isLongLived() |
|
113 | + { |
|
114 | 114 | if ($this->expiresAt) { |
115 | - return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); |
|
115 | + return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); |
|
116 | 116 | } |
117 | 117 | return false; |
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Checks the validity of the access token. |
|
122 | - * |
|
123 | - * @param string|null $appId Application ID to use |
|
124 | - * @param string|null $appSecret App secret value to use |
|
125 | - * @param string|null $machineId |
|
126 | - * |
|
127 | - * @return boolean |
|
128 | - */ |
|
129 | - public function isValid($appId = null, $appSecret = null, $machineId = null) |
|
130 | - { |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Checks the validity of the access token. |
|
122 | + * |
|
123 | + * @param string|null $appId Application ID to use |
|
124 | + * @param string|null $appSecret App secret value to use |
|
125 | + * @param string|null $machineId |
|
126 | + * |
|
127 | + * @return boolean |
|
128 | + */ |
|
129 | + public function isValid($appId = null, $appSecret = null, $machineId = null) |
|
130 | + { |
|
131 | 131 | $accessTokenInfo = $this->getInfo($appId, $appSecret); |
132 | 132 | $machineId = $machineId ?: $this->machineId; |
133 | 133 | return static::validateAccessToken($accessTokenInfo, $appId, $machineId); |
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Ensures the provided GraphSessionInfo object is valid, |
|
138 | - * throwing an exception if not. Ensures the appId matches, |
|
139 | - * that the machineId matches if it's being used, |
|
140 | - * that the token is valid and has not expired. |
|
141 | - * |
|
142 | - * @param GraphSessionInfo $tokenInfo |
|
143 | - * @param string|null $appId Application ID to use |
|
144 | - * @param string|null $machineId |
|
145 | - * |
|
146 | - * @return boolean |
|
147 | - */ |
|
148 | - public static function validateAccessToken(GraphSessionInfo $tokenInfo, |
|
149 | - $appId = null, $machineId = null) |
|
150 | - { |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Ensures the provided GraphSessionInfo object is valid, |
|
138 | + * throwing an exception if not. Ensures the appId matches, |
|
139 | + * that the machineId matches if it's being used, |
|
140 | + * that the token is valid and has not expired. |
|
141 | + * |
|
142 | + * @param GraphSessionInfo $tokenInfo |
|
143 | + * @param string|null $appId Application ID to use |
|
144 | + * @param string|null $machineId |
|
145 | + * |
|
146 | + * @return boolean |
|
147 | + */ |
|
148 | + public static function validateAccessToken(GraphSessionInfo $tokenInfo, |
|
149 | + $appId = null, $machineId = null) |
|
150 | + { |
|
151 | 151 | $targetAppId = FacebookSession::_getTargetAppId($appId); |
152 | 152 | |
153 | 153 | $appIdIsValid = $tokenInfo->getAppId() == $targetAppId; |
@@ -156,90 +156,90 @@ discard block |
||
156 | 156 | |
157 | 157 | // Not all access tokens return an expiration. E.g. an app access token. |
158 | 158 | if ($tokenInfo->getExpiresAt() instanceof \DateTime) { |
159 | - $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); |
|
159 | + $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); |
|
160 | 160 | } else { |
161 | - $accessTokenIsStillAlive = true; |
|
161 | + $accessTokenIsStillAlive = true; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive; |
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Get a valid access token from a code. |
|
169 | - * |
|
170 | - * @param string $code |
|
171 | - * @param string|null $appId |
|
172 | - * @param string|null $appSecret |
|
173 | - * @param string|null $machineId |
|
174 | - * |
|
175 | - * @return AccessToken |
|
176 | - */ |
|
177 | - public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) |
|
178 | - { |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Get a valid access token from a code. |
|
169 | + * |
|
170 | + * @param string $code |
|
171 | + * @param string|null $appId |
|
172 | + * @param string|null $appSecret |
|
173 | + * @param string|null $machineId |
|
174 | + * |
|
175 | + * @return AccessToken |
|
176 | + */ |
|
177 | + public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) |
|
178 | + { |
|
179 | 179 | $params = array( |
180 | - 'code' => $code, |
|
181 | - 'redirect_uri' => '', |
|
180 | + 'code' => $code, |
|
181 | + 'redirect_uri' => '', |
|
182 | 182 | ); |
183 | 183 | |
184 | 184 | if ($machineId) { |
185 | - $params['machine_id'] = $machineId; |
|
185 | + $params['machine_id'] = $machineId; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | return static::requestAccessToken($params, $appId, $appSecret); |
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get a valid code from an access token. |
|
193 | - * |
|
194 | - * @param AccessToken|string $accessToken |
|
195 | - * @param string|null $appId |
|
196 | - * @param string|null $appSecret |
|
197 | - * |
|
198 | - * @return AccessToken |
|
199 | - */ |
|
200 | - public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
|
201 | - { |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get a valid code from an access token. |
|
193 | + * |
|
194 | + * @param AccessToken|string $accessToken |
|
195 | + * @param string|null $appId |
|
196 | + * @param string|null $appSecret |
|
197 | + * |
|
198 | + * @return AccessToken |
|
199 | + */ |
|
200 | + public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
|
201 | + { |
|
202 | 202 | $accessToken = (string) $accessToken; |
203 | 203 | |
204 | 204 | $params = array( |
205 | - 'access_token' => $accessToken, |
|
206 | - 'redirect_uri' => '', |
|
205 | + 'access_token' => $accessToken, |
|
206 | + 'redirect_uri' => '', |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | return static::requestCode($params, $appId, $appSecret); |
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Exchanges a short lived access token with a long lived access token. |
|
214 | - * |
|
215 | - * @param string|null $appId |
|
216 | - * @param string|null $appSecret |
|
217 | - * |
|
218 | - * @return AccessToken |
|
219 | - */ |
|
220 | - public function extend($appId = null, $appSecret = null) |
|
221 | - { |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Exchanges a short lived access token with a long lived access token. |
|
214 | + * |
|
215 | + * @param string|null $appId |
|
216 | + * @param string|null $appSecret |
|
217 | + * |
|
218 | + * @return AccessToken |
|
219 | + */ |
|
220 | + public function extend($appId = null, $appSecret = null) |
|
221 | + { |
|
222 | 222 | $params = array( |
223 | - 'grant_type' => 'fb_exchange_token', |
|
224 | - 'fb_exchange_token' => $this->accessToken, |
|
223 | + 'grant_type' => 'fb_exchange_token', |
|
224 | + 'fb_exchange_token' => $this->accessToken, |
|
225 | 225 | ); |
226 | 226 | |
227 | 227 | return static::requestAccessToken($params, $appId, $appSecret); |
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Request an access token based on a set of params. |
|
232 | - * |
|
233 | - * @param array $params |
|
234 | - * @param string|null $appId |
|
235 | - * @param string|null $appSecret |
|
236 | - * |
|
237 | - * @return AccessToken |
|
238 | - * |
|
239 | - * @throws FacebookRequestException |
|
240 | - */ |
|
241 | - public static function requestAccessToken(array $params, $appId = null, $appSecret = null) |
|
242 | - { |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Request an access token based on a set of params. |
|
232 | + * |
|
233 | + * @param array $params |
|
234 | + * @param string|null $appId |
|
235 | + * @param string|null $appSecret |
|
236 | + * |
|
237 | + * @return AccessToken |
|
238 | + * |
|
239 | + * @throws FacebookRequestException |
|
240 | + */ |
|
241 | + public static function requestAccessToken(array $params, $appId = null, $appSecret = null) |
|
242 | + { |
|
243 | 243 | $response = static::request('/oauth/access_token', $params, $appId, $appSecret); |
244 | 244 | $data = $response->getResponse(); |
245 | 245 | |
@@ -248,133 +248,133 @@ discard block |
||
248 | 248 | * @see https://github.com/facebook/facebook-php-sdk-v4/issues/36 |
249 | 249 | */ |
250 | 250 | if (is_array($data)) { |
251 | - if (isset($data['access_token'])) { |
|
251 | + if (isset($data['access_token'])) { |
|
252 | 252 | $expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0; |
253 | 253 | return new static($data['access_token'], $expiresAt); |
254 | - } |
|
254 | + } |
|
255 | 255 | } elseif($data instanceof \stdClass) { |
256 | - if (isset($data->access_token)) { |
|
256 | + if (isset($data->access_token)) { |
|
257 | 257 | $expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0; |
258 | 258 | $machineId = isset($data->machine_id) ? (string) $data->machine_id : null; |
259 | 259 | return new static((string) $data->access_token, $expiresAt, $machineId); |
260 | - } |
|
260 | + } |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | throw FacebookRequestException::create( |
264 | - $response->getRawResponse(), |
|
265 | - $data, |
|
266 | - 401 |
|
264 | + $response->getRawResponse(), |
|
265 | + $data, |
|
266 | + 401 |
|
267 | 267 | ); |
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Request a code from a long lived access token. |
|
272 | - * |
|
273 | - * @param array $params |
|
274 | - * @param string|null $appId |
|
275 | - * @param string|null $appSecret |
|
276 | - * |
|
277 | - * @return string |
|
278 | - * |
|
279 | - * @throws FacebookRequestException |
|
280 | - */ |
|
281 | - public static function requestCode(array $params, $appId = null, $appSecret = null) |
|
282 | - { |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Request a code from a long lived access token. |
|
272 | + * |
|
273 | + * @param array $params |
|
274 | + * @param string|null $appId |
|
275 | + * @param string|null $appSecret |
|
276 | + * |
|
277 | + * @return string |
|
278 | + * |
|
279 | + * @throws FacebookRequestException |
|
280 | + */ |
|
281 | + public static function requestCode(array $params, $appId = null, $appSecret = null) |
|
282 | + { |
|
283 | 283 | $response = static::request('/oauth/client_code', $params, $appId, $appSecret); |
284 | 284 | $data = $response->getResponse(); |
285 | 285 | |
286 | 286 | if (isset($data->code)) { |
287 | - return (string) $data->code; |
|
287 | + return (string) $data->code; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | throw FacebookRequestException::create( |
291 | - $response->getRawResponse(), |
|
292 | - $data, |
|
293 | - 401 |
|
291 | + $response->getRawResponse(), |
|
292 | + $data, |
|
293 | + 401 |
|
294 | 294 | ); |
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Send a request to Graph with an app access token. |
|
299 | - * |
|
300 | - * @param string $endpoint |
|
301 | - * @param array $params |
|
302 | - * @param string|null $appId |
|
303 | - * @param string|null $appSecret |
|
304 | - * |
|
305 | - * @return \Facebook\FacebookResponse |
|
306 | - * |
|
307 | - * @throws FacebookRequestException |
|
308 | - */ |
|
309 | - protected static function request($endpoint, array $params, $appId = null, $appSecret = null) |
|
310 | - { |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Send a request to Graph with an app access token. |
|
299 | + * |
|
300 | + * @param string $endpoint |
|
301 | + * @param array $params |
|
302 | + * @param string|null $appId |
|
303 | + * @param string|null $appSecret |
|
304 | + * |
|
305 | + * @return \Facebook\FacebookResponse |
|
306 | + * |
|
307 | + * @throws FacebookRequestException |
|
308 | + */ |
|
309 | + protected static function request($endpoint, array $params, $appId = null, $appSecret = null) |
|
310 | + { |
|
311 | 311 | $targetAppId = FacebookSession::_getTargetAppId($appId); |
312 | 312 | $targetAppSecret = FacebookSession::_getTargetAppSecret($appSecret); |
313 | 313 | |
314 | 314 | if (!isset($params['client_id'])) { |
315 | - $params['client_id'] = $targetAppId; |
|
315 | + $params['client_id'] = $targetAppId; |
|
316 | 316 | } |
317 | 317 | if (!isset($params['client_secret'])) { |
318 | - $params['client_secret'] = $targetAppSecret; |
|
318 | + $params['client_secret'] = $targetAppSecret; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | // The response for this endpoint is not JSON, so it must be handled |
322 | 322 | // differently, not as a GraphObject. |
323 | 323 | $request = new FacebookRequest( |
324 | - FacebookSession::newAppSession($targetAppId, $targetAppSecret), |
|
325 | - 'GET', |
|
326 | - $endpoint, |
|
327 | - $params |
|
324 | + FacebookSession::newAppSession($targetAppId, $targetAppSecret), |
|
325 | + 'GET', |
|
326 | + $endpoint, |
|
327 | + $params |
|
328 | 328 | ); |
329 | 329 | return $request->execute(); |
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Get more info about an access token. |
|
334 | - * |
|
335 | - * @param string|null $appId |
|
336 | - * @param string|null $appSecret |
|
337 | - * |
|
338 | - * @return GraphSessionInfo |
|
339 | - */ |
|
340 | - public function getInfo($appId = null, $appSecret = null) |
|
341 | - { |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Get more info about an access token. |
|
334 | + * |
|
335 | + * @param string|null $appId |
|
336 | + * @param string|null $appSecret |
|
337 | + * |
|
338 | + * @return GraphSessionInfo |
|
339 | + */ |
|
340 | + public function getInfo($appId = null, $appSecret = null) |
|
341 | + { |
|
342 | 342 | $params = array('input_token' => $this->accessToken); |
343 | 343 | |
344 | 344 | $request = new FacebookRequest( |
345 | - FacebookSession::newAppSession($appId, $appSecret), |
|
346 | - 'GET', |
|
347 | - '/debug_token', |
|
348 | - $params |
|
345 | + FacebookSession::newAppSession($appId, $appSecret), |
|
346 | + 'GET', |
|
347 | + '/debug_token', |
|
348 | + $params |
|
349 | 349 | ); |
350 | 350 | $response = $request->execute()->getGraphObject(GraphSessionInfo::className()); |
351 | 351 | |
352 | 352 | // Update the data on this token |
353 | 353 | if ($response->getExpiresAt()) { |
354 | - $this->expiresAt = $response->getExpiresAt(); |
|
354 | + $this->expiresAt = $response->getExpiresAt(); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | return $response; |
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Returns the access token as a string. |
|
362 | - * |
|
363 | - * @return string |
|
364 | - */ |
|
365 | - public function __toString() |
|
366 | - { |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Returns the access token as a string. |
|
362 | + * |
|
363 | + * @return string |
|
364 | + */ |
|
365 | + public function __toString() |
|
366 | + { |
|
367 | 367 | return $this->accessToken; |
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Returns true if the access token is an app session token. |
|
372 | - * |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function isAppSession() |
|
376 | - { |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Returns true if the access token is an app session token. |
|
372 | + * |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function isAppSession() |
|
376 | + { |
|
377 | 377 | return strpos($this->accessToken, "|") !== false; |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | 380 | } |
@@ -252,7 +252,7 @@ |
||
252 | 252 | $expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0; |
253 | 253 | return new static($data['access_token'], $expiresAt); |
254 | 254 | } |
255 | - } elseif($data instanceof \stdClass) { |
|
255 | + } elseif ($data instanceof \stdClass) { |
|
256 | 256 | if (isset($data->access_token)) { |
257 | 257 | $expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0; |
258 | 258 | $machineId = isset($data->machine_id) ? (string) $data->machine_id : null; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Returns the raw signed request data. |
65 | 65 | * |
66 | - * @return string|null |
|
66 | + * @return string |
|
67 | 67 | */ |
68 | 68 | public function getRawSignedRequest() |
69 | 69 | { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * Returns a property from the signed request data if available. |
85 | 85 | * |
86 | 86 | * @param string $key |
87 | - * @param mixed|null $default |
|
87 | + * @param integer $default |
|
88 | 88 | * |
89 | 89 | * @return mixed|null |
90 | 90 | */ |
@@ -33,99 +33,99 @@ discard block |
||
33 | 33 | class SignedRequest |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $rawSignedRequest; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - public $payload; |
|
45 | - |
|
46 | - /** |
|
47 | - * Instantiate a new SignedRequest entity. |
|
48 | - * |
|
49 | - * @param string|null $rawSignedRequest The raw signed request. |
|
50 | - * @param string|null $state random string to prevent CSRF. |
|
51 | - * @param string|null $appSecret |
|
52 | - */ |
|
53 | - public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | - { |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $rawSignedRequest; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + public $payload; |
|
45 | + |
|
46 | + /** |
|
47 | + * Instantiate a new SignedRequest entity. |
|
48 | + * |
|
49 | + * @param string|null $rawSignedRequest The raw signed request. |
|
50 | + * @param string|null $state random string to prevent CSRF. |
|
51 | + * @param string|null $appSecret |
|
52 | + */ |
|
53 | + public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | + { |
|
55 | 55 | if (!$rawSignedRequest) { |
56 | - return; |
|
56 | + return; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->rawSignedRequest = $rawSignedRequest; |
60 | 60 | $this->payload = static::parse($rawSignedRequest, $state, $appSecret); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns the raw signed request data. |
|
65 | - * |
|
66 | - * @return string|null |
|
67 | - */ |
|
68 | - public function getRawSignedRequest() |
|
69 | - { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns the raw signed request data. |
|
65 | + * |
|
66 | + * @return string|null |
|
67 | + */ |
|
68 | + public function getRawSignedRequest() |
|
69 | + { |
|
70 | 70 | return $this->rawSignedRequest; |
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Returns the parsed signed request data. |
|
75 | - * |
|
76 | - * @return array|null |
|
77 | - */ |
|
78 | - public function getPayload() |
|
79 | - { |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Returns the parsed signed request data. |
|
75 | + * |
|
76 | + * @return array|null |
|
77 | + */ |
|
78 | + public function getPayload() |
|
79 | + { |
|
80 | 80 | return $this->payload; |
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns a property from the signed request data if available. |
|
85 | - * |
|
86 | - * @param string $key |
|
87 | - * @param mixed|null $default |
|
88 | - * |
|
89 | - * @return mixed|null |
|
90 | - */ |
|
91 | - public function get($key, $default = null) |
|
92 | - { |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns a property from the signed request data if available. |
|
85 | + * |
|
86 | + * @param string $key |
|
87 | + * @param mixed|null $default |
|
88 | + * |
|
89 | + * @return mixed|null |
|
90 | + */ |
|
91 | + public function get($key, $default = null) |
|
92 | + { |
|
93 | 93 | if (isset($this->payload[$key])) { |
94 | - return $this->payload[$key]; |
|
94 | + return $this->payload[$key]; |
|
95 | 95 | } |
96 | 96 | return $default; |
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns user_id from signed request data if available. |
|
101 | - * |
|
102 | - * @return string|null |
|
103 | - */ |
|
104 | - public function getUserId() |
|
105 | - { |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns user_id from signed request data if available. |
|
101 | + * |
|
102 | + * @return string|null |
|
103 | + */ |
|
104 | + public function getUserId() |
|
105 | + { |
|
106 | 106 | return $this->get('user_id'); |
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Checks for OAuth data in the payload. |
|
111 | - * |
|
112 | - * @return boolean |
|
113 | - */ |
|
114 | - public function hasOAuthData() |
|
115 | - { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Checks for OAuth data in the payload. |
|
111 | + * |
|
112 | + * @return boolean |
|
113 | + */ |
|
114 | + public function hasOAuthData() |
|
115 | + { |
|
116 | 116 | return isset($this->payload['oauth_token']) || isset($this->payload['code']); |
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Creates a signed request from an array of data. |
|
121 | - * |
|
122 | - * @param array $payload |
|
123 | - * @param string|null $appSecret |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function make(array $payload, $appSecret = null) |
|
128 | - { |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Creates a signed request from an array of data. |
|
121 | + * |
|
122 | + * @param array $payload |
|
123 | + * @param string|null $appSecret |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function make(array $payload, $appSecret = null) |
|
128 | + { |
|
129 | 129 | $payload['algorithm'] = 'HMAC-SHA256'; |
130 | 130 | $payload['issued_at'] = time(); |
131 | 131 | $encodedPayload = static::base64UrlEncode(json_encode($payload)); |
@@ -134,20 +134,20 @@ discard block |
||
134 | 134 | $encodedSig = static::base64UrlEncode($hashedSig); |
135 | 135 | |
136 | 136 | return $encodedSig.'.'.$encodedPayload; |
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Validates and decodes a signed request and returns |
|
141 | - * the payload as an array. |
|
142 | - * |
|
143 | - * @param string $signedRequest |
|
144 | - * @param string|null $state |
|
145 | - * @param string|null $appSecret |
|
146 | - * |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | - { |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Validates and decodes a signed request and returns |
|
141 | + * the payload as an array. |
|
142 | + * |
|
143 | + * @param string $signedRequest |
|
144 | + * @param string|null $state |
|
145 | + * @param string|null $appSecret |
|
146 | + * |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | + { |
|
151 | 151 | list($encodedSig, $encodedPayload) = static::split($signedRequest); |
152 | 152 | |
153 | 153 | // Signature validation |
@@ -159,228 +159,228 @@ discard block |
||
159 | 159 | $data = static::decodePayload($encodedPayload); |
160 | 160 | static::validateAlgorithm($data); |
161 | 161 | if ($state) { |
162 | - static::validateCsrf($data, $state); |
|
162 | + static::validateCsrf($data, $state); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $data; |
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Validates the format of a signed request. |
|
170 | - * |
|
171 | - * @param string $signedRequest |
|
172 | - * |
|
173 | - * @throws FacebookSDKException |
|
174 | - */ |
|
175 | - public static function validateFormat($signedRequest) |
|
176 | - { |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Validates the format of a signed request. |
|
170 | + * |
|
171 | + * @param string $signedRequest |
|
172 | + * |
|
173 | + * @throws FacebookSDKException |
|
174 | + */ |
|
175 | + public static function validateFormat($signedRequest) |
|
176 | + { |
|
177 | 177 | if (strpos($signedRequest, '.') !== false) { |
178 | - return; |
|
178 | + return; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | throw new FacebookSDKException( |
182 | - 'Malformed signed request.', 606 |
|
182 | + 'Malformed signed request.', 606 |
|
183 | 183 | ); |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Decodes a raw valid signed request. |
|
188 | - * |
|
189 | - * @param string $signedRequest |
|
190 | - * |
|
191 | - * @returns array |
|
192 | - */ |
|
193 | - public static function split($signedRequest) |
|
194 | - { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Decodes a raw valid signed request. |
|
188 | + * |
|
189 | + * @param string $signedRequest |
|
190 | + * |
|
191 | + * @returns array |
|
192 | + */ |
|
193 | + public static function split($signedRequest) |
|
194 | + { |
|
195 | 195 | static::validateFormat($signedRequest); |
196 | 196 | |
197 | 197 | return explode('.', $signedRequest, 2); |
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Decodes the raw signature from a signed request. |
|
202 | - * |
|
203 | - * @param string $encodedSig |
|
204 | - * |
|
205 | - * @returns string |
|
206 | - * |
|
207 | - * @throws FacebookSDKException |
|
208 | - */ |
|
209 | - public static function decodeSignature($encodedSig) |
|
210 | - { |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Decodes the raw signature from a signed request. |
|
202 | + * |
|
203 | + * @param string $encodedSig |
|
204 | + * |
|
205 | + * @returns string |
|
206 | + * |
|
207 | + * @throws FacebookSDKException |
|
208 | + */ |
|
209 | + public static function decodeSignature($encodedSig) |
|
210 | + { |
|
211 | 211 | $sig = static::base64UrlDecode($encodedSig); |
212 | 212 | |
213 | 213 | if ($sig) { |
214 | - return $sig; |
|
214 | + return $sig; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | throw new FacebookSDKException( |
218 | - 'Signed request has malformed encoded signature data.', 607 |
|
218 | + 'Signed request has malformed encoded signature data.', 607 |
|
219 | 219 | ); |
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Decodes the raw payload from a signed request. |
|
224 | - * |
|
225 | - * @param string $encodedPayload |
|
226 | - * |
|
227 | - * @returns array |
|
228 | - * |
|
229 | - * @throws FacebookSDKException |
|
230 | - */ |
|
231 | - public static function decodePayload($encodedPayload) |
|
232 | - { |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Decodes the raw payload from a signed request. |
|
224 | + * |
|
225 | + * @param string $encodedPayload |
|
226 | + * |
|
227 | + * @returns array |
|
228 | + * |
|
229 | + * @throws FacebookSDKException |
|
230 | + */ |
|
231 | + public static function decodePayload($encodedPayload) |
|
232 | + { |
|
233 | 233 | $payload = static::base64UrlDecode($encodedPayload); |
234 | 234 | |
235 | 235 | if ($payload) { |
236 | - $payload = json_decode($payload, true); |
|
236 | + $payload = json_decode($payload, true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | if (is_array($payload)) { |
240 | - return $payload; |
|
240 | + return $payload; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | throw new FacebookSDKException( |
244 | - 'Signed request has malformed encoded payload data.', 607 |
|
244 | + 'Signed request has malformed encoded payload data.', 607 |
|
245 | 245 | ); |
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Validates the algorithm used in a signed request. |
|
250 | - * |
|
251 | - * @param array $data |
|
252 | - * |
|
253 | - * @throws FacebookSDKException |
|
254 | - */ |
|
255 | - public static function validateAlgorithm(array $data) |
|
256 | - { |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Validates the algorithm used in a signed request. |
|
250 | + * |
|
251 | + * @param array $data |
|
252 | + * |
|
253 | + * @throws FacebookSDKException |
|
254 | + */ |
|
255 | + public static function validateAlgorithm(array $data) |
|
256 | + { |
|
257 | 257 | if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') { |
258 | - return; |
|
258 | + return; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | throw new FacebookSDKException( |
262 | - 'Signed request is using the wrong algorithm.', 605 |
|
262 | + 'Signed request is using the wrong algorithm.', 605 |
|
263 | 263 | ); |
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Hashes the signature used in a signed request. |
|
268 | - * |
|
269 | - * @param string $encodedData |
|
270 | - * @param string|null $appSecret |
|
271 | - * |
|
272 | - * @return string |
|
273 | - * |
|
274 | - * @throws FacebookSDKException |
|
275 | - */ |
|
276 | - public static function hashSignature($encodedData, $appSecret = null) |
|
277 | - { |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Hashes the signature used in a signed request. |
|
268 | + * |
|
269 | + * @param string $encodedData |
|
270 | + * @param string|null $appSecret |
|
271 | + * |
|
272 | + * @return string |
|
273 | + * |
|
274 | + * @throws FacebookSDKException |
|
275 | + */ |
|
276 | + public static function hashSignature($encodedData, $appSecret = null) |
|
277 | + { |
|
278 | 278 | $hashedSig = hash_hmac( |
279 | - 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
279 | + 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
280 | 280 | ); |
281 | 281 | |
282 | 282 | if ($hashedSig) { |
283 | - return $hashedSig; |
|
283 | + return $hashedSig; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | throw new FacebookSDKException( |
287 | - 'Unable to hash signature from encoded payload data.', 602 |
|
287 | + 'Unable to hash signature from encoded payload data.', 602 |
|
288 | 288 | ); |
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Validates the signature used in a signed request. |
|
293 | - * |
|
294 | - * @param string $hashedSig |
|
295 | - * @param string $sig |
|
296 | - * |
|
297 | - * @throws FacebookSDKException |
|
298 | - */ |
|
299 | - public static function validateSignature($hashedSig, $sig) |
|
300 | - { |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Validates the signature used in a signed request. |
|
293 | + * |
|
294 | + * @param string $hashedSig |
|
295 | + * @param string $sig |
|
296 | + * |
|
297 | + * @throws FacebookSDKException |
|
298 | + */ |
|
299 | + public static function validateSignature($hashedSig, $sig) |
|
300 | + { |
|
301 | 301 | if (mb_strlen($hashedSig) === mb_strlen($sig)) { |
302 | - $validate = 0; |
|
303 | - for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
302 | + $validate = 0; |
|
303 | + for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
304 | 304 | $validate |= ord($hashedSig[$i]) ^ ord($sig[$i]); |
305 | - } |
|
306 | - if ($validate === 0) { |
|
305 | + } |
|
306 | + if ($validate === 0) { |
|
307 | 307 | return; |
308 | - } |
|
308 | + } |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | throw new FacebookSDKException( |
312 | - 'Signed request has an invalid signature.', 602 |
|
312 | + 'Signed request has an invalid signature.', 602 |
|
313 | 313 | ); |
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Validates a signed request against CSRF. |
|
318 | - * |
|
319 | - * @param array $data |
|
320 | - * @param string $state |
|
321 | - * |
|
322 | - * @throws FacebookSDKException |
|
323 | - */ |
|
324 | - public static function validateCsrf(array $data, $state) |
|
325 | - { |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Validates a signed request against CSRF. |
|
318 | + * |
|
319 | + * @param array $data |
|
320 | + * @param string $state |
|
321 | + * |
|
322 | + * @throws FacebookSDKException |
|
323 | + */ |
|
324 | + public static function validateCsrf(array $data, $state) |
|
325 | + { |
|
326 | 326 | if (isset($data['state']) && $data['state'] === $state) { |
327 | - return; |
|
327 | + return; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | throw new FacebookSDKException( |
331 | - 'Signed request did not pass CSRF validation.', 604 |
|
331 | + 'Signed request did not pass CSRF validation.', 604 |
|
332 | 332 | ); |
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Base64 decoding which replaces characters: |
|
337 | - * + instead of - |
|
338 | - * / instead of _ |
|
339 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | - * |
|
341 | - * @param string $input base64 url encoded input |
|
342 | - * |
|
343 | - * @return string decoded string |
|
344 | - */ |
|
345 | - public static function base64UrlDecode($input) |
|
346 | - { |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Base64 decoding which replaces characters: |
|
337 | + * + instead of - |
|
338 | + * / instead of _ |
|
339 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | + * |
|
341 | + * @param string $input base64 url encoded input |
|
342 | + * |
|
343 | + * @return string decoded string |
|
344 | + */ |
|
345 | + public static function base64UrlDecode($input) |
|
346 | + { |
|
347 | 347 | $urlDecodedBase64 = strtr($input, '-_', '+/'); |
348 | 348 | static::validateBase64($urlDecodedBase64); |
349 | 349 | return base64_decode($urlDecodedBase64); |
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Base64 encoding which replaces characters: |
|
354 | - * + instead of - |
|
355 | - * / instead of _ |
|
356 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | - * |
|
358 | - * @param string $input string to encode |
|
359 | - * |
|
360 | - * @return string base64 url encoded input |
|
361 | - */ |
|
362 | - public static function base64UrlEncode($input) |
|
363 | - { |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Base64 encoding which replaces characters: |
|
354 | + * + instead of - |
|
355 | + * / instead of _ |
|
356 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | + * |
|
358 | + * @param string $input string to encode |
|
359 | + * |
|
360 | + * @return string base64 url encoded input |
|
361 | + */ |
|
362 | + public static function base64UrlEncode($input) |
|
363 | + { |
|
364 | 364 | return strtr(base64_encode($input), '+/', '-_'); |
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Validates a base64 string. |
|
369 | - * |
|
370 | - * @param string $input base64 value to validate |
|
371 | - * |
|
372 | - * @throws FacebookSDKException |
|
373 | - */ |
|
374 | - public static function validateBase64($input) |
|
375 | - { |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Validates a base64 string. |
|
369 | + * |
|
370 | + * @param string $input base64 value to validate |
|
371 | + * |
|
372 | + * @throws FacebookSDKException |
|
373 | + */ |
|
374 | + public static function validateBase64($input) |
|
375 | + { |
|
376 | 376 | $pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/'; |
377 | 377 | if (preg_match($pattern, $input)) { |
378 | - return; |
|
378 | + return; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | throw new FacebookSDKException( |
382 | - 'Signed request contains malformed base64 encoding.', 608 |
|
382 | + 'Signed request contains malformed base64 encoding.', 608 |
|
383 | 383 | ); |
384 | - } |
|
384 | + } |
|
385 | 385 | |
386 | 386 | } |
@@ -18,14 +18,8 @@ |
||
18 | 18 | use Facebook\FacebookSession; |
19 | 19 | use Facebook\FacebookRedirectLoginHelper; |
20 | 20 | use Facebook\FacebookRequest; |
21 | -use Facebook\FacebookResponse; |
|
22 | 21 | use Facebook\FacebookSDKException; |
23 | 22 | use Facebook\FacebookRequestException; |
24 | -use Facebook\FacebookAuthorizationException; |
|
25 | -use Facebook\GraphObject; |
|
26 | -use Facebook\Entities\AccessToken; |
|
27 | -use Facebook\HttpClients\FacebookCurlHttpClient; |
|
28 | -use Facebook\HttpClients\FacebookHttpable; |
|
29 | 23 | |
30 | 24 | require_once dirname(__FILE__) . '/functions.inc.php'; |
31 | 25 |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licence: GPL |
|
4 | - * Please contact CBlue regarding any licences issues. |
|
5 | - * Author: [email protected] |
|
6 | - * Copyright: CBlue SPRL, 20XX |
|
7 | - * |
|
8 | - * External login module : FACEBOOK |
|
9 | - * |
|
10 | - * This files provides the facebookConnect() and facebook_get_url functions |
|
11 | - * Please edit the facebook.conf.php file to adapt it to your fb application parameter |
|
12 | - */ |
|
3 | + * Licence: GPL |
|
4 | + * Please contact CBlue regarding any licences issues. |
|
5 | + * Author: [email protected] |
|
6 | + * Copyright: CBlue SPRL, 20XX |
|
7 | + * |
|
8 | + * External login module : FACEBOOK |
|
9 | + * |
|
10 | + * This files provides the facebookConnect() and facebook_get_url functions |
|
11 | + * Please edit the facebook.conf.php file to adapt it to your fb application parameter |
|
12 | + */ |
|
13 | 13 | |
14 | 14 | require_once dirname(__FILE__) . '/../../inc/global.inc.php'; |
15 | 15 | require_once dirname(__FILE__) . '/facebook.init.php'; |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * Please edit the facebook.conf.php file to adapt it to your fb application parameter |
12 | 12 | */ |
13 | 13 | |
14 | -require_once dirname(__FILE__) . '/../../inc/global.inc.php'; |
|
15 | -require_once dirname(__FILE__) . '/facebook.init.php'; |
|
16 | -require_once dirname(__FILE__) . '/facebook-php-sdk/autoload.php'; |
|
14 | +require_once dirname(__FILE__).'/../../inc/global.inc.php'; |
|
15 | +require_once dirname(__FILE__).'/facebook.init.php'; |
|
16 | +require_once dirname(__FILE__).'/facebook-php-sdk/autoload.php'; |
|
17 | 17 | |
18 | 18 | use Facebook\FacebookSession; |
19 | 19 | use Facebook\FacebookRedirectLoginHelper; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | use Facebook\HttpClients\FacebookCurlHttpClient; |
28 | 28 | use Facebook\HttpClients\FacebookHttpable; |
29 | 29 | |
30 | -require_once dirname(__FILE__) . '/functions.inc.php'; |
|
30 | +require_once dirname(__FILE__).'/functions.inc.php'; |
|
31 | 31 | |
32 | 32 | // dont rename $facebook_config to $facebookConfig otherwise get a "Facebook\\FacebookSDKException" |
33 | 33 | FacebookSession::setDefaultApplication($facebook_config['appId'], $facebook_config['secret']); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $locale = $graphObject->getProperty('locale'); |
58 | 58 | $language = facebookPluginGetLanguage($locale); |
59 | 59 | if (!$language) { |
60 | - $language='en_US'; |
|
60 | + $language = 'en_US'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | //Checks if user already exists in chamilo |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $_user['user_id'] = $chamilo_uid; |
86 | 86 | $_user['uidReset'] = true; |
87 | 87 | $_SESSION['_user'] = $_user; |
88 | - header('Location:' . api_get_path(WEB_PATH)); |
|
88 | + header('Location:'.api_get_path(WEB_PATH)); |
|
89 | 89 | exit(); |
90 | 90 | } else { |
91 | 91 | return false; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $_user['user_id'] = $chamilo_uid; |
99 | 99 | $_user['uidReset'] = true; |
100 | 100 | $_SESSION['_user'] = $_user; |
101 | - header('Location:' . api_get_path(WEB_PATH)); |
|
101 | + header('Location:'.api_get_path(WEB_PATH)); |
|
102 | 102 | exit(); |
103 | 103 | } |
104 | 104 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | { |
118 | 118 | global $facebook_config; |
119 | 119 | $helper = new FacebookRedirectLoginHelper($facebook_config['return_url']); |
120 | - $loginUrl = $helper->getLoginUrl( |
|
120 | + $loginUrl = $helper->getLoginUrl( |
|
121 | 121 | array('scope' => 'email') |
122 | 122 | ); |
123 | 123 |
@@ -148,7 +148,7 @@ |
||
148 | 148 | * - language |
149 | 149 | * - courses : string of all courses code separated by '|' |
150 | 150 | * - admin : boolean |
151 | - * @return boolean |
|
151 | + * @return boolean|null |
|
152 | 152 | * @author ndiechburg <[email protected]> |
153 | 153 | * */ |
154 | 154 | function external_update_user($new_user) { |
@@ -20,7 +20,7 @@ |
||
20 | 20 | //Those are the mandatory fields for user creation. |
21 | 21 | //See external_add_user function for all the fields you can have. |
22 | 22 | $table = USERINFO_TABLE; |
23 | - $sql = "SELECT * from $table where username='" . Database::escape_string($login) . "'"; |
|
23 | + $sql = "SELECT * from $table where username='".Database::escape_string($login)."'"; |
|
24 | 24 | $result = Database::query($sql); |
25 | 25 | |
26 | 26 | if (Database::num_rows($result) == 0) { //false password |
@@ -95,30 +95,43 @@ |
||
95 | 95 | * */ |
96 | 96 | function external_add_user($u) { |
97 | 97 | //Setting default |
98 | - if (empty($u['password'])) |
|
99 | - $u['password'] = null; |
|
100 | - if (empty($u['status'])) |
|
101 | - $u['status'] = 5; |
|
102 | - if (!isset($u['official_code'])) |
|
103 | - $u['official_code'] = ''; |
|
104 | - if (!isset($u['language'])) |
|
105 | - $u['language'] = ''; |
|
106 | - if (!isset($u['phone'])) |
|
107 | - $u['phone'] = ''; |
|
108 | - if (!isset($u['picture_uri'])) |
|
109 | - $u['picture_uri'] = ''; |
|
110 | - if (!isset($u['auth_source'])) |
|
111 | - $u['auth_source'] = PLATFORM_AUTH_SOURCE; |
|
112 | - if (!isset($u['expiration_date'])) |
|
113 | - $u['expiration_date'] = '0000-00-00 00:00:00'; |
|
114 | - if (!isset($u['active'])) |
|
115 | - $u['active'] = 1; |
|
116 | - if (!isset($u['hr_dept_id'])) |
|
117 | - $u['hr_dept_id'] = 0; //id of responsible HR |
|
118 | - if (!isset($u['extra'])) |
|
119 | - $u['extra'] = null; |
|
120 | - if (!isset($u['encrypt_method'])) |
|
121 | - $u['encrypt_method'] = ''; |
|
98 | + if (empty($u['password'])) { |
|
99 | + $u['password'] = null; |
|
100 | + } |
|
101 | + if (empty($u['status'])) { |
|
102 | + $u['status'] = 5; |
|
103 | + } |
|
104 | + if (!isset($u['official_code'])) { |
|
105 | + $u['official_code'] = ''; |
|
106 | + } |
|
107 | + if (!isset($u['language'])) { |
|
108 | + $u['language'] = ''; |
|
109 | + } |
|
110 | + if (!isset($u['phone'])) { |
|
111 | + $u['phone'] = ''; |
|
112 | + } |
|
113 | + if (!isset($u['picture_uri'])) { |
|
114 | + $u['picture_uri'] = ''; |
|
115 | + } |
|
116 | + if (!isset($u['auth_source'])) { |
|
117 | + $u['auth_source'] = PLATFORM_AUTH_SOURCE; |
|
118 | + } |
|
119 | + if (!isset($u['expiration_date'])) { |
|
120 | + $u['expiration_date'] = '0000-00-00 00:00:00'; |
|
121 | + } |
|
122 | + if (!isset($u['active'])) { |
|
123 | + $u['active'] = 1; |
|
124 | + } |
|
125 | + if (!isset($u['hr_dept_id'])) { |
|
126 | + $u['hr_dept_id'] = 0; |
|
127 | + } |
|
128 | + //id of responsible HR |
|
129 | + if (!isset($u['extra'])) { |
|
130 | + $u['extra'] = null; |
|
131 | + } |
|
132 | + if (!isset($u['encrypt_method'])) { |
|
133 | + $u['encrypt_method'] = ''; |
|
134 | + } |
|
122 | 135 | |
123 | 136 | $chamilo_uid = UserManager::create_user($u['firstname'], $u['lastname'], $u['status'], $u['email'], $u['username'], $u['password'], $u['official_code'], $u['language'], $u['phone'], $u['picture_uri'], $u['auth_source'], $u['expiration_date'], $u['active'], $u['hr_dept_id'], $u['extra'], $u['encrypt_method']); |
124 | 137 | return $chamilo_uid; |