Created
August 1, 2017 03:56
-
-
Save iamrobert/9ad2b5c2f457e31cf5e2bc21abdc9d73 to your computer and use it in GitHub Desktop.
Prestashop | Add Category Links to SmartBlog for posts.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//modules/smartblog/controllers/front/details.php | |
//Also need to add in details.php: | |
// {foreach from=$postcategory item=post} | |
// {include file="./item_category_loop.tpl" postcategory=$postcategory} | |
// {/foreach} | |
<?php | |
include_once(dirname(__FILE__).'/../../classes/controllers/FrontController.php'); | |
class smartblogDetailsModuleFrontController extends smartblogModuleFrontController | |
{ | |
public $ssl = false; | |
public $_report = ''; | |
private $_postsObject; | |
public function init() | |
{ | |
parent::init(); | |
} | |
public function initContent() | |
{ | |
parent::initContent(); | |
$id_post = Tools::getValue('id_post'); | |
Hook::exec('actionsbsingle', array('id_post' => $id_post)); | |
$blogcomment = new Blogcomment(); | |
$SmartBlogPost = new SmartBlogPost(); | |
$BlogCategory = new BlogCategory(); | |
$id_lang = $this->context->language->id; | |
$id_lang_defaut = Configuration::get('PS_LANG_DEFAULT'); | |
$post = $SmartBlogPost->getPost($id_post,$id_lang); | |
$tags = $SmartBlogPost->getProductTags($id_post); | |
$comment = $blogcomment->getComment($id_post); | |
$countcomment = $blogcomment->getToltalComment($id_post); | |
$id_cate = $post['id_category']; | |
// | |
$category_status = ''; | |
$totalpages = ''; | |
$cat_image = 'no'; | |
$categoryinfo = ''; | |
$title_category = ''; | |
$cat_link_rewrite = ''; | |
$blogcomment = new Blogcomment(); | |
$SmartBlogPost = new SmartBlogPost(); | |
$BlogCategory = new BlogCategory(); | |
$BlogPostCategory = new BlogPostCategory(); | |
$id_category = Tools::getvalue('id_category'); | |
$posts_per_page = Configuration::get('smartpostperpage'); | |
$limit_start = 0; | |
$limit = $posts_per_page; | |
if(!$id_category = Tools::getvalue('id_category')) | |
{ | |
$total = $SmartBlogPost->getToltal($this->context->language->id); | |
}else{ | |
$total = $SmartBlogPost->getToltalByCategory($this->context->language->id,$id_category); | |
Hook::exec('actionsbcat', array('id_category' => Tools::getvalue('id_category'))); | |
} | |
// if($total != '' || $total != 0) | |
// $totalpages = ceil($total/$posts_per_page); | |
// if((boolean)Tools::getValue('page')){ | |
// $c = Tools::getValue('page'); | |
// $limit_start = $posts_per_page * ($c - 1); | |
// } | |
if(!$id_category = Tools::getvalue('id_category')) | |
{ | |
$allNews = $SmartBlogPost->getAllPost($this->context->language->id,$limit_start,$limit); | |
}else{ | |
$categoryinfo = $BlogCategory->getNameCategory($id_category); | |
$title_category = $categoryinfo[0]['meta_title']; | |
$category_status = $categoryinfo[0]['active']; | |
$cat_link_rewrite = $categoryinfo[0]['link_rewrite']; | |
if($category_status == 1){ | |
$allNews = $BlogPostCategory->getToltalByCategory($this->context->language->id,$id_category,$limit_start,$limit); | |
} | |
elseif($category_status == 0) | |
{ | |
$allNews = ''; | |
} | |
} | |
// $i = 0; | |
// if(!empty($allNews)){ | |
// foreach($allNews as $item){ | |
// $to[$i] = $blogcomment->getToltalComment($item['id_post']); | |
// $i++; | |
// } | |
// $j = 0; | |
// foreach($to as $item){ | |
// if($item == ''){ | |
// $allNews[$j]['totalcomment'] = 0; | |
// }else{ | |
// $allNews[$j]['totalcomment'] = $item; | |
// } | |
// $j++; | |
// } | |
// } | |
// | |
$title_category = $BlogCategory->getNameCategory($id_cate); | |
if (file_exists(_PS_MODULE_DIR_.'smartblog/images/' . Tools::getValue('id_post') . '.jpg') ) | |
{ | |
$post_img = Tools::getValue('id_post'); | |
}else{ | |
$post_img = 'no'; | |
} | |
SmartBlogPost::postViewed($id_post); | |
$this->context->smarty->assign(array( | |
'post'=>$post, | |
'comments'=>$comment, | |
'tags'=>$tags, | |
'title_category'=>$title_category[0]['meta_title'], | |
'cat_link_rewrite'=>$title_category[0]['link_rewrite'], | |
'meta_title'=>$post['meta_title'], | |
'post_active'=>$post['active'], | |
'content'=>$post['content'], | |
'id_post'=>$post['id_post'], | |
'smartshowauthorstyle'=>Configuration::get('smartshowauthorstyle'), | |
'smartshowauthor'=>Configuration::get('smartshowauthor'), | |
'created'=>$post['created'], | |
'firstname'=>$post['firstname'], | |
'lastname'=>$post['lastname'], | |
'smartcustomcss' => Configuration::get('smartcustomcss'), | |
'smartshownoimg' => Configuration::get('smartshownoimg'), | |
'comment_status'=>$post['comment_status'], | |
'countcomment'=>$countcomment, | |
'post_img'=>$post_img, | |
'_report'=>$this->_report, | |
'id_category'=>$post['id_category'], | |
// | |
'postcategory'=>$allNews, | |
// | |
// | |
)); | |
$this->context->smarty->assign('HOOK_SMART_BLOG_POST_FOOTER', | |
Hook::exec('displaySmartAfterPost')); | |
$this->setTemplate('posts.tpl'); | |
} | |
public function _posts(){ | |
$SmartBlogPost = new SmartBlogPost(); | |
if(Tools::isSubmit('addComment')){ | |
$id_lang = $this->context->language->id; | |
$id_post = Tools::getValue('id_post'); | |
$post = $SmartBlogPost->getPost($id_post,$id_lang); | |
if($post['comment_status'] == 1){ | |
$blogcomment = new Blogcomment(); | |
$name = Tools::getValue('name'); | |
$comment = Tools::getValue('comment'); | |
$mail = Tools::getValue('mail'); | |
if(Tools::getValue('mail') == '') | |
{ | |
$website = '#'; | |
}else{ | |
$website = Tools::getValue('website'); | |
} | |
$id_parent_post = (int)Tools::getValue('id_parent_post'); | |
if(empty($name)){ | |
$this->_report .= '<p class="error">'.$this->module->l('Name is required').'</p>'; | |
} | |
elseif(empty($comment)){ | |
$this->_report .= '<p class="error">'.$this->module->l('Comment is required').'</p>'; | |
} | |
elseif(!filter_var($mail,FILTER_VALIDATE_EMAIL)){ | |
$this->_report .= '<p class="error">'.$this->module->l('E-mail is not valid').'</p>'; | |
} | |
else | |
{ | |
$comments['name'] = $name; | |
$comments['mail'] = $mail; | |
$comments['comment'] = $comment; | |
$comments['website'] = $website; | |
if(!$id_parent_post = Tools::getvalue('comment_parent')) | |
{ | |
$id_parent_post = 0; | |
} | |
$value = Configuration::get('smartacceptcomment'); | |
if(Configuration::get('smartacceptcomment') != '' && Configuration::get('smartacceptcomment') != null){ | |
$value = Configuration::get('smartacceptcomment'); | |
}else{ | |
$value = 0; | |
} | |
$bc = new Blogcomment(); | |
$bc->id_post = (int)$id_post; | |
$bc->name = $name; | |
$bc->email = $mail; | |
$bc->content = $comment; | |
$bc->website = $website; | |
$bc->id_parent = (int)$id_parent_post; | |
$bc->active = (int)$value; | |
if($bc->add()){ | |
$this->_report.='<p class="success">'.$this->module->l('Comment added !').'</p>'; | |
Hook::exec('actionsbpostcomment', array('bc' => $bc)); | |
$this->smartsendMail($name,$mail,$comment); | |
} | |
} | |
} | |
} | |
} | |
private function smartsendMail($sname,$semailAddr,$scomment,$slink = null) | |
{ | |
$name = Tools::stripslashes($sname); | |
$e_body ='You have Received a New Comment In Your Blog Post From '. $name . '. Comment: '.$scomment.' .Your Can reply Here : '.$slink.''; | |
$emailAddr = Tools::stripslashes($semailAddr); | |
$comment = Tools::stripslashes($scomment); | |
$subject = 'New Comment Posted'; | |
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); | |
$to = Configuration::get('PS_SHOP_EMAIL'); | |
$contactMessage = | |
" | |
$comment | |
Name: $name | |
IP: ".((version_compare(_PS_VERSION_, '1.3.0.0', '<'))?$_SERVER['REMOTE_ADDR']:Tools::getRemoteAddr()); | |
if(Mail::Send($id_lang, | |
'contact', | |
$subject, | |
array( | |
'{message}' => nl2br($e_body), | |
'{email}' => $emailAddr, | |
), | |
$to, | |
null, | |
$emailAddr, | |
$name | |
)) | |
return true; | |
} | |
} | |
// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment