Esempio n. 1
0
 public function displayList()
 {
     $id_lang = $this->context->language->id;
     $id_shop = $this->context->shop->id;
     $limit_per_page = intval($this->conf['list_limit_page']);
     $current_page = isset($_GET['p']) && is_numeric($_GET['p']) ? intval($_GET['p']) : 1;
     $start = ($current_page - 1) * $limit_per_page;
     $category = null;
     if (!is_null($this->id_category) && is_numeric($this->id_category)) {
         $category = new BlogCategory(intval($this->id_category));
         $category_lang = $category->id_lang;
         if ($category_lang != 0 && $category_lang != $id_lang || !$category->isAssociatedToShop($id_shop)) {
             $category->active = 0;
         }
     }
     if ($category && $category->active) {
         $nb_articles = $category->nbPosts(true, true);
         // first page if page not exists
         $max_page = ceil($nb_articles / $limit_per_page);
         if ($max_page < $current_page) {
             $current_page = 1;
             $start = 0;
         }
         $list = $category->getPosts(true, true, $start, intval($this->conf['list_limit_page']));
         /* Metas */
         $curr_meta_title = $this->context->smarty->getTemplateVars('meta_title');
         $this->context->smarty->assign(array('meta_title' => $curr_meta_title . ' - ' . $category->name, 'meta_description' => $category->meta_description, 'meta_keywords' => $category->meta_keywords));
         $categoryLink = BlogCategory::linkCategory($category->id, $category->link_rewrite, $category->id_lang);
         $paginationLink = BlogCategory::linkCategory($category->id, $category->link_rewrite, $category->id_lang, '');
         $this->context->smarty->assign(array('categoryLink' => $categoryLink, 'post_category' => $category, 'paginationLink' => $paginationLink));
     } elseif ($category && $category->active == 0) {
         $this->context->smarty->assign('post_category', false);
         $this->context->smarty->assign('notfound', true);
     } else {
         if (isset($_GET['search']) && $_GET['search'] != '') {
             //search articles
             $search_query = $_GET['search'];
             $nb_articles = BlogPost::searchPosts($search_query, true, true, true);
             $list = BlogPost::searchPosts($search_query, true, true, false, $start, $limit_per_page);
             $this->context->smarty->assign('search_query_nb', $nb_articles);
             $this->context->smarty->assign('search_query', $search_query);
             $paginationLink = BlogPost::linkList('', null, $search_query);
             $this->context->smarty->assign('paginationLink', $paginationLink);
         } else {
             $paginationLink = BlogPost::linkList('');
             /*                 * * ALL ARTICLES ** */
             $nb_articles = BlogPost::listPosts(true, true, null, null, true, null, null, null);
             $list = BlogPost::listPosts(true, true, $start, $limit_per_page, false, null, null, null);
             $this->context->smarty->assign('paginationLink', $paginationLink);
         }
     }
     if (isset($list) && is_array($list) && count($list)) {
         /** pagination * */
         $nb_pages = ceil($nb_articles / $limit_per_page);
         $next = $current_page > 1 ? true : false;
         //articles plus recents
         $back = $current_page >= 1 && $current_page < $nb_pages ? true : false;
         //articles precedents
         $i = 0;
         foreach ($list as $val) {
             $list[$i]['link'] = BlogPost::linkPost($val['id_blog_post'], $val['link_rewrite'], $val['id_lang']);
             $categories = BlogCategory::getPostCategories($val['id_blog_post'], true, true);
             if ($categories) {
                 $j = 0;
                 foreach ($categories as $cat) {
                     $categories[$j]['link'] = BlogCategory::linkCategory($cat['id_blog_category'], $cat['link_rewrite'], $cat['id_lang']);
                     $j++;
                 }
             }
             $list[$i]['categories'] = $categories;
             $i++;
         }
         $this->context->smarty->assign(array('post_list' => $list, 'next' => $next, 'back' => $back, 'curr_page' => $current_page));
     }
     $this->setTemplate('list.tpl');
 }