Skip to content

Commit b986cc6

Browse files
author
tobiasz.cudnik
committed
Releasing 0.9.5 to trunk
0 parents  commit b986cc6

File tree

127 files changed

+23641
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+23641
-0
lines changed

cli/phpquery

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env php
2+
<?php
3+
if (!isset($argv[1]) || $argv[1] == 'help' || $argv[1] == '--help' || $argv[1] == '-h')
4+
die("Usage:
5+
phpquery URL --method1 arg1 arg2 argN --method2 arg1 arg2 argN ...
6+
Example:
7+
phpquery 'http://localhost' --find 'div > p' --contents
8+
Pipe:
9+
cat index.html | phpquery --find 'div > p' --contents
10+
Docs:
11+
http://code.google.com/p/phpquery/wiki/\n");
12+
/* ALL-IN-ONE-SECTION-START */
13+
set_include_path(get_include_path()
14+
.':'.'/usr/lib/phpquery'
15+
.':'.realpath(dirname(__FILE__).'/../phpQuery')
16+
);
17+
require_once('phpQuery.php');
18+
/* ALL-IN-ONE-SECTION-END */
19+
//phpQuery::$debug = true;
20+
//var_dump($argv);
21+
if (isset($argv[1]) && parse_url($argv[1], PHP_URL_HOST)) {
22+
if (@include_once('Zend/Http/Client.php')) {
23+
// use Ajax if possible
24+
phpQuery::ajaxAllowURL($argv[1]);
25+
// TODO support contentType passing (from response headers)
26+
phpQuery::get($argv[1],
27+
new Callback('phpQueryCli', new CallbackParam, array_slice($argv, 2))
28+
);
29+
} else {
30+
// use file wrapper when no Ajax
31+
phpQueryCli(file_get_contents($argv[1]), array_slice($argv, 2));
32+
}
33+
} else if (feof(STDIN) === false) {
34+
$markup = '';
35+
while(!feof(STDIN))
36+
$markup .= fgets(STDIN, 4096);
37+
phpQueryCli($markup, array_slice($argv, 1));
38+
} else {
39+
phpQueryCli($argv[1], array_slice($argv, 2));
40+
}
41+
function phpQueryCli($markup, $callQueue) {
42+
$pq = phpQuery::newDocument($markup);
43+
$method = null;
44+
$params = array();
45+
foreach($callQueue as $param) {
46+
if (strpos($param, '--') === 0) {
47+
if ($method) {
48+
$pq = call_user_func_array(array($pq, $method), $params);
49+
}
50+
$method = substr($param, 2); // delete --
51+
$params = array();
52+
} else {
53+
$param = str_replace('\n', "\n", $param);
54+
$params[] = strtolower($param) == 'null'
55+
? null
56+
: $param;
57+
}
58+
}
59+
if ($method)
60+
$pq = call_user_func_array(array($pq, $method), $params);
61+
if (is_array($pq))
62+
foreach($pq as $v)
63+
print $v;
64+
else
65+
print $pq."\n";
66+
//var_dump($pq);
67+
}
68+
?>

demo.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
require('phpQuery/phpQuery.php');
3+
4+
// INITIALIZE IT
5+
// phpQuery::newDocumentHTML($markup);
6+
// phpQuery::newDocumentXML();
7+
// phpQuery::newDocumentFileXHTML('test.html');
8+
// phpQuery::newDocumentFilePHP('test.php');
9+
// phpQuery::newDocument('test.xml', 'application/rss+xml');
10+
// this one defaults to text/html in utf8
11+
$doc = phpQuery::newDocument('<div/>');
12+
13+
// FILL IT
14+
// array syntax works like ->find() here
15+
$doc['div']->append('<ul></ul>');
16+
// array set changes inner html
17+
$doc['div ul'] = '<li>1</li> <li>2</li> <li>3</li>';
18+
19+
// MANIPULATE IT
20+
$li = null;
21+
// almost everything can be a chain
22+
$doc['ul > li']
23+
->addClass('my-new-class')
24+
->filter(':last')
25+
->addClass('last-li')
26+
// save it anywhere in the chain
27+
->toReference($li);
28+
29+
// SELECT DOCUMENT
30+
// pq(); is using selected document as default
31+
phpQuery::selectDocument($doc);
32+
// documents are selected when created or by above method
33+
// query all unordered lists in last selected document
34+
$ul = pq('ul')->insertAfter('div');
35+
36+
// ITERATE IT
37+
// all direct LIs from $ul
38+
foreach($ul['> li'] as $li) {
39+
// iteration returns PLAIN dom nodes, NOT phpQuery objects
40+
$tagName = $li->tagName;
41+
$childNodes = $li->childNodes;
42+
// so you NEED to wrap it within phpQuery, using pq();
43+
pq($li)->addClass('my-second-new-class');
44+
}
45+
46+
// PRINT OUTPUT
47+
// 1st way
48+
print phpQuery::getDocument($doc->getDocumentID());
49+
// 2nd way
50+
print phpQuery::getDocument(pq('div')->getDocumentID());
51+
// 3rd way
52+
print pq('div')->getDocument();
53+
// 4th way
54+
print $doc->htmlOuter();
55+
// 5th way
56+
print $doc;
57+
// another...
58+
print $doc['ul'];

jQueryServer/demo/demo.htm

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
2+
"http://www.w3.org/TR/html4/strict.dtd">
3+
<html lang="en">
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<title>jQuery Server Plugin</title>
7+
<script type="text/javascript" src='jquery.js'></script>
8+
<script type="text/javascript" src='../jQueryServer.js'></script>
9+
<script type="text/javascript">
10+
jQuery.serverConfig.url = '/phpQuery/jQueryServer/jQueryServer.php';
11+
function demo() {
12+
$.server({
13+
url: document.location.toString(),
14+
dataType: 'json'
15+
})
16+
.find('li')
17+
.client(function(response){
18+
$.each(response, function(k, li){
19+
$('ul').append(li);
20+
});
21+
});
22+
}
23+
$(function(){
24+
$('ul').append('<li>above LIs will be downloaded and appended below in 2 seconds...</li>');
25+
setTimeout(demo, 2000);
26+
});
27+
</script>
28+
</head>
29+
<body>
30+
<div>jQuery Server Plugin demo...</div>
31+
<ul>
32+
<li>test1</li>
33+
<li>test2</li>
34+
<li>test3</li>
35+
</ul>
36+
</body>
37+
</html>

0 commit comments

Comments
 (0)