rrichards               Thu Jun 12 16:02:06 2003 EDT

  Modified files:              
    /php4/ext/dom       php_dom.h php_dom.c node.c domimplementation.c 
                        document.c 
  Log:
  add node->isSupported()
  add domimplementation->hasFeature()
  add formatOutput property (extends DOM)
  call xmlFreeDoc when doc is no longer referenced rather than custom code
  save and savexml now format based on formatOutput property
  
Index: php4/ext/dom/php_dom.h
diff -u php4/ext/dom/php_dom.h:1.3 php4/ext/dom/php_dom.h:1.4
--- php4/ext/dom/php_dom.h:1.3  Tue Jun 10 16:03:27 2003
+++ php4/ext/dom/php_dom.h      Thu Jun 12 16:02:05 2003
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_dom.h,v 1.3 2003/06/10 20:03:27 imajes Exp $ */
+/* $Id: php_dom.h,v 1.4 2003/06/12 20:02:05 rrichards Exp $ */
 
 #ifndef PHP_DOM_H
 #define PHP_DOM_H
@@ -73,6 +73,7 @@
 void dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, 
zval **retval, dom_object *intern  TSRMLS_DC);
 void php_dom_create_implementation(zval **retval  TSRMLS_DC);
 int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child);
+int dom_has_feature(char *feature, char *version);
 
 #define DOM_NO_ARGS() \
        if (ZEND_NUM_ARGS() != 0) { \
Index: php4/ext/dom/php_dom.c
diff -u php4/ext/dom/php_dom.c:1.9 php4/ext/dom/php_dom.c:1.10
--- php4/ext/dom/php_dom.c:1.9  Tue Jun 10 16:03:27 2003
+++ php4/ext/dom/php_dom.c      Thu Jun 12 16:02:05 2003
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_dom.c,v 1.9 2003/06/10 20:03:27 imajes Exp $ */
+/* $Id: php_dom.c,v 1.10 2003/06/12 20:02:05 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -102,8 +102,13 @@
                object->document->refcount--;
                ret_refcount = object->document->refcount;
                if (ret_refcount == 0) {
-                       dom_clean_nodes(object TSRMLS_CC);
-                       node_free_resource(object->document->ptr TSRMLS_CC);
+                       if (object->document->ptr != NULL) {
+                               dom_clean_nodes(object TSRMLS_CC);
+                               /* No references to Doc so can use xmlFreeDoc
+                               node_free_resource(object->document->ptr TSRMLS_CC); */
+                               xmlFreeDoc((xmlDoc *) object->document->ptr);
+                               object->document->ptr = NULL;
+                       }
                        efree(object->document);
                        object->document = NULL;
                }
@@ -590,7 +595,7 @@
        php_info_print_table_start();
        php_info_print_table_row(2, "DOM/XML", "enabled");
        php_info_print_table_row(2, "DOM/XML API Version", DOM_API_VERSION);
-       php_info_print_table_row(2, "libxml Version", xmlParserVersion);
+       php_info_print_table_row(2, "libxml Version", LIBXML_DOTTED_VERSION);
 #if defined(LIBXML_HTML_ENABLED)
        php_info_print_table_row(2, "HTML Support", "enabled");
 #endif
@@ -979,6 +984,10 @@
 
 
        object_init_ex(wrapper, ce);
+       /* Add object properties not needing function calls */
+       if (obj->type == XML_DOCUMENT_NODE || obj->type == XML_HTML_DOCUMENT_NODE) {
+               add_property_bool(wrapper, "formatOutput", 0);
+       }
        intern = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
        if (obj->doc != NULL) {
                if (domobj != NULL) {
@@ -1018,6 +1027,20 @@
     return SUCCESS;
 }
 /* }}} end dom_hierarchy */
+
+/* {{{ dom_has_feature(char *feature, char *version) */
+int dom_has_feature(char *feature, char *version)
+{
+       int retval = 0;
+
+       if (!(strcmp (version, "1.0") && strcmp (version,"2.0") && strcmp(version, 
""))) {
+               if ((!strcasecmp(feature, "Core") && strcmp (version, "1.0")) || 
!strcasecmp(feature, "XML"))
+                       retval = 1;
+       }
+
+       return retval;
+}
+/* }}} end dom_has_feature */
 
 /* {{{ void dom_element_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, 
char *local, zval **retval  TSRMLS_DC) */
 void dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, 
zval **retval, dom_object *intern  TSRMLS_DC)
Index: php4/ext/dom/node.c
diff -u php4/ext/dom/node.c:1.4 php4/ext/dom/node.c:1.5
--- php4/ext/dom/node.c:1.4     Tue Jun 10 16:03:27 2003
+++ php4/ext/dom/node.c Thu Jun 12 16:02:05 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: node.c,v 1.4 2003/06/10 20:03:27 imajes Exp $ */
+/* $Id: node.c,v 1.5 2003/06/12 20:02:05 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -1123,12 +1123,23 @@
 
 
 /* {{{ proto boolean dom_node_is_supported(string feature, string version);
-URL: 
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-Node-supports
+URL: 
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Level-2-Core-Node-supports
 Since: DOM Level 2
 */
 PHP_FUNCTION(dom_node_is_supported)
 {
- DOM_NOT_IMPLEMENTED();
+       int feature_len, version_len;
+       char *feature, *version;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &feature, 
&feature_len, &version, &version_len) == FAILURE) {
+               return;
+       }
+
+       if (dom_has_feature(feature, version)) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
 }
 /* }}} end dom_node_is_supported */
 
Index: php4/ext/dom/domimplementation.c
diff -u php4/ext/dom/domimplementation.c:1.3 php4/ext/dom/domimplementation.c:1.4
--- php4/ext/dom/domimplementation.c:1.3        Tue Jun 10 16:03:27 2003
+++ php4/ext/dom/domimplementation.c    Thu Jun 12 16:02:05 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: domimplementation.c,v 1.3 2003/06/10 20:03:27 imajes Exp $ */
+/* $Id: domimplementation.c,v 1.4 2003/06/12 20:02:05 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -50,7 +50,18 @@
 */
 PHP_FUNCTION(dom_domimplementation_has_feature)
 {
- DOM_NOT_IMPLEMENTED();
+       int feature_len, version_len;
+       char *feature, *version;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &feature, 
&feature_len, &version, &version_len) == FAILURE) {
+               return;
+       }
+
+       if (dom_has_feature(feature, version)) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
 }
 /* }}} end dom_domimplementation_has_feature */
 
Index: php4/ext/dom/document.c
diff -u php4/ext/dom/document.c:1.5 php4/ext/dom/document.c:1.6
--- php4/ext/dom/document.c:1.5 Tue Jun 10 16:03:27 2003
+++ php4/ext/dom/document.c     Thu Jun 12 16:02:05 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: document.c,v 1.5 2003/06/10 20:03:27 imajes Exp $ */
+/* $Id: document.c,v 1.6 2003/06/12 20:02:05 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -75,6 +75,27 @@
 };
 
 
+int dom_document_get_formatting(zval *id TSRMLS_DC) {
+       zval *format, *member;
+       zend_object_handlers *std_hnd;
+       int retformat = 0;
+
+       MAKE_STD_ZVAL(member);
+       ZVAL_STRING(member, "formatOutput", 1);
+
+       std_hnd = zend_get_std_object_handlers();
+       format = std_hnd->read_property(id, member TSRMLS_CC);
+
+       if (format->type == IS_BOOL) {
+               retformat = Z_BVAL_P(format);
+       }
+
+       zval_dtor(member);
+       FREE_ZVAL(member);
+
+       return retformat;
+}
+
 /* {{{ proto doctype   documenttype    
 readonly=yes 
 URL: 
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-B63ED1A31
@@ -1070,7 +1091,7 @@
 {
        zval *id;
        xmlDoc *docp;
-       int file_len, bytes;
+       int file_len, bytes, format;
        dom_object *intern;
        char *file;
 
@@ -1084,7 +1105,9 @@
                RETURN_FALSE;
        }
 
-       bytes = xmlSaveFile(file, docp);
+       /* encoding handled by property on doc */
+       format = dom_document_get_formatting(id TSRMLS_CC);
+       bytes = xmlSaveFormatFileEnc(file, docp, NULL, format);
 
        if (bytes == -1) {
                RETURN_FALSE;
@@ -1105,7 +1128,7 @@
        xmlBufferPtr buf;
        xmlChar *mem;
        dom_object *intern, *nodeobj;
-       int size;
+       int size, format;
 
        DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
 
@@ -1113,6 +1136,8 @@
                return;
        }
 
+       format = dom_document_get_formatting(id TSRMLS_CC);
+
        if (nodep != NULL) {
                /* Dump contents of Node */
                DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
@@ -1126,7 +1151,8 @@
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch 
buffer");
                        RETURN_FALSE;
                }
-               xmlNodeDump(buf, docp, node, 0, 0);
+
+               xmlNodeDump(buf, docp, node, 0, format);
                mem = (xmlChar*) xmlBufferContent(buf);
                if (!mem) {
                        xmlBufferFree(buf);
@@ -1135,9 +1161,8 @@
                RETVAL_STRING(mem,  1);
                xmlBufferFree(buf);
        } else {
-               /* Dump Document Contents 
-               Encoding is handled from the encoding property set on the document */
-               xmlDocDumpMemory(docp, &mem, &size);
+               /* Encoding is handled from the encoding property set on the document 
*/
+               xmlDocDumpFormatMemory(docp, &mem, &size, format);
                if (!size) {
                        RETURN_FALSE;
                }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to