Previous Thread
Next Thread
Print Thread
Rate Thread
Custom island that shows an rss feed
#316765 02/28/2008 3:29 PM
Joined: Feb 2007
Posts: 329
Yarp™
OP Offline
Yarp™
Joined: Feb 2007
Posts: 329
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).

Sponsored Links
Re: Custom island that shows an rss feed
blaaskaak #316766 02/28/2008 3:57 PM
Joined: Jan 2007
Posts: 70
Power User
Offline
Power User
Joined: Jan 2007
Posts: 70
Works great, just wish it would open the links in a new window.

smile

Re: Custom island that shows an rss feed
Stephen G #316767 02/28/2008 5:05 PM
Joined: Feb 2007
Posts: 329
Yarp™
OP Offline
Yarp™
Joined: Feb 2007
Posts: 329
Just add a target to the link. No rocket science needed to add that smile

Re: Custom island that shows an rss feed
blaaskaak #316771 02/28/2008 9:23 PM
Joined: Jan 2007
Posts: 70
Power User
Offline
Power User
Joined: Jan 2007
Posts: 70
laugh

Re: Custom island that shows an rss feed
Stephen G #316774 02/29/2008 3:48 AM
Joined: Feb 2007
Posts: 329
Yarp™
OP Offline
Yarp™
Joined: Feb 2007
Posts: 329
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.

Sponsored Links
Re: Custom island that shows an rss feed
blaaskaak #316777 02/29/2008 7:48 PM
Joined: Jan 2007
Posts: 70
Power User
Offline
Power User
Joined: Jan 2007
Posts: 70
Perfect.

smile

Re: Custom island that shows an rss feed
Stephen G #316837 04/05/2008 8:07 PM
Joined: Jan 2007
Posts: 70
Power User
Offline
Power User
Joined: Jan 2007
Posts: 70
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

Re: Custom island that shows an rss feed
Stephen G #316838 04/05/2008 10:27 PM
Joined: Feb 2007
Posts: 329
Yarp™
OP Offline
Yarp™
Joined: Feb 2007
Posts: 329
Hmm, I'll give that a try. Have you tried both url's seperate?

Re: Custom island that shows an rss feed
blaaskaak #316839 04/05/2008 11:20 PM
Joined: Jan 2007
Posts: 70
Power User
Offline
Power User
Joined: Jan 2007
Posts: 70
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

Re: Custom island that shows an rss feed
Stephen G #316852 04/08/2008 4:49 PM
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
Offline
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
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)?


- Allen wavey
- What Drives You?
Sponsored Links
Re: Custom island that shows an rss feed
AllenAyres #316857 04/09/2008 3:19 PM
Joined: Feb 2007
Posts: 329
Yarp™
OP Offline
Yarp™
Joined: Feb 2007
Posts: 329
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.

Re: Custom island that shows an rss feed
blaaskaak #316886 04/25/2008 6:36 AM
Joined: Sep 1999
Posts: 76
Power User
Offline
Power User
Joined: Sep 1999
Posts: 76
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?)

Re: Custom island that shows an rss feed
Myke #316887 04/25/2008 6:55 AM
Joined: Feb 2007
Posts: 329
Yarp™
OP Offline
Yarp™
Joined: Feb 2007
Posts: 329
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.

Re: Custom island that shows an rss feed
blaaskaak #316888 04/25/2008 7:36 AM
Joined: Jan 2000
Posts: 5,796
Likes: 8
UBB.Dev / UBB.Wiki Owner
Time Lord
Offline
UBB.Dev / UBB.Wiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,796
Likes: 8
Initially I believe it was used to parse an RSS feed from ubbcentral; but went wonky on some sites...


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, UBB.Sitemaps
Re: Custom island that shows an rss feed
Gizmo #316889 04/25/2008 10:23 AM
Joined: Feb 2007
Posts: 329
Yarp™
OP Offline
Yarp™
Joined: Feb 2007
Posts: 329
Ah, the latest new thingy in control panel, yep, that would be it laugh

Re: Custom island that shows an rss feed
blaaskaak #316894 04/29/2008 3:17 PM
Joined: Apr 2008
Posts: 7
Lurker
Offline
Lurker
Joined: Apr 2008
Posts: 7
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 */


Re: Custom island that shows an rss feed
Jaymo #316895 04/30/2008 12:53 AM
Joined: Feb 2002
Posts: 2,286
Veteran
Offline
Veteran
Joined: Feb 2002
Posts: 2,286
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


Fans Focus - Focusing on Fans of Sport

(Okay - mainly football (the British variety wink at the moment - but expanding all the time....)
Re: Custom island that shows an rss feed
Ian_W #316899 04/30/2008 2:18 PM
Joined: Apr 2008
Posts: 7
Lurker
Offline
Lurker
Joined: Apr 2008
Posts: 7
ARRG! Sounded like a great idea, Ian, but nope, same result....

Re: Custom island that shows an rss feed
Jaymo #316905 05/01/2008 1:25 PM
Joined: Feb 2007
Posts: 329
Yarp™
OP Offline
Yarp™
Joined: Feb 2007
Posts: 329
Did a couple of tries to get multiple feeds running, but no luck so far yet frown

Re: Custom island that shows an rss feed
blaaskaak #316907 05/01/2008 7:14 PM
Joined: Oct 2006
Posts: 18
Newbie
Offline
Newbie
Joined: Oct 2006
Posts: 18
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 */



trosfrihed.dk
Custom Ubb 7.5.2
Re: Custom island that shows an rss feed
arentzen #316908 05/02/2008 3:16 AM
Joined: Feb 2002
Posts: 2,286
Veteran
Offline
Veteran
Joined: Feb 2002
Posts: 2,286
Thanks - will this work on multiple feeds?

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


Fans Focus - Focusing on Fans of Sport

(Okay - mainly football (the British variety wink at the moment - but expanding all the time....)
Re: Custom island that shows an rss feed
Ian_W #316909 05/02/2008 3:55 AM
Joined: Jan 2000
Posts: 5,796
Likes: 8
UBB.Dev / UBB.Wiki Owner
Time Lord
Offline
UBB.Dev / UBB.Wiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,796
Likes: 8
I translated mine to "stories" and "count" like they are in any other feed reader wink...

hadn't tried it yet though


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, UBB.Sitemaps
Re: Custom island that shows an rss feed
Ian_W #316910 05/02/2008 11:00 AM
Joined: Oct 2006
Posts: 18
Newbie
Offline
Newbie
Joined: Oct 2006
Posts: 18
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


trosfrihed.dk
Custom Ubb 7.5.2
Re: Custom island that shows an rss feed
arentzen #316911 05/02/2008 6:03 PM
Joined: Apr 2008
Posts: 7
Lurker
Offline
Lurker
Joined: Apr 2008
Posts: 7
FANTASTIC, thanks for the info, Peter.


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
badfrog
badfrog
somewhere on the coast of Maine
Posts: 94
Joined: March 2007
Forum Statistics
Forums63
Topics37,533
Posts293,731
Members13,834
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online 202
Topics Created 0
Posts Made 0
Users Online 0
Birthdays 7
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,796
Greg Hard 4,625
Top Posters(30 Days)
isaac 7
driv 3
Top Likes Received
isaac 34
Gizmo 8
Brett 7
Morgan 2
Top Likes Received (30 Days)
isaac 1
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2020 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 7.7.5
(Snapshot build 20200315.dev)
Responsive Width:

PHP: 5.4.45 Page Time: 0.067s Queries: 63 (0.022s) Memory: 3.4638 MB (Peak: 3.7757 MB) Data Comp: Zlib Server Time: 2020-04-08 05:44:00 UTC
Valid HTML 5 and Valid CSS