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(); }