|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
//error_reporting(E_ALL); |
|
3
|
|
|
set_include_path( |
|
4
|
|
|
get_include_path().PATH_SEPARATOR |
|
5
|
|
|
.'zend-framework/' |
|
6
|
|
|
); |
|
7
|
|
|
|
|
8
|
|
|
require_once('../PhpQuery/PhpQuery.php'); |
|
9
|
|
|
PhpQuery::$debug = true; |
|
|
|
|
|
|
10
|
|
|
PhpQuery::$ajaxAllowedHosts[] = 'wikipedia.org'; |
|
11
|
|
|
PhpQuery::$ajaxAllowedHosts[] = 'google.com'; |
|
12
|
|
|
PhpQuery::$ajaxAllowedHosts[] = 'code.google.com'; |
|
13
|
|
|
PhpQuery::$ajaxAllowedHosts[] = 'www.google.com'; |
|
14
|
|
|
|
|
15
|
|
|
//$pq = PhpQuery::ajax(array( |
|
|
|
|
|
|
16
|
|
|
// 'url' => 'http://wikipedia.org/', |
|
17
|
|
|
// 'success' => 'v87shs79d8fhs9d' |
|
18
|
|
|
//)); |
|
19
|
|
|
//function v87shs79d8fhs9d($html) { |
|
20
|
|
|
// $title = PhpQuery::newDocument($html)->find('title'); |
|
21
|
|
|
// $testName = 'Simple AJAX'; |
|
22
|
|
|
// if ( strpos(strtolower($title->html()), 'wikipedia') !== false ) |
|
23
|
|
|
// print "Test '$testName' PASSED :)"; |
|
24
|
|
|
// else { |
|
25
|
|
|
// print "Test '$testName' <strong>FAILED</strong> !!! "; |
|
26
|
|
|
// print "<pre>"; |
|
27
|
|
|
// print_r($title->whois()); |
|
28
|
|
|
// print "</pre>\n"; |
|
29
|
|
|
// } |
|
30
|
|
|
// print "\n"; |
|
31
|
|
|
//} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
$testName = 'Load'; |
|
35
|
|
|
$test = PhpQuery::newDocumentFile('test.html') |
|
|
|
|
|
|
36
|
|
|
->find('div:first') |
|
37
|
|
|
->load('http://wikipedia.org/ div[lang]'); |
|
38
|
|
|
if (pq('div[lang]')->size()) |
|
39
|
|
|
print "Test '$testName' PASSED :)"; |
|
40
|
|
|
else { |
|
41
|
|
|
print "Test '$testName' <strong>FAILED</strong> !!! "; |
|
42
|
|
|
print "<pre>"; |
|
43
|
|
|
print "</pre>\n"; |
|
44
|
|
|
} |
|
45
|
|
|
print "\n"; |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
// http://code.google.com/p/phpquery/issues/detail?id=130 |
|
49
|
|
|
$pq = PhpQuery::ajax(array( |
|
|
|
|
|
|
50
|
|
|
'url' => 'http://'.$_SERVER['SERVER_NAME'].preg_replace('@/[^/]+$@', '/test_ajax_data_1', $_SERVER['REQUEST_URI']), |
|
51
|
|
|
'success' => 'a789fhasdui3124', |
|
52
|
|
|
'error' => 'jhdbg786213u8dsfg7y' |
|
53
|
|
|
)); |
|
54
|
|
|
function a789fhasdui3124($html) { |
|
55
|
|
|
$testName = 'AJAX request text node'; |
|
56
|
|
|
if ( $html == 'hello world' ) |
|
57
|
|
|
print "Test '$testName' PASSED :)"; |
|
58
|
|
|
else { |
|
59
|
|
|
print "Test '$testName' <strong>FAILED</strong> !!! "; |
|
60
|
|
|
} |
|
61
|
|
|
print "\n"; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
function jhdbg786213u8dsfg7y() { |
|
65
|
|
|
$testName = 'AJAX request text node'; |
|
66
|
|
|
print "Test '$testName' <strong>FAILED</strong> !!! "; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
//$testName = 'gdata plugin'; |
|
|
|
|
|
|
71
|
|
|
//PhpQuery::extend('gdata'); |
|
72
|
|
|
//$xhr = PhpQuery::$plugins->gdata('[email protected]', 'XXX'); |
|
73
|
|
|
//$url = 'http://code.google.com/p/phpquery/w/edit/Callbacks'; |
|
74
|
|
|
//PhpQuery::ajax(array('url' => $url, 'success' => 'ksjsdgh892jh23'), $xhr); |
|
75
|
|
|
//function ksjsdgh892jh23($html) { |
|
76
|
|
|
// print $html; |
|
77
|
|
|
// print pq($html)->find('script')->remove()->end(); |
|
78
|
|
|
// if (pq('div[lang]')->size()) |
|
79
|
|
|
// print "Test '$testName' PASSED :)"; |
|
80
|
|
|
// else { |
|
81
|
|
|
// print "Test '$testName' <strong>FAILED</strong> !!! "; |
|
82
|
|
|
// print "<pre>"; |
|
83
|
|
|
// print "</pre>\n"; |
|
84
|
|
|
// } |
|
85
|
|
|
// print "\n"; |
|
86
|
|
|
//} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.