Exemplo n.º 1
0
 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;
 }
Exemplo n.º 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();
 }
Exemplo n.º 3
0
 public function getDelay()
 {
     $temp_result = Tools::jsonDecode(SliderLayer::base64Decode($this->params), true);
     $result = $temp_result['delay'];
     return $result;
 }
Exemplo n.º 4
0
 public function mergeParams($pattern)
 {
     $params_data = array_merge($pattern, Tools::jsonDecode(SliderLayer::base64Decode($this->params), true));
     $this->mergeData($params_data);
     return $this;
 }
Exemplo n.º 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;
 }