Version: current

     1 <?php
     2
     3 class WebylonNews extends DashboardPlugin {
     4     static $position = "left";
     5     static $sort = 1;
     6     static $title = "Webylon News";
     7     static $icon = "dashboard/images/22/feed.png";
     8
     9     /**
    10      * @var $rss_url = sets the url of the RSS feed
    11      */
    12     static $rss_url = 'http://webylon.ru/stuff/rss.php?v=3.1';
    13
    14     /**
    15      * Uses SimplePie to pull in the news feed from $rss_url variable, process and cast it, then output it to a DataObjectSet
    16      *
    17      * @return DataObjectSet
    18      */
    19     function LatestSSNews() {
    20         $sp23 = Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/simplepie.php');
    21         $sp24 = Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/simplepie.inc');
    22
    23         if(file_exists($sp23))
    24             include_once $sp23;
    25         elseif(file_exists($sp24))
    26             include_once $sp24;
    27
    28         $output = new DataObjectSet();
    29
    30         $feed = new SimplePie(self::$rss_url, TEMP_FOLDER);
    31         $feed->init();
    32         if($items = $feed->get_items(0, 2)) {
    33             foreach($items as $item) {
    34
    35                 // Cast the Date
    36                 $date = new Date('Date');
    37                 $date->setValue($item->get_date());
    38
    39                 // Cast the Title
    40                 $title = new Text('Title');
    41                 $title->setValue($item->get_title());
    42
    43                 // Cast the description and strip
    44                 $desc = new HTMLText('Description');
    45 //              $desc->setValue(strip_tags($item->get_description()));
    46                 $desc->setValue($item->get_description());
    47
    48                 $output->push(new ArrayData(array(
    49                     'Title'         => $title,
    50                     'Date'          => $date,
    51                     'Link'          => $item->get_link(),
    52                     'Description'   => $desc
    53                 )));
    54             }
    55             return $output;
    56         }
    57     }
    58 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -