1 <?php
defined('IN_CMS') or die('No direct access allowed.');
5 private static $document;
7 public static function headers() {
9 Response
::header('Content-Type', 'application/xml');
12 private static function element($name, $value = null, $attributes = array()) {
13 $element = static::$document->createElement($name);
15 if(is_null($value) === false) {
16 $text = static::$document->createTextNode($value);
17 $element->appendChild($text);
20 foreach($attributes as $key => $val) {
21 $element->setAttribute($key, $val);
27 public static function generate() {
28 // create a dom xml object
29 static::$document = new DOMDocument('1.0', 'UTF-8');
31 // create our rss feed
32 $rss = static::element('rss', null, array('version' => '2.0'));
33 static::$document->appendChild($rss);
36 $channel = static::element('channel');
37 $rss->appendChild($channel);
40 $title = static::element('title', Config
::get('metadata.sitename'));
41 $channel->appendChild($title);
44 $link = static::element('link', 'http://' . $_SERVER['HTTP_HOST']);
45 $channel->appendChild($link);
48 $description = static::element('description', Config
::get('metadata.description'));
49 $channel->appendChild($description);
53 $params = array('status' => 'published', 'sortby' => 'id', 'sortmode' => 'desc');
55 foreach(Posts
::list_all($params) as $post) {
56 $item = static::element('item');
57 $channel->appendChild($item);
60 $title = static::element('title', $post->title
);
61 $item->appendChild($title);
64 $url = 'http://' . $_SERVER['HTTP_HOST'] . Url
::make(IoC
::resolve('posts_page')->slug
. '/' . $post->slug
);
65 $link = static::element('link', $url);
66 $item->appendChild($link);
69 $description = static::element('description', $post->description
);
70 $item->appendChild($description);
73 $date = static::element('pubDate', date(DATE_RSS
, $post->created
));
74 $item->appendChild($date);
78 Response
::content(static::$document->saveXML());