UBB.Dev
Posted By: blaaskaak Custom island that shows an rss feed - 02/28/2008 10:29 PM
A quick and dirty one, it shows the content of an rss feed. I had one feed it didn't work with, and a few others it did work with. It just shows the headers+the link to the article.

Code
/* PHP CODE HERE */
$display="";
$count=0;
$xml = getFeed('http://www.fotogalerijen.be/parkcast/parkcast.xml');
foreach( $xml as $feed ) {
if ($count>=10) {
break;
}
if( ! $feed['title'] ) {
break;
}
$display.="<a href=\"".$feed['link']."\">".$feed['title']."</a><br />";
$count++;
}

/* BODY HERE */
$body = <<<EOF
$display
EOF;

Just copy/paste above code in a custom field, set the caching time on some value, edit the hardcoded feed url, and edit the max number of entries (10 now).
Posted By: Stephen G Re: Custom island that shows an rss feed - 02/28/2008 10:57 PM
Works great, just wish it would open the links in a new window.

smile
Posted By: blaaskaak Re: Custom island that shows an rss feed - 02/29/2008 12:05 AM
Just add a target to the link. No rocket science needed to add that smile
Posted By: Stephen G Re: Custom island that shows an rss feed - 02/29/2008 4:23 AM
laugh
Posted By: blaaskaak Re: Custom island that shows an rss feed - 02/29/2008 10:48 AM
okay, I wanted a date/time added to it, so I took it a little further. Configuration is a bit more easy now since it's all listed on top. It also shows the content now of the feed if you fly over it.

Styles used are those from the buildin posts island.

enjoy!

Code
// configuration
$feedurl = 'http://www.fotogalerijen.be/parkcast/parkcast.xml';
$maxentries = 10;
$showdate = 1;

// start code

$body = "";
$count = 0;
$dateinfo = "";
$xml = getFeed($feedurl);
foreach( $xml as $feed ) {
if ($count >= $maxentries) {
break;
}
if( !$feed['title'] ) {
break;
}
$link=$feed['link'];
$time=$feed['time'];
$title=$feed['title'];
$description=$feed['description'];
$pubdate=strtotime($feed['pubdate']);
$pubtime = $html->convert_time($pubdate);

if ($showdate)
$dateinfo = <<<EOF
<span class="small">
$pubtime
</span>
EOF;

$body.= <<<EOF
<tr>
<td class="{$style_side}alt-1" align="left">
<div title="$description">
<a href="$link" target="_blank">$title</a></div>
$dateinfo
</td>
</tr>
EOF;
$count++;
}

I just thought of some security issues if the feed would contain html, so just add feeds you trust ok wink I'm away for the weekend, so don't have time to get into it now.
Posted By: Stephen G Re: Custom island that shows an rss feed - 03/01/2008 2:48 AM
Perfect.

smile
Posted By: Stephen G Re: Custom island that shows an rss feed - 04/06/2008 3:07 AM
A weird thing happens when I have two separate islands with the same code in on the same page but with two different urls to feeds.

It only shows one of the feeds in bot islands.

Hmmm
Posted By: blaaskaak Re: Custom island that shows an rss feed - 04/06/2008 5:27 AM
Hmm, I'll give that a try. Have you tried both url's seperate?
Posted By: Stephen G Re: Custom island that shows an rss feed - 04/06/2008 6:20 AM
Well, when I have only one instance of the code in an island and one URL it shows the feed

But if I have the same code in two islands, even with separate urls only one feed shows up in both islands even though the urls to the feeds are different

I'm using a different code at the minute but I really like the above code, just can't understand why it only seems to work in one instance
Posted By: AllenAyres Re: Custom island that shows an rss feed - 04/08/2008 11:49 PM
Very nice Yarp! How difficult would it be to include a pit of the post body, similar to how active topics does it, but only for the specified forum(s)?
Posted By: blaaskaak Re: Custom island that shows an rss feed - 04/09/2008 10:19 PM
Wouldn't be difficult at all. If it's a field in the feed, you can display it.

I do know I played with a version during dev that had the message content as tooltip text.
Posted By: Myke Re: Custom island that shows an rss feed - 04/25/2008 1:36 PM
Thanks for this! I was previously using an external rss reader (lastRSS) in order to populate a custom island, but this is much cleaner! I'm using it to show a list of recent changes from our wiki (http://virtuafighter.com/ bottom left island).

I feel a bit silly asking this, because my searching hasn't been successful, but where can I find some documentation on getFeed() ? Specifically, I'd like to know what rss protocols it supports, and what fields it returns (or does that just depend on the rss feed?)
Posted By: blaaskaak Re: Custom island that shows an rss feed - 04/25/2008 1:55 PM
getfeed is a function that is in the ubb sourcecode, but as far as I know, it is not used anywhere by ubb itself. I found about it by trying out Ian Spence' rss topic creator.

it's in /libs/ubbthreads.inc.php if you want to have a look at it.
Posted By: Gizmo Re: Custom island that shows an rss feed - 04/25/2008 2:36 PM
Initially I believe it was used to parse an RSS feed from ubbcentral; but went wonky on some sites...
Posted By: blaaskaak Re: Custom island that shows an rss feed - 04/25/2008 5:23 PM
Ah, the latest new thingy in control panel, yep, that would be it laugh
Posted By: Jaymo Re: Custom island that shows an rss feed - 04/29/2008 10:17 PM
Hey, blaaskaak, this is a cool tool - I'm using it successfully but am experiencing the same issue mentioned above, where, despite using three unique URL's, each Island displays information identical to the content of the first Custom Island.

Any insight would be much appreciated!

Let me show you the three pieces of code I'm using:

This one displays the headlines from Variety.com:

Code
/* PHP CODE HERE, IF NECESSARY */

$display="";
$count=0;
$xml = getFeed('http://feeds.feedburner.com/variety/news/film');
foreach( $xml as $feed ) {
if ($count>=5) {
break;
}
if( ! $feed['title'] ) {
break;
}
$display.="<a href=\"".$feed['link']."\">".$feed['title']."</a><br /><br />";
$count++;
}

/* DO NOT CHANGE THE LINE BELOW */
$body = <<<EOF
$display
EOF;
/* DO NOT CHANGE THE LINE ABOVE */

The following two, though possessing unique URL's, display the same info as the code listed above.

Code
/* PHP CODE HERE, IF NECESSARY */

$display="";
$count=0;
$xml = getFeed('http://feeds.feedburner.com/variety/reviews/film');
foreach( $xml as $feed ) {
if ($count>=5) {
break;
}
if( ! $feed['title'] ) {
break;
}
$display.="<a href=\"".$feed['link']."\">".$feed['title']."</a><br />";
$count++;
}

/* DO NOT CHANGE THE LINE BELOW */
$body = <<<EOF
$display
EOF;
/* DO NOT CHANGE THE LINE ABOVE */

/* PHP CODE HERE, IF NECESSARY */

$display="";
$count=0;
$xml = getFeed('http://link.brightcove.com/services/link/bcpid714034225?action=rss');
foreach( $xml as $feed ) {
if ($count>=5) {
break;
}
if( ! $feed['title'] ) {
break;
}
$display.="<a href=\"".$feed['link']."\">".$feed['title']."</a><br />";
$count++;
}

/* DO NOT CHANGE THE LINE BELOW */
$body = <<<EOF
$display
EOF;
/* DO NOT CHANGE THE LINE ABOVE */

Posted By: Ian_W Re: Custom island that shows an rss feed - 04/30/2008 7:53 AM
Just a thought - try adding 1, 2 & 3 after each $feed, $xml, $display etc. for each feed, so that the code is unique.

I have not tried this, but it is worth a try smile
Posted By: Jaymo Re: Custom island that shows an rss feed - 04/30/2008 9:18 PM
ARRG! Sounded like a great idea, Ian, but nope, same result....
Posted By: blaaskaak Re: Custom island that shows an rss feed - 05/01/2008 8:25 PM
Did a couple of tries to get multiple feeds running, but no luck so far yet frown
Posted By: arentzen Re: Custom island that shows an rss feed - 05/02/2008 2:14 AM
Hello out there. Its been a long time ago since last visit.... But i'd installed version 7.2.2 and has also struggeled with feeds in custom boxes. If you running PHP5, there is a function called simplexml_load_file which works excellent.

The code generates a link, a date, and a short description with 45 chars. Replace the url to the wanted feed in $feed


PHP Code
/* PHP CODE HERE, IF NECESSARY */
$feed = simplexml_load_file("http://www.dr.dk/nyheder/service/feeds/allenyheder");
$taeller = 0;
$antal = 5; /*number of news*/
foreach($feed->channel->item as $item){
while(
$taeller<$antal){

/* formatting description with 45 chars*/
if (strlen($item->description) > 45) {
$item->description = substr($item->description , 0, 45);
}
/* formatting date*/
$pubdate=strtotime($item->pubDate);
$pubtime = $html->convert_time($pubdate);
$dateinfo = <<<EOF
<span class="small">
$pubtime
</span>
EOF;

$link = utf8_decode("<a href='{$item->link}' target='_blank'>{$item->title}</a><br />");
$description= utf8_decode("{$item->description}...<br />");


$body.= <<<EOF

<tr>
<td class="
{$style_side}alt-1" align="left">$link
$dateinfo <br />
$description
</td>
</tr>
EOF;

break;

}
$taeller ++;

}

/* DO NOT CHANGE THE LINE BELOW */

Posted By: Ian_W Re: Custom island that shows an rss feed - 05/02/2008 10:16 AM
Thanks - will this work on multiple feeds?

BTW - what does taeller & antal mean in English - just curious wink
Posted By: Gizmo Re: Custom island that shows an rss feed - 05/02/2008 10:55 AM
I translated mine to "stories" and "count" like they are in any other feed reader wink...

hadn't tried it yet though
Posted By: arentzen Re: Custom island that shows an rss feed - 05/02/2008 6:00 PM
Originally Posted by Ian_W
Thanks - will this work on multiple feeds?

BTW - what does taeller & antal mean in English - just curious wink

Yes. It works on multiple feeds. I had test the script with different urls in different custom boxes


taeller = counter
antal = numbers
$antal is a variable to decide how many items in the feed you want. Feel free to rename any variables. Remember the script requires PHP 5
Posted By: Jaymo Re: Custom island that shows an rss feed - 05/03/2008 1:03 AM
FANTASTIC, thanks for the info, Peter.
© UBB.Developers