Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Feedsplitter

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Nov 17, 2004 2:11 am    Post subject: Feedsplitter Reply with quote

Here's a little plugin that interfaces with the Feedsplitter service to enable javascript driven access to RSS feeds from your template. It takes the following parameters, all optional except for "feed":

feed - url to the rss feed you wish to display
maxitems - number of items to display
target - name of target window (use "_blank" for new windows)
stylesheet - set to true to use Feedsplitter's stylesheet
recache - set to true to recache the feed at Feedster
noscript - message to display in place of feed if javascript is not available

eg:
Code:
{feedsplitter feed="http://www.phpinsider.com/smarty-forum/rdf.php" target="_blank" stylesheet=true}


Enjoy!

function.feedsplitter.php
[php:1:44e0109475]<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/


/**
* Smarty {feedsplitter} function plugin
*
* Type: function<br>
* Name: feedsplitter<br>
* Purpose: interface to feedsplitter service
* Author: boots
* @link http://chxo.com/feedsplitter/
* @param array
* @param Smarty
* @return string
*/

function smarty_function_feedsplitter_verify($plugin='', $param_model, $params, &$smarty) {

foreach(array('requires', 'allowed', 'deprecated') as $category) {
if (!array_key_exists($category, $param_model)) {
$param_model[$category] = array();
}
}
$_missing = array_diff(array_keys($param_model['requires']), array_keys($params));
if (!empty($_missing)) {
$smarty->trigger_error("[$plugin] missing required parameter(s) ".join(', ', $_missing), E_USER_ERROR);
return false;
}

$_params = array();

foreach ($param_model['requires'] as $field=>$type) {
if (array_key_exists($field, $params) && !empty($params[$field])) {
$_params[$field] = $params[$field];
}
}
foreach ($param_model['allowed'] as $field=>$type) {
if (array_key_exists($field, $params) && isset($params[$field])) {
$_params[$field] = $params[$field];
}
}
foreach ($param_model['deprecated'] as $field=>$type) {
if (array_key_exists($field, $params)) {
$smarty->trigger_error("[$plugin] deprecated parameter '$field'", E_USER_INFO);
$_params[$field] = $params[$field];
}
}
return $_params;
}

function smarty_function_feedsplitter($params, &$smarty)
{
$_params = smarty_function_feedsplitter_verify(
'feedsplitter'
, array(
'requires' => array(
'feed' => 'string'
)
, 'allowed' => array(
'maxitems' => 'integer'
, 'target' => 'string'
, 'stylesheet' => 'boolean'
, 'recache' => 'boolean'
, 'noscript' => 'string'
)
, 'deprecated' => array(
)
)
, $params
, $smarty
);

if (!array_key_exists('noscript', $_params))
$_params['noscript'] = 'Javascript newsfeed here.';

$_params_out = 'http://chxo.com/feedsplitter/feedsplitter.php?format=jstable&';
foreach ($_params as $field=>$value) {
if ($field == 'feed')
$value = urlencode($value);
if ($field != 'noscript')
$_params_out .= $field.'='.$value.'&';
}

return '<script type="text/javascript" src="'.$_params_out.'">'
. '});</script><noscript>'.$_params['noscript'].'</noscript>';
}

/* vim: set expandtab: */
?>[/php:1:44e0109475]

ps. Just to fend off any questions, I realize that the smarty_function_feedsplitter_verify() function can be folded directly into the plugin function. It is actually stripped out (and down) from a class I am working on that is meant to be a helper for plugin writers by abstracting repeated patterns like checking plugin inputs and instead only requiring a "simple" definition of the requirements for the plugin. If it gets to the point where I am happy with it, I will post the results of that experiment. In the meantime, just include both of the above functions in the plugin file (function.feedsplitter.php) and you can ignore the fact that it contains two functions.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP