Add module advslider
This commit is contained in:
parent
719b0aa743
commit
e54b05cd03
137
modules/advslider/advslider.php
Normal file
137
modules/advslider/advslider.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_CAN_LOAD_FILES_'))
|
||||
exit;
|
||||
|
||||
include_once(dirname(__FILE__) . '/classes/AdvSlide.php');
|
||||
|
||||
class AdvSlider extends Module
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'advslider';
|
||||
$this->tab = 'front_office_features';
|
||||
$this->version = '1.0';
|
||||
$this->author = 'Antadis';
|
||||
$this->need_instance = 0;
|
||||
|
||||
$this->bootstrap = true;
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Slider avancé');
|
||||
$this->description = $this->l('Gestion du slider');
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
$sql[] =
|
||||
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advslider` (
|
||||
`id_slide` int(10) unsigned NOT NULL auto_increment,
|
||||
`position` INT(11) UNSIGNED NOT NULL default 0,
|
||||
`active` INT(11) UNSIGNED NOT NULL default 1,
|
||||
`light` INT(11) UNSIGNED NOT NULL default 1,
|
||||
PRIMARY KEY (`id_slide`)
|
||||
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
||||
|
||||
$sql[] =
|
||||
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advslider_lang` (
|
||||
`id_slide` int(10) unsigned NOT NULL,
|
||||
`id_lang` int(10) unsigned NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`subtitle` varchar(255) NOT NULL,
|
||||
`label` varchar(255) NOT NULL,
|
||||
`url` varchar(255),
|
||||
`description` TEXT,
|
||||
PRIMARY KEY (`id_slide`,`id_lang`)
|
||||
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
||||
|
||||
$sql[] =
|
||||
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advslider_shop` (
|
||||
`id_slide` int(10) unsigned NOT NULL auto_increment,
|
||||
`id_shop` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_slide`, `id_shop`)
|
||||
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
||||
|
||||
|
||||
foreach ($sql as $_sql) {
|
||||
Db::getInstance()->Execute($_sql);
|
||||
}
|
||||
|
||||
$tab = new Tab();
|
||||
$tab->class_name = 'AdminAdvSlider';
|
||||
$tab->id_parent = Tab::getCurrentParentId();
|
||||
$tab->module = $this->name;
|
||||
$languages = Language::getLanguages();
|
||||
foreach ($languages as $language) {
|
||||
$tab->name[$language['id_lang']] = 'Slider';
|
||||
}
|
||||
|
||||
$img_dir = _PS_IMG_DIR_ . 'slider';
|
||||
$folder = is_dir($img_dir);
|
||||
if (!$folder)
|
||||
{
|
||||
$folder = mkdir($img_dir, 0755, true);
|
||||
}
|
||||
|
||||
return parent::install()
|
||||
&& $tab->add()
|
||||
&& $this->registerHook('displaySlider')
|
||||
&& $this->registerHook('displayHeader')
|
||||
&& $this->registerHook('actionRefreshSlider')
|
||||
&& $folder;
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
$sql = 'DROP TABLE IF EXISTS
|
||||
`' . _DB_PREFIX_ . 'advslider_lang`,
|
||||
`' . _DB_PREFIX_ . 'advslider_shop`,
|
||||
`' . _DB_PREFIX_ . 'advslider`
|
||||
';
|
||||
|
||||
Db::getInstance()->Execute($sql);
|
||||
|
||||
$idTab = Tab::getIdFromClassName('AdminAdvSlider');
|
||||
if ($idTab) {
|
||||
$tab = new Tab($idTab);
|
||||
$tab->delete();
|
||||
}
|
||||
|
||||
return parent::uninstall();
|
||||
}
|
||||
|
||||
public function hookDisplaySlider($params)
|
||||
{
|
||||
if (!$this->isCached('advslider.tpl', $this->getCacheId())) {
|
||||
$slides = AdvSlide::getSlides();
|
||||
|
||||
if (!$slides) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->smarty->assign('slides', $slides);
|
||||
}
|
||||
|
||||
return $this->display(__FILE__, 'advslider.tpl', $this->getCacheId());
|
||||
}
|
||||
|
||||
public function hookHeader($params)
|
||||
{
|
||||
$jsFiles = $this->context->controller->js_files;
|
||||
foreach($jsFiles as $jsFile) {
|
||||
if(strpos($jsFile, 'flexslider') !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->controller->addJS($this->_path.'js/flexslider.js');
|
||||
}
|
||||
|
||||
public function hookActionRefreshSlider()
|
||||
{
|
||||
$this->_clearCache('advslider');
|
||||
}
|
||||
|
||||
}
|
184
modules/advslider/classes/AdvSlide.php
Normal file
184
modules/advslider/classes/AdvSlide.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
class AdvSlide extends ObjectModel
|
||||
{
|
||||
public $id_slide;
|
||||
public $position;
|
||||
public $active;
|
||||
|
||||
public $title;
|
||||
public $subtitle;
|
||||
public $label;
|
||||
public $url;
|
||||
public $description;
|
||||
public $light;
|
||||
|
||||
public static $definition = array(
|
||||
'table' => 'advslider',
|
||||
'primary' => 'id_slide',
|
||||
'multilang' => TRUE,
|
||||
'fields' => array(
|
||||
'id_slide' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'active' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'light' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
|
||||
// Lang fields
|
||||
'title' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName', 'size' => 255),
|
||||
'subtitle' => array('type' => self::TYPE_HTML, 'lang' => TRUE, 'validate' => 'isCleanHtml', 'size' => 255),
|
||||
'label' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName', 'size' => 255),
|
||||
'url' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isUrl', 'size' => 255),
|
||||
'description' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isCleanHtml')
|
||||
)
|
||||
);
|
||||
|
||||
public function __construct($id = NULL, $id_lang = NULL, $id_shop = NULL)
|
||||
{
|
||||
parent::__construct($id, $id_lang, $id_shop);
|
||||
|
||||
$this->image_dir = _PS_IMG_DIR_ . 'slider/';
|
||||
}
|
||||
|
||||
public function add($null_values = false, $autodate = true)
|
||||
{
|
||||
$result = parent::add($null_values, $autodate);
|
||||
Hook::exec('actionRefreshSlider');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function update($null_values = FALSE)
|
||||
{
|
||||
$result = parent::update($null_values);
|
||||
Hook::exec('actionRefreshSlider');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function delete($null_values = FALSE)
|
||||
{
|
||||
$result = parent::delete($null_values);
|
||||
Hook::exec('actionRefreshSlider');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getSlides()
|
||||
{
|
||||
$context = Context::getContext();
|
||||
|
||||
$slides = Db::getInstance()->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'advslider` adv
|
||||
JOIN `'._DB_PREFIX_.'advslider_lang` advl ON adv.`id_slide` = advl.`id_slide` AND id_lang = '. (int)$context->language->id . '
|
||||
WHERE adv.`active` = 1
|
||||
ORDER BY `position` ASC
|
||||
');
|
||||
|
||||
foreach($slides as $key => $slide) {
|
||||
if(!file_exists(_PS_IMG_DIR_ . 'slider/' . $slide['id_slide'] . '.jpg')) {
|
||||
unset($slides[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $slides;
|
||||
}
|
||||
|
||||
public function deleteImage($force_delete = false)
|
||||
{
|
||||
if (!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$imgToDelete = Tools::getValue('imgName', false);
|
||||
|
||||
if ($imgToDelete === false) {
|
||||
return parent::deleteImage($force_delete = false);
|
||||
}
|
||||
|
||||
if ($force_delete || !$this->hasMultishopEntries()) {
|
||||
/* Deleting object images and thumbnails (cache) */
|
||||
|
||||
if ($this->image_dir) {
|
||||
if (file_exists($this->image_dir.$this->id.'-'.$imgToDelete.'.'.$this->image_format)
|
||||
&& !unlink($this->image_dir.$this->id.'-'.$imgToDelete.'.'.$this->image_format)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (file_exists(_PS_TMP_IMG_DIR_.$this->def['table'].'_'.$this->id.'-'.$imgToDelete.'.'.$this->image_format)
|
||||
&& !unlink(_PS_TMP_IMG_DIR_.$this->def['table'].'_'.$this->id.'-'.$imgToDelete.'.'.$this->image_format)) {
|
||||
return false;
|
||||
}
|
||||
if (file_exists(_PS_TMP_IMG_DIR_.$this->def['table'].'_mini_'.$this->id.'-'.$imgToDelete.'.'.$this->image_format)
|
||||
&& !unlink(_PS_TMP_IMG_DIR_.$this->def['table'].'_mini_'.$this->id.'-'.$imgToDelete.'.'.$this->image_format)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function cleanPositions()
|
||||
{
|
||||
return Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'advslider`
|
||||
SET `position`= `position` - 1
|
||||
WHERE `id_slide` = '.(int)$this->id_slide.'
|
||||
AND `position` > '.(int)$this->position);
|
||||
}
|
||||
|
||||
public function updatePosition($way, $position)
|
||||
{
|
||||
$sql = 'SELECT `position`, `id_slide`
|
||||
FROM `'._DB_PREFIX_.'advslider`
|
||||
ORDER BY `position` ASC';
|
||||
if (!$res = Db::getInstance()->executeS($sql))
|
||||
return false;
|
||||
|
||||
foreach ($res as $row)
|
||||
if ((int)$row['id_slide'] == (int)$this->id_slide)
|
||||
$moved_row = $row;
|
||||
|
||||
if (!isset($moved_row) || !isset($position))
|
||||
return false;
|
||||
|
||||
// < and > statements rather than BETWEEN operator
|
||||
// since BETWEEN is treated differently according to databases
|
||||
$res = Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'advslider`
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way
|
||||
? '> '.(int)$moved_row['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$moved_row['position'].' AND `position` >= '.(int)$position)
|
||||
)
|
||||
&& Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'advslider`
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_slide`='.(int)$moved_row['id_slide']
|
||||
);
|
||||
$this->refreshPositions();
|
||||
|
||||
Hook::exec('actionRefreshSlider');
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function refreshPositions()
|
||||
{
|
||||
$sql = 'SELECT `id_slide`
|
||||
FROM `'._DB_PREFIX_.'advslider`
|
||||
ORDER BY `position` ASC';
|
||||
if (!$blocks = Db::getInstance()->executeS($sql))
|
||||
return false;
|
||||
|
||||
$pos=0;
|
||||
foreach ($blocks as $block) {
|
||||
Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'advslider`
|
||||
SET `position` = '.(int)$pos.'
|
||||
WHERE `id_slide`='.(int)$block['id_slide']);
|
||||
$pos++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
322
modules/advslider/controllers/admin/AdminAdvSlider.php
Normal file
322
modules/advslider/controllers/admin/AdminAdvSlider.php
Normal file
@ -0,0 +1,322 @@
|
||||
<?php
|
||||
include_once dirname(__FILE__).'/../../classes/AdvSlide.php';
|
||||
|
||||
class AdminAdvSliderController extends ModuleAdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'advslider';
|
||||
$this->className = 'AdvSlide';
|
||||
$this->identifier = 'id_slide';
|
||||
$this->lang = TRUE;
|
||||
$this->deleted = FALSE;
|
||||
$this->bootstrap = TRUE;
|
||||
$this->fieldImageSettings = array(
|
||||
'name' => 'image',
|
||||
'dir' => 'slider'
|
||||
);
|
||||
$this->position_identifier = 'id_slide';
|
||||
$this->_defaultOrderBy = 'position';
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->actions = array('edit', 'delete');
|
||||
|
||||
$this->fields_list = array(
|
||||
'id_slide' => array(
|
||||
'title' => 'ID',
|
||||
'width' => 25
|
||||
),
|
||||
'image_desktop' => array(
|
||||
'title' => $this->module->l('Image'),
|
||||
'image' => $this->fieldImageSettings['dir'],
|
||||
'width' => 75
|
||||
),
|
||||
'title' => array(
|
||||
'title' => $this->module->l('Titre'),
|
||||
),
|
||||
'url' => array(
|
||||
'title' => $this->module->l('Url'),
|
||||
'width' => 45,
|
||||
),
|
||||
'position' => array(
|
||||
'title' => $this->l('Position'),
|
||||
'align' => 'center',
|
||||
'position' => 'position',
|
||||
'filter_key' => 'a!position'
|
||||
)
|
||||
);
|
||||
|
||||
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL){
|
||||
$this->_join .= 'JOIN `'._DB_PREFIX_.'advslider_shop` as ashop ON a.`id_slide` = ashop.`id_slide` AND ashop.`id_shop` IN ('.implode(', ', Shop::getContextListShopID()).') ';
|
||||
$this->_group .= 'GROUP BY ashop.`id_slide`';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
parent::initPageHeaderToolbar();
|
||||
|
||||
if ($this->display != 'edit' && $this->display != 'add') {
|
||||
$this->page_header_toolbar_btn['new_link'] = array(
|
||||
'href' => self::$currentIndex.'&id_parent='.(int)Tools::getValue('id_slide').'&addadvslider&token='.$this->token,
|
||||
'desc' => $this->l('Ajouter une nouvelle slide', NULL, NULL, FALSE),
|
||||
'icon' => 'process-icon-new'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$this->fields_form = array(
|
||||
'tinymce' => TRUE,
|
||||
'legend' => array(
|
||||
'title' => $this->className,
|
||||
),
|
||||
'submit' => array(
|
||||
'name' => 'submitAdvSlider',
|
||||
'title' => $this->l('Save'),
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Titre'),
|
||||
'name' => 'title',
|
||||
'lang' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Sous-titre'),
|
||||
'name' => 'subtitle',
|
||||
'lang' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Texte foncé ?'),
|
||||
'name' => 'light',
|
||||
'required' => FALSE,
|
||||
'is_bool' => TRUE,
|
||||
'default' => 1,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'light_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'light_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Label lien'),
|
||||
'name' => 'label',
|
||||
'lang' => TRUE
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Lien'),
|
||||
'name' => 'url',
|
||||
'lang' => TRUE
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Description'),
|
||||
'name' => 'description',
|
||||
'autoload_rte' => TRUE,
|
||||
'lang' => TRUE
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Activé'),
|
||||
'name' => 'active',
|
||||
'required' => FALSE,
|
||||
'is_bool' => TRUE,
|
||||
'default' => 1,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'shop',
|
||||
'label' => $this->l('Shop'),
|
||||
'form_group_class' => 'fieldhide input_association',
|
||||
'name' => 'checkBoxShopAsso_advslider'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$obj = $this->loadObject(TRUE);
|
||||
|
||||
$image = FALSE;
|
||||
$image_url = '';
|
||||
$image_size = '';
|
||||
|
||||
$image_mobile = FALSE;
|
||||
$image_url_mobile = '';
|
||||
$image_size_mobile = '';
|
||||
|
||||
if($obj) {
|
||||
$image = _PS_IMG_DIR_ . 'slider/' . $obj->id.'.jpg';
|
||||
$image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350, $this->imageType, TRUE, TRUE);
|
||||
$image_size = file_exists($image) ? filesize($image) / 1000 : FALSE;
|
||||
|
||||
$image_mobile = _PS_IMG_DIR_ . 'slider/' . $obj->id.'-image_mobile.jpg';
|
||||
$image_url_mobile = ImageManager::thumbnail($image_mobile, $this->table.'_'.(int)$obj->id.'-image_mobile.'.$this->imageType, 350, $this->imageType, TRUE, TRUE);
|
||||
$image_size_mobile = file_exists($image_mobile) ? filesize($image_mobile) / 1000 : FALSE;
|
||||
}
|
||||
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Image'),
|
||||
'name' => 'image',
|
||||
'display_image' => TRUE,
|
||||
'lang' => TRUE,
|
||||
'required' => TRUE,
|
||||
'image' => $image_url,
|
||||
'size' => $image_size,
|
||||
'delete_url' => self::$currentIndex.'&'.$this->identifier.'='.$this->object->id.'&token='.$this->token.'&deleteImage=1'
|
||||
);
|
||||
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Image Mobile 900x900'),
|
||||
'name' => 'image_mobile',
|
||||
'display_image' => TRUE,
|
||||
'lang' => TRUE,
|
||||
'required' => TRUE,
|
||||
'image' => $image_url_mobile,
|
||||
'size' => $image_size_mobile,
|
||||
'delete_url' => self::$currentIndex.'&'.$this->identifier.'='.$this->object->id.'&token='.$this->token.'&deleteImage=1&imgName=image_mobile'
|
||||
);
|
||||
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
protected function copyFromPost(&$object, $table)
|
||||
{
|
||||
parent::copyFromPost($object, $table);
|
||||
|
||||
if(Shop::isFeatureActive()) {
|
||||
$object->id_shop_list = array();
|
||||
foreach (Tools::getValue('checkBoxShopAsso_advslider') as $id_shop => $value)
|
||||
$object->id_shop_list[] = $id_shop;
|
||||
}
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::getValue('deleteImage')) {
|
||||
$this->processForceDeleteImage();
|
||||
$this->refreshPreview();
|
||||
}
|
||||
parent::postProcess();
|
||||
|
||||
$images = array('image_mobile');
|
||||
|
||||
foreach($images as $imageName) {
|
||||
if(isset($_FILES[$imageName]) && !empty($_FILES[$imageName]['tmp_name'])) {
|
||||
$obj = $this->loadObject(TRUE);
|
||||
|
||||
$fileTemp = $_FILES[$imageName]['tmp_name'];
|
||||
$fileParts = pathinfo($_FILES[$imageName]['name']);
|
||||
|
||||
if(file_exists(_PS_IMG_DIR_.'slider/'.$obj->id.'-'.$imageName.'.jpg')) {
|
||||
unlink(_PS_IMG_DIR_.'slider/'.$obj->id.'-'.$imageName.'.jpg');
|
||||
}
|
||||
|
||||
if($fileParts['extension'] == 'jpg') {
|
||||
$res = move_uploaded_file($fileTemp, _PS_IMG_DIR_.'slider/'.$obj->id.'-'.$imageName.'.jpg');
|
||||
if(!$res) {
|
||||
$this->errors[] = sprintf(Tools::displayError('An error occured during upload of file %s'), $obj->id.'.jpg');
|
||||
}
|
||||
else {
|
||||
$this->confirmations[] = sprintf($this->l('File %s has been uploaded'), $obj->id.'.jpg');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->errors[] = sprintf(Tools::displayError('File %s have not good extension, only .jpg or .png'), $obj->id.'.jpg');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function processForceDeleteImage()
|
||||
{
|
||||
$link = $this->loadObject(TRUE);
|
||||
|
||||
if (Validate::isLoadedObject($link)) {
|
||||
$link->deleteImage(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
protected function postImage($id)
|
||||
{
|
||||
$ret = parent::postImage($id);
|
||||
$this->refreshPreview();
|
||||
|
||||
if (isset($_FILES) && count($_FILES) && $_FILES['image']['name'] != NULL && !empty($this->object->id) ) {
|
||||
return TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function refreshPreview()
|
||||
{
|
||||
$current_preview = _PS_TMP_IMG_DIR_.'advslider_mini_'.$this->object->id_slide.'_'.$this->context->shop->id.'.jpg';
|
||||
|
||||
if (file_exists($current_preview)) {
|
||||
unlink($current_preview);
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdatePositions()
|
||||
{
|
||||
$way = (int)(Tools::getValue('way'));
|
||||
$id = (int)(Tools::getValue('id'));
|
||||
$positions = Tools::getValue('slide');
|
||||
$obj = 'advslider';
|
||||
|
||||
if (is_array($positions)) {
|
||||
foreach ($positions as $position => $value) {
|
||||
$pos = explode('_', $value);
|
||||
|
||||
if (isset($pos[2]) && (int)$pos[2] === $id) {
|
||||
$menu_obj = new AdvSlide((int)$pos[2]);
|
||||
|
||||
if (Validate::isLoadedObject($menu_obj)) {
|
||||
if (isset($position) && $menu_obj->updatePosition($way, $position)) {
|
||||
echo 'ok position '.(int)$position.' for '.$obj.' '.(int)$pos[2]."\r\n";
|
||||
}
|
||||
else {
|
||||
echo '{"hasError" : true, "errors" : "Can not update '.$obj.' '.(int)$id.' to position '.(int)$position.' "}';
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo '{"hasError" : true, "errors" : "This '.$obj.' ('.(int)$id.') cannot be loaded"}';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
35
modules/advslider/index.php
Normal file
35
modules/advslider/index.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 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-2014 PrestaShop SA
|
||||
* @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;
|
5
modules/advslider/js/flexslider.js
Normal file
5
modules/advslider/js/flexslider.js
Normal file
File diff suppressed because one or more lines are too long
BIN
modules/advslider/logo.gif
Normal file
BIN
modules/advslider/logo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
modules/advslider/logo.png
Normal file
BIN
modules/advslider/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
@ -0,0 +1,69 @@
|
||||
{if strpos($name, 'multilang') === false}
|
||||
{include file='helpers/uploader/simple.tpl'}
|
||||
{else}
|
||||
{assign var=languages value=Language::getLanguages(false)}
|
||||
{if !isset($defaultFormLanguage)}
|
||||
{assign var=defaultFormLanguage value=$languages[0].id_lang}
|
||||
{/if}
|
||||
<div class="row">
|
||||
{foreach from=$languages item=language}
|
||||
{if $languages|count > 1}
|
||||
<div class="translatable-field lang-{$language.id_lang}" {if $language.id_lang != $defaultFormLanguage}style="display:none"{/if}>
|
||||
{/if}
|
||||
<div class="col-lg-6">
|
||||
|
||||
{foreach $files as $file}
|
||||
{if isset($file.image) && $file.type == 'image'}
|
||||
<div>
|
||||
{if !empty($file.image[$language['id_lang']])}
|
||||
{if Validate::isUrl($file.image[$language['id_lang']])}<img src="{$file.image[$language['id_lang']]}" class="img-thumbnail" />{else}{$file.image[$language['id_lang']]}{/if}
|
||||
{if isset($file.delete_url[$language['id_lang']])}<a href="{$file.delete_url[$language['id_lang']]}">{l s='Supprimer'}</a>{/if}
|
||||
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
|
||||
<input id="{$name}_{$language.id_lang}" type="file" name="{$name}_{$language.id_lang}" class="hide" />
|
||||
<div class="dummyfile input-group">
|
||||
<span class="input-group-addon"><i class="icon-file"></i></span>
|
||||
<input id="{$name}_{$language.id_lang}-name" type="text" class="disabled" name="filename" readonly />
|
||||
<span class="input-group-btn">
|
||||
<button id="{$name}_{$language.id_lang}-selectbutton" type="button" name="submitAddAttachments" class="btn btn-default">
|
||||
<i class="icon-folder-open"></i> {l s='Choose a file'}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{if $languages|count > 1}
|
||||
<div class="col-lg-2">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" tabindex="-1" data-toggle="dropdown">
|
||||
{$language.iso_code}
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{foreach from=$languages item=lang}
|
||||
<li><a href="javascript:hideOtherLanguage({$lang.id_lang});" tabindex="-1">{$lang.name}</a></li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
{if $languages|count > 1}
|
||||
</div>
|
||||
{/if}
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#{$name}_{$language.id_lang}-selectbutton').click(function(e){
|
||||
$('#{$name}_{$language.id_lang}').trigger('click');
|
||||
});
|
||||
$('#{$name}_{$language.id_lang}').change(function(e){
|
||||
var val = $(this).val();
|
||||
var file = val.split(/[\\/]/);
|
||||
$('#{$name}_{$language.id_lang}-name').val(file[file.length-1]);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{/foreach}
|
||||
</div>
|
||||
|
||||
{/if}
|
3
modules/advslider/views/templates/hook/advslider.tpl
Normal file
3
modules/advslider/views/templates/hook/advslider.tpl
Normal file
@ -0,0 +1,3 @@
|
||||
<!-- Block Advmenu module -->
|
||||
|
||||
<!-- /Block Advmenu module -->
|
Loading…
Reference in New Issue
Block a user