Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

RSS Feeds


Go to End


10 Posts   5128 Views

Avatar
Mackodlak

Community Member, 95 Posts

6 May 2011 at 1:45am

Ok guys, I have an assignment that I have to finish by monday preferably. I need to have a RSS feed page that would display RSS feeds from like 8-10 sources and then I have to randomly pick like 3 of them and place them on home page or sth else.

I have been looking at some links here:

http://www.silverstripe.org/customising-the-cms/show/11548
http://www.silverstripe.org/general-questions/show/9594?start=0

to name a few, and also been trying to figure out some modules like SS_RSS_Feed_Manager and RSS connector.
I am trying to make some sense out of this, but could use some help.

Since I'm kinda new to SS and PHP I would bee grateful if you could assist me in a best way to do this.
I have precious little time to complete this so I can't try out all the options before me, so mby if you could point me in right direction, if not provide me with a solution

Avatar
ayyurek

Community Member, 41 Posts

14 May 2011 at 1:00am

Edited: 14/05/2011 1:00am

I don't know if it helps but I am getting news form an external RSS source with this code.

class RssListPage extends Page {
   static $db = array(
   
   );
   static $has_one = array(
   );
   
 
}
 
class RssListPage_Controller extends Page_Controller {


function CustomRSSFeed() {

   include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/simplepie.inc'));
   
   $feed = new SimplePie("http://www.yourdomain.com/rss.xml", TEMP_FOLDER);
   $feed->init();
   
   $output = new DataObjectSet();
   if($items = $feed->get_items(0, 10)){
      foreach($items as $item){
         $output->push(new ArrayData(array(
            "Title" => $item->get_title(),
			"Summary" => $item->get_description(),
			"Date" => $item->get_date('d m y | g:i'),
            "Link" => $item->get_link()
         )));
      }
   }
   return $output;
}
 
}

and in template

<% control CustomRSSFeed %>
$Title $Summary $Date
<% end_control %>

Avatar
Mackodlak

Community Member, 95 Posts

25 May 2011 at 11:37pm

Hey mate,

I am sorry for not answering you sooner. Haven't rly looked at this post in a while, but seems like it may be just what I'm looking for.

I guess I would have to dl silverpie and another thing, the source is somehow connected with $feed = new SimplePie("http://www.yourdomain.com/rss.xml", TEMP_FOLDER); line, I just didn't figure out what is TEMP_FOLDER?

Avatar
Mackodlak

Community Member, 95 Posts

26 May 2011 at 8:53pm

Just to clarify, should I make a folder named TEMP_FOLDER or what? cause I tried what you showed me and for some reason dev/build won't make this page type, it just keeps ignoring it each time I try.

Avatar
ayyurek

Community Member, 41 Posts

27 May 2011 at 2:27am

Hi,

Actually I didn't do anything specially about temp_folder when I used this code. It just worked.

But I think it points to tmp folder in the file system. Silverstripe uses this folder for cache and other purposes, unless you create a folder named silverstripe-cache. Maybe tmp folder is not writable because of security issues. You can try to create a folder in the root of your web site and name it silverstripe-cache. (in the same level with mysite, assets etc.) And make this folder writable.

I hope it helps.

Avatar
Mackodlak

Community Member, 95 Posts

27 May 2011 at 2:56am

Edited: 27/05/2011 2:58am

Yeah, it is working perfectly, I actually did a lot of work with this today and it has helped me a lot.
The problem wasn't with TEMP_FOLDER but I just copy-pasted ur code when trying it out and forgot to put <?php at the begining of .php file so that is the reason it didn't work.
Kinda noobish mistake from me, but then again I am a noob with silverstripe, php and html :D But I think I'm a fast learner.

Anyways it is working for me, but I have other issues with it. I am pulling feed from numerous sources and each has it's own RSS feed format. Let me explain: under 'description' (this->get_description) there is all sorts of things - long texts, short texts; links; icons; "SPONSORED BY..." parts etc. Example:
http://rss.packetstormsecurity.org/files/ - the way I want it to be displayed
http://isc.sans.edu/rssfeed_full.xml - to much text - mby only show first paragraph
http://www.darkreading.com/rss/all.xml - perfect - the way I want it to be displayed
http://feeds.wired.com/wired/politics/security?format=xml - I don't want icons and blue links/text
http://feeds.feedburner.com/itsecurity?format=xml - would like not to display On-Demand Webinar > Watch Now!>>SPONSORED BY: Juniper Networks part (and simmilar)

Is there a way to show just the dirst paragraph of actual description? the "On-Demand Webinar > Watch Now!>>SPONSORED BY: Juniper Networks" on IT security would be ok if it is left there if all other feeds from other sources display nicely - how do you think would be the best way to dispay them?

Avatar
ayyurek

Community Member, 41 Posts

27 May 2011 at 3:28am

What data you get, it depends on the publisher :)

But you can get first paragraph with $Summary.FirstParagraph

Have a look at

http://api.silverstripe.org/2.4/sapphire/model/Text.html

You can maybe find some way to get just text without links and images =)

You can also hide images and other stuff with css display:none. But it will not be a nice method. If there are so many images.

<div id="rss-container">
$Summary
</div>

and in css file
#rss-container img { display:none; }

Avatar
Mackodlak

Community Member, 95 Posts

7 July 2011 at 9:16pm

Well having a problem with RSS.
$Summary.FirstParagraph doesn't work
I need sth fixed length to be able to fit into layout
RSS returns $Title, $Link and $Summary
Help plz

Go to Top