Section 9.3. Rolling Your Own: LinkPimp PubSub


9.3. Rolling Your Own: LinkPimp PubSub

Having said all that, and given that there are currently no implementations of mod_changedpage to receive pages from, let's concentrate on working with cloud. What's more, every cloud implementation in the wild uses XML-RPC, so, for simplicity, this is all we will support here. Extending the script to support SOAP and HTTP-POST would not be hard, if necessary, but it probably won't be necessary.

The following Publish and Subscribe (PubSub) system is for web sites displaying various feeds, rendered into XHTML and inserted onto the page using a server-side include. It is currently working live on the test site: http://www.benhammersley.com/linkpimp.

This system also incorporates two other things we have already discussed. First, it renders the feed into XHTMLyou can leave the onscreen formatting to a stylesheetbut the subroutine that does this is quite obvious in the code and can be turned to do something else: send IM notifications, for example.

Second, it uses Syndic8's API and subscription list service to tell it which feeds to examine. This allows you not only to play with the Syndic8 system, but also to add or remove feeds from the site without touching its code. I can merely log on to Syndic8 and subscribe to a feed there, and it should be incorporated into the site within the hour. It is rough and ready, but you will undoubtedly get ideas of your own from it.

The system comes in two parts:


LinkpimpClient.pl

This script retrieves a subscription list from Syndic8, using that site's XML-RPC interface, checks to see if any of the feeds contain a cloud element, and subscribes, if necessary. It then renders the feeds into XHTML, if necessary, and saves them to disk. It then creates a new file called feeds.shtml, which contains the server-side include instructions to include the feeds. This script is run hourly. Example 9-4, later in this chapter, contains the complete listing.


LinkpimpListener.pl

This script listens for PubSub notifications and refreshes the rendered feed when necessary. This script is run as a daemon. Example 9-5, later in this chapter, contains the complete listing.

Running the system creates three files internal to its working:


logfile.txt

The system creates a verbose log to explain what is happening. You can disable this, if you wish.


pubsub.txt

This file holds the URL and last-subscription-time of all the feeds to which you have PubSub subscriptions. It must not be deleted. LinkpimpStrimmer.pl keeps it healthy by stripping it of URLs older than 24 hours.


Feeds.shtml

This file contains the server-side include instructions for displaying the feeds on your page. In turn, it should be called in with its own SSI directive from your customer-facing page, using the command:

<!--#include file="feeds.shtml" -->



    Developing Feeds with RSS and Atom
    Developing Feeds with Rss and Atom
    ISBN: 0596008813
    EAN: 2147483647
    Year: 2003
    Pages: 118

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net