Ejemplo n.º 1
0
 public function smartblogrelatedpostsHookdisplaySmartAfterPost($params)
 {
     if (Tools::getvalue('controller') == 'category' || Tools::getvalue('controller') == 'tagpost') {
         return;
     }
     $id_post = pSQL(Tools::getvalue('id_post'));
     if ($id_post == '') {
         $slug = Tools::getvalue('slug');
         $id_post = $this->slug2id($slug);
     }
     if (!$this->isCached('plugins/smartblogrelatedposts.tpl', $this->getCacheId())) {
         $posts = SmartBlogPost::getRelatedPostsById_post($id_post);
         $i = 0;
         foreach ($posts as $i => &$post) {
             $posts[$i]['created'] = Smartblog::displayDate($post['created']);
             $employee = new Employee((int) $post['id_author']);
             $post['lastname'] = $employee->lastname;
             $post['firstname'] = $employee->firstname;
         }
         $this->smarty->assign(array('posts' => $posts));
     }
     return $this->display(__FILE__, 'views/templates/front/plugins/smartblogrelatedposts.tpl');
 }
Ejemplo n.º 2
0
 public function initContent()
 {
     $smartblogurlpattern = (int) Configuration::get('smartblogurlpattern');
     //now we will check whihc option we need to url rewrite
     $id_post = null;
     switch ($smartblogurlpattern) {
         case 1:
             $SmartBlog = new smartblog();
             $slug = Tools::getValue('slug');
             $id_post = $SmartBlog->slug2id($slug);
             break;
         case 2:
             $id_post = pSQL(Tools::getvalue('id_post'));
             break;
         case 3:
             $id_post = pSQL(Tools::getvalue('id_post'));
             break;
         default:
             $id_post = pSQL(Tools::getvalue('id_post'));
     }
     if ($id_post) {
         $this->post = new SmartBlogPost($id_post, true, $this->context->language->id, $this->context->shop->id);
     }
     if (!Validate::isLoadedObject($this->post)) {
         header('HTTP/1.1 404 Not Found');
         header('Status: 404 Not Found');
         $this->errors[] = Tools::displayError('Post not found');
     }
     parent::initContent();
     $this->canonicalRedirection();
     if (!$this->errors) {
         Hook::exec('actionsbsingle', array('id_post' => $this->post));
         $blogcomment = new Blogcomment();
         $SmartBlogPost = new SmartBlogPost();
         $BlogCategory = new BlogCategory();
         $id_lang = $this->context->language->id;
         $post = $SmartBlogPost->getPost($id_post, $id_lang);
         $title_category = array();
         $getPostCategories = $this->getPostCategories($id_post);
         $i = 0;
         foreach ($getPostCategories as $category) {
             $title_category[] = $BlogCategory->getNameCategory($getPostCategories[$i]['id_smart_blog_category']);
             $i++;
         }
         $post['post_img'] = null;
         //--extra added
         $tags = $SmartBlogPost->getProductTags($id_post);
         $comment = $blogcomment->getComment($id_post);
         $countcomment = $blogcomment->getToltalComment($id_post);
         $id_cate = $post['id_category'];
         //$title_category = $BlogCategory->getNameCategory($id_cate);
         if (file_exists(_PS_MODULE_DIR_ . 'smartblog/images/' . $id_post . '.jpg')) {
             $post_img = $id_post . '.jpg';
         } else {
             $post_img = 'no';
         }
         $posts_previous = SmartBlogPost::getPreviousPostsById($id_lang, $id_post);
         $posts_next = SmartBlogPost::getNextPostsById($id_lang, $id_post);
         /* Server Params */
         $protocol_link = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://';
         $protocol_content = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
         $smartbloglink = new SmartBlogLink($protocol_link, $protocol_content);
         SmartBlogPost::postViewed($id_post);
         //here we can give validation if category page or other page it will show
         $post['date'] = Smartblog::displayDate($post['created']);
         $this->context->smarty->assign(array('smartbloglink' => $smartbloglink, 'post' => $post, 'posts_next' => $posts_next, 'posts_previous' => $posts_previous, 'comments' => $comment, 'enableguestcomment' => Configuration::get('smartenableguestcomment'), 'is_looged' => $this->context->customer->isLogged(), 'is_looged_id' => $this->context->customer->id, 'is_looged_email' => $this->context->customer->email, 'is_looged_fname' => $this->context->customer->firstname, 'tags' => $tags, 'title_category' => $title_category, 'meta_title' => $post['meta_title'], 'post_active' => $post['active'], 'blogcontent' => $post['content'], 'id_post' => $post['id_post'], 'smartshowauthorstyle' => Configuration::get('smartshowauthorstyle'), 'smartshowauthor' => Configuration::get('smartshowauthor'), 'created' => Smartblog::displayDate($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']));
         $this->context->smarty->assign('HOOK_SMART_BLOG_POST_FOOTER', Hook::exec('displaySmartAfterPost'));
     }
     $this->setTemplate('posts.tpl');
 }
Ejemplo n.º 3
0
 public static function GetPostLatestHome($limit)
 {
     $sorting = Configuration::get('latestnews_sort_by');
     if ($sorting == 'name_ASC') {
         $orderby = 'pl.meta_title';
         $orderway = 'ASC';
     } elseif ($sorting == 'name_DESC') {
         $orderby = 'pl.meta_title';
         $orderway = 'DESC';
     } elseif ($sorting == 'id_ASC') {
         $orderby = 'p.id_smart_blog_post';
         $orderway = 'ASC';
     } else {
         $orderby = 'p.id_smart_blog_post';
         $orderway = 'DESC';
     }
     if ($limit == '' && $limit == null) {
         $limit = 3;
     }
     $id_lang = (int) Context::getContext()->language->id;
     $id_lang_defaut = Configuration::get('PS_LANG_DEFAULT');
     $result = array();
     $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post p INNER JOIN 
             ' . _DB_PREFIX_ . 'smart_blog_post_lang pl ON p.id_smart_blog_post=pl.id_smart_blog_post INNER JOIN 
             ' . _DB_PREFIX_ . 'smart_blog_post_shop ps ON pl.id_smart_blog_post = ps.id_smart_blog_post AND ps.id_shop = ' . (int) Context::getContext()->shop->id . '
             WHERE pl.id_lang=' . $id_lang . ' 		
             AND p.active= 1 ORDER BY p.id_smart_blog_post DESC 
             LIMIT ' . $limit;
     $posts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
     if (empty($posts)) {
         $sql2 = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post p INNER JOIN 
             ' . _DB_PREFIX_ . 'smart_blog_post_lang pl ON p.id_smart_blog_post=pl.id_smart_blog_post INNER JOIN 
             ' . _DB_PREFIX_ . 'smart_blog_post_shop ps ON pl.id_smart_blog_post = ps.id_smart_blog_post  AND ps.id_shop = ' . (int) Context::getContext()->shop->id . '
             WHERE pl.id_lang=' . $id_lang_defaut . ' 		
             AND p.active= 1 ORDER BY ' . $orderby . ' ' . $orderway . ' 
             LIMIT ' . pSQL($limit);
         $posts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql2);
     }
     $i = 0;
     foreach ($posts as $post) {
         $result[$i]['id'] = $post['id_smart_blog_post'];
         $result[$i]['title'] = $post['meta_title'];
         $result[$i]['meta_description'] = strip_tags($post['meta_description']);
         $result[$i]['short_description'] = strip_tags($post['short_description']);
         $result[$i]['content'] = strip_tags($post['content']);
         $result[$i]['category'] = $post['id_category'];
         $result[$i]['date_added'] = Smartblog::displayDate($post['created']);
         $result[$i]['viewed'] = $post['viewed'];
         $result[$i]['is_featured'] = $post['is_featured'];
         $result[$i]['link_rewrite'] = $post['link_rewrite'];
         if (file_exists(_PS_MODULE_DIR_ . 'smartblog/images/' . $post['id_smart_blog_post'] . '.jpg')) {
             $image = $post['id_smart_blog_post'];
             $result[$i]['post_img'] = $image;
         } else {
             $result[$i]['post_img'] = 'no';
         }
         $i++;
     }
     return $result;
 }
Ejemplo n.º 4
0
 public function initContent()
 {
     $category_status = '';
     $totalpages = '';
     $cat_image = 'no';
     $categoryinfo = '';
     $title_category = '';
     $cat_link_rewrite = '';
     $blogcomment = new Blogcomment();
     $SmartBlogPost = new SmartBlogPost();
     $BlogCategory = new BlogCategory();
     $BlogPostCategory = new BlogPostCategory();
     $smartblogurlpattern = (int) Configuration::get('smartblogurlpattern');
     //now we will check whihc option we need to url rewrite
     switch ($smartblogurlpattern) {
         case 1:
             $SmartBlog = new smartblog();
             $slug = Tools::getValue('slug');
             $id_category = $SmartBlog->categoryslug2id($slug);
             break;
         case 2:
             $SmartBlog = new smartblog();
             $id_category = Tools::getValue('id_category');
             //                if($id_category==''){
             //                   $id_category = $SmartBlog->categoryslug2id($slug);
             //                }
             break;
         default:
             $id_category = Tools::getValue('id_category');
     }
     //$categoryinfo = $BlogCategory->getNameCategory($id_category);
     $posts_per_page = Configuration::get('smartpostperpage');
     $limit_start = 0;
     $limit = $posts_per_page;
     if (!$id_category) {
         $total = (int) $SmartBlogPost->getToltal($this->context->language->id);
     } else {
         $total = (int) $SmartBlogPost->getToltalByCategory($this->context->language->id, $id_category);
         Hook::exec('actionsbcat', array('id_category' => pSQL(Tools::getvalue('id_category'))));
     }
     if ($total != '' || $total != 0) {
         $totalpages = ceil($total / $posts_per_page);
     }
     if ((bool) Tools::getValue('page')) {
         $c = (int) Tools::getValue('page');
         $limit_start = $posts_per_page * ($c - 1);
     }
     if (!$id_category) {
         $allNews = $SmartBlogPost->getAllPost($this->context->language->id, $limit_start, $limit);
     } else {
         if (file_exists(_PS_MODULE_DIR_ . 'smartblog/images/category/' . $id_category . '.jpg')) {
             $cat_image = $id_category;
         } else {
             $cat_image = 'no';
         }
         $categoryinfo = $BlogCategory->getNameCategory($id_category);
         $title_category = $categoryinfo[0]['name'];
         $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;
     $to = array();
     if (!empty($allNews)) {
         foreach ($allNews as $item) {
             $to[$i] = $blogcomment->getToltalComment($item['id_post']);
             $i++;
             if (file_exists(_PS_MODULE_DIR_ . 'smartblog/images/' . $item['id_post'] . '.jpg')) {
                 $item['post_img'] = $item['id_post'] . '.jpg';
             } else {
                 $item['post_img'] = 'no';
             }
         }
         $j = 0;
         foreach ($to as $item) {
             if ($item == '') {
                 $allNews[$j]['totalcomment'] = 0;
             } else {
                 $allNews[$j]['totalcomment'] = $item;
             }
             $j++;
         }
     }
     $protocol_link = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://';
     $protocol_content = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
     $smartbloglink = new SmartBlogLink($protocol_link, $protocol_content);
     $i = 0;
     foreach ($allNews as $post) {
         $allNews[$i]['created'] = Smartblog::displayDate($post['created']);
         $i++;
     }
     parent::initContent();
     $this->canonicalRedirection();
     $this->context->smarty->assign(array('smartbloglink' => $smartbloglink, 'postcategory' => $allNews, 'category_status' => $category_status, 'title_category' => $title_category, 'cat_link_rewrite' => $cat_link_rewrite, 'id_category' => $id_category, 'cat_image' => $cat_image, 'categoryinfo' => $categoryinfo, 'smartshowauthorstyle' => Configuration::get('smartshowauthorstyle'), 'smartshowauthor' => Configuration::get('smartshowauthor'), 'limit' => isset($limit) ? $limit : 0, 'limit_start' => isset($limit_start) ? $limit_start : 0, 'c' => isset($c) ? $c : 1, 'total' => $total, 'smartblogliststyle' => Configuration::get('smartblogliststyle'), 'smartcustomcss' => Configuration::get('smartcustomcss'), 'smartshownoimg' => Configuration::get('smartshownoimg'), 'smartdisablecatimg' => Configuration::get('smartdisablecatimg'), 'smartshowviewed' => Configuration::get('smartshowviewed'), 'post_per_page' => $posts_per_page, 'pagenums' => $totalpages - 1, 'totalpages' => $totalpages));
     $template_name = 'postcategory.tpl';
     $this->setTemplate($template_name);
 }