mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-07-11 00:26:18 +02:00
Blog Plugin as a part of Monstra CMS
This commit is contained in:
2
plugins/blog/README.md
Normal file
2
plugins/blog/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
Monstra CMS Blog
|
||||
================
|
356
plugins/blog/blog.plugin.php
Normal file
356
plugins/blog/blog.plugin.php
Normal file
@ -0,0 +1,356 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Blog plugin
|
||||
*
|
||||
* @package Monstra
|
||||
* @subpackage Plugins
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version 1.7.3
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Register plugin
|
||||
Plugin::register( __FILE__,
|
||||
__('Blog', 'blog'),
|
||||
__('Blog plugin for Monstra', 'blog'),
|
||||
'1.7.3',
|
||||
'Awilum',
|
||||
'http://monstra.org/');
|
||||
|
||||
|
||||
/**
|
||||
* Blog Class
|
||||
*/
|
||||
class Blog {
|
||||
|
||||
|
||||
/**
|
||||
* Parrent page name(slug)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $parent_page_name = 'blog';
|
||||
|
||||
|
||||
/**
|
||||
* Get tags
|
||||
*
|
||||
* <code>
|
||||
* echo Blog::getTags();
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getTags($slug = null) {
|
||||
|
||||
// Display view
|
||||
return View::factory('blog/views/frontend/tags')
|
||||
->assign('tags', Blog::getTagsArray($slug))
|
||||
->render();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get breadcrumbs
|
||||
*
|
||||
* <code>
|
||||
* echo Blog::breadcrumbs();
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function breadcrumbs() {
|
||||
$current_page = Pages::$requested_page;
|
||||
$parent_page = '';
|
||||
if ($current_page !== 'error404') {
|
||||
$page = Pages::$pages->select('[slug="'.$current_page.'"]', null);
|
||||
if (trim($page['parent']) !== '') {
|
||||
$parent = true;
|
||||
$parent_page = Pages::$pages->select('[slug="'.$page['parent'].'"]', null);
|
||||
} else {
|
||||
$parent = false;
|
||||
}
|
||||
|
||||
// Display view
|
||||
View::factory('blog/views/frontend/breadcrumbs')
|
||||
->assign('current_page', $current_page)
|
||||
->assign('page', $page)
|
||||
->assign('parent', $parent)
|
||||
->assign('parent_page', $parent_page)
|
||||
->display();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get tags array
|
||||
*
|
||||
* <code>
|
||||
* echo Blog::getTagsArray();
|
||||
* </code>
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getTagsArray($slug = null) {
|
||||
|
||||
// Init vars
|
||||
$tags = array();
|
||||
$tags_string = '';
|
||||
|
||||
if ($slug == null) {
|
||||
$posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published"]', 'all');
|
||||
} else {
|
||||
$posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published" and slug="'.$slug.'"]', 'all');
|
||||
}
|
||||
|
||||
foreach($posts as $post) {
|
||||
$tags_string .= $post['keywords'].',';
|
||||
}
|
||||
|
||||
$tags_string = substr($tags_string, 0, strlen($tags_string)-1);
|
||||
|
||||
// Explode tags in tags array
|
||||
$tags = explode(',', $tags_string);
|
||||
|
||||
// Remove empty array elementss
|
||||
foreach ($tags as $key => $value) {
|
||||
if ($tags[$key] == '') {
|
||||
unset($tags[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Trim tags
|
||||
array_walk($tags, create_function('&$val', '$val = trim($val);'));
|
||||
|
||||
// Get unique tags
|
||||
$tags = array_unique($tags);
|
||||
|
||||
// Return tags
|
||||
return $tags;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get posts
|
||||
*
|
||||
* <code>
|
||||
* // Get all posts
|
||||
* echo Blog::getPosts();
|
||||
*
|
||||
* // Get last 5 posts
|
||||
* echo Blog::getPosts(5);
|
||||
* </code>
|
||||
*
|
||||
* @param integer $num Number of posts to show
|
||||
* @return string
|
||||
*/
|
||||
public static function getPosts($nums = 10) {
|
||||
|
||||
// Get page param
|
||||
$page = (Request::get('page')) ? (int)Request::get('page') : 1;
|
||||
|
||||
if (Request::get('tag')) {
|
||||
$query = '[parent="'.Blog::$parent_page_name.'" and status="published" and contains(keywords, "'.Request::get('tag').'")]';
|
||||
Notification::set('tag', Request::get('tag'));
|
||||
} else {
|
||||
$query = '[parent="'.Blog::$parent_page_name.'" and status="published"]';
|
||||
Notification::clean();
|
||||
}
|
||||
|
||||
// Get Elements Count
|
||||
$elements = count(Pages::$pages->select($query, 'all'));
|
||||
|
||||
// Get Pages Count
|
||||
$pages = ceil($elements/$nums);
|
||||
|
||||
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
} elseif ($page > $pages) {
|
||||
$page = $pages;
|
||||
}
|
||||
|
||||
$start = ($page-1)*$nums;
|
||||
|
||||
// If there is no posts
|
||||
if ($start < 0) $start = 0;
|
||||
|
||||
// Get posts and sort by DESC
|
||||
$posts = Pages::$pages->select($query, $nums, $start, array('slug', 'title', 'author', 'date'), 'date', 'DESC');
|
||||
|
||||
// Loop
|
||||
foreach($posts as $key => $post) {
|
||||
$post_short = explode("{cut}", Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $post['id'] . '.page.txt')));
|
||||
$posts[$key]['content'] = Filter::apply('content', $post_short[0]);
|
||||
}
|
||||
|
||||
// Display view
|
||||
return View::factory('blog/views/frontend/index')
|
||||
->assign('posts', $posts)
|
||||
->render().
|
||||
View::factory('blog/views/frontend/pager')
|
||||
->assign('pages', $pages)
|
||||
->assign('page', $page)
|
||||
->render();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get posts block
|
||||
*
|
||||
* <code>
|
||||
* // Get all posts
|
||||
* echo Blog::getPostsBlock();
|
||||
*
|
||||
* // Get last 5 posts
|
||||
* echo Blog::getPostsBlock(5);
|
||||
* </code>
|
||||
*
|
||||
* @param integer $num Number of posts to show
|
||||
* @return string
|
||||
*/
|
||||
public static function getPostsBlock($nums = 10) {
|
||||
|
||||
// XPath Query
|
||||
$query = '[parent="'.Blog::$parent_page_name.'" and status="published"]';
|
||||
|
||||
// Get posts and sort by DESC
|
||||
$posts = Pages::$pages->select($query, $nums, 0, array('slug', 'title', 'author', 'date'), 'date', 'DESC');
|
||||
|
||||
// Loop
|
||||
foreach($posts as $key => $post) {
|
||||
$post_short = explode("{cut}", Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $post['id'] . '.page.txt')));
|
||||
$posts[$key]['content'] = Filter::apply('content', $post_short[0]);
|
||||
}
|
||||
|
||||
// Display view
|
||||
return View::factory('blog/views/frontend/block')
|
||||
->assign('posts', $posts)
|
||||
->render();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get related posts
|
||||
*
|
||||
* <code>
|
||||
* echo Blog::getRelatedPosts();
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getRelatedPosts($limit = null) {
|
||||
|
||||
$related_posts = array();
|
||||
$tags = Blog::getTagsArray(Page::slug());
|
||||
|
||||
foreach($tags as $tag) {
|
||||
|
||||
$query = '[parent="'.Blog::$parent_page_name.'" and status="published" and contains(keywords, "'.$tag.'") and slug!="'.Page::slug().'"]';
|
||||
|
||||
if ($result = Arr::subvalSort(Pages::$pages->select($query, ($limit == null) ? 'all' : (int)$limit), 'date', 'DESC')) {
|
||||
$related_posts = $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Display view
|
||||
return View::factory('blog/views/frontend/related_posts')
|
||||
->assign('related_posts', $related_posts)
|
||||
->render();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get post content
|
||||
*
|
||||
* <code>
|
||||
* echo Blog::getPost();
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPost() {
|
||||
|
||||
// Get post
|
||||
$post = Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . Pages::$page['id'] . '.page.txt'));
|
||||
|
||||
// Apply content filter
|
||||
$post = Filter::apply('content', $post);
|
||||
|
||||
// Remove {cut} shortcode
|
||||
$post = strtr($post, array('{cut}' => ''));
|
||||
|
||||
// Return post
|
||||
return $post;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get post content before cut
|
||||
*
|
||||
* <code>
|
||||
* echo Blog::getPostBeforeCut('home');
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPostBeforeCut($slug) {
|
||||
|
||||
$page = Pages::$pages->select('[slug="'.$slug.'"]', null);
|
||||
|
||||
// Get post
|
||||
$post = explode("{cut}", Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt')));
|
||||
|
||||
// Apply content filter
|
||||
$post_content = Filter::apply('content', $post[0]);
|
||||
|
||||
// Return post
|
||||
return $post_content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get post content after cut
|
||||
*
|
||||
* <code>
|
||||
* echo Blog::getPostAfterCut('home');
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPostAfterCut($slug) {
|
||||
|
||||
$page = Pages::$pages->select('[slug="'.$slug.'"]', null);
|
||||
|
||||
// Get post
|
||||
$post = explode("{cut}", Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt')));
|
||||
|
||||
// Apply content filter
|
||||
$post_content = Filter::apply('content', $post[1]);
|
||||
|
||||
// Return post
|
||||
return $post_content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Blog Post title
|
||||
*
|
||||
* <code>
|
||||
* echo Blog::getPostTitle();
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPostTitle() {
|
||||
return Page::title();
|
||||
}
|
||||
|
||||
}
|
||||
|
11
plugins/blog/install/blog.manifest.xml
Normal file
11
plugins/blog/install/blog.manifest.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<plugin_location>plugins/blog/blog.plugin.php</plugin_location>
|
||||
<plugin_status>active</plugin_status>
|
||||
<plugin_priority>15</plugin_priority>
|
||||
<plugin_name>Blog</plugin_name>
|
||||
<plugin_description>Blog plugin for Monstra</plugin_description>
|
||||
<plugin_version>1.7.3</plugin_version>
|
||||
<plugin_author>Awilum</plugin_author>
|
||||
<plugin_author_uri>http://monstra.org/</plugin_author_uri>
|
||||
</root>
|
12
plugins/blog/languages/en.lang.php
Normal file
12
plugins/blog/languages/en.lang.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'blog' => array(
|
||||
'Blog' => 'Blog',
|
||||
'Blog plugin for Monstra' => 'Blog plugin for Monstra',
|
||||
'begin' => 'begin',
|
||||
'end' => 'end',
|
||||
'prev' => 'prev',
|
||||
'next' => 'next',
|
||||
)
|
||||
);
|
13
plugins/blog/languages/ru.lang.php
Normal file
13
plugins/blog/languages/ru.lang.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'blog' => array(
|
||||
'Blog' => 'Блог',
|
||||
'Blog plugin for Monstra' => 'Плагин блога для Monstra',
|
||||
'begin' => 'начало',
|
||||
'end' => 'конец',
|
||||
'prev' => 'назад',
|
||||
'next' => 'вперед',
|
||||
'Related posts' => 'Статьи по теме',
|
||||
)
|
||||
);
|
40
plugins/blog/rss.php
Normal file
40
plugins/blog/rss.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
define('ROOT', rtrim(dirname(__FILE__), '\\/'));
|
||||
define('BACKEND', false);
|
||||
define('MONSTRA_ACCESS', true);
|
||||
|
||||
// Load bootstrap file
|
||||
require_once(ROOT . DS . 'engine' . DS . '_init.php');
|
||||
|
||||
// Get all posts for blog parent page/post
|
||||
$posts = Pages::$pages->select('[parent="blog" 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>
|
5
plugins/blog/views/frontend/block.view.php
Normal file
5
plugins/blog/views/frontend/block.view.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php foreach($posts as $post) { ?>
|
||||
<a href="<?php echo Option::get('siteurl'); ?><?php echo Blog::$parent_page_name; ?>/<?php echo $post['slug']; ?>"><?php echo $post['title']; ?></a> <small class="monstra-blog-date"><?php echo Date::format($post['date'], 'd M Y'); ?></small><br>
|
||||
<?php echo $post['content']; ?>
|
||||
<br><br>
|
||||
<?php } ?>
|
5
plugins/blog/views/frontend/breadcrumbs.view.php
Normal file
5
plugins/blog/views/frontend/breadcrumbs.view.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php if ($parent) { ?>
|
||||
<a href="<?php echo Site::url().$page['parent']; ?><?php if(Notification::get('tag')) { ?>?tag=<?php echo Notification::get('tag'); ?><?php } ?>"><?php echo $parent_page['title']; ?></a> <span>→</span> <a href="<?php echo Site::url().$page['parent'].'/'.$page['slug']; ?>"><?php echo $page['title']; ?></a>
|
||||
<?php } else { ?>
|
||||
<a href="<?php echo Site::url().$page['slug']; ?><?php if(Notification::get('tag')) { ?>?tag=<?php echo Notification::get('tag'); ?><?php } ?>"><?php echo $page['title']; ?></a>
|
||||
<?php } ?>
|
5
plugins/blog/views/frontend/index.view.php
Normal file
5
plugins/blog/views/frontend/index.view.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php foreach($posts as $post) { ?>
|
||||
<a href="<?php echo Option::get('siteurl'); ?><?php echo Blog::$parent_page_name; ?>/<?php echo $post['slug'] ?>"><?php echo $post['title']; ?></a> <small class="monstra-blog-date"><?php echo Date::format($post['date'], 'd M Y'); ?></small><br>
|
||||
<?php echo $post['content']; ?>
|
||||
<br><br>
|
||||
<?php } ?>
|
28
plugins/blog/views/frontend/pager.view.php
Normal file
28
plugins/blog/views/frontend/pager.view.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
if (Request::get('tag')) $tag = '&tag='.Request::get('tag'); else $tag = '';
|
||||
|
||||
$neighbours = 6;
|
||||
$left_neighbour = $page - $neighbours;
|
||||
if ($left_neighbour < 1) $left_neighbour = 1;
|
||||
|
||||
$right_neighbour = $page + $neighbours;
|
||||
if ($right_neighbour > $pages) $right_neighbour = $pages;
|
||||
|
||||
if ($page > 1) {
|
||||
echo ' <a href="?page=1'.$tag.'">'.__('begin', 'blog').'</a> ... <a href="?page=' . ($page-1) . $tag.'">'.__('prev', 'blog').'</a> ';
|
||||
}
|
||||
|
||||
for ($i=$left_neighbour; $i<=$right_neighbour; $i++) {
|
||||
if ($i != $page) {
|
||||
echo ' <a href="?page=' . $i . $tag.'">' . $i . '</a> ';
|
||||
} else {
|
||||
echo ' <b>' . $i . '</b> ';
|
||||
}
|
||||
}
|
||||
|
||||
if ($page < $pages) {
|
||||
echo ' <a href="?page=' . ($page+1) . $tag.'">'.__('next', 'blog').'</a> ... <a href="?page=' . $pages . $tag.'">'.__('end', 'blog').'</a> ';
|
||||
}
|
||||
|
||||
?>
|
7
plugins/blog/views/frontend/related_posts.view.php
Normal file
7
plugins/blog/views/frontend/related_posts.view.php
Normal file
@ -0,0 +1,7 @@
|
||||
<br><br>
|
||||
<b><?php echo __('Related posts', 'blog'); ?>:</b>
|
||||
<div>
|
||||
<?php foreach($related_posts as $related_post) { ?>
|
||||
<a href="<?php echo Option::get('siteurl'); ?><?php echo Blog::$parent_page_name; ?>/<?php echo $related_post['slug']; ?>"><?php echo $related_post['title']; ?></a><br>
|
||||
<?php } ?>
|
||||
</div>
|
3
plugins/blog/views/frontend/tags.view.php
Normal file
3
plugins/blog/views/frontend/tags.view.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php foreach($tags as $tag) { ?>
|
||||
<a href="<?php echo Option::get('siteurl'); ?><?php echo Blog::$parent_page_name; ?>?tag=<?php echo $tag; ?>"><span class="label label-important" data-original-title=""><?php echo $tag; ?></span></a>
|
||||
<?php } ?>
|
Reference in New Issue
Block a user