public function displayPost() { $id_lang = $this->context->language->id; $id_shop = $this->context->shop->id; if (is_null($this->id_post) || !is_numeric($this->id_post)) { return $this->displayList(); } $post = new BlogPost($this->id_post); if ($post->status == 'published' && $post->isAssociatedToShop($id_shop)) { //comment submit if (Tools::isSubmit('submitMessage') && $this->conf['comment_active'] && $post->allow_comments) { $comment = new BlogComment(); try { $message = trim(strip_tags(Tools::getValue('blog_comment'))); $comment->id_blog_post = $this->id_post; $comment->customer_name = pSQL(Tools::getValue('customer_name')); if ($message == '' || strlen($comment->customer_name) < (int) $this->conf['comment_name_min_length']) { throw new Exception('error_input'); } if (!Validate::isMessage($message) || !Validate::isGenericName($comment->customer_name)) { throw new Exception('error_input_invalid'); } $comment->content = $message; $id_customer = (int) $this->context->customer->id; $id_guest = (int) $this->context->cookie->id_guest; if (!$this->conf['comment_guest'] && empty($id_customer)) { throw new Exception('error_guest'); } //get last comment from customer $customerComment = BlogComment::getByCustomer($this->id_post, $id_customer, true, $id_guest); $comment->id_customer = $id_customer; $comment->id_guest = $id_guest; $comment->id_lang = $id_lang; $comment->id_shop = $id_shop; if ($customerComment['content'] == $comment->content) { throw new Exception('error_already'); } if ($customerComment && strtotime($customerComment['date_add']) + (int) $this->conf['comment_min_time'] > time()) { throw new Exception('error_delay'); } $comment->active = $this->conf['comment_moderate'] ? 0 : 1; $comment->save(); $this->context->smarty->assign('psblog_confirmation', true); } catch (Exception $e) { $comment->content = Tools::getValue('blog_comment'); $comment->customer_name = Tools::getValue('customer_name'); $this->context->smarty->assign('psblog_error', $e->getMessage()); $this->context->smarty->assign('comment', $comment); } } /* * * view article ** */ $images = $post->getImages(false); $categories = $post->listCategories(true); $products = $post->getProducts(true); $related = $post->listRelated(true, true); if (is_array($related) && count($related) > 0) { $i = 0; foreach ($related as $val) { $related[$i]['link'] = BlogPost::linkPost($val['id_blog_post'], $val['link_rewrite'], $val['id_lang']); $i++; } } if (is_array($products) && count($products) > 0) { $i = 0; foreach ($products as $p) { $product = new Product($p['id_product'], false, $id_lang); $products[$i]['link'] = $this->context->link->getProductLink($product); $products[$i]['imageLink'] = $this->context->link->getImageLink($p['link_rewrite'], $p['id_product'] . '-' . $p['id_image'], $this->conf['product_img_format']); $i++; } } /* SEO metas */ $curr_meta_title = $this->context->smarty->getTemplateVars('meta_title'); $this->context->smarty->assign(array('meta_title' => $curr_meta_title . ' - ' . $post->title, 'meta_description' => $post->meta_description, 'meta_keywords' => $post->meta_keywords)); if ($this->conf['view_display_popin'] == 1) { $this->addjqueryPlugin('fancybox'); $this->addJS($this->module->getPathUri() . 'js/popin.js'); } if ($categories) { $i = 0; foreach ($categories as $cat) { $categories[$i]['link'] = BlogCategory::linkCategory($cat['id_blog_category'], $cat['link_rewrite'], $cat['id_lang']); $i++; } } $comments = $post->getComments(); $this->context->smarty->assign(array('post_images' => $images, 'post_products' => $products, 'post_related' => $related, 'post_categories' => $categories, 'post_comments' => $comments)); } else { $post->status = 'suspended'; } $this->context->smarty->assign('post', $post); $this->setTemplate('view.tpl'); }