Lines Matching +full:check +full:- +full:attr

3  * phpQuery is a server-side, chainable, CSS3 selector driven
8 * @link http://phpquery-library.blogspot.com/
11 * @license http://www.opensource.org/licenses/mit-license.php MIT License
13 * @deprecated 2022-10-19
68 * The explicit original target of the event (Mozilla-specific).
76 * The original target of the event, before any retargetings (Mozilla-specific).
102 * Returns the name of the event (case-insensitive).
109 $this->$k = $v;
111 if (! $this->timeStamp)
112 $this->timeStamp = time();
119 $this->runDefault = false;
126 $this->bubbles = false;
135 * - in XHTML fragments, <br /> changes to <br clear="none" />
137 * @todo check XML catalogs compatibility
178 $this->load($markup, $contentType, $newDocumentID);
179 $this->id = $newDocumentID
185 $this->contentType = strtolower($contentType);
187 $this->document = $markup;
188 $this->root = $this->document;
189 $this->charset = $this->document->encoding;
192 $loaded = $this->loadMarkup($markup);
195 // $this->document->formatOutput = true;
196 $this->document->preserveWhiteSpace = true;
197 $this->xpath = new DOMXPath($this->document);
198 $this->afterMarkupLoad();
206 if ($this->isXHTML) {
207 $this->xpath->registerNamespace("html", "http://www.w3.org/1999/xhtml");
212 if ($this->contentType) {
213 self::debug("Load markup for content type {$this->contentType}");
215 list($contentType, $charset) = $this->contentTypeToArray($this->contentType);
218 phpQuery::debug("Loading HTML, content type '{$this->contentType}'");
219 $loaded = $this->loadMarkupHTML($markup, $charset);
223 phpQuery::debug("Loading XML, content type '{$this->contentType}'");
224 $loaded = $this->loadMarkupXML($markup, $charset);
228 if (strpos('xml', $this->contentType) !== false) {
229 phpQuery::debug("Loading XML, content type '{$this->contentType}'");
230 $loaded = $this->loadMarkupXML($markup, $charset);
232 … phpQuery::debug("Could not determine document type from content type '{$this->contentType}'");
236 if ($this->isXML($markup)) {
238 $loaded = $this->loadMarkupXML($markup);
239 if (! $loaded && $this->isXHTML) {
241 $loaded = $this->loadMarkupHTML($markup);
245 $loaded = $this->loadMarkupHTML($markup);
251 $this->isXML = $this->isXHTML = $this->isHTML = false;
256 $this->document = new DOMDocument($version, $charset);
257 $this->charset = $this->document->encoding;
258 // $this->document->encoding = $charset;
259 $this->document->formatOutput = true;
260 $this->document->preserveWhiteSpace = true;
265 $this->loadMarkupReset();
266 $this->isHTML = true;
267 if (!isset($this->isDocumentFragment))
268 $this->isDocumentFragment = self::isDocumentFragmentHTML($markup);
270 $documentCharset = $this->charsetFromHTML($markup);
274 $markup = $this->charsetFixHTML($markup);
280 // HTTP 1.1 says that the default charset is ISO-8859-1
281 // @see http://www.w3.org/International/O-HTTP-charset
283 $documentCharset = 'ISO-8859-1';
308 $markup = $this->charsetAppendToHTML($markup, $requestedCharset);
316 if ($this->isDocumentFragment) {
318 $return = $this->documentFragmentLoadMarkup($this, $charset, $markup);
322 $markup = $this->charsetAppendToHTML($markup, $charset);
325 $this->documentCreate($charset);
327 ? $this->document->loadHTML($markup)
328 : @$this->document->loadHTML($markup);
330 $this->root = $this->document;
332 if ($return && ! $this->contentType)
333 $this->contentType = 'text/html';
339 $this->loadMarkupReset();
340 $this->isXML = true;
341 // check agains XHTML in contentType or markup
342 $isContentTypeXHTML = $this->isXHTML();
343 $isMarkupXHTML = $this->isXHTML($markup);
346 $this->isXHTML = true;
349 if (! isset($this->isDocumentFragment))
350 $this->isDocumentFragment = $this->isXHTML
356 $documentCharset = $this->charsetFromXML($markup);
358 if ($this->isXHTML) {
359 // this is XHTML, try to get charset from content-type meta header
360 $documentCharset = $this->charsetFromHTML($markup);
363 $this->charsetAppendToXML($markup, $documentCharset);
382 if ($this->isDocumentFragment) {
384 $return = $this->documentFragmentLoadMarkup($this, $charset, $markup);
390 $markup = $this->charsetAppendToXML($markup, $charset);
395 // $this->document->resolveExternals = true;
398 $this->documentCreate($charset);
400 $this->document->resolveExternals = true;
402 ? $this->document->loadXML($markup)
403 : @$this->document->loadXML($markup);
409 $return = $this->document->loadXML($markup, $libxmlStatic);
411 // $return = $this->document->loadHTML($markup);
414 $this->root = $this->document;
417 if (! $this->contentType) {
418 if ($this->isXHTML)
419 $this->contentType = 'application/xhtml+xml';
421 $this->contentType = 'text/xml';
430 return strpos($this->contentType, 'xhtml') !== false;
435 // $doctype = isset($dom->doctype) && is_object($dom->doctype)
436 // ? $dom->doctype->publicId
463 preg_match('@<meta[^>]+http-equiv\\s*=\\s*(["|\'])Content-Type\\1([^>]+?)>@i',
468 // get attr 'content'
472 return $this->contentTypeToArray($matches[2]);
475 $contentType = $this->contentTypeFromHTML($markup);
497 preg_match('@\s*<meta[^>]+http-equiv\\s*=\\s*(["|\'])Content-Type\\1([^>]+?)>@i',
511 // remove existing meta[type=content-type]
512 …$html = preg_replace('@\s*<meta[^>]+http-equiv\\s*=\\s*(["|\'])Content-Type\\1([^>]+?)>@i', '', $h…
513 $meta = '<meta http-equiv="Content-Type" content="text/html;charset='
567 // $fake = $this->documentFragmentCreate($node, $sourceCharset);
572 // $this->import($fake->root->childNodes)
575 // $return[] = $this->document->importNode($node, true);
581 // $fake = $this->documentFragmentCreate($source, $sourceCharset);
585 // return $this->import($fake->root->childNodes);
591 $return[] = $this->document->importNode($node, true);
594 $fake = $this->documentFragmentCreate($source, $sourceCharset);
598 return $this->import($fake->root->childNodes);
610 $fake->contentType = $this->contentType;
611 $fake->isXML = $this->isXML;
612 $fake->isHTML = $this->isHTML;
613 $fake->isXHTML = $this->isXHTML;
614 $fake->root = $fake->document;
616 $charset = $this->charset;
617 // $fake->documentCreate($this->charset);
623 if (! $this->documentFragmentLoadMarkup($fake, $charset))
625 $nodes = $fake->import($source);
627 $fake->root->appendChild($node);
630 $this->documentFragmentLoadMarkup($fake, $charset, $source);
644 $fragment->isDocumentFragment = false;
645 if ($fragment->isXML) {
646 if ($fragment->isXHTML) {
648 $fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?>'
649 .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
650 .'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
652 $fragment->root = $fragment->document->firstChild->nextSibling;
654 … $fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?><fake>'.$markup.'</fake>');
655 $fragment->root = $fragment->document->firstChild;
658 …$markup2 = phpQuery::$defaultDoctype.'<html><head><meta http-equiv="Content-Type" content="text/ht…
667 $fragment->loadMarkupHTML($markup2);
669 $fragment->root = $noBody
670 ? $fragment->document->firstChild->nextSibling->firstChild->nextSibling
671 : $fragment->document->firstChild->nextSibling->firstChild->nextSibling;
673 if (! $fragment->root)
675 $fragment->isDocumentFragment = true;
680 $tmp = $fragment->isDocumentFragment;
681 $fragment->isDocumentFragment = false;
682 $markup = $fragment->markup();
683 if ($fragment->isXML) {
685 if ($fragment->isXHTML) {
694 $fragment->isDocumentFragment = $tmp;
712 if ($this->isDocumentFragment && ! $innerMarkup)
714 if ($node->isSameNode($this->root)) {
717 + phpQuery::DOMNodeListToArray($node->childNodes)
720 if ($this->isXML && ! $innerMarkup) {
721 self::debug("Getting outerXML with charset '{$this->charset}'");
725 $markup .= $this->document->saveXML($node);
730 if ($node->childNodes)
731 foreach($node->childNodes as $child)
739 $fake = $this->documentFragmentCreate($loop);
740 $markup = $this->documentFragmentToMarkup($fake);
742 if ($this->isXHTML) {
749 if ($this->isDocumentFragment) {
752 // return $this->markup(
753 //// $this->document->getElementsByTagName('body')->item(0)
754 // $this->document->root, true
756 $markup = $this->documentFragmentToMarkup($this);
760 …self::debug("Getting markup (".($this->isXML?'XML':'HTML')."), final with charset '{$this->charset…
761 $markup = $this->isXML
762 ? $this->document->saveXML()
763 : $this->document->saveHTML();
764 if ($this->isXHTML) {
797 if ($xml[$posCierre-1] == "/"){
798 $xml = substr_replace($xml, "></$tag>", $posCierre-1, 2);
825 * @TODO support more than event in $type (space-separated)
838 // TODO check add($pq->document)
839 $pq->find('*')->add($pq->document)
840 ->trigger($type, $data);
845 $event->relatedTarget = $event->target;
846 $event->target = $node;
860 $event->currentTarget = $node;
862 if (isset($eventNode->eventHandlers)) {
863 foreach($eventNode->eventHandlers as $eventType => $handlers) {
875 $event->data = $handler['data']
881 $event->bubbles = false;
887 if (! $event->bubbles)
889 $node = $node->parentNode;
904 * @TODO support more than event in $type (space-separated)
917 if (!isset($eventNode->eventHandlers[$type]))
918 $eventNode->eventHandlers[$type] = array();
919 $eventNode->eventHandlers[$type][] = array(
932 * @TODO support more than event in $type (space-separated)
937 if (is_object($eventNode) && isset($eventNode->eventHandlers[$type])) {
939 foreach($eventNode->eventHandlers[$type] as $k => $handler)
941 unset($eventNode->eventHandlers[$type][$k]);
943 unset($eventNode->eventHandlers[$type]);
948 foreach(phpQuery::$documents[$documentID]->eventsNodes as $eventNode) {
949 if ($node->isSameNode($eventNode))
954 phpQuery::$documents[$documentID]->eventsNodes[] = $node;
955 return phpQuery::$documents[$documentID]->eventsNodes[
956 count(phpQuery::$documents[$documentID]->eventsNodes)-1
961 ? in_array($type, phpQuery::$documents[$documentID]->eventsGlobal)
972 * Callback class introduces currying-like pattern.
1006 $this->callback = $callback;
1007 $this->params = $params;
1011 return 'Callback: '.$this->name;
1014 return isset($this->name) && $this->name;
1017 $this->name = $name;
1023 // return new Callback($this->callback, $this->params+$params);
1036 $this->reference =& $reference;
1037 $this->callback = array($this, 'callback');
1040 return $this->reference;
1043 return 'Callback: '.$this->name;
1046 return isset($this->name) && $this->name;
1059 $this->value =& $value;
1060 $this->name = $name;
1061 $this->callback = array($this, 'callback');
1064 return $this->value;
1067 return $this->getName();
1070 return 'Callback: '.$this->name;
1073 return isset($this->name) && $this->name;
1090 $this->callback =& $reference;
1101 // $this->callback =& $reference;
1140 * @TODO refactor to ->nodes
1161 * be queried against <html>, but getDocument(id)->htmlOuter() will return
1191 // var_dump($documentID->getDocumentID());
1193 ? $documentID->getDocumentID()
1200 $this->documentID = $id;
1201 $this->documentWrapper =& phpQuery::$documents[$id];
1202 $this->document =& $this->documentWrapper->document;
1203 $this->xpath =& $this->documentWrapper->xpath;
1204 $this->charset =& $this->documentWrapper->charset;
1205 $this->documentFragment =& $this->documentWrapper->isDocumentFragment;
1206 // TODO check $this->DOM->documentElement;
1207 // $this->root = $this->document->documentElement;
1208 $this->root =& $this->documentWrapper->root;
1209 // $this->toRoot();
1210 $this->elements = array($this->root);
1215 * @param $attr
1218 public function __get($attr) { argument
1219 switch($attr) {
1222 return $this->size();
1225 return $this->$attr;
1239 phpQuery::$documents[$this->getDocumentID()]['documentFragment'] = $state;
1242 return $this->documentFragment;
1249 // return $node instanceof DOMDOCUMENT || $node->tagName == 'html';
1251 || ($node instanceof DOMELEMENT && $node->tagName == 'html')
1252 || $this->root->isSameNode($node);
1258 return $this->size() == 1 && $this->isRoot($this->elements[0]);
1269 $this->elements = array($this->root);
1271 // return $this->newInstance(array($this->root));
1278 * ->getDocumentIDRef($myDocumentId)
1279 * ->find('div')->...
1288 $documentID = $this->getDocumentID();
1297 return phpQuery::getDocument($this->getDocumentID());
1304 return $this->document;
1312 return $this->documentID;
1322 phpQuery::unloadDocuments($this->getDocumentID());
1325 return $this->documentWrapper->isHTML;
1328 return $this->documentWrapper->isXHTML;
1331 return $this->documentWrapper->isXML;
1340 return phpQuery::param($this->serializeArray());
1349 $source = $this->filter('form, input, select, textarea')
1350 ->find('input, select, textarea')
1351 ->andSelf()
1352 ->not('form');
1354 // $source->dumpDie();
1357 if ($input->is('[disabled]'))
1359 if (!$input->is('[name]'))
1361 if ($input->is('[type=checkbox]') && !$input->is('[checked]'))
1364 if ($submit && $input->is('[type=submit]')) {
1365 if ($submit instanceof DOMELEMENT && ! $input->elements[0]->isSameNode($submit))
1367 else if (is_string($submit) && $input->attr('name') != $submit)
1371 'name' => $input->attr('name'),
1372 'value' => $input->val(),
1397 $pattern[ mb_strlen($pattern)-1 ],
1433 $classChars = array('.', '-');
1434 $pseudoChars = array('-');
1435 $tagChars = array('*', '|', '-');
1448 if ($this->isChar($c) || in_array($c, $tagChars)) {
1450 && ($this->isChar($query[$i]) || in_array($query[$i], $tagChars))) {
1458 while( isset($query[$i]) && ($this->isChar($query[$i]) || $query[$i] == '-')) {
1478 $return =& $queries[ count($queries)-1 ];
1484 … while( isset($query[$i]) && ($this->isChar($query[$i]) || in_array($query[$i], $classChars))) {
1494 && ($this->isChar($query[$i])
1510 && ($this->isChar($query[$i])
1530 $stack--;
1541 … while( isset($query[$i]) && ($this->isChar($query[$i]) || in_array($query[$i], $pseudoChars))) {
1554 $stack--;
1586 ? (isset($this->elements[$index]) ? $this->elements[$index] : null)
1587 : $this->elements;
1612 $return = $this->eq($index)->text();
1615 for($i = 0; $i < $this->size(); $i++) {
1616 $return[] = $this->eq($i)->text();
1639 $return = $this->eq($index)->text();
1642 for($i = 0; $i < $this->size(); $i++) {
1643 $return[] = $this->eq($i)->text();
1667 ? new $class($this, $this->getDocumentID())
1668 : new phpQueryObject($this->getDocumentID());
1669 $new->previous = $this;
1671 $new->elements = $this->elements;
1672 if ($this->elementsBackup)
1673 $this->elements = $this->elementsBackup;
1675 $new->elements = phpQuery::pq($newStack, $this->getDocumentID())->stack();
1677 $new->elements = $newStack;
1692 // multi-class
1696 $nodeClasses = explode(' ', $node->getAttribute('class') );
1708 // single-class
1714 explode(' ', $node->getAttribute('class') )
1725 if (! $this->elements)
1726 $this->debug('Stack empty, skipping...');
1727 // var_dump($this->elements[0]->nodeType);
1729 foreach($this->stack(array(1, 9, 13)) as $k => $stackNode) {
1735 if (! $testNode->parentNode && ! $this->isRoot($testNode)) {
1736 $this->root->appendChild($testNode);
1740 $testNode = isset($testNode->parentNode)
1741 ? $testNode->parentNode
1745 $xpath = $this->documentWrapper->isXHTML
1746 ? $this->getNodeXpath($stackNode, 'html')
1747 : $this->getNodeXpath($stackNode);
1748 // FIXME pseudoclasses-only query, support XML
1752 $this->debug("XPATH: {$query}");
1754 $nodes = $this->xpath->query($query);
1755 $this->debug("QUERY FETCHED");
1756 if (! $nodes->length )
1757 $this->debug('Nothing found');
1763 … $this->debug("Found: ".$this->whois( $node ).", comparing with {$compare}()")
1776 $debug[] = $this->whois( $node );
1781 $this->debug("Matched ".count($debug).": ".implode(', ', $debug));
1784 $this->root->removeChild($detachAfter);
1786 $this->elements = $stack;
1796 $this->elementsBackup = $this->elements;
1802 $this->elements = array($context);
1804 $this->elements = array();
1807 $this->elements[] = $c;
1809 $this->elements = $context->elements;
1811 $queries = $this->parseSelector($selectors);
1812 $this->debug(array('FIND', $selectors, $queries));
1814 // remember stack state because of multi-queries
1815 $oldStack = $this->elements;
1819 $this->elements = $oldStack;
1824 ? mb_ereg_match('^[\w|\||-]+$', $s) || $s == '*'
1825 : preg_match('@^[\w|\||-]+$@', $s) || $s == '*';
1827 if ($this->isXML()) {
1836 $XQuery .= "*[local-name()='$s']";
1851 $attr = trim($s, '][');
1853 // attr with specifed value
1856 list($attr, $value) = explode('=', $attr);
1858 if ($this->isRegexp($attr)) {
1860 $attr = substr($attr, 0, -1);
1862 $XQuery .= "[@{$attr}]";
1864 $XQuery .= "[@{$attr}='{$value}']";
1866 // attr without specified value
1868 $XQuery .= "[@{$attr}]";
1871 $this->runQuery($XQuery, $s, 'is');
1873 if (! $this->length())
1878 … // TODO use return $this->find("./self::*[contains(concat(\" \",@class,\" \"), \" $class \")]");
1883 $this->runQuery($XQuery, $s, 'matchClasses');
1885 if (! $this->length() )
1889 $this->runQuery($XQuery);
1891 $this->elements = $this
1892 ->siblings(
1894 )->elements;
1895 if (! $this->length() )
1899 // TODO /following-sibling::
1900 $this->runQuery($XQuery);
1903 $subElements = $this->elements;
1904 $this->elements = array();
1907 $test = $node->nextSibling;
1909 $test = $test->nextSibling;
1910 if ($test && $this->is($subSelector, $test))
1911 $this->elements[] = $test;
1913 if (! $this->length() )
1919 $this->runQuery($XQuery);
1922 if (! $this->length())
1924 $this->pseudoClasses($s);
1925 if (! $this->length())
1943 $this->runQuery($XQuery);
1946 foreach($this->elements as $node)
1947 if (! $this->elementsContainsNode($node, $stack))
1950 $this->elements = $stack;
1951 return $this->newInstance();
1962 $args = substr($class, $haveArgs+1, -1);
1969 foreach($this->elements as $i => $node) {
1975 $this->elements = $stack;
1979 $this->elements = isset( $this->elements[$k] )
1980 ? array( $this->elements[$k] )
1984 $this->elements = array_slice($this->elements, $args+1);
1987 $this->elements = array_slice($this->elements, 0, $args+1);
1990 if (isset($this->elements[0]))
1991 $this->elements = array($this->elements[0]);
1994 if ($this->elements)
1995 $this->elements = array($this->elements[count($this->elements)-1]);
1999 foreach($this->elements as $node) {
2000 if ( $node->childNodes->length )
2003 $this->elements = $stack;
2008 foreach($this->elements as $node) {
2009 if (mb_stripos($node->textContent, $text) === false)
2013 $this->elements = $stack;
2017 $this->elements = $this->not($selector)->stack();
2029 $end = $end-$start;
2030 $this->elements = array_slice($this->elements, $start, $end);
2035 foreach($this->stack(1) as $el) {
2036 if ($this->find($selector, $el, true)->length)
2039 $this->elements = $stack;
2043 $this->elements = phpQuery::merge(
2044 $this->map(array($this, 'is'),
2047 $this->map(array($this, 'is'),
2053 // foreach($this->elements as $node)
2054 // if ($node->is('input[type=submit]') || $node->is('button[type=submit]'))
2056 // $this->elements = $stack;
2058 $this->elements = $this->map(
2061 )->elements;
2069 $this->elements = $this->map(
2072 )->elements;
2075 $this->elements = $this->map(
2077 return $node instanceof DOMELEMENT && $node->childNodes->length
2080 )->elements;
2083 $this->elements = $this->map(
2085 return $node instanceof DOMELEMENT && $node->childNodes->length
2088 )->elements;
2093 $this->elements = $this->map(
2096 )->elements;
2099 $this->elements = $this->map(
2101 return pq($node)->not(":disabled") ? $node : null;
2103 )->elements;
2106 $this->elements = $this->map(
2108 $isHeader = isset($node->tagName) && in_array($node->tagName, array(
2115 )->elements;
2116 // $this->elements = $this->map(
2118 // return $node->is("h1")
2119 // || $node->is("h2")
2120 // || $node->is("h3")
2121 // || $node->is("h4")
2122 // || $node->is("h5")
2123 // || $node->is("h6")
2124 // || $node->is("h7")
2127 // )->elements;
2129 case 'only-child':
2130 $this->elements = $this->map(
2132 return pq($node)->siblings()->size() == 0 ? $node : null;
2134 )->elements;
2136 case 'first-child':
2137 $this->elements = $this->map(
2139 return pq($node)->prevAll()->size() == 0 ? $node : null;
2141 )->elements;
2143 case 'last-child':
2144 $this->elements = $this->map(
2146 return pq($node)->nextAll()->size() == 0 ? $node : null;
2148 )->elements;
2150 case 'nth-child':
2154 // nth-child(n+b) to nth-child(1n+b)
2157 // :nth-child(index/even/odd/equation)
2159 $mapped = $this->map(
2161 $index = pq($node)->prevAll()->size() + 1;
2172 $mapped = $this->map(
2174 $prevs = pq($node)->prevAll()->size();
2180 if ($b && $param[2] == "-")
2181 $b = -$b;
2183 return ($index - $b) % $a == 0
2186 …phpQuery::debug($a . "*" . floor($index / $a) . "+$b-1 == " . ($a * floor($index / $a) + $b - 1) .…
2187 return $a * floor($index / $a) + $b - 1 == $prevs
2205 // return ($index-$b)%$a == 0
2213 $mapped = $this->map(
2215 $prevs = pq($node)->prevAll()->size();
2216 if ($prevs && $prevs == $index - 1)
2225 $this->elements = $mapped->elements;
2228 $this->debug("Unknown pseudoclass '{$class}', skipping...");
2246 $oldStack = $this->elements;
2249 $this->elements = $nodes;
2251 $this->elements = array($nodes);
2252 $this->filter($selector, true);
2253 $stack = $this->elements;
2254 $this->elements = $oldStack;
2264 * - $index int
2265 * - $node DOMNode
2272 $this->elementsBackup = $this->elements;
2273 $this->debug("Filtering by callback");
2276 foreach($this->elements as $index => $node) {
2281 $this->elements = $newStack;
2284 : $this->newInstance();
2294 return $this->filterCallback($selectors, $_skipHistory);
2296 $this->elementsBackup = $this->elements;
2299 $selectors = $this->parseSelector($selectors);
2301 $this->debug(array("Filtering:", $selectors));
2311 foreach($this->stack() as $node) {
2317 $attr = trim($s, '[]');
2318 if ( mb_strpos($attr, '=')) {
2319 list( $attr, $val ) = explode('=', $attr);
2320 if ($attr == 'nodeType' && $node->nodeType != $val)
2329 if ( $node->getAttribute('id') != substr($s, 1) )
2333 if (! $this->matchClasses( $s, $node ) )
2338 $attr = trim($s, '[]');
2339 if (mb_strpos($attr, '=')) {
2340 list($attr, $val) = explode('=', $attr);
2342 if ($attr == 'nodeType') {
2343 if ($val != $node->nodeType)
2345 } else if ($this->isRegexp($attr)) {
2350 switch( substr($attr, -1)) {
2364 $attr = substr($attr, 0, -1);
2366 ? mb_ereg_match($pattern, $node->getAttribute($attr))
2367 : preg_match("@{$pattern}@", $node->getAttribute($attr));
2370 } else if ($node->getAttribute($attr) != $val)
2372 } else if (! $node->hasAttribute($attr))
2381 if (isset($node->tagName)) {
2382 if ($node->tagName != $s)
2384 } else if ($s == 'html' && ! $this->isRoot($node))
2387 // AVOID NON-SIMPLE SELECTORS
2390 $this->debug(array('Skipping non simple selector', $selector));
2396 // if element passed all chunks of selector - add it to new stack
2400 $tmpStack = $this->elements;
2401 $this->elements = $stack;
2406 $this->pseudoClasses($s);
2407 foreach($this->elements as $node)
2411 $this->elements = $tmpStack;
2413 $this->elements = $finalStack;
2417 $this->debug("Stack length after filter(): ".count($finalStack));
2418 return $this->newInstance();
2429 ? substr($value, 1, -1)
2453 $this->_loadSelector = $selector;
2471 if ($this->_loadSelector) {
2472 $html = phpQuery::newDocument($html)->find($this->_loadSelector);
2473 unset($this->_loadSelector);
2475 foreach($this->stack(1) as $node) {
2476 phpQuery::pq($node, $this->getDocumentID())
2477 ->markup($html);
2512 * @TODO support more than event in $type (space-separated)
2515 foreach($this->elements as $node)
2516 phpQueryEvents::trigger($this->getDocumentID(), $type, $data, $node);
2539 * @TODO support more than event in $type (space-separated)
2542 // TODO check if $data is callable, not using is_callable
2547 foreach($this->elements as $node)
2548 phpQueryEvents::add($this->getDocumentID(), $node, $type, $data, $callback);
2558 * @TODO support more than event in $type (space-separated)
2561 foreach($this->elements as $node)
2562 phpQueryEvents::remove($this->getDocumentID(), $node, $type, $callback);
2572 return $this->bind('change', $callback);
2573 return $this->trigger('change');
2582 return $this->bind('submit', $callback);
2583 return $this->trigger('submit');
2592 return $this->bind('click', $callback);
2593 return $this->trigger('click');
2602 $wrapper = pq($wrapper)->_clone();
2603 if (! $wrapper->length() || ! $this->length() )
2605 $wrapper->insertBefore($this->elements[0]);
2606 $deepest = $wrapper->elements[0];
2607 while($deepest->firstChild && $deepest->firstChild instanceof DOMELEMENT)
2608 $deepest = $deepest->firstChild;
2609 pq($deepest)->append($this);
2620 if (! $this->length())
2622 return phpQuery::pq($wrapper, $this->getDocumentID())
2623 ->clone()
2624 ->insertBefore($this->get(0))
2625 ->map(array($this, '___wrapAllCallback'))
2626 ->append($this);
2636 while($deepest->firstChild && $deepest->firstChild instanceof DOMELEMENT)
2637 $deepest = $deepest->firstChild;
2649 ->slice(0, 1)
2650 ->beforePHP($codeBefore)
2651 ->end()
2652 ->slice(-1)
2653 ->afterPHP($codeAfter)
2654 ->end();
2663 foreach($this->stack() as $node)
2664 phpQuery::pq($node, $this->getDocumentID())->wrapAll($wrapper);
2674 foreach($this->stack() as $node)
2675 phpQuery::pq($node, $this->getDocumentID())->wrapAllPHP($codeBefore, $codeAfter);
2685 foreach($this->stack() as $node)
2686 phpQuery::pq($node, $this->getDocumentID())->contents()->wrapAll($wrapper);
2696 foreach($this->stack(1) as $node)
2697 phpQuery::pq($node, $this->getDocumentID())->contents()
2698 ->wrapAllPHP($codeBefore, $codeAfter);
2709 foreach($this->stack(1) as $el) {
2711 // if (! isset($el->childNodes))
2713 foreach($el->childNodes as $node) {
2717 return $this->newInstance($stack);
2727 foreach($this->stack(1) as $node) {
2728 if (! $node->parentNode )
2732 foreach($node->childNodes as $chNode )
2735 // $node->parentNode->appendChild($chNode);
2736 $node->parentNode->insertBefore($chNode, $node);
2737 $node->parentNode->removeChild($node);
2747 $markup = pq($markup, $this->getDocumentID());
2749 foreach($this->stack(1) as $node) {
2751 ->contents()->toReference($content)->end()
2752 ->replaceWith($markup->clone()->append($content));
2762 $oldStack = $this->elements;
2763 $this->elementsBackup = $this->elements;
2764 $this->elements = array();
2766 $this->elements[] = $oldStack[$num];
2767 return $this->newInstance();
2775 return count($this->elements);
2784 return $this->size();
2787 return $this->size();
2796 // $this->elements = array_pop( $this->history );
2798 // $this->previous->DOM = $this->DOM;
2799 // $this->previous->XPath = $this->XPath;
2800 return $this->previous
2801 ? $this->previous
2806 * Normal use ->clone() .
2813 //pr(array('copy... ', $this->whois()));
2814 //$this->dumpHistory('copy');
2815 $this->elementsBackup = $this->elements;
2816 foreach($this->elements as $node) {
2817 $newStack[] = $node->cloneNode(true);
2819 $this->elements = $newStack;
2820 return $this->newInstance();
2828 return $this->replaceWith(phpQuery::php($code));
2838 return $this->after($content)->remove();
2848 foreach(phpQuery::pq($selector, $this->getDocumentID()) as $node)
2849 phpQuery::pq($node, $this->getDocumentID())
2850 ->after($this->_clone())
2851 ->remove();
2861 ? $this->filter($selector)->elements
2862 : $this->elements;
2864 if (! $node->parentNode )
2866 if (isset($node->tagName))
2867 $this->debug("Removing '{$node->tagName}'");
2868 $node->parentNode->removeChild($node);
2874 phpQueryEvents::trigger($this->getDocumentID(),
2875 $event->type, array($event), $node
2881 if ($node->tagName == 'textarea' && $newMarkup != $oldMarkup) {
2886 phpQueryEvents::trigger($this->getDocumentID(),
2887 $event->type, array($event), $node
2900 if ($this->documentWrapper->isXML)
2913 if ($this->documentWrapper->isXML)
2928 $nodes = $this->documentWrapper->import($html);
2929 $this->empty();
2930 foreach($this->stack(1) as $alreadyAdded => $node) {
2932 if (($this->isXHTML() || $this->isHTML()) && $node->tagName == 'textarea')
2933 $oldHtml = pq($node, $this->getDocumentID())->markup();
2935 $node->appendChild($alreadyAdded
2936 ? $newNode->cloneNode(true)
2941 if (($this->isXHTML() || $this->isHTML()) && $node->tagName == 'textarea')
2942 $this->markupEvents($html, $oldHtml, $node);
2947 $return = $this->documentWrapper->markup($this->elements, true);
2969 $markup = $this->documentWrapper->markup($this->elements);
2985 return $this->markupOuter();
2994 return $this->markupPHP($code);
3004 ? $this->markup(phpQuery::php($code))
3005 : phpQuery::markupToPHP($this->markup());
3014 return phpQuery::markupToPHP($this->markupOuter());
3023 foreach($this->stack(1) as $node) {
3024 // foreach($node->getElementsByTagName('*') as $newNode) {
3025 foreach($node->childNodes as $newNode) {
3026 if ($newNode->nodeType != 1)
3028 if ($selector && ! $this->is($selector, $newNode))
3030 if ($this->elementsContainsNode($newNode, $stack))
3035 $this->elementsBackup = $this->elements;
3036 $this->elements = $stack;
3037 return $this->newInstance();
3045 return $this->children( $selector );
3053 return $this->insert($content, __FUNCTION__);
3061 return $this->insert("<php><!-- {$content} --></php>", 'append');
3069 return $this->insert($seletor, __FUNCTION__);
3077 return $this->insert($content, __FUNCTION__);
3086 return $this->insert("<php><!-- {$content} --></php>", 'prepend');
3094 return $this->insert($seletor, __FUNCTION__);
3102 return $this->insert($content, __FUNCTION__);
3110 return $this->insert("<php><!-- {$content} --></php>", 'before');
3119 return $this->insert($seletor, __FUNCTION__);
3127 return $this->insert($content, __FUNCTION__);
3135 return $this->insert("<php><!-- {$content} --></php>", 'after');
3143 return $this->insert($seletor, __FUNCTION__);
3154 $this->debug("Inserting data with '{$type}'");
3168 $insertFrom = $this->elements;
3171 $insertTo = $this->documentWrapper->import($target);
3175 $thisStack = $this->elements;
3176 $this->toRoot();
3177 $insertTo = $this->find($target)->elements;
3178 $this->elements = $thisStack;
3182 $insertTo = $this->elements;
3183 $insertFrom = $this->documentWrapper->import($target);
3191 $insertTo = $target->elements;
3192 if ($this->documentFragment && $this->stackIsRoot())
3194 // $loop = $this->find('body > *')->elements;
3196 // $loop = $this->newInstance($this->root)->find('> *')->elements;
3197 $loop = $this->root->childNodes;
3199 $loop = $this->elements;
3201 $insertFrom = $this->getDocumentID() == $target->getDocumentID()
3203 : $target->documentWrapper->import($loop);
3205 $insertTo = $this->elements;
3206 if ( $target->documentFragment && $target->stackIsRoot() )
3208 // $loop = $target->find('body > *')->elements;
3209 $loop = $target->root->childNodes;
3211 $loop = $target->elements;
3213 $insertFrom = $this->getDocumentID() == $target->getDocumentID()
3215 : $this->documentWrapper->import($loop);
3220 // if ( $target->ownerDocument != $this->DOM )
3221 // $target = $this->DOM->importNode($target, true);
3224 if ($this->documentFragment && $this->stackIsRoot())
3226 $loop = $this->root->childNodes;
3227 // $loop = $this->find('body > *')->elements;
3229 $loop = $this->elements;
3232 … $insertFrom[] = ! $fromNode->ownerDocument->isSameNode($target->ownerDocument)
3233 ? $target->ownerDocument->importNode($fromNode, true)
3237 if (! $target->ownerDocument->isSameNode($this->document))
3238 $target = $this->document->importNode($target, true);
3239 $insertTo = $this->elements;
3251 $firstChild = $toNode->firstChild;
3255 $nextSibling = $toNode->nextSibling;
3261 ? $fromNode->cloneNode(true)
3266 // $toNode->insertBefore(
3268 // $toNode->lastChild->nextSibling
3270 $toNode->appendChild($insert);
3275 $toNode->insertBefore(
3282 if (! $toNode->parentNode)
3285 $toNode->parentNode->insertBefore(
3292 if (! $toNode->parentNode)
3295 $toNode->parentNode->insertBefore(
3306 phpQueryEvents::trigger($this->getDocumentID(),
3307 $event->type, array($event), $insert
3319 $index = -1;
3321 ? $subject->elements[0]
3323 foreach($this->newInstance() as $k => $node) {
3324 if ($node->isSameNode($subject))
3339 // $last = count($this->elements)-1;
3348 $end = $end-$start;
3349 return $this->newInstance(
3350 array_slice($this->elements, $start, $end)
3359 $this->elementsBackup = $this->elements;
3360 $this->elements = array_reverse($this->elements);
3361 return $this->newInstance();
3369 return $this->html(htmlspecialchars($text));
3373 foreach($this->elements as $node) {
3374 $text = $node->textContent;
3375 if (count($this->elements) > 1 && $text)
3394 * Deprecated, use $pq->plugin() instead.
3402 return $this->plugin($class, $file);
3445 return $this->newInstance(
3446 $this->getElementSiblings('nextSibling', $selector, true)
3457 return $this->prev($selector);
3465 return $this->newInstance(
3466 $this->getElementSiblings('previousSibling', $selector, true)
3474 return $this->newInstance(
3475 $this->getElementSiblings('previousSibling', $selector)
3483 return $this->newInstance(
3484 $this->getElementSiblings('nextSibling', $selector)
3493 foreach($this->stack() as $node) {
3495 while( isset($test->{$direction}) && $test->{$direction}) {
3496 $test = $test->{$direction};
3505 $stackOld = $this->elements;
3506 $this->elements = $stack;
3507 $stack = $this->filter($selector, true)->stack();
3508 $this->elements = $stackOld;
3520 $this->getElementSiblings('previousSibling', $selector),
3521 $this->getElementSiblings('nextSibling', $selector)
3524 if (! $this->elementsContainsNode($node, $stack))
3527 return $this->newInstance($stack);
3541 foreach($this->stack() as $node) {
3544 foreach($selector->stack() as $notNode) {
3545 if ($notNode->isSameNode($node))
3551 if (! $selector->isSameNode($node))
3554 if (! $this->is($selector))
3559 $orgStack = $this->stack();
3560 $matched = $this->filter($selector, true)->stack();
3563 // foreach($this->parseSelector($selector) as $s) {
3565 // $this->filter(array($s))->stack()
3569 if (! $this->elementsContainsNode($node, $matched))
3572 return $this->newInstance($stack);
3584 $this->elementsBackup = $this->elements;
3585 $found = phpQuery::pq($selector, $this->getDocumentID());
3586 $this->merge($found->elements);
3587 return $this->newInstance();
3595 if (! $this->elementsContainsNode($newNode) )
3596 $this->elements[] = $newNode;
3605 : $this->elements;
3607 if ( $node->isSameNode( $nodeToCheck ) )
3619 foreach($this->elements as $node )
3620 if ( $node->parentNode && ! $this->elementsContainsNode($node->parentNode, $stack) )
3621 $stack[] = $node->parentNode;
3622 $this->elementsBackup = $this->elements;
3623 $this->elements = $stack;
3625 $this->filter($selector, true);
3626 return $this->newInstance();
3635 if (! $this->elements )
3636 $this->debug('parents() - stack empty');
3637 foreach($this->elements as $node) {
3639 while( $test->parentNode) {
3640 $test = $test->parentNode;
3641 if ($this->isRoot($test))
3643 if (! $this->elementsContainsNode($test, $stack)) {
3649 $this->elementsBackup = $this->elements;
3650 $this->elements = $stack;
3652 $this->filter($selector, true);
3653 return $this->newInstance();
3662 return $this->elements;
3666 foreach($this->elements as $node) {
3667 if (in_array($node->nodeType, $nodeTypes))
3673 protected function attrEvents($attr, $oldAttr, $oldValue, $node) { argument
3675 if (! $this->isXHTML() && ! $this->isHTML())
3679 $isInputValue = $node->tagName == 'input'
3681 in_array($node->getAttribute('type'),
3683 || !$node->getAttribute('type')
3685 $isRadio = $node->tagName == 'input'
3686 && $node->getAttribute('type') == 'radio';
3687 $isCheckbox = $node->tagName == 'input'
3688 && $node->getAttribute('type') == 'checkbox';
3689 $isOption = $node->tagName == 'option';
3690 if ($isInputValue && $attr == 'value' && $oldValue != $node->getAttribute($attr)) {
3695 } else if (($isRadio || $isCheckbox) && $attr == 'checked' && (
3696 // check
3697 (! $oldAttr && $node->hasAttribute($attr))
3698 // un-check
3699 || (! $node->hasAttribute($attr) && $oldAttr)
3705 } else if ($isOption && $node->parentNode && $attr == 'selected' && (
3707 (! $oldAttr && $node->hasAttribute($attr))
3708 // un-select
3709 || (! $node->hasAttribute($attr) && $oldAttr)
3712 'target' => $node->parentNode,
3717 phpQueryEvents::trigger($this->getDocumentID(),
3718 $event->type, array($event), $node
3722 public function attr($attr = null, $value = null) { function in phpQueryObject
3723 foreach($this->stack(1) as $node) {
3725 $loop = $attr == '*'
3726 ? $this->getNodeAttrs($node)
3727 : array($attr);
3729 $oldValue = $node->getAttribute($a);
3730 $oldAttr = $node->hasAttribute($a);
3731 // TODO raises an error when charset other than UTF-8
3732 // while document's charset is also not UTF-8
3733 @$node->setAttribute($a, $value);
3734 $this->attrEvents($a, $oldAttr, $oldValue, $node);
3736 } else if ($attr == '*') {
3739 foreach($node->attributes as $n => $v)
3740 $return[$n] = $v->value;
3743 return $node->hasAttribute($attr)
3744 ? $node->getAttribute($attr)
3755 foreach($node->attributes as $n => $o)
3763 * @todo check CDATA ???
3765 public function attrPHP($attr, $code) { argument
3771 // $value = mb_convert_encoding($value, 'UTF-8', 'HTML-ENTITIES');
3773 foreach($this->stack(1) as $node) {
3775 // $attrNode = $this->DOM->createAttribute($attr);
3776 $node->setAttribute($attr, $value);
3777 // $attrNode->value = $value;
3778 // $node->appendChild($attrNode);
3779 } else if ( $attr == '*') {
3782 foreach($node->attributes as $n => $v)
3783 $return[$n] = $v->value;
3786 return $node->getAttribute($attr);
3795 public function removeAttr($attr) { argument
3796 foreach($this->stack(1) as $node) {
3797 $loop = $attr == '*'
3798 ? $this->getNodeAttrs($node)
3799 : array($attr);
3801 $oldValue = $node->getAttribute($a);
3802 $node->removeAttribute($a);
3803 $this->attrEvents($a, $oldValue, null, $node);
3815 if ($this->eq(0)->is('select')) {
3816 $selected = $this->eq(0)->find('option[selected=selected]');
3817 if ($selected->is('[value]'))
3818 return $selected->attr('value');
3820 return $selected->text();
3821 } else if ($this->eq(0)->is('textarea'))
3822 return $this->eq(0)->markup();
3824 return $this->eq(0)->attr('value');
3827 foreach($this->stack(1) as $node) {
3828 $node = pq($node, $this->getDocumentID());
3829 if (is_array($val) && in_array($node->attr('type'), array('checkbox', 'radio'))) {
3830 $isChecked = in_array($node->attr('value'), $val)
3831 || in_array($node->attr('name'), $val);
3833 $node->attr('checked', 'checked');
3835 $node->removeAttr('checked');
3836 } else if ($node->get(0)->tagName == 'select') {
3845 foreach($node['option']->stack(1) as $option) {
3846 $option = pq($option, $this->getDocumentID());
3850 $selected = is_null($option->attr('value'))
3851 ? in_array($option->markup(), $_val)
3852 : in_array($option->attr('value'), $_val);
3853 // $optionValue = $option->attr('value');
3854 // $optionText = $option->text();
3862 $option->attr('selected', 'selected');
3864 $option->removeAttr('selected');
3866 } else if ($node->get(0)->tagName == 'textarea')
3867 $node->markup($val);
3869 $node->attr('value', $val);
3880 if ( $this->previous )
3881 $this->elements = array_merge($this->elements, $this->previous->elements);
3892 foreach($this->stack(1) as $node) {
3893 if (! $this->is(".$className", $node))
3894 $node->setAttribute(
3896 trim($node->getAttribute('class').' '.$className)
3907 foreach($this->stack(1) as $node) {
3908 $classes = $node->getAttribute('class');
3912 $node->setAttribute('class', $newValue);
3923 foreach($this->stack(1) as $node) {
3924 if ( $this->is(".$className", $node))
3935 foreach($this->stack(1) as $node) {
3936 $classes = explode( ' ', $node->getAttribute('class'));
3940 $node->setAttribute('class', implode(' ', $classes));
3942 $node->removeAttribute('class');
3953 foreach($this->stack(1) as $node) {
3954 if ( $this->is( $node, '.'.$className ))
3955 $this->removeClass($className);
3957 $this->addClass($className);
3962 * Proper name without underscore (just ->empty()) also works.
3979 foreach($this->stack(1) as $node) {
3981 $node->nodeValue = '';
4000 foreach($this->elements as $v)
4023 //// foreach($this->newInstance() as $node) {
4024 // foreach($this->newInstance() as $node) {
4030 array_unshift($params, $this->elements);
4031 return $this->newInstance(
4033 // phpQuery::map($this->elements, $callback)
4046 return phpQuery::data($this->get(0), $key, $value, $this->getDocumentID());
4049 phpQuery::data($node, $key, $value, $this->getDocumentID());
4060 phpQuery::removeData($node, $key, $this->getDocumentID());
4070 $this->debug('iterating foreach');
4071 // phpQuery::selectDocument($this->getDocumentID());
4072 $this->elementsBackup = $this->elements;
4073 $this->elementsInterator = $this->elements;
4074 $this->valid = isset( $this->elements[0] )
4076 // $this->elements = $this->valid
4077 // ? array($this->elements[0])
4079 $this->current = 0;
4085 return $this->elementsInterator[ $this->current ];
4091 return $this->current;
4094 * Double-function method.
4105 // if ($cssSelector || $this->valid)
4106 // return $this->_next($cssSelector);
4107 $this->valid = isset( $this->elementsInterator[ $this->current+1 ] )
4110 if (! $this->valid && $this->elementsInterator) {
4111 $this->elementsInterator = null;
4112 } else if ($this->valid) {
4113 $this->current++;
4115 return $this->_next($cssSelector);
4122 return $this->valid;
4130 return $this->find($offset)->size() > 0;
4136 return $this->find($offset);
4142 // $this->find($offset)->replaceWith($value);
4143 $this->find($offset)->html($value);
4165 : $this->elements;
4177 while($sibling->previousSibling) {
4178 $sibling = $sibling->previousSibling;
4180 if ($isElement && $sibling->tagName == $node->tagName)
4183 $xpath[] = $this->isXML()
4184 ? "*[local-name()='{$node->tagName}'][{$i}]"
4185 : "{$node->tagName}[{$i}]";
4186 $node = $node->parentNode;
4200 : $this->elements;
4202 if (isset($node->tagName)) {
4203 $tag = in_array($node->tagName, array('php', 'js'))
4204 ? strtoupper($node->tagName)
4205 : $node->tagName;
4207 .($node->getAttribute('id')
4208 ? '#'.$node->getAttribute('id'):'')
4209 .($node->getAttribute('class')
4210 ? '.'.join('.', explode(' ', $node->getAttribute('class'))):'')
4211 .($node->getAttribute('name')
4212 ? '[name="'.$node->getAttribute('name').'"]':'')
4213 … .($node->getAttribute('value') && strpos($node->getAttribute('value'), '<'.'?php') === false
4214 … ? '[value="'.substr(str_replace("\n", '', $node->getAttribute('value')), 0, 15).'"]':'')
4215 … .($node->getAttribute('value') && strpos($node->getAttribute('value'), '<'.'?php') !== false
4217 .($node->getAttribute('selected')
4219 .($node->getAttribute('checked')
4223 if (trim($node->textContent))
4224 $return[] = 'Text:'.substr(str_replace("\n", ' ', $node->textContent), 0, 15);
4244 var_dump($this->htmlOuter());
4252 var_dump('whois', $this->whois());
4261 var_dump('length', $this->length());
4270 foreach($this->stack() as $node)
4271 $output .= $this->dumpTreeInternal($node);
4279 $whois = $this->whois($node);
4282 $return .= str_repeat(' - ', $intend).$whois."\n";
4283 if (isset($node->childNodes))
4284 foreach($node->childNodes as $chNode)
4285 $return .= $this->dumpTreeInternal($chNode, $intend+1);
4294 var_dump($this->htmlOuter());
4300 // -- Multibyte Compatibility functions ---------------------------------------
4306 * Included for mbstring pseudo-compatability.
4316 * Included for mbstring pseudo-compatability.
4326 * Included for mbstring pseudo-compatability.
4339 * Included for mbstring pseudo-compatability.
4351 * Included for mbstring pseudo-compatability.
4364 * Included for mbstring pseudo-compatability.
4377 * Included for mbstring pseudo-compatability.
4404 …tic $defaultDoctype = 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/…
4410 public static $defaultDoctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
4412 public static $defaultCharset = 'UTF-8';
4452 'contentType' => "application/x-www-form-urlencoded",
4471 * Multi-purpose function.
4477 * - Import into selected document:
4479 * - Import into document with ID from $pq->getDocumentID():
4480 * pq('<div/>', $pq->getDocumentID())
4481 * - Import into same document as DOMNode belongs to:
4483 * - Import into document from phpQuery object:
4487 * - Run query on last selected document:
4489 * - Run query on document with ID from $pq->getDocumentID():
4490 * pq('div.myClass', $pq->getDocumentID())
4491 * - Run query on same document as DOMNode belongs to and use node(s)as root for query:
4493 * - Run query on document from phpQuery object
4498 …* @param string|phpQueryObject|DOMNode $context DOM ID from $pq->getDocumentID(), phpQuery obje…
4507 ? $arg1 : $arg1->ownerDocument;
4508 if ($documentWrapper->document->isSameNode($compare))
4509 $context = $documentWrapper->id;
4518 $domId = $context->getDocumentID();
4523 $domId = self::newDocument($context)->getDocumentID();
4529 // $domId = self::newDocument($context->ownerDocument);
4539 if ($arg1->getDocumentID() == $domId)
4546 $phpQuery->elements = array();
4547 foreach($arg1->elements as $node)
4548 $phpQuery->elements[] = $phpQuery->document->importNode($node, true);
4558 $phpQuery->elements = array();
4560 $sameDocument = $node->ownerDocument instanceof DOMDOCUMENT
4561 && ! $node->ownerDocument->isSameNode($phpQuery->document);
4562 $phpQuery->elements[] = $sameDocument
4563 ? $phpQuery->document->importNode($node, true)
4573 return $phpQuery->newInstance(
4574 $phpQuery->documentWrapper->import($arg1)
4584 $phpQuery->elements = $context->elements;
4586 $phpQuery->elements = array();
4588 $phpQuery->elements[] = $node;
4590 $phpQuery->elements = array($context);
4591 return $phpQuery->find($arg1);
4687 public static function phpToMarkup($php, $charset = 'utf-8') {
4708 $php = preg_replace($regex, '\\1<php><!-- \\3 --></php>', $php);
4711 public static function _phpToMarkupCallback($php, $charset = 'utf-8') {
4728 $content = $content->markupOuter();
4731 '@<php>\s*<!--(.*?)-->\s*</php>@s',
4738 /* <node attr='< ?php ? >'> extra space added to save highlighters */
4861 // $wrapper->id = $id;
4863 phpQuery::$documents[$wrapper->id] = $wrapper;
4865 phpQuery::selectDocument($wrapper->id);
4866 return $wrapper->id;
5021 * 'document' - document for global events, @see phpQuery::getDocumentID()
5022 * 'referer' - implemented
5023 * 'requested_with' - TODO; not implemented (X-Requested-With)
5043 // $client->setParameterPost(null);
5044 // $client->setParameterGet(null);
5045 $client->setAuth(false);
5046 $client->setHeaders("If-Modified-Since", null);
5047 $client->setHeaders("Referer", null);
5048 $client->resetParameters();
5053 $client->setCookieJar();
5056 $client->setConfig(array(
5111 $client->setUri($options['url']);
5112 $client->setMethod(strtoupper($options['type']));
5114 $client->setHeaders('Referer', $options['referer']);
5115 $client->setHeaders(array(
5116 // 'content-type' => $options['contentType'],
5117 'User-Agent' => 'Mozilla/5.0 (X11; U; Linux x86; en-US; rv:1.9.0.5) Gecko'
5120 'Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
5121 // 'Connection' => 'keep-alive',
5123 'Accept-Language' => 'en-us,en;q=0.5',
5126 $client->setAuth($options['username'], $options['password']);
5128 $client->setHeaders("If-Modified-Since",
5133 $client->setHeaders("Accept",
5141 $serialized = $options['data']->serializeArray($options['data']);
5147 $client->setParameterGet($options['data']);
5149 $client->setEncType($options['contentType']);
5150 $client->setParameterPost($options['data']);
5164 // if ($client->getCookieJar())
5165 // self::debug("Cookies: <pre>".var_export($client->getCookieJar()->getMatchingCookies…
5168 $response = $client->request();
5170 self::debug('Status: '.$response->getStatus().' / '.$response->getMessage());
5171 self::debug($client->getLastRequest());
5172 self::debug($response->getHeaders());
5174 if ($response->isSuccessful()) {
5176 self::$lastModified = $response->getHeader('Last-Modified');
5177 $data = self::httpData($response->getBody(), $options['dataType'], $options);
5179 … phpQuery::callbackRun($options['success'], array($data, $response->getStatus(), $options));
5184 …hpQuery::callbackRun($options['error'], array($client, $response->getStatus(), $response->getMessa…
5186 …s::trigger($documentID, 'ajaxError', array($client, /*$response->getStatus(),*/$response->getMessa…
5189 phpQuery::callbackRun($options['complete'], array($client, $response->getStatus()));
5192 if ($options['global'] && ! --self::$active)
5324 if ($source->isSameNode($document->document))
5329 if ($source->ownerDocument->isSameNode($document->document))
5333 return $source->getDocumentID();
5441 $callback->callback = $params[0];
5445 $paramStructure = $callback->params;
5446 $callback = $callback->callback;
5466 $elements = $one->elements;
5467 foreach($two->elements as $node) {
5470 if ($node2->isSameNode($node))
5477 // $one = $one->newInstance();
5478 // $one->elements = $elements;
5505 * @TODO there are problems with non-static methods, second parameter pass it
5582 return "<$type><!-- ".trim($code)." --></$type>";
5593 foreach(phpQuery::$documents[$documentID]->dataNodes as $dataNode) {
5594 if ($node->isSameNode($dataNode))
5598 phpQuery::$documents[$documentID]->dataNodes[] = $node;
5603 foreach(phpQuery::$documents[$documentID]->dataNodes as $k => $dataNode) {
5604 if ($node->isSameNode($dataNode)) {
5605 unset(self::$documents[$documentID]->dataNodes[$k]);
5606 unset(self::$documents[$documentID]->data[ $dataNode->dataID ]);
5612 // TODO check if this works
5616 if (! isset($node->dataID))
5617 $node->dataID = ++phpQuery::$documents[$documentID]->uuid;
5618 $id = $node->dataID;
5619 if (! isset($document->data[$id]))
5620 $document->data[$id] = array();
5622 $document->data[$id][$name] = $data;
5624 if (isset($document->data[$id][$name]))
5625 return $document->data[$id][$name];
5631 // TODO check if this works
5635 $id = $node->dataID;
5637 if (isset($document->data[$id][$name]))
5638 unset($document->data[$id][$name]);
5640 foreach($document->data[$id] as $name)