@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public static $PhpQueryMethods = null; |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Enter description here... |
|
| 19 | - * |
|
| 20 | - * @param \PhpQuery\PhpQueryObject $self |
|
| 21 | - * @param null $callback |
|
| 22 | - * @param null $location |
|
| 23 | - * @throws \Exception |
|
| 24 | - * @todo support 'reset' event |
|
| 25 | - */ |
|
| 17 | + /** |
|
| 18 | + * Enter description here... |
|
| 19 | + * |
|
| 20 | + * @param \PhpQuery\PhpQueryObject $self |
|
| 21 | + * @param null $callback |
|
| 22 | + * @param null $location |
|
| 23 | + * @throws \Exception |
|
| 24 | + * @todo support 'reset' event |
|
| 25 | + */ |
|
| 26 | 26 | public static function WebBrowser($self, $callback = null, $location = null) { |
| 27 | 27 | $self = $self->_clone()->toRoot(); |
| 28 | 28 | $location = $location |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | return $self; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Method changing browser location. |
|
| 71 | - * Fires callback registered with WebBrowser(), if any. |
|
| 72 | - * @param $self |
|
| 73 | - * @param $url |
|
| 74 | - * @return bool |
|
| 75 | - */ |
|
| 69 | + /** |
|
| 70 | + * Method changing browser location. |
|
| 71 | + * Fires callback registered with WebBrowser(), if any. |
|
| 72 | + * @param $self |
|
| 73 | + * @param $url |
|
| 74 | + * @return bool |
|
| 75 | + */ |
|
| 76 | 76 | public static function location($self, $url = null) { |
| 77 | 77 | // TODO if ! $url return actual location ??? |
| 78 | 78 | $xhr = isset($self->document->xhr) |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
| 97 | - public static function download($self, $url = null) { |
|
| 98 | - $xhr = isset($self->document->xhr) |
|
| 97 | + public static function download($self, $url = null) { |
|
| 98 | + $xhr = isset($self->document->xhr) |
|
| 99 | 99 | ? $self->document->xhr |
| 100 | 100 | : null; |
| 101 | 101 | $xhr = PhpQuery::ajax(array( |
@@ -111,19 +111,19 @@ discard block |
||
| 111 | 111 | ); |
| 112 | 112 | } |
| 113 | 113 | return $return; |
| 114 | - } |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | class UtilWebBrowser { |
| 117 | - /** |
|
| 118 | - * |
|
| 119 | - * @param $url |
|
| 120 | - * @param $callback |
|
| 121 | - * @param $param1 |
|
| 122 | - * @param $param2 |
|
| 123 | - * @param $param3 |
|
| 124 | - * @throws \Exception |
|
| 125 | - * @return \Zend_Http_Client |
|
| 126 | - */ |
|
| 117 | + /** |
|
| 118 | + * |
|
| 119 | + * @param $url |
|
| 120 | + * @param $callback |
|
| 121 | + * @param $param1 |
|
| 122 | + * @param $param2 |
|
| 123 | + * @param $param3 |
|
| 124 | + * @throws \Exception |
|
| 125 | + * @return \Zend_Http_Client |
|
| 126 | + */ |
|
| 127 | 127 | public static function browserGet($url, $callback, |
| 128 | 128 | $param1 = null, $param2 = null, $param3 = null) { |
| 129 | 129 | PhpQuery::debug("[WebBrowser] GET: $url"); |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | return $pq; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * @param Zend_Http_Client $xhr |
|
| 280 | - */ |
|
| 278 | + /** |
|
| 279 | + * @param Zend_Http_Client $xhr |
|
| 280 | + */ |
|
| 281 | 281 | public static function browserDownload($xhr) { |
| 282 | 282 | PhpQuery::debug("[WebBrowser] Received from ".$xhr->getUri(true)); |
| 283 | 283 | // TODO handle meta redirects |
@@ -286,11 +286,11 @@ discard block |
||
| 286 | 286 | return $body; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * @param $e |
|
| 291 | - * @param null $callback |
|
| 292 | - */ |
|
| 293 | - public static function hadleClick($e, $callback = null) { |
|
| 289 | + /** |
|
| 290 | + * @param $e |
|
| 291 | + * @param null $callback |
|
| 292 | + */ |
|
| 293 | + public static function hadleClick($e, $callback = null) { |
|
| 294 | 294 | $node = PhpQuery::pq($e->target); |
| 295 | 295 | $type = null; |
| 296 | 296 | if ($node->is('a[href]')) { |
@@ -312,13 +312,13 @@ discard block |
||
| 312 | 312 | $node->parents('form')->trigger('submit', array($e)); |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Enter description here... |
|
| 317 | - * |
|
| 318 | - * @TODO trigger submit for form after form's submit button has a click event |
|
| 319 | - * @param $e |
|
| 320 | - * @param null $callback |
|
| 321 | - */ |
|
| 315 | + /** |
|
| 316 | + * Enter description here... |
|
| 317 | + * |
|
| 318 | + * @TODO trigger submit for form after form's submit button has a click event |
|
| 319 | + * @param $e |
|
| 320 | + * @param null $callback |
|
| 321 | + */ |
|
| 322 | 322 | public static function handleSubmit($e, $callback = null) { |
| 323 | 323 | $node = PhpQuery::pq($e->target); |
| 324 | 324 | if (!$node->is('form') || !$node->is('[action]')) |
@@ -363,91 +363,91 @@ discard block |
||
| 363 | 363 | * @author stevenlewis at hotmail dot com |
| 364 | 364 | */ |
| 365 | 365 | function glue_url($parsed) |
| 366 | - { |
|
| 367 | - if (! is_array($parsed)) return false; |
|
| 368 | - $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '':'//'): ''; |
|
| 369 | - $uri .= isset($parsed['user']) ? $parsed['user'].($parsed['pass']? ':'.$parsed['pass']:'').'@':''; |
|
| 370 | - $uri .= isset($parsed['host']) ? $parsed['host'] : ''; |
|
| 371 | - $uri .= isset($parsed['port']) ? ':'.$parsed['port'] : ''; |
|
| 372 | - if(isset($parsed['path'])) |
|
| 373 | - { |
|
| 374 | - $uri .= (substr($parsed['path'],0,1) == '/')?$parsed['path']:'/'.$parsed['path']; |
|
| 375 | - } |
|
| 376 | - $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : ''; |
|
| 377 | - $uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : ''; |
|
| 378 | - return $uri; |
|
| 379 | - } |
|
| 366 | + { |
|
| 367 | + if (! is_array($parsed)) return false; |
|
| 368 | + $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '':'//'): ''; |
|
| 369 | + $uri .= isset($parsed['user']) ? $parsed['user'].($parsed['pass']? ':'.$parsed['pass']:'').'@':''; |
|
| 370 | + $uri .= isset($parsed['host']) ? $parsed['host'] : ''; |
|
| 371 | + $uri .= isset($parsed['port']) ? ':'.$parsed['port'] : ''; |
|
| 372 | + if(isset($parsed['path'])) |
|
| 373 | + { |
|
| 374 | + $uri .= (substr($parsed['path'],0,1) == '/')?$parsed['path']:'/'.$parsed['path']; |
|
| 375 | + } |
|
| 376 | + $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : ''; |
|
| 377 | + $uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : ''; |
|
| 378 | + return $uri; |
|
| 379 | + } |
|
| 380 | 380 | /** |
| 381 | - * Enter description here... |
|
| 382 | - * |
|
| 383 | - * @author adrian-php at sixfingeredman dot net |
|
| 384 | - */ |
|
| 381 | + * Enter description here... |
|
| 382 | + * |
|
| 383 | + * @author adrian-php at sixfingeredman dot net |
|
| 384 | + */ |
|
| 385 | 385 | function resolve_url($base, $url) { |
| 386 | - if (!strlen($base)) return $url; |
|
| 387 | - // Step 2 |
|
| 388 | - if (!strlen($url)) return $base; |
|
| 389 | - // Step 3 |
|
| 390 | - if (preg_match('!^[a-z]+:!i', $url)) return $url; |
|
| 391 | - $base = parse_url($base); |
|
| 392 | - if ($url{0} == "#") { |
|
| 393 | - // Step 2 (fragment) |
|
| 394 | - $base['fragment'] = substr($url, 1); |
|
| 395 | - return unparse_url($base); |
|
| 396 | - } |
|
| 397 | - unset($base['fragment']); |
|
| 398 | - unset($base['query']); |
|
| 399 | - if (substr($url, 0, 2) == "//") { |
|
| 400 | - // Step 4 |
|
| 401 | - return unparse_url(array( |
|
| 402 | - 'scheme'=>$base['scheme'], |
|
| 403 | - 'path'=>substr($url,2), |
|
| 404 | - )); |
|
| 405 | - } else if ($url{0} == "/") { |
|
| 406 | - // Step 5 |
|
| 407 | - $base['path'] = $url; |
|
| 408 | - } else { |
|
| 409 | - // Step 6 |
|
| 410 | - $path = explode('/', $base['path']); |
|
| 411 | - $url_path = explode('/', $url); |
|
| 412 | - // Step 6a: drop file from base |
|
| 413 | - array_pop($path); |
|
| 414 | - // Step 6b, 6c, 6e: append url while removing "." and ".." from |
|
| 415 | - // the directory portion |
|
| 416 | - $end = array_pop($url_path); |
|
| 417 | - foreach ($url_path as $segment) { |
|
| 418 | - if ($segment == '.') { |
|
| 419 | - // skip |
|
| 420 | - } else if ($segment == '..' && $path && $path[sizeof($path)-1] != '..') { |
|
| 421 | - array_pop($path); |
|
| 422 | - } else { |
|
| 423 | - $path[] = $segment; |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - // Step 6d, 6f: remove "." and ".." from file portion |
|
| 427 | - if ($end == '.') { |
|
| 428 | - $path[] = ''; |
|
| 429 | - } else if ($end == '..' && $path && $path[sizeof($path)-1] != '..') { |
|
| 430 | - $path[sizeof($path)-1] = ''; |
|
| 431 | - } else { |
|
| 432 | - $path[] = $end; |
|
| 433 | - } |
|
| 434 | - // Step 6h |
|
| 435 | - $base['path'] = join('/', $path); |
|
| 386 | + if (!strlen($base)) return $url; |
|
| 387 | + // Step 2 |
|
| 388 | + if (!strlen($url)) return $base; |
|
| 389 | + // Step 3 |
|
| 390 | + if (preg_match('!^[a-z]+:!i', $url)) return $url; |
|
| 391 | + $base = parse_url($base); |
|
| 392 | + if ($url{0} == "#") { |
|
| 393 | + // Step 2 (fragment) |
|
| 394 | + $base['fragment'] = substr($url, 1); |
|
| 395 | + return unparse_url($base); |
|
| 396 | + } |
|
| 397 | + unset($base['fragment']); |
|
| 398 | + unset($base['query']); |
|
| 399 | + if (substr($url, 0, 2) == "//") { |
|
| 400 | + // Step 4 |
|
| 401 | + return unparse_url(array( |
|
| 402 | + 'scheme'=>$base['scheme'], |
|
| 403 | + 'path'=>substr($url,2), |
|
| 404 | + )); |
|
| 405 | + } else if ($url{0} == "/") { |
|
| 406 | + // Step 5 |
|
| 407 | + $base['path'] = $url; |
|
| 408 | + } else { |
|
| 409 | + // Step 6 |
|
| 410 | + $path = explode('/', $base['path']); |
|
| 411 | + $url_path = explode('/', $url); |
|
| 412 | + // Step 6a: drop file from base |
|
| 413 | + array_pop($path); |
|
| 414 | + // Step 6b, 6c, 6e: append url while removing "." and ".." from |
|
| 415 | + // the directory portion |
|
| 416 | + $end = array_pop($url_path); |
|
| 417 | + foreach ($url_path as $segment) { |
|
| 418 | + if ($segment == '.') { |
|
| 419 | + // skip |
|
| 420 | + } else if ($segment == '..' && $path && $path[sizeof($path)-1] != '..') { |
|
| 421 | + array_pop($path); |
|
| 422 | + } else { |
|
| 423 | + $path[] = $segment; |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + // Step 6d, 6f: remove "." and ".." from file portion |
|
| 427 | + if ($end == '.') { |
|
| 428 | + $path[] = ''; |
|
| 429 | + } else if ($end == '..' && $path && $path[sizeof($path)-1] != '..') { |
|
| 430 | + $path[sizeof($path)-1] = ''; |
|
| 431 | + } else { |
|
| 432 | + $path[] = $end; |
|
| 433 | + } |
|
| 434 | + // Step 6h |
|
| 435 | + $base['path'] = join('/', $path); |
|
| 436 | 436 | |
| 437 | - } |
|
| 438 | - // Step 7 |
|
| 439 | - return glue_url($base); |
|
| 437 | + } |
|
| 438 | + // Step 7 |
|
| 439 | + return glue_url($base); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | function unparse_url($parsed_url) { |
| 443 | - $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; |
|
| 444 | - $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; |
|
| 445 | - $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; |
|
| 446 | - $user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; |
|
| 447 | - $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; |
|
| 448 | - $pass = ($user || $pass) ? "$pass@" : ''; |
|
| 449 | - $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; |
|
| 450 | - $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; |
|
| 451 | - $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; |
|
| 452 | - return "$scheme$user$pass$host$port$path$query$fragment"; |
|
| 443 | + $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; |
|
| 444 | + $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; |
|
| 445 | + $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; |
|
| 446 | + $user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; |
|
| 447 | + $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; |
|
| 448 | + $pass = ($user || $pass) ? "$pass@" : ''; |
|
| 449 | + $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; |
|
| 450 | + $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; |
|
| 451 | + $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; |
|
| 452 | + return "$scheme$user$pass$host$port$path$query$fragment"; |
|
| 453 | 453 | } |
| 454 | 454 | \ No newline at end of file |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | : $self->document->xhr->getUri(true); |
| 32 | 32 | // FIXME tmp |
| 33 | 33 | $self->document->WebBrowserCallback = $callback; |
| 34 | - if (! $location) |
|
| 34 | + if (!$location) |
|
| 35 | 35 | throw new \Exception('Location needed to activate WebBrowser plugin !'); |
| 36 | 36 | else { |
| 37 | 37 | $self->bind('click', array($location, $callback), array('\PhpQuery\Plugin\UtilWebBrowser', 'hadleClick')); |
@@ -49,10 +49,10 @@ discard block |
||
| 49 | 49 | $url = $self->find('a')->attr('href'); |
| 50 | 50 | if ($url) { |
| 51 | 51 | $url = resolve_url($self->document->location, $url); |
| 52 | - if (! $dir) |
|
| 52 | + if (!$dir) |
|
| 53 | 53 | $dir = getcwd(); |
| 54 | 54 | // TODO resolv name from response headers |
| 55 | - if (! $filename) { |
|
| 55 | + if (!$filename) { |
|
| 56 | 56 | $matches = null; |
| 57 | 57 | preg_match('@/([^/]+)$@', $url, $matches); |
| 58 | 58 | $filename = $matches[1]; |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | PhpQuery::debug("Meta redirect... '{$refresh->attr('content')}'\n"); |
| 255 | 255 | // there is a refresh, so get the new url |
| 256 | 256 | $content = $refresh->attr('content'); |
| 257 | - $urlRefresh = substr($content, strpos($content, '=')+1); |
|
| 257 | + $urlRefresh = substr($content, strpos($content, '=') + 1); |
|
| 258 | 258 | $urlRefresh = trim($urlRefresh, '\'"'); |
| 259 | 259 | // XXX not secure ?! |
| 260 | 260 | PhpQuery::ajaxAllowURL($urlRefresh); |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | 'url' => resolve_url($e->data[0], $node->attr('href')), |
| 303 | 303 | 'referer' => $node->document->location, |
| 304 | 304 | ), $xhr); |
| 305 | - if ((! $callback || !($callback instanceof \Callback)) && $e->data[1]) |
|
| 305 | + if ((!$callback || !($callback instanceof \Callback)) && $e->data[1]) |
|
| 306 | 306 | $callback = $e->data[1]; |
| 307 | 307 | if ($xhr->getLastResponse()->isSuccessful() && $callback) |
| 308 | 308 | PhpQuery::callbackRun($callback, array( |
@@ -333,10 +333,10 @@ discard block |
||
| 333 | 333 | // : $node->find(':submit:first')->get(0); |
| 334 | 334 | : $node->find('*:submit:first')->get(0); |
| 335 | 335 | $data = array(); |
| 336 | - foreach($node->serializeArray($submit) as $r) |
|
| 336 | + foreach ($node->serializeArray($submit) as $r) |
|
| 337 | 337 | // XXXt.c maybe $node->not(':submit')->add($sumit) would be better ? |
| 338 | 338 | // foreach($node->serializeArray($submit) as $r) |
| 339 | - $data[ $r['name'] ] = $r['value']; |
|
| 339 | + $data[$r['name']] = $r['value']; |
|
| 340 | 340 | $options = array( |
| 341 | 341 | 'type' => $node->attr('method') |
| 342 | 342 | ? $node->attr('method') |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | if ($node->attr('enctype')) |
| 350 | 350 | $options['contentType'] = $node->attr('enctype'); |
| 351 | 351 | $xhr = PhpQuery::ajax($options, $xhr); |
| 352 | - if ((! $callback || !($callback instanceof Callback)) && $e->data[1]) |
|
| 352 | + if ((!$callback || !($callback instanceof Callback)) && $e->data[1]) |
|
| 353 | 353 | $callback = $e->data[1]; |
| 354 | 354 | if ($xhr->getLastResponse()->isSuccessful() && $callback) |
| 355 | 355 | PhpQuery::callbackRun($callback, array( |
@@ -364,14 +364,14 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | function glue_url($parsed) |
| 366 | 366 | { |
| 367 | - if (! is_array($parsed)) return false; |
|
| 368 | - $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '':'//'): ''; |
|
| 369 | - $uri .= isset($parsed['user']) ? $parsed['user'].($parsed['pass']? ':'.$parsed['pass']:'').'@':''; |
|
| 367 | + if (!is_array($parsed)) return false; |
|
| 368 | + $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : ''; |
|
| 369 | + $uri .= isset($parsed['user']) ? $parsed['user'].($parsed['pass'] ? ':'.$parsed['pass'] : '').'@' : ''; |
|
| 370 | 370 | $uri .= isset($parsed['host']) ? $parsed['host'] : ''; |
| 371 | 371 | $uri .= isset($parsed['port']) ? ':'.$parsed['port'] : ''; |
| 372 | - if(isset($parsed['path'])) |
|
| 372 | + if (isset($parsed['path'])) |
|
| 373 | 373 | { |
| 374 | - $uri .= (substr($parsed['path'],0,1) == '/')?$parsed['path']:'/'.$parsed['path']; |
|
| 374 | + $uri .= (substr($parsed['path'], 0, 1) == '/') ? $parsed['path'] : '/'.$parsed['path']; |
|
| 375 | 375 | } |
| 376 | 376 | $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : ''; |
| 377 | 377 | $uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : ''; |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | // Step 4 |
| 401 | 401 | return unparse_url(array( |
| 402 | 402 | 'scheme'=>$base['scheme'], |
| 403 | - 'path'=>substr($url,2), |
|
| 403 | + 'path'=>substr($url, 2), |
|
| 404 | 404 | )); |
| 405 | 405 | } else if ($url{0} == "/") { |
| 406 | 406 | // Step 5 |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | foreach ($url_path as $segment) { |
| 418 | 418 | if ($segment == '.') { |
| 419 | 419 | // skip |
| 420 | - } else if ($segment == '..' && $path && $path[sizeof($path)-1] != '..') { |
|
| 420 | + } else if ($segment == '..' && $path && $path[sizeof($path) - 1] != '..') { |
|
| 421 | 421 | array_pop($path); |
| 422 | 422 | } else { |
| 423 | 423 | $path[] = $segment; |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | // Step 6d, 6f: remove "." and ".." from file portion |
| 427 | 427 | if ($end == '.') { |
| 428 | 428 | $path[] = ''; |
| 429 | - } else if ($end == '..' && $path && $path[sizeof($path)-1] != '..') { |
|
| 430 | - $path[sizeof($path)-1] = ''; |
|
| 429 | + } else if ($end == '..' && $path && $path[sizeof($path) - 1] != '..') { |
|
| 430 | + $path[sizeof($path) - 1] = ''; |
|
| 431 | 431 | } else { |
| 432 | 432 | $path[] = $end; |
| 433 | 433 | } |
@@ -440,14 +440,14 @@ discard block |
||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | function unparse_url($parsed_url) { |
| 443 | - $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; |
|
| 443 | + $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : ''; |
|
| 444 | 444 | $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; |
| 445 | - $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; |
|
| 445 | + $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : ''; |
|
| 446 | 446 | $user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; |
| 447 | - $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; |
|
| 447 | + $pass = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : ''; |
|
| 448 | 448 | $pass = ($user || $pass) ? "$pass@" : ''; |
| 449 | 449 | $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; |
| 450 | - $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; |
|
| 451 | - $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; |
|
| 450 | + $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : ''; |
|
| 451 | + $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : ''; |
|
| 452 | 452 | return "$scheme$user$pass$host$port$path$query$fragment"; |
| 453 | 453 | } |
| 454 | 454 | \ 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) |
@@ -20,89 +20,89 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class jQueryServer { |
| 22 | 22 | public $config = array( |
| 23 | - 'allowedRefererHosts' => array( |
|
| 24 | - '.' |
|
| 25 | - ), |
|
| 26 | - 'refererMustMatch' => true, |
|
| 23 | + 'allowedRefererHosts' => array( |
|
| 24 | + '.' |
|
| 25 | + ), |
|
| 26 | + 'refererMustMatch' => true, |
|
| 27 | 27 | ); |
| 28 | 28 | public $calls = null; |
| 29 | 29 | public $options = null; |
| 30 | 30 | public $allowedHosts = null; |
| 31 | 31 | function __construct($data) { |
| 32 | - $pq = null; |
|
| 33 | - include_once(dirname(__FILE__) . '/../PhpQuery/PhpQuery.php'); |
|
| 34 | - if (file_exists(dirname(__FILE__) . '/jQueryServer.config.php')) { |
|
| 35 | - include_once(dirname(__FILE__) . '/jQueryServer.config.php'); |
|
| 36 | - if ($jQueryServerConfig) |
|
| 37 | - $this->config = array_merge_recursive($this->config, $jQueryServerConfig); |
|
| 38 | - } |
|
| 39 | - if ($this->config['refererMustMatch']) { |
|
| 40 | - foreach ($this->config['allowedRefererHosts'] as $i => $host) |
|
| 41 | - if ($host == '.') |
|
| 42 | - $this->config['allowedRefererHosts'][$i] = $_SERVER['HTTP_HOST']; |
|
| 43 | - $referer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); |
|
| 44 | - $authorized = $referer |
|
| 45 | - && in_array($referer, $this->config['allowedRefererHosts']); |
|
| 46 | - if (!$authorized) { |
|
| 47 | - throw new \Exception("Host '{$_SERVER['HTTP_REFERER']}' not authorized to make requests."); |
|
| 48 | - return; |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - // PhpQueryClass::$debug = true; |
|
| 52 | - // if (! function_exists('json_decode')) { |
|
| 53 | - // include_once(dirname(__FILE__).'/JSON.php'); |
|
| 54 | - // $this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); |
|
| 55 | - // } |
|
| 56 | - // $data = $this->jsonDecode($data); |
|
| 57 | - $data = PhpQuery::parseJSON($data); |
|
| 58 | - // load document (required for first $data element) |
|
| 59 | - if (is_array($data[0]) && isset($data[0]['url'])) { |
|
| 60 | - $this->options = $data[0]; |
|
| 61 | - $ajax = $this->options; |
|
| 62 | - $this->calls = array_slice($data, 1); |
|
| 63 | - $ajax['success'] = array( |
|
| 64 | - $this, |
|
| 65 | - 'success' |
|
| 66 | - ); |
|
| 67 | - PhpQuery::ajax($ajax); |
|
| 68 | - } |
|
| 69 | - else { |
|
| 70 | - throw new \Exception("URL needed to download content"); |
|
| 71 | - } |
|
| 32 | + $pq = null; |
|
| 33 | + include_once(dirname(__FILE__) . '/../PhpQuery/PhpQuery.php'); |
|
| 34 | + if (file_exists(dirname(__FILE__) . '/jQueryServer.config.php')) { |
|
| 35 | + include_once(dirname(__FILE__) . '/jQueryServer.config.php'); |
|
| 36 | + if ($jQueryServerConfig) |
|
| 37 | + $this->config = array_merge_recursive($this->config, $jQueryServerConfig); |
|
| 38 | + } |
|
| 39 | + if ($this->config['refererMustMatch']) { |
|
| 40 | + foreach ($this->config['allowedRefererHosts'] as $i => $host) |
|
| 41 | + if ($host == '.') |
|
| 42 | + $this->config['allowedRefererHosts'][$i] = $_SERVER['HTTP_HOST']; |
|
| 43 | + $referer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); |
|
| 44 | + $authorized = $referer |
|
| 45 | + && in_array($referer, $this->config['allowedRefererHosts']); |
|
| 46 | + if (!$authorized) { |
|
| 47 | + throw new \Exception("Host '{$_SERVER['HTTP_REFERER']}' not authorized to make requests."); |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + // PhpQueryClass::$debug = true; |
|
| 52 | + // if (! function_exists('json_decode')) { |
|
| 53 | + // include_once(dirname(__FILE__).'/JSON.php'); |
|
| 54 | + // $this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); |
|
| 55 | + // } |
|
| 56 | + // $data = $this->jsonDecode($data); |
|
| 57 | + $data = PhpQuery::parseJSON($data); |
|
| 58 | + // load document (required for first $data element) |
|
| 59 | + if (is_array($data[0]) && isset($data[0]['url'])) { |
|
| 60 | + $this->options = $data[0]; |
|
| 61 | + $ajax = $this->options; |
|
| 62 | + $this->calls = array_slice($data, 1); |
|
| 63 | + $ajax['success'] = array( |
|
| 64 | + $this, |
|
| 65 | + 'success' |
|
| 66 | + ); |
|
| 67 | + PhpQuery::ajax($ajax); |
|
| 68 | + } |
|
| 69 | + else { |
|
| 70 | + throw new \Exception("URL needed to download content"); |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | public function success($response) { |
| 74 | - $pq = PhpQuery::newDocument($response); |
|
| 75 | - foreach ($this->calls as $k => $r) { |
|
| 76 | - // check if method exists |
|
| 77 | - if (!method_exists(get_class($pq), $r['method'])) { |
|
| 78 | - throw new \Exception("Method '{$r['method']}' not implemented in PhpQuery, sorry..."); |
|
| 79 | - // execute method |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - $pq = call_user_func_array(array( |
|
| 83 | - $pq, |
|
| 84 | - $r['method'] |
|
| 85 | - ), $r['arguments']); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - if (!isset($this->options['dataType'])) |
|
| 89 | - $this->options['dataType'] = ''; |
|
| 90 | - switch (strtolower($this->options['dataType'])) { |
|
| 91 | - case 'json': |
|
| 92 | - if ($pq instanceof PhpQueryObject) { |
|
| 93 | - $results = array(); |
|
| 94 | - foreach ($pq as $node) |
|
| 95 | - $results[] = pq($node)->htmlOuter(); |
|
| 96 | - print PhpQuery::toJSON($results); |
|
| 97 | - } |
|
| 98 | - else { |
|
| 99 | - print PhpQuery::toJSON($pq); |
|
| 100 | - } |
|
| 101 | - break; |
|
| 102 | - default: |
|
| 103 | - print $pq; |
|
| 104 | - } |
|
| 105 | - // output results |
|
| 74 | + $pq = PhpQuery::newDocument($response); |
|
| 75 | + foreach ($this->calls as $k => $r) { |
|
| 76 | + // check if method exists |
|
| 77 | + if (!method_exists(get_class($pq), $r['method'])) { |
|
| 78 | + throw new \Exception("Method '{$r['method']}' not implemented in PhpQuery, sorry..."); |
|
| 79 | + // execute method |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + $pq = call_user_func_array(array( |
|
| 83 | + $pq, |
|
| 84 | + $r['method'] |
|
| 85 | + ), $r['arguments']); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + if (!isset($this->options['dataType'])) |
|
| 89 | + $this->options['dataType'] = ''; |
|
| 90 | + switch (strtolower($this->options['dataType'])) { |
|
| 91 | + case 'json': |
|
| 92 | + if ($pq instanceof PhpQueryObject) { |
|
| 93 | + $results = array(); |
|
| 94 | + foreach ($pq as $node) |
|
| 95 | + $results[] = pq($node)->htmlOuter(); |
|
| 96 | + print PhpQuery::toJSON($results); |
|
| 97 | + } |
|
| 98 | + else { |
|
| 99 | + print PhpQuery::toJSON($pq); |
|
| 100 | + } |
|
| 101 | + break; |
|
| 102 | + default: |
|
| 103 | + print $pq; |
|
| 104 | + } |
|
| 105 | + // output results |
|
| 106 | 106 | } |
| 107 | 107 | // public function jsonEncode($data) { |
| 108 | 108 | // return function_exists('json_encode') |
@@ -30,9 +30,9 @@ |
||
| 30 | 30 | public $allowedHosts = null; |
| 31 | 31 | function __construct($data) { |
| 32 | 32 | $pq = null; |
| 33 | - include_once(dirname(__FILE__) . '/../PhpQuery/PhpQuery.php'); |
|
| 34 | - if (file_exists(dirname(__FILE__) . '/jQueryServer.config.php')) { |
|
| 35 | - include_once(dirname(__FILE__) . '/jQueryServer.config.php'); |
|
| 33 | + include_once(dirname(__FILE__).'/../PhpQuery/PhpQuery.php'); |
|
| 34 | + if (file_exists(dirname(__FILE__).'/jQueryServer.config.php')) { |
|
| 35 | + include_once(dirname(__FILE__).'/jQueryServer.config.php'); |
|
| 36 | 36 | if ($jQueryServerConfig) |
| 37 | 37 | $this->config = array_merge_recursive($this->config, $jQueryServerConfig); |
| 38 | 38 | } |
@@ -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; |
@@ -12,106 +12,106 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class DOMEvent |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Returns a boolean indicating whether the event bubbles up through the DOM or not. |
|
| 17 | - * |
|
| 18 | - * @var bool |
|
| 19 | - */ |
|
| 20 | - public $bubbles = true; |
|
| 21 | - /** |
|
| 22 | - * Returns a boolean indicating whether the event is cancelable. |
|
| 23 | - * |
|
| 24 | - * @var bool |
|
| 25 | - */ |
|
| 26 | - public $cancelable = true; |
|
| 27 | - /** |
|
| 28 | - * Returns a reference to the currently registered target for the event. |
|
| 29 | - * |
|
| 30 | - * @var bool |
|
| 31 | - */ |
|
| 32 | - public $currentTarget; |
|
| 33 | - /** |
|
| 34 | - * Returns detail about the event, depending on the type of event. |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - * @link http://developer.mozilla.org/en/DOM/event.detail |
|
| 38 | - */ |
|
| 39 | - public $detail; // ??? |
|
| 40 | - /** |
|
| 41 | - * Used to indicate which phase of the event flow is currently being evaluated. |
|
| 42 | - * |
|
| 43 | - * NOT IMPLEMENTED |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - * @link http://developer.mozilla.org/en/DOM/event.eventPhase |
|
| 47 | - */ |
|
| 48 | - public $eventPhase; // ??? |
|
| 49 | - /** |
|
| 50 | - * The explicit original target of the event (Mozilla-specific). |
|
| 51 | - * |
|
| 52 | - * NOT IMPLEMENTED |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - public $explicitOriginalTarget; // moz only |
|
| 57 | - /** |
|
| 58 | - * The original target of the event, before any retargetings (Mozilla-specific). |
|
| 59 | - * |
|
| 60 | - * NOT IMPLEMENTED |
|
| 61 | - * |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - public $originalTarget; // moz only |
|
| 65 | - /** |
|
| 66 | - * Identifies a secondary target for the event. |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $relatedTarget; |
|
| 71 | - /** |
|
| 72 | - * Returns a reference to the target to which the event was originally dispatched. |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $target; |
|
| 77 | - /** |
|
| 78 | - * Returns the time that the event was created. |
|
| 79 | - * |
|
| 80 | - * @var string |
|
| 81 | - */ |
|
| 82 | - public $timeStamp; |
|
| 83 | - /** |
|
| 84 | - * Returns the name of the event (case-insensitive). |
|
| 85 | - */ |
|
| 86 | - public $type; |
|
| 87 | - public $runDefault = true; |
|
| 88 | - public $data = null; |
|
| 15 | + /** |
|
| 16 | + * Returns a boolean indicating whether the event bubbles up through the DOM or not. |
|
| 17 | + * |
|
| 18 | + * @var bool |
|
| 19 | + */ |
|
| 20 | + public $bubbles = true; |
|
| 21 | + /** |
|
| 22 | + * Returns a boolean indicating whether the event is cancelable. |
|
| 23 | + * |
|
| 24 | + * @var bool |
|
| 25 | + */ |
|
| 26 | + public $cancelable = true; |
|
| 27 | + /** |
|
| 28 | + * Returns a reference to the currently registered target for the event. |
|
| 29 | + * |
|
| 30 | + * @var bool |
|
| 31 | + */ |
|
| 32 | + public $currentTarget; |
|
| 33 | + /** |
|
| 34 | + * Returns detail about the event, depending on the type of event. |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + * @link http://developer.mozilla.org/en/DOM/event.detail |
|
| 38 | + */ |
|
| 39 | + public $detail; // ??? |
|
| 40 | + /** |
|
| 41 | + * Used to indicate which phase of the event flow is currently being evaluated. |
|
| 42 | + * |
|
| 43 | + * NOT IMPLEMENTED |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + * @link http://developer.mozilla.org/en/DOM/event.eventPhase |
|
| 47 | + */ |
|
| 48 | + public $eventPhase; // ??? |
|
| 49 | + /** |
|
| 50 | + * The explicit original target of the event (Mozilla-specific). |
|
| 51 | + * |
|
| 52 | + * NOT IMPLEMENTED |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + public $explicitOriginalTarget; // moz only |
|
| 57 | + /** |
|
| 58 | + * The original target of the event, before any retargetings (Mozilla-specific). |
|
| 59 | + * |
|
| 60 | + * NOT IMPLEMENTED |
|
| 61 | + * |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + public $originalTarget; // moz only |
|
| 65 | + /** |
|
| 66 | + * Identifies a secondary target for the event. |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $relatedTarget; |
|
| 71 | + /** |
|
| 72 | + * Returns a reference to the target to which the event was originally dispatched. |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $target; |
|
| 77 | + /** |
|
| 78 | + * Returns the time that the event was created. |
|
| 79 | + * |
|
| 80 | + * @var string |
|
| 81 | + */ |
|
| 82 | + public $timeStamp; |
|
| 83 | + /** |
|
| 84 | + * Returns the name of the event (case-insensitive). |
|
| 85 | + */ |
|
| 86 | + public $type; |
|
| 87 | + public $runDefault = true; |
|
| 88 | + public $data = null; |
|
| 89 | 89 | |
| 90 | - public function __construct($data) |
|
| 91 | - { |
|
| 92 | - foreach ($data as $k => $v) { |
|
| 93 | - $this->$k = $v; |
|
| 94 | - } |
|
| 95 | - if (!$this->timeStamp) { |
|
| 96 | - $this->timeStamp = time(); |
|
| 97 | - } |
|
| 98 | - } |
|
| 90 | + public function __construct($data) |
|
| 91 | + { |
|
| 92 | + foreach ($data as $k => $v) { |
|
| 93 | + $this->$k = $v; |
|
| 94 | + } |
|
| 95 | + if (!$this->timeStamp) { |
|
| 96 | + $this->timeStamp = time(); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Cancels the event (if it is cancelable). |
|
| 102 | - * |
|
| 103 | - */ |
|
| 104 | - public function preventDefault() |
|
| 105 | - { |
|
| 106 | - $this->runDefault = false; |
|
| 107 | - } |
|
| 100 | + /** |
|
| 101 | + * Cancels the event (if it is cancelable). |
|
| 102 | + * |
|
| 103 | + */ |
|
| 104 | + public function preventDefault() |
|
| 105 | + { |
|
| 106 | + $this->runDefault = false; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Stops the propagation of events further along in the DOM. |
|
| 111 | - * |
|
| 112 | - */ |
|
| 113 | - public function stopPropagation() |
|
| 114 | - { |
|
| 115 | - $this->bubbles = false; |
|
| 116 | - } |
|
| 109 | + /** |
|
| 110 | + * Stops the propagation of events further along in the DOM. |
|
| 111 | + * |
|
| 112 | + */ |
|
| 113 | + public function stopPropagation() |
|
| 114 | + { |
|
| 115 | + $this->bubbles = false; |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | if (0) { |
| 14 | 14 | PhpQuery::$plugins->browserGet('http://google.com/', 'success1'); |
| 15 | 15 | /** |
| 16 | - * |
|
| 17 | - * @param $pq PhpQueryObject |
|
| 18 | - * @return unknown_type |
|
| 19 | - */ |
|
| 16 | + * |
|
| 17 | + * @param $pq PhpQueryObject |
|
| 18 | + * @return unknown_type |
|
| 19 | + */ |
|
| 20 | 20 | function success1($pq) { |
| 21 | 21 | print 'success1 callback'; |
| 22 | 22 | $pq |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | ; |
| 29 | 29 | } |
| 30 | 30 | /** |
| 31 | - * |
|
| 32 | - * @param $html PhpQueryObject |
|
| 33 | - * @return unknown_type |
|
| 34 | - */ |
|
| 31 | + * |
|
| 32 | + * @param $html PhpQueryObject |
|
| 33 | + * @return unknown_type |
|
| 34 | + */ |
|
| 35 | 35 | function success2($pq) { |
| 36 | 36 | print 'success2 callback'; |
| 37 | 37 | print $pq |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | )); |
| 54 | 54 | function a789fhasdui3124($html) { |
| 55 | 55 | $testName = 'AJAX request text node'; |
| 56 | - if ( $html == 'hello world' ) |
|
| 56 | + if ($html == 'hello world') |
|
| 57 | 57 | print "Test '$testName' PASSED :)"; |
| 58 | 58 | else { |
| 59 | 59 | print "Test '$testName' <strong>FAILED</strong> !!! "; |
@@ -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,6 +8,6 @@ |
||
| 8 | 8 | <body> |
| 9 | 9 | <span>Hello World!</span> |
| 10 | 10 | <span>ąśżźć</span> |
| 11 | - <a href='<?php foreach($foo as $bar) { print $foo['1'] } ?>'>Attr test</a> |
|
| 11 | + <a href='<?php foreach ($foo as $bar) { print $foo['1'] } ?>'>Attr test</a> |
|
| 12 | 12 | </body> |
| 13 | 13 | </html> |
@@ -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()); |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | $testName = 'Attribute change in iteration'; |
| 18 | 18 | $expected = 'new attr value'; |
| 19 | 19 | $doc = PhpQuery::newDocumentFile('test.html'); |
| 20 | -foreach($doc['p[rel]:first'] as $p) |
|
| 20 | +foreach ($doc['p[rel]:first'] as $p) |
|
| 21 | 21 | pq($p)->attr('rel', $expected); |
| 22 | 22 | if ($doc['p[rel]:first']->attr('rel') == $expected) |
| 23 | 23 | print "Test '{$testName}' passed :)"; |
@@ -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 |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | // create_function('$node', 'return $node->getAttribute("name");') |
| 21 | 21 | // ); |
| 22 | 22 | $results = array(); |
| 23 | -foreach($inputs as $node) { |
|
| 23 | +foreach ($inputs as $node) { |
|
| 24 | 24 | $node = pq($node); |
| 25 | 25 | $name = $node->attr('name'); |
| 26 | 26 | $results[$name] = false; |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | ->val(array('foo')) |
| 43 | 43 | ->end() |
| 44 | 44 | ; |
| 45 | -foreach($results as $name => $result) { |
|
| 45 | +foreach ($results as $name => $result) { |
|
| 46 | 46 | print $result |
| 47 | 47 | ? "Test for '$name' PASSED :)<br />\n" |
| 48 | 48 | : "Test for '$name' <strong>FAILED</strong> !!!<br />\n"; |