first commit
This commit is contained in:
466
modules/leoblog/controllers/front/blog.php
Normal file
466
modules/leoblog/controllers/front/blog.php
Normal file
@@ -0,0 +1,466 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
include_once(_PS_MODULE_DIR_.'leoblog/loader.php');
|
||||
|
||||
class LeoblogblogModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
public $php_self;
|
||||
protected $template_path = '';
|
||||
// public $rewrite;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->context = Context::getContext();
|
||||
$this->template_path = _PS_MODULE_DIR_.'leoblog/views/templates/front/';
|
||||
// $this->rewrite = 'aaaa';
|
||||
}
|
||||
|
||||
public function captcha()
|
||||
{
|
||||
include_once(_PS_MODULE_DIR_.'leoblog/classes/captcha.php');
|
||||
$captcha = new LeoCaptcha();
|
||||
$this->context->cookie->leocaptch = $captcha->getCode();
|
||||
$captcha->showImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object &$object Object
|
||||
* @param string $table Object table
|
||||
* @ DONE
|
||||
*/
|
||||
protected function copyFromPost(&$object, $table, $post = array())
|
||||
{
|
||||
/* Classical fields */
|
||||
foreach ($post as $key => $value) {
|
||||
if (key_exists($key, $object) && $key != 'id_'.$table) {
|
||||
/* Do not take care of password field if empty */
|
||||
if ($key == 'passwd' && Tools::getValue('id_'.$table) && empty($value)) {
|
||||
continue;
|
||||
}
|
||||
if ($key == 'passwd' && !empty($value)) {
|
||||
/* Automatically encrypt password in MD5 */
|
||||
$value = Tools::encrypt($value);
|
||||
}
|
||||
$object->{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/* Multilingual fields */
|
||||
$rules = call_user_func(array(get_class($object), 'getValidationRules'), get_class($object));
|
||||
if (count($rules['validateLang'])) {
|
||||
$languages = Language::getLanguages(false);
|
||||
foreach ($languages as $language) {
|
||||
foreach (array_keys($rules['validateLang']) as $field) {
|
||||
$field_name = $field.'_'.(int)($language['id_lang']);
|
||||
$value = Tools::getValue($field_name);
|
||||
if (isset($value)) {
|
||||
# validate module
|
||||
$object->{$field}[(int)($language['id_lang'])] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save user comment
|
||||
*/
|
||||
protected function comment()
|
||||
{
|
||||
$post = array();
|
||||
$post['user'] = Tools::getValue('user');
|
||||
$post['email'] = Tools::getValue('email');
|
||||
$post['comment'] = Tools::getValue('comment');
|
||||
$post['captcha'] = Tools::getValue('captcha');
|
||||
$post['id_leoblog_blog'] = Tools::getValue('id_leoblog_blog');
|
||||
$post['submitcomment'] = Tools::getValue('submitcomment');
|
||||
|
||||
if (!empty($post)) {
|
||||
$comment = new LeoBlogComment();
|
||||
$captcha = Tools::getValue('captcha');
|
||||
$this->copyFromPost($comment, 'comment', $post);
|
||||
|
||||
$error = new stdClass();
|
||||
$error->error = true;
|
||||
|
||||
if (isset($this->context->cookie->leocaptch) && $captcha && $captcha == $this->context->cookie->leocaptch) {
|
||||
if ($comment->validateFields(false) && $comment->validateFieldsLang(false)) {
|
||||
$comment->save();
|
||||
$error->message = $this->l('Thanks for your comment, it will be published soon!!!', 'blog');
|
||||
$error->error = false;
|
||||
} else {
|
||||
# validate module
|
||||
$error->message = $this->l('An error occurred while sending the comment. Please recorrect data in fields!!!', 'blog');
|
||||
}
|
||||
} else {
|
||||
# validate module
|
||||
$error->message = $this->l('An error with captcha code, please try to recorrect!!!', 'blog');
|
||||
}
|
||||
|
||||
|
||||
die(Tools::jsonEncode($error));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
|
||||
$this->php_self = 'blog';
|
||||
// $this->php_self = 'module-leoblog-blog';
|
||||
|
||||
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();
|
||||
if ($config->get('url_use_id', 1)) {
|
||||
// URL HAVE ID
|
||||
$blog = new LeoBlogBlog(Tools::getValue('id'), $this->context->language->id);
|
||||
} else {
|
||||
// REMOVE ID FROM URL
|
||||
$url_rewrite = explode('/', $_SERVER['REQUEST_URI']) ;
|
||||
$url_last_item = count($url_rewrite) - 1;
|
||||
$url_rewrite = rtrim($url_rewrite[$url_last_item], 'html');
|
||||
$url_rewrite = rtrim($url_rewrite, '\.'); // result : product.html -> product.
|
||||
$blog = LeoBlogBlog::findByRewrite(array('link_rewrite'=>$url_rewrite));
|
||||
}
|
||||
|
||||
$template = $config->get('template', 'default');
|
||||
// set link demo
|
||||
if (Tools::getValue('bloglayout') != null) {
|
||||
if (is_dir(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.Tools::getValue('bloglayout'))) {
|
||||
$template = Tools::getValue('bloglayout');
|
||||
} elseif (is_dir(_PS_MODULE_DIR_ .'leoblog/views/templates/front/'.Tools::getValue('bloglayout'))) {
|
||||
$template = Tools::getValue('bloglayout');
|
||||
}
|
||||
}
|
||||
//set file include
|
||||
if (is_dir(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template) || is_dir(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template)) {
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_social.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_social.tpl')) {
|
||||
$_social = 'module:leoblog/views/templates/front/'.$template.'/_social.tpl';
|
||||
} else {
|
||||
$_social = 'module:leoblog/views/templates/front/default/_social.tpl';
|
||||
}
|
||||
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_facebook_comment.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_facebook_comment.tpl')) {
|
||||
$_facebook_comment = 'module:leoblog/views/templates/front/'.$template.'/_facebook_comment.tpl';
|
||||
} else {
|
||||
$_facebook_comment = 'module:leoblog/views/templates/front/default/_facebook_comment.tpl';
|
||||
}
|
||||
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_diquis_comment.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_diquis_comment.tpl')) {
|
||||
$_diquis_comment = 'module:leoblog/views/templates/front/'.$template.'/_diquis_comment.tpl';
|
||||
} else {
|
||||
$_diquis_comment = 'module:leoblog/views/templates/front/default/_diquis_comment.tpl';
|
||||
}
|
||||
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_local_comment.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_local_comment.tpl')) {
|
||||
$_local_comment = 'module:leoblog/views/templates/front/'.$template.'/_local_comment.tpl';
|
||||
} else {
|
||||
$_local_comment = 'module:leoblog/views/templates/front/default/_local_comment.tpl';
|
||||
}
|
||||
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_pagination.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_pagination.tpl')) {
|
||||
$_pagination = 'module:leoblog/views/templates/front/'.$template.'/_pagination.tpl';
|
||||
} else {
|
||||
$_pagination = 'module:leoblog/views/templates/front/default/_pagination.tpl';
|
||||
}
|
||||
|
||||
if (!file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/blog.tpl') && !file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/blog.tpl')) {
|
||||
$template = 'default';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$blog->id_leoblog_blog) {
|
||||
$vars = array(
|
||||
'error' => true,
|
||||
);
|
||||
$this->context->smarty->assign($vars);
|
||||
|
||||
return $this->setTemplate('module:leoblog/views/templates/front/'.$template.'/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);
|
||||
|
||||
|
||||
$url = _PS_BASE_URL_;
|
||||
if (Tools::usingSecureMode()) {
|
||||
# validate module
|
||||
$url = _PS_BASE_URL_SSL_;
|
||||
}
|
||||
|
||||
$id_shop = $this->context->shop->id;
|
||||
$blog->preview_url = '';
|
||||
if ($blog->image) {
|
||||
$blog->image_url = $url._THEME_DIR_.'assets/img/modules/leoblog/'.$id_shop.'/b/'.$blog->image;
|
||||
// if (!file_exists(_LEOBLOG_CACHE_IMG_DIR_.'b/'.$id_shop.'/'.$blog->id.'/lg-'.$blog->image)) {
|
||||
# FIX : CHANGE CONFIG IN BACKOFFICE NOT CHANGE AT FRONTEND
|
||||
@mkdir(_LEOBLOG_CACHE_IMG_DIR_.'b/'.$id_shop, 0777);
|
||||
@mkdir(_LEOBLOG_CACHE_IMG_DIR_.'b/'.$id_shop.'/'.$blog->id, 0777);
|
||||
|
||||
if (ImageManager::resize(_PS_THEME_DIR_.'assets/img/modules/leoblog/'.$id_shop.'/b/'.$blog->image, _LEOBLOG_CACHE_IMG_DIR_.'b/'.$id_shop.'/'.$blog->id.'/lg-'.$blog->image, $image_w, $image_h)) {
|
||||
# validate module
|
||||
$blog->preview_url = $url._LEOBLOG_CACHE_IMG_URI_.'b/'.$id_shop.'/'.$blog->id.'/lg-'.$blog->image;
|
||||
}
|
||||
// }
|
||||
|
||||
$blog->preview_url = $url._LEOBLOG_CACHE_IMG_URI_.'b/'.$id_shop.'/'.$blog->id.'/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;
|
||||
|
||||
//DONGND:: author name
|
||||
if ($blog->author_name != '') {
|
||||
# HAVE AUTHOR IN BO
|
||||
$blog->author = $blog->author_name;
|
||||
$blog->author_link = $helper->getBlogAuthorLink($blog->author_name);
|
||||
} else {
|
||||
# AUTO GENERATE AUTHOR
|
||||
$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->updateField($blog->id, array('hits' => $blog->hits));
|
||||
$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);
|
||||
}
|
||||
}
|
||||
if ((bool)Module::isEnabled('appagebuilder')) {
|
||||
$appagebuilder = Module::getInstanceByName('appagebuilder');
|
||||
$blog->description = $appagebuilder->buildShortCode($blog->description);
|
||||
$blog->content = $appagebuilder->buildShortCode($blog->content);
|
||||
}
|
||||
|
||||
$vars = array(
|
||||
'tags' => $tags,
|
||||
'meta_title' => Tools::ucfirst($blog->meta_title).' - '.Configuration::get('PS_SHOP_NAME'),
|
||||
'meta_keywords' => $blog->meta_keywords,
|
||||
'meta_description' => $blog->meta_description,
|
||||
'blog' => $blog,
|
||||
'samecats' => $samecats,
|
||||
'tagrelated' => $tagrelated,
|
||||
'config' => $config,
|
||||
'id_leoblog_blog' => $blog->id_leoblog_blog,
|
||||
'is_active' => $blog->active,
|
||||
'productrelated' => array(),
|
||||
'module_tpl' => $template,
|
||||
'captcha_image' => $captcha_image,
|
||||
'blog_link' => $blog_link,
|
||||
'_social' => $_social,
|
||||
'_facebook_comment' => $_facebook_comment,
|
||||
'_diquis_comment' => $_diquis_comment,
|
||||
'_local_comment' => $_local_comment,
|
||||
'_pagination' => $_pagination
|
||||
);
|
||||
|
||||
$vars = array_merge($vars, $evars);
|
||||
|
||||
$this->context->smarty->assign($vars);
|
||||
|
||||
// $this->setTemplate($template.'/blog.tpl');
|
||||
$this->setTemplate('module:leoblog/views/templates/front/'.$template.'/blog.tpl');
|
||||
}
|
||||
|
||||
// DONGND:: add meta
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
if ($config->get('url_use_id', 1)) {
|
||||
$blog = new LeoBlogBlog(Tools::getValue('id'), $this->context->language->id);
|
||||
} else {
|
||||
$url_rewrite = explode('/', $_SERVER['REQUEST_URI']) ;
|
||||
$url_last_item = count($url_rewrite) - 1;
|
||||
$url_rewrite = rtrim($url_rewrite[$url_last_item], '.html');
|
||||
$blog = LeoBlogBlog::findByRewrite(array('link_rewrite' => $url_rewrite));
|
||||
}
|
||||
$page['meta']['title'] = Tools::ucfirst($blog->meta_title).' - '.Configuration::get('PS_SHOP_NAME');
|
||||
$page['meta']['keywords'] = $blog->meta_keywords;
|
||||
$page['meta']['description'] = $blog->meta_description;
|
||||
return $page;
|
||||
}
|
||||
//DONGND:: add breadcrumb
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$helper = LeoBlogHelper::getInstance();
|
||||
$link = $helper->getFontBlogLink();
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => $config->get('blog_link_title_'.$this->context->language->id, $this->l('Blog', 'blog')),
|
||||
'url' => $link,
|
||||
);
|
||||
|
||||
if ($config->get('url_use_id', 1)) {
|
||||
$blog = new LeoBlogBlog(Tools::getValue('id'), $this->context->language->id);
|
||||
} else {
|
||||
$url_rewrite = explode('/', $_SERVER['REQUEST_URI']) ;
|
||||
$url_last_item = count($url_rewrite) - 1;
|
||||
$url_rewrite = rtrim($url_rewrite[$url_last_item], '.html');
|
||||
$blog = LeoBlogBlog::findByRewrite(array('link_rewrite' => $url_rewrite));
|
||||
}
|
||||
|
||||
$category = new leoblogcat($blog->id_leoblogcat, $this->context->language->id);
|
||||
$params = array(
|
||||
'rewrite' => $category->link_rewrite,
|
||||
'id' => $category->id_leoblogcat
|
||||
);
|
||||
|
||||
$category_link = $helper->getBlogCatLink($params);
|
||||
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => $category->title,
|
||||
'url' => $category_link,
|
||||
);
|
||||
|
||||
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => Tools::ucfirst($blog->meta_title),
|
||||
'url' => $helper->getBlogLink(get_object_vars($blog)),
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
//DONGND:: get layout
|
||||
public function getLayout()
|
||||
{
|
||||
$entity = 'module-leoblog-'.$this->php_self;
|
||||
|
||||
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
|
||||
|
||||
if ($overridden_layout = Hook::exec(
|
||||
'overrideLayoutTemplate',
|
||||
array(
|
||||
'default_layout' => $layout,
|
||||
'entity' => $entity,
|
||||
'locale' => $this->context->language->locale,
|
||||
'controller' => $this,
|
||||
)
|
||||
)) {
|
||||
return $overridden_layout;
|
||||
}
|
||||
|
||||
if ((int) Tools::getValue('content_only')) {
|
||||
$layout = 'layouts/layout-content-only.tpl';
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
}
|
||||
358
modules/leoblog/controllers/front/category.php
Normal file
358
modules/leoblog/controllers/front/category.php
Normal file
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
include_once(_PS_MODULE_DIR_.'leoblog/loader.php');
|
||||
|
||||
class LeoblogcategoryModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
public $php_self;
|
||||
protected $template_path = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->context = Context::getContext();
|
||||
$this->template_path = _PS_MODULE_DIR_.'leoblog/views/templates/front/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
|
||||
/* Load Css and JS File */
|
||||
LeoBlogHelper::loadMedia($this->context, $this);
|
||||
|
||||
$this->php_self = 'category';
|
||||
|
||||
// $this->php_self = 'module-leoblog-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)));
|
||||
if ($config->get('url_use_id', 1)) {
|
||||
// URL HAVE ID
|
||||
$category = new Leoblogcat($id_category, $this->context->language->id);
|
||||
} else {
|
||||
// REMOVE ID FROM URL
|
||||
$url_rewrite = explode('/', $_SERVER['REQUEST_URI']) ;
|
||||
$url_last_item = count($url_rewrite) - 1;
|
||||
$url_rewrite = rtrim($url_rewrite[$url_last_item], 'html');
|
||||
$url_rewrite = rtrim($url_rewrite, '\.'); // result : product.html -> product.
|
||||
$category = Leoblogcat::findByRewrite(array('link_rewrite'=>$url_rewrite));
|
||||
}
|
||||
|
||||
$template = $config->get('template', 'default');
|
||||
// set link demo
|
||||
if (Tools::getValue('bloglayout') != null) {
|
||||
if (is_dir(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.Tools::getValue('bloglayout'))) {
|
||||
$template = Tools::getValue('bloglayout');
|
||||
} elseif (is_dir(_PS_MODULE_DIR_ .'leoblog/views/templates/front/'.Tools::getValue('bloglayout'))) {
|
||||
$template = Tools::getValue('bloglayout');
|
||||
}
|
||||
}
|
||||
//set file include
|
||||
if (is_dir(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template) || is_dir(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template)) {
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_listing_blog.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_listing_blog.tpl')) {
|
||||
$_listing_blog = 'module:leoblog/views/templates/front/'.$template.'/_listing_blog.tpl';
|
||||
} else {
|
||||
$_listing_blog = 'module:leoblog/views/templates/front/default/_listing_blog.tpl';
|
||||
}
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_pagination.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_pagination.tpl')) {
|
||||
$_pagination = 'module:leoblog/views/templates/front/'.$template.'/_pagination.tpl';
|
||||
} else {
|
||||
$_pagination = 'module:leoblog/views/templates/front/default/_pagination.tpl';
|
||||
}
|
||||
|
||||
if (!file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/category.tpl') && !file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/category.tpl')) {
|
||||
$template = 'default';
|
||||
}
|
||||
}
|
||||
|
||||
if ($category->id_leoblogcat && $category->active) {
|
||||
// $_GET['rewrite'] = $category->link_rewrite;
|
||||
$id_shop = $this->context->shop->id;
|
||||
$url = _PS_BASE_URL_;
|
||||
if (Tools::usingSecureMode()) {
|
||||
# validate module
|
||||
$url = _PS_BASE_URL_SSL_;
|
||||
}
|
||||
if ($category->image) {
|
||||
# validate module
|
||||
$category->image = $url._THEME_DIR_.'assets/img/modules/leoblog/'.$id_shop.'/c/'.$category->image;
|
||||
}
|
||||
|
||||
$blogs = LeoBlogBlog::getListBlogs($category->id_leoblogcat, $this->context->language->id, $p, $limit, 'id_leoblog_blog', 'DESC', array(), true);
|
||||
$count = LeoBlogBlog::countBlogs($category->id_leoblogcat, $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']);
|
||||
}
|
||||
|
||||
if ($blog['author_name'] != '') {
|
||||
$blog['author'] = $blog['author_name'];
|
||||
$blog['author_link'] = $helper->getBlogAuthorLink($blog['author_name']);
|
||||
} else {
|
||||
$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']);
|
||||
}
|
||||
|
||||
if ($blog['author_name'] != '') {
|
||||
$blog['author'] = $blog['author_name'];
|
||||
$blog['author_link'] = $helper->getBlogAuthorLink($blog['author_name']);
|
||||
} else {
|
||||
$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);
|
||||
$all_cats = array();
|
||||
self::parentCategories($category, $all_cats);
|
||||
|
||||
/* 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'] = $url._THEME_DIR_.'assets/img/modules/leoblog/'.$id_shop.'/c/'.$child['image'];
|
||||
|
||||
$child['category_link'] = $helper->getBlogCatLink($params);
|
||||
if ($child['active']) {
|
||||
$childrens[] = $child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((bool)Module::isEnabled('appagebuilder')) {
|
||||
$appagebuilder = Module::getInstanceByName('appagebuilder');
|
||||
$category->content_text = $appagebuilder->buildShortCode($category->content_text);
|
||||
|
||||
foreach ($leading_blogs as $key => &$blog) {
|
||||
$blog['description'] = $appagebuilder->buildShortCode($blog['description']);
|
||||
$blog['content'] = $appagebuilder->buildShortCode($blog['content']);
|
||||
}
|
||||
}
|
||||
|
||||
$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),
|
||||
'config' => $config,
|
||||
'range' => $range,
|
||||
'category' => $category,
|
||||
'start' => $start,
|
||||
'childrens' => $childrens,
|
||||
'stop' => $stop,
|
||||
'pages_nb' => $pages_nb,
|
||||
'nb_items' => $count,
|
||||
'p' => (int)$p,
|
||||
'n' => (int)$n,
|
||||
'meta_title' => Tools::ucfirst($category->title).' - '.Configuration::get('PS_SHOP_NAME'),
|
||||
'meta_keywords' => $category->meta_keywords,
|
||||
'meta_description' => $category->meta_description,
|
||||
'requestPage' => $r['requestUrl'],
|
||||
'requestNb' => $r,
|
||||
'_listing_blog' => $_listing_blog,
|
||||
'_pagination' => $_pagination
|
||||
));
|
||||
} else {
|
||||
$this->context->smarty->assign(array(
|
||||
'active' => '0',
|
||||
'leading_blogs' => array(),
|
||||
'secondary_blogs' => array(),
|
||||
'controller' => 'category',
|
||||
'category' => $category
|
||||
));
|
||||
}
|
||||
|
||||
$this->setTemplate('module:leoblog/views/templates/front/'.$template.'/category.tpl');
|
||||
}
|
||||
|
||||
public static function parentCategories($current, &$return)
|
||||
{
|
||||
if ($current->id_parent) {
|
||||
$obj = new Leoblogcat($current->id_parent, Context::getContext()->language->id);
|
||||
self::parentCategories($obj, $return);
|
||||
}
|
||||
$return[] = $current;
|
||||
}
|
||||
|
||||
//DONGND:: add meta
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
if ($config->get('url_use_id', 1)) {
|
||||
// URL HAVE ID
|
||||
$category = new Leoblogcat((int)Tools::getValue('id'), $this->context->language->id);
|
||||
} else {
|
||||
// REMOVE ID FROM URL
|
||||
$url_rewrite = explode('/', $_SERVER['REQUEST_URI']) ;
|
||||
$url_last_item = count($url_rewrite) - 1;
|
||||
$url_rewrite = rtrim($url_rewrite[$url_last_item], '.html');
|
||||
$category = Leoblogcat::findByRewrite(array('link_rewrite' => $url_rewrite));
|
||||
}
|
||||
$page['meta']['title'] = Tools::ucfirst($category->title).' - '.Configuration::get('PS_SHOP_NAME');
|
||||
$page['meta']['keywords'] = $category->meta_keywords;
|
||||
$page['meta']['description'] = $category->meta_description;
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
//DONGND:: add breadcrumb
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$helper = LeoBlogHelper::getInstance();
|
||||
$link = $helper->getFontBlogLink();
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => $config->get('blog_link_title_'.$this->context->language->id, $this->l('Blog', 'category')),
|
||||
'url' => $link,
|
||||
);
|
||||
|
||||
if ($config->get('url_use_id', 1)) {
|
||||
// URL HAVE ID
|
||||
$category = new Leoblogcat((int)Tools::getValue('id'), $this->context->language->id);
|
||||
} else {
|
||||
// REMOVE ID FROM URL
|
||||
$url_rewrite = explode('/', $_SERVER['REQUEST_URI']) ;
|
||||
$url_last_item = count($url_rewrite) - 1;
|
||||
$url_rewrite = rtrim($url_rewrite[$url_last_item], '.html');
|
||||
$category = Leoblogcat::findByRewrite(array('link_rewrite'=>$url_rewrite));
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'rewrite' => $category->link_rewrite,
|
||||
'id' => $category->id_leoblogcat
|
||||
);
|
||||
|
||||
$category_link = $helper->getBlogCatLink($params);
|
||||
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => $category->title,
|
||||
'url' => $category_link,
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
//DONGND:: get layout
|
||||
public function getLayout()
|
||||
{
|
||||
$entity = 'module-leoblog-'.$this->php_self;
|
||||
|
||||
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
|
||||
|
||||
if ($overridden_layout = Hook::exec(
|
||||
'overrideLayoutTemplate',
|
||||
array(
|
||||
'default_layout' => $layout,
|
||||
'entity' => $entity,
|
||||
'locale' => $this->context->language->locale,
|
||||
'controller' => $this,
|
||||
)
|
||||
)) {
|
||||
return $overridden_layout;
|
||||
}
|
||||
|
||||
if ((int) Tools::getValue('content_only')) {
|
||||
$layout = 'layouts/layout-content-only.tpl';
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
}
|
||||
36
modules/leoblog/controllers/front/index.php
Normal file
36
modules/leoblog/controllers/front/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2012 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2012 PrestaShop SA
|
||||
* @version Release: $Revision: 13573 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
277
modules/leoblog/controllers/front/list.php
Normal file
277
modules/leoblog/controllers/front/list.php
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
include_once(_PS_MODULE_DIR_.'leoblog/loader.php');
|
||||
|
||||
class LeobloglistModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
public $php_self;
|
||||
protected $template_path = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->context = Context::getContext();
|
||||
$this->template_path = _PS_MODULE_DIR_.'leoblog/views/templates/front/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
// $this->php_self = 'module-leoblog-list';
|
||||
$this->php_self = 'list';
|
||||
|
||||
$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 = 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');
|
||||
|
||||
// set link demo
|
||||
if (Tools::getValue('bloglayout') != null) {
|
||||
if (is_dir(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.Tools::getValue('bloglayout'))) {
|
||||
$template = Tools::getValue('bloglayout');
|
||||
} elseif (is_dir(_PS_MODULE_DIR_ .'leoblog/views/templates/front/'.Tools::getValue('bloglayout'))) {
|
||||
$template = Tools::getValue('bloglayout');
|
||||
}
|
||||
}
|
||||
//set file include
|
||||
if (is_dir(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template) || is_dir(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template)) {
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_listing_blog.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_listing_blog.tpl')) {
|
||||
$_listing_blog = 'module:leoblog/views/templates/front/'.$template.'/_listing_blog.tpl';
|
||||
} else {
|
||||
$_listing_blog = 'module:leoblog/views/templates/front/default/_listing_blog.tpl';
|
||||
}
|
||||
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_pagination.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_pagination.tpl')) {
|
||||
$_pagination = 'module:leoblog/views/templates/front/'.$template.'/_pagination.tpl';
|
||||
} else {
|
||||
$_pagination = 'module:leoblog/views/templates/front/default/_pagination.tpl';
|
||||
}
|
||||
|
||||
if (!file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/listing.tpl') && !file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/listing.tpl')) {
|
||||
$template = 'default';
|
||||
}
|
||||
}
|
||||
|
||||
$condition = array();
|
||||
|
||||
if ($author) {
|
||||
$employee_obj = new Employee($author);
|
||||
if (isset($employee_obj) && $employee_obj->id != '') {
|
||||
$condition = array(
|
||||
'type' => 'author',
|
||||
'id_employee' => $author,
|
||||
'employee' => new Employee($author)
|
||||
);
|
||||
} else {
|
||||
$condition = array(
|
||||
'type' => 'author',
|
||||
'author_name' => $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();
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
if ($blog['author_name'] != '') {
|
||||
$blog['author'] = $blog['author_name'];
|
||||
$blog['author_link'] = $helper->getBlogAuthorLink($blog['author_name']);
|
||||
} else {
|
||||
$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']);
|
||||
}
|
||||
|
||||
if ($blog['author_name'] != '') {
|
||||
$blog['author'] = $blog['author_name'];
|
||||
$blog['author_link'] = $helper->getBlogAuthorLink($blog['author_name']);
|
||||
} else {
|
||||
$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);
|
||||
}
|
||||
|
||||
if (!isset($r)) {
|
||||
$r = $helper->getPaginationLink('module-leoblog-list', 'list', array(), false, true);
|
||||
}
|
||||
|
||||
$url_rss = '';
|
||||
$enbrss = (int)$config->get('indexation', 0);
|
||||
if ($enbrss == 1) {
|
||||
$url_rss = Tools::htmlentitiesutf8('http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__).'modules/leoblog/rss.php';
|
||||
}
|
||||
|
||||
if ((bool)Module::isEnabled('appagebuilder')) {
|
||||
$appagebuilder = Module::getInstanceByName('appagebuilder');
|
||||
|
||||
foreach ($leading_blogs as $key => &$blog) {
|
||||
$blog['description'] = $appagebuilder->buildShortCode($blog['description']);
|
||||
$blog['content'] = $appagebuilder->buildShortCode($blog['content']);
|
||||
}
|
||||
}
|
||||
$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,
|
||||
'nb_items' => $count,
|
||||
'range' => $range,
|
||||
'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, 'Blog').' - '.Configuration::get('PS_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',
|
||||
'url_rss' => $url_rss,
|
||||
'_listing_blog' => $_listing_blog,
|
||||
'_pagination' => $_pagination
|
||||
));
|
||||
$this->setTemplate('module:leoblog/views/templates/front/'.$template.'/listing.tpl');
|
||||
}
|
||||
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
$page['meta']['title'] = $config->get('meta_title_'.Context::getContext()->language->id, 'Blog').' - '.Configuration::get('PS_SHOP_NAME');
|
||||
$page['meta']['keywords'] = $config->get('meta_keywords_'.Context::getContext()->language->id);
|
||||
$page['meta']['description'] = $config->get('meta_description_'.Context::getContext()->language->id);
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$link = LeoBlogHelper::getInstance()->getFontBlogLink();
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => $config->get('blog_link_title_'.$this->context->language->id, $this->l('Blog', 'list')),
|
||||
'url' => $link,
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getLayout()
|
||||
{
|
||||
$entity = 'module-leoblog-'.$this->php_self;
|
||||
|
||||
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
|
||||
|
||||
if ($overridden_layout = Hook::exec(
|
||||
'overrideLayoutTemplate',
|
||||
array(
|
||||
'default_layout' => $layout,
|
||||
'entity' => $entity,
|
||||
'locale' => $this->context->language->locale,
|
||||
'controller' => $this,
|
||||
)
|
||||
)) {
|
||||
return $overridden_layout;
|
||||
}
|
||||
|
||||
if ((int) Tools::getValue('content_only')) {
|
||||
$layout = 'layouts/layout-content-only.tpl';
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
}
|
||||
269
modules/leoblog/controllers/front/search.php
Normal file
269
modules/leoblog/controllers/front/search.php
Normal file
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
include_once(_PS_MODULE_DIR_.'leoblog/loader.php');
|
||||
|
||||
class LeoblogsearchModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
public $php_self;
|
||||
protected $template_path = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->context = Context::getContext();
|
||||
$this->template_path = _PS_MODULE_DIR_.'leoblog/views/templates/front/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$this->php_self = 'search';
|
||||
|
||||
$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);
|
||||
|
||||
$limit = (int)$limit_leading_blogs + (int)$limit_secondary_blogs;
|
||||
$n = $limit;
|
||||
$p = abs((int)(Tools::getValue('p', 1)));
|
||||
$template = $config->get('template', 'default');
|
||||
// set link demo
|
||||
if (Tools::getValue('bloglayout') != null) {
|
||||
if (is_dir(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.Tools::getValue('bloglayout'))) {
|
||||
$template = Tools::getValue('bloglayout');
|
||||
} elseif (is_dir(_PS_MODULE_DIR_ .'leoblog/views/templates/front/'.Tools::getValue('bloglayout'))) {
|
||||
$template = Tools::getValue('bloglayout');
|
||||
}
|
||||
}
|
||||
//set file include
|
||||
if (is_dir(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template) || is_dir(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template)) {
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_listing_blog.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_listing_blog.tpl')) {
|
||||
$_listing_blog = 'module:leoblog/views/templates/front/'.$template.'/_listing_blog.tpl';
|
||||
} else {
|
||||
$_listing_blog = 'module:leoblog/views/templates/front/default/_listing_blog.tpl';
|
||||
}
|
||||
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/_pagination.tpl') || file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/_pagination.tpl')) {
|
||||
$_pagination = 'module:leoblog/views/templates/front/'.$template.'/_pagination.tpl';
|
||||
} else {
|
||||
$_pagination = 'module:leoblog/views/templates/front/default/_pagination.tpl';
|
||||
}
|
||||
|
||||
if (!file_exists(_PS_THEME_DIR_.'modules/leoblog/views/templates/front/'.$template.'/search.tpl') && !file_exists(_PS_MODULE_DIR_.'leoblog/views/templates/front/'.$template.'/search.tpl')) {
|
||||
$template = 'default';
|
||||
}
|
||||
}
|
||||
|
||||
// $blogs = LeoBlogBlog::getListBlogs(null, $this->context->language->id, $n, $n, 'id_leoblog_blog', 'DESC', array(), true);
|
||||
$count = LeoBlogBlog::countBlogs(null, $this->context->language->id, true);
|
||||
|
||||
if (Tools::getValue('search_blog') == 'Best_articles') {
|
||||
$blogs = LeoBlogBlog::getListBlogs(null, $this->context->language->id, $p, $n, 'hits', 'DESC', array(), true);
|
||||
} elseif (Tools::getValue('search_blog') == 'Latest_articles') {
|
||||
$blogs = LeoBlogBlog::getListBlogs(null, $this->context->language->id, $p, $n, 'date_add', 'DESC', array(), true);
|
||||
} elseif (Tools::getValue('search_blog') == 'Articles_favorite') {
|
||||
$blogs = LeoBlogBlog::getListBlogs(null, $this->context->language->id, $p, $n, 'favorite', 'DESC', array('favorite' => 1), true);
|
||||
$count = LeoBlogBlog::countBlogs(null, $this->context->language->id, array('favorite' => 1), true);
|
||||
} elseif (Tools::getValue('search_blog') != '') {
|
||||
$blogs = LeoBlogBlog::getListBlogs(null, $this->context->language->id, $p, $n, 'id_leoblog_blog', 'DESC', array('search' => Tools::getValue('search_blog')), true);
|
||||
$count = LeoBlogBlog::countBlogs(null, $this->context->language->id, array('search' => Tools::getValue('search_blog')), true);
|
||||
} else {
|
||||
$blogs = LeoBlogBlog::getListBlogs(null, $this->context->language->id, $p, $n, 'id_leoblog_blog', 'DESC', array(), true);
|
||||
}
|
||||
|
||||
// print_r($count);die;
|
||||
|
||||
$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']);
|
||||
}
|
||||
|
||||
if ($blog['author_name'] != '') {
|
||||
$blog['author'] = $blog['author_name'];
|
||||
$blog['author_link'] = $helper->getBlogAuthorLink($blog['author_name']);
|
||||
} else {
|
||||
$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']);
|
||||
}
|
||||
|
||||
if ($blog['author_name'] != '') {
|
||||
$blog['author'] = $blog['author_name'];
|
||||
$blog['author_link'] = $helper->getBlogAuthorLink($blog['author_name']);
|
||||
} else {
|
||||
$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);
|
||||
}
|
||||
|
||||
$r = $helper->getPaginationLink('module-leoblog-search', 'search', array(), false, true);
|
||||
|
||||
if ((bool)Module::isEnabled('appagebuilder')) {
|
||||
$appagebuilder = Module::getInstanceByName('appagebuilder');
|
||||
|
||||
foreach ($leading_blogs as $key => &$blog) {
|
||||
$blog['description'] = $appagebuilder->buildShortCode($blog['description']);
|
||||
$blog['content'] = $appagebuilder->buildShortCode($blog['content']);
|
||||
}
|
||||
}
|
||||
|
||||
$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),
|
||||
'title_page' => Tools::str_replace_once('_', ' ', Tools::getValue('search_blog')),
|
||||
'nb_items' => $count,
|
||||
'range' => $range,
|
||||
'start' => $start,
|
||||
'stop' => $stop,
|
||||
'pages_nb' => $pages_nb,
|
||||
'config' => $config,
|
||||
'p' => (int)$p,
|
||||
'n' => (int)$n,
|
||||
'meta_title' => 'Blog Search - '.Configuration::get('PS_SHOP_NAME'),
|
||||
'meta_keywords' => $config->get('meta_keywords_'.Context::getContext()->language->id),
|
||||
'meta_description' => $config->get('meta_description_'.Context::getContext()->language->id),
|
||||
'requestPage' => Context::getContext()->link->getModuleLink('leoblog', 'search', array()).'?search_blog='.Tools::getValue('search_blog'),
|
||||
'requestNb' => $r,
|
||||
'_listing_blog' => $_listing_blog,
|
||||
'_pagination' => $_pagination
|
||||
|
||||
));
|
||||
$this->setTemplate('module:leoblog/views/templates/front/'.$template.'/search.tpl');
|
||||
}
|
||||
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
$page['meta']['title'] = 'Blog Search - '.Configuration::get('PS_SHOP_NAME');
|
||||
$page['meta']['keywords'] = $config->get('meta_keywords_'.Context::getContext()->language->id);
|
||||
$page['meta']['description'] = $config->get('meta_description_'.Context::getContext()->language->id);
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$helper = LeoBlogHelper::getInstance();
|
||||
$link = $helper->getFontBlogLink();
|
||||
$config = LeoBlogConfig::getInstance();
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => $config->get('blog_link_title_'.$this->context->language->id, $this->l('Blog', 'search')),
|
||||
'url' => $link,
|
||||
);
|
||||
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => 'Search',
|
||||
'url' => Context::getContext()->link->getModuleLink('leoblog', 'search', array()),
|
||||
);
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getLayout()
|
||||
{
|
||||
$entity = 'module-leoblog-'.$this->php_self;
|
||||
|
||||
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
|
||||
|
||||
if ($overridden_layout = Hook::exec(
|
||||
'overrideLayoutTemplate',
|
||||
array(
|
||||
'default_layout' => $layout,
|
||||
'entity' => $entity,
|
||||
'locale' => $this->context->language->locale,
|
||||
'controller' => $this,
|
||||
)
|
||||
)) {
|
||||
return $overridden_layout;
|
||||
}
|
||||
|
||||
if ((int) Tools::getValue('content_only')) {
|
||||
$layout = 'layouts/layout-content-only.tpl';
|
||||
}
|
||||
if (Configuration::get('LEOBLOG_COLUMN_POSITION') == 'left') {
|
||||
$layout = 'layouts/layout-left-column.tpl';
|
||||
} else {
|
||||
$layout = 'layouts/layout-right-column.tpl';
|
||||
}
|
||||
return $layout;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user