toutpratique/modules/cms_comments/cms_comments.php
2015-10-20 12:26:53 +02:00

76 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
include_once dirname(__FILE__).'/classes/CmsComments.php';
class Cms_Comments extends Module
{
public function __construct()
{
$this->name = 'cms_comments';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'Antadis';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Comments CMS ANTADIS');
$this->description = $this->l('Manage your comments in CMS Antadis');
$this->secure_key = Tools::encrypt($this->name);
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
if (!parent::install()
|| !$this->registerHook('footer')
|| !$this->registerHook('productComments')
|| !$this->createTables()
)
return false;
}
public function createTables (){
return true;
}
public function hookdisplayFooter()
{
$this->context->controller->addJS(($this->_path).'comments.js', 'all');
}
public function hookproductComments($params)
{
$id_element = $params['element'];
if (!Validate::isInt($id_element)) {
return false;
}
$comments = CmsComments::loadComments($id_element);
foreach ($comments as $key => $comment) {
$comments[$key]['comments'] = self::do_clickable($comment['comments']);
}
$this->smarty->assign(array(
'comments' => $comments,
'id_element' => $id_element
));
return $this->display(__FILE__, 'comments.tpl');
}
public static function do_clickable($text)
{
return preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</a>', $text);
}
}