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