FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Rss.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class Rss extends Xml{
6 
7  public $limit = 15;
8 
9  public function render(){
10  if(!headers_sent()) header('Content-type: application/rss+xml; charset=utf-8');
11  $rss = new \SimpleXmlElement('<rss version="2.0" />');
12  $this->xmlEncode($channel = $rss->addChild('channel'),$this->channel);
13  foreach($this->items as $item) $this->xmlEncode($channel->addChild('item'),$item);
14  print($rss->asXML());
15  }
16 
17  protected function getChannel(){
18  return [
19  'title' => $this->title,
20  'link' => \Rsi\Http::host(true) . $this->_controller->route(),
21  'copyright' => \Rsi\Http::host(),
22  'pubDate' => date('r'),
23  'generator' => 'FRED™ RSS view'
24  ];
25  }
26 
27  protected function getItems(){
28  $html = $this->_fred->html;
29  $items = [];
30  foreach($this->_controller->widgets as $widget) if($widget instanceof \Rsi\Fred\Controller\Widget\Table){
31  $title = $date = null;
32  $captions = [];
33  foreach($widget->columns as $column => $config){
34  $captions[$column] = $widget->columnCaption($column);
35  if(!$title && !($config['format'] ?? null)) $title = $column;
36  if(!$date && (substr($config['format'] ?? null,0,4) == 'date')) $date = $column;
37  }
38  $widget->searchParams($search,$order);
39  foreach($widget->provider->search($search,$order,$widget->params,0,$this->limit) as $record){
40  $table = '';
41  foreach($captions as $column => $caption) $table .= $html->tr($html->_th($caption) . $html->_td($record[$column]));
42  $item = ['guid' => md5(implode('|',$record)),'description' => $html->table($table)];
43  if($title) $item['title'] = $record[$title];
44  if($date) $item['pubDate'] = date('r',strtotime($record[$date]));
45  $items[] = $item;
46  }
47  break;
48  }
49  return $items;
50  }
51 
52 }
Framework for Rapid and Easy Development.
Definition: Fred.php:18
xmlEncode($parent, $data)
Definition: Xml.php:7