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;
|
||||
Reference in New Issue
Block a user