Re: [SMARTY-DEV] RSS block

From: Date: Mon, 28 Oct 2002 09:02:50 +0000
Subject: Re: [SMARTY-DEV] RSS block
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-301@lists.php.net to get a copy of this message
I've implemented something similar. But it's not a smarty block. Instead I use a template to display the content. It works very well with the german Heise Newsticker (http://www.heise.de/newsticker/heise.rdf). Here's my function which returns the html content of the parsed template. It should be easy to make a block function of it. function NewsFeed ($url) { $template = new smartTemplate(); $news = Array(); $fcontents = join ('', file ($url)); $fcontents = str_replace("</item>", "", $fcontents); $items = explode("<item>",$fcontents); // Parse Channel Infos ereg("<channel>(.*)</channel>",$items[0],$matches); $channelBlock = $matches[1]; ereg("<title>(.*)</title>",$channelBlock,$matches); $title = trim($matches[1]); ereg("<link>(.*)</link>",$channelBlock,$matches); $link = trim($matches[1]); ereg("<description>(.*)</description>",$channelBlock,$matches); $description = trim($matches[1]); $channel = Array("title"=>$title,"link"=>$link,"description"=>$description); // Parse News unset($items[0]); foreach ($items as $item) { ereg("<title>(.*)</title>",$item,$matches); $title = trim($matches[1]); ereg("<link>(.*)</link>",$item,$matches); $link = trim($matches[1]); ereg("<description>(.*)</description>",$item,$matches); $description = trim($matches[1]); $news[] = Array("title"=>$title,"link"=>$link,"description"=>$description); } $template->assign("channel",$channel); $template->assign("news",$news); $content = $template->fetch("newsfeed.tpl"); return $content; } -------- {* TEMPLATE: newsfeed.tpl *} {if (strval($channel.title) != "")} {* <div style="background-color:{$_API->theme->rowcolor1}; padding:2px;"> <b><a href="{$channel.link}" target="_blank">&gt;&gt; {$channel.title}</a></b> </div> *} <table cellspacing="0" cellpadding="0"> {section name="record" loop=$news} <tr> <td align="center" width="10" valign="top"> <b>&middot;</b> </td> <td valign="top"> <a href="{$news[record].link}" target="_blank">{$news[record].title}</a><br/> </td> </tr> {sectionelse} No current news {/section} </table> {else} NewsFeed Block not configured correctly. {/if} "Peter Bowyer" <peter@mapledesign.co.uk> schrieb im Newsbeitrag news:5.1.1.6.0.20021027084928.030f26e0@mail.fluidhosting.com... > At 14:59 26/10/02 -0300, garland_foster@salutia.com wrote: > >if you don't know and you think that such a plugin > >would be a good idea I will code it, just send me ideas and suggestions > >about what parameteres should we use and so. > > {rss url=http://www.foo.com/feed.rss > tpl="my_rss_tpl/site_foo.tpl" num=3} > Where: > - tpl allows you to specify a separate template per rss feed > - num limits the number of items from the rss feed shown. > > I've not used RSS much so others may be able to come up with more useful > parameters. > > Peter > > -- > Narrow Gauge Heaven - news, photos, railway directory and discussion forums! > http://www.narrow-gauge.co.uk > > Glenbranter - Scottish narrow gauge in 009 > http://glenbranter.narrow-gauge.co.uk >

« previous php.smarty.dev (#301) next »