This source file includes following definitions.
- PHP_METHOD
- dom_text_whole_text_read
- PHP_FUNCTION
- PHP_FUNCTION
- PHP_FUNCTION
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "php.h"
27 #if HAVE_LIBXML && HAVE_DOM
28 #include "php_dom.h"
29 #include "dom_ce.h"
30
31
32 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_text_split_text, 0, 0, 1)
33 ZEND_ARG_INFO(0, offset)
34 ZEND_END_ARG_INFO();
35
36 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_text_is_whitespace_in_element_content, 0, 0, 0)
37 ZEND_END_ARG_INFO();
38
39 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_text_replace_whole_text, 0, 0, 1)
40 ZEND_ARG_INFO(0, content)
41 ZEND_END_ARG_INFO();
42
43 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_text_construct, 0, 0, 0)
44 ZEND_ARG_INFO(0, value)
45 ZEND_END_ARG_INFO();
46
47
48
49
50
51
52
53
54
55 const zend_function_entry php_dom_text_class_functions[] = {
56 PHP_FALIAS(splitText, dom_text_split_text, arginfo_dom_text_split_text)
57 PHP_FALIAS(isWhitespaceInElementContent, dom_text_is_whitespace_in_element_content, arginfo_dom_text_is_whitespace_in_element_content)
58 PHP_FALIAS(isElementContentWhitespace, dom_text_is_whitespace_in_element_content, arginfo_dom_text_is_whitespace_in_element_content)
59 PHP_FALIAS(replaceWholeText, dom_text_replace_whole_text, arginfo_dom_text_replace_whole_text)
60 PHP_ME(domtext, __construct, arginfo_dom_text_construct, ZEND_ACC_PUBLIC)
61 PHP_FE_END
62 };
63
64
65 PHP_METHOD(domtext, __construct)
66 {
67
68 zval *id;
69 xmlNodePtr nodep = NULL, oldnode = NULL;
70 dom_object *intern;
71 char *value = NULL;
72 int value_len;
73 zend_error_handling error_handling;
74
75 zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
76 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|s", &id, dom_text_class_entry, &value, &value_len) == FAILURE) {
77 zend_restore_error_handling(&error_handling TSRMLS_CC);
78 return;
79 }
80
81 zend_restore_error_handling(&error_handling TSRMLS_CC);
82 nodep = xmlNewText((xmlChar *) value);
83
84 if (!nodep) {
85 php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
86 RETURN_FALSE;
87 }
88
89 intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
90 if (intern != NULL) {
91 oldnode = dom_object_get_node(intern);
92 if (oldnode != NULL) {
93 php_libxml_node_free_resource(oldnode TSRMLS_CC);
94 }
95 php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern TSRMLS_CC);
96 }
97 }
98
99
100
101
102
103
104
105 int dom_text_whole_text_read(dom_object *obj, zval **retval TSRMLS_DC)
106 {
107 xmlNodePtr node;
108 xmlChar *wholetext = NULL;
109
110 node = dom_object_get_node(obj);
111
112 if (node == NULL) {
113 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
114 return FAILURE;
115 }
116
117
118 while (node->prev && ((node->prev->type == XML_TEXT_NODE) || (node->prev->type == XML_CDATA_SECTION_NODE))) {
119 node = node->prev;
120 }
121
122
123 while (node && ((node->type == XML_TEXT_NODE) || (node->type == XML_CDATA_SECTION_NODE))) {
124 wholetext = xmlStrcat(wholetext, node->content);
125 node = node->next;
126 }
127
128 ALLOC_ZVAL(*retval);
129 if (wholetext != NULL) {
130 ZVAL_STRING(*retval, wholetext, 1);
131 xmlFree(wholetext);
132 } else {
133 ZVAL_EMPTY_STRING(*retval);
134 }
135
136 return SUCCESS;
137 }
138
139
140
141
142
143
144
145 PHP_FUNCTION(dom_text_split_text)
146 {
147 zval *id;
148 xmlChar *cur;
149 xmlChar *first;
150 xmlChar *second;
151 xmlNodePtr node;
152 xmlNodePtr nnode;
153 long offset;
154 int ret;
155 int length;
156 dom_object *intern;
157
158 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &id, dom_text_class_entry, &offset) == FAILURE) {
159 return;
160 }
161 DOM_GET_OBJ(node, id, xmlNodePtr, intern);
162
163 if (node->type != XML_TEXT_NODE && node->type != XML_CDATA_SECTION_NODE) {
164 RETURN_FALSE;
165 }
166
167 cur = xmlNodeGetContent(node);
168 if (cur == NULL) {
169 RETURN_FALSE;
170 }
171 length = xmlUTF8Strlen(cur);
172
173 if (offset > length || offset < 0) {
174 xmlFree(cur);
175 RETURN_FALSE;
176 }
177
178 first = xmlUTF8Strndup(cur, offset);
179 second = xmlUTF8Strsub(cur, offset, length - offset);
180
181 xmlFree(cur);
182
183 xmlNodeSetContent(node, first);
184 nnode = xmlNewDocText(node->doc, second);
185
186 xmlFree(first);
187 xmlFree(second);
188
189 if (nnode == NULL) {
190 RETURN_FALSE;
191 }
192
193 if (node->parent != NULL) {
194 nnode->type = XML_ELEMENT_NODE;
195 xmlAddNextSibling(node, nnode);
196 nnode->type = XML_TEXT_NODE;
197 }
198
199 return_value = php_dom_create_object(nnode, &ret, return_value, intern TSRMLS_CC);
200 }
201
202
203
204
205
206
207 PHP_FUNCTION(dom_text_is_whitespace_in_element_content)
208 {
209 zval *id;
210 xmlNodePtr node;
211 dom_object *intern;
212
213 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_text_class_entry) == FAILURE) {
214 return;
215 }
216 DOM_GET_OBJ(node, id, xmlNodePtr, intern);
217
218 if (xmlIsBlankNode(node)) {
219 RETURN_TRUE;
220 } else {
221 RETURN_FALSE;
222 }
223 }
224
225
226
227
228
229
230 PHP_FUNCTION(dom_text_replace_whole_text)
231 {
232 DOM_NOT_IMPLEMENTED();
233 }
234
235
236 #endif
237
238
239
240
241
242
243
244
245