public function actionEdit() { if ($this->validatePermission('smartslider_edit')) { $generatorId = N2Request::getInt('generator_id'); $generatorModel = new N2SmartsliderGeneratorModel(); $generator = $generatorModel->get($generatorId); if ($this->validateDatabase($generator)) { $slidesModel = new N2SmartsliderSlidesModel(); $slides = $slidesModel->getAll(-1, 'OR generator_id = ' . $generator['id'] . ''); if (count($slides) > 0) { $slide = $slides[0]; if (N2Request::getInt('save')) { $request = new N2Data(N2Request::getVar('generator')); $slideParams = new N2Data($slide['params'], true); $slideParams->set('record-slides', $request->get('record-slides', 1)); $slidesModel->updateParams($slide['id'], $slideParams->toArray()); $request->un_set('record-slides'); $generatorModel->save($generatorId, $request->toArray()); N2SmartsliderSlidesModel::markChanged($slide['slider']); N2Message::success(n2_('Generator updated and cache cleared.')); $this->redirect(array("generator/edit", array("generator_id" => $generatorId)), 302, true); } N2Request::set('sliderid', $slide['slider']); $this->addView("../../inline/_sliders", array("appObj" => $this), "sidebar"); $this->addView("edit", array("generatorModel" => $generatorModel, "generator" => $generator, "slide" => $slide)); $this->render(); } else { $this->redirect(array("sliders/index"), 302, true); } } else { $this->redirect(array("sliders/index"), 302, true); } } }
public function actionRecordsTable() { $this->validateToken(); $this->validatePermission('smartslider_edit'); $generatorId = N2Request::getInt('generator_id'); $generatorModel = new N2SmartsliderGeneratorModel(); if ($generatorId > 0) { $generator = $generatorModel->get($generatorId); $this->validateDatabase($generator); } else { $info = new N2Data(N2Request::getVar('generator')); $generator = array('group' => $info->get('group'), 'type' => $info->get('type'), 'params' => '{}'); } $info = $generatorModel->getGeneratorInfo($generator['group'], $generator['type']); $generator['params'] = new N2Data($generator['params'], true); $generator['params']->loadArray(N2Request::getVar('generator')); require_once $info->path . '/generator.php'; $class = 'N2Generator' . $generator['group'] . $generator['type']; /** @var N2GeneratorAbstract $dataSource */ $dataSource = new $class($info, $generator['params']); $request = new N2Data(N2Request::getVar('generator')); $group = max(intval($request->get('record-group', 1)), 1); $result = $dataSource->getData(max($request->get('record-slides', 1), 1), max($request->get('record-start', 1), 1), $group); if (count($result)) { ob_start(); $headings = array(); for ($i = 1; $i <= $group; $i++) { $headings[] = '#'; foreach ($result[0][0] as $k => $v) { $headings[] = '{' . $k . '/' . $i . '}'; } } $headingHTML = N2Html::tag('thead', array(), N2Html::tag('tr', array(), '<th>' . implode('</th><th>', $headings) . '</th>')); $rows = array(); $i = 0; foreach ($result as $records) { foreach ($records as $g => $record) { $rows[$i][] = $i + 1; foreach ($record as $k => $v) { $rows[$i][] = N2Html::tag('div', array(), htmlentities($v)); } } $i++; } for ($i = 0; $i < count($rows); $i++) { $rows[$i] = '<td>' . implode('</td><td>', $rows[$i]) . '</td>'; } $recordHTML = N2Html::tag('tbody', array(), '<tr>' . implode('</tr><tr>', $rows) . '</tr>'); echo N2Html::tag('div', array('style' => 'width: 100%; height: 100%; overflow: auto;'), N2Html::tag('table', array('class' => 'n2-generator-records n2-table n2-table-fancy', 'style' => 'margin: 10px; width: auto; table-layout: fixed;'), $headingHTML . $recordHTML)); $this->response->respond(array('html' => ob_get_clean())); } else { N2Message::notice('No records found for the filter'); $this->response->error(); } }
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()); } } }