* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminJsComposerSettingController extends AdminController {
public function __construct() {
$this->bootstrap = true;
$this->className = 'Configuration';
$this->table = 'Configuration';
parent::__construct();
$arr = array();
$arr[] = array('id' => 'no', 'name' => 'No');
$arr[] = array('id' => 'yes', 'name' => 'Yes');
$tab_arr[] = array('id' => 'general', 'name' => 'General Style');
$tab_arr[] = array('id' => 'classic', 'name' => 'Classic Style');
parent::__construct();
$this->fields_options = array(
'email' => array(
'title' => $this->l('General Setting for Visual Composer'),
'icon' => 'icon-cogs',
'fields' => array(
'vc_load_flex_js' => array(
'title' => $this->l('Load Flexslider JS:'),
'desc' => $this->l('if you want to load Flexslider JS from your theme or module.'),
'validation' => 'isGenericName',
'type' => 'select',
'identifier' => 'id',
'list' => $arr
),
'vc_load_flex_css' => array(
'title' => $this->l('Load Flexslider CSS:'),
'desc' => $this->l('if you want to load Flexslider CSS from your theme or module.'),
'validation' => 'isGenericName',
'type' => 'select',
'identifier' => 'id',
'list' => $arr
),
'vc_load_nivo_js' => array(
'title' => $this->l('Load NivoSlider JS:'),
'desc' => $this->l('if you want to load NivoSlider JS from your theme or module.'),
'validation' => 'isGenericName',
'type' => 'select',
'identifier' => 'id',
'list' => $arr
),
'vc_load_nivo_css' => array(
'title' => $this->l('Load NivoSlider CSS:'),
'desc' => $this->l('if you want to load NivoSlider CSS from your theme or module.'),
'validation' => 'isGenericName',
'type' => 'select',
'identifier' => 'id',
'list' => $arr
),
'vc_product_tab_style' => array(
'title' => $this->l('Product Tab Style'),
'desc' => $this->l('you Can Change Product Tab Style.'),
'validation' => 'isGenericName',
'type' => 'select',
'identifier' => 'id',
'list' => $tab_arr
),
'vc_include_modules' => array(
'title' => $this->l('Include Modules'),
'desc' => $this->l('You can include modules by putting modules name here(e.g. blockcms) to be appear in visual composer shortcodes list. Put a module name per line.'),
'type' => 'textarea',
'identifier' => 'id',
'rows' => 7,
'cols' => 7,
),
'vc_exclude_modules' => array(
'title' => $this->l('Exclude Modules'),
'desc' => $this->l('You can exclude modules by putting modules name here(e.g. blockcms) to be removed from visual composer shortcodes list. Put a module name per line.'),
'type' => 'textarea',
'identifier' => 'id',
'rows' => 7,
'cols' => 7,
),
// 'vc_custom_hook' => array(
// 'title' => $this->l('Custom Hook'),
// 'desc' => $this->l('Put custom hook name per line.'),
// 'type' => 'textarea',
// 'identifier' => 'id',
// 'rows' => 7,
// 'cols' => 7,
// ),
),
'submit' => array('title' => $this->l('Save'))
),
);
// ksort($this->fields_options['email']['fields']);
}
public function initPageHeaderToolbar() {
parent::initPageHeaderToolbar();
// $this->page_header_toolbar_btn['import_tinymcejs'] = array(
// 'href' => self::$currentIndex . '&action=importtinymce&token=' . $this->token,
// 'desc' => $this->l('Import Tinymce', null, null, false),
// 'icon' => 'process-icon-import'
// );
}
public function renderList() {
$custom_hook = unserialize(Configuration::get('vc_custom_hook'));
$hook_list = array();
if (!empty($custom_hook)) {
foreach ($custom_hook as $inc) {
$inc = trim($inc);
$hook_list[] = $inc;
}
}
//checking if update is available------------------
if (Tools::isSubmit('check_update')) {
$Smartlisence = new Smartlisence();
$this_val = array(
'version' => JsComposer::$vc_version,
'module_name' => JsComposer::$vc_mode_name,
'theme_name'=> basename(_THEME_DIR_),
'purchase_key'=> Tools::getValue('purchase_key')
);
//remove
Configuration::deleteByName('jscomposer_update_timeout');
$out = $Smartlisence->checkUpdate($this_val);
}
//checking if update is available------------------
$css = "
";
$jscomposer_status = Configuration::get('jscomposer_status', '0');
if ($jscomposer_status == '1') {
$activation_details = $css . '
'
. ' Module Activated'
. '
';
$disable_status = 'disabled';
$below_message = 'In order to register your purchase code on another domain, deregister it first by clicking the button below.
';
$active_button = "";
$deactive_button = "";
} else {
$activation_details = $css . ''
. ' Not Activated'
. '
';
$disable_status = '';
$below_message = 'Reminder ! One registration per Website. If registered elsewhere please deactivate that registration first.
';
$active_button = "";
$deactive_button = "";
}
$purchase_key = Configuration::get('jscomposer_purchase_key', '');
$html = "";
$html .= '';
$Smartlisence = new Smartlisence();
if($Smartlisence->isActive()){
$html .='
';
} else {
$html .='
';
$html .= '
';
}
$html .='
';
//-----------
$html .='
';
$html .='';
$html .=' ';
$html .='| ';
$html .='Hook Name';
$html .=' | ';
$html .='';
$html .='Description';
$html .=' | ';
$html .=' ';
$html .=' | ';
$html .='
';
$html .=' ';
$html .='';
foreach ($hook_list as $inc) {
$url = $_SERVER['REQUEST_URI'] . '&deleteCustomHook=' . $inc;
$html .=' ';
$html .=' | ';
$html .= $inc;
$html .=' | ';
$html .=' ';
$html .= 'This block is attached to custom hook. To display it in .tpl file use: {hook h="' . $inc . '"}';
$html .=' | ';
$html .=' ';
$html .=' ';
$html .=' | ';
$html .='
';
}
if (empty($hook_list)) {
$html .=' ';
$html .='| ';
$html .=' ';
$html .='';
$html .=' No records found';
$html .=' ';
$html .=' | ';
$html .='
';
}
$html .=' ';
$html .='
';
//---------
$html .='
';
$html .='
';
$html.='';
$html.= $this->externalControllers();
return $html;
}
public function externalControllers(){
$controllers = Configuration::get('VC_ENQUEUED_CONTROLLERS');
$controllers = Tools::jsonDecode($controllers, true);
$template = _PS_MODULE_DIR_ . '/jscomposer/views/templates/admin/backend_hook_list.tpl' ;
$this->context->smarty->assign(array(
'controllers' => $controllers,
'baseDir' => _PS_BASE_URL_.__PS_BASE_URI__,
'url_base' => Context::getContext()->link->getAdminLink('AdminJsModuleList'),
'url_admin_ajax' => Context::getContext()->link->getAdminLink('AdminJsComposerAjax'),
'url_module_name' => '',
'url_status' => ''
));
$html = '';
$html = $this->context->smarty->fetch($template);
return $html;
}
public function initContent() {
if (Tools::isSubmit('deactivateVc')) {
$this_val = array(
'version' => JsComposer::$vc_version,
'module_name' => JsComposer::$vc_mode_name,
'theme_name'=> basename(_THEME_DIR_),
'purchase_key'=> Tools::getValue('purchase_key')
);
$Smartlisence = new Smartlisence();
$Smartlisence->deactivateModule($this_val);
}
if (Tools::isSubmit('activateVc')) {
$this_val = array(
'version' => JsComposer::$vc_version,
'module_name' => JsComposer::$vc_mode_name,
'theme_name'=> basename(_THEME_DIR_),
'purchase_key'=> Tools::getValue('purchase_key')
);
$Smartlisence = new Smartlisence();
$Smartlisence->activateModule($this_val);
}
if (Tools::isSubmit('updateVc')) {
$this_val = array(
'version' => JsComposer::$vc_version,
'module_name' => JsComposer::$vc_mode_name,
'theme_name'=> basename(_THEME_DIR_),
'purchase_key'=> Tools::getValue('purchase_key')
);
$Smartlisence = new Smartlisence();
$Smartlisence->updateModule($this_val);
}
if (isset($_REQUEST['deleteCustomHook'])) {
$deleteCustomHook = $_REQUEST['deleteCustomHook'];
if ($deleteCustomHook != '') {
$old_hook_list = unserialize(Configuration::get('vc_custom_hook'));
if ($old_hook_list == '') {
$old_hook_list = array();
}
// foreach($old_hook_list as $key => $hook){
// if(in_array($deleteCustomHook, $old_hook_list)){
// unset($old_hook_list[$key]);
// }
// }
$key = array_search($deleteCustomHook, $old_hook_list);
unset($old_hook_list[$key]);
$updated_hook_list = serialize($old_hook_list);
Configuration::updateValue('vc_custom_hook', $updated_hook_list);
$mod_obj = Module::getInstanceByName('jscomposer');
$id_hook = Hook::getIdByName($deleteCustomHook);
$mod_obj->unregisterHook($id_hook);
$url = $this->context->link->getAdminLink('AdminJsComposerSetting', true);
Tools::redirectAdmin($url);
}
}
if (Tools::isSubmit('customhookadd')) {
$Smartlisence = new Smartlisence();
if($Smartlisence->isActive()){
$old_hook_list = unserialize(Configuration::get('vc_custom_hook'));
if (isset($old_hook_list) && ($old_hook_list == '')) {
$old_hook_list = array();
}
$new_hook = Tools::getValue('vc_custom_hook');
if (in_array($new_hook, $old_hook_list)) {
$new_hook = '';
} else {
$old_hook_list[] = $new_hook;
}
$updated_hook_list = serialize($old_hook_list);
Configuration::updateValue('vc_custom_hook', $updated_hook_list);
if ($new_hook != '') {
//$new_hook_list = explode("\n", $new_hook_list);
// foreach ($new_hook_list as $inc) {
$inc = trim($new_hook);
$mod_obj = Module::getInstanceByName('jscomposer');
$mod_obj->registerHook($inc);
// }
}
}
}
parent::initContent();
}
// public function beforeUpdateOptions()
// {
// // echo $_SERVER['REQUEST_URI'];die();
// $old_hook_list = unserialize(Configuration::get('vc_custom_hook'));
//
// if($old_hook_list==''){
// $old_hook_list = array();
// }
// $new_hook = Tools::getValue('vc_custom_hook');
//
// if(in_array($new_hook, $old_hook_list)){
// $new_hook='';
// }else{
// $old_hook_list[] = $new_hook;
// }
//
//
// $updated_hook_list= serialize($old_hook_list);
// Configuration::updateValue('vc_custom_hook', $updated_hook_list);
//
//// $old_hook_list = array();
// // $new_hook_list = array();
//
// // $hook_remove_list = array();
//
//// if (!empty($old_hook)) {
//// $old_hook = explode("\n", $old_hook);
//// foreach ($old_hook as $inc) {
//// $inc = trim($inc);
//// $old_hook_list [] = $inc;
//// }
//// }
//
//
//// if (!empty($new_hook)) {
//// $new_hook = explode("\n", $new_hook);
//// foreach ($new_hook as $inc) {
//// $inc = trim($inc);
//// if(!in_array($inc, $old_hook_list)){
//// $old_hook_list []= $inc;
//// $new_hook_list[] = $inc;
//// }
//// }
//// }
////
//
// // var_dump($new_hook_list);die();
//// $hook_remove_list = array_diff($new_hook_list, $old_hook_list);
// /*
// print_r($new_hook_list );
// print_r($old_hook_list );
// print_r($hook_remove_list );
// */
//// foreach ($hook_remove_list as $handle) {
//// $handle = trim($handle);
////
//// $mod_obj = Module::getInstanceByName('jscomposer');
//// $id_hook = Hook::getIdByName($handle);
//// $mod_obj->unregisterHook($id_hook);
//// }
// //print_r(Configuration::get('vc_custom_hook'));
// if ($new_hook!='') {
// //$new_hook_list = explode("\n", $new_hook_list);
//// foreach ($new_hook_list as $inc) {
// $inc = trim($new_hook);
//
// $mod_obj = Module::getInstanceByName('jscomposer');
// $mod_obj->registerHook($inc);
//// }
// }
// // $_POST['vc_custom_hook'] = $fonts;
// }
public function initHeader() {
// if (Tools::getValue('action') == 'importtinymce') {
// JsComposer::installTinymce(false);
// $redirect = $this->context->link->getAdminLink('AdminJsComposerSetting') . '&importsuccess=true';
// Tools::redirectAdmin($redirect);
// }
parent::initHeader();
}
}