コード例 #1
0
/**
 * 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;
}
コード例 #2
0
/**
 * 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;
}
コード例 #3
0
ファイル: Blog.php プロジェクト: ngardner/BentoCMS
 function actionArticles($params = '')
 {
     $objBlog = new BlogModel();
     $objSettings = Settings::getInstance();
     $perPage = $objSettings->getEntry('blog', 'per-page-admin');
     $pageNumb = !empty($params['pageNumb']) ? $params['pageNumb'] : 1;
     $categoryId = !empty($params['category_id']) ? $params['category_id'] : false;
     $articleList = $objBlog->getArticles(array('page' => $pageNumb, 'category_id' => $categoryId, 'howMany' => $perPage));
     $totalPages = ceil($objBlog->totalArticles / $perPage);
     $categoryList = $objBlog->getCategories();
     $this->view->assign('currentCategory', $categoryId);
     $this->view->assign('articleList', $articleList);
     $this->view->assign('totalPages', $totalPages);
     $this->view->assign('pageNumb', $pageNumb);
     $this->view->assign('categoryList', $categoryList);
     $this->view->assign('content', $this->view->fetch('tpl/blog/articles.tpl'));
     $this->view->assign('messages', $this->messages);
     $this->finish();
 }