phpQuery can connect to Google Code’s wiki editing form, authorize itself, replace page contents and finally submit the form.
// declare main variable
$pq = null;
// create dummy document as start point
phpQuery::newDocument('
<div>')
// authorize your google account
->script('google_login')
// redirect authorized XHR component to googlecode's wiki form
->location('http://code.google.com/p/phpquery/w/edit/test')
// save result as $pq, althought we could continue the chain
// but it would break in case of error...
->toReference($pq);
if ($pq) {
// read about CallbackReference later in this post...
$pq->WebBrowser(new CallbackReference($pq))
->find('textarea:first')
->val('lorem ipsum')
->parents('form')
// first submit is Preview, so fire up second
->find(':submit:eq(1)')
// triggering submit event thought input[type=submit]:click
// is a way to choose which submit is send
->click();
if ($pq) {
// print without tags
print $pq->script('safe_print');
}
}
You can notice hot new feature – new CallbackReference($pq). Such callback sets first callback parameter to passed variable, by reference. Such pattern works with all methods accepting callbacks. Thanks to that, we can use if statements instead of function callbacks. In above example, CallbackReference object is called when click event is triggered.
Presented code snippet makes use of new Script plugin, particularly google_login.
Now it can be combined with automated XML documentation to wiki script, but this maybe for jQuery 1.3…