first commit
This commit is contained in:
62
modules/ph_simpleblog/controllers/front/ajax.php
Normal file
62
modules/ph_simpleblog/controllers/front/ajax.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
require_once _PS_MODULE_DIR_ . 'ph_simpleblog/ph_simpleblog.php';
|
||||
|
||||
class Ph_SimpleBlogAjaxModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
public $product;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Module::isEnabled('ph_simpleblog')
|
||||
&& (Tools::getValue('action') == 'addRating' || Tools::getValue('action') == 'removeRating')
|
||||
&& Tools::getValue('secure_key') == $this->module->secure_key) {
|
||||
parent::postProcess();
|
||||
} else {
|
||||
die('Access denied');
|
||||
}
|
||||
}
|
||||
|
||||
public function displayAjaxAddRating()
|
||||
{
|
||||
$id_simpleblog_post = Tools::getValue('id_simpleblog_post');
|
||||
$reply = SimpleBlogPost::changeRating('up', (int) $id_simpleblog_post);
|
||||
$message = $reply[0]['likes'];
|
||||
$this->ajaxDie(
|
||||
json_encode(
|
||||
array(
|
||||
'hasError' => false,
|
||||
'status' => 'success',
|
||||
'message' => $message
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function displayAjaxRemoveRating()
|
||||
{
|
||||
$id_simpleblog_post = Tools::getValue('id_simpleblog_post');
|
||||
$reply = SimpleBlogPost::changeRating('down', (int) $id_simpleblog_post);
|
||||
$message = $reply[0]['likes'];
|
||||
$this->ajaxDie(
|
||||
json_encode(
|
||||
array(
|
||||
'hasError' => false,
|
||||
'status' => 'success',
|
||||
'message' => $message
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
76
modules/ph_simpleblog/controllers/front/author-v16.php
Normal file
76
modules/ph_simpleblog/controllers/front/author-v16.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
|
||||
class PH_SimpleBlogAuthorModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
protected $SimpleBlogAuthor;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// Get Post by link_rewrite
|
||||
$id_simpleblog_author = Tools::getValue('author_id');
|
||||
|
||||
|
||||
if ($id_simpleblog_author && Validate::isUnsignedInt($id_simpleblog_author)) {
|
||||
$author = new SimpleBlogPostAuthor($id_simpleblog_author, (int) Context::getContext()->language->id);
|
||||
if (!Validate::isLoadedObject($author)) {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
} else {
|
||||
$this->SimpleBlogAuthor = $author;
|
||||
}
|
||||
} else {
|
||||
die('Blog for PrestaShop: URL is not valid');
|
||||
}
|
||||
|
||||
|
||||
// Assign meta tags
|
||||
$this->assignMetas();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
// Assign JS and CSS for single post page
|
||||
$this->addModulePageAssets();
|
||||
|
||||
parent::initContent();
|
||||
|
||||
// Smarty variables
|
||||
$this->context->smarty->assign('is_16', true);
|
||||
$this->context->smarty->assign('author', $this->SimpleBlogAuthor);
|
||||
|
||||
$this->setTemplate('author.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign meta tags to single post page.
|
||||
*/
|
||||
protected function assignMetas()
|
||||
{
|
||||
$this->context->smarty->assign('meta_title', sprintf($this->module->l('Posts by %s', 'author-v16'), $this->SimpleBlogAuthor->firstname));
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS, JS and other assets for this page.
|
||||
*/
|
||||
protected function addModulePageAssets()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return SimpleBlogPost object
|
||||
* @return object
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->SimpleBlogAuthor;
|
||||
}
|
||||
}
|
||||
76
modules/ph_simpleblog/controllers/front/author-v17.php
Normal file
76
modules/ph_simpleblog/controllers/front/author-v17.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
|
||||
class PH_SimpleBlogAuthorModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
protected $SimpleBlogAuthor;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// Get Post by link_rewrite
|
||||
$id_simpleblog_author = Tools::getValue('author_id');
|
||||
|
||||
|
||||
if ($id_simpleblog_author && Validate::isUnsignedInt($id_simpleblog_author)) {
|
||||
$author = new SimpleBlogPostAuthor($id_simpleblog_author, (int) Context::getContext()->language->id);
|
||||
if (!Validate::isLoadedObject($author)) {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
} else {
|
||||
$this->SimpleBlogAuthor = $author;
|
||||
}
|
||||
} else {
|
||||
die('Blog for PrestaShop: URL is not valid');
|
||||
}
|
||||
|
||||
|
||||
// Assign meta tags
|
||||
$this->assignMetas();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
// Assign JS and CSS for single post page
|
||||
$this->addModulePageAssets();
|
||||
|
||||
parent::initContent();
|
||||
|
||||
// Smarty variables
|
||||
$this->context->smarty->assign('is_16', true);
|
||||
$this->context->smarty->assign('author', $this->SimpleBlogAuthor);
|
||||
|
||||
$this->setTemplate('author.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign meta tags to single post page.
|
||||
*/
|
||||
protected function assignMetas()
|
||||
{
|
||||
$this->context->smarty->assign('meta_title', sprintf($this->module->l('Posts by %s', 'author-v16'), $this->SimpleBlogAuthor->firstname));
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS, JS and other assets for this page.
|
||||
*/
|
||||
protected function addModulePageAssets()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return SimpleBlogPost object
|
||||
* @return object
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->SimpleBlogAuthor;
|
||||
}
|
||||
}
|
||||
15
modules/ph_simpleblog/controllers/front/author.php
Normal file
15
modules/ph_simpleblog/controllers/front/author.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/ph_simpleblog.php';
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
include_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/author-v17.php';
|
||||
} else {
|
||||
include_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/author-v16.php';
|
||||
}
|
||||
52
modules/ph_simpleblog/controllers/front/authorslist-v16.php
Normal file
52
modules/ph_simpleblog/controllers/front/authorslist-v16.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
|
||||
class PH_SimpleBlogAuthorsListModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
protected $blogAuthors;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->blogAuthors = SimpleBlogPostAuthor::getAll();
|
||||
|
||||
// Assign meta tags
|
||||
$this->assignMetas();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
// Assign JS and CSS for single post page
|
||||
$this->addModulePageAssets();
|
||||
|
||||
parent::initContent();
|
||||
|
||||
$this->context->smarty->assign('authors', $this->blogAuthors);
|
||||
|
||||
$this->setTemplate('authors.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign meta tags to single post page.
|
||||
*/
|
||||
protected function assignMetas()
|
||||
{
|
||||
$defaultMetaTitleForBlog = Configuration::get('PH_BLOG_MAIN_TITLE', $this->context->language->id);
|
||||
$this->context->smarty->assign('meta_title', $defaultMetaTitleForBlog.' - '.$this->module->l('Authors', 'authorslist-v16'));
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS, JS and other assets for this page.
|
||||
*/
|
||||
protected function addModulePageAssets()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
76
modules/ph_simpleblog/controllers/front/authorslist-v17.php
Normal file
76
modules/ph_simpleblog/controllers/front/authorslist-v17.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
|
||||
class PH_SimpleBlogAuthorModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
protected $SimpleBlogAuthor;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// Get Post by link_rewrite
|
||||
$id_simpleblog_author = Tools::getValue('author_id');
|
||||
|
||||
|
||||
if ($id_simpleblog_author && Validate::isUnsignedInt($id_simpleblog_author)) {
|
||||
$author = new SimpleBlogPostAuthor($id_simpleblog_author, (int) Context::getContext()->language->id);
|
||||
if (!Validate::isLoadedObject($author)) {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
} else {
|
||||
$this->SimpleBlogAuthor = $author;
|
||||
}
|
||||
} else {
|
||||
die('Blog for PrestaShop: URL is not valid');
|
||||
}
|
||||
|
||||
|
||||
// Assign meta tags
|
||||
$this->assignMetas();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
// Assign JS and CSS for single post page
|
||||
$this->addModulePageAssets();
|
||||
|
||||
parent::initContent();
|
||||
|
||||
// Smarty variables
|
||||
$this->context->smarty->assign('is_16', true);
|
||||
$this->context->smarty->assign('author', $this->SimpleBlogAuthor);
|
||||
|
||||
$this->setTemplate('author.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign meta tags to single post page.
|
||||
*/
|
||||
protected function assignMetas()
|
||||
{
|
||||
$this->context->smarty->assign('meta_title', sprintf($this->module->l('Posts by %s', 'author-v16'), $this->SimpleBlogAuthor->firstname));
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS, JS and other assets for this page.
|
||||
*/
|
||||
protected function addModulePageAssets()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return SimpleBlogPost object
|
||||
* @return object
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->SimpleBlogAuthor;
|
||||
}
|
||||
}
|
||||
15
modules/ph_simpleblog/controllers/front/authorslist.php
Normal file
15
modules/ph_simpleblog/controllers/front/authorslist.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/ph_simpleblog.php';
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
include_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/authorslist-v17.php';
|
||||
} else {
|
||||
include_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/authorslist-v16.php';
|
||||
}
|
||||
14
modules/ph_simpleblog/controllers/front/category.php
Normal file
14
modules/ph_simpleblog/controllers/front/category.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2014-2017 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/ph_simpleblog.php';
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/list.php';
|
||||
|
||||
class PH_SimpleBlogCategoryModuleFrontController extends ph_simplebloglistModuleFrontController
|
||||
{
|
||||
}
|
||||
23
modules/ph_simpleblog/controllers/front/categorypage.php
Normal file
23
modules/ph_simpleblog/controllers/front/categorypage.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2014-2017 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/ph_simpleblog.php';
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/list.php';
|
||||
|
||||
class PH_SimpleBlogCategoryPageModuleFrontController extends ph_simplebloglistModuleFrontController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if (!version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
$this->display_column_left = (is_object(Context::getContext()->theme) ? Context::getContext()->theme->hasLeftColumn('module-ph_simpleblog-list') : true);
|
||||
$this->display_column_right = (is_object(Context::getContext()->theme) ? Context::getContext()->theme->hasRightColumn('module-ph_simpleblog-list') : true);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
modules/ph_simpleblog/controllers/front/index.php
Normal file
35
modules/ph_simpleblog/controllers/front/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 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-2013 PrestaShop SA
|
||||
* @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;
|
||||
219
modules/ph_simpleblog/controllers/front/list-v16.php
Normal file
219
modules/ph_simpleblog/controllers/front/list-v16.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
|
||||
class PH_SimpleBlogListModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
public $context;
|
||||
public $sb_category = false;
|
||||
public $simpleblog_search;
|
||||
public $simpleblog_keyword;
|
||||
public $is_search = false;
|
||||
public $is_category = false;
|
||||
|
||||
public $posts_per_page;
|
||||
public $n;
|
||||
public $p;
|
||||
|
||||
private $blogCategory;
|
||||
|
||||
private $listController;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$sb_category = Tools::getValue('sb_category');
|
||||
$simpleblog_search = Tools::getValue('simpleblog_search');
|
||||
$simpleblog_keyword = Tools::getValue('simpleblog_keyword');
|
||||
$this->listController = Tools::getValue('controller');
|
||||
|
||||
if ($sb_category) {
|
||||
$this->sb_category = $sb_category;
|
||||
$this->is_category = true;
|
||||
}
|
||||
|
||||
if ($this->listController == 'category' && !$this->sb_category) {
|
||||
Tools::redirect($this->context->link->getModuleLink('ph_simpleblog', 'list'));
|
||||
}
|
||||
|
||||
if ($simpleblog_search && $simpleblog_keyword) {
|
||||
$this->simpleblog_search = $simpleblog_search;
|
||||
$this->simpleblog_keyword = $simpleblog_keyword;
|
||||
$this->is_search = true;
|
||||
}
|
||||
|
||||
$this->posts_per_page = Configuration::get('PH_BLOG_POSTS_PER_PAGE');
|
||||
$this->p = (int) Tools::getValue('p', 0);
|
||||
|
||||
$this->context = Context::getContext();
|
||||
}
|
||||
|
||||
public function assignGeneralPurposesVariables()
|
||||
{
|
||||
$gridType = Configuration::get('PH_BLOG_COLUMNS');
|
||||
$gridColumns = Configuration::get('PH_BLOG_GRID_COLUMNS');
|
||||
$blogLayout = Configuration::get('PH_BLOG_LIST_LAYOUT');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'categories' => SimpleBlogCategory::getCategories((int) $this->context->language->id),
|
||||
'blogMainTitle' => Configuration::get('PH_BLOG_MAIN_TITLE', (int) $this->context->language->id),
|
||||
'grid' => Configuration::get('PH_BLOG_COLUMNS'),
|
||||
'columns' => $gridColumns,
|
||||
'blogLayout' => $blogLayout,
|
||||
'module_dir' => _MODULE_DIR_.'ph_simpleblog/',
|
||||
'tpl_path' => _PS_MODULE_DIR_.'ph_simpleblog/views/templates/front/',
|
||||
'gallery_dir' => _MODULE_DIR_.'ph_simpleblog/galleries/',
|
||||
'is_category' => false,
|
||||
'is_search' => false,
|
||||
'shopLogo' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_LOGO')),
|
||||
'shopUrl' => $this->context->shop->getBaseURL(true, false),
|
||||
));
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$id_lang = $this->context->language->id;
|
||||
|
||||
parent::initContent();
|
||||
|
||||
$this->context->smarty->assign('is_16', (bool) (version_compare(_PS_VERSION_, '1.6.0', '>=') === true));
|
||||
|
||||
$this->assignGeneralPurposesVariables();
|
||||
|
||||
// Category things
|
||||
if ($this->sb_category != '') {
|
||||
$this->context->smarty->assign('is_category', true);
|
||||
|
||||
$SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, $id_lang);
|
||||
|
||||
// Category not found so now we are looking for categories in same rewrite but other languages and if we found something, then we redirect 301
|
||||
if (!Validate::isLoadedObject($SimpleBlogCategory)) {
|
||||
$SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, false);
|
||||
|
||||
if (Validate::isLoadedObject($SimpleBlogCategory)) {
|
||||
$SimpleBlogCategory = new SimpleBlogCategory($SimpleBlogCategory->id, $id_lang);
|
||||
header('HTTP/1.1 301 Moved Permanently');
|
||||
header('Location: '.SimpleBlogCategory::getLink($SimpleBlogCategory->link_rewrite));
|
||||
} else {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header('Status: 404 Not Found');
|
||||
Tools::redirect($this->context->link->getPageLink('404'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->blogCategory = $SimpleBlogCategory;
|
||||
|
||||
if ($SimpleBlogCategory->id_parent > 0) {
|
||||
$parent = new SimpleBlogCategory($SimpleBlogCategory->id_parent, $id_lang);
|
||||
$this->context->smarty->assign('parent_category', $parent);
|
||||
}
|
||||
|
||||
$finder = new BlogPostsFinder();
|
||||
$finder->setIdCategory($SimpleBlogCategory->id);
|
||||
$posts = $finder->findPosts();
|
||||
|
||||
$this->context->smarty->assign('blogCategory', $SimpleBlogCategory);
|
||||
$this->context->smarty->assign('category_rewrite', $SimpleBlogCategory->link_rewrite);
|
||||
} else {
|
||||
$finder = new BlogPostsFinder();
|
||||
$posts = $finder->findPosts();
|
||||
}
|
||||
|
||||
$this->assignPagination($this->posts_per_page, sizeof($posts));
|
||||
$posts = array_splice($posts, $this->p ? ($this->p - 1) * $this->posts_per_page : 0, $this->posts_per_page);
|
||||
|
||||
$this->assignMetas();
|
||||
|
||||
$this->context->smarty->assign('posts', $posts);
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
$this->setTemplate('module:ph_simpleblog/views/templates/front/1.7/list.tpl');
|
||||
} else {
|
||||
$this->setTemplate('list.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
public function assignMetas()
|
||||
{
|
||||
$defaultMetaTitleForBlog = Configuration::get('PH_BLOG_MAIN_TITLE', $this->context->language->id);
|
||||
$defaultMetaDescriptionForBlog = Configuration::get('PH_BLOG_MAIN_META_DESCRIPTION', $this->context->language->id);
|
||||
|
||||
if ($this->sb_category) {
|
||||
$meta_title = $this->blogCategory->name.' - '.Configuration::get('PS_SHOP_NAME');
|
||||
} else {
|
||||
if (empty($defaultMetaTitleForBlog)) {
|
||||
$meta_title = Configuration::get('PS_SHOP_NAME').' - '.$this->module->l('Blog', 'list-v16');
|
||||
} else {
|
||||
$meta_title = $defaultMetaTitleForBlog;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->sb_category) {
|
||||
if (!empty($this->blogCategory->meta_description)) {
|
||||
$meta_description = $this->blogCategory->meta_description;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->p > 1) {
|
||||
$meta_title .= ' ('.$this->p.')';
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('meta_title', $meta_title);
|
||||
|
||||
if (!empty($meta_description)) {
|
||||
$this->context->smarty->assign('meta_description', strip_tags($meta_description));
|
||||
}
|
||||
}
|
||||
|
||||
public function assignPagination($limit, $nbPosts)
|
||||
{
|
||||
$this->n = $limit;
|
||||
$this->p = abs((int) Tools::getValue('p', 1));
|
||||
|
||||
$current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
|
||||
//delete parameter page
|
||||
$current_url = preg_replace('/(\?)?(&)?p=\d+/', '$1', $current_url);
|
||||
|
||||
$range = 2; /* how many pages around page selected */
|
||||
|
||||
if ($this->p < 1) {
|
||||
$this->p = 1;
|
||||
}
|
||||
|
||||
$pages_nb = ceil($nbPosts / (int) $this->n);
|
||||
|
||||
$start = (int) ($this->p - $range);
|
||||
|
||||
if ($start < 1) {
|
||||
$start = 1;
|
||||
}
|
||||
$stop = (int) ($this->p + $range);
|
||||
|
||||
if ($stop > $pages_nb) {
|
||||
$stop = (int) $pages_nb;
|
||||
}
|
||||
$this->context->smarty->assign('nb_posts', $nbPosts);
|
||||
$pagination_infos = array(
|
||||
'products_per_page' => $limit,
|
||||
'pages_nb' => $pages_nb,
|
||||
'p' => $this->p,
|
||||
'n' => $this->n,
|
||||
'range' => $range,
|
||||
'start' => $start,
|
||||
'stop' => $stop,
|
||||
'current_url' => $current_url,
|
||||
);
|
||||
$this->context->smarty->assign($pagination_infos);
|
||||
}
|
||||
|
||||
public function getBlogCategory()
|
||||
{
|
||||
return $this->blogCategory;
|
||||
}
|
||||
}
|
||||
287
modules/ph_simpleblog/controllers/front/list-v17.php
Normal file
287
modules/ph_simpleblog/controllers/front/list-v17.php
Normal file
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
|
||||
class PH_SimpleBlogListModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
public $context;
|
||||
public $sb_category = false;
|
||||
public $simpleblog_search;
|
||||
public $simpleblog_keyword;
|
||||
public $is_search = false;
|
||||
public $is_category = false;
|
||||
|
||||
public $posts_per_page;
|
||||
public $n;
|
||||
public $p;
|
||||
|
||||
private $blogCategory;
|
||||
|
||||
private $listController;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$sb_category = Tools::getValue('sb_category');
|
||||
$module_controller = Tools::getValue('controller');
|
||||
$simpleblog_search = Tools::getValue('simpleblog_search');
|
||||
$simpleblog_keyword = Tools::getValue('simpleblog_keyword');
|
||||
$this->listController = Tools::getValue('controller');
|
||||
|
||||
if ($sb_category) {
|
||||
$this->sb_category = $sb_category;
|
||||
$this->is_category = true;
|
||||
}
|
||||
|
||||
|
||||
if ($this->listController == 'category' && !$this->sb_category) {
|
||||
Tools::redirect($this->context->link->getModuleLink('ph_simpleblog', 'list'));
|
||||
}
|
||||
|
||||
if ($simpleblog_search && $simpleblog_keyword) {
|
||||
$this->simpleblog_search = $simpleblog_search;
|
||||
$this->simpleblog_keyword = $simpleblog_keyword;
|
||||
$this->is_search = true;
|
||||
}
|
||||
|
||||
$this->posts_per_page = Configuration::get('PH_BLOG_POSTS_PER_PAGE');
|
||||
$this->p = (int) Tools::getValue('p', 0);
|
||||
|
||||
$this->context = Context::getContext();
|
||||
}
|
||||
|
||||
public function assignGeneralPurposesVariables()
|
||||
{
|
||||
$gridType = Configuration::get('PH_BLOG_COLUMNS');
|
||||
$gridColumns = Configuration::get('PH_BLOG_GRID_COLUMNS');
|
||||
$blogLayout = Configuration::get('PH_BLOG_LIST_LAYOUT');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'categories' => SimpleBlogCategory::getCategories((int) $this->context->language->id),
|
||||
'blogMainTitle' => Configuration::get('PH_BLOG_MAIN_TITLE', (int) $this->context->language->id),
|
||||
'grid' => Configuration::get('PH_BLOG_COLUMNS'),
|
||||
'columns' => $gridColumns,
|
||||
'blogLayout' => $blogLayout,
|
||||
'module_dir' => _MODULE_DIR_.'ph_simpleblog/',
|
||||
'tpl_path' => _PS_MODULE_DIR_.'ph_simpleblog/views/templates/front/',
|
||||
'gallery_dir' => _MODULE_DIR_.'ph_simpleblog/galleries/',
|
||||
'is_category' => $this->is_category,
|
||||
'is_search' => $this->is_search,
|
||||
));
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$id_lang = $this->context->language->id;
|
||||
|
||||
parent::initContent();
|
||||
|
||||
$this->context->smarty->assign('is_16', (bool) (version_compare(_PS_VERSION_, '1.6.0', '>=') === true));
|
||||
|
||||
$this->assignGeneralPurposesVariables();
|
||||
|
||||
// Category things
|
||||
if ($this->sb_category != '') {
|
||||
$SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, $id_lang);
|
||||
|
||||
// Category not found so now we are looking for categories in same rewrite but other languages and if we found something, then we redirect 301
|
||||
if (!Validate::isLoadedObject($SimpleBlogCategory)) {
|
||||
$SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, false);
|
||||
|
||||
if (Validate::isLoadedObject($SimpleBlogCategory)) {
|
||||
$SimpleBlogCategory = new SimpleBlogCategory($SimpleBlogCategory->id, $id_lang);
|
||||
header('HTTP/1.1 301 Moved Permanently');
|
||||
header('Location: '.SimpleBlogCategory::getLink($SimpleBlogCategory->link_rewrite));
|
||||
} else {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header('Status: 404 Not Found');
|
||||
Tools::redirect($this->context->link->getPageLink('404'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->blogCategory = $SimpleBlogCategory;
|
||||
|
||||
if ($SimpleBlogCategory->id_parent > 0) {
|
||||
$parent = new SimpleBlogCategory($SimpleBlogCategory->id_parent, $id_lang);
|
||||
$this->context->smarty->assign('parent_category', $parent);
|
||||
}
|
||||
|
||||
$finder = new BlogPostsFinder();
|
||||
$finder->setIdCategory($SimpleBlogCategory->id);
|
||||
$posts = $finder->findPosts();
|
||||
|
||||
$this->context->smarty->assign('blogCategory', $SimpleBlogCategory);
|
||||
$this->context->smarty->assign('category_rewrite', $SimpleBlogCategory->link_rewrite);
|
||||
} elseif ($this->is_search) {
|
||||
// @todo: complete refactoring "authors" to 2.0.0
|
||||
// Posts by author
|
||||
$this->context->smarty->assign('is_search', true);
|
||||
|
||||
// echo SimpleBlogPost::getSearchLink('author', 'kpodemski', $id_lang);
|
||||
// @todo: meta titles, blog title, specific layout
|
||||
switch ($this->simpleblog_search) {
|
||||
case 'author':
|
||||
break;
|
||||
case 'tag':
|
||||
break;
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('meta_title', $this->l('Posts by', 'list-v17').' '.$this->simpleblog_author.' - '.$this->l('Blog', 'list-v17'));
|
||||
|
||||
$posts = SimpleBlogPost::findPosts($this->simpleblog_search, $this->simpleblog_keyword, $id_lang, $this->posts_per_page, $this->p);
|
||||
|
||||
$this->assignPagination($this->posts_per_page, sizeof(SimpleBlogPost::findPosts($this->simpleblog_search, $this->simpleblog_keyword, $id_lang)));
|
||||
|
||||
$this->context->smarty->assign('posts', $posts);
|
||||
} else {
|
||||
$finder = new BlogPostsFinder();
|
||||
$posts = $finder->findPosts();
|
||||
// if (Tools::getValue('y', 0)) {
|
||||
// // archive
|
||||
// $ids = [];
|
||||
|
||||
// foreach ($posts as $key => $post) {
|
||||
// $dateAdd = strtotime($post['date_add']);
|
||||
// if (date('Y', $dateAdd) != (int) Tools::getValue('y')) {
|
||||
// unset($posts[$key]);
|
||||
// } else {
|
||||
// $ids[] = $post['id_simpleblog_post'];
|
||||
// }
|
||||
// }
|
||||
|
||||
// $posts = SimpleBlogPost::getPosts($id_lang, $this->posts_per_page, null, $this->p, true, false, false, null, false, false, null, 'IN', $ids);
|
||||
// } else {
|
||||
// $posts = SimpleBlogPost::getPosts($id_lang, $this->posts_per_page, null, $this->p);
|
||||
// }
|
||||
}
|
||||
|
||||
$this->assignPagination($this->posts_per_page, sizeof($posts));
|
||||
$posts = array_splice($posts, $this->p ? ($this->p - 1) * $this->posts_per_page : 0, $this->posts_per_page);
|
||||
|
||||
$this->assignMetas();
|
||||
|
||||
$this->context->smarty->assign('posts', $posts);
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
$this->setTemplate('module:ph_simpleblog/views/templates/front/1.7/list.tpl');
|
||||
} else {
|
||||
$this->setTemplate('list.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
public function assignMetas()
|
||||
{
|
||||
$pageVariables = $this->getTemplateVarPage();
|
||||
$defaultMetaTitleForBlog = Configuration::get('PH_BLOG_MAIN_TITLE', $this->context->language->id);
|
||||
$defaultMetaDescriptionForBlog = Configuration::get('PH_BLOG_MAIN_META_DESCRIPTION', $this->context->language->id);
|
||||
|
||||
if ($this->sb_category) {
|
||||
$meta_title = $this->blogCategory->name.' - '.$pageVariables['meta']['title'];
|
||||
if (!empty($this->blogCategory->meta_title)) {
|
||||
$meta_title = $this->blogCategory->meta_title.' - '.$pageVariables['meta']['title'];
|
||||
}
|
||||
} else {
|
||||
if (empty($defaultMetaTitleForBlog)) {
|
||||
$meta_title = $pageVariables['meta']['title'].' '.$this->l('Blog', 'list-v17');
|
||||
} else {
|
||||
$meta_title = $defaultMetaTitleForBlog;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->sb_category) {
|
||||
if (!empty($this->blogCategory->meta_description)) {
|
||||
$meta_description = $this->blogCategory->meta_description;
|
||||
} else {
|
||||
$meta_description = $pageVariables['meta']['description'];
|
||||
}
|
||||
} else {
|
||||
$meta_description = empty($defaultMetaDescriptionForBlog) ? $pageVariables['meta']['description'] : $defaultMetaDescriptionForBlog;
|
||||
}
|
||||
|
||||
if ($this->p > 1) {
|
||||
$meta_title .= ' ('.$this->p.')';
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('meta_title', $meta_title);
|
||||
$this->context->smarty->assign('meta_description', strip_tags($meta_description));
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$id_lang = $this->context->language->id;
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->l('Blog'),
|
||||
'url' => $this->context->link->getModuleLink('ph_simpleblog', 'list'),
|
||||
];
|
||||
|
||||
if ($this->sb_category != '') {
|
||||
$SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, $id_lang);
|
||||
// Category not found so now we looking for categories in same rewrite but other languages and if we found then we redirect 301
|
||||
if (!Validate::isLoadedObject($SimpleBlogCategory)) {
|
||||
$SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, false);
|
||||
}
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $SimpleBlogCategory->name,
|
||||
'url' => $SimpleBlogCategory->link_rewrite,
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function assignPagination($limit, $nbPosts)
|
||||
{
|
||||
$this->n = $limit;
|
||||
$this->p = abs((int) Tools::getValue('p', 1));
|
||||
|
||||
$current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
|
||||
//delete parameter page
|
||||
$current_url = preg_replace('/(\?)?(&)?p=\d+/', '$1', $current_url);
|
||||
|
||||
$range = 2; /* how many pages around page selected */
|
||||
|
||||
if ($this->p < 1) {
|
||||
$this->p = 1;
|
||||
}
|
||||
|
||||
$pages_nb = ceil($nbPosts / (int) $this->n);
|
||||
|
||||
$start = (int) ($this->p - $range);
|
||||
|
||||
if ($start < 1) {
|
||||
$start = 1;
|
||||
}
|
||||
$stop = (int) ($this->p + $range);
|
||||
|
||||
if ($stop > $pages_nb) {
|
||||
$stop = (int) $pages_nb;
|
||||
}
|
||||
$this->context->smarty->assign('nb_posts', $nbPosts);
|
||||
$pagination_infos = array(
|
||||
'products_per_page' => $limit,
|
||||
'pages_nb' => $pages_nb,
|
||||
'p' => $this->p,
|
||||
'n' => $this->n,
|
||||
'range' => $range,
|
||||
'start' => $start,
|
||||
'stop' => $stop,
|
||||
'current_url' => $current_url,
|
||||
);
|
||||
$this->context->smarty->assign($pagination_infos);
|
||||
}
|
||||
|
||||
public function getBlogCategory()
|
||||
{
|
||||
return $this->blogCategory;
|
||||
}
|
||||
}
|
||||
15
modules/ph_simpleblog/controllers/front/list.php
Normal file
15
modules/ph_simpleblog/controllers/front/list.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/ph_simpleblog.php';
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
include_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/list-v17.php';
|
||||
} else {
|
||||
include_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/list-v16.php';
|
||||
}
|
||||
23
modules/ph_simpleblog/controllers/front/page.php
Normal file
23
modules/ph_simpleblog/controllers/front/page.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2014-2017 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/ph_simpleblog.php';
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/list.php';
|
||||
|
||||
class ph_simpleblogpageModuleFrontController extends ph_simplebloglistModuleFrontController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if (!version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
$this->display_column_left = (is_object(Context::getContext()->theme) ? Context::getContext()->theme->hasLeftColumn('module-ph_simpleblog-list') : true);
|
||||
$this->display_column_right = (is_object(Context::getContext()->theme) ? Context::getContext()->theme->hasRightColumn('module-ph_simpleblog-list') : true);
|
||||
}
|
||||
}
|
||||
}
|
||||
301
modules/ph_simpleblog/controllers/front/single-v16.php
Normal file
301
modules/ph_simpleblog/controllers/front/single-v16.php
Normal file
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
|
||||
class PH_SimpleBlogSingleModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
protected $SimpleBlogPost;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// Get Post by link_rewrite
|
||||
$simpleblog_post_rewrite = Tools::getValue('rewrite');
|
||||
|
||||
if ($simpleblog_post_rewrite && Validate::isLinkRewrite($simpleblog_post_rewrite)) {
|
||||
$this->simpleblog_post_rewrite = $simpleblog_post_rewrite;
|
||||
} else {
|
||||
die('Blog for PrestaShop: URL is not valid');
|
||||
}
|
||||
|
||||
$SimpleBlogPost = SimpleBlogPost::getByRewrite($this->simpleblog_post_rewrite, (int) Context::getContext()->language->id);
|
||||
|
||||
// Check for matching current url with post url informations
|
||||
if (!Validate::isLoadedObject($SimpleBlogPost) || Validate::isLoadedObject($SimpleBlogPost) && !$SimpleBlogPost->active) {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
}
|
||||
|
||||
if (Validate::isLoadedObject($SimpleBlogPost)
|
||||
&& $this->simpleblog_post_rewrite != $SimpleBlogPost->link_rewrite
|
||||
|| Tools::getValue('sb_category') != $SimpleBlogPost->category_rewrite) {
|
||||
header('HTTP/1.1 301 Moved Permanently');
|
||||
header('Location: '.SimpleBlogPost::getLink($SimpleBlogPost->link_rewrite, $SimpleBlogPost->category_rewrite));
|
||||
}
|
||||
|
||||
// There you go, our blog post
|
||||
$this->SimpleBlogPost = $SimpleBlogPost;
|
||||
|
||||
// Check access to post
|
||||
if (!$this->SimpleBlogPost->isAccessGranted()) {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
}
|
||||
|
||||
// Assign meta tags
|
||||
$this->assignMetas();
|
||||
}
|
||||
|
||||
public function checkForSmartShortcodeAddons()
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$dir = _PS_MODULE_DIR_.'smartshortcode/addons';
|
||||
|
||||
if (is_dir($dir)) {
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
if (is_dir("{$dir}/{$file}/front")) {
|
||||
include_once "{$dir}/{$file}/front/shortcode.php";
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
// Assign JS and CSS for single post page
|
||||
$this->addModulePageAssets();
|
||||
|
||||
parent::initContent();
|
||||
|
||||
// Increase post views
|
||||
$this->SimpleBlogPost->increaseViewsNb();
|
||||
|
||||
// Support for SmartShortcode module from CodeCanyon
|
||||
$this->supportThirdPartyPlugins();
|
||||
|
||||
// Smarty variables
|
||||
$this->context->smarty->assign('is_16', true);
|
||||
$this->context->smarty->assign('post', $this->SimpleBlogPost);
|
||||
$this->context->smarty->assign('guest', (int) $this->context->cookie->id_guest);
|
||||
$this->context->smarty->assign('gallery_dir', _MODULE_DIR_.'ph_simpleblog/galleries/');
|
||||
|
||||
// Comments
|
||||
$this->prepareCommentsSection();
|
||||
|
||||
// Related products
|
||||
if (Configuration::get('PH_BLOG_DISPLAY_RELATED')) {
|
||||
$related_products = SimpleBlogPost::getRelatedProducts($this->SimpleBlogPost->id_product);
|
||||
$this->context->smarty->assign('related_products', $related_products);
|
||||
}
|
||||
|
||||
$this->setTemplate('single.tpl');
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
$errors = array();
|
||||
$confirmation = '1';
|
||||
|
||||
if (Tools::isSubmit('submitNewComment') && Tools::getValue('id_simpleblog_post')) {
|
||||
if (Configuration::get('PH_BLOG_COMMENT_ALLOW_GUEST') && Configuration::get('PH_BLOG_COMMENTS_RECAPTCHA')) {
|
||||
if (!class_exists('ReCaptcha') && file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/assets/recaptchalib.php')) {
|
||||
require_once(_PS_MODULE_DIR_ . 'ph_simpleblog/assets/recaptchalib.php');
|
||||
}
|
||||
|
||||
$secret = Configuration::get('PH_BLOG_COMMENTS_RECAPTCHA_SECRET_KEY');
|
||||
$response = null;
|
||||
|
||||
if (!class_exists('ReCaptcha')) {
|
||||
die('Sorry, you want to use reCAPTCHA but class to handle this doesn\'t exists');
|
||||
}
|
||||
|
||||
$reCaptcha = new ReCaptcha($secret);
|
||||
|
||||
if (Tools::getValue('g-recaptcha-response')) {
|
||||
$response = $reCaptcha->verifyResponse(
|
||||
$_SERVER["REMOTE_ADDR"],
|
||||
Tools::getValue('g-recaptcha-response')
|
||||
);
|
||||
}
|
||||
|
||||
if ($response == null) {
|
||||
$errors[] = $this->module->l('Please provide valid reCAPTCHA value', 'single-v16');
|
||||
}
|
||||
}
|
||||
|
||||
if (Tools::getValue('comment_content') && Validate::isGenericName(Tools::getValue('comment_content'))) {
|
||||
$comment_content = Tools::getValue('comment_content');
|
||||
} else {
|
||||
$errors[] = $this->module->l('Please write something and remember that HTML is not allowed in comment content.', 'single-v16');
|
||||
}
|
||||
|
||||
$customer_name = Tools::getValue('customer_name');
|
||||
|
||||
if (!Validate::isGenericName($customer_name)) {
|
||||
$errors[] = $this->module->l('Please provide valid name', 'single-v16');
|
||||
}
|
||||
|
||||
if (!Validate::isInt(Tools::getValue('id_parent'))) {
|
||||
die('FATAL ERROR [2]');
|
||||
} else {
|
||||
$id_parent = Tools::getValue('id_parent');
|
||||
}
|
||||
|
||||
$ip_address = Tools::getRemoteAddr();
|
||||
|
||||
if (sizeof($errors)) {
|
||||
$this->errors = $errors;
|
||||
} else {
|
||||
$comment = new SimpleBlogComment();
|
||||
$comment->id_simpleblog_post = (int)Tools::getValue('id_simpleblog_post');
|
||||
$comment->id_parent = $id_parent;
|
||||
$comment->id_customer = (int)$this->context->customer->id ? (int)$this->context->customer->id : 0;
|
||||
$comment->id_guest = (int)$this->context->customer->id_guest ? (int)$this->context->customer->id_guest : 0;
|
||||
$comment->name = $customer_name;
|
||||
$comment->email = isset($this->context->customer->email) ? $this->context->customer->email : null;
|
||||
$comment->comment = $comment_content;
|
||||
$comment->active = Configuration::get('PH_BLOG_COMMENT_AUTO_APPROVAL') ? 1 : 0;
|
||||
$comment->ip = Tools::getRemoteAddr();
|
||||
|
||||
if ($comment->add()) {
|
||||
if (!Configuration::get('PH_BLOG_COMMENT_AUTO_APPROVAL')) {
|
||||
$confirmation = '2';
|
||||
}
|
||||
|
||||
$link = $this->context->link->getModuleLink('ph_simpleblog', 'single', array('confirmation' => $confirmation, 'rewrite' => $this->SimpleBlogPost->link_rewrite, 'sb_category' => $this->SimpleBlogPost->category_rewrite));
|
||||
|
||||
if (Configuration::get('PH_BLOG_COMMENT_NOTIFICATIONS')) {
|
||||
$toName = strval(Configuration::get('PS_SHOP_NAME'));
|
||||
$fromName = strval(Configuration::get('PS_SHOP_NAME'));
|
||||
$to = Configuration::get('PH_BLOG_COMMENT_NOTIFY_EMAIL');
|
||||
$from = Configuration::get('PS_SHOP_EMAIL');
|
||||
$customer = $this->context->customer;
|
||||
|
||||
if ($this->context->customer->isLogged()) {
|
||||
$lastname = $this->context->customer->lastname;
|
||||
$firstname = $this->context->customer->firstname;
|
||||
} else {
|
||||
$lastname = '';
|
||||
$firstname = $customer_name;
|
||||
}
|
||||
|
||||
Mail::Send(
|
||||
$this->context->language->id,
|
||||
'new_comment',
|
||||
sprintf(Mail::l('New comment on %1$s blog for article: %2$s', $this->context->language->id), $toName, $this->SimpleBlogPost->title),
|
||||
array(
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{post_title}' => $this->SimpleBlogPost->title,
|
||||
'{post_link}' => $this->SimpleBlogPost->url,
|
||||
'{comment_content}' => $comment_content,
|
||||
),
|
||||
$to,
|
||||
$toName,
|
||||
$from,
|
||||
$fromName,
|
||||
null,
|
||||
null,
|
||||
_PS_MODULE_DIR_.'ph_simpleblog/mails/'
|
||||
);
|
||||
}
|
||||
|
||||
Tools::redirect($link);
|
||||
} else {
|
||||
$this->errors = $this->module->l('Something went wrong! Comment can not be added!', 'single-v16');
|
||||
}
|
||||
}
|
||||
}
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign meta tags to single post page.
|
||||
*/
|
||||
protected function assignMetas()
|
||||
{
|
||||
if (!empty($this->SimpleBlogPost->meta_title)) {
|
||||
$this->context->smarty->assign('meta_title', $this->SimpleBlogPost->meta_title);
|
||||
} else {
|
||||
$this->context->smarty->assign('meta_title', $this->SimpleBlogPost->title);
|
||||
}
|
||||
|
||||
if (!empty($this->SimpleBlogPost->meta_description)) {
|
||||
$this->context->smarty->assign('meta_description', $this->SimpleBlogPost->meta_description);
|
||||
}
|
||||
|
||||
if (!empty($this->SimpleBlogPost->meta_keywords)) {
|
||||
$this->context->smarty->assign('meta_keywords', $this->SimpleBlogPost->meta_keywords);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare comments section, check for access to add comments etc.
|
||||
*/
|
||||
protected function prepareCommentsSection()
|
||||
{
|
||||
$this->context->smarty->assign('allow_comments', $this->SimpleBlogPost->allowComments());
|
||||
|
||||
if ($this->SimpleBlogPost->allowComments() == true) {
|
||||
$comments = SimpleBlogComment::getComments($this->SimpleBlogPost->id_simpleblog_post);
|
||||
$this->context->smarty->assign('comments', $comments);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS, JS and other assets for this page.
|
||||
*/
|
||||
protected function addModulePageAssets()
|
||||
{
|
||||
$this->context->controller->addJqueryPlugin('cooki-plugin');
|
||||
$this->context->controller->addJqueryPlugin('cookie-plugin');
|
||||
$this->context->controller->addjqueryPlugin('fancybox');
|
||||
|
||||
$this->context->controller->addCSS(array(
|
||||
_THEME_CSS_DIR_.'category.css' => 'all',
|
||||
_THEME_CSS_DIR_.'product_list.css' => 'all',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method check for existing other third party plugins in store
|
||||
* and if such a plugins exists we are preparing them to use.
|
||||
*/
|
||||
protected function supportThirdPartyPlugins()
|
||||
{
|
||||
if (file_exists(_PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php')) {
|
||||
require_once(_PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php');
|
||||
}
|
||||
|
||||
if ((bool)Module::isEnabled('jscomposer')) {
|
||||
$this->SimpleBlogPost->content = JsComposer::do_shortcode($this->SimpleBlogPost->content);
|
||||
|
||||
if (vc_mode() === 'page_editable') {
|
||||
$this->SimpleBlogPost->content = call_user_func(JsComposer::$front_editor_actions['vc_content'], $this->SimpleBlogPost->content);
|
||||
}
|
||||
}
|
||||
if ((bool)Module::isEnabled('smartshortcode')) {
|
||||
$smartshortcode = Module::getInstanceByName('smartshortcode');
|
||||
$this->checkForSmartShortcodeAddons();
|
||||
$this->SimpleBlogPost->content = $smartshortcode->parse($this->SimpleBlogPost->content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return SimpleBlogPost object
|
||||
* @return object
|
||||
*/
|
||||
public function getPost()
|
||||
{
|
||||
return $this->SimpleBlogPost;
|
||||
}
|
||||
}
|
||||
385
modules/ph_simpleblog/controllers/front/single-v17.php
Normal file
385
modules/ph_simpleblog/controllers/front/single-v17.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
|
||||
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
|
||||
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
|
||||
use PrestaShop\PrestaShop\Core\Product\ProductListingPresenter;
|
||||
use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
|
||||
|
||||
class PH_SimpleBlogSingleModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
protected $SimpleBlogPost;
|
||||
protected $previousPost = false;
|
||||
protected $nextPost = false;
|
||||
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// Get Post by link_rewrite
|
||||
$simpleblog_post_rewrite = Tools::getValue('rewrite');
|
||||
|
||||
if ($simpleblog_post_rewrite && Validate::isLinkRewrite($simpleblog_post_rewrite)) {
|
||||
$this->simpleblog_post_rewrite = $simpleblog_post_rewrite;
|
||||
} else {
|
||||
die('Blog for PrestaShop: URL is not valid');
|
||||
}
|
||||
|
||||
$SimpleBlogPost = SimpleBlogPost::getByRewrite($this->simpleblog_post_rewrite, (int) Context::getContext()->language->id);
|
||||
|
||||
// Check for matching current url with post url informations
|
||||
if (!Validate::isLoadedObject($SimpleBlogPost) || Validate::isLoadedObject($SimpleBlogPost) && !$SimpleBlogPost->active) {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
}
|
||||
|
||||
if (Validate::isLoadedObject($SimpleBlogPost)
|
||||
&& $this->simpleblog_post_rewrite != $SimpleBlogPost->link_rewrite
|
||||
||
|
||||
Tools::getValue('sb_category') != $SimpleBlogPost->category_rewrite) {
|
||||
header('HTTP/1.1 301 Moved Permanently');
|
||||
header('Location: '.SimpleBlogPost::getLink($SimpleBlogPost->link_rewrite, $SimpleBlogPost->category_rewrite));
|
||||
}
|
||||
|
||||
// There you go, our blog post
|
||||
$this->SimpleBlogPost = $SimpleBlogPost;
|
||||
|
||||
$this->previousPost = $this->SimpleBlogPost->getPreviousPost();
|
||||
$this->nextPost = $this->SimpleBlogPost->getNextPost();
|
||||
|
||||
// Check access to post
|
||||
if (!$this->SimpleBlogPost->isAccessGranted()) {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
}
|
||||
|
||||
// Assign meta tags
|
||||
$this->assignMetas();
|
||||
}
|
||||
|
||||
public function checkForSmartShortcodeAddons()
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$dir = _PS_MODULE_DIR_.'smartshortcode/addons';
|
||||
|
||||
if (is_dir($dir)) {
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
if (is_dir("{$dir}/{$file}/front")) {
|
||||
include_once "{$dir}/{$file}/front/shortcode.php";
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
// Assign JS and CSS for single post page
|
||||
$this->addModulePageAssets();
|
||||
|
||||
parent::initContent();
|
||||
|
||||
// Increase post views
|
||||
$this->SimpleBlogPost->increaseViewsNb();
|
||||
|
||||
// Support for SmartShortcode module from CodeCanyon
|
||||
$this->supportThirdPartyPlugins();
|
||||
|
||||
// Smarty variables
|
||||
$this->context->smarty->assign('is_16', true);
|
||||
$this->context->smarty->assign('post', $this->SimpleBlogPost);
|
||||
$this->context->smarty->assign('guest', (int) $this->context->cookie->id_guest);
|
||||
$this->context->smarty->assign('gallery_dir', _MODULE_DIR_.'ph_simpleblog/galleries/');
|
||||
$this->context->smarty->assign('previousPost', $this->previousPost);
|
||||
$this->context->smarty->assign('nextPost', $this->nextPost);
|
||||
|
||||
Media::addJsDef(
|
||||
array(
|
||||
'ph_simpleblog_ajax' => $this->context->link->getModuleLink('ph_simpleblog', 'ajax'),
|
||||
'ph_simpleblog_token' => $this->module->secure_key,
|
||||
)
|
||||
);
|
||||
|
||||
// Comments
|
||||
$this->prepareCommentsSection();
|
||||
|
||||
// Related products
|
||||
if (Configuration::get('PH_BLOG_DISPLAY_RELATED')) {
|
||||
$related_products = $this->getRelatedProducts();
|
||||
$this->context->smarty->assign('related_products', $related_products);
|
||||
}
|
||||
|
||||
$this->setTemplate('module:ph_simpleblog/views/templates/front/1.7/single.tpl');
|
||||
}
|
||||
|
||||
public function getRelatedProducts()
|
||||
{
|
||||
$products = SimpleBlogPost::getRelatedProducts($this->SimpleBlogPost->id_product);
|
||||
|
||||
$productsArray = array();
|
||||
if ($products) {
|
||||
$assembler = new ProductAssembler($this->context);
|
||||
|
||||
$presenterFactory = new ProductPresenterFactory($this->context);
|
||||
$presentationSettings = $presenterFactory->getPresentationSettings();
|
||||
$presenter = new ProductListingPresenter(
|
||||
new ImageRetriever(
|
||||
$this->context->link
|
||||
),
|
||||
$this->context->link,
|
||||
new PriceFormatter(),
|
||||
new ProductColorsRetriever(),
|
||||
$this->context->getTranslator()
|
||||
);
|
||||
foreach ($products as $rawProduct) {
|
||||
$productInfo = $assembler->assembleProduct($rawProduct);
|
||||
if ($productInfo) {
|
||||
$productsArray[] = $presenter->present(
|
||||
$presentationSettings,
|
||||
$productInfo,
|
||||
$this->context->language
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $productsArray;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
$SimpleBlogPost = SimpleBlogPost::getByRewrite($this->simpleblog_post_rewrite, $id_lang);
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->l('Blog'),
|
||||
'url' => $this->context->link->getModuleLink('ph_simpleblog', 'list')
|
||||
];
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $SimpleBlogPost->category,
|
||||
'url' => $SimpleBlogPost->category_url
|
||||
];
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $SimpleBlogPost->title,
|
||||
'url' => $SimpleBlogPost->url
|
||||
];
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
$errors = array();
|
||||
$confirmation = '1';
|
||||
|
||||
if (Tools::isSubmit('submitNewComment') && Tools::getValue('id_simpleblog_post')) {
|
||||
if (Configuration::get('PH_BLOG_COMMENT_ALLOW_GUEST') && Configuration::get('PH_BLOG_COMMENTS_RECAPTCHA')) {
|
||||
if (!class_exists('ReCaptcha') && file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/assets/recaptchalib.php')) {
|
||||
require_once(_PS_MODULE_DIR_ . 'ph_simpleblog/assets/recaptchalib.php');
|
||||
}
|
||||
|
||||
$secret = Configuration::get('PH_BLOG_COMMENTS_RECAPTCHA_SECRET_KEY');
|
||||
$response = null;
|
||||
|
||||
if (!class_exists('ReCaptcha')) {
|
||||
die('Sorry, you want to use reCAPTCHA but class to handle this doesn\'t exists');
|
||||
}
|
||||
|
||||
$reCaptcha = new ReCaptcha($secret);
|
||||
|
||||
if (Tools::getValue('g-recaptcha-response')) {
|
||||
$response = $reCaptcha->verifyResponse(
|
||||
$_SERVER["REMOTE_ADDR"],
|
||||
Tools::getValue('g-recaptcha-response')
|
||||
);
|
||||
}
|
||||
|
||||
if ($response == null) {
|
||||
$errors[] = $this->module->l('Please provide valid reCAPTCHA value', 'single-v17');
|
||||
}
|
||||
}
|
||||
|
||||
if (Tools::getValue('comment_content') && Validate::isGenericName(Tools::getValue('comment_content'))) {
|
||||
$comment_content = Tools::getValue('comment_content');
|
||||
} else {
|
||||
$errors[] = $this->module->l('Please write something and remember that HTML is not allowed in comment content.', 'single-v17');
|
||||
}
|
||||
|
||||
$customer_name = Tools::getValue('customer_name');
|
||||
|
||||
if (!Validate::isGenericName($customer_name)) {
|
||||
$errors[] = $this->module->l('Please provide valid name', 'single-v17');
|
||||
}
|
||||
|
||||
if (!Validate::isInt(Tools::getValue('id_parent'))) {
|
||||
die('FATAL ERROR [2]');
|
||||
} else {
|
||||
$id_parent = Tools::getValue('id_parent');
|
||||
}
|
||||
|
||||
$ip_address = Tools::getRemoteAddr();
|
||||
|
||||
if (sizeof($errors)) {
|
||||
$this->errors = $errors;
|
||||
} else {
|
||||
$comment = new SimpleBlogComment();
|
||||
$comment->id_simpleblog_post = (int)Tools::getValue('id_simpleblog_post');
|
||||
$comment->id_parent = $id_parent;
|
||||
$comment->id_customer = (int)$this->context->customer->id ? (int)$this->context->customer->id : 0;
|
||||
$comment->id_guest = (int)$this->context->customer->id_guest ? (int)$this->context->customer->id_guest : 0;
|
||||
$comment->name = $customer_name;
|
||||
$comment->email = isset($this->context->customer->email) ? $this->context->customer->email : null;
|
||||
$comment->comment = $comment_content;
|
||||
$comment->active = Configuration::get('PH_BLOG_COMMENT_AUTO_APPROVAL') ? 1 : 0;
|
||||
$comment->ip = Tools::getRemoteAddr();
|
||||
|
||||
if ($comment->add()) {
|
||||
if (!Configuration::get('PH_BLOG_COMMENT_AUTO_APPROVAL')) {
|
||||
$confirmation = $this->l('Your comment was sucessfully added but it will be visible after moderator approval.', 'single-v17');
|
||||
} else {
|
||||
$confirmation = $this->l('Your comment was sucessfully added.', 'single-v17');
|
||||
}
|
||||
|
||||
$link = $this->context->link->getModuleLink('ph_simpleblog', 'single', array('rewrite' => $this->SimpleBlogPost->link_rewrite, 'sb_category' => $this->SimpleBlogPost->category_rewrite));
|
||||
|
||||
if (Configuration::get('PH_BLOG_COMMENT_NOTIFICATIONS')) {
|
||||
$toName = strval(Configuration::get('PS_SHOP_NAME'));
|
||||
$fromName = strval(Configuration::get('PS_SHOP_NAME'));
|
||||
$to = Configuration::get('PH_BLOG_COMMENT_NOTIFY_EMAIL');
|
||||
$from = Configuration::get('PS_SHOP_EMAIL');
|
||||
$customer = $this->context->customer;
|
||||
|
||||
if ($this->context->customer->isLogged()) {
|
||||
$lastname = $this->context->customer->lastname;
|
||||
$firstname = $this->context->customer->firstname;
|
||||
} else {
|
||||
$lastname = '';
|
||||
$firstname = $customer_name;
|
||||
}
|
||||
|
||||
Mail::Send(
|
||||
$this->context->language->id,
|
||||
'new_comment',
|
||||
sprintf($this->l('New comment on %1$s blog for article: %2$s', 'single-v17'), $toName, $this->SimpleBlogPost->title),
|
||||
array(
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{post_title}' => $this->SimpleBlogPost->title,
|
||||
'{post_link}' => $this->SimpleBlogPost->url,
|
||||
'{comment_content}' => $comment_content,
|
||||
),
|
||||
$to,
|
||||
$toName,
|
||||
$from,
|
||||
$fromName,
|
||||
null,
|
||||
null,
|
||||
_PS_MODULE_DIR_.'ph_simpleblog/mails/'
|
||||
);
|
||||
}
|
||||
|
||||
$this->success[] = $confirmation;
|
||||
|
||||
$this->redirectWithNotifications($link);
|
||||
} else {
|
||||
$this->errors = $this->module->l('Something went wrong! Comment can not be added!', 'single-v17');
|
||||
}
|
||||
}
|
||||
}
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign meta tags to single post page.
|
||||
*/
|
||||
protected function assignMetas()
|
||||
{
|
||||
if (!empty($this->SimpleBlogPost->meta_title)) {
|
||||
$this->context->smarty->assign('meta_title', $this->SimpleBlogPost->meta_title);
|
||||
} else {
|
||||
$this->context->smarty->assign('meta_title', $this->SimpleBlogPost->title);
|
||||
}
|
||||
|
||||
if (!empty($this->SimpleBlogPost->meta_description)) {
|
||||
$this->context->smarty->assign('meta_description', $this->SimpleBlogPost->meta_description);
|
||||
}
|
||||
|
||||
if (!empty($this->SimpleBlogPost->meta_keywords)) {
|
||||
$this->context->smarty->assign('meta_keywords', $this->SimpleBlogPost->meta_keywords);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare comments section, check for access to add comments etc.
|
||||
*/
|
||||
protected function prepareCommentsSection()
|
||||
{
|
||||
$this->context->smarty->assign('allow_comments', $this->SimpleBlogPost->allowComments());
|
||||
|
||||
if ($this->SimpleBlogPost->allowComments() == true) {
|
||||
$comments = SimpleBlogComment::getComments($this->SimpleBlogPost->id_simpleblog_post);
|
||||
$this->context->smarty->assign('comments', $comments);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS, JS and other assets for this page.
|
||||
*/
|
||||
protected function addModulePageAssets()
|
||||
{
|
||||
$this->context->controller->addJqueryPlugin('cooki-plugin');
|
||||
$this->context->controller->addJqueryPlugin('cookie-plugin');
|
||||
$this->context->controller->addjqueryPlugin('fancybox');
|
||||
|
||||
$this->context->controller->addCSS(array(
|
||||
_THEME_CSS_DIR_.'category.css' => 'all',
|
||||
_THEME_CSS_DIR_.'product_list.css' => 'all',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method check for existing other third party plugins in store
|
||||
* and if such a plugins exists we are preparing them to use.
|
||||
*/
|
||||
protected function supportThirdPartyPlugins()
|
||||
{
|
||||
if (file_exists(_PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php')) {
|
||||
require_once(_PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php');
|
||||
}
|
||||
|
||||
if ((bool)Module::isEnabled('jscomposer')) {
|
||||
$this->SimpleBlogPost->content = JsComposer::do_shortcode($this->SimpleBlogPost->content);
|
||||
|
||||
if (vc_mode() === 'page_editable') {
|
||||
$this->SimpleBlogPost->content = call_user_func(JsComposer::$front_editor_actions['vc_content'], $this->SimpleBlogPost->content);
|
||||
}
|
||||
}
|
||||
if ((bool)Module::isEnabled('smartshortcode')) {
|
||||
$smartshortcode = Module::getInstanceByName('smartshortcode');
|
||||
$this->checkForSmartShortcodeAddons();
|
||||
$this->SimpleBlogPost->content = $smartshortcode->parse($this->SimpleBlogPost->content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return SimpleBlogPost object
|
||||
* @return object
|
||||
*/
|
||||
public function getPost()
|
||||
{
|
||||
return $this->SimpleBlogPost;
|
||||
}
|
||||
}
|
||||
15
modules/ph_simpleblog/controllers/front/single.php
Normal file
15
modules/ph_simpleblog/controllers/front/single.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog for PrestaShop module by Krystian Podemski from PrestaHome.
|
||||
*
|
||||
* @author Krystian Podemski <krystian@prestahome.com>
|
||||
* @copyright Copyright (c) 2008-2019 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
|
||||
* @license You only can use module, nothing more!
|
||||
*/
|
||||
require_once _PS_MODULE_DIR_.'ph_simpleblog/ph_simpleblog.php';
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
include_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/single-v17.php';
|
||||
} else {
|
||||
include_once _PS_MODULE_DIR_.'ph_simpleblog/controllers/front/single-v16.php';
|
||||
}
|
||||
Reference in New Issue
Block a user