/** * Load the data, don't forget to validate the incoming data */ private function getData() { // get categories $categories = FrontendBlogModel::getAllCategories(); $possibleCategories = array(); foreach ($categories as $category) { $possibleCategories[$category['url']] = $category['id']; } // requested category $requestedCategory = \SpoonFilter::getValue($this->URL->getParameter(1, 'string'), array_keys($possibleCategories), 'false'); // requested page $requestedPage = $this->URL->getParameter('page', 'int', 1); // validate category if ($requestedCategory == 'false') { $this->redirect(FrontendNavigation::getURL(404)); } // set category $this->category = $categories[$possibleCategories[$requestedCategory]]; // set URL and limit $this->pagination['url'] = FrontendNavigation::getURLForBlock('Blog', 'Category') . '/' . $requestedCategory; $this->pagination['limit'] = $this->get('fork.settings')->get('Blog', 'overview_num_items', 10); // populate count fields in pagination $this->pagination['num_items'] = FrontendBlogModel::getAllForCategoryCount($requestedCategory); $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']); // redirect if the request page doesn't exists 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::getAllForCategory($requestedCategory, $this->pagination['limit'], $this->pagination['offset']); }
/** * Parse */ private function parse() { // get categories $categories = FrontendBlogModel::getAllCategories(); // any categories? if (!empty($categories)) { // build link $link = FrontendNavigation::getURLForBlock('Blog', 'Category'); // loop and reset url foreach ($categories as &$row) { $row['url'] = $link . '/' . $row['url']; } } // assign comments $this->tpl->assign('widgetBlogCategories', $categories); }
/** * Parse the data into the template */ private function parse() { // get RSS-link $rssTitle = $this->get('fork.settings')->get('Blog', 'rss_title_' . FRONTEND_LANGUAGE); $rssLink = FrontendNavigation::getURLForBlock('Blog', 'Rss'); // add RSS-feed $this->header->addRssLink($rssTitle, $rssLink); // get RSS-link for the comments $rssCommentTitle = vsprintf(FL::msg('CommentsOn'), array($this->record['title'])); $rssCommentsLink = FrontendNavigation::getURLForBlock('Blog', 'ArticleCommentsRss') . '/' . $this->record['url']; // add RSS-feed into the metaCustom $this->header->addRssLink($rssCommentTitle, $rssCommentsLink); // add specified image if (isset($this->record['image']) && $this->record['image'] != '') { $this->header->addOpenGraphImage(FRONTEND_FILES_URL . '/blog/images/source/' . $this->record['image']); } // Open Graph-data: add images from content $this->header->extractOpenGraphImages($this->record['text']); // Open Graph-data: add additional OpenGraph data $this->header->addOpenGraphData('title', $this->record['title'], true); $this->header->addOpenGraphData('type', 'article', true); $this->header->addOpenGraphData('url', SITE_URL . $this->record['full_url'], true); $this->header->addOpenGraphData('site_name', $this->get('fork.settings')->get('Core', 'site_title_' . FRONTEND_LANGUAGE, SITE_DEFAULT_TITLE), true); $this->header->addOpenGraphData('description', $this->record['meta_description_overwrite'] == 'Y' ? $this->record['meta_description'] : $this->record['title'], true); // Twitter Card $imgURL = FRONTEND_FILES_URL . '/blog/images/source/' . $this->record['image']; $this->header->setTwitterCard($this->record['title'], $this->record['meta_description'], $imgURL); // when there are 2 or more categories with at least one item in it, // the category will be added in the breadcrumb if (count(FrontendBlogModel::getAllCategories()) > 1) { $this->breadcrumb->addElement($this->record['category_title'], FrontendNavigation::getURLForBlock('Blog', 'Category') . '/' . $this->record['category_url']); } // add into breadcrumb $this->breadcrumb->addElement($this->record['title']); // set meta $this->header->setPageTitle($this->record['meta_title'], $this->record['meta_title_overwrite'] == 'Y'); $this->header->addMetaDescription($this->record['meta_description'], $this->record['meta_description_overwrite'] == 'Y'); $this->header->addMetaKeywords($this->record['meta_keywords'], $this->record['meta_keywords_overwrite'] == 'Y'); // advanced SEO-attributes if (isset($this->record['meta_data']['seo_index'])) { $this->header->addMetaData(array('name' => 'robots', 'content' => $this->record['meta_data']['seo_index'])); } if (isset($this->record['meta_data']['seo_follow'])) { $this->header->addMetaData(array('name' => 'robots', 'content' => $this->record['meta_data']['seo_follow'])); } $this->header->setCanonicalUrl($this->record['full_url']); // assign article $this->tpl->assign('item', $this->record); // count comments $commentCount = count($this->comments); // assign the comments $this->tpl->assign('commentsCount', $commentCount); $this->tpl->assign('comments', $this->comments); // options if ($commentCount > 1) { $this->tpl->assign('blogCommentsMultiple', true); } // parse the form $this->frm->parse($this->tpl); // some options if ($this->URL->getParameter('comment', 'string') == 'moderation') { $this->tpl->assign('commentIsInModeration', true); } if ($this->URL->getParameter('comment', 'string') == 'spam') { $this->tpl->assign('commentIsSpam', true); } if ($this->URL->getParameter('comment', 'string') == 'true') { $this->tpl->assign('commentIsAdded', true); } // assign settings $this->tpl->assign('settings', $this->settings); $navigation = FrontendBlogModel::getNavigation($this->record['id']); // set previous and next link for usage with Flip ahead if (!empty($navigation['previous'])) { $this->header->addLink(array('rel' => 'prev', 'href' => SITE_URL . $navigation['previous']['url'])); } if (!empty($navigation['next'])) { $this->header->addLink(array('rel' => 'next', 'href' => SITE_URL . $navigation['next']['url'])); } // assign navigation $this->tpl->assign('navigation', $navigation); }