/frontend/modules/blog/actions/index.php
PHP | 92 lines | 34 code | 15 blank | 43 comment | 6 complexity | d3ce2375a8983f444176925ddca96f25 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, MIT, AGPL-3.0, LGPL-2.1, BSD-3-Clause
- <?php
- /*
- * This file is part of Fork CMS.
- *
- * For the full copyright and license information, please view the license
- * file that was distributed with this source code.
- */
- /**
- * This is the overview-action
- *
- * @author Tijs Verkoyen <tijs@sumocoders.be>
- * @author Davy Hellemans <davy.hellemans@netlash.com>
- */
- class FrontendBlogIndex extends FrontendBaseBlock
- {
- /**
- * The articles
- *
- * @var array
- */
- private $items;
- /**
- * The pagination array
- * It will hold all needed parameters, some of them need initialization.
- *
- * @var array
- */
- protected $pagination = array('limit' => 10, 'offset' => 0, 'requested_page' => 1, 'num_items' => null, 'num_pages' => null);
- /**
- * Execute the extra
- */
- public function execute()
- {
- parent::execute();
- $this->loadTemplate();
- $this->getData();
- $this->parse();
- }
- /**
- * Load the data, don't forget to validate the incoming data
- */
- private function getData()
- {
- // requested page
- $requestedPage = $this->URL->getParameter('page', 'int', 1);
- // set URL and limit
- $this->pagination['url'] = FrontendNavigation::getURLForBlock('blog');
- $this->pagination['limit'] = FrontendModel::getModuleSetting('blog', 'overview_num_items', 10);
- // populate count fields in pagination
- $this->pagination['num_items'] = FrontendBlogModel::getAllCount();
- $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
- // num pages is always equal to at least 1
- if($this->pagination['num_pages'] == 0) $this->pagination['num_pages'] = 1;
- // redirect if the request page doesn't exist
- if($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) $this->redirect(FrontendNavigation::getURL(404));
- // populate calculated fields in pagination
- $this->pagination['requested_page'] = $requestedPage;
- $this->pagination['offset'] = ($this->pagination['requested_page'] * $this->pagination['limit']) - $this->pagination['limit'];
- // get articles
- $this->items = FrontendBlogModel::getAll($this->pagination['limit'], $this->pagination['offset']);
- }
- /**
- * Parse the data into the template
- */
- private function parse()
- {
- // get RSS-link
- $rssLink = FrontendModel::getModuleSetting('blog', 'feedburner_url_' . FRONTEND_LANGUAGE);
- if($rssLink == '') $rssLink = FrontendNavigation::getURLForBlock('blog', 'rss');
- // add RSS-feed
- $this->header->addLink(array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => FrontendModel::getModuleSetting('blog', 'rss_title_' . FRONTEND_LANGUAGE), 'href' => $rssLink), true);
- // assign articles
- $this->tpl->assign('items', $this->items);
- // parse the pagination
- $this->parsePagination();
- }
- }