Lines Matching refs:this

145 		$this->dom = $dom;
146 $dom->nodes[] = $this;
151 $this->clear();
156 return $this->outertext();
161 $this->dom = null;
162 $this->nodes = null;
163 $this->parent = null;
164 $this->children = null;
169 echo str_repeat("\t", $depth) . $this->tag;
171 if ($show_attr && count($this->attr) > 0) {
173 foreach ($this->attr as $k => $v) {
181 if ($this->nodes) {
182 foreach ($this->nodes as $node) {
190 $string = $this->tag;
192 if (count($this->attr) > 0) {
194 foreach ($this->attr as $k => $v) {
200 if (count($this->_) > 0) {
202 foreach ($this->_ as $k => $v) {
216 if (isset($this->text)) {
217 $string .= " text: ({$this->text})";
228 $string .= ' children: ' . count($this->children);
229 $string .= ' nodes: ' . count($this->nodes);
230 $string .= ' tag_start: ' . $this->tag_start;
243 // I am SURE that this doesn't work properly.
247 $this->parent = $parent;
248 $this->parent->nodes[] = $this;
249 $this->parent->children[] = $this;
252 return $this->parent;
257 return !empty($this->children);
263 return $this->children;
266 if (isset($this->children[$idx])) {
267 return $this->children[$idx];
275 if (count($this->children) > 0) {
276 return $this->children[0];
283 if (count($this->children) > 0) {
284 return end($this->children);
291 if ($this->parent === null) {
295 $idx = array_search($this, $this->parent->children, true);
297 if ($idx !== false && isset($this->parent->children[$idx + 1])) {
298 return $this->parent->children[$idx + 1];
306 if ($this->parent === null) {
310 $idx = array_search($this, $this->parent->children, true);
313 return $this->parent->children[$idx - 1];
324 if ($this->parent === null) {
328 $ancestor = $this->parent;
347 if (isset($this->_[HDOM_INFO_INNER])) {
348 return $this->_[HDOM_INFO_INNER];
351 if (isset($this->_[HDOM_INFO_TEXT])) {
352 return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
357 foreach ($this->nodes as $n) {
371 if ($this->tag === 'text') {
372 if (!empty($this->text)) {
373 $text = ' with text: ' . $this->text;
377 $debug_object->debug_log(1, 'Innertext of tag: ' . $this->tag . $text);
380 if ($this->tag === 'root') {
381 return $this->innertext();
384 // todo: What is the use of this callback? Remove?
385 if ($this->dom && $this->dom->callback !== null) {
386 call_user_func_array($this->dom->callback, array($this));
389 if (isset($this->_[HDOM_INFO_OUTER])) {
390 return $this->_[HDOM_INFO_OUTER];
393 if (isset($this->_[HDOM_INFO_TEXT])) {
394 return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
399 if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]) {
400 $ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup();
403 if (isset($this->_[HDOM_INFO_INNER])) {
405 if ($this->tag !== 'br') {
406 $ret .= $this->_[HDOM_INFO_INNER];
408 } elseif ($this->nodes) {
409 foreach ($this->nodes as $n) {
410 $ret .= $this->convert_text($n->outertext());
414 if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END] != 0) {
415 $ret .= '</' . $this->tag . '>';
423 if (isset($this->_[HDOM_INFO_INNER])) {
424 return $this->_[HDOM_INFO_INNER];
427 switch ($this->nodetype) {
428 case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
433 if (strcasecmp($this->tag, 'script') === 0) { return ''; }
434 if (strcasecmp($this->tag, 'style') === 0) { return ''; }
439 // for some span tags, and some p tags) $this->nodes is set to NULL.
442 // WHY is this happening?
443 if (!is_null($this->nodes)) {
444 foreach ($this->nodes as $n) {
450 $ret .= $this->convert_text($n->text());
452 // If this node is a span... add a space at the end of it so
456 $ret .= $this->dom->default_span_text;
465 $ret = $this->innertext();
474 if (isset($this->_[HDOM_INFO_TEXT])) {
475 return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
478 $ret = '<' . $this->tag;
481 foreach ($this->attr as $key => $val) {
487 $ret .= @$this->_[HDOM_INFO_SPACE][$i][0];
493 switch (@$this->_[HDOM_INFO_QUOTE][$i])
501 . @$this->_[HDOM_INFO_SPACE][$i][1]
503 . @$this->_[HDOM_INFO_SPACE][$i][2]
510 $ret = $this->dom->restore_noise($ret);
511 return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>';
516 $selectors = $this->parse_selector($selector);
526 if (!isset($this->_[HDOM_INFO_BEGIN])) { return array(); }
528 $head = array($this->_[HDOM_INFO_BEGIN] => 1);
536 $n = ($k === -1) ? $this->dom->root : $this->dom->nodes[$k];
537 //PaperG - Pass this optional parameter on to the seek function.
557 $found[] = $this->dom->nodes[$k];
577 $end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0;
579 $parent = $this->parent;
588 $nodes_start = $this->_[HDOM_INFO_BEGIN] + 1;
590 $nodes = array_slice($this->dom->nodes, $nodes_start, $nodes_count, true);
592 $nodes = $this->children;
594 && $this->parent
595 && in_array($this, $this->parent->children)) { // Next-Sibling Combinator
596 $index = array_search($this, $this->parent->children, true) + 1;
597 if ($index < count($this->parent->children))
598 $nodes[] = $this->parent->children[$index];
600 && $this->parent
601 && in_array($this, $this->parent->children)) { // Subsequent Sibling Combinator
602 $index = array_search($this, $this->parent->children, true);
603 $nodes = array_slice($this->parent->children, $index);
606 // Go throgh each element starting at this element until the end tag
607 // Note: If this element is a void tag, any previous void element is
694 // If this is the correct node, continue with next
717 // If they have told us that this is a "plaintext"
742 $check = $this->match(
749 $check = $this->match(
775 // It's passed by reference so this is actually what this function returns.
837 * Note: if you try to look at this attribute, you MUST use getAttribute
844 * is required to determine of this should be documented or removed.
846 * Matches selectors in this order:
898 if ($this->dom->lowercase) {
967 if (isset($this->attr[$name])) {
968 return $this->convert_text($this->attr[$name]);
971 case 'outertext': return $this->outertext();
972 case 'innertext': return $this->innertext();
973 case 'plaintext': return $this->text();
974 case 'xmltext': return $this->xmltext();
975 default: return array_key_exists($name, $this->attr);
985 case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value;
987 if (isset($this->_[HDOM_INFO_TEXT])) {
988 return $this->_[HDOM_INFO_TEXT] = $value;
990 return $this->_[HDOM_INFO_INNER] = $value;
993 if (!isset($this->attr[$name])) {
994 $this->_[HDOM_INFO_SPACE][] = array(' ', '', '');
995 $this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE;
998 $this->attr[$name] = $value;
1009 return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]);
1014 if (isset($this->attr[$name])) { unset($this->attr[$name]); }
1027 if ($this->dom) {
1028 $sourceCharset = strtoupper($this->dom->_charset);
1029 $targetCharset = strtoupper($this->dom->_target_charset);
1046 && ($this->is_utf8($text))) {
1101 if ($this->tag !== 'img') {
1106 if (isset($this->attr['width'])) {
1107 $width = $this->attr['width'];
1110 if (isset($this->attr['height'])) {
1111 $height = $this->attr['height'];
1115 if (isset($this->attr['style'])) {
1116 // Thanks to user gnarf from stackoverflow for this regular expression.
1121 $this->attr['style'],
1161 // Look at all the parent tags of this image to see if they specify a
1163 // Note that in this case, the class or id will have the img subselector
1181 $ret = $this->outertext();
1198 if (isset($this->class)) {
1199 if ($this->hasClass($c)) {
1202 $this->class .= ' ' . $c;
1205 $this->class = $c;
1218 if (isset($this->class)) {
1219 return in_array($class, explode(' ', $this->class), true);
1232 if (!isset($this->class)) {
1237 $this->removeAttribute('class');
1246 $class = array_diff(explode(' ', $this->class), $class);
1248 $this->removeAttribute('class');
1250 $this->class = implode(' ', $class);
1257 return $this->attr;
1262 return $this->__get($name);
1267 $this->__set($name, $value);
1272 return $this->__isset($name);
1277 $this->__set($name, null);
1282 if ($this->parent) {
1283 $this->parent->removeChild($this);
1289 $nidx = array_search($node, $this->nodes, true);
1290 $cidx = array_search($node, $this->children, true);
1291 $didx = array_search($node, $this->dom->nodes, true);
1309 unset($this->nodes[$nidx]);
1310 unset($this->children[$cidx]);
1311 unset($this->dom->nodes[$didx]);
1320 return $this->find("#$id", 0);
1325 return $this->find("#$id", $idx);
1330 return $this->find($name, 0);
1335 return $this->find($name, $idx);
1340 return $this->parent();
1345 return $this->children($idx);
1350 return $this->first_child();
1355 return $this->last_child();
1360 return $this->next_sibling();
1365 return $this->prev_sibling();
1370 return $this->has_child();
1375 return $this->tag;
1380 $node->parent($this);
1470 $this->load_file($str);
1472 $this->load(
1485 $this->optional_closing_array = array();
1488 $this->_target_charset = $target_charset;
1493 $this->clear();
1507 $this->prepare($str, $lowercase, $defaultBRText, $defaultSpanText);
1512 $this->remove_noise("'<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>'is");
1513 $this->remove_noise("'<\s*script\s*>(.*?)<\s*/\s*script\s*>'is");
1517 $this->doc = str_replace("\r", ' ', $this->doc);
1518 $this->doc = str_replace("\n", ' ', $this->doc);
1521 $this->size = strlen($this->doc);
1525 $this->remove_noise("'<!\[CDATA\[(.*?)\]\]>'is", true);
1527 $this->remove_noise("'<!--(.*?)-->'is");
1529 $this->remove_noise("'<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>'is");
1530 $this->remove_noise("'<\s*style\s*>(.*?)<\s*/\s*style\s*>'is");
1532 $this->remove_noise("'<\s*(?:code)[^>]*>(.*?)<\s*/\s*(?:code)\s*>'is");
1534 $this->remove_noise("'(<\?)(.*?)(\?>)'s", true);
1537 $this->remove_noise("'(\{\w)(.*?)(\})'s", true);
1541 $this->parse();
1543 $this->root->_[HDOM_INFO_END] = $this->cursor;
1544 $this->parse_charset();
1547 return $this;
1555 $this->load($doc, true);
1563 $this->callback = $function_name;
1568 $this->callback = null;
1573 $ret = $this->root->innertext();
1580 return $this->root->find($selector, $idx, $lowercase);
1585 if (isset($this->nodes)) {
1586 foreach ($this->nodes as $n) {
1595 if (isset($this->children)) {
1596 foreach ($this->children as $n) {
1602 if (isset($this->parent)) {
1603 $this->parent->clear();
1604 unset($this->parent);
1607 if (isset($this->root)) {
1608 $this->root->clear();
1609 unset($this->root);
1612 unset($this->doc);
1613 unset($this->noise);
1618 $this->root->dump($show_attr);
1626 $this->clear();
1628 $this->doc = trim($str);
1629 $this->size = strlen($this->doc);
1630 $this->original_size = $this->size; // original size of the html
1631 $this->pos = 0;
1632 $this->cursor = 1;
1633 $this->noise = array();
1634 $this->nodes = array();
1635 $this->lowercase = $lowercase;
1636 $this->default_br_text = $defaultBRText;
1637 $this->default_span_text = $defaultSpanText;
1638 $this->root = new simple_html_dom_node($this);
1639 $this->root->tag = 'root';
1640 $this->root->_[HDOM_INFO_BEGIN] = -1;
1641 $this->root->nodetype = HDOM_TYPE_ROOT;
1642 $this->parent = $this->root;
1643 if ($this->size > 0) { $this->char = $this->doc[0]; }
1651 if (($s = $this->copy_until_char('<')) === '') {
1652 if($this->read_tag()) {
1660 $node = new simple_html_dom_node($this);
1661 ++$this->cursor;
1663 $this->link_nodes($node, false);
1689 $el = $this->root->find('meta[http-equiv=Content-Type]', 0, true);
1727 if ($meta = $this->root->find('meta[charset]', 0)) {
1754 $this->doc,
1763 if (!@iconv('CP1252', 'UTF-8', $this->doc)) {
1802 return $this->_charset = $charset;
1808 if ($this->char !== '<') {
1809 $this->root->_[HDOM_INFO_END] = $this->cursor;
1813 $begin_tag_pos = $this->pos;
1814 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
1817 if ($this->char === '/') {
1818 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
1821 $this->skip($this->token_blank);
1822 $tag = $this->copy_until_char('>');
1829 $parent_lower = strtolower($this->parent->tag);
1837 if (isset($this->optional_closing_tags[$parent_lower])
1838 && isset($this->block_tags[$tag_lower])) {
1840 $this->parent->_[HDOM_INFO_END] = 0;
1841 $org_parent = $this->parent;
1845 while (($this->parent->parent)
1846 && strtolower($this->parent->tag) !== $tag_lower
1848 $this->parent = $this->parent->parent;
1852 if (strtolower($this->parent->tag) !== $tag_lower) {
1853 $this->parent = $org_parent; // restore origonal parent
1855 if ($this->parent->parent) {
1856 $this->parent = $this->parent->parent;
1859 $this->parent->_[HDOM_INFO_END] = $this->cursor;
1860 return $this->as_text_node($tag);
1862 } elseif (($this->parent->parent)
1863 && isset($this->block_tags[$tag_lower])
1867 $this->parent->_[HDOM_INFO_END] = 0; // No end tag
1868 $org_parent = $this->parent;
1872 while (($this->parent->parent)
1873 && strtolower($this->parent->tag) !== $tag_lower
1875 $this->parent = $this->parent->parent;
1879 if (strtolower($this->parent->tag) !== $tag_lower) {
1880 $this->parent = $org_parent; // restore origonal parent
1881 $this->parent->_[HDOM_INFO_END] = $this->cursor;
1882 return $this->as_text_node($tag);
1884 } elseif (($this->parent->parent)
1885 && strtolower($this->parent->parent->tag) === $tag_lower
1887 $this->parent->_[HDOM_INFO_END] = 0;
1888 $this->parent = $this->parent->parent;
1890 return $this->as_text_node($tag);
1895 $this->parent->_[HDOM_INFO_END] = $this->cursor;
1897 if ($this->parent->parent) {
1898 $this->parent = $this->parent->parent;
1901 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
1906 $node = new simple_html_dom_node($this);
1907 $node->_[HDOM_INFO_BEGIN] = $this->cursor;
1908 ++$this->cursor;
1909 $tag = $this->copy_until($this->token_slash); // Get tag name
1917 $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until_char('>');
1927 if ($this->char === '>') { $node->_[HDOM_INFO_TEXT] .= '>'; }
1929 $this->link_nodes($node, true);
1930 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
1939 $this->link_nodes($node, false);
1940 $this->char = $this->doc[--$this->pos]; // prev
1946 $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until('<>');
1949 if ($this->char === '<') {
1950 $this->link_nodes($node, false);
1955 if ($this->char === '>') { $node->_[HDOM_INFO_TEXT] .= '>'; }
1956 $this->link_nodes($node, false);
1957 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
1964 $node->tag = ($this->lowercase) ? $tag_lower : $tag;
1967 if (isset($this->optional_closing_tags[$tag_lower])) {
1969 while (isset($this->optional_closing_tags[$tag_lower][strtolower($this->parent->tag)])) {
1970 $this->parent->_[HDOM_INFO_END] = 0;
1971 $this->parent = $this->parent->parent;
1973 $node->parent = $this->parent;
1979 $space = array($this->copy_skip($this->token_blank), '', '');
1984 $name = $this->copy_until($this->token_equal);
1986 if ($name === '' && $this->char !== null && $space[0] === '') {
1990 if ($guard === $this->pos) { // Escape infinite loop
1991 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
1995 $guard = $this->pos;
1999 if ($this->pos >= $this->size - 1 && $this->char !== '>') {
2004 $this->link_nodes($node, false);
2010 if ($this->doc[$this->pos - 1] == '<') {
2016 $this->doc,
2018 $this->pos - $begin_tag_pos - 1
2020 $this->pos -= 2;
2021 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2022 $this->link_nodes($node, false);
2026 if ($name !== '/' && $name !== '') { // this is a attribute name
2028 $space[1] = $this->copy_skip($this->token_blank);
2030 $name = $this->restore_noise($name); // might be a noisy name
2032 if ($this->lowercase) { $name = strtolower($name); }
2034 if ($this->char === '=') { // attribute with value
2035 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2036 $this->parse_attr($node, $name, $space); // get attribute value
2041 if ($this->char != '>') { $this->char = $this->doc[--$this->pos]; } // prev
2048 $this->copy_skip($this->token_blank),
2055 } while ($this->char !== '>' && $this->char !== '/'); // go until the tag ended
2057 $this->link_nodes($node, true);
2061 if ($this->copy_until_char('>') === '/') {
2066 if (!isset($this->self_closing_tags[strtolower($node->tag)])) {
2067 $this->parent = $node;
2071 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2075 // since a br tag never has sub nodes, this works well.
2077 $node->_[HDOM_INFO_INNER] = $this->default_br_text;
2088 $space[2] = $this->copy_skip($this->token_blank);
2090 switch ($this->char) {
2093 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2094 $value = $this->copy_until_char('"');
2095 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2099 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2100 $value = $this->copy_until_char('\'');
2101 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2105 $value = $this->copy_until($this->token_attr);
2108 $value = $this->restore_noise($value);
2114 if ($this->strip_rn) {
2119 // PaperG: If this is a "class" selector, lets get rid of the preceeding
2133 $node->parent = $this->parent;
2134 $this->parent->nodes[] = $node;
2136 $this->parent->children[] = $node;
2142 $node = new simple_html_dom_node($this);
2143 ++$this->cursor;
2145 $this->link_nodes($node, false);
2146 $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2152 $this->pos += strspn($this->doc, $chars, $this->pos);
2153 $this->char = ($this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2158 $pos = $this->pos;
2159 $len = strspn($this->doc, $chars, $pos);
2160 $this->pos += $len;
2161 $this->char = ($this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2163 return substr($this->doc, $pos, $len);
2168 $pos = $this->pos;
2169 $len = strcspn($this->doc, $chars, $pos);
2170 $this->pos += $len;
2171 $this->char = ($this->pos < $this->size) ? $this->doc[$this->pos] : null; // next
2172 return substr($this->doc, $pos, $len);
2177 if ($this->char === null) { return ''; }
2179 if (($pos = strpos($this->doc, $char, $this->pos)) === false) {
2180 $ret = substr($this->doc, $this->pos, $this->size - $this->pos);
2181 $this->char = null;
2182 $this->pos = $this->size;
2186 if ($pos === $this->pos) { return ''; }
2188 $pos_old = $this->pos;
2189 $this->char = $this->doc[$pos];
2190 $this->pos = $pos;
2191 return substr($this->doc, $pos_old, $pos - $pos_old);
2201 $this->doc,
2207 $key = '___noise___' . sprintf('% 5d', count($this->noise) + 1000);
2214 $this->noise[$key] = $matches[$i][$idx][0];
2215 $this->doc = substr_replace($this->doc, $key, $matches[$i][$idx][1], strlen($matches[$i][$idx][0]));
2219 $this->size = strlen($this->doc);
2221 if ($this->size > 0) {
2222 $this->char = $this->doc[0];
2250 if (isset($this->noise[$key])) {
2252 . $this->noise[$key]
2255 // do this to prevent an infinite loop.
2277 foreach($this->noise as $noiseElement) {
2286 return $this->root->innertext();
2293 return $this->root->innertext();
2295 return $this->root->innertext();
2297 return $this->root->text();
2299 return $this->_charset;
2301 return $this->_target_charset;
2307 return $this->root->childNodes($idx);
2312 return $this->root->first_child();
2317 return $this->root->last_child();
2332 return $this->find("#$id", 0);
2337 return $this->find("#$id", $idx);
2342 return $this->find($name, 0);
2347 return $this->find($name, $idx);
2353 $this->load_file($args);