Ejemplo n.º 1
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);
 }
 public function postProcess()
 {
     if (Tools::isSubmit('deletesmart_blog_category') && Tools::getValue('id_smart_blog_category') != '') {
         $id_lang = (int) Context::getContext()->language->id;
         $catpost = (int) SmartBlogPost::getToltalByCategory($id_lang, Tools::getValue('id_smart_blog_category'));
         if ((int) $catpost != 0) {
             $this->errors[] = Tools::displayError('You need to delete all posts associate with this category .');
         } else {
             $BlogCategory = new BlogCategory((int) Tools::getValue('id_smart_blog_category'));
             if (!$BlogCategory->delete()) {
                 $this->errors[] = Tools::displayError('An error occurred while deleting the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 Hook::exec('actionsbdeletecat', array('BlogCategory' => $BlogCategory));
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
             }
         }
     } elseif (Tools::isSubmit('submitAddsmart_blog_category')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         if (!($id_smart_blog_category = (int) Tools::getValue('id_smart_blog_category'))) {
             $BlogCategory = new BlogCategory();
             $languages = Language::getLanguages(false);
             foreach ($languages as $language) {
                 $title = str_replace('"', '', htmlspecialchars_decode(html_entity_decode(Tools::getValue('meta_title_' . $language['id_lang']))));
                 $BlogCategory->meta_title[$language['id_lang']] = $title;
                 $BlogCategory->meta_keyword[$language['id_lang']] = Tools::getValue('meta_keyword_' . $language['id_lang']);
                 $BlogCategory->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
                 $BlogCategory->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']);
                 if (Tools::getValue('link_rewrite_' . $language['id_lang']) == '' && Tools::getValue('link_rewrite_' . $language['id_lang']) == null) {
                     $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('meta_title_' . $language['id_lang']));
                 } else {
                     $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('link_rewrite_' . $language['id_lang']));
                 }
             }
             $BlogCategory->id_parent = Tools::getValue('id_parent');
             $BlogCategory->position = Tools::getValue('position');
             $BlogCategory->desc_limit = Tools::getValue('desc_limit');
             $BlogCategory->active = Tools::getValue('active');
             $BlogCategory->created = Date('y-m-d H:i:s');
             $BlogCategory->modified = Date('y-m-d H:i:s');
             if (!$BlogCategory->save()) {
                 $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
             } else {
                 Hook::exec('actionsbnewcat', array('BlogCategory' => $BlogCategory));
                 $this->processImageCategory($_FILES, $BlogCategory->id);
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
             }
         } elseif ($id_smart_blog_category = Tools::getValue('id_smart_blog_category')) {
             $BlogCategory = new BlogCategory($id_smart_blog_category);
             $languages = Language::getLanguages(false);
             foreach ($languages as $language) {
                 $title = str_replace('"', '', htmlspecialchars_decode(html_entity_decode(Tools::getValue('meta_title_' . $language['id_lang']))));
                 $BlogCategory->meta_title[$language['id_lang']] = $title;
                 $BlogCategory->meta_keyword[$language['id_lang']] = Tools::getValue('meta_keyword_' . $language['id_lang']);
                 $BlogCategory->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
                 $BlogCategory->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']);
                 $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('link_rewrite_' . $language['id_lang']));
             }
             $BlogCategory->id_parent = Tools::getValue('id_parent');
             $BlogCategory->position = Tools::getValue('position');
             $BlogCategory->desc_limit = Tools::getValue('desc_limit');
             $BlogCategory->active = Tools::getValue('active');
             $BlogCategory->modified = Date('y-m-d H:i:s');
             if (!$BlogCategory->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 Hook::exec('actionsbupdatecat', array('BlogCategory' => $BlogCategory));
             }
             $this->processImageCategory($_FILES, $BlogCategory->id_smart_blog_category);
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
         }
     } elseif (Tools::isSubmit('statussmart_blog_category') && Tools::getValue($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Hook::exec('actionsbtogglecat', array('SmartBlogCat' => $this->object));
                     $identifier = (int) $object->id_parent ? '&id_smart_blog_category=' . (int) $object->id_parent : '';
                     Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('smart_blog_categoryOrderby') && Tools::isSubmit('smart_blog_categoryOrderway')) {
         $this->_defaultOrderBy = Tools::getValue('smart_blog_categoryOrderby');
         $this->_defaultOrderWay = Tools::getValue('smart_blog_categoryOrderway');
     }
 }
Ejemplo n.º 3
0
 public function initContent()
 {
     parent::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();
     $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 ((bool) 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 {
         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]['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++;
         }
     }
     $this->context->smarty->assign(array('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);
 }