Archive for October, 2009
Help Blog Editors Reliably Discover Your API
It seems that tons of people have the same complaint: the Wordpress application for iPhone does not discover their blog and, therefore, is of no use to them.
The same goes for many desktop-based applications.
I, too, spent quite a lot of time trying to figure that one out but now that I have succeeded, here is how I would recommend working on this issue if your blog is affected:
- Go to your blog home page and select “View source”
- Look for <link ref=”EditURI”… you will see that this line contains a URL ending with xmlrpc.php?rsd. Point your browser to that URL. A rather empty page should be displayed. Check its source; if it is XML, it’s all good.
- If the previous step fails, go to the same URL but without ?rsd. If this fails too, you need to check that you have a file called xmlrpc.php and that: a. No rewrite rule messes up your URL; b. No plugin renders it invisible — e.g. “private”
- If both steps work well, it is VERY likely that the blog editor you are using — or trying to use, more accurately — is choking on malformed XHTML code. It is what seems to mystify most of us.
To convince your blog editor to “discover” your blog, we are going to give it a nicely formed XHTML page:
First, make a copy of index.php: cp index.php index.o.php
Now, create a new index.php page with this code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="generator" content="WordPress abc" /> <!-- leave this for stats --> <link rel="pingback" href="http://nexus.zteo.com/xmlrpc.php" /> <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://nexus.zteo.com/xmlrpc.php?rsd" /> <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://nexus.zteo.com/wp-includes/wlwmanifest.xml" /> <link rel='index' href='http://nexus.zteo.com' /> <head> <body> </body> </html> |
Of course, you need to replace all instances of nexus.zteo.com with your own blog’s information; for instance myblog.mydomain.com
Discover your blog using your favourite blog editor.
Restore your index.php: cp index.o.php index.php
Done!
If you enjoyed this post, make sure you subscribe to my RSS feed!
ClicDev: display last 24 hours visitors
A quick note about Clic!Dev: it is now possible, in the admin control panel, to select Setup Hacks > enable 24 hour users to add an extra information dialog to the footer of your hosted board’s main page. This will end up looking like so (but obviously adapted to whatever skins you are using):

If you enjoyed this post, make sure you subscribe to my RSS feed!
S2ajax v1.0 connects simply PHP and JavaScript
Here comes S2ajax v1.0!
And it was long overdue. Six months already since I posted S2ajax says “hi()” I can hardly believe it.
What I think of as v1.0’s main feature is that it is now possible to simply export classes in PHP and these classes can be instantiated in JavaScript. Whenever these instances are modified through asynchronous method calls, these modifications are transparently persisted server-side.
The concept
Is it a PHP class? Is it a JavaScript class? Why, it’s both! The class is defined in PHP on the server. Instances of the class are created on demand using JavaScript on the client. Whatever modifications are made to an instance are serialized on the server.
You can create a complex application using as many classes and instances as you need.

Under the hood
The PHP class is exported; the proxy JavaScript code is generated.
Whenever the client needs to access one of the class’ properties/methods, the proxy transparently talks to the class; the class lives server-side.

The Client’s point of view
An arbitrary number of instances of the class can be created in JavaScript.
The only hint that you are using a client-server architecture is the fact that when invoking a method, its return value is obtained through a callback. This mechanism allows your client interface to remain responsive while the server is preparing a response.

The server’s point of view
S2ajax automatically persists your instances’ state and data between consecutive asynchronous calls. You still get the benefits of the “shared nothing” approach of PHP but complex objects can be manipulated through an unlimited number of clients requests.

A code sample
Server-side
Let’s create a class that will increment an instance variable every time a method is invoked. Let’s keep it as simple as possible:
class CounterTester { private $counter; function __construct() { $this->counter = 0; } public function increment_counter() { $this->counter++; return $this->counter; } } |
Clearly, every time increment_counter() is invoked, $counter will be incremented and its new value returned.
Client-Side
First, an instance of our class is created. Then, when a user click on the button labeled ‘Increment counter’, the instance’s increment_counter() method will be invoked and the new $counter value returned to our callback and displayed.
<script> function display_result(val) { alert(val); // Display new counter value } var counter = new CounterTester(); </script> <button onclick="counter.increment_counter(display_result);">Increment counter</button> |
Note that we could create as many instances of our class as we wish and provided we display the matching buttons, we could independently increment multiple counters.
Get it now!
Click our valiant friend “Octocat”, artistically represented below, to go to S2ajax’s Github page. If you just wish to use the library, look for the [Download] button:
If you enjoyed this post, make sure you subscribe to my RSS feed!
PHP PDO class and XAMPP/”exotic” MySQL configurations
Last night I was trying to setup a @mail server but the installer kept choking when attempting to connect to my local database.
I am posting here my quick workaround in case you too, dear reader, get a dreaded “PDO” error message complaining about your attempt to “connect to unix://”
Here is I how I solved the issue for @mail: I opened library/Zend/Db/Adapter/Pdo/Abstract.php, found the line that creates the PDO object (”new PDO(…“) and, in this example, the first argument passed to the constructor was $dsn.
The problem is that PDO sees that this variables references “localhost” and decides that, since the database is local, it is going to use mysql.sock (hence the unix:// scheme)
This works as long as the file is found in its default location. If it is elsewhere, you are out of luck. This happens, for instance, if you use XAMPP.
Here is my quick fix, inserted right before the creation of the PDO object:
$dsn = str_replace(’host=localhost’, ‘unix_socket=/opt/lampp/var/mysql/mysql.sock’, $dsn);
All done.
Note: I have not investigated enough to know whether this is something missing in the Zend Framework or in @mail itself.
If you enjoyed this post, make sure you subscribe to my RSS feed!







