Example #1
0
 public function postProcess()
 {
     $errors = array();
     $confirmation = '1';
     if (Tools::isSubmit('submitNewComment') && Tools::getValue('id_simpleblog_post')) {
         $SimpleBlogPost = $this->SimpleBlogPost;
         if (Configuration::get('PH_BLOG_COMMENT_ALLOW_GUEST') && Configuration::get('PH_BLOG_COMMENTS_RECAPTCHA')) {
             if (!class_exists('ReCaptcha') && file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/assets/recaptchalib.php')) {
                 require_once _PS_MODULE_DIR_ . 'ph_simpleblog/assets/recaptchalib.php';
             }
             $secret = Configuration::get('PH_BLOG_COMMENTS_RECAPTCHA_SECRET_KEY');
             $response = null;
             if (!class_exists('ReCaptcha')) {
                 die('Sorry, you want to use reCAPTCHA but class to handle this doesn\'t exists');
             }
             $reCaptcha = new ReCaptcha($secret);
             if (Tools::getValue('g-recaptcha-response')) {
                 $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], Tools::getValue('g-recaptcha-response'));
             }
             if ($response == null) {
                 $errors[] = $this->module->l('Please provide valid reCAPTCHA value', 'single');
             }
         }
         if (Tools::getValue('comment_content') && Validate::isGenericName(Tools::getValue('comment_content'))) {
             $comment_content = Tools::getValue('comment_content');
         } else {
             $errors[] = $this->module->l('Please write something and remember that HTML is not allowed in comment content.', 'single');
         }
         $customer_name = Tools::getValue('customer_name');
         if (!Validate::isGenericName($customer_name)) {
             $errors[] = $this->module->l('Please provide valid name', 'single');
         }
         if (!Validate::isInt(Tools::getValue('id_parent'))) {
             die('FATAL ERROR [2]');
         } else {
             $id_parent = Tools::getValue('id_parent');
         }
         $ip_address = Tools::getRemoteAddr();
         if (sizeof($errors)) {
             $this->errors = $errors;
         } else {
             $comment = new SimpleBlogComment();
             $comment->id_simpleblog_post = (int) Tools::getValue('id_simpleblog_post');
             $comment->id_parent = $id_parent;
             $comment->id_customer = (int) $this->context->customer->id ? (int) $this->context->customer->id : 0;
             $comment->id_guest = (int) $this->context->customer->id_guest ? (int) $this->context->customer->id_guest : 0;
             $comment->name = $customer_name;
             $comment->email = isset($this->context->customer->email) ? $this->context->customer->email : null;
             $comment->comment = $comment_content;
             $comment->active = Configuration::get('PH_BLOG_COMMENT_AUTO_APPROVAL') ? 1 : 0;
             $comment->ip = Tools::getRemoteAddr();
             if ($comment->add()) {
                 if (!Configuration::get('PH_BLOG_COMMENT_AUTO_APPROVAL')) {
                     $confirmation = '2';
                 }
                 $link = $this->context->link->getModuleLink('ph_simpleblog', 'single', array('confirmation' => $confirmation, 'rewrite' => $SimpleBlogPost->link_rewrite, 'sb_category' => $SimpleBlogPost->category_rewrite));
                 if (Configuration::get('PH_BLOG_COMMENT_NOTIFICATIONS')) {
                     $toName = strval(Configuration::get('PS_SHOP_NAME'));
                     $fromName = strval(Configuration::get('PS_SHOP_NAME'));
                     $to = Configuration::get('PH_BLOG_COMMENT_NOTIFY_EMAIL');
                     $from = Configuration::get('PS_SHOP_EMAIL');
                     $customer = $this->context->customer;
                     if ($this->context->customer->isLogged()) {
                         $lastname = $this->context->customer->lastname;
                         $firstname = $this->context->customer->firstname;
                     } else {
                         $lastname = '';
                         $firstname = $customer_name;
                     }
                     Mail::Send($this->context->language->id, 'new_comment', sprintf(Mail::l('New comment on %1$s blog for article: %2$s', $this->context->language->id), $toName, $SimpleBlogPost->title), array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{post_title}' => $SimpleBlogPost->title, '{post_link}' => $SimpleBlogPost->url, '{comment_content}' => $comment_content), $to, $toName, $from, $fromName, null, null, _PS_MODULE_DIR_ . 'ph_simpleblog/mails/');
                 }
                 Tools::redirect($link);
             } else {
                 $this->errors = $this->module->l('Something went wrong! Comment can not be added!', 'single');
             }
         }
     }
     return parent::postProcess();
 }
Example #2
0
 public function __construct($id_simpleblog_post = null, $id_lang = null, $id_shop = null)
 {
     parent::__construct($id_simpleblog_post, $id_lang, $id_shop);
     $category = new SimpleBlogCategory($this->id_simpleblog_category, $id_lang);
     $this->category = $category->name;
     $this->category_rewrite = $category->link_rewrite;
     $this->url = self::getLink($this->link_rewrite, $this->category_rewrite, $id_lang);
     $this->category_url = SimpleBlogCategory::getLink($category->link_rewrite, $id_lang);
     if ($category->id_parent > 0) {
         $parent = new SimpleBlogCategory($category->id_parent, $id_lang);
         $this->parent_category = $parent;
     }
     if (file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/covers/' . $this->id_simpleblog_post . '.' . $this->cover)) {
         $this->banner = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $this->id_simpleblog_post . '.' . $this->cover;
         $this->banner_thumb = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $this->id_simpleblog_post . '-thumb.' . $this->cover;
         $this->banner_wide = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $this->id_simpleblog_post . '-wide.' . $this->cover;
     }
     if (file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/featured/' . $this->id_simpleblog_post . '.' . $this->featured)) {
         $this->featured_image = _MODULE_DIR_ . 'ph_simpleblog/featured/' . $this->id_simpleblog_post . '.' . $this->featured;
     }
     if ($this->id) {
         $tags = SimpleBlogTag::getPostTags((int) $this->id);
         $this->tags = $tags;
         if (isset($tags) && isset($tags[$id_lang])) {
             $this->tags_list = $tags[$id_lang];
         }
         $this->comments = SimpleBlogComment::getCommentsCount((int) $this->id);
         $this->post_type = SimpleBlogPostType::getSlugById((int) $this->id_simpleblog_post_type);
         if ($this->post_type == 'gallery') {
             $this->gallery = SimpleBlogPostImage::getAllById((int) $this->id);
         }
     }
 }