* 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($locale = '') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $current_page = Pages::$requested_page; $parent_page = ''; if ($current_page !== 'error404') { $page = Pages::$pages->select('[slug="'.$current_page.'" and locale="'.$locale.'"]', null); if (trim($page['parent']) !== '') { $parent = true; $parent_page = Pages::$pages->select('[slug="'.$page['parent'].'" and locale="'.$locale.'"]', 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, $locale='') { // Init vars $tags = array(); $tags_string = ''; $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; if ($slug == null) { $posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published" and locale="'.$locale.'"]', 'all'); } else { $posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published" and slug="'.$slug.'" and locale="'.$locale.'"]', 'all'); } foreach($posts as $post) { if (isset($post['tags'])) { $tags_string .= $post['tags'].','; } } $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, $locale = '') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; // 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 locale="'.$locale.'" and contains(tags, "'.Request::get('tag').'")]'; Notification::set('tag', Request::get('tag')); } else { $query = '[parent="'.Blog::$parent_page_name.'" and status="published" and locale="'.$locale.'"]'; 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', 'locale', 'template'), '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]); $posts[$key]['slug'] = $posts[$key]['slug']; $posts[$key]['locale'] = ($posts[$key]['locale'] == Site::getCurrentSiteLocale()) ? '' : $posts[$key]['locale'].'/'; } // 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, $locale = '') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; // XPath Query $query = '[parent="'.Blog::$parent_page_name.'" and status="published" and locale="'.$locale.'"]'; // 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, $locale = '') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $related_posts = array(); $tags = Blog::getTagsArray(Page::slug()); foreach($tags as $tag) { $query = '[parent="'.Blog::$parent_page_name.'" and locale="'.$locale.'" and status="published" and contains(tags, "'.$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, $locale = '') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $page = Pages::$pages->select('[slug="'.$slug.'" and locale="'.$locale.'"]', 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, $locale = '') { $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $page = Pages::$pages->select('[slug="'.$slug.'" and locale="'.$locale.'"]', 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(); } /** * _rss */ public static function _rss() { if (Uri::segment(0) == 'rss') { include PLUGINS . DS . 'blog' . DS . 'rss.php'; Request::shutdown(); } } }