first commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminApPageBuilderController extends ModuleAdminControllerCore
|
||||
{
|
||||
public static $shortcode_lang;
|
||||
public static $lang_id;
|
||||
public static $language;
|
||||
public $error_text = '';
|
||||
public $theme_name;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$url = 'index.php?controller=adminmodules&configure=appagebuilder&token='.Tools::getAdminTokenLite('AdminModules')
|
||||
.'&tab_module=Home&module_name=appagebuilder';
|
||||
Tools::redirectAdmin($url);
|
||||
$this->bootstrap = true;
|
||||
$this->className = 'Configuration';
|
||||
$this->table = 'configuration';
|
||||
$this->theme_name = apPageHelper::getThemeName();
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,815 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(_PS_MODULE_DIR_.'appagebuilder/classes/ApPageBuilderDetailsModel.php');
|
||||
|
||||
class AdminApPageBuilderDetailsController extends ModuleAdminControllerCore
|
||||
{
|
||||
private $theme_name = '';
|
||||
public $module_name = 'appagebuilder';
|
||||
public $tpl_save = '';
|
||||
public $file_content = array();
|
||||
public $explicit_select;
|
||||
public $order_by;
|
||||
public $order_way;
|
||||
public $profile_css_folder;
|
||||
public $module_path;
|
||||
// public $module_path_resource;
|
||||
public $str_search = array();
|
||||
public $str_relace = array();
|
||||
public $theme_dir;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'appagebuilder_details';
|
||||
$this->className = 'ApPageBuilderDetailsModel';
|
||||
$this->lang = false;
|
||||
$this->explicit_select = true;
|
||||
$this->allow_export = true;
|
||||
$this->can_import = true;
|
||||
$this->context = Context::getContext();
|
||||
$this->_join = '
|
||||
INNER JOIN `'._DB_PREFIX_.'appagebuilder_details_shop` ps ON (ps.`id_appagebuilder_details` = a.`id_appagebuilder_details`)';
|
||||
$this->_select .= ' ps.active as active, ps.active_mobile as active_mobile, ps.active_tablet as active_tablet';
|
||||
|
||||
$this->order_by = 'id_appagebuilder_details';
|
||||
$this->order_way = 'DESC';
|
||||
parent::__construct();
|
||||
$this->fields_list = array(
|
||||
'id_appagebuilder_details' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 50,
|
||||
'class' => 'fixed-width-xs'
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Name'),
|
||||
'width' => 140,
|
||||
'type' => 'text',
|
||||
'filter_key' => 'a!name'
|
||||
),
|
||||
'plist_key' => array(
|
||||
'title' => $this->l('Product List Key'),
|
||||
'filter_key' => 'a!plist_key',
|
||||
'type' => 'text',
|
||||
'width' => 140,
|
||||
),
|
||||
'class_detail' => array(
|
||||
'title' => $this->l('Class'),
|
||||
'width' => 140,
|
||||
'type' => 'text',
|
||||
'filter_key' => 'a!class_detail',
|
||||
'orderby' => false
|
||||
),
|
||||
'active' => array(
|
||||
'title' => $this->l('Is Default'),
|
||||
'active' => 'status',
|
||||
'filter_key' => 'ps!active',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
),
|
||||
'active_mobile' => array(
|
||||
'title' => $this->l('Is Mobile'),
|
||||
'active' => 'active_mobile',
|
||||
'filter_key' => 'ps!active_mobile',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
),
|
||||
'active_tablet' => array(
|
||||
'title' => $this->l('Is Tablet'),
|
||||
'active' => 'active_table',
|
||||
'filter_key' => 'ps!active_tablet',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
)
|
||||
);
|
||||
$this->bulk_actions = array(
|
||||
'delete' => array(
|
||||
'text' => $this->l('Delete selected'),
|
||||
'confirm' => $this->l('Delete selected items?'),
|
||||
'icon' => 'icon-trash'
|
||||
)
|
||||
);
|
||||
$this->theme_dir = apPageHelper::getConfigDir('_PS_THEME_DIR_');
|
||||
|
||||
//nghiatd - add theme mobile and table
|
||||
$correct_mobile = Db::getInstance()->executeS('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "'._DB_NAME_.'" AND TABLE_NAME="'._DB_PREFIX_.'appagebuilder_details" AND column_name="active_mobile"');
|
||||
if (count($correct_mobile) < 1) {
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_details_shop` ADD `active_mobile` int(11) NOT NULL');
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_details_shop` ADD `active_tablet` int(11) NOT NULL');
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_details` ADD `active_mobile` int(11) NOT NULL');
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_details` ADD `active_tablet` int(11) NOT NULL');
|
||||
}
|
||||
|
||||
$this->_where = ' AND ps.id_shop='.(int)$this->context->shop->id;
|
||||
$this->theme_name = apPageHelper::getThemeName();
|
||||
$this->profile_css_folder = $this->theme_dir.'modules/'.$this->module_name.'/';
|
||||
$this->module_path = __PS_BASE_URI__.'modules/'.$this->module_name.'/';
|
||||
// $this->module_path_resource = $this->module_path.'views/';
|
||||
$this->str_search = array('_APAMP_', '_APQUOT_', '_APAPOST_', '_APTAB_', '_APNEWLINE_', '_APENTER_', '_APOBRACKET_', '_APCBRACKET_', '_APOCBRACKET_', '_APCCBRACKET_',);
|
||||
$this->str_relace = array('&', '\"', '\'', '\t', '\r', '\n', '[', ']', '{', '}');
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
parent::initToolbar();
|
||||
|
||||
# SAVE AND STAY
|
||||
if ($this->display == 'add' || $this->display == 'edit') {
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/function.js');
|
||||
|
||||
$this->page_header_toolbar_btn['SaveAndStay'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save and stay'),
|
||||
'js' => 'TopSaveAndStay()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSaveAndStay_Name' => 'submitAdd'.$this->table.'AndStay'));
|
||||
|
||||
$this->page_header_toolbar_btn['Save'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save'),
|
||||
'js' => 'TopSave()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSave_Name' => 'submitAdd'.$this->table));
|
||||
}
|
||||
|
||||
# SHOW LINK EXPORT ALL FOR TOOLBAR
|
||||
switch ($this->display) {
|
||||
default:
|
||||
$this->toolbar_btn['new'] = array(
|
||||
'href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->l('Add new'),
|
||||
'class' => 'btn_add_new',
|
||||
);
|
||||
if (!$this->display && $this->can_import) {
|
||||
$this->toolbar_btn['import'] = array(
|
||||
'href' => self::$currentIndex . '&import' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->trans('Import', array(), 'Admin.Actions'),
|
||||
'class' => 'btn_xml_import',
|
||||
);
|
||||
}
|
||||
if ($this->allow_export) {
|
||||
$this->toolbar_btn['export'] = array(
|
||||
'href' => self::$currentIndex . '&export' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->l('Export'),
|
||||
'class' => 'btn_xml_export',
|
||||
);
|
||||
Media::addJsDef(array('record_id' => 'appagebuilder_detailsBox[]'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function processExport($text_delimiter = '"')
|
||||
{
|
||||
$record_id = Tools::getValue('record_id');
|
||||
$file_name = 'ap_product_detail_all.xml';
|
||||
# VALIDATE MODULE
|
||||
unset($text_delimiter);
|
||||
|
||||
if ($record_id) {
|
||||
$record_id_str = implode(", ", $record_id);
|
||||
$this->_where = ' AND a.id_appagebuilder_details IN ( '.pSQL($record_id_str).' )';
|
||||
$file_name = 'ap_product_detail.xml';
|
||||
}
|
||||
|
||||
$this->getList($this->context->language->id, null, null, 0, false);
|
||||
if (!count($this->_list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->_list;
|
||||
$this->file_content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
$this->file_content .= '<data>' . "\n";
|
||||
$this->file_content .= '<product_details>' . "\n";
|
||||
if ($data) {
|
||||
foreach ($data as $product_detail) {
|
||||
$this->file_content .= '<record>' . "\n";
|
||||
foreach ($product_detail as $key => $value) {
|
||||
$this->file_content .= ' <'.$key.'>';
|
||||
$this->file_content .= '<![CDATA['.$value.']]>';
|
||||
$this->file_content .= '</'.$key.'>' . "\n";
|
||||
}
|
||||
$this->file_content .= '</record>' . "\n";
|
||||
}
|
||||
}
|
||||
$this->file_content .= '</product_details>' . "\n";
|
||||
$this->file_content .= '</data>' . "\n";
|
||||
header('Content-type: text/xml');
|
||||
header('Content-Disposition: attachment; filename="'.$file_name.'"');
|
||||
echo $this->file_content;
|
||||
die();
|
||||
}
|
||||
|
||||
public function processImport()
|
||||
{
|
||||
$upload_file = new Uploader('importFile');
|
||||
$upload_file->setAcceptTypes(array('xml'));
|
||||
$file = $upload_file->process();
|
||||
$file = $file[0];
|
||||
if (!isset($file['save_path'])) {
|
||||
$this->errors[] = $this->trans('Failed to import.', array(), 'Admin.Notifications.Error');
|
||||
return;
|
||||
}
|
||||
$files_content = simplexml_load_file($file['save_path']);
|
||||
$override = Tools::getValue('override');
|
||||
|
||||
if (isset($files_content->product_details) && $files_content->product_details) {
|
||||
foreach ($files_content->product_details->children() as $product_details) {
|
||||
if (!$override) {
|
||||
$num = ApPageSetting::getRandomNumber();
|
||||
$obj_model = new ApPageBuilderDetailsModel();
|
||||
$obj_model->plist_key = 'detail'.$num;
|
||||
$obj_model->name = $product_details->name->__toString();
|
||||
$obj_model->class_detail = $product_details->class_detail->__toString();
|
||||
$obj_model->params = $product_details->params->__toString();
|
||||
$obj_model->type = $product_details->type->__toString();
|
||||
$obj_model->active = 0;
|
||||
$obj_model->url_img_preview = $product_details->url_img_preview->__toString();
|
||||
if ($obj_model->save()) {
|
||||
$this->saveTplFile($obj_model->plist_key, $obj_model->params);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->confirmations[] = $this->trans('Successful importing.', array(), 'Admin.Notifications.Success');
|
||||
} else {
|
||||
$this->errors[] = $this->trans('Failed to import.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
if ($object->page == 'product_detail') {
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderProductDetail');
|
||||
} else {
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderHome');
|
||||
}
|
||||
$this->redirect_after .= '&id_appagebuilder_details='.$object->id;
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
parent::postProcess();
|
||||
|
||||
if (Tools::getIsset('active_mobileappagebuilder_details') || Tools::getIsset('active_tableappagebuilder_details')) {
|
||||
if (Validate::isLoadedObject($object = $this->loadObject())) {
|
||||
$result = Tools::getIsset('active_mobileappagebuilder_details')?$object->toggleStatusMT('active_mobile'):$object->toggleStatusMT('active_tablet');
|
||||
if ($result) {
|
||||
// $this->mesage[] = Tools::displayError('You should enebale mobile theme in theme config');
|
||||
|
||||
$matches = array();
|
||||
if (preg_match('/[\?|&]controller=([^&]*)/', (string)$_SERVER['HTTP_REFERER'], $matches) !== false && Tools::strtolower($matches[1]) != Tools::strtolower(preg_replace('/controller/i', '', get_class($this)))) {
|
||||
$this->redirect_after = preg_replace('/[\?|&]conf=([^&]*)/i', '', (string)$_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token.'&mobiletheme';
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('You can not disable default profile, Please select other profile as default');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('An error occurred while updating the status for an object.')
|
||||
.'<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->errors) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::getIsset('duplicateappagebuilder_details')) {
|
||||
$id = Tools::getValue('id_appagebuilder_details');
|
||||
$model = new ApPageBuilderDetailsModel($id);
|
||||
$duplicate_object = $model->duplicateObject();
|
||||
$duplicate_object->name = $this->l('Duplicate of').' '.$duplicate_object->name;
|
||||
$old_key = $duplicate_object->plist_key;
|
||||
$duplicate_object->plist_key = 'detail'.ApPageSetting::getRandomNumber();
|
||||
# FIX 1751 : empty
|
||||
$duplicate_object->params = $model->params;
|
||||
if ($duplicate_object->add()) {
|
||||
//duplicate shortCode
|
||||
$filecontent = Tools::file_get_contents(apPageHelper::getConfigDir('theme_details').$old_key.'.tpl');
|
||||
ApPageSetting::writeFile(apPageHelper::getConfigDir('theme_details'), $duplicate_object->plist_key.'.tpl', $filecontent);
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token;
|
||||
$this->redirect();
|
||||
} else {
|
||||
Tools::displayError('Can not duplicate Profiles');
|
||||
}
|
||||
}
|
||||
if (Tools::isSubmit('saveELement')) {
|
||||
$filecontent = Tools::getValue('filecontent');
|
||||
$fileName = Tools::getValue('fileName');
|
||||
apPageHelper::createDir(apPageHelper::getConfigDir('theme_details'));
|
||||
ApPageSetting::writeFile(apPageHelper::getConfigDir('theme_details'), $fileName.'.tpl', $filecontent);
|
||||
}
|
||||
}
|
||||
|
||||
public function convertObjectToTpl($object_form)
|
||||
{
|
||||
$tpl = '';
|
||||
|
||||
foreach ($object_form as $object) {
|
||||
if ($object['name'] == 'functional_buttons') {
|
||||
//DONGND:: fix can save group column when change class
|
||||
if (isset($object['form']['class']) && $object['form']['class'] != '') {
|
||||
$tpl .= '<div class="'.$object['form']['class'].'">';
|
||||
} else {
|
||||
$tpl .= '<div class="row">';
|
||||
}
|
||||
foreach ($object['columns'] as $objectC) {
|
||||
$tpl .= '<div class="'.$this->convertToColumnClass($objectC['form']).'">';
|
||||
$tpl .= $this->convertObjectToTpl($objectC['sub']);
|
||||
$tpl .= '
|
||||
</div>';
|
||||
}
|
||||
|
||||
$tpl .= '</div>';
|
||||
} else if ($object['name'] == 'code') {
|
||||
$tpl .= $object['code'];
|
||||
} else {
|
||||
if (!isset($this->file_content[$object['name']])) {
|
||||
$this->returnFileContent($object['name']);
|
||||
//DONGND:: add config to type gallery
|
||||
if ($object['name'] == "product_image_with_thumb" || $object['name'] == "product_image_show_all") {
|
||||
$strdata = '';
|
||||
foreach ($object['form'] as $key => $value) {
|
||||
$strdata .= ' data-'.$key.'="'.$value.'"';
|
||||
}
|
||||
$this->file_content[$object['name']] = str_replace('id="content">', 'id="content"'.$strdata.'>', $this->file_content[$object['name']]);
|
||||
}
|
||||
}
|
||||
//add class
|
||||
$tpl .= $this->file_content[$object['name']];
|
||||
}
|
||||
}
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
public function convertToColumnClass($form)
|
||||
{
|
||||
$class = '';
|
||||
foreach ($form as $key => $val) {
|
||||
//DONGND:: check class name of column
|
||||
if ($key == 'class') {
|
||||
if ($val != '') {
|
||||
$class .= ($class=='')?$val:' '.$val;
|
||||
}
|
||||
} else {
|
||||
$class .= ($class=='')?'col-'.$key.'-'.$val:' col-'.$key.'-'.$val;
|
||||
}
|
||||
}
|
||||
return $class;
|
||||
}
|
||||
|
||||
public function returnFileContent($pelement)
|
||||
{
|
||||
$tpl_dir = apPageHelper::getConfigDir('theme_details').$pelement.'.tpl';
|
||||
if (!file_exists($tpl_dir)) {
|
||||
$tpl_dir = apPageHelper::getConfigDir('module_details').$pelement.'.tpl';
|
||||
}
|
||||
$this->file_content[$pelement] = Tools::file_get_contents($tpl_dir);
|
||||
return $this->file_content[$pelement];
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
if (Tools::getIsset('pelement')) {
|
||||
$helper = new HelperForm();
|
||||
$helper->submit_action = 'saveELement';
|
||||
$inputs = array(
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'name' => 'filecontent',
|
||||
'label' => $this->l('File Content'),
|
||||
'desc' => $this->l('Please carefully when edit tpl file'),
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'fileName',
|
||||
)
|
||||
);
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => sprintf($this->l('You are Editing file: %s'), Tools::getValue('pelement').'.tpl'),
|
||||
'icon' => 'icon-cogs'
|
||||
),
|
||||
'action' => Context::getContext()->link->getAdminLink('AdminApPageBuilderShortcodes'),
|
||||
'input' => $inputs,
|
||||
'name' => 'importData',
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'button btn btn-default pull-right'
|
||||
),
|
||||
'tinymce' => false,
|
||||
),
|
||||
);
|
||||
$helper->tpl_vars = array(
|
||||
'fields_value' => $this->getFileContent()
|
||||
);
|
||||
return $helper->generateForm(array($fields_form));
|
||||
}
|
||||
$this->initToolbar();
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('duplicate');
|
||||
$this->addRowAction('delete');
|
||||
return $this->importForm() . parent::renderList();
|
||||
}
|
||||
|
||||
public function getFileContent()
|
||||
{
|
||||
$pelement = Tools::getValue('pelement');
|
||||
$tpl_dir = apPageHelper::getConfigDir('theme_details').$pelement.'.tpl';
|
||||
if (!file_exists($tpl_dir)) {
|
||||
$tpl_dir = apPageHelper::getConfigDir('module_details').$pelement.'.tpl';
|
||||
}
|
||||
return array('fileName' => $pelement, 'filecontent' => Tools::file_get_contents($tpl_dir));
|
||||
}
|
||||
|
||||
public function setHelperDisplay(Helper $helper)
|
||||
{
|
||||
parent::setHelperDisplay($helper);
|
||||
$this->helper->module = APPageBuilder::getInstance();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$this->initToolbar();
|
||||
$this->context->controller->addJqueryUI('ui.sortable');
|
||||
$this->context->controller->addJqueryUI('ui.draggable');
|
||||
//$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/form.js');
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/detail.js');
|
||||
$this->context->controller->addCss(apPageHelper::getCssAdminDir().'admin/form.css');
|
||||
|
||||
if (is_dir(apPageHelper::getConfigDir('theme_details'))) {
|
||||
$source_file = Tools::scandir(apPageHelper::getConfigDir('theme_details'), 'tpl');
|
||||
$source_template_file = Tools::scandir(apPageHelper::getConfigDir('theme_details'), 'tpl');
|
||||
$source_file = array_merge($source_file, $source_template_file);
|
||||
}
|
||||
|
||||
$params = array('gridLeft' => array(), 'gridRight' => array());
|
||||
|
||||
$this->object->params = str_replace($this->str_search, $this->str_relace, $this->object->params);
|
||||
|
||||
$config_dir = apPageHelper::getConfigDir('theme_details') . 'config.json';
|
||||
if (!file_exists($config_dir)) {
|
||||
$config_dir = apPageHelper::getConfigDir('module_details') . 'config.json';
|
||||
}
|
||||
|
||||
$config_file = Tools::jsonDecode(Tools::file_get_contents($config_dir), true);
|
||||
$element_by_name = array();
|
||||
foreach ($config_file as $k1 => $groups) {
|
||||
foreach ($groups['group'] as $k2 => $group) {
|
||||
$config_file[$k1]['group'][$k2]['dataForm'] = (!isset($group['data-form']))?'':Tools::jsonEncode($group['data-form']);
|
||||
if (isset($group['file'])) {
|
||||
$element_by_name[$group['file']] = $group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->object->params)) {
|
||||
//add sample data
|
||||
if (Tools::getIsset('sampledetail')) {
|
||||
switch (Tools::getValue('sampledetail')) {
|
||||
case 'product_image_thumbs_bottom':
|
||||
$this->object->url_img_preview = 'https://i.pinimg.com/originals/8c/16/f9/8c16f9f024af16977adc1f618872eb8b.jpg';
|
||||
$this->object->params = '{"gridLeft":{"0":{"name":"functional_buttons","form":"","columns":{"0":{"form":{"form_id":"form_9367402777406408","md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_image_with_thumb","form":{"templateview":"bottom","numberimage":"5","numberimage1200":"5","numberimage992":"4","numberimage768":"3","numberimage576":"3","numberimage480":"2","numberimage360":"2","templatemodal":"1","templatethumb":"1","templatezoomtype":"out","zoomposition":"right","zoomwindowwidth":"400","zoomwindowheight":"400"}}}},"1":{"form":{"form_id":"form_15874367062488778","md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_detail_name","form":""},"1":{"name":"hook_display_product_additional_info","form":""},"2":{"name":"hook_display_leo_product_review_extra","form":""},"3":{"name":"product_price","form":""},"4":{"name":"product_description_short","form":""},"5":{"name":"product_customization","form":""},"6":{"name":"product_actions_form","form":""},"7":{"name":"hook_display_reassurance","form":""}}},"2":{"form":{"form_id":"form_4666379129988496","md":12,"lg":12,"xl":12,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_more_info_tab","form":""},"1":{"name":"product_accessories","form":""},"2":{"name":"hook_display_footer_product","form":""}}}}}},"class":"product-image-thumbs product-thumbs-bottom"}';
|
||||
break;
|
||||
case 'product_image_thumbs_left':
|
||||
$this->object->url_img_preview = 'https://i.pinimg.com/originals/98/b4/b0/98b4b05fef8913b2a37cbb592b921e7b.jpg';
|
||||
$this->object->params = '{"gridLeft":{"0":{"name":"functional_buttons","form":"","columns":{"0":{"form":{"md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_image_with_thumb","form":{"templateview":"left","numberimage":"5","numberimage1200":"4","numberimage992":"4","numberimage768":"3","numberimage576":"3","numberimage480":"2","numberimage360":"2","templatemodal":"1","templatethumb":"1","templatezoomtype":"in","zoomposition":"right","zoomwindowwidth":"400","zoomwindowheight":"400"}}}},"1":{"form":{"md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_detail_name","form":""},"1":{"name":"hook_display_product_additional_info","form":""},"2":{"name":"hook_display_leo_product_review_extra","form":""},"3":{"name":"product_price","form":""},"4":{"name":"product_description_short","form":""},"5":{"name":"product_customization","form":""},"6":{"name":"product_actions_form","form":""},"7":{"name":"hook_display_reassurance","form":""}}},"2":{"form":{"md":12,"lg":12,"xl":12,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_more_info_accordions","form":""},"1":{"name":"product_accessories","form":""},"2":{"name":"hook_display_footer_product","form":""}}}}}},"class":"product-image-thumbs product-thumbs-left"}';
|
||||
break;
|
||||
case 'product_image_thumbs_right':
|
||||
$this->object->url_img_preview = 'https://i.pinimg.com/originals/81/c4/41/81c441c1b2f6c3e56b3da56b65324423.jpg';
|
||||
$this->object->params = '{"gridLeft":{"0":{"name":"functional_buttons","form":"","columns":{"0":{"form":{"md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_image_with_thumb","form":{"templateview":"right","numberimage":"5","numberimage1200":"4","numberimage992":"4","numberimage768":"3","numberimage576":"3","numberimage480":"2","numberimage360":"2","templatemodal":"1","templatethumb":"1","templatezoomtype":"in","zoomposition":"right","zoomwindowwidth":"400","zoomwindowheight":"400"}}}},"1":{"form":{"md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_detail_name","form":""},"1":{"name":"hook_display_product_additional_info","form":""},"2":{"name":"hook_display_leo_product_review_extra","form":""},"3":{"name":"product_price","form":""},"4":{"name":"product_description_short","form":""},"5":{"name":"product_customization","form":""},"6":{"name":"product_actions_form","form":""},"7":{"name":"hook_display_reassurance","form":""}}},"2":{"form":{"md":12,"lg":12,"xl":12,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_more_info_default","form":""},"1":{"name":"product_accessories","form":""},"2":{"name":"hook_display_footer_product","form":""}}}}}},"class":"product-image-thumbs product-thumbs-right"}';
|
||||
break;
|
||||
case 'product_image_no_thumbs':
|
||||
$this->object->url_img_preview = 'https://i.pinimg.com/originals/60/ca/57/60ca570f6a8254c3741d8c9db78eb3d5.jpg';
|
||||
$this->object->params = '{"gridLeft":{"0":{"name":"functional_buttons","form":"","columns":{"0":{"form":{"md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_image_with_thumb","form":{"templateview":"none","numberimage":"5","numberimage1200":"5","numberimage992":"4","numberimage768":"3","numberimage576":"3","numberimage480":"2","numberimage360":"2","templatemodal":"1","templatethumb":"1","templatezoomtype":"in","zoomposition":"right","zoomwindowwidth":"400","zoomwindowheight":"400"}}}},"1":{"form":{"md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_detail_name","form":""},"1":{"name":"hook_display_product_additional_info","form":""},"2":{"name":"hook_display_leo_product_review_extra","form":""},"3":{"name":"product_price","form":""},"4":{"name":"product_description_short","form":""},"5":{"name":"product_customization","form":""},"6":{"name":"product_actions_form","form":""},"7":{"name":"hook_display_reassurance","form":""}}},"2":{"form":{"md":12,"lg":12,"xl":12,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_more_info_tab","form":""},"1":{"name":"product_accessories","form":""},"2":{"name":"hook_display_footer_product","form":""}}}}}},"class":"product-image-thumbs no-thumbs"}';
|
||||
break;
|
||||
case 'product_image_no_thumbs_fullwidth':
|
||||
$this->object->url_img_preview = 'https://i.pinimg.com/originals/c5/d9/02/c5d9025b68250832a31eac3b6d344955.jpg';
|
||||
$this->object->params = '{"gridLeft":{"0":{"name":"functional_buttons","form":"","columns":{"0":{"form":{"class":"","xl":"12","lg":"12","md":"12","sm":"12","xs":"12","sp":"12"},"element":"column","sub":{"0":{"name":"product_image_with_thumb","form":{"templateview":"none","numberimage":"5","numberimage1200":"5","numberimage992":"4","numberimage768":"3","numberimage576":"3","numberimage480":"2","numberimage360":"2","templatemodal":"1","templatethumb":"1","templatezoomtype":"in","zoomposition":"right","zoomwindowwidth":"400","zoomwindowheight":"400"}}}},"1":{"form":{"class":"offset-lg-2 offset-xl-2","xl":"8","lg":"8","md":"12","sm":"12","xs":"12","sp":"12"},"element":"column","sub":{"0":{"name":"product_detail_name","form":""},"1":{"name":"hook_display_product_additional_info","form":""},"2":{"name":"hook_display_leo_product_review_extra","form":""},"3":{"name":"product_price","form":""},"4":{"name":"product_description_short","form":""},"5":{"name":"product_customization","form":""},"6":{"name":"product_actions_form","form":""},"7":{"name":"hook_display_reassurance","form":""},"8":{"name":"product_more_info_tab","form":""}}},"2":{"form":{"class":"","xl":"12","lg":"12","md":"12","sm":"12","xs":"12","sp":"12"},"element":"column","sub":{"0":{"name":"product_accessories","form":""},"1":{"name":"hook_display_footer_product","form":""}}}}}},"class":"product-image-thumbs no-thumbs"}';
|
||||
break;
|
||||
case 'product_image_gallery':
|
||||
$this->object->url_img_preview = 'https://i.pinimg.com/originals/b1/a8/b9/b1a8b9381d8d3e3c4d13dfe24231581f.jpg';
|
||||
$this->object->params = '{"gridLeft":{"0":{"name":"functional_buttons","form":"","columns":{"0":{"form":{"md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_image_show_all","form":{"templatezoomtype":"in","zoomposition":"right","zoomwindowwidth":"400","zoomwindowheight":"400"}}}},"1":{"form":{"md":6,"lg":6,"xl":6,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_detail_name","form":""},"1":{"name":"hook_display_product_additional_info","form":""},"2":{"name":"hook_display_leo_product_review_extra","form":""},"3":{"name":"product_price","form":""},"4":{"name":"product_description_short","form":""},"5":{"name":"product_customization","form":""},"6":{"name":"product_actions_form","form":""},"7":{"name":"hook_display_reassurance","form":""}}},"2":{"form":{"md":12,"lg":12,"xl":12,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_more_info_tab","form":""},"1":{"name":"product_accessories","form":""},"2":{"name":"hook_display_footer_product","form":""}}}}}},"class":"product-image-gallery"}';
|
||||
break;
|
||||
case 'product_image_no_thumbs_center':
|
||||
$this->object->url_img_preview = 'https://i.pinimg.com/originals/38/99/1a/38991a8c1582669d29abe889bc0d5f52.jpg';
|
||||
$this->object->params = '{"gridLeft":{"0":{"name":"functional_buttons","form":"","columns":{"0":{"form":{"class":"","xl":"4","lg":"4","md":"12","sm":"12","xs":"12","sp":"12"},"element":"column","sub":{"0":{"name":"product_detail_name","form":""},"1":{"name":"hook_display_product_additional_info","form":""},"2":{"name":"hook_display_leo_product_review_extra","form":""},"3":{"name":"product_price","form":""},"4":{"name":"product_description_short","form":""},"5":{"name":"hook_display_reassurance","form":""}}},"1":{"form":{"class":"","xl":"5","lg":"5","md":"12","sm":"12","xs":"12","sp":"12"},"element":"column","sub":{"0":{"name":"product_image_with_thumb","form":{"templateview":"none","numberimage":"5","numberimage1200":"5","numberimage992":"4","numberimage768":"3","numberimage576":"3","numberimage480":"2","numberimage360":"2","templatemodal":"1","templatethumb":"1","templatezoomtype":"in","zoomposition":"right","zoomwindowwidth":"400","zoomwindowheight":"400"}}}},"2":{"form":{"class":"","xl":"3","lg":"3","md":"12","sm":"12","xs":"12","sp":"12"},"element":"column","sub":{"0":{"name":"product_customization","form":""},"1":{"name":"product_actions_form","form":""}}},"3":{"form":{"md":12,"lg":12,"xl":12,"sm":12,"xs":12,"sp":12},"element":"column","sub":{"0":{"name":"product_more_info_tab","form":""},"1":{"name":"product_accessories","form":""},"2":{"name":"hook_display_footer_product","form":""}}}}}},"class":"product-image-thumbs no-thumbs"}';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$params = Tools::jsonDecode($this->object->params, true);
|
||||
if ($params['gridLeft']) {
|
||||
foreach ($params['gridLeft'] as $key => $value) {
|
||||
$params['gridLeft'][$key]['dataForm'] = (!isset($value['form']))?'':Tools::jsonEncode($value['form']);
|
||||
|
||||
if (isset($element_by_name[$value['name']])) {
|
||||
$params['gridLeft'][$key]['config'] = $element_by_name[$value['name']];
|
||||
}
|
||||
if ($value['name'] == "functional_buttons") {
|
||||
foreach ($value['columns'] as $k => $v) {
|
||||
$params['gridLeft'][$key]['columns'][$k]['dataForm'] = (!isset($v['form']))?'':Tools::jsonEncode($v['form']);
|
||||
foreach ($v['sub'] as $ke => $ve) {
|
||||
$params['gridLeft'][$key]['columns'][$k]['sub'][$ke]['dataForm'] = (!isset($ve['form']))?'':Tools::jsonEncode($ve['form']);
|
||||
if (isset($element_by_name[$ve['name']])) {
|
||||
$params['gridLeft'][$key]['columns'][$k]['sub'][$ke]['config'] = $element_by_name[$ve['name']];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$block_list = array(
|
||||
'gridLeft' => array('title' => 'Product-Layout', 'class' => 'left-block'),
|
||||
);
|
||||
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Ap Profile Manage'),
|
||||
'icon' => 'icon-folder-close'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name'),
|
||||
'name' => 'name',
|
||||
'required' => true,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Product List Key'),
|
||||
'name' => 'plist_key',
|
||||
'readonly' => 'readonly',
|
||||
'desc' => $this->l('Tpl File name'),
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Class'),
|
||||
'type' => 'text',
|
||||
'name' => 'class_detail',
|
||||
'width' => 140
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Url Image Preview'),
|
||||
'type' => 'text',
|
||||
'name' => 'url_img_preview',
|
||||
'desc' => $this->l('Only for developers'),
|
||||
'width' => 140
|
||||
),
|
||||
array(
|
||||
'type' => 'ap_proGrid',
|
||||
'name' => 'ap_proGrid',
|
||||
'params' => $params,
|
||||
'blockList' => $block_list,
|
||||
'elements' => $config_file,
|
||||
'demodetaillink' => 'index.php?controller=AdminApPageBuilderDetails'.'&token='.Tools::getAdminTokenLite('AdminApPageBuilderDetails').'&addappagebuilder_details',
|
||||
'element_by_name' => $element_by_name,
|
||||
'widthList' => ApPageSetting::returnWidthList(),
|
||||
'columnGrids' => ApPageSetting::getColumnGrid(),
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'params'
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
),
|
||||
'buttons' => array(
|
||||
'save-and-stay' => array(
|
||||
'title' => $this->l('Save and Stay'),
|
||||
'name' => 'submitAdd'.$this->table.'AndStay',
|
||||
'type' => 'submit',
|
||||
'class' => 'btn btn-default pull-right',
|
||||
'icon' => 'process-icon-save')
|
||||
)
|
||||
);
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function importForm()
|
||||
{
|
||||
$helper = new HelperForm();
|
||||
$helper->submit_action = 'import' . $this->table;
|
||||
$inputs = array(
|
||||
array(
|
||||
'type' => 'file',
|
||||
'name' => 'importFile',
|
||||
'label' => $this->l('File'),
|
||||
'desc' => $this->l('Only accept xml file'),
|
||||
),
|
||||
);
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'action' => Context::getContext()->link->getAdminLink('AdminApPageBuilderDetailsController'),
|
||||
'input' => $inputs,
|
||||
'submit' => array('title' => $this->l('Import'), 'class' => 'button btn btn-success'),
|
||||
'tinymce' => false,
|
||||
),
|
||||
);
|
||||
$helper->fields_value = isset($this->fields_value) ? $this->fields_value : array();
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->currentIndex = self::$currentIndex;
|
||||
$helper->token = $this->token;
|
||||
$helper->table = 'xml_import';
|
||||
$html = $helper->generateForm(array($fields_form));
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function replaceSpecialStringToHtml($arr)
|
||||
{
|
||||
foreach ($arr as &$v) {
|
||||
if ($v['name'] == 'code') {
|
||||
// validate module
|
||||
$v['code'] = str_replace($this->str_search, $this->str_relace, $v['code']);
|
||||
} else {
|
||||
if ($v['name'] == 'functional_buttons') {
|
||||
foreach ($v as &$f) {
|
||||
if ($f['name'] == 'code') {
|
||||
// validate module
|
||||
$f['code'] = str_replace($this->str_search, $this->str_relace, $f['code']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function getFieldsValue($obj)
|
||||
{
|
||||
$file_value = parent::getFieldsValue($obj);
|
||||
if (!$obj->id) {
|
||||
$num = ApPageSetting::getRandomNumber();
|
||||
$file_value['plist_key'] = 'detail'.$num;
|
||||
$file_value['name'] = $file_value['plist_key'];
|
||||
$file_value['class_detail'] = 'detail-'.$num;
|
||||
}
|
||||
return $file_value;
|
||||
}
|
||||
|
||||
public function processAdd()
|
||||
{
|
||||
if ($obj = parent::processAdd()) {
|
||||
$this->saveTplFile($obj->plist_key, $obj->params);
|
||||
}
|
||||
}
|
||||
|
||||
public function processUpdate()
|
||||
{
|
||||
if ($obj = parent::processUpdate()) {
|
||||
$this->saveTplFile($obj->plist_key, $obj->params);
|
||||
}
|
||||
}
|
||||
|
||||
public function processDelete()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
Tools::deleteFile(apPageHelper::getConfigDir('theme_details').$object->plist_key.'.tpl');
|
||||
parent::processDelete();
|
||||
}
|
||||
|
||||
//save file
|
||||
public function saveTplFile($plist_key, $params = '')
|
||||
{
|
||||
$data_form = str_replace($this->str_search, $this->str_relace, $params);
|
||||
$data_form = Tools::jsonDecode($data_form, true);
|
||||
|
||||
$grid_left = $data_form['gridLeft'];
|
||||
$tpl_grid = $this->returnFileContent('header_product');
|
||||
$tpl_grid = str_replace('class="product-detail', 'class="product-detail '.Tools::getValue('class_detail', '').' '.Tools::getValue('main_class', ''), $tpl_grid);
|
||||
$tpl_grid .= $this->convertObjectToTpl($grid_left);
|
||||
$tpl_grid .= $this->returnFileContent('footer_product');
|
||||
|
||||
$tpl_grid = preg_replace('/\{\*[\s\S]*?\*\}/', '', $tpl_grid);
|
||||
|
||||
$folder = apPageHelper::getConfigDir('theme_details');
|
||||
if (!is_dir($folder)) {
|
||||
mkdir($folder, 0755, true);
|
||||
}
|
||||
$file = $plist_key.'.tpl';
|
||||
//$tpl_grid = preg_replace('/\{\*[\s\S]*?\*\}/', '', $tpl_grid);
|
||||
//$tpl_grid = str_replace(" mod='appagebuilder'", '', $tpl_grid);
|
||||
|
||||
ApPageSetting::writeFile($folder, $file, apPageHelper::getLicenceTPL().$tpl_grid);
|
||||
}
|
||||
|
||||
public function processStatus()
|
||||
{
|
||||
if (Validate::isLoadedObject($object = $this->loadObject())) {
|
||||
if ($object->toggleStatus()) {
|
||||
$matches = array();
|
||||
if (preg_match('/[\?|&]controller=([^&]*)/', (string)$_SERVER['HTTP_REFERER'], $matches) !== false && Tools::strtolower($matches[1]) != Tools::strtolower(preg_replace('/controller/i', '', get_class($this)))) {
|
||||
$this->redirect_after = preg_replace('/[\?|&]conf=([^&]*)/i', '', (string)$_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('An error occurred while updating the status for an object.')
|
||||
.'<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* SHOW LINK DUPLICATE FOR EACH ROW
|
||||
*/
|
||||
public function displayDuplicateLink($token = null, $id = null, $name = null)
|
||||
{
|
||||
$controller = 'AdminApPageBuilderDetails';
|
||||
$token = Tools::getAdminTokenLite($controller);
|
||||
$html = '<a href="#" title="Duplicate" onclick="confirm_link(\'\', \'Duplicate Product Details ID '.$id.'. If you wish to proceed, click "Yes". If not, click "No".\', \'Yes\', \'No\', \'index.php?controller='.$controller.'&id_appagebuilder_details='.$id.'&duplicateappagebuilder_details&token='.$token.'\', \'#\')">
|
||||
<i class="icon-copy"></i> Duplicate
|
||||
</a>';
|
||||
|
||||
// validate module
|
||||
unset($name);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function access($action, $disable = false)
|
||||
{
|
||||
if (Tools::getIsset('update'.$this->table) && Tools::getIsset($this->identifier)) {
|
||||
// Allow person see "EDIT" form
|
||||
$action = 'view';
|
||||
}
|
||||
return parent::access($action, $disable);
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
# SET ACTION : IMPORT DATA
|
||||
if ($this->can_import && Tools::getIsset('import' . $this->table)) {
|
||||
if ($this->access('edit')) {
|
||||
$this->action = 'import';
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->errors) <= 0) {
|
||||
if (Tools::isSubmit('duplicate'.$this->table)) {
|
||||
if ($this->id_object) {
|
||||
if (!$this->access('add')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to duplicate this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
} elseif (Tools::getIsset('saveELement') && Tools::getValue('saveELement')) {
|
||||
if (!$this->access('edit')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
} elseif ($this->can_import && Tools::getIsset('import' . $this->table)) {
|
||||
if (!$this->access('edit')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to import data.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1235
modules/appagebuilder/controllers/admin/AdminApPageBuilderHome.php
Normal file
1235
modules/appagebuilder/controllers/admin/AdminApPageBuilderHome.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,413 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
require_once(_PS_MODULE_DIR_.'appagebuilder/libs/Helper.php');
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminApPageBuilderHookController extends ModuleAdminControllerCore
|
||||
{
|
||||
/**
|
||||
* @var Boolean $display_key
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
public $display_key = 0;
|
||||
/**
|
||||
* @var Array $hookspos
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
public $hookspos = array();
|
||||
/**
|
||||
* @var Array $ownPositions
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
// public $ownPositions = array();
|
||||
/**
|
||||
* @var String $theme_name
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
public $theme_name;
|
||||
/**
|
||||
* @var String $theme_name
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
public $themeKey;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'leohook';
|
||||
$this->className = 'AdminApPageBuilderHook';
|
||||
$this->lang = true;
|
||||
$this->context = Context::getContext();
|
||||
parent::__construct();
|
||||
$this->display_key = (int)Tools::getValue('show_modules');
|
||||
|
||||
// $this->ownPositions = array(
|
||||
// 'displayHeaderRight',
|
||||
// 'displaySlideshow',
|
||||
// 'topNavigation',
|
||||
// 'displayPromoteTop',
|
||||
// 'displayBottom',
|
||||
// 'displayMassBottom'
|
||||
// );
|
||||
$this->hookspos = ApPageSetting::getHook();
|
||||
$this->theme_name = apPageHelper::getThemeName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build List linked Icons Toolbar
|
||||
*/
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
if (empty($this->display)) {
|
||||
$this->page_header_toolbar_btn['save'] = array(
|
||||
'href' => 'index.php?tab=AdminApPageBuilderHook&token='.Tools::getAdminTokenLite('AdminApPageBuilderHook').'&action=savepos',
|
||||
'id' => 'savepos',
|
||||
'desc' => $this->l('Save Positions')
|
||||
);
|
||||
}
|
||||
parent::initPageHeaderToolbar();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* render list of modules following positions in the layout editor.
|
||||
*/
|
||||
public function renderList()
|
||||
{
|
||||
$filePath = _PS_ALL_THEMES_DIR_.$this->theme_name.'';
|
||||
$showed = true;
|
||||
$xml = simplexml_load_file($filePath.'/config.xml');
|
||||
|
||||
if (isset($xml->theme_key)) {
|
||||
$this->themeKey = trim((string)$xml->theme_key);
|
||||
}
|
||||
$this->themeKey = '1111';
|
||||
if ($this->themeKey) {
|
||||
$this->initToolbarTitle();
|
||||
$this->initToolbar();
|
||||
$hookspos = $this->hookspos;
|
||||
|
||||
foreach ($hookspos as $hook) {
|
||||
if (Hook::getIdByName($hook)) {
|
||||
// validate module
|
||||
} else {
|
||||
$new_hook = new Hook();
|
||||
$new_hook->name = pSQL($hook);
|
||||
$new_hook->title = pSQL($hook);
|
||||
$new_hook->add();
|
||||
// $id_hook = $new_hook->id;
|
||||
}
|
||||
}
|
||||
|
||||
// $sql = 'UPDATE `'._DB_PREFIX_.'hook` SET position=1, live_edit=1
|
||||
// WHERE name in ("'.implode('","', $hookspos).'") ';
|
||||
// Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
|
||||
|
||||
$modules = Module::getModulesInstalled(0);
|
||||
$assoc_modules_id = array();
|
||||
|
||||
$assoc_modules_id = $module_instances = array();
|
||||
foreach ($modules as $module) {
|
||||
if ($tmp_instance = Module::getInstanceById((int)$module['id_module'])) {
|
||||
// We want to be able to sort modules by display name
|
||||
$module_instances[$tmp_instance->displayName] = $tmp_instance;
|
||||
// But we also want to associate hooks to modules using the modules IDs
|
||||
$assoc_modules_id[(int)$module['id_module']] = $tmp_instance->displayName;
|
||||
}
|
||||
}
|
||||
$hooks = Hook::getHooks(!(int)Tools::getValue('hook_position'));
|
||||
|
||||
$hookModules = array();
|
||||
|
||||
$hookedModules = array();
|
||||
foreach ($hooks as $key => $hook) {
|
||||
// validate module
|
||||
unset($key);
|
||||
|
||||
$k = $hook['name'];
|
||||
$k = (Tools::strtolower(Tools::substr($k, 0, 1)).Tools::substr($k, 1));
|
||||
if (in_array($k, $hookspos)) {
|
||||
// Get all modules for this hook or only the filtered module
|
||||
$hookModules[$k]['modules'] = Hook::getModulesFromHook($hook['id_hook'], $this->display_key);
|
||||
$hookModules[$k]['module_count'] = count($hookModules[$k]['modules']);
|
||||
|
||||
if (is_array($hookModules[$k]['modules']) && !empty($hookModules[$k]['modules'])) {
|
||||
foreach ($hookModules[$k]['modules'] as $module_key => $module) {
|
||||
if (isset($assoc_modules_id[$module['id_module']])) {
|
||||
$hookedModules[] = $module['id_module'];
|
||||
$hookModules[$k]['modules'][$module_key]['instance'] = $module_instances[$assoc_modules_id[$module['id_module']]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$instances = array();
|
||||
foreach ($modules as $module) {
|
||||
if ($tmp_instance = Module::getInstanceById($module['id_module'])) {
|
||||
foreach ($hookspos as $hk) {
|
||||
$retro_hook_name = Hook::getRetroHookName($hk);
|
||||
$hook_callable = is_callable(array($tmp_instance, 'hook'.$hk));
|
||||
$hook_retro_callable = is_callable(array($tmp_instance, 'hook'.$retro_hook_name));
|
||||
if ($hook_retro_callable || $hook_callable) {
|
||||
$instances[$tmp_instance->displayName] = $tmp_instance;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ksort($instances);
|
||||
|
||||
$tpl = $this->createTemplate('panel.tpl');
|
||||
|
||||
// $this->context->controller->addJqueryUI('ui.sortable');
|
||||
// $this->context->controller->addJqueryUI('ui.draggable');
|
||||
$this->context->controller->addCss(apPageHelper::getCssAdminDir().'admin/style_hook_cpanel.css');
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'/jquery-ui-1.10.3.custom.min.js', 'all');
|
||||
$tpl->assign(array(
|
||||
'showed' => $showed,
|
||||
'toolbar' => $this->context->smarty->fetch('toolbar.tpl'),
|
||||
'modules' => $instances,
|
||||
'hookspos' => $hookspos,
|
||||
'URI' => __PS_BASE_URI__.'modules/',
|
||||
'hookModules' => $hookModules,
|
||||
'noModuleConfig' => $this->l('No Configuration For This Module'),
|
||||
'currentURL' => 'index.php?tab=AdminApPageBuilderHook&token='.Tools::getAdminTokenLite('AdminApPageBuilderHook').'',
|
||||
// 'moduleEditURL' => 'index.php?tab=AdminApPageBuilderHook&token='.Tools::getAdminTokenLite('AdminApPageBuilderHook').'',
|
||||
'moduleEditURL' => 'index.php?controller=adminmodules&token='.Tools::getAdminTokenLite('AdminModules').'&tab_module=Home',
|
||||
));
|
||||
|
||||
return $tpl->fetch();
|
||||
} else {
|
||||
$tpl = $this->createTemplate('error.tpl');
|
||||
$tpl->assign(array(
|
||||
'showed' => false,
|
||||
'themeURL' => 'index.php?controller=AdminThemes&token='.Tools::getAdminTokenLite('AdminThemes')
|
||||
));
|
||||
return $tpl->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process posting data
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
if (count($this->errors) > 0) {
|
||||
if ($this->ajax) {
|
||||
$array = array('hasError' => true, 'errors' => $this->errors[0]);
|
||||
die(Tools::jsonEncode($array));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::getValue('action') && Tools::getValue('action') == 'modulehook') {
|
||||
// AJAX EDIT HOOK - READ
|
||||
$id = (int)Tools::getValue('id');
|
||||
|
||||
$tmp_instance = Module::getInstanceById($id);
|
||||
$hooks = array();
|
||||
|
||||
foreach ($this->hookspos as $hk) {
|
||||
$retro_hook_name = Hook::getRetroHookName($hk);
|
||||
$hook_callable = is_callable(array($tmp_instance, 'hook'.$hk));
|
||||
$hook_retro_callable = is_callable(array($tmp_instance, 'hook'.$retro_hook_name));
|
||||
|
||||
if ($hook_retro_callable || $hook_callable) {
|
||||
$hooks[] = $hk;
|
||||
}
|
||||
}
|
||||
$hooks = implode('|', $hooks);
|
||||
$sql = 'SELECT * FROM `'._DB_PREFIX_.'leohook` WHERE id_module='.(int)$id.' AND theme="'.pSQL($this->theme_name).'" AND id_shop='.(int)($this->context->shop->id);
|
||||
|
||||
if ($row = Db::getInstance()->getRow($sql)) {
|
||||
die('{"hasError" : false, "hook" : "'.$row['name_hook'].'","hooks":"'.$hooks.'"}');
|
||||
} else {
|
||||
die('{"hasError" : true, "errors" : "Can not update module position","hooks":"'.$hooks.'"}');
|
||||
}
|
||||
}
|
||||
if (Tools::getValue('action') && Tools::getValue('action') == 'overridehook') {
|
||||
// AJAX EDIT HOOK - SAVE
|
||||
$id_module = (int)Tools::getValue('hdidmodule');
|
||||
$name_hook = Tools::getValue('name_hook');
|
||||
if (is_numeric($name_hook)) {
|
||||
$sql = 'DELETE FROM`'._DB_PREFIX_.'leohook` WHERE id_module='.(int)$id_module.' AND theme="'.pSQL($this->theme_name).'" AND id_shop='.(int)($this->context->shop->id);
|
||||
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
|
||||
die('{"hasError" : false, "errors" : "done!delete module position"}');
|
||||
} elseif ($name_hook) {
|
||||
$desHook = Tools::getValue('deshook');
|
||||
$desHookId = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT id_hook FROM `'._DB_PREFIX_."hook` WHERE name='".pSQL($desHook)."'");
|
||||
$sql = 'SELECT *
|
||||
FROM `'._DB_PREFIX_.'leohook` WHERE id_hook= '.(int)$desHookId.' AND id_module='.(int)$id_module.' AND theme="'.pSQL($this->theme_name).'" AND id_shop='.(int)($this->context->shop->id);
|
||||
|
||||
if ($row = Db::getInstance()->getRow($sql)) {
|
||||
$sql = ' UPDATE `'._DB_PREFIX_.'leohook` SET `id_hook`='.(int)$desHookId.', name_hook="'.pSQL($name_hook).'"
|
||||
WHERE id_module='.(int)$id_module.' AND theme="'.pSQL($this->theme_name).'" AND id_shop='.(int)($this->context->shop->id);
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
|
||||
} else {
|
||||
$sql = ' INSERT INTO `'._DB_PREFIX_.'leohook` (id_hook, id_module, id_shop, theme, name_hook)
|
||||
VALUES('.(int)$desHookId.','.(int)$id_module.','.(int)($this->context->shop->id).',"'.pSQL($this->theme_name).'","'.pSQL($name_hook).'")';
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
|
||||
}
|
||||
die('{"hasError" : false, "errors" : "done!update module position"}');
|
||||
}
|
||||
die('{"hasError" : true, "errors" : "Can not update module position"}');
|
||||
}
|
||||
if (Tools::getValue('action') && Tools::getValue('action') == 'savepos') {
|
||||
// SUBMIT - SAVE HOOK
|
||||
$positions = Tools::getValue('position');
|
||||
$way = (int)(Tools::getValue('way'));
|
||||
$unhook = Tools::getValue('unhook');
|
||||
$id_shop = Context::getContext()->shop->id;
|
||||
|
||||
if (is_array($unhook)) {
|
||||
foreach ($unhook as $id_module => $str_hookId) {
|
||||
$hookIds = explode(',', $str_hookId);
|
||||
foreach ($hookIds as $hookId) {
|
||||
$module = Module::getInstanceById($id_module);
|
||||
if (Validate::isLoadedObject($module)) {
|
||||
!$module->unregisterHook((int)$hookId, array($id_shop));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($positions) && !empty($positions)) {
|
||||
foreach ($positions as $pos) {
|
||||
$tmp = explode('|', $pos);
|
||||
if (count($tmp) == 2 && $tmp[0] && $tmp[1]) {
|
||||
$position = $tmp[0];
|
||||
$hookId = Hook::getIdByName($position);
|
||||
$oldhooks = explode(',', Tools::getValue($position));
|
||||
|
||||
$ids = explode(',', $tmp[1]);
|
||||
if ($hookId && count($oldhooks)) {
|
||||
foreach ($ids as $index => $id_module) {
|
||||
$module = Module::getInstanceById($id_module);
|
||||
|
||||
if (Validate::isLoadedObject($module) && isset($oldhooks[$index]) && is_numeric($oldhooks[$index]) && $oldhooks[$index] != $hookId) {
|
||||
// MOVE MODULE TO OTHER HOOK
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'hook_module` SET id_hook='.(int)$hookId.'
|
||||
WHERE id_module='.(int)$id_module.' AND id_hook='.(int)$oldhooks[$index].' AND id_shop='.(int)($id_shop);
|
||||
try {
|
||||
// FIX: Drag a module to one hook in 2 times. Save 500 error
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql);
|
||||
} catch (Exception $ex) {
|
||||
}
|
||||
} elseif (Validate::isLoadedObject($module) && (!isset($oldhooks[$index]) || !(int)$oldhooks[$index])) {
|
||||
$this->registerHook($id_module, $hookId, array($id_shop));
|
||||
//echo 'new:'.$id_module;
|
||||
}
|
||||
$module->updatePosition($hookId, $way, $index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
die('{"hasError" : false, "errors" : "update module position"}');
|
||||
}
|
||||
}
|
||||
|
||||
public function registerHook($id_module, $id_hook, $shop_list = null)
|
||||
{
|
||||
// If shop lists is null, we fill it with all shops
|
||||
if (is_null($shop_list)) {
|
||||
$shop_list = Shop::getShops(true, null, true);
|
||||
}
|
||||
|
||||
$return = true;
|
||||
foreach ($shop_list as $shop_id) {
|
||||
// Check if already register
|
||||
$sql = 'SELECT hm.`id_module`
|
||||
FROM `'._DB_PREFIX_.'hook_module` hm, `'._DB_PREFIX_.'hook` h
|
||||
WHERE hm.`id_module` = '.(int)($id_module).' AND h.`id_hook` = '.(int)$id_hook.'
|
||||
AND h.`id_hook` = hm.`id_hook` AND `id_shop` = '.(int)$shop_id;
|
||||
|
||||
|
||||
if (Db::getInstance()->getRow($sql)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get module position in hook
|
||||
$sql = 'SELECT MAX(`position`) AS position
|
||||
FROM `'._DB_PREFIX_.'hook_module`
|
||||
WHERE `id_hook` = '.(int)$id_hook.' AND `id_shop` = '.(int)$shop_id;
|
||||
if (!$position = Db::getInstance()->getValue($sql)) {
|
||||
$position = 0;
|
||||
}
|
||||
|
||||
// Register module in hook
|
||||
$return &= Db::getInstance()->insert('hook_module', array(
|
||||
'id_module' => (int)$id_module,
|
||||
'id_hook' => (int)$id_hook,
|
||||
'id_shop' => (int)$shop_id,
|
||||
'position' => (int)($position + 1),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
|
||||
if (count($this->errors) <= 0) {
|
||||
if (Tools::getIsset('updateleohook') && Tools::getValue('updateleohook')) {
|
||||
if (!$this->access('edit')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(_PS_MODULE_DIR_ . 'appagebuilder/classes/ApPageSetting.php');
|
||||
|
||||
class AdminApPageBuilderImagesController extends ModuleAdminController
|
||||
{
|
||||
protected $max_image_size = null;
|
||||
public $theme_name;
|
||||
public $module_name = 'appagebuilder';
|
||||
public $img_path;
|
||||
public $folder_name;
|
||||
public $module_path;
|
||||
public $tpl_path;
|
||||
public $theme_dir;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->theme_dir = apPageHelper::getConfigDir('_PS_THEME_DIR_');
|
||||
$this->folder_name = Tools::getIsset('imgDir') ? Tools::getValue('imgDir') : 'images';
|
||||
$this->bootstrap = true;
|
||||
$this->max_image_size = (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
|
||||
$this->theme_name = apPageHelper::getThemeName();
|
||||
$this->img_path = apPageHelper::getImgThemeDir($this->folder_name);
|
||||
$this->img_url = apPageHelper::getImgThemeUrl($this->folder_name);
|
||||
$this->className = 'ApPageBuilderImages';
|
||||
$this->context = Context::getContext();
|
||||
$this->module_path = __PS_BASE_URI__ . 'modules/' . $this->module_name . '/';
|
||||
$this->tpl_path = _PS_ROOT_DIR_ . '/modules/' . $this->module_name . '/views/templates/admin';
|
||||
|
||||
# LIVE THEME EDITER
|
||||
$leo_controller = Tools::getValue('leo_controller');
|
||||
if ($leo_controller == 'live_theme_edit') {
|
||||
$this->context->controller->addCss(apPageHelper::getCssAdminDir() . 'admin/images.css', 'all');
|
||||
|
||||
$this->img_path = _PS_ALL_THEMES_DIR_ . apPageHelper::getThemeName() . '/assets/img/patterns/';
|
||||
$this->img_url = __PS_BASE_URI__ . 'themes/' . apPageHelper::getThemeName() . '/assets/img/patterns/';
|
||||
$this->context->controller->addCss(apPageHelper::getCssAdminDir() . 'admin/images.css', 'all');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Live Theme Editor
|
||||
*/
|
||||
public function renderList()
|
||||
{
|
||||
$tpl = $this->createTemplate('imagemanager.tpl');
|
||||
$sort_by = Tools::getValue('sortBy');
|
||||
$images = $this->getImageList($sort_by);
|
||||
$image_uploader = new HelperImageUploader('file');
|
||||
$image_uploader->setSavePath($this->img_path);
|
||||
$image_uploader->setMultiple(true)->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminApPageBuilderImages') . '&ajax=1&action=addimage&leo_controller=live_theme_edit'); // url upload image
|
||||
|
||||
$tpl->assign(array(
|
||||
'img_dir' => $this->folder_name,
|
||||
'countImages' => count($images),
|
||||
'images' => $images,
|
||||
'max_image_size' => $this->max_image_size / 1024 / 1024,
|
||||
'image_uploader' => $image_uploader->render(),
|
||||
'imgManUrl' => Context::getContext()->link->getAdminLink('AdminApPageBuilderImages'),
|
||||
'token' => $this->token,
|
||||
'url_param' => '&leo_controller=live_theme_edit'
|
||||
));
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Live Theme Editor
|
||||
*/
|
||||
public function ajaxProcessReloadBackground()
|
||||
{
|
||||
$sort_by = Tools::getValue('sortBy');
|
||||
$tpl = $this->createTemplate('imagemanager.tpl');
|
||||
$images = $this->getImageList($sort_by);
|
||||
$tpl->assign(array(
|
||||
'images' => $images,
|
||||
'reloadBack' => 1
|
||||
));
|
||||
die(Tools::jsonEncode($tpl->fetch()));
|
||||
}
|
||||
|
||||
public function getImageList($sortBy)
|
||||
{
|
||||
$path = $this->img_path;
|
||||
# CACH 1 : lay cac file anh
|
||||
$images = glob($path . '{*.jpeg,*.JPEG,*.jpg,*.JPG,*.gif,*.GIF,*.png,*.PNG}', GLOB_BRACE);
|
||||
if ($images === null) {
|
||||
# CACH 2 : lay cac file anh
|
||||
$files = scandir($path);
|
||||
$files = array_diff($files, array(
|
||||
'..',
|
||||
'.'
|
||||
)); # insert code
|
||||
|
||||
$images = array();
|
||||
foreach ($files as $key => $image) {
|
||||
# validate module
|
||||
unset($key);
|
||||
$ext = Tools::substr($image, strrpos($image, '.') + 1);
|
||||
if (in_array($ext, array(
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'gif',
|
||||
'JPG',
|
||||
'JPEG',
|
||||
'PNG',
|
||||
'GIF'
|
||||
))) {
|
||||
$images[] = $image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($sortBy == 'name_desc') {
|
||||
rsort($images);
|
||||
}
|
||||
|
||||
if ($sortBy == 'date' || $sortBy == 'date_desc') {
|
||||
ksort($images);
|
||||
}
|
||||
if ($sortBy == 'date_desc') {
|
||||
rsort($images);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($images as &$file) {
|
||||
$fileInfo = pathinfo($file);
|
||||
$result[] = array(
|
||||
'name' => $fileInfo['basename'],
|
||||
'link' => $this->img_url . $fileInfo['basename']
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function renderTemplate($tpl_name)
|
||||
{
|
||||
$path = '';
|
||||
if (file_exists($this->theme_dir . 'modules/' . $this->module->name . '/views/templates/admin/' . $tpl_name) && $this->viewAccess()) {
|
||||
$path = $this->theme_dir . 'modules/' . $this->module->name . '/views/templates/admin/' . $tpl_name;
|
||||
} elseif (file_exists($this->getTemplatePath() . $this->override_folder . $tpl_name) && $this->viewAccess()) {
|
||||
$path = $this->getTemplatePath() . $this->override_folder . $tpl_name;
|
||||
}
|
||||
$content = Context::getContext()->smarty->fetch($path);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Manage Image
|
||||
*/
|
||||
public function ajaxProcessManageImage()
|
||||
{
|
||||
$smarty = Context::getContext()->smarty;
|
||||
$sort_by = Tools::getValue('sortBy');
|
||||
$images = $this->getImageList($sort_by);
|
||||
$image_uploader = new HelperImageUploader('file');
|
||||
$image_uploader->setSavePath($this->img_path);
|
||||
$image_uploader->setTemplateDirectory($this->tpl_path . '/helpers/uploader');
|
||||
|
||||
$image_uploader->setTemplate('ajax.tpl');
|
||||
$image_uploader->setMultiple(true)->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminApPageBuilderImages') . '&ajax=1&action=addimage&imgDir=' . $this->folder_name);
|
||||
$upload_html = $image_uploader->render();
|
||||
$smarty->assign(array(
|
||||
'img_dir' => $this->folder_name,
|
||||
'widget' => Tools::getValue('widget'),
|
||||
'countImages' => count($images),
|
||||
'images' => $images,
|
||||
'max_image_size' => $this->max_image_size / 1024 / 1024,
|
||||
'image_uploader' => $upload_html,
|
||||
'imgManUrl' => Context::getContext()->link->getAdminLink('AdminApPageBuilderImages'),
|
||||
'token' => $this->token,
|
||||
'link' => Context::getContext()->link
|
||||
));
|
||||
die($this->renderTemplate('imagemanager.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Add Image
|
||||
*/
|
||||
public function ajaxProcessAddImage()
|
||||
{
|
||||
if (isset($_FILES['file'])) {
|
||||
try {
|
||||
$image_uploader = new HelperUploader('file');
|
||||
|
||||
if (!file_exists($this->img_path)) {
|
||||
mkdir($this->img_path, 0755, true);
|
||||
}
|
||||
$image_uploader->setSavePath($this->img_path);
|
||||
$image_uploader->setAcceptTypes(array(
|
||||
'jpeg',
|
||||
'gif',
|
||||
'png',
|
||||
'jpg'
|
||||
))->setMaxSize($this->max_image_size);
|
||||
$total_errors = array();
|
||||
|
||||
$files = $image_uploader->process();
|
||||
foreach ($files as &$file) {
|
||||
$errors = array();
|
||||
// Evaluate the memory required to resize the image: ifit's too much, you can't resize it.
|
||||
if (!ImageManager::checkImageMemoryLimit($file['save_path'])) {
|
||||
$errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded.
|
||||
Please increase your memory_limit value via your server\'s configuration settings.');
|
||||
}
|
||||
if (count($errors)) {
|
||||
$total_errors = array_merge($total_errors, $errors);
|
||||
}
|
||||
//unlink($file['save_path']);
|
||||
//Necesary to prevent hacking
|
||||
unset($file['save_path']);
|
||||
//Add image preview and delete url
|
||||
}
|
||||
if (count($total_errors)) {
|
||||
$this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors);
|
||||
}
|
||||
$images = $this->getImageList('date');
|
||||
$tpl = $this->createTemplate('imagemanager.tpl');
|
||||
$tpl->assign(array(
|
||||
'images' => $images,
|
||||
'reloadSliderImage' => 1,
|
||||
'link' => Context::getContext()->link
|
||||
));
|
||||
|
||||
die(Tools::jsonEncode($tpl->fetch()));
|
||||
} catch (Exception $ex) {
|
||||
die("Error in ajaxProcessAddImage");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Sort Image
|
||||
*/
|
||||
public function ajaxProcessReLoadSliderImage()
|
||||
{
|
||||
$tpl = $this->createTemplate('imagemanager.tpl');
|
||||
$sort_by = Tools::getValue('sortBy');
|
||||
$images = $this->getImageList($sort_by);
|
||||
$tpl->assign(array(
|
||||
'images' => $images,
|
||||
'reloadSliderImage' => 1,
|
||||
'link' => Context::getContext()->link
|
||||
));
|
||||
die(Tools::jsonEncode($tpl->fetch()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Delete Image
|
||||
*/
|
||||
public function ajaxProcessDeleteImage()
|
||||
{
|
||||
if (($img_name = Tools::getValue('imgName', false)) !== false) {
|
||||
$link = $this->img_path;
|
||||
$this->icon_path = $link = str_replace('modules/appagebuilder/images', 'modules/appagebuilder/icon', $link);
|
||||
|
||||
if (file_exists($link . $img_name)) {
|
||||
unlink($link . $img_name);
|
||||
$images = $this->getIconList('date');
|
||||
} else if (file_exists($this->img_path . $img_name)) {
|
||||
unlink($this->img_path . $img_name);
|
||||
$images = $this->getImageList('date');
|
||||
} else {
|
||||
throw new PrestaShopException('Do not find' . $link . $img_name);
|
||||
}
|
||||
|
||||
$tpl = $this->createTemplate('imagemanager.tpl');
|
||||
$tpl->assign(array(
|
||||
'images' => $images,
|
||||
'reloadSliderImage' => 1,
|
||||
'link' => Context::getContext()->link
|
||||
));
|
||||
|
||||
die(Tools::jsonEncode($tpl->fetch()));
|
||||
}
|
||||
}
|
||||
|
||||
public function getIconList($sortBy)
|
||||
{
|
||||
$path = $this->icon_path;
|
||||
$images = glob($path . '{*.jpeg,*.JPEG,*.jpg,*.JPG,*.gif,*.GIF,*.png,*.PNG}', GLOB_BRACE);
|
||||
|
||||
if ($images === null) {
|
||||
# CACH 2 : lay cac file anh
|
||||
$files = scandir($path);
|
||||
$files = array_diff($files, array(
|
||||
'..',
|
||||
'.'
|
||||
)); # insert code
|
||||
|
||||
$images = array();
|
||||
foreach ($files as $key => $image) {
|
||||
# validate module
|
||||
unset($key);
|
||||
$ext = Tools::substr($image, strrpos($image, '.') + 1);
|
||||
if (in_array($ext, array(
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'gif',
|
||||
'JPG',
|
||||
'JPEG',
|
||||
'PNG',
|
||||
'GIF'
|
||||
))) {
|
||||
$images[] = $image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($sortBy == 'name_desc') {
|
||||
rsort($images);
|
||||
}
|
||||
|
||||
if ($sortBy == 'date' || $sortBy == 'date_desc') {
|
||||
ksort($images);
|
||||
}
|
||||
if ($sortBy == 'date_desc') {
|
||||
rsort($images);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($images as &$file) {
|
||||
$fileInfo = pathinfo($file);
|
||||
$result[] = array(
|
||||
'name' => $fileInfo['basename'],
|
||||
'link' => str_replace(
|
||||
'modules/appagebuilder/images',
|
||||
'modules/appagebuilder/icon',
|
||||
$this->img_url
|
||||
) . $fileInfo['basename']
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function viewAccess($disable = true)
|
||||
{
|
||||
// return $this->access('view', $disable);
|
||||
unset($disable);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminApPageBuilderModuleController extends ModuleAdminControllerCore
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$url = 'index.php?controller=AdminModules&configure=appagebuilder&token='.Tools::getAdminTokenLite('AdminModules');
|
||||
Tools::redirectAdmin($url);
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(_PS_MODULE_DIR_.'appagebuilder/classes/ApPageBuilderPositionsModel.php');
|
||||
|
||||
class AdminApPageBuilderPositionsController extends ModuleAdminControllerCore
|
||||
{
|
||||
public $position_js_folder = '';
|
||||
public $position_css_folder = '';
|
||||
public $module_name = 'appagebuilder';
|
||||
public $explicit_select;
|
||||
public $order_by;
|
||||
public $order_way;
|
||||
public $theme_dir;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'appagebuilder_positions';
|
||||
$this->className = 'ApPageBuilderPositionsModel';
|
||||
$this->lang = false;
|
||||
$this->explicit_select = true;
|
||||
$this->allow_export = true;
|
||||
$this->context = Context::getContext();
|
||||
$this->order_by = 'position';
|
||||
$this->order_way = 'DESC';
|
||||
$this->_join = '
|
||||
INNER JOIN `'._DB_PREFIX_.'appagebuilder_positions_shop` ps ON (ps.`id_appagebuilder_positions` = a.`id_appagebuilder_positions`)';
|
||||
parent::__construct();
|
||||
$this->fields_list = array(
|
||||
'id_appagebuilder_positions' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 50,
|
||||
'class' => 'fixed-width-xs'
|
||||
),
|
||||
'position' => array(
|
||||
'title' => $this->l('Position'),
|
||||
'width' => 140,
|
||||
'type' => 'text',
|
||||
'filter_key' => 'a!position',
|
||||
'remove_onclick' => true
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Name'),
|
||||
'width' => 140,
|
||||
'type' => 'text',
|
||||
'filter_key' => 'a!name',
|
||||
'remove_onclick' => true
|
||||
),
|
||||
'position_key' => array(
|
||||
'title' => $this->l('Key'),
|
||||
'filter_key' => 'a!position_key',
|
||||
'type' => 'text',
|
||||
'width' => 140,
|
||||
'remove_onclick' => true
|
||||
)
|
||||
);
|
||||
$this->list_no_link = 'no';
|
||||
$this->bulk_actions = array(
|
||||
'delete' => array(
|
||||
'text' => $this->l('Delete selected'),
|
||||
'confirm' => $this->l('Delete selected items?'),
|
||||
'icon' => 'icon-trash'
|
||||
),
|
||||
'correctlink' => array(
|
||||
'text' => $this->l('Correct Image Link'),
|
||||
'confirm' => $this->l('Are you sure you want to change image url from old theme to new theme?'),
|
||||
'icon' => 'icon-edit'
|
||||
),
|
||||
'insertLang' => array(
|
||||
'text' => $this->l('Auto Input Data for New Lang'),
|
||||
'confirm' => $this->l('Auto insert data for new language?'),
|
||||
'icon' => 'icon-edit'
|
||||
)
|
||||
);
|
||||
$this->_where = ' AND ps.id_shop='.(int)$this->context->shop->id;
|
||||
|
||||
$this->theme_dir = apPageHelper::getConfigDir('_PS_THEME_DIR_');
|
||||
$this->position_css_folder = apPageHelper::getConfigDir('_PS_THEME_DIR_').apPageHelper::getCssDir().'positions/';
|
||||
$this->position_js_folder = apPageHelper::getConfigDir('_PS_THEME_DIR_').apPageHelper::getJsDir().'positions/';
|
||||
|
||||
if (!is_dir($this->position_css_folder)) {
|
||||
mkdir($this->position_css_folder, 0755, true);
|
||||
}
|
||||
if (!is_dir($this->position_js_folder)) {
|
||||
mkdir($this->position_js_folder, 0755, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
parent::initToolbar();
|
||||
|
||||
# SAVE AND STAY
|
||||
if ($this->display == 'add' || $this->display == 'edit') {
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/function.js');
|
||||
|
||||
$this->page_header_toolbar_btn['SaveAndStay'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save and stay'),
|
||||
'js' => 'TopSaveAndStay()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSaveAndStay_Name' => 'submitAdd'.$this->table.'AndStay'));
|
||||
|
||||
$this->page_header_toolbar_btn['Save'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save'),
|
||||
'js' => 'TopSave()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSave_Name' => 'submitAdd'.$this->table));
|
||||
}
|
||||
|
||||
# Delete POSITIONS NOT USE
|
||||
switch ($this->display) {
|
||||
default:
|
||||
$this->toolbar_btn['new'] = array(
|
||||
'href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->l('Add new'),
|
||||
'class' => 'btn_add_new',
|
||||
);
|
||||
$this->toolbar_btn['eraser'] = array(
|
||||
'href' => self::$currentIndex.'&leo_delete_position=1&token='.$this->token,
|
||||
'desc' => $this->l('Delete position do not use (fix error when create profile)'),
|
||||
'imgclass' => 'eraser',
|
||||
'class' => 'leo_delete_position',
|
||||
);
|
||||
if ($this->allow_export) {
|
||||
unset($this->toolbar_btn['export']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function processDelete()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
// Check using other profile
|
||||
$result = ApPageBuilderPositionsModel::getProfileUsingPosition($object->id);
|
||||
if (!$result) {
|
||||
$object = parent::processDelete();
|
||||
if ($object->position_key) {
|
||||
Tools::deleteFile($this->position_css_folder.$object->position.$object->position_key.'.css');
|
||||
Tools::deleteFile($this->position_js_folder.$object->position.$object->position_key.'.js');
|
||||
}
|
||||
} else {
|
||||
$name_profile = '';
|
||||
$sep = '';
|
||||
foreach ($result as $item) {
|
||||
$name_profile .= $sep.$item['name'];
|
||||
$sep = ', ';
|
||||
}
|
||||
$this->errors[] = sprintf($this->l('Can not delete position "%s", it is being used by Profile : "%s"'), $object->name, $name_profile);
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function processBulkDelete()
|
||||
{
|
||||
// Remove resouce and update table profiles
|
||||
$arr = $this->boxes;
|
||||
if (!$arr) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($arr as $id) {
|
||||
$profiles = ApPageBuilderPositionsModel::getProfileUsingPosition($id);
|
||||
$object = new ApPageBuilderPositionsModel($id);
|
||||
if (!$profiles) {
|
||||
$object->delete();
|
||||
if ($object->position_key) {
|
||||
Tools::deleteFile($this->position_css_folder.$object->position.$object->position_key.'.css');
|
||||
Tools::deleteFile($this->position_js_folder.$object->position.$object->position_key.'.js');
|
||||
}
|
||||
} else {
|
||||
$name_profile = '';
|
||||
$sep = '';
|
||||
foreach ($profiles as $profile) {
|
||||
$name_profile .= $sep.$profile['name'];
|
||||
$sep = ', ';
|
||||
}
|
||||
$this->errors[] = sprintf($this->l('Can not delete position "%s", it is being used by Profile : "%s"'), $object->name, $name_profile);
|
||||
}
|
||||
}
|
||||
if (empty($this->errors)) {
|
||||
$this->confirmations[] = $this->_conf[1];
|
||||
}
|
||||
}
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderHome');
|
||||
$this->redirect_after .= '&id_appagebuilder_positions='.$object->id;
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
public function processStatus()
|
||||
{
|
||||
if (Validate::isLoadedObject($object = $this->loadObject())) {
|
||||
if ($object->toggleStatus()) {
|
||||
$matches = array();
|
||||
if (preg_match('/[\?|&]controller=([^&]*)/', (string)$_SERVER['HTTP_REFERER'], $matches) !== false && Tools::strtolower($matches[1]) != Tools::strtolower(preg_replace('/controller/i', '', get_class($this)))) {
|
||||
$this->redirect_after = preg_replace('/[\?|&]conf=([^&]*)/i', '', (string)$_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token;
|
||||
}
|
||||
|
||||
$id_category = (($id_category = (int)Tools::getValue('id_category')) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '';
|
||||
$this->redirect_after .= '&conf=5'.$id_category;
|
||||
} else {
|
||||
$this->errors[] = $this->l('You can not disable default profile, Please select other profile as default');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->l('An error occurred while updating the status for an object.').' <b>'.$this->table.'</b> '.$this->l('(cannot load object)');
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
parent::postProcess();
|
||||
if (count($this->errors) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::getIsset('duplicateappagebuilder_positions')) {
|
||||
$id = Tools::getValue('id_appagebuilder_positions');
|
||||
$this->duplicatePosition($id, '');
|
||||
}
|
||||
|
||||
# Delete POSITIONS NOT USE
|
||||
if (Tools::getValue('leo_delete_position') && Tools::getValue('leo_delete_position')) {
|
||||
apPageHelper::processDeleteOldPosition();
|
||||
$this->confirmations[] = 'POSITIONS NOT USE have been deleted successfully.';
|
||||
}
|
||||
}
|
||||
|
||||
public function duplicatePosition($id, $type = '', $name = '')
|
||||
{
|
||||
$id = (int)$id;
|
||||
$object = ApPageBuilderPositionsModel::getPositionById($id);
|
||||
if ($object) {
|
||||
$key = ApPageSetting::getRandomNumber();
|
||||
$old_key = $object['position_key'];
|
||||
$name = $name ? $name : $this->l('Duplicate ').$key;
|
||||
$data = array('name' => $name, 'position' => $object['position'], 'position_key' => 'duplicate_'.$key);
|
||||
$model = new ApPageBuilderPositionsModel();
|
||||
$duplicate_id = $model->addAuto($data);
|
||||
AdminApPageBuilderShortcodesController::duplcateDataPosition($id, $duplicate_id);
|
||||
if ($duplicate_id) {
|
||||
//duplicate shortCode
|
||||
ApPageSetting::writeFile($this->position_js_folder, $data['position'].$data['position_key'].'.js', Tools::file_get_contents($this->position_js_folder.$data['position'].$old_key.'.js'));
|
||||
ApPageSetting::writeFile($this->position_css_folder, $data['position'].$data['position_key'].'.css', Tools::file_get_contents($this->position_css_folder.$data['position'].$old_key.'.css'));
|
||||
if ($type != 'ajax') {
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token;
|
||||
$this->redirect();
|
||||
} else {
|
||||
return $duplicate_id;
|
||||
}
|
||||
} else {
|
||||
if ($type != 'ajax') {
|
||||
Tools::displayError('Can not duplicate Position');
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if ($type != 'ajax') {
|
||||
Tools::displayError('Can not duplicate Position');
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
$this->initToolbar();
|
||||
|
||||
$this->addRowAction('view');
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('duplicate');
|
||||
$this->addRowAction('delete');
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$this->initToolbar();
|
||||
$this->context->controller->addJqueryUI('ui.sortable');
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Ap Position Manage'),
|
||||
'icon' => 'icon-folder-close'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name'),
|
||||
'name' => 'name',
|
||||
'required' => true,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Position Key'),
|
||||
'name' => 'position_key',
|
||||
'required' => true,
|
||||
'desc' => $this->l('Use it to save as file name of css and js of Position'),
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Type'),
|
||||
'name' => 'position',
|
||||
'options' => array(
|
||||
'query' => array(
|
||||
array(
|
||||
'id' => 'header',
|
||||
'name' => $this->l('Header'),
|
||||
),
|
||||
array(
|
||||
'id' => 'content',
|
||||
'name' => $this->l('Content'),
|
||||
),
|
||||
array(
|
||||
'id' => 'footer',
|
||||
'name' => $this->l('Footer'),
|
||||
),
|
||||
array(
|
||||
'id' => 'product',
|
||||
'name' => $this->l('Product'),
|
||||
)
|
||||
),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Custom Css'),
|
||||
'name' => 'css',
|
||||
'desc' => sprintf($this->l('Please set write Permission for folder %s'), $this->position_css_folder),
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Custom Js'),
|
||||
'name' => 'js',
|
||||
'desc' => sprintf($this->l('Please set write Permission for folder %s'), $this->position_js_folder),
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
),
|
||||
'buttons' => array(
|
||||
'save-and-stay' => array(
|
||||
'title' => $this->l('Save and Stay'),
|
||||
'name' => 'submitAdd'.$this->table.'AndStay',
|
||||
'type' => 'submit',
|
||||
'class' => 'btn btn-default pull-right',
|
||||
'icon' => 'process-icon-save'
|
||||
))
|
||||
);
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function getFieldsValue($obj)
|
||||
{
|
||||
$file_value = parent::getFieldsValue($obj);
|
||||
if ($obj->id && $obj->position_key) {
|
||||
$file_value['css'] = Tools::file_get_contents($this->position_css_folder.$obj->position.$obj->position_key.'.css');
|
||||
$file_value['js'] = Tools::file_get_contents($this->position_js_folder.$obj->position.$obj->position_key.'.js');
|
||||
} else {
|
||||
$file_value['position_key'] = 'position'.ApPageSetting::getRandomNumber();
|
||||
}
|
||||
return $file_value;
|
||||
}
|
||||
|
||||
public function processAdd()
|
||||
{
|
||||
if ($obj = parent::processAdd()) {
|
||||
$this->saveCustomJsAndCss($obj->position.$obj->position_key, '');
|
||||
}
|
||||
}
|
||||
|
||||
public function processUpdate()
|
||||
{
|
||||
// Check ifchange position => need delete current file css/js before update
|
||||
$old_object = parent::loadObject();
|
||||
if ($obj = parent::processUpdate()) {
|
||||
$this->saveCustomJsAndCss($obj->position.$obj->position_key, $old_object->position.$obj->position_key);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveCustomJsAndCss($key, $old_key = '')
|
||||
{
|
||||
// Delete old file
|
||||
if ($old_key) {
|
||||
Tools::deleteFile($this->position_css_folder.$old_key.'.css');
|
||||
Tools::deleteFile($this->position_js_folder.$old_key.'.js');
|
||||
}
|
||||
//DONGND:: validate
|
||||
// if (!empty(Tools::getValue('js'))) {
|
||||
if (Tools::getValue('js') != '') {
|
||||
ApPageSetting::writeFile($this->position_js_folder, $key.'.js', Tools::getValue('js'));
|
||||
}
|
||||
//DONGND:: validate
|
||||
// if (!empty(Tools::getValue('css'))) {
|
||||
if (Tools::getValue('css') != '') {
|
||||
ApPageSetting::writeFile($this->position_css_folder, $key.'.css', Tools::getValue('css'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto create a position for page build profile editing/creating
|
||||
* @param type $obj
|
||||
*/
|
||||
public function autoCreatePosition($obj)
|
||||
{
|
||||
$model = new ApPageBuilderPositionsModel();
|
||||
$id = $model->addAuto($obj);
|
||||
if ($id) {
|
||||
$this->saveCustomJsAndCss($obj['position'].$obj['position_key'], '');
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function updateName($id, $name)
|
||||
{
|
||||
return ApPageBuilderPositionsModel::updateName($id, $name);
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
Context::getContext()->controller->addJs(apPageHelper::getJsAdminDir().'admin/form_admin_positions.js');
|
||||
Media::addJsDefL('leo_confirm_text', $this->l('Are you sure you want to Delete do not use position. Please back-up all thing before?'));
|
||||
Media::addJsDefL('leo_form_submit', Context::getContext()->link->getAdminLink('AdminApPageBuilderPositions'));
|
||||
}
|
||||
|
||||
public function displayDuplicateLink($token = null, $id = null, $name = null)
|
||||
{
|
||||
$controller = 'AdminApPageBuilderPositions';
|
||||
$token = Tools::getAdminTokenLite($controller);
|
||||
$html = '<a href="#" title="Duplicate" onclick="confirm_link(\'\', \'Duplicate Position ID '.$id.'. If you wish to proceed, click "Yes". If not, click "No".\', \'Yes\', \'No\', \'index.php?controller='.$controller.'&id_appagebuilder_positions='.$id.'&duplicateappagebuilder_positions&token='.$token.'\', \'#\')">
|
||||
<i class="icon-copy"></i> Duplicate
|
||||
</a>';
|
||||
|
||||
// validate module
|
||||
unset($name);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function access($action, $disable = false)
|
||||
{
|
||||
if (Tools::getIsset('update'.$this->table) && Tools::getIsset($this->identifier)) {
|
||||
// Allow person see "EDIT" form
|
||||
$action = 'view';
|
||||
}
|
||||
return parent::access($action, $disable);
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
|
||||
if (count($this->errors) <= 0) {
|
||||
if (Tools::isSubmit('duplicate'.$this->table)) {
|
||||
if ($this->id_object) {
|
||||
if (!$this->access('add')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to duplicate this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
} elseif (Tools::getIsset('leo_delete_position') && Tools::getValue('leo_delete_position')) {
|
||||
if (!$this->access('delete')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to delelte this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminAdminApthemeConfigLiveController extends ModuleAdminControllerCore
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,732 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(_PS_MODULE_DIR_.'appagebuilder/classes/ApPageBuilderProductsModel.php');
|
||||
|
||||
class AdminApPageBuilderProductsController extends ModuleAdminControllerCore
|
||||
{
|
||||
private $theme_name = '';
|
||||
public $module_name = 'appagebuilder';
|
||||
public $tpl_save = '';
|
||||
public $file_content = array();
|
||||
public $explicit_select;
|
||||
public $order_by;
|
||||
public $order_way;
|
||||
public $profile_css_folder;
|
||||
public $module_path;
|
||||
// public $module_path_resource;
|
||||
public $str_search = array();
|
||||
public $str_relace = array();
|
||||
public $theme_dir;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'appagebuilder_products';
|
||||
$this->className = 'ApPageBuilderProductsModel';
|
||||
$this->lang = false;
|
||||
$this->explicit_select = true;
|
||||
$this->allow_export = true;
|
||||
$this->context = Context::getContext();
|
||||
$this->_join = '
|
||||
INNER JOIN `'._DB_PREFIX_.'appagebuilder_products_shop` ps ON (ps.`id_appagebuilder_products` = a.`id_appagebuilder_products`)';
|
||||
$this->_select .= ' ps.active as active, ps.active_mobile as active_mobile, ps.active_tablet as active_tablet';
|
||||
|
||||
$this->order_by = 'id_appagebuilder_products';
|
||||
$this->order_way = 'DESC';
|
||||
parent::__construct();
|
||||
$this->fields_list = array(
|
||||
'id_appagebuilder_products' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 50,
|
||||
'class' => 'fixed-width-xs'
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Name'),
|
||||
'width' => 140,
|
||||
'type' => 'text',
|
||||
'filter_key' => 'a!name'
|
||||
),
|
||||
'plist_key' => array(
|
||||
'title' => $this->l('Product List Key'),
|
||||
'filter_key' => 'a!plist_key',
|
||||
'type' => 'text',
|
||||
'width' => 140,
|
||||
),
|
||||
'class' => array(
|
||||
'title' => $this->l('Class'),
|
||||
'width' => 140,
|
||||
'type' => 'text',
|
||||
'filter_key' => 'a!class',
|
||||
'orderby' => false
|
||||
),
|
||||
'active' => array(
|
||||
'title' => $this->l('Is Default'),
|
||||
'active' => 'status',
|
||||
'filter_key' => 'ps!active',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
),
|
||||
'active_mobile' => array(
|
||||
'title' => $this->l('Is Mobile'),
|
||||
'active' => 'active_mobile',
|
||||
'filter_key' => 'ps!active_mobile',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
),
|
||||
'active_tablet' => array(
|
||||
'title' => $this->l('Is Tablet'),
|
||||
'active' => 'active_tablet',
|
||||
'filter_key' => 'ps!active_tablet',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
)
|
||||
);
|
||||
$this->bulk_actions = array(
|
||||
'delete' => array(
|
||||
'text' => $this->l('Delete selected'),
|
||||
'confirm' => $this->l('Delete selected items?'),
|
||||
'icon' => 'icon-trash'
|
||||
)
|
||||
);
|
||||
|
||||
//nghiatd - add theme mobile and table
|
||||
$correct_mobile = Db::getInstance()->executeS('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "'._DB_NAME_.'" AND TABLE_NAME="'._DB_PREFIX_.'appagebuilder_products" AND column_name="active_mobile"');
|
||||
if (count($correct_mobile) < 1) {
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_products_shop` ADD `active_mobile` int(11) NOT NULL');
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_products_shop` ADD `active_tablet` int(11) NOT NULL');
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_products` ADD `active_mobile` int(11) NOT NULL');
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_products` ADD `active_tablet` int(11) NOT NULL');
|
||||
}
|
||||
|
||||
$this->theme_dir = apPageHelper::getConfigDir('_PS_THEME_DIR_');
|
||||
|
||||
$this->_where = ' AND ps.id_shop='.(int)$this->context->shop->id;
|
||||
$this->theme_name = apPageHelper::getThemeName();
|
||||
$this->profile_css_folder = $this->theme_dir.'modules/'.$this->module_name.'/';
|
||||
$this->module_path = __PS_BASE_URI__.'modules/'.$this->module_name.'/';
|
||||
// $this->module_path_resource = $this->module_path.'views/';
|
||||
$this->str_search = array('_APAMP_', '_APQUOT_', '_APAPOST_', '_APTAB_', '_APNEWLINE_', '_APENTER_', '_APOBRACKET_', '_APCBRACKET_', '_APOCBRACKET_', '_APCCBRACKET_');
|
||||
$this->str_relace = array('&', '\"', '\'', '\t', '\r', '\n', '[', ']', '{', '}');
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
parent::initToolbar();
|
||||
|
||||
# SAVE AND STAY
|
||||
if ($this->display == 'add' || $this->display == 'edit') {
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/function.js');
|
||||
|
||||
$this->page_header_toolbar_btn['SaveAndStay'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save and stay'),
|
||||
'js' => 'TopSaveAndStay()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSaveAndStay_Name' => 'submitAdd'.$this->table.'AndStay'));
|
||||
|
||||
$this->page_header_toolbar_btn['Save'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save'),
|
||||
'js' => 'TopSave()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSave_Name' => 'submitAdd'.$this->table));
|
||||
}
|
||||
|
||||
# SHOW LINK EXPORT ALL FOR TOOLBAR
|
||||
switch ($this->display) {
|
||||
default:
|
||||
$this->toolbar_btn['new'] = array(
|
||||
'href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->l('Add new'),
|
||||
'class' => 'btn_add_new',
|
||||
);
|
||||
if (!$this->display && $this->can_import) {
|
||||
$this->toolbar_btn['import'] = array(
|
||||
'href' => self::$currentIndex . '&import' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->trans('Import', array(), 'Admin.Actions'),
|
||||
'class' => 'btn_xml_import',
|
||||
);
|
||||
}
|
||||
if ($this->allow_export) {
|
||||
$this->toolbar_btn['export'] = array(
|
||||
'href' => self::$currentIndex . '&export' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->l('Export'),
|
||||
'class' => 'btn_xml_export',
|
||||
);
|
||||
Media::addJsDef(array('record_id' => 'appagebuilder_productsBox[]'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function processExport($text_delimiter = '"')
|
||||
{
|
||||
// $multilang = false;
|
||||
if (isset($this->className) && $this->className) {
|
||||
$definition = ObjectModel::getDefinition($this->className);
|
||||
// $multilang = $definition['multilang'];
|
||||
}
|
||||
|
||||
$record_id = Tools::getValue('record_id');
|
||||
$file_name = 'ap_product_list_all.xml';
|
||||
// validate module
|
||||
unset($text_delimiter);
|
||||
|
||||
if ($record_id) {
|
||||
$record_id_str = implode(", ", $record_id);
|
||||
$this->_where = ' AND a.'.$this->identifier.' IN ( '.pSQL($record_id_str).' )';
|
||||
$file_name = 'ap_product_list.xml';
|
||||
}
|
||||
|
||||
$this->getList($this->context->language->id, null, null, 0, false);
|
||||
if (!count($this->_list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->_list;
|
||||
|
||||
$data_all = array();
|
||||
foreach (Language::getLanguages() as $key => $lang) {
|
||||
$this->getList($lang['id_lang'], null, null, 0, false);
|
||||
$data_all[$lang['iso_code']] = $this->_list;
|
||||
}
|
||||
|
||||
$this->file_content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
$this->file_content .= '<data>' . "\n";
|
||||
$this->file_content .= '<product_list>' . "\n";
|
||||
|
||||
if ($data) {
|
||||
foreach ($data as $product_detail) {
|
||||
$this->file_content .= '<record>' . "\n";
|
||||
foreach ($product_detail as $key => $value) {
|
||||
if (isset($definition['fields'][$key]['lang']) && $definition['fields'][$key]['lang']) {
|
||||
# MULTI LANG
|
||||
$this->file_content .= ' <'.$key.'>'. "\n";
|
||||
foreach (Language::getLanguages() as $key_lang => $lang) {
|
||||
// validate module
|
||||
unset($key_lang);
|
||||
$this->file_content .= ' <'.$lang['iso_code'].'>';
|
||||
$this->file_content .= '<![CDATA['.$value.']]>';
|
||||
$this->file_content .= '</'.$lang['iso_code'].'>' . "\n";
|
||||
}
|
||||
$this->file_content .= ' </'.$key.'>' . "\n";
|
||||
} else {
|
||||
# SINGLE LANG
|
||||
$this->file_content .= ' <'.$key.'>';
|
||||
$this->file_content .= '<![CDATA['.$value.']]>';
|
||||
$this->file_content .= '</'.$key.'>' . "\n";
|
||||
}
|
||||
}
|
||||
$this->file_content .= '</record>' . "\n";
|
||||
}
|
||||
}
|
||||
$this->file_content .= '</product_list>' . "\n";
|
||||
$this->file_content .= '</data>' . "\n";
|
||||
header('Content-type: text/xml');
|
||||
header('Content-Disposition: attachment; filename="'.$file_name.'"');
|
||||
echo $this->file_content;
|
||||
die();
|
||||
}
|
||||
|
||||
public function processImport()
|
||||
{
|
||||
$upload_file = new Uploader('importFile');
|
||||
$upload_file->setAcceptTypes(array('xml'));
|
||||
$file = $upload_file->process();
|
||||
$file = $file[0];
|
||||
if (!isset($file['save_path'])) {
|
||||
$this->errors[] = $this->trans('Failed to import.', array(), 'Admin.Notifications.Error');
|
||||
return;
|
||||
}
|
||||
$files_content = simplexml_load_file($file['save_path']);
|
||||
$override = Tools::getValue('override');
|
||||
|
||||
if (isset($files_content->product_list) && $files_content->product_list) {
|
||||
foreach ($files_content->product_list->children() as $product_details) {
|
||||
if (!$override) {
|
||||
$obj_model = new ApPageBuilderProductsModel();
|
||||
$obj_model->plist_key = 'plist'.ApPageSetting::getRandomNumber();
|
||||
$obj_model->name = $product_details->name->__toString();
|
||||
$obj_model->class = $product_details->class->__toString();
|
||||
$obj_model->params = $product_details->params->__toString();
|
||||
$obj_model->type = $product_details->type->__toString();
|
||||
$obj_model->active = 0;
|
||||
|
||||
if ($obj_model->save()) {
|
||||
$this->saveTplFile($obj_model->plist_key, $obj_model->params);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->confirmations[] = $this->trans('Successful importing.', array(), 'Admin.Notifications.Success');
|
||||
} else {
|
||||
$this->errors[] = $this->trans('Wrong file to import.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
if ($object->page == 'product_detail') {
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderProductDetail');
|
||||
} else {
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderHome');
|
||||
}
|
||||
$this->redirect_after .= '&id_appagebuilder_products='.$object->id;
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
parent::postProcess();
|
||||
|
||||
if (Tools::getIsset('active_mobileappagebuilder_products') || Tools::getIsset('active_tabletappagebuilder_products')) {
|
||||
if (Validate::isLoadedObject($object = $this->loadObject())) {
|
||||
$result = Tools::getIsset('active_mobileappagebuilder_products')?$object->toggleStatusMT('active_mobile'):$object->toggleStatusMT('active_tablet');
|
||||
if ($result) {
|
||||
// $this->mesage[] = Tools::displayError('You should enebale mobile theme in theme config');
|
||||
|
||||
$matches = array();
|
||||
if (preg_match('/[\?|&]controller=([^&]*)/', (string)$_SERVER['HTTP_REFERER'], $matches) !== false && Tools::strtolower($matches[1]) != Tools::strtolower(preg_replace('/controller/i', '', get_class($this)))) {
|
||||
$this->redirect_after = preg_replace('/[\?|&]conf=([^&]*)/i', '', (string)$_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token.'&mobiletheme';
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('You can not disable default profile, Please select other profile as default');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('An error occurred while updating the status for an object.')
|
||||
.'<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->errors) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::getIsset('duplicateappagebuilder_products')) {
|
||||
$id = Tools::getValue('id_appagebuilder_products');
|
||||
$model = new ApPageBuilderProductsModel($id);
|
||||
$duplicate_object = $model->duplicateObject();
|
||||
if (isset($model->params)) {
|
||||
# FIX : insert code can not duplicate
|
||||
$duplicate_object->params = $model->params;
|
||||
}
|
||||
$duplicate_object->name = $this->l('Duplicate of').' '.$duplicate_object->name;
|
||||
$old_key = $duplicate_object->plist_key;
|
||||
$duplicate_object->plist_key = 'plist'.ApPageSetting::getRandomNumber();
|
||||
if ($duplicate_object->add()) {
|
||||
//duplicate shortCode
|
||||
$filecontent = Tools::file_get_contents(apPageHelper::getConfigDir('theme_profiles').$old_key.'.tpl');
|
||||
ApPageSetting::writeFile(apPageHelper::getConfigDir('theme_profiles'), $duplicate_object->plist_key.'.tpl', $filecontent);
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token;
|
||||
$this->redirect();
|
||||
} else {
|
||||
Tools::displayError('Can not duplicate Profiles');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Tools::isSubmit('saveELement')) {
|
||||
$filecontent = Tools::getValue('filecontent');
|
||||
$fileName = Tools::getValue('fileName');
|
||||
if (!is_dir($this->theme_dir.'modules/appagebuilder/views/templates/front/products/')) {
|
||||
if (!is_dir($this->theme_dir.'modules/appagebuilder/views/templates/front/products/')) {
|
||||
mkdir($this->theme_dir.'modules/appagebuilder/views/templates/front/products/', 0755, true);
|
||||
}
|
||||
}
|
||||
ApPageSetting::writeFile($this->theme_dir.'modules/appagebuilder/views/templates/front/products/', $fileName.'.tpl', $filecontent);
|
||||
}
|
||||
}
|
||||
|
||||
public function convertObjectToTpl($object_form)
|
||||
{
|
||||
$tpl = '';
|
||||
foreach ($object_form as $object) {
|
||||
if ($object['name'] == 'functional_buttons') {
|
||||
$tpl .= ApPageSetting::getProductFunctionalButtons();
|
||||
$tpl .= $this->convertObjectToTpl($object['element']);
|
||||
$tpl .= '</div>';
|
||||
} else if ($object['name'] == 'code') {
|
||||
$tpl .= $object['code'];
|
||||
} else {
|
||||
if (!isset($this->file_content[$object['name']])) {
|
||||
$this->returnFileContent($object['name']);
|
||||
}
|
||||
$tpl .= $this->file_content[$object['name']];
|
||||
}
|
||||
}
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
public function returnFileContent($pelement)
|
||||
{
|
||||
$tpl_dir = $this->theme_dir.'modules/appagebuilder/views/templates/front/products/'.$pelement.'.tpl';
|
||||
if (!file_exists($tpl_dir)) {
|
||||
$tpl_dir = _PS_MODULE_DIR_.'appagebuilder/views/templates/front/products/'.$pelement.'.tpl';
|
||||
}
|
||||
$this->file_content[$pelement] = Tools::file_get_contents($tpl_dir);
|
||||
return $this->file_content[$pelement];
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
if (Tools::getIsset('pelement')) {
|
||||
$helper = new HelperForm();
|
||||
$helper->submit_action = 'saveELement';
|
||||
$inputs = array(
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'name' => 'filecontent',
|
||||
'label' => $this->l('File Content'),
|
||||
'desc' => $this->l('Please carefully when edit tpl file'),
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'fileName',
|
||||
)
|
||||
);
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => sprintf($this->l('You are Editing file: %s'), Tools::getValue('pelement').'.tpl'),
|
||||
'icon' => 'icon-cogs'
|
||||
),
|
||||
'action' => Context::getContext()->link->getAdminLink('AdminApPageBuilderShortcodes'),
|
||||
'input' => $inputs,
|
||||
'name' => 'importData',
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'button btn btn-default pull-right'
|
||||
),
|
||||
'tinymce' => false,
|
||||
),
|
||||
);
|
||||
$helper->tpl_vars = array(
|
||||
'fields_value' => $this->getFileContent()
|
||||
);
|
||||
return $helper->generateForm(array($fields_form));
|
||||
}
|
||||
$this->initToolbar();
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('duplicate');
|
||||
$this->addRowAction('delete');
|
||||
return $this->importForm() . parent::renderList();
|
||||
}
|
||||
|
||||
public function importForm()
|
||||
{
|
||||
$helper = new HelperForm();
|
||||
$helper->submit_action = 'import' . $this->table;
|
||||
$inputs = array(
|
||||
array(
|
||||
'type' => 'file',
|
||||
'name' => 'importFile',
|
||||
'label' => $this->l('File'),
|
||||
'desc' => $this->l('Only accept xml file'),
|
||||
),
|
||||
);
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'action' => Context::getContext()->link->getAdminLink('AdminApPageBuilderShortcodeController'),
|
||||
'input' => $inputs,
|
||||
'submit' => array('title' => $this->l('Import'), 'class' => 'button btn btn-success'),
|
||||
'tinymce' => false,
|
||||
),
|
||||
);
|
||||
$helper->fields_value = isset($this->fields_value) ? $this->fields_value : array();
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->currentIndex = self::$currentIndex;
|
||||
$helper->token = $this->token;
|
||||
$helper->table = 'xml_import';
|
||||
$html = $helper->generateForm(array($fields_form));
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getFileContent()
|
||||
{
|
||||
$pelement = Tools::getValue('pelement');
|
||||
$tpl_dir = $this->theme_dir.'modules/appagebuilder/views/templates/front/products/'.$pelement.'.tpl';
|
||||
if (!file_exists($tpl_dir)) {
|
||||
$tpl_dir = _PS_MODULE_DIR_.'appagebuilder/views/templates/front/products/'.$pelement.'.tpl';
|
||||
}
|
||||
return array('fileName' => $pelement, 'filecontent' => Tools::file_get_contents($tpl_dir));
|
||||
}
|
||||
|
||||
public function setHelperDisplay(Helper $helper)
|
||||
{
|
||||
parent::setHelperDisplay($helper);
|
||||
$this->helper->module = APPageBuilder::getInstance();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$this->initToolbar();
|
||||
$this->context->controller->addJqueryUI('ui.sortable');
|
||||
$this->context->controller->addJqueryUI('ui.draggable');
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/form.js');
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/product-list.js');
|
||||
$this->context->controller->addCss(apPageHelper::getCssAdminDir().'admin/form.css');
|
||||
$source_file = Tools::scandir(_PS_MODULE_DIR_.'appagebuilder/views/templates/front/products/', 'tpl');
|
||||
if (is_dir($this->theme_dir.'modules/appagebuilder/views/templates/front/products/')) {
|
||||
$source_template_file = Tools::scandir($this->theme_dir.'modules/appagebuilder/views/templates/front/products/', 'tpl');
|
||||
$source_file = array_merge($source_file, $source_template_file);
|
||||
}
|
||||
$elements = array();
|
||||
$icon_list = ApPageSetting::getProductElementIcon();
|
||||
foreach ($source_file as $value) {
|
||||
$fileName = basename($value, '.tpl');
|
||||
if ($fileName == 'index') {
|
||||
continue;
|
||||
}
|
||||
$elements[$fileName] = array(
|
||||
'name' => str_replace('_', ' ', $fileName),
|
||||
'icon' => (isset($icon_list[$fileName]) ? $icon_list[$fileName] : 'icon-sun'));
|
||||
}
|
||||
$params = array('gridLeft' => array(), 'gridRight' => array());
|
||||
|
||||
$this->object->params = str_replace($this->str_search, $this->str_relace, $this->object->params);
|
||||
|
||||
if (isset($this->object->params)) {
|
||||
$params = Tools::jsonDecode($this->object->params, true);
|
||||
}
|
||||
|
||||
//$params['gridLeft'] = $this->replaceSpecialStringToHtml($params['gridLeft']);
|
||||
//$params['gridRight'] = $this->replaceSpecialStringToHtml($params['gridRight']);
|
||||
|
||||
$block_list = array(
|
||||
'gridLeft' => array('title' => 'Product-Image', 'class' => 'left-block'),
|
||||
'gridRight' => array('title' => 'Product-Meta', 'class' => 'right-block'),
|
||||
);
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Ap Profile Manage'),
|
||||
'icon' => 'icon-folder-close'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name'),
|
||||
'name' => 'name',
|
||||
'required' => true,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Product List Key'),
|
||||
'name' => 'plist_key',
|
||||
'readonly' => 'readonly',
|
||||
'desc' => $this->l('Tpl File name'),
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Class'),
|
||||
'type' => 'text',
|
||||
'name' => 'class',
|
||||
'width' => 140
|
||||
),
|
||||
array(
|
||||
'type' => 'ap_proGrid',
|
||||
'name' => 'ap_proGrid',
|
||||
'label' => $this->l('Layout'),
|
||||
'elements' => $elements,
|
||||
'params' => $params,
|
||||
'blockList' => $block_list
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'params'
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
),
|
||||
'buttons' => array(
|
||||
'save-and-stay' => array(
|
||||
'title' => $this->l('Save and Stay'),
|
||||
'name' => 'submitAdd'.$this->table.'AndStay',
|
||||
'type' => 'submit',
|
||||
'class' => 'btn btn-default pull-right',
|
||||
'icon' => 'process-icon-save')
|
||||
)
|
||||
);
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function replaceSpecialStringToHtml($arr)
|
||||
{
|
||||
foreach ($arr as &$v) {
|
||||
if ($v['name'] == 'code') {
|
||||
// validate module
|
||||
$v['code'] = str_replace($this->str_search, $this->str_relace, $v['code']);
|
||||
} else {
|
||||
if ($v['name'] == 'functional_buttons') {
|
||||
foreach ($v as &$f) {
|
||||
if ($f['name'] == 'code') {
|
||||
// validate module
|
||||
$f['code'] = str_replace($this->str_search, $this->str_relace, $f['code']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function getFieldsValue($obj)
|
||||
{
|
||||
$file_value = parent::getFieldsValue($obj);
|
||||
if (!$obj->id) {
|
||||
$num = ApPageSetting::getRandomNumber();
|
||||
$file_value['plist_key'] = 'plist'.$num;
|
||||
$file_value['name'] = $file_value['plist_key'];
|
||||
$file_value['class'] = 'product-list-'.$num;
|
||||
}
|
||||
return $file_value;
|
||||
}
|
||||
|
||||
public function processAdd()
|
||||
{
|
||||
if ($obj = parent::processAdd()) {
|
||||
$this->saveTplFile($obj->plist_key, $obj->params);
|
||||
}
|
||||
}
|
||||
|
||||
public function processUpdate()
|
||||
{
|
||||
if ($obj = parent::processUpdate()) {
|
||||
$this->saveTplFile($obj->plist_key, $obj->params);
|
||||
}
|
||||
}
|
||||
|
||||
public function processDelete()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
Tools::deleteFile(apPageHelper::getConfigDir('theme_profiles').$object->plist_key.'.tpl');
|
||||
parent::processDelete();
|
||||
}
|
||||
|
||||
public function saveTplFile($plist_key, $params = '')
|
||||
{
|
||||
$data_form = str_replace($this->str_search, $this->str_relace, $params);
|
||||
$data_form = Tools::jsonDecode($data_form, true);
|
||||
|
||||
$grid_left = $data_form['gridLeft'];
|
||||
$grid_right = $data_form['gridRight'];
|
||||
$tpl_grid = ApPageSetting::getProductContainer();
|
||||
$tpl_grid .= ApPageSetting::getProductLeftBlock().$this->convertObjectToTpl($grid_left)."</div>\n";
|
||||
$tpl_grid .= ApPageSetting::getProductRightBlock().$this->convertObjectToTpl($grid_right)."</div>\n";
|
||||
$tpl_grid .= ApPageSetting::getProductContainerEnd();
|
||||
$folder = apPageHelper::getConfigDir('theme_profiles');
|
||||
if (!is_dir($folder)) {
|
||||
mkdir($folder, 0755, true);
|
||||
}
|
||||
$file = $plist_key.'.tpl';
|
||||
$tpl_grid = preg_replace('/\{\*[\s\S]*?\*\}/', '', $tpl_grid);
|
||||
$tpl_grid = str_replace(" mod='appagebuilder'", '', $tpl_grid);
|
||||
ApPageSetting::writeFile($folder, $file, apPageHelper::getLicenceTPL().$tpl_grid);
|
||||
}
|
||||
|
||||
public function processStatus()
|
||||
{
|
||||
if (Validate::isLoadedObject($object = $this->loadObject())) {
|
||||
if ($object->toggleStatus()) {
|
||||
$matches = array();
|
||||
if (preg_match('/[\?|&]controller=([^&]*)/', (string)$_SERVER['HTTP_REFERER'], $matches) !== false && Tools::strtolower($matches[1]) != Tools::strtolower(preg_replace('/controller/i', '', get_class($this)))) {
|
||||
$this->redirect_after = preg_replace('/[\?|&]conf=([^&]*)/i', '', (string)$_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('An error occurred while updating the status for an object.')
|
||||
.'<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function displayDuplicateLink($token = null, $id = null, $name = null)
|
||||
{
|
||||
$controller = 'AdminApPageBuilderProducts';
|
||||
$token = Tools::getAdminTokenLite($controller);
|
||||
$html = '<a href="#" title="Duplicate" onclick="confirm_link(\'\', \'Duplicate Product List ID '.$id.'. If you wish to proceed, click "Yes". If not, click "No".\', \'Yes\', \'No\', \'index.php?controller='.$controller.'&id_appagebuilder_products='.$id.'&duplicateappagebuilder_products&token='.$token.'\', \'#\')">
|
||||
<i class="icon-copy"></i> Duplicate
|
||||
</a>';
|
||||
|
||||
// validate module
|
||||
unset($name);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function access($action, $disable = false)
|
||||
{
|
||||
if (Tools::getIsset('update'.$this->table) && Tools::getIsset($this->identifier)) {
|
||||
// Allow person see "EDIT" form
|
||||
$action = 'view';
|
||||
}
|
||||
return parent::access($action, $disable);
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
# SET ACTION : IMPORT DATA
|
||||
if ($this->can_import && Tools::getIsset('import' . $this->table)) {
|
||||
if ($this->access('edit')) {
|
||||
$this->action = 'import';
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->errors) <= 0) {
|
||||
if (Tools::isSubmit('duplicate'.$this->table)) {
|
||||
if ($this->id_object) {
|
||||
if (!$this->access('add')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to duplicate this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
} elseif ($this->can_import && Tools::getIsset('import' . $this->table)) {
|
||||
if (!$this->access('edit')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to import data.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,855 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(_PS_MODULE_DIR_.'appagebuilder/classes/ApPageBuilderProfilesModel.php');
|
||||
|
||||
class AdminApPageBuilderProfilesController extends ModuleAdminControllerCore
|
||||
{
|
||||
private $theme_name = '';
|
||||
public $profile_js_folder = '';
|
||||
public $profile_css_folder = '';
|
||||
public $module_name = 'appagebuilder';
|
||||
public $explicit_select;
|
||||
public $order_by;
|
||||
public $order_way;
|
||||
public $theme_dir;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'appagebuilder_profiles';
|
||||
$this->className = 'ApPageBuilderProfilesModel';
|
||||
$this->lang = false;
|
||||
$this->explicit_select = true;
|
||||
$this->allow_export = true;
|
||||
|
||||
parent::__construct();
|
||||
$this->theme_dir = apPageHelper::getConfigDir('_PS_THEME_DIR_');
|
||||
|
||||
$this->context = Context::getContext();
|
||||
|
||||
$this->order_by = 'page';
|
||||
$this->order_way = 'DESC';
|
||||
$alias = 'sa';
|
||||
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$this->_join .= ' JOIN `'._DB_PREFIX_.'appagebuilder_profiles_shop`
|
||||
sa ON (a.`id_appagebuilder_profiles` = sa.`id_appagebuilder_profiles` AND sa.id_shop = '.$id_shop.')';
|
||||
$this->_select .= ' sa.active as active, sa.active_mobile as active_mobile, sa.active_tablet as active_tablet';
|
||||
|
||||
$this->fields_list = array(
|
||||
'id_appagebuilder_profiles' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 50,
|
||||
'class' => 'fixed-width-xs'
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Name'),
|
||||
'width' => 140,
|
||||
'type' => 'text',
|
||||
'filter_key' => 'a!name'
|
||||
),
|
||||
'profile_key' => array(
|
||||
'title' => $this->l('Key'),
|
||||
'filter_key' => 'a!profile_key',
|
||||
'type' => 'text',
|
||||
'width' => 140,
|
||||
),
|
||||
'active' => array(
|
||||
'title' => $this->l('Is Default'),
|
||||
'active' => 'status',
|
||||
'filter_key' => $alias.'!active',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
),
|
||||
'active_mobile' => array(
|
||||
'title' => $this->l('Is Mobile'),
|
||||
'active' => 'active_mobile',
|
||||
'filter_key' => $alias.'!active_mobile',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
),
|
||||
'active_tablet' => array(
|
||||
'title' => $this->l('Is Tablet'),
|
||||
'active' => 'active_tablet',
|
||||
'filter_key' => $alias.'!active_tablet',
|
||||
'align' => 'text-center',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm',
|
||||
'orderby' => false
|
||||
)
|
||||
);
|
||||
|
||||
$this->bulk_actions = array(
|
||||
'delete' => array(
|
||||
'text' => $this->l('Delete selected'),
|
||||
'confirm' => $this->l('Delete selected items?'),
|
||||
'icon' => 'icon-trash'
|
||||
),
|
||||
'insertLang' => array(
|
||||
'text' => $this->l('Auto Input Data for New Lang'),
|
||||
'confirm' => $this->l('Auto insert data for new language?'),
|
||||
'icon' => 'icon-edit'
|
||||
)
|
||||
);
|
||||
|
||||
//nghiatd - add theme mobile and table
|
||||
$correct_mobile = Db::getInstance()->executeS('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "'._DB_NAME_.'" AND TABLE_NAME="'._DB_PREFIX_.'appagebuilder_profiles_shop" AND column_name="active_mobile"');
|
||||
if (count($correct_mobile) < 1) {
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_profiles_shop` ADD `active_mobile` int(11) NOT NULL');
|
||||
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'appagebuilder_profiles_shop` ADD `active_tablet` int(11) NOT NULL');
|
||||
}
|
||||
|
||||
|
||||
$this->_where = ' AND sa.id_shop='.(int)$this->context->shop->id;
|
||||
$this->theme_name = apPageHelper::getThemeName();
|
||||
|
||||
$this->profile_css_folder = apPageHelper::getConfigDir('_PS_THEME_DIR_').apPageHelper::getCssDir().'profiles/';
|
||||
$this->profile_js_folder = apPageHelper::getConfigDir('_PS_THEME_DIR_').apPageHelper::getJsDir().'profiles/';
|
||||
|
||||
if (!is_dir($this->profile_css_folder)) {
|
||||
mkdir($this->profile_css_folder, 0755, true);
|
||||
}
|
||||
if (!is_dir($this->profile_js_folder)) {
|
||||
mkdir($this->profile_js_folder, 0755, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
parent::initToolbar();
|
||||
|
||||
# SAVE AND STAY
|
||||
if ($this->display == 'add' || $this->display == 'edit') {
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/function.js');
|
||||
|
||||
$this->page_header_toolbar_btn['SaveAndStay'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save and stay'),
|
||||
'js' => 'TopSaveAndStay()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSaveAndStay_Name' => 'submitAdd'.$this->table.'AndStay'));
|
||||
|
||||
$this->page_header_toolbar_btn['Save'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save'),
|
||||
'js' => 'TopSave()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSave_Name' => 'submitAdd'.$this->table));
|
||||
}
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
$this->addJqueryPlugin('tagify');
|
||||
}
|
||||
|
||||
public function processDelete()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
$object->loadDataShop();
|
||||
|
||||
if ($object && !$object->active) {
|
||||
$object = parent::processDelete();
|
||||
if ($object->profile_key) {
|
||||
Tools::deleteFile($this->profile_css_folder.$object->profile_key.'.css');
|
||||
Tools::deleteFile($this->profile_js_folder.$object->profile_key.'.js');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('Can not delete Default Profile.');
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function processBulkDelete()
|
||||
{
|
||||
$arr = $this->boxes;
|
||||
if (!$arr) {
|
||||
return;
|
||||
}
|
||||
foreach ($arr as $id) {
|
||||
$object = new $this->className($id);
|
||||
$object->loadDataShop();
|
||||
if ($object && !$object->active) {
|
||||
$object->delete();
|
||||
if ($object->profile_key) {
|
||||
Tools::deleteFile($this->profile_css_folder.$object->profile_key.'.css');
|
||||
Tools::deleteFile($this->profile_js_folder.$object->profile_key.'.js');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('Can not delete Default Profile.');
|
||||
}
|
||||
}
|
||||
if (empty($this->errors)) {
|
||||
$this->confirmations[] = $this->_conf[1];
|
||||
}
|
||||
}
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
//echo 'here';die;
|
||||
$object = $this->loadObject();
|
||||
if ($object->page == 'product_detail') {
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderProductDetail');
|
||||
} else {
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderHome');
|
||||
}
|
||||
$this->redirect_after .= '&id_appagebuilder_profiles='.$object->id;
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
public function displayViewLink($token = null, $id = null, $name = null)
|
||||
{
|
||||
// validate module
|
||||
unset($name);
|
||||
$token = Context::getContext()->link->getAdminLink('AdminApPageBuilderHome');
|
||||
$href = $token . '&id_appagebuilder_profiles='.$id;
|
||||
$html = '<a href="'.$href.'" class="btn btn-default" title="View"><i class="icon-search-plus"></i> View</a>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function processBulkinsertLang()
|
||||
{
|
||||
// Remove resouce and update table profiles
|
||||
$arr = $this->boxes;
|
||||
if (!$arr) {
|
||||
// validate module
|
||||
$arr[] = Tools::getValue('id');
|
||||
}
|
||||
|
||||
if (!$arr) {
|
||||
return;
|
||||
}
|
||||
foreach ($arr as $item) {
|
||||
if ($item) {
|
||||
//has profile id
|
||||
$pfile = new ApPageBuilderProfilesModel($item);
|
||||
$id_positions = array($pfile->header, $pfile->content, $pfile->footer, $pfile->product);
|
||||
$list_position = $pfile->getPositionsForProfile($id_positions);
|
||||
$list_pos_id = array();
|
||||
foreach ($list_position as $v) {
|
||||
// validate module
|
||||
$list_pos_id[] = $v['id_appagebuilder_positions'];
|
||||
}
|
||||
$s_model = new ApPageBuilderModel();
|
||||
$list_short_c = $s_model->getAllItemsByPositionId($list_pos_id);
|
||||
$context = Context::getContext();
|
||||
$id_lang = (int)$context->language->id;
|
||||
foreach ($list_short_c as $shor_code) {
|
||||
$s_model = new ApPageBuilderModel($shor_code['id']);
|
||||
if ($s_model->params) {
|
||||
foreach ($s_model->params as $key => $value) {
|
||||
if ($key != $id_lang) {
|
||||
// validate module
|
||||
$s_model->params[$key] = $s_model->params[$id_lang];
|
||||
}
|
||||
// validate module
|
||||
unset($value);
|
||||
}
|
||||
}
|
||||
$s_model->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function processStatus()
|
||||
{
|
||||
if (Validate::isLoadedObject($object = $this->loadObject())) {
|
||||
if ($object->toggleStatus()) {
|
||||
$matches = array();
|
||||
if (preg_match('/[\?|&]controller=([^&]*)/', (string)$_SERVER['HTTP_REFERER'], $matches) !== false && Tools::strtolower($matches[1]) != Tools::strtolower(preg_replace('/controller/i', '', get_class($this)))) {
|
||||
$this->redirect_after = preg_replace('/[\?|&]conf=([^&]*)/i', '', (string)$_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token;
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('You can not disable default profile, Please select other profile as default');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('An error occurred while updating the status for an object.')
|
||||
.'<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
parent::postProcess();
|
||||
if (count($this->errors) > 0) {
|
||||
return;
|
||||
}
|
||||
if (Tools::getIsset('active_mobileappagebuilder_profiles') || Tools::getIsset('active_tabletappagebuilder_profiles')) {
|
||||
if (Validate::isLoadedObject($object = $this->loadObject())) {
|
||||
$result = Tools::getIsset('active_mobileappagebuilder_profiles')?$object->toggleStatusMT('active_mobile'):$object->toggleStatusMT('active_tablet');
|
||||
if ($result) {
|
||||
// $this->mesage[] = Tools::displayError('You should enebale mobile theme in theme config');
|
||||
|
||||
$matches = array();
|
||||
if (preg_match('/[\?|&]controller=([^&]*)/', (string)$_SERVER['HTTP_REFERER'], $matches) !== false && Tools::strtolower($matches[1]) != Tools::strtolower(preg_replace('/controller/i', '', get_class($this)))) {
|
||||
$this->redirect_after = preg_replace('/[\?|&]conf=([^&]*)/i', '', (string)$_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token.'&mobiletheme';
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('You can not disable default profile, Please select other profile as default');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('An error occurred while updating the status for an object.')
|
||||
.'<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
}
|
||||
if (Tools::getIsset('duplicateappagebuilder_profiles')) {
|
||||
// $context = Context::getContext();
|
||||
// $id_shop = $context->shop->id;
|
||||
$id = Tools::getValue('id_appagebuilder_profiles');
|
||||
$model = new ApPageBuilderProfilesModel($id);
|
||||
|
||||
if ($model) {
|
||||
$old_key = $model->profile_key;
|
||||
$model->profile_key = $profile_key = 'profile'.ApPageSetting::getRandomNumber();
|
||||
$model->id = null;
|
||||
$model->name = $this->l('Duplicate of ') . $model->name;
|
||||
$model->active = '';
|
||||
$model->friendly_url = array();
|
||||
$duplicate_object = $model->save();
|
||||
|
||||
if ($duplicate_object) {
|
||||
//duplicate shortCode
|
||||
$id_new = $model->id;
|
||||
ApPageSetting::writeFile($this->profile_js_folder, $profile_key.'.js', Tools::file_get_contents($this->profile_js_folder.$old_key.'.js'));
|
||||
ApPageSetting::writeFile($this->profile_css_folder, $profile_key.'.css', Tools::file_get_contents($this->profile_css_folder.$old_key.'.css'));
|
||||
AdminApPageBuilderShortcodesController::duplicateData($id, $id_new);
|
||||
$this->redirect_after = self::$currentIndex.'&token='.$this->token;
|
||||
$this->redirect();
|
||||
} else {
|
||||
Tools::displayError('Can not create new profile');
|
||||
}
|
||||
} else {
|
||||
Tools::displayError('Profile is not exist to duplicate');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
$this->initToolbar();
|
||||
$this->addRowAction('view');
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('duplicate');
|
||||
$this->addRowAction('delete');
|
||||
$this->context->controller->addCss(apPageHelper::getCssAdminDir().'admin/form.css');
|
||||
$tpl_name = 'list.tpl';
|
||||
$path = '';
|
||||
if (file_exists($this->theme_dir.'modules/'.$this->module->name.'/views/templates/admin/'.$tpl_name)) {
|
||||
$path = $this->theme_dir.'modules/'.$this->module->name.'/views/templates/admin/'.$tpl_name;
|
||||
} elseif (file_exists($this->getTemplatePath().$this->override_folder.$tpl_name)) {
|
||||
$path = $this->getTemplatePath().$this->override_folder.$tpl_name;
|
||||
}
|
||||
$model = new ApPageBuilderProfilesModel();
|
||||
$list_profiles = $model->getAllProfileByShop();
|
||||
// Build url for back from live edit page, it is stored in cookie and read in fontContent function below
|
||||
$controller = 'AdminApPageBuilderHome';
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
$url_edit_profile_token = Tools::getAdminTokenLite($controller);
|
||||
$params = array('token' => $url_edit_profile_token);
|
||||
$url_edit_profile = dirname($_SERVER['PHP_SELF']).'/'.Dispatcher::getInstance()->createUrl($controller, $id_lang, $params, false);
|
||||
$live_edit_params = array(
|
||||
'ap_live_edit' => true,
|
||||
'ad' => basename(_PS_ADMIN_DIR_),
|
||||
'liveToken' => Tools::getAdminTokenLite('AdminModulesPositions'),
|
||||
'id_employee' => (int)Context::getContext()->employee->id,
|
||||
'id_shop' => (int)Context::getContext()->shop->id
|
||||
);
|
||||
$url_live_edit = $this->getLiveEditUrl($live_edit_params);
|
||||
$lang = '';
|
||||
if (Configuration::get('PS_REWRITING_SETTINGS') && count(Language::getLanguages(true)) > 1) {
|
||||
$lang = Language::getIsoById($this->context->employee->id_lang).'/';
|
||||
}
|
||||
$url_preview = $this->context->shop->getBaseUrl().(Configuration::get('PS_REWRITING_SETTINGS') ? '' : 'index.php').$lang;
|
||||
$cookie = new Cookie('url_live_back');
|
||||
$cookie->setExpire(time() + 60 * 60);
|
||||
$cookie->variable_name = $url_edit_profile;
|
||||
$cookie->write();
|
||||
// Save token for check valid
|
||||
$cookie = new Cookie('ap_token'); //make your own cookie
|
||||
$cookie->setExpire(time() + 60 * 60);
|
||||
$cookie->variable_name = $live_edit_params['liveToken'];
|
||||
$cookie->write();
|
||||
|
||||
$profile_link = $this->context->link->getAdminLink('AdminApPageBuilderProfiles').'&addappagebuilder_profiles';
|
||||
$this->context->smarty->assign(array(
|
||||
'profile_link' => $profile_link,
|
||||
'url_preview' => $url_preview,
|
||||
'list_profile' => $list_profiles,
|
||||
'use_mobile_theme' => $this->module->getConfig('USE_MOBILE_THEME'),
|
||||
'url_live_edit' => $url_live_edit,
|
||||
'url_profile_detail' => $this->context->link->getAdminLink('AdminApPageBuilderProfiles'),
|
||||
'url_edit_profile_token' => $url_edit_profile_token,
|
||||
'url_edit_profile' => $url_edit_profile));
|
||||
$content = $this->context->smarty->fetch($path);
|
||||
$path_guide = $this->getTemplatePath().'guide.tpl';
|
||||
$guide_box = ApPageSetting::buildGuide($this->context, $path_guide, 0);
|
||||
return $guide_box.parent::renderList().$content;
|
||||
//return parent::renderList();
|
||||
}
|
||||
|
||||
public function getLiveEditUrl($live_edit_params)
|
||||
{
|
||||
$lang = '';
|
||||
$admin_dir = dirname($_SERVER['PHP_SELF']);
|
||||
$admin_dir = Tools::substr($admin_dir, strrpos($admin_dir, '/') + 1);
|
||||
$dir = str_replace($admin_dir, '', dirname($_SERVER['SCRIPT_NAME']));
|
||||
if (Configuration::get('PS_REWRITING_SETTINGS') && count(Language::getLanguages(true)) > 1) {
|
||||
$lang = Language::getIsoById(Context::getContext()->employee->id_lang).'/';
|
||||
}
|
||||
$url = Tools::getCurrentUrlProtocolPrefix().Tools::getHttpHost().$dir.$lang.
|
||||
Dispatcher::getInstance()->createUrl('index', (int)Context::getContext()->language->id, $live_edit_params);
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$this->initToolbar();
|
||||
$this->context->controller->addJqueryUI('ui.sortable');
|
||||
$groups = Group::getGroups($this->default_form_language, true);
|
||||
// UNSET GROUP_BOX
|
||||
if ($this->object->id == '') {
|
||||
$model = new ApPageBuilderProfilesModel();
|
||||
$list_profiles = $model->getAllProfileByShop();
|
||||
foreach ($list_profiles as $profile) {
|
||||
$group_boxs = $profile['group_box'];
|
||||
$aray_group_box = explode(',', $group_boxs);
|
||||
foreach ($aray_group_box as $group_box) {
|
||||
if ($group_box!=1&&$group_box!=2&&$group_box!=3) {
|
||||
while ($group = current($groups)) {
|
||||
if ($group['id_group'] == $group_box) {
|
||||
unset($groups[key($groups)]);
|
||||
}
|
||||
next($groups);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Ap Profile Manage'),
|
||||
'icon' => 'icon-folder-close'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name'),
|
||||
'name' => 'name',
|
||||
'required' => true,
|
||||
'hint' => $this->l('Invalid characters:'),' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Friendly URL'),
|
||||
'name' => 'friendly_url',
|
||||
'lang' => true,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
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' => '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."')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Profile Key'),
|
||||
'name' => 'profile_key',
|
||||
'readonly' => 'readonly',
|
||||
'desc' => $this->l('Use it to save as file name of css and js of profile'),
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'group',
|
||||
'label' => $this->l('Apply default profile for these groups'),
|
||||
'name' => 'groupBox',
|
||||
'values' => $groups,
|
||||
'col' => '6',
|
||||
'hint' => $this->l('Select the groups that you would like to apply this profile is default.')
|
||||
),
|
||||
array(
|
||||
'type' => 'html',
|
||||
'name' => 'dump_name',
|
||||
'html_content' => '<div class="alert alert-info">'.$this->l('Fullwidth Function: is only for develop')
|
||||
.'<br/>'.$this->l('To use this function, you have to download')
|
||||
.'<br/><a href="http://demothemes.info/prestashop/appagebuilder/header.tpl.zip" title="'.$this->l('Header file').'">'
|
||||
.'<b>header.tpl</b></a>'
|
||||
.'<br/><a href="http://demothemes.info/prestashop/appagebuilder/footer.tpl.zip" title="'.$this->l('Footer file').'">'
|
||||
.'<b>footer.tpl</b></a><br/>'
|
||||
.$this->l('file and compare or override in themes folder').'</div>'
|
||||
),
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'fullwidth_index_hook',
|
||||
'label' => $this->l('Fullwidth Homepage'),
|
||||
'class' => 'checkbox-group',
|
||||
'desc' => $this->l('The setting full-width for above HOOKS, apply for Home page'),
|
||||
'values' => array(
|
||||
'query' => self::getCheckboxIndexHook(),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'fullwidth_other_hook',
|
||||
'label' => $this->l('Fullwidth other Pages'),
|
||||
'class' => 'checkbox-group',
|
||||
'desc' => $this->l('The setting full-width for above HOOKS, apply for all OTHER pages ( not Home page )'),
|
||||
'values' => array(
|
||||
'query' => self::getCheckboxOtherHook(),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'disable_cache_hook',
|
||||
'label' => $this->l('Disable cache Hooks'),
|
||||
'class' => 'checkbox-group',
|
||||
'desc' => $this->l('Some modules always update data, disable cache for those modules show correct info.'),
|
||||
'values' => array(
|
||||
'query' => self::getCheckboxCacheHook(),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
//'label' => $this->l('Profile For Page'),
|
||||
'name' => 'page',
|
||||
'class' => 'hide',
|
||||
'options' => array(
|
||||
'query' => array(
|
||||
array(
|
||||
'id' => 'index',
|
||||
'name' => $this->l('Index'),
|
||||
),
|
||||
array(
|
||||
'id' => 'product_detail',
|
||||
'name' => $this->l('Product Detail'),
|
||||
)
|
||||
),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
),
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
),
|
||||
'buttons' => array(
|
||||
'save-and-stay' => array(
|
||||
'title' => $this->l('Save and Stay'),
|
||||
'name' => 'submitAdd'.$this->table.'AndStay',
|
||||
'type' => 'submit',
|
||||
'class' => 'btn btn-default pull-right',
|
||||
'icon' => 'process-icon-save'
|
||||
)
|
||||
)
|
||||
);
|
||||
$is_edit = Tools::getValue('id_appagebuilder_profiles');
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Custom Css'),
|
||||
'name' => 'css',
|
||||
'desc' => sprintf($this->l('Please set write Permission for folder %s'), $this->profile_css_folder),
|
||||
);
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Custom Js'),
|
||||
'name' => 'js',
|
||||
'desc' => sprintf($this->l('Please set write Permission for folder %s'), $this->profile_js_folder),
|
||||
);
|
||||
// Display link view if it existed
|
||||
if ($is_edit) {
|
||||
$profile_link = $this->context->link->getAdminLink('AdminApPageBuilderHome').'&id_appagebuilder_profiles='.$is_edit;
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'html',
|
||||
'name' => 'default_html',
|
||||
'name' => 'dess',
|
||||
'html_content' => '<a class="btn btn-info" href="'.$profile_link.'">
|
||||
<i class="icon icon-table"></i> '.$this->l('View and edit use mode Layout design').' >></a>'
|
||||
);
|
||||
}
|
||||
|
||||
$default_index_hook = $this->getDefaultIndexHook();
|
||||
$default_other_hook = $this->getDefaultOtherHook();
|
||||
$default_disable_cache_hook = $this->getDefaultDisableCacheHook();
|
||||
foreach ($default_index_hook as $key => $value) {
|
||||
$this->fields_value['fullwidth_index_hook_'.$key] = $value;
|
||||
}
|
||||
foreach ($default_other_hook as $key => $value) {
|
||||
$this->fields_value['fullwidth_other_hook_'.$key] = $value;
|
||||
}
|
||||
foreach ($default_disable_cache_hook as $key => $value) {
|
||||
$this->fields_value['disable_cache_hook_'.$key] = $value;
|
||||
}
|
||||
foreach ($groups as $group) {
|
||||
$this->fields_value['groupBox_'.$group['id_group']] = Tools::getValue('groupBox_'.$group['id_group'], in_array($group['id_group'], explode(',', $this->object->group_box)));
|
||||
}
|
||||
|
||||
$path_guide = $this->getTemplatePath().'guide.tpl';
|
||||
$guide_box = ApPageSetting::buildGuide($this->context, $path_guide, 2);
|
||||
return $guide_box.parent::renderForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read file css + js to form when add/edit
|
||||
*/
|
||||
public function getFieldsValue($obj)
|
||||
{
|
||||
$file_value = parent::getFieldsValue($obj);
|
||||
if ($obj->id && $obj->profile_key) {
|
||||
$file_value['css'] = Tools::file_get_contents($this->profile_css_folder.$obj->profile_key.'.css');
|
||||
$file_value['js'] = Tools::file_get_contents($this->profile_js_folder.$obj->profile_key.'.js');
|
||||
} else {
|
||||
$file_value['profile_key'] = 'profile'.ApPageSetting::getRandomNumber();
|
||||
}
|
||||
return $file_value;
|
||||
}
|
||||
|
||||
public function processAdd()
|
||||
{
|
||||
parent::validateRules();
|
||||
if (count($this->errors)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->object = parent::processAdd()) {
|
||||
$this->saveCustomJsAndCss($this->object->profile_key, '');
|
||||
}
|
||||
$this->processParams();
|
||||
if (!Tools::isSubmit('submitAdd'.$this->table.'AndStay')) {
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderHome');
|
||||
$this->redirect_after .= '&id_appagebuilder_profiles='.($this->object->id);
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
public function processUpdate()
|
||||
{
|
||||
parent::validateRules();
|
||||
if (count($this->errors)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->object = parent::processUpdate()) {
|
||||
$this->saveCustomJsAndCss($this->object->profile_key, $this->object->profile_key);
|
||||
}
|
||||
|
||||
$this->processParams();
|
||||
if (!Tools::isSubmit('submitAdd'.$this->table.'AndStay')) {
|
||||
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminApPageBuilderHome');
|
||||
$this->redirect_after .= '&id_appagebuilder_profiles='.($this->object->id);
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fullwidth hook, save to params
|
||||
*/
|
||||
public function processParams()
|
||||
{
|
||||
$params = Tools::jsonDecode($this->object->params);
|
||||
if ($params === null) {
|
||||
$params = new stdClass();
|
||||
}
|
||||
|
||||
# get post index hook
|
||||
$index_hook = ApPageSetting::getIndexHook();
|
||||
$post_index_hooks = array();
|
||||
foreach ($index_hook as $key => $value) {
|
||||
// validate module
|
||||
$post_index_hooks[$value] = Tools::getValue('fullwidth_index_hook_'.$value) ?
|
||||
Tools::getValue('fullwidth_index_hook_'.$value) : ApPageSetting::HOOK_BOXED;
|
||||
// validate module
|
||||
unset($key);
|
||||
}
|
||||
$params->fullwidth_index_hook = $post_index_hooks;
|
||||
|
||||
# get post other hook
|
||||
$other_hook = ApPageSetting::getOtherHook();
|
||||
$post_other_hooks = array();
|
||||
foreach ($other_hook as $key => $value) {
|
||||
// validate module
|
||||
$post_other_hooks[$value] = Tools::getValue('fullwidth_other_hook_'.$value) ? Tools::getValue('fullwidth_other_hook_'.$value) : ApPageSetting::HOOK_BOXED;
|
||||
// validate module
|
||||
unset($key);
|
||||
}
|
||||
$params->fullwidth_other_hook = $post_other_hooks;
|
||||
|
||||
# get post disable hook
|
||||
$cache_hooks = ApPageSetting::getCacheHook();
|
||||
$post_disable_hooks = array();
|
||||
foreach ($cache_hooks as $key => $value) {
|
||||
// validate module
|
||||
$post_disable_hooks[$value] = Tools::getValue('disable_cache_hook_'.$value) ? Tools::getValue('disable_cache_hook_'.$value) : ApPageSetting::HOOK_BOXED;
|
||||
// validate module
|
||||
unset($key);
|
||||
}
|
||||
$params->disable_cache_hook = $post_disable_hooks;
|
||||
|
||||
|
||||
# Save to params
|
||||
$this->object->params = Tools::jsonEncode($params);
|
||||
|
||||
# Save group_box
|
||||
if (Tools::getValue('groupBox')) {
|
||||
$this->object->group_box = implode(',', Tools::getValue('groupBox'));
|
||||
} else {
|
||||
$this->object->group_box = '';
|
||||
}
|
||||
|
||||
$this->object->save();
|
||||
}
|
||||
|
||||
public function saveCustomJsAndCss($key, $old_key = '')
|
||||
{
|
||||
# DELETE OLD FILE
|
||||
if ($old_key) {
|
||||
Tools::deleteFile($this->profile_css_folder.$old_key.'.css');
|
||||
Tools::deleteFile($this->profile_js_folder.$old_key.'.js');
|
||||
}
|
||||
|
||||
if (Tools::getValue('js') != '') {
|
||||
ApPageSetting::writeFile($this->profile_js_folder, $key.'.js', Tools::getValue('js'));
|
||||
}
|
||||
|
||||
if (Tools::getValue('css') != '') {
|
||||
# FIX CUSTOMER CAN NOT TYPE "\"
|
||||
$temp = Tools::getAllValues();
|
||||
$css = $temp['css'];
|
||||
ApPageSetting::writeFile($this->profile_css_folder, $key.'.css', $css);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate form : create checkbox in admin form ( add/edit profile )
|
||||
*/
|
||||
public static function getCheckboxIndexHook()
|
||||
{
|
||||
$ids = ApPageSetting::getIndexHook();
|
||||
$names = ApPageSetting::getIndexHook();
|
||||
return apPageHelper::getArrayOptions($ids, $names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate form : create checkbox in admin form ( add/edit profile )
|
||||
*/
|
||||
public static function getCheckboxOtherHook()
|
||||
{
|
||||
$ids = ApPageSetting::getOtherHook();
|
||||
$names = ApPageSetting::getOtherHook();
|
||||
return apPageHelper::getArrayOptions($ids, $names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate form : create checkbox in admin form ( add/edit profile )
|
||||
*/
|
||||
public static function getCheckboxCacheHook()
|
||||
{
|
||||
$ids = ApPageSetting::getCacheHook();
|
||||
$names = ApPageSetting::getCacheHook();
|
||||
return apPageHelper::getArrayOptions($ids, $names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fullwidth hook from database or default
|
||||
*/
|
||||
public function getDefaultIndexHook()
|
||||
{
|
||||
$params = Tools::jsonDecode($this->object->params);
|
||||
return isset($params->fullwidth_index_hook) ? $params->fullwidth_index_hook : ApPageSetting::getIndexHook(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fullwidth hook from database or default
|
||||
*/
|
||||
public function getDefaultOtherHook()
|
||||
{
|
||||
$params = Tools::jsonDecode($this->object->params);
|
||||
return isset($params->fullwidth_other_hook) ? $params->fullwidth_other_hook : ApPageSetting::getOtherHook(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fullwidth hook from database or default
|
||||
*/
|
||||
public function getDefaultDisableCacheHook()
|
||||
{
|
||||
$params = Tools::jsonDecode($this->object->params);
|
||||
return isset($params->disable_cache_hook) ? $params->disable_cache_hook : ApPageSetting::getCacheHook(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
|
||||
if (count($this->errors) <= 0) {
|
||||
if (Tools::isSubmit('duplicate'.$this->table)) {
|
||||
if ($this->id_object) {
|
||||
if (!$this->access('add')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to duplicate this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,840 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(_PS_MODULE_DIR_.'appagebuilder/classes/ApPageBuilderShortcodeModel.php');
|
||||
|
||||
class AdminApPageBuilderShortcodeController extends ModuleAdminControllerCore
|
||||
{
|
||||
public $tpl_path;
|
||||
public $module_name;
|
||||
public static $shortcode_lang;
|
||||
public static $language;
|
||||
public $theme_dir;
|
||||
public static $lang_id;
|
||||
public $tpl_controller_path;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'appagebuilder_shortcode';
|
||||
$this->identifier = 'id_appagebuilder_shortcode';
|
||||
$this->className = 'ApPageBuilderShortcodeModel';
|
||||
$this->allow_export = true;
|
||||
$this->can_import = true;
|
||||
$id_shop = apPageHelper::getIDShop();
|
||||
$this->_join = '
|
||||
INNER JOIN `'._DB_PREFIX_.'appagebuilder_shortcode_shop` ps ON (ps.`id_appagebuilder_shortcode` = a.`id_appagebuilder_shortcode` AND ps.`id_shop` = '.$id_shop.')';
|
||||
$this->_select .= ' ps.active as active, ';
|
||||
$this->lang = true;
|
||||
$this->shop = true;
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('duplicate');
|
||||
$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_appagebuilder_shortcode' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'type' => 'text',
|
||||
'class' => 'fixed-width-sm'
|
||||
),
|
||||
'shortcode_name' => array(
|
||||
'title' => $this->l('Name'),
|
||||
'type' => 'text',
|
||||
),
|
||||
'shortcode_key' => array(
|
||||
'title' => $this->l('Key'),
|
||||
'type' => 'text',
|
||||
),
|
||||
'active' => array(
|
||||
'title' => $this->l('Status'),
|
||||
'active' => 'status',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-sm'
|
||||
),
|
||||
);
|
||||
|
||||
$this->_defaultOrderBy = 'id_appagebuilder_shortcode';
|
||||
$this->module_name = 'appagebuilder';
|
||||
$this->tpl_path = _PS_ROOT_DIR_.'/modules/'.$this->module_name.'/views/templates/admin';
|
||||
self::$language = Language::getLanguages(false);
|
||||
$this->theme_dir = apPageHelper::getConfigDir('_PS_THEME_DIR_');
|
||||
$this->tpl_controller_path = _PS_ROOT_DIR_.'/modules/'.$this->module_name.'/views/templates/admin/ap_page_builder_shortcode/';
|
||||
apPageHelper::loadShortCode(apPageHelper::getConfigDir('_PS_THEME_DIR_'));
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
//DONGND:: get list shortcode to tiny mce
|
||||
if (Tools::getIsset('get_listshortcode')) {
|
||||
die($this->module->getListShortCodeForEditor());
|
||||
} else {
|
||||
parent::initContent();
|
||||
}
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
parent::initToolbar();
|
||||
|
||||
# SAVE AND STAY
|
||||
if ($this->display == 'add' || $this->display == 'edit') {
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/function.js');
|
||||
|
||||
$this->page_header_toolbar_btn['SaveAndStay'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save and stay'),
|
||||
'js' => 'TopSaveAndStay()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSaveAndStay_Name' => 'submitAdd'.$this->table.'AndStay'));
|
||||
|
||||
$this->page_header_toolbar_btn['Save'] = array(
|
||||
'href' => 'javascript:void(0);',
|
||||
'desc' => $this->l('Save'),
|
||||
'js' => 'TopSave()',
|
||||
'icon' => 'process-icon-save',
|
||||
);
|
||||
Media::addJsDef(array('TopSave_Name' => 'submitAdd'.$this->table));
|
||||
}
|
||||
|
||||
# SHOW LINK EXPORT ALL FOR TOOLBAR
|
||||
switch ($this->display) {
|
||||
default:
|
||||
$this->toolbar_btn['new'] = array(
|
||||
'href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->l('Add new'),
|
||||
'class' => 'btn_add_new',
|
||||
);
|
||||
if (!$this->display && $this->can_import) {
|
||||
$this->toolbar_btn['import'] = array(
|
||||
'href' => self::$currentIndex . '&import' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->trans('Import', array(), 'Admin.Actions'),
|
||||
'class' => 'btn_xml_import',
|
||||
);
|
||||
}
|
||||
if ($this->allow_export) {
|
||||
$this->toolbar_btn['export'] = array(
|
||||
'href' => self::$currentIndex . '&export' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->l('Export'),
|
||||
'class' => 'btn_xml_export',
|
||||
);
|
||||
Media::addJsDef(array('record_id' => 'appagebuilder_shortcodeBox[]'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function processExport($text_delimiter = '"')
|
||||
{
|
||||
// $multilang = false;
|
||||
if (isset($this->className) && $this->className) {
|
||||
$definition = ObjectModel::getDefinition($this->className);
|
||||
// $multilang = $definition['multilang'];
|
||||
}
|
||||
|
||||
$record_id = Tools::getValue('record_id');
|
||||
$file_name = 'ap_shortcode_all.xml';
|
||||
# VALIDATE MODULE
|
||||
unset($text_delimiter);
|
||||
|
||||
if ($record_id) {
|
||||
$record_id_str = implode(", ", $record_id);
|
||||
$this->_where = ' AND a.'.$this->identifier.' IN ( '.pSQL($record_id_str).' )';
|
||||
$file_name = 'ap_shortcode.xml';
|
||||
}
|
||||
|
||||
$this->getList($this->context->language->id, null, null, 0, false);
|
||||
if (!count($this->_list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->_list;
|
||||
|
||||
$data_all = array();
|
||||
$this->_join_ori = $this->_join;
|
||||
$this->_select .= ' apl.id_appagebuilder, apl.params,';
|
||||
foreach (Language::getLanguages() as $key => $lang) {
|
||||
$this->_join = $this->_join_ori. '
|
||||
LEFT JOIN `'._DB_PREFIX_.'appagebuilder` ap ON (ap.id_appagebuilder_shortcode = a.id_appagebuilder_shortcode)
|
||||
LEFT JOIN `'._DB_PREFIX_.'appagebuilder_lang` apl ON (ap.id_appagebuilder = apl.id_appagebuilder AND apl.id_lang = '.$lang['id_lang'].' )
|
||||
';
|
||||
$this->getList($lang['id_lang'], null, null, 0, false);
|
||||
$data_all[$lang['iso_code']] = $this->_list;
|
||||
}
|
||||
|
||||
$this->file_content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
$this->file_content .= '<data>' . "\n";
|
||||
$this->file_content .= '<shortcode>' . "\n";
|
||||
$definition['fields']['params'] = array('lang' => '1');
|
||||
if ($data) {
|
||||
foreach ($data as $key_data => $product_detail) {
|
||||
$this->file_content .= '<record>' . "\n";
|
||||
// add more field
|
||||
$product_detail['params'] = '';
|
||||
foreach ($product_detail as $key => $value) {
|
||||
if (isset($definition['fields'][$key]['lang']) && $definition['fields'][$key]['lang']) {
|
||||
# MULTI LANG
|
||||
$this->file_content .= ' <'.$key.'>'. "\n";
|
||||
foreach (Language::getLanguages() as $key_lang => $lang) {
|
||||
unset($key_lang);
|
||||
$this->file_content .= ' <'.$lang['iso_code'].'>';
|
||||
$this->file_content .= '<![CDATA['.$data_all[$lang['iso_code']][$key_data][$key].']]>';
|
||||
$this->file_content .= '</'.$lang['iso_code'].'>' . "\n";
|
||||
}
|
||||
$this->file_content .= ' </'.$key.'>' . "\n";
|
||||
} else {
|
||||
# SINGLE LANG
|
||||
$this->file_content .= ' <'.$key.'>';
|
||||
$this->file_content .= '<![CDATA['.$value.']]>';
|
||||
$this->file_content .= '</'.$key.'>' . "\n";
|
||||
}
|
||||
}
|
||||
$this->file_content .= '</record>' . "\n";
|
||||
}
|
||||
}
|
||||
$this->file_content .= '</shortcode>' . "\n";
|
||||
$this->file_content .= '</data>' . "\n";
|
||||
header('Content-type: text/xml');
|
||||
header('Content-Disposition: attachment; filename="'.$file_name.'"');
|
||||
echo $this->file_content;
|
||||
die();
|
||||
}
|
||||
|
||||
public function processImport()
|
||||
{
|
||||
$upload_file = new Uploader('importFile');
|
||||
$upload_file->setAcceptTypes(array('xml'));
|
||||
$file = $upload_file->process();
|
||||
$file = $file[0];
|
||||
if (!isset($file['save_path'])) {
|
||||
$this->errors[] = $this->trans('Failed to import.', array(), 'Admin.Notifications.Error');
|
||||
return;
|
||||
}
|
||||
$files_content = simplexml_load_file($file['save_path']);
|
||||
$override = Tools::getValue('override');
|
||||
|
||||
if (isset($files_content->shortcode) && $files_content->shortcode) {
|
||||
foreach ($files_content->shortcode->children() as $product_details) {
|
||||
if (!$override) {
|
||||
$obj_model = new ApPageBuilderShortcodeModel();
|
||||
$obj_model->shortcode_key = $product_details->shortcode_key->__toString();
|
||||
$obj_model->active = $product_details->active->__toString();
|
||||
$name = array();
|
||||
foreach (Language::getLanguages() as $key_lang => $lang) {
|
||||
unset($key_lang);
|
||||
$name[$lang['id_lang']] = $product_details->shortcode_name->{$lang['iso_code']}->__toString();
|
||||
}
|
||||
$obj_model->shortcode_name = $name;
|
||||
$obj_model->save();
|
||||
|
||||
|
||||
$ap_model = new ApPageBuilderModel();
|
||||
$ap_model->hook_name = 'apshortcode';
|
||||
$ap_model->id_appagebuilder_shortcode = $obj_model->id;
|
||||
foreach (Language::getLanguages() as $lang) {
|
||||
$ap_model->params[$lang['id_lang']] = $product_details->params->{$lang['iso_code']}->__toString();
|
||||
}
|
||||
$ap_model->save();
|
||||
}
|
||||
}
|
||||
$this->confirmations[] = $this->trans('Successful importing.', array(), 'Admin.Notifications.Success');
|
||||
} else {
|
||||
$this->errors[] = $this->trans('Wrong file to import.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
|
||||
public function renderList()
|
||||
{
|
||||
return $this->importForm() . parent::renderList();
|
||||
}
|
||||
|
||||
public function importForm()
|
||||
{
|
||||
$helper = new HelperForm();
|
||||
$helper->submit_action = 'import' . $this->table;
|
||||
$inputs = array(
|
||||
array(
|
||||
'type' => 'file',
|
||||
'name' => 'importFile',
|
||||
'label' => $this->l('File'),
|
||||
'desc' => $this->l('Only accept xml file'),
|
||||
),
|
||||
);
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'action' => Context::getContext()->link->getAdminLink('AdminApPageBuilderShortcodeController'),
|
||||
'input' => $inputs,
|
||||
'submit' => array('title' => $this->l('Import'), 'class' => 'button btn btn-success'),
|
||||
'tinymce' => false,
|
||||
),
|
||||
);
|
||||
$helper->fields_value = isset($this->fields_value) ? $this->fields_value : array();
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->currentIndex = self::$currentIndex;
|
||||
$helper->token = $this->token;
|
||||
$helper->table = 'xml_import';
|
||||
$html = $helper->generateForm(array($fields_form));
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
|
||||
$txt_legend = '';
|
||||
if (Validate::isLoadedObject($this->object)) {
|
||||
$this->display = 'edit';
|
||||
$txt_legend = $this->l('Edit Shortcode');
|
||||
} else {
|
||||
$this->display = 'add';
|
||||
$txt_legend = $this->l('Add New Shortcode');
|
||||
}
|
||||
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $txt_legend,
|
||||
'icon' => 'icon-cogs',
|
||||
),
|
||||
'input' => array(
|
||||
// array(
|
||||
// 'type' => 'hidden',
|
||||
// 'name' => 'id_appagebuilder_shortcode',
|
||||
// ),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_appagebuilder',
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'shortcode_content',
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'stay_page',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'label' => $this->l('Shortcode Name'),
|
||||
'name' => 'shortcode_name',
|
||||
),
|
||||
array(
|
||||
'type' => 'textbutton',
|
||||
'label' => $this->l('Shortcode Key'),
|
||||
'name' => 'shortcode_key',
|
||||
'readonly' => 'readonly',
|
||||
'lang' => false,
|
||||
'button' => array(
|
||||
'label' => $this->l('Copy To Clipboard'),
|
||||
'class' => 'bt_copy_clipboard shortcode_key',
|
||||
'attributes' => array(
|
||||
// 'onclick' => 'alert(\'something done\');'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'is_bool' => true, //retro compat 1.5
|
||||
'label' => $this->l('Active'),
|
||||
'name' => 'active',
|
||||
'default_value' => 1,
|
||||
'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' => 'shortcode_save_btn btn btn-default pull-right',
|
||||
),
|
||||
'buttons' => array(
|
||||
'save_and_stay' => array(
|
||||
'title' => $this->l('Save and stay'),
|
||||
'name' => 'submitAdd'.$this->table.'AndStay',
|
||||
'type' => 'submit',
|
||||
'class' => 'shortcode_save_stay_btn btn btn-default pull-right',
|
||||
'icon' => 'process-icon-save-and-stay'
|
||||
)
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
if (Validate::isLoadedObject($this->object)) {
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'textbutton',
|
||||
'label' => $this->l('Embed Hook'),
|
||||
'name' => 'shortcode_embedded_hook',
|
||||
'readonly' => 'readonly',
|
||||
'desc' => $this->l('Insert embed hook in any tpl file'),
|
||||
'lang' => false,
|
||||
'button' => array(
|
||||
'label' => $this->l('Copy To Clipboard'),
|
||||
'class' => 'bt_copy_clipboard shortcode_embedded_hook',
|
||||
'attributes' => array(
|
||||
// 'onclick' => 'alert(\'something done\');'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'textbutton',
|
||||
'label' => $this->l('Embed Code'),
|
||||
'name' => 'shortcode_embedded_code',
|
||||
'readonly' => 'readonly',
|
||||
'desc' => $this->l('Insert embed code in any content with editor'),
|
||||
'lang' => false,
|
||||
'button' => array(
|
||||
'label' => $this->l('Copy To Clipboard'),
|
||||
'class' => 'bt_copy_clipboard shortcode_embedded_code',
|
||||
'attributes' => array(
|
||||
// 'onclick' => 'alert(\'something done\');'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->context->controller->addJqueryUI('ui.sortable');
|
||||
$this->context->controller->addJqueryUI('ui.draggable');
|
||||
$this->context->controller->addCss(apPageHelper::getCssAdminDir().'admin/form.css');
|
||||
$this->context->controller->addCss(apPageHelper::getCssAdminDir().'animate.css');
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/form.js');
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/home.js?t=1');
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/isotope.pkgd.min.js');
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
|
||||
|
||||
$this->context->controller->addJs(apPageHelper::getJsAdminDir().'admin/jquery-validation-1.9.0/jquery.validate.js');
|
||||
$this->context->controller->addCss(apPageHelper::getJsAdminDir().'admin/jquery-validation-1.9.0/screen.css');
|
||||
|
||||
// $version = Configuration::get('PS_INSTALL_VERSION');
|
||||
// $tiny_path = ($version >= '1.6.0.13') ? 'admin/' : '';
|
||||
// $tiny_path .= 'tinymce.inc.js';
|
||||
|
||||
// Pham_Khanh_Dong fix loading TINY_MCE library for all Prestashop_Versions
|
||||
$tiny_path = 'tinymce.inc.js';
|
||||
if (version_compare(_PS_VERSION_, '1.6.0.13', '>')) {
|
||||
$tiny_path = 'admin/tinymce.inc.js';
|
||||
}
|
||||
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.$tiny_path);
|
||||
$bo_theme = ((Validate::isLoadedObject($this->context->employee) && $this->context->employee->bo_theme) ? $this->context->employee->bo_theme : 'default');
|
||||
if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR.'template')) {
|
||||
$bo_theme = 'default';
|
||||
}
|
||||
$this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload.js');
|
||||
$this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js');
|
||||
$this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js');
|
||||
$this->context->controller->addJs(_PS_JS_DIR_.'vendor/spin.js');
|
||||
$this->context->controller->addJs(_PS_JS_DIR_.'vendor/ladda.js');
|
||||
|
||||
//load javascript for menu tree
|
||||
$tree = new HelperTreeCategories('123', null);
|
||||
$tree->render();
|
||||
|
||||
// if (isset($result_profile) && $result_profile) {
|
||||
|
||||
$languages = array();
|
||||
foreach (Language::getLanguages(false) as $lang) {
|
||||
$languages[$lang['iso_code']] = $lang['id_lang'];
|
||||
}
|
||||
|
||||
// get shortcode information
|
||||
$shortcode_infos = ApShortCodeBase::getShortCodeInfos();
|
||||
//include all short code default
|
||||
$shortcodes = Tools::scandir($this->tpl_path.'/ap_page_builder_shortcodes', 'tpl');
|
||||
$shortcode_form = array();
|
||||
foreach ($shortcodes as $s_from) {
|
||||
if ($s_from == 'shortcodelist.tpl') {
|
||||
continue;
|
||||
}
|
||||
$shortcode_form[] = $this->tpl_path.'/ap_page_builder_shortcodes/'.$s_from;
|
||||
};
|
||||
$tpl = $this->createTemplate('home.tpl');
|
||||
|
||||
$model = new ApPageBuilderShortcodeModel();
|
||||
|
||||
$data_shortcode_content = array();
|
||||
$positions_dum = array();
|
||||
|
||||
$data_form = '{}';
|
||||
|
||||
$id_appagebuilder = ApPageBuilderModel::getIdByIdShortCode($this->object->id);
|
||||
|
||||
if ($id_appagebuilder) {
|
||||
$positions_dum = $model->getShortCodeContent($id_appagebuilder, null);
|
||||
$temp = $positions_dum['content'];
|
||||
|
||||
foreach ($temp as $key_hook => &$row) {
|
||||
if (!is_array($row)) {
|
||||
$row = array('hook_name' => $key_hook, 'content' => '');
|
||||
}
|
||||
if ($key_hook == 'displayLeftColumn' || $key_hook == 'displayRightColumn') {
|
||||
$row['class'] = 'col-md-3';
|
||||
} else {
|
||||
$row['class'] = 'col-md-12';
|
||||
}
|
||||
}
|
||||
$data_shortcode_content = $temp;
|
||||
$data = $model->getAllItems($id_appagebuilder, null, (int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
$data_form = Tools::jsonEncode($data['dataForm']);
|
||||
}
|
||||
|
||||
$tpl->assign(array(
|
||||
'data_shortcode_content' => $data_shortcode_content,
|
||||
// 'positions' => $positions,
|
||||
// 'listPositions' => $list_positions,
|
||||
// 'dataByHook' => $data_by_hook,
|
||||
// 'exportItems' => $export_items,
|
||||
// 'currentProfile' => $result_profile,
|
||||
// 'currentPosition' => $current_position,
|
||||
// 'profilesList' => $this->getAllProfiles($result_profile['id_appagebuilder_profiles']),
|
||||
'tplPath' => $this->tpl_path,
|
||||
'ajaxShortCodeUrl' => Context::getContext()->link->getAdminLink('AdminApPageBuilderShortcodes'),
|
||||
'ajaxHomeUrl' => Context::getContext()->link->getAdminLink('AdminApPageBuilderHome'),
|
||||
'shortcodeForm' => $shortcode_form,
|
||||
'moduleDir' => _MODULE_DIR_,
|
||||
'imgModuleLink' => apPageHelper::getImgThemeUrl(),
|
||||
'shortcodeInfos' => Tools::jsonEncode($shortcode_infos),
|
||||
'languages' => Tools::jsonEncode($languages),
|
||||
'dataForm' => $data_form,
|
||||
// 'errorText' => $this->error_text,
|
||||
'imgController' => Context::getContext()->link->getAdminLink('AdminApPageBuilderImages'),
|
||||
'widthList' => ApPageSetting::returnWidthList(),
|
||||
'lang_id' => (int)$this->context->language->id,
|
||||
// 'idProfile' => '',
|
||||
// 'checkSaveMultithreading' => $check_save_multithreading,
|
||||
// 'checkSaveSubmit' => $check_save_submit,
|
||||
// 'errorSubmit' => $errorSubmit
|
||||
'listAnimation' => ApPageSetting::getAnimationsColumnGroup(),
|
||||
));
|
||||
// return $guide_box.$tpl->fetch();
|
||||
// } else {
|
||||
// $this->errors[] = $this->l('Your Profile ID is not exist!');
|
||||
// }
|
||||
|
||||
return parent::renderForm().$tpl->fetch();
|
||||
}
|
||||
|
||||
public function getFieldsValue($obj)
|
||||
{
|
||||
$file_value = parent::getFieldsValue($obj);
|
||||
|
||||
if ($file_value['shortcode_key'] == '') {
|
||||
$file_value['shortcode_key'] = 'sc'.ApPageSetting::getRandomNumber();
|
||||
} else {
|
||||
$file_value['shortcode_embedded_hook'] = "{hook h='displayApSC' sc_key=".$file_value['shortcode_key']."}";
|
||||
$file_value['shortcode_embedded_code'] = "[ApSC sc_key=".$file_value['shortcode_key']."][/ApSC]";
|
||||
}
|
||||
|
||||
return $file_value;
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (count($this->errors) > 0) {
|
||||
return;
|
||||
}
|
||||
if (Tools::isSubmit('submitAddappagebuilder_shortcode')) {
|
||||
parent::validateRules();
|
||||
|
||||
if ((int) Tools::getValue('id_appagebuilder_shortcode')) {
|
||||
$mess_id = '4';
|
||||
} else {
|
||||
$mess_id = '3';
|
||||
}
|
||||
|
||||
$shortcode_obj = new ApPageBuilderShortcodeModel((int) Tools::getValue('id_appagebuilder_shortcode'));
|
||||
$shortcode_obj->shortcode_key = Tools::getValue('shortcode_key');
|
||||
$shortcode_obj->active = Tools::getValue('active');
|
||||
|
||||
//DONGND:: fields multi lang
|
||||
$languages = Language::getLanguages();
|
||||
$name = array();
|
||||
foreach ($languages as $key => $value) {
|
||||
$name[$value['id_lang']] = Tools::getValue('shortcode_name_'.$value['id_lang']);
|
||||
}
|
||||
$shortcode_obj->shortcode_name = $name;
|
||||
|
||||
$shortcode_obj->save();
|
||||
|
||||
$shortcode_content = Tools::jsonDecode(Tools::getValue('shortcode_content'), 1);
|
||||
|
||||
$id_appagebuilder = ApPageBuilderModel::getIdByIdShortCode($shortcode_obj->id);
|
||||
if ($id_appagebuilder) {
|
||||
$obj_model = new ApPageBuilderModel($id_appagebuilder);
|
||||
} else {
|
||||
$obj_model = new ApPageBuilderModel();
|
||||
}
|
||||
|
||||
$obj_model->hook_name = 'apshortcode';
|
||||
$obj_model->id_appagebuilder_shortcode = $shortcode_obj->id;
|
||||
|
||||
if (isset($shortcode_content['groups'])) {
|
||||
foreach (self::$language as $lang) {
|
||||
$params = '';
|
||||
if (self::$shortcode_lang) {
|
||||
foreach (self::$shortcode_lang as &$s_type) {
|
||||
foreach ($s_type as $key => $value) {
|
||||
$s_type[$key] = $key.'_'.$lang['id_lang'];
|
||||
// validate module
|
||||
unset($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$obj_model->params[$lang['id_lang']] = '';
|
||||
ApShortCodesBuilder::$lang_id = $lang['id_lang'];
|
||||
foreach ($shortcode_content['groups'] as $groups) {
|
||||
$params = $this->getParamByHook($groups, $params, '');
|
||||
}
|
||||
$obj_model->params[$lang['id_lang']] = $params;
|
||||
}
|
||||
}
|
||||
|
||||
if ($obj_model->id) {
|
||||
$obj_model->save();
|
||||
} else {
|
||||
$obj_model->add();
|
||||
}
|
||||
|
||||
if ($shortcode_obj->save()) {
|
||||
$this->module->clearShortCodeCache($shortcode_obj->shortcode_key);
|
||||
|
||||
if (Tools::getValue('stay_page')) {
|
||||
# validate module
|
||||
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$shortcode_obj->id.'&conf='.$mess_id.'&update'.$this->table.'&token='.$this->token;
|
||||
} else {
|
||||
# validate module
|
||||
$this->redirect_after = self::$currentIndex.'&conf=4&token='.$this->token;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (Tools::getIsset('duplicateappagebuilder_shortcode')) {
|
||||
//DONGND:: duplicate
|
||||
if (Tools::getIsset('id_appagebuilder_shortcode') && (int)Tools::getValue('id_appagebuilder_shortcode')) {
|
||||
if ($shortcode_obj = new ApPageBuilderShortcodeModel((int) Tools::getValue('id_appagebuilder_shortcode'))) {
|
||||
$duplicate_object = new ApPageBuilderShortcodeModel();
|
||||
$duplicate_object->active = $shortcode_obj->active;
|
||||
|
||||
$languages = Language::getLanguages();
|
||||
$name = array();
|
||||
foreach ($languages as $key => $value) {
|
||||
$name[$value['id_lang']] = $this->l('Duplicate of').' '.$shortcode_obj->shortcode_name[$value['id_lang']];
|
||||
}
|
||||
|
||||
$duplicate_object->shortcode_name = $name;
|
||||
$duplicate_object->shortcode_key = 'sc'.ApPageSetting::getRandomNumber();
|
||||
|
||||
if ($duplicate_object->add()) {
|
||||
//duplicate shortCode
|
||||
$id_appagebuilder = ApPageBuilderModel::getIdByIdShortCode($shortcode_obj->id);
|
||||
if ($id_appagebuilder) {
|
||||
$obj_model = new ApPageBuilderModel($id_appagebuilder);
|
||||
$duplicate_obj_object = new ApPageBuilderModel();
|
||||
$duplicate_obj_object->hook_name = 'apshortcode';
|
||||
$duplicate_obj_object->id_appagebuilder_shortcode = $duplicate_object->id;
|
||||
$duplicate_obj_object->params = $obj_model->params;
|
||||
$duplicate_obj_object->add();
|
||||
|
||||
$this->redirect_after = self::$currentIndex.'&conf=3&token='.$this->token;
|
||||
} else {
|
||||
$this->redirect_after = self::$currentIndex.'&conf=3&token='.$this->token;
|
||||
}
|
||||
} else {
|
||||
Tools::displayError('Can not duplicate shortcode');
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (Tools::getIsset('statusappagebuilder_shortcode') || Tools::getIsset('deleteappagebuilder_shortcode')) {
|
||||
$shortcode_obj = new ApPageBuilderShortcodeModel((int) Tools::getValue('id_appagebuilder_shortcode'));
|
||||
$this->module->clearShortCodeCache($shortcode_obj->shortcode_key);
|
||||
}
|
||||
parent::postProcess();
|
||||
}
|
||||
}
|
||||
|
||||
private function getParamByHook($groups, $params, $hook, $action = 'save')
|
||||
{
|
||||
$groups['params']['specific_type'] = (isset($groups['params']['specific_type']) && $groups['params']['specific_type']) ? $groups['params']['specific_type'] : '';
|
||||
$groups['params']['controller_pages'] = (isset($groups['params']['controller_pages']) && $groups['params']['controller_pages']) ? $groups['params']['controller_pages'] : '';
|
||||
$groups['params']['controller_id'] = (isset($groups['params']['controller_id']) && $groups['params']['controller_id']) ? $groups['params']['controller_id'] : '';
|
||||
$params .= '[ApRow'.ApShortCodesBuilder::converParamToAttr2($groups['params'], 'ApRow', $this->theme_dir).']';
|
||||
//check exception page
|
||||
$this->saveExceptionConfig($hook, $groups['params']['specific_type'], $groups['params']['controller_pages'], $groups['params']['controller_id']);
|
||||
foreach ($groups['columns'] as $columns) {
|
||||
$columns['params']['specific_type'] = (isset($columns['params']['specific_type']) && $columns['params']['specific_type']) ? $columns['params']['specific_type'] : '';
|
||||
$columns['params']['controller_pages'] = (isset($columns['params']['controller_pages']) && $columns['params']['controller_pages']) ? $columns['params']['controller_pages'] : '';
|
||||
$columns['params']['controller_id'] = (isset($columns['params']['controller_id']) && $columns['params']['controller_id']) ? $columns['params']['controller_id'] : '';
|
||||
$this->saveExceptionConfig($hook, $columns['params']['specific_type'], $columns['params']['controller_pages'], $columns['params']['controller_id']);
|
||||
$params .= '[ApColumn'.ApShortCodesBuilder::converParamToAttr2($columns['params'], 'ApColumn', $this->theme_dir).']';
|
||||
foreach ($columns['widgets'] as $widgets) {
|
||||
if ($widgets['type'] == 'ApTabs' || $widgets['type'] == 'ApAjaxTabs' || $widgets['type'] == 'ApAccordions') {
|
||||
$params .= '['.$widgets['type'].ApShortCodesBuilder::converParamToAttr2($widgets['params'], $widgets['type'], $this->theme_dir).']';
|
||||
foreach ($widgets['widgets'] as $sub_widgets) {
|
||||
$type_sub = Tools::substr($widgets['type'], 0, -1);
|
||||
$params .= '['.$type_sub.ApShortCodesBuilder::converParamToAttr2($sub_widgets['params'], str_replace('_', '_sub_', $widgets['type']), $this->theme_dir).']';
|
||||
foreach ($sub_widgets['widgets'] as $sub_widget) {
|
||||
$params .= '['.$sub_widget['type']
|
||||
.ApShortCodesBuilder::converParamToAttr2($sub_widget['params'], $sub_widget['type'], $this->theme_dir).'][/'
|
||||
.$sub_widget['type'].']';
|
||||
}
|
||||
$params .= '[/'.$type_sub.']';
|
||||
}
|
||||
$params .= '[/'.$widgets['type'].']';
|
||||
} else {
|
||||
$params .= '['.$widgets['type'].ApShortCodesBuilder::converParamToAttr2($widgets['params'], $widgets['type'], $this->theme_dir).'][/'.$widgets['type'].']';
|
||||
if ($widgets['type'] == 'ApModule' && $action == 'save') {
|
||||
$is_delete = (int)$widgets['params']['is_display'];
|
||||
if ($is_delete) {
|
||||
if (!isset($widgets['params']['hook'])) {
|
||||
// FIX : Module not choose hook -> error
|
||||
$widgets['params']['hook'] = '';
|
||||
}
|
||||
$this->deleteModuleFromHook($widgets['params']['hook'], $widgets['params']['name_module']);
|
||||
}
|
||||
} else if ($widgets['type'] == 'ApProductCarousel') {
|
||||
if ($widgets['params']['order_way'] == 'random') {
|
||||
$this->config_module[$hook]['productCarousel']['order_way'] = 'random';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$params .= '[/ApColumn]';
|
||||
}
|
||||
$params .= '[/ApRow]';
|
||||
return $params;
|
||||
}
|
||||
|
||||
private function saveExceptionConfig($hook, $type, $page, $ids)
|
||||
{
|
||||
if (!$type) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($type == 'all') {
|
||||
if ($type != '') {
|
||||
$list = explode(',', $page);
|
||||
foreach ($list as $val) {
|
||||
$val = trim($val);
|
||||
if ($val && (!is_array($this->config_module) || !isset($this->config_module[$hook]) || !isset($this->config_module[$hook]['exception']) || !isset($val, $this->config_module[$hook]['exception']))) {
|
||||
$this->config_module[$hook]['exception'][] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->config_module[$hook][$type] = array();
|
||||
if ($type != 'index') {
|
||||
$ids = explode(',', $ids);
|
||||
foreach ($ids as $val) {
|
||||
$val = trim($val);
|
||||
if (!in_array($val, $this->config_module[$hook][$type])) {
|
||||
$this->config_module[$hook][$type][] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function adminContent($assign, $tpl_name)
|
||||
{
|
||||
if (file_exists($this->tpl_controller_path.$tpl_name)) {
|
||||
$tpl = $this->createTemplate($tpl_name);
|
||||
} else {
|
||||
$tpl = $this->createTemplate('ApGeneral.tpl');
|
||||
}
|
||||
$assign['moduleDir'] = _MODULE_DIR_;
|
||||
foreach ($assign as $key => $ass) {
|
||||
$tpl->assign(array($key => $ass));
|
||||
}
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
public function displayDuplicateLink($token = null, $id = null, $name = null)
|
||||
{
|
||||
$href = self::$currentIndex.'&'.$this->identifier.'='.$id.'&duplicate'.$this->table.'&token='.($token != null ? $token : $this->token);
|
||||
$html = '<a href="'.$href.'" title="Duplicate">
|
||||
<i class="icon-copy"></i> Duplicate
|
||||
</a>';
|
||||
|
||||
// validate module
|
||||
unset($name);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function access($action, $disable = false)
|
||||
{
|
||||
if (Tools::getIsset('update'.$this->table) && Tools::getIsset($this->identifier)) {
|
||||
// Allow person see "EDIT" form
|
||||
$action = 'view';
|
||||
}
|
||||
return parent::access($action, $disable);
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
# SET ACTION : IMPORT DATA
|
||||
if ($this->can_import && Tools::getIsset('import' . $this->table)) {
|
||||
if ($this->access('edit')) {
|
||||
$this->action = 'import';
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->errors) <= 0) {
|
||||
if (Tools::isSubmit('duplicate'.$this->table)) {
|
||||
if ($this->id_object) {
|
||||
if (!$this->access('add')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to duplicate this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
} elseif ($this->can_import && Tools::getIsset('import' . $this->table)) {
|
||||
if (!$this->access('edit')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to import data.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(_PS_MODULE_DIR_.'appagebuilder/classes/ApPageSetting.php');
|
||||
require_once(_PS_MODULE_DIR_.'appagebuilder/controllers/admin/AdminApPageBuilderPositions.php');
|
||||
|
||||
class AdminApPageBuilderShortcodesController extends ModuleAdminControllerCore
|
||||
{
|
||||
public static $shortcode_lang;
|
||||
public static $language;
|
||||
public static $lang_id;
|
||||
public $file_content = '';
|
||||
protected $max_image_size = null;
|
||||
public $theme_name;
|
||||
public $config_module;
|
||||
public $hook_assign;
|
||||
public $module_name;
|
||||
public $module_path;
|
||||
public $tpl_controller_path;
|
||||
public $tpl_front_path;
|
||||
public $shortcode_dir;
|
||||
public $shortcode_override_dir;
|
||||
public $theme_dir;
|
||||
public $theme_url;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->show_toolbar = true;
|
||||
$this->table = 'appagebuilder';
|
||||
$this->className = 'ApPageBuilderShortCode';
|
||||
$this->context = Context::getContext();
|
||||
$this->module_name = 'appagebuilder';
|
||||
$this->module_path = __PS_BASE_URI__.'modules/'.$this->module_name.'/';
|
||||
$this->tpl_controller_path = _PS_ROOT_DIR_.'/modules/'.$this->module_name.'/views/templates/admin/ap_page_builder_shortcodes/';
|
||||
$this->tpl_front_path = _PS_ROOT_DIR_.'/modules/'.$this->module_name.'/views/templates/font/';
|
||||
$this->shortcode_dir = _PS_MODULE_DIR_.'appagebuilder/classes/shortcodes/';
|
||||
|
||||
self::$language = Language::getLanguages(false);
|
||||
parent::__construct();
|
||||
$this->theme_dir = apPageHelper::getConfigDir('_PS_THEME_DIR_');
|
||||
$this->theme_url = _THEMES_DIR_.apPageHelper::getThemeName().'/';
|
||||
$this->shortcode_override_dir = $this->theme_dir.'modules/appagebuilder/classes/shortcodes/';
|
||||
$this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
|
||||
$this->theme_name = apPageHelper::getThemeName();
|
||||
$this->hook_assign = array('rightcolumn', 'leftcolumn', 'home', 'top', 'footer');
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (Tools::getIsset('type_shortcode')) {
|
||||
# Run AJAX here for Hight Speed
|
||||
$this->ajaxLoadWidget();
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate all data relate with profile
|
||||
* @param type int $old_id : current profile id is duplicating
|
||||
* @param type int $new_id : new profile id after duplicated
|
||||
*/
|
||||
public static function duplicateData($old_id, $new_id)
|
||||
{
|
||||
// $context = Context::getContext();
|
||||
$positions = array();
|
||||
$sql = 'SELECT *
|
||||
FROM `'._DB_PREFIX_.'appagebuilder_profiles` p
|
||||
WHERE p.id_appagebuilder_profiles='.(int)$old_id;
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
if ($result) {
|
||||
$positions[] = $result['header'];
|
||||
$positions[] = $result['content'];
|
||||
$positions[] = $result['footer'];
|
||||
$positions[] = $result['product'];
|
||||
}
|
||||
$sql_update = 'UPDATE '._DB_PREFIX_.'appagebuilder_profiles ';
|
||||
$sep = ' SET ';
|
||||
$is_update = false;
|
||||
// Duplicate positions
|
||||
foreach ($positions as $item) {
|
||||
$id = (int)$item;
|
||||
$object = ApPageBuilderPositionsModel::getPositionById($id);
|
||||
if ($object) {
|
||||
$key = ApPageSetting::getRandomNumber();
|
||||
$old_key = $object['position_key'];
|
||||
$name = 'Duplicate '.$key;
|
||||
$data = array('name' => $name, 'position' => $object['position'], 'position_key' => 'duplicate_'.$key);
|
||||
$model = new ApPageBuilderPositionsModel();
|
||||
$duplicate_id = $model->addAuto($data);
|
||||
if ($duplicate_id) {
|
||||
$position_controller = new AdminApPageBuilderPositionsController();
|
||||
$sql_update .= $sep.$data['position'].'='.$duplicate_id;
|
||||
$sep = ', ';
|
||||
$is_update = true;
|
||||
self::duplcateDataPosition($id, $duplicate_id);
|
||||
ApPageSetting::writeFile($position_controller->position_js_folder, $data['position'].$data['position_key'].'.js', Tools::file_get_contents($position_controller->position_js_folder.$data['position'].$old_key.'.js'));
|
||||
ApPageSetting::writeFile($position_controller->position_css_folder, $data['position'].$data['position_key'].'.css', Tools::file_get_contents($position_controller->position_css_folder.$data['position'].$old_key.'.css'));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($is_update) {
|
||||
$sql_update .= ' WHERE id_appagebuilder_profiles='.(int)$new_id;
|
||||
Db::getInstance()->execute($sql_update);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate a position: dulicate data in table appagebuilder_lang; appagebuilder; appagebuilder_shop;
|
||||
* @param type int $old_id: position id for duplicate
|
||||
* @param type int $duplicate_id: new position id
|
||||
*/
|
||||
public static function duplcateDataPosition($old_id, $duplicate_id)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
// Get list appagebuilder for copy
|
||||
$sql = 'SELECT * from '._DB_PREFIX_.'appagebuilder p WHERE p.id_appagebuilder_positions='.(int)$old_id;
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
foreach ($result as $item) {
|
||||
// Duplicate to tables appagebuilder
|
||||
$sql = 'INSERT INTO '._DB_PREFIX_.'appagebuilder (id_appagebuilder_positions, hook_name)
|
||||
VALUES("'.(int)$duplicate_id.'", "'.pSQL($item['hook_name']).'")';
|
||||
Db::getInstance()->execute($sql);
|
||||
// Duplicate to tables appagebuilder_shop
|
||||
$id_new = Db::getInstance()->Insert_ID();
|
||||
$sql = 'INSERT INTO '._DB_PREFIX_.'appagebuilder_shop (id_appagebuilder, id_shop)
|
||||
VALUES('.(int)$id_new.', '.(int)$id_shop.')';
|
||||
Db::getInstance()->execute($sql);
|
||||
// Copy data and languages
|
||||
$sql = 'SELECT * from '._DB_PREFIX_.'appagebuilder_lang p
|
||||
WHERE p.id_appagebuilder='.(int)$item['id_appagebuilder'];
|
||||
$old_data = Db::getInstance()->executeS($sql);
|
||||
foreach ($old_data as $temp) {
|
||||
// Not pSQL at here because duplicate profile is error
|
||||
$sql = 'INSERT INTO '._DB_PREFIX_."appagebuilder_lang (id_appagebuilder, id_lang, params)
|
||||
VALUES('".(int)$id_new."', '".(int)$temp['id_lang']."', '".apPageHelper::replaceFormId($temp['params'])."')";
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function adminContent($assign, $tpl_name)
|
||||
{
|
||||
if (file_exists($this->tpl_controller_path.$tpl_name)) {
|
||||
$tpl = $this->createTemplate($tpl_name);
|
||||
} else {
|
||||
$tpl = $this->createTemplate('ApGeneral.tpl');
|
||||
}
|
||||
$assign['moduleDir'] = _MODULE_DIR_;
|
||||
foreach ($assign as $key => $ass) {
|
||||
$tpl->assign(array($key => $ass));
|
||||
}
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX :
|
||||
* - load widget or module
|
||||
* - call method of widget
|
||||
*/
|
||||
private function ajaxLoadWidget()
|
||||
{
|
||||
$type_shortcode = Tools::ucfirst(Tools::getValue('type_shortcode'));
|
||||
$type = Tools::getValue('type');
|
||||
$shor_code_dir = '';
|
||||
// Add new widget from apollotheme
|
||||
if ($type === 'widget') {
|
||||
if (!$shor_code_dir = ApPageSetting::requireShortCode($type_shortcode.'.php', $this->theme_dir)) {
|
||||
die($this->l('This short code is not exist'));
|
||||
}
|
||||
if (class_exists($type_shortcode) != true) {
|
||||
// validate module
|
||||
require_once($shor_code_dir);
|
||||
}
|
||||
|
||||
$obj = new $type_shortcode;
|
||||
die($obj->renderForm());
|
||||
} elseif ($type === 'module') {
|
||||
// Custom a module
|
||||
$shor_code_dir = ApPageSetting::requireShortCode('ApModule.php', $this->theme_dir);
|
||||
if (class_exists('ApModule') != true) {
|
||||
// validate module
|
||||
require_once($shor_code_dir);
|
||||
}
|
||||
$obj = new ApModule();
|
||||
die($obj->renderForm());
|
||||
}
|
||||
|
||||
|
||||
|
||||
# RUN WIDGET METHOD - BEGIN
|
||||
$result = array(
|
||||
'hasError' => false,
|
||||
'error' => '',
|
||||
'success' => false,
|
||||
'information' => '',
|
||||
);
|
||||
$type_shortcode = Tools::ucfirst(Tools::getValue('type_shortcode'));
|
||||
if (Tools::getIsset('type_shortcode') && $type_shortcode) {
|
||||
if ($shor_code_dir = ApPageSetting::requireShortCode($type_shortcode.'.php', $this->theme_dir)) {
|
||||
if (class_exists($type_shortcode) != true) {
|
||||
require_once($shor_code_dir);
|
||||
}
|
||||
$obj = new $type_shortcode;
|
||||
$method_name = Tools::getValue('method_name', '');
|
||||
$method_name = 'ajaxCallBack'.Tools::toCamelCase($method_name, true);
|
||||
if (method_exists($obj, $method_name)) {
|
||||
# RUN WIDGET METHOD
|
||||
$obj->{$method_name}();
|
||||
$result['information'] = $method_name . $this->l(' is successful');
|
||||
} else {
|
||||
$result['error'] = sprintf($this->l('%s method is not exist'), $method_name);
|
||||
}
|
||||
} else {
|
||||
$result['error'] = sprintf($this->l('%s is not found'), $type_shortcode.'.php');
|
||||
}
|
||||
} else {
|
||||
$result['error'] = $this->l('type_shortcode param is empty');
|
||||
}
|
||||
|
||||
if (count($result['error'])) {
|
||||
$result['hasError'] = true;
|
||||
}
|
||||
|
||||
die(Tools::jsonEncode($result));
|
||||
# RUN WIDGET METHOD - END
|
||||
}
|
||||
|
||||
public function viewAccess($disable = true)
|
||||
{
|
||||
// return $this->access('view', $disable);
|
||||
unset($disable);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Apollotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* ApPageBuilder is module help you can build content for your shop
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author Apollotheme <apollotheme@gmail.com>
|
||||
* @copyright 2007-2019 Apollotheme
|
||||
* @license http://apollotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminApPageBuilderThemeEditorController extends ModuleAdminControllerCore
|
||||
{
|
||||
public $themeName = '';
|
||||
public $css_patterns;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'appagebuilder_themeeditor';
|
||||
$this->lang = false;
|
||||
$this->context = Context::getContext();
|
||||
parent::__construct();
|
||||
$this->themeName = apPageHelper::getThemeName();
|
||||
$this->js_patterns = apPageHelper::getConfigDir('_PS_THEME_DIR_').apPageHelper::getJsDir().'patterns/';
|
||||
$this->css_patterns = apPageHelper::getConfigDir('_PS_THEME_DIR_').apPageHelper::getCssDir().'patterns/';
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (count($this->errors) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::getValue('action') && Tools::getValue('action') == 'savedata' && Tools::getValue('customize')) {
|
||||
$data = LeoFrameworkHelper::getPost(array('action-mode', 'saved_file', 'newfile', 'customize', 'customize_match', 'active'), 0);
|
||||
|
||||
$selectors = $data['customize'];
|
||||
$matches = $data['customize_match'];
|
||||
|
||||
$output = '';
|
||||
|
||||
$cache = array();
|
||||
foreach ($selectors as $match => $customizes) {
|
||||
$output .= "\r\n/* customize for $match */ \r\n";
|
||||
foreach ($customizes as $key => $customize) {
|
||||
if (isset($matches[$match]) && isset($matches[$match][$key])) {
|
||||
$tmp = explode('|', $matches[$match][$key]);
|
||||
$attribute = Tools::strtolower(trim($tmp[1]));
|
||||
if (trim($customize)) {
|
||||
$output .= $tmp[0].' { ';
|
||||
if ($attribute == 'background-image') {
|
||||
$output .= $attribute.':url('.$customize.')';
|
||||
} elseif ($attribute == 'font-size') {
|
||||
$output .= $attribute.':'.$customize.'px';
|
||||
} else if (strpos($attribute, 'color') !== false) {
|
||||
$output .= $attribute.':#'.$customize;
|
||||
} else if ($attribute == 'background') {
|
||||
$output .= $attribute.':#'.$customize;
|
||||
} else {
|
||||
$output .= $attribute.':'.$customize;
|
||||
}
|
||||
$output .= "} \r\n";
|
||||
}
|
||||
$cache[$match][] = array('val' => $customize, 'selector' => $tmp[0], 'attr' => $tmp[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# RENAME
|
||||
if (!empty($data['saved_file']) && !empty($data['newfile'])) {
|
||||
# DELETE PATTERN
|
||||
if (isset($data['saved_file']) && $data['saved_file'] && file_exists($this->css_patterns.$data['saved_file'].'.css')) {
|
||||
unlink($this->css_patterns.$data['saved_file'].'.css');
|
||||
}
|
||||
if (isset($data['saved_file']) && $data['saved_file'] && file_exists($this->css_patterns.$data['saved_file'].'.json')) {
|
||||
unlink($this->css_patterns.$data['saved_file'].'.json');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (empty($data['newfile'])) {
|
||||
# EDIT PATTERN
|
||||
$nameFile = $data['saved_file'] ? $data['saved_file'] : 'profile-'.time();
|
||||
} else {
|
||||
# CREATE PATTERN
|
||||
$nameFile = preg_replace('#\s+#', '-', trim($data['newfile']));
|
||||
}
|
||||
|
||||
if ($data['action-mode'] != 'save-delete') {
|
||||
# CREATE + EDIT
|
||||
if (!is_dir($this->css_patterns)) {
|
||||
mkdir($this->css_patterns, 0755, true);
|
||||
}
|
||||
|
||||
if (!empty($output)) {
|
||||
LeoFrameworkHelper::writeToCache($this->css_patterns, $nameFile, $output);
|
||||
}
|
||||
if (!empty($cache)) {
|
||||
LeoFrameworkHelper::writeToCache($this->css_patterns, $nameFile, Tools::jsonEncode($cache), 'json');
|
||||
}
|
||||
|
||||
if (isset($data['active']) && $data['active']) {
|
||||
# SET ACTIVE - YES
|
||||
apPageHelper::setConfig('C_PROFILE', $nameFile);
|
||||
} elseif (isset($data['active']) && empty($data['active'])) {
|
||||
# SET ACTIVE - NO
|
||||
$pattern_active = apPageHelper::getConfig('C_PROFILE');
|
||||
if ($nameFile == $pattern_active) {
|
||||
apPageHelper::setConfig('C_PROFILE', '');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# SET ACTIVE - NO
|
||||
$pattern_active = apPageHelper::getConfig('C_PROFILE');
|
||||
if ($data['saved_file'] == $pattern_active) {
|
||||
apPageHelper::setConfig('C_PROFILE', '');
|
||||
}
|
||||
# DELETE PATTERN
|
||||
if (isset($data['saved_file']) && $data['saved_file'] && file_exists($this->css_patterns.$data['saved_file'].'.css')) {
|
||||
unlink($this->css_patterns.$data['saved_file'].'.css');
|
||||
}
|
||||
if (isset($data['saved_file']) && $data['saved_file'] && file_exists($this->css_patterns.$data['saved_file'].'.json')) {
|
||||
unlink($this->css_patterns.$data['saved_file'].'.json');
|
||||
}
|
||||
}
|
||||
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get list of files inside folder path.
|
||||
*/
|
||||
private function getFileList($path, $e = null, $nameOnly = false)
|
||||
{
|
||||
$output = array();
|
||||
$directories = glob($path.'*'.$e);
|
||||
if ($directories) {
|
||||
foreach ($directories as $dir) {
|
||||
$dir = basename($dir);
|
||||
if ($nameOnly) {
|
||||
$dir = str_replace($e, '', $dir);
|
||||
}
|
||||
$output[$dir] = $dir;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* render list of modules following positions in the layout editor.
|
||||
*/
|
||||
public function renderList()
|
||||
{
|
||||
$filePath = _PS_ALL_THEMES_DIR_.$this->themeName.'';
|
||||
|
||||
$xml = simplexml_load_file($filePath.'/config.xml');
|
||||
|
||||
if (!isset($xml->theme_key) || empty($xml->theme_key)) {
|
||||
return '<div class="panel"><div class="panel-content"><div class="alert alert-warning">'.'This function is only avariable using for Theme from <b><a href=http://www.leotheme.com/ target=_blank>leotheme.com</a></b> or using theme built-in <b>Leo Framework</b>'.'</div></div></div>';
|
||||
}
|
||||
|
||||
$tpl = $this->createTemplate('themeeditor.tpl');
|
||||
Context::getContext()->controller->addCss(apPageHelper::getCssAdminDir().'admin/themeeditor.css');
|
||||
Context::getContext()->controller->addCss(apPageHelper::getCssAdminDir().'colorpicker/css/colorpicker.css');
|
||||
Context::getContext()->controller->addCss(apPageHelper::getCssAdminDir().'paneltool.css');
|
||||
|
||||
Context::getContext()->controller->addJs(apPageHelper::getJsAdminDir().'colorpicker/js/colorpicker.js');
|
||||
Context::getContext()->controller->addJs(apPageHelper::getJsAdminDir().'admin/themeeditor.js');
|
||||
|
||||
|
||||
|
||||
$output = LeoFrameworkHelper::renderEdtiorThemeForm($this->themeName);
|
||||
|
||||
$profiles = $this->getFileList($this->css_patterns, '.css', true);
|
||||
$patterns = $this->getFileList(_PS_ALL_THEMES_DIR_.$this->themeName.'/assets/img/patterns/', '.png');
|
||||
$patternsjpg = $this->getFileList(_PS_ALL_THEMES_DIR_.$this->themeName.'/assets/img/patterns/', '.jpg');
|
||||
|
||||
$patterns = array_merge($patterns, $patternsjpg);
|
||||
$backGroundValue = array(
|
||||
'attachment' => array('scroll', 'fixed', 'local', 'initial', 'inherit'),
|
||||
'repeat' => array('repeat', 'repeat-x', 'repeat-y', 'no-repeat', 'initial', 'inherit'),
|
||||
'position' => array('left top', 'left center', 'left bottom', 'right top', 'right center', 'right bottom', 'center top', 'center center', 'center bottom')
|
||||
);
|
||||
$siteURL = _PS_BASE_URL_.__PS_BASE_URI__;
|
||||
// URL LOAD IMAGE BUTTON
|
||||
$imgLink = Context::getContext()->link->getAdminLink('AdminApPageBuilderImages').'&leo_controller=live_theme_edit';
|
||||
$backgroundImageURL = _PS_BASE_URL_._THEME_DIR_.'assets/img/patterns/';
|
||||
|
||||
$ssl_enable = Configuration::get('PS_SSL_ENABLED');
|
||||
if ($ssl_enable) {
|
||||
$siteURL = str_replace('http:', 'https:', $siteURL);
|
||||
$imgLink = str_replace('http:', 'https:', $imgLink);
|
||||
$backgroundImageURL = str_replace('http:', 'https:', $backgroundImageURL);
|
||||
}
|
||||
|
||||
$tpl->assign(array(
|
||||
'actionURL' => 'index.php?tab=AdminApPageBuilderThemeEditor&token='.Tools::getAdminTokenLite('AdminApPageBuilderThemeEditor').'&action=savedata',
|
||||
'text_layout' => $this->l('Layout'),
|
||||
'text_elements' => $this->l('Elements'),
|
||||
'profiles' => $profiles,
|
||||
'profiles_active' => apPageHelper::getConfig('c_profile'),
|
||||
'xmlselectors' => $output,
|
||||
'apPageHelper' => apPageHelper::getInstance(),
|
||||
'themeName' => $this->themeName,
|
||||
'patterns' => $patterns,
|
||||
'backgroundImageURL' => $backgroundImageURL,
|
||||
'siteURL' => $siteURL,
|
||||
'customizeFolderURL' => _PS_THEME_URI_.apPageHelper::getCssDir().'patterns/',
|
||||
'backLink' => 'index.php?controller=AdminModules&configure=appagebuilder&token='.Tools::getAdminTokenLite('AdminModules'),
|
||||
'imgLink' => $imgLink,
|
||||
'backGroundValue' => $backGroundValue
|
||||
));
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
}
|
||||
36
modules/appagebuilder/controllers/admin/index.php
Normal file
36
modules/appagebuilder/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;
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Leo Theme for Prestashop 1.6.x
|
||||
*
|
||||
* @author http://www.leotheme.com
|
||||
* @copyright Copyright (C) October 2013 LeoThemes.com <@emai:leotheme@gmail.com>
|
||||
* <info@leotheme.com>.All rights reserved.
|
||||
* @license GNU General Public License version 2
|
||||
*/
|
||||
|
||||
class ApPageBuilderApPagebuilderHomeModuleFrontController extends FrontController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->display_column_left = false;
|
||||
$this->display_column_right = false;
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
$this->addJS(_THEME_JS_DIR_.'index.js');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'HOOK_HOME' => Hook::exec('displayHome'),
|
||||
'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'),
|
||||
'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent')
|
||||
));
|
||||
$this->display_column_left = false;
|
||||
$this->display_column_right = false;
|
||||
$this->context->smarty->assign(array(
|
||||
'page_name' => 'index',
|
||||
));
|
||||
$this->setTemplate('index.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* set html <body id="index"
|
||||
*/
|
||||
public function getPageName()
|
||||
{
|
||||
$page_name = 'index';
|
||||
return $page_name;
|
||||
}
|
||||
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
unset($page['body_classes']['page-']);
|
||||
$page['body_classes']['page-index'] = true;
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
36
modules/appagebuilder/controllers/front/index.php
Normal file
36
modules/appagebuilder/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;
|
||||
36
modules/appagebuilder/controllers/index.php
Normal file
36
modules/appagebuilder/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