Jump to:

23481 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » RSS Feeds

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

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

Page: 1 2
Go to End
Author Topic: 2628 Views
  • Mackodlak
    Avatar
    Community Member
    95 Posts

    RSS Feeds Link to this post

    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

  • ayyurek
    Avatar
    Community Member
    41 Posts

    Re: RSS Feeds Link to this post

    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 %>

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: RSS Feeds Link to this post

    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?

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: RSS Feeds Link to this post

    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.

  • ayyurek
    Avatar
    Community Member
    41 Posts

    Re: RSS Feeds Link to this post

    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.

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: RSS Feeds Link to this post

    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 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?

  • ayyurek
    Avatar
    Community Member
    41 Posts

    Re: RSS Feeds Link to this post

    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; }

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: RSS Feeds Link to this post

    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

    2628 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.