cataphract Tue, 18 Jan 2011 19:45:38 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=307561
Log: - Implemented FR #39771 (Made DOMDocument::saveHTML accept an optional DOMNode like DOMDocument::saveXML). Bug: http://bugs.php.net/39771 (Open) DOMDocument->saveHTML does not accept an optional DOMNode like saveXML Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/dom/document.c D php/php-src/branches/PHP_5_3/ext/dom/tests/DOMDocument_saveHTML_error1.phpt A php/php-src/branches/PHP_5_3/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt U php/php-src/trunk/ext/dom/document.c D php/php-src/trunk/ext/dom/tests/DOMDocument_saveHTML_error1.phpt A php/php-src/trunk/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2011-01-18 17:58:58 UTC (rev 307560) +++ php/php-src/branches/PHP_5_3/NEWS 2011-01-18 19:45:38 UTC (rev 307561) @@ -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 Modified: php/php-src/branches/PHP_5_3/ext/dom/document.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/dom/document.c 2011-01-18 17:58:58 UTC (rev 307560) +++ php/php-src/branches/PHP_5_3/ext/dom/document.c 2011-01-18 19:45:38 UTC (rev 307561) @@ -2284,33 +2284,63 @@ */ 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 */ Deleted: php/php-src/branches/PHP_5_3/ext/dom/tests/DOMDocument_saveHTML_error1.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/dom/tests/DOMDocument_saveHTML_error1.phpt 2011-01-18 17:58:58 UTC (rev 307560) +++ php/php-src/branches/PHP_5_3/ext/dom/tests/DOMDocument_saveHTML_error1.phpt 2011-01-18 19:45:38 UTC (rev 307561) @@ -1,24 +0,0 @@ ---TEST-- -DOMDocument::saveHTML() should fail if a parameter is given ---CREDITS-- -Knut Urdalen <k...@php.net> -#PHPTestFest2009 Norway 2009-06-09 \o/ ---SKIPIF-- -<?php -require_once('skipif.inc'); -?> ---FILE-- -<?php -$doc = new DOMDocument('1.0'); -$root = $doc->createElement('html'); -$root = $doc->appendChild($root); -$head = $doc->createElement('head'); -$head = $root->appendChild($head); -$title = $doc->createElement('title'); -$title = $head->appendChild($title); -$text = $doc->createTextNode('This is the title'); -$text = $title->appendChild($text); -echo $doc->saveHTML(true); -?> ---EXPECTF-- -Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in %s on line %d Added: php/php-src/branches/PHP_5_3/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt 2011-01-18 19:45:38 UTC (rev 307561) @@ -0,0 +1,24 @@ +--TEST-- +DOMDocument::saveHTML() optional parameters +--SKIPIF-- +<?php +require_once dirname(__FILE__) .'/skipif.inc'; +?> +--FILE-- +<?php +$doc = new DOMDocument('1.0'); +$root = $doc->createElement('html'); +$root = $doc->appendChild($root); +$head = $doc->createElement('head'); +$head = $root->appendChild($head); +$title = $doc->createElement('title'); +$title = $head->appendChild($title); +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); +echo $doc->saveHTML(NULL), "\n"; +echo $doc->saveHTML($title), "\n"; +?> +--EXPECTF-- +<html><head><title>This is the title</title></head></html> + +<title>This is the title</title> Modified: php/php-src/trunk/ext/dom/document.c =================================================================== --- php/php-src/trunk/ext/dom/document.c 2011-01-18 17:58:58 UTC (rev 307560) +++ php/php-src/trunk/ext/dom/document.c 2011-01-18 19:45:38 UTC (rev 307561) @@ -2284,33 +2284,63 @@ */ 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 */ Deleted: php/php-src/trunk/ext/dom/tests/DOMDocument_saveHTML_error1.phpt =================================================================== --- php/php-src/trunk/ext/dom/tests/DOMDocument_saveHTML_error1.phpt 2011-01-18 17:58:58 UTC (rev 307560) +++ php/php-src/trunk/ext/dom/tests/DOMDocument_saveHTML_error1.phpt 2011-01-18 19:45:38 UTC (rev 307561) @@ -1,24 +0,0 @@ ---TEST-- -DOMDocument::saveHTML() should fail if a parameter is given ---CREDITS-- -Knut Urdalen <k...@php.net> -#PHPTestFest2009 Norway 2009-06-09 \o/ ---SKIPIF-- -<?php -require_once('skipif.inc'); -?> ---FILE-- -<?php -$doc = new DOMDocument('1.0'); -$root = $doc->createElement('html'); -$root = $doc->appendChild($root); -$head = $doc->createElement('head'); -$head = $root->appendChild($head); -$title = $doc->createElement('title'); -$title = $head->appendChild($title); -$text = $doc->createTextNode('This is the title'); -$text = $title->appendChild($text); -echo $doc->saveHTML(true); -?> ---EXPECTF-- -Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in %s on line %d Added: php/php-src/trunk/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt =================================================================== --- php/php-src/trunk/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt (rev 0) +++ php/php-src/trunk/ext/dom/tests/DOMDocument_saveHTML_variant1.phpt 2011-01-18 19:45:38 UTC (rev 307561) @@ -0,0 +1,24 @@ +--TEST-- +DOMDocument::saveHTML() optional parameters +--SKIPIF-- +<?php +require_once dirname(__FILE__) .'/skipif.inc'; +?> +--FILE-- +<?php +$doc = new DOMDocument('1.0'); +$root = $doc->createElement('html'); +$root = $doc->appendChild($root); +$head = $doc->createElement('head'); +$head = $root->appendChild($head); +$title = $doc->createElement('title'); +$title = $head->appendChild($title); +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); +echo $doc->saveHTML(NULL), "\n"; +echo $doc->saveHTML($title), "\n"; +?> +--EXPECTF-- +<html><head><title>This is the title</title></head></html> + +<title>This is the title</title>
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php