// move to themeconfigurator
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@@ -26,21 +26,281 @@
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
|
||||
class ThemeConfigurator extends Module
|
||||
{
|
||||
protected $max_image_size = 1048576;
|
||||
protected $default_language;
|
||||
protected $languages;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'themeconfigurator';
|
||||
$this->tab = 'front_office_features';
|
||||
$this->version = '0.1';
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->secure_key = Tools::encrypt($this->name);
|
||||
$this->default_language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT'));
|
||||
$this->languages = Language::getLanguages();
|
||||
|
||||
parent::__construct();
|
||||
$this->displayName = $this->l('Theme configurator');
|
||||
$this->description = $this->l('Configure elements of your theme');
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->module_path = _PS_MODULE_DIR_.$this->name.'/';
|
||||
$this->uploads_path = _PS_MODULE_DIR_.$this->name.'/images/';
|
||||
$this->admin_tpl_path = _PS_MODULE_DIR_.$this->name.'/views/templates/admin/';
|
||||
$this->hooks_tpl_path = _PS_MODULE_DIR_.$this->name.'/views/templates/hooks/';
|
||||
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (!parent::install() ||
|
||||
!$this->installDB() ||
|
||||
!$this->registerHook('displayHeader') ||
|
||||
!$this->registerHook('displayTop') ||
|
||||
!$this->registerHook('displayLeftColumn') ||
|
||||
!$this->registerHook('displayRightColumn') ||
|
||||
!$this->registerHook('displayHome') ||
|
||||
!$this->registerHook('displayFooter') ||
|
||||
!$this->registerHook('displayBackOfficeHeader'))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function installDB()
|
||||
{
|
||||
return (
|
||||
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'themeconfigurator`') &&
|
||||
Db::getInstance()->Execute('
|
||||
CREATE TABLE `'._DB_PREFIX_.'themeconfigurator` (
|
||||
`id_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_shop` int(10) unsigned NOT NULL,
|
||||
`id_lang` int(10) unsigned NOT NULL,
|
||||
`item_order` int(10) unsigned NOT NULL,
|
||||
`title` VARCHAR(100),
|
||||
`title_use` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
||||
`hook` VARCHAR(100),
|
||||
`url` VARCHAR(100),
|
||||
`target` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
||||
`image` VARCHAR(100),
|
||||
`image_w` VARCHAR(10),
|
||||
`image_h` VARCHAR(10),
|
||||
`html` TEXT,
|
||||
`active` tinyint(1) unsigned NOT NULL DEFAULT \'1\',
|
||||
PRIMARY KEY (`id_item`)
|
||||
) ENGINE = '._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;')
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
$images = Db::getInstance()->executeS('SELECT image FROM `'._DB_PREFIX_.'themeconfigurator`');
|
||||
foreach ($images as $image)
|
||||
$this->deleteImage($image['image']);
|
||||
|
||||
if (!Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'themeconfigurator`') ||
|
||||
!parent::uninstall())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hookDisplayBackOfficeHeader()
|
||||
{
|
||||
if (Tools::getValue('configure') != $this->name)
|
||||
return;
|
||||
$this->context->controller->addCSS($this->_path.'views/css/admin.css');
|
||||
$this->context->controller->addJquery();
|
||||
$this->context->controller->addJS($this->_path.'views/js/admin.js');
|
||||
}
|
||||
|
||||
public function hookdisplayHeader($params)
|
||||
{
|
||||
$this->context->controller->addCss($this->_path.'views/css/hooks.css', 'all');
|
||||
}
|
||||
|
||||
public function hookDisplayTop()
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'htmlitems'=> $this->getItemsFromHook('top'),
|
||||
'hook' => 'top'
|
||||
));
|
||||
return $this->display(__FILE__, 'views/templates/hooks/hook.tpl');
|
||||
}
|
||||
|
||||
public function hookDisplayHome()
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'htmlitems'=> $this->getItemsFromHook('home'),
|
||||
'hook' => 'home'
|
||||
));
|
||||
return $this->display(__FILE__, 'views/templates/hooks/hook.tpl');
|
||||
}
|
||||
|
||||
public function hookDisplayLeftColumn()
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'htmlitems'=> $this->getItemsFromHook('left'),
|
||||
'hook' => 'left'
|
||||
));
|
||||
return $this->display(__FILE__, 'views/templates/hooks/hook.tpl');
|
||||
}
|
||||
|
||||
public function hookDisplayRightColumn()
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'htmlitems'=> $this->getItemsFromHook('right'),
|
||||
'hook' => 'right'
|
||||
));
|
||||
return $this->display(__FILE__, 'views/templates/hooks/hook.tpl');
|
||||
}
|
||||
|
||||
public function hookDisplayFooter()
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'htmlitems'=> $this->getItemsFromHook('footer'),
|
||||
'hook' => 'footer'
|
||||
));
|
||||
return $this->display(__FILE__, 'views/templates/hooks/hook.tpl');
|
||||
}
|
||||
|
||||
protected function getItemsFromHook($hook)
|
||||
{
|
||||
if (!$hook)
|
||||
return false;
|
||||
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'themeconfigurator`
|
||||
WHERE id_shop = '.(int)$this->context->shop->id.' AND id_lang = '.(int)$this->context->language->id.' AND hook = \''.pSQL($hook).'\' AND active = 1
|
||||
ORDER BY item_order ASC'
|
||||
);
|
||||
}
|
||||
|
||||
protected function deleteImage($image)
|
||||
{
|
||||
$file_name = $this->uploads_path.$image;
|
||||
if (realpath(dirname($file_name)) != $this->uploads_path)
|
||||
die;
|
||||
|
||||
if ($image != '' && is_file($file_name))
|
||||
unlink($file_name);
|
||||
}
|
||||
|
||||
protected function removeItem()
|
||||
{
|
||||
$id_item = (int)Tools::getValue('item_id');
|
||||
|
||||
if ($image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'themeconfigurator` WHERE id_item = '.(int)$id_item))
|
||||
$this->deleteImage($image);
|
||||
|
||||
Db::getInstance()->delete(_DB_PREFIX_.'themeconfigurator', 'id_item = '.(int)$id_item);
|
||||
|
||||
if (Db::getInstance()->Affected_Rows() == 1)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'themeconfigurator`
|
||||
SET item_order = item_order-1
|
||||
WHERE (
|
||||
item_order > '.(int)Tools::getValue('item_order').' AND
|
||||
id_shop = '.(int)$this->context->shop->id.' AND
|
||||
hook = \''.pSQL(Tools::getValue('item_hook')).'\')
|
||||
');
|
||||
|
||||
$this->context->smarty->assign('confirmation', $this->l('Successful deletion.'));
|
||||
}
|
||||
else
|
||||
$this->context->smarty->assign('error', $this->l('Can\'t delete the slide.'));
|
||||
}
|
||||
|
||||
protected function updateItem()
|
||||
{
|
||||
$id_item = (int)Tools::getValue('item_id');
|
||||
|
||||
$title = Tools::getValue('item_title');
|
||||
$content = Tools::getValue('item_html');
|
||||
if (!Validate::isCleanHtml($title, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')) || !Validate::isCleanHtml($content,(int)Configuration::get('PS_ALLOW_HTML_IFRAME')))
|
||||
{
|
||||
$this->context->smarty->assign('error', $this->l('Invalid content'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_image = '';
|
||||
$image_w = (is_numeric(Tools::getValue('item_img_w'))) ? (int)Tools::getValue('item_img_w') : '';
|
||||
$image_h = (is_numeric(Tools::getValue('item_img_h'))) ? (int)Tools::getValue('item_img_h') : '';
|
||||
|
||||
if(!empty($_FILES['item_img']['name']))
|
||||
{
|
||||
if ($old_image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'themeconfigurator` WHERE id_item = '.(int)$id_item))
|
||||
$this->_deleteImages($old_image);
|
||||
|
||||
if (!$image = $this->uploadImage($_FILES['item_img'], $image_w, $image_h))
|
||||
return false;
|
||||
|
||||
$new_image = 'image = \''.pSQL($image).'\',';
|
||||
}
|
||||
else
|
||||
{
|
||||
$image_w = '';
|
||||
$image_h = '';
|
||||
}
|
||||
|
||||
if (!Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'themeconfigurator` SET
|
||||
title = \''.pSQL($title).'\',
|
||||
title_use = '.(int)Tools::getValue('item_title_use').',
|
||||
hook = \''.pSQL(Tools::getValue('item_hook')).'\',
|
||||
url = \''.pSQL(Tools::getValue('item_url')).'\',
|
||||
target = '.(int)Tools::getValue('item_target').',
|
||||
'.$new_image.'
|
||||
image_w = '.(int)$image_w.',
|
||||
image_h = '.(int)$image_h.',
|
||||
active = '.(int)Tools::getValue('item_active').',
|
||||
html = \''.pSQL($content).'\'
|
||||
WHERE id_item = '.(int)Tools::getValue('item_id')
|
||||
))
|
||||
{
|
||||
if ($image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'themeconfigurator` WHERE id_item = '.(int)Tools::getValue('item_id')))
|
||||
$this->deleteImage($image);
|
||||
|
||||
$this->context->smarty->assign('error', $this->l('An error occured while saving data.'));
|
||||
return false;
|
||||
}
|
||||
$this->context->smarty->assign('confirmation', $this->l('Successfully updated.'));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
protected function uploadImage($image, $image_w = '', $image_h = '')
|
||||
{
|
||||
$res = false;
|
||||
if (is_array($image) && (ImageManager::validateUpload($image, $this->max_image_size) === false) && ($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) && move_uploaded_file($image['tmp_name'], $tmp_name))
|
||||
{
|
||||
$type = Tools::strtolower(Tools::substr(strrchr($image['name'], '.'), 1));
|
||||
$img_name = Tools::encrypt($image['name'].sha1(microtime())).'.'.$type;
|
||||
Configuration::set('PS_IMAGE_QUALITY','png_all');
|
||||
if (ImageManager::resize($tmp_name, dirname(__FILE__).'/images/'.$img_name, $image_w, $image_h))
|
||||
$res = true;
|
||||
|
||||
}
|
||||
|
||||
if (isset($temp_name))
|
||||
@unlink($tmp_name);
|
||||
if (!$res)
|
||||
{
|
||||
$this->context->smarty->assign('error', $this->l('An error occurred during the image upload.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return $img_name;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
if (Tools::isSubmit('submitModule'))
|
||||
@@ -71,19 +331,107 @@ class ThemeConfigurator extends Module
|
||||
$module_instance->install();
|
||||
}
|
||||
}
|
||||
return $this->renderForm();
|
||||
|
||||
if (Tools::isSubmit('newItem'))
|
||||
$this->addItem();
|
||||
elseif (Tools::isSubmit('updateItem'))
|
||||
$this->updateItem();
|
||||
elseif (Tools::isSubmit('removeItem'))
|
||||
$this->removeItem();
|
||||
|
||||
$html = $this->renderConfigurationForm();
|
||||
$html .= $this->renderThemeConfiguratorForm();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
protected function addItem()
|
||||
{
|
||||
$title = Tools::getValue('item_title');
|
||||
$content = Tools::getValue('item_html');
|
||||
if (!Validate::isCleanHtml($title, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')) || !Validate::isCleanHtml($content, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')))
|
||||
{
|
||||
$this->context->smarty->assign('error', $this->l('Invalid content'));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!$current_order = (int)Db::getInstance()->getValue('
|
||||
SELECT item_order + 1
|
||||
FROM `'._DB_PREFIX_.'themeconfigurator`
|
||||
WHERE
|
||||
id_shop = '.(int)$this->context->shop->id.'
|
||||
AND id_lang = '.(int)Tools::getValue('id_lang').'
|
||||
AND hook = \''.pSQL(Tools::getValue('item_hook')).'\'
|
||||
ORDER BY item_order DESC'
|
||||
))
|
||||
$current_order = 1;
|
||||
|
||||
$image_w = is_numeric(Tools::getValue('item_img_w')) ? (int)Tools::getValue('item_img_w') : '';
|
||||
$image_h = is_numeric(Tools::getValue('item_img_h')) ? (int)Tools::getValue('item_img_h') : '';
|
||||
|
||||
if(!empty($_FILES['item_img']['name']))
|
||||
{
|
||||
if (!$image = $this->uploadImage($_FILES['item_img'], $image_w, $image_h))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$image = '';
|
||||
$image_w = '';
|
||||
$image_h = '';
|
||||
}
|
||||
|
||||
if (!Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'themeconfigurator` (
|
||||
`id_shop`, `id_lang`, `item_order`, `title`, `title_use`, `hook`, `url`, `target`, `image`, `image_w`, `image_h`, `html`, `active`
|
||||
) VALUES (
|
||||
\''.(int)$this->context->shop->id.'\',
|
||||
\''.(int)Tools::getValue('id_lang').'\',
|
||||
\''.(int)$current_order.'\',
|
||||
\''.pSQL($title).'\',
|
||||
\''.(int)Tools::getValue('item_title_use').'\',
|
||||
\''.pSQL(Tools::getValue('item_hook')).'\',
|
||||
\''.pSQL(Tools::getValue('item_url')).'\',
|
||||
\''.(int)Tools::getValue('item_target').'\',
|
||||
\''.pSQL($image).'\',
|
||||
\''.pSQL($image_w).'\',
|
||||
\''.pSQL($image_h).'\',
|
||||
\''.pSQL($content).'\',
|
||||
1)
|
||||
'))
|
||||
{
|
||||
if (!Tools::isEmpty($image))
|
||||
$this->deleteImage($image);
|
||||
|
||||
$this->context->smarty->assign('error', $this->l('An error occured while saving data.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('confirmation', $this->l('New item added successfull.'));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function renderConfigurationForm()
|
||||
{
|
||||
$inputs = array();
|
||||
foreach ($this->getConfigurableModules() as $module)
|
||||
{
|
||||
$desc = '';
|
||||
if (isset($module['is_module']) && $module['is_module'])
|
||||
{
|
||||
$module_instance = Module::getInstanceByName($module['name']);
|
||||
if (Validate::isLoadedObject($module_instance) && method_exists($module_instance, 'getContent'))
|
||||
$desc = '<a href="'.$this->context->link->getAdminLink('AdminModules', true).'&configure='.urlencode($module_instance->name).'&tab_module='.$module_instance->tab.'&module_name='.urlencode($module_instance->name).'">'.$this->l('Configure').'</a>';
|
||||
}
|
||||
if (!$desc && isset($module['desc']) && $module['desc'])
|
||||
$desc = $module['desc'];
|
||||
|
||||
$inputs[] = array(
|
||||
'type' => 'switch',
|
||||
'label' => $module['label'],
|
||||
'name' => $module['name'],
|
||||
'desc' => (isset($module['desc']) ? $module['desc'] : ''),
|
||||
'desc' => $desc,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
@@ -97,6 +445,7 @@ class ThemeConfigurator extends Module
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
@@ -131,6 +480,52 @@ class ThemeConfigurator extends Module
|
||||
|
||||
return $helper->generateForm(array($fields_form));
|
||||
}
|
||||
|
||||
protected function renderThemeConfiguratorForm()
|
||||
{
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$items = array();
|
||||
|
||||
$this->context->smarty->assign('htmlcontent', array(
|
||||
'admin_tpl_path' => $this->admin_tpl_path,
|
||||
'hooks_tpl_path' => $this->hooks_tpl_path,
|
||||
|
||||
'info' => array(
|
||||
'module' => $this->name,
|
||||
'name' => $this->displayName,
|
||||
'version' => $this->version,
|
||||
'psVersion' => _PS_VERSION_,
|
||||
'context' => (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 0) ? 1 : ($this->context->shop->getTotalShops() != 1) ? $this->context->shop->getContext() : 1
|
||||
)
|
||||
));
|
||||
|
||||
foreach ($this->languages as $language) {
|
||||
$hooks[$language['id_lang']] = array('home', 'top', 'left', 'right', 'footer');
|
||||
|
||||
foreach ($hooks[$language['id_lang']] as $hook)
|
||||
$items[$language['id_lang']][$hook] = Db::getInstance()->ExecuteS('
|
||||
SELECT * FROM `'._DB_PREFIX_.'themeconfigurator`
|
||||
WHERE id_shop = '.(int)$id_shop.'
|
||||
AND id_lang = '.(int)$language['id_lang'].'
|
||||
AND hook = \''.pSQL($hook).'\'
|
||||
ORDER BY item_order ASC'
|
||||
);
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('htmlitems', array(
|
||||
'items' => $items,
|
||||
'lang' => array(
|
||||
'default' => $this->default_language,
|
||||
'all' => $this->languages,
|
||||
'lang_dir' => _THEME_LANG_DIR_,
|
||||
'user' => $this->context->language->id
|
||||
),
|
||||
'postAction' => 'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&tab_module=other&module_name='.$this->name.'',
|
||||
'id_shop' => $id_shop
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/admin/admin.tpl');
|
||||
}
|
||||
|
||||
protected function getConfigurableModules()
|
||||
{
|
||||
@@ -138,52 +533,39 @@ class ThemeConfigurator extends Module
|
||||
array(
|
||||
'label' => $this->l('Display the reinsurance block'),
|
||||
'name' => 'blockreinsurance',
|
||||
'desc' => '<a href="#">'.$this->l('Configure the reinsurance block').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('blockreinsurance')) && $module->active),
|
||||
'is_module' => true,
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Display the social following links'),
|
||||
'name' => 'blocksocial',
|
||||
'desc' => '<a href="#">'.$this->l('Configure the social following links').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('blocksocial')) && $module->active),
|
||||
'is_module' => true,
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Display contact information'),
|
||||
'name' => 'blockcontactinfos',
|
||||
'desc' => '<a href="#">'.$this->l('Configure the contact information of your store').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('blockcontactinfos')) && $module->active),
|
||||
'is_module' => true,
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Display social buttons on the products page'),
|
||||
'name' => 'addsharethis',
|
||||
'desc' => '<a href="#">'.$this->l('Configure').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('addsharethis')) && $module->active),
|
||||
'is_module' => true,
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Display facebook block on the home page'),
|
||||
'name' => 'blockfacebook',
|
||||
'desc' => '<a href="#">'.$this->l('Configure').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('blockfacebook')) && $module->active),
|
||||
'is_module' => true,
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Customer cms information block'),
|
||||
'name' => 'blockcmsinfo',
|
||||
'desc' => '<a href="#">'.$this->l('Configure').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('blockcmsinfo')) && $module->active),
|
||||
'is_module' => true,
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Customer banner information block'),
|
||||
'name' => 'tmhtmlcontent',
|
||||
'desc' => '<a href="#">'.$this->l('Configure').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('tmhtmlcontent')) && $module->active),
|
||||
'is_module' => true,
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Enable Quick view'),
|
||||
'name' => 'quick_view',
|
||||
@@ -192,14 +574,12 @@ class ThemeConfigurator extends Module
|
||||
array(
|
||||
'label' => $this->l('Enable top banner'),
|
||||
'name' => 'blockbanner',
|
||||
'desc' => '<a href="#">'.$this->l('Configure').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('blockbanner')) && $module->active),
|
||||
'is_module' => true,
|
||||
),
|
||||
array(
|
||||
'label' => $this->l('Enable product payment logos'),
|
||||
'name' => 'productpaymentlogos',
|
||||
'desc' => '<a href="#">'.$this->l('Configure').'</a>',
|
||||
'value' => (int)(Validate::isLoadedObject($module = Module::getInstanceByName('productpaymentlogos')) && $module->active),
|
||||
'is_module' => true,
|
||||
)
|
||||
@@ -213,5 +593,5 @@ class ThemeConfigurator extends Module
|
||||
$values[$module['name']] = $module['value'];
|
||||
return $values;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
@@ -1,16 +1,13 @@
|
||||
<div id="htmlcontent">
|
||||
<h2>{$htmlcontent.info.name} (v.{$htmlcontent.info.version})</h2>
|
||||
|
||||
{if $error}
|
||||
{if isset($error) && $error}
|
||||
{include file="{$htmlcontent.admin_tpl_path}messages.tpl" id="main" text=$error class='error'}
|
||||
{/if}
|
||||
{if $confirmation}
|
||||
{if isset($confirmation) && $confirmation}
|
||||
{include file="{$htmlcontent.admin_tpl_path}messages.tpl" id="main" text=$confirmation class='conf'}
|
||||
{/if}
|
||||
|
||||
<!-- New -->
|
||||
{include file="{$htmlcontent.admin_tpl_path}new.tpl"}
|
||||
<!-- Slides -->
|
||||
{include file="{$htmlcontent.admin_tpl_path}items.tpl"}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -9,7 +9,7 @@
|
||||
<div id="items-{$lang}" class="lang-content" style="display:{if $lang == $htmlitems.lang.default.id_lang}block{else}none{/if};">
|
||||
{foreach name=hooks from=$langItems key=hook item=hookItems}
|
||||
|
||||
<h4 class="hook-title">{l s='Hook' mod='tmhtmlcontent'} "{$hook}"</h4>
|
||||
<h4 class="hook-title">{l s='Hook' mod='themeconfigurator'} "{$hook}"</h4>
|
||||
{if $hookItems}
|
||||
<ul id="items">
|
||||
{foreach name=items from=$hookItems item=hItem}
|
||||
@@ -17,37 +17,37 @@
|
||||
<span class="item-order">{if $hItem.item_order le 9}0{/if}{$hItem.item_order}</span>
|
||||
<!--<i class="icon-sort"></i>-->
|
||||
<span class="item-title">{$hItem.title}</span>
|
||||
<span class="button btn btn-default button-edit pull-right"><i class="icon-edit"></i>{l s='Edit' mod='tmhtmlcontent'}</span>
|
||||
<span class="button btn btn-default button-close pull-right"><i class="icon-remove"></i>{l s='Close' mod='tmhtmlcontent'}</span>
|
||||
<span class="button btn btn-default button-edit pull-right"><i class="icon-edit"></i>{l s='Edit' mod='themeconfigurator'}</span>
|
||||
<span class="button btn btn-default button-close pull-right"><i class="icon-remove"></i>{l s='Close' mod='themeconfigurator'}</span>
|
||||
|
||||
<div class="item-container">
|
||||
<form method="post" action="{$htmlitems.postAction}" enctype="multipart/form-data" class="item-form defaultForm form-horizontal">
|
||||
<input type="hidden" name="lang_id" value="{$lang}" />
|
||||
<input type="hidden" name="id_lang" value="{$lang}" />
|
||||
<input type="hidden" name="item_id" value="{$hItem.id_item}" />
|
||||
<input type="hidden" name="item_order" value="{$hItem.item_order}" />
|
||||
<div class="image-display item-field form-group">
|
||||
<img src="{$module_dir}images/{$hItem.image}" alt="" title="" style="width:{$hItem.image_w}px; height:{$hItem.image_h}px;{if !$hItem.image} display:none;{/if}" class="preview" />
|
||||
</div>
|
||||
<div class="active item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Active' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Active' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="checkbox" name="item_active" value="1"{if $hItem.active == 1} checked="checked"{/if} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="title item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Title' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Title' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="text" name="item_title" size="48" value="{$hItem.title}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="title_use item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Use title in front' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Use title in front' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="checkbox" name="item_title_use" value="1"{if $hItem.title_use == 1} checked="checked"{/if} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="hook item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Hook' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Hook' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<select name="item_hook" default="home">
|
||||
<option value="home"{if $hItem.hook == 'home'} selected="selected"{/if}>home</option>
|
||||
@@ -59,45 +59,45 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="image item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Image' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Image' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="file" name="item_img" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="image_w item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Image width' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Image width' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input name="item_img_w" type="text" maxlength="4" size="4" value="{$hItem.image_w}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="image_h item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Image height' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Image height' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input name="item_img_h" type="text" maxlength="4" size="4" value="{$hItem.image_h}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="url item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='URL' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='URL' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="text" name="item_url" size="48" value="{$hItem.url}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="target item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Target blank' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Target blank' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="checkbox" name="item_target" value="1"{if $hItem.target == 1} checked="checked"{/if} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="html item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='HTML' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='HTML' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<textarea name="item_html" cols="65" rows="12">{$hItem.html}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-lg-9 col-lg-offset-3">
|
||||
<button type="submit" name="removeItem" class="button btn btn-default button-remove" onClick="this.form.submit();"><i class="icon-remove-sign"></i>{l s='Remove' mod='tmhtmlcontent'}</button>
|
||||
<button type="submit" name="updateItem" class="button btn btn-default button-save" onClick="this.form.submit();"><i class="icon-save"></i>{l s='Save' mod='tmhtmlcontent'}</button>
|
||||
<button type="submit" name="removeItem" class="button btn btn-default button-remove" onClick="this.form.submit();"><i class="icon-remove-sign"></i>{l s='Remove' mod='themeconfigurator'}</button>
|
||||
<button type="submit" name="updateItem" class="button btn btn-default button-save" onClick="this.form.submit();"><i class="icon-save"></i>{l s='Save' mod='themeconfigurator'}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -107,7 +107,7 @@
|
||||
</ul>
|
||||
{else}
|
||||
<div class="item">
|
||||
{l s='No items available' mod='tmhtmlcontent'}
|
||||
{l s='No items available' mod='themeconfigurator'}
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
@@ -1,12 +1,12 @@
|
||||
<div class="new-item">
|
||||
<div class="form-group clearfix">
|
||||
<span class="button btn btn-default new-item"><i class="icon-plus-sign"></i>{l s='Add item' mod='tmhtmlcontent'}</span>
|
||||
<span class="button btn btn-default new-item"><i class="icon-plus-sign"></i>{l s='Add item' mod='themeconfigurator'}</span>
|
||||
</div>
|
||||
<div class="item-container">
|
||||
<form method="post" action="{$htmlitems.postAction}" enctype="multipart/form-data" class="item-form defaultForm form-horizontal">
|
||||
<div class="panel">
|
||||
<div class="language item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Language' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Language' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" >
|
||||
{foreach from=$htmlitems.lang.all item=lang}
|
||||
@@ -19,21 +19,21 @@
|
||||
<li id="lang-{$lang.id_lang}" class="new-lang-flag"><a href="javascript:hideOtherLanguage({$lang.id_lang});">{$lang.name}</a></li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
<input type="hidden" id="lang-id" name="lang_id" value="{$htmlitems.lang.default.id_lang}" />
|
||||
<input type="hidden" id="lang-id" name="id_lang" value="{$htmlitems.lang.default.id_lang}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="title item-field form-group">
|
||||
<label class="control-label col-lg-3 ">{l s='Title' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3 ">{l s='Title' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input class="form-control" type="text" name="item_title" size="48" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="title_use item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Use title in front' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Use title in front' mod='themeconfigurator'}</label>
|
||||
<input type="checkbox" name="item_title_use" value="1" />
|
||||
</div>
|
||||
<div class="hook item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Hook' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Hook' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<select class="form-control" name="item_hook" default="home">
|
||||
<option value="home">home</option>
|
||||
@@ -45,44 +45,44 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="image item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Image' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Image' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="file" name="item_img" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="image_w item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Image width' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Image width' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input name="item_img_w" type="text" maxlength="4" size="4" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="image_h item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Image height' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Image height' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input name="item_img_h" type="text" maxlength="4" size="4" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="url item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='URL' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='URL' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="text" name="item_url" size="48" value="http://" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="target item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='Target blank' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='Target blank' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="checkbox" name="item_target" value="1" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="html item-field form-group">
|
||||
<label class="control-label col-lg-3">{l s='HTML' mod='tmhtmlcontent'}</label>
|
||||
<label class="control-label col-lg-3">{l s='HTML' mod='themeconfigurator'}</label>
|
||||
<div class="col-lg-7">
|
||||
<textarea name="item_html" cols="65" rows="12"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-lg-9 col-lg-offset-3">
|
||||
<button type="submit" name="newItem" class="button-save btn btn-default" onClick="this.form.submit();">{l s='Save' mod='tmhtmlcontent'}</button>
|
||||
<button type="submit" name="newItem" class="button-save btn btn-default" onClick="this.form.submit();">{l s='Save' mod='themeconfigurator'}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,7 +1,7 @@
|
||||
{if isset($htmlitems.items) && $htmlitems.items}
|
||||
<div id="htmlcontent_home">
|
||||
{if isset($htmlitems) && $htmlitems}
|
||||
<div id="htmlcontent_{$hook}">
|
||||
<ul class="htmlcontent-home clearfix row">
|
||||
{foreach name=items from=$htmlitems.items item=hItem}
|
||||
{foreach name=items from=$htmlitems item=hItem}
|
||||
<li class="htmlcontent-item col-xs-4">
|
||||
{if $hItem.url}
|
||||
<a href="{$hItem.url}" class="item-link"{if $hItem.target == 1} target="_blank"{/if}>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>tmhtmlcontent</name>
|
||||
<displayName><![CDATA[TM HTML content]]></displayName>
|
||||
<version><![CDATA[1.0]]></version>
|
||||
<description><![CDATA[]]></description>
|
||||
<author><![CDATA[TemplateMonster]]></author>
|
||||
<tab><![CDATA[other]]></tab>
|
||||
<is_configurable>1</is_configurable>
|
||||
<need_instance>1</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
|
Before Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 136 KiB |
|
Before Width: | Height: | Size: 137 KiB |
|
Before Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 140 KiB |
|
Before Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 121 KiB |
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
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;
|
||||
@@ -1,387 +0,0 @@
|
||||
<?php
|
||||
if(!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class TmHtmlContent extends Module {
|
||||
|
||||
protected $maxImageSize = 1048576;
|
||||
private $_html = '';
|
||||
protected $_defaultLanguage;
|
||||
protected $_languages;
|
||||
|
||||
public function __construct() {
|
||||
$this->name = 'tmhtmlcontent'; // Defines module name
|
||||
$this->tab = 'other'; // Defines module tab name/module category in the admin panel
|
||||
$this->author = 'TemplateMonster'; // Defines module author
|
||||
$this->version = '1.0'; // Defines module version
|
||||
$this->secure_key = Tools::encrypt($this->name);
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->_defaultLanguage = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT'));
|
||||
$this->_languages = Language::getLanguages();
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('TM HTML content');
|
||||
$this->desctiption = $this->l('Module for HTML content with images and links.');
|
||||
|
||||
// Paths
|
||||
$this->module_path = _PS_MODULE_DIR_.$this->name.'/';
|
||||
$this->uploads_path = _PS_MODULE_DIR_.$this->name.'/images/';
|
||||
$this->admin_tpl_path = _PS_MODULE_DIR_.$this->name.'/views/templates/admin/';
|
||||
$this->hooks_tpl_path = _PS_MODULE_DIR_.$this->name.'/views/templates/hooks/';
|
||||
}
|
||||
|
||||
private function installDB() {
|
||||
|
||||
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'tmhtmlcontent`');
|
||||
|
||||
if (!Db::getInstance()->Execute('
|
||||
CREATE TABLE `'._DB_PREFIX_.'tmhtmlcontent` (
|
||||
`id_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_shop` int(10) unsigned NOT NULL,
|
||||
`id_lang` int(10) unsigned NOT NULL,
|
||||
`item_order` int(10) unsigned NOT NULL,
|
||||
`title` VARCHAR(100),
|
||||
`title_use` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
||||
`hook` VARCHAR(100),
|
||||
`url` VARCHAR(100),
|
||||
`target` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
|
||||
`image` VARCHAR(100),
|
||||
`image_w` VARCHAR(10),
|
||||
`image_h` VARCHAR(10),
|
||||
`html` TEXT,
|
||||
`active` tinyint(1) unsigned NOT NULL DEFAULT \'1\',
|
||||
PRIMARY KEY (`id_item`)
|
||||
) ENGINE = '._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;'))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function install() {
|
||||
/* Adds Module */
|
||||
if (!parent::install() ||
|
||||
$this->installDB() &&
|
||||
!$this->registerHook('displayHeader') ||
|
||||
!$this->registerHook('displayTop') ||
|
||||
!$this->registerHook('displayLeftColumn') ||
|
||||
!$this->registerHook('displayRightColumn') ||
|
||||
!$this->registerHook('displayHome') ||
|
||||
!$this->registerHook('displayFooter') ||
|
||||
!$this->registerHook('displayBackOfficeHeader'))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function uninstall() {
|
||||
|
||||
$images = Db::getInstance()->ExecuteS('SELECT image FROM `'._DB_PREFIX_.'tmhtmlcontent`');
|
||||
foreach ($images as $image)
|
||||
$this->_deleteImages($image);
|
||||
|
||||
|
||||
if (!Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'tmhtmlcontent`') OR
|
||||
!parent::uninstall())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getContent() {
|
||||
$this->context->smarty->assign('error', 0);
|
||||
$this->context->smarty->assign('confirmation', 0);
|
||||
|
||||
if (Tools::isSubmit('newItem')){
|
||||
$this->_addItem();
|
||||
} elseif (Tools::isSubmit('updateItem')){
|
||||
$this->_updateItem();
|
||||
} elseif (Tools::isSubmit('removeItem')) {
|
||||
$this->_removeItem();
|
||||
}
|
||||
return $this->_displayForm();
|
||||
}
|
||||
|
||||
private function _displayForm() {
|
||||
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$items = array();
|
||||
|
||||
$this->context->smarty->assign('htmlcontent', array(
|
||||
'admin_tpl_path' => $this->admin_tpl_path,
|
||||
'hooks_tpl_path' => $this->hooks_tpl_path,
|
||||
|
||||
'info' => array(
|
||||
'module' => $this->name,
|
||||
'name' => $this->displayName,
|
||||
'version' => $this->version,
|
||||
'psVersion' => _PS_VERSION_,
|
||||
'context' => (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 0) ? 1 : ($this->context->shop->getTotalShops() != 1) ? $this->context->shop->getContext() : 1
|
||||
)
|
||||
));
|
||||
|
||||
foreach ($this->_languages as $language) {
|
||||
$hooks[$language['id_lang']] = array('home', 'top', 'left', 'right', 'footer');
|
||||
foreach ($hooks[$language['id_lang']] as $hook) {
|
||||
$items[$language['id_lang']][$hook] = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_shop = '.$id_shop.' AND id_lang = '.$language['id_lang'].' AND hook = \''.$hook.'\' ORDER BY item_order ASC');
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('htmlitems', array(
|
||||
'items' => $items,
|
||||
'lang' => array(
|
||||
'default' => $this->_defaultLanguage,
|
||||
'all' => $this->_languages,
|
||||
'lang_dir' => _THEME_LANG_DIR_,
|
||||
'user' => $this->context->language->id
|
||||
),
|
||||
'postAction' => 'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&tab_module=other&module_name='.$this->name.'',
|
||||
'id_shop' => $id_shop
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/admin/admin.tpl');
|
||||
}
|
||||
|
||||
|
||||
private function _addItem() {
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$lastOrder = Db::getInstance()->ExecuteS('SELECT item_order FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_shop = '.$id_shop.' AND id_lang = '.(int)Tools::getValue('lang_id').' AND hook = \''.Tools::getValue('item_hook').'\' ORDER BY item_order DESC LIMIT 1');
|
||||
$currentOrder = ($lastOrder) ? $lastOrder[0]['item_order']+1 : 1 ;
|
||||
|
||||
$image_w = (is_numeric(Tools::getValue('item_img_w'))) ? intval(Tools::getValue('item_img_w')) : '';
|
||||
$image_h = (is_numeric(Tools::getValue('item_img_h'))) ? intval(Tools::getValue('item_img_h')) : '';
|
||||
|
||||
if(!empty($_FILES['item_img']['name'])){
|
||||
$image = $this->_uploadImage($_FILES['item_img'], $image_w, $image_h);
|
||||
if(empty($image))
|
||||
return false;
|
||||
} else {
|
||||
$image = '';
|
||||
$image_w = '';
|
||||
$image_h = '';
|
||||
}
|
||||
|
||||
$insert = Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'tmhtmlcontent` (
|
||||
`id_shop`, `id_lang`, `item_order`, `title`, `title_use`, `hook`, `url`, `target`, `image`, `image_w`, `image_h`, `html`, `active`
|
||||
) VALUES (
|
||||
\''.$id_shop.'\',
|
||||
\''.(int)Tools::getValue('lang_id').'\',
|
||||
\''.$currentOrder.'\',
|
||||
\''.Tools::getValue('item_title').'\',
|
||||
\''.(int)Tools::getValue('item_title_use').'\',
|
||||
\''.Tools::getValue('item_hook').'\',
|
||||
\''.Tools::getValue('item_url').'\',
|
||||
\''.(int)Tools::getValue('item_target').'\',
|
||||
\''.$image.'\',
|
||||
\''.$image_w.'\',
|
||||
\''.$image_h.'\',
|
||||
\''.str_replace("'", "´", Tools::getValue('item_html')).'\',
|
||||
1)
|
||||
');
|
||||
|
||||
if(!$insert){
|
||||
$this->_deleteImages($image);
|
||||
$this->context->smarty->assign('error', $this->l('An error occured while saving data.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('confirmation', $this->l('New item added successfull.'));
|
||||
}
|
||||
|
||||
private function _updateItem() {
|
||||
|
||||
$newImage = '';
|
||||
|
||||
$image_w = (is_numeric(Tools::getValue('item_img_w'))) ? intval(Tools::getValue('item_img_w')) : '';
|
||||
$image_h = (is_numeric(Tools::getValue('item_img_h'))) ? intval(Tools::getValue('item_img_h')) : '';
|
||||
|
||||
if(!empty($_FILES['item_img']['name'])){
|
||||
if ($oldImage = Db::getInstance()->ExecuteS('SELECT image FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_item = '.(int)Tools::getValue('item_id')))
|
||||
$this->_deleteImages($oldImage[0]);
|
||||
|
||||
$image = $this->_uploadImage($_FILES['item_img'], $image_w, $image_h);
|
||||
if(empty($image))
|
||||
return false;
|
||||
$newImage = 'image = \''.$image.'\',';
|
||||
} else {
|
||||
$image_w = '';
|
||||
$image_h = '';
|
||||
}
|
||||
$update = Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'tmhtmlcontent` SET
|
||||
title = \''.Tools::getValue('item_title').'\',
|
||||
title_use = \''.(int)Tools::getValue('item_title_use').'\',
|
||||
hook = \''.Tools::getValue('item_hook').'\',
|
||||
url = \''.Tools::getValue('item_url').'\',
|
||||
target = \''.(int)Tools::getValue('item_target').'\',
|
||||
'.$newImage.'
|
||||
image_w = \''.$image_w.'\',
|
||||
image_h = \''.$image_h.'\',
|
||||
active = \''.(int)Tools::getValue('item_active').'\',
|
||||
html = \''.str_replace("'", "´", Tools::getValue('item_html')).'\'
|
||||
WHERE id_item = '.(int)Tools::getValue('item_id'));
|
||||
|
||||
if(!$update){
|
||||
if ($newImage = Db::getInstance()->ExecuteS('SELECT image FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_item = '.(int)Tools::getValue('item_id')))
|
||||
$this->_deleteImages($oldImage[0]);
|
||||
$this->context->smarty->assign('error', $this->l('An error occured while saving data.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('confirmation', $this->l('Saved succsessfull.'));
|
||||
|
||||
}
|
||||
|
||||
public function _removeItem() {
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
if ($delImage = Db::getInstance()->ExecuteS('SELECT image FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_item = '.(int)Tools::getValue('item_id')))
|
||||
$this->_deleteImages($delImage[0]);
|
||||
|
||||
Db::getInstance()->delete(_DB_PREFIX_.'tmhtmlcontent', 'id_item = '.(int)Tools::getValue('item_id'));
|
||||
|
||||
if(Db::getInstance()->Affected_Rows() == 1){
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'tmhtmlcontent`
|
||||
SET item_order = item_order-1
|
||||
WHERE (
|
||||
item_order > '.Tools::getValue('item_order').' AND
|
||||
id_shop = '.$id_shop.' AND
|
||||
hook = \''.Tools::getValue('item_hook').'\')
|
||||
');
|
||||
|
||||
$this->context->smarty->assign('confirmation', $this->l('Deleted succsessfull.'));
|
||||
}else{
|
||||
$this->context->smarty->assign('error', $this->l('Cant delete slide data from database.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _uploadImage($image, $image_w = '', $image_h = '') {
|
||||
/* Uploads image */
|
||||
|
||||
$type = @strtolower(substr(strrchr($image['name'], '.'), 1));
|
||||
$imagesize = array();
|
||||
$imagesize = @getimagesize($image['tmp_name']);
|
||||
Configuration::set('PS_IMAGE_QUALITY','png_all');
|
||||
$salt = sha1(microtime());
|
||||
|
||||
if (isset($image) &&
|
||||
isset($image['tmp_name']) &&
|
||||
!empty($image['tmp_name']) &&
|
||||
!empty($imagesize) &&
|
||||
in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) &&
|
||||
in_array($type, array('jpg', 'gif', 'jpeg', 'png')))
|
||||
{
|
||||
$temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
|
||||
|
||||
if ($error = ImageManager::validateUpload($image))
|
||||
$errors[] = $error;
|
||||
elseif (!$temp_name || !move_uploaded_file($image['tmp_name'], $temp_name))
|
||||
return false;
|
||||
elseif (ImageManager::resize($temp_name, dirname(__FILE__).'/images/'.Tools::encrypt($image['name'].$salt).'.'.$type, $image_w, $image_h))
|
||||
return Tools::encrypt($image['name'].$salt).'.'.$type;
|
||||
else
|
||||
$this->context->smarty->assign('error', $this->l('An error occurred during the image upload.'));
|
||||
if (isset($temp_name))
|
||||
@unlink($temp_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _deleteImages($image) {
|
||||
if ($image && $image['image']!='' && is_file($this->uploads_path.$image['image']))
|
||||
unlink($this->uploads_path.$image['image']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function hookDisplayBackOfficeHeader() {
|
||||
// Check if module is loaded
|
||||
if (Tools::getValue('configure') != $this->name)
|
||||
return false;
|
||||
|
||||
// CSS
|
||||
$this->context->controller->addCSS($this->_path.'views/css/admin.css');
|
||||
// JS
|
||||
$this->context->controller->addJquery();
|
||||
$this->context->controller->addJS($this->_path.'views/js/admin.js');
|
||||
}
|
||||
|
||||
|
||||
public function hookdisplayHeader($params) {
|
||||
$this->context->controller->addCss($this->_path.'views/css/hooks.css', 'all');
|
||||
}
|
||||
|
||||
|
||||
public function hookDisplayTop() {
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$id_lang = $this->context->language->id;
|
||||
$hook_name = 'top';
|
||||
$items = array();
|
||||
$items = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_shop = '.$id_shop.' AND id_lang = '.$id_lang.' AND hook = \''.$hook_name.'\' AND active = 1 ORDER BY item_order ASC');
|
||||
|
||||
$this->context->smarty->assign('htmlitems', array(
|
||||
'items' => $items
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/hooks/top.tpl');
|
||||
}
|
||||
|
||||
|
||||
public function hookDisplayHome() {
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$id_lang = $this->context->language->id;
|
||||
$hook_name = 'home';
|
||||
$items = array();
|
||||
$items = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_shop = '.$id_shop.' AND id_lang = '.$id_lang.' AND hook = \''.$hook_name.'\' AND active = 1 ORDER BY item_order ASC');
|
||||
|
||||
$this->context->smarty->assign('htmlitems', array(
|
||||
'items' => $items
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/hooks/home.tpl');
|
||||
}
|
||||
|
||||
public function hookDisplayLeftColumn() {
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$id_lang = $this->context->language->id;
|
||||
$hook_name = 'left';
|
||||
$items = array();
|
||||
$items = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_shop = '.$id_shop.' AND id_lang = '.$id_lang.' AND hook = \''.$hook_name.'\' AND active = 1 ORDER BY item_order ASC');
|
||||
|
||||
$this->context->smarty->assign('htmlitems', array(
|
||||
'items' => $items
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/hooks/left.tpl');
|
||||
}
|
||||
|
||||
public function hookDisplayRightColumn() {
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$id_lang = $this->context->language->id;
|
||||
$hook_name = 'right';
|
||||
$items = array();
|
||||
$items = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_shop = '.$id_shop.' AND id_lang = '.$id_lang.' AND hook = \''.$hook_name.'\' AND active = 1 ORDER BY item_order ASC');
|
||||
|
||||
$this->context->smarty->assign('htmlitems', array(
|
||||
'items' => $items
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/hooks/right.tpl');
|
||||
}
|
||||
|
||||
public function hookDisplayFooter() {
|
||||
$id_shop = (int)$this->context->shop->id;
|
||||
$id_lang = $this->context->language->id;
|
||||
$hook_name = 'footer';
|
||||
$items = array();
|
||||
$items = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'tmhtmlcontent` WHERE id_shop = '.$id_shop.' AND id_lang = '.$id_lang.' AND hook = \''.$hook_name.'\' AND active = 1 ORDER BY item_order ASC');
|
||||
|
||||
$this->context->smarty->assign('htmlitems', array(
|
||||
'items' => $items
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/hooks/footer.tpl');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
@@ -1,27 +0,0 @@
|
||||
{if isset($htmlitems.items) && $htmlitems.items}
|
||||
<div id="htmlcontent_footer">
|
||||
<ul class="htmlcontent-home clearfix row">
|
||||
{foreach name=items from=$htmlitems.items item=hItem}
|
||||
<li class="htmlcontent-item col-xs-4">
|
||||
{if $hItem.url}
|
||||
<a href="{$hItem.url}" class="item-link"{if $hItem.target == 1} target="_blank"{/if}>
|
||||
{/if}
|
||||
{if $hItem.image}
|
||||
<img src="{$module_dir}images/{$hItem.image}" class="item-img" alt="" />
|
||||
{/if}
|
||||
{if $hItem.title && $hItem.title_use == 1}
|
||||
<h3 class="item-title">{$hItem.title}</h3>
|
||||
{/if}
|
||||
{if $hItem.html}
|
||||
<div class="item-html">
|
||||
{$hItem.html} <i class="icon-double-angle-right"></i>
|
||||
</div>
|
||||
{/if}
|
||||
{if $hItem.url}
|
||||
</a>
|
||||
{/if}
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,27 +0,0 @@
|
||||
{if isset($htmlitems.items) && $htmlitems.items}
|
||||
<div id="htmlcontent_left">
|
||||
<ul class="htmlcontent-home clearfix row">
|
||||
{foreach name=items from=$htmlitems.items item=hItem}
|
||||
<li class="htmlcontent-item span4">
|
||||
{if $hItem.url}
|
||||
<a href="{$hItem.url}" class="item-link"{if $hItem.target == 1} target="_blank"{/if}>
|
||||
{/if}
|
||||
{if $hItem.image}
|
||||
<img src="{$module_dir}images/{$hItem.image}" class="item-img" alt="" />
|
||||
{/if}
|
||||
{if $hItem.title && $hItem.title_use == 1}
|
||||
<h3 class="item-title">{$hItem.title}</h3>
|
||||
{/if}
|
||||
{if $hItem.html}
|
||||
<div class="item-html">
|
||||
{$hItem.html} <i class="icon-double-angle-right"></i>
|
||||
</div>
|
||||
{/if}
|
||||
{if $hItem.url}
|
||||
</a>
|
||||
{/if}
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,27 +0,0 @@
|
||||
{if isset($htmlitems.items) && $htmlitems.items}
|
||||
<div id="htmlcontent_right">
|
||||
<ul class="htmlcontent-home clearfix row">
|
||||
{foreach name=items from=$htmlitems.items item=hItem}
|
||||
<li class="htmlcontent-item col-xs-4">
|
||||
{if $hItem.url}
|
||||
<a href="{$hItem.url}" class="item-link"{if $hItem.target == 1} target="_blank"{/if}>
|
||||
{/if}
|
||||
{if $hItem.image}
|
||||
<img src="{$module_dir}images/{$hItem.image}" class="item-img" alt="" />
|
||||
{/if}
|
||||
{if $hItem.title && $hItem.title_use == 1}
|
||||
<h3 class="item-title">{$hItem.title}</h3>
|
||||
{/if}
|
||||
{if $hItem.html}
|
||||
<div class="item-html">
|
||||
{$hItem.html} <i class="icon-double-angle-right"></i>
|
||||
</div>
|
||||
{/if}
|
||||
{if $hItem.url}
|
||||
</a>
|
||||
{/if}
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,27 +0,0 @@
|
||||
{if isset($htmlitems.items) && $htmlitems.items}
|
||||
<div id="htmlcontent_top">
|
||||
<ul class="htmlcontent-home clearfix row">
|
||||
{foreach name=items from=$htmlitems.items item=hItem}
|
||||
<li class="htmlcontent-item col-xs-4">
|
||||
{if $hItem.url}
|
||||
<a href="{$hItem.url}" class="item-link"{if $hItem.target == 1} target="_blank"{/if}>
|
||||
{/if}
|
||||
{if $hItem.image}
|
||||
<img src="{$module_dir}images/{$hItem.image}" class="item-img" alt="" />
|
||||
{/if}
|
||||
{if $hItem.title && $hItem.title_use == 1}
|
||||
<h3 class="item-title">{$hItem.title}</h3>
|
||||
{/if}
|
||||
{if $hItem.html}
|
||||
<div class="item-html">
|
||||
{$hItem.html} <i class="icon-double-angle-right"></i>
|
||||
</div>
|
||||
{/if}
|
||||
{if $hItem.url}
|
||||
</a>
|
||||
{/if}
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||