]> granicus.if.org Git - php/commitdiff
Under threat of being slept with by Marcus, adding new getParent() method
authorJohn Coggeshall <john@php.net>
Thu, 23 Mar 2006 14:22:40 +0000 (14:22 +0000)
committerJohn Coggeshall <john@php.net>
Thu, 23 Mar 2006 14:22:40 +0000 (14:22 +0000)
for node traversals

ext/tidy/php_tidy.h
ext/tidy/tests/tidy_019.phpt [new file with mode: 0644]
ext/tidy/tidy.c

index 3beff75dd8396758a414733e27ca6b30cf9cd348..d038be22544bbd60a1d45961310cca5306dfa847 100644 (file)
@@ -89,6 +89,7 @@ TIDY_NODE_METHOD(isText);
 TIDY_NODE_METHOD(isJste);
 TIDY_NODE_METHOD(isAsp);
 TIDY_NODE_METHOD(isPhp);
+TIDY_NODE_METHOD(getParent);
 
 ZEND_BEGIN_MODULE_GLOBALS(tidy)
        char *default_config;
diff --git a/ext/tidy/tests/tidy_019.phpt b/ext/tidy/tests/tidy_019.phpt
new file mode 100644 (file)
index 0000000..f92168b
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Test 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]->getParent()->name);
+?>
+--EXPECT--
+string(4) "body"
+
index 2fae9c7ac985943076255f6bdfd8b43491e1e30e..f72319cb3991d63b663982b38ef910b3fbadf639 100644 (file)
@@ -302,6 +302,7 @@ 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}
 };
 
@@ -1696,6 +1697,30 @@ TIDY_NODE_METHOD(isPhp)
 }
 /* }}} */
 
+/* {{{ proto boolean tidyNode::getParent()
+   Returns the parent node if available or NULL */
+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);