From ecc4ca62202d150357b54f18b882b24888c1a835 Mon Sep 17 00:00:00 2001 From: Google Code Exporter Date: Mon, 25 May 2015 14:02:43 -0400 Subject: [PATCH] Migrating wiki contents from Google Code --- Ajax.md | 70 ++++++++++++++++++ Attributes.md | 33 +++++++++ Basics.md | 54 ++++++++++++++ CSS.md | 1 + Callbacks.md | 91 +++++++++++++++++++++++ Chains.md | 1 + CommandLineInterface.md | 14 ++++ Debugging.md | 16 +++++ Dependencies.md | 14 ++++ Events.md | 47 ++++++++++++ LibrarySections.md | 1 + Manipulation.md | 45 ++++++++++++ Manual.md | 21 ++++++ MultiDocumentSupport.md | 53 ++++++++++++++ PHPSupport.md | 78 ++++++++++++++++++++ PluginsClientSidePorts.md | 7 ++ PluginsServerSide.md | 77 ++++++++++++++++++++ ProjectHome.md | 147 ++++++++++++++++++++++++++++++++++++++ ReleasePackages.md | 11 +++ SVNCheckout.md | 14 ++++ ScriptsPlugin.md | 24 +++++++ Selectors.md | 76 ++++++++++++++++++++ Traversing.md | 34 +++++++++ Utilities.md | 20 ++++++ WebBrowser.md | 37 ++++++++++ jQueryDifferences.md | 1 + jQueryHelpers.md | 3 + jQueryPortingState.md | 29 ++++++++ jQueryServer.md | 16 +++++ jQueryServerSidePorts.md | 6 ++ test.md | 1 + 31 files changed, 1042 insertions(+) create mode 100644 Ajax.md create mode 100644 Attributes.md create mode 100644 Basics.md create mode 100644 CSS.md create mode 100644 Callbacks.md create mode 100644 Chains.md create mode 100644 CommandLineInterface.md create mode 100644 Debugging.md create mode 100644 Dependencies.md create mode 100644 Events.md create mode 100644 LibrarySections.md create mode 100644 Manipulation.md create mode 100644 Manual.md create mode 100644 MultiDocumentSupport.md create mode 100644 PHPSupport.md create mode 100644 PluginsClientSidePorts.md create mode 100644 PluginsServerSide.md create mode 100644 ProjectHome.md create mode 100644 ReleasePackages.md create mode 100644 SVNCheckout.md create mode 100644 ScriptsPlugin.md create mode 100644 Selectors.md create mode 100644 Traversing.md create mode 100644 Utilities.md create mode 100644 WebBrowser.md create mode 100644 jQueryDifferences.md create mode 100644 jQueryHelpers.md create mode 100644 jQueryPortingState.md create mode 100644 jQueryServer.md create mode 100644 jQueryServerSidePorts.md create mode 100644 test.md diff --git a/Ajax.md b/Ajax.md new file mode 100644 index 0000000..10160d5 --- /dev/null +++ b/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](http://code.google.com/p/phpquery/wiki/Ajax) 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/Attributes.md b/Attributes.md new file mode 100644 index 0000000..1381d91 --- /dev/null +++ b/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/Basics.md b/Basics.md new file mode 100644 index 0000000..309a8b1 --- /dev/null +++ b/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](http://code.google.com/p/phpquery/wiki/PHPSupport) + * 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](http://code.google.com/p/phpquery/wiki/PHPSupport) +## 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/CSS.md b/CSS.md new file mode 100644 index 0000000..e1a913a --- /dev/null +++ b/CSS.md @@ -0,0 +1 @@ +Work in progress. Scheduled before 1.0. \ No newline at end of file diff --git a/Callbacks.md b/Callbacks.md new file mode 100644 index 0000000..e47a904 --- /dev/null +++ b/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](http://code.google.com/p/phpquery/wiki/Ajax) 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/Chains.md b/Chains.md new file mode 100644 index 0000000..2ff4028 --- /dev/null +++ b/Chains.md @@ -0,0 +1 @@ +TODO ;) \ No newline at end of file diff --git a/CommandLineInterface.md b/CommandLineInterface.md new file mode 100644 index 0000000..92dd774 --- /dev/null +++ b/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/Debugging.md b/Debugging.md new file mode 100644 index 0000000..f290347 --- /dev/null +++ b/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/Dependencies.md b/Dependencies.md new file mode 100644 index 0000000..67bcba3 --- /dev/null +++ b/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/Events.md b/Events.md new file mode 100644 index 0000000..c1c8079 --- /dev/null +++ b/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](http://code.google.com/p/phpquery/wiki/Ajax) 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/LibrarySections.md b/LibrarySections.md new file mode 100644 index 0000000..d6a3885 --- /dev/null +++ b/LibrarySections.md @@ -0,0 +1 @@ +Renamed to [Manual](http://code.google.com/p/phpquery/wiki/Manual). \ No newline at end of file diff --git a/Manipulation.md b/Manipulation.md new file mode 100644 index 0000000..8d96a8d --- /dev/null +++ b/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/Manual.md b/Manual.md new file mode 100644 index 0000000..8eb8868 --- /dev/null +++ b/Manual.md @@ -0,0 +1,21 @@ + 1. [Basics](http://code.google.com/p/phpquery/wiki/Basics) + 1. [Ported jQuery sections](http://code.google.com/p/phpquery/wiki/jQueryPortingState) + 1. [Selectors](http://code.google.com/p/phpquery/wiki/Selectors) + 1. [Attributes](http://code.google.com/p/phpquery/wiki/Attributes) + 1. [Traversing](http://code.google.com/p/phpquery/wiki/Traversing) + 1. [Manipulation](http://code.google.com/p/phpquery/wiki/Manipulation) + 1. [Ajax](http://code.google.com/p/phpquery/wiki/Ajax) + 1. [Events](http://code.google.com/p/phpquery/wiki/Events) + 1. [Utilities](http://code.google.com/p/phpquery/wiki/Utilities) + 1. [Plugin ports](http://code.google.com/p/phpquery/wiki/PluginsClientSidePorts) + 1. [PHP Support](http://code.google.com/p/phpquery/wiki/PHPSupport) + 1. [Command Line Interface](http://code.google.com/p/phpquery/wiki/CommandLineInterface) + 1. [Multi document support](http://code.google.com/p/phpquery/wiki/MultiDocumentSupport) + 1. [Plugins](http://code.google.com/p/phpquery/wiki/PluginsServerSide) + 1. [WebBrowser](http://code.google.com/p/phpquery/wiki/WebBrowser) + 1. [Scripts](http://code.google.com/p/phpquery/wiki/ScriptsPlugin) + 1. [jQueryServer](http://code.google.com/p/phpquery/wiki/jQueryServer) + 1. [Debugging](http://code.google.com/p/phpquery/wiki/Debugging) + 1. Bootstrap file + +**[API Reference](http://meta20.net/phpquery-api/)** is also available. \ No newline at end of file diff --git a/MultiDocumentSupport.md b/MultiDocumentSupport.md new file mode 100644 index 0000000..07691a0 --- /dev/null +++ b/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/PHPSupport.md b/PHPSupport.md new file mode 100644 index 0000000..f51ce39 --- /dev/null +++ b/PHPSupport.md @@ -0,0 +1,78 @@ +Although **phpQuery** is a [jQuery port](http://code.google.com/p/phpquery/wiki/jQueryPortingState), 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](http://code.google.com/p/phpquery/wiki/Callbacks) + * [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](http://code.google.com/p/phpquery/wiki/Callbacks) 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/PluginsClientSidePorts.md b/PluginsClientSidePorts.md new file mode 100644 index 0000000..90763da --- /dev/null +++ b/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/PluginsServerSide.md b/PluginsServerSide.md new file mode 100644 index 0000000..21f111e --- /dev/null +++ b/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/ProjectHome.md b/ProjectHome.md new file mode 100644 index 0000000..ede8766 --- /dev/null +++ b/ProjectHome.md @@ -0,0 +1,147 @@ +# phpQuery - pq(); # +**phpQuery** is a server-side, chainable, CSS3 selector driven Document Object Model (DOM) API [based on](http://code.google.com/p/phpquery/wiki/jQueryPortingState) [jQuery JavaScript Library](http://jquery.com/). + +Library is written in [PHP5](http://code.google.com/p/phpquery/wiki/Dependencies) and provides additional [Command Line Interface](http://code.google.com/p/phpquery/wiki/CommandLineInterface) (CLI). + +## PEAR installation ## +``` +pear channel-discover phpquery-pear.appspot.com +pear install phpquery/phpQuery +``` + +## `GitHub` ## +Fork & pull request: [github.com/TobiaszCudnik/phpquery](https://github.com/TobiaszCudnik/phpquery). + +## [Download](http://code.google.com/p/phpquery/downloads/list) ## + * [Available packages](http://code.google.com/p/phpquery/downloads/list) ([rss](http://code.google.com/feeds/p/phpquery/downloads/basic)) + * [Release notes](http://phpquery-library.blogspot.com/search/label/release) + * Bugs: [active](http://code.google.com/p/phpquery/issues/list?can=2&q=label%3AType-Defect) / [fixed](http://code.google.com/p/phpquery/issues/list?can=1&q=label%3AType-Defect%20status%3AFixed) + * [Dependencies](http://code.google.com/p/phpquery/wiki/Dependencies) + * [SVN checkout](http://code.google.com/p/phpquery/wiki/SVNCheckout) + +## [Manual](http://code.google.com/p/phpquery/wiki/Manual) ## + 1. [Basics](http://code.google.com/p/phpquery/wiki/Basics) + 1. [Ported jQuery sections](http://code.google.com/p/phpquery/wiki/jQueryPortingState) + 1. [Selectors](http://code.google.com/p/phpquery/wiki/Selectors) + 1. [Attributes](http://code.google.com/p/phpquery/wiki/Attributes) + 1. [Traversing](http://code.google.com/p/phpquery/wiki/Traversing) + 1. [Manipulation](http://code.google.com/p/phpquery/wiki/Manipulation) + 1. [Ajax](http://code.google.com/p/phpquery/wiki/Ajax) + 1. [Events](http://code.google.com/p/phpquery/wiki/Events) + 1. [Utilities](http://code.google.com/p/phpquery/wiki/Utilities) + 1. [Plugin ports](http://code.google.com/p/phpquery/wiki/PluginsClientSidePorts) + 1. [PHP Support](http://code.google.com/p/phpquery/wiki/PHPSupport) + 1. [Command Line Interface](http://code.google.com/p/phpquery/wiki/CommandLineInterface) + 1. [Multi document support](http://code.google.com/p/phpquery/wiki/MultiDocumentSupport) + 1. [Plugins](http://code.google.com/p/phpquery/wiki/PluginsServerSide) + 1. [WebBrowser](http://code.google.com/p/phpquery/wiki/WebBrowser) + 1. [Scripts](http://code.google.com/p/phpquery/wiki/ScriptsPlugin) + 1. [jQueryServer](http://code.google.com/p/phpquery/wiki/jQueryServer) + 1. [Debugging](http://code.google.com/p/phpquery/wiki/Debugging) + 1. Bootstrap file + +## Documentation ## + * **[Wiki](http://code.google.com/p/phpquery/w/list)** + * [Manual](http://code.google.com/p/phpquery/wiki/Manual) + * [API reference](http://meta20.net/phpquery-api/) + * [jQuery documentation wiki](http://docs.jquery.com/Main_Page) + * [CHM version](http://www.box.net/index.php?rm=box_download_shared_file&file_id=f_196697302&shared_name=p5gk0bnk94) + * [CheatSheet](http://colorcharge.com/wp-content/uploads/2007/12/jquery12_colorcharge.png) + +## Publications ## + * **[Official blog](http://phpquery-library.blogspot.com/)** with latest [release notes](http://phpquery-library.blogspot.com/search/label/release) + * [Author's blog](http://tobiasz123.wordpress.com/) with [examples and new feature sneak peaks](http://tobiasz123.wordpress.com/tag/phpquery/) + * Follow **[phpQuery on Twitter](http://twitter.com/phpQuery)** + * Roadmap: [Planned](http://code.google.com/p/phpquery/issues/list?q=label%3AEnhancement&can=2&sort=milestone) / [Completed](http://code.google.com/p/phpquery/issues/list?can=1&q=label%3AEnhancement%20status%3AFixed&sort=milestone) + +## Feedback ## + * **[Issue/Bug Tracker](http://code.google.com/p/phpquery/issues/list?sort=milestone)** ([new issue](http://code.google.com/p/phpquery/issues/entry)) + * **[Google Group](http://groups.google.com/group/phpquery/topics?gvc=2)** + * **IRC** #phpquery at [freenode.net](http://freenode.net/) + * **ohloh.net** has [phpQuery project](https://www.ohloh.net/projects/phpquery) + +--- + +# Examples # +## [CLI](CommandLineInterface.md) ## +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 +``` +## PHP ## +Examples from [demo.php](http://code.google.com/p/phpquery/source/browse/branches/dev/demo.php) +``` +require('phpQuery/phpQuery.php'); +// for PEAR installation use this +// require('phpQuery.php'); +``` + +#### INITIALIZE IT #### +``` +// $doc = phpQuery::newDocumentHTML($markup); +// $doc = phpQuery::newDocumentXML(); +// $doc = phpQuery::newDocumentFileXHTML('test.html'); +// $doc = phpQuery::newDocumentFilePHP('test.php'); +// $doc = phpQuery::newDocument('test.xml', 'application/rss+xml'); +// this one defaults to text/html in utf8 +$doc = phpQuery::newDocument('
    '); +``` + +#### FILL IT #### +``` +// array syntax works like ->find() here +$doc['div']->append('
      '); +// array set changes inner html +$doc['div ul'] = '
    • 1
    • 2
    • 3
    • '; +``` + +#### MANIPULATE IT #### +``` +// almost everything can be a chain +$li = null; +$doc['ul > li'] + ->addClass('my-new-class') + ->filter(':last') + ->addClass('last-li') +// save it anywhere in the chain + ->toReference($li); +``` + +#### SELECT DOCUMENT #### +``` +// pq(); is using selected document as default +phpQuery::selectDocument($doc); +// documents are selected when created or by above method +// query all unordered lists in last selected document +pq('ul')->insertAfter('div'); +``` + +#### ITERATE IT #### +``` +// all LIs from last selected DOM +foreach(pq('li') as $li) { + // iteration returns PLAIN dom nodes, NOT phpQuery objects + $tagName = $li->tagName; + $childNodes = $li->childNodes; + // so you NEED to wrap it within phpQuery, using pq(); + pq($li)->addClass('my-second-new-class'); +} +``` + +#### PRINT OUTPUT #### +``` +// 1st way +print phpQuery::getDocument($doc->getDocumentID()); +// 2nd way +print phpQuery::getDocument(pq('div')->getDocumentID()); +// 3rd way +print pq('div')->getDocument(); +// 4th way +print $doc->htmlOuter(); +// 5th way +print $doc; +// another... +print $doc['ul']; +``` \ No newline at end of file diff --git a/ReleasePackages.md b/ReleasePackages.md new file mode 100644 index 0000000..13b8767 --- /dev/null +++ b/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/SVNCheckout.md b/SVNCheckout.md new file mode 100644 index 0000000..0258eb1 --- /dev/null +++ b/SVNCheckout.md @@ -0,0 +1,14 @@ +#### Checkout latest release #### +``` +svn checkout http://phpquery.googlecode.com/svn/trunk/ phpQuery +``` +#### Checkout developer branch #### +``` +svn checkout http://phpquery.googlecode.com/svn/branches/dev/ phpQuery-dev +``` + +You can directly [browse the code](http://code.google.com/p/phpquery/source/browse/) using web interface. + +SVN changelog is also available thou [web interface](http://code.google.com/p/phpquery/source/list) and also as [RSS](http://code.google.com/feeds/p/phpquery/svnchanges/basic). + +Get SVN for Windows from [TortoiseSVN](http://tortoisesvn.tigris.org/). \ No newline at end of file diff --git a/ScriptsPlugin.md b/ScriptsPlugin.md new file mode 100644 index 0000000..70780b2 --- /dev/null +++ b/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/Selectors.md b/Selectors.md new file mode 100644 index 0000000..b696c47 --- /dev/null +++ b/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/Traversing.md b/Traversing.md new file mode 100644 index 0000000..9c0b600 --- /dev/null +++ b/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/Utilities.md b/Utilities.md new file mode 100644 index 0000000..c1c5421 --- /dev/null +++ b/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/WebBrowser.md b/WebBrowser.md new file mode 100644 index 0000000..2ffe7d3 --- /dev/null +++ b/WebBrowser.md @@ -0,0 +1,37 @@ +**WebBrowser** is a phpQuery [plugin](http://code.google.com/p/phpquery/wiki/PluginsServerSide) 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/jQueryDifferences.md b/jQueryDifferences.md new file mode 100644 index 0000000..4cc32f2 --- /dev/null +++ b/jQueryDifferences.md @@ -0,0 +1 @@ +Renamed to [jQueryPortingState](http://code.google.com/p/phpquery/wiki/jQueryPortingState). \ No newline at end of file diff --git a/jQueryHelpers.md b/jQueryHelpers.md new file mode 100644 index 0000000..2df052a --- /dev/null +++ b/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/jQueryPortingState.md b/jQueryPortingState.md new file mode 100644 index 0000000..8162797 --- /dev/null +++ b/jQueryPortingState.md @@ -0,0 +1,29 @@ +phpQuery is almost a full port of the [jQuery JavaScript Library](http://jquery.com/). + +## Ported Sections ## + 1. [Selectors](http://code.google.com/p/phpquery/wiki/Selectors) + 1. [Attributes](http://code.google.com/p/phpquery/wiki/Attributes) + 1. [Traversing](http://code.google.com/p/phpquery/wiki/Traversing) + 1. [Manipulation](http://code.google.com/p/phpquery/wiki/Manipulation) + 1. [Ajax](http://code.google.com/p/phpquery/wiki/Ajax) + 1. [Events](http://code.google.com/p/phpquery/wiki/Events) + 1. [Utilities](http://code.google.com/p/phpquery/wiki/Utilities) + 1. [Plugin ports](http://code.google.com/p/phpquery/wiki/PluginsClientSidePorts) + +## Additional methods ## +phpQuery features many additional methods comparing to jQuery: + * htmlOuter() + * xml() + * xmlOuter() + * markup() + * markupOuter() + * getString() + * reverse() + * contentsUnwrap() + * switchWith() + * all from [PHPSupport](http://code.google.com/p/phpquery/wiki/PHPSupport) + * all from [Basic](http://code.google.com/p/phpquery/wiki/Basic) + * all from [MultiDocumentSupport](http://code.google.com/p/phpquery/wiki/MultiDocumentSupport) + +## 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/jQueryServer.md b/jQueryServer.md new file mode 100644 index 0000000..7a221a0 --- /dev/null +++ b/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](http://code.google.com/p/phpquery/wiki/Ajax) request to somewhere ([crossdomain allowed](http://code.google.com/p/phpquery/wiki/CrossDomainAjax)) + 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](http://code.google.com/p/phpquery/wiki/Ajax) hosts and referers. \ No newline at end of file diff --git a/jQueryServerSidePorts.md b/jQueryServerSidePorts.md new file mode 100644 index 0000000..5a6eeb5 --- /dev/null +++ b/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 diff --git a/test.md b/test.md new file mode 100644 index 0000000..34c92c2 --- /dev/null +++ b/test.md @@ -0,0 +1 @@ +lorem ipsum \ No newline at end of file