toutpratique/controllers/front/PostCmsController.php

97 lines
2.7 KiB
PHP
Raw Normal View History

2015-07-10 16:29:27 +02:00
<?php
2015-08-07 17:59:33 +02:00
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsPost.php';
2015-08-20 11:28:09 +02:00
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsCategory.php';
2015-07-10 16:29:27 +02:00
class PostCmsControllerCore extends FrontController
{
public $php_self = 'postcms';
public $postcms;
public function canonicalRedirection($canonical_url = '') {
parent::canonicalRedirection($this->context->link->getPostCmsLink($this->postcms->id));
}
public function init() {
2015-08-12 14:41:06 +02:00
$id_post_cms = Tools::getValue('id_post_cms', 0);
2015-07-10 16:29:27 +02:00
$this->postcms = new CmsPsPost($id_post_cms, $this->context->language->id);
if (!Validate::isLoadedObject($this->postcms)
|| !$this->postcms->active) {
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
}
parent::init();
}
public function initContent() {
parent::initContent();
2015-08-12 10:53:32 +02:00
2015-08-20 11:28:09 +02:00
$id_lang = Context::getContext()->language->id;
2015-08-17 15:17:04 +02:00
$article = CmsPsPost::injectsData($this->postcms, TRUE);
2015-10-12 12:54:29 +02:00
$category = new CmsPsCategory($this->postcms->id_category, $id_lang);
// $bestsTips = $category->getArticles($id_lang, 4, 1, FALSE, 'note');
$relations = $this->postcms->loadPostCmsRelation(10);
2015-08-20 11:28:09 +02:00
2015-09-25 17:22:27 +02:00
$cart = Context::getContext()->cart;
$nb_product_in_cart = $cart->nbProducts();
2015-10-12 12:37:18 +02:00
$article = $this->formatArticle($article);
2015-10-12 12:54:29 +02:00
$all_articles = $category->getArticles($id_lang, 999999, 1, FALSE, 'note');
2015-10-12 12:37:18 +02:00
2015-07-10 16:29:27 +02:00
$this->context->smarty->assign(array(
2015-10-12 12:54:29 +02:00
'path' => Tools::getPath($this->postcms->id, '', FALSE, 'postcms'),
'category' => $category,
'relations' => $relations,
'nb_product_in_cart' => $nb_product_in_cart,
// 'bestsTips' => $bestsTips,
'all_articles' => $all_articles,
'post' => $article
2015-07-10 16:29:27 +02:00
));
$this->setTemplate(_PS_THEME_DIR_.'postcms.tpl');
}
2015-10-12 12:37:18 +02:00
public function formatArticle($article)
{
$article->content = str_replace(
array('h1', '</h1>',
'<p>---ATTENTION---</p>',
2015-10-14 11:22:13 +02:00
'<p>---TRUCS---</p>',
2015-10-12 12:37:18 +02:00
'<p>---TRUC---</p>',
'<p>---ASAVOIR---</p>',
'<p>---ANOTER---</p>',
2015-10-12 12:41:36 +02:00
'<p>---FIN---</p>',
'---ATTENTION---',
2015-10-14 11:22:13 +02:00
'---TRUCS---',
2015-10-12 12:41:36 +02:00
'---TRUC---',
'---ASAVOIR---',
'---ANOTER---',
'---FIN---',
2015-12-14 16:07:18 +01:00
'---VIDEO---',
'---AMAZON---',
2015-10-12 12:37:18 +02:00
),
array('h2', '</h2>',
2015-10-27 14:56:01 +01:00
'<div class="info warning"><h5>Attention</h5>',
'<div class="info truc"><h5>Trucs</h5>',
'<div class="info truc"><h5>Trucs</h5>',
'<div class="info asavoir"><h5>A savoir</h5>',
'<div class="info anoter"><h5>A noter</h5>',
2015-10-12 12:41:36 +02:00
'</div>',
2015-10-27 14:56:01 +01:00
'<div class="info warning"><h5>Attention</h5>',
'<div class="info truc"><h5>Trucs</h5>',
'<div class="info truc"><h5>Trucs</h5>',
'<div class="info asavoir"><h5>A savoir</h5>',
'<div class="info anoter"><h5>A noter</h5>',
2015-10-12 12:41:36 +02:00
'</div>',
2015-12-14 16:07:18 +01:00
'',
'',
2015-10-12 12:37:18 +02:00
),
$article->content);
return $article;
}
2015-08-12 12:04:17 +02:00
}