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_ . 'leosliderlayer/grouplayer.php';
         include_once _PS_MODULE_DIR_ . 'leosliderlayer/sliderlayer.php';
         $content = Tools::file_get_contents($_FILES['import_file']['tmp_name']);
         $content = Tools::jsonDecode(SliderLayer::base64Decode($content), true);
         $languageField = array('title', 'link', 'image', 'thumbnail', 'video', 'layersparams');
         $languages = Language::getLanguages();
         $langList = array();
         foreach ($languages as $lang) {
             $langList[$lang['iso_code']] = $lang['id_lang'];
         }
         $override_group = Tools::getValue('override_group');
         //override or edit
         if ($override_group && LeoSliderGroup::groupExists($content['id_leosliderlayer_groups'])) {
             $group = new LeoSliderGroup($content['id_leosliderlayer_groups']);
             //edit group
             $group = $this->setDataForGroup($group, $content);
             if (!$group->update()) {
                 return false;
             }
             LeoSliderGroup::deleteAllSlider($content['id_leosliderlayer_groups']);
             foreach ($content['sliders'] as $slider) {
                 $obj = new SliderLayer();
                 foreach ($slider as $key => $val) {
                     if (in_array($key, $languageField)) {
                         foreach ($val as $keyLang => $valLang) {
                             $obj->{$key}[$langList[$keyLang]] = $valLang;
                         }
                     } else {
                         $obj->{$key} = $val;
                     }
                 }
                 $obj->id_group = $group->id;
                 if (isset($slider['id']) && $slider['id'] && SliderLayer::sliderExist($slider['id'])) {
                     $obj->update();
                 } else {
                     $obj->add();
                 }
             }
         } else {
             $group = new LeoSliderGroup();
             $group = $this->setDataForGroup($group, $content);
             if (!$group->add()) {
                 return false;
             }
             foreach ($content['sliders'] as $slider) {
                 $obj = new SliderLayer();
                 foreach ($slider as $key => $val) {
                     if (in_array($key, $languageField)) {
                         foreach ($val as $keyLang => $valLang) {
                             $obj->{$key}[$langList[$keyLang]] = $valLang;
                         }
                     } else {
                         $obj->{$key} = $val;
                     }
                 }
                 $obj->id_group = $group->id;
                 $obj->id = 0;
                 $obj->add();
             }
         }
         //add new
         //return true;
     }
     Tools::redirectAdmin('index.php?controller=AdminModules&token=' . Tools::getAdminTokenLite('AdminModules') . '&configure=leosliderlayer&tab_module=leotheme&module_name=leosliderlayer&conf=4');
     //return false;
 }
示例#2
0
 /**
  * @see FrontController::initContent()
  */
 public function display()
 {
     if (!is_dir(_PS_ROOT_DIR_ . '/cache/' . $this->_nameModule)) {
         mkdir(_PS_ROOT_DIR_ . '/cache/' . $this->_nameModule, 0755);
     }
     $id_group = Tools::getValue('id_group');
     $id_lang = $this->context->language->id;
     //preview group
     if ($id_group) {
         $group = $this->getSliderGroupByID($id_group);
         if (!Tools::getValue('id_slider') && !Tools::getValue('preview')) {
             $sliders = $this->getSlides($id_group, $id_lang, 1);
         }
     }
     $id_slider = Tools::getValue('id_slide');
     if ($id_slider && !Tools::getValue('preview')) {
         $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);
         foreach ($slider_preview_data as $key => $val) {
             $sliders[0][$key] = $val;
         }
         $tmpSlider = array();
         $tmpSlider = $sliders[0]['params'];
         $sliders[0]['params'] = array();
         foreach ($tmpSlider as $key => $val) {
             $sliders[0]['params'][$key] = $val;
         }
         $tmpSlider = $sliders[0]['video'];
         $sliders[0]['video'] = array();
         foreach ($tmpSlider as $key => $val) {
             $sliders[0]['video'][$key] = $val;
         }
         $tmpSlider = $sliders[0]['layers'];
         $sliders[0]['layers'] = array();
         foreach ($tmpSlider as $key => $val) {
             foreach ($val as $k => $v) {
                 $sliders[0]['layersparams'][$key][$k] = $v;
             }
         }
     }
     if (!isset($group) || !$group) {
         return false;
     }
     if (!$sliders) {
         return false;
     }
     $sliderObj = new LeoSliderLayer();
     $groupData = $sliderObj->groupData;
     $this->_sliderData = $sliderObj->_sliderData;
     $sliderParams = Tools::jsonDecode(SliderLayer::base64Decode($group['params']), true);
     $sliderParams = array_merge($groupData, $sliderParams);
     if (isset($sliderParams['fullwidth']) && (!empty($sliderParams['fullwidth']) || $sliderParams['fullwidth'] == 'boxed')) {
         $sliderParams['image_cropping'] = false;
     }
     $sliderParams['hide_navigator_after'] = $sliderParams['show_navigator'] ? 0 : $sliderParams['hide_navigator_after'];
     $sliderParams['slider_class'] = trim(isset($sliderParams['fullwidth']) && !empty($sliderParams['fullwidth']) ? $sliderParams['fullwidth'] : 'boxed');
     $sliderFullwidth = $sliderParams['slider_class'] == 'boxed' ? 'off' : 'on';
     //generate back-ground
     if ($sliderParams['background_image']) {
         $sliderParams['background'] = 'background: url(' . __PS_BASE_URI__ . 'modules/' . $this->_nameModule . '/images/' . $sliderParams['background_url'] . ') no-repeat scroll left 0 ' . $sliderParams['background_color'] . ';';
     } else {
         $sliderParams['background'] = 'background-color:' . $sliderParams['background_color'];
     }
     //include library genimage
     if (!class_exists('PhpThumbFactory')) {
         require_once _PS_MODULE_DIR_ . 'leosliderlayer/libs/phpthumb/ThumbLib.inc.php';
     }
     //echo "<pre>";print_r($sliders);die;
     //process slider
     foreach ($sliders as $key => $slider) {
         if (!Tools::getValue('preview')) {
             $slider['layers'] = array();
             $slider['params'] = array_merge($this->_sliderData, Tools::jsonDecode(SliderLayer::base64Decode($slider['params']), true));
             $slider['layersparams'] = Tools::jsonDecode(SliderLayer::base64Decode($slider['layersparams']), true);
             $slider['video'] = Tools::jsonDecode(SliderLayer::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="' . SliderLayer::renderTarget($slider['params']['target']) . '"';
         } else {
             $slider['data_target'] = '';
         }
         $slider['data_delay'] = $slider['params']['delay'] ? 'data-delay="' . (int) $slider['params']['delay'] . '"' : '';
         //videoURL
         $slider['videoURL'] = '';
         if ($slider['video']['usevideo'] == 'youtube' || $slider['video']['usevideo'] == 'vimeo') {
             $slider['videoURL'] = 'http://player.vimeo.com/video/' . $slider['video']['videoid'] . '/';
             if ($slider['video']['usevideo'] == 'youtube') {
                 $slider['videoURL'] = 'http://www.youtube.com/embed/' . $slider['video']['videoid'] . '/';
             }
         }
         $slider['background_color'] = '';
         if (isset($slider['video']['background_color']) && $slider['video']['background_color']) {
             $slider['background_color'] = $slider['video']['background_color'];
         }
         if ($sliderParams['image_cropping']) {
             //gender main_image
             if ($slider['image'] && file_exists($this->img_path . $slider['image'])) {
                 $slider['main_image'] = $this->renderThumb($slider['image'], $sliderParams['width'], $sliderParams['height']);
             } else {
                 $slider['main_image'] = '';
             }
             if ($slider['thumbnail'] && file_exists($this->img_path . $slider['thumbnail'])) {
                 $slider['thumbnail'] = $this->renderThumb($slider['thumbnail'], $sliderParams['thumbnail_width'], $sliderParams['thumbnail_height']);
             } else {
                 if ($slider['image'] && file_exists($this->img_path . $slider['image'])) {
                     $slider['thumbnail'] = $this->renderThumb($slider['image'], $sliderParams['thumbnail_width'], $sliderParams['thumbnail_height']);
                 } else {
                     $slider['thumbnail'] = '';
                 }
             }
         } else {
             $slider['main_image'] = '';
             if ($slider['image'] && file_exists($this->img_path . $slider['image'])) {
                 $slider['main_image'] = $this->img_url . $slider['image'];
             }
             if ($slider['thumbnail'] && file_exists($this->img_path . $slider['thumbnail'])) {
                 $slider['thumbnail'] = $this->img_url . $slider['thumbnail'];
             } else {
                 if ($slider['image'] && file_exists($this->img_path . $slider['image'])) {
                     $slider['thumbnail'] = $slider['main_image'];
                 } else {
                     $slider['thumbnail'] = '';
                 }
             }
         }
         if (isset($slider['layersparams']) && $slider['layersparams']) {
             foreach ($slider['layersparams'] as &$layerCss) {
                 $layerCssVal = '';
                 if (isset($layerCss['layer_font_size']) && $layerCss['layer_font_size']) {
                     $layerCssVal = 'font-size:' . $layerCss['layer_font_size'];
                 }
                 if (isset($layerCss['layer_background_color']) && $layerCss['layer_background_color']) {
                     $layerCssVal .= ($layerCssVal != '' ? ';' : '') . 'background-color:' . $layerCss['layer_background_color'];
                 }
                 if (isset($layerCss['layer_color']) && $layerCss['layer_color']) {
                     $layerCssVal .= ($layerCssVal != '' ? ';' : '') . 'color:' . $layerCss['layer_color'];
                 }
                 $layerCss['css'] = $layerCssVal;
                 if (!isset($layerCss['layer_link'])) {
                     $layerCss['layer_link'] = $slider['link'];
                 }
                 $layerCss['layer_target'] = SliderLayer::renderTarget($slider['params']['target']);
             }
         }
         $sliders[$key] = $slider;
     }
     if (file_exists(_PS_THEME_DIR_ . 'modules/leosliderlayer/leosliderlayer.tpl')) {
         $leosliderlayer_tpl = _PS_THEME_DIR_ . 'modules/leosliderlayer/leosliderlayer.tpl';
     } else {
         $leosliderlayer_tpl = _PS_MODULE_DIR_ . 'leosliderlayer/leosliderlayer.tpl';
     }
     //add js + css
     $this->addJS(__PS_BASE_URI__ . str_replace('//', '/', 'modules/leosliderlayer') . '/js/jquery.themepunch.plugins.min.js');
     $this->addJS(__PS_BASE_URI__ . str_replace('//', '/', 'modules/leosliderlayer') . '/js/jquery.themepunch.revolution.min.js');
     if (file_exists(_PS_THEME_DIR_ . 'css/modules/leosliderlayer/css/typo.css')) {
         $this->context->controller->addCSS(_PS_THEME_DIR_ . 'css/modules/leosliderlayer/css/typo.css');
     } else {
         $this->addCSS(__PS_BASE_URI__ . str_replace('//', '/', 'modules/leosliderlayer') . '/css/typo.css', 'all');
     }
     $sliderParams['slider_start_with_slide'] = LeoSliderGroup::showStartWithSlide($sliderParams['start_with_slide'], $sliders);
     $this->context->smarty->assign(array('sliderParams' => $sliderParams, 'sliders' => $sliders, 'sliderIDRand' => rand(20, rand()), 'sliderFullwidth' => $sliderFullwidth, 'leosliderlayer_tpl' => $leosliderlayer_tpl, 'sliderImgUrl' => $this->img_url));
     $this->setTemplate('preview.tpl');
     parent::display();
 }
示例#3
0
 /**
  * System get Delay value from GROUP when SLIDER's Delay <= 0
  */
 public static function showDelay($slide_id = 0, $delay = null, $group_delay = null)
 {
     $default = 9000;
     # Get Delay form SLIDER
     if ($delay > 0) {
         return $delay;
     }
     if (!empty($slide_id)) {
         $slider = new SliderLayer($slide_id);
         $s_delay = $slider->getDelay();
         if ($s_delay > 0) {
             return $s_delay;
         }
     }
     # Get Delay form GROUP
     if ($group_delay > 0) {
         return $group_delay;
     }
     if (!empty($slide_id)) {
         $slider = new SliderLayer($slide_id);
         $group = new LeoSliderGroup($slider->id_group);
         $g_delay = $group->getDelay();
         if ($g_delay > 0) {
             return $g_delay;
         }
     }
     return $default;
 }
示例#4
0
 public static function getGroupOption()
 {
     $result = array();
     $obj = new LeoSliderGroup();
     $groups = $obj->getGroups(null, null);
     foreach ($groups as $group) {
         $temp = array();
         $temp['id'] = $group['id_leosliderlayer_groups'];
         $temp['name'] = $group['title'];
         $result[] = $temp;
     }
     return $result;
 }
示例#5
0
 private function prepareHookForApPageBuilder($group_id)
 {
     $tpl = 'leosliderlayer.tpl';
     if (!$this->isCached($tpl, $this->getCacheId($group_id . '_' . $this->name))) {
         //die('aaaa');
         if (!is_dir(_PS_ROOT_DIR_ . '/cache/' . $this->name)) {
             mkdir(_PS_ROOT_DIR_ . '/cache/' . $this->name, 0755);
         }
         //get slider via id
         $group = $this->getSliderGroupById($group_id);
         if (!$group) {
             return false;
         }
         $sliders = $this->getSlides($group["id_leosliderlayer_groups"], 1);
         $sliders = SliderLayer::filterSlider($sliders, $this->_sliderData);
         if (!$sliders) {
             return false;
         }
         $sliderParams = Tools::jsonDecode(SliderLayer::base64Decode($group["params"]), true);
         $sliderParams = array_merge($this->groupData, $sliderParams);
         if (isset($sliderParams['fullwidth']) && (!empty($sliderParams['fullwidth']) || $sliderParams['fullwidth'] == 'boxed')) {
             $sliderParams['image_cropping'] = false;
         }
         $sliderParams['hide_navigator_after'] = $sliderParams['show_navigator'] ? 0 : $sliderParams['hide_navigator_after'];
         $sliderParams['slider_class'] = trim(isset($sliderParams['fullwidth']) && !empty($sliderParams['fullwidth']) ? $sliderParams['fullwidth'] : 'boxed');
         $sliderFullwidth = $sliderParams['slider_class'] == "boxed" ? "off" : "on";
         //generate back-ground
         if ($sliderParams["background_image"] && $sliderParams["background_url"] && file_exists($this->img_path . $sliderParams['background_url'])) {
             $sliderParams["background"] = 'background: url(' . $this->img_url . $sliderParams["background_url"] . ') no-repeat scroll left 0 ' . $sliderParams["background_color"] . ';';
         } else {
             $sliderParams["background"] = 'background-color:' . $sliderParams["background_color"];
         }
         //include library genimage
         if (!class_exists('PhpThumbFactory')) {
             require_once _PS_MODULE_DIR_ . 'leosliderlayer/libs/phpthumb/ThumbLib.inc.php';
         }
         $whiteMainImg = __PS_BASE_URI__ . 'modules/' . $this->name . '/assets/white50.png';
         //process slider
         foreach ($sliders as $key => $slider) {
             $slider["layers"] = array();
             $slider['params'] = array_merge($this->_sliderData, Tools::jsonDecode(SliderLayer::base64Decode($slider["params"]), true));
             $slider['layersparams'] = Tools::jsonDecode(SliderLayer::base64Decode($slider["layersparams"]), true);
             $slider['video'] = Tools::jsonDecode(SliderLayer::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="' . SliderLayer::renderTarget($slider['params']['target']) . '"';
             } else {
                 $slider['data_target'] = '';
             }
             $slider['data_delay'] = $slider['params']['delay'] ? 'data-delay="' . (int) $slider['params']['delay'] . '"' : '';
             //videoURL
             $slider['videoURL'] = '';
             if ($slider['video']['usevideo'] == 'youtube' || $slider['video']['usevideo'] == 'vimeo') {
                 $slider['videoURL'] = 'http://player.vimeo.com/video/' . $slider['video']['videoid'] . '/';
                 if ($slider['video']['usevideo'] == 'youtube') {
                     $slider['videoURL'] = 'http://www.youtube.com/embed/' . $slider['video']['videoid'] . '/';
                 }
             }
             $slider['background_color'] = '';
             if (isset($slider['video']['background_color']) && $slider['video']['background_color']) {
                 $slider['background_color'] = $slider['video']['background_color'];
             }
             if ($slider['image'] == '') {
                 $slider['image'] = "blank.gif";
             }
             if ($sliderParams['image_cropping']) {
                 //gender main_image
                 if ($slider['image'] && file_exists($this->img_path . $slider['image'])) {
                     $slider['main_image'] = $this->renderThumb($slider['image'], $sliderParams['width'], $sliderParams['height']);
                 } else {
                     $slider['main_image'] = $whiteMainImg;
                 }
                 if ($slider['thumbnail'] && file_exists($this->img_path . $slider['thumbnail'])) {
                     $slider['thumbnail'] = $this->renderThumb($slider['thumbnail'], $sliderParams['thumbnail_width'], $sliderParams['thumbnail_height']);
                 } else {
                     if ($slider['image'] && file_exists($this->img_path . $slider['image'])) {
                         $slider['thumbnail'] = $this->renderThumb($slider['image'], $sliderParams['thumbnail_width'], $sliderParams['thumbnail_height']);
                     } else {
                         $slider['thumbnail'] = $whiteMainImg;
                     }
                 }
             } else {
                 $slider['main_image'] = '';
                 if ($slider['image'] && file_exists($this->img_path . $slider['image'])) {
                     $slider['main_image'] = $this->img_url . $slider['image'];
                 }
                 if ($slider['thumbnail'] && file_exists($this->img_path . $slider['thumbnail'])) {
                     $slider['thumbnail'] = $this->img_url . $slider['thumbnail'];
                 } else {
                     if ($slider['image'] && file_exists($this->img_path . $slider['image'])) {
                         $slider['thumbnail'] = $slider['main_image'];
                     } else {
                         $slider['thumbnail'] = $whiteMainImg;
                     }
                 }
             }
             if ($slider['layersparams']) {
                 foreach ($slider['layersparams'] as &$layerCss) {
                     $layerCssVal = '';
                     if (isset($layerCss['layer_font_size']) && $layerCss['layer_font_size']) {
                         $layerCssVal = 'font-size:' . $layerCss['layer_font_size'];
                     }
                     if (isset($layerCss['layer_background_color']) && $layerCss['layer_background_color']) {
                         $layerCssVal .= ($layerCssVal != '' ? ';' : '') . 'background-color:' . $layerCss['layer_background_color'];
                     }
                     if (isset($layerCss['layer_color']) && $layerCss['layer_color']) {
                         $layerCssVal .= ($layerCssVal != '' ? ';' : '') . 'color:' . $layerCss['layer_color'];
                     }
                     $layerCss['css'] = $layerCssVal;
                     if (!isset($layerCss['layer_link'])) {
                         $layerCss['layer_link'] = str_replace("_ASM_", "&", $slider['link']);
                     }
                     $layerCss['layer_target'] = SliderLayer::renderTarget($slider['params']['target']);
                     if (isset($layerCss['layer_caption']) && $layerCss['layer_caption']) {
                         $layerCss['layer_caption'] = utf8_decode($layerCss['layer_caption']);
                     }
                 }
             }
             $sliders[$key] = $slider;
         }
         //echo "<pre>";print_r($sliders);die;
         $sliderParams['slider_start_with_slide'] = LeoSliderGroup::showStartWithSlide($sliderParams['start_with_slide'], $sliders);
         $this->smarty->assign(array('sliderParams' => $sliderParams, 'sliders' => $sliders, 'sliderIDRand' => rand(20, rand()), 'sliderFullwidth' => $sliderFullwidth, 'sliderImgUrl' => $this->img_url));
     }
     return true;
 }
示例#6
0
 public function hookActionShopDataDuplication($params)
 {
     $groupList = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT gr.*
                         FROM `' . _DB_PREFIX_ . 'leosliderlayer_groups` gr
                         WHERE gr.`id_shop` = ' . (int) $params['old_id_shop']);
     foreach ($groupList as $list) {
         $group = new LeoSliderGroup();
         foreach ($list as $key => $value) {
             if ($key != "id" && $key != "id_shop") {
                 $group->{$key} = $value;
             }
         }
         $group->id_shop = (int) $params['new_id_shop'];
         $group->add();
         //import slider
         $sliderList = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT sl.id_leosliderlayer_slides as id
                         FROM `' . _DB_PREFIX_ . 'leosliderlayer_slides` sl
                         WHERE sl.`id_group` = ' . (int) $list["id_leosliderlayer_groups"]);
         $fields = array("active", "image", "thumbnail", "video", "title", "layersparams", "title", "position", "link", "params");
         foreach ($sliderList as $key => $value) {
             $sliderOld = new SliderLayer($value["id"]);
             //print_r($sliderOld);die;
             $sliderNew = new SliderLayer();
             $sliderNew->id_group = $group->id;
             foreach ($fields as $field) {
                 $sliderNew->{$field} = $sliderOld->{$field};
             }
             $sliderNew->add();
         }
     }
     $this->clearCache();
 }