|
Plugins
Creating Plugins
See the PluginAPI page for API details IntroductionBecause 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 OverviewPlugins:
Remember: ATOM and RSS feeds differ in what data is available and how that data is formatted. When writing a plugin consider both. Simple PluginBelow 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 PluginThe 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;
}
?>
|