diff --git a/plugins/blog/README.md b/plugins/blog/README.md index e9f5bbd..9cc1fbf 100644 --- a/plugins/blog/README.md +++ b/plugins/blog/README.md @@ -1,2 +1,40 @@ -Monstra CMS Blog +Blog ================ + +### Usage + +#### Get Post + + +#### Get Posts + + +#### Get 5 Posts (could be any amount, 5 or 1 or 25): + + +#### Get related Posts + + +#### Get 4 latest posts from Blog + + +#### Get Tags&Keywords + + +#### Get Tags&Keywords for current page + + +Get Post Title + + +### Shortcode for content + +#### Divided post into 2 parts (short and full) + {cut} + +Example: + +
Best free themes for Monstra CMS at monstrathemes.com
+ {cut} +There is going to display your content as blog post =)
+ \ No newline at end of file diff --git a/plugins/blog/blog.plugin.php b/plugins/blog/blog.plugin.php index 1346deb..2e4bbcd 100644 --- a/plugins/blog/blog.plugin.php +++ b/plugins/blog/blog.plugin.php @@ -1,387 +1,387 @@ - * echo Blog::getTags(); - * - * - * @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 - * - *
- * echo Blog::breadcrumbs();
- *
- *
- * @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
- *
- *
- * echo Blog::getTagsArray();
- *
- *
- * @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
- *
- *
- * // Get all posts
- * echo Blog::getPosts();
- *
- * // Get last 5 posts
- * echo Blog::getPosts(5);
- *
- *
- * @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
- *
- *
- * // Get all posts
- * echo Blog::getPostsBlock();
- *
- * // Get last 5 posts
- * echo Blog::getPostsBlock(5);
- *
- *
- * @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
- *
- *
- * echo Blog::getRelatedPosts();
- *
- *
- * @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
- *
- *
- * echo Blog::getPost();
- *
- *
- * @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
- *
- *
- * echo Blog::getPostBeforeCut('home');
- *
- *
- * @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
- *
- *
- * echo Blog::getPostAfterCut('home');
- *
- *
- * @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
- *
- *
- * echo Blog::getPostTitle();
- *
- *
- * @return string
- */
- public static function getPostTitle() {
- return Page::title();
- }
-
-
- /**
- * Get Blog Post Date
- *
- *
- * echo Blog::getPostDate();
- *
- *
- * @param string $format Date format
- * @return string
- */
- public static function getPostDate($format = 'Y-m-d') {
- return Page::date($format);
- }
-
-
- /**
- * Get author of current post
- *
- *
- * echo Blog::getPostAuthor();
- *
- *
- * @return string
- */
- public static function getPostAuthor()
- {
- return Page::author();
- }
-
+ public static $parent_page_name = 'blog';
+
+
+ /**
+ * Get tags
+ *
+ *
+ * echo Blog::getTags();
+ *
+ *
+ * @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
+ *
+ *
+ * echo Blog::breadcrumbs();
+ *
+ *
+ * @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
+ *
+ *
+ * echo Blog::getTagsArray();
+ *
+ *
+ * @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
+ *
+ *
+ * // Get all posts
+ * echo Blog::getPosts();
+ *
+ * // Get last 5 posts
+ * echo Blog::getPosts(5);
+ *
+ *
+ * @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
+ *
+ *
+ * // Get all posts
+ * echo Blog::getPostsBlock();
+ *
+ * // Get last 5 posts
+ * echo Blog::getPostsBlock(5);
+ *
+ *
+ * @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
+ *
+ *
+ * echo Blog::getRelatedPosts();
+ *
+ *
+ * @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
+ *
+ *
+ * echo Blog::getPost();
+ *
+ *
+ * @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
+ *
+ *
+ * echo Blog::getPostBeforeCut('home');
+ *
+ *
+ * @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
+ *
+ *
+ * echo Blog::getPostAfterCut('home');
+ *
+ *
+ * @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
+ *
+ *
+ * echo Blog::getPostTitle();
+ *
+ *
+ * @return string
+ */
+ public static function getPostTitle() {
+ return Page::title();
+ }
+
+
+ /**
+ * Get Blog Post Date
+ *
+ *
+ * echo Blog::getPostDate();
+ *
+ *
+ * @param string $format Date format
+ * @return string
+ */
+ public static function getPostDate($format = 'Y-m-d') {
+ return Page::date($format);
+ }
+
+
+ /**
+ * Get author of current post
+ *
+ *
+ * echo Blog::getPostAuthor();
+ *
+ *
+ * @return string
+ */
+ public static function getPostAuthor()
+ {
+ return Page::author();
+ }
+
+
+}
+