Download project

This commit is contained in:
Roman Pyrih
2024-11-20 09:09:44 +01:00
parent 547a138d6a
commit 5ff041757f
40737 changed files with 7766183 additions and 0 deletions

View File

@@ -0,0 +1,340 @@
<?php
/**
* Copyright ETS Software Technology Co., Ltd
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 website only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future.
*
* @author ETS Software Technology Co., Ltd
* @copyright ETS Software Technology Co., Ltd
* @license Valid for 1 website (or project) for each purchase of license
*/
if (!defined('_PS_VERSION_'))
exit;
class Ets_blogBlogModuleFrontController extends ModuleFrontController
{
public $display_column_left = false;
public $display_column_right = false;
public $errors= array();
public $_success = '';
public function __construct()
{
parent::__construct();
}
public function init()
{
parent::init();
if(($blog_search = trim(Tools::getValue('ets_blog_search')))!='' && Validate::isCleanHtml($blog_search))
{
Tools::redirect($this->module->getLink('blog',array('search'=> urlencode($blog_search))));
}
}
public function initContent()
{
if(Tools::isSubmit('bcsubmit'))
{
$this->submitCommentPost();
}
parent::initContent();
$this->module->setMetas();
$this->context->smarty->assign(
array(
'blog_content' => $this->_initContent(),
'blog_left_sidebar' => $this->module->hookDisplayLeftColumn(),
)
);
if($this->module->is17)
$this->setTemplate('module:ets_blog/views/templates/front/blog.tpl');
}
public function _initContent()
{
if($this->context->cookie->_success)
{
$this->_success = $this->context->cookie->_success;
$this->context->cookie->_success = '';
}
$this->module->assignConfig();
$id_post = (int)Tools::getValue('id_post');
if($id_post && ($postObj = new Ets_blog_post($id_post)) && Validate::isLoadedObject($postObj))
{
$post = $postObj->getPost((int)$id_post);
if($post)
{
$urlAlias = Tools::strtolower(trim(Tools::getValue('url_alias')));
$edit_comment = (int)Tools::getValue('edit_comment');
if($urlAlias && !$edit_comment && $urlAlias != Tools::strtolower(trim($post['url_alias'])))
Tools::redirect($this->module->getLink('blog',array('id_post' => $post['id_post'])));
if((int)Tools::getValue('all_comment'))
$climit=false;
else
$climit = 5;
$cstart = $climit ? 0 : false;
$countComment= Ets_blog_comment::countCommentsWithFilter(' AND bc.approved = 1 AND bc.id_post='.(int)$postObj->id);
if($climit && $countComment > (int)$climit )
{
$this->context->smarty->assign('link_view_all_comment', $this->module->getLink('blog',array('id_post' => $postObj->id,'all_comment'=>1)).'#blog-comments-list');
}
$comments= Ets_blog_comment::getCommentsWithFilter(' AND bc.approved = 1 AND bc.id_post='.(int)$postObj->id,' bc.id_comment desc, ',$cstart,$climit);
if($comments)
foreach($comments as &$comment)
$comment['reply'] = false;
$this->context->smarty->assign(
array(
'hasLoggedIn' => $this->context->customer->logged,
'allowGuestsComments' => true,
'blog_post' => $post,
'show_tags' => false,
'show_date' => true,
'show_categories' => true,
'show_author' => true,
'blog_errors' => $this->errors,
'blog_success' => $this->_success,
'display_desc' => true,
'date_format' =>$this->context->language->date_format_lite,
'blog_layout' => Tools::strtolower(Configuration::get('ETS_BLOG_LAYOUT')),
'breadcrumb' => $this->module->is17 ? $this->module->getBreadCrumb() : false,
'image_folder' => _PS_ETS_BLOG_IMG_,
'allow_rating' => true,
'report_url' => $this->module->getLink('report'),
'default_rating' => 5,
'everage_rating' => $postObj->getAvgRating(),
'total_review' => $postObj->getTotalReviews(),
'allowComments' => true,
'comments' => $comments,
'reportedComments' =>$this->context->cookie->ets_blog_reported_comments ? @unserialize($this->context->cookie->ets_blog_reported_comments) : false,
'id_lang'=> $this->context->language->id,
'blog_related_posts_type'=>'carousel',
'text_gdpr' => $this->module->l('I agree with the use of cookie and personal data according to EU GDPR','blog'),
)
);
return $this->module->display($this->module->name,'single_post.tpl');
}
else
{
header("HTTP/1.0 404 Not Found");
$this->context->smarty->assign(
array(
'blog_post' => false
));
}
}
else
return $this->displayListPosts();
}
public function displayListPosts(){
$params = array('page'=>"_page_");
$filter = ' AND p.enabled =1';
$sort ='';
$id_category = (int)trim(Tools::getValue('id_category'));
$year = (int)Tools::getValue('year');
$month = (int)Tools::getValue('month');
$latest = Tools::getValue('latest');
if($id_category && $this->module->friendly && (Tools::strpos($_SERVER['REQUEST_URI'],'category_url_alias') !==false || Tools::strpos($_SERVER['REQUEST_URI'],'url_alias')!==false))
{
Tools::redirect($this->module->getLink('blog',array('id_category'=>$id_category)));
}
if($id_category)
{
if(($category = new Ets_blog_category($id_category,$this->context->language->id)) && Validate::isLoadedObject($category) && $category->enabled)
{
$urlAlias = Tools::strtolower(trim(Tools::getValue('url_alias',Tools::getValue('category_url_alias'))));
if($urlAlias && $urlAlias != Tools::strtolower(trim($category->url_alias)))
Tools::redirect($this->module->getLink('blog',array('id_category' => $id_category)));
}
$filter .= " AND pc.id_category='".(int)$id_category."'";
$params['id_category'] = (int)trim($id_category);
}
elseif($latest=='true')
{
$params['latest'] = 'true';
$sort = 'p.id_post DESC, ';
}
if(($id_author = (int)Tools::getValue('id_author')))
{
$params['id_author'] = $id_author;
$filter .= " AND p.added_by = ".$id_author;
$employee = $this->getAuthorById($id_author);
}
if($month && $year)
{
$filter .=' AND MONTH(p.date_add) ="'.pSQL($month).'" AND YEAR(p.date_add)="'.pSQL($year).'"';
$params['year']=$year;
$params['month']=$month;
}
if($year)
{
$filter .=' AND YEAR(p.date_add)="'.pSQL($year).'"';
$params['year']=$year;
}
elseif(($search = urldecode(trim(Tools::getValue('search'))))!='' && Validate::isCleanHtml($search))
{
$filter .= " AND (pl.title like '%".pSQL($search)."%' OR pl.description like '%".pSQL($search)."%' OR pl.short_description LIKE '%".pSQL($search)."%')";
$params['search'] = $search;
}
$page = (int)Tools::getValue('page');
if($page <1)
$page=1;
$totalRecords = (int)Ets_blog_post::countPostsWithFilter($filter);
$paggination = new Ets_blog_paggination_class();
$paggination->total = $totalRecords;
$paggination->url = $this->module->getLink('blog', $params);
$paggination->limit = 10;
$totalPages = ceil($totalRecords / $paggination->limit);
if($page > $totalPages)
$page = $totalPages;
$paggination->page = $page;
$start = $paggination->limit * ($page - 1);
if($start < 0)
$start = 0;
$posts = Ets_blog_post::getPostsWithFilter($filter, $sort, $start, $paggination->limit);
if($posts)
{
foreach($posts as &$post)
{
$post['id_category'] = Ets_blog_post::getCategoriesStrByIdPost($post['id_post']);
if($post['thumb'])
$post['thumb'] = $this->context->link->getMediaLink(_PS_ETS_BLOG_IMG_.'post/'.$post['thumb']);
if($post['image'])
$post['image'] = $this->context->link->getMediaLink(_PS_ETS_BLOG_IMG_.'post/'.$post['image']);
$post['link'] = $this->module->getLink('blog',array('id_post'=>$post['id_post']));
$post['categories'] = Ets_blog_post::getCategoriesByIdPost($post['id_post'],false,true);
$post['everage_rating'] = Ets_blog_post::getAvgRatingById($post['id_post']);
$post['total_review'] = Ets_blog_post::getTotalReviewsById($post['id_post']);
}
}
$category = (int)$id_category ? (($cat = Ets_blog_category::getCategoryById((int)$id_category)) ? $cat : array('enabled' => false)) : false;
if($category && !$category['enabled'])
header("HTTP/1.0 404 Not Found");
$search = Tools::getValue('search');
$this->context->smarty->assign(
array(
'blog_posts' => $posts,
'blog_paggination' => $paggination->render(),
'blog_category' => $category,
'blog_search' => trim($search)!='' && Validate::isCleanHtml($search) ? urldecode(trim($search)) : false,
'blog_latest' => trim($latest)=='true' ? true : false,
'author' => isset($employee) && $employee ? $employee:false,
'month' => $month && $year ? $year.' - '.$this->module->getMonthName($month) :false,
'year' => $year ? $year :false,
'allow_rating'=> true,
'show_date' => true,
'show_views' => true,
'is_main_page' => !$month && !$year && !$category && !$latest && !$search ? true : false,
'breadcrumb' => $this->module->getBreadCrumb(),
'date_format' => $this->context->language->date_format_lite,
'show_categories' => true ,
'blog_layout' => Tools::strtolower(Configuration::get('ETS_BLOG_LAYOUT')),
)
);
return $this->module->display($this->module->name, 'blog_list.tpl');
}
private function getAuthorById($id_author)
{
$employee = new Employee($id_author);
$params=array();
$author = array();
$params['id_author'] = $id_author;
$author['name']=trim(Tools::strtolower($employee->firstname.' '.$employee->lastname));
$params['alias'] = str_replace(' ','-',$author['name']);
$author['alias'] = $params['alias'];
$author['author_link']= $this->module->getLink('blog',$params);
$author['avata']= '';
return $author;
}
public function submitCommentPost()
{
$subject = Tools::getValue('subject');
$comment = Tools::getValue('comment');
$id_post = (int)Tools::getValue('id_post');
if(!$subject)
$this->errors[] = $this->module->l('Subject is required','blog');
else
{
if(Tools::strlen($subject) < 10)
$this->errors[] = $this->module->l('Subject needs to be at least 10 characters','blog');
if(Tools::strlen($subject) >300)
$this->errors[] = $this->module->l('Subject cannot be longer than 300 characters','blog');
if(!Validate::isCleanHtml($subject,false))
$this->errors[] = $this->module->l('Subject is not valid','blog');
}
if(!$comment)
$this->errors[] = $this->module->l('Comment is required','blog');
else
{
if(Tools::strlen($comment) < 20)
$this->errors[] = $this->module->l('Comment needs to be at least 20 characters','blog');
if(!Validate::isCleanHtml($comment,false))
$this->errors[] = $this->module->l('Comment is not valid','blog');
if(Tools::strlen($comment) >2000)
$this->errors[] = $this->module->l('Comment cannot be longer than 2000 characters','blog');
}
if(!(int)$this->context->cookie->id_customer)
{
$name_customer = Tools::getValue('name_customer');
if(!$name_customer)
$this->errors[] = $this->module->l('Name is required','blog');
elseif($name_customer && !Validate::isCleanHtml($name_customer))
$this->errors[] = $this->module->l('Name is not valid');
$email_customer = Tools::getValue('email_customer');
if(!$email_customer)
$this->errors[] = $this->module->l('Email is rerequired','blog');
elseif(!Validate::isEmail($email_customer))
$this->errors[] = $this->module->l('Email is not valid','blog');
}
$rating = Tools::getValue('rating');
if(!$rating)
$this->errors[] = $this->module->l('Rating is required','blog');
elseif(!Validate::isInt($rating))
$this->errors[] = $this->module->l('Rating is not valid','blog');
elseif($rating > 5 || $rating < 1)
$this->errors[] = $this->module->l('Rating needs to be from 1 to 5','blog');
if(!$this->errors)
{
$commentObj = new Ets_blog_comment();
$commentObj->approved = (int)Configuration::get('ETS_BLOG_COMMENT_AUTO_APPROVED') ? 1 : 0;
$commentObj->subject = $subject;
$commentObj->comment = $comment;
$commentObj->id_post = $id_post;
$commentObj->viewed =0;
if((int)$this->context->cookie->id_customer)
{
$commentObj->id_user = (int)$this->context->cookie->id_customer;
$commentObj->name = $this->context->customer->firstname.' '.$this->context->customer->lastname;
$commentObj->email = $this->context->customer->email;
}
else
{
$commentObj->name = $name_customer;
$commentObj->email = $email_customer;
}
$commentObj->rating = (int)$rating;
$commentObj->reported = 1;
if($commentObj->add())
{
$this->context->cookie->_success = $this->module->l('Comment has been submitted ','blog');
if($commentObj->approved)
$this->context->cookie->_success .= $this->module->l('and approved','blog');
else
$this->context->cookie->_success .= $this->module->l('and is waiting for approval','blog');
Tools::redirect($this->module->getLink('blog',array('id_post'=>$commentObj->id_post)));
}
}
else
{
$this->context->smarty->assign(
Tools::getAllValues()
);
}
}
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* Copyright ETS Software Technology Co., Ltd
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 website only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future.
*
* @author ETS Software Technology Co., Ltd
* @copyright ETS Software Technology Co., Ltd
* @license Valid for 1 website (or project) for each purchase of license
*/
if (!defined('_PS_VERSION_'))
exit;
class Ets_blogCategoryModuleFrontController extends ModuleFrontController
{
public $display_column_left = false;
public $display_column_right = false;
public $errors= array();
public $success = '';
public function __construct()
{
parent::__construct();
}
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
$this->module->setMetas();
$this->context->smarty->assign(
array(
'blog_content' => $this->_initContent(),
'blog_left_sidebar' => $this->module->hookDisplayLeftColumn(),
)
);
if($this->module->is17)
$this->setTemplate('module:ets_blog/views/templates/front/blog.tpl');
}
public function _initContent()
{
$categoryData = $this->getCategories();
if(isset($categoryData['categories']) && $categoryData['categories'])
{
foreach($categoryData['categories'] as &$category)
{
$category['link']=$this->module->getLink('blog',array('id_category'=>$category['id_category']));
if($category['image'])
$category['image'] = $this->context->link->getMediaLink(_PS_ETS_BLOG_IMG_.'category/'.$category['image']);
if($category['thumb'])
$category['thumb'] = $this->context->link->getMediaLink(_PS_ETS_BLOG_IMG_.'category/'.$category['thumb']);
$category['count_posts'] =(int)Ets_blog_post::countPostsWithFilter(' AND pc.id_category="'.(int)$category['id_category'].'" AND p.enabled=1');
$category['sub_categogires'] = Ets_blog_category::getCategoriesWithFilter(' AND c.enabled=1',false,false,false,$category['id_category']);
if($category['sub_categogires'])
{
foreach($category['sub_categogires'] as &$sub)
{
$sub['link'] = $this->module->getLink('blog',array('id_category'=>$sub['id_category']));
}
}
}
}
$this->context->smarty->assign(
array(
'blog_categories' => $categoryData['categories'],
'blog_paggination' => $categoryData['paggination'],
'path' => $this->module->getBreadCrumb(),
'blog_layout' => Tools::strtolower(Configuration::get('ETS_BLOG_LAYOUT')),
'breadcrumb' => $this->module->is17 ? $this->module->getBreadCrumb() : false,
'show_date' => (int)Configuration::get('ETS_BLOG_SHOW_POST_DATE') ? true : false,
'date_format' => $this->context->language->date_format_lite,
'image_folder' => _PS_ETS_BLOG_IMG_.'category/',
)
);
return $this->module->display($this->module->name,'list-category.tpl');
}
public function getCategories()
{
$filter = ' AND c.enabled = 1 AND id_parent=0';
$sort = ' c.sort_order asc, c.id_category asc, ';
$page = (int)Tools::getValue('page');
if($page < 1)
$page = 1;
$totalRecords = (int)Ets_blog_category::countCategoriesWithFilter($filter);
$paggination = new Ets_blog_paggination_class();
$paggination->total = $totalRecords;
$paggination->url = $this->module->getLink('category', array('page'=>"_page_"));
$paggination->limit = 8;
$totalPages = ceil($totalRecords / $paggination->limit);
if($page > $totalPages)
$page = $totalPages;
$paggination->page = $page;
$start = $paggination->limit * ($page - 1);
if($start < 0)
$start = 0;
$categories = Ets_blog_category::getCategoriesWithFilter($filter, $sort, $start, $paggination->limit);
return array(
'categories' => $categories ,
'paggination' => $paggination->render()
);
}
}

View File

@@ -0,0 +1,361 @@
<?php
/**
* Copyright ETS Software Technology Co., Ltd
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 website only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future.
*
* @author ETS Software Technology Co., Ltd
* @copyright ETS Software Technology Co., Ltd
* @license Valid for 1 website (or project) for each purchase of license
*/
if (!defined('_PS_VERSION_'))
exit;
class Ets_blogcommentsModuleFrontController extends ModuleFrontController
{
public $display_column_left = false;
public $display_column_right = false;
public $_errros= array();
public $_sussecfull;
public function __construct()
{
parent::__construct();
$this->display_column_right = false;
$this->display_column_left = false;
}
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
//$this->module->setMetas();
if (!$this->context->customer->isLogged())
{
Tools::redirect('index.php?controller=authentication');
}
if(Tools::isSubmit('submitComment') || Tools::isSubmit('submitCommentStay'))
$this->_saveComment();
if(Tools::isSubmit('del') && ($id_comment=(int)Tools::getValue('id_comment')) && ($comment = new Ets_blog_comment($id_comment)))
{
if($comment->id_user == $this->context->customer->id)
{
$comment->delete();
if(Tools::isSubmit('ajax'))
{
die(
json_encode(
array(
'success' => $this->module->l('You have just deleted the comment successfully','comments'),
)
)
);
}
else
Tools::redirectLink($this->context->link->getModuleLink($this->module->name,'comments',array('deletedcomment'=>1)));
}
else
{
if(Tools::isSubmit('ajax'))
{
die(
json_encode(
array(
'error' => $this->module->l('Sorry, you do not have permission','comments'),
)
)
);
}
else
$this->_errros[]=$this->module->l('Sorry, you do not have permission','comments');
}
}
if(Tools::isSubmit('deletedcomment'))
$this->_sussecfull = $this->module->l('You have just deleted the comment successfully','comments');
if(Tools::isSubmit('updateComment'))
$this->_sussecfull = $this->module->l('Comment updated','comments');
$this->context->smarty->assign(
array(
'html_content' => $this->renderComments(),
'errors_html'=>$this->_errros ? $this->module->displayError($this->_errros) : false,
'sucsecfull_html' => $this->_sussecfull ? $this->module->displayConfirmation($this->_sussecfull):'',
'breadcrumb' => $this->module->is17 ? $this->getBreadCrumb() : false,
'path' => $this->getBreadCrumb(),
)
);
$this->setTemplate('module:ets_blog/views/templates/front/management_comments.tpl');
}
public function _saveComment()
{
$id_comment = (int)Tools::getValue('id_comment');
$commentObj= new Ets_blog_comment($id_comment);
if(!Validate::isLoadedObject($commentObj) || $commentObj->id_user!=$this->context->customer->id)
$this->_errros[] = $this->module->l('Comment is not valid');
if(!($subject = Tools::getValue('subject')))
$this->_errros[]= $this->module->l('Subject is required','comments');
elseif(!Validate::isCleanHtml($subject))
$this->_errros[]= $this->module->l('Subject is not valid','comments');
else
$commentObj->subject = $subject;
if(!($comment = Tools::getValue('comment')))
$this->_errros[] = $this->module->l('Comment is required','comments');
elseif(Tools::strlen($comment)<20)
$this->_errros[]=$this->module->l('Comment need to be at least 20 characters','comments');
elseif(!Validate::isCleanHtml($comment,true))
$this->_errros[] = $this->module->l('Comment is not valid','comments');
else
$commentObj->comment = Tools::getValue('comment');
$rating = (int)Tools::getValue('rating');
if($rating<1 || $rating > 5)
$this->_errros[] = $this->module->l('Rating is not valid','comments');
else
$commentObj->rating = $rating;
if(!$this->_errros)
{
$commentObj->update();
if(Tools::isSubmit('submitComment'))
Tools::redirectLink($this->context->link->getModuleLink($this->module->name,'comments',array('updateComment'=>1)));
else
$this->_sussecfull = $this->module->l('Comment updated','comments');
}
}
public function getBreadCrumb()
{
$nodes=array();
$nodes[] = array(
'title' => $this->module->l('Home','comment'),
'url' => $this->context->link->getPageLink('index', true),
);
$nodes[] = array(
'title' => $this->module->l('Your account','comments'),
'url' => $this->context->link->getPageLink('my-account'),
);
$nodes[] = array(
'title' => $this->module->l('My blog comments','comments'),
'url' => $this->context->link->getModuleLink('ets_blog','comments'),
);
if($this->module->is17)
return array('links' => $nodes,'count' => count($nodes));
return $this->module->displayBreadcrumb($nodes);
}
public function renderComments()
{
if(Tools::isSubmit('editcomment') && ($id_comment = (int)Tools::getValue('id_comment')))
{
$commentObj = new Ets_blog_comment($id_comment);
if($commentObj->id_user!=$this->context->customer->id)
{
return $this->module->displayError($this->module->l('Comment is not valid','comments'));
}
else
{
$id_comment = (int)Tools::getValue('id_comment');
$this->context->smarty->assign(
array(
'ets_comment'=> $commentObj,
'link_back_list' => $this->context->link->getModuleLink($this->module->name,'comments'),
'edit_approved' => false,
)
);
return $this->module->display($this->module->name,'form_comment_customer.tpl');
}
}
$fields_list = array(
'id_comment' => array(
'title' => $this->module->l('Id','comments'),
'width' => 40,
'type' => 'text',
'sort' => true,
'filter' => true,
),
'subject' => array(
'title' => $this->module->l('Subject','comments'),
//'width' => 140,
'type' => 'text',
'sort' => true,
'filter' => true,
),
'rating' => array(
'title' => $this->module->l('Rating','comments'),
//'width' => 100,
'type' => 'select',
'sort' => true,
'filter' => true,
'rating_field' => true,
'filter_list' => array(
'id_option' => 'rating',
'value' => 'stars',
'list' => array(
0 => array(
'rating' => 0,
'stars' => $this->module->l('No reviews','comments')
),
1 => array(
'rating' => 1,
'stars' => $this->module->l('1 star','comments')
),
2 => array(
'rating' => 2,
'stars' => $this->module->l('2 stars','comments')
),
3 => array(
'rating' => 3,
'stars' =>$this->module->l('3 stars','comments')
),
4 => array(
'rating' => 4,
'stars' => $this->module->l('4 stars','comments')
),
5 => array(
'rating' => 5,
'stars' => $this->module->l('5 stars','comments')
),
)
)
),
'title'=>array(
'title'=>$this->module->l('Blog post','comments'),
'type' => 'text',
'filter' => true,
'strip_tag'=>false,
),
'approved' => array(
'title' => $this->module->l('Status','comments'),
'type' => 'active',
'sort' => true,
'filter' => true,
'strip_tag' => false,
'filter_list' => array(
'id_option' => 'enabled',
'value' => 'title',
'list' => array(
0 => array(
'enabled' => 1,
'title' => $this->module->l('Approved','comments')
),
1 => array(
'enabled' => 0,
'title' => $this->module->l('Pending','comments')
)
)
)
),
);
//Filter
$filter = " AND bc.id_user='".(int)$this->context->customer->id."'";
$show_reset = false;
if(($id = trim(Tools::getValue('id_comment')))!='' && Validate::isCleanHtml($id))
{
$filter .= " AND bc.id_comment = ".(int)$id;
$show_reset = true;
}
if(($com = trim(Tools::getValue('comment')))!='' && Validate::isCleanHtml($com))
{
$filter .= " AND bc.comment like '%".pSQL($com)."%'";
$show_reset = true;
}
if(($subject = trim(Tools::getValue('subject')))!='' && Validate::isCleanHtml($subject))
{
$filter .= " AND (bc.subject LIKE '%".pSQL($subject)."%' OR bc.comment LIKE '%".pSQL($subject)."%')";
$show_reset = true;
}
if(($rating = trim(Tools::getValue('rating')))!='' && Validate::isCleanHtml($rating))
{
$filter .= " AND bc.rating = ".(int)$rating;
$show_reset = true;
}
if(($name = trim(Tools::getValue('name')))!='' && Validate::isCleanHtml($name))
{
$filter .= " AND bc.name like '%".pSQL($name)."%'";
$show_reset = true;
}
if(($approved = trim(Tools::getValue('approved')))!='' && Validate::isCleanHtml($approved))
{
$filter .= " AND bc.approved = ".(int)$approved;
$show_reset = true;
}
if(($reported = trim(Tools::getValue('reported')))!='' && Validate::isCleanHtml($reported))
{
$filter .= " AND bc.reported = ".(int)$reported;
$show_reset = true;
}
if(($title = trim(Tools::getValue('title')))!='' && Validate::isCleanHtml($title))
{
$filter .= " AND pl.title like '%".pSQL($title)."%'";
$show_reset = true;
}
//Sort
$sort_post = Tools::strtolower(Tools::getValue('sort'));
$sort_type = Tools::strtolower(Tools::getValue('sort_type','desc'));
if(!in_array($sort_type,array('desc','asc')))
$sort_type ='desc';
if($sort_post && isset($fields_list[$sort_post]))
{
$sort = $sort_post." ".($sort_type=='asc' ? ' ASC ' :' DESC ')." , ";
}
else
$sort = 'bc.id_comment desc,';
//Paggination
$page = (int)Tools::getValue('page');
if($page <1)
$page=1;
$totalRecords = (int)Ets_blog_comment::countCommentsWithFilter($filter,false);
$paggination = new Ets_blog_paggination_class();
$paggination->total = $totalRecords;
$paggination->url = $this->context->link->getModuleLink($this->module->name, 'comments',array('list'=>1)).'&page=_page_'.$this->module->getUrlExtra($fields_list);
$paggination->limit = (int)Tools::getValue('paginator_comment_select_limit',20);
$paggination->name ='comment';
$totalPages = ceil($totalRecords / $paggination->limit);
if($page > $totalPages)
$page = $totalPages;
$paggination->page = $page;
$start = $paggination->limit * ($page - 1);
if($start < 0)
$start = 0;
$comments = Ets_blog_comment::getCommentsWithFilter($filter, $sort, $start, $paggination->limit,false);
if($comments)
{
foreach($comments as &$comment)
{
$comment['view_url'] = $this->module->getLink('blog', array('id_post' => $comment['id_post'])).'#blog_comment_line_'.$comment['id_comment'];
$comment['title'] = '<a target="_blank" href="'.$this->module->getLink('blog',array('id_post'=>$comment['id_post'])).'" title="'.$comment['title'].'">'.$comment['title'].'</a>';
$comment['action_edit_approved'] = false;
}
}
$paggination->text = $this->module->l('Showing {start} to {end} of {total} ({pages} Pages)','comments');
$paggination->style_links = $this->module->l('links','comments');
$paggination->style_results = $this->module->l('results','comments');
$listData = array(
'name' => 'comment',
'actions' => array('view','edit','delete'),
'currentIndex' => $this->context->link->getModuleLink($this->module->name, 'comments',array('list'=>1)).($paggination->limit!=20 ? '&paginator_comment_select_limit='.$paggination->limit:''),
'postIndex' => $this->context->link->getModuleLink($this->module->name, 'comments',array('list'=>1)),
'identifier' => 'id_comment',
'show_toolbar' => true,
'show_action' => true,
'title' => $this->module->l('Comments','comments'),
'fields_list' => $fields_list,
'field_values' => $comments,
'paggination' => $paggination->render(),
'filter_params' => $this->module->getFilterParams($fields_list),
'show_reset' => $show_reset,
'totalRecords' => $totalRecords,
'show_add_new' => false,
'sort'=> $sort_post ?: 'id_comment',
'sort_type'=> $sort_type,
);
return $this->module->renderList($listData);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright ETS Software Technology Co., Ltd
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 website only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future.
*
* @author ETS Software Technology Co., Ltd
* @copyright ETS Software Technology Co., Ltd
* @license Valid for 1 website (or project) for each purchase of license
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;