/** * Smarty {blog_archive} block plugin * * Type: block<br> * Name: blog_archive<br> * Purpose: Loads in a blog articles from the database<br> * Useage: * {blog_archive varname='archive' category='test' year='2010'} * ... * {/blog_articles} * @author Nathan Gardner <*****@*****.**> */ function smarty_block_blog_archive(&$params, $content, &$smarty, &$repeat) { if ($repeat) { $objBlog = new BlogModel(); $months = array(); $filters = array(); $filters['nolimit'] = true; if (!empty($params['year'])) { $filters['year'] = $params['year']; } if (!empty($params['category'])) { $filters['category_id'] = $objBlog->getCategoryId($params['category']); } $allArticles = $objBlog->getArticles($filters); if (!empty($allArticles)) { foreach ($allArticles as $article) { $year = substr($article['publishDate'], 0, 4); $month = substr($article['publishDate'], 5, 2); if ($params['yearly']) { $index = $year; } else { $index = $year . $month; } if (empty($months[$index])) { $months[$index] = array('month' => $month, 'year' => $year, 'count' => 1); } else { $months[$index]['count'] = $months[$index]['count'] + 1; } } } $params['data'] = $months; $repeat = count($months); } if (is_array($params['data'])) { if ($month = array_shift($params['data'])) { $smarty->assign($params['varname'], $month); } } if (empty($month)) { $repeat = false; } else { $repeat = true; } return $content; }
/** * Smarty {blog_articles} block plugin * * Type: block<br> * Name: blog_articles<br> * Purpose: Loads in a blog articles from the database<br> * Useage: * {blog_articles varname='myblog' category='test'} * {$myblog.title}<br/> * {$myblog.article}<br/> * {/blog_articles} * @author Nathan Gardner <*****@*****.**> */ function smarty_block_blog_articles(&$params, $content, &$smarty, &$repeat) { if ($repeat) { $objBlog = new BlogModel(); if (!empty($params['identifier'])) { // pull just one article $filters = array(); $filters['id'] = $objBlog->getArticleId($params['identifier']); } else { $filters = array(); $filters['status'] = 'published'; // limit to category if (!empty($params['category'])) { $filters['category_id'] = $objBlog->getCategoryId($params['category']); } // limit amount returned if (!empty($params['limit'])) { $filters['limit'] = intval($params['limit']); } // preview flag if (!empty($params['preview'])) { $filters['preview'] = true; } } $params['articles'] = $objBlog->getArticles($filters); $repeat = $params['articles']; } if (is_array($params['articles'])) { if ($article = array_shift($params['articles'])) { $smarty->assign($params['varname'], $article); } } if (empty($article)) { $repeat = false; } else { $repeat = true; } return $content; }
function smarty_function_blogmenu($params, &$smarty) { $output = ''; $objBlog = new BlogModel(); $categoryList = $objBlog->getCategories(); global $__catListTemp; if (!empty($categoryList)) { // limit to a parent if (!empty($params['parent'])) { // find parent $parent_id = $objBlog->getCategoryId($params['parent']); if ($parent_id) { smarty_function_blogmenu_parent($categoryList, $parent_id); $categoryList = $__catListTemp; } } reset($categoryList); // draw menu $output = smarty_function_blogmenu_makemenu($categoryList, $output, $smarty); } return $output; }