Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ I've gathered some fix and new features here and there, as will keep looking for
* https://github.com/kevee/phpquery (include php-css-parser)
* https://github.com/lucassouza1/phpquery

## Manual

* [Manual](wiki/README.md) imported from http://code.google.com/p/phpquery/wiki

## Extracts from fmorrow README.md:

### Whats phpQuery?
Expand Down
70 changes: 70 additions & 0 deletions wiki/Ajax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## Example
```
pq('#element')->load('http://somesite.com/page .inline-selector')->...
```
# Table of Contents
* [Server Side Ajax](#Server_Side_Ajax.md)
* [Cross Domain Ajax](#Cross_Domain_Ajax.md)
* [Ajax Requests](#Ajax_Requests.md)
* [Ajax Events](#Ajax_Events.md)
* [Misc](#Misc.md)
## Server Side Ajax
Ajax, standing for _Asynchronous JavaScript and XML_ is combination of HTTP Client and XML parser which doesn't lock program's thread (doing request in asynchronous way).

**phpQuery** also offers such functionality, making use of solid quality [Zend\_Http\_Client](http://framework.zend.com/manual/en/zend.http.html). Unfortunately requests aren't asynchronous, but nothing is impossible. For today, instead of [XMLHttpRequest](http://en.wikipedia.org/wiki/XMLHttpRequest) you always get Zend\_Http\_Client instance. API unification is [planned](http://code.google.com/p/phpquery/issues/detail?id=44).
## Cross Domain Ajax
For security reasons, by default **phpQuery** doesn't allow connections to hosts other than actual `$_SERVER['HTTP_HOST']`. Developer needs to grant rights to other hosts before making an [Ajax](Ajax.md) request.

There are 2 methods for allowing other hosts
* phpQuery::**ajaxAllowURL**($url)
* phpQuery::**ajaxAllowHost**($host)

```
// connect to google.com
phpQuery::ajaxAllowHost('google.com');
phpQuery::get('http://google.com/ig');
// or using same string
$url = 'http://google.com/ig';
phpQuery::ajaxAllowURL($url);
phpQuery::get($url);
```
## Ajax Requests
* **[phpQuery::ajax](http://docs.jquery.com/Ajax/jQuery.ajax)**[($options)](http://docs.jquery.com/Ajax/jQuery.ajax) Load a remote page using an HTTP request.
* **[load](http://docs.jquery.com/Ajax/load)**[($url, $data, $callback)](http://docs.jquery.com/Ajax/load) Load HTML from a remote file and inject it into the DOM.
* **[phpQuery::get](http://docs.jquery.com/Ajax/jQuery.get)**[($url, $data, $callback)](http://docs.jquery.com/Ajax/jQuery.get) Load a remote page using an HTTP GET request.
* **[phpQuery::getJSON](http://docs.jquery.com/Ajax/jQuery.getJSON)**[($url, $data, $callback)](http://docs.jquery.com/Ajax/jQuery.getJSON) Load JSON data using an HTTP GET request.
* **[phpQuery::getScript](http://docs.jquery.com/Ajax/jQuery.getScript)**[($url, $callback)](http://docs.jquery.com/Ajax/jQuery.getScript) Loads, and executes, a local JavaScript file using an HTTP GET request.
* **[phpQuery::post](http://docs.jquery.com/Ajax/jQuery.post)**[($url, $data, $callback, $type)](http://docs.jquery.com/Ajax/jQuery.post) Load a remote page using an HTTP POST request.
## Ajax Events
* **[ajaxComplete](http://docs.jquery.com/Ajax/ajaxComplete)**[($callback)](http://docs.jquery.com/Ajax/ajaxComplete) Attach a function to be executed whenever an AJAX request completes. This is an Ajax Event.
* **[ajaxError](http://docs.jquery.com/Ajax/ajaxError)**[($callback)](http://docs.jquery.com/Ajax/ajaxError) Attach a function to be executed whenever an AJAX request fails. This is an Ajax Event.
* **[ajaxSend](http://docs.jquery.com/Ajax/ajaxSend)**[($callback)](http://docs.jquery.com/Ajax/ajaxSend) Attach a function to be executed before an AJAX request is sent. This is an Ajax Event.
* **[ajaxStart](http://docs.jquery.com/Ajax/ajaxStart)**[($callback)](http://docs.jquery.com/Ajax/ajaxStart) Attach a function to be executed whenever an AJAX request begins and there is none already active. This is an Ajax Event.
* **[ajaxStop](http://docs.jquery.com/Ajax/ajaxStop)**[($callback)](http://docs.jquery.com/Ajax/ajaxStop) Attach a function to be executed whenever all AJAX requests have ended. This is an Ajax Event.
* **[ajaxSuccess](http://docs.jquery.com/Ajax/ajaxSuccess)**[($callback)](http://docs.jquery.com/Ajax/ajaxSuccess) Attach a function to be executed whenever an AJAX request completes successfully. This is an Ajax Event.
## Misc
* **[phpQuery::ajaxSetup](http://docs.jquery.com/Ajax/jQuery.ajaxSetup)**[($options)](http://docs.jquery.com/Ajax/jQuery.ajaxSetup) Setup global settings for AJAX requests.
* **[serialize](http://docs.jquery.com/Ajax/serialize)**[()](http://docs.jquery.com/Ajax/serialize) Serializes a set of input elements into a string of data. This will serialize all given elements.
* **[serializeArray](http://docs.jquery.com/Ajax/serializeArray)**[()](http://docs.jquery.com/Ajax/serializeArray) Serializes all forms and form elements (like the .serialize() method) but returns a JSON data structure for you to work with.
## Options
Detailed options description in available at [jQuery Documentation Site](http://docs.jquery.com/Ajax/jQuery.ajax#toptions).
* **`async`** `Boolean`
* **`beforeSend`** `Function`
* **`cache`** `Boolean`
* **`complete`** `Function`
* **`contentType`** `String`
* **`data`** `Object, String`
* **`dataType`** `String`
* **`error`** `Function`
* **`global`** `Boolean`
* **`ifModified`** `Boolean`
* **`jsonp`** `String`
* **`password`** `String`
* **`processData`** `Boolean`
* **`success`** `Function`
* **`timeout`** `Number`
* **`type`** `String`
* **`url`** `String`
* **`username`** `String`

Read more at [Ajax](http://docs.jquery.com/Ajax) section on [jQuery Documentation Site](http://docs.jquery.com/).
33 changes: 33 additions & 0 deletions wiki/Attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Example
```
pq('a')->attr('href', 'newVal')->removeClass('className')->html('newHtml')->...
```
# Table of Contents
* [Attr](#Attr.md)
* [Class](#Class.md)
* [HTML](#HTML.md)
* [Text](#Text.md)
* [Value](#Value.md)
## Attr
* **[attr](http://docs.jquery.com/Attributes/attr)**[($name)](http://docs.jquery.com/Attributes/attr) Access a property on the first matched element. This method makes it easy to retrieve a property value from the first matched element. If the element does not have an attribute with such a name, undefined is returned.
* **[attr](http://docs.jquery.com/Attributes/attr)**[($properties)](http://docs.jquery.com/Attributes/attr) Set a key/value object as properties to all matched elements.
* **[attr](http://docs.jquery.com/Attributes/attr)**[($key, $value)](http://docs.jquery.com/Attributes/attr) Set a single property to a value, on all matched elements.
* **[attr](http://docs.jquery.com/Attributes/attr)**[($key, $fn)](http://docs.jquery.com/Attributes/attr) Set a single property to a computed value, on all matched elements.
* **[removeAttr](http://docs.jquery.com/Attributes/removeAttr)**[($name)](http://docs.jquery.com/Attributes/removeAttr) Remove an attribute from each of the matched elements.
## Class
* **[addClass](http://docs.jquery.com/Attributes/addClass)**[($class)](http://docs.jquery.com/Attributes/addClass) Adds the specified class(es) to each of the set of matched elements.
* **[hasClass](http://docs.jquery.com/Attributes/hasClass)**[($class)](http://docs.jquery.com/Attributes/hasClass) Returns true if the specified class is present on at least one of the set of matched elements.
* **[removeClass](http://docs.jquery.com/Attributes/removeClass)**[($class)](http://docs.jquery.com/Attributes/removeClass) Removes all or the specified class(es) from the set of matched elements.
* **[toggleClass](http://docs.jquery.com/Attributes/toggleClass)**[($class)](http://docs.jquery.com/Attributes/toggleClass) Adds the specified class if it is not present, removes the specified class if it is present.
## HTML
* **[html](http://docs.jquery.com/Attributes/html)**[()](http://docs.jquery.com/Attributes/html) Get the html contents (innerHTML) of the first matched element. This property is not available on XML documents (although it will work for XHTML documents).
* **[html](http://docs.jquery.com/Attributes/html)**[($val)](http://docs.jquery.com/Attributes/html) Set the html contents of every matched element. This property is not available on XML documents (although it will work for XHTML documents).
## Text
* **[text](http://docs.jquery.com/Attributes/text)**[()](http://docs.jquery.com/Attributes/text) Get the combined text contents of all matched elements.
* **[text](http://docs.jquery.com/Attributes/text)**[($val)](http://docs.jquery.com/Attributes/text) Set the text contents of all matched elements.
## Value
* **[val](http://docs.jquery.com/Attributes/val)**[()](http://docs.jquery.com/Attributes/val) Get the content of the value attribute of the first matched element.
* **[val](http://docs.jquery.com/Attributes/val)**[($val)](http://docs.jquery.com/Attributes/val) Set the value attribute of every matched element.
* **[val](http://docs.jquery.com/Attributes/val)**[($val)](http://docs.jquery.com/Attributes/val) Checks, or selects, all the radio buttons, checkboxes, and select options that match the set of values.

Read more at [Attributes](http://docs.jquery.com/Attributes) section on [jQuery Documentation Site](http://docs.jquery.com/).
54 changes: 54 additions & 0 deletions wiki/Basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Example
```
phpQuery::newDocumentFileXHTML('my-xhtml.html')->find('p');
$ul = pq('ul');
```
# Table of Contents
* [Loading documents](#Loading_documents.md)
* [pq() function](#pq_function.md)

## Loading documents
* phpQuery::**newDocument**($html, $contentType = null) Creates new document from markup. If no $contentType, autodetection is made (based on markup). If it fails, text/html in utf-8 is used.
* phpQuery::**newDocumentFile**($file, $contentType = null) Creates new document from file. Works like newDocument()
* phpQuery::**newDocumentHTML**($html, $charset = 'utf-8')
* phpQuery::**newDocumentXHTML**($html, $charset = 'utf-8')
* phpQuery::**newDocumentXML**($html, $charset = 'utf-8')
* phpQuery::**newDocumentPHP**($html, $contentType = null) Read more about it on [PHPSupport page](PHPSupport.md)
* phpQuery::**newDocumentFileHTML**($file, $charset = 'utf-8')
* phpQuery::**newDocumentFileXHTML**($file, $charset = 'utf-8')
* phpQuery::**newDocumentFileXML**($file, $charset = 'utf-8')
* phpQuery::**newDocumentFilePHP**($file, $contentType) Read more about it on [PHPSupport page](PHPSupport.md)
## pq function
**`pq($param, $context = null);`**

**pq();** function is equivalent of jQuery's **$();**. It's used for 3 type of things:
1. Importing markup
```
// Import into selected document:
// doesn't accept text nodes at beginning of input string
pq('<div/>')
// Import into document with ID from $pq->getDocumentID():
pq('<div/>', $pq->getDocumentID())
// Import into same document as DOMNode belongs to:
pq('<div/>', DOMNode)
// Import into document from phpQuery object:
pq('<div/>', $pq)
```
1. Running queries
```
// Run query on last selected document:
pq('div.myClass')
// Run query on document with ID from $pq->getDocumentID():
pq('div.myClass', $pq->getDocumentID())
// Run query on same document as DOMNode belongs to and use node(s)as root for query:
pq('div.myClass', DOMNode)
// Run query on document from phpQuery object
// and use object's stack as root node(s) for query:
pq('div.myClass', $pq)
```
1. Wrapping DOMNodes with phpQuery objects
```
foreach(pq('li') as $li)
// $li is pure DOMNode, change it to phpQuery object
pq($li);
```
1 change: 1 addition & 0 deletions wiki/CSS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Work in progress. Scheduled before 1.0.
91 changes: 91 additions & 0 deletions wiki/Callbacks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Table of Contents
* [What are callbacks](#What_are_callbacks.md)
* [phpQuery callback system](#phpQuery_callbacks.md)
* [Callback class](#Callback.md)
* [CallbackParam class](#CallbackParam.md)
* [CallbackReference class](#CallbackReference.md)
* [Scope Pseudo-Inheritance](#Scope_Pseudo_Inheritance.md)
## What are callbacks
Callbacks are functions _called back_ by other functions in proper moment (eg on [Ajax](Ajax.md) request error).

In **JavaScript** this pattern can be very flexible due to [Closures](http://en.wikipedia.org/wiki/Closure_(computer_science)) support, which can be inline (no code break) and inherits scope (no need to passing params).

**PHP** has only simple [support for callbacks](http://pl2.php.net/manual/en/function.call-user-func-array.php) so the case is more complicated. That's why phpQuery extends callback support by it's own.
## phpQuery callback system
phpQuery uses it's own approach to callbacks. This task is achieved thou **Callback**, **CallbackParam** and **CallbackReference** classes.
### Callback
Callback class is used for wrapping valid callbacks with params.
#### Example 1
```
function myCallback($param1, $param2) {
var_dump($param1);
var_dump($param2);
}
phpQuery::get($url,
new Callback('myCallback', 'myParam1', new CallbackParam)
);
// now $param1 in myCallback will have value 'myParam1'
// and $param2 will be parameter passed by function calling callback
// which in this example would be ajax request result
```
### CallbackParam
As we can see in [last example](#Example_1.md), new instance of CallbackParam class is used for defining places, where original callback parameter(s) will be placed. Such pattern can be used also without Callback class for some methods.
#### Example 2
```
phpQuery::each(
// first param is array which will be iterated
array(1,2,3),
// second param is callback (string or array to call objects method)
'myCallback',
// rest of params are ParamStructure
// CallbackParam objects will be changed to $i and $v by phpQuery::each method
'param1', new CallbackParam, new CallbackParam, 'param4'
);
function myCallback($param1, $i, $v, $param4) {
print "Index: $i; Value: $v";
}
```
Methods supporting CallbackParam **without** using Callback class:
* `phpQuery::each()`
* `phpQuery::map()`
* `pq()->each()`
* `pq()->map()`
### CallbackReference
Finally, CallbackReference can be used when we don't really want a callback, only parameter passed to it. CallbackReference takes first parameter's value and passes it to reference. Thanks to that, we can use **if statement** instead of **callback function**.
#### Example 3
```
$html;
phpQuery::get($url, new CallbackReference($html));
if ($html) {
// callback triggered, value non-false
phpQuery::get($url, new CallbackReference($html));
if ($html) {
// we just skipped 2 function declarations
}
}
```
## Scope Pseudo Inheritance
There is an easy way to pseudo inherit scope in PHP. [Scope](http://en.wikipedia.org/wiki/Scope_(programming)) means _variables accessible in specified point of code_ (which in other words means _any variable you can use_). It's achieved using [compact()](http://php.net/compact) and [extract()](http://php.net/extract) functions.
#### Example 4
Look at this modified [example 2](#Example_2.md). Previous comments were removed.
```
$a = 'foo';
$b = 'bar';
phpQuery::each(
array(1,2,3),
'myCallback',
// notice that 'param1' changed to compact('a', 'b')
// where 'a' and 'b' are variable names accessible in actual scope
compact('a', 'b'), new CallbackParam, new CallbackParam, 'param4'
);
function myCallback($scope, $i, $v, $param4) {
// this is the place where variables from $scope array
// are forwarded to actual function's scope
extract($scope);
print "Var a: $a"; // will print 'Var a: foo'
print "Var b: $b"; // will print 'Var a: bar'
print "Index: $i; Value: $v";
}
```
## Future
In the future this functionality will be extended and more methods will support it. Check [Issue Tracker entry #48](http://code.google.com/p/phpquery/issues/detail?id=48) if you're interested in any way.
1 change: 1 addition & 0 deletions wiki/Chains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO ;)
14 changes: 14 additions & 0 deletions wiki/CommandLineInterface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
phpQuery features CommandLineInterface aka CLI.
```
Usage: phpquery URL --method1 arg1 arg2 argN --method2 arg1 arg2 argN ...
Example: phpquery 'http://localhost' --find 'div > p' --contents
Pipe: cat index.html | phpquery --find 'div > p' --contents
Docs: http://code.google.com/p/phpquery/wiki/
```
## Example
Fetch number of downloads of all release packages.
```
phpquery 'http://code.google.com/p/phpquery/downloads/list?can=1' \
--find '.vt.col_4 a' --contents \
--getString null array_sum
```
16 changes: 16 additions & 0 deletions wiki/Debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Enabling debugging
```
// enable debugging messages
phpQuery::$debug = 1;
// enable extensive debugging messages
// used to debug document loading errors from phpQuery::newDocument()
phpQuery::$debug = 2;
```
## Debugging methods
```
// debug inside chain
pq('.foo')->dump()->...;
pq('.foo')->dumpWhois()->...;
pq('.foo')->dumpTree()->...;
pq('.foo')->dumpDie()->...;
```
14 changes: 14 additions & 0 deletions wiki/Dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
**phpQuery** depends on following code parts:
* [PHP5](#PHP5.md)
* [PHP5 DOM extension](#DOM_extension.md)
* [Zend Framework](#Zend_Framework.md)

## PHP5
Required version of PHP is [PHP5](http://www.php.net/), **5.2** recommended.

## DOM extension
PHP5's build-in [DOM extension](http://php.net/manual/en/book.dom.php) is required. Users of
[windows XAMPP](http://www.apachefriends.org/en/xampp-windows.html) (and maybe other unofficial PHP distributions) need to disable depracated [DOM XML](http://php.net/manual/en/ref.domxml.php) extension. More information can be found in [this post on mrclay.org](http://mrclay.org/index.php/2008/10/08/getting-phpquery-running-under-xampp-for-windows/)

## Zend Framework
[Zend Framework](http://framework.zend.com/) is used as HTTP Client and JSON encoder. Those who already have Zend Framework in their applications, can remove directory **/phpQuery/Zend**. Only condition is having proper include path set for own copy of the library.
Loading