public function makeCache($fileName, $content) { if (!$this->isImage($fileName)) { return false; } $targetFile = $this->getStorageFilePath($fileName); if (!$this->isCached($fileName)) { N2Filesystem::createFile($targetFile, $content); } return $targetFile; }
private function createCacheFile($fileName, $hash, $content) { $manifestData = array(); $manifestData['hash'] = $hash; $this->addManifestData($manifestData); N2Filesystem::createFile($this->getManifestFilePath($fileName), json_encode($manifestData)); N2Filesystem::createFile($this->getStorageFilePath($fileName), $this->isRaw ? $content : json_encode($content)); if ($this->isAccessible) { return $this->getStorageFilePath($fileName); } return $content; }
protected function addManifestData(&$manifestData) { $manifestData['nextCacheRefresh'] = N2Pluggable::applyFilters('SSNextCacheRefresh', $this->parameters['slider']->slidesBuilder->getNextCacheRefresh(), array($this->parameters['slider'])); $variations = 1; $params = $this->parameters['slider']->params; if ($params->get('randomize', 0) || $params->get('randomizeFirst', 0)) { $variations = intval($params->get('variations', 5)); if ($variations < 1) { $variations = 1; } } N2Filesystem::createFile($this->getManifestFilePath('variations'), $variations); }
public function make() { $hash = $this->getHash(); $file = $this->getStorageFilePath($hash . '.' . $this->fileType); if (!$this->isCached($file)) { $buffer = ''; for ($i = 0; $i < count($this->files); $i++) { $buffer .= file_get_contents($this->files[$i]); } if ($this->minify !== false) { $buffer = call_user_func($this->minify, $buffer); } N2Filesystem::createFile($file, $buffer); } return $file; }
private function createCacheFile($fileName, $content) { return N2Filesystem::createFile($this->getStorageFilePath($fileName), $content); }
function recursive_extract($files, $targetFolder) { foreach ($files as $fileName => $file) { if (is_array($file)) { if (N2Filesystem::createFolder($targetFolder . $fileName . '/')) { $this->recursive_extract($file, $targetFolder . $fileName . '/'); } else { return false; } } else { if (!N2Filesystem::createFile($targetFolder . $fileName, $file)) { return false; } } } return true; }
public function create($saveAsFile = false) { $this->backup = new N2SmartSliderBackup(); $slidersModel = new N2SmartsliderSlidersModel(); if ($this->backup->slider = $slidersModel->get($this->sliderId)) { $this->backup->slider['params'] = new N2Data($this->backup->slider['params'], true); $slidesModel = new N2SmartsliderSlidesModel(); $this->backup->slides = $slidesModel->getAll($this->backup->slider['id']); if (empty($this->backup->slider['type'])) { $this->backup->slider['type'] = 'simple'; } $class = 'N2SSPluginType' . $this->backup->slider['type']; N2Loader::importPath(call_user_func(array($class, "getPath")) . NDS . 'backup'); $class = 'N2SmartSliderBackup' . $this->backup->slider['type']; call_user_func_array(array($class, 'export'), array($this, $this->backup->slider)); $enabledWidgets = array(); $plugins = array(); N2Plugin::callPlugin('sswidget', 'onWidgetList', array(&$plugins)); $params = $this->backup->slider['params']; foreach ($plugins as $k => $v) { $widget = $params->get('widget' . $k); if ($widget && $widget != 'disabled') { $enabledWidgets[$k] = $widget; } } foreach ($enabledWidgets as $k => $v) { $class = 'N2SSPluginWidget' . $k . $v; if (class_exists($class, false)) { $params->fillDefault(call_user_func(array($class, 'getDefaults'))); call_user_func_array(array($class, 'prepareExport'), array($this, &$params)); } else { unset($enabledWidgets); } } for ($i = 0; $i < count($this->backup->slides); $i++) { $slide = $this->backup->slides[$i]; self::addImage($slide['thumbnail']); $slide['params'] = new N2Data($slide['params'], true); self::addImage($slide['params']->get('backgroundImage')); self::addLightbox($slide['params']->get('link')); N2SmartSliderLayer::prepareExport($this, $slide['slide']); if (!empty($slide['generator_id'])) { N2Loader::import("models.generator", "smartslider"); $generatorModel = new N2SmartsliderGeneratorModel(); $this->backup->generators[] = $generatorModel->get($slide['generator_id']); } } $zip = new N2ZipFile(); $this->images = array_unique($this->images); $this->visuals = array_unique($this->visuals); foreach ($this->images as $image) { $this->backup->NextendImageManager_ImageData[$image] = N2ImageManager::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 = N2ImageHelper::fixed($image, true); if (N2Filesystem::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[] = N2StorageSectionAdmin::getById($visual); } $zip->addFile(serialize($this->backup), 'data'); if (!$saveAsFile) { ob_end_clean(); header('Content-disposition: attachment; filename=' . preg_replace('/[^a-zA-Z0-9_-]/', '', $this->backup->slider['title']) . '.ss3'); header('Content-type: application/zip'); echo $zip->file(); n2_exit(true); } else { $file = preg_replace('/[^a-zA-Z0-9_-]/', '', $this->backup->slider['title']) . '.ss3'; $folder = N2Platform::getPublicDir(); $folder .= '/export/'; if (!N2Filesystem::existsFolder($folder)) { N2Filesystem::createFolder($folder); } N2Filesystem::createFile($folder . $file, $zip->file()); } } }