Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
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
Joined: Jan 2007
Posts: 70
Power User
Power User
Joined: Jan 2007
Posts: 70
Works great, just wish it would open the links in a new window.

smile

Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
Just add a target to the link. No rocket science needed to add that smile

Joined: Jan 2007
Posts: 70
Power User
Power User
Joined: Jan 2007
Posts: 70
laugh

Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
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
Joined: Jan 2007
Posts: 70
Power User
Power User
Joined: Jan 2007
Posts: 70
Perfect.

smile

Joined: Jan 2007
Posts: 70
Power User
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

Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
Hmm, I'll give that a try. Have you tried both url's seperate?

Joined: Jan 2007
Posts: 70
Power User
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

Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
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
Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
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.

Joined: Sep 1999
Posts: 76
Power User
Power User
Offline
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?)

Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
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.

Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
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, My UBB Scripts
Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
Ah, the latest new thingy in control panel, yep, that would be it laugh

Joined: Apr 2008
Posts: 7
Lurker
Lurker
Offline
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 */


Joined: Feb 2002
Posts: 2,286
Veteran
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....)
Joined: Apr 2008
Posts: 7
Lurker
Lurker
Offline
Joined: Apr 2008
Posts: 7
ARRG! Sounded like a great idea, Ian, but nope, same result....

Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
Did a couple of tries to get multiple feeds running, but no luck so far yet frown

Joined: Oct 2006
Posts: 18
Newbie
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
Joined: Feb 2002
Posts: 2,286
Veteran
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....)
Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
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, My UBB Scripts
Joined: Oct 2006
Posts: 18
Newbie
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
Joined: Apr 2008
Posts: 7
Lurker
Lurker
Offline
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
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)