2007-09-06 22:33:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class RSSWidget extends Widget {
|
|
|
|
static $db = array(
|
2008-02-25 08:48:33 +00:00
|
|
|
"RSSTitle" => "Text",
|
2007-09-06 22:33:58 +00:00
|
|
|
"RssUrl" => "Text",
|
2008-02-25 08:48:33 +00:00
|
|
|
"NumberToShow" => "Int"
|
2007-09-06 22:33:58 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static $defaults = array(
|
2008-02-24 08:23:04 +00:00
|
|
|
"NumberToShow" => 10,
|
2008-02-25 08:48:33 +00:00
|
|
|
"RSSTitle" => 'RSS Feed'
|
2007-09-06 22:33:58 +00:00
|
|
|
);
|
|
|
|
static $cmsTitle = "RSS Feed";
|
|
|
|
static $description = "Shows the latest entries of a RSS feed.";
|
|
|
|
|
|
|
|
function getCMSFields() {
|
|
|
|
return new FieldSet(
|
2008-02-25 08:48:33 +00:00
|
|
|
new TextField("RSSTitle", _t('RSSWidget.CT', "Custom title for the feed")),
|
2007-12-18 01:41:51 +00:00
|
|
|
new TextField("RssUrl", _t('RSSWidget.URL', "URL of RSS Feed")),
|
|
|
|
new NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show"))
|
2007-09-06 22:33:58 +00:00
|
|
|
);
|
|
|
|
}
|
2008-02-25 08:48:33 +00:00
|
|
|
function Title() {
|
|
|
|
return ($this->RSSTitle) ? $this->RSSTitle : 'RSS Feed';
|
|
|
|
}
|
2007-09-06 22:33:58 +00:00
|
|
|
|
|
|
|
function FeedItems() {
|
|
|
|
$output = new DataObjectSet();
|
2008-02-24 08:19:24 +00:00
|
|
|
$this->feed = new SimplePie($this->RssUrl);
|
|
|
|
$this->feed->init();
|
2007-09-11 06:38:05 +00:00
|
|
|
if($items = $this->feed->get_items(0, $this->NumberToShow)) {
|
|
|
|
foreach($items as $item) {
|
|
|
|
$output->push(new ArrayData(array(
|
|
|
|
"Title" => $item->get_title(),
|
|
|
|
"Link" => $item->get_link()
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
return $output;
|
2007-09-06 22:33:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|