first commit
This commit is contained in:
617
modules/leoblog/controllers/admin/AdminLeoblogBlogs.php
Normal file
617
modules/leoblog/controllers/admin/AdminLeoblogBlogs.php
Normal file
@@ -0,0 +1,617 @@
|
||||
<?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 AdminLeoblogBlogsController extends ModuleAdminController
|
||||
{
|
||||
protected $max_image_size;
|
||||
protected $position_identifier = 'id_leoblog_blog';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'leoblog_blog';
|
||||
$this->identifier = 'id_leoblog_blog';
|
||||
$this->className = 'LeoBlogBlog';
|
||||
$this->lang = true;
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('delete');
|
||||
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
|
||||
$this->fields_list = array(
|
||||
'id_leoblog_blog' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
|
||||
'meta_title' => array('title' => $this->l('Blog Title'), 'filter_key' => 'b!meta_title'),
|
||||
'author_name' => array('title' => $this->l('Author Name'), 'filter_key' => 'a!author_name'),
|
||||
'title' => array('title' => $this->l('Category Title'), 'filter_key' => 'cl!title'),
|
||||
'active' => array('title' => $this->l('Displayed'), 'align' => 'center', 'active' => 'status', 'class' => 'fixed-width-sm', 'type' => 'bool', 'orderby' => true),
|
||||
'date_add' => array('title' => $this->l('Date Create'), 'type' => 'date', 'filter_key' => 'a!date_add'),
|
||||
'date_upd' => array('title' => $this->l('Date Update'), 'type' => 'datetime', 'filter_key' => 'a!date_upd')
|
||||
|
||||
);
|
||||
$this->max_image_size = Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
|
||||
$this->_select .= ' cl.title ';
|
||||
$this->_join .= ' LEFT JOIN '._DB_PREFIX_.'leoblogcat c ON a.id_leoblogcat = c.id_leoblogcat
|
||||
LEFT JOIN '._DB_PREFIX_.'leoblogcat_lang cl ON cl.id_leoblogcat=c.id_leoblogcat AND cl.id_lang=b.id_lang
|
||||
';
|
||||
if (Shop::getContext() == Shop::CONTEXT_SHOP) {
|
||||
$this->_join .= ' INNER JOIN `'._DB_PREFIX_.'leoblog_blog_shop` sh ON (sh.`id_leoblog_blog` = b.`id_leoblog_blog` AND sh.id_shop = '.(int)Context::getContext()->shop->id.') ';
|
||||
}
|
||||
$this->_where = '';
|
||||
$this->_group = ' GROUP BY (a.id_leoblog_blog) ';
|
||||
$this->_orderBy = 'a.id_leoblog_blog';
|
||||
$this->_orderWay = 'DESC';
|
||||
}
|
||||
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
$link = $this->context->link;
|
||||
if (Tools::getValue('id_leoblog_blog')) {
|
||||
$helper = LeoBlogHelper::getInstance();
|
||||
$blog_obj = new LeoBlogBlog(Tools::getValue('id_leoblog_blog'), $this->context->language->id);
|
||||
$this->page_header_toolbar_btn['view-blog-preview'] = array(
|
||||
'href' => $helper->getBlogLink(get_object_vars($blog_obj)),
|
||||
'desc' => $this->l('Preview Blog'),
|
||||
'icon' => 'icon-preview leoblog-comment-link-icon icon-3x process-icon-preview',
|
||||
'target' => '_blank',
|
||||
);
|
||||
|
||||
$this->page_header_toolbar_btn['view-blog-comment'] = array(
|
||||
'href' => $link->getAdminLink('AdminLeoblogComments').'&id_leoblog_blog='.Tools::getValue('id_leoblog_blog'),
|
||||
'desc' => $this->l('Manage Comments'),
|
||||
'icon' => 'icon-comment leoblog-comment-link-icon icon-3x process-icon-comment',
|
||||
'target' => '_blank',
|
||||
);
|
||||
}
|
||||
|
||||
return parent::initPageHeaderToolbar();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
if (!$this->loadObject(true)) {
|
||||
if (Validate::isLoadedObject($this->object)) {
|
||||
$this->display = 'edit';
|
||||
} else {
|
||||
$this->display = 'add';
|
||||
}
|
||||
}
|
||||
$this->autoCorrect();
|
||||
$this->initToolbar();
|
||||
$this->initPageHeaderToolbar();
|
||||
|
||||
$id_leoblogcat = (int)(Tools::getValue('id_leoblogcat'));
|
||||
$obj = new leoblogcat($id_leoblogcat);
|
||||
$obj->getTree();
|
||||
$menus = $obj->getDropdown(null, $obj->id_parent, false);
|
||||
array_shift($menus);
|
||||
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
if ($this->object->image) {
|
||||
$thumb = _THEME_DIR_.'assets/img/modules/leoblog/'.$id_shop.'/b/'.$this->object->image;
|
||||
} else {
|
||||
$thumb = '';
|
||||
}
|
||||
$default_author_name = '';
|
||||
if (isset($this->context->employee->firstname) && isset($this->context->employee->lastname)) {
|
||||
$default_author_name = $this->context->employee->firstname.' '.$this->context->employee->lastname;
|
||||
}
|
||||
|
||||
if ($this->object->id == '') {
|
||||
$this->object->author_name = $default_author_name;
|
||||
}
|
||||
if ($this->object->thumb) {
|
||||
$thumb_img = _THEME_DIR_.'assets/img/modules/leoblog/'.$id_shop.'/b/'.$this->object->thumb;
|
||||
} else {
|
||||
$thumb_img = '';
|
||||
}
|
||||
|
||||
$this->multiple_fieldsets = true;
|
||||
|
||||
$this->fields_form[0]['form'] = array(
|
||||
'tinymce' => true,
|
||||
'legend' => array(
|
||||
'title' => $this->l('Blog Form'),
|
||||
'icon' => 'icon-folder-close'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Category'),
|
||||
'name' => 'id_leoblogcat',
|
||||
'options' => array('query' => $menus,
|
||||
'id' => 'id',
|
||||
'name' => 'title'),
|
||||
'default' => $id_leoblogcat,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Meta title:'),
|
||||
'name' => 'meta_title',
|
||||
'id' => 'name', // for copyMeta2friendlyURL compatibility
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'class' => 'copyMeta2friendlyURL',
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Subtitle:'),
|
||||
'name' => 'subtitle',
|
||||
'id' => 'subname', // for copyMeta2friendlyURL compatibility
|
||||
'lang' => true,
|
||||
'class' => 'copyMeta2friendlyURL',
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Friendly URL'),
|
||||
'name' => 'link_rewrite',
|
||||
'required' => true,
|
||||
'lang' => true,
|
||||
'hint' => $this->l('Only letters and the minus (-) character are allowed')
|
||||
),
|
||||
array(
|
||||
'type' => 'tags',
|
||||
'label' => $this->l('Tags'),
|
||||
'name' => 'tags',
|
||||
'lang' => true,
|
||||
'hint' => array(
|
||||
$this->l('Invalid characters:').' <>;=#{}',
|
||||
$this->l('To add "tags" click in the field, write something, and then press "Enter."')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'label' => $this->l('Image Name:'),
|
||||
'name' => 'image',
|
||||
),
|
||||
array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Image'),
|
||||
'name' => 'image_link',
|
||||
'display_image' => true,
|
||||
'default' => '',
|
||||
'desc' => $this->l('Max file size is: ').($this->max_image_size/1024/1024). 'MB',
|
||||
'thumb' => $thumb,
|
||||
// 'image' => $thumb,
|
||||
// 'delete_url' => self::$currentIndex.'&'.$this->identifier.'=a&token='.$this->token.'&deleteImage=1',
|
||||
'class' => 'leoblog_image_upload',
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'label' => $this->l('Thumb Name:'),
|
||||
'name' => 'thumb',
|
||||
),
|
||||
array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Thumb image'),
|
||||
'name' => 'thumb_link',
|
||||
'display_image' => true,
|
||||
'default' => '',
|
||||
'desc' => $this->l('Max file size is: ').($this->max_image_size/1024/1024). 'MB',
|
||||
'thumb' => $thumb_img,
|
||||
// 'image' => $thumb_img,
|
||||
// 'delete_url' => self::$currentIndex.'&'.$this->identifier.'=a&token='.$this->token.'&deleteImage=1',
|
||||
'class' => 'leoblog_image_upload',
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Video Code'),
|
||||
'name' => 'video_code',
|
||||
'rows' => 5,
|
||||
'cols' => 30,
|
||||
'hint' => $this->l('Enter Video Code Copying From Youtube, Vimeo').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Blog description'),
|
||||
'name' => 'description',
|
||||
'autoload_rte' => true,
|
||||
'lang' => true,
|
||||
'rows' => 5,
|
||||
'cols' => 30,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Blog Content'),
|
||||
'name' => 'content',
|
||||
'autoload_rte' => true,
|
||||
'lang' => true,
|
||||
'rows' => 5,
|
||||
'cols' => 40,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Author Name'),
|
||||
'name' => 'author_name',
|
||||
'desc' => $this->l('Name of author will display on front-end')
|
||||
),
|
||||
array(
|
||||
'type' => 'date_leoblog',
|
||||
'label' => $this->l('Date Create'),
|
||||
'name' => 'date_add',
|
||||
'default' => date('Y-m-d'),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Indexation (by search engines):'),
|
||||
'name' => 'indexation',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'indexation_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'indexation_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Blog favorite'),
|
||||
'name' => 'favorite',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'favorite_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Yes')
|
||||
),
|
||||
array(
|
||||
'id' => 'favorite_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('No')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Displayed:'),
|
||||
'name' => 'active',
|
||||
'required' => false,
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-default pull-right'
|
||||
),
|
||||
'buttons' => array(
|
||||
'save_and_preview' => array(
|
||||
'name' => 'saveandstay',
|
||||
'type' => 'submit',
|
||||
'title' => $this->l('Save and stay'),
|
||||
'class' => 'btn btn-default pull-right',
|
||||
'icon' => 'process-icon-save-and-stay'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->fields_form[1]['form'] = array(
|
||||
'tinymce' => true,
|
||||
'legend' => array(
|
||||
'title' => $this->l('SEO'),
|
||||
'icon' => 'icon-folder-close'
|
||||
),
|
||||
'input' => array(
|
||||
// custom template
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Meta description'),
|
||||
'name' => 'meta_description',
|
||||
'lang' => true,
|
||||
'cols' => 40,
|
||||
'rows' => 10,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'tags',
|
||||
'label' => $this->l('Meta keywords'),
|
||||
'name' => 'meta_keywords',
|
||||
'lang' => true,
|
||||
'hint' => array(
|
||||
$this->l('Invalid characters:').' <>;=#{}',
|
||||
$this->l('To add "tags" click in the field, write something, and then press "Enter."')
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
Media::addJsDef(array(
|
||||
'leoblog_del_img_txt' => $this->l('Delete'),
|
||||
'leoblog_del_img_mess' => $this->l('Are you sure delete this?'),
|
||||
'PS_ALLOW_ACCENTED_CHARS_URL' => (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'),
|
||||
));
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
$this->toolbar_title = $this->l('Blogs Management');
|
||||
$this->toolbar_btn['new'] = array(
|
||||
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
|
||||
'desc' => $this->l('Add new')
|
||||
);
|
||||
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('viewblog') && ($id_leoblog_blog = (int)Tools::getValue('id_leoblog_blog')) && ($blog = new LeoBlogBlog($id_leoblog_blog, $this->context->language->id)) && Validate::isLoadedObject($blog)) {
|
||||
$this->redirect_after = $this->getPreviewUrl($blog);
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('submitAddleoblog_blog') || Tools::isSubmit('submitAddleoblog_blogAndPreview') || Tools::isSubmit('saveandstay')) {
|
||||
if (count($this->errors)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent::validateRules();
|
||||
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
if (!$id_leoblog_blog = (int)Tools::getValue('id_leoblog_blog')) {
|
||||
# ADD
|
||||
$blog = new LeoBlogBlog();
|
||||
$this->copyFromPost($blog, 'blog');
|
||||
|
||||
if (isset($_FILES['image_link']) && isset($_FILES['image_link']['tmp_name']) && !empty($_FILES['image_link']['tmp_name'])) {
|
||||
if (!$image = $this->_uploadImage($_FILES['image_link'], '', '')) {
|
||||
return false;
|
||||
}
|
||||
$blog->image = $image;
|
||||
}
|
||||
|
||||
if (isset($_FILES['thumb_link']) && isset($_FILES['thumb_link']['tmp_name']) && !empty($_FILES['thumb_link']['tmp_name'])) {
|
||||
if (!$thumb = $this->_uploadImage($_FILES['thumb_link'], '', '', true)) {
|
||||
return false;
|
||||
}
|
||||
$blog->thumb = $thumb;
|
||||
}
|
||||
$blog->id_employee = $this->context->employee->id;
|
||||
|
||||
if (!$blog->add(false)) {
|
||||
$this->errors[] = $this->l('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
|
||||
} else {
|
||||
# validate module
|
||||
$this->updateAssoShop($blog->id);
|
||||
}
|
||||
} else {
|
||||
# EDIT
|
||||
$blog = new LeoBlogBlog($id_leoblog_blog);
|
||||
$this->copyFromPost($blog, 'blog');
|
||||
|
||||
if (isset($_FILES['image_link']) && isset($_FILES['image_link']['tmp_name']) && !empty($_FILES['image_link']['tmp_name'])) {
|
||||
if (file_exists(_LEOBLOG_CACHE_IMG_DIR_.'b/'.$id_shop.'/'.$id_leoblog_blog)) {
|
||||
LeoBlogHelper::rrmdir(_LEOBLOG_CACHE_IMG_DIR_.'b/'.$id_shop.'/'.$id_leoblog_blog);
|
||||
}
|
||||
if (!$image = $this->_uploadImage($_FILES['image_link'], '', '')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$blog->image = $image;
|
||||
}
|
||||
|
||||
if (isset($_FILES['thumb_link']) && isset($_FILES['thumb_link']['tmp_name']) && !empty($_FILES['thumb_link']['tmp_name'])) {
|
||||
if (file_exists(_LEOBLOG_CACHE_IMG_DIR_.'b/'.$id_shop.'/'.$id_leoblog_blog)) {
|
||||
LeoBlogHelper::rrmdir(_LEOBLOG_CACHE_IMG_DIR_.'b/'.$id_shop.'/'.$id_leoblog_blog);
|
||||
}
|
||||
if (!$thumb = $this->_uploadImage($_FILES['thumb_link'], '', '', true)) {
|
||||
return false;
|
||||
}
|
||||
$blog->thumb = $thumb;
|
||||
}
|
||||
if (!$blog->update()) {
|
||||
$this->errors[] = $this->l('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
|
||||
} else {
|
||||
# validate module
|
||||
$this->updateAssoShop($blog->id);
|
||||
}
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('submitAddblogAndPreview')) {
|
||||
# validate module
|
||||
$this->redirect_after = $this->previewUrl($blog);
|
||||
} elseif (Tools::isSubmit('saveandstay')) {
|
||||
# validate module
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$blog->id.'&conf=4&update'.$this->table.'&token='.Tools::getValue('token'));
|
||||
} else {
|
||||
# validate module
|
||||
Tools::redirectAdmin(self::$currentIndex.'&id_leoblogcat='.$blog->id_leoblogcat.'&conf=4&token='.Tools::getValue('token'));
|
||||
}
|
||||
} else {
|
||||
parent::postProcess(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _uploadImage($image, $image_w = null, $image_h = null, $thumb_image = false)
|
||||
{
|
||||
$folder_theme = _PS_THEME_DIR_;
|
||||
|
||||
$res = false;
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
LeoBlogHelper::buildFolder($id_shop);
|
||||
if (is_array($image) && (ImageManager::validateUpload($image, $this->max_image_size) === false) && ($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) && move_uploaded_file($image['tmp_name'], $tmp_name)) {
|
||||
$type = Tools::strtolower(Tools::substr(strrchr($image['name'], '.'), 1));
|
||||
if ($thumb_image) {
|
||||
$img_name = 't-'.Tools::strtolower(str_replace('.'.$type, '', $image['name']).'.'.$type);
|
||||
} else {
|
||||
$img_name = 'b-'.Tools::strtolower(str_replace('.'.$type, '', $image['name']).'.'.$type);
|
||||
}
|
||||
|
||||
if (file_exists($folder_theme.'assets/img/modules/leoblog/'.$id_shop.'/b/'.$img_name)) {
|
||||
@unlink($folder_theme.'assets/img/modules/leoblog/'.$id_shop.'/b/'.$img_name);
|
||||
}
|
||||
$image_type = 'jpg';
|
||||
if (Configuration::get('LEOBLOG_IMAGE_TYPE') != null) {
|
||||
$image_type = Configuration::get('LEOBLOG_IMAGE_TYPE');
|
||||
}
|
||||
// Configuration::set('PS_IMAGE_QUALITY', 'png_all');
|
||||
Configuration::set('PS_IMAGE_QUALITY', $image_type);
|
||||
if (ImageManager::resize($tmp_name, $folder_theme.'assets/img/modules/leoblog/'.$id_shop.'/b/'.$img_name, (int)$image_w, (int)$image_h)) {
|
||||
$res = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if (isset($temp_name))
|
||||
// @unlink($tmp_name);
|
||||
if (!$res) {
|
||||
# validate module
|
||||
return false;
|
||||
}
|
||||
|
||||
return $img_name;
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
$this->addJqueryUi('ui.widget');
|
||||
$this->addJqueryPlugin('tagify');
|
||||
$media_dir = $this->module->getMediaDir();
|
||||
if (file_exists(_PS_THEME_DIR_.'js/modules/leoblog/assets/admin/form.js')) {
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.'modules/leoblog/assets/admin/form.js');
|
||||
} else {
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.$media_dir.'js/admin/form.js');
|
||||
}
|
||||
|
||||
if (file_exists(_PS_THEME_DIR_.'css/modules/leoblog/assets/admin/form.css')) {
|
||||
$this->context->controller->addCss(__PS_BASE_URI__.'modules/leoblog/assets/admin/form.css');
|
||||
} else {
|
||||
$this->context->controller->addCss(__PS_BASE_URI__.$media_dir.'css/admin/form.css');
|
||||
}
|
||||
}
|
||||
|
||||
public function autoCorrect()
|
||||
{
|
||||
// check `favorite` name column, if not exist auto add
|
||||
if (Db::getInstance()->executeS('SHOW TABLES LIKE \'%leoblog_blog%\'') && count(Db::getInstance()->executes('SELECT "favorite" FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "'._DB_NAME_.'" AND TABLE_NAME = "'._DB_PREFIX_.'leoblog_blog" AND COLUMN_NAME = "favorite"'))<1) {
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'leoblog_blog` ADD `favorite` tinyint(1) NOT NULL');
|
||||
}
|
||||
// check `subtitle` name column, if not exist auto add
|
||||
if (Db::getInstance()->executeS('SHOW TABLES LIKE \'%leoblog_blog_lang%\'') && count(Db::getInstance()->executes('SELECT "subtitle" FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "'._DB_NAME_.'" AND TABLE_NAME = "'._DB_PREFIX_.'leoblog_blog_lang" AND COLUMN_NAME = "subtitle"'))<1) {
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'leoblog_blog_lang` ADD `subtitle` varchar(250) NULL');
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateblogPositions()
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1') {
|
||||
$id_leoblog_blog = (int)Tools::getValue('id_leoblog_blog');
|
||||
$id_category = (int)Tools::getValue('id_leoblog_blog_category');
|
||||
$way = (int)Tools::getValue('way');
|
||||
$positions = Tools::getValue('blog');
|
||||
if (is_array($positions)) {
|
||||
foreach ($positions as $key => $value) {
|
||||
$pos = explode('_', $value);
|
||||
if ((isset($pos[1]) && isset($pos[2])) && ($pos[1] == $id_category && $pos[2] == $id_leoblog_blog)) {
|
||||
$position = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$blog = new blog($id_leoblog_blog);
|
||||
if (Validate::isLoadedObject($blog)) {
|
||||
if (isset($position) && $blog->updatePosition($way, $position)) {
|
||||
die(true);
|
||||
} else {
|
||||
die('{"hasError" : true, "errors" : "Can not update blog position"}');
|
||||
}
|
||||
} else {
|
||||
die('{"hasError" : true, "errors" : "This blog can not be loaded"}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateblogCategoriesPositions()
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1') {
|
||||
$id_leoblog_blog_category_to_move = (int)Tools::getValue('id_leoblog_blog_category_to_move');
|
||||
$id_leoblog_blog_category_parent = (int)Tools::getValue('id_leoblog_blog_category_parent');
|
||||
$way = (int)Tools::getValue('way');
|
||||
$positions = Tools::getValue('blog_category');
|
||||
if (is_array($positions)) {
|
||||
foreach ($positions as $key => $value) {
|
||||
$pos = explode('_', $value);
|
||||
if ((isset($pos[1]) && isset($pos[2])) && ($pos[1] == $id_leoblog_blog_category_parent && $pos[2] == $id_leoblog_blog_category_to_move)) {
|
||||
$position = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$blog_category = new blogCategory($id_leoblog_blog_category_to_move);
|
||||
if (Validate::isLoadedObject($blog_category)) {
|
||||
if (isset($position) && $blog_category->updatePosition($way, $position)) {
|
||||
die(true);
|
||||
} else {
|
||||
die('{"hasError" : true, "errors" : "Can not update blog categories position"}');
|
||||
}
|
||||
} else {
|
||||
die('{"hasError" : true, "errors" : "This blog category can not be loaded"}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessPublishblog()
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1') {
|
||||
if ($id_leoblog_blog = (int)Tools::getValue('id_leoblog_blog')) {
|
||||
$bo_blog_url = dirname($_SERVER['PHP_SELF']).'/index.php?tab=AdminblogContent&id_leoblog_blog='.(int)$id_leoblog_blog.'&updateblog&token='.$this->token;
|
||||
|
||||
if (Tools::getValue('redirect')) {
|
||||
die($bo_blog_url);
|
||||
}
|
||||
|
||||
$blog = new blog((int)(Tools::getValue('id_leoblog_blog')));
|
||||
if (!Validate::isLoadedObject($blog)) {
|
||||
die('error: invalid id');
|
||||
}
|
||||
|
||||
$blog->active = 1;
|
||||
if ($blog->save()) {
|
||||
die($bo_blog_url);
|
||||
} else {
|
||||
die('error: saving');
|
||||
}
|
||||
} else {
|
||||
die('error: parameters');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
519
modules/leoblog/controllers/admin/AdminLeoblogCategories.php
Normal file
519
modules/leoblog/controllers/admin/AdminLeoblogCategories.php
Normal file
@@ -0,0 +1,519 @@
|
||||
<?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 AdminLeoblogCategoriesController extends ModuleAdminController
|
||||
{
|
||||
public $name = 'leoblog';
|
||||
protected $fields_form = array();
|
||||
private $_html = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->id_leoblogcat = true;
|
||||
$this->table = 'leoblogcat';
|
||||
|
||||
$this->className = 'leoblogcat';
|
||||
$this->lang = true;
|
||||
$this->fields_options = array();
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->toolbar_title = $this->l('Categories Management');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build List linked Icons Toolbar
|
||||
*/
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
//DONGND:: update new direction for media
|
||||
$media_dir = $this->module->getMediaDir();
|
||||
$this->context->controller->addCss(__PS_BASE_URI__.'js/jquery/ui/themes/base/jquery.ui.tabs.css');
|
||||
if (file_exists(_PS_THEME_DIR_.'css/modules/leoblog/assets/admin/form.css')) {
|
||||
$this->context->controller->addCss(__PS_BASE_URI__.'modules/leoblog/assets/admin/form.css');
|
||||
} else {
|
||||
$this->context->controller->addCss(__PS_BASE_URI__.$media_dir.'css/admin/form.css');
|
||||
}
|
||||
|
||||
if (empty($this->display)) {
|
||||
parent::initPageHeaderToolbar();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
$this->addJqueryUi('ui.widget');
|
||||
$this->addJqueryPlugin('tagify');
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.'js/jquery/ui/jquery.ui.sortable.min.js');
|
||||
$media_dir = $this->module->getMediaDir();
|
||||
if (file_exists(_PS_THEME_DIR_.'js/modules/leoblog/assets/admin/jquery.nestable.js')) {
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.'modules/leoblog/assets/admin/jquery.nestable.js');
|
||||
} else {
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.$media_dir.'js/admin/jquery.nestable.js');
|
||||
}
|
||||
if (file_exists(_PS_THEME_DIR_.'js/modules/leoblog/assets/admin/form.js')) {
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.'modules/leoblog/assets/admin/form.js');
|
||||
} else {
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.$media_dir.'js/admin/form.js');
|
||||
}
|
||||
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.'js/jquery/plugins/jquery.cookie-plugin.js');
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.'js/jquery/ui/jquery.ui.tabs.min.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* get live Edit URL
|
||||
*/
|
||||
public function getLiveEditUrl($live_edit_params)
|
||||
{
|
||||
$url = $this->context->shop->getBaseURL().Dispatcher::getInstance()->createUrl('index', (int)$this->context->language->id, $live_edit_params);
|
||||
if (Configuration::get('PS_REWRITING_SETTINGS')) {
|
||||
$url = str_replace('index.php', '', $url);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* add toolbar icons
|
||||
*/
|
||||
public function initToolbar()
|
||||
{
|
||||
$this->context->smarty->assign('toolbar_scroll', 1);
|
||||
$this->context->smarty->assign('show_toolbar', 1);
|
||||
$this->context->smarty->assign('toolbar_btn', $this->toolbar_btn);
|
||||
$this->context->smarty->assign('title', $this->toolbar_title);
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (count($this->errors) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::getValue('doupdatepos') && Tools::isSubmit('updatePosition')) {
|
||||
$list = Tools::getValue('list');
|
||||
$root = 1;
|
||||
$child = array();
|
||||
foreach ($list as $id => $parent_id) {
|
||||
if ($parent_id <= 0) {
|
||||
# validate module
|
||||
$parent_id = $root;
|
||||
}
|
||||
$child[$parent_id][] = $id;
|
||||
}
|
||||
$res = true;
|
||||
foreach ($child as $id_parent => $menus) {
|
||||
$i = 0;
|
||||
foreach ($menus as $id_leoblogcat) {
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'leoblogcat` SET `position` = '.(int)$i.', id_parent = '.(int)$id_parent.'
|
||||
WHERE `id_leoblogcat` = '.(int)$id_leoblogcat;
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
die($this->l('Update Positions Done'));
|
||||
}
|
||||
/* delete megamenu item */
|
||||
if (Tools::getValue('dodel')) {
|
||||
$obj = new Leoblogcat((int)Tools::getValue('id_leoblogcat'));
|
||||
$res = $obj->delete();
|
||||
Tools::redirectAdmin(AdminController::$currentIndex.'&token='.Tools::getValue('token'));
|
||||
}
|
||||
if (Tools::getValue('delete_many_menu')) {
|
||||
$list = array_filter(explode(',', trim(Tools::getValue('list'), ',')));
|
||||
if (is_array($list) && $list) {
|
||||
#validate module
|
||||
foreach ($list as $id) {
|
||||
$obj = new Leoblogcat((int)$id);
|
||||
if ($obj->id) {
|
||||
$obj->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Tools::redirectAdmin(AdminController::$currentIndex.'&token='.Tools::getValue('token'));
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('save'.$this->name) && Tools::isSubmit('active')) {
|
||||
if ($id_leoblogcat = Tools::getValue('id_leoblogcat')) {
|
||||
# validate module
|
||||
$megamenu = new leoblogcat((int)$id_leoblogcat);
|
||||
} else {
|
||||
# validate module
|
||||
$megamenu = new leoblogcat();
|
||||
$megamenu->randkey = LeoBlogHelper::genKey();
|
||||
}
|
||||
$this->copyFromPost($megamenu, $this->table);
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
|
||||
LeoBlogHelper::buildFolder($id_shop);
|
||||
$megamenu->id_shop = $this->context->shop->id;
|
||||
|
||||
if ($megamenu->validateFields(false) && $megamenu->validateFieldsLang(false)) {
|
||||
$megamenu->save();
|
||||
if (isset($_FILES['image_link']) && isset($_FILES['image_link']['tmp_name']) && !empty($_FILES['image_link']['tmp_name'])) {
|
||||
$folder_theme = _PS_THEME_DIR_;
|
||||
|
||||
if ($megamenu->image != '') {
|
||||
$old_image = $megamenu->image;
|
||||
}
|
||||
|
||||
if (ImageManager::validateUpload($_FILES['image_link'])) {
|
||||
return false;
|
||||
} elseif (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image_link']['tmp_name'], $tmp_name)) {
|
||||
return false;
|
||||
} elseif (!ImageManager::resize($tmp_name, $folder_theme.'assets/img/modules/leoblog/'.$id_shop.'/c/'.$_FILES['image_link']['name'])) {
|
||||
return false;
|
||||
}
|
||||
unlink($tmp_name);
|
||||
$megamenu->image = $_FILES['image_link']['name'];
|
||||
if (isset($old_image)) {
|
||||
unlink($folder_theme.'assets/img/modules/leoblog/'.$id_shop.'/c/'.$old_image);
|
||||
}
|
||||
|
||||
$megamenu->save();
|
||||
}
|
||||
Tools::redirectAdmin(AdminController::$currentIndex.'&saveleoblog&token='.Tools::getValue('token').'&id_leoblogcat='.$megamenu->id);
|
||||
} else {
|
||||
// validate module
|
||||
$this->_html .= $this->displayWarning($this->l('An error occurred while attempting to save.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
$this->initToolbar();
|
||||
if (!$this->loadObject(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$obj = $this->object;
|
||||
$tree = Tools::htmlentitiesDecodeUTF8($obj->getTree());
|
||||
$menus = $obj->getDropdown(null, $obj->id_parent);
|
||||
|
||||
# FIX : PARENT IS NOT THIS CATEGORY
|
||||
$id_leoblogcat = (int) (Tools::getValue('id_leoblogcat'));
|
||||
foreach ($menus as $key => $menu) {
|
||||
if ($menu['id'] == $id_leoblogcat) {
|
||||
unset($menus[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
|
||||
$templates = LeoBlogHelper::getTemplates();
|
||||
|
||||
$soption = array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
);
|
||||
|
||||
$this->fields_form[0]['form'] = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Category Form.'),
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'label' => $this->l('Category ID'),
|
||||
'name' => 'id_leoblogcat',
|
||||
'default' => 0,
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Theme - Template'),
|
||||
'name' => 'template',
|
||||
'options' => array('query' => $templates,
|
||||
'id' => 'template',
|
||||
'name' => 'template'),
|
||||
'default' => 'default',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Meta title:'),
|
||||
'default' => '',
|
||||
'name' => 'title',
|
||||
'id' => 'name', // for copyMeta2friendlyURL compatibility
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'class' => 'copyMeta2friendlyURL',
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Friendly URL'),
|
||||
'name' => 'link_rewrite',
|
||||
'required' => true,
|
||||
'lang' => true,
|
||||
'default' => '',
|
||||
'hint' => $this->l('Only letters and the minus (-) character are allowed')
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Parent ID'),
|
||||
'name' => 'id_parent',
|
||||
'options' => array('query' => $menus,
|
||||
'id' => 'id',
|
||||
'name' => 'title'),
|
||||
'default' => 'url',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Is Active'),
|
||||
'name' => 'active',
|
||||
'values' => $soption,
|
||||
'default' => '1',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Title'),
|
||||
'name' => 'show_title',
|
||||
'values' => $soption,
|
||||
'default' => '1',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Addion Css Class'),
|
||||
'name' => 'menu_class',
|
||||
'display_image' => true,
|
||||
'default' => ''
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Menu Icon Class'),
|
||||
'name' => 'icon_class',
|
||||
'display_image' => true,
|
||||
'default' => '',
|
||||
'desc' => $this->l('The module integrated with FontAwesome').'. '
|
||||
.$this->l('Check list of icons and class name in here')
|
||||
.' <a href="http://fontawesome.io/" target="_blank">http://fontawesome.io/</a> or your icon class'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'label' => $this->l('Image name'),
|
||||
'name' => 'image',
|
||||
'default' => '',
|
||||
),
|
||||
array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Image'),
|
||||
'name' => 'image_link',
|
||||
'display_image' => true,
|
||||
'default' => '',
|
||||
'desc' => $this->l(''),
|
||||
'thumb' => '',
|
||||
'title' => $this->l('Icon Preview'),
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Content'),
|
||||
'name' => 'content_text',
|
||||
'lang' => true,
|
||||
'default' => '',
|
||||
'autoload_rte' => true
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-large btn-danger'
|
||||
)
|
||||
);
|
||||
|
||||
$this->fields_form[1]['form'] = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('SEO META'),
|
||||
),
|
||||
'input' => array(
|
||||
// custom template
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Meta description'),
|
||||
'name' => 'meta_description',
|
||||
'lang' => true,
|
||||
'cols' => 40,
|
||||
'rows' => 10,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}',
|
||||
'default' => ''
|
||||
),
|
||||
array(
|
||||
'type' => 'tags',
|
||||
'label' => $this->l('Meta keywords'),
|
||||
'name' => 'meta_keywords',
|
||||
'lang' => true,
|
||||
'default' => '',
|
||||
'hint' => array(
|
||||
$this->l('Invalid characters:').' <>;=#{}',
|
||||
$this->l('To add "tags" click in the field, write something, and then press "Enter."')
|
||||
)
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-large btn-danger'
|
||||
)
|
||||
);
|
||||
|
||||
Media::addJsDef(array(
|
||||
'PS_ALLOW_ACCENTED_CHARS_URL' => (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'),
|
||||
));
|
||||
|
||||
$helper = new HelperForm();
|
||||
$helper->module = $this;
|
||||
$helper->name_controller = $this->name;
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->token = Tools::getValue('token');
|
||||
foreach (Language::getLanguages(false) as $lang) {
|
||||
$helper->languages[] = array(
|
||||
'id_lang' => $lang['id_lang'],
|
||||
'iso_code' => $lang['iso_code'],
|
||||
'name' => $lang['name'],
|
||||
'is_default' => ($default_lang == $lang['id_lang'] ? 1 : 0)
|
||||
);
|
||||
}
|
||||
|
||||
$helper->currentIndex = AdminController::$currentIndex;
|
||||
$helper->default_form_language = $default_lang;
|
||||
$helper->allow_employee_form_lang = $default_lang;
|
||||
$helper->toolbar_scroll = true;
|
||||
$helper->title = $this->l('Categories Management');
|
||||
$helper->submit_action = 'save'.$this->name;
|
||||
$helper->tpl_vars = array(
|
||||
'fields_value' => $this->getConfigFieldsValues($obj),
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id,
|
||||
);
|
||||
|
||||
$helper->toolbar_btn = false;
|
||||
$this->context->smarty->assign(array(
|
||||
'leoblog_del_img_txt' => $this->l('Delete'),
|
||||
'leoblog_del_img_mess' => $this->l('Are you sure delete this?'),
|
||||
'action' => AdminController::$currentIndex.'&save'.$this->name.'&token='.Tools::getValue('token'),
|
||||
'addnew' => AdminController::$currentIndex.'&token='.Tools::getValue('token'),
|
||||
'generate_form' => $helper->generateForm($this->fields_form),
|
||||
'text_title' => $this->l('Tree Blog Categories Management'),
|
||||
'text_content' => $this->l('To sort orders or update parent-child, you drap and drop expected menu.'),
|
||||
'text_value' => $this->l('New Category'),
|
||||
'text_process' => $this->l('Processing ...'),
|
||||
'tree' => $tree,
|
||||
));
|
||||
|
||||
$content = Context::getContext()->smarty->fetch($this->getTemplatePath().'category.tpl');
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asign value for each input of Data form
|
||||
*/
|
||||
public function getConfigFieldsValues($obj)
|
||||
{
|
||||
$languages = Language::getLanguages(false);
|
||||
$fields_values = array();
|
||||
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
|
||||
foreach ($this->fields_form as $k => $f) {
|
||||
foreach ($f['form']['input'] as $j => $input) {
|
||||
if (isset($obj->{trim($input['name'])})) {
|
||||
if (isset($obj->{trim($input['name'])})) {
|
||||
$data = $obj->{trim($input['name'])};
|
||||
} else {
|
||||
$data = $input['default'];
|
||||
}
|
||||
|
||||
if (isset($input['lang'])) {
|
||||
foreach ($languages as $lang) {
|
||||
# validate module
|
||||
$fields_values[$input['name']][$lang['id_lang']] = isset($data[$lang['id_lang']]) ? $data[$lang['id_lang']] : $input['default'];
|
||||
}
|
||||
} else {
|
||||
# validate module
|
||||
$fields_values[$input['name']] = $data;
|
||||
}
|
||||
} else {
|
||||
//if ($input['name'] == 'image_link' && $data) {
|
||||
if ($input['name'] == 'image_link' && $obj->image != '') {
|
||||
//$thumb = __PS_BASE_URI__.'modules/'.$this->name.'/views/img/c/'.$data;
|
||||
$thumb = _THEME_DIR_.'/assets/img/modules/leoblog/'.$id_shop.'/c/'.$obj->image;
|
||||
$this->fields_form[$k]['form']['input'][$j]['thumb'] = $thumb;
|
||||
}
|
||||
|
||||
if (isset($input['lang'])) {
|
||||
foreach ($languages as $lang) {
|
||||
$v = Tools::getValue('title', Configuration::get($input['name'], $lang['id_lang']));
|
||||
$fields_values[$input['name']][$lang['id_lang']] = $v ? $v : $input['default'];
|
||||
}
|
||||
} else {
|
||||
$v = Tools::getValue($input['name'], Configuration::get($input['name']));
|
||||
$fields_values[$input['name']] = $v ? $v : $input['default'];
|
||||
}
|
||||
|
||||
if ($input['name'] == $obj->type.'_type') {
|
||||
# validate module
|
||||
$fields_values[$input['name']] = $obj->item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fields_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
|
||||
if (count($this->errors) <= 0) {
|
||||
if ($this->id_object) {
|
||||
# EDIT
|
||||
if (!$this->access('edit')) {
|
||||
if (Tools::isSubmit('save'.$this->name) && Tools::getValue('save'.$this->name)) {
|
||||
$this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->access('delete')) {
|
||||
if (Tools::getValue('dodel')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to delete this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# ADD
|
||||
if (!$this->access('add')) {
|
||||
if (Tools::isSubmit('save'.$this->name) && Tools::getValue('save'.$this->name)) {
|
||||
$this->errors[] = $this->trans('You do not have permission to add this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
188
modules/leoblog/controllers/admin/AdminLeoblogComments.php
Normal file
188
modules/leoblog/controllers/admin/AdminLeoblogComments.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?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');
|
||||
require_once(_PS_MODULE_DIR_.'leoblog/classes/comment.php');
|
||||
|
||||
class AdminLeoblogCommentsController extends ModuleAdminController
|
||||
{
|
||||
protected $max_image_size = 1048576;
|
||||
protected $position_identifier = 'id_leoblog_blog';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'leoblog_comment';
|
||||
$this->identifier = 'id_comment';
|
||||
$this->className = 'LeoBlogComment';
|
||||
$this->lang = false;
|
||||
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('delete');
|
||||
|
||||
if (Tools::getValue('id_leoblog_blog')) {
|
||||
# validate module
|
||||
$this->_where = ' AND id_leoblog_blog='.(int)Tools::getValue('id_leoblog_blog');
|
||||
}
|
||||
parent::__construct();
|
||||
|
||||
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
|
||||
|
||||
$this->fields_list = array(
|
||||
'id_comment' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
|
||||
'id_leoblog_blog' => array('title' => $this->l('Blog ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
|
||||
'user' => array('title' => $this->l('User')),
|
||||
'comment' => array('title' => $this->l('Comment')),
|
||||
'date_add' => array('title' => $this->l('Date Added'),'type' => 'datetime'),
|
||||
'active' => array('title' => $this->l('Displayed'), 'align' => 'center', 'active' => 'status', 'class' => 'fixed-width-sm', 'type' => 'bool', 'orderby' => false)
|
||||
);
|
||||
}
|
||||
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
$link = $this->context->link;
|
||||
|
||||
if (Tools::getValue('id_leoblog_blog')) {
|
||||
$this->page_header_toolbar_btn['back-blog'] = array(
|
||||
'href' => $link->getAdminLink('AdminLeoblogBlogs').'&updateleoblog_blog&id_leoblog_blog='.Tools::getValue('id_leoblog_blog'),
|
||||
'desc' => $this->l('Back To The Blog'),
|
||||
'icon' => 'icon-blog icon-3x process-icon-blog'
|
||||
);
|
||||
}
|
||||
return parent::initPageHeaderToolbar();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
if (!$this->loadObject(true)) {
|
||||
if (Validate::isLoadedObject($this->object)) {
|
||||
$this->display = 'edit';
|
||||
} else {
|
||||
$this->display = 'add';
|
||||
}
|
||||
}
|
||||
$this->initToolbar();
|
||||
$this->initPageHeaderToolbar();
|
||||
$blog = new LeoBlogBlog($this->object->id_leoblog_blog, $this->context->language->id);
|
||||
|
||||
$this->multiple_fieldsets = true;
|
||||
$this->object->blog_title = $blog->meta_title;
|
||||
|
||||
$this->fields_form[0]['form'] = array(
|
||||
'tinymce' => true,
|
||||
'legend' => array(
|
||||
'title' => $this->l('Blog Form'),
|
||||
'icon' => 'icon-folder-close'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'label' => $this->l('Comment ID'),
|
||||
'name' => 'id_comment',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Blog Title'),
|
||||
'name' => 'blog_title',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('User'),
|
||||
'name' => 'user',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Email'),
|
||||
'name' => 'email',
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Blog Content'),
|
||||
'name' => 'comment',
|
||||
'rows' => 5,
|
||||
'cols' => 40,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Displayed:'),
|
||||
'name' => 'active',
|
||||
'required' => false,
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-default pull-right'
|
||||
),
|
||||
'buttons' => array(
|
||||
'save_and_preview' => array(
|
||||
'name' => 'saveandstay',
|
||||
'type' => 'submit',
|
||||
'title' => $this->l('Save and stay'),
|
||||
'class' => 'btn btn-default pull-right',
|
||||
'icon' => 'process-icon-save-and-stay'
|
||||
)
|
||||
)
|
||||
);
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
$this->toolbar_title = $this->l('Comments Management');
|
||||
$this->toolbar_btn['new'] = null;
|
||||
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('saveandstay')) {
|
||||
parent::validateRules();
|
||||
|
||||
if (count($this->errors)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($id_comment = (int)Tools::getValue('id_comment')) {
|
||||
$comment = new LeoBlogComment($id_comment);
|
||||
$this->copyFromPost($comment, 'comment');
|
||||
|
||||
if (!$comment->update()) {
|
||||
$this->errors[] = $this->l('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
|
||||
} else {
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.Tools::getValue('id_comment').'&conf=4&update'.$this->table.'&token='.Tools::getValue('token'));
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->l('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
|
||||
}
|
||||
} else {
|
||||
parent::postProcess();
|
||||
}
|
||||
}
|
||||
}
|
||||
839
modules/leoblog/controllers/admin/AdminLeoblogDashboard.php
Normal file
839
modules/leoblog/controllers/admin/AdminLeoblogDashboard.php
Normal file
@@ -0,0 +1,839 @@
|
||||
<?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');
|
||||
require_once(_PS_MODULE_DIR_.'leoblog/classes/comment.php');
|
||||
|
||||
class AdminLeoblogDashboardController extends ModuleAdminController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->display = 'view';
|
||||
$this->addRowAction('view');
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
parent::initPageHeaderToolbar();
|
||||
|
||||
$this->page_header_toolbar_title = $this->l('Dashboard');
|
||||
$this->page_header_toolbar_btn = array();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (count($this->errors)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('saveConfiguration')) {
|
||||
$keys = LeoBlogHelper::getConfigKey(false);
|
||||
$post = array();
|
||||
foreach ($keys as $key) {
|
||||
# validate module
|
||||
$post[$key] = Tools::getValue($key);
|
||||
if ($key == 'social_code') {
|
||||
$post[$key] = LeoBlogHelper::correctEnCodeData(Tools::getValue($key));
|
||||
}
|
||||
}
|
||||
|
||||
$multi_lang_keys = LeoBlogHelper::getConfigKey(true);
|
||||
foreach ($multi_lang_keys as $multi_lang_key) {
|
||||
foreach (Language::getIDs(false) as $id_lang) {
|
||||
$post[$multi_lang_key.'_'.(int)$id_lang] = Tools::getValue($multi_lang_key.'_'.(int)$id_lang);
|
||||
}
|
||||
}
|
||||
// print_r(Tools::jsonEncode($post));die;
|
||||
// Configuration::updateValue(Tools::strtoupper(_LEO_BLOG_PREFIX_.'cfg_global_'.$post['template']), Tools::jsonEncode($post));
|
||||
if ($post['template'] != 'default') {
|
||||
LeoBlogConfig::updateConfigValue('cfg_global_'.$post['template'], Tools::jsonEncode($post));
|
||||
} else {
|
||||
LeoBlogConfig::updateConfigValue('cfg_global', Tools::jsonEncode($post));
|
||||
}
|
||||
|
||||
|
||||
Configuration::updateValue(Tools::strtoupper(_LEO_BLOG_PREFIX_.'template_current'), $post['template']);
|
||||
Configuration::updateValue('LEOBLOG_DASHBOARD_DEFAULTTAB', Tools::getValue('LEOBLOG_DASHBOARD_DEFAULTTAB'));
|
||||
}
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
$this->addJqueryUi('ui.widget');
|
||||
$this->addJqueryPlugin('tagify');
|
||||
if (file_exists(_PS_THEME_DIR_.'js/modules/leoblog/assets/form.js')) {
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.'modules/leoblog/assets/admin/form.js');
|
||||
} else {
|
||||
$this->context->controller->addJS(__PS_BASE_URI__.$this->module->getMediaDir().'js/admin/form.js');
|
||||
}
|
||||
}
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
$link = $this->context->link;
|
||||
|
||||
$quicktools = array();
|
||||
|
||||
$quicktools[] = array(
|
||||
'title' => $this->l('Categories'),
|
||||
'href' => $link->getAdminLink('AdminLeoblogCategories'),
|
||||
'icon' => 'icon-desktop',
|
||||
'class' => '',
|
||||
);
|
||||
|
||||
$quicktools[] = array(
|
||||
'title' => $this->l('Add Category'),
|
||||
'href' => $link->getAdminLink('AdminLeoblogCategories'),
|
||||
'icon' => 'icon-list',
|
||||
'class' => '',
|
||||
);
|
||||
|
||||
$quicktools[] = array(
|
||||
'title' => $this->l('Blogs'),
|
||||
'href' => $link->getAdminLink('AdminLeoblogBlogs'),
|
||||
'icon' => 'icon-list',
|
||||
'class' => '',
|
||||
);
|
||||
|
||||
$quicktools[] = array(
|
||||
'title' => $this->l('Add Blog'),
|
||||
'href' => $link->getAdminLink('AdminLeoblogBlogs').'&addleoblog_blog',
|
||||
'icon' => 'icon-list',
|
||||
'class' => '',
|
||||
);
|
||||
|
||||
$quicktools[] = array(
|
||||
'title' => $this->l('Comments'),
|
||||
'href' => $link->getAdminLink('AdminLeoblogComments'),
|
||||
'icon' => 'icon-list',
|
||||
'class' => '',
|
||||
);
|
||||
|
||||
$onoff = array(
|
||||
array(
|
||||
'id' => 'indexation_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'indexation_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
);
|
||||
|
||||
//$obj = new Leoblogcat();
|
||||
//$menus = $obj->getDropdown(null, $obj->id_parent);
|
||||
$templates = LeoBlogHelper::getTemplates();
|
||||
$url_rss = Tools::htmlentitiesutf8('http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__).'modules/leoblog/rss.php';
|
||||
$form = '';
|
||||
|
||||
$this->fields_form[0]['form'] = array(
|
||||
'tinymce' => true,
|
||||
// 'legend' => array(
|
||||
// 'title' => $this->l('General Setting'),
|
||||
// 'icon' => 'icon-folder-close',
|
||||
// ),
|
||||
'input' => array(
|
||||
|
||||
// custom template
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'LEOBLOG_DASHBOARD_DEFAULTTAB',
|
||||
'default' => '',
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Theme - Template'),
|
||||
'name' => 'template',
|
||||
'options' => array('query' => $templates,
|
||||
'id' => 'template',
|
||||
'name' => 'template'),
|
||||
'default' => 'default',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Root Link Title'),
|
||||
'name' => 'blog_link_title',
|
||||
'required' => true,
|
||||
'lang' => true,
|
||||
'desc' => $this->l('Make Link Title For Blog Root Link, Example http://domain/blog'),
|
||||
'default' => 'Blog',
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Friendly URL'),
|
||||
'name' => 'url_use_id',
|
||||
'required' => false,
|
||||
'class' => 'form-action',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'hint' => $this->l('When turn on Prestashop SEO, Blog show Friendly URL'),
|
||||
'options' => array(
|
||||
'query' => array(
|
||||
array(
|
||||
'value' => 1,
|
||||
'name' => self::l('Include ID'),
|
||||
),
|
||||
array(
|
||||
'value' => 0,
|
||||
'name' => self::l('NOT include ID'),
|
||||
),
|
||||
),
|
||||
'id' => 'value',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Root'),
|
||||
'name' => 'link_rewrite',
|
||||
'required' => true,
|
||||
'lang' => true,
|
||||
// 'desc' => $this->l('Make seo start with this, Example http://domain/blog'),
|
||||
'hint' => $this->l('Example http://domain/blog.html'),
|
||||
'default' => 'blog',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Category'),
|
||||
'name' => 'category_rewrite',
|
||||
'required' => true,
|
||||
'lang' => true,
|
||||
'default' => 'category',
|
||||
'form_group_class' => 'url_use_id_sub url_use_id-0',
|
||||
'hint' => $this->l('Example http://domain/blog/category/name.html'),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Detail'),
|
||||
'name' => 'detail_rewrite',
|
||||
'required' => true,
|
||||
'lang' => true,
|
||||
'default' => 'detail',
|
||||
'form_group_class' => 'url_use_id_sub url_use_id-0',
|
||||
'hint' => $this->l('Example http://domain/blog/detail/name.html'),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Meta Title'),
|
||||
'name' => 'meta_title',
|
||||
'lang' => true,
|
||||
'cols' => 40,
|
||||
'rows' => 10,
|
||||
'default' => 'Blog',
|
||||
'desc' => $this->l('Display browser title on frontpage blog')
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Meta description'),
|
||||
'name' => 'meta_description',
|
||||
'lang' => true,
|
||||
'cols' => 40,
|
||||
'rows' => 10,
|
||||
'default' => '',
|
||||
'desk' => $this->l('Display meta descrition on frontpage blog').'note: note <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'tags',
|
||||
'label' => $this->l('Meta keywords'),
|
||||
'name' => 'meta_keywords',
|
||||
'default' => '',
|
||||
'lang' => true,
|
||||
'desc' => array(
|
||||
$this->l('Invalid characters:').' <>;=#{}',
|
||||
$this->l('To add "tags" click in the field, write something, and then press "Enter."')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Rss:'),
|
||||
'name' => 'indexation',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '',
|
||||
'values' => $onoff,
|
||||
'desc' => $url_rss
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Rss Limit Items'),
|
||||
'name' => 'rss_limit_item',
|
||||
'default' => '20',
|
||||
'desc' => 'Set Maximun shows in rss'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Rss Title'),
|
||||
'name' => 'rss_title_item',
|
||||
'default' => 'RSS FEED',
|
||||
'desc' => 'Set title in rss'
|
||||
),
|
||||
// array(
|
||||
// 'type' => 'text',
|
||||
// 'label' => $this->l('Limit Latest Item'),
|
||||
// 'name' => 'latest_limit_items',
|
||||
// 'default' => '20',
|
||||
// 'desc' => 'Set Maximun shows in latest blog page'
|
||||
// ),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-danger'
|
||||
)
|
||||
);
|
||||
|
||||
$this->fields_form[1]['form'] = array(
|
||||
'tinymce' => true,
|
||||
'default' => '',
|
||||
// 'legend' => array(
|
||||
// 'title' => $this->l('Listing Blog Setting'),
|
||||
// 'icon' => 'icon-folder-close'
|
||||
// ),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Category Info:'),
|
||||
'name' => 'listing_show_categoryinfo',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'desc' => $this->l('Display category information in listing blogs'),
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Sub Categories:'),
|
||||
'name' => 'listing_show_subcategories',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
'desc' => $this->l('Display subcategory in listing blog')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Leading Column:'),
|
||||
'name' => 'listing_leading_column',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '1',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Leading Limit Items:'),
|
||||
'name' => 'listing_leading_limit_items',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '2',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Leading Image Width:'),
|
||||
'name' => 'listing_leading_img_width',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '690',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Leading Image Height:'),
|
||||
'name' => 'listing_leading_img_height',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '300',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Secondary Column:'),
|
||||
'name' => 'listing_secondary_column',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '3',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Secondary Limit Items:'),
|
||||
'name' => 'listing_secondary_limit_items',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '6',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Secondary Image Width:'),
|
||||
'name' => 'listing_secondary_img_width',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '390',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Secondary Image Height:'),
|
||||
'name' => 'listing_secondary_img_height',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '220',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Title:'),
|
||||
'name' => 'listing_show_title',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Description:'),
|
||||
'name' => 'listing_show_description',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Readmore:'),
|
||||
'name' => 'listing_show_readmore',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Image:'),
|
||||
'name' => 'listing_show_image',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Author:'),
|
||||
'name' => 'listing_show_author',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Category:'),
|
||||
'name' => 'listing_show_category',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Created Date:'),
|
||||
'name' => 'listing_show_created',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Hits:'),
|
||||
'name' => 'listing_show_hit',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Counter:'),
|
||||
'name' => 'listing_show_counter',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-danger'
|
||||
)
|
||||
);
|
||||
|
||||
$this->fields_form[2]['form'] = array(
|
||||
'tinymce' => true,
|
||||
'default' => '',
|
||||
// 'legend' => array(
|
||||
// 'title' => $this->l('Item Blog Setting'),
|
||||
// 'icon' => 'icon-folder-close'
|
||||
// ),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Item Image Width:'),
|
||||
'name' => 'item_img_width',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '690',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Item Image Height:'),
|
||||
'name' => 'item_img_height',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '350',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Description:'),
|
||||
'name' => 'item_show_description',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Image:'),
|
||||
'name' => 'item_show_image',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Author:'),
|
||||
'name' => 'item_show_author',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Category:'),
|
||||
'name' => 'item_show_category',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Created Date:'),
|
||||
'name' => 'item_show_created',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Hits:'),
|
||||
'name' => 'item_show_hit',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Counter:'),
|
||||
'name' => 'item_show_counter',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Social Sharing CODE'),
|
||||
'name' => 'social_code',
|
||||
'required' => false,
|
||||
'default' => '',
|
||||
'desc' => 'put sharing social code from sharethis service....to replace current sharing social.'
|
||||
),
|
||||
// array(
|
||||
// 'type' => 'switch',
|
||||
// 'label' => $this->l('Comment Engine:'),
|
||||
// 'name' => 'item_comment_engine',
|
||||
// 'required' => false,
|
||||
// 'class' => 't',
|
||||
// 'default' => '1',
|
||||
// 'values' => $onoff,
|
||||
// ),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show List Comment:'),
|
||||
'name' => 'item_show_listcomment',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
'desc' => $this->l('Show/Hidden the list comment'),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Form Comment:'),
|
||||
'name' => 'item_show_formcomment',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'default' => '1',
|
||||
'values' => $onoff,
|
||||
'desc' => $this->l('This option just worked for the local comment'),
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Comment Engine:'),
|
||||
'name' => 'item_comment_engine',
|
||||
'id' => 'item_comment_engine',
|
||||
'options' => array('query' => array(
|
||||
array('id' => 'local', 'name' => $this->l('Local')),
|
||||
array('id' => 'facebook', 'name' => $this->l('Facebook')),
|
||||
array('id' => 'diquis', 'name' => $this->l('Diquis')),
|
||||
),
|
||||
'id' => 'id',
|
||||
'name' => 'name'),
|
||||
'default' => 'local'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Limit Local Comment'),
|
||||
'name' => 'item_limit_comments',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '10',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Diquis Account:'),
|
||||
'name' => 'item_diquis_account',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => 'demo4leotheme',
|
||||
'desc' => '<a target="_blank" href="https://disqus.com/admin/signup/">'.$this->l('Sign Up Diquis').'</a>'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Facebook Application ID:'),
|
||||
'name' => 'item_facebook_appid',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '100858303516',
|
||||
'desc' => '<a target="_blank" href="http://developers.facebook.com/docs/reference/plugins/comments/">'.$this->l('Register A Comment Box, Then Get Application ID in Script Or Register Facebook Application ID to moderate comments').'</a>'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Facebook Width:'),
|
||||
'name' => 'item_facebook_width',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'default' => '600'
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-danger'
|
||||
)
|
||||
);
|
||||
$this->fields_form[3]['form'] = array(
|
||||
'tinymce' => true,
|
||||
'default' => '',
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Popular Blog'),
|
||||
'name' => 'show_popular_blog',
|
||||
'is_bool' => true,
|
||||
'default' => '0',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Limit Popular Blog'),
|
||||
'name' => 'limit_popular_blog',
|
||||
'default' => '5',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Recent Blog'),
|
||||
'name' => 'show_recent_blog',
|
||||
'is_bool' => true,
|
||||
'default' => '0',
|
||||
'values' => $onoff,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Limit Recent Blog'),
|
||||
'name' => 'limit_recent_blog',
|
||||
'default' => '5',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show All Tags'),
|
||||
'name' => 'show_all_tags',
|
||||
'is_bool' => true,
|
||||
'default' => '0',
|
||||
'values' => $onoff,
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-danger'
|
||||
)
|
||||
);
|
||||
|
||||
if (Configuration::get(Tools::strtoupper(_LEO_BLOG_PREFIX_.'template_current')) == 'default') {
|
||||
$data = LeoBlogConfig::getConfigValue('cfg_global');
|
||||
} else {
|
||||
$data = LeoBlogConfig::getConfigValue('cfg_global_'.Configuration::get(Tools::strtoupper(_LEO_BLOG_PREFIX_.'template_current')));
|
||||
}
|
||||
|
||||
$obj = new stdClass();
|
||||
|
||||
if ($data && $tmp = Tools::jsonDecode($data, true)) {
|
||||
foreach ($tmp as $key => $value) {
|
||||
# validate module
|
||||
$obj->{$key} = $value;
|
||||
}
|
||||
}
|
||||
$fields_value = $this->getConfigFieldsValues($obj);
|
||||
$fields_value['social_code'] = LeoBlogHelper::correctDeCodeData($fields_value['social_code']);
|
||||
$helper = new HelperForm($this);
|
||||
|
||||
$this->setHelperDisplay($helper);
|
||||
// $helper->override_folder = 'test/';
|
||||
$helper->fields_value = $fields_value;
|
||||
$helper->tpl_vars = $this->tpl_form_vars;
|
||||
!is_null($this->base_tpl_form) ? $helper->base_tpl = $this->base_tpl_form : '';
|
||||
if ($this->tabAccess['view']) {
|
||||
$helper->tpl_vars['show_toolbar'] = false;
|
||||
$helper->tpl_vars['submit_action'] = 'saveConfiguration';
|
||||
if (Tools::getValue('back')) {
|
||||
$helper->tpl_vars['back'] = '';
|
||||
} else {
|
||||
$helper->tpl_vars['back'] = '';
|
||||
}
|
||||
}
|
||||
$form = $helper->generateForm($this->fields_form);
|
||||
$template = $this->createTemplate('panel.tpl');
|
||||
|
||||
$comments = LeoBlogComment::getComments(null, 10, $this->context->language->id);
|
||||
$blogs = LeoBlogBlog::getListBlogs(null, $this->context->language->id, 0, 10, 'hits', 'DESC');
|
||||
|
||||
$template->assign(array(
|
||||
'quicktools' => $quicktools,
|
||||
'showed' => 1,
|
||||
'comment_link' => $link->getAdminLink('AdminLeoblogComments'),
|
||||
'blog_link' => $link->getAdminLink('AdminLeoblogBlogs'),
|
||||
'blogs' => $blogs,
|
||||
'count_blogs' => LeoBlogBlog::countBlogs(null, $this->context->language->id),
|
||||
'count_cats' => Leoblogcat::countCats(),
|
||||
'count_comments' => LeoBlogComment::countComments(),
|
||||
'latest_comments' => $comments,
|
||||
'globalform' => $form,
|
||||
'default_tab' => Configuration::get('LEOBLOG_DASHBOARD_DEFAULTTAB')
|
||||
));
|
||||
return $template->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asign value for each input of Data form
|
||||
*/
|
||||
public function getConfigFieldsValues($obj)
|
||||
{
|
||||
$languages = Language::getLanguages(false);
|
||||
$fields_values = array();
|
||||
|
||||
foreach ($this->fields_form as $k => $f) {
|
||||
foreach ($f['form']['input'] as $j => $input) {
|
||||
if (isset($input['lang'])) {
|
||||
foreach ($languages as $lang) {
|
||||
if (isset($obj->{trim($input['name']).'_'.$lang['id_lang']})) {
|
||||
$data = $obj->{trim($input['name']).'_'.$lang['id_lang']};
|
||||
$fields_values[$input['name']][$lang['id_lang']] = $data;
|
||||
} else {
|
||||
# validate module
|
||||
$fields_values[$input['name']][$lang['id_lang']] = $input['default'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isset($obj->{trim($input['name'])})) {
|
||||
$data = $obj->{trim($input['name'])};
|
||||
|
||||
if ($input['name'] == 'image' && $data) {
|
||||
$thumb = __PS_BASE_URI__.'modules/'.$this->name.'/views/img/'.$data;
|
||||
$this->fields_form[$k]['form']['input'][$j]['thumb'] = $thumb;
|
||||
}
|
||||
|
||||
$fields_values[$input['name']] = $data;
|
||||
} else {
|
||||
# validate module
|
||||
$fields_values[$input['name']] = $input['default'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fields_values['LEOBLOG_DASHBOARD_DEFAULTTAB'] = Tools::getValue('LEOBLOG_DASHBOARD_DEFAULTTAB', Configuration::get('LEOBLOG_DASHBOARD_DEFAULTTAB'));
|
||||
return $fields_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
|
||||
if (count($this->errors) <= 0) {
|
||||
# EDIT
|
||||
if (!$this->access('edit')) {
|
||||
if (Tools::isSubmit('saveConfiguration') && Tools::getValue('saveConfiguration')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
modules/leoblog/controllers/admin/AdminLeoblogModule.php
Normal file
31
modules/leoblog/controllers/admin/AdminLeoblogModule.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminLeoblogModuleController extends ModuleAdminControllerCore
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$url = 'index.php?controller=adminmodules&configure=leoblog&tab_module=front_office_features&module_name=leoblog&token='.Tools::getAdminTokenLite('AdminModules');
|
||||
Tools::redirectAdmin($url);
|
||||
}
|
||||
}
|
||||
36
modules/leoblog/controllers/admin/index.php
Normal file
36
modules/leoblog/controllers/admin/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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
36
modules/leoblog/controllers/index.php
Normal file
36
modules/leoblog/controllers/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;
|
||||
Reference in New Issue
Block a user