1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-02 19:27:52 +02:00

Blog Plugin as a part of Monstra CMS #188

This commit is contained in:
Awilum
2014-02-12 23:53:07 +02:00
parent 81ffb867be
commit 9ea4477bd8
2 changed files with 44 additions and 1 deletions

View File

@@ -20,6 +20,8 @@ Plugin::register( __FILE__,
'Awilum', 'Awilum',
'http://monstra.org/'); 'http://monstra.org/');
// Add action
Action::add('frontend_pre_render', 'Blog::_rss');
/** /**
* Blog Class * Blog Class
@@ -34,7 +36,6 @@ class Blog {
*/ */
public static $parent_page_name = 'blog'; public static $parent_page_name = 'blog';
/** /**
* Get tags * Get tags
* *
@@ -382,6 +383,15 @@ class Blog {
return Page::author(); return Page::author();
} }
/**
* _rss
*/
public static function _rss() {
if (Uri::segment(0) == 'rss') {
include PLUGINS . DS . 'blog' . DS . 'rss.php';
Request::shutdown();
}
}
} }

33
plugins/blog/rss.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
// Get all posts for blog parent page/post
$posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published"]', 5, 0, array('slug', 'title', 'author', 'date'), 'date', 'DESC');
// Date now
$now = date("D, d M Y H:i:s T");
ob_end_clean();
?>
<?php header('Content-type: text/xml; charset="utf-8"'); ?>
<?php echo'<?xml version="1.0" encoding="utf-8"?>'."\n"; ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>MonstraCMS::BLOG::RSS</title>
<link><?php echo Option::get('siteurl'); ?>/blog</link>
<description>The latest updates for <?php echo Option::get('sitename'); ?>.</description>
<language>en-us</language>
<pubDate><?php echo $now; ?></pubDate>
<lastBuildDate><?php echo $now; ?></lastBuildDate>
<atom:link href="<?php echo Option::get('siteurl'); ?>/rss.php" rel="self" type="application/rss+xml" />
<generator>Monstra</generator>
<?php foreach ($posts as $post) { ?>
<item>
<title><?php echo $post['title']; ?></title>
<link><?php echo Option::get('siteurl').'/blog/'.$post['slug']; ?></link>
<guid><?php echo Option::get('siteurl').'/blog/'.$post['slug']; ?></guid>
<pubDate><?php echo Date::format($post['date'], 'd M Y'); ?></pubDate>
<description><![CDATA[<?php echo Text::toHtml(Text::cut(File::getContent(STORAGE . DS . 'pages' . DS . $post['id'] . '.page.txt'), 300)); ?>]]></description>
<author><?php echo $post['author']; ?></author>
</item>
<?php } ?>
</channel>
</rss>