first commit
This commit is contained in:
373
modules/leoslideshow/controllers/admin/AdminLeoSlideshow.php
Normal file
373
modules/leoslideshow/controllers/admin/AdminLeoSlideshow.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Adds image, text or video to your homepage.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminLeoSlideshowController extends ModuleAdminController
|
||||
{
|
||||
protected $max_image_size = null;
|
||||
public $theme_name;
|
||||
public $img_path;
|
||||
public $img_url;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
|
||||
parent::__construct();
|
||||
$this->theme_name = LeoSlideshowHelper::getThemeName();
|
||||
$this->img_path = LeoSlideshowHelper::getImgThemeDir();
|
||||
$this->img_url = LeoSlideshowHelper::getImgThemeUrl();
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
$media_dir = $this->module->getMediaDir();
|
||||
$this->addCss(__PS_BASE_URI__.$media_dir.'css/admin/admincontroller.css', 'all');
|
||||
return parent::setMedia($isNewTheme);
|
||||
}
|
||||
|
||||
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 (($img_name = Tools::getValue('imgName', false)) !== false) {
|
||||
# module validation
|
||||
unlink($this->img_path.$img_name);
|
||||
}
|
||||
|
||||
if ($reload_slider_image = Tools::getValue('reloadSliderImage')) {
|
||||
//DONGND:: reload list image after delete
|
||||
$tpl = $this->createTemplate('imagemanager.tpl');
|
||||
$sort_by = Tools::getValue('sortBy');
|
||||
|
||||
$images = $this->getImageList($sort_by);
|
||||
$tpl->assign(array(
|
||||
'images' => $images,
|
||||
'reloadSliderImage' => $reload_slider_image,
|
||||
'link' => $this->context->link,
|
||||
));
|
||||
if ($reload_slider_image) {
|
||||
# module validation
|
||||
die(Tools::jsonEncode($tpl->fetch()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
public function importGroup()
|
||||
{
|
||||
$type = Tools::strtolower(Tools::substr(strrchr($_FILES['import_file']['name'], '.'), 1));
|
||||
|
||||
if (isset($_FILES['import_file']) && $type == 'txt' && isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) {
|
||||
include_once(_PS_MODULE_DIR_.'leoslideshow/classes/LeoSlideshowGroup.php');
|
||||
include_once(_PS_MODULE_DIR_.'leoslideshow/classes/LeoSlideshowSlide.php');
|
||||
|
||||
$content = Tools::file_get_contents($_FILES['import_file']['tmp_name']);
|
||||
$content = Tools::jsonDecode(LeoSlideshowSlide::base64Decode($content), true);
|
||||
|
||||
//DONGND:: validate if file not match
|
||||
if (!is_array($content) || !isset($content['id_leoslideshow_groups']) || $content['id_leoslideshow_groups'] == '') {
|
||||
return false;
|
||||
}
|
||||
$language_field = array('title', 'link', 'image', 'thumbnail', 'video', 'layersparams');
|
||||
$languages = Language::getLanguages();
|
||||
$lang_list = array();
|
||||
foreach ($languages as $lang) {
|
||||
# module validation
|
||||
$lang_list[$lang['iso_code']] = $lang['id_lang'];
|
||||
}
|
||||
|
||||
$override_group = Tools::getValue('override_group');
|
||||
|
||||
//override or edit
|
||||
if ($override_group && LeoSlideshowGroup::groupExists($content['id_leoslideshow_groups'])) {
|
||||
$mod_group = new LeoSlideshowGroup($content['id_leoslideshow_groups']);
|
||||
//edit group
|
||||
$mod_group = $this->setDataForGroup($mod_group, $content);
|
||||
if (!$mod_group->update()) {
|
||||
# module validation
|
||||
return false;
|
||||
}
|
||||
LeoSlideshowGroup::deleteAllSlider($content['id_leoslideshow_groups']);
|
||||
|
||||
foreach ($content['sliders'] as $slider) {
|
||||
$mod_slide = new LeoSlideshowSlide();
|
||||
foreach ($slider as $key => $val) {
|
||||
if (in_array($key, $language_field)) {
|
||||
foreach ($val as $key_lang => $val_lang) {
|
||||
# module validation
|
||||
$mod_slide->{$key}[$lang_list[$key_lang]] = $val_lang;
|
||||
}
|
||||
} else {
|
||||
# module validation
|
||||
$mod_slide->{$key} = $val;
|
||||
}
|
||||
}
|
||||
$mod_slide->id_group = $mod_group->id;
|
||||
if (isset($slider['id']) && $slider['id'] && LeoSlideshowSlide::sliderExist($slider['id'])) {
|
||||
# module validation
|
||||
$mod_slide->update();
|
||||
} else {
|
||||
# module validation
|
||||
$mod_slide->add();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$mod_group = new LeoSlideshowGroup();
|
||||
$mod_group = $this->setDataForGroup($mod_group, $content);
|
||||
$mod_group->randkey = LeoSlideshowHelper::genKey();
|
||||
if (!$mod_group->add()) {
|
||||
# module validation
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($content['sliders'] as $slider) {
|
||||
$mod_slide = new LeoSlideshowSlide();
|
||||
foreach ($slider as $key => $val) {
|
||||
if (in_array($key, $language_field)) {
|
||||
foreach ($val as $key_lang => $val_lang) {
|
||||
# module validation
|
||||
$mod_slide->{$key}[$lang_list[$key_lang]] = $val_lang;
|
||||
}
|
||||
} else {
|
||||
# module validation
|
||||
$mod_slide->{$key} = $val;
|
||||
}
|
||||
}
|
||||
$mod_slide->id_group = $mod_group->id;
|
||||
$mod_slide->id = 0;
|
||||
$mod_slide->add();
|
||||
}
|
||||
}
|
||||
//add new
|
||||
//return true;
|
||||
}
|
||||
Tools::redirectAdmin('index.php?controller=AdminModules&token='.Tools::getAdminTokenLite('AdminModules').'&configure=leoslideshow&tab_module=leotheme&module_name=leoslideshow&conf=4');
|
||||
// return false;
|
||||
}
|
||||
|
||||
public function setDataForGroup($group, $content)
|
||||
{
|
||||
$group->title = $content['title'];
|
||||
$group->id_shop = $this->context->shop->id;
|
||||
$group->hook = $content['hook'];
|
||||
$group->active = $content['active'];
|
||||
$group->params = $content['params'];
|
||||
$group->sliders = $content['sliders'];
|
||||
return $group;
|
||||
}
|
||||
/*
|
||||
* get all slider data
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* renderForm contains all necessary initialization needed for all tabs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function renderList()
|
||||
{
|
||||
$media_dir = $this->module->getMediaDir();
|
||||
$typo = Tools::getValue('typo');
|
||||
if ($typo) {
|
||||
if (file_exists(_PS_THEME_DIR_.'assets/css/modules/leoslideshow/views/css/typo/typo.css')) {
|
||||
$typo_dir = _THEME_DIR_.'assets/css/modules/leoslideshow/views/css/typo/typo.css';
|
||||
} else {
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoslideshow/views/css/typo/typo.css')) {
|
||||
$typo_dir = _THEME_DIR_.str_replace('//', '/', 'modules/leoslideshow').'/views/css/typo/typo.css';
|
||||
} else {
|
||||
$typo_dir = __PS_BASE_URI__.$media_dir.'/css/typo/typo.css';
|
||||
}
|
||||
}
|
||||
|
||||
$this->addCss($typo_dir, 'all');
|
||||
$this->addJS(__PS_BASE_URI__.$media_dir.'js/admin/jquery-ui-1.10.3.custom.min.js');
|
||||
|
||||
$content = Tools::file_get_contents($this->context->link->getMediaLink($typo_dir));
|
||||
preg_match_all('#\.tp-caption\.(\w+)\s*{\s*#', $content, $matches);
|
||||
|
||||
if (isset($matches[1])) {
|
||||
# module validation
|
||||
$captions = $matches[1];
|
||||
}
|
||||
$tpl = $this->createTemplate('typo.tpl');
|
||||
$tpl->assign(array(
|
||||
'typoDir' => $typo_dir,
|
||||
'captions' => $captions,
|
||||
'field' => Tools::getValue('field')
|
||||
));
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
//this code for select or upload IMG
|
||||
$tpl = $this->createTemplate('imagemanager.tpl');
|
||||
$sort_by = Tools::getValue('sortBy');
|
||||
$reload_slider_image = Tools::getValue('reloadSliderImage');
|
||||
$images = $this->getImageList($sort_by);
|
||||
$tpl->assign(array(
|
||||
'images' => $images,
|
||||
'reloadSliderImage' => $reload_slider_image,
|
||||
));
|
||||
if ($reload_slider_image) {
|
||||
# module validation
|
||||
die(Tools::jsonEncode($tpl->fetch()));
|
||||
}
|
||||
|
||||
$image_uploader = new HelperImageUploader('file');
|
||||
$image_uploader->setSavePath($this->img_path);
|
||||
$url = Context::getContext()->link->getAdminLink('AdminLeoSlideshow').'&ajax=1&action=addSliderImage';
|
||||
$image_uploader->setMultiple(true)->setUseAjax(true)->setUrl($url);
|
||||
|
||||
$tpl->assign(array(
|
||||
'countImages' => count($images),
|
||||
'images' => $images,
|
||||
'max_image_size' => $this->max_image_size / 1024 / 1024,
|
||||
'image_uploader' => $image_uploader->render(),
|
||||
'imgManUrl' => Context::getContext()->link->getAdminLink('AdminLeoSlideshow'),
|
||||
'token' => $this->token,
|
||||
'imgUploadDir' => $this->img_path
|
||||
));
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
public function getImageList($sort_by)
|
||||
{
|
||||
$path = $this->img_path;
|
||||
$this->createFolderUpImage();
|
||||
$images = glob($path.'{*.jpeg,*.JPEG,*.jpg,*.JPG,*.gif,*.GIF,*.png,*.PNG}', GLOB_BRACE);
|
||||
if (!$images) {
|
||||
# module validation
|
||||
$images = $this->getAllImage($path);
|
||||
}
|
||||
|
||||
if ($sort_by == 'name_desc') {
|
||||
# module validation
|
||||
rsort($images);
|
||||
}
|
||||
|
||||
if ($sort_by == 'date' || $sort_by == 'date_desc') {
|
||||
# module validation
|
||||
array_multisort(array_map('filemtime', $images), SORT_NUMERIC, SORT_DESC, $images);
|
||||
}
|
||||
if ($sort_by == 'date_desc') {
|
||||
# module validation
|
||||
rsort($images);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($images as &$file) {
|
||||
$file_info = pathinfo($file);
|
||||
$result[] = array('name' => $file_info['basename'], 'link' => $this->img_url.$file_info['basename']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getAllImage($path)
|
||||
{
|
||||
$images = array();
|
||||
foreach (scandir($path) as $d) {
|
||||
if (preg_match('/(.*)\.(jpg|png|gif|jpeg)$/', $d)) {
|
||||
# module validation
|
||||
$images[] = $d;
|
||||
}
|
||||
}
|
||||
return $images;
|
||||
}
|
||||
|
||||
public function ajaxProcessaddSliderImage()
|
||||
{
|
||||
if (isset($_FILES['file'])) {
|
||||
$image_uploader = new HelperUploader('file');
|
||||
$this->createFolderUpImage();
|
||||
$image_uploader->setSavePath($this->img_path);
|
||||
$image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg'))->setMaxSize($this->max_image_size);
|
||||
$files = $image_uploader->process();
|
||||
$total_errors = array();
|
||||
|
||||
foreach ($files as &$file) {
|
||||
$errors = array();
|
||||
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
|
||||
if (!ImageManager::checkImageMemoryLimit($file['save_path'])) {
|
||||
# module validation
|
||||
$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)) {
|
||||
# module validation
|
||||
$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)) {
|
||||
# module validation
|
||||
$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()));
|
||||
}
|
||||
}
|
||||
|
||||
public function createFolderUpImage()
|
||||
{
|
||||
if (!is_dir($this->img_path)) {
|
||||
mkdir($this->img_path, 0755, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
* OVERRIDE CORE
|
||||
*/
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
if (count($this->errors) <= 0) {
|
||||
if (($module_instance = Module::getInstanceByName('leoslideshow'))) {
|
||||
if (!$module_instance->access('configure')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to configure this.', array(), 'Admin.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Adds image, text or video to your homepage.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminLeoSlideshowMenuModuleController extends ModuleAdminControllerCore
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Configuration::get('LEOSLIDESHOW_GROUP_DE') && Configuration::get('LEOSLIDESHOW_GROUP_DE') != '') {
|
||||
$url = 'index.php?controller=adminmodules&configure=leoslideshow&editgroup=1&id_group='.Configuration::get('LEOSLIDESHOW_GROUP_DE').'&tab_module=front_office_features&module_name=leoslideshow&token='.Tools::getAdminTokenLite('AdminModules');
|
||||
} else {
|
||||
$url = 'index.php?controller=adminmodules&configure=leoslideshow&tab_module=front_office_features&module_name=leoslideshow&token='.Tools::getAdminTokenLite('AdminModules');
|
||||
}
|
||||
Tools::redirectAdmin($url);
|
||||
}
|
||||
}
|
||||
35
modules/leoslideshow/controllers/admin/index.php
Normal file
35
modules/leoslideshow/controllers/admin/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;
|
||||
35
modules/leoslideshow/controllers/front/index.php
Normal file
35
modules/leoslideshow/controllers/front/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;
|
||||
437
modules/leoslideshow/controllers/front/preview.php
Normal file
437
modules/leoslideshow/controllers/front/preview.php
Normal file
@@ -0,0 +1,437 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Adds image, text or video to your homepage.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class LeoSlideshowPreviewModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
private $name_module = 'leoslideshow';
|
||||
public $theme_name;
|
||||
public $img_path;
|
||||
public $img_url;
|
||||
public $slider_data = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->theme_name = LeoSlideshowHelper::getThemeName();
|
||||
$this->img_path = LeoSlideshowHelper::getImgThemeDir();
|
||||
$this->img_url = LeoSlideshowHelper::getImgThemeUrl();
|
||||
|
||||
include_once($this->module->getLocalPath().$this->name_module.'.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function display()
|
||||
{
|
||||
$media_dir = $this->module->getMediaDir();
|
||||
// tpl in theme folder or module folder
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoslideshow/views/templates/front/leoslideshow.tpl')) {
|
||||
# module validation
|
||||
$leoslideshow_tpl = 1;
|
||||
} else {
|
||||
$leoslideshow_tpl = 0;
|
||||
}
|
||||
if (file_exists(_PS_THEME_DIR_.'modules/leoslideshow/views/css/typo/typo.css')) {
|
||||
# module validation
|
||||
$typo_dir = _THEME_DIR_.str_replace('//', '/', 'modules/leoslideshow').'views/css/typo/typo.css';
|
||||
} else {
|
||||
# module validation
|
||||
$typo_dir = __PS_BASE_URI__.$media_dir.'/css/typo/typo.css';
|
||||
}
|
||||
if (file_exists(_PS_THEME_DIR_.'assets/css/modules/leoslideshow/views/css/typo/typo.css')) {
|
||||
# module validation
|
||||
$typo_dir = _THEME_DIR_.'assets/css/modules/leoslideshow/views/css/typo/typo.css';
|
||||
} else {
|
||||
# module validation
|
||||
$typo_dir = __PS_BASE_URI__.$media_dir.'/css/typo/typo.css';
|
||||
}
|
||||
$this->addCSS($typo_dir, 'all');
|
||||
$this->addCSS(__PS_BASE_URI__.$media_dir.'css/iView/iview.css', 'all');
|
||||
$this->addCSS(__PS_BASE_URI__.$media_dir.'css/iView/skin_4_responsive/style.css', 'all');
|
||||
|
||||
$this->addJS(__PS_BASE_URI__.$media_dir.'js/iView/raphael-min.js');
|
||||
$this->addJS(__PS_BASE_URI__.$media_dir.'js/iView/iview.js');
|
||||
|
||||
if (!is_dir(_PS_ROOT_DIR_.'/cache/'.$this->name_module)) {
|
||||
# module validation
|
||||
mkdir(_PS_ROOT_DIR_.'/cache/'.$this->name_module, 0755, true);
|
||||
}
|
||||
|
||||
# PREVIEW GROUP
|
||||
$id_group = Tools::getValue('id_group');
|
||||
$id_lang = $this->context->language->id;
|
||||
if ($id_group) {
|
||||
$group = LeoSlideshowGroup::getGroupByID($id_group);
|
||||
if (!Tools::getValue('id_slider') && !Tools::getValue('preview')) {
|
||||
# module validation
|
||||
$sliders = $this->getSlides($id_group, $id_lang, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($group) || !$group) {
|
||||
# module validation
|
||||
return false;
|
||||
}
|
||||
|
||||
$id_slider = Tools::getValue('id_slide');
|
||||
if ($id_slider && !Tools::getValue('preview')) {
|
||||
# module validation
|
||||
$sliders = $this->getSlide($id_slider, $id_lang);
|
||||
}
|
||||
|
||||
if (Tools::getValue('preview')) {
|
||||
$slider_preview_data = trim(html_entity_decode((Tools::getValue('slider_preview_data'))));
|
||||
$slider_preview_data = Tools::jsonDecode($slider_preview_data);
|
||||
// echo '<pre>';
|
||||
// print_r($slider_preview_data);die();
|
||||
foreach ($slider_preview_data as $key => $val) {
|
||||
# module validation
|
||||
$sliders[0][$key] = $val;
|
||||
}
|
||||
$tmp_slider = array();
|
||||
$tmp_slider = $sliders[0]['params'];
|
||||
$sliders[0]['params'] = array();
|
||||
foreach ($tmp_slider as $key => $val) {
|
||||
# module validation
|
||||
$sliders[0]['params'][$key] = $val;
|
||||
}
|
||||
$tmp_slider = $sliders[0]['video'];
|
||||
$sliders[0]['video'] = array();
|
||||
foreach ($tmp_slider as $key => $val) {
|
||||
# module validation
|
||||
$sliders[0]['video'][$key] = $val;
|
||||
}
|
||||
$tmp_slider = $sliders[0]['layers'];
|
||||
$sliders[0]['layers'] = array();
|
||||
foreach ($tmp_slider as $key => $val) {
|
||||
foreach ($val as $k => $v) {
|
||||
# module validation
|
||||
$sliders[0]['layersparams'][$key][$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($sliders) || !$sliders) {
|
||||
# module validation
|
||||
return false;
|
||||
}
|
||||
$this->name = 'leoslideshow';
|
||||
$slider_module = new LeoSlideshow();
|
||||
$group_data = $slider_module->group_data;
|
||||
$this->slider_data = $slider_module->slider_data;
|
||||
$slider_params = Tools::jsonDecode(LeoSlideshowSlide::base64Decode($group['params']), true);
|
||||
// echo '<pre>';
|
||||
// print_r($slider_params);die();
|
||||
$slider_params = array_merge($group_data, $slider_params);
|
||||
$mod_group = new LeoSlideshowGroup();
|
||||
$mod_group->setModule($this->module);
|
||||
$slider_params = $mod_group->setData($slider_params)->beforeLoad()->loadFrontEnd();
|
||||
if (isset($slider_params['fullwidth']) && (!empty($slider_params['fullwidth']) || $slider_params['fullwidth'] == 'boxed')) {
|
||||
# module validation
|
||||
$slider_params['image_cropping'] = false;
|
||||
}
|
||||
|
||||
$slider_params['hide_navigator_after'] = $slider_params['show_navigator'] ? 0 : $slider_params['hide_navigator_after'];
|
||||
$slider_params['slider_class'] = trim(isset($slider_params['fullwidth']) && !empty($slider_params['fullwidth']) ? $slider_params['fullwidth'] : 'boxed');
|
||||
$slider_fullwidth = $slider_params['slider_class'] == 'boxed' ? 'off' : 'on';
|
||||
|
||||
// generate back-ground
|
||||
if ($slider_params['background_image'] && $slider_params['background_url'] && file_exists($this->img_path.$slider_params['background_url'])) {
|
||||
# module validation
|
||||
$slider_params['background'] = 'background: url('.$this->img_url.$slider_params['background_url'].') no-repeat scroll left 0 '.$slider_params['background_color'].';';
|
||||
} else {
|
||||
# module validation
|
||||
$slider_params['background'] = 'background-color:'.$slider_params['background_color'];
|
||||
}
|
||||
|
||||
//include library genimage
|
||||
if (!class_exists('PhpThumbFactory')) {
|
||||
# module validation
|
||||
require_once _PS_MODULE_DIR_.'leoslideshow/libs/phpthumb/ThumbLib.inc.php';
|
||||
}
|
||||
|
||||
$white_main_img = __PS_BASE_URI__.'modules/'.$this->name.'/views/img/white50.png';
|
||||
|
||||
//process slider
|
||||
foreach ($sliders as $key => $slider) {
|
||||
if (!Tools::getValue('preview')) {
|
||||
$slider['layers'] = array();
|
||||
$slider['params'] = array_merge($this->slider_data, Tools::jsonDecode(LeoSlideshowSlide::base64Decode($slider['params']), true));
|
||||
$slider['layersparams'] = Tools::jsonDecode(LeoSlideshowSlide::base64Decode($slider['layersparams']), true);
|
||||
$slider['video'] = Tools::jsonDecode(LeoSlideshowSlide::base64Decode($slider['video']), true);
|
||||
}
|
||||
$slider['data_link'] = '';
|
||||
if ($slider['params']['enable_link'] && $slider['link']) {
|
||||
// $slider['data_link'] = 'data-link="'.$slider['link'].'"';
|
||||
// $slider['data_target'] = 'data-target="'.LeoSlideshowSlide::renderTarget($slider['params']['target']).'"';
|
||||
$slider['data_link'] = $slider['link'];
|
||||
$slider['data_target'] = LeoSlideshowSlide::renderTarget($slider['params']['target']);
|
||||
} else {
|
||||
# module validation
|
||||
$slider['data_target'] = '';
|
||||
}
|
||||
|
||||
$slider['data_delay'] = (int)$slider['params']['delay'];
|
||||
|
||||
//videoURL
|
||||
$slider['videoURL'] = '';
|
||||
$slider['video']['active'] = '0';
|
||||
if ($slider['video']['usevideo'] == 'youtube' || $slider['video']['usevideo'] == 'vimeo') {
|
||||
$slider['video']['active'] = '1';
|
||||
$slider['video']['videoURL'] = Tools::getCurrentUrlProtocolPrefix() . 'player.vimeo.com/video/'.$slider['video']['videoid'].'/';
|
||||
if ($slider['video']['usevideo'] == 'youtube') {
|
||||
# module validation
|
||||
$slider['video']['videoURL'] = Tools::getCurrentUrlProtocolPrefix() . 'www.youtube.com/embed/'.$slider['video']['videoid'].'/';
|
||||
}
|
||||
}
|
||||
|
||||
if ($slider['video']['videoauto'] == 1) {
|
||||
# module validation
|
||||
$slider['video']['videoauto'] = 'autoplay=1';
|
||||
} else {
|
||||
# module validation
|
||||
$slider['video']['videoauto'] = 'autoplay=0';
|
||||
}
|
||||
|
||||
// $slider['background_color'] = '';
|
||||
//DONGND:: background color for preview
|
||||
if (!isset($slider['background_color']) || $slider['background_color'] == '') {
|
||||
$slider['background_color'] = '';
|
||||
if (isset($slider_params['background_color']) && $slider_params['background_color']) {
|
||||
# module validation
|
||||
$slider['background_color'] = $slider_params['background_color'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($slider['video']['background_color']) && $slider['video']['background_color']) {
|
||||
# module validation
|
||||
$slider['background_color'] = $slider['video']['background_color'];
|
||||
}
|
||||
// echo '<pre>';
|
||||
// print_r($slider);
|
||||
LeoSlideshowSlide::getBackground($slider_params, $slider);
|
||||
// echo '<pre>';
|
||||
// print_r($slider);
|
||||
// echo '<pre>';
|
||||
// print_r($slider['image']);
|
||||
if ($slider['image'] == '') {
|
||||
# module validation
|
||||
$slider['image'] = 'views/img/blank.gif';
|
||||
}
|
||||
// echo '<pre>';
|
||||
// print_r($this->img_path.$slider['image']);
|
||||
if ($slider_params['image_cropping']) {
|
||||
//gender main_image
|
||||
if ($slider['image'] && file_exists($this->img_path.$slider['image'])) {
|
||||
# module validation
|
||||
$slider['main_image'] = $this->renderThumb($slider['image'], $slider_params['width'], $slider_params['height']);
|
||||
} else {
|
||||
# module validation
|
||||
$slider['main_image'] = $white_main_img;
|
||||
}
|
||||
|
||||
if ($slider['thumbnail'] && file_exists($this->img_path.$slider['thumbnail'])) {
|
||||
# module validation
|
||||
//$slider['thumbnail'] = $this->renderThumb($slider['thumbnail'], $sliderParams['thumbnail_width'], $sliderParams['thumbnail_height']);
|
||||
} else if ($slider['image'] && file_exists($this->img_path.$slider['image'])) {
|
||||
# module validation
|
||||
//$slider['thumbnail'] = $this->renderThumb($slider['image'], $sliderParams['thumbnail_width'], $sliderParams['thumbnail_height']);
|
||||
} else {
|
||||
# module validation
|
||||
$slider['thumbnail'] = $white_main_img;
|
||||
}
|
||||
} else {
|
||||
$slider['main_image'] = __PS_BASE_URI__.'modules/leoslideshow'.'/views/img/blank.gif';
|
||||
|
||||
if ($slider['image'] && file_exists($this->img_path.$slider['image'])) {
|
||||
# module validation
|
||||
$slider['main_image'] = $this->img_url.$slider['image'];
|
||||
} else if (((Tools::substr($slider['image'], 0, 7) == 'http://')) || ((Tools::substr($slider['image'], 0, 8) == 'https://')) || ((Tools::substr($slider['image'], 0, 10) == 'data:image'))) {
|
||||
# Image External Link
|
||||
$slider['main_image'] = $slider['image'];
|
||||
}
|
||||
|
||||
if ($slider['thumbnail'] && file_exists($this->img_path.$slider['thumbnail'])) {
|
||||
# module validation
|
||||
$slider['thumbnail'] = $this->img_url.$slider['thumbnail'];
|
||||
} else if ($slider['image'] && file_exists($this->img_path.$slider['image'])) {
|
||||
# module validation
|
||||
$slider['thumbnail'] = $slider['main_image'];
|
||||
} else if (((Tools::substr($slider['thumbnail'], 0, 7) == 'http://')) || ((Tools::substr($slider['thumbnail'], 0, 8) == 'https://')) || ((Tools::substr($slider['thumbnail'], 0, 10) == 'data:image'))) {
|
||||
# Image External Link
|
||||
$slider['thumbnail'] = $slider['thumbnail'];
|
||||
} else {
|
||||
# module validation
|
||||
$slider['thumbnail'] = $white_main_img;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($slider['layersparams']) && $slider['layersparams']) {
|
||||
foreach ($slider['layersparams'] as $k => &$layer_css) {
|
||||
if ($layer_css['layer_status'] == 0) {
|
||||
unset($slider['layersparams'][$k]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$layer_css_val = '';
|
||||
if (isset($layer_css['layer_font_size']) && $layer_css['layer_font_size']) {
|
||||
# module validation
|
||||
$layer_css_val = 'font-size:'.$layer_css['layer_font_size'];
|
||||
}
|
||||
if (isset($layer_css['layer_background_color']) && $layer_css['layer_background_color']) {
|
||||
# module validation
|
||||
$layer_css_val .= ($layer_css_val != '' ? ';' : '').'background-color:'.$layer_css['layer_background_color'];
|
||||
}
|
||||
if (isset($layer_css['layer_color']) && $layer_css['layer_color']) {
|
||||
# module validation
|
||||
$layer_css_val .= ($layer_css_val != '' ? ';' : '').'color:'.$layer_css['layer_color'];
|
||||
}
|
||||
$layer_css['css'] = $layer_css_val;
|
||||
if (!isset($layer_css['layer_link'])) {
|
||||
# module validation
|
||||
$layer_css['layer_link'] = $slider['link'];
|
||||
}
|
||||
$layer_css['layer_target'] = LeoSlideshowSlide::renderTarget($layer_css['layer_target']);
|
||||
if (isset($layer_css['layer_caption']) && $layer_css['layer_caption']) {
|
||||
# module validation
|
||||
$layer_css['layer_caption'] = utf8_decode($layer_css['layer_caption']);
|
||||
}
|
||||
if (isset($layer_css['layer_type']) && $layer_css['layer_type'] == 'image') {
|
||||
if (((Tools::substr($layer_css['layer_content'], 0, 4) != 'http')) && ((Tools::substr($layer_css['layer_content'], 0, 8) != 'data:image'))) {
|
||||
$layer_css['layer_content'] = $this->img_url. $layer_css['layer_content'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$sliders[$key] = $slider;
|
||||
}
|
||||
// die();
|
||||
$slider_params['start_with_slide'] = LeoSlideshowGroup::showStartWithSlide($slider_params['start_with_slide'], $sliders);
|
||||
$sliders = LeoSlideshowSlide::showBulletCustomHTML($slider_params, $sliders);
|
||||
$slider_params['playLabel'] = LeoSlideshowHelper::l('Play');
|
||||
$slider_params['pauseLabel'] = LeoSlideshowHelper::l('Pause');
|
||||
$slider_params['closeLabel'] = LeoSlideshowHelper::l('Close');
|
||||
$slider_params['rtl'] = $this->context->language->is_rtl;
|
||||
// echo '<pre>';
|
||||
// print_r($sliders);die();
|
||||
$this->context->smarty->assign(array(
|
||||
'sliderParams' => $slider_params,
|
||||
'sliders' => $sliders,
|
||||
'sliderIDRand' => rand(20, rand()),
|
||||
'sliderFullwidth' => $slider_fullwidth,
|
||||
'sliderImgUrl' => $this->img_url,
|
||||
'leoslideshow_tpl' => $leoslideshow_tpl,
|
||||
'rand_num' => uniqid(),
|
||||
));
|
||||
// print_r($leoslideshow_tpl);die();
|
||||
// $this->setTemplate('preview.tpl');
|
||||
|
||||
if ($leoslideshow_tpl == 1) {
|
||||
if (!file_exists(_PS_THEME_DIR_.'modules/leoslideshow/views/templates/front/preview.tpl')) {
|
||||
@copy(_PS_MODULE_DIR_.'leoslideshow/views/templates/front/preview.tpl', _PS_THEME_DIR_.'modules/leoslideshow/views/templates/front/preview.tpl');
|
||||
}
|
||||
|
||||
$this->setTemplate('../modules/leoslideshow/views/templates/front/preview.tpl');
|
||||
} else {
|
||||
$this->setTemplate('module:leoslideshow/views/templates/front/preview.tpl');
|
||||
}
|
||||
|
||||
parent::display();
|
||||
}
|
||||
|
||||
public function renderThumb($src_file, $width, $height)
|
||||
{
|
||||
$sub_folder = '/';
|
||||
if (!$src_file) {
|
||||
# module validation
|
||||
return '';
|
||||
}
|
||||
if (strpos($src_file, '/') !== false) {
|
||||
$path = @pathinfo($src_file);
|
||||
if (strpos($path['dirname'], '/') !== -1) {
|
||||
$sub_folder = $path['dirname'].'/';
|
||||
$folder_list = explode('/', $path['dirname']);
|
||||
$tmp_folder = '/';
|
||||
foreach ($folder_list as $value) {
|
||||
if ($value) {
|
||||
if (!is_dir(_PS_ROOT_DIR_.'/cache/'.$this->name_module.$tmp_folder.$value)) {
|
||||
# module validation
|
||||
mkdir(_PS_ROOT_DIR_.'/cache/'.$this->name_module.$tmp_folder.$value, 0755, true);
|
||||
}
|
||||
|
||||
$tmp_folder .= $value.'/';
|
||||
}
|
||||
}
|
||||
}
|
||||
$image_name = $path['basename'];
|
||||
} else {
|
||||
# module validation
|
||||
$image_name = $src_file;
|
||||
}
|
||||
|
||||
$path = '';
|
||||
if (file_exists($this->img_path.$src_file)) {
|
||||
//return image url
|
||||
$path = __PS_BASE_URI__.'cache/'.$this->name_module.$sub_folder.$width.'_'.$height.'_'.$image_name;
|
||||
$save_path = _PS_ROOT_DIR_.'/cache/'.$this->name_module.$sub_folder.$width.'_'.$height.'_'.$image_name;
|
||||
if (!file_exists($save_path)) {
|
||||
$thumb = PhpThumbFactory::create($this->img_path.$src_file);
|
||||
$thumb->adaptiveResize($width, $height);
|
||||
$thumb->save($save_path);
|
||||
}
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all slider data
|
||||
*/
|
||||
public function getSlides($id_group, $id_lang, $active = null)
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
if (!$id_lang) {
|
||||
# module validation
|
||||
$id_lang = $this->context->language->id;
|
||||
}
|
||||
|
||||
$sql = 'SELECT lsl.`id_leoslideshow_slides` as id_slide,lsl.*,lsll.*
|
||||
FROM '._DB_PREFIX_.'leoslideshow_slides lsl
|
||||
LEFT JOIN '._DB_PREFIX_.'leoslideshow_slides_lang lsll ON (lsl.id_leoslideshow_slides = lsll.id_leoslideshow_slides)
|
||||
WHERE lsl.id_group = '.(int)$id_group.'
|
||||
AND lsll.id_lang = '.(int)$id_lang.
|
||||
($active ? ' AND lsl.`active` = 1' : ' ').'
|
||||
ORDER BY lsl.position';
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* get all slider data
|
||||
*/
|
||||
public function getSlide($id_slider, $id_lang)
|
||||
{
|
||||
$sql = 'SELECT lsl.`id_leoslideshow_slides` as id_slide, lsl.*,lsll.*
|
||||
FROM '._DB_PREFIX_.'leoslideshow_slides lsl
|
||||
LEFT JOIN '._DB_PREFIX_.'leoslideshow_slides_lang lsll ON (lsl.id_leoslideshow_slides = lsll.id_leoslideshow_slides)
|
||||
WHERE lsl.id_leoslideshow_slides= '.(int)$id_slider.' AND lsll.id_lang = '.(int)$id_lang;
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
}
|
||||
}
|
||||
35
modules/leoslideshow/controllers/index.php
Normal file
35
modules/leoslideshow/controllers/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;
|
||||
Reference in New Issue
Block a user