]>
Commit | Line | Data |
---|---|---|
d96eca60 JR |
1 | diff -upr php-4.1.2/ext/domxml/config.m4 php-4.1.2-dom-xslt/ext/domxml/config.m4 |
2 | --- php-4.1.2/ext/domxml/config.m4 Thu Oct 4 08:42:45 2001 | |
3 | +++ php-4.1.2-dom-xslt/ext/domxml/config.m4 Fri Jan 18 08:58:47 2002 | |
4 | @@ -1,5 +1,6 @@ | |
5 | -dnl $Id$ | |
6 | -dnl config.m4 for extension domxml | |
7 | +dnl | |
8 | +dnl $Id$ | |
9 | +dnl | |
10 | ||
11 | AC_DEFUN(PHP_DOM_CHECK_VERSION,[ | |
12 | old_CPPFLAGS=$CPPFLAGS | |
13 | @@ -20,17 +21,16 @@ AC_DEFUN(PHP_DOM_CHECK_VERSION,[ | |
14 | ||
15 | PHP_ARG_WITH(dom, for DOM support, | |
16 | [ --with-dom[=DIR] Include DOM support (requires libxml >= 2.4.2). | |
17 | - DIR is the libxml install directory, | |
18 | - defaults to /usr.]) | |
19 | + DIR is the libxml install directory.]) | |
20 | ||
21 | if test "$PHP_DOM" != "no"; then | |
22 | ||
23 | DOMXML_DIR_ADD="" | |
24 | - if test -r $PHP_DOM/include/libxml/tree.h; then | |
25 | - DOMXML_DIR=$PHP_DOM | |
26 | - elif test -r $PHP_DOM/include/libxml2/libxml/tree.h; then | |
27 | + if test -r $PHP_DOM/include/libxml2/libxml/tree.h; then | |
28 | DOMXML_DIR=$PHP_DOM | |
29 | DOMXML_DIR_ADD="/libxml2" | |
30 | + elif test -r $PHP_DOM/include/libxml/tree.h; then | |
31 | + DOMXML_DIR=$PHP_DOM | |
32 | else | |
33 | for i in /usr/local /usr; do | |
34 | test -r $i/include/libxml/tree.h && DOMXML_DIR=$i | |
35 | @@ -63,4 +63,110 @@ if test "$PHP_DOM" != "no"; then | |
36 | AC_DEFINE(HAVE_DOMXML,1,[ ]) | |
37 | PHP_EXTENSION(domxml, $ext_shared) | |
38 | PHP_SUBST(DOMXML_SHARED_LIBADD) | |
39 | +fi | |
40 | + | |
41 | +AC_DEFUN(PHP_DOM_XSLT_CHECK_VERSION,[ | |
42 | + old_CPPFLAGS=$CPPFLAGS | |
43 | + CPPFLAGS=-I$DOMXSLT_DIR/include | |
44 | + AC_MSG_CHECKING(for libxslt version) | |
45 | + AC_EGREP_CPP(yes,[ | |
46 | + #include <libxslt/xsltconfig.h> | |
47 | + #if LIBXSLT_VERSION >= 10003 | |
48 | + yes | |
49 | + #endif | |
50 | + ],[ | |
51 | + AC_MSG_RESULT(>= 1.0.3) | |
52 | + ],[ | |
53 | + AC_MSG_ERROR(libxslt version 1.0.3 or greater required.) | |
54 | + ]) | |
55 | + CPPFLAGS=$old_CPPFLAGS | |
56 | +]) | |
57 | + | |
58 | +AC_DEFUN(PHP_DOM_EXSLT_CHECK_VERSION,[ | |
59 | + old_CPPFLAGS=$CPPFLAGS | |
60 | + CPPFLAGS=-I$DOMEXSLT_DIR/include | |
61 | + AC_MSG_CHECKING(for libexslt version) | |
62 | + AC_EGREP_CPP(yes,[ | |
63 | + #include <libexslt/exsltconfig.h> | |
64 | + #if LIBEXSLT_VERSION >= 600 | |
65 | + yes | |
66 | + #endif | |
67 | + ],[ | |
68 | + AC_MSG_RESULT(>= 1.0.3) | |
69 | + ],[ | |
70 | + AC_MSG_ERROR(libxslt version 1.0.3 or greater required.) | |
71 | + ]) | |
72 | + CPPFLAGS=$old_CPPFLAGS | |
73 | +]) | |
74 | + | |
75 | +PHP_ARG_WITH(dom-xslt, for DOM XSLT support, | |
76 | +[ --with-dom-xslt[=DIR] Include DOM XSLT support (requires libxslt >= 1.0.3). | |
77 | + DIR is the libxslt install directory.]) | |
78 | + | |
79 | +PHP_ARG_WITH(dom-exslt, for DOM EXSLT support, | |
80 | +[ --with-dom-exslt[=DIR] Include DOM EXSLT support (requires libxslt >= 1.0.3). | |
81 | + DIR is the libexslt install directory.]) | |
82 | + | |
83 | +if test "$PHP_DOM_XSLT" != "no"; then | |
84 | + | |
85 | + if test -r $PHP_DOM_XSLT/include/libxslt/transform.h; then | |
86 | + DOMXSLT_DIR=$PHP_DOM_XSLT | |
87 | + else | |
88 | + for i in /usr/local /usr; do | |
89 | + test -r $i/include/libxslt/transform.h && DOMXSLT_DIR=$i | |
90 | + done | |
91 | + fi | |
92 | + | |
93 | + if test -z "$DOMXSLT_DIR"; then | |
94 | + AC_MSG_RESULT(not found) | |
95 | + AC_MSG_ERROR(Please reinstall the libxslt >= 1.0.3 distribution) | |
96 | + fi | |
97 | + | |
98 | + PHP_DOM_XSLT_CHECK_VERSION | |
99 | + | |
100 | + PHP_ADD_LIBRARY_WITH_PATH(xslt, $DOMXSLT_DIR/lib, DOMXML_SHARED_LIBADD) | |
101 | + | |
102 | + PHP_ADD_INCLUDE($DOMXSLT_DIR/include) | |
103 | + | |
104 | + if test "$PHP_DOM" = "no"; then | |
105 | + AC_MSG_ERROR(DOMXSLT requires DOMXML. Use --with-dom=<DIR>) | |
106 | + fi | |
107 | + | |
108 | + AC_DEFINE(HAVE_DOMXSLT,1,[ ]) | |
109 | + | |
110 | + PHP_SUBST(DOMXML_SHARED_LIBADD) | |
111 | +fi | |
112 | + | |
113 | +if test "$PHP_DOM_EXSLT" != "no"; then | |
114 | + if test "$PHP_DOM" = "no"; then | |
115 | + AC_MSG_ERROR(DOMEXSLT requires DOMXML. Use --with-dom=<DIR>) | |
116 | + fi | |
117 | + | |
118 | + if test "$PHP_DOM_XSLT" = "no"; then | |
119 | + AC_MSG_ERROR(DOMEXSLT requires DOMXSLT. Use --with-dom-xslt=<DIR>) | |
120 | + fi | |
121 | + | |
122 | + if test -r $PHP_DOM_EXSLT/include/libexslt/exslt.h; then | |
123 | + DOMEXSLT_DIR=$PHP_DOM_EXSLT | |
124 | + else | |
125 | + for i in /usr/local /usr; do | |
126 | + test -r $i/include/libexslt/exslt.h && DOMEXSLT_DIR=$i | |
127 | + done | |
128 | + fi | |
129 | + | |
130 | + if test -z "$DOMEXSLT_DIR"; then | |
131 | + AC_MSG_RESULT(not found) | |
132 | + AC_MSG_ERROR(Please reinstall the libxslt >= 1.0.3 distribution) | |
133 | + fi | |
134 | + | |
135 | + PHP_DOM_EXSLT_CHECK_VERSION | |
136 | + | |
137 | + PHP_ADD_LIBRARY_WITH_PATH(exslt, $DOMEXSLT_DIR/lib, DOMXML_SHARED_LIBADD) | |
138 | + | |
139 | + PHP_ADD_INCLUDE($DOMEXSLT_DIR/include) | |
140 | + | |
141 | + AC_DEFINE(HAVE_DOMEXSLT,1,[ ]) | |
142 | + | |
143 | + PHP_SUBST(DOMXML_SHARED_LIBADD) | |
144 | + | |
145 | fi | |
146 | diff -upr php-4.1.2/ext/domxml/php_domxml.c php-4.1.2-dom-xslt/ext/domxml/php_domxml.c | |
147 | --- php-4.1.2/ext/domxml/php_domxml.c Fri Dec 14 11:45:46 2001 | |
148 | +++ php-4.1.2-dom-xslt/ext/domxml/php_domxml.c Tue Feb 26 17:03:46 2002 | |
149 | @@ -16,7 +16,11 @@ | |
150 | +----------------------------------------------------------------------+ | |
151 | */ | |
152 | ||
153 | -/* $Id$ */ | |
154 | +/* $Id$ */ | |
155 | + | |
156 | +/* TODO | |
157 | + * - Support Notation Nodes | |
158 | + * */ | |
159 | ||
160 | ||
161 | #ifdef HAVE_CONFIG_H | |
162 | @@ -33,7 +37,7 @@ | |
163 | ||
164 | /* General macros used by domxml */ | |
165 | #define DOMXML_DOMOBJ_NEW(zval, obj, ret) if (NULL == (zval = php_domobject_new(obj, ret TSRMLS_CC))) { \ | |
166 | - php_error(E_WARNING, "%s() cannot create required DOM object", \ | |
167 | + php_error(E_WARNING, "%s(): cannot create required DOM object", \ | |
168 | get_active_function_name(TSRMLS_C)); \ | |
169 | RETURN_FALSE; \ | |
170 | } | |
171 | @@ -46,13 +50,13 @@ | |
172 | DOMXML_RET_ZVAL(zval); | |
173 | ||
174 | #define DOMXML_GET_THIS(zval) if (NULL == (zval = getThis())) { \ | |
175 | - php_error(E_WARNING, "%s() underlying object missing", \ | |
176 | + php_error(E_WARNING, "%s(): underlying object missing", \ | |
177 | get_active_function_name(TSRMLS_C)); \ | |
178 | RETURN_FALSE; \ | |
179 | } | |
180 | ||
181 | #define DOMXML_GET_OBJ(ret, zval, le) if (NULL == (ret = php_dom_get_object(zval, le, 0 TSRMLS_CC))) { \ | |
182 | - php_error(E_WARNING, "%s() cannot fetch DOM object", \ | |
183 | + php_error(E_WARNING, "%s(): cannot fetch DOM object", \ | |
184 | get_active_function_name(TSRMLS_C)); \ | |
185 | RETURN_FALSE; \ | |
186 | } | |
187 | @@ -80,6 +84,17 @@ | |
188 | } \ | |
189 | DOMXML_GET_OBJ(ret, zval, le); | |
190 | ||
191 | +#define DOMXML_PARAM_ONE(ret, zval, le, s, p1) if (NULL == (zval = getThis())) { \ | |
192 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o"s, &zval, p1) == FAILURE) { \ | |
193 | + return; \ | |
194 | + } \ | |
195 | + } else { \ | |
196 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s, p1) == FAILURE) { \ | |
197 | + return; \ | |
198 | + } \ | |
199 | + } \ | |
200 | + DOMXML_GET_OBJ(ret, zval, le); | |
201 | + | |
202 | #define DOMXML_PARAM_TWO(ret, zval, le, s, p1, p2) if (NULL == (zval = getThis())) { \ | |
203 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o"s, &zval, p1, p2) == FAILURE) { \ | |
204 | return; \ | |
205 | @@ -91,6 +106,18 @@ | |
206 | } \ | |
207 | DOMXML_GET_OBJ(ret, zval, le); | |
208 | ||
209 | +#define DOMXML_PARAM_THREE(ret, zval, le, s, p1, p2, p3) if (NULL == (zval = getThis())) { \ | |
210 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o"s, &zval, p1, p2, p3) == FAILURE) { \ | |
211 | + return; \ | |
212 | + } \ | |
213 | + } else { \ | |
214 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s, p1, p2, p3) == FAILURE) { \ | |
215 | + return; \ | |
216 | + } \ | |
217 | + } \ | |
218 | + DOMXML_GET_OBJ(ret, zval, le); | |
219 | + | |
220 | + | |
221 | #define DOMXML_PARAM_FOUR(ret, zval, le, s, p1, p2, p3, p4) if (NULL == (zval = getThis())) { \ | |
222 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o"s, &zval, p1, p2, p3, p4) == FAILURE) { \ | |
223 | return; \ | |
224 | @@ -102,6 +129,7 @@ | |
225 | } \ | |
226 | DOMXML_GET_OBJ(ret, zval, le); | |
227 | ||
228 | + | |
229 | static int le_domxmldocp; | |
230 | static int le_domxmldoctypep; | |
231 | static int le_domxmldtdp; | |
232 | @@ -116,6 +144,9 @@ static int le_domxmlnotationp; | |
233 | /*static int le_domxmlentityp;*/ | |
234 | static int le_domxmlentityrefp; | |
235 | /*static int le_domxmlnsp;*/ | |
236 | +#if HAVE_DOMXSLT | |
237 | +static int le_domxsltstylesheetp; | |
238 | +#endif | |
239 | ||
240 | #if defined(LIBXML_XPATH_ENABLED) | |
241 | static int le_xpathctxp; | |
242 | @@ -140,6 +171,9 @@ zend_class_entry *domxmlns_class_entry; | |
243 | zend_class_entry *xpathctx_class_entry; | |
244 | zend_class_entry *xpathobject_class_entry; | |
245 | #endif | |
246 | +#if HAVE_DOMXSLT | |
247 | +zend_class_entry *domxsltstylesheet_class_entry; | |
248 | +#endif | |
249 | ||
250 | ||
251 | static int node_attributes(zval **attributes, xmlNode *nodep TSRMLS_DC); | |
252 | @@ -149,28 +183,48 @@ static zend_function_entry domxml_functi | |
253 | PHP_FE(domxml_version, NULL) | |
254 | PHP_FE(xmldoc, NULL) | |
255 | PHP_FE(xmldocfile, NULL) | |
256 | +#if defined(LIBXML_HTML_ENABLED) | |
257 | + PHP_FE(html_doc, NULL) | |
258 | + PHP_FE(html_doc_file, NULL) | |
259 | +#endif | |
260 | PHP_FE(xmltree, NULL) | |
261 | + PHP_FE(domxml_substitute_entities_default, NULL) | |
262 | PHP_FE(domxml_add_root, NULL) | |
263 | - PHP_FE(domxml_dumpmem, NULL) | |
264 | + PHP_FE(domxml_dump_mem, NULL) | |
265 | + PHP_FE(domxml_dump_mem_file, NULL) | |
266 | + PHP_FE(domxml_dump_node, NULL) | |
267 | +#if defined(LIBXML_HTML_ENABLED) | |
268 | + PHP_FE(domxml_html_dump_mem, NULL) | |
269 | +#endif | |
270 | PHP_FE(domxml_node_attributes, NULL) | |
271 | PHP_FE(domxml_elem_get_attribute, NULL) | |
272 | PHP_FE(domxml_elem_set_attribute, NULL) | |
273 | PHP_FE(domxml_node_children, NULL) | |
274 | + PHP_FE(domxml_node_has_attributes, NULL) | |
275 | PHP_FE(domxml_node_new_child, NULL) | |
276 | PHP_FE(domxml_node, NULL) | |
277 | PHP_FE(domxml_node_unlink_node, NULL) | |
278 | PHP_FE(domxml_node_set_content, NULL) | |
279 | + PHP_FE(domxml_node_get_content, NULL) | |
280 | PHP_FE(domxml_new_xmldoc, NULL) | |
281 | ||
282 | #if defined(LIBXML_XPATH_ENABLED) | |
283 | PHP_FE(xpath_new_context, NULL) | |
284 | PHP_FE(xpath_eval, NULL) | |
285 | PHP_FE(xpath_eval_expression, NULL) | |
286 | + PHP_FE(xpath_register_ns, NULL) | |
287 | #endif | |
288 | #if defined(LIBXML_XPTR_ENABLED) | |
289 | PHP_FE(xptr_new_context, NULL) | |
290 | PHP_FE(xptr_eval, NULL) | |
291 | #endif | |
292 | +#if HAVE_DOMXSLT | |
293 | + PHP_FE(domxml_xslt_version, NULL) | |
294 | + PHP_FE(domxml_xslt_stylesheet, NULL) | |
295 | + PHP_FE(domxml_xslt_stylesheet_doc, NULL) | |
296 | + PHP_FE(domxml_xslt_stylesheet_file, NULL) | |
297 | + PHP_FE(domxml_xslt_process, NULL) | |
298 | +#endif | |
299 | ||
300 | PHP_FALIAS(domxml_root, domxml_doc_document_element, NULL) | |
301 | PHP_FALIAS(domxml_attributes, domxml_node_attributes, NULL) | |
302 | @@ -183,6 +237,8 @@ static zend_function_entry domxml_functi | |
303 | PHP_FALIAS(domxml_unlink_node, domxml_node_unlink_node, NULL) | |
304 | PHP_FALIAS(set_content, domxml_node_set_content, NULL) | |
305 | PHP_FALIAS(new_xmldoc, domxml_new_xmldoc, NULL) | |
306 | + PHP_FALIAS(domxml_dumpmem, domxml_dump_mem, NULL) | |
307 | + | |
308 | {NULL, NULL, NULL} | |
309 | }; | |
310 | ||
311 | @@ -206,7 +262,12 @@ static function_entry php_domxmldoc_clas | |
312 | PHP_FALIAS(add_root, domxml_add_root, NULL) | |
313 | PHP_FALIAS(imported_node, domxml_doc_imported_node, NULL) | |
314 | PHP_FALIAS(dtd, domxml_intdtd, NULL) | |
315 | - PHP_FALIAS(dumpmem, domxml_dumpmem, NULL) | |
316 | + PHP_FALIAS(dumpmem, domxml_dump_mem, NULL) | |
317 | + PHP_FALIAS(dump_mem, domxml_dump_mem, NULL) | |
318 | + PHP_FALIAS(dump_mem_file, domxml_dump_mem_file, NULL) | |
319 | +#if defined(LIBXML_HTML_ENABLED) | |
320 | + PHP_FALIAS(html_dump_mem, domxml_html_dump_mem, NULL) | |
321 | +#endif | |
322 | #if defined(LIBXML_XPATH_ENABLED) | |
323 | PHP_FALIAS(xpath_init, xpath_init, NULL) | |
324 | PHP_FALIAS(xpath_new_context, xpath_new_context, NULL) | |
325 | @@ -217,13 +278,13 @@ static function_entry php_domxmldoc_clas | |
326 | ||
327 | static function_entry php_domxmldoctype_class_functions[] = { | |
328 | PHP_FALIAS(name, domxml_doctype_name, NULL) | |
329 | -/* | |
330 | +/* | |
331 | PHP_FALIAS(entities, domxml_doctype_entities, NULL) | |
332 | PHP_FALIAS(notations, domxml_doctype_notations, NULL) | |
333 | PHP_FALIAS(system_id, domxml_doctype_system_id, NULL) | |
334 | PHP_FALIAS(public_id, domxml_doctype_public_id, NULL) | |
335 | PHP_FALIAS(internal_subset, domxml_doctype_internal_subset, NULL) | |
336 | -*/ | |
337 | +*/ | |
338 | {NULL, NULL, NULL} | |
339 | }; | |
340 | ||
341 | @@ -249,16 +310,20 @@ static zend_function_entry php_domxmlnod | |
342 | PHP_FALIAS(owner_document, domxml_node_owner_document, NULL) | |
343 | PHP_FALIAS(new_child, domxml_node_new_child, NULL) | |
344 | PHP_FALIAS(attributes, domxml_node_attributes, NULL) | |
345 | + PHP_FALIAS(has_attributes, domxml_node_has_attributes, NULL) | |
346 | PHP_FALIAS(node, domxml_node, NULL) | |
347 | PHP_FALIAS(unlink, domxml_node_unlink_node, NULL) | |
348 | + PHP_FALIAS(replace_node, domxml_node_replace_node, NULL) | |
349 | PHP_FALIAS(set_content, domxml_node_set_content, NULL) | |
350 | + PHP_FALIAS(get_content, domxml_node_get_content, NULL) | |
351 | PHP_FALIAS(text_concat, domxml_node_text_concat, NULL) | |
352 | PHP_FALIAS(set_name, domxml_node_set_name, NULL) | |
353 | PHP_FALIAS(node_name, domxml_node_name, NULL) | |
354 | PHP_FALIAS(node_type, domxml_node_type, NULL) | |
355 | PHP_FALIAS(node_value, domxml_node_value, NULL) | |
356 | PHP_FALIAS(clone_node, domxml_clone_node, NULL) | |
357 | - PHP_FALIAS(is_blank_node, domxml_is_blank_node, NULL) | |
358 | + PHP_FALIAS(is_blank_node, domxml_is_blank_node, NULL) | |
359 | + PHP_FALIAS(dump_node, domxml_dump_node, NULL) | |
360 | {NULL, NULL, NULL} | |
361 | }; | |
362 | ||
363 | @@ -299,7 +364,7 @@ static zend_function_entry php_domxmlent | |
364 | }; | |
365 | ||
366 | static zend_function_entry php_domxmlentity_class_functions[] = { | |
367 | -/* | |
368 | +/* | |
369 | PHP_FALIAS(public_id, domxml_entity_public_id, NULL) | |
370 | PHP_FALIAS(system_id, domxml_entity_system_id, NULL) | |
371 | PHP_FALIAS(notation_name, domxml_entity_notation_name, NULL) | |
372 | @@ -317,6 +382,7 @@ static zend_function_entry php_domxmlpi_ | |
373 | static zend_function_entry php_xpathctx_class_functions[] = { | |
374 | PHP_FALIAS(xpath_eval, xpath_eval, NULL) | |
375 | PHP_FALIAS(xpath_eval_expression, xpath_eval_expression, NULL) | |
376 | + PHP_FALIAS(xpath_register_ns, xpath_register_ns, NULL) | |
377 | {NULL, NULL, NULL} | |
378 | }; | |
379 | ||
380 | @@ -329,7 +395,7 @@ static zend_function_entry php_domxmlatt | |
381 | PHP_FALIAS(name, domxml_attr_name, NULL) | |
382 | PHP_FALIAS(value, domxml_attr_value, NULL) | |
383 | PHP_FALIAS(specified, domxml_attr_specified, NULL) | |
384 | -/* | |
385 | +/* | |
386 | PHP_FALIAS(owner_element, domxml_attr_owner_element, NULL) | |
387 | */ | |
388 | {NULL, NULL, NULL} | |
389 | @@ -339,8 +405,16 @@ static zend_function_entry php_domxmlns_ | |
390 | {NULL, NULL, NULL} | |
391 | }; | |
392 | ||
393 | +#if HAVE_DOMXSLT | |
394 | +static zend_function_entry php_domxsltstylesheet_class_functions[] = { | |
395 | +/* TODO: maybe some more methods? */ | |
396 | + PHP_FALIAS(process, domxml_xslt_process, NULL) | |
397 | + {NULL, NULL, NULL} | |
398 | +}; | |
399 | +#endif | |
400 | + | |
401 | zend_module_entry domxml_module_entry = { | |
402 | - STANDARD_MODULE_HEADER, | |
403 | + STANDARD_MODULE_HEADER, | |
404 | "domxml", | |
405 | domxml_functions, | |
406 | PHP_MINIT(domxml), | |
407 | @@ -348,7 +422,7 @@ zend_module_entry domxml_module_entry = | |
408 | PHP_RINIT(domxml), | |
409 | NULL, | |
410 | PHP_MINFO(domxml), | |
411 | - NO_VERSION_YET, | |
412 | + NO_VERSION_YET, | |
413 | STANDARD_MODULE_PROPERTIES | |
414 | }; | |
415 | ||
416 | @@ -370,14 +444,14 @@ static void dom_object_set_data(void *ob | |
417 | ||
418 | static zval *dom_object_get_data(void *obj) | |
419 | { | |
420 | -/* | |
421 | +/* | |
422 | char tmp[20]; | |
423 | sprintf(tmp, "%08X", obj); | |
424 | fprintf(stderr, "Trying getting %s from object ...", tmp); | |
425 | if(((xmlNodePtr) obj)->_private) | |
426 | fprintf(stderr, " found\n"); | |
427 | else | |
428 | - fprintf(stderr, " not found\n"); | |
429 | + fprintf(stderr, " not found\n"); | |
430 | */ | |
431 | return ((zval *) (((xmlNodePtr) obj)->_private)); | |
432 | } | |
433 | @@ -411,9 +485,14 @@ static inline void node_list_wrapper_dto | |
434 | { | |
435 | while (node != NULL) { | |
436 | node_list_wrapper_dtor(node->children); | |
437 | - // FIXME temporary fix; think of something better | |
438 | - if (node->type != XML_ATTRIBUTE_DECL && node->type != XML_DTD_NODE) { | |
439 | - attr_list_wrapper_dtor(node->properties); | |
440 | + switch (node->type) { | |
441 | + /* Skip property freeing for the following types */ | |
442 | + case XML_ATTRIBUTE_DECL: | |
443 | + case XML_DTD_NODE: | |
444 | + case XML_ENTITY_DECL: | |
445 | + break; | |
446 | + default: | |
447 | + attr_list_wrapper_dtor(node->properties); | |
448 | } | |
449 | node_wrapper_dtor(node); | |
450 | node = node->next; | |
451 | @@ -474,6 +553,92 @@ static void php_free_xpath_object(zend_r | |
452 | #endif | |
453 | ||
454 | ||
455 | +#if HAVE_DOMXSLT | |
456 | +static void php_free_xslt_stylesheet(zend_rsrc_list_entry *rsrc TSRMLS_DC) | |
457 | +{ | |
458 | + xsltStylesheetPtr sheet = (xsltStylesheetPtr) rsrc->ptr; | |
459 | + | |
460 | + if (sheet) { | |
461 | + node_wrapper_dtor((xmlNodePtr) sheet); | |
462 | + xsltFreeStylesheet(sheet); | |
463 | + } | |
464 | +} | |
465 | + | |
466 | +static void xsltstylesheet_set_data(void *obj, zval *wrapper) | |
467 | +{ | |
468 | +/* | |
469 | + char tmp[20]; | |
470 | + sprintf(tmp, "%08X", obj); | |
471 | + fprintf(stderr, "Adding %s to hash\n", tmp); | |
472 | +*/ | |
473 | + ((xsltStylesheetPtr) obj)->_private = wrapper; | |
474 | +} | |
475 | + | |
476 | + | |
477 | +static zval *xsltstylesheet_get_data(void *obj) | |
478 | +{ | |
479 | +/* | |
480 | + char tmp[20]; | |
481 | + sprintf(tmp, "%08X", obj); | |
482 | + fprintf(stderr, "Trying getting %s from object ...", tmp); | |
483 | + if(((xmlNodePtr) obj)->_private) | |
484 | + fprintf(stderr, " found\n"); | |
485 | + else | |
486 | + fprintf(stderr, " not found\n"); | |
487 | +*/ | |
488 | + return ((zval *) (((xsltStylesheetPtr) obj)->_private)); | |
489 | +} | |
490 | + | |
491 | +void *php_xsltstylesheet_get_object(zval *wrapper, int rsrc_type1, int rsrc_type2 TSRMLS_DC) | |
492 | +{ | |
493 | + void *obj; | |
494 | + zval **handle; | |
495 | + int type; | |
496 | + | |
497 | + if (NULL == wrapper) { | |
498 | + php_error(E_WARNING, "xsltstylesheet_get_object() invalid wrapper object passed"); | |
499 | + return NULL; | |
500 | + } | |
501 | + | |
502 | + if (Z_TYPE_P(wrapper) != IS_OBJECT) { | |
503 | + php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C)); | |
504 | + return NULL; | |
505 | + } | |
506 | + | |
507 | + if (zend_hash_index_find(Z_OBJPROP_P(wrapper), 0, (void **) &handle) == FAILURE) { | |
508 | + php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C)); | |
509 | + return NULL; | |
510 | + } | |
511 | + | |
512 | + obj = zend_list_find(Z_LVAL_PP(handle), &type); | |
513 | + if (!obj || ((type != rsrc_type1) && (type != rsrc_type2))) { | |
514 | + php_error(E_WARNING, "%s(): underlying object missing or of invalid type", get_active_function_name(TSRMLS_C)); | |
515 | + return NULL; | |
516 | + } | |
517 | + | |
518 | + return obj; | |
519 | +} | |
520 | + | |
521 | +static void php_xsltstylesheet_set_object(zval *wrapper, void *obj, int rsrc_type) | |
522 | +{ | |
523 | + zval *handle, *addr; | |
524 | + | |
525 | + MAKE_STD_ZVAL(handle); | |
526 | + Z_TYPE_P(handle) = IS_LONG; | |
527 | + Z_LVAL_P(handle) = zend_list_insert(obj, rsrc_type); | |
528 | + | |
529 | + MAKE_STD_ZVAL(addr); | |
530 | + Z_TYPE_P(addr) = IS_LONG; | |
531 | + Z_LVAL_P(addr) = (int) obj; | |
532 | + | |
533 | + zend_hash_index_update(Z_OBJPROP_P(wrapper), 0, &handle, sizeof(zval *), NULL); | |
534 | + zend_hash_index_update(Z_OBJPROP_P(wrapper), 1, &addr, sizeof(zval *), NULL); | |
535 | + zval_add_ref(&wrapper); | |
536 | + xsltstylesheet_set_data(obj, wrapper); | |
537 | +} | |
538 | +#endif /* HAVE_DOMXSLT */ | |
539 | + | |
540 | + | |
541 | void *php_xpath_get_object(zval *wrapper, int rsrc_type1, int rsrc_type2 TSRMLS_DC) | |
542 | { | |
543 | void *obj; | |
544 | @@ -486,18 +651,18 @@ void *php_xpath_get_object(zval *wrapper | |
545 | } | |
546 | ||
547 | if (Z_TYPE_P(wrapper) != IS_OBJECT) { | |
548 | - php_error(E_WARNING, "%s() wrapper is not an object", get_active_function_name(TSRMLS_C)); | |
549 | + php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C)); | |
550 | return NULL; | |
551 | } | |
552 | ||
553 | if (zend_hash_index_find(Z_OBJPROP_P(wrapper), 0, (void **) &handle) == FAILURE) { | |
554 | - php_error(E_WARNING, "%s() underlying object missing", get_active_function_name(TSRMLS_C)); | |
555 | + php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C)); | |
556 | return NULL; | |
557 | } | |
558 | ||
559 | obj = zend_list_find(Z_LVAL_PP(handle), &type); | |
560 | if (!obj || ((type != rsrc_type1) && (type != rsrc_type2))) { | |
561 | - php_error(E_WARNING, "%s() underlying object missing or of invalid type", get_active_function_name(TSRMLS_C)); | |
562 | + php_error(E_WARNING, "%s(): underlying object missing or of invalid type", get_active_function_name(TSRMLS_C)); | |
563 | return NULL; | |
564 | } | |
565 | ||
566 | @@ -507,7 +672,7 @@ void *php_xpath_get_object(zval *wrapper | |
567 | ||
568 | static void xpath_object_set_data(void *obj, zval *wrapper) | |
569 | { | |
570 | -/* | |
571 | +/* | |
572 | char tmp[20]; | |
573 | sprintf(tmp, "%08X", obj); | |
574 | fprintf(stderr, "Adding %s to hash\n", tmp); | |
575 | @@ -518,12 +683,12 @@ static void xpath_object_set_data(void * | |
576 | ||
577 | static zval *xpath_object_get_data(void *obj) | |
578 | { | |
579 | -/* | |
580 | +/* | |
581 | char tmp[20]; | |
582 | sprintf(tmp, "%08X", obj); | |
583 | - fprintf(stderr, "Trying getting %s from hash ...", tmp); | |
584 | + fprintf(stderr, "Trying getting %s from hash ...", tmp); | |
585 | if(((xmlXPathObjectPtr) obj)->user) | |
586 | - fprintf(stderr, " found\n"); | |
587 | + fprintf(stderr, " found\n"); | |
588 | else | |
589 | fprintf(stderr, " not found\n"); | |
590 | */ | |
591 | @@ -574,7 +739,7 @@ static zval *php_xpathobject_new(xmlXPat | |
592 | ||
593 | /* | |
594 | rsrc_type = le_xpathobjectp; | |
595 | - php_xpath_set_object(wrapper, (void *) obj, rsrc_type); | |
596 | + php_xpath_set_object(wrapper, (void *) obj, rsrc_type); | |
597 | */ | |
598 | ||
599 | php_xpath_set_object(wrapper, (void *) obj, le_xpathobjectp); | |
600 | @@ -594,19 +759,19 @@ void *php_xpath_get_context(zval *wrappe | |
601 | } | |
602 | ||
603 | if (Z_TYPE_P(wrapper) != IS_OBJECT) { | |
604 | - php_error(E_WARNING, "%s() wrapper is not an object", get_active_function_name(TSRMLS_C)); | |
605 | + php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C)); | |
606 | return NULL; | |
607 | } | |
608 | ||
609 | if (zend_hash_index_find(Z_OBJPROP_P(wrapper), 0, (void **) &handle) == | |
610 | FAILURE) { | |
611 | - php_error(E_WARNING, "%s() underlying object missing", get_active_function_name(TSRMLS_C)); | |
612 | + php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C)); | |
613 | return NULL; | |
614 | } | |
615 | ||
616 | obj = zend_list_find(Z_LVAL_PP(handle), &type); | |
617 | if (!obj || ((type != rsrc_type1) && (type != rsrc_type2))) { | |
618 | - php_error(E_WARNING, "%s() Underlying object missing or of invalid type", get_active_function_name(TSRMLS_C)); | |
619 | + php_error(E_WARNING, "%s(): underlying object missing or of invalid type", get_active_function_name(TSRMLS_C)); | |
620 | return NULL; | |
621 | } | |
622 | ||
623 | @@ -628,9 +793,9 @@ static zval *xpath_context_get_data(void | |
624 | /* | |
625 | char tmp[20]; | |
626 | sprintf(tmp, "%08X", obj); | |
627 | - fprintf(stderr, "Trying getting %s from hash ...", tmp); | |
628 | + fprintf(stderr, "Trying getting %s from hash ...", tmp); | |
629 | if(((xmlXPathContextPtr) obj)->user) | |
630 | - fprintf(stderr, " found\n"); | |
631 | + fprintf(stderr, " found\n"); | |
632 | else | |
633 | fprintf(stderr, " not found\n"); | |
634 | */ | |
635 | @@ -661,7 +826,7 @@ static zval *php_xpathcontext_new(xmlXPa | |
636 | int rsrc_type; | |
637 | ||
638 | if (! found) { | |
639 | - *found = 0; | |
640 | + *found = 0; | |
641 | } | |
642 | ||
643 | if (!obj) { | |
644 | @@ -677,8 +842,8 @@ static zval *php_xpathcontext_new(xmlXPa | |
645 | } | |
646 | ||
647 | MAKE_STD_ZVAL(wrapper); | |
648 | -/* | |
649 | - fprintf(stderr, "Adding new XPath Context\n"); | |
650 | +/* | |
651 | + fprintf(stderr, "Adding new XPath Context\n"); | |
652 | */ | |
653 | object_init_ex(wrapper, xpathctx_class_entry); | |
654 | rsrc_type = le_xpathctxp; | |
655 | @@ -700,12 +865,12 @@ void *php_dom_get_object(zval *wrapper, | |
656 | } | |
657 | ||
658 | if (Z_TYPE_P(wrapper) != IS_OBJECT) { | |
659 | - php_error(E_WARNING, "%s() wrapper is not an object", get_active_function_name(TSRMLS_C)); | |
660 | + php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C)); | |
661 | return NULL; | |
662 | } | |
663 | ||
664 | if (zend_hash_index_find(Z_OBJPROP_P(wrapper), 0, (void **) &handle) == FAILURE) { | |
665 | - php_error(E_WARNING, "%s() underlying object missing", get_active_function_name(TSRMLS_C)); | |
666 | + php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C)); | |
667 | return NULL; | |
668 | } | |
669 | ||
670 | @@ -713,7 +878,7 @@ void *php_dom_get_object(zval *wrapper, | |
671 | ||
672 | /* The following test should be replaced with search in all parents */ | |
673 | if (!obj) { /* || ((type != rsrc_type1) && (type != rsrc_type2))) { */ | |
674 | - php_error(E_WARNING, "%s() underlying object missing or of invalid type", get_active_function_name(TSRMLS_C)); | |
675 | + php_error(E_WARNING, "%s(): underlying object missing or of invalid type", get_active_function_name(TSRMLS_C)); | |
676 | return NULL; | |
677 | } | |
678 | ||
679 | @@ -747,7 +912,7 @@ static zval *php_domobject_new(xmlNodePt | |
680 | int rsrc_type; | |
681 | ||
682 | if (! found) { | |
683 | - *found = 0; | |
684 | + *found = 0; | |
685 | } | |
686 | ||
687 | if (!obj) { | |
688 | @@ -795,8 +960,10 @@ static zval *php_domobject_new(xmlNodePt | |
689 | object_init_ex(wrapper, domxmlcomment_class_entry); | |
690 | rsrc_type = le_domxmlcommentp; | |
691 | content = xmlNodeGetContent(nodep); | |
692 | - if (content) | |
693 | + if (content) { | |
694 | + add_property_long(wrapper, "type", Z_TYPE_P(nodep)); | |
695 | add_property_stringl(wrapper, "content", (char *) content, strlen(content), 1); | |
696 | + } | |
697 | break; | |
698 | } | |
699 | ||
700 | @@ -817,7 +984,6 @@ static zval *php_domobject_new(xmlNodePt | |
701 | xmlNodePtr nodep = obj; | |
702 | object_init_ex(wrapper, domxmlentityref_class_entry); | |
703 | rsrc_type = le_domxmlentityrefp; | |
704 | - content = xmlNodeGetContent(nodep); | |
705 | add_property_stringl(wrapper, "name", (char *) nodep->name, strlen(nodep->name), 1); | |
706 | break; | |
707 | } | |
708 | @@ -851,8 +1017,10 @@ static zval *php_domobject_new(xmlNodePt | |
709 | } | |
710 | ||
711 | case XML_DOCUMENT_NODE: | |
712 | + case XML_HTML_DOCUMENT_NODE: | |
713 | { | |
714 | xmlDocPtr docp = (xmlDocPtr) obj; | |
715 | + | |
716 | object_init_ex(wrapper, domxmldoc_class_entry); | |
717 | rsrc_type = le_domxmldocp; | |
718 | if (docp->name) | |
719 | @@ -863,7 +1031,10 @@ static zval *php_domobject_new(xmlNodePt | |
720 | add_property_stringl(wrapper, "url", (char *) docp->URL, strlen(docp->URL), 1); | |
721 | else | |
722 | add_property_stringl(wrapper, "url", "", 0, 1); | |
723 | - add_property_stringl(wrapper, "version", (char *) docp->version, strlen(docp->version), 1); | |
724 | + if (docp->version) | |
725 | + add_property_stringl(wrapper, "version", (char *) docp->version, strlen(docp->version), 1); | |
726 | + else | |
727 | + add_property_stringl(wrapper, "version", "", 0, 1); | |
728 | if (docp->encoding) | |
729 | add_property_stringl(wrapper, "encoding", (char *) docp->encoding, strlen(docp->encoding), 1); | |
730 | add_property_long(wrapper, "standalone", docp->standalone); | |
731 | @@ -900,8 +1071,8 @@ static zval *php_domobject_new(xmlNodePt | |
732 | break; | |
733 | } | |
734 | ||
735 | - default: | |
736 | - php_error(E_WARNING, "%s() unsupported node type: %d\n", get_active_function_name(TSRMLS_C), Z_TYPE_P(obj)); | |
737 | + default: | |
738 | + php_error(E_WARNING, "%s(): unsupported node type: %d\n", get_active_function_name(TSRMLS_C), Z_TYPE_P(obj)); | |
739 | FREE_ZVAL(wrapper); | |
740 | return NULL; | |
741 | } | |
742 | @@ -911,6 +1082,17 @@ static zval *php_domobject_new(xmlNodePt | |
743 | } | |
744 | ||
745 | ||
746 | +static void domxml_error(void *ctx, const char *msg, ...) | |
747 | +{ | |
748 | + char buf[1024]; | |
749 | + va_list ap; | |
750 | + va_start(ap, msg); | |
751 | + vsnprintf(buf, 1024, msg, ap); | |
752 | + va_end(ap); | |
753 | + php_error(E_WARNING, buf); | |
754 | +} | |
755 | + | |
756 | + | |
757 | PHP_RINIT_FUNCTION(domxml) | |
758 | { | |
759 | return SUCCESS; | |
760 | @@ -932,12 +1114,12 @@ PHP_MINIT_FUNCTION(domxml) | |
761 | le_domxmlelementp = zend_register_list_destructors_ex(php_free_xml_node, NULL, "domelement", module_number); | |
762 | le_domxmldtdp = zend_register_list_destructors_ex(php_free_xml_node, NULL, "domdtd", module_number); | |
763 | le_domxmlcdatap = zend_register_list_destructors_ex(php_free_xml_node, NULL, "domcdata", module_number); | |
764 | + le_domxmlentityrefp = zend_register_list_destructors_ex(php_free_xml_node, NULL, "domentityref", module_number); | |
765 | + le_domxmlpip = zend_register_list_destructors_ex(php_free_xml_node, NULL, "dompi", module_number); | |
766 | ||
767 | /* Not yet initialized le_*s */ | |
768 | le_domxmldoctypep = -10000; | |
769 | - le_domxmlpip = -10002; | |
770 | le_domxmlnotationp = -10003; | |
771 | - le_domxmlentityrefp = -10004; | |
772 | ||
773 | #if defined(LIBXML_XPATH_ENABLED) | |
774 | le_xpathctxp = zend_register_list_destructors_ex(php_free_xpath_context, NULL, "xpathcontext", module_number); | |
775 | @@ -946,6 +1128,10 @@ PHP_MINIT_FUNCTION(domxml) | |
776 | ||
777 | /* le_domxmlnsp = register_list_destructors(NULL, NULL); */ | |
778 | ||
779 | +#if HAVE_DOMXSLT | |
780 | + le_domxsltstylesheetp = zend_register_list_destructors_ex(php_free_xslt_stylesheet, NULL, "xsltstylesheet", module_number); | |
781 | +#endif | |
782 | + | |
783 | INIT_OVERLOADED_CLASS_ENTRY(ce, "DomNode", php_domxmlnode_class_functions, NULL, NULL, NULL); | |
784 | domxmlnode_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); | |
785 | ||
786 | @@ -996,6 +1182,11 @@ PHP_MINIT_FUNCTION(domxml) | |
787 | xpathobject_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); | |
788 | #endif | |
789 | ||
790 | +#if HAVE_DOMXSLT | |
791 | + INIT_OVERLOADED_CLASS_ENTRY(ce, "XsltStylesheet", php_domxsltstylesheet_class_functions, NULL, NULL, NULL); | |
792 | + domxsltstylesheet_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); | |
793 | +#endif | |
794 | + | |
795 | REGISTER_LONG_CONSTANT("XML_ELEMENT_NODE", XML_ELEMENT_NODE, CONST_CS | CONST_PERSISTENT); | |
796 | REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NODE", XML_ATTRIBUTE_NODE, CONST_CS | CONST_PERSISTENT); | |
797 | REGISTER_LONG_CONSTANT("XML_TEXT_NODE", XML_TEXT_NODE, CONST_CS | CONST_PERSISTENT); | |
798 | @@ -1040,6 +1231,15 @@ PHP_MINIT_FUNCTION(domxml) | |
799 | REGISTER_LONG_CONSTANT("XPATH_USERS", XPATH_USERS, CONST_CS | CONST_PERSISTENT); | |
800 | #endif | |
801 | ||
802 | + xmlSetGenericErrorFunc(xmlGenericErrorContext, (xmlGenericErrorFunc)domxml_error); | |
803 | +#if HAVE_DOMXSLT | |
804 | + xsltSetGenericErrorFunc(xsltGenericErrorContext, (xmlGenericErrorFunc)domxml_error); | |
805 | +#if HAVE_DOMEXSLT | |
806 | + exsltRegisterAll(); | |
807 | +#endif | |
808 | +#endif | |
809 | + | |
810 | + | |
811 | return SUCCESS; | |
812 | } | |
813 | ||
814 | @@ -1065,12 +1265,24 @@ PHP_MINFO_FUNCTION(domxml) | |
815 | php_info_print_table_start(); | |
816 | php_info_print_table_row(2, "DOM/XML", "enabled"); | |
817 | php_info_print_table_row(2, "libxml Version", LIBXML_DOTTED_VERSION); | |
818 | +#if defined(LIBXML_HTML_ENABLED) | |
819 | + php_info_print_table_row(2, "HTML Support", "enabled"); | |
820 | +#endif | |
821 | #if defined(LIBXML_XPATH_ENABLED) | |
822 | php_info_print_table_row(2, "XPath Support", "enabled"); | |
823 | #endif | |
824 | #if defined(LIBXML_XPTR_ENABLED) | |
825 | php_info_print_table_row(2, "XPointer Support", "enabled"); | |
826 | #endif | |
827 | +#if HAVE_DOMXSLT | |
828 | + php_info_print_table_row(2, "DOM/XSLT", "enabled"); | |
829 | + php_info_print_table_row(2, "libxslt Version", LIBXSLT_DOTTED_VERSION); | |
830 | +#if HAVE_DOMEXSLT | |
831 | + php_info_print_table_row(2, "DOM/EXSLT", "enabled"); | |
832 | + php_info_print_table_row(2, "libexslt Version", LIBEXSLT_DOTTED_VERSION); | |
833 | +#endif | |
834 | +#endif | |
835 | + | |
836 | php_info_print_table_end(); | |
837 | } | |
838 | ||
839 | @@ -1318,13 +1530,13 @@ PHP_FUNCTION(domxml_is_blank_node) | |
840 | PHP_FUNCTION(domxml_node_type) | |
841 | { | |
842 | zval *id; | |
843 | - xmlNode *n; | |
844 | + xmlNode *node; | |
845 | ||
846 | - DOMXML_GET_THIS_OBJ(n, id, le_domxmlnodep); | |
847 | + DOMXML_GET_THIS_OBJ(node, id, le_domxmlnodep); | |
848 | ||
849 | DOMXML_NO_ARGS(); | |
850 | ||
851 | - RETURN_LONG(Z_TYPE_P(n)); | |
852 | + RETURN_LONG(node->type); | |
853 | } | |
854 | /* }}} */ | |
855 | ||
856 | @@ -1533,7 +1745,7 @@ PHP_FUNCTION(domxml_node_parent) | |
857 | int ret; | |
858 | ||
859 | DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep); | |
860 | - | |
861 | + | |
862 | DOMXML_NO_ARGS(); | |
863 | ||
864 | last = nodep->parent; | |
865 | @@ -1558,7 +1770,7 @@ PHP_FUNCTION(domxml_node_children) | |
866 | /* Even if the nodep is a XML_DOCUMENT_NODE the type is at the | |
867 | same position. | |
868 | */ | |
869 | - if (Z_TYPE_P(nodep) == XML_DOCUMENT_NODE) | |
870 | + if ((Z_TYPE_P(nodep) == XML_DOCUMENT_NODE) || (Z_TYPE_P(nodep) == XML_HTML_DOCUMENT_NODE)) | |
871 | last = ((xmlDoc *) nodep)->children; | |
872 | else | |
873 | last = nodep->children; | |
874 | @@ -1579,32 +1791,27 @@ PHP_FUNCTION(domxml_node_children) | |
875 | } | |
876 | /* }}} */ | |
877 | ||
878 | -/* {{{ proto object domxml_node_unlink_node(void) | |
879 | - Deletes node */ | |
880 | +/* {{{ proto void domxml_node_unlink_node([object node]) | |
881 | + Deletes the node */ | |
882 | PHP_FUNCTION(domxml_node_unlink_node) | |
883 | { | |
884 | zval *id; | |
885 | xmlNode *nodep; | |
886 | ||
887 | - DOMXML_NO_ARGS(); | |
888 | - | |
889 | - DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep); | |
890 | - | |
891 | - DOMXML_NO_ARGS(); | |
892 | + DOMXML_PARAM_NONE(nodep, id, le_domxmlnodep); | |
893 | ||
894 | xmlUnlinkNode(nodep); | |
895 | xmlFreeNode(nodep); | |
896 | zval_dtor(id); /* This is not enough because the children won't be deleted */ | |
897 | - RETURN_TRUE; | |
898 | } | |
899 | /* }}} */ | |
900 | ||
901 | -/* {{{ proto object domxml_node_add_child(int domnode) | |
902 | +/* {{{ proto object domxml_node_add_child(object domnode) | |
903 | Adds existing node to parent node */ | |
904 | PHP_FUNCTION(domxml_node_add_child) | |
905 | { | |
906 | zval *id, *rv, *node; | |
907 | - xmlNodePtr child, nodep; | |
908 | + xmlNodePtr child, nodep, new_child; | |
909 | int ret; | |
910 | ||
911 | DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep); | |
912 | @@ -1615,10 +1822,20 @@ PHP_FUNCTION(domxml_node_add_child) | |
913 | ||
914 | DOMXML_GET_OBJ(child, node, le_domxmlnodep); | |
915 | ||
916 | - child = xmlAddChild(nodep, child); | |
917 | + if (child->type == XML_ATTRIBUTE_NODE) { | |
918 | + php_error(E_WARNING, "%s(): can't add attribute node", get_active_function_name(TSRMLS_C)); | |
919 | + RETURN_FALSE; | |
920 | + } | |
921 | + | |
922 | + if (NULL == (new_child = xmlCopyNode(child, 1))) { | |
923 | + php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C)); | |
924 | + RETURN_FALSE; | |
925 | + } | |
926 | + | |
927 | + child = xmlAddChild(nodep, new_child); | |
928 | ||
929 | if (NULL == child) { | |
930 | - php_error(E_WARNING, "%s() couldn't add child", get_active_function_name(TSRMLS_C)); | |
931 | + php_error(E_WARNING, "%s(): couldn't add child", get_active_function_name(TSRMLS_C)); | |
932 | RETURN_FALSE; | |
933 | } | |
934 | ||
935 | @@ -1626,12 +1843,39 @@ PHP_FUNCTION(domxml_node_add_child) | |
936 | } | |
937 | /* }}} */ | |
938 | ||
939 | -/* {{{ proto object domxml_node_append_child(int domnode) | |
940 | +/* {{{ proto object domxml_node_replace_node(object domnode) | |
941 | + Replaces one node with another node */ | |
942 | +PHP_FUNCTION(domxml_node_replace_node) | |
943 | +{ | |
944 | + zval *id, *rv, *node; | |
945 | + xmlNodePtr repnode, nodep, new_repnode; | |
946 | + int ret; | |
947 | + | |
948 | + DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep); | |
949 | + | |
950 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) { | |
951 | + return; | |
952 | + } | |
953 | + | |
954 | + DOMXML_GET_OBJ(repnode, node, le_domxmlnodep); | |
955 | + | |
956 | + if (NULL == (new_repnode = xmlCopyNode(repnode, 1))) { | |
957 | + php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C)); | |
958 | + RETURN_FALSE; | |
959 | + } | |
960 | + | |
961 | + repnode = xmlReplaceNode(nodep, new_repnode); | |
962 | + | |
963 | + DOMXML_RET_OBJ(rv, repnode, &ret); | |
964 | +} | |
965 | +/* }}} */ | |
966 | + | |
967 | +/* {{{ proto object domxml_node_append_child(object domnode) | |
968 | Adds node to list of children */ | |
969 | PHP_FUNCTION(domxml_node_append_child) | |
970 | { | |
971 | zval *id, *rv, *node; | |
972 | - xmlNodePtr child, nodep; | |
973 | + xmlNodePtr child, nodep, new_child; | |
974 | int ret; | |
975 | ||
976 | DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep); | |
977 | @@ -1642,11 +1886,21 @@ PHP_FUNCTION(domxml_node_append_child) | |
978 | ||
979 | DOMXML_GET_OBJ(child, node, le_domxmlnodep); | |
980 | ||
981 | + if (child->type == XML_ATTRIBUTE_NODE) { | |
982 | + php_error(E_WARNING, "%s(): can't append attribute node", get_active_function_name(TSRMLS_C)); | |
983 | + RETURN_FALSE; | |
984 | + } | |
985 | + | |
986 | + if (NULL == (new_child = xmlCopyNode(child, 1))) { | |
987 | + php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C)); | |
988 | + RETURN_FALSE; | |
989 | + } | |
990 | + | |
991 | // FIXME reverted xmlAddChildList; crashes | |
992 | - child = xmlAddSibling(nodep, child); | |
993 | + child = xmlAddSibling(nodep, new_child); | |
994 | ||
995 | if (NULL == child) { | |
996 | - php_error(E_WARNING, "%s() couldn't add node", get_active_function_name(TSRMLS_C)); | |
997 | + php_error(E_WARNING, "%s(): couldn't append node", get_active_function_name(TSRMLS_C)); | |
998 | RETURN_FALSE; | |
999 | } | |
1000 | ||
1001 | @@ -1654,7 +1908,7 @@ PHP_FUNCTION(domxml_node_append_child) | |
1002 | } | |
1003 | /* }}} */ | |
1004 | ||
1005 | -/* {{{ proto object domxml_node_insert_before(int newnode, int refnode) | |
1006 | +/* {{{ proto object domxml_node_insert_before(object newnode, object refnode) | |
1007 | Adds node in list of nodes before given node */ | |
1008 | PHP_FUNCTION(domxml_node_insert_before) | |
1009 | { | |
1010 | @@ -1674,7 +1928,7 @@ PHP_FUNCTION(domxml_node_insert_before) | |
1011 | child = xmlAddPrevSibling(refp, child); | |
1012 | ||
1013 | if (NULL == child) { | |
1014 | - php_error(E_WARNING, "%s() couldn't add newnode as the previous sibling of refnode", get_active_function_name(TSRMLS_C)); | |
1015 | + php_error(E_WARNING, "%s(): couldn't add newnode as the previous sibling of refnode", get_active_function_name(TSRMLS_C)); | |
1016 | RETURN_FALSE; | |
1017 | } | |
1018 | ||
1019 | @@ -1783,11 +2037,35 @@ PHP_FUNCTION(domxml_node_set_content) | |
1020 | /* FIXME: Actually the property 'content' of the node has to be updated | |
1021 | as well. Since 'content' should disappear sooner or later and being | |
1022 | replaces by a function 'content()' I skip this for now | |
1023 | - */ | |
1024 | + */ | |
1025 | RETURN_TRUE; | |
1026 | } | |
1027 | /* }}} */ | |
1028 | ||
1029 | +/* {{{ proto string domxml_node_get_content() | |
1030 | + Gets content of a node. | |
1031 | + | |
1032 | + "Read the value of a node, this can be either the text carried directly by | |
1033 | +this node if it's a TEXT node or the aggregate string of the values carried by | |
1034 | +this node child's (TEXT and ENTITY_REF). Entity references are substituted." | |
1035 | + */ | |
1036 | +PHP_FUNCTION(domxml_node_get_content) | |
1037 | +{ | |
1038 | + zval *id; | |
1039 | + xmlNode *nodep; | |
1040 | + xmlChar *mem; | |
1041 | + | |
1042 | + DOMXML_PARAM_NONE(nodep, id, le_domxmlnodep); | |
1043 | + mem = xmlNodeGetContent(nodep); | |
1044 | + if (!mem) { | |
1045 | + RETURN_FALSE; | |
1046 | + } | |
1047 | + | |
1048 | + RETURN_STRING(mem,1); | |
1049 | +} | |
1050 | +/* }}} */ | |
1051 | + | |
1052 | + | |
1053 | /* End of Methods DomNode }}} */ | |
1054 | ||
1055 | ||
1056 | @@ -1902,7 +2180,7 @@ PHP_FUNCTION(domxml_elem_set_attribute) | |
1057 | ||
1058 | attr = xmlSetProp(nodep, name, value); | |
1059 | if (!attr) { | |
1060 | - php_error(E_WARNING, "%s() no such attribute '%s'", get_active_function_name(TSRMLS_C), name); | |
1061 | + php_error(E_WARNING, "%s(): no such attribute '%s'", get_active_function_name(TSRMLS_C), name); | |
1062 | RETURN_FALSE; | |
1063 | } | |
1064 | ||
1065 | @@ -1966,7 +2244,7 @@ PHP_FUNCTION(domxml_elem_set_attribute_n | |
1066 | xmlAttr *attrp; | |
1067 | ||
1068 | DOMXML_NOT_IMPLEMENTED(); | |
1069 | - | |
1070 | + | |
1071 | if ((ZEND_NUM_ARGS() == 1) && getParameters(ht, 1, &arg1) == SUCCESS) { | |
1072 | id = getThis(); | |
1073 | nodep = php_dom_get_object(id, le_domxmlelementp, 0 TSRMLS_CC); | |
1074 | @@ -2052,8 +2330,8 @@ PHP_FUNCTION(domxml_doc_doctype) | |
1075 | Returns DomeDOMImplementation */ | |
1076 | PHP_FUNCTION(domxml_doc_implementation) | |
1077 | { | |
1078 | - zval *id; | |
1079 | - xmlDocPtr docp; | |
1080 | +/* zval *id; | |
1081 | + xmlDocPtr docp;*/ | |
1082 | ||
1083 | DOMXML_NOT_IMPLEMENTED(); | |
1084 | ||
1085 | @@ -2283,7 +2561,7 @@ PHP_FUNCTION(domxml_doc_create_processin | |
1086 | } | |
1087 | /* }}} */ | |
1088 | ||
1089 | -/* {{{ proto object domxml_doc_imported_node(int node, bool recursive) | |
1090 | +/* {{{ proto object domxml_doc_imported_node(object node, bool recursive) | |
1091 | Creates new element node */ | |
1092 | PHP_FUNCTION(domxml_doc_imported_node) | |
1093 | { | |
1094 | @@ -2311,7 +2589,7 @@ PHP_FUNCTION(domxml_doc_imported_node) | |
1095 | } | |
1096 | /* }}} */ | |
1097 | ||
1098 | -/* {{{ proto object domxml_dtd([int doc_handle]) | |
1099 | +/* {{{ proto object domxml_dtd(void) | |
1100 | Returns DTD of document */ | |
1101 | PHP_FUNCTION(domxml_intdtd) | |
1102 | { | |
1103 | @@ -2331,9 +2609,9 @@ PHP_FUNCTION(domxml_intdtd) | |
1104 | } | |
1105 | /* }}} */ | |
1106 | ||
1107 | -/* {{{ proto string domxml_dumpmem([int doc_handle]) | |
1108 | +/* {{{ proto string domxml_dump_mem([object doc_handle]) | |
1109 | Dumps document into string */ | |
1110 | -PHP_FUNCTION(domxml_dumpmem) | |
1111 | +PHP_FUNCTION(domxml_dump_mem) | |
1112 | { | |
1113 | zval *id; | |
1114 | xmlDoc *docp; | |
1115 | @@ -2341,7 +2619,6 @@ PHP_FUNCTION(domxml_dumpmem) | |
1116 | int size; | |
1117 | ||
1118 | DOMXML_PARAM_NONE(docp, id, le_domxmldocp); | |
1119 | - | |
1120 | xmlDocDumpMemory(docp, &mem, &size); | |
1121 | if (!size) { | |
1122 | RETURN_FALSE; | |
1123 | @@ -2350,6 +2627,73 @@ PHP_FUNCTION(domxml_dumpmem) | |
1124 | } | |
1125 | /* }}} */ | |
1126 | ||
1127 | +/* {{{ proto int domxml_dump_mem_file([object doc_handle],filename,compressmode) | |
1128 | + Dumps document into file and uses compression if specified | |
1129 | + Returns false on error, otherwise the length of the xml-document (uncompressed) | |
1130 | + */ | |
1131 | +PHP_FUNCTION(domxml_dump_mem_file) | |
1132 | +{ | |
1133 | + zval *id; | |
1134 | + xmlDoc *docp; | |
1135 | + int file_len, bytes; | |
1136 | + int compressmode = 0; | |
1137 | + char *file; | |
1138 | + DOMXML_PARAM_THREE(docp, id, le_domxmldocp, "s|l", &file, &file_len, &compressmode); | |
1139 | + | |
1140 | + xmlSetCompressMode (compressmode); | |
1141 | + bytes = xmlSaveFile(file,docp); | |
1142 | + if (bytes == -1) | |
1143 | + { | |
1144 | + RETURN_FALSE; | |
1145 | + } | |
1146 | + RETURN_LONG(bytes); | |
1147 | +} | |
1148 | +/* }}} */ | |
1149 | + | |
1150 | +/* {{{ proto string domxml_dump_node([object doc_handle],object node_handle[,int format[,int level]]) | |
1151 | + Dumps node into string */ | |
1152 | +PHP_FUNCTION(domxml_dump_node) | |
1153 | +{ | |
1154 | + zval *id, *nodep; | |
1155 | + xmlDocPtr docp; | |
1156 | + xmlNodePtr elementp; | |
1157 | + xmlChar *mem ; | |
1158 | + xmlBufferPtr buf; | |
1159 | + int level = 0; | |
1160 | + int format = 0; | |
1161 | + | |
1162 | + DOMXML_PARAM_THREE(docp, id, le_domxmldocp,"o|ll",&nodep,&format,&level); | |
1163 | + | |
1164 | + DOMXML_GET_OBJ(elementp, nodep, le_domxmlnodep); | |
1165 | + | |
1166 | + if (Z_TYPE_P(elementp) == XML_DOCUMENT_NODE || Z_TYPE_P(elementp) == XML_HTML_DOCUMENT_NODE ) { | |
1167 | + php_error(E_WARNING, "%s(): cannot dump element with a document node", get_active_function_name(TSRMLS_C)); | |
1168 | + RETURN_FALSE; | |
1169 | + } | |
1170 | + | |
1171 | + buf = xmlBufferCreate(); | |
1172 | + if (!buf) | |
1173 | + { | |
1174 | + php_error(E_WARNING, "%s(): could fetch buffer", get_active_function_name(TSRMLS_C)); | |
1175 | + RETURN_FALSE; | |
1176 | + } | |
1177 | + | |
1178 | + xmlNodeDump(buf, docp, elementp,level,format); | |
1179 | + | |
1180 | + mem = (xmlChar*) xmlBufferContent(buf); | |
1181 | + | |
1182 | + if (!mem) { | |
1183 | + xmlBufferFree(buf); | |
1184 | + RETURN_FALSE; | |
1185 | + } | |
1186 | + RETVAL_STRING(mem, 1); | |
1187 | + | |
1188 | + xmlBufferFree(buf); | |
1189 | + | |
1190 | +} | |
1191 | +/* }}} */ | |
1192 | + | |
1193 | + | |
1194 | /* {{{ proto object xmldoc(string xmldoc [, bool from_file]) | |
1195 | Creates DOM object of XML document */ | |
1196 | PHP_FUNCTION(xmldoc) | |
1197 | @@ -2413,6 +2757,106 @@ PHP_FUNCTION(xmldocfile) | |
1198 | } | |
1199 | /* }}} */ | |
1200 | ||
1201 | +#if defined(LIBXML_HTML_ENABLED) | |
1202 | +/* {{{ proto string domxml_html_dump_mem([int doc_handle]) | |
1203 | + Dumps document into string as HTML */ | |
1204 | +PHP_FUNCTION(domxml_html_dump_mem) | |
1205 | +{ | |
1206 | + zval *id; | |
1207 | + xmlDoc *docp; | |
1208 | + xmlChar *mem; | |
1209 | + int size; | |
1210 | + | |
1211 | + DOMXML_PARAM_NONE(docp, id, le_domxmldocp); | |
1212 | + | |
1213 | + htmlDocDumpMemory(docp, &mem, &size); | |
1214 | + if (!size) { | |
1215 | + RETURN_FALSE; | |
1216 | + } | |
1217 | + RETURN_STRINGL(mem, size, 1); | |
1218 | +} | |
1219 | +/* }}} */ | |
1220 | + | |
1221 | +/* {{{ proto object html_doc(string html_doc [, bool from_file]) | |
1222 | + Creates DOM object of HTML document */ | |
1223 | +PHP_FUNCTION(html_doc) | |
1224 | +{ | |
1225 | + zval *rv; | |
1226 | + xmlDoc *docp; | |
1227 | + int ret; | |
1228 | + char *buffer; | |
1229 | + int buffer_len; | |
1230 | + zend_bool from_file = 0; | |
1231 | + | |
1232 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &buffer, &buffer_len, &from_file) == FAILURE) { | |
1233 | + return; | |
1234 | + } | |
1235 | + | |
1236 | + if (from_file) { | |
1237 | + docp = htmlParseFile(buffer, NULL); | |
1238 | + } else { | |
1239 | + docp = htmlParseDoc(buffer, NULL); | |
1240 | + } | |
1241 | + if (!docp) | |
1242 | + RETURN_FALSE; | |
1243 | + | |
1244 | + DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret); | |
1245 | +} | |
1246 | +/* }}} */ | |
1247 | + | |
1248 | +/* {{{ proto object html_doc_file(string filename) | |
1249 | + Creates DOM object of HTML document in file */ | |
1250 | +PHP_FUNCTION(html_doc_file) | |
1251 | +{ | |
1252 | + zval *rv; | |
1253 | + xmlDoc *docp; | |
1254 | + int ret, file_len; | |
1255 | + char *file; | |
1256 | + | |
1257 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) { | |
1258 | + return; | |
1259 | + } | |
1260 | + | |
1261 | + docp = htmlParseFile(file, NULL); | |
1262 | + if (!docp) { | |
1263 | + RETURN_FALSE; | |
1264 | + } | |
1265 | + | |
1266 | + DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret); | |
1267 | + | |
1268 | + add_property_resource(return_value, "doc", ret); | |
1269 | + if (docp->name) | |
1270 | + add_property_stringl(return_value, "name", (char *) docp->name, strlen(docp->name), 1); | |
1271 | + if (docp->URL) | |
1272 | + add_property_stringl(return_value, "url", (char *) docp->URL, strlen(docp->URL), 1); | |
1273 | + if (docp->version) | |
1274 | + add_property_stringl(return_value, "version", (char *) docp->version, strlen(docp->version), 1); | |
1275 | +/* add_property_stringl(return_value, "version", (char *) docp->version, strlen(docp->version), 1);*/ | |
1276 | + if (docp->encoding) | |
1277 | + add_property_stringl(return_value, "encoding", (char *) docp->encoding, strlen(docp->encoding), 1); | |
1278 | + add_property_long(return_value, "standalone", docp->standalone); | |
1279 | + add_property_long(return_value, "type", Z_TYPE_P(docp)); | |
1280 | + add_property_long(return_value, "compression", docp->compression); | |
1281 | + add_property_long(return_value, "charset", docp->charset); | |
1282 | + zend_list_addref(ret); | |
1283 | +} | |
1284 | +/* }}} */ | |
1285 | +#endif /* defined(LIBXML_HTML_ENABLED) */ | |
1286 | + | |
1287 | +/* {{{ proto bool domxml_substitute_entities_default(bool enable) | |
1288 | + Set and return the previous value for default entity support */ | |
1289 | +PHP_FUNCTION(domxml_substitute_entities_default) | |
1290 | +{ | |
1291 | + zend_bool enable; | |
1292 | + | |
1293 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &enable) == FAILURE) { | |
1294 | + return; | |
1295 | + } | |
1296 | + | |
1297 | + RETURN_BOOL(xmlSubstituteEntitiesDefault(enable)); | |
1298 | +} | |
1299 | +/* }}} */ | |
1300 | + | |
1301 | /* {{{ proto bool domxml_node_text_concat(string content) | |
1302 | Add string tocontent of a node */ | |
1303 | PHP_FUNCTION(domxml_node_text_concat) | |
1304 | @@ -2421,7 +2865,7 @@ PHP_FUNCTION(domxml_node_text_concat) | |
1305 | xmlNode *nodep; | |
1306 | char *content; | |
1307 | int content_len; | |
1308 | - | |
1309 | + | |
1310 | DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep); | |
1311 | ||
1312 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &content, &content_len) == FAILURE) { | |
1313 | @@ -2589,7 +3033,7 @@ static int node_children(zval **children | |
1314 | ||
1315 | /* Get the namespace of the current node and add it as a property */ | |
1316 | /* XXX FIXME XXX */ | |
1317 | -/* | |
1318 | +/* | |
1319 | if(!node_namespace(&namespace, last)) | |
1320 | zend_hash_update(Z_OBJPROP_P(child), "namespace", sizeof("namespace"), (void *) &namespace, sizeof(zval *), NULL); | |
1321 | */ | |
1322 | @@ -2619,7 +3063,7 @@ PHP_FUNCTION(xmltree) | |
1323 | xmlNode *root; | |
1324 | int ret, buf_len; | |
1325 | char *buf; | |
1326 | - | |
1327 | + | |
1328 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &buf_len) == FAILURE) { | |
1329 | return; | |
1330 | } | |
1331 | @@ -2690,7 +3134,7 @@ static void php_xpathptr_new_context(INT | |
1332 | } | |
1333 | /* }}} */ | |
1334 | ||
1335 | -/* {{{ proto string xpath_new_context([int doc_handle]) | |
1336 | +/* {{{ proto object xpath_new_context([int doc_handle]) | |
1337 | Creates new XPath context */ | |
1338 | PHP_FUNCTION(xpath_new_context) | |
1339 | { | |
1340 | @@ -2698,7 +3142,7 @@ PHP_FUNCTION(xpath_new_context) | |
1341 | } | |
1342 | /* }}} */ | |
1343 | ||
1344 | -/* {{{ proto string xptr_new_context([int doc_handle]) | |
1345 | +/* {{{ proto object xptr_new_context([int doc_handle]) | |
1346 | Creates new XPath context */ | |
1347 | PHP_FUNCTION(xptr_new_context) | |
1348 | { | |
1349 | @@ -2731,10 +3175,10 @@ static void php_xpathptr_eval(INTERNAL_F | |
1350 | } | |
1351 | ||
1352 | ctxp = php_xpath_get_context(id, le_xpathctxp, 0 TSRMLS_CC); | |
1353 | - if (!ctxp) { | |
1354 | - php_error(E_WARNING, "%s() cannot fetch XPATH context", get_active_function_name(TSRMLS_C)); | |
1355 | - RETURN_FALSE; | |
1356 | - } | |
1357 | + if (!ctxp) { | |
1358 | + php_error(E_WARNING, "%s(): cannot fetch XPATH context", get_active_function_name(TSRMLS_C)); | |
1359 | + RETURN_FALSE; | |
1360 | + } | |
1361 | ||
1362 | if (contextnode) { | |
1363 | DOMXML_GET_OBJ(contextnodep, contextnode, le_domxmlnodep); | |
1364 | @@ -2761,7 +3205,7 @@ static void php_xpathptr_eval(INTERNAL_F | |
1365 | } | |
1366 | ||
1367 | if (NULL == (rv = php_xpathobject_new(xpathobjp, &ret TSRMLS_CC))) { | |
1368 | - php_error(E_WARNING, "%s() cannot create required XPATH objcet", get_active_function_name(TSRMLS_C)); | |
1369 | + php_error(E_WARNING, "%s(): cannot create required XPATH objcet", get_active_function_name(TSRMLS_C)); | |
1370 | RETURN_FALSE; | |
1371 | } | |
1372 | SEPARATE_ZVAL(&rv); | |
1373 | @@ -2836,7 +3280,7 @@ static void php_xpathptr_eval(INTERNAL_F | |
1374 | } | |
1375 | /* }}} */ | |
1376 | ||
1377 | -/* {{{ proto int xpath_eval([int xpathctx_handle,] string str) | |
1378 | +/* {{{ proto object xpath_eval([object xpathctx_handle,] string str) | |
1379 | Evaluates the XPath Location Path in the given string */ | |
1380 | PHP_FUNCTION(xpath_eval) | |
1381 | { | |
1382 | @@ -2844,13 +3288,46 @@ PHP_FUNCTION(xpath_eval) | |
1383 | } | |
1384 | /* }}} */ | |
1385 | ||
1386 | -/* {{{ proto int xpath_eval_expression([int xpathctx_handle,] string str) | |
1387 | - Evaluates the XPath Location Path in the given string */ | |
1388 | +/* {{{ proto object xpath_eval_expression([object xpathctx_handle,] string str) | |
1389 | + Evaluates the XPath expression in the given string */ | |
1390 | PHP_FUNCTION(xpath_eval_expression) | |
1391 | { | |
1392 | php_xpathptr_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_XPATH, 1); | |
1393 | } | |
1394 | /* }}} */ | |
1395 | + | |
1396 | +/* {{{ proto bool xpath_register_ns([object xpathctx_handle,] string namespace_prefix, string namespace_uri) | |
1397 | + Registeres the given namespace in the passed XPath context */ | |
1398 | +PHP_FUNCTION(xpath_register_ns) | |
1399 | +{ | |
1400 | + /* | |
1401 | + TODO: | |
1402 | + - automagically register all namespaces when creating a new context | |
1403 | + */ | |
1404 | + | |
1405 | + int prefix_len, uri_len, result; | |
1406 | + xmlXPathContextPtr ctxp; | |
1407 | + char *prefix, *uri, *uri_static; | |
1408 | + zval *id; | |
1409 | + | |
1410 | + DOMXML_PARAM_FOUR(ctxp, id, le_xpathctxp, "ss", &prefix, &prefix_len, &uri, &uri_len); | |
1411 | + | |
1412 | + /* set the context node to NULL - what is a context node anyway? */ | |
1413 | + ctxp->node = NULL; | |
1414 | + | |
1415 | + /* | |
1416 | + this is a hack - libxml2 doesn't copy the URI, it simply uses the string | |
1417 | + given in the parameter - which is normally deallocated after the function | |
1418 | + */ | |
1419 | + uri_static = estrndup(uri, uri_len); | |
1420 | + result = xmlXPathRegisterNs(ctxp, prefix, uri_static); | |
1421 | + | |
1422 | + if (0 == result) { | |
1423 | + RETURN_TRUE; | |
1424 | + } | |
1425 | + RETURN_FALSE; | |
1426 | +} | |
1427 | +/* }}} */ | |
1428 | #endif /* defined(LIBXML_XPATH_ENABLED) */ | |
1429 | ||
1430 | #if defined(LIBXML_XPTR_ENABLED) | |
1431 | @@ -2864,12 +3341,266 @@ PHP_FUNCTION(xptr_eval) | |
1432 | #endif /* LIBXML_XPTR_ENABLED */ | |
1433 | ||
1434 | /* {{{ proto string domxml_version(void) | |
1435 | - Dumps document into string */ | |
1436 | + Get XML library version */ | |
1437 | PHP_FUNCTION(domxml_version) | |
1438 | { | |
1439 | RETURN_STRING(LIBXML_DOTTED_VERSION, 1); | |
1440 | } | |
1441 | /* }}} */ | |
1442 | + | |
1443 | +#if HAVE_DOMXSLT | |
1444 | +static zval *php_xsltstylesheet_new(xsltStylesheetPtr obj, int *found TSRMLS_DC) | |
1445 | +{ | |
1446 | + zval *wrapper; | |
1447 | + int rsrc_type; | |
1448 | + | |
1449 | + if (! found) { | |
1450 | + *found = 0; | |
1451 | + } | |
1452 | + | |
1453 | + if (!obj) { | |
1454 | + MAKE_STD_ZVAL(wrapper); | |
1455 | + ZVAL_NULL(wrapper); | |
1456 | + return wrapper; | |
1457 | + } | |
1458 | + | |
1459 | + if ((wrapper = (zval *) dom_object_get_data((void *) obj))) { | |
1460 | + zval_add_ref(&wrapper); | |
1461 | + *found = 1; | |
1462 | + return wrapper; | |
1463 | + } | |
1464 | + | |
1465 | + MAKE_STD_ZVAL(wrapper); | |
1466 | + | |
1467 | + object_init_ex(wrapper, domxsltstylesheet_class_entry); | |
1468 | + rsrc_type = le_domxsltstylesheetp; | |
1469 | + php_xsltstylesheet_set_object(wrapper, (void *) obj, rsrc_type); | |
1470 | + | |
1471 | + return (wrapper); | |
1472 | +} | |
1473 | + | |
1474 | +/* {{{ proto object domxml_xslt_stylesheet(string xsltstylesheet) | |
1475 | + Creates XSLT Stylesheet object from string */ | |
1476 | +PHP_FUNCTION(domxml_xslt_stylesheet) | |
1477 | +{ | |
1478 | + zval *rv; | |
1479 | + xmlDocPtr docp; | |
1480 | + xsltStylesheetPtr sheetp; | |
1481 | + int ret; | |
1482 | + char *buffer; | |
1483 | + int buffer_len; | |
1484 | + | |
1485 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, &buffer_len) == FAILURE) { | |
1486 | + RETURN_FALSE; | |
1487 | + } | |
1488 | + | |
1489 | + docp = xmlParseDoc(buffer); | |
1490 | + | |
1491 | + if (!docp) | |
1492 | + RETURN_FALSE; | |
1493 | + | |
1494 | + sheetp = xsltParseStylesheetDoc(docp); | |
1495 | + | |
1496 | + if (!sheetp) | |
1497 | + RETURN_FALSE; | |
1498 | + | |
1499 | + rv = php_xsltstylesheet_new(sheetp, &ret TSRMLS_CC); | |
1500 | + DOMXML_RET_ZVAL(rv); | |
1501 | +} | |
1502 | +/* }}} */ | |
1503 | + | |
1504 | +/* {{{ proto object domxml_xslt_stylesheet_doc(object xmldoc) | |
1505 | + Creates XSLT Stylesheet object from DOM Document object */ | |
1506 | +PHP_FUNCTION(domxml_xslt_stylesheet_doc) | |
1507 | +{ | |
1508 | + zval *rv, *idxml; | |
1509 | + xmlDocPtr docp; | |
1510 | + xmlDocPtr newdocp; | |
1511 | + xsltStylesheetPtr sheetp; | |
1512 | + int ret; | |
1513 | + | |
1514 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &idxml) == FAILURE) { | |
1515 | + RETURN_FALSE; | |
1516 | + } | |
1517 | + | |
1518 | + DOMXML_GET_OBJ(docp, idxml, le_domxmldocp); | |
1519 | + | |
1520 | + newdocp = xmlCopyDoc(docp, 1); | |
1521 | + | |
1522 | + if (!newdocp) | |
1523 | + RETURN_FALSE; | |
1524 | + | |
1525 | + sheetp = xsltParseStylesheetDoc(newdocp); | |
1526 | + | |
1527 | + if (!sheetp) | |
1528 | + RETURN_FALSE; | |
1529 | + | |
1530 | + rv = php_xsltstylesheet_new(sheetp, &ret TSRMLS_CC); | |
1531 | + DOMXML_RET_ZVAL(rv); | |
1532 | +} | |
1533 | +/* }}} */ | |
1534 | + | |
1535 | +/* {{{ proto object domxml_xslt_stylesheet_file(string filename) | |
1536 | + Creates XSLT Stylesheet object from file */ | |
1537 | +PHP_FUNCTION(domxml_xslt_stylesheet_file) | |
1538 | +{ | |
1539 | + zval *rv; | |
1540 | + xsltStylesheetPtr sheetp; | |
1541 | + int ret, file_len; | |
1542 | + char *file; | |
1543 | + | |
1544 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) { | |
1545 | + RETURN_FALSE; | |
1546 | + } | |
1547 | + | |
1548 | + sheetp = xsltParseStylesheetFile(file); | |
1549 | + | |
1550 | + if (!sheetp) | |
1551 | + RETURN_FALSE; | |
1552 | + | |
1553 | + rv = php_xsltstylesheet_new(sheetp, &ret TSRMLS_CC); | |
1554 | + DOMXML_RET_ZVAL(rv); | |
1555 | +} | |
1556 | +/* }}} */ | |
1557 | + | |
1558 | +/* {{{ php_domxslt_string_to_xpathexpr() | |
1559 | + Translates a string to a XPath Expression */ | |
1560 | +static char *php_domxslt_string_to_xpathexpr(const char *str) | |
1561 | +{ | |
1562 | + const xmlChar *string = (const xmlChar *)str; | |
1563 | + | |
1564 | + xmlChar *value; | |
1565 | + | |
1566 | + TSRMLS_FETCH(); | |
1567 | + | |
1568 | + if (xmlStrchr(string, '"')) { | |
1569 | + if (xmlStrchr(string, '\'')) { | |
1570 | + php_error(E_WARNING, "Cannot create XPath expression (string contains both quote and double-quotes) in %s", | |
1571 | + get_active_function_name(TSRMLS_C)); | |
1572 | + return NULL; | |
1573 | + } | |
1574 | + value = xmlStrdup((const xmlChar *)"'"); | |
1575 | + value = xmlStrcat(value, string); | |
1576 | + value = xmlStrcat(value, (const xmlChar *)"'"); | |
1577 | + } | |
1578 | + else { | |
1579 | + value = xmlStrdup((const xmlChar *)"\""); | |
1580 | + value = xmlStrcat(value, string); | |
1581 | + value = xmlStrcat(value, (const xmlChar *)"\""); | |
1582 | + } | |
1583 | + | |
1584 | + return (char *)value; | |
1585 | +} | |
1586 | + | |
1587 | +/* {{{ php_domxslt_make_params() | |
1588 | + Translates a PHP array to a libxslt parameters array */ | |
1589 | +static char **php_domxslt_make_params(zval *idvars, int xpath_params) | |
1590 | +{ | |
1591 | + HashTable *parht; | |
1592 | + int parsize; | |
1593 | + zval **value; | |
1594 | + char *xpath_expr, *string_key = NULL; | |
1595 | + ulong num_key; | |
1596 | + char **params = NULL; | |
1597 | + int i = 0; | |
1598 | + | |
1599 | + TSRMLS_FETCH(); | |
1600 | + | |
1601 | + parht = HASH_OF(idvars); | |
1602 | + parsize = (2 * zend_hash_num_elements(parht) + 1) * sizeof(char *); | |
1603 | + params = (char **)emalloc(parsize); | |
1604 | + memset((char *)params, 0, parsize); | |
1605 | + | |
1606 | + for (zend_hash_internal_pointer_reset(parht); | |
1607 | + zend_hash_get_current_data(parht, (void **)&value) == SUCCESS; | |
1608 | + zend_hash_move_forward(parht)) { | |
1609 | + | |
1610 | + if (zend_hash_get_current_key(parht, &string_key, &num_key, 1) != HASH_KEY_IS_STRING) { | |
1611 | + php_error(E_WARNING, "Invalid argument or parameter array to %s", | |
1612 | + get_active_function_name(TSRMLS_C)); | |
1613 | + return NULL; | |
1614 | + } | |
1615 | + else { | |
1616 | + SEPARATE_ZVAL(value); | |
1617 | + convert_to_string_ex(value); | |
1618 | + | |
1619 | + if (!xpath_params) { | |
1620 | + xpath_expr = php_domxslt_string_to_xpathexpr(Z_STRVAL_PP(value)); | |
1621 | + } | |
1622 | + else { | |
1623 | + xpath_expr = Z_STRVAL_PP(value); | |
1624 | + } | |
1625 | + | |
1626 | + if (xpath_expr) { | |
1627 | + params[i++] = string_key; | |
1628 | + params[i++] = xpath_expr; | |
1629 | + } | |
1630 | + } | |
1631 | + } | |
1632 | + | |
1633 | + params[i++] = NULL; | |
1634 | + | |
1635 | + return params; | |
1636 | +} | |
1637 | + | |
1638 | +/* {{{ proto object domxml_xslt_process(object xslstylesheet, object xmldoc [, array xslt_parameters [, bool xpath_parameters]]) | |
1639 | + Perform an XSLT transformation */ | |
1640 | +PHP_FUNCTION(domxml_xslt_process) | |
1641 | +{ | |
1642 | +/* TODO: | |
1643 | + - test memory deallocation | |
1644 | + - test other stuff | |
1645 | + - check xsltsp->errors ??? | |
1646 | +*/ | |
1647 | + zval *rv, *idxsl, *idxml, *idparams = NULL; | |
1648 | + zend_bool xpath_params = 0; | |
1649 | + xsltStylesheetPtr xsltstp; | |
1650 | + xmlDocPtr xmldocp; | |
1651 | + xmlDocPtr docp; | |
1652 | + char **params = NULL; | |
1653 | + int ret; | |
1654 | + | |
1655 | + DOMXML_GET_THIS(idxsl); | |
1656 | + | |
1657 | + xsltstp = php_xsltstylesheet_get_object(idxsl, le_domxsltstylesheetp, 0 TSRMLS_CC); | |
1658 | + if (!xsltstp) { | |
1659 | + php_error(E_WARNING, "%s(): underlying object missing", | |
1660 | + get_active_function_name(TSRMLS_C)); | |
1661 | + RETURN_FALSE; | |
1662 | + } | |
1663 | + | |
1664 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|ab", &idxml, &idparams, &xpath_params) == FAILURE) { | |
1665 | + RETURN_FALSE; | |
1666 | + } | |
1667 | + | |
1668 | + DOMXML_GET_OBJ(xmldocp, idxml, le_domxmldocp); | |
1669 | + | |
1670 | + if (idparams) { | |
1671 | + params = php_domxslt_make_params(idparams, xpath_params); | |
1672 | + } | |
1673 | + | |
1674 | + docp = xsltApplyStylesheet(xsltstp, xmldocp, (const char**)params); | |
1675 | + | |
1676 | + if (params) { | |
1677 | + efree(params); | |
1678 | + } | |
1679 | + | |
1680 | + if (!docp) { | |
1681 | + RETURN_FALSE; | |
1682 | + } | |
1683 | + | |
1684 | + DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret); | |
1685 | +} | |
1686 | +/* }}} */ | |
1687 | + | |
1688 | +/* {{{ proto string domxml_xslt_version(void) | |
1689 | + Get XSLT library version */ | |
1690 | +PHP_FUNCTION(domxml_xslt_version) | |
1691 | +{ | |
1692 | + RETURN_STRING(LIBXSLT_DOTTED_VERSION, 1); | |
1693 | +} | |
1694 | +/* }}} */ | |
1695 | +#endif /* HAVE_DOMXSLT */ | |
1696 | ||
1697 | #endif /* HAVE_DOMXML */ | |
1698 | ||
1699 | diff -upr php-4.1.2/ext/domxml/php_domxml.h php-4.1.2-dom-xslt/ext/domxml/php_domxml.h | |
1700 | --- php-4.1.2/ext/domxml/php_domxml.h Fri Dec 14 11:45:46 2001 | |
1701 | +++ php-4.1.2-dom-xslt/ext/domxml/php_domxml.h Tue Jan 22 00:21:32 2002 | |
1702 | @@ -16,19 +16,36 @@ | |
1703 | +----------------------------------------------------------------------+ | |
1704 | */ | |
1705 | ||
1706 | -/* $Id$ */ | |
1707 | +/* $Id$ */ | |
1708 | ||
1709 | #ifndef PHP_DOMXML_H | |
1710 | #define PHP_DOMXML_H | |
1711 | ||
1712 | #if HAVE_DOMXML | |
1713 | #include <libxml/parser.h> | |
1714 | +#include <libxml/tree.h> | |
1715 | +#include <libxml/xmlerror.h> | |
1716 | +#if defined(LIBXML_HTML_ENABLED) | |
1717 | +#include <libxml/HTMLparser.h> | |
1718 | +#include <libxml/HTMLtree.h> | |
1719 | +#endif | |
1720 | #if defined(LIBXML_XPATH_ENABLED) | |
1721 | #include <libxml/xpath.h> | |
1722 | +#include <libxml/xpathInternals.h> | |
1723 | #endif | |
1724 | #if defined(LIBXML_XPTR_ENABLED) | |
1725 | #include <libxml/xpointer.h> | |
1726 | #endif | |
1727 | +#if HAVE_DOMXSLT | |
1728 | +#include <libxslt/xsltconfig.h> | |
1729 | +#include <libxslt/xsltInternals.h> | |
1730 | +#include <libxslt/xsltutils.h> | |
1731 | +#include <libxslt/transform.h> | |
1732 | +#if HAVE_DOMEXSLT | |
1733 | +#include <libexslt/exslt.h> | |
1734 | +#include <libexslt/exsltconfig.h> | |
1735 | +#endif | |
1736 | +#endif | |
1737 | ||
1738 | extern zend_module_entry domxml_module_entry; | |
1739 | #define domxml_module_ptr &domxml_module_entry | |
1740 | @@ -40,8 +57,13 @@ PHP_MINFO_FUNCTION(domxml); | |
1741 | PHP_FUNCTION(domxml_version); | |
1742 | PHP_FUNCTION(xmldoc); | |
1743 | PHP_FUNCTION(xmldocfile); | |
1744 | +#if defined(LIBXML_HTML_ENABLED) | |
1745 | +PHP_FUNCTION(html_doc); | |
1746 | +PHP_FUNCTION(html_doc_file); | |
1747 | +#endif | |
1748 | PHP_FUNCTION(xmltree); | |
1749 | PHP_FUNCTION(domxml_new_xmldoc); | |
1750 | +PHP_FUNCTION(domxml_substitute_entities_default); | |
1751 | ||
1752 | /* Class Document methods */ | |
1753 | PHP_FUNCTION(domxml_doc_doctype); | |
1754 | @@ -57,7 +79,13 @@ PHP_FUNCTION(domxml_doc_create_entity_re | |
1755 | PHP_FUNCTION(domxml_doc_imported_node); | |
1756 | PHP_FUNCTION(domxml_add_root); | |
1757 | PHP_FUNCTION(domxml_intdtd); | |
1758 | -PHP_FUNCTION(domxml_dumpmem); | |
1759 | +PHP_FUNCTION(domxml_dump_mem); | |
1760 | +PHP_FUNCTION(domxml_dump_mem_file); | |
1761 | +PHP_FUNCTION(domxml_dump_node); | |
1762 | + | |
1763 | +#if defined(LIBXML_HTML_ENABLED) | |
1764 | +PHP_FUNCTION(domxml_html_dump_mem); | |
1765 | +#endif | |
1766 | ||
1767 | /* Class DocumentType methods */ | |
1768 | PHP_FUNCTION(domxml_doctype_name); | |
1769 | @@ -89,8 +117,10 @@ PHP_FUNCTION(domxml_node_prefix); | |
1770 | PHP_FUNCTION(domxml_node); | |
1771 | PHP_FUNCTION(domxml_clone_node); | |
1772 | PHP_FUNCTION(domxml_node_unlink_node); | |
1773 | +PHP_FUNCTION(domxml_node_replace_node); | |
1774 | PHP_FUNCTION(domxml_node_new_child); | |
1775 | PHP_FUNCTION(domxml_node_set_content); | |
1776 | +PHP_FUNCTION(domxml_node_get_content); | |
1777 | PHP_FUNCTION(domxml_node_text_concat); | |
1778 | PHP_FUNCTION(domxml_node_set_name); | |
1779 | PHP_FUNCTION(domxml_node_name); | |
1780 | @@ -135,12 +165,22 @@ PHP_FUNCTION(xpath_init); | |
1781 | PHP_FUNCTION(xpath_new_context); | |
1782 | PHP_FUNCTION(xpath_eval); | |
1783 | PHP_FUNCTION(xpath_eval_expression); | |
1784 | +PHP_FUNCTION(xpath_register_ns); | |
1785 | #endif | |
1786 | #if defined(LIBXML_XPTR_ENABLED) | |
1787 | PHP_FUNCTION(xptr_new_context); | |
1788 | PHP_FUNCTION(xptr_eval); | |
1789 | #endif | |
1790 | PHP_FUNCTION(domxml_test); | |
1791 | + | |
1792 | +/* DOMXSLT functions */ | |
1793 | +#if HAVE_DOMXSLT | |
1794 | +PHP_FUNCTION(domxml_xslt_stylesheet); | |
1795 | +PHP_FUNCTION(domxml_xslt_stylesheet_doc); | |
1796 | +PHP_FUNCTION(domxml_xslt_stylesheet_file); | |
1797 | +PHP_FUNCTION(domxml_xslt_process); | |
1798 | +PHP_FUNCTION(domxml_xslt_version); | |
1799 | +#endif | |
1800 | ||
1801 | #else | |
1802 | #define domxml_module_ptr NULL |