]> granicus.if.org Git - php/commitdiff
merge the tidyNode::getParent() patch from HEAD
authorNuno Lopes <nlopess@php.net>
Sun, 11 Feb 2007 16:07:30 +0000 (16:07 +0000)
committerNuno Lopes <nlopess@php.net>
Sun, 11 Feb 2007 16:07:30 +0000 (16:07 +0000)
NEWS
ext/tidy/tests/028.phpt [new file with mode: 0644]
ext/tidy/tidy.c

diff --git a/NEWS b/NEWS
index 23dbb1a5d5c878abeea98f739b6542e7d9391787..b143aee272e37d787d18106a410c591fd3ec3dca 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ PHP                                                                        NEWS
 - Upgraded SQLite 3 to version 3.3.12 (Ilia)
 - Upgraded PCRE to version 7.0 (Nuno)
 - Add --ri switch to CLI which allows to check extension information. (Marcus)
+- Added tidyNode::getParent() method (John, Nuno)
 - Fixed bug #40431 (dynamic properties may cause crash in ReflectionProperty 
   methods). (Tony)
 - Fixed bug #40428, imagepstext() doesn't accept optional parameter (Pierre)
diff --git a/ext/tidy/tests/028.phpt b/ext/tidy/tests/028.phpt
new file mode 100644 (file)
index 0000000..01f3fd1
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+tidyNode::getParent()
+--SKIPIF--
+<?php if (!extension_loaded("tidy")) print "skip"; ?>
+--FILE--
+<?php
+$x = tidy_parse_string("<body><div>Content</div></body>");
+var_dump($x->body()->child[0]->name);
+var_dump($x->body()->child[0]->getParent()->name);
+var_dump($x->root()->getParent());
+?>
+--EXPECT--
+string(3) "div"
+string(4) "body"
+NULL
index 76a08ed9150c62943ddf10fa2e9eb0b8c1b575c2..94c711198d46bf5b25c6b47a793eec50e35667d8 100644 (file)
@@ -267,6 +267,7 @@ static TIDY_NODE_METHOD(isText);
 static TIDY_NODE_METHOD(isJste);
 static TIDY_NODE_METHOD(isAsp);
 static TIDY_NODE_METHOD(isPhp);
+static TIDY_NODE_METHOD(getParent);
 /* }}} */
 
 ZEND_DECLARE_MODULE_GLOBALS(tidy)
@@ -341,6 +342,7 @@ static zend_function_entry tidy_funcs_node[] = {
        TIDY_NODE_ME(isJste, NULL)
        TIDY_NODE_ME(isAsp, NULL)
        TIDY_NODE_ME(isPhp, NULL)
+       TIDY_NODE_ME(getParent, NULL)
        {NULL, NULL, NULL}
 };
 
@@ -1659,6 +1661,29 @@ static TIDY_NODE_METHOD(isPhp)
 }
 /* }}} */
 
+/* {{{ proto tidyNode tidyNode::getParent()
+   Returns the parent node if available or NULL */
+static TIDY_NODE_METHOD(getParent)
+{
+       TidyNode        parent_node;
+       PHPTidyObj *newobj;
+       TIDY_FETCH_ONLY_OBJECT;
+
+       parent_node = tidyGetParent(obj->node);
+       if(parent_node) {
+               tidy_instanciate(tidy_ce_node, return_value TSRMLS_CC);
+               newobj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC);
+               newobj->node = parent_node;
+               newobj->type = is_node;
+               newobj->ptdoc = obj->ptdoc;
+               newobj->ptdoc->ref_count++;
+               tidy_add_default_properties(newobj, is_node TSRMLS_CC);
+       } else {
+               ZVAL_NULL(return_value);
+       }
+}
+/* }}} */
+
 static void _php_tidy_register_nodetypes(INIT_FUNC_ARGS)
 {
        TIDY_NODE_CONST(ROOT, Root);