76 lines
1.7 KiB
PHP
76 lines
1.7 KiB
PHP
<?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);
|
||
}
|
||
|
||
|
||
}
|