2003-06-05 17:06:52 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2019-01-30 09:03:12 +00:00
|
|
|
| Copyright (c) The PHP Group |
|
2003-06-05 17:06:52 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2003-06-05 17:06:52 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 12:51:34 +00:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2003-06-05 17:06:52 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Christian Stocker <chregu@php.net> |
|
|
|
|
| Rob Richards <rrichards@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
2020-05-12 20:54:43 +00:00
|
|
|
#if defined(HAVE_LIBXML) && defined(HAVE_DOM)
|
2003-06-05 17:06:52 +00:00
|
|
|
#include "php_dom.h"
|
2020-02-26 15:42:49 +00:00
|
|
|
#include "zend_interfaces.h"
|
2017-07-09 00:15:38 +00:00
|
|
|
|
2003-06-05 17:06:52 +00:00
|
|
|
/*
|
2015-01-03 09:22:58 +00:00
|
|
|
* class DOMNodeList
|
2003-06-05 17:06:52 +00:00
|
|
|
*
|
2018-06-24 20:31:55 +00:00
|
|
|
* URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-536297177
|
2015-01-03 09:22:58 +00:00
|
|
|
* Since:
|
2003-06-05 17:06:52 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-03 09:22:58 +00:00
|
|
|
/* {{{ length int
|
|
|
|
readonly=yes
|
2003-06-05 17:06:52 +00:00
|
|
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-203510337
|
2015-01-03 09:22:58 +00:00
|
|
|
Since:
|
2003-06-05 17:06:52 +00:00
|
|
|
*/
|
2014-12-13 22:06:14 +00:00
|
|
|
int dom_nodelist_length_read(dom_object *obj, zval *retval)
|
2003-06-05 17:06:52 +00:00
|
|
|
{
|
2003-11-29 20:40:18 +00:00
|
|
|
dom_nnodemap_object *objmap;
|
|
|
|
xmlNodePtr nodep, curnode;
|
|
|
|
int count = 0;
|
2004-01-10 11:50:25 +00:00
|
|
|
HashTable *nodeht;
|
2003-11-29 20:40:18 +00:00
|
|
|
|
|
|
|
objmap = (dom_nnodemap_object *)obj->ptr;
|
2004-02-17 11:13:47 +00:00
|
|
|
if (objmap != NULL) {
|
|
|
|
if (objmap->ht) {
|
|
|
|
count = xmlHashSize(objmap->ht);
|
2004-01-10 11:50:25 +00:00
|
|
|
} else {
|
2004-02-17 11:13:47 +00:00
|
|
|
if (objmap->nodetype == DOM_NODESET) {
|
2014-04-16 13:52:59 +00:00
|
|
|
nodeht = HASH_OF(&objmap->baseobj_zv);
|
2004-02-17 11:13:47 +00:00
|
|
|
count = zend_hash_num_elements(nodeht);
|
|
|
|
} else {
|
|
|
|
nodep = dom_object_get_node(objmap->baseobj);
|
|
|
|
if (nodep) {
|
|
|
|
if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
|
|
|
|
curnode = nodep->children;
|
|
|
|
if (curnode) {
|
2004-01-10 11:50:25 +00:00
|
|
|
count++;
|
2004-02-17 11:13:47 +00:00
|
|
|
while (curnode->next != NULL) {
|
|
|
|
count++;
|
|
|
|
curnode = curnode->next;
|
|
|
|
}
|
2004-01-10 11:50:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-02-17 11:13:47 +00:00
|
|
|
if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
|
|
|
|
nodep = xmlDocGetRootElement((xmlDoc *) nodep);
|
|
|
|
} else {
|
|
|
|
nodep = nodep->children;
|
|
|
|
}
|
2014-09-03 19:35:53 +00:00
|
|
|
curnode = dom_get_elements_by_tag_name_ns_raw(
|
|
|
|
nodep, (char *) objmap->ns, (char *) objmap->local, &count, -1);
|
2004-01-10 11:50:25 +00:00
|
|
|
}
|
2003-11-29 20:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-25 17:24:55 +00:00
|
|
|
ZVAL_LONG(retval, count);
|
2003-06-05 17:06:52 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-07-09 00:15:38 +00:00
|
|
|
|
2020-07-01 13:32:55 +00:00
|
|
|
/* {{{ */
|
2020-04-11 20:01:51 +00:00
|
|
|
PHP_METHOD(DOMNodeList, count)
|
2017-07-09 00:15:38 +00:00
|
|
|
{
|
|
|
|
zval *id;
|
|
|
|
dom_object *intern;
|
|
|
|
|
2018-11-15 16:54:19 +00:00
|
|
|
id = ZEND_THIS;
|
2018-11-14 00:32:19 +00:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
2019-12-30 17:14:29 +00:00
|
|
|
RETURN_THROWS();
|
2017-07-09 00:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
intern = Z_DOMOBJ_P(id);
|
|
|
|
if(dom_nodelist_length_read(intern, return_value) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} end dom_nodelist_count */
|
|
|
|
|
2003-06-05 17:06:52 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2020-07-01 13:32:55 +00:00
|
|
|
/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-844377136
|
2015-01-03 09:22:58 +00:00
|
|
|
Since:
|
2003-06-05 17:06:52 +00:00
|
|
|
*/
|
2020-04-11 20:01:51 +00:00
|
|
|
PHP_METHOD(DOMNodeList, item)
|
2003-06-05 17:06:52 +00:00
|
|
|
{
|
2011-08-08 13:45:18 +00:00
|
|
|
zval *id;
|
2014-08-25 21:50:30 +00:00
|
|
|
zend_long index;
|
2005-06-26 22:34:26 +00:00
|
|
|
int ret;
|
2003-11-29 20:40:18 +00:00
|
|
|
dom_object *intern;
|
|
|
|
xmlNodePtr itemnode = NULL;
|
|
|
|
|
|
|
|
dom_nnodemap_object *objmap;
|
2014-10-09 15:07:12 +00:00
|
|
|
xmlNodePtr nodep, curnode;
|
|
|
|
int count = 0;
|
2003-11-29 20:40:18 +00:00
|
|
|
|
2018-11-15 16:54:19 +00:00
|
|
|
id = ZEND_THIS;
|
2018-11-14 00:32:19 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
|
2019-12-30 17:14:29 +00:00
|
|
|
RETURN_THROWS();
|
2003-11-29 20:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= 0) {
|
2014-04-15 18:30:41 +00:00
|
|
|
intern = Z_DOMOBJ_P(id);
|
2003-11-29 20:40:18 +00:00
|
|
|
|
|
|
|
objmap = (dom_nnodemap_object *)intern->ptr;
|
2004-02-17 11:13:47 +00:00
|
|
|
if (objmap != NULL) {
|
|
|
|
if (objmap->ht) {
|
2014-10-09 15:07:12 +00:00
|
|
|
if (objmap->nodetype == XML_ENTITY_NODE) {
|
|
|
|
itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
|
|
|
|
} else {
|
|
|
|
itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
|
|
|
|
}
|
2004-01-10 11:50:25 +00:00
|
|
|
} else {
|
2004-02-17 11:13:47 +00:00
|
|
|
if (objmap->nodetype == DOM_NODESET) {
|
2014-04-16 13:52:59 +00:00
|
|
|
HashTable *nodeht = HASH_OF(&objmap->baseobj_zv);
|
2014-04-15 18:30:41 +00:00
|
|
|
zval *entry = zend_hash_index_find(nodeht, index);
|
|
|
|
if (entry) {
|
|
|
|
ZVAL_COPY(return_value, entry);
|
2004-02-17 11:13:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-08-13 15:02:41 +00:00
|
|
|
} else if (objmap->baseobj) {
|
2014-10-09 15:07:12 +00:00
|
|
|
nodep = dom_object_get_node(objmap->baseobj);
|
|
|
|
if (nodep) {
|
|
|
|
if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
|
|
|
|
curnode = nodep->children;
|
|
|
|
while (count < index && curnode != NULL) {
|
|
|
|
count++;
|
|
|
|
curnode = curnode->next;
|
|
|
|
}
|
|
|
|
itemnode = curnode;
|
|
|
|
} else {
|
|
|
|
if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
|
|
|
|
nodep = xmlDocGetRootElement((xmlDoc *) nodep);
|
|
|
|
} else {
|
|
|
|
nodep = nodep->children;
|
|
|
|
}
|
2015-01-30 18:03:59 +00:00
|
|
|
itemnode = dom_get_elements_by_tag_name_ns_raw(nodep, (char *) objmap->ns, (char *) objmap->local, &count, index);
|
2014-10-09 15:07:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-29 20:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-29 19:57:51 +00:00
|
|
|
if (itemnode) {
|
2011-08-08 13:45:18 +00:00
|
|
|
DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
|
2004-03-31 17:18:59 +00:00
|
|
|
return;
|
2004-03-29 19:57:51 +00:00
|
|
|
}
|
2003-11-29 20:40:18 +00:00
|
|
|
}
|
2004-03-29 19:57:51 +00:00
|
|
|
|
|
|
|
RETVAL_NULL();
|
2003-06-05 17:06:52 +00:00
|
|
|
}
|
|
|
|
/* }}} end dom_nodelist_item */
|
2008-08-14 08:39:05 +00:00
|
|
|
|
2020-02-26 15:42:49 +00:00
|
|
|
ZEND_METHOD(DOMNodeList, getIterator)
|
|
|
|
{
|
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
zend_create_internal_iterator_zval(return_value, ZEND_THIS);
|
|
|
|
}
|
2017-07-09 00:15:38 +00:00
|
|
|
|
2003-08-22 15:04:29 +00:00
|
|
|
#endif
|