@@ -311,10 +311,11 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | public static function getDocument($id = null) |
| 313 | 313 | { |
| 314 | - if ($id) |
|
| 315 | - PhpQuery::selectDocument($id); |
|
| 316 | - else |
|
| 317 | - $id = PhpQuery::$defaultDocumentID; |
|
| 314 | + if ($id) { |
|
| 315 | + PhpQuery::selectDocument($id); |
|
| 316 | + } else { |
|
| 317 | + $id = PhpQuery::$defaultDocumentID; |
|
| 318 | + } |
|
| 318 | 319 | return new PhpQueryObject($id); |
| 319 | 320 | } |
| 320 | 321 | |
@@ -328,8 +329,9 @@ discard block |
||
| 328 | 329 | */ |
| 329 | 330 | public static function newDocument($markup = null, $contentType = null) |
| 330 | 331 | { |
| 331 | - if (!$markup) |
|
| 332 | - $markup = ''; |
|
| 332 | + if (!$markup) { |
|
| 333 | + $markup = ''; |
|
| 334 | + } |
|
| 333 | 335 | $documentID = PhpQuery::createDocumentWrapper($markup, $contentType); |
| 334 | 336 | return new PhpQueryObject($documentID); |
| 335 | 337 | } |
@@ -399,8 +401,8 @@ discard block |
||
| 399 | 401 | '@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(")([^"]*)<' |
| 400 | 402 | . '?php?(.*?)(?:\\?>)([^"]*)"@s', |
| 401 | 403 | ); |
| 402 | - foreach ($regexes as $regex) |
|
| 403 | - while (preg_match($regex, $php, $matches)) { |
|
| 404 | + foreach ($regexes as $regex) { |
|
| 405 | + while (preg_match($regex, $php, $matches)) { |
|
| 404 | 406 | $php = preg_replace_callback( |
| 405 | 407 | $regex, |
| 406 | 408 | // create_function('$m, $charset = "'.$charset.'"', |
@@ -414,6 +416,7 @@ discard block |
||
| 414 | 416 | ), |
| 415 | 417 | $php |
| 416 | 418 | ); |
| 419 | + } |
|
| 417 | 420 | } |
| 418 | 421 | $regex = '@(^|>[^<]*)+?(<\?php(.*?)(\?>))@s'; |
| 419 | 422 | //preg_match_all($regex, $php, $matches); |
@@ -447,8 +450,9 @@ discard block |
||
| 447 | 450 | */ |
| 448 | 451 | public static function markupToPHP($content) |
| 449 | 452 | { |
| 450 | - if ($content instanceof PhpQueryObject) |
|
| 451 | - $content = $content->markupOuter(); |
|
| 453 | + if ($content instanceof PhpQueryObject) { |
|
| 454 | + $content = $content->markupOuter(); |
|
| 455 | + } |
|
| 452 | 456 | /* <php>...</php> to <?php...? > */ |
| 453 | 457 | $content = preg_replace_callback( |
| 454 | 458 | '@<php>\s*<!--(.*?)-->\s*</php>@s', |
@@ -466,8 +470,8 @@ discard block |
||
| 466 | 470 | '@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(\')([^\']*)(?:<|%3C)\\?(?:php)?(.*?)(?:\\?(?:>|%3E))([^\']*)\'@s', |
| 467 | 471 | '@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(")([^"]*)(?:<|%3C)\\?(?:php)?(.*?)(?:\\?(?:>|%3E))([^"]*)"@s', |
| 468 | 472 | ); |
| 469 | - foreach ($regexes as $regex) |
|
| 470 | - while (preg_match($regex, $content)) |
|
| 473 | + foreach ($regexes as $regex) { |
|
| 474 | + while (preg_match($regex, $content)) |
|
| 471 | 475 | $content = preg_replace_callback( |
| 472 | 476 | $regex, |
| 473 | 477 | create_function( |
@@ -482,6 +486,7 @@ discard block |
||
| 482 | 486 | ), |
| 483 | 487 | $content |
| 484 | 488 | ); |
| 489 | + } |
|
| 485 | 490 | return $content; |
| 486 | 491 | } |
| 487 | 492 | |
@@ -581,8 +586,9 @@ discard block |
||
| 581 | 586 | */ |
| 582 | 587 | protected static function createDocumentWrapper($html, $contentType = null, $documentID = null) |
| 583 | 588 | { |
| 584 | - if (function_exists('domxml_open_mem')) |
|
| 585 | - throw new \Exception("Old PHP4 DOM XML extension detected. PhpQuery won't work until this extension is enabled."); |
|
| 589 | + if (function_exists('domxml_open_mem')) { |
|
| 590 | + throw new \Exception("Old PHP4 DOM XML extension detected. PhpQuery won't work until this extension is enabled."); |
|
| 591 | + } |
|
| 586 | 592 | // $id = $documentID |
| 587 | 593 | // ? $documentID |
| 588 | 594 | // : md5(microtime()); |
@@ -629,10 +635,11 @@ discard block |
||
| 629 | 635 | default: |
| 630 | 636 | throw new \Exception("Unsupported \$target type"); |
| 631 | 637 | } |
| 632 | - if (is_string($source)) |
|
| 633 | - $source = array( |
|
| 638 | + if (is_string($source)) { |
|
| 639 | + $source = array( |
|
| 634 | 640 | $source => $source |
| 635 | 641 | ); |
| 642 | + } |
|
| 636 | 643 | foreach ($source as $method => $callback) { |
| 637 | 644 | if (isset($targetRef[$method])) { |
| 638 | 645 | // throw new \Exception |
@@ -665,14 +672,17 @@ discard block |
||
| 665 | 672 | // TODO $class checked agains PhpQuery_$class |
| 666 | 673 | // if (strpos($class, 'PhpQuery') === 0) |
| 667 | 674 | // $class = substr($class, 8); |
| 668 | - if (in_array($class, self::$pluginsLoaded)) |
|
| 669 | - return true; |
|
| 670 | - if (!$file) |
|
| 671 | - $file = $class . '.php'; |
|
| 675 | + if (in_array($class, self::$pluginsLoaded)) { |
|
| 676 | + return true; |
|
| 677 | + } |
|
| 678 | + if (!$file) { |
|
| 679 | + $file = $class . '.php'; |
|
| 680 | + } |
|
| 672 | 681 | $objectClassExists = class_exists('\\PhpQuery\\Plugin\\' . $class); |
| 673 | 682 | $staticClassExists = class_exists('\PhpQuery\Plugin\Util' . $class); |
| 674 | - if (!$objectClassExists && !$staticClassExists) |
|
| 675 | - require_once($file); |
|
| 683 | + if (!$objectClassExists && !$staticClassExists) { |
|
| 684 | + require_once($file); |
|
| 685 | + } |
|
| 676 | 686 | self::$pluginsLoaded[] = $class; |
| 677 | 687 | // static methods |
| 678 | 688 | if (class_exists('\PhpQuery\Plugin\Util' . $class)) { |
@@ -682,30 +692,33 @@ discard block |
||
| 682 | 692 | && !is_null($vars['PhpQueryMethods']) ? $vars['PhpQueryMethods'] |
| 683 | 693 | : get_class_methods($realClass); |
| 684 | 694 | foreach ($loop as $method) { |
| 685 | - if ($method == '__initialize') |
|
| 686 | - continue; |
|
| 695 | + if ($method == '__initialize') { |
|
| 696 | + continue; |
|
| 697 | + } |
|
| 687 | 698 | if (!is_callable( |
| 688 | 699 | array( |
| 689 | 700 | $realClass, |
| 690 | 701 | $method |
| 691 | 702 | ) |
| 692 | 703 | ) |
| 693 | - ) |
|
| 694 | - continue; |
|
| 704 | + ) { |
|
| 705 | + continue; |
|
| 706 | + } |
|
| 695 | 707 | if (isset(self::$pluginsStaticMethods[$method])) { |
| 696 | 708 | throw new \Exception("Duplicate method '{$method}' from plugin '{$c}' conflicts with same method from plugin '" |
| 697 | 709 | . self::$pluginsStaticMethods[$method] . "'"); |
| 698 | 710 | } |
| 699 | 711 | self::$pluginsStaticMethods[$method] = $class; |
| 700 | 712 | } |
| 701 | - if (method_exists($realClass, '__initialize')) |
|
| 702 | - call_user_func_array( |
|
| 713 | + if (method_exists($realClass, '__initialize')) { |
|
| 714 | + call_user_func_array( |
|
| 703 | 715 | array( |
| 704 | 716 | $realClass, |
| 705 | 717 | '__initialize' |
| 706 | 718 | ), |
| 707 | 719 | array() |
| 708 | 720 | ); |
| 721 | + } |
|
| 709 | 722 | } |
| 710 | 723 | // object methods |
| 711 | 724 | if (class_exists('\\PhpQuery\\Plugin\\' . $class)) { |
@@ -721,8 +734,9 @@ discard block |
||
| 721 | 734 | $method |
| 722 | 735 | ) |
| 723 | 736 | ) |
| 724 | - ) |
|
| 725 | - continue; |
|
| 737 | + ) { |
|
| 738 | + continue; |
|
| 739 | + } |
|
| 726 | 740 | if (isset(self::$pluginsMethods[$method])) { |
| 727 | 741 | throw new \Exception("Duplicate method '{$method}' from plugin '{$class}' conflicts with same method from plugin '" |
| 728 | 742 | . self::$pluginsMethods[$method] . "'"); |
@@ -743,8 +757,9 @@ discard block |
||
| 743 | 757 | public static function unloadDocuments($id = null) |
| 744 | 758 | { |
| 745 | 759 | if (isset($id)) { |
| 746 | - if ($id = self::getDocumentID($id)) |
|
| 747 | - unset(PhpQuery::$documents[$id]); |
|
| 760 | + if ($id = self::getDocumentID($id)) { |
|
| 761 | + unset(PhpQuery::$documents[$id]); |
|
| 762 | + } |
|
| 748 | 763 | } else { |
| 749 | 764 | foreach (PhpQuery::$documents as $k => $v) { |
| 750 | 765 | unset(PhpQuery::$documents[$k]); |
@@ -767,10 +782,12 @@ discard block |
||
| 767 | 782 | public static function DOMNodeListToArray($DOMNodeList) |
| 768 | 783 | { |
| 769 | 784 | $array = array(); |
| 770 | - if (!$DOMNodeList) |
|
| 771 | - return $array; |
|
| 772 | - foreach ($DOMNodeList as $node) |
|
| 773 | - $array[] = $node; |
|
| 785 | + if (!$DOMNodeList) { |
|
| 786 | + return $array; |
|
| 787 | + } |
|
| 788 | + foreach ($DOMNodeList as $node) { |
|
| 789 | + $array[] = $node; |
|
| 790 | + } |
|
| 774 | 791 | return $array; |
| 775 | 792 | } |
| 776 | 793 | |
@@ -789,8 +806,9 @@ discard block |
||
| 789 | 806 | |
| 790 | 807 | public static function debug($text) |
| 791 | 808 | { |
| 792 | - if (self::$debug) |
|
| 793 | - print var_dump($text); |
|
| 809 | + if (self::$debug) { |
|
| 810 | + print var_dump($text); |
|
| 811 | + } |
|
| 794 | 812 | } |
| 795 | 813 | |
| 796 | 814 | /** |
@@ -832,16 +850,18 @@ discard block |
||
| 832 | 850 | $client = new \Zend_Http_Client(); |
| 833 | 851 | $client->setCookieJar(); |
| 834 | 852 | } |
| 835 | - if (isset($options['timeout'])) |
|
| 836 | - $client->setConfig( |
|
| 853 | + if (isset($options['timeout'])) { |
|
| 854 | + $client->setConfig( |
|
| 837 | 855 | array( |
| 838 | 856 | 'timeout' => $options['timeout'], |
| 839 | 857 | ) |
| 840 | 858 | ); |
| 859 | + } |
|
| 841 | 860 | // 'maxredirects' => 0, |
| 842 | - foreach (self::$ajaxAllowedHosts as $k => $host) |
|
| 843 | - if ($host == '.' && isset($_SERVER['HTTP_HOST'])) |
|
| 861 | + foreach (self::$ajaxAllowedHosts as $k => $host) { |
|
| 862 | + if ($host == '.' && isset($_SERVER['HTTP_HOST'])) |
|
| 844 | 863 | self::$ajaxAllowedHosts[$k] = $_SERVER['HTTP_HOST']; |
| 864 | + } |
|
| 845 | 865 | $host = parse_url($options['url'], PHP_URL_HOST); |
| 846 | 866 | if (!in_array($host, self::$ajaxAllowedHosts)) { |
| 847 | 867 | throw new \Exception("Request not permitted, host '$host' not present in " |
@@ -859,8 +879,9 @@ discard block |
||
| 859 | 879 | } else if ($options['data']) { |
| 860 | 880 | $jsonp = false; |
| 861 | 881 | foreach ($options['data'] as $n => $v) { |
| 862 | - if ($v == '?') |
|
| 863 | - $jsonp = true; |
|
| 882 | + if ($v == '?') { |
|
| 883 | + $jsonp = true; |
|
| 884 | + } |
|
| 864 | 885 | } |
| 865 | 886 | if (!$jsonp) { |
| 866 | 887 | $options['data'][$jsonpCallbackParam] = '?'; |
@@ -873,25 +894,30 @@ discard block |
||
| 873 | 894 | $jsonpData = $jsonpUrl = false; |
| 874 | 895 | if ($options['data']) { |
| 875 | 896 | foreach ($options['data'] as $n => $v) { |
| 876 | - if ($v == '?') |
|
| 877 | - $jsonpData = $n; |
|
| 897 | + if ($v == '?') { |
|
| 898 | + $jsonpData = $n; |
|
| 899 | + } |
|
| 878 | 900 | } |
| 879 | 901 | } |
| 880 | - if (preg_match($jsre, $options['url'])) |
|
| 881 | - $jsonpUrl = true; |
|
| 902 | + if (preg_match($jsre, $options['url'])) { |
|
| 903 | + $jsonpUrl = true; |
|
| 904 | + } |
|
| 882 | 905 | if ($jsonpData !== false || $jsonpUrl) { |
| 883 | 906 | // remember callback name for httpData() |
| 884 | 907 | $options['_jsonp'] = $jsonpCallback; |
| 885 | - if ($jsonpData !== false) |
|
| 886 | - $options['data'][$jsonpData] = $jsonpCallback; |
|
| 887 | - if ($jsonpUrl) |
|
| 888 | - $options['url'] = preg_replace($jsre, "=$jsonpCallback\\1", $options['url']); |
|
| 908 | + if ($jsonpData !== false) { |
|
| 909 | + $options['data'][$jsonpData] = $jsonpCallback; |
|
| 910 | + } |
|
| 911 | + if ($jsonpUrl) { |
|
| 912 | + $options['url'] = preg_replace($jsre, "=$jsonpCallback\\1", $options['url']); |
|
| 913 | + } |
|
| 889 | 914 | } |
| 890 | 915 | } |
| 891 | 916 | $client->setUri($options['url']); |
| 892 | 917 | $client->setMethod(strtoupper($options['type'])); |
| 893 | - if (isset($options['referer']) && $options['referer']) |
|
| 894 | - $client->setHeaders('Referer', $options['referer']); |
|
| 918 | + if (isset($options['referer']) && $options['referer']) { |
|
| 919 | + $client->setHeaders('Referer', $options['referer']); |
|
| 920 | + } |
|
| 895 | 921 | $client->setHeaders( |
| 896 | 922 | array( |
| 897 | 923 | // 'content-type' => $options['contentType'], |
@@ -904,14 +930,16 @@ discard block |
||
| 904 | 930 | 'Accept-Language' => 'en-us,en;q=0.5', |
| 905 | 931 | ) |
| 906 | 932 | ); |
| 907 | - if ($options['username']) |
|
| 908 | - $client->setAuth($options['username'], $options['password']); |
|
| 909 | - if (isset($options['ifModified']) && $options['ifModified']) |
|
| 910 | - $client->setHeaders( |
|
| 933 | + if ($options['username']) { |
|
| 934 | + $client->setAuth($options['username'], $options['password']); |
|
| 935 | + } |
|
| 936 | + if (isset($options['ifModified']) && $options['ifModified']) { |
|
| 937 | + $client->setHeaders( |
|
| 911 | 938 | "If-Modified-Since", |
| 912 | 939 | self::$lastModified ? self::$lastModified |
| 913 | 940 | : "Thu, 01 Jan 1970 00:00:00 GMT" |
| 914 | 941 | ); |
| 942 | + } |
|
| 915 | 943 | $client->setHeaders( |
| 916 | 944 | "Accept", |
| 917 | 945 | isset($options['dataType']) |
@@ -922,8 +950,9 @@ discard block |
||
| 922 | 950 | if ($options['data'] instanceof PhpQueryObject) { |
| 923 | 951 | $serialized = $options['data']->serializeArray($options['data']); |
| 924 | 952 | $options['data'] = array(); |
| 925 | - foreach ($serialized as $r) |
|
| 926 | - $options['data'][$r['name']] = $r['value']; |
|
| 953 | + foreach ($serialized as $r) { |
|
| 954 | + $options['data'][$r['name']] = $r['value']; |
|
| 955 | + } |
|
| 927 | 956 | } |
| 928 | 957 | if (strtolower($options['type']) == 'get') { |
| 929 | 958 | $client->setParameterGet($options['data']); |
@@ -931,20 +960,22 @@ discard block |
||
| 931 | 960 | $client->setEncType($options['contentType']); |
| 932 | 961 | $client->setParameterPost($options['data']); |
| 933 | 962 | } |
| 934 | - if (self::$active == 0 && $options['global']) |
|
| 935 | - PhpQueryEvents::trigger($documentID, 'ajaxStart'); |
|
| 963 | + if (self::$active == 0 && $options['global']) { |
|
| 964 | + PhpQueryEvents::trigger($documentID, 'ajaxStart'); |
|
| 965 | + } |
|
| 936 | 966 | self::$active++; |
| 937 | 967 | // beforeSend callback |
| 938 | - if (isset($options['beforeSend']) && $options['beforeSend']) |
|
| 939 | - PhpQuery::callbackRun( |
|
| 968 | + if (isset($options['beforeSend']) && $options['beforeSend']) { |
|
| 969 | + PhpQuery::callbackRun( |
|
| 940 | 970 | $options['beforeSend'], |
| 941 | 971 | array( |
| 942 | 972 | $client |
| 943 | 973 | ) |
| 944 | 974 | ); |
| 975 | + } |
|
| 945 | 976 | // ajaxSend event |
| 946 | - if ($options['global']) |
|
| 947 | - PhpQueryEvents::trigger( |
|
| 977 | + if ($options['global']) { |
|
| 978 | + PhpQueryEvents::trigger( |
|
| 948 | 979 | $documentID, |
| 949 | 980 | 'ajaxSend', |
| 950 | 981 | array( |
@@ -952,6 +983,7 @@ discard block |
||
| 952 | 983 | $options |
| 953 | 984 | ) |
| 954 | 985 | ); |
| 986 | + } |
|
| 955 | 987 | if (PhpQuery::$debug) { |
| 956 | 988 | self::debug("{$options['type']}: {$options['url']}\n"); |
| 957 | 989 | self::debug("Options: <pre>" . var_export($options, true) . "</pre>\n"); |
@@ -972,8 +1004,8 @@ discard block |
||
| 972 | 1004 | // XXX tempolary |
| 973 | 1005 | self::$lastModified = $response->getHeader('Last-Modified'); |
| 974 | 1006 | $data = self::httpData($response->getBody(), $options['dataType'], $options); |
| 975 | - if (isset($options['success']) && $options['success']) |
|
| 976 | - PhpQuery::callbackRun( |
|
| 1007 | + if (isset($options['success']) && $options['success']) { |
|
| 1008 | + PhpQuery::callbackRun( |
|
| 977 | 1009 | $options['success'], |
| 978 | 1010 | array( |
| 979 | 1011 | $data, |
@@ -981,8 +1013,9 @@ discard block |
||
| 981 | 1013 | $options |
| 982 | 1014 | ) |
| 983 | 1015 | ); |
| 984 | - if ($options['global']) |
|
| 985 | - PhpQueryEvents::trigger( |
|
| 1016 | + } |
|
| 1017 | + if ($options['global']) { |
|
| 1018 | + PhpQueryEvents::trigger( |
|
| 986 | 1019 | $documentID, |
| 987 | 1020 | 'ajaxSuccess', |
| 988 | 1021 | array( |
@@ -990,9 +1023,10 @@ discard block |
||
| 990 | 1023 | $options |
| 991 | 1024 | ) |
| 992 | 1025 | ); |
| 1026 | + } |
|
| 993 | 1027 | } else { |
| 994 | - if (isset($options['error']) && $options['error']) |
|
| 995 | - PhpQuery::callbackRun( |
|
| 1028 | + if (isset($options['error']) && $options['error']) { |
|
| 1029 | + PhpQuery::callbackRun( |
|
| 996 | 1030 | $options['error'], |
| 997 | 1031 | array( |
| 998 | 1032 | $client, |
@@ -1000,8 +1034,9 @@ discard block |
||
| 1000 | 1034 | $response->getMessage() |
| 1001 | 1035 | ) |
| 1002 | 1036 | ); |
| 1003 | - if ($options['global']) |
|
| 1004 | - PhpQueryEvents::trigger( |
|
| 1037 | + } |
|
| 1038 | + if ($options['global']) { |
|
| 1039 | + PhpQueryEvents::trigger( |
|
| 1005 | 1040 | $documentID, |
| 1006 | 1041 | 'ajaxError', |
| 1007 | 1042 | array( |
@@ -1011,17 +1046,19 @@ discard block |
||
| 1011 | 1046 | $options |
| 1012 | 1047 | ) |
| 1013 | 1048 | ); |
| 1049 | + } |
|
| 1014 | 1050 | } |
| 1015 | - if (isset($options['complete']) && $options['complete']) |
|
| 1016 | - PhpQuery::callbackRun( |
|
| 1051 | + if (isset($options['complete']) && $options['complete']) { |
|
| 1052 | + PhpQuery::callbackRun( |
|
| 1017 | 1053 | $options['complete'], |
| 1018 | 1054 | array( |
| 1019 | 1055 | $client, |
| 1020 | 1056 | $response->getStatus() |
| 1021 | 1057 | ) |
| 1022 | 1058 | ); |
| 1023 | - if ($options['global']) |
|
| 1024 | - PhpQueryEvents::trigger( |
|
| 1059 | + } |
|
| 1060 | + if ($options['global']) { |
|
| 1061 | + PhpQueryEvents::trigger( |
|
| 1025 | 1062 | $documentID, |
| 1026 | 1063 | 'ajaxComplete', |
| 1027 | 1064 | array( |
@@ -1029,8 +1066,10 @@ discard block |
||
| 1029 | 1066 | $options |
| 1030 | 1067 | ) |
| 1031 | 1068 | ); |
| 1032 | - if ($options['global'] && !--self::$active) |
|
| 1033 | - PhpQueryEvents::trigger($documentID, 'ajaxStop'); |
|
| 1069 | + } |
|
| 1070 | + if ($options['global'] && !--self::$active) { |
|
| 1071 | + PhpQueryEvents::trigger($documentID, 'ajaxStop'); |
|
| 1072 | + } |
|
| 1034 | 1073 | return $client; |
| 1035 | 1074 | // if (is_null($domId)) |
| 1036 | 1075 | // $domId = self::$defaultDocumentID ? self::$defaultDocumentID : false; |
@@ -1039,14 +1078,15 @@ discard block |
||
| 1039 | 1078 | |
| 1040 | 1079 | protected static function httpData($data, $type, $options) |
| 1041 | 1080 | { |
| 1042 | - if (isset($options['dataFilter']) && $options['dataFilter']) |
|
| 1043 | - $data = self::callbackRun( |
|
| 1081 | + if (isset($options['dataFilter']) && $options['dataFilter']) { |
|
| 1082 | + $data = self::callbackRun( |
|
| 1044 | 1083 | $options['dataFilter'], |
| 1045 | 1084 | array( |
| 1046 | 1085 | $data, |
| 1047 | 1086 | $type |
| 1048 | 1087 | ) |
| 1049 | 1088 | ); |
| 1089 | + } |
|
| 1050 | 1090 | if (is_string($data)) { |
| 1051 | 1091 | if ($type == "json") { |
| 1052 | 1092 | if (isset($options['_jsonp']) && $options['_jsonp']) { |
@@ -1141,8 +1181,9 @@ discard block |
||
| 1141 | 1181 | public static function ajaxAllowURL($url1, $url2 = null, $url3 = null) |
| 1142 | 1182 | { |
| 1143 | 1183 | $loop = is_array($url1) ? $url1 : func_get_args(); |
| 1144 | - foreach ($loop as $url) |
|
| 1145 | - PhpQuery::ajaxAllowHost(parse_url($url, PHP_URL_HOST)); |
|
| 1184 | + foreach ($loop as $url) { |
|
| 1185 | + PhpQuery::ajaxAllowHost(parse_url($url, PHP_URL_HOST)); |
|
| 1186 | + } |
|
| 1146 | 1187 | } |
| 1147 | 1188 | |
| 1148 | 1189 | /** |
@@ -1154,8 +1195,9 @@ discard block |
||
| 1154 | 1195 | */ |
| 1155 | 1196 | public static function toJSON($data) |
| 1156 | 1197 | { |
| 1157 | - if (function_exists('json_encode')) |
|
| 1158 | - return json_encode($data); |
|
| 1198 | + if (function_exists('json_encode')) { |
|
| 1199 | + return json_encode($data); |
|
| 1200 | + } |
|
| 1159 | 1201 | require_once('Zend/Json/Encoder.php'); |
| 1160 | 1202 | return \Zend_Json_Encoder::encode($data); |
| 1161 | 1203 | } |
@@ -1172,8 +1214,9 @@ discard block |
||
| 1172 | 1214 | if (function_exists('json_decode')) { |
| 1173 | 1215 | $return = json_decode(trim($json), true); |
| 1174 | 1216 | // json_decode and UTF8 issues |
| 1175 | - if (isset($return)) |
|
| 1176 | - return $return; |
|
| 1217 | + if (isset($return)) { |
|
| 1218 | + return $return; |
|
| 1219 | + } |
|
| 1177 | 1220 | } |
| 1178 | 1221 | require_once('Zend/Json/Decoder.php'); |
| 1179 | 1222 | return \Zend_Json_Decoder::decode($json); |
@@ -1189,18 +1232,21 @@ discard block |
||
| 1189 | 1232 | { |
| 1190 | 1233 | if ($source instanceof \DOMDocument) { |
| 1191 | 1234 | foreach (PhpQuery::$documents as $id => $document) { |
| 1192 | - if ($source->isSameNode($document->document)) |
|
| 1193 | - return $id; |
|
| 1235 | + if ($source->isSameNode($document->document)) { |
|
| 1236 | + return $id; |
|
| 1237 | + } |
|
| 1194 | 1238 | } |
| 1195 | 1239 | } else if ($source instanceof \DOMNode) { |
| 1196 | 1240 | foreach (PhpQuery::$documents as $id => $document) { |
| 1197 | - if ($source->ownerDocument->isSameNode($document->document)) |
|
| 1198 | - return $id; |
|
| 1241 | + if ($source->ownerDocument->isSameNode($document->document)) { |
|
| 1242 | + return $id; |
|
| 1243 | + } |
|
| 1199 | 1244 | } |
| 1200 | - } else if ($source instanceof PhpQueryObject) |
|
| 1201 | - return $source->getDocumentID(); |
|
| 1202 | - else if (is_string($source) && isset(PhpQuery::$documents[$source])) |
|
| 1203 | - return $source; |
|
| 1245 | + } else if ($source instanceof PhpQueryObject) { |
|
| 1246 | + return $source->getDocumentID(); |
|
| 1247 | + } else if (is_string($source) && isset(PhpQuery::$documents[$source])) { |
|
| 1248 | + return $source; |
|
| 1249 | + } |
|
| 1204 | 1250 | } |
| 1205 | 1251 | |
| 1206 | 1252 | /** |
@@ -1212,8 +1258,9 @@ discard block |
||
| 1212 | 1258 | */ |
| 1213 | 1259 | public static function getDOMDocument($source) |
| 1214 | 1260 | { |
| 1215 | - if ($source instanceof \DOMDocument) |
|
| 1216 | - return $source; |
|
| 1261 | + if ($source instanceof \DOMDocument) { |
|
| 1262 | + return $source; |
|
| 1263 | + } |
|
| 1217 | 1264 | $source = self::getDocumentID($source); |
| 1218 | 1265 | return $source ? self::$documents[$id]['document'] : null; |
| 1219 | 1266 | } |
@@ -1231,14 +1278,17 @@ discard block |
||
| 1231 | 1278 | { |
| 1232 | 1279 | $array = array(); |
| 1233 | 1280 | if (is_object($object) && $object instanceof \DOMNodeList) { |
| 1234 | - foreach ($object as $value) |
|
| 1235 | - $array[] = $value; |
|
| 1281 | + foreach ($object as $value) { |
|
| 1282 | + $array[] = $value; |
|
| 1283 | + } |
|
| 1236 | 1284 | } else if (is_object($object) && !($object instanceof \Iterator)) { |
| 1237 | - foreach (get_object_vars($object) as $name => $value) |
|
| 1238 | - $array[0][$name] = $value; |
|
| 1285 | + foreach (get_object_vars($object) as $name => $value) { |
|
| 1286 | + $array[0][$name] = $value; |
|
| 1287 | + } |
|
| 1239 | 1288 | } else { |
| 1240 | - foreach ($object as $name => $value) |
|
| 1241 | - $array[0][$name] = $value; |
|
| 1289 | + foreach ($object as $name => $value) { |
|
| 1290 | + $array[0][$name] = $value; |
|
| 1291 | + } |
|
| 1242 | 1292 | } |
| 1243 | 1293 | return $array; |
| 1244 | 1294 | } |
@@ -1265,8 +1315,8 @@ discard block |
||
| 1265 | 1315 | $paramStructure = array_slice($paramStructure, 2); |
| 1266 | 1316 | } |
| 1267 | 1317 | if (is_object($object) && !($object instanceof \Iterator)) { |
| 1268 | - foreach (get_object_vars($object) as $name => $value) |
|
| 1269 | - PhpQuery::callbackRun( |
|
| 1318 | + foreach (get_object_vars($object) as $name => $value) { |
|
| 1319 | + PhpQuery::callbackRun( |
|
| 1270 | 1320 | $callback, |
| 1271 | 1321 | array( |
| 1272 | 1322 | $name, |
@@ -1274,9 +1324,10 @@ discard block |
||
| 1274 | 1324 | ), |
| 1275 | 1325 | $paramStructure |
| 1276 | 1326 | ); |
| 1327 | + } |
|
| 1277 | 1328 | } else { |
| 1278 | - foreach ($object as $name => $value) |
|
| 1279 | - PhpQuery::callbackRun( |
|
| 1329 | + foreach ($object as $name => $value) { |
|
| 1330 | + PhpQuery::callbackRun( |
|
| 1280 | 1331 | $callback, |
| 1281 | 1332 | array( |
| 1282 | 1333 | $name, |
@@ -1284,6 +1335,7 @@ discard block |
||
| 1284 | 1335 | ), |
| 1285 | 1336 | $paramStructure |
| 1286 | 1337 | ); |
| 1338 | + } |
|
| 1287 | 1339 | } |
| 1288 | 1340 | } |
| 1289 | 1341 | |
@@ -1315,8 +1367,9 @@ discard block |
||
| 1315 | 1367 | // } |
| 1316 | 1368 | // $vv = call_user_func_array($callback, $callbackArgs); |
| 1317 | 1369 | if (is_array($vv)) { |
| 1318 | - foreach ($vv as $vvv) |
|
| 1319 | - $result[] = $vvv; |
|
| 1370 | + foreach ($vv as $vvv) { |
|
| 1371 | + $result[] = $vvv; |
|
| 1372 | + } |
|
| 1320 | 1373 | } else if ($vv !== null) { |
| 1321 | 1374 | $result[] = $vv; |
| 1322 | 1375 | } |
@@ -1333,20 +1386,23 @@ discard block |
||
| 1333 | 1386 | */ |
| 1334 | 1387 | public static function callbackRun($callback, $params = array(), $paramStructure = null) |
| 1335 | 1388 | { |
| 1336 | - if (!$callback) |
|
| 1337 | - return; |
|
| 1389 | + if (!$callback) { |
|
| 1390 | + return; |
|
| 1391 | + } |
|
| 1338 | 1392 | if ($callback instanceof \CallbackParameterToReference) { |
| 1339 | 1393 | // TODO support ParamStructure to select which $param push to reference |
| 1340 | - if (isset($params[0])) |
|
| 1341 | - $callback->callback = $params[0]; |
|
| 1394 | + if (isset($params[0])) { |
|
| 1395 | + $callback->callback = $params[0]; |
|
| 1396 | + } |
|
| 1342 | 1397 | return true; |
| 1343 | 1398 | } |
| 1344 | 1399 | if ($callback instanceof \Callback) { |
| 1345 | 1400 | $paramStructure = $callback->params; |
| 1346 | 1401 | $callback = $callback->callback; |
| 1347 | 1402 | } |
| 1348 | - if (!$paramStructure) |
|
| 1349 | - return call_user_func_array($callback, $params); |
|
| 1403 | + if (!$paramStructure) { |
|
| 1404 | + return call_user_func_array($callback, $params); |
|
| 1405 | + } |
|
| 1350 | 1406 | $p = 0; |
| 1351 | 1407 | foreach ($paramStructure as $i => $v) { |
| 1352 | 1408 | $paramStructure[$i] = $v instanceof \CallbackParam ? $params[$p++] : $v; |
@@ -1368,11 +1424,13 @@ discard block |
||
| 1368 | 1424 | foreach ($two->elements as $node) { |
| 1369 | 1425 | $exists = false; |
| 1370 | 1426 | foreach ($elements as $node2) { |
| 1371 | - if ($node2->isSameNode($node)) |
|
| 1372 | - $exists = true; |
|
| 1427 | + if ($node2->isSameNode($node)) { |
|
| 1428 | + $exists = true; |
|
| 1429 | + } |
|
| 1430 | + } |
|
| 1431 | + if (!$exists) { |
|
| 1432 | + $elements[] = $node; |
|
| 1373 | 1433 | } |
| 1374 | - if (!$exists) |
|
| 1375 | - $elements[] = $node; |
|
| 1376 | 1434 | } |
| 1377 | 1435 | return $elements; |
| 1378 | 1436 | // $one = $one->newInstance(); |
@@ -1399,8 +1457,9 @@ discard block |
||
| 1399 | 1457 | $k |
| 1400 | 1458 | ) |
| 1401 | 1459 | ); |
| 1402 | - if ($r === !(bool) $invert) |
|
| 1403 | - $result[] = $v; |
|
| 1460 | + if ($r === !(bool) $invert) { |
|
| 1461 | + $result[] = $v; |
|
| 1462 | + } |
|
| 1404 | 1463 | } |
| 1405 | 1464 | return $result; |
| 1406 | 1465 | } |
@@ -1539,8 +1598,9 @@ discard block |
||
| 1539 | 1598 | { |
| 1540 | 1599 | // search are return if alredy exists |
| 1541 | 1600 | foreach (PhpQuery::$documents[$documentID]->dataNodes as $dataNode) { |
| 1542 | - if ($node->isSameNode($dataNode)) |
|
| 1543 | - return $dataNode; |
|
| 1601 | + if ($node->isSameNode($dataNode)) { |
|
| 1602 | + return $dataNode; |
|
| 1603 | + } |
|
| 1544 | 1604 | } |
| 1545 | 1605 | // if doesn't, add it |
| 1546 | 1606 | PhpQuery::$documents[$documentID]->dataNodes[] = $node; |
@@ -1560,41 +1620,51 @@ discard block |
||
| 1560 | 1620 | |
| 1561 | 1621 | public static function data($node, $name, $data, $documentID = null) |
| 1562 | 1622 | { |
| 1563 | - if (!$documentID) |
|
| 1564 | - // TODO check if this works |
|
| 1623 | + if (!$documentID) { |
|
| 1624 | + // TODO check if this works |
|
| 1565 | 1625 | $documentID = self::getDocumentID($node); |
| 1626 | + } |
|
| 1566 | 1627 | $document = PhpQuery::$documents[$documentID]; |
| 1567 | 1628 | $node = self::dataSetupNode($node, $documentID); |
| 1568 | - if (!isset($node->dataID)) |
|
| 1569 | - $node->dataID = ++PhpQuery::$documents[$documentID]->uuid; |
|
| 1629 | + if (!isset($node->dataID)) { |
|
| 1630 | + $node->dataID = ++PhpQuery::$documents[$documentID]->uuid; |
|
| 1631 | + } |
|
| 1570 | 1632 | $id = $node->dataID; |
| 1571 | - if (!isset($document->data[$id])) |
|
| 1572 | - $document->data[$id] = array(); |
|
| 1573 | - if (!is_null($data)) |
|
| 1574 | - $document->data[$id][$name] = $data; |
|
| 1633 | + if (!isset($document->data[$id])) { |
|
| 1634 | + $document->data[$id] = array(); |
|
| 1635 | + } |
|
| 1636 | + if (!is_null($data)) { |
|
| 1637 | + $document->data[$id][$name] = $data; |
|
| 1638 | + } |
|
| 1575 | 1639 | if ($name) { |
| 1576 | - if (isset($document->data[$id][$name])) |
|
| 1577 | - return $document->data[$id][$name]; |
|
| 1578 | - } else |
|
| 1579 | - return $id; |
|
| 1640 | + if (isset($document->data[$id][$name])) { |
|
| 1641 | + return $document->data[$id][$name]; |
|
| 1642 | + } |
|
| 1643 | + } else { |
|
| 1644 | + return $id; |
|
| 1645 | + } |
|
| 1580 | 1646 | } |
| 1581 | 1647 | |
| 1582 | 1648 | public static function removeData($node, $name, $documentID) |
| 1583 | 1649 | { |
| 1584 | - if (!$documentID) |
|
| 1585 | - // TODO check if this works |
|
| 1650 | + if (!$documentID) { |
|
| 1651 | + // TODO check if this works |
|
| 1586 | 1652 | $documentID = self::getDocumentID($node); |
| 1653 | + } |
|
| 1587 | 1654 | $document = PhpQuery::$documents[$documentID]; |
| 1588 | 1655 | $node = self::dataSetupNode($node, $documentID); |
| 1589 | 1656 | $id = $node->dataID; |
| 1590 | 1657 | if ($name) { |
| 1591 | - if (isset($document->data[$id][$name])) |
|
| 1592 | - unset($document->data[$id][$name]); |
|
| 1658 | + if (isset($document->data[$id][$name])) { |
|
| 1659 | + unset($document->data[$id][$name]); |
|
| 1660 | + } |
|
| 1593 | 1661 | $name = null; |
| 1594 | - foreach ($document->data[$id] as $name) |
|
| 1595 | - break; |
|
| 1596 | - if (!$name) |
|
| 1597 | - self::removeData($node, $name, $documentID); |
|
| 1662 | + foreach ($document->data[$id] as $name) { |
|
| 1663 | + break; |
|
| 1664 | + } |
|
| 1665 | + if (!$name) { |
|
| 1666 | + self::removeData($node, $name, $documentID); |
|
| 1667 | + } |
|
| 1598 | 1668 | } else { |
| 1599 | 1669 | self::dataRemoveNode($node, $documentID); |
| 1600 | 1670 | } |
@@ -1625,8 +1695,9 @@ discard block |
||
| 1625 | 1695 | $args |
| 1626 | 1696 | ); |
| 1627 | 1697 | return isset($return) ? $return : $this; |
| 1628 | - } else |
|
| 1629 | - throw new \Exception("Method '{$method}' doesnt exist"); |
|
| 1698 | + } else { |
|
| 1699 | + throw new \Exception("Method '{$method}' doesnt exist"); |
|
| 1700 | + } |
|
| 1630 | 1701 | } |
| 1631 | 1702 | } |
| 1632 | 1703 | |
@@ -562,10 +562,12 @@ discard block |
||
| 562 | 562 | } |
| 563 | 563 | foreach ($queries as $k => $q) { |
| 564 | 564 | if (isset($q[0])) { |
| 565 | - if (isset($q[0][0]) && $q[0][0] == ':') |
|
| 566 | - array_unshift($queries[$k], '*'); |
|
| 567 | - if ($q[0] != '>') |
|
| 568 | - array_unshift($queries[$k], ' '); |
|
| 565 | + if (isset($q[0][0]) && $q[0][0] == ':') { |
|
| 566 | + array_unshift($queries[$k], '*'); |
|
| 567 | + } |
|
| 568 | + if ($q[0] != '>') { |
|
| 569 | + array_unshift($queries[$k], ' '); |
|
| 570 | + } |
|
| 569 | 571 | } |
| 570 | 572 | } |
| 571 | 573 | return $queries; |
@@ -585,21 +587,22 @@ discard block |
||
| 585 | 587 | $args = func_get_args(); |
| 586 | 588 | $args = array_slice($args, 1); |
| 587 | 589 | foreach ($args as $callback) { |
| 588 | - if (is_array($return)) |
|
| 589 | - foreach ($return as $k => $v) |
|
| 590 | + if (is_array($return)) { |
|
| 591 | + foreach ($return as $k => $v) |
|
| 590 | 592 | $return[$k] = PhpQuery::callbackRun( |
| 591 | 593 | $callback, |
| 592 | 594 | array( |
| 593 | 595 | $v |
| 594 | 596 | ) |
| 595 | 597 | ); |
| 596 | - else |
|
| 597 | - $return = PhpQuery::callbackRun( |
|
| 598 | + } else { |
|
| 599 | + $return = PhpQuery::callbackRun( |
|
| 598 | 600 | $callback, |
| 599 | 601 | array( |
| 600 | 602 | $return |
| 601 | 603 | ) |
| 602 | 604 | ); |
| 605 | + } |
|
| 603 | 606 | } |
| 604 | 607 | return $return; |
| 605 | 608 | } |
@@ -619,9 +622,9 @@ discard block |
||
| 619 | 622 | */ |
| 620 | 623 | public function getString($index = null, $callback1 = null, $callback2 = null, $callback3 = null) |
| 621 | 624 | { |
| 622 | - if ($index) |
|
| 623 | - $return = $this->eq($index)->text(); |
|
| 624 | - else { |
|
| 625 | + if ($index) { |
|
| 626 | + $return = $this->eq($index)->text(); |
|
| 627 | + } else { |
|
| 625 | 628 | $return = array(); |
| 626 | 629 | for ($i = 0; $i < $this->size(); $i++) { |
| 627 | 630 | $return[] = $this->eq($i)->text(); |
@@ -656,9 +659,9 @@ discard block |
||
| 656 | 659 | */ |
| 657 | 660 | public function getStrings($index = null, $callback1 = null, $callback2 = null, $callback3 = null) |
| 658 | 661 | { |
| 659 | - if ($index) |
|
| 660 | - $return = $this->eq($index)->text(); |
|
| 661 | - else { |
|
| 662 | + if ($index) { |
|
| 663 | + $return = $this->eq($index)->text(); |
|
| 664 | + } else { |
|
| 662 | 665 | $return = array(); |
| 663 | 666 | for ($i = 0; $i < $this->size(); $i++) { |
| 664 | 667 | $return[] = $this->eq($i)->text(); |
@@ -668,21 +671,22 @@ discard block |
||
| 668 | 671 | $args = array_slice($args, 1); |
| 669 | 672 | } |
| 670 | 673 | foreach ($args as $callback) { |
| 671 | - if (is_array($return)) |
|
| 672 | - foreach ($return as $k => $v) |
|
| 674 | + if (is_array($return)) { |
|
| 675 | + foreach ($return as $k => $v) |
|
| 673 | 676 | $return[$k] = PhpQuery::callbackRun( |
| 674 | 677 | $callback, |
| 675 | 678 | array( |
| 676 | 679 | $v |
| 677 | 680 | ) |
| 678 | 681 | ); |
| 679 | - else |
|
| 680 | - $return = PhpQuery::callbackRun( |
|
| 682 | + } else { |
|
| 683 | + $return = PhpQuery::callbackRun( |
|
| 681 | 684 | $callback, |
| 682 | 685 | array( |
| 683 | 686 | $return |
| 684 | 687 | ) |
| 685 | 688 | ); |
| 689 | + } |
|
| 686 | 690 | } |
| 687 | 691 | return $return; |
| 688 | 692 | } |
@@ -702,8 +706,9 @@ discard block |
||
| 702 | 706 | $new->previous = $this; |
| 703 | 707 | if (is_null($newStack)) { |
| 704 | 708 | $new->elements = $this->elements; |
| 705 | - if ($this->elementsBackup) |
|
| 706 | - $this->elements = $this->elementsBackup; |
|
| 709 | + if ($this->elementsBackup) { |
|
| 710 | + $this->elements = $this->elementsBackup; |
|
| 711 | + } |
|
| 707 | 712 | } else if (is_string($newStack)) { |
| 708 | 713 | $new->elements = PhpQuery::pq($newStack, $this->getDocumentID())->stack(); |
| 709 | 714 | } else { |
@@ -730,11 +735,13 @@ discard block |
||
| 730 | 735 | $classesCount = count($classes); |
| 731 | 736 | $nodeClasses = explode(' ', $node->getAttribute('class')); |
| 732 | 737 | $nodeClassesCount = count($nodeClasses); |
| 733 | - if ($classesCount > $nodeClassesCount) |
|
| 734 | - return false; |
|
| 738 | + if ($classesCount > $nodeClassesCount) { |
|
| 739 | + return false; |
|
| 740 | + } |
|
| 735 | 741 | $diff = count(array_diff($classes, $nodeClasses)); |
| 736 | - if (!$diff) |
|
| 737 | - return true; |
|
| 742 | + if (!$diff) { |
|
| 743 | + return true; |
|
| 744 | + } |
|
| 738 | 745 | // single-class |
| 739 | 746 | } else { |
| 740 | 747 | return in_array( |
@@ -751,11 +758,13 @@ discard block |
||
| 751 | 758 | */ |
| 752 | 759 | protected function runQuery($XQuery, $selector = null, $compare = null) |
| 753 | 760 | { |
| 754 | - if ($compare && !method_exists($this, $compare)) |
|
| 755 | - return false; |
|
| 761 | + if ($compare && !method_exists($this, $compare)) { |
|
| 762 | + return false; |
|
| 763 | + } |
|
| 756 | 764 | $stack = array(); |
| 757 | - if (!$this->elements) |
|
| 758 | - $this->debug('Stack empty, skipping...'); |
|
| 765 | + if (!$this->elements) { |
|
| 766 | + $this->debug('Stack empty, skipping...'); |
|
| 767 | + } |
|
| 759 | 768 | // var_dump($this->elements[0]->nodeType); |
| 760 | 769 | // element, document |
| 761 | 770 | foreach ($this->stack( |
@@ -787,8 +796,9 @@ discard block |
||
| 787 | 796 | // run query, get elements |
| 788 | 797 | $nodes = $this->xpath->query($query); |
| 789 | 798 | $this->debug("QUERY FETCHED"); |
| 790 | - if (!$nodes->length) |
|
| 791 | - $this->debug('Nothing found'); |
|
| 799 | + if (!$nodes->length) { |
|
| 800 | + $this->debug('Nothing found'); |
|
| 801 | + } |
|
| 792 | 802 | $debug = array(); |
| 793 | 803 | foreach ($nodes as $node) { |
| 794 | 804 | $matched = false; |
@@ -810,23 +820,26 @@ discard block |
||
| 810 | 820 | $node |
| 811 | 821 | ) |
| 812 | 822 | ) |
| 813 | - ) |
|
| 814 | - $matched = true; |
|
| 823 | + ) { |
|
| 824 | + $matched = true; |
|
| 825 | + } |
|
| 815 | 826 | PhpQuery::$debug = $PhpQueryDebug; |
| 816 | 827 | } else { |
| 817 | 828 | $matched = true; |
| 818 | 829 | } |
| 819 | 830 | if ($matched) { |
| 820 | - if (PhpQuery::$debug) |
|
| 821 | - $debug[] = $this->whois($node); |
|
| 831 | + if (PhpQuery::$debug) { |
|
| 832 | + $debug[] = $this->whois($node); |
|
| 833 | + } |
|
| 822 | 834 | $stack[] = $node; |
| 823 | 835 | } |
| 824 | 836 | } |
| 825 | 837 | if (PhpQuery::$debug) { |
| 826 | 838 | $this->debug("Matched " . count($debug) . ": " . implode(', ', $debug)); |
| 827 | 839 | } |
| 828 | - if ($detachAfter) |
|
| 829 | - $this->root->removeChild($detachAfter); |
|
| 840 | + if ($detachAfter) { |
|
| 841 | + $this->root->removeChild($detachAfter); |
|
| 842 | + } |
|
| 830 | 843 | } |
| 831 | 844 | $this->elements = $stack; |
| 832 | 845 | } |
@@ -841,9 +854,10 @@ discard block |
||
| 841 | 854 | */ |
| 842 | 855 | public function find($selectors, $context = null, $noHistory = false) |
| 843 | 856 | { |
| 844 | - if (!$noHistory) |
|
| 845 | - // backup last stack /for end()/ |
|
| 857 | + if (!$noHistory) { |
|
| 858 | + // backup last stack /for end()/ |
|
| 846 | 859 | $this->elementsBackup = $this->elements; |
| 860 | + } |
|
| 847 | 861 | // allow to define context |
| 848 | 862 | // TODO combine code below with PhpQuery::pq() context guessing code |
| 849 | 863 | // as generic function |
@@ -854,9 +868,10 @@ discard block |
||
| 854 | 868 | ); |
| 855 | 869 | } elseif (is_array($context)) { |
| 856 | 870 | $this->elements = array(); |
| 857 | - foreach ($context as $c) |
|
| 858 | - if ($c instanceof \DOMElement) |
|
| 871 | + foreach ($context as $c) { |
|
| 872 | + if ($c instanceof \DOMElement) |
|
| 859 | 873 | $this->elements[] = $c; |
| 874 | + } |
|
| 860 | 875 | } elseif ($context instanceof PhpQueryObject) { |
| 861 | 876 | $this->elements = $context->elements; |
| 862 | 877 | } |
@@ -900,13 +915,15 @@ discard block |
||
| 900 | 915 | } |
| 901 | 916 | // ID |
| 902 | 917 | } else if ($s[0] == '#') { |
| 903 | - if ($delimiterBefore) |
|
| 904 | - $XQuery .= '*'; |
|
| 918 | + if ($delimiterBefore) { |
|
| 919 | + $XQuery .= '*'; |
|
| 920 | + } |
|
| 905 | 921 | $XQuery .= "[@id='" . substr($s, 1) . "']"; |
| 906 | 922 | // ATTRIBUTES |
| 907 | 923 | } else if ($s[0] == '[') { |
| 908 | - if ($delimiterBefore) |
|
| 909 | - $XQuery .= '*'; |
|
| 924 | + if ($delimiterBefore) { |
|
| 925 | + $XQuery .= '*'; |
|
| 926 | + } |
|
| 910 | 927 | // strip side brackets |
| 911 | 928 | $attr = trim($s, ']['); |
| 912 | 929 | $execute = false; |
@@ -930,27 +947,31 @@ discard block |
||
| 930 | 947 | if ($execute) { |
| 931 | 948 | $this->runQuery($XQuery, $s, 'is'); |
| 932 | 949 | $XQuery = ''; |
| 933 | - if (!$this->length()) |
|
| 934 | - break; |
|
| 950 | + if (!$this->length()) { |
|
| 951 | + break; |
|
| 952 | + } |
|
| 935 | 953 | } |
| 936 | 954 | // CLASSES |
| 937 | 955 | } else if ($s[0] == '.') { |
| 938 | 956 | // TODO use return $this->find("./self::*[contains(concat(\" \",@class,\" \"), \" $class \")]"); |
| 939 | 957 | // thx wizDom ;) |
| 940 | - if ($delimiterBefore) |
|
| 941 | - $XQuery .= '*'; |
|
| 958 | + if ($delimiterBefore) { |
|
| 959 | + $XQuery .= '*'; |
|
| 960 | + } |
|
| 942 | 961 | $XQuery .= '[@class]'; |
| 943 | 962 | $this->runQuery($XQuery, $s, 'matchClasses'); |
| 944 | 963 | $XQuery = ''; |
| 945 | - if (!$this->length()) |
|
| 946 | - break; |
|
| 964 | + if (!$this->length()) { |
|
| 965 | + break; |
|
| 966 | + } |
|
| 947 | 967 | // ~ General Sibling Selector |
| 948 | 968 | } else if ($s[0] == '~') { |
| 949 | 969 | $this->runQuery($XQuery); |
| 950 | 970 | $XQuery = ''; |
| 951 | 971 | $this->elements = $this->siblings(substr($s, 1))->elements; |
| 952 | - if (!$this->length()) |
|
| 953 | - break; |
|
| 972 | + if (!$this->length()) { |
|
| 973 | + break; |
|
| 974 | + } |
|
| 954 | 975 | // + Adjacent sibling selectors |
| 955 | 976 | } else if ($s[0] == '+') { |
| 956 | 977 | // TODO /following-sibling:: |
@@ -962,13 +983,16 @@ discard block |
||
| 962 | 983 | foreach ($subElements as $node) { |
| 963 | 984 | // search first \DOMElement sibling |
| 964 | 985 | $test = $node->nextSibling; |
| 965 | - while ($test && !($test instanceof \DOMElement)) |
|
| 966 | - $test = $test->nextSibling; |
|
| 967 | - if ($test && $this->is($subSelector, $test)) |
|
| 968 | - $this->elements[] = $test; |
|
| 986 | + while ($test && !($test instanceof \DOMElement)) { |
|
| 987 | + $test = $test->nextSibling; |
|
| 988 | + } |
|
| 989 | + if ($test && $this->is($subSelector, $test)) { |
|
| 990 | + $this->elements[] = $test; |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + if (!$this->length()) { |
|
| 994 | + break; |
|
| 969 | 995 | } |
| 970 | - if (!$this->length()) |
|
| 971 | - break; |
|
| 972 | 996 | // PSEUDO CLASSES |
| 973 | 997 | } else if ($s[0] == ':') { |
| 974 | 998 | // TODO optimization for :first :last |
@@ -976,11 +1000,13 @@ discard block |
||
| 976 | 1000 | $this->runQuery($XQuery); |
| 977 | 1001 | $XQuery = ''; |
| 978 | 1002 | } |
| 979 | - if (!$this->length()) |
|
| 980 | - break; |
|
| 1003 | + if (!$this->length()) { |
|
| 1004 | + break; |
|
| 1005 | + } |
|
| 981 | 1006 | $this->pseudoClasses($s); |
| 982 | - if (!$this->length()) |
|
| 983 | - break; |
|
| 1007 | + if (!$this->length()) { |
|
| 1008 | + break; |
|
| 1009 | + } |
|
| 984 | 1010 | // DIRECT DESCENDANDS |
| 985 | 1011 | } else if ($s == '>') { |
| 986 | 1012 | $XQuery .= '/'; |
@@ -1000,9 +1026,10 @@ discard block |
||
| 1000 | 1026 | $this->runQuery($XQuery); |
| 1001 | 1027 | $XQuery = ''; |
| 1002 | 1028 | } |
| 1003 | - foreach ($this->elements as $node) |
|
| 1004 | - if (!$this->elementsContainsNode($node, $stack)) |
|
| 1029 | + foreach ($this->elements as $node) { |
|
| 1030 | + if (!$this->elementsContainsNode($node, $stack)) |
|
| 1005 | 1031 | $stack[] = $node; |
| 1032 | + } |
|
| 1006 | 1033 | } |
| 1007 | 1034 | $this->elements = $stack; |
| 1008 | 1035 | return $this->newInstance(); |
@@ -1026,10 +1053,11 @@ discard block |
||
| 1026 | 1053 | case 'odd': |
| 1027 | 1054 | $stack = array(); |
| 1028 | 1055 | foreach ($this->elements as $i => $node) { |
| 1029 | - if ($class == 'even' && ($i % 2) == 0) |
|
| 1030 | - $stack[] = $node; |
|
| 1031 | - else if ($class == 'odd' && $i % 2) |
|
| 1032 | - $stack[] = $node; |
|
| 1056 | + if ($class == 'even' && ($i % 2) == 0) { |
|
| 1057 | + $stack[] = $node; |
|
| 1058 | + } else if ($class == 'odd' && $i % 2) { |
|
| 1059 | + $stack[] = $node; |
|
| 1060 | + } |
|
| 1033 | 1061 | } |
| 1034 | 1062 | $this->elements = $stack; |
| 1035 | 1063 | break; |
@@ -1046,16 +1074,18 @@ discard block |
||
| 1046 | 1074 | $this->elements = array_slice($this->elements, 0, $args + 1); |
| 1047 | 1075 | break; |
| 1048 | 1076 | case 'first': |
| 1049 | - if (isset($this->elements[0])) |
|
| 1050 | - $this->elements = array( |
|
| 1077 | + if (isset($this->elements[0])) { |
|
| 1078 | + $this->elements = array( |
|
| 1051 | 1079 | $this->elements[0] |
| 1052 | 1080 | ); |
| 1081 | + } |
|
| 1053 | 1082 | break; |
| 1054 | 1083 | case 'last': |
| 1055 | - if ($this->elements) |
|
| 1056 | - $this->elements = array( |
|
| 1084 | + if ($this->elements) { |
|
| 1085 | + $this->elements = array( |
|
| 1057 | 1086 | $this->elements[count($this->elements) - 1] |
| 1058 | 1087 | ); |
| 1088 | + } |
|
| 1059 | 1089 | break; |
| 1060 | 1090 | /*case 'parent': |
| 1061 | 1091 | $stack = array(); |
@@ -1069,8 +1099,9 @@ discard block |
||
| 1069 | 1099 | $text = trim($args, "\"'"); |
| 1070 | 1100 | $stack = array(); |
| 1071 | 1101 | foreach ($this->elements as $node) { |
| 1072 | - if (mb_stripos($node->textContent, $text) === false) |
|
| 1073 | - continue; |
|
| 1102 | + if (mb_stripos($node->textContent, $text) === false) { |
|
| 1103 | + continue; |
|
| 1104 | + } |
|
| 1074 | 1105 | $stack[] = $node; |
| 1075 | 1106 | } |
| 1076 | 1107 | $this->elements = $stack; |
@@ -1084,16 +1115,18 @@ discard block |
||
| 1084 | 1115 | $args = explode(',', str_replace(', ', ',', trim($args, "\"'"))); |
| 1085 | 1116 | $start = $args[0]; |
| 1086 | 1117 | $end = isset($args[1]) ? $args[1] : null; |
| 1087 | - if ($end > 0) |
|
| 1088 | - $end = $end - $start; |
|
| 1118 | + if ($end > 0) { |
|
| 1119 | + $end = $end - $start; |
|
| 1120 | + } |
|
| 1089 | 1121 | $this->elements = array_slice($this->elements, $start, $end); |
| 1090 | 1122 | break; |
| 1091 | 1123 | case 'has': |
| 1092 | 1124 | $selector = trim($args, "\"'"); |
| 1093 | 1125 | $stack = array(); |
| 1094 | 1126 | foreach ($this->stack(1) as $el) { |
| 1095 | - if ($this->find($selector, $el, true)->length) |
|
| 1096 | - $stack[] = $el; |
|
| 1127 | + if ($this->find($selector, $el, true)->length) { |
|
| 1128 | + $stack[] = $el; |
|
| 1129 | + } |
|
| 1097 | 1130 | } |
| 1098 | 1131 | $this->elements = $stack; |
| 1099 | 1132 | break; |
@@ -1231,14 +1264,16 @@ discard block |
||
| 1231 | 1264 | break; |
| 1232 | 1265 | case 'nth-child': |
| 1233 | 1266 | $param = trim($args, "\"'"); |
| 1234 | - if (!$param) |
|
| 1235 | - break; |
|
| 1267 | + if (!$param) { |
|
| 1268 | + break; |
|
| 1269 | + } |
|
| 1236 | 1270 | // nth-child(n+b) to nth-child(1n+b) |
| 1237 | - if ($param{0} == 'n') |
|
| 1238 | - $param = '1' . $param; |
|
| 1271 | + if ($param{0} == 'n') { |
|
| 1272 | + $param = '1' . $param; |
|
| 1273 | + } |
|
| 1239 | 1274 | // :nth-child(index/even/odd/equation) |
| 1240 | - if ($param == 'even' || $param == 'odd') |
|
| 1241 | - $mapped = $this->map( |
|
| 1275 | + if ($param == 'even' || $param == 'odd') { |
|
| 1276 | + $mapped = $this->map( |
|
| 1242 | 1277 | create_function( |
| 1243 | 1278 | '$node, $param', |
| 1244 | 1279 | '$index = pq($node)->prevAll()->size()+1; |
@@ -1252,10 +1287,10 @@ discard block |
||
| 1252 | 1287 | new \CallbackParam(), |
| 1253 | 1288 | $param |
| 1254 | 1289 | ); |
| 1255 | - else if (mb_strlen($param) > 1 |
|
| 1290 | + } else if (mb_strlen($param) > 1 |
|
| 1256 | 1291 | && preg_match('/^(\d*)n([-+]?)(\d*)/', $param) === 1 |
| 1257 | - ) |
|
| 1258 | - // an+b |
|
| 1292 | + ) { |
|
| 1293 | + // an+b |
|
| 1259 | 1294 | $mapped = $this->map( |
| 1260 | 1295 | create_function( |
| 1261 | 1296 | '$node, $param', |
@@ -1299,8 +1334,8 @@ discard block |
||
| 1299 | 1334 | new \CallbackParam(), |
| 1300 | 1335 | $param |
| 1301 | 1336 | ); |
| 1302 | - else |
|
| 1303 | - // index |
|
| 1337 | + } else { |
|
| 1338 | + // index |
|
| 1304 | 1339 | $mapped = $this->map( |
| 1305 | 1340 | create_function( |
| 1306 | 1341 | '$node, $index', |
@@ -1315,6 +1350,7 @@ discard block |
||
| 1315 | 1350 | new \CallbackParam(), |
| 1316 | 1351 | $param |
| 1317 | 1352 | ); |
| 1353 | + } |
|
| 1318 | 1354 | $this->elements = $mapped->elements; |
| 1319 | 1355 | break; |
| 1320 | 1356 | default: |
@@ -1345,21 +1381,24 @@ discard block |
||
| 1345 | 1381 | $selector |
| 1346 | 1382 | ) |
| 1347 | 1383 | ); |
| 1348 | - if (!$selector) |
|
| 1349 | - return false; |
|
| 1384 | + if (!$selector) { |
|
| 1385 | + return false; |
|
| 1386 | + } |
|
| 1350 | 1387 | $oldStack = $this->elements; |
| 1351 | 1388 | $returnArray = false; |
| 1352 | 1389 | if ($nodes && is_array($nodes)) { |
| 1353 | 1390 | $this->elements = $nodes; |
| 1354 | - } else if ($nodes) |
|
| 1355 | - $this->elements = array( |
|
| 1391 | + } else if ($nodes) { |
|
| 1392 | + $this->elements = array( |
|
| 1356 | 1393 | $nodes |
| 1357 | 1394 | ); |
| 1395 | + } |
|
| 1358 | 1396 | $this->filter($selector, true); |
| 1359 | 1397 | $stack = $this->elements; |
| 1360 | 1398 | $this->elements = $oldStack; |
| 1361 | - if ($nodes) |
|
| 1362 | - return $stack ? $stack : null; |
|
| 1399 | + if ($nodes) { |
|
| 1400 | + return $stack ? $stack : null; |
|
| 1401 | + } |
|
| 1363 | 1402 | return (bool) count($stack); |
| 1364 | 1403 | } |
| 1365 | 1404 | |
@@ -1391,8 +1430,9 @@ discard block |
||
| 1391 | 1430 | $node |
| 1392 | 1431 | ) |
| 1393 | 1432 | ); |
| 1394 | - if (is_null($result) || (!is_null($result) && $result)) |
|
| 1395 | - $newStack[] = $node; |
|
| 1433 | + if (is_null($result) || (!is_null($result) && $result)) { |
|
| 1434 | + $newStack[] = $node; |
|
| 1435 | + } |
|
| 1396 | 1436 | } |
| 1397 | 1437 | $this->elements = $newStack; |
| 1398 | 1438 | return $_skipHistory ? $this : $this->newInstance(); |
@@ -1408,10 +1448,12 @@ discard block |
||
| 1408 | 1448 | */ |
| 1409 | 1449 | public function filter($selectors, $_skipHistory = false) |
| 1410 | 1450 | { |
| 1411 | - if ($selectors instanceof \Callback OR $selectors instanceof \Closure) |
|
| 1412 | - return $this->filterCallback($selectors, $_skipHistory); |
|
| 1413 | - if (!$_skipHistory) |
|
| 1414 | - $this->elementsBackup = $this->elements; |
|
| 1451 | + if ($selectors instanceof \Callback OR $selectors instanceof \Closure) { |
|
| 1452 | + return $this->filterCallback($selectors, $_skipHistory); |
|
| 1453 | + } |
|
| 1454 | + if (!$_skipHistory) { |
|
| 1455 | + $this->elementsBackup = $this->elements; |
|
| 1456 | + } |
|
| 1415 | 1457 | $notSimpleSelector = array( |
| 1416 | 1458 | ' ', |
| 1417 | 1459 | '>', |
@@ -1419,23 +1461,27 @@ discard block |
||
| 1419 | 1461 | '+', |
| 1420 | 1462 | '/' |
| 1421 | 1463 | ); |
| 1422 | - if (!is_array($selectors)) |
|
| 1423 | - $selectors = $this->parseSelector($selectors); |
|
| 1424 | - if (!$_skipHistory) |
|
| 1425 | - $this->debug( |
|
| 1464 | + if (!is_array($selectors)) { |
|
| 1465 | + $selectors = $this->parseSelector($selectors); |
|
| 1466 | + } |
|
| 1467 | + if (!$_skipHistory) { |
|
| 1468 | + $this->debug( |
|
| 1426 | 1469 | array( |
| 1427 | 1470 | "Filtering:", |
| 1428 | 1471 | $selectors |
| 1429 | 1472 | ) |
| 1430 | 1473 | ); |
| 1474 | + } |
|
| 1431 | 1475 | $finalStack = array(); |
| 1432 | 1476 | foreach ($selectors as $selector) { |
| 1433 | 1477 | $stack = array(); |
| 1434 | - if (!$selector) |
|
| 1435 | - break; |
|
| 1478 | + if (!$selector) { |
|
| 1479 | + break; |
|
| 1480 | + } |
|
| 1436 | 1481 | // avoid first space or / |
| 1437 | - if (in_array($selector[0], $notSimpleSelector)) |
|
| 1438 | - $selector = array_slice($selector, 1); |
|
| 1482 | + if (in_array($selector[0], $notSimpleSelector)) { |
|
| 1483 | + $selector = array_slice($selector, 1); |
|
| 1484 | + } |
|
| 1439 | 1485 | // PER NODE selector chunks |
| 1440 | 1486 | foreach ($this->stack() as $node) { |
| 1441 | 1487 | $break = false; |
@@ -1446,21 +1492,25 @@ discard block |
||
| 1446 | 1492 | $attr = trim($s, '[]'); |
| 1447 | 1493 | if (mb_strpos($attr, '=')) { |
| 1448 | 1494 | list($attr, $val) = explode('=', $attr); |
| 1449 | - if ($attr == 'nodeType' && $node->nodeType != $val) |
|
| 1450 | - $break = true; |
|
| 1495 | + if ($attr == 'nodeType' && $node->nodeType != $val) { |
|
| 1496 | + $break = true; |
|
| 1497 | + } |
|
| 1451 | 1498 | } |
| 1452 | - } else |
|
| 1453 | - $break = true; |
|
| 1499 | + } else { |
|
| 1500 | + $break = true; |
|
| 1501 | + } |
|
| 1454 | 1502 | } else { |
| 1455 | 1503 | // \DOMElement only |
| 1456 | 1504 | // ID |
| 1457 | 1505 | if ($s[0] == '#') { |
| 1458 | - if ($node->getAttribute('id') != substr($s, 1)) |
|
| 1459 | - $break = true; |
|
| 1506 | + if ($node->getAttribute('id') != substr($s, 1)) { |
|
| 1507 | + $break = true; |
|
| 1508 | + } |
|
| 1460 | 1509 | // CLASSES |
| 1461 | 1510 | } else if ($s[0] == '.') { |
| 1462 | - if (!$this->matchClasses($s, $node)) |
|
| 1463 | - $break = true; |
|
| 1511 | + if (!$this->matchClasses($s, $node)) { |
|
| 1512 | + $break = true; |
|
| 1513 | + } |
|
| 1464 | 1514 | // ATTRS |
| 1465 | 1515 | } else if ($s[0] == '[') { |
| 1466 | 1516 | // strip side brackets |
@@ -1469,8 +1519,9 @@ discard block |
||
| 1469 | 1519 | list($attr, $val) = explode('=', $attr); |
| 1470 | 1520 | $val = self::unQuote($val); |
| 1471 | 1521 | if ($attr == 'nodeType') { |
| 1472 | - if ($val != $node->nodeType) |
|
| 1473 | - $break = true; |
|
| 1522 | + if ($val != $node->nodeType) { |
|
| 1523 | + $break = true; |
|
| 1524 | + } |
|
| 1474 | 1525 | } else if ($this->isRegexp($attr)) { |
| 1475 | 1526 | $val = extension_loaded('mbstring') |
| 1476 | 1527 | && PhpQuery::$mbstringSupport ? quotemeta(trim($val, '"\'')) |
@@ -1494,12 +1545,15 @@ discard block |
||
| 1494 | 1545 | $isMatch = extension_loaded('mbstring') |
| 1495 | 1546 | && PhpQuery::$mbstringSupport ? mb_ereg_match($pattern, $node->getAttribute($attr)) |
| 1496 | 1547 | : preg_match("@{$pattern}@", $node->getAttribute($attr)); |
| 1497 | - if (!$isMatch) |
|
| 1498 | - $break = true; |
|
| 1499 | - } else if ($node->getAttribute($attr) != $val) |
|
| 1500 | - $break = true; |
|
| 1501 | - } else if (!$node->hasAttribute($attr)) |
|
| 1502 | - $break = true; |
|
| 1548 | + if (!$isMatch) { |
|
| 1549 | + $break = true; |
|
| 1550 | + } |
|
| 1551 | + } else if ($node->getAttribute($attr) != $val) { |
|
| 1552 | + $break = true; |
|
| 1553 | + } |
|
| 1554 | + } else if (!$node->hasAttribute($attr)) { |
|
| 1555 | + $break = true; |
|
| 1556 | + } |
|
| 1503 | 1557 | // PSEUDO CLASSES |
| 1504 | 1558 | } else if ($s[0] == ':') { |
| 1505 | 1559 | // skip |
@@ -1508,10 +1562,12 @@ discard block |
||
| 1508 | 1562 | if ($s != '*') { |
| 1509 | 1563 | // TODO namespaces |
| 1510 | 1564 | if (isset($node->tagName)) { |
| 1511 | - if ($node->tagName != $s) |
|
| 1512 | - $break = true; |
|
| 1513 | - } else if ($s == 'html' && !$this->isRoot($node)) |
|
| 1514 | - $break = true; |
|
| 1565 | + if ($node->tagName != $s) { |
|
| 1566 | + $break = true; |
|
| 1567 | + } |
|
| 1568 | + } else if ($s == 'html' && !$this->isRoot($node)) { |
|
| 1569 | + $break = true; |
|
| 1570 | + } |
|
| 1515 | 1571 | } |
| 1516 | 1572 | // AVOID NON-SIMPLE SELECTORS |
| 1517 | 1573 | } else if (in_array($s, $notSimpleSelector)) { |
@@ -1524,24 +1580,28 @@ discard block |
||
| 1524 | 1580 | ); |
| 1525 | 1581 | } |
| 1526 | 1582 | } |
| 1527 | - if ($break) |
|
| 1528 | - break; |
|
| 1583 | + if ($break) { |
|
| 1584 | + break; |
|
| 1585 | + } |
|
| 1529 | 1586 | } |
| 1530 | 1587 | // if element passed all chunks of selector - add it to new stack |
| 1531 | - if (!$break) |
|
| 1532 | - $stack[] = $node; |
|
| 1588 | + if (!$break) { |
|
| 1589 | + $stack[] = $node; |
|
| 1590 | + } |
|
| 1533 | 1591 | } |
| 1534 | 1592 | $tmpStack = $this->elements; |
| 1535 | 1593 | $this->elements = $stack; |
| 1536 | 1594 | // PER ALL NODES selector chunks |
| 1537 | - foreach ($selector as $s) |
|
| 1538 | - // PSEUDO CLASSES |
|
| 1595 | + foreach ($selector as $s) { |
|
| 1596 | + // PSEUDO CLASSES |
|
| 1539 | 1597 | if ($s[0] == ':') |
| 1540 | 1598 | $this->pseudoClasses($s); |
| 1541 | - foreach ($this->elements as $node) |
|
| 1542 | - // XXX it should be merged without duplicates |
|
| 1599 | + } |
|
| 1600 | + foreach ($this->elements as $node) { |
|
| 1601 | + // XXX it should be merged without duplicates |
|
| 1543 | 1602 | // but jQuery doesnt do that |
| 1544 | 1603 | $finalStack[] = $node; |
| 1604 | + } |
|
| 1545 | 1605 | $this->elements = $tmpStack; |
| 1546 | 1606 | } |
| 1547 | 1607 | $this->elements = $finalStack; |
@@ -1583,10 +1643,11 @@ discard block |
||
| 1583 | 1643 | } |
| 1584 | 1644 | if (mb_strpos($url, ' ') !== false) { |
| 1585 | 1645 | $matches = null; |
| 1586 | - if (extension_loaded('mbstring') && PhpQuery::$mbstringSupport) |
|
| 1587 | - mb_ereg('^([^ ]+) (.*)$', $url, $matches); |
|
| 1588 | - else |
|
| 1589 | - preg_match('@^([^ ]+) (.*)$@', $url, $matches); |
|
| 1646 | + if (extension_loaded('mbstring') && PhpQuery::$mbstringSupport) { |
|
| 1647 | + mb_ereg('^([^ ]+) (.*)$', $url, $matches); |
|
| 1648 | + } else { |
|
| 1649 | + preg_match('@^([^ ]+) (.*)$@', $url, $matches); |
|
| 1650 | + } |
|
| 1590 | 1651 | $url = $matches[1]; |
| 1591 | 1652 | $selector = $matches[2]; |
| 1592 | 1653 | // FIXME this sucks, pass as callback param |
@@ -1817,8 +1878,9 @@ discard block |
||
| 1817 | 1878 | */ |
| 1818 | 1879 | public function trigger($type, $data = array()) |
| 1819 | 1880 | { |
| 1820 | - foreach ($this->elements as $node) |
|
| 1821 | - PhpQueryEvents::trigger($this->getDocumentID(), $type, $data, $node); |
|
| 1881 | + foreach ($this->elements as $node) { |
|
| 1882 | + PhpQueryEvents::trigger($this->getDocumentID(), $type, $data, $node); |
|
| 1883 | + } |
|
| 1822 | 1884 | return $this; |
| 1823 | 1885 | } |
| 1824 | 1886 | |
@@ -1853,8 +1915,9 @@ discard block |
||
| 1853 | 1915 | $callback = $data; |
| 1854 | 1916 | $data = null; |
| 1855 | 1917 | } |
| 1856 | - foreach ($this->elements as $node) |
|
| 1857 | - PhpQueryEvents::add($this->getDocumentID(), $node, $type, $data, $callback); |
|
| 1918 | + foreach ($this->elements as $node) { |
|
| 1919 | + PhpQueryEvents::add($this->getDocumentID(), $node, $type, $data, $callback); |
|
| 1920 | + } |
|
| 1858 | 1921 | return $this; |
| 1859 | 1922 | } |
| 1860 | 1923 | |
@@ -1869,8 +1932,9 @@ discard block |
||
| 1869 | 1932 | */ |
| 1870 | 1933 | public function unbind($type = null, $callback = null) |
| 1871 | 1934 | { |
| 1872 | - foreach ($this->elements as $node) |
|
| 1873 | - PhpQueryEvents::remove($this->getDocumentID(), $node, $type, $callback); |
|
| 1935 | + foreach ($this->elements as $node) { |
|
| 1936 | + PhpQueryEvents::remove($this->getDocumentID(), $node, $type, $callback); |
|
| 1937 | + } |
|
| 1874 | 1938 | return $this; |
| 1875 | 1939 | } |
| 1876 | 1940 | |
@@ -1882,8 +1946,9 @@ discard block |
||
| 1882 | 1946 | */ |
| 1883 | 1947 | public function change($callback = null) |
| 1884 | 1948 | { |
| 1885 | - if ($callback) |
|
| 1886 | - return $this->bind('change', $callback); |
|
| 1949 | + if ($callback) { |
|
| 1950 | + return $this->bind('change', $callback); |
|
| 1951 | + } |
|
| 1887 | 1952 | return $this->trigger('change'); |
| 1888 | 1953 | } |
| 1889 | 1954 | |
@@ -1895,8 +1960,9 @@ discard block |
||
| 1895 | 1960 | */ |
| 1896 | 1961 | public function submit($callback = null) |
| 1897 | 1962 | { |
| 1898 | - if ($callback) |
|
| 1899 | - return $this->bind('submit', $callback); |
|
| 1963 | + if ($callback) { |
|
| 1964 | + return $this->bind('submit', $callback); |
|
| 1965 | + } |
|
| 1900 | 1966 | return $this->trigger('submit'); |
| 1901 | 1967 | } |
| 1902 | 1968 | |
@@ -1908,8 +1974,9 @@ discard block |
||
| 1908 | 1974 | */ |
| 1909 | 1975 | public function click($callback = null) |
| 1910 | 1976 | { |
| 1911 | - if ($callback) |
|
| 1912 | - return $this->bind('click', $callback); |
|
| 1977 | + if ($callback) { |
|
| 1978 | + return $this->bind('click', $callback); |
|
| 1979 | + } |
|
| 1913 | 1980 | return $this->trigger('click'); |
| 1914 | 1981 | } |
| 1915 | 1982 | |
@@ -1922,12 +1989,14 @@ discard block |
||
| 1922 | 1989 | public function wrapAllOld($wrapper) |
| 1923 | 1990 | { |
| 1924 | 1991 | $wrapper = pq($wrapper)->_clone(); |
| 1925 | - if (!$wrapper->length() || !$this->length()) |
|
| 1926 | - return $this; |
|
| 1992 | + if (!$wrapper->length() || !$this->length()) { |
|
| 1993 | + return $this; |
|
| 1994 | + } |
|
| 1927 | 1995 | $wrapper->insertBefore($this->elements[0]); |
| 1928 | 1996 | $deepest = $wrapper->elements[0]; |
| 1929 | - while ($deepest->firstChild && $deepest->firstChild instanceof \DOMElement) |
|
| 1930 | - $deepest = $deepest->firstChild; |
|
| 1997 | + while ($deepest->firstChild && $deepest->firstChild instanceof \DOMElement) { |
|
| 1998 | + $deepest = $deepest->firstChild; |
|
| 1999 | + } |
|
| 1931 | 2000 | pq($deepest)->append($this); |
| 1932 | 2001 | return $this; |
| 1933 | 2002 | } |
@@ -1941,8 +2010,9 @@ discard block |
||
| 1941 | 2010 | */ |
| 1942 | 2011 | public function wrapAll($wrapper) |
| 1943 | 2012 | { |
| 1944 | - if (!$this->length()) |
|
| 1945 | - return $this; |
|
| 2013 | + if (!$this->length()) { |
|
| 2014 | + return $this; |
|
| 2015 | + } |
|
| 1946 | 2016 | return PhpQuery::pq($wrapper, $this->getDocumentID())->clone()->insertBefore($this->get(0))->map( |
| 1947 | 2017 | array( |
| 1948 | 2018 | $this, |
@@ -1960,8 +2030,9 @@ discard block |
||
| 1960 | 2030 | public function ___wrapAllCallback($node) |
| 1961 | 2031 | { |
| 1962 | 2032 | $deepest = $node; |
| 1963 | - while ($deepest->firstChild && $deepest->firstChild instanceof \DOMElement) |
|
| 1964 | - $deepest = $deepest->firstChild; |
|
| 2033 | + while ($deepest->firstChild && $deepest->firstChild instanceof \DOMElement) { |
|
| 2034 | + $deepest = $deepest->firstChild; |
|
| 2035 | + } |
|
| 1965 | 2036 | return $deepest; |
| 1966 | 2037 | } |
| 1967 | 2038 | |
@@ -1987,8 +2058,9 @@ discard block |
||
| 1987 | 2058 | */ |
| 1988 | 2059 | public function wrap($wrapper) |
| 1989 | 2060 | { |
| 1990 | - foreach ($this->stack() as $node) |
|
| 1991 | - PhpQuery::pq($node, $this->getDocumentID())->wrapAll($wrapper); |
|
| 2061 | + foreach ($this->stack() as $node) { |
|
| 2062 | + PhpQuery::pq($node, $this->getDocumentID())->wrapAll($wrapper); |
|
| 2063 | + } |
|
| 1992 | 2064 | return $this; |
| 1993 | 2065 | } |
| 1994 | 2066 | |
@@ -2002,8 +2074,9 @@ discard block |
||
| 2002 | 2074 | */ |
| 2003 | 2075 | public function wrapPHP($codeBefore, $codeAfter) |
| 2004 | 2076 | { |
| 2005 | - foreach ($this->stack() as $node) |
|
| 2006 | - PhpQuery::pq($node, $this->getDocumentID())->wrapAllPHP($codeBefore, $codeAfter); |
|
| 2077 | + foreach ($this->stack() as $node) { |
|
| 2078 | + PhpQuery::pq($node, $this->getDocumentID())->wrapAllPHP($codeBefore, $codeAfter); |
|
| 2079 | + } |
|
| 2007 | 2080 | return $this; |
| 2008 | 2081 | } |
| 2009 | 2082 | |
@@ -2015,8 +2088,9 @@ discard block |
||
| 2015 | 2088 | */ |
| 2016 | 2089 | public function wrapInner($wrapper) |
| 2017 | 2090 | { |
| 2018 | - foreach ($this->stack() as $node) |
|
| 2019 | - PhpQuery::pq($node, $this->getDocumentID())->contents()->wrapAll($wrapper); |
|
| 2091 | + foreach ($this->stack() as $node) { |
|
| 2092 | + PhpQuery::pq($node, $this->getDocumentID())->contents()->wrapAll($wrapper); |
|
| 2093 | + } |
|
| 2020 | 2094 | return $this; |
| 2021 | 2095 | } |
| 2022 | 2096 | |
@@ -2030,8 +2104,9 @@ discard block |
||
| 2030 | 2104 | */ |
| 2031 | 2105 | public function wrapInnerPHP($codeBefore, $codeAfter) |
| 2032 | 2106 | { |
| 2033 | - foreach ($this->stack(1) as $node) |
|
| 2034 | - PhpQuery::pq($node, $this->getDocumentID())->contents()->wrapAllPHP($codeBefore, $codeAfter); |
|
| 2107 | + foreach ($this->stack(1) as $node) { |
|
| 2108 | + PhpQuery::pq($node, $this->getDocumentID())->contents()->wrapAllPHP($codeBefore, $codeAfter); |
|
| 2109 | + } |
|
| 2035 | 2110 | return $this; |
| 2036 | 2111 | } |
| 2037 | 2112 | |
@@ -2065,15 +2140,18 @@ discard block |
||
| 2065 | 2140 | public function contentsUnwrap() |
| 2066 | 2141 | { |
| 2067 | 2142 | foreach ($this->stack(1) as $node) { |
| 2068 | - if (!$node->parentNode) |
|
| 2069 | - continue; |
|
| 2143 | + if (!$node->parentNode) { |
|
| 2144 | + continue; |
|
| 2145 | + } |
|
| 2070 | 2146 | $childNodes = array(); |
| 2071 | 2147 | // any modification in DOM tree breaks childNodes iteration, so cache them first |
| 2072 | - foreach ($node->childNodes as $chNode) |
|
| 2073 | - $childNodes[] = $chNode; |
|
| 2074 | - foreach ($childNodes as $chNode) |
|
| 2075 | - // $node->parentNode->appendChild($chNode); |
|
| 2148 | + foreach ($node->childNodes as $chNode) { |
|
| 2149 | + $childNodes[] = $chNode; |
|
| 2150 | + } |
|
| 2151 | + foreach ($childNodes as $chNode) { |
|
| 2152 | + // $node->parentNode->appendChild($chNode); |
|
| 2076 | 2153 | $node->parentNode->insertBefore($chNode, $node); |
| 2154 | + } |
|
| 2077 | 2155 | $node->parentNode->removeChild($node); |
| 2078 | 2156 | } |
| 2079 | 2157 | return $this; |
@@ -2105,8 +2183,9 @@ discard block |
||
| 2105 | 2183 | $oldStack = $this->elements; |
| 2106 | 2184 | $this->elementsBackup = $this->elements; |
| 2107 | 2185 | $this->elements = array(); |
| 2108 | - if (isset($oldStack[$num])) |
|
| 2109 | - $this->elements[] = $oldStack[$num]; |
|
| 2186 | + if (isset($oldStack[$num])) { |
|
| 2187 | + $this->elements[] = $oldStack[$num]; |
|
| 2188 | + } |
|
| 2110 | 2189 | return $this->newInstance(); |
| 2111 | 2190 | } |
| 2112 | 2191 | |
@@ -2204,8 +2283,9 @@ discard block |
||
| 2204 | 2283 | */ |
| 2205 | 2284 | public function replaceAll($selector) |
| 2206 | 2285 | { |
| 2207 | - foreach (PhpQuery::pq($selector, $this->getDocumentID()) as $node) |
|
| 2208 | - PhpQuery::pq($node, $this->getDocumentID())->after($this->_clone())->remove(); |
|
| 2286 | + foreach (PhpQuery::pq($selector, $this->getDocumentID()) as $node) { |
|
| 2287 | + PhpQuery::pq($node, $this->getDocumentID())->after($this->_clone())->remove(); |
|
| 2288 | + } |
|
| 2209 | 2289 | return $this; |
| 2210 | 2290 | } |
| 2211 | 2291 | |
@@ -2218,10 +2298,12 @@ discard block |
||
| 2218 | 2298 | { |
| 2219 | 2299 | $loop = $selector ? $this->filter($selector)->elements : $this->elements; |
| 2220 | 2300 | foreach ($loop as $node) { |
| 2221 | - if (!$node->parentNode) |
|
| 2222 | - continue; |
|
| 2223 | - if (isset($node->tagName)) |
|
| 2224 | - $this->debug("Removing '{$node->tagName}'"); |
|
| 2301 | + if (!$node->parentNode) { |
|
| 2302 | + continue; |
|
| 2303 | + } |
|
| 2304 | + if (isset($node->tagName)) { |
|
| 2305 | + $this->debug("Removing '{$node->tagName}'"); |
|
| 2306 | + } |
|
| 2225 | 2307 | $node->parentNode->removeChild($node); |
| 2226 | 2308 | // Mutation event |
| 2227 | 2309 | $event = new Dom\DOMEvent(array( |
@@ -2271,22 +2353,23 @@ discard block |
||
| 2271 | 2353 | public function markup($markup = null, $callback1 = null, $callback2 = null, $callback3 = null) |
| 2272 | 2354 | { |
| 2273 | 2355 | $args = func_get_args(); |
| 2274 | - if ($this->documentWrapper->isXML) |
|
| 2275 | - return call_user_func_array( |
|
| 2356 | + if ($this->documentWrapper->isXML) { |
|
| 2357 | + return call_user_func_array( |
|
| 2276 | 2358 | array( |
| 2277 | 2359 | $this, |
| 2278 | 2360 | 'xml' |
| 2279 | 2361 | ), |
| 2280 | 2362 | $args |
| 2281 | 2363 | ); |
| 2282 | - else |
|
| 2283 | - return call_user_func_array( |
|
| 2364 | + } else { |
|
| 2365 | + return call_user_func_array( |
|
| 2284 | 2366 | array( |
| 2285 | 2367 | $this, |
| 2286 | 2368 | 'html' |
| 2287 | 2369 | ), |
| 2288 | 2370 | $args |
| 2289 | 2371 | ); |
| 2372 | + } |
|
| 2290 | 2373 | } |
| 2291 | 2374 | |
| 2292 | 2375 | /** |
@@ -2301,22 +2384,23 @@ discard block |
||
| 2301 | 2384 | public function markupOuter($callback1 = null, $callback2 = null, $callback3 = null) |
| 2302 | 2385 | { |
| 2303 | 2386 | $args = func_get_args(); |
| 2304 | - if ($this->documentWrapper->isXML) |
|
| 2305 | - return call_user_func_array( |
|
| 2387 | + if ($this->documentWrapper->isXML) { |
|
| 2388 | + return call_user_func_array( |
|
| 2306 | 2389 | array( |
| 2307 | 2390 | $this, |
| 2308 | 2391 | 'xmlOuter' |
| 2309 | 2392 | ), |
| 2310 | 2393 | $args |
| 2311 | 2394 | ); |
| 2312 | - else |
|
| 2313 | - return call_user_func_array( |
|
| 2395 | + } else { |
|
| 2396 | + return call_user_func_array( |
|
| 2314 | 2397 | array( |
| 2315 | 2398 | $this, |
| 2316 | 2399 | 'htmlOuter' |
| 2317 | 2400 | ), |
| 2318 | 2401 | $args |
| 2319 | 2402 | ); |
| 2403 | + } |
|
| 2320 | 2404 | } |
| 2321 | 2405 | |
| 2322 | 2406 | /** |
@@ -2339,8 +2423,9 @@ discard block |
||
| 2339 | 2423 | // for now, limit events for textarea |
| 2340 | 2424 | if (($this->isXHTML() || $this->isHTML()) |
| 2341 | 2425 | && $node->tagName == 'textarea' |
| 2342 | - ) |
|
| 2343 | - $oldHtml = pq($node, $this->getDocumentID())->markup(); |
|
| 2426 | + ) { |
|
| 2427 | + $oldHtml = pq($node, $this->getDocumentID())->markup(); |
|
| 2428 | + } |
|
| 2344 | 2429 | foreach ($nodes as $newNode) { |
| 2345 | 2430 | $node->appendChild( |
| 2346 | 2431 | $alreadyAdded ? $newNode->cloneNode(true) |
@@ -2350,8 +2435,9 @@ discard block |
||
| 2350 | 2435 | // for now, limit events for textarea |
| 2351 | 2436 | if (($this->isXHTML() || $this->isHTML()) |
| 2352 | 2437 | && $node->tagName == 'textarea' |
| 2353 | - ) |
|
| 2354 | - $this->markupEvents($html, $oldHtml, $node); |
|
| 2438 | + ) { |
|
| 2439 | + $this->markupEvents($html, $oldHtml, $node); |
|
| 2440 | + } |
|
| 2355 | 2441 | } |
| 2356 | 2442 | return $this; |
| 2357 | 2443 | } else { |
@@ -2477,12 +2563,15 @@ discard block |
||
| 2477 | 2563 | foreach ($this->stack(1) as $node) { |
| 2478 | 2564 | // foreach($node->getElementsByTagName('*') as $newNode) { |
| 2479 | 2565 | foreach ($node->childNodes as $newNode) { |
| 2480 | - if ($newNode->nodeType != 1) |
|
| 2481 | - continue; |
|
| 2482 | - if ($selector && !$this->is($selector, $newNode)) |
|
| 2483 | - continue; |
|
| 2484 | - if ($this->elementsContainsNode($newNode, $stack)) |
|
| 2485 | - continue; |
|
| 2566 | + if ($newNode->nodeType != 1) { |
|
| 2567 | + continue; |
|
| 2568 | + } |
|
| 2569 | + if ($selector && !$this->is($selector, $newNode)) { |
|
| 2570 | + continue; |
|
| 2571 | + } |
|
| 2572 | + if ($this->elementsContainsNode($newNode, $stack)) { |
|
| 2573 | + continue; |
|
| 2574 | + } |
|
| 2486 | 2575 | $stack[] = $newNode; |
| 2487 | 2576 | } |
| 2488 | 2577 | } |
@@ -2684,25 +2773,27 @@ discard block |
||
| 2684 | 2773 | if ($target instanceof self) { |
| 2685 | 2774 | if ($to) { |
| 2686 | 2775 | $insertTo = $target->elements; |
| 2687 | - if ($this->documentFragment && $this->stackIsRoot()) |
|
| 2688 | - // get all body children |
|
| 2776 | + if ($this->documentFragment && $this->stackIsRoot()) { |
|
| 2777 | + // get all body children |
|
| 2689 | 2778 | // $loop = $this->find('body > *')->elements; |
| 2690 | 2779 | // TODO test it, test it hard... |
| 2691 | 2780 | // $loop = $this->newInstance($this->root)->find('> *')->elements; |
| 2692 | 2781 | $loop = $this->root->childNodes; |
| 2693 | - else |
|
| 2694 | - $loop = $this->elements; |
|
| 2782 | + } else { |
|
| 2783 | + $loop = $this->elements; |
|
| 2784 | + } |
|
| 2695 | 2785 | // import nodes if needed |
| 2696 | 2786 | $insertFrom = $this->getDocumentID() == $target->getDocumentID() ? $loop |
| 2697 | 2787 | : $target->documentWrapper->import($loop); |
| 2698 | 2788 | } else { |
| 2699 | 2789 | $insertTo = $this->elements; |
| 2700 | - if ($target->documentFragment && $target->stackIsRoot()) |
|
| 2701 | - // get all body children |
|
| 2790 | + if ($target->documentFragment && $target->stackIsRoot()) { |
|
| 2791 | + // get all body children |
|
| 2702 | 2792 | // $loop = $target->find('body > *')->elements; |
| 2703 | 2793 | $loop = $target->root->childNodes; |
| 2704 | - else |
|
| 2705 | - $loop = $target->elements; |
|
| 2794 | + } else { |
|
| 2795 | + $loop = $target->elements; |
|
| 2796 | + } |
|
| 2706 | 2797 | // import nodes if needed |
| 2707 | 2798 | $insertFrom = $this->getDocumentID() == $target->getDocumentID() ? $loop |
| 2708 | 2799 | : $this->documentWrapper->import($loop); |
@@ -2716,22 +2807,26 @@ discard block |
||
| 2716 | 2807 | $insertTo = array( |
| 2717 | 2808 | $target |
| 2718 | 2809 | ); |
| 2719 | - if ($this->documentFragment && $this->stackIsRoot()) |
|
| 2720 | - // get all body children |
|
| 2810 | + if ($this->documentFragment && $this->stackIsRoot()) { |
|
| 2811 | + // get all body children |
|
| 2721 | 2812 | $loop = $this->root->childNodes; |
| 2813 | + } |
|
| 2722 | 2814 | // $loop = $this->find('body > *')->elements; |
| 2723 | - else |
|
| 2724 | - $loop = $this->elements; |
|
| 2725 | - foreach ($loop as $fromNode) |
|
| 2726 | - // import nodes if needed |
|
| 2815 | + else { |
|
| 2816 | + $loop = $this->elements; |
|
| 2817 | + } |
|
| 2818 | + foreach ($loop as $fromNode) { |
|
| 2819 | + // import nodes if needed |
|
| 2727 | 2820 | $insertFrom[] = !$fromNode->ownerDocument->isSameNode( |
| 2728 | 2821 | $target->ownerDocument |
| 2729 | 2822 | ) ? $target->ownerDocument->importNode($fromNode, true) |
| 2730 | 2823 | : $fromNode; |
| 2824 | + } |
|
| 2731 | 2825 | } else { |
| 2732 | 2826 | // import node if needed |
| 2733 | - if (!$target->ownerDocument->isSameNode($this->document)) |
|
| 2734 | - $target = $this->document->importNode($target, true); |
|
| 2827 | + if (!$target->ownerDocument->isSameNode($this->document)) { |
|
| 2828 | + $target = $this->document->importNode($target, true); |
|
| 2829 | + } |
|
| 2735 | 2830 | $insertTo = $this->elements; |
| 2736 | 2831 | $insertFrom[] = $target; |
| 2737 | 2832 | } |
@@ -2773,17 +2868,19 @@ discard block |
||
| 2773 | 2868 | break; |
| 2774 | 2869 | case 'insertBefore': |
| 2775 | 2870 | case 'before': |
| 2776 | - if (!$toNode->parentNode) |
|
| 2777 | - throw new \Exception("No parentNode, can't do {$type}()"); |
|
| 2778 | - else |
|
| 2779 | - $toNode->parentNode->insertBefore($insert, $toNode); |
|
| 2871 | + if (!$toNode->parentNode) { |
|
| 2872 | + throw new \Exception("No parentNode, can't do {$type}()"); |
|
| 2873 | + } else { |
|
| 2874 | + $toNode->parentNode->insertBefore($insert, $toNode); |
|
| 2875 | + } |
|
| 2780 | 2876 | break; |
| 2781 | 2877 | case 'insertAfter': |
| 2782 | 2878 | case 'after': |
| 2783 | - if (!$toNode->parentNode) |
|
| 2784 | - throw new \Exception("No parentNode, can't do {$type}()"); |
|
| 2785 | - else |
|
| 2786 | - $toNode->parentNode->insertBefore($insert, $nextSibling); |
|
| 2879 | + if (!$toNode->parentNode) { |
|
| 2880 | + throw new \Exception("No parentNode, can't do {$type}()"); |
|
| 2881 | + } else { |
|
| 2882 | + $toNode->parentNode->insertBefore($insert, $nextSibling); |
|
| 2883 | + } |
|
| 2787 | 2884 | break; |
| 2788 | 2885 | } |
| 2789 | 2886 | // Mutation event |
@@ -2816,8 +2913,9 @@ discard block |
||
| 2816 | 2913 | $subject = $subject instanceof PhpQueryObject ? $subject->elements[0] |
| 2817 | 2914 | : $subject; |
| 2818 | 2915 | foreach ($this->newInstance() as $k => $node) { |
| 2819 | - if ($node->isSameNode($subject)) |
|
| 2820 | - $index = $k; |
|
| 2916 | + if ($node->isSameNode($subject)) { |
|
| 2917 | + $index = $k; |
|
| 2918 | + } |
|
| 2821 | 2919 | } |
| 2822 | 2920 | return $index; |
| 2823 | 2921 | } |
@@ -2841,8 +2939,9 @@ discard block |
||
| 2841 | 2939 | // $start = $last+$start; |
| 2842 | 2940 | // if ($start > $last) |
| 2843 | 2941 | // return array(); |
| 2844 | - if ($end > 0) |
|
| 2845 | - $end = $end - $start; |
|
| 2942 | + if ($end > 0) { |
|
| 2943 | + $end = $end - $start; |
|
| 2944 | + } |
|
| 2846 | 2945 | return $this->newInstance(array_slice($this->elements, $start, $end)); |
| 2847 | 2946 | } |
| 2848 | 2947 | |
@@ -2868,15 +2967,17 @@ discard block |
||
| 2868 | 2967 | */ |
| 2869 | 2968 | public function text($text = null, $callback1 = null, $callback2 = null, $callback3 = null) |
| 2870 | 2969 | { |
| 2871 | - if (isset($text)) |
|
| 2872 | - return $this->html(htmlspecialchars($text)); |
|
| 2970 | + if (isset($text)) { |
|
| 2971 | + return $this->html(htmlspecialchars($text)); |
|
| 2972 | + } |
|
| 2873 | 2973 | $args = func_get_args(); |
| 2874 | 2974 | $args = array_slice($args, 1); |
| 2875 | 2975 | $return = ''; |
| 2876 | 2976 | foreach ($this->elements as $node) { |
| 2877 | 2977 | $text = $node->textContent; |
| 2878 | - if (count($this->elements) > 1 && $text) |
|
| 2879 | - $text .= "\n"; |
|
| 2978 | + if (count($this->elements) > 1 && $text) { |
|
| 2979 | + $text .= "\n"; |
|
| 2980 | + } |
|
| 2880 | 2981 | foreach ($args as $callback) { |
| 2881 | 2982 | $text = PhpQuery::callbackRun( |
| 2882 | 2983 | $callback, |
@@ -2969,8 +3070,9 @@ discard block |
||
| 2969 | 3070 | ), |
| 2970 | 3071 | $args |
| 2971 | 3072 | ); |
| 2972 | - } else |
|
| 2973 | - throw new \Exception("Method '{$method}' doesnt exist"); |
|
| 3073 | + } else { |
|
| 3074 | + throw new \Exception("Method '{$method}' doesnt exist"); |
|
| 3075 | + } |
|
| 2974 | 3076 | } |
| 2975 | 3077 | |
| 2976 | 3078 | /** |
@@ -3043,11 +3145,13 @@ discard block |
||
| 3043 | 3145 | $test = $node; |
| 3044 | 3146 | while (isset($test->{$direction}) && $test->{$direction}) { |
| 3045 | 3147 | $test = $test->{$direction}; |
| 3046 | - if (!$test instanceof \DOMElement) |
|
| 3047 | - continue; |
|
| 3148 | + if (!$test instanceof \DOMElement) { |
|
| 3149 | + continue; |
|
| 3150 | + } |
|
| 3048 | 3151 | $stack[] = $test; |
| 3049 | - if ($limitToOne) |
|
| 3050 | - break; |
|
| 3152 | + if ($limitToOne) { |
|
| 3153 | + break; |
|
| 3154 | + } |
|
| 3051 | 3155 | } |
| 3052 | 3156 | } |
| 3053 | 3157 | if ($selector) { |
@@ -3073,8 +3177,9 @@ discard block |
||
| 3073 | 3177 | $this->getElementSiblings('nextSibling', $selector) |
| 3074 | 3178 | ); |
| 3075 | 3179 | foreach ($siblings as $node) { |
| 3076 | - if (!$this->elementsContainsNode($node, $stack)) |
|
| 3077 | - $stack[] = $node; |
|
| 3180 | + if (!$this->elementsContainsNode($node, $stack)) { |
|
| 3181 | + $stack[] = $node; |
|
| 3182 | + } |
|
| 3078 | 3183 | } |
| 3079 | 3184 | return $this->newInstance($stack); |
| 3080 | 3185 | } |
@@ -3087,32 +3192,37 @@ discard block |
||
| 3087 | 3192 | */ |
| 3088 | 3193 | public function not($selector = null) |
| 3089 | 3194 | { |
| 3090 | - if (is_string($selector)) |
|
| 3091 | - PhpQuery::debug( |
|
| 3195 | + if (is_string($selector)) { |
|
| 3196 | + PhpQuery::debug( |
|
| 3092 | 3197 | array( |
| 3093 | 3198 | 'not', |
| 3094 | 3199 | $selector |
| 3095 | 3200 | ) |
| 3096 | 3201 | ); |
| 3097 | - else |
|
| 3098 | - PhpQuery::debug('not'); |
|
| 3202 | + } else { |
|
| 3203 | + PhpQuery::debug('not'); |
|
| 3204 | + } |
|
| 3099 | 3205 | $stack = array(); |
| 3100 | 3206 | if ($selector instanceof self || $selector instanceof \DOMNODE) { |
| 3101 | 3207 | foreach ($this->stack() as $node) { |
| 3102 | 3208 | if ($selector instanceof self) { |
| 3103 | 3209 | $matchFound = false; |
| 3104 | 3210 | foreach ($selector->stack() as $notNode) { |
| 3105 | - if ($notNode->isSameNode($node)) |
|
| 3106 | - $matchFound = true; |
|
| 3211 | + if ($notNode->isSameNode($node)) { |
|
| 3212 | + $matchFound = true; |
|
| 3213 | + } |
|
| 3214 | + } |
|
| 3215 | + if (!$matchFound) { |
|
| 3216 | + $stack[] = $node; |
|
| 3107 | 3217 | } |
| 3108 | - if (!$matchFound) |
|
| 3109 | - $stack[] = $node; |
|
| 3110 | 3218 | } else if ($selector instanceof \DOMNODE) { |
| 3111 | - if (!$selector->isSameNode($node)) |
|
| 3112 | - $stack[] = $node; |
|
| 3219 | + if (!$selector->isSameNode($node)) { |
|
| 3220 | + $stack[] = $node; |
|
| 3221 | + } |
|
| 3113 | 3222 | } else { |
| 3114 | - if (!$this->is($selector)) |
|
| 3115 | - $stack[] = $node; |
|
| 3223 | + if (!$this->is($selector)) { |
|
| 3224 | + $stack[] = $node; |
|
| 3225 | + } |
|
| 3116 | 3226 | } |
| 3117 | 3227 | } |
| 3118 | 3228 | } else { |
@@ -3125,9 +3235,10 @@ discard block |
||
| 3125 | 3235 | // $this->filter(array($s))->stack() |
| 3126 | 3236 | // ); |
| 3127 | 3237 | // } |
| 3128 | - foreach ($orgStack as $node) |
|
| 3129 | - if (!$this->elementsContainsNode($node, $matched)) |
|
| 3238 | + foreach ($orgStack as $node) { |
|
| 3239 | + if (!$this->elementsContainsNode($node, $matched)) |
|
| 3130 | 3240 | $stack[] = $node; |
| 3241 | + } |
|
| 3131 | 3242 | } |
| 3132 | 3243 | return $this->newInstance($stack); |
| 3133 | 3244 | } |
@@ -3140,8 +3251,9 @@ discard block |
||
| 3140 | 3251 | */ |
| 3141 | 3252 | public function add($selector = null) |
| 3142 | 3253 | { |
| 3143 | - if (!$selector) |
|
| 3144 | - return $this; |
|
| 3254 | + if (!$selector) { |
|
| 3255 | + return $this; |
|
| 3256 | + } |
|
| 3145 | 3257 | $stack = array(); |
| 3146 | 3258 | $this->elementsBackup = $this->elements; |
| 3147 | 3259 | $found = PhpQuery::pq($selector, $this->getDocumentID()); |
@@ -3154,10 +3266,11 @@ discard block |
||
| 3154 | 3266 | */ |
| 3155 | 3267 | protected function merge() |
| 3156 | 3268 | { |
| 3157 | - foreach (func_get_args() as $nodes) |
|
| 3158 | - foreach ($nodes as $newNode) |
|
| 3269 | + foreach (func_get_args() as $nodes) { |
|
| 3270 | + foreach ($nodes as $newNode) |
|
| 3159 | 3271 | if (!$this->elementsContainsNode($newNode)) |
| 3160 | 3272 | $this->elements[] = $newNode; |
| 3273 | + } |
|
| 3161 | 3274 | } |
| 3162 | 3275 | |
| 3163 | 3276 | /** |
@@ -3168,8 +3281,9 @@ discard block |
||
| 3168 | 3281 | { |
| 3169 | 3282 | $loop = !is_null($elementsStack) ? $elementsStack : $this->elements; |
| 3170 | 3283 | foreach ($loop as $node) { |
| 3171 | - if ($node->isSameNode($nodeToCheck)) |
|
| 3172 | - return true; |
|
| 3284 | + if ($node->isSameNode($nodeToCheck)) { |
|
| 3285 | + return true; |
|
| 3286 | + } |
|
| 3173 | 3287 | } |
| 3174 | 3288 | return false; |
| 3175 | 3289 | } |
@@ -3183,15 +3297,17 @@ discard block |
||
| 3183 | 3297 | public function parent($selector = null) |
| 3184 | 3298 | { |
| 3185 | 3299 | $stack = array(); |
| 3186 | - foreach ($this->elements as $node) |
|
| 3187 | - if ($node->parentNode |
|
| 3300 | + foreach ($this->elements as $node) { |
|
| 3301 | + if ($node->parentNode |
|
| 3188 | 3302 | && !$this->elementsContainsNode($node->parentNode, $stack) |
| 3189 | 3303 | ) |
| 3190 | 3304 | $stack[] = $node->parentNode; |
| 3305 | + } |
|
| 3191 | 3306 | $this->elementsBackup = $this->elements; |
| 3192 | 3307 | $this->elements = $stack; |
| 3193 | - if ($selector) |
|
| 3194 | - $this->filter($selector, true); |
|
| 3308 | + if ($selector) { |
|
| 3309 | + $this->filter($selector, true); |
|
| 3310 | + } |
|
| 3195 | 3311 | return $this->newInstance(); |
| 3196 | 3312 | } |
| 3197 | 3313 | |
@@ -3204,14 +3320,16 @@ discard block |
||
| 3204 | 3320 | public function parents($selector = null) |
| 3205 | 3321 | { |
| 3206 | 3322 | $stack = array(); |
| 3207 | - if (!$this->elements) |
|
| 3208 | - $this->debug('parents() - stack empty'); |
|
| 3323 | + if (!$this->elements) { |
|
| 3324 | + $this->debug('parents() - stack empty'); |
|
| 3325 | + } |
|
| 3209 | 3326 | foreach ($this->elements as $node) { |
| 3210 | 3327 | $test = $node; |
| 3211 | 3328 | while ($test->parentNode) { |
| 3212 | 3329 | $test = $test->parentNode; |
| 3213 | - if ($this->isRoot($test)) |
|
| 3214 | - break; |
|
| 3330 | + if ($this->isRoot($test)) { |
|
| 3331 | + break; |
|
| 3332 | + } |
|
| 3215 | 3333 | if (!$this->elementsContainsNode($test, $stack)) { |
| 3216 | 3334 | $stack[] = $test; |
| 3217 | 3335 | continue; |
@@ -3220,8 +3338,9 @@ discard block |
||
| 3220 | 3338 | } |
| 3221 | 3339 | $this->elementsBackup = $this->elements; |
| 3222 | 3340 | $this->elements = $stack; |
| 3223 | - if ($selector) |
|
| 3224 | - $this->filter($selector, true); |
|
| 3341 | + if ($selector) { |
|
| 3342 | + $this->filter($selector, true); |
|
| 3343 | + } |
|
| 3225 | 3344 | return $this->newInstance(); |
| 3226 | 3345 | } |
| 3227 | 3346 | |
@@ -3234,16 +3353,19 @@ discard block |
||
| 3234 | 3353 | */ |
| 3235 | 3354 | public function stack($nodeTypes = null) |
| 3236 | 3355 | { |
| 3237 | - if (!isset($nodeTypes)) |
|
| 3238 | - return $this->elements; |
|
| 3239 | - if (!is_array($nodeTypes)) |
|
| 3240 | - $nodeTypes = array( |
|
| 3356 | + if (!isset($nodeTypes)) { |
|
| 3357 | + return $this->elements; |
|
| 3358 | + } |
|
| 3359 | + if (!is_array($nodeTypes)) { |
|
| 3360 | + $nodeTypes = array( |
|
| 3241 | 3361 | $nodeTypes |
| 3242 | 3362 | ); |
| 3363 | + } |
|
| 3243 | 3364 | $return = array(); |
| 3244 | 3365 | foreach ($this->elements as $node) { |
| 3245 | - if (in_array($node->nodeType, $nodeTypes)) |
|
| 3246 | - $return[] = $node; |
|
| 3366 | + if (in_array($node->nodeType, $nodeTypes)) { |
|
| 3367 | + $return[] = $node; |
|
| 3368 | + } |
|
| 3247 | 3369 | } |
| 3248 | 3370 | return $return; |
| 3249 | 3371 | } |
@@ -3252,8 +3374,9 @@ discard block |
||
| 3252 | 3374 | protected function attrEvents($attr, $oldAttr, $oldValue, $node) |
| 3253 | 3375 | { |
| 3254 | 3376 | // skip events for XML documents |
| 3255 | - if (!$this->isXHTML() && !$this->isHTML()) |
|
| 3256 | - return; |
|
| 3377 | + if (!$this->isXHTML() && !$this->isHTML()) { |
|
| 3378 | + return; |
|
| 3379 | + } |
|
| 3257 | 3380 | $event = null; |
| 3258 | 3381 | // identify |
| 3259 | 3382 | $isInputValue = $node->tagName == 'input' |
@@ -3331,11 +3454,13 @@ discard block |
||
| 3331 | 3454 | } else if ($attr == '*') { |
| 3332 | 3455 | // jQuery difference |
| 3333 | 3456 | $return = array(); |
| 3334 | - foreach ($node->attributes as $n => $v) |
|
| 3335 | - $return[$n] = $v->value; |
|
| 3457 | + foreach ($node->attributes as $n => $v) { |
|
| 3458 | + $return[$n] = $v->value; |
|
| 3459 | + } |
|
| 3336 | 3460 | return $return; |
| 3337 | - } else |
|
| 3338 | - return $node->hasAttribute($attr) ? $node->getAttribute($attr) : null; |
|
| 3461 | + } else { |
|
| 3462 | + return $node->hasAttribute($attr) ? $node->getAttribute($attr) : null; |
|
| 3463 | + } |
|
| 3339 | 3464 | } |
| 3340 | 3465 | return is_null($value) ? '' : $this; |
| 3341 | 3466 | } |
@@ -3362,8 +3487,9 @@ discard block |
||
| 3362 | 3487 | protected function getNodeAttrs($node) |
| 3363 | 3488 | { |
| 3364 | 3489 | $return = array(); |
| 3365 | - foreach ($node->attributes as $n => $o) |
|
| 3366 | - $return[] = $n; |
|
| 3490 | + foreach ($node->attributes as $n => $o) { |
|
| 3491 | + $return[] = $n; |
|
| 3492 | + } |
|
| 3367 | 3493 | return $return; |
| 3368 | 3494 | } |
| 3369 | 3495 | |
@@ -3393,11 +3519,13 @@ discard block |
||
| 3393 | 3519 | } else if ($attr == '*') { |
| 3394 | 3520 | // jQuery diff |
| 3395 | 3521 | $return = array(); |
| 3396 | - foreach ($node->attributes as $n => $v) |
|
| 3397 | - $return[$n] = $v->value; |
|
| 3522 | + foreach ($node->attributes as $n => $v) { |
|
| 3523 | + $return[$n] = $v->value; |
|
| 3524 | + } |
|
| 3398 | 3525 | return $return; |
| 3399 | - } else |
|
| 3400 | - return $node->getAttribute($attr); |
|
| 3526 | + } else { |
|
| 3527 | + return $node->getAttribute($attr); |
|
| 3528 | + } |
|
| 3401 | 3529 | } |
| 3402 | 3530 | return $this; |
| 3403 | 3531 | } |
@@ -3435,14 +3563,16 @@ discard block |
||
| 3435 | 3563 | if (!isset($val)) { |
| 3436 | 3564 | if ($this->eq(0)->is('select')) { |
| 3437 | 3565 | $selected = $this->eq(0)->find('option[selected=selected]'); |
| 3438 | - if ($selected->is('[value]')) |
|
| 3439 | - return $selected->attr('value'); |
|
| 3440 | - else |
|
| 3441 | - return $selected->text(); |
|
| 3442 | - } else if ($this->eq(0)->is('textarea')) |
|
| 3443 | - return $this->eq(0)->markup(); |
|
| 3444 | - else |
|
| 3445 | - return $this->eq(0)->attr('value'); |
|
| 3566 | + if ($selected->is('[value]')) { |
|
| 3567 | + return $selected->attr('value'); |
|
| 3568 | + } else { |
|
| 3569 | + return $selected->text(); |
|
| 3570 | + } |
|
| 3571 | + } else if ($this->eq(0)->is('textarea')) { |
|
| 3572 | + return $this->eq(0)->markup(); |
|
| 3573 | + } else { |
|
| 3574 | + return $this->eq(0)->attr('value'); |
|
| 3575 | + } |
|
| 3446 | 3576 | } else { |
| 3447 | 3577 | $_val = null; |
| 3448 | 3578 | foreach ($this->stack(1) as $node) { |
@@ -3458,20 +3588,22 @@ discard block |
||
| 3458 | 3588 | ) { |
| 3459 | 3589 | $isChecked = in_array($node->attr('value'), $val) |
| 3460 | 3590 | || in_array($node->attr('name'), $val); |
| 3461 | - if ($isChecked) |
|
| 3462 | - $node->attr('checked', 'checked'); |
|
| 3463 | - else |
|
| 3464 | - $node->removeAttr('checked'); |
|
| 3591 | + if ($isChecked) { |
|
| 3592 | + $node->attr('checked', 'checked'); |
|
| 3593 | + } else { |
|
| 3594 | + $node->removeAttr('checked'); |
|
| 3595 | + } |
|
| 3465 | 3596 | } else if ($node->get(0)->tagName == 'select') { |
| 3466 | 3597 | if (!isset($_val)) { |
| 3467 | 3598 | $_val = array(); |
| 3468 | - if (!is_array($val)) |
|
| 3469 | - $_val = array( |
|
| 3599 | + if (!is_array($val)) { |
|
| 3600 | + $_val = array( |
|
| 3470 | 3601 | (string) $val |
| 3471 | 3602 | ); |
| 3472 | - else |
|
| 3473 | - foreach ($val as $v) |
|
| 3603 | + } else { |
|
| 3604 | + foreach ($val as $v) |
|
| 3474 | 3605 | $_val[] = $v; |
| 3606 | + } |
|
| 3475 | 3607 | } |
| 3476 | 3608 | foreach ($node['option']->stack(1) as $option) { |
| 3477 | 3609 | $option = pq($option, $this->getDocumentID()); |
@@ -3488,15 +3620,17 @@ discard block |
||
| 3488 | 3620 | // $selected = true; |
| 3489 | 3621 | // else if ($optionText == $v && $optionTextLenght == mb_strlen($v)) |
| 3490 | 3622 | // $selected = true; |
| 3491 | - if ($selected) |
|
| 3492 | - $option->attr('selected', 'selected'); |
|
| 3493 | - else |
|
| 3494 | - $option->removeAttr('selected'); |
|
| 3623 | + if ($selected) { |
|
| 3624 | + $option->attr('selected', 'selected'); |
|
| 3625 | + } else { |
|
| 3626 | + $option->removeAttr('selected'); |
|
| 3627 | + } |
|
| 3495 | 3628 | } |
| 3496 | - } else if ($node->get(0)->tagName == 'textarea') |
|
| 3497 | - $node->markup($val); |
|
| 3498 | - else |
|
| 3499 | - $node->attr('value', $val); |
|
| 3629 | + } else if ($node->get(0)->tagName == 'textarea') { |
|
| 3630 | + $node->markup($val); |
|
| 3631 | + } else { |
|
| 3632 | + $node->attr('value', $val); |
|
| 3633 | + } |
|
| 3500 | 3634 | } |
| 3501 | 3635 | } |
| 3502 | 3636 | return $this; |
@@ -3509,8 +3643,9 @@ discard block |
||
| 3509 | 3643 | */ |
| 3510 | 3644 | public function andSelf() |
| 3511 | 3645 | { |
| 3512 | - if ($this->previous) |
|
| 3513 | - $this->elements = array_merge($this->elements, $this->previous->elements); |
|
| 3646 | + if ($this->previous) { |
|
| 3647 | + $this->elements = array_merge($this->elements, $this->previous->elements); |
|
| 3648 | + } |
|
| 3514 | 3649 | return $this; |
| 3515 | 3650 | } |
| 3516 | 3651 | |
@@ -3522,17 +3657,19 @@ discard block |
||
| 3522 | 3657 | */ |
| 3523 | 3658 | public function addClass($className) |
| 3524 | 3659 | { |
| 3525 | - if (!$className) |
|
| 3526 | - return $this; |
|
| 3660 | + if (!$className) { |
|
| 3661 | + return $this; |
|
| 3662 | + } |
|
| 3527 | 3663 | foreach ($this->stack(1) as $node) { |
| 3528 | - if (!$this->is(".$className", $node)) |
|
| 3529 | - $node->setAttribute( |
|
| 3664 | + if (!$this->is(".$className", $node)) { |
|
| 3665 | + $node->setAttribute( |
|
| 3530 | 3666 | 'class', |
| 3531 | 3667 | trim( |
| 3532 | 3668 | $node->getAttribute('class') . ' ' |
| 3533 | 3669 | . $className |
| 3534 | 3670 | ) |
| 3535 | 3671 | ); |
| 3672 | + } |
|
| 3536 | 3673 | } |
| 3537 | 3674 | return $this; |
| 3538 | 3675 | } |
@@ -3563,8 +3700,9 @@ discard block |
||
| 3563 | 3700 | public function hasClass($className) |
| 3564 | 3701 | { |
| 3565 | 3702 | foreach ($this->stack(1) as $node) { |
| 3566 | - if ($this->is(".$className", $node)) |
|
| 3567 | - return true; |
|
| 3703 | + if ($this->is(".$className", $node)) { |
|
| 3704 | + return true; |
|
| 3705 | + } |
|
| 3568 | 3706 | } |
| 3569 | 3707 | return false; |
| 3570 | 3708 | } |
@@ -3586,10 +3724,11 @@ discard block |
||
| 3586 | 3724 | $className |
| 3587 | 3725 | ) |
| 3588 | 3726 | ); |
| 3589 | - if ($classes) |
|
| 3590 | - $node->setAttribute('class', implode(' ', $classes)); |
|
| 3591 | - else |
|
| 3592 | - $node->removeAttribute('class'); |
|
| 3727 | + if ($classes) { |
|
| 3728 | + $node->setAttribute('class', implode(' ', $classes)); |
|
| 3729 | + } else { |
|
| 3730 | + $node->removeAttribute('class'); |
|
| 3731 | + } |
|
| 3593 | 3732 | } |
| 3594 | 3733 | } |
| 3595 | 3734 | return $this; |
@@ -3604,10 +3743,11 @@ discard block |
||
| 3604 | 3743 | public function toggleClass($className) |
| 3605 | 3744 | { |
| 3606 | 3745 | foreach ($this->stack(1) as $node) { |
| 3607 | - if ($this->is($node, '.' . $className)) |
|
| 3608 | - $this->removeClass($className); |
|
| 3609 | - else |
|
| 3610 | - $this->addClass($className); |
|
| 3746 | + if ($this->is($node, '.' . $className)) { |
|
| 3747 | + $this->removeClass($className); |
|
| 3748 | + } else { |
|
| 3749 | + $this->addClass($className); |
|
| 3750 | + } |
|
| 3611 | 3751 | } |
| 3612 | 3752 | return $this; |
| 3613 | 3753 | } |
@@ -3657,14 +3797,15 @@ discard block |
||
| 3657 | 3797 | $paramStructure = func_get_args(); |
| 3658 | 3798 | $paramStructure = array_slice($paramStructure, 1); |
| 3659 | 3799 | } |
| 3660 | - foreach ($this->elements as $v) |
|
| 3661 | - PhpQuery::callbackRun( |
|
| 3800 | + foreach ($this->elements as $v) { |
|
| 3801 | + PhpQuery::callbackRun( |
|
| 3662 | 3802 | $callback, |
| 3663 | 3803 | array( |
| 3664 | 3804 | $v |
| 3665 | 3805 | ), |
| 3666 | 3806 | $paramStructure |
| 3667 | 3807 | ); |
| 3808 | + } |
|
| 3668 | 3809 | return $this; |
| 3669 | 3810 | } |
| 3670 | 3811 | |
@@ -3732,8 +3873,9 @@ discard block |
||
| 3732 | 3873 | // is child which we look up doesn't exist |
| 3733 | 3874 | return PhpQuery::data($this->get(0), $key, $value, $this->getDocumentID()); |
| 3734 | 3875 | } else { |
| 3735 | - foreach ($this as $node) |
|
| 3736 | - PhpQuery::data($node, $key, $value, $this->getDocumentID()); |
|
| 3876 | + foreach ($this as $node) { |
|
| 3877 | + PhpQuery::data($node, $key, $value, $this->getDocumentID()); |
|
| 3878 | + } |
|
| 3737 | 3879 | return $this; |
| 3738 | 3880 | } |
| 3739 | 3881 | } |
@@ -3746,8 +3888,9 @@ discard block |
||
| 3746 | 3888 | */ |
| 3747 | 3889 | public function removeData($key) |
| 3748 | 3890 | { |
| 3749 | - foreach ($this as $node) |
|
| 3750 | - PhpQuery::removeData($node, $key, $this->getDocumentID()); |
|
| 3891 | + foreach ($this as $node) { |
|
| 3892 | + PhpQuery::removeData($node, $key, $this->getDocumentID()); |
|
| 3893 | + } |
|
| 3751 | 3894 | return $this; |
| 3752 | 3895 | } |
| 3753 | 3896 | // INTERFACE IMPLEMENTATIONS |
@@ -3884,8 +4027,9 @@ discard block |
||
| 3884 | 4027 | while ($sibling->previousSibling) { |
| 3885 | 4028 | $sibling = $sibling->previousSibling; |
| 3886 | 4029 | $isElement = $sibling instanceof \DOMElement; |
| 3887 | - if ($isElement && $sibling->tagName == $node->tagName) |
|
| 3888 | - $i++; |
|
| 4030 | + if ($isElement && $sibling->tagName == $node->tagName) { |
|
| 4031 | + $i++; |
|
| 4032 | + } |
|
| 3889 | 4033 | } |
| 3890 | 4034 | $xpath[] = $this->isXML() ? "*[local-name()='{$node->tagName}'][{$i}]" |
| 3891 | 4035 | : "{$node->tagName}[{$i}]"; |
@@ -3928,9 +4072,10 @@ discard block |
||
| 3928 | 4072 | : '') . ($node->getAttribute('selected') ? '[selected]' : '') |
| 3929 | 4073 | . ($node->getAttribute('checked') ? '[checked]' : ''); |
| 3930 | 4074 | } else if ($node instanceof \DOMTEXT) { |
| 3931 | - if (trim($node->textContent)) |
|
| 3932 | - $return[] = 'Text:' |
|
| 4075 | + if (trim($node->textContent)) { |
|
| 4076 | + $return[] = 'Text:' |
|
| 3933 | 4077 | . substr(str_replace("\n", ' ', $node->textContent), 0, 15); |
| 4078 | + } |
|
| 3934 | 4079 | } else { |
| 3935 | 4080 | |
| 3936 | 4081 | } |
@@ -3980,8 +4125,9 @@ discard block |
||
| 3980 | 4125 | $output = $title ? 'DUMP #' . (PhpQuery::$dumpCount++) . " \n" : ''; |
| 3981 | 4126 | $debug = PhpQuery::$debug; |
| 3982 | 4127 | PhpQuery::$debug = false; |
| 3983 | - foreach ($this->stack() as $node) |
|
| 3984 | - $output .= $this->__dumpTree($node); |
|
| 4128 | + foreach ($this->stack() as $node) { |
|
| 4129 | + $output .= $this->__dumpTree($node); |
|
| 4130 | + } |
|
| 3985 | 4131 | PhpQuery::$debug = $debug; |
| 3986 | 4132 | print $html ? nl2br(str_replace(' ', ' ', $output)) : $output; |
| 3987 | 4133 | return $this; |
@@ -3991,11 +4137,13 @@ discard block |
||
| 3991 | 4137 | { |
| 3992 | 4138 | $whois = $this->whois($node); |
| 3993 | 4139 | $return = ''; |
| 3994 | - if ($whois) |
|
| 3995 | - $return .= str_repeat(' - ', $intend) . $whois . "\n"; |
|
| 3996 | - if (isset($node->childNodes)) |
|
| 3997 | - foreach ($node->childNodes as $chNode) |
|
| 4140 | + if ($whois) { |
|
| 4141 | + $return .= str_repeat(' - ', $intend) . $whois . "\n"; |
|
| 4142 | + } |
|
| 4143 | + if (isset($node->childNodes)) { |
|
| 4144 | + foreach ($node->childNodes as $chNode) |
|
| 3998 | 4145 | $return .= $this->__dumpTree($chNode, $intend + 1); |
| 4146 | + } |
|
| 3999 | 4147 | return $return; |
| 4000 | 4148 | } |
| 4001 | 4149 | |
@@ -8,9 +8,11 @@ |
||
| 8 | 8 | foreach($self[$selector]->filter($filter) as $el) { |
| 9 | 9 | $el = pq($el, $self->getDocumentID()); |
| 10 | 10 | // imgs and scripts |
| 11 | - if ( $el->is('img') || $el->is('script') ) |
|
| 12 | - $el->attr('src', $params[0].$el->attr('src')); |
|
| 11 | + if ( $el->is('img') || $el->is('script') ) { |
|
| 12 | + $el->attr('src', $params[0].$el->attr('src')); |
|
| 13 | + } |
|
| 13 | 14 | // css |
| 14 | - if ( $el->is('link') ) |
|
| 15 | - $el->attr('href', $params[0].$el->attr('href')); |
|
| 16 | -} |
|
| 17 | 15 | \ No newline at end of file |
| 16 | + if ( $el->is('link') ) { |
|
| 17 | + $el->attr('href', $params[0].$el->attr('href')); |
|
| 18 | + } |
|
| 19 | + } |
|
| 18 | 20 | \ No newline at end of file |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | : $self->document->xhr->getUri(true); |
| 32 | 32 | // FIXME tmp |
| 33 | 33 | $self->document->WebBrowserCallback = $callback; |
| 34 | - if (! $location) |
|
| 35 | - throw new \Exception('Location needed to activate WebBrowser plugin !'); |
|
| 36 | - else { |
|
| 34 | + if (! $location) { |
|
| 35 | + throw new \Exception('Location needed to activate WebBrowser plugin !'); |
|
| 36 | + } else { |
|
| 37 | 37 | $self->bind('click', array($location, $callback), array('\PhpQuery\Plugin\UtilWebBrowser', 'hadleClick')); |
| 38 | 38 | $self->bind('submit', array($location, $callback), array('\PhpQuery\Plugin\UtilWebBrowser', 'handleSubmit')); |
| 39 | 39 | } |
@@ -43,14 +43,16 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | public static function downloadTo($self, $dir = null, $filename = null) { |
| 45 | 45 | $url = null; |
| 46 | - if ($self->is('a[href]')) |
|
| 47 | - $url = $self->attr('href'); |
|
| 48 | - else if ($self->find('a')->length) |
|
| 49 | - $url = $self->find('a')->attr('href'); |
|
| 46 | + if ($self->is('a[href]')) { |
|
| 47 | + $url = $self->attr('href'); |
|
| 48 | + } else if ($self->find('a')->length) { |
|
| 49 | + $url = $self->find('a')->attr('href'); |
|
| 50 | + } |
|
| 50 | 51 | if ($url) { |
| 51 | 52 | $url = resolve_url($self->document->location, $url); |
| 52 | - if (! $dir) |
|
| 53 | - $dir = getcwd(); |
|
| 53 | + if (! $dir) { |
|
| 54 | + $dir = getcwd(); |
|
| 55 | + } |
|
| 54 | 56 | // TODO resolv name from response headers |
| 55 | 57 | if (! $filename) { |
| 56 | 58 | $matches = null; |
@@ -84,11 +86,12 @@ discard block |
||
| 84 | 86 | $return = false; |
| 85 | 87 | if ($xhr->getLastResponse()->isSuccessful()) { |
| 86 | 88 | $return = \PhpQuery\Plugin\UtilWebBrowser::browserReceive($xhr); |
| 87 | - if (isset($self->document->WebBrowserCallback)) |
|
| 88 | - PhpQuery::callbackRun( |
|
| 89 | + if (isset($self->document->WebBrowserCallback)) { |
|
| 90 | + PhpQuery::callbackRun( |
|
| 89 | 91 | $self->document->WebBrowserCallback, |
| 90 | 92 | array($return) |
| 91 | 93 | ); |
| 94 | + } |
|
| 92 | 95 | } |
| 93 | 96 | return $return; |
| 94 | 97 | } |
@@ -104,11 +107,12 @@ discard block |
||
| 104 | 107 | $return = false; |
| 105 | 108 | if ($xhr->getLastResponse()->isSuccessful()) { |
| 106 | 109 | $return = \PhpQuery\Plugin\UtilWebBrowser::browserDownload($xhr); |
| 107 | - if (isset($self->document->WebBrowserCallback)) |
|
| 108 | - PhpQuery::callbackRun( |
|
| 110 | + if (isset($self->document->WebBrowserCallback)) { |
|
| 111 | + PhpQuery::callbackRun( |
|
| 109 | 112 | $self->document->WebBrowserCallback, |
| 110 | 113 | array($return) |
| 111 | 114 | ); |
| 115 | + } |
|
| 112 | 116 | } |
| 113 | 117 | return $return; |
| 114 | 118 | } |
@@ -184,8 +188,9 @@ discard block |
||
| 184 | 188 | // self::browserReceive($xhr)//->WebBrowser($callback) |
| 185 | 189 | // )); |
| 186 | 190 | return $xhr; |
| 187 | - } else |
|
| 188 | - return false; |
|
| 191 | + } else { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 189 | 194 | } |
| 190 | 195 | /** |
| 191 | 196 | * |
@@ -216,13 +221,15 @@ discard block |
||
| 216 | 221 | // self::browserReceive($xhr)//->WebBrowser($callback) |
| 217 | 222 | // )); |
| 218 | 223 | return $xhr; |
| 219 | - } else |
|
| 220 | - return false; |
|
| 224 | + } else { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 221 | 227 | } |
| 222 | 228 | protected static function authorizeHost($url) { |
| 223 | 229 | $host = parse_url($url, PHP_URL_HOST); |
| 224 | - if ($host) |
|
| 225 | - PhpQuery::ajaxAllowHost($host); |
|
| 230 | + if ($host) { |
|
| 231 | + PhpQuery::ajaxAllowHost($host); |
|
| 232 | + } |
|
| 226 | 233 | } |
| 227 | 234 | protected static function ajaxSettingsPrepare($settings) { |
| 228 | 235 | unset($settings['success']); |
@@ -271,8 +278,9 @@ discard block |
||
| 271 | 278 | array('\PhpQuery\Plugin\UtilWebBrowser', 'browserReceive'), array($xhr) |
| 272 | 279 | ); |
| 273 | 280 | } |
| 274 | - } else |
|
| 275 | - return $pq; |
|
| 281 | + } else { |
|
| 282 | + return $pq; |
|
| 283 | + } |
|
| 276 | 284 | } |
| 277 | 285 | |
| 278 | 286 | /** |
@@ -302,14 +310,17 @@ discard block |
||
| 302 | 310 | 'url' => resolve_url($e->data[0], $node->attr('href')), |
| 303 | 311 | 'referer' => $node->document->location, |
| 304 | 312 | ), $xhr); |
| 305 | - if ((! $callback || !($callback instanceof \Callback)) && $e->data[1]) |
|
| 306 | - $callback = $e->data[1]; |
|
| 307 | - if ($xhr->getLastResponse()->isSuccessful() && $callback) |
|
| 308 | - PhpQuery::callbackRun($callback, array( |
|
| 313 | + if ((! $callback || !($callback instanceof \Callback)) && $e->data[1]) { |
|
| 314 | + $callback = $e->data[1]; |
|
| 315 | + } |
|
| 316 | + if ($xhr->getLastResponse()->isSuccessful() && $callback) { |
|
| 317 | + PhpQuery::callbackRun($callback, array( |
|
| 309 | 318 | self::browserReceive($xhr) |
| 310 | 319 | )); |
| 311 | - } else if ($node->is(':submit') && $node->parents('form')->size()) |
|
| 312 | - $node->parents('form')->trigger('submit', array($e)); |
|
| 320 | + } |
|
| 321 | + } else if ($node->is(':submit') && $node->parents('form')->size()) { |
|
| 322 | + $node->parents('form')->trigger('submit', array($e)); |
|
| 323 | + } |
|
| 313 | 324 | } |
| 314 | 325 | |
| 315 | 326 | /** |
@@ -321,8 +332,9 @@ discard block |
||
| 321 | 332 | */ |
| 322 | 333 | public static function handleSubmit($e, $callback = null) { |
| 323 | 334 | $node = PhpQuery::pq($e->target); |
| 324 | - if (!$node->is('form') || !$node->is('[action]')) |
|
| 325 | - return; |
|
| 335 | + if (!$node->is('form') || !$node->is('[action]')) { |
|
| 336 | + return; |
|
| 337 | + } |
|
| 326 | 338 | // TODO document.location |
| 327 | 339 | $xhr = isset($node->document->xhr) |
| 328 | 340 | ? $node->document->xhr |
@@ -333,10 +345,11 @@ discard block |
||
| 333 | 345 | // : $node->find(':submit:first')->get(0); |
| 334 | 346 | : $node->find('*:submit:first')->get(0); |
| 335 | 347 | $data = array(); |
| 336 | - foreach($node->serializeArray($submit) as $r) |
|
| 337 | - // XXXt.c maybe $node->not(':submit')->add($sumit) would be better ? |
|
| 348 | + foreach($node->serializeArray($submit) as $r) { |
|
| 349 | + // XXXt.c maybe $node->not(':submit')->add($sumit) would be better ? |
|
| 338 | 350 | // foreach($node->serializeArray($submit) as $r) |
| 339 | 351 | $data[ $r['name'] ] = $r['value']; |
| 352 | + } |
|
| 340 | 353 | $options = array( |
| 341 | 354 | 'type' => $node->attr('method') |
| 342 | 355 | ? $node->attr('method') |
@@ -346,15 +359,18 @@ discard block |
||
| 346 | 359 | 'referer' => $node->document->location, |
| 347 | 360 | // 'success' => $e->data[1], |
| 348 | 361 | ); |
| 349 | - if ($node->attr('enctype')) |
|
| 350 | - $options['contentType'] = $node->attr('enctype'); |
|
| 362 | + if ($node->attr('enctype')) { |
|
| 363 | + $options['contentType'] = $node->attr('enctype'); |
|
| 364 | + } |
|
| 351 | 365 | $xhr = PhpQuery::ajax($options, $xhr); |
| 352 | - if ((! $callback || !($callback instanceof Callback)) && $e->data[1]) |
|
| 353 | - $callback = $e->data[1]; |
|
| 354 | - if ($xhr->getLastResponse()->isSuccessful() && $callback) |
|
| 355 | - PhpQuery::callbackRun($callback, array( |
|
| 366 | + if ((! $callback || !($callback instanceof Callback)) && $e->data[1]) { |
|
| 367 | + $callback = $e->data[1]; |
|
| 368 | + } |
|
| 369 | + if ($xhr->getLastResponse()->isSuccessful() && $callback) { |
|
| 370 | + PhpQuery::callbackRun($callback, array( |
|
| 356 | 371 | self::browserReceive($xhr) |
| 357 | 372 | )); |
| 373 | + } |
|
| 358 | 374 | } |
| 359 | 375 | } |
| 360 | 376 | /** |
@@ -364,7 +380,9 @@ discard block |
||
| 364 | 380 | */ |
| 365 | 381 | function glue_url($parsed) |
| 366 | 382 | { |
| 367 | - if (! is_array($parsed)) return false; |
|
| 383 | + if (! is_array($parsed)) { |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 368 | 386 | $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '':'//'): ''; |
| 369 | 387 | $uri .= isset($parsed['user']) ? $parsed['user'].($parsed['pass']? ':'.$parsed['pass']:'').'@':''; |
| 370 | 388 | $uri .= isset($parsed['host']) ? $parsed['host'] : ''; |
@@ -383,11 +401,17 @@ discard block |
||
| 383 | 401 | * @author adrian-php at sixfingeredman dot net |
| 384 | 402 | */ |
| 385 | 403 | function resolve_url($base, $url) { |
| 386 | - if (!strlen($base)) return $url; |
|
| 404 | + if (!strlen($base)) { |
|
| 405 | + return $url; |
|
| 406 | + } |
|
| 387 | 407 | // Step 2 |
| 388 | - if (!strlen($url)) return $base; |
|
| 408 | + if (!strlen($url)) { |
|
| 409 | + return $base; |
|
| 410 | + } |
|
| 389 | 411 | // Step 3 |
| 390 | - if (preg_match('!^[a-z]+:!i', $url)) return $url; |
|
| 412 | + if (preg_match('!^[a-z]+:!i', $url)) { |
|
| 413 | + return $url; |
|
| 414 | + } |
|
| 391 | 415 | $base = parse_url($base); |
| 392 | 416 | if ($url{0} == "#") { |
| 393 | 417 | // Step 2 (fragment) |
@@ -72,8 +72,9 @@ |
||
| 72 | 72 | * @return bool |
| 73 | 73 | */ |
| 74 | 74 | public static function script($name, $callback) { |
| 75 | - if (\PhpQuery\Plugin\UtilScripts::$scriptMethods[$name]) |
|
| 76 | - throw new \Exception("Script name conflict - '$name'"); |
|
| 75 | + if (\PhpQuery\Plugin\UtilScripts::$scriptMethods[$name]) { |
|
| 76 | + throw new \Exception("Script name conflict - '$name'"); |
|
| 77 | + } |
|
| 77 | 78 | \PhpQuery\Plugin\UtilScripts::$scriptMethods[$name] = $callback; |
| 78 | 79 | } |
| 79 | 80 | } |
| 80 | 81 | \ No newline at end of file |
@@ -33,13 +33,15 @@ discard block |
||
| 33 | 33 | include_once(dirname(__FILE__) . '/../PhpQuery/PhpQuery.php'); |
| 34 | 34 | if (file_exists(dirname(__FILE__) . '/jQueryServer.config.php')) { |
| 35 | 35 | include_once(dirname(__FILE__) . '/jQueryServer.config.php'); |
| 36 | - if ($jQueryServerConfig) |
|
| 37 | - $this->config = array_merge_recursive($this->config, $jQueryServerConfig); |
|
| 36 | + if ($jQueryServerConfig) { |
|
| 37 | + $this->config = array_merge_recursive($this->config, $jQueryServerConfig); |
|
| 38 | + } |
|
| 38 | 39 | } |
| 39 | 40 | if ($this->config['refererMustMatch']) { |
| 40 | - foreach ($this->config['allowedRefererHosts'] as $i => $host) |
|
| 41 | - if ($host == '.') |
|
| 41 | + foreach ($this->config['allowedRefererHosts'] as $i => $host) { |
|
| 42 | + if ($host == '.') |
|
| 42 | 43 | $this->config['allowedRefererHosts'][$i] = $_SERVER['HTTP_HOST']; |
| 44 | + } |
|
| 43 | 45 | $referer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); |
| 44 | 46 | $authorized = $referer |
| 45 | 47 | && in_array($referer, $this->config['allowedRefererHosts']); |
@@ -65,8 +67,7 @@ discard block |
||
| 65 | 67 | 'success' |
| 66 | 68 | ); |
| 67 | 69 | PhpQuery::ajax($ajax); |
| 68 | - } |
|
| 69 | - else { |
|
| 70 | + } else { |
|
| 70 | 71 | throw new \Exception("URL needed to download content"); |
| 71 | 72 | } |
| 72 | 73 | } |
@@ -77,25 +78,25 @@ discard block |
||
| 77 | 78 | if (!method_exists(get_class($pq), $r['method'])) { |
| 78 | 79 | throw new \Exception("Method '{$r['method']}' not implemented in PhpQuery, sorry..."); |
| 79 | 80 | // execute method |
| 80 | - } |
|
| 81 | - else { |
|
| 81 | + } else { |
|
| 82 | 82 | $pq = call_user_func_array(array( |
| 83 | 83 | $pq, |
| 84 | 84 | $r['method'] |
| 85 | 85 | ), $r['arguments']); |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | - if (!isset($this->options['dataType'])) |
|
| 89 | - $this->options['dataType'] = ''; |
|
| 88 | + if (!isset($this->options['dataType'])) { |
|
| 89 | + $this->options['dataType'] = ''; |
|
| 90 | + } |
|
| 90 | 91 | switch (strtolower($this->options['dataType'])) { |
| 91 | 92 | case 'json': |
| 92 | 93 | if ($pq instanceof PhpQueryObject) { |
| 93 | 94 | $results = array(); |
| 94 | - foreach ($pq as $node) |
|
| 95 | - $results[] = pq($node)->htmlOuter(); |
|
| 95 | + foreach ($pq as $node) { |
|
| 96 | + $results[] = pq($node)->htmlOuter(); |
|
| 97 | + } |
|
| 96 | 98 | print PhpQuery::toJSON($results); |
| 97 | - } |
|
| 98 | - else { |
|
| 99 | + } else { |
|
| 99 | 100 | print PhpQuery::toJSON($pq); |
| 100 | 101 | } |
| 101 | 102 | break; |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | $test = PhpQuery::newDocumentFile('test.html') |
| 36 | 36 | ->find('div:first') |
| 37 | 37 | ->load('http://wikipedia.org/ div[lang]'); |
| 38 | -if (pq('div[lang]')->size()) |
|
| 38 | +if (pq('div[lang]')->size()) { |
|
| 39 | 39 | print "Test '$testName' PASSED :)"; |
| 40 | -else { |
|
| 40 | +} else { |
|
| 41 | 41 | print "Test '$testName' <strong>FAILED</strong> !!! "; |
| 42 | 42 | print "<pre>"; |
| 43 | 43 | print "</pre>\n"; |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | )); |
| 54 | 54 | function a789fhasdui3124($html) { |
| 55 | 55 | $testName = 'AJAX request text node'; |
| 56 | - if ( $html == 'hello world' ) |
|
| 57 | - print "Test '$testName' PASSED :)"; |
|
| 58 | - else { |
|
| 56 | + if ( $html == 'hello world' ) { |
|
| 57 | + print "Test '$testName' PASSED :)"; |
|
| 58 | + } else { |
|
| 59 | 59 | print "Test '$testName' <strong>FAILED</strong> !!! "; |
| 60 | 60 | } |
| 61 | 61 | print "\n"; |
@@ -8,9 +8,9 @@ discard block |
||
| 8 | 8 | $testName = 'Scripts/example'; |
| 9 | 9 | $doc = PhpQuery::newDocumentFile('test.html'); |
| 10 | 10 | $testResult = 10; |
| 11 | -if ($doc->script('example', 'p')->length == $testResult) |
|
| 11 | +if ($doc->script('example', 'p')->length == $testResult) { |
|
| 12 | 12 | print "Test '$testName' PASSED :)"; |
| 13 | -else { |
|
| 13 | +} else { |
|
| 14 | 14 | print "Test '$testName' <strong>FAILED</strong> !!! "; |
| 15 | 15 | print "<pre>"; |
| 16 | 16 | var_dump($doc->whois()); |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | $editor = PhpQuery::newDocument('<div/>') |
| 27 | 27 | ->script('google_login') |
| 28 | 28 | ->location($url); |
| 29 | -if ($editor->find('textarea#content')->length == $testResult) |
|
| 29 | +if ($editor->find('textarea#content')->length == $testResult) { |
|
| 30 | 30 | print "Test '$testName' PASSED :)"; |
| 31 | -else { |
|
| 31 | +} else { |
|
| 32 | 32 | print "Test '$testName' <strong>FAILED</strong> !!! "; |
| 33 | 33 | print "<pre>"; |
| 34 | 34 | var_dump($doc->whois()); |
@@ -7,20 +7,23 @@ |
||
| 7 | 7 | $result = PhpQuery::newDocumentFile('test.html') |
| 8 | 8 | ->find('p[rel]:first') |
| 9 | 9 | ->attr('rel', $expected); |
| 10 | -if ($result->attr('rel') == $expected) |
|
| 10 | +if ($result->attr('rel') == $expected) { |
|
| 11 | 11 | print "Test '{$testName}' passed :)"; |
| 12 | -else |
|
| 12 | +} else { |
|
| 13 | 13 | print "Test '{$testName}' <strong>FAILED</strong> !!!"; |
| 14 | +} |
|
| 14 | 15 | print "\n"; |
| 15 | 16 | |
| 16 | 17 | |
| 17 | 18 | $testName = 'Attribute change in iteration'; |
| 18 | 19 | $expected = 'new attr value'; |
| 19 | 20 | $doc = PhpQuery::newDocumentFile('test.html'); |
| 20 | -foreach($doc['p[rel]:first'] as $p) |
|
| 21 | +foreach($doc['p[rel]:first'] as $p) { |
|
| 21 | 22 | pq($p)->attr('rel', $expected); |
| 22 | -if ($doc['p[rel]:first']->attr('rel') == $expected) |
|
| 23 | +} |
|
| 24 | +if ($doc['p[rel]:first']->attr('rel') == $expected) { |
|
| 23 | 25 | print "Test '{$testName}' passed :)"; |
| 24 | -else |
|
| 26 | +} else { |
|
| 25 | 27 | print "Test '{$testName}' <strong>FAILED</strong> !!!"; |
| 28 | +} |
|
| 26 | 29 | print "\n"; |
| 27 | 30 | \ No newline at end of file |