71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsPost.php';
|
|
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsCategory.php';
|
|
|
|
class CategoryCmsControllerCore extends FrontController
|
|
{
|
|
public $php_self = 'categorycms';
|
|
public $categorycms;
|
|
|
|
const PER_PAGE = 4;
|
|
|
|
public function canonicalRedirection($canonical_url = '') {
|
|
parent::canonicalRedirection($this->context->link->getCategoryCmsLink($this->categorycms->id));
|
|
}
|
|
|
|
public function init() {
|
|
$id_category_cms = Tools::getValue('id_category_cms', 0);
|
|
$this->categorycms = new CmsPsCategory($id_category_cms, $this->context->language->id);
|
|
|
|
if (!Validate::isLoadedObject($this->categorycms)
|
|
|| !$this->categorycms->active) {
|
|
header('HTTP/1.1 404 Not Found');
|
|
header('Status: 404 Not Found');
|
|
}
|
|
parent::init();
|
|
}
|
|
|
|
public function initContent() {
|
|
parent::initContent();
|
|
$id_lang = Context::getContext()->language->id;
|
|
|
|
$tipsDay = CmsPsCategory::getTipsofDay($this->categorycms->id, $id_lang);
|
|
|
|
$page = Tools::getValue('page', 1);
|
|
$total = $this->categorycms->getArticles($id_lang, 9999999, 1, TRUE, 'date_add');
|
|
$nb_page = ceil($total / self::PER_PAGE);
|
|
if($page > $nb_page) {
|
|
$page = $nb_page;
|
|
}
|
|
|
|
$articles = $this->categorycms->getArticles($id_lang, self::PER_PAGE, $page, FALSE, 'date_add');
|
|
|
|
$bestsTips = $this->categorycms->getArticles($id_lang, 3, 1, FALSE, 'note');
|
|
|
|
if (isset($_GET['order_by'])) {
|
|
$url_pagination = $this->removeqsvar($_SERVER['REQUEST_URI'], 'page');
|
|
} else {
|
|
$url_pagination = strtok($_SERVER['REQUEST_URI'], '?');
|
|
}
|
|
|
|
$this->context->smarty->assign(array(
|
|
'path' => Tools::getPath($this->categorycms->id, '', FALSE, 'categoriescms'),
|
|
'categorycms' => $this->categorycms,
|
|
'articles' => $articles,
|
|
'bestsTips' => $bestsTips,
|
|
'url_pagination'=> $url_pagination,
|
|
'total' => $total,
|
|
'limit' => count($articles),
|
|
'nb_page' => $nb_page,
|
|
'p' => $page,
|
|
'tipsDay' => $tipsDay
|
|
));
|
|
|
|
$this->setTemplate(_PS_THEME_DIR_.'categorycms.tpl');
|
|
}
|
|
|
|
public function removeqsvar($url, $varname) {
|
|
return preg_replace('/([?&])'.$varname.'=[^&]+(&|$)/','$1',$url);
|
|
}
|
|
} |