Exemplo n.º 1
0
 /**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     if (Tools::getValue('captchaimage')) {
         $this->captcha();
         exit;
     }
     $config = LeoBlogConfig::getInstance();
     /* Load Css and JS File */
     LeoBlogHelper::loadMedia($this->context, $this);
     parent::initContent();
     if (Tools::isSubmit('submitcomment')) {
         # validate module
         $this->comment();
     }
     $helper = LeoBlogHelper::getInstance();
     $blog = new LeoBlogBlog(Tools::getValue('id'), $this->context->language->id);
     //		$_GET['rewrite'] = $blog->link_rewrite;
     if (!$blog->id_leoblog_blog) {
         $full_path = '<a href="' . $helper->getFontBlogLink() . '">' . htmlentities($config->get('blog_link_title_' . $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8') . '</a>';
         $vars = array('error' => true, 'path' => $full_path);
         $this->context->smarty->assign($vars);
         return $this->setTemplate($config->get('template', 'default') . '/blog.tpl');
     }
     $category = new leoblogcat($blog->id_leoblogcat, $this->context->language->id);
     $image_w = $config->get('item_img_width', 690);
     $image_h = $config->get('item_img_height', 300);
     $template = !empty($category->template) ? $category->template : 'default';
     // have to have a value ( not empty )
     $this->template_path .= $template . '/';
     $module_tpl = $this->template_path;
     $url = _PS_BASE_URL_;
     if (Tools::usingSecureMode()) {
         # validate module
         $url = _PS_BASE_URL_SSL_;
     }
     $blog->preview_url = '';
     if ($blog->image) {
         $blog->image_url = $url . _LEOBLOG_BLOG_IMG_URI_ . 'b/' . $blog->image;
         if (ImageManager::resize(_LEOBLOG_BLOG_IMG_DIR_ . 'b/' . $blog->image, _LEOBLOG_CACHE_IMG_DIR_ . 'b/lg-' . $blog->image, $image_w, $image_h)) {
             # validate module
             $blog->preview_url = $url . _LEOBLOG_CACHE_IMG_URI_ . 'b/lg-' . $blog->image;
         }
     }
     $captcha_image = $helper->getBlogLink(get_object_vars($blog), array('captchaimage' => 1));
     $blog_link = $helper->getBlogLink(get_object_vars($blog));
     $params = array('rewrite' => $category->link_rewrite, 'id' => $category->id_leoblogcat);
     $blog->category_link = $helper->getBlogCatLink($params);
     $blog->category_title = $category->title;
     $employee = new Employee($blog->id_employee);
     $blog->author = $employee->firstname . ' ' . $employee->lastname;
     $blog->author_link = $helper->getBlogAuthorLink($employee->id);
     $tags = array();
     if ($blog->tags && ($tmp = explode(',', $blog->tags))) {
         foreach ($tmp as $tag) {
             $tags[] = array('tag' => $tag, 'link' => $helper->getBlogTagLink($tag));
         }
     }
     $blog->hits = $blog->hits + 1;
     //$blog->save();
     $blog->updateField($blog->id, array('hits' => $blog->hits));
     /* breadscrumb */
     $params = array('rewrite' => $category->link_rewrite, 'id' => $category->id_leoblogcat);
     $category_link = $helper->getBlogCatLink($params);
     $full_path = '<a href="' . $helper->getFontBlogLink() . '">' . htmlentities($config->get('blog_link_title_' . $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8') . '</a><span class="navigation-pipe">' . Configuration::get('PS_NAVIGATION_PIPE') . '</span>';
     $full_path .= '<a href="' . Tools::safeOutput($category_link) . '">' . htmlentities($category->title, ENT_NOQUOTES, 'UTF-8') . '</a><span class="navigation-pipe">' . Configuration::get('PS_NAVIGATION_PIPE') . '</span>' . $blog->meta_title;
     $limit = 5;
     $samecats = LeoBlogBlog::getListBlogs($category->id_leoblogcat, $this->context->language->id, 0, $limit, 'date_add', 'DESC', array('type' => 'samecat', 'id_leoblog_blog' => $blog->id_leoblog_blog), true);
     foreach ($samecats as $key => $sblog) {
         $sblog['link'] = $helper->getBlogLink($sblog);
         $samecats[$key] = $sblog;
     }
     $tagrelated = array();
     if ($blog->tags) {
         $tagrelated = LeoBlogBlog::getListBlogs($category->id_leoblogcat, $this->context->language->id, 0, $limit, 'id_leoblog_blog', 'DESC', array('type' => 'tag', 'tag' => $blog->tags), true);
         foreach ($tagrelated as $key => $tblog) {
             $tblog['link'] = $helper->getBlogLink($tblog);
             $tagrelated[$key] = $tblog;
         }
     }
     /* Comments */
     $evars = array();
     if ($config->get('item_comment_engine', 'local') == 'local') {
         $count_comment = 0;
         if ($config->get('comment_engine', 'local') == 'local') {
             # validate module
             $count_comment = LeoBlogComment::countComments($blog->id_leoblog_blog, true);
         }
         $blog_link = $helper->getBlogLink(get_object_vars($blog));
         $limit = (int) $config->get('item_limit_comments', 10);
         $n = $limit;
         $p = abs((int) Tools::getValue('p', 1));
         $comment = new LeoBlogComment();
         $comments = $comment->getList($blog->id_leoblog_blog, $this->context->language->id, $p, $limit);
         $nb_blogs = $count_comment;
         $range = 2;
         /* how many pages around page selected */
         if ($p > $nb_blogs / $n + 1) {
             Tools::redirect(preg_replace('/[&?]p=\\d+/', '', $_SERVER['REQUEST_URI']));
         }
         $pages_nb = ceil($nb_blogs / (int) $n);
         $start = (int) ($p - $range);
         if ($start < 1) {
             $start = 1;
         }
         $stop = (int) ($p + $range);
         if ($stop > $pages_nb) {
             $stop = (int) $pages_nb;
         }
         $evars = array('pages_nb' => $pages_nb, 'nb_items' => $count_comment, 'p' => (int) $p, 'n' => (int) $n, 'requestPage' => $blog_link, 'requestNb' => $blog_link, 'start' => $start, 'comments' => $comments, 'range' => $range, 'blog_count_comment' => $count_comment, 'stop' => $stop);
     }
     if ((bool) Module::isEnabled('smartshortcode')) {
         if (context::getcontext()->controller->controller_type == 'front') {
             $smartshortcode = Module::getInstanceByName('smartshortcode');
             $blog->content = $smartshortcode->parse($blog->content);
         }
     }
     $vars = array('tags' => $tags, 'meta_title' => Tools::ucfirst($blog->meta_title) . ' - ' . $this->context->shop->name, 'meta_keywords' => $blog->meta_keywords, 'meta_description' => $blog->meta_description, 'blog' => $blog, 'samecats' => $samecats, 'tagrelated' => $tagrelated, 'path' => $full_path, 'config' => $config, 'id_leoblog_blog' => $blog->id_leoblog_blog, 'is_active' => $blog->active, 'productrelated' => array(), 'module_tpl' => $module_tpl, 'captcha_image' => $captcha_image, 'blog_link' => $blog_link);
     $vars = array_merge($vars, $evars);
     $this->context->smarty->assign($vars);
     $this->setTemplate($template . '/blog.tpl');
 }
Exemplo n.º 2
0
 /**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     $config = LeoBlogConfig::getInstance();
     /* Load Css and JS File */
     LeoBlogHelper::loadMedia($this->context, $this);
     $this->php_self = 'category';
     parent::initContent();
     $id_category = (int) Tools::getValue('id');
     $helper = LeoBlogHelper::getInstance();
     $limit_leading_blogs = (int) $config->get('listing_leading_limit_items', 1);
     $limit_secondary_blogs = (int) $config->get('listing_secondary_limit_items', 6);
     $limit = (int) $limit_leading_blogs + (int) $limit_secondary_blogs;
     $n = $limit;
     $p = abs((int) Tools::getValue('p', 1));
     $category = new Leoblogcat($id_category, $this->context->language->id);
     $template = isset($category->template) && $category->template ? $category->template : $config->get('template', 'default');
     if ($category->id_leoblogcat && $category->active) {
         //			$_GET['rewrite'] = $category->link_rewrite;
         $this->template_path .= $template . '/';
         if ($category->image) {
             # validate module
             $category->image = _LEOBLOG_BLOG_IMG_URI_ . 'c/' . $category->image;
         }
         $blogs = LeoBlogBlog::getListBlogs($id_category, $this->context->language->id, $p, $limit, 'id_leoblog_blog', 'DESC', array(), true);
         $count = LeoBlogBlog::countBlogs($id_category, $this->context->language->id, true);
         $authors = array();
         $leading_blogs = array();
         $secondary_blogs = array();
         //			$links 	   =  array();
         if (count($blogs)) {
             $leading_blogs = array_slice($blogs, 0, $limit_leading_blogs);
             $secondary_blogs = array_splice($blogs, $limit_leading_blogs, count($blogs));
         }
         $image_w = (int) $config->get('listing_leading_img_width', 690);
         $image_h = (int) $config->get('listing_leading_img_height', 300);
         foreach ($leading_blogs as $key => $blog) {
             $blog = LeoBlogHelper::buildBlog($helper, $blog, $image_w, $image_h, $config);
             if ($blog['id_employee']) {
                 if (!isset($authors[$blog['id_employee']])) {
                     # validate module
                     $authors[$blog['id_employee']] = new Employee($blog['id_employee']);
                 }
                 $blog['author'] = $authors[$blog['id_employee']]->firstname . ' ' . $authors[$blog['id_employee']]->lastname;
                 $blog['author_link'] = $helper->getBlogAuthorLink($authors[$blog['id_employee']]->id);
             } else {
                 $blog['author'] = '';
                 $blog['author_link'] = '';
             }
             $leading_blogs[$key] = $blog;
         }
         $image_w = (int) $config->get('listing_secondary_img_width', 390);
         $image_h = (int) $config->get('listing_secondary_img_height', 200);
         foreach ($secondary_blogs as $key => $blog) {
             $blog = LeoBlogHelper::buildBlog($helper, $blog, $image_w, $image_h, $config);
             if ($blog['id_employee']) {
                 if (!isset($authors[$blog['id_employee']])) {
                     # validate module
                     $authors[$blog['id_employee']] = new Employee($blog['id_employee']);
                 }
                 $blog['author'] = $authors[$blog['id_employee']]->firstname . ' ' . $authors[$blog['id_employee']]->lastname;
                 $blog['author_link'] = $helper->getBlogAuthorLink($authors[$blog['id_employee']]->id);
             } else {
                 $blog['author'] = '';
                 $blog['author_link'] = '';
             }
             $secondary_blogs[$key] = $blog;
         }
         $nb_blogs = $count;
         $range = 2;
         /* how many pages around page selected */
         if ($p > $nb_blogs / $n + 1) {
             Tools::redirect(preg_replace('/[&?]p=\\d+/', '', $_SERVER['REQUEST_URI']));
         }
         $pages_nb = ceil($nb_blogs / (int) $n);
         $start = (int) ($p - $range);
         if ($start < 1) {
             $start = 1;
         }
         $stop = (int) ($p + $range);
         if ($stop > $pages_nb) {
             $stop = (int) $pages_nb;
         }
         $params = array('rewrite' => $category->link_rewrite, 'id' => $category->id_leoblogcat);
         /* breadcrumb */
         $r = $helper->getPaginationLink('module-leoblog-category', 'category', $params, false, true);
         $path = '';
         $all_cats = array();
         self::parentCategories($category, $all_cats);
         foreach ($all_cats as $key => $cat) {
             if ($cat->id == 1) {
                 # validate module
                 $path .= '<a href="' . $helper->getFontBlogLink() . '">' . htmlentities($config->get('blog_link_title_' . $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8') . '</a><span class="navigation-pipe">' . Configuration::get('PS_NAVIGATION_PIPE') . '</span>';
             } elseif (count($all_cats) - 1 == $key) {
                 # validate module
                 $path .= $cat->title;
             } else {
                 $params = array('rewrite' => $cat->link_rewrite, 'id' => $cat->id);
                 $path .= '<a href="' . $helper->getBlogCatLink($params) . '">' . htmlentities($cat->title, ENT_NOQUOTES, 'UTF-8') . '</a><span class="navigation-pipe">' . Configuration::get('PS_NAVIGATION_PIPE') . '</span>';
             }
         }
         /* sub categories */
         $categories = $category->getChild($category->id_leoblogcat, $this->context->language->id);
         $childrens = array();
         if ($categories) {
             foreach ($categories as $child) {
                 $params = array('rewrite' => $child['link_rewrite'], 'id' => $child['id_leoblogcat']);
                 $child['thumb'] = _LEOBLOG_BLOG_IMG_URI_ . 'c/' . $child['image'];
                 $child['category_link'] = $helper->getBlogCatLink($params);
                 $childrens[] = $child;
             }
         }
         $this->context->smarty->assign(array('leading_blogs' => $leading_blogs, 'secondary_blogs' => $secondary_blogs, 'listing_leading_column' => $config->get('listing_leading_column', 1), 'listing_secondary_column' => $config->get('listing_secondary_column', 3), 'module_tpl' => $this->template_path, 'config' => $config, 'range' => $range, 'category' => $category, 'start' => $start, 'childrens' => $childrens, 'stop' => $stop, 'path' => $path, 'pages_nb' => $pages_nb, 'nb_items' => $count, 'p' => (int) $p, 'n' => (int) $n, 'meta_title' => Tools::ucfirst($category->title) . ' - ' . $this->context->shop->name, 'meta_keywords' => $category->meta_keywords, 'meta_description' => $category->meta_description, 'requestPage' => $r['requestUrl'], 'requestNb' => $r, 'category' => $category));
     } else {
         $path = '<a href="' . $helper->getFontBlogLink() . '">' . htmlentities($config->get('blog_link_title_' . $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8') . '</a><span class="navigation-pipe">' . Configuration::get('PS_NAVIGATION_PIPE') . '</span>';
         $this->context->smarty->assign(array('active' => '0', 'path' => $path, 'leading_blogs' => array(), 'secondary_blogs' => array(), 'controller' => 'category', 'category' => $category));
     }
     $this->setTemplate($template . '/category.tpl');
 }
Exemplo n.º 3
0
 /**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     $config = LeoBlogConfig::getInstance();
     $authors = array();
     /* Load Css and JS File */
     LeoBlogHelper::loadMedia($this->context, $this);
     parent::initContent();
     $helper = LeoBlogHelper::getInstance();
     $limit_leading_blogs = (int) $config->get('listing_leading_limit_items', 1);
     $limit_secondary_blogs = (int) $config->get('listing_secondary_limit_items', 6);
     //$latest_limit_items = (int)$config->get( 'latest_limit_items', 20 );
     $author = (int) Tools::getValue('author');
     $tag = trim(Tools::getValue('tag'));
     $n = (int) $limit_leading_blogs + (int) $limit_secondary_blogs;
     $p = abs((int) Tools::getValue('p', 1));
     $template = $config->get('template', 'default');
     $this->template_path .= $template . '/';
     $condition = array();
     if ($author) {
         $condition = array('type' => 'author', 'id_employee' => $author, 'employee' => new Employee($author));
         $r = $helper->getPaginationLink('module-leoblog-list', 'list', array('author' => $author));
     }
     if ($tag) {
         $condition = array('type' => 'tag', 'tag' => urldecode($tag));
         $r = $helper->getPaginationLink('module-leoblog-list', 'list', array('tag' => $tag));
     }
     $blogs = LeoBlogBlog::getListBlogs(null, $this->context->language->id, $p, $n, 'id_leoblog_blog', 'DESC', $condition, true);
     $count = LeoBlogBlog::countBlogs(null, $this->context->language->id, $condition, true);
     $leading_blogs = array();
     $secondary_blogs = array();
     //		$links 	   		 =  array();
     if (count($blogs)) {
         $leading_blogs = array_slice($blogs, 0, $limit_leading_blogs);
         $secondary_blogs = array_splice($blogs, $limit_leading_blogs, count($blogs));
     }
     $image_w = (int) $config->get('listing_leading_img_width', 690);
     $image_h = (int) $config->get('listing_leading_img_height', 300);
     foreach ($leading_blogs as $key => $blog) {
         $blog = LeoBlogHelper::buildBlog($helper, $blog, $image_w, $image_h, $config);
         if ($blog['id_employee']) {
             if (!isset($authors[$blog['id_employee']])) {
                 # validate module
                 $authors[$blog['id_employee']] = new Employee($blog['id_employee']);
             }
             $blog['author'] = $authors[$blog['id_employee']]->firstname . ' ' . $authors[$blog['id_employee']]->lastname;
             $blog['author_link'] = $helper->getBlogAuthorLink($authors[$blog['id_employee']]->id);
         } else {
             $blog['author'] = '';
             $blog['author_link'] = '';
         }
         $leading_blogs[$key] = $blog;
     }
     $image_w = (int) $config->get('listing_secondary_img_width', 390);
     $image_h = (int) $config->get('listing_secondary_img_height', 200);
     foreach ($secondary_blogs as $key => $blog) {
         $blog = LeoBlogHelper::buildBlog($helper, $blog, $image_w, $image_h, $config);
         if ($blog['id_employee']) {
             if (!isset($authors[$blog['id_employee']])) {
                 # validate module
                 $authors[$blog['id_employee']] = new Employee($blog['id_employee']);
             }
             $blog['author'] = $authors[$blog['id_employee']]->firstname . ' ' . $authors[$blog['id_employee']]->lastname;
             $blog['author_link'] = $helper->getBlogAuthorLink($authors[$blog['id_employee']]->id);
         } else {
             $blog['author'] = '';
             $blog['author_link'] = '';
         }
         $secondary_blogs[$key] = $blog;
     }
     $module_tpl = $this->template_path;
     //$nbBlogs = $count > $latest_limit_items?$latest_limit_items:$count;
     $nb_blogs = $count;
     $range = 2;
     /* how many pages around page selected */
     if ($p > $nb_blogs / $n + 1) {
         Tools::redirect(preg_replace('/[&?]p=\\d+/', '', $_SERVER['REQUEST_URI']));
     }
     $pages_nb = ceil($nb_blogs / (int) $n);
     $start = (int) ($p - $range);
     if ($start < 1) {
         $start = 1;
     }
     $stop = (int) ($p + $range);
     if ($stop > $pages_nb) {
         $stop = (int) $pages_nb;
     }
     if (!isset($r)) {
         $r = $helper->getPaginationLink('module-leoblog-list', 'list', array(), false, true);
     }
     $module_tpl = $this->template_path;
     /* breadcrumb */
     $path = '<a href="' . $helper->getFontBlogLink() . '">' . htmlentities($config->get('blog_link_title_' . $this->context->language->id, 'Blog'), ENT_NOQUOTES, 'UTF-8') . '</a>';
     $this->context->smarty->assign(array('leading_blogs' => $leading_blogs, 'secondary_blogs' => $secondary_blogs, 'listing_leading_column' => $config->get('listing_leading_column', 1), 'listing_secondary_column' => $config->get('listing_secondary_column', 3), 'filter' => $condition, 'module_tpl' => $module_tpl, 'nb_items' => $count, 'range' => $range, 'path' => $path, 'start' => $start, 'stop' => $stop, 'pages_nb' => $pages_nb, 'config' => $config, 'p' => (int) $p, 'n' => (int) $n, 'meta_title' => $config->get('meta_title_' . Context::getContext()->language->id) . ' - ' . $this->context->shop->name, 'meta_keywords' => $config->get('meta_keywords_' . Context::getContext()->language->id), 'meta_description' => $config->get('meta_description_' . Context::getContext()->language->id), 'requestPage' => $r['requestUrl'], 'requestNb' => $r, 'controller' => 'latest'));
     $this->setTemplate($template . '/listing.tpl');
 }