PubSubHubbub With Posterous
If you want to let your own script subscribe to Posterous directly via PubSubHubbub (powered by Superfeedr, but in this instance not going through their dashboard), here's an example.
$ curl -vd 'hub.mode=subscribe&hub.verify=sync&hub.callback=
http%3A%2F%2Fcharlvn.za.net%2Fsomescript.php&hub.topic=
http%3A%2F%2Fp.charlvn.com%2Frss.xml' http://posterous.
superfeedr.com
In the above, http://charlvn.za.net/somescript.php would be my script (which has to be set up first) and http://p.charlvn.com/rss.xml is the Posterous feed I'm trying to subscribe to.
If you receive a HTTP/1.1 204 No Content response, you should be fine.
Now, somescript.php could be something like this:
<?php if (isset($_REQUEST['hub_challenge']))
{ echo $_REQUEST['hub_challenge']; }
else { $document = new DOMDocument();
$document->load('php://input');
$xpath = new DOMXPath($document);
$xpath->registerNamespace('atom',
'http://www.w3.org/2005/Atom');
$status = $xpath->evaluate('string(//atom:entry/atom:title)');
if (trim($status)) { $uri =
'http://charlvn:[email protected]/statuses/update.xml?
status=' . urlencode($status);
$context = stream_context_create(array('http'=>array
('method'=>'POST'))); file_get_contents($uri, 0, $context);} }
You might notice here that even though the original feed is in RSS format, the code that gets pushed to you is in Atom.
Always blindly accepting the hub_challenge is maybe not a good idea. However, not much harm done as long as you keep the URL of the script secret.
This would just post the title to Twitter, nothing interesting, and actually Posterous can do this straight out of the box. But, being your own script, now is the time to get creative. :)