My favorites | Sign in
Project Home Downloads Wiki Issues
READ-ONLY: This project has been archived. For more information see this post.
Search
for
Plugins  
Creating Plugins
Updated Dec 14, 2008 by damian.d...@gmail.com

See the PluginAPI page for API details

Introduction

Because no two feeds are alike HulloHallo processes all feeds based upon rules. These rules can easily be created by end users. Rules are written in PHP and can be simple (e.g. just returning the data passed to it) to complex. When we talk about rules, we are talking about plugins.

Quick Overview

Plugins:

  • are written in PHP
  • are functions
  • are named in accordance with the site they apply rules to (e.g. flickr.php, digg.php)
  • are not required. If a plugin for a particular site is not found, the default plugin will be used.
  • have two objects that must be passed to them. They are $feedItem & $feedInfo. See the PluginAPI for details.
  • always return the $feedItem object.
  • never return the $feedInfo object (unless the developer wants HulloHallo to say GoodebyeFarewell).
  • function declarations must always be capitalized. Flickr not flickr.
  • Only one function per plugin!

Remember: ATOM and RSS feeds differ in what data is available and how that data is formatted. When writing a plugin consider both.

Simple Plugin

Below is the default plugin:

<?php
     function DefaultRule($feedItem, $feedInfo)
     {
	return $feedItem;
     }
?>

As you can see, this plugin simply returns the data passed to it.

A Complex Plugin

The following example is the default Flickr plugin provided with HulloHallo. It makes extensive use of both the $feedItem & the feedInfo objects. Note that the plugin checks to see what type of feed was passed to it (RSS2.0 or ATOM) in order to apply appropriate proccesing rules on the item. This plugin is a good example of how ATOM and RSS feeds differ and what is available to each in the API.

<?php
	function Flickr($feedItem, $feedInfo)
	{
		if($feedInfo->xml_type == 'RSSv2')
		{
			//because we have access to the media namespace in the RSS2 file, lets format the description to be a linked photo
			$imageSize = '';//options are t,s,m,o or blank.  See http://www.flickr.com/services/api/misc.urls.html for size details
			if($imageSize == '')//getting the larger medium size file
			{
				//the imagesize was left blank - so show the larger medium size file.
                                $size = '';
			}
			else
			{
				$size = '_' . $imageSize;
			}
			$imageLinkData = explode('_', $feedItem->thumbnailUrl);
			$extensionData = explode('.', $imageLinkData[2]);
			$imageLink = $imageLinkData[0] . '_' . $imageLinkData[1] . $size . '.' . $extensionData[1];
			
			$feedItem->description = '<a href = "' . $feedItem->link . '" title = "' . $feedItem->title . '"><img src = "' . $imageLink . '" alt = "" /></a>';
		}
		if($feedInfo->xml_type == 'ATOM')
		{
			$descriptionParts = explode('<br />', $feedItem->description);
			$feedItem->description = $descriptionParts[1];//return only the image link
		}
		
		$feedItem->title = 'Photo Added: <a href = "' . $feedItem->link . '" title = "' . $feedItem->title . '">' . $feedItem->title . '</a>';
		
			
		return $feedItem;
	}
?>
Powered by Google Project Hosting