From: Gustavo André dos Santos Lopes Date: Tue, 18 Jan 2011 19:45:38 +0000 (+0000) Subject: - Implemented FR #39771 (Made DOMDocument::saveHTML accept an optional X-Git-Tag: php-5.3.6RC1~105 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6ac882106be05d4a0086dacf3d85980a4e380b0;p=php - Implemented FR #39771 (Made DOMDocument::saveHTML accept an optional DOMNode like DOMDocument::saveXML). --- diff --git a/NEWS b/NEWS index d2209ada5e..414a1b003c 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,10 @@ - Calendar extension: . Fixed bug #53574 (Integer overflow in SdnToJulian, sometimes leading to segfault). (Gustavo) + +- DOM extension: + . Implemented FR #39771 (Made DOMDocument::saveHTML accept an optional DOMNode + like DOMDocument::saveXML). (Gustavo) - DateTime extension: . Fixed a bug in DateTime->modify() where absolute date/time statements had diff --git a/ext/dom/document.c b/ext/dom/document.c index 51a5a93e9c..aeca66fe19 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -2284,33 +2284,63 @@ Convenience method to output as html */ PHP_FUNCTION(dom_document_save_html) { - zval *id; + zval *id, *nodep = NULL; xmlDoc *docp; - dom_object *intern; - xmlChar *mem; + xmlNode *node; + xmlBufferPtr buf; + dom_object *intern, *nodeobj; + xmlChar *mem = NULL; int size, format; dom_doc_propsptr doc_props; - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O|O!", &id, dom_document_class_entry, &nodep, dom_node_class_entry) + == FAILURE) { return; } DOM_GET_OBJ(docp, id, xmlDocPtr, intern); -#if LIBXML_VERSION >= 20623 doc_props = dom_get_doc_props(intern->document); format = doc_props->formatoutput; - htmlDocDumpMemoryFormat(docp, &mem, &size, format); + + if (nodep != NULL) { + /* Dump contents of Node */ + DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj); + if (node->doc != docp) { + php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC); + RETURN_FALSE; + } + + buf = xmlBufferCreate(); + if (!buf) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch buffer"); + RETURN_FALSE; + } + + xmlNodeDump(buf, docp, node, 0, format); + mem = (xmlChar*) xmlBufferContent(buf); + if (!mem) { + RETVAL_FALSE; + } else { + RETVAL_STRING(mem, 1); + } + xmlBufferFree(buf); + } else { +#if LIBXML_VERSION >= 20623 + htmlDocDumpMemoryFormat(docp, &mem, &size, format); #else - htmlDocDumpMemory(docp, &mem, &size); + htmlDocDumpMemory(docp, &mem, &size); #endif - if (!size) { + if (!size) { + RETVAL_FALSE; + } else { + RETVAL_STRINGL(mem, size, 1); + } if (mem) xmlFree(mem); - RETURN_FALSE; } - RETVAL_STRINGL(mem, size, 1); - xmlFree(mem); + } /* }}} end dom_document_save_html */ diff --git a/ext/dom/tests/DOMDocument_saveHTML_error1.phpt b/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt similarity index 58% rename from ext/dom/tests/DOMDocument_saveHTML_error1.phpt rename to ext/dom/tests/DOMDocument_saveHTML_variant1.phpt index 78718de8e7..d1691138ae 100644 --- a/ext/dom/tests/DOMDocument_saveHTML_error1.phpt +++ b/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt @@ -1,11 +1,8 @@ --TEST-- -DOMDocument::saveHTML() should fail if a parameter is given ---CREDITS-- -Knut Urdalen -#PHPTestFest2009 Norway 2009-06-09 \o/ +DOMDocument::saveHTML() optional parameters --SKIPIF-- --FILE-- createElement('title'); $title = $head->appendChild($title); $text = $doc->createTextNode('This is the title'); $text = $title->appendChild($text); -echo $doc->saveHTML(true); +echo $doc->saveHTML(NULL), "\n"; +echo $doc->saveHTML($title), "\n"; ?> --EXPECTF-- -Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in %s on line %d +This is the title + +This is the title