Esempio n. 1
0
 function fetchElement()
 {
     $dir = N2Platform::getPublicDir();
     $extension = N2XmlHelper::getAttribute($this->_xml, 'extension');
     $files = scandir($dir);
     $validated_files = array();
     foreach ($files as $file) {
         if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == $extension) {
             $validated_files[] = $file;
         }
     }
     $this->_xml->addChild('option', n2_('Choose a file to import'))->addAttribute('value', '');
     foreach ($validated_files as $f) {
         $this->_xml->addChild('option', $f)->addAttribute('value', $f);
     }
     return parent::fetchElement();
 }
Esempio n. 2
0
 public static function getImagesFolder()
 {
     return N2Platform::getPublicDir();
 }
Esempio n. 3
0
<?php

$this->widget->init('topbar', array("actions" => array(N2Html::tag('a', array('href' => $this->appType->router->createUrl(array('sliders/index')), 'class' => 'n2-button n2-button-red n2-button-big n2-h4 n2-b n2-uc'), n2_('Cancel')), N2Html::tag('a', array('href' => '#', 'class' => 'n2-button n2-button-green n2-button-big n2-h4 n2-b n2-uc', 'onclick' => 'return NextendForm.submit("#smartslider-form");'), n2_('Import')))));
?>
<form id="smartslider-form" action="" method="post">
    <?php 
$_class->renderImportFromServerForm();
?>
    <input name="save" value="1" type="hidden"/>
</form>

<div class="n2-form ">
    <div class="n2-form-tab ">
        <div class="n2-h2 n2-content-box-title-bg"><?php 
n2_e('Instructions');
?>
</div>

        <div class="n2-description">
            <p><?php 
printf(n2_('Smart Slider export files are listed from the directory only with <i>ss3</i> extension: %s'), N2Platform::getPublicDir());
?>
            </p>
        </div>
    </div>
</div>
<?php 
N2SS3::showBeacon('Import slider');
Esempio n. 4
0
 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());
         }
     }
 }
Esempio n. 5
0
 public function actionImportFromServer()
 {
     if ($this->validatePermission('smartslider_edit')) {
         if (N2Request::getInt('save')) {
             if ($this->validateToken()) {
                 $data = new N2Data(N2Request::getVar('slider'));
                 $file = $data->get('import-file');
                 if (empty($file)) {
                     N2Message::error(n2_('Please select a file!'));
                     $this->refresh();
                 } else {
                     $dir = N2Platform::getPublicDir();
                     if (N2Filesystem::fileexists($dir . '/' . $file)) {
                         N2Loader::import('libraries.import', 'smartslider');
                         $import = new N2SmartSliderImport();
                         $sliderId = $import->import($dir . '/' . $file, $data->get('image-mode', 'clone'), $data->get('linked-visuals', 0));
                         if ($sliderId !== false) {
                             if ($data->get('delete')) {
                                 @unlink($dir . '/' . $file);
                             }
                             N2Message::success(n2_('Slider imported.'));
                             $this->redirect(array("slider/edit", array("sliderid" => $sliderId)));
                         } else {
                             N2Message::error(n2_('Import error!'));
                             $this->refresh();
                         }
                     } else {
                         N2Message::error(n2_('The chosen file is missing!'));
                         $this->refresh();
                     }
                 }
             } else {
                 $this->refresh();
             }
         }
         $this->addView('importFromServer');
         $this->render();
     }
 }