setMVCHelper($MVCHelper); $this->sliderId = $sliderId; } public function create($saveAsFile = false) { $this->backup = new BackupData(); $slidersModel = new ModelSliders($this); if ($this->backup->slider = $slidersModel->get($this->sliderId)) { $zip = new Creator(); if (empty($this->backup->slider['type'])) { $this->backup->slider['type'] = 'simple'; } self::addImage($this->backup->slider['thumbnail']); $this->backup->slider['params'] = new SliderParams($this->backup->slider['id'], $this->backup->slider['type'], $this->backup->slider['params'], true); if ($this->backup->slider['type'] == 'group') { $xref = new ModelSlidersXRef($this); $sliders = $xref->getSliders($this->backup->slider['id'], 'published'); foreach ($sliders as $k => $slider) { $export = new self($this->MVCHelper, $slider['slider_id']); $fileName = $export->create(true); $zip->addFile(file_get_contents($fileName), 'sliders/' . $k . '.ss3'); unlink($fileName); } } else { $slidesModel = new ModelSlides($this); $this->backup->slides = $slidesModel->getAll($this->backup->slider['id']); $sliderType = SliderTypeFactory::getType($this->backup->slider['type']); $sliderType->export($this, $this->backup->slider); /** @var AbstractWidget[] $enabledWidgets */ $enabledWidgets = array(); $widgetGroups = WidgetGroupFactory::getGroups(); $params = $this->backup->slider['params']; foreach ($widgetGroups as $groupName => $group) { $widgetName = $params->get('widget' . $groupName); if ($widgetName && $widgetName != 'disabled') { $widget = $group->getWidget($widgetName); if ($widget) { $enabledWidgets[$groupName] = $widget; } } } foreach ($enabledWidgets as $k => $widget) { $params->fillDefault($widget->getDefaults()); $widget->prepareExport($this, $params); } for ($i = 0; $i < count($this->backup->slides); $i++) { $slide = $this->backup->slides[$i]; self::addImage($slide['thumbnail']); $slide['params'] = new Data($slide['params'], true); self::addImage($slide['params']->get('backgroundImage')); self::addImage($slide['params']->get('ligthboxImage')); if ($slide['params']->has('link')) { // Compatibility fix for the old SS3 import files self::addLightbox($slide['params']->get('link')); } if ($slide['params']->has('href')) { self::addLightbox($slide['params']->get('href')); } $layers = json_decode($slide['slide'], true); $this->prepareLayer($layers); if (!empty($slide['generator_id'])) { $generatorModel = new ModelGenerator($this); $this->backup->generators[] = $generatorModel->get($slide['generator_id']); } } } $this->images = array_unique($this->images); $this->visuals = array_unique($this->visuals); foreach ($this->images as $image) { $this->backup->NextendImageManager_ImageData[$image] = ImageManager::getImageData($image, true); if ($this->backup->NextendImageManager_ImageData[$image]) { self::addImage($this->backup->NextendImageManager_ImageData[$image]['tablet']['image']); self::addImage($this->backup->NextendImageManager_ImageData[$image]['mobile']['image']); } else { unset($this->backup->NextendImageManager_ImageData[$image]); } } $this->images = array_unique($this->images); $usedNames = array(); foreach ($this->images as $image) { $file = ResourceTranslator::toPath($image); if (Filesystem::fileexists($file)) { $fileName = strtolower(basename($file)); while (in_array($fileName, $usedNames)) { $fileName = $this->uniqueCounter . $fileName; $this->uniqueCounter++; } $usedNames[] = $fileName; $this->backup->imageTranslation[$image] = $fileName; $zip->addFile(file_get_contents($file), 'images/' . $fileName); } } foreach ($this->visuals as $visual) { $this->backup->visuals[] = Section::getById($visual); } $zip->addFile(serialize($this->backup), 'data'); if (!$saveAsFile) { PageFlow::cleanOutputBuffers(); header('Content-disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($this->backup->slider['title'] . '.ss3')); header('Content-type: application/zip'); // PHPCS - contains binary zip data, so nothing to escape echo $zip->file(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped PageFlow::exitApplication(); } else { $file = $this->sliderId . '-' . preg_replace('/[^a-zA-Z0-9_-]/', '', $this->backup->slider['title']) . '.ss3'; $folder = Platform::getPublicDirectory(); $folder .= '/export/'; if (!Filesystem::existsFolder($folder)) { Filesystem::createFolder($folder); } Filesystem::createFile($folder . $file, $zip->file()); return $folder . $file; } } } /** * @param array $layers */ public function prepareLayer($layers) { foreach ($layers as $layer) { if (isset($layer['type'])) { switch ($layer['type']) { case 'content': ComponentContent::prepareExport($this, $layer); break; case 'row': ComponentRow::prepareExport($this, $layer); break; case 'col': ComponentCol::prepareExport($this, $layer); break; case 'group': $this->prepareLayer($layer['layers']); break; default: ComponentLayer::prepareExport($this, $layer); } } else { ComponentLayer::prepareExport($this, $layer); } } } public function createHTML($isZIP = true) { Platform::setIsAdmin(false); //Some features are disabled on the admin area $this->files = array(); PageFlow::cleanOutputBuffers(); AssetManager::createStack(); Predefined::frontend(true); ob_start(); $applicationTypeFrontend = ApplicationSmartSlider3::getInstance() ->getApplicationTypeFrontend(); $applicationTypeFrontend->process('slider', 'display', false, array( 'sliderID' => $this->sliderId, 'usage' => 'Export as HTML' )); $slidersModel = new ModelSliders($this); $slider = $slidersModel->get($this->sliderId); $sliderHTML = ob_get_clean(); $headHTML = ''; $css = AssetManager::getCSS(true); foreach ($css['url'] as $url) { $headHTML .= Html::style($url, true, array( 'media' => 'screen, print' )) . "\n"; } array_unshift($css['files'], ResourceTranslator::toPath('$ss3-frontend$/dist/normalize.min.css')); foreach ($css['files'] as $file) { if (file_exists($file)) { $headHTML .= $this->addCSSFile($file); } else { } } if ($css['inline'] != '') { $headHTML .= Html::style($css['inline']) . "\n"; } $js = AssetManager::getJs(true); if ($js['globalInline'] != '') { $headHTML .= Html::script($js['globalInline']) . "\n"; } foreach ($js['url'] as $url) { $headHTML .= Html::scriptFile($url) . "\n"; } foreach ($js['files'] as $file) { $path = 'js/' . basename($file); if (file_exists($file)) { $this->files[$path] = file_get_contents($file); } else { } $headHTML .= Html::scriptFile($path) . "\n"; } if ($js['inline'] != '') { $headHTML .= Html::script($js['inline']) . "\n"; } $sliderHTML = preg_replace_callback('/(src|srcset)=["|\'](.*?)["|\']/i', array( $this, 'replaceHTMLImage' ), $sliderHTML); $sliderHTML = preg_replace_callback('/url\(\s*([\'"]|('))?(\S*\.(?:jpe?g|gif|png))([\'"]|('))?\s*\)[^;}]*?/i', array( $this, 'replaceHTMLBGImage' ), $sliderHTML); $sliderHTML = preg_replace_callback('/(data-href)=["|\'](.*?)["|\']/i', array( $this, 'replaceHTMLImage' ), $sliderHTML); $sliderHTML = preg_replace_callback('/(srcset)=["|\'](.*?)["|\']/i', array( $this, 'replaceHTMLRetinaImage' ), $sliderHTML); $sliderHTML = preg_replace_callback('/(data-n2-lightbox-urls)=["|\'](.*?)["|\']/i', array( $this, 'replaceLightboxImages' ), $sliderHTML); $sliderHTML = preg_replace_callback('/(data-n2-lightbox)=["|\'](.*?)["|\']/i', array( $this, 'replaceHTMLImageHrefLightbox' ), $sliderHTML); $headHTML = preg_replace_callback('/"([^"]*?\.(jpg|png|gif|jpeg|webp|svg|mp4))"/i', array( $this, 'replaceJSON' ), $headHTML); $headHTML = preg_replace_callback('/(--n2bgimage:URL\(")(.*?)("\);)/i', array( $this, 'replaceCssBGImage' ), $headHTML); $this->files['index.html'] = "\n\n
\n\n\n\n