diff --git a/README.md b/README.md index f9c33f7..6287d32 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/wiki/Ajax.md b/wiki/Ajax.md new file mode 100644 index 0000000..fe9a24e --- /dev/null +++ b/wiki/Ajax.md @@ -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/). \ No newline at end of file diff --git a/wiki/Attributes.md b/wiki/Attributes.md new file mode 100644 index 0000000..c4ca398 --- /dev/null +++ b/wiki/Attributes.md @@ -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/). \ No newline at end of file diff --git a/wiki/Basics.md b/wiki/Basics.md new file mode 100644 index 0000000..dedd006 --- /dev/null +++ b/wiki/Basics.md @@ -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('
') +// Import into document with ID from $pq->getDocumentID(): +pq('
', $pq->getDocumentID()) +// Import into same document as DOMNode belongs to: +pq('
', DOMNode) +// Import into document from phpQuery object: +pq('
', $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); +``` \ No newline at end of file diff --git a/wiki/CSS.md b/wiki/CSS.md new file mode 100644 index 0000000..e1a913a --- /dev/null +++ b/wiki/CSS.md @@ -0,0 +1 @@ +Work in progress. Scheduled before 1.0. \ No newline at end of file diff --git a/wiki/Callbacks.md b/wiki/Callbacks.md new file mode 100644 index 0000000..856bccf --- /dev/null +++ b/wiki/Callbacks.md @@ -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. \ No newline at end of file diff --git a/wiki/Chains.md b/wiki/Chains.md new file mode 100644 index 0000000..2ff4028 --- /dev/null +++ b/wiki/Chains.md @@ -0,0 +1 @@ +TODO ;) \ No newline at end of file diff --git a/wiki/CommandLineInterface.md b/wiki/CommandLineInterface.md new file mode 100644 index 0000000..f3e4d9d --- /dev/null +++ b/wiki/CommandLineInterface.md @@ -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 +``` \ No newline at end of file diff --git a/wiki/Debugging.md b/wiki/Debugging.md new file mode 100644 index 0000000..b608806 --- /dev/null +++ b/wiki/Debugging.md @@ -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()->...; +``` \ No newline at end of file diff --git a/wiki/Dependencies.md b/wiki/Dependencies.md new file mode 100644 index 0000000..4a4108d --- /dev/null +++ b/wiki/Dependencies.md @@ -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. \ No newline at end of file diff --git a/wiki/Events.md b/wiki/Events.md new file mode 100644 index 0000000..0fd4f4d --- /dev/null +++ b/wiki/Events.md @@ -0,0 +1,47 @@ +# Table of Contents + * [Example](#Example.md) + * [Server Side Events](#Server_Side_Events.md) + * [Page Load](#Page_Load.md) + * [Event Handling](#Event_Handling.md) + * [Interaction Helpers](#Interaction_Helpers.md) + * [Event Helpers](#Event_Helpers.md) + +## Example +``` +pq('form')->bind('submit', 'submitHandler')->trigger('submit')->... +function submitHandler($e) { + print 'Target: '.$e->target->tagName; + print 'Bubbling ? '.$e->currentTarget->tagName; +} +``` + +## Server Side Events +phpQuery support **server-side** events, same as jQuery handle client-side ones. On server there isn't, of course, events such as _mouseover_ (but they can be triggered). + +By default, phpQuery automatically fires up only **change** event for form elements. If you load WebBrowser plugin, **submit** and **click** will be handled properly - eg submitting form with inputs' data to action URL via new [Ajax](Ajax.md) request. + +$this (`this` in JS) context for handler scope **isn't available**. You have to use one of following manually: + * $event->**target** + * $event->**currentTarget** + * $event->**relatedTarget** + +## Page Load +_none_ + +## Event Handling + * **[bind](http://docs.jquery.com/Events/bind)**[($type, $data, $fn)](http://docs.jquery.com/Events/bind) Binds a handler to one or more events (like click) for each matched element. Can also bind custom events. + * **[one](http://docs.jquery.com/Events/one)**[($type, $data, $fn)](http://docs.jquery.com/Events/one) Binds a handler to one or more events to be executed once for each matched element. + * **[trigger](http://docs.jquery.com/Events/trigger)**[($type , $data )](http://docs.jquery.com/Events/trigger) Trigger a type of event on every matched element. + * **[triggerHandler](http://docs.jquery.com/Events/triggerHandler)**[($type , $data )](http://docs.jquery.com/Events/triggerHandler) This particular method triggers all bound event handlers on an element (for a specific event type) WITHOUT executing the browsers default actions. + * **[unbind](http://docs.jquery.com/Events/unbind)**[($type , $data )](http://docs.jquery.com/Events/unbind) This does the opposite of bind, it removes bound events from each of the matched elements. + +## Interaction Helpers +_none_ + +## Event Helpers + * **[change](http://docs.jquery.com/Events/change)**[()](http://docs.jquery.com/Events/change) Triggers the change event of each matched element. + * **[change](http://docs.jquery.com/Events/change)**[($fn)](http://docs.jquery.com/Events/change) Binds a function to the change event of each matched element. + * **[submit](http://docs.jquery.com/Events/submit)**[()](http://docs.jquery.com/Events/submit) Trigger the submit event of each matched element. + * **[submit](http://docs.jquery.com/Events/submit)**[($fn)](http://docs.jquery.com/Events/submit) Bind a function to the submit event of each matched element. + +Read more at [Events](http://docs.jquery.com/Events) section on [jQuery Documentation Site](http://docs.jquery.com/). \ No newline at end of file diff --git a/wiki/LibrarySections.md b/wiki/LibrarySections.md new file mode 100644 index 0000000..3d323e3 --- /dev/null +++ b/wiki/LibrarySections.md @@ -0,0 +1 @@ +Renamed to [Manual](Manual.md). \ No newline at end of file diff --git a/wiki/Manipulation.md b/wiki/Manipulation.md new file mode 100644 index 0000000..255df6a --- /dev/null +++ b/wiki/Manipulation.md @@ -0,0 +1,45 @@ +## Example +``` +pq('div.old')->replaceWith( pq('div.new')->clone() )->appendTo('.trash')->prepend('Deleted')->... +``` +# Table of Contents + * [Changing Contents](#Changing_Contents.md) + * [Inserting Inside](#Inserting_Inside.md) + * [Inserting Outside](#Inserting_Outside.md) + * [Inserting Around](#Inserting_Around.md) + * [Replacing](#Replacing.md) + * [Removing](#Removing.md) + * [Copying](#Copying.md) +## Changing Contents + * **[html](http://docs.jquery.com/Manipulation/html)**[()](http://docs.jquery.com/Manipulation/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/Manipulation/html)**[($val)](http://docs.jquery.com/Manipulation/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](http://docs.jquery.com/Manipulation/text)**[()](http://docs.jquery.com/Manipulation/text) Get the combined text contents of all matched elements. + * **[text](http://docs.jquery.com/Manipulation/text)**[($val)](http://docs.jquery.com/Manipulation/text) Set the text contents of all matched elements. +## Inserting Inside + * **[append](http://docs.jquery.com/Manipulation/append)**[($content)](http://docs.jquery.com/Manipulation/append) Append content to the inside of every matched element. + * **[appendTo](http://docs.jquery.com/Manipulation/appendTo)**[($content)](http://docs.jquery.com/Manipulation/appendTo) Append all of the matched elements to another, specified, set of elements. + * **[prepend](http://docs.jquery.com/Manipulation/prepend)**[($content)](http://docs.jquery.com/Manipulation/prepend) Prepend content to the inside of every matched element. + * **[prependTo](http://docs.jquery.com/Manipulation/prependTo)**[($content)](http://docs.jquery.com/Manipulation/prependTo) Prepend all of the matched elements to another, specified, set of elements. +## Inserting Outside + * **[after](http://docs.jquery.com/Manipulation/after)**[($content)](http://docs.jquery.com/Manipulation/after) Insert content after each of the matched elements. + * **[before](http://docs.jquery.com/Manipulation/before)**[($content)](http://docs.jquery.com/Manipulation/before) Insert content before each of the matched elements. + * **[insertAfter](http://docs.jquery.com/Manipulation/insertAfter)**[($content)](http://docs.jquery.com/Manipulation/insertAfter) Insert all of the matched elements after another, specified, set of elements. + * **[insertBefore](http://docs.jquery.com/Manipulation/insertBefore)**[($content)](http://docs.jquery.com/Manipulation/insertBefore) Insert all of the matched elements before another, specified, set of elements. +## Inserting Around + * **[wrap](http://docs.jquery.com/Manipulation/wrap)**[($html)](http://docs.jquery.com/Manipulation/wrap) Wrap each matched element with the specified HTML content. + * **[wrap](http://docs.jquery.com/Manipulation/wrap)**[($elem)](http://docs.jquery.com/Manipulation/wrap) Wrap each matched element with the specified element. + * **[wrapAll](http://docs.jquery.com/Manipulation/wrapAll)**[($html)](http://docs.jquery.com/Manipulation/wrapAll) Wrap all the elements in the matched set into a single wrapper element. + * **[wrapAll](http://docs.jquery.com/Manipulation/wrapAll)**[($elem)](http://docs.jquery.com/Manipulation/wrapAll) Wrap all the elements in the matched set into a single wrapper element. + * **[wrapInner](http://docs.jquery.com/Manipulation/wrapInner)**[($html)](http://docs.jquery.com/Manipulation/wrapInner) Wrap the inner child contents of each matched element (including text nodes) with an HTML structure. + * **[wrapInner](http://docs.jquery.com/Manipulation/wrapInner)**[($elem)](http://docs.jquery.com/Manipulation/wrapInner) Wrap the inner child contents of each matched element (including text nodes) with a DOM element. +## Replacing + * **[replaceWith](http://docs.jquery.com/Manipulation/replaceWith)**[($content)](http://docs.jquery.com/Manipulation/replaceWith) Replaces all matched elements with the specified HTML or DOM elements. + * **[replaceAll](http://docs.jquery.com/Manipulation/replaceAll)**[($selector)](http://docs.jquery.com/Manipulation/replaceAll) Replaces the elements matched by the specified selector with the matched elements. +## Removing + * **[empty](http://docs.jquery.com/Manipulation/empty)**[()](http://docs.jquery.com/Manipulation/empty) Remove all child nodes from the set of matched elements. + * **[remove](http://docs.jquery.com/Manipulation/remove)**[($expr)](http://docs.jquery.com/Manipulation/remove) Removes all matched elements from the DOM. +## Copying + * **[clone](http://docs.jquery.com/Manipulation/clone)**[()](http://docs.jquery.com/Manipulation/clone) Clone matched DOM Elements and select the clones. + * **[clone](http://docs.jquery.com/Manipulation/clone)**[($true)](http://docs.jquery.com/Manipulation/clone) Clone matched DOM Elements, and all their event handlers, and select the clones. + +Read more at [Manipulation](http://docs.jquery.com/Manipulation) section on [jQuery Documentation Site](http://docs.jquery.com/). \ No newline at end of file diff --git a/wiki/MultiDocumentSupport.md b/wiki/MultiDocumentSupport.md new file mode 100644 index 0000000..6febb38 --- /dev/null +++ b/wiki/MultiDocumentSupport.md @@ -0,0 +1,53 @@ +## What MultiDocumentSupport is + * support for working on several documents in same time + * easy importing of nodes from one document to another + * pointing document thought + * phpQuery object + * [DOMNode](http://www.php.net/manual/en/class.domnode.php) object + * [DOMDocument](http://www.php.net/manual/en/class.domdocument.php) object + * internal document ID + * last created (or selected) document is assumed to be default in pq(); +## What MultiDocumentSupport is NOT + * it's **not possible** to fetch nodes from several document in one query + * it's **not possible** to operate on nodes from several document in one phpQuery object + +## Example +``` +// first three documents are wrapped inside phpQuery +$doc1 = phpQuery::newDocumentFile('my-file.html'); +$doc2 = phpQuery::newDocumentFile('my-file.html'); +$doc3 = phpQuery::newDocumentFile('my-other-file.html'); +// $doc4 is plain DOMDocument +$doc4 = new DOMDocument; +$doc4->loadHTMLFile('my-file.html'); +// find first UL list in $doc1 +$doc1->find('ul:first') + // append all LIs from $doc2 (node import) + ->append( $doc2->find('li') ) + // append UL (with new LIs) into $doc3 BODY (node import) + ->appendTo( $doc3->find('body') ); +// this will find all LIs from $doc3 +// thats because it was created as last one +pq('li'); +// this will find all LIs inside first UL in $doc2 (context query) +pq('li', $doc2->find('ul:first')->get()); +// this will find all LIs in whole $doc2 (not a context query) +pq('li', $doc2->find('ul:first')->getDocumentID()); +// this will transparently load $doc4 into phpQuery::$documents +// and then all LIs will be found +// TODO this example must be verified +pq('li', $doc4); +``` +## Static Methods + * phpQuery::**newDocument**($html) Creates new document from markup + * phpQuery::**newDocumentFile**($file) Creates new document from file + * phpQuery::**getDocument**($id = null) Returns phpQueryObject containing document with id $id or default document (last created/selected) + * phpQuery::**selectDocument**($id) Sets default document to $id + * phpQuery::**unloadDocuments**($id = null) Unloades all or specified document from memory + * phpQuery::**getDocumentID**($source) Returns $source's document ID + * phpQuery::**getDOMDocument**($source) Get DOMDocument object related to $source +## Object Methods + * $pq->**getDocument**() Returns object with stack set to document root + * $pq->**getDocumentID**() Get object's Document ID + * $pq->**getDocumentIDRef**(&$documentID) Saves object's DocumentID to $var by reference + * $pq->**unloadDocument**() Unloads whole document from memory \ No newline at end of file diff --git a/wiki/PHPSupport.md b/wiki/PHPSupport.md new file mode 100644 index 0000000..f5e9987 --- /dev/null +++ b/wiki/PHPSupport.md @@ -0,0 +1,78 @@ +Although **phpQuery** is a [jQuery port](jQueryPortingState.md), there is extensive PHP-specific support. + +# Table of Contents + * [Class Interfaces](#Class_Interfaces.md) + * [Iterator Interface](#Iterator.md) + * [ArrayAccess](#Array_Access.md) + * [Countable Interface](#Countable.md) + * [Callbacks](Callbacks.md) + * [PHP Code Support](#PHP_Code_Support.md) + * [Opening PHP files as DOM](#Opening_PHP_files_as_DOM.md) + * [Inputting PHP code](#Inputting_PHP_code.md) + * [Outputting PHP code](#Outputting_PHP_code.md) + +## Class Interfaces +phpQuery implements some of [Standard PHP Library (SPL)](http://pl.php.net/spl) interfaces. +#### Iterator +Iterator interface allows looping objects thou native PHP **foreach loop**. Example: +``` +// get all direct LI elements from UL list of class 'im-the-list' +$LIs = pq('ul.im-the-list > li'); +foreach($LIs as $li) { + pq($li)->addClass('foreached'); +} +``` +Now there is a catch above. Foreach loop **doesn't return phpQuery object**. Instead it returns pure DOMNode. That's how jQuery does, because not always you need **phpQuery** when you found interesting nodes. +#### Array Access +If you like writing arrays, with phpQuery you can still do it, thanks to the ArrayAccess interface. +``` +$pq = phpQuery::newDocumentFile('somefile.html'); +// print first list outer HTML +print $pq['ul:first']; +// change INNER HTML of second LI directly in first UL +$pq['ul:first > li:eq(1)'] = 'new inner html of second LI directly in first UL'; +// now look at the difference (outer vs inner) +print $pq['ul:first > li:eq(1)']; +// will print
  • new inner html of second LI directly in first UL
  • +``` +#### Countable +If used to do `count($something)` you can still do this that way, instead of eg `pq('p')->size()`. +``` +// count all direct LIs in first list +print count(pq('ul:first > li')); +``` +## Callbacks +There is a special [Callbacks](Callbacks.md) wiki section, to which you should refer to. +## PHP Code Support +#### Opening PHP files as DOM +PHP files can be opened using **phpQuery::newDocumentPHP($markup)** or **phpQuery::newDocumentFilePHP($file)**. Such files are visible as DOM, where: + * PHP tags beetween DOM elements are available (queryable) as ` ...code... ` + * PHP tags inside attributes are HTML entities + * PHP tags between DOM element's attributes are **not yet supported** +#### Inputting PHP code +Additional methods allows placing PHP code inside DOM. Below each method visible is it's logic equivalent. + * **attrPHP**($attr, $code) + * [attr](http://docs.jquery.com/Attributes/attr)($attr, "") + * **addClassPHP**($code) + * [addClass](http://docs.jquery.com/Attributes/addClass)("") + * **beforePHP**($code) + * [before](http://docs.jquery.com/Manipulation/before)("") + * **afterPHP**($code) + * [after](http://docs.jquery.com/Manipulation/after)("") + * **prependPHP**($code) + * [prepend](http://docs.jquery.com/Manipulation/prepend)("") + * **appendPHP**($code) + * [append](http://docs.jquery.com/Manipulation/append)("") + * **php**($code) + * [html](http://docs.jquery.com/Manipulation/html)("") + * **wrapAllPHP**($codeBefore, $codeAfter) + * [wrapAll](http://docs.jquery.com/Manipulation/wrapAll)("") + * **wrapPHP**($codeBefore, $codeAfter) + * [wrap](http://docs.jquery.com/Manipulation/wrap)("") + * **wrapInnerPHP**($codeBefore, $codeAfter) + * [wrapInner](http://docs.jquery.com/Manipulation/wrapInner)("") + * **replaceWithPHP**($code) + * [replaceWith](http://docs.jquery.com/Manipulation/replaceWith)("") +#### Outputting PHP code +Code inserted with methods above won't be returned as valid (runnable) using classic output methods such as **html()**. To make it work, **php()** method without parameter have to be used. Optionaly **phpQuery::markupToPHP($markup)** can activate tags in string outputed before. +**REMEMBER** Outputing runnable code and placing it on webserver is always dangerous ! \ No newline at end of file diff --git a/wiki/PluginsClientSidePorts.md b/wiki/PluginsClientSidePorts.md new file mode 100644 index 0000000..d7a2e28 --- /dev/null +++ b/wiki/PluginsClientSidePorts.md @@ -0,0 +1,7 @@ +In [Issue Tracker](http://code.google.com/p/phpquery/issues/list) there is a list of [plugins which are planned to be ported](http://code.google.com/p/phpquery/issues/list?can=2&q=label%3APort). +## JSON +Port of [JSON](http://jollytoad.googlepages.com/json.js) plugin. +``` +$jsonString = phpQuery::toJSON( pq('form')->serializeArray() ); +$array = phpQuery::parseJSON('{"foo": "bar"}'); +``` \ No newline at end of file diff --git a/wiki/PluginsServerSide.md b/wiki/PluginsServerSide.md new file mode 100644 index 0000000..641e34f --- /dev/null +++ b/wiki/PluginsServerSide.md @@ -0,0 +1,77 @@ +If you need to write plugin only for simple task, write a **script** using ScriptsPlugin. + +## Using plugins +Plugins are loaded using **plugin** method from phpQueryObject or phpQuery static namespace. +``` +// all calls to plugin below are equal +phpQuery::plugin('example') +phpQuery::plugin('example', 'example.php') +pq('ul')->plugin('example') +pq('ul')->plugin('example', 'example.php') +``` +## Writing plugins +Plugin consist from 2 classes - first extending **phpQueryObjects** (result of pq(); function) and second, extending static **phpQuery::$plugins** namespace. Plugin classes are never intialized, just method calls are forwarded in static way from phpQuery. + +#### Extending phpQueryObject +``` +/** + * phpQuery plugin class extending phpQuery object. + * Methods from this class are callable on every phpQuery object. + * + * Class name prefix 'phpQueryObjectPlugin_' must be preserved. + */ +abstract class phpQueryObjectPlugin_example { + /** + * Limit binded methods. + * + * null means all public. + * array means only specified ones. + * + * @var array|null + */ + public static $phpQueryMethods = null; + /** + * Enter description here... + * + * @param phpQueryObject $self + */ + public static function example($self, $arg1) { + // this method can be called on any phpQuery object, like this: + // pq('div')->example('$arg1 Value') + + // do something + $self->append('Im just an example !'); + // change stack of result object + return $self->find('div'); + } + protected static function helperFunction() { + // this method WONT be avaible as phpQuery method, + // because it isn't publicly callable + } +} +``` +#### Extending phpQuery +``` +/** + * phpQuery plugin class extending phpQuery static namespace. + * Methods from this class are callable as follows: + * phpQuery::$plugins->staticMethod() + * + * Class name prefix 'phpQueryPlugin_' must be preserved. + */ +abstract class phpQueryPlugin_example { + /** + * Limit binded methods. + * + * null means all public. + * array means only specified ones. + * + * @var array|null + */ + public static $phpQueryMethods = null; + public static function staticMethod() { + // this method can be called within phpQuery class namespace, like this: + // phpQuery::$plugins->staticMethod() + } +} +``` \ No newline at end of file diff --git a/wiki/README.md b/wiki/README.md new file mode 100644 index 0000000..79c4866 --- /dev/null +++ b/wiki/README.md @@ -0,0 +1,24 @@ + 1. [Basics](Basics.md) + 1. [Ported jQuery sections](jQueryPortingState.md) + 1. [Selectors](Selectors.md) + 1. [Attributes](Attributes.md) + 1. [Traversing](Traversing.md) + 1. [Manipulation](Manipulation.md) + 1. [Ajax](Ajax.md) + 1. [Events](Events.md) + 1. [Utilities](Utilities.md) + 1. [Plugin ports](PluginsClientSidePorts.md) + 1. [PHP Support](PHPSupport.md) + 1. [Command Line Interface](CommandLineInterface.md) + 1. [Multi document support](MultiDocumentSupport.md) + 1. [Plugins](PluginsServerSide.md) + 1. [WebBrowser](WebBrowser.md) + 1. [Scripts](ScriptsPlugin.md) + 1. [jQueryServer](jQueryServer.md) + 1. [Debugging](Debugging.md) + 1. Bootstrap file + + +This manual is copied from http://code.google.com/p/phpquery/wiki/Manual + +The wiki was downloaded from the [Google Code source repository for phpQuery](https://code.google.com/p/phpquery/source/browse/#svn%2Fwiki), which is under the MIT License. diff --git a/wiki/ReleasePackages.md b/wiki/ReleasePackages.md new file mode 100644 index 0000000..c5929ca --- /dev/null +++ b/wiki/ReleasePackages.md @@ -0,0 +1,11 @@ +# This page is TODO + +## Formats + * RPM + * ZIP + +## Forms + * Standard + * OneFile + * Broken plugins support ? + * ZendFramework not included \ No newline at end of file diff --git a/wiki/ScriptsPlugin.md b/wiki/ScriptsPlugin.md new file mode 100644 index 0000000..f8e5921 --- /dev/null +++ b/wiki/ScriptsPlugin.md @@ -0,0 +1,24 @@ +ScriptsPlugin simplifies writing short code scripts which can be easily reused (chained). It removes plugin overhead allowing script to be one-line command. + +## Using scripts +Before using any script, you need to load **Scripts** plugin, like so: +``` +phpQuery::plugin('Scripts'); +// or inside a chain +pq('li')->plugin('Scripts'); +``` +After that, any available script can be used thou **script** method. +``` +print pq('div')->script('safe_print'); +``` +## Writing scripts +Scripts are placed in **/phpQuery/plugins/Scripts**. Each script has it's own file. Each file has access to 4 variables: + * **$self** Represents $this + * **$params** Represents parameters passed to script() method (without script name) + * **$return** If not null, will be used as method result + * **$config** Content of config.php file +By default each script returns $self aka $this. +##### Example script +``` +$return = $self->find($params[0]); +``` \ No newline at end of file diff --git a/wiki/Selectors.md b/wiki/Selectors.md new file mode 100644 index 0000000..0d737bc --- /dev/null +++ b/wiki/Selectors.md @@ -0,0 +1,76 @@ +Selectors are the heart of jQuery-like interface. Most of [CSS Level 3](http://www.w3.org/TR/2005/WD-css3-selectors-20051215/) syntax is implemented (in state same as in jQuery). +## Example +``` +pq(".class ul > li[rel='foo']:first:has(a)")->appendTo('.append-target-wrapper div')->... +``` +# Table of Contents + * [Basics](#Basics.md) + * [Hierarchy](#Hierarchy.md) + * [Basic Filters](#Basic_Filters.md) + * [Content Filters](#Content_Filters.md) + * [Visibility Filters](#Visibility_Filters.md) + * [Attribute Filters](#Attribute_Filters.md) + * [Child Filters](#Child_Filters.md) + * [Forms](#Forms.md) + * [Form Filters](#Form_Filters.md) +## Basics + * **[#id](http://docs.jquery.com/Selectors/id)** Matches a single element with the given id attribute. + * **[element](http://docs.jquery.com/Selectors/element)** Matches all elements with the given name. + * **[.class](http://docs.jquery.com/Selectors/class)** Matches all elements with the given class. + * **[\*](http://docs.jquery.com/Selectors/all)** Matches all elements. + * **[selector1, selector2, selectorN](http://docs.jquery.com/Selectors/multiple)** Matches the combined results of all the specified selectors. +## Hierarchy + * **[ancestor descendant](http://docs.jquery.com/Selectors/descendant)** Matches all descendant elements specified by "descendant" of elements specified by "ancestor". + * **[parent > child](http://docs.jquery.com/Selectors/child)** Matches all child elements specified by "child" of elements specified by "parent". + * **[prev + next](http://docs.jquery.com/Selectors/next)** Matches all next elements specified by "next" that are next to elements specified by "prev". + * **[prev ~ siblings](http://docs.jquery.com/Selectors/siblings)** Matches all sibling elements after the "prev" element that match the filtering "siblings" selector. +## Basic Filters + * **[:first](http://docs.jquery.com/Selectors/first)** Matches the first selected element. + * **[:last](http://docs.jquery.com/Selectors/last)** Matches the last selected element. + * **[:not(selector)](http://docs.jquery.com/Selectors/not)** Filters out all elements matching the given selector. + * **[:even](http://docs.jquery.com/Selectors/even)** Matches even elements, zero-indexed. + * **[:odd](http://docs.jquery.com/Selectors/odd)** Matches odd elements, zero-indexed. + * **[:eq(index)](http://docs.jquery.com/Selectors/eq)** Matches a single element by its index. + * **[:gt(index)](http://docs.jquery.com/Selectors/gt)** Matches all elements with an index above the given one. + * **[:lt(index)](http://docs.jquery.com/Selectors/lt)** Matches all elements with an index below the given one. + * **[:header](http://docs.jquery.com/Selectors/header)** Matches all elements that are headers, like h1, h2, h3 and so on. + * **[:animated](http://docs.jquery.com/Selectors/animated)** Matches all elements that are currently being animated. +## Content Filters + * **[:contains(text)](http://docs.jquery.com/Selectors/contains)** Matches elements which contain the given text. + * **[:empty](http://docs.jquery.com/Selectors/empty)** Matches all elements that have no children (including text nodes). + * **[:has(selector)](http://docs.jquery.com/Selectors/has)** Matches elements which contain at least one element that matches the specified selector. + * **[:parent](http://docs.jquery.com/Selectors/parent)** Matches all elements that are parents - they have child elements, including text. +## Visibility Filters +_none_ +## Attribute Filters + * **[[attribute](http://docs.jquery.com/Selectors/attributeHas)]** Matches elements that have the specified attribute. + * **[[attribute=value](http://docs.jquery.com/Selectors/attributeEquals)]** Matches elements that have the specified attribute with a certain value. + * **[[attribute!=value](http://docs.jquery.com/Selectors/attributeNotEqual)]** Matches elements that don't have the specified attribute with a certain value. + * **[[attribute^=value](http://docs.jquery.com/Selectors/attributeStartsWith)]** Matches elements that have the specified attribute and it starts with a certain value. + * **[[attribute$=value](http://docs.jquery.com/Selectors/attributeEndsWith)]** Matches elements that have the specified attribute and it ends with a certain value. + * **[[attribute\*=value](http://docs.jquery.com/Selectors/attributeContains)]** Matches elements that have the specified attribute and it contains a certain value. + * **[[selector1](http://docs.jquery.com/Selectors/attributeMultiple)[selector2](selector2.md)[selectorN](selectorN.md)]** Matches elements that have the specified attribute and it contains a certain value. +## Child Filters + * **[:nth-child(index/even/odd/equation)](http://docs.jquery.com/Selectors/nthChild)** Matches all elements that are the nth-child of their parent or that are the parent's even or odd children. + * **[:first-child](http://docs.jquery.com/Selectors/firstChild)** Matches all elements that are the first child of their parent. + * **[:last-child](http://docs.jquery.com/Selectors/lastChild)** Matches all elements that are the last child of their parent. + * **[:only-child](http://docs.jquery.com/Selectors/onlyChild)** Matches all elements that are the only child of their parent. +## Forms + * **[:input](http://docs.jquery.com/Selectors/input)** Matches all input, textarea, select and button elements. + * **[:text](http://docs.jquery.com/Selectors/text)** Matches all input elements of type text. + * **[:password](http://docs.jquery.com/Selectors/password)** Matches all input elements of type password. + * **[:radio](http://docs.jquery.com/Selectors/radio)** Matches all input elements of type radio. + * **[:checkbox](http://docs.jquery.com/Selectors/checkbox)** Matches all input elements of type checkbox. + * **[:submit](http://docs.jquery.com/Selectors/submit)** Matches all input elements of type submit. + * **[:image](http://docs.jquery.com/Selectors/image)** Matches all input elements of type image. + * **[:reset](http://docs.jquery.com/Selectors/reset)** Matches all input elements of type reset. + * **[:button](http://docs.jquery.com/Selectors/button)** Matches all button elements and input elements of type button. + * **[:file](http://docs.jquery.com/Selectors/file)** Matches all input elements of type file. + * **[:hidden](http://docs.jquery.com/Selectors/hidden)** Matches all elements that are hidden, or input elements of type "hidden". +## Form Filters + * **[:enabled](http://docs.jquery.com/Selectors/enabled)** Matches all elements that are enabled. + * **[:disabled](http://docs.jquery.com/Selectors/disabled)** Matches all elements that are disabled. + * **[:checked](http://docs.jquery.com/Selectors/checked)** Matches all elements that are checked. + * **[:selected](http://docs.jquery.com/Selectors/selected)** Matches all elements that are selected. + +Read more at [Selectors](http://docs.jquery.com/Selectors) section on [jQuery Documentation Site](http://docs.jquery.com/). \ No newline at end of file diff --git a/wiki/Traversing.md b/wiki/Traversing.md new file mode 100644 index 0000000..cc89f5b --- /dev/null +++ b/wiki/Traversing.md @@ -0,0 +1,34 @@ +## Example +``` +pq('div > p')->add('div > ul')->filter(':has(a)')->find('p:first')->nextAll()->andSelf()->... +``` +# Table of Contents + * [Filtering](#Filtering.md) + * [Finding](#Finding.md) + * [Chaining](#Chaining.md) +## Filtering + * **[eq](http://docs.jquery.com/Traversing/eq)**[($index)](http://docs.jquery.com/Traversing/eq) Reduce the set of matched elements to a single element. + * **[hasClass](http://docs.jquery.com/Traversing/hasClass)**[($class)](http://docs.jquery.com/Traversing/hasClass) Checks the current selection against a class and returns true, if at least one element of the selection has the given class. + * **[filter](http://docs.jquery.com/Traversing/filter)**[($expr)](http://docs.jquery.com/Traversing/filter) Removes all elements from the set of matched elements that do not match the specified expression(s). + * **[filter](http://docs.jquery.com/Traversing/filter)**[($fn)](http://docs.jquery.com/Traversing/filter) Removes all elements from the set of matched elements that does not match the specified function. + * **[is](http://docs.jquery.com/Traversing/is)**[($expr)](http://docs.jquery.com/Traversing/is) Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression. + * **[map](http://docs.jquery.com/Traversing/map)**[($callback)](http://docs.jquery.com/Traversing/map) Translate a set of elements in the jQuery object into another set of values in an array (which may, or may not, be elements). + * **[not](http://docs.jquery.com/Traversing/not)**[($expr)](http://docs.jquery.com/Traversing/not) Removes elements matching the specified expression from the set of matched elements. + * **[slice](http://docs.jquery.com/Traversing/slice)**[($start, $end)](http://docs.jquery.com/Traversing/slice) Selects a subset of the matched elements. +## Finding + * **[add](http://docs.jquery.com/Traversing/add)**[($expr)](http://docs.jquery.com/Traversing/add) Adds more elements, matched by the given expression, to the set of matched elements. + * **[children](http://docs.jquery.com/Traversing/children)**[($expr)](http://docs.jquery.com/Traversing/children) Get a set of elements containing all of the unique immediate children of each of the matched set of elements. + * **[contents](http://docs.jquery.com/Traversing/contents)**[()](http://docs.jquery.com/Traversing/contents) Find all the child nodes inside the matched elements (including text nodes), or the content document, if the element is an iframe. + * **[find](http://docs.jquery.com/Traversing/find)**[($expr)](http://docs.jquery.com/Traversing/find) Searches for all elements that match the specified expression. This method is a good way to find additional descendant elements with which to process. + * **[next](http://docs.jquery.com/Traversing/next)**[($expr)](http://docs.jquery.com/Traversing/next) Get a set of elements containing the unique next siblings of each of the given set of elements. + * **[nextAll](http://docs.jquery.com/Traversing/nextAll)**[($expr)](http://docs.jquery.com/Traversing/nextAll) Find all sibling elements after the current element. + * **[parent](http://docs.jquery.com/Traversing/parent)**[($expr)](http://docs.jquery.com/Traversing/parent) Get a set of elements containing the unique parents of the matched set of elements. + * **[parents](http://docs.jquery.com/Traversing/parents)**[($expr)](http://docs.jquery.com/Traversing/parents) Get a set of elements containing the unique ancestors of the matched set of elements (except for the root element). The matched elements can be filtered with an optional expression. + * **[prev](http://docs.jquery.com/Traversing/prev)**[($expr)](http://docs.jquery.com/Traversing/prev) Get a set of elements containing the unique previous siblings of each of the matched set of elements. + * **[prevAll](http://docs.jquery.com/Traversing/prevAll)**[($expr)](http://docs.jquery.com/Traversing/prevAll) Find all sibling elements before the current element. + * **[siblings](http://docs.jquery.com/Traversing/siblings)**[($expr)](http://docs.jquery.com/Traversing/siblings) Get a set of elements containing all of the unique siblings of each of the matched set of elements. Can be filtered with an optional expressions. +## Chaining + * **[andSelf](http://docs.jquery.com/Traversing/andSelf)**[()](http://docs.jquery.com/Traversing/andSelf) Add the previous selection to the current selection. + * **[end](http://docs.jquery.com/Traversing/end)**[()](http://docs.jquery.com/Traversing/end) Revert the most recent 'destructive' operation, changing the set of matched elements to its previous state (right before the destructive operation). + +Read more at [Traversing](http://docs.jquery.com/Traversing) section on [jQuery Documentation Site](http://docs.jquery.com/). \ No newline at end of file diff --git a/wiki/Utilities.md b/wiki/Utilities.md new file mode 100644 index 0000000..b42720a --- /dev/null +++ b/wiki/Utilities.md @@ -0,0 +1,20 @@ +# Table of Contents + * [User Agent](#User_Agent.md) + * [Array and Object operations](#Array_and_Object_operations.md) + * [Test operations](#Test_operations.md) + * [String operations](#String_operations.md) +## User Agent +_none_ +## Array and Object operations + * **[phpQuery::each](http://docs.jquery.com/Utilities/jQuery.each)**[($object, $callback)](http://docs.jquery.com/Utilities/jQuery.each) A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. + * **[phpQuery::grep](http://docs.jquery.com/Utilities/jQuery.grep)**[($array, $callback, $invert)](http://docs.jquery.com/Utilities/jQuery.grep) Filter items out of an array, by using a filter function. + * **[phpQuery::makeArray](http://docs.jquery.com/Utilities/jQuery.makeArray)**[($obj)](http://docs.jquery.com/Utilities/jQuery.makeArray) Turns an array-like object into a true array. + * **[phpQuery::map](http://docs.jquery.com/Utilities/jQuery.map)**[($array, $callback)](http://docs.jquery.com/Utilities/jQuery.map) Translate all items in an array to another array of items. + * **[phpQuery::inArray](http://docs.jquery.com/Utilities/jQuery.inArray)**[($value, $array)](http://docs.jquery.com/Utilities/jQuery.inArray) Determine the index of the first parameter in the Array (-1 if not found). + * **[phpQuery::unique](http://docs.jquery.com/Utilities/jQuery.unique)**[($array)](http://docs.jquery.com/Utilities/jQuery.unique) Remove all duplicate elements from an array of elements. +## Test operations + * **[phpQuery::isFunction](http://docs.jquery.com/Utilities/jQuery.isFunction)**[($obj)](http://docs.jquery.com/Utilities/jQuery.isFunction) Determine if the parameter passed is a function. +## String operations + * **[phpQuery::trim](http://docs.jquery.com/Utilities/jQuery.trim)**[($str)](http://docs.jquery.com/Utilities/jQuery.trim) Remove the whitespace from the beginning and end of a string. + +Read more at [Utilities](http://docs.jquery.com/Utilities) section on [jQuery Documentation Site](http://docs.jquery.com/). \ No newline at end of file diff --git a/wiki/WebBrowser.md b/wiki/WebBrowser.md new file mode 100644 index 0000000..6b189c1 --- /dev/null +++ b/wiki/WebBrowser.md @@ -0,0 +1,37 @@ +**WebBrowser** is a phpQuery [plugin](PluginsServerSide.md) that mimics behaviors of web browser. Thanks to that developer can simulate user's behavior inside a PHP script. + +## Supported + * Link navigation (click event) + * Form navigation (submit event) + * Cookies (thought [Zend\_Http\_CookieJar](http://framework.zend.com/manual/en/zend.http.cookies.html)) + * Relative links + * document.location (not an object, yet) + +## Use cases + * Fill forms and submit them easly + * Login to secure pages and collect content + * Write test cases reproducing browsing proccess + +## Example 1 +Adding web browser functionality to existing phpQuery object and submiting the form. +``` +->WebBrowser('callback')->find('form')->submit()->... +``` + +## Example 2 +Querying Google against "search phrase": +``` +require_once('phpQuery/phpQuery.php'); +phpQuery::browserGet('http://www.google.com/', 'success1'); +function success1($browser) { + $browser + ->WebBrowser('success2') + ->find('input[name=q]') + ->val('search phrase') + ->parents('form') + ->submit(); +} +function success2($browser) { + print $browser; +} +``` \ No newline at end of file diff --git a/wiki/jQueryDifferences.md b/wiki/jQueryDifferences.md new file mode 100644 index 0000000..2d87ca9 --- /dev/null +++ b/wiki/jQueryDifferences.md @@ -0,0 +1 @@ +Renamed to [jQueryPortingState](jQueryPortingState.md). \ No newline at end of file diff --git a/wiki/jQueryHelpers.md b/wiki/jQueryHelpers.md new file mode 100644 index 0000000..2df052a --- /dev/null +++ b/wiki/jQueryHelpers.md @@ -0,0 +1,3 @@ +jQuery helper libraries written in PHP + * [jquery-php](http://code.google.com/p/jquery-php/) + * [PQuery](http://www.ngcoders.com/php/pquery-php-and-jquery) \ No newline at end of file diff --git a/wiki/jQueryPortingState.md b/wiki/jQueryPortingState.md new file mode 100644 index 0000000..d4d75b5 --- /dev/null +++ b/wiki/jQueryPortingState.md @@ -0,0 +1,29 @@ +phpQuery is almost a full port of the [jQuery JavaScript Library](http://jquery.com/). + +## Ported Sections + 1. [Selectors](Selectors.md) + 1. [Attributes](Attributes.md) + 1. [Traversing](Traversing.md) + 1. [Manipulation](Manipulation.md) + 1. [Ajax](Ajax.md) + 1. [Events](Events.md) + 1. [Utilities](Utilities.md) + 1. [Plugin ports](PluginsClientSidePorts.md) + +## Additional methods +phpQuery features many additional methods comparing to jQuery: + * htmlOuter() + * xml() + * xmlOuter() + * markup() + * markupOuter() + * getString() + * reverse() + * contentsUnwrap() + * switchWith() + * all from [PHPSupport](PHPSupport.md) + * all from [Basic](Basic.md) + * all from [MultiDocumentSupport](MultiDocumentSupport.md) + +## Other Differences + * [Server Side Events](http://code.google.com/p/phpquery/wiki/Events?ts=1225458859&updated=Events#Server_Side_Events) \ No newline at end of file diff --git a/wiki/jQueryServer.md b/wiki/jQueryServer.md new file mode 100644 index 0000000..3be1b27 --- /dev/null +++ b/wiki/jQueryServer.md @@ -0,0 +1,16 @@ +**jQueryServer** is a jQuery plugin giving unobstrusive, client-side bindings to server-side implementation of jQuery. + +## Example scenario + 1. Connect to server and make an [Ajax](Ajax.md) request to somewhere ([crossdomain allowed](CrossDomainAjax.md)) + 1. Do some manipulations, you can even trigger a [server-side event](http://code.google.com/p/phpquery/wiki/Events#Server_Side_Events) + 1. Get processed date back to the browser + +## Example code +``` +$.server({url: 'http://somesite.com'}) + .find('.my-class') + .client(function(response){ + $('.destination').html(response); +}); +``` +Since version **0.5.1** (this is **not** phpQuery release version number) there is a support for config file which **authorizes** [Ajax](Ajax.md) hosts and referers. \ No newline at end of file diff --git a/wiki/jQueryServerSidePorts.md b/wiki/jQueryServerSidePorts.md new file mode 100644 index 0000000..5a6eeb5 --- /dev/null +++ b/wiki/jQueryServerSidePorts.md @@ -0,0 +1,6 @@ +jQuery ports to server-side languages: + * **PHP** - [phpQuery](http://code.google.com/p/phpquery/) + * **ActionScript** - [as3query](http://tech.nitoyon.com/blog/2008/01/as3query_alpha.html) + * **Ruby** - [hpricot](http://code.whytheluckystiff.net/hpricot/) + * **Perl** - [pQuery](http://search.cpan.org/~ingy/pQuery/lib/pQuery.pm) + * **Python** - [PyQuery](http://pypi.python.org/pypi/pyquery) \ No newline at end of file