summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo André dos Santos Lopes <cataphract@php.net>2011-01-18 19:45:38 +0000
committerGustavo André dos Santos Lopes <cataphract@php.net>2011-01-18 19:45:38 +0000
commit163b3bcec9488b3e991ca4fd732712378b9821d7 (patch)
tree9bf2f7e6a24f73a1d82419731308a9b7ed13544f
parentb5e12bd4da0fbc2abdcd92b9ced721e3b383439a (diff)
downloadphp-git-163b3bcec9488b3e991ca4fd732712378b9821d7.tar.gz
- Implemented FR #39771 (Made DOMDocument::saveHTML accept an optional
DOMNode like DOMDocument::saveXML).
-rw-r--r--ext/dom/document.c52
-rw-r--r--ext/dom/tests/DOMDocument_saveHTML_variant1.phpt (renamed from ext/dom/tests/DOMDocument_saveHTML_error1.phpt)14
2 files changed, 48 insertions, 18 deletions
diff --git a/ext/dom/document.c b/ext/dom/document.c
index 540e04de68..42598e3e87 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
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 <knut@php.net>
-#PHPTestFest2009 Norway 2009-06-09 \o/
+DOMDocument::saveHTML() optional parameters
--SKIPIF--
<?php
-require_once('skipif.inc');
+require_once dirname(__FILE__) .'/skipif.inc';
?>
--FILE--
<?php
@@ -18,7 +15,10 @@ $title = $doc->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
+<html><head><title>This is the title</title></head></html>
+
+<title>This is the title</title>