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
6 -dnl config.m4 for extension domxml
11 AC_DEFUN(PHP_DOM_CHECK_VERSION,[
12 old_CPPFLAGS=$CPPFLAGS
13 @@ -20,17 +21,16 @@ AC_DEFUN(PHP_DOM_CHECK_VERSION,[
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,
19 + DIR is the libxml install directory.])
21 if test "$PHP_DOM" != "no"; then
24 - if test -r $PHP_DOM/include/libxml/tree.h; then
26 - elif test -r $PHP_DOM/include/libxml2/libxml/tree.h; then
27 + if test -r $PHP_DOM/include/libxml2/libxml/tree.h; then
29 DOMXML_DIR_ADD="/libxml2"
30 + elif test -r $PHP_DOM/include/libxml/tree.h; then
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)
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)
46 + #include <libxslt/xsltconfig.h>
47 + #if LIBXSLT_VERSION >= 10003
51 + AC_MSG_RESULT(>= 1.0.3)
53 + AC_MSG_ERROR(libxslt version 1.0.3 or greater required.)
55 + CPPFLAGS=$old_CPPFLAGS
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)
63 + #include <libexslt/exsltconfig.h>
64 + #if LIBEXSLT_VERSION >= 600
68 + AC_MSG_RESULT(>= 1.0.3)
70 + AC_MSG_ERROR(libxslt version 1.0.3 or greater required.)
72 + CPPFLAGS=$old_CPPFLAGS
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.])
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.])
83 +if test "$PHP_DOM_XSLT" != "no"; then
85 + if test -r $PHP_DOM_XSLT/include/libxslt/transform.h; then
86 + DOMXSLT_DIR=$PHP_DOM_XSLT
88 + for i in /usr/local /usr; do
89 + test -r $i/include/libxslt/transform.h && DOMXSLT_DIR=$i
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)
98 + PHP_DOM_XSLT_CHECK_VERSION
100 + PHP_ADD_LIBRARY_WITH_PATH(xslt, $DOMXSLT_DIR/lib, DOMXML_SHARED_LIBADD)
102 + PHP_ADD_INCLUDE($DOMXSLT_DIR/include)
104 + if test "$PHP_DOM" = "no"; then
105 + AC_MSG_ERROR(DOMXSLT requires DOMXML. Use --with-dom=<DIR>)
108 + AC_DEFINE(HAVE_DOMXSLT,1,[ ])
110 + PHP_SUBST(DOMXML_SHARED_LIBADD)
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>)
118 + if test "$PHP_DOM_XSLT" = "no"; then
119 + AC_MSG_ERROR(DOMEXSLT requires DOMXSLT. Use --with-dom-xslt=<DIR>)
122 + if test -r $PHP_DOM_EXSLT/include/libexslt/exslt.h; then
123 + DOMEXSLT_DIR=$PHP_DOM_EXSLT
125 + for i in /usr/local /usr; do
126 + test -r $i/include/libexslt/exslt.h && DOMEXSLT_DIR=$i
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)
135 + PHP_DOM_EXSLT_CHECK_VERSION
137 + PHP_ADD_LIBRARY_WITH_PATH(exslt, $DOMEXSLT_DIR/lib, DOMXML_SHARED_LIBADD)
139 + PHP_ADD_INCLUDE($DOMEXSLT_DIR/include)
141 + AC_DEFINE(HAVE_DOMEXSLT,1,[ ])
143 + PHP_SUBST(DOMXML_SHARED_LIBADD)
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
150 +----------------------------------------------------------------------+
157 + * - Support Notation Nodes
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)); \
172 DOMXML_RET_ZVAL(zval);
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)); \
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)); \
189 DOMXML_GET_OBJ(ret, zval, le);
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) { \
196 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s, p1) == FAILURE) { \
200 + DOMXML_GET_OBJ(ret, zval, le);
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) { \
207 DOMXML_GET_OBJ(ret, zval, le);
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) { \
214 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s, p1, p2, p3) == FAILURE) { \
218 + DOMXML_GET_OBJ(ret, zval, le);
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) { \
226 DOMXML_GET_OBJ(ret, zval, le);
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;*/
237 +static int le_domxsltstylesheetp;
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;
247 +zend_class_entry *domxsltstylesheet_class_entry;
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)
255 PHP_FE(xmldocfile, NULL)
256 +#if defined(LIBXML_HTML_ENABLED)
257 + PHP_FE(html_doc, NULL)
258 + PHP_FE(html_doc_file, NULL)
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)
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)
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)
288 #if defined(LIBXML_XPTR_ENABLED)
289 PHP_FE(xptr_new_context, NULL)
290 PHP_FE(xptr_eval, NULL)
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)
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)
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)
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
327 static function_entry php_domxmldoctype_class_functions[] = {
328 PHP_FALIAS(name, domxml_doctype_name, NULL)
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)
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)
363 @@ -299,7 +364,7 @@ static zend_function_entry php_domxmlent
366 static zend_function_entry php_domxmlentity_class_functions[] = {
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)
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)
386 PHP_FALIAS(owner_element, domxml_attr_owner_element, NULL)
389 @@ -339,8 +405,16 @@ static zend_function_entry php_domxmlns_
394 +static zend_function_entry php_domxsltstylesheet_class_functions[] = {
395 +/* TODO: maybe some more methods? */
396 + PHP_FALIAS(process, domxml_xslt_process, NULL)
401 zend_module_entry domxml_module_entry = {
402 - STANDARD_MODULE_HEADER,
403 + STANDARD_MODULE_HEADER,
407 @@ -348,7 +422,7 @@ zend_module_entry domxml_module_entry =
413 STANDARD_MODULE_PROPERTIES
416 @@ -370,14 +444,14 @@ static void dom_object_set_data(void *ob
418 static zval *dom_object_get_data(void *obj)
423 sprintf(tmp, "%08X", obj);
424 fprintf(stderr, "Trying getting %s from object ...", tmp);
425 if(((xmlNodePtr) obj)->_private)
426 fprintf(stderr, " found\n");
428 - fprintf(stderr, " not found\n");
429 + fprintf(stderr, " not found\n");
431 return ((zval *) (((xmlNodePtr) obj)->_private));
433 @@ -411,9 +485,14 @@ static inline void node_list_wrapper_dto
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:
444 + case XML_ENTITY_DECL:
447 + attr_list_wrapper_dtor(node->properties);
449 node_wrapper_dtor(node);
451 @@ -474,6 +553,92 @@ static void php_free_xpath_object(zend_r
456 +static void php_free_xslt_stylesheet(zend_rsrc_list_entry *rsrc TSRMLS_DC)
458 + xsltStylesheetPtr sheet = (xsltStylesheetPtr) rsrc->ptr;
461 + node_wrapper_dtor((xmlNodePtr) sheet);
462 + xsltFreeStylesheet(sheet);
466 +static void xsltstylesheet_set_data(void *obj, zval *wrapper)
470 + sprintf(tmp, "%08X", obj);
471 + fprintf(stderr, "Adding %s to hash\n", tmp);
473 + ((xsltStylesheetPtr) obj)->_private = wrapper;
477 +static zval *xsltstylesheet_get_data(void *obj)
481 + sprintf(tmp, "%08X", obj);
482 + fprintf(stderr, "Trying getting %s from object ...", tmp);
483 + if(((xmlNodePtr) obj)->_private)
484 + fprintf(stderr, " found\n");
486 + fprintf(stderr, " not found\n");
488 + return ((zval *) (((xsltStylesheetPtr) obj)->_private));
491 +void *php_xsltstylesheet_get_object(zval *wrapper, int rsrc_type1, int rsrc_type2 TSRMLS_DC)
497 + if (NULL == wrapper) {
498 + php_error(E_WARNING, "xsltstylesheet_get_object() invalid wrapper object passed");
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));
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));
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));
521 +static void php_xsltstylesheet_set_object(zval *wrapper, void *obj, int rsrc_type)
523 + zval *handle, *addr;
525 + MAKE_STD_ZVAL(handle);
526 + Z_TYPE_P(handle) = IS_LONG;
527 + Z_LVAL_P(handle) = zend_list_insert(obj, rsrc_type);
529 + MAKE_STD_ZVAL(addr);
530 + Z_TYPE_P(addr) = IS_LONG;
531 + Z_LVAL_P(addr) = (int) obj;
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);
538 +#endif /* HAVE_DOMXSLT */
541 void *php_xpath_get_object(zval *wrapper, int rsrc_type1, int rsrc_type2 TSRMLS_DC)
544 @@ -486,18 +651,18 @@ void *php_xpath_get_object(zval *wrapper
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));
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));
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));
566 @@ -507,7 +672,7 @@ void *php_xpath_get_object(zval *wrapper
568 static void xpath_object_set_data(void *obj, zval *wrapper)
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 *
577 static zval *xpath_object_get_data(void *obj)
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");
589 fprintf(stderr, " not found\n");
591 @@ -574,7 +739,7 @@ static zval *php_xpathobject_new(xmlXPat
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);
599 php_xpath_set_object(wrapper, (void *) obj, le_xpathobjectp);
600 @@ -594,19 +759,19 @@ void *php_xpath_get_context(zval *wrappe
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));
609 if (zend_hash_index_find(Z_OBJPROP_P(wrapper), 0, (void **) &handle) ==
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));
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));
623 @@ -628,9 +793,9 @@ static zval *xpath_context_get_data(void
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");
633 fprintf(stderr, " not found\n");
635 @@ -661,7 +826,7 @@ static zval *php_xpathcontext_new(xmlXPa
644 @@ -677,8 +842,8 @@ static zval *php_xpathcontext_new(xmlXPa
647 MAKE_STD_ZVAL(wrapper);
649 - fprintf(stderr, "Adding new XPath Context\n");
651 + fprintf(stderr, "Adding new XPath Context\n");
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,
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));
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));
670 @@ -713,7 +878,7 @@ void *php_dom_get_object(zval *wrapper,
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));
679 @@ -747,7 +912,7 @@ static zval *php_domobject_new(xmlNodePt
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);
694 + add_property_long(wrapper, "type", Z_TYPE_P(nodep));
695 add_property_stringl(wrapper, "content", (char *) content, strlen(content), 1);
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);
708 @@ -851,8 +1017,10 @@ static zval *php_domobject_new(xmlNodePt
711 case XML_DOCUMENT_NODE:
712 + case XML_HTML_DOCUMENT_NODE:
714 xmlDocPtr docp = (xmlDocPtr) obj;
716 object_init_ex(wrapper, domxmldoc_class_entry);
717 rsrc_type = le_domxmldocp;
719 @@ -863,7 +1031,10 @@ static zval *php_domobject_new(xmlNodePt
720 add_property_stringl(wrapper, "url", (char *) docp->URL, strlen(docp->URL), 1);
722 add_property_stringl(wrapper, "url", "", 0, 1);
723 - add_property_stringl(wrapper, "version", (char *) docp->version, strlen(docp->version), 1);
725 + add_property_stringl(wrapper, "version", (char *) docp->version, strlen(docp->version), 1);
727 + add_property_stringl(wrapper, "version", "", 0, 1);
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
736 - php_error(E_WARNING, "%s() unsupported node type: %d\n", get_active_function_name(TSRMLS_C), Z_TYPE_P(obj));
738 + php_error(E_WARNING, "%s(): unsupported node type: %d\n", get_active_function_name(TSRMLS_C), Z_TYPE_P(obj));
742 @@ -911,6 +1082,17 @@ static zval *php_domobject_new(xmlNodePt
746 +static void domxml_error(void *ctx, const char *msg, ...)
751 + vsnprintf(buf, 1024, msg, ap);
753 + php_error(E_WARNING, buf);
757 PHP_RINIT_FUNCTION(domxml)
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);
767 /* Not yet initialized le_*s */
768 le_domxmldoctypep = -10000;
769 - le_domxmlpip = -10002;
770 le_domxmlnotationp = -10003;
771 - le_domxmlentityrefp = -10004;
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)
777 /* le_domxmlnsp = register_list_destructors(NULL, NULL); */
780 + le_domxsltstylesheetp = zend_register_list_destructors_ex(php_free_xslt_stylesheet, NULL, "xsltstylesheet", module_number);
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);
786 @@ -996,6 +1182,11 @@ PHP_MINIT_FUNCTION(domxml)
787 xpathobject_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
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);
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);
802 + xmlSetGenericErrorFunc(xmlGenericErrorContext, (xmlGenericErrorFunc)domxml_error);
804 + xsltSetGenericErrorFunc(xsltGenericErrorContext, (xmlGenericErrorFunc)domxml_error);
806 + exsltRegisterAll();
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");
821 #if defined(LIBXML_XPATH_ENABLED)
822 php_info_print_table_row(2, "XPath Support", "enabled");
824 #if defined(LIBXML_XPTR_ENABLED)
825 php_info_print_table_row(2, "XPointer Support", "enabled");
828 + php_info_print_table_row(2, "DOM/XSLT", "enabled");
829 + php_info_print_table_row(2, "libxslt Version", LIBXSLT_DOTTED_VERSION);
831 + php_info_print_table_row(2, "DOM/EXSLT", "enabled");
832 + php_info_print_table_row(2, "libexslt Version", LIBEXSLT_DOTTED_VERSION);
836 php_info_print_table_end();
839 @@ -1318,13 +1530,13 @@ PHP_FUNCTION(domxml_is_blank_node)
840 PHP_FUNCTION(domxml_node_type)
846 - DOMXML_GET_THIS_OBJ(n, id, le_domxmlnodep);
847 + DOMXML_GET_THIS_OBJ(node, id, le_domxmlnodep);
851 - RETURN_LONG(Z_TYPE_P(n));
852 + RETURN_LONG(node->type);
856 @@ -1533,7 +1745,7 @@ PHP_FUNCTION(domxml_node_parent)
859 DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
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
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;
873 last = nodep->children;
874 @@ -1579,32 +1791,27 @@ PHP_FUNCTION(domxml_node_children)
878 -/* {{{ proto object domxml_node_unlink_node(void)
880 +/* {{{ proto void domxml_node_unlink_node([object node])
881 + Deletes the node */
882 PHP_FUNCTION(domxml_node_unlink_node)
889 - DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
892 + DOMXML_PARAM_NONE(nodep, id, le_domxmlnodep);
894 xmlUnlinkNode(nodep);
896 zval_dtor(id); /* This is not enough because the children won't be deleted */
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)
906 zval *id, *rv, *node;
907 - xmlNodePtr child, nodep;
908 + xmlNodePtr child, nodep, new_child;
911 DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
912 @@ -1615,10 +1822,20 @@ PHP_FUNCTION(domxml_node_add_child)
914 DOMXML_GET_OBJ(child, node, le_domxmlnodep);
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));
922 + if (NULL == (new_child = xmlCopyNode(child, 1))) {
923 + php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C));
927 + child = xmlAddChild(nodep, new_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));
935 @@ -1626,12 +1843,39 @@ PHP_FUNCTION(domxml_node_add_child)
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)
944 + zval *id, *rv, *node;
945 + xmlNodePtr repnode, nodep, new_repnode;
948 + DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
950 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
954 + DOMXML_GET_OBJ(repnode, node, le_domxmlnodep);
956 + if (NULL == (new_repnode = xmlCopyNode(repnode, 1))) {
957 + php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C));
961 + repnode = xmlReplaceNode(nodep, new_repnode);
963 + DOMXML_RET_OBJ(rv, repnode, &ret);
967 +/* {{{ proto object domxml_node_append_child(object domnode)
968 Adds node to list of children */
969 PHP_FUNCTION(domxml_node_append_child)
971 zval *id, *rv, *node;
972 - xmlNodePtr child, nodep;
973 + xmlNodePtr child, nodep, new_child;
976 DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
977 @@ -1642,11 +1886,21 @@ PHP_FUNCTION(domxml_node_append_child)
979 DOMXML_GET_OBJ(child, node, le_domxmlnodep);
981 + if (child->type == XML_ATTRIBUTE_NODE) {
982 + php_error(E_WARNING, "%s(): can't append attribute node", get_active_function_name(TSRMLS_C));
986 + if (NULL == (new_child = xmlCopyNode(child, 1))) {
987 + php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C));
991 // FIXME reverted xmlAddChildList; crashes
992 - child = xmlAddSibling(nodep, child);
993 + child = xmlAddSibling(nodep, new_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));
1001 @@ -1654,7 +1908,7 @@ PHP_FUNCTION(domxml_node_append_child)
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)
1010 @@ -1674,7 +1928,7 @@ PHP_FUNCTION(domxml_node_insert_before)
1011 child = xmlAddPrevSibling(refp, child);
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));
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
1029 +/* {{{ proto string domxml_node_get_content()
1030 + Gets content of a node.
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."
1036 +PHP_FUNCTION(domxml_node_get_content)
1042 + DOMXML_PARAM_NONE(nodep, id, le_domxmlnodep);
1043 + mem = xmlNodeGetContent(nodep);
1048 + RETURN_STRING(mem,1);
1053 /* End of Methods DomNode }}} */
1056 @@ -1902,7 +2180,7 @@ PHP_FUNCTION(domxml_elem_set_attribute)
1058 attr = xmlSetProp(nodep, name, value);
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);
1065 @@ -1966,7 +2244,7 @@ PHP_FUNCTION(domxml_elem_set_attribute_n
1068 DOMXML_NOT_IMPLEMENTED();
1071 if ((ZEND_NUM_ARGS() == 1) && getParameters(ht, 1, &arg1) == SUCCESS) {
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)
1083 DOMXML_NOT_IMPLEMENTED();
1085 @@ -2283,7 +2561,7 @@ PHP_FUNCTION(domxml_doc_create_processin
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)
1094 @@ -2311,7 +2589,7 @@ PHP_FUNCTION(domxml_doc_imported_node)
1098 -/* {{{ proto object domxml_dtd([int doc_handle])
1099 +/* {{{ proto object domxml_dtd(void)
1100 Returns DTD of document */
1101 PHP_FUNCTION(domxml_intdtd)
1103 @@ -2331,9 +2609,9 @@ PHP_FUNCTION(domxml_intdtd)
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)
1115 @@ -2341,7 +2619,6 @@ PHP_FUNCTION(domxml_dumpmem)
1118 DOMXML_PARAM_NONE(docp, id, le_domxmldocp);
1120 xmlDocDumpMemory(docp, &mem, &size);
1123 @@ -2350,6 +2627,73 @@ PHP_FUNCTION(domxml_dumpmem)
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)
1131 +PHP_FUNCTION(domxml_dump_mem_file)
1135 + int file_len, bytes;
1136 + int compressmode = 0;
1138 + DOMXML_PARAM_THREE(docp, id, le_domxmldocp, "s|l", &file, &file_len, &compressmode);
1140 + xmlSetCompressMode (compressmode);
1141 + bytes = xmlSaveFile(file,docp);
1146 + RETURN_LONG(bytes);
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)
1156 + xmlNodePtr elementp;
1162 + DOMXML_PARAM_THREE(docp, id, le_domxmldocp,"o|ll",&nodep,&format,&level);
1164 + DOMXML_GET_OBJ(elementp, nodep, le_domxmlnodep);
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));
1171 + buf = xmlBufferCreate();
1174 + php_error(E_WARNING, "%s(): could fetch buffer", get_active_function_name(TSRMLS_C));
1178 + xmlNodeDump(buf, docp, elementp,level,format);
1180 + mem = (xmlChar*) xmlBufferContent(buf);
1183 + xmlBufferFree(buf);
1186 + RETVAL_STRING(mem, 1);
1188 + xmlBufferFree(buf);
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)
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)
1211 + DOMXML_PARAM_NONE(docp, id, le_domxmldocp);
1213 + htmlDocDumpMemory(docp, &mem, &size);
1217 + RETURN_STRINGL(mem, size, 1);
1221 +/* {{{ proto object html_doc(string html_doc [, bool from_file])
1222 + Creates DOM object of HTML document */
1223 +PHP_FUNCTION(html_doc)
1230 + zend_bool from_file = 0;
1232 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &buffer, &buffer_len, &from_file) == FAILURE) {
1237 + docp = htmlParseFile(buffer, NULL);
1239 + docp = htmlParseDoc(buffer, NULL);
1244 + DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret);
1248 +/* {{{ proto object html_doc_file(string filename)
1249 + Creates DOM object of HTML document in file */
1250 +PHP_FUNCTION(html_doc_file)
1254 + int ret, file_len;
1257 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
1261 + docp = htmlParseFile(file, NULL);
1266 + DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret);
1268 + add_property_resource(return_value, "doc", ret);
1270 + add_property_stringl(return_value, "name", (char *) docp->name, strlen(docp->name), 1);
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);
1285 +#endif /* defined(LIBXML_HTML_ENABLED) */
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)
1293 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &enable) == FAILURE) {
1297 + RETURN_BOOL(xmlSubstituteEntitiesDefault(enable));
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)
1310 DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
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
1315 /* Get the namespace of the current node and add it as a property */
1319 if(!node_namespace(&namespace, last))
1320 zend_hash_update(Z_OBJPROP_P(child), "namespace", sizeof("namespace"), (void *) &namespace, sizeof(zval *), NULL);
1322 @@ -2619,7 +3063,7 @@ PHP_FUNCTION(xmltree)
1328 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &buf_len) == FAILURE) {
1331 @@ -2690,7 +3134,7 @@ static void php_xpathptr_new_context(INT
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)
1340 @@ -2698,7 +3142,7 @@ PHP_FUNCTION(xpath_new_context)
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)
1349 @@ -2731,10 +3175,10 @@ static void php_xpathptr_eval(INTERNAL_F
1352 ctxp = php_xpath_get_context(id, le_xpathctxp, 0 TSRMLS_CC);
1354 - php_error(E_WARNING, "%s() cannot fetch XPATH context", get_active_function_name(TSRMLS_C));
1358 + php_error(E_WARNING, "%s(): cannot fetch XPATH context", get_active_function_name(TSRMLS_C));
1363 DOMXML_GET_OBJ(contextnodep, contextnode, le_domxmlnodep);
1364 @@ -2761,7 +3205,7 @@ static void php_xpathptr_eval(INTERNAL_F
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));
1373 @@ -2836,7 +3280,7 @@ static void php_xpathptr_eval(INTERNAL_F
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)
1382 @@ -2844,13 +3288,46 @@ PHP_FUNCTION(xpath_eval)
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)
1392 php_xpathptr_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_XPATH, 1);
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)
1402 + - automagically register all namespaces when creating a new context
1405 + int prefix_len, uri_len, result;
1406 + xmlXPathContextPtr ctxp;
1407 + char *prefix, *uri, *uri_static;
1410 + DOMXML_PARAM_FOUR(ctxp, id, le_xpathctxp, "ss", &prefix, &prefix_len, &uri, &uri_len);
1412 + /* set the context node to NULL - what is a context node anyway? */
1413 + ctxp->node = NULL;
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
1419 + uri_static = estrndup(uri, uri_len);
1420 + result = xmlXPathRegisterNs(ctxp, prefix, uri_static);
1422 + if (0 == result) {
1428 #endif /* defined(LIBXML_XPATH_ENABLED) */
1430 #if defined(LIBXML_XPTR_ENABLED)
1431 @@ -2864,12 +3341,266 @@ PHP_FUNCTION(xptr_eval)
1432 #endif /* LIBXML_XPTR_ENABLED */
1434 /* {{{ proto string domxml_version(void)
1435 - Dumps document into string */
1436 + Get XML library version */
1437 PHP_FUNCTION(domxml_version)
1439 RETURN_STRING(LIBXML_DOTTED_VERSION, 1);
1444 +static zval *php_xsltstylesheet_new(xsltStylesheetPtr obj, int *found TSRMLS_DC)
1454 + MAKE_STD_ZVAL(wrapper);
1455 + ZVAL_NULL(wrapper);
1459 + if ((wrapper = (zval *) dom_object_get_data((void *) obj))) {
1460 + zval_add_ref(&wrapper);
1465 + MAKE_STD_ZVAL(wrapper);
1467 + object_init_ex(wrapper, domxsltstylesheet_class_entry);
1468 + rsrc_type = le_domxsltstylesheetp;
1469 + php_xsltstylesheet_set_object(wrapper, (void *) obj, rsrc_type);
1474 +/* {{{ proto object domxml_xslt_stylesheet(string xsltstylesheet)
1475 + Creates XSLT Stylesheet object from string */
1476 +PHP_FUNCTION(domxml_xslt_stylesheet)
1480 + xsltStylesheetPtr sheetp;
1485 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, &buffer_len) == FAILURE) {
1489 + docp = xmlParseDoc(buffer);
1494 + sheetp = xsltParseStylesheetDoc(docp);
1499 + rv = php_xsltstylesheet_new(sheetp, &ret TSRMLS_CC);
1500 + DOMXML_RET_ZVAL(rv);
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)
1510 + xmlDocPtr newdocp;
1511 + xsltStylesheetPtr sheetp;
1514 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &idxml) == FAILURE) {
1518 + DOMXML_GET_OBJ(docp, idxml, le_domxmldocp);
1520 + newdocp = xmlCopyDoc(docp, 1);
1525 + sheetp = xsltParseStylesheetDoc(newdocp);
1530 + rv = php_xsltstylesheet_new(sheetp, &ret TSRMLS_CC);
1531 + DOMXML_RET_ZVAL(rv);
1535 +/* {{{ proto object domxml_xslt_stylesheet_file(string filename)
1536 + Creates XSLT Stylesheet object from file */
1537 +PHP_FUNCTION(domxml_xslt_stylesheet_file)
1540 + xsltStylesheetPtr sheetp;
1541 + int ret, file_len;
1544 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
1548 + sheetp = xsltParseStylesheetFile(file);
1553 + rv = php_xsltstylesheet_new(sheetp, &ret TSRMLS_CC);
1554 + DOMXML_RET_ZVAL(rv);
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)
1562 + const xmlChar *string = (const xmlChar *)str;
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));
1574 + value = xmlStrdup((const xmlChar *)"'");
1575 + value = xmlStrcat(value, string);
1576 + value = xmlStrcat(value, (const xmlChar *)"'");
1579 + value = xmlStrdup((const xmlChar *)"\"");
1580 + value = xmlStrcat(value, string);
1581 + value = xmlStrcat(value, (const xmlChar *)"\"");
1584 + return (char *)value;
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)
1594 + char *xpath_expr, *string_key = NULL;
1596 + char **params = NULL;
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);
1606 + for (zend_hash_internal_pointer_reset(parht);
1607 + zend_hash_get_current_data(parht, (void **)&value) == SUCCESS;
1608 + zend_hash_move_forward(parht)) {
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));
1616 + SEPARATE_ZVAL(value);
1617 + convert_to_string_ex(value);
1619 + if (!xpath_params) {
1620 + xpath_expr = php_domxslt_string_to_xpathexpr(Z_STRVAL_PP(value));
1623 + xpath_expr = Z_STRVAL_PP(value);
1627 + params[i++] = string_key;
1628 + params[i++] = xpath_expr;
1633 + params[i++] = NULL;
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)
1643 + - test memory deallocation
1644 + - test other stuff
1645 + - check xsltsp->errors ???
1647 + zval *rv, *idxsl, *idxml, *idparams = NULL;
1648 + zend_bool xpath_params = 0;
1649 + xsltStylesheetPtr xsltstp;
1650 + xmlDocPtr xmldocp;
1652 + char **params = NULL;
1655 + DOMXML_GET_THIS(idxsl);
1657 + xsltstp = php_xsltstylesheet_get_object(idxsl, le_domxsltstylesheetp, 0 TSRMLS_CC);
1659 + php_error(E_WARNING, "%s(): underlying object missing",
1660 + get_active_function_name(TSRMLS_C));
1664 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|ab", &idxml, &idparams, &xpath_params) == FAILURE) {
1668 + DOMXML_GET_OBJ(xmldocp, idxml, le_domxmldocp);
1671 + params = php_domxslt_make_params(idparams, xpath_params);
1674 + docp = xsltApplyStylesheet(xsltstp, xmldocp, (const char**)params);
1684 + DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret);
1688 +/* {{{ proto string domxml_xslt_version(void)
1689 + Get XSLT library version */
1690 +PHP_FUNCTION(domxml_xslt_version)
1692 + RETURN_STRING(LIBXSLT_DOTTED_VERSION, 1);
1695 +#endif /* HAVE_DOMXSLT */
1697 #endif /* HAVE_DOMXML */
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
1703 +----------------------------------------------------------------------+
1709 #ifndef PHP_DOMXML_H
1710 #define PHP_DOMXML_H
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>
1720 #if defined(LIBXML_XPATH_ENABLED)
1721 #include <libxml/xpath.h>
1722 +#include <libxml/xpathInternals.h>
1724 #if defined(LIBXML_XPTR_ENABLED)
1725 #include <libxml/xpointer.h>
1728 +#include <libxslt/xsltconfig.h>
1729 +#include <libxslt/xsltInternals.h>
1730 +#include <libxslt/xsltutils.h>
1731 +#include <libxslt/transform.h>
1733 +#include <libexslt/exslt.h>
1734 +#include <libexslt/exsltconfig.h>
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);
1748 PHP_FUNCTION(xmltree);
1749 PHP_FUNCTION(domxml_new_xmldoc);
1750 +PHP_FUNCTION(domxml_substitute_entities_default);
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);
1763 +#if defined(LIBXML_HTML_ENABLED)
1764 +PHP_FUNCTION(domxml_html_dump_mem);
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);
1786 #if defined(LIBXML_XPTR_ENABLED)
1787 PHP_FUNCTION(xptr_new_context);
1788 PHP_FUNCTION(xptr_eval);
1790 PHP_FUNCTION(domxml_test);
1792 +/* DOMXSLT functions */
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);
1802 #define domxml_module_ptr NULL