public function actionEnd() { $this->validateToken(); $this->validatePermission('smartslider_edit'); $key = N2Request::getCmd('key'); N2SmartSliderSettings::set('guide-' . $key, 0); N2Message::notice('The ' . $key . ' guide completed. If you need it again, you can turn it on in the "Settings"!'); $this->response->respond(); }
public static function api($posts) { if (class_exists('JHttp')) { $posts_default = array('platform' => N2Platform::getPlatform()); $client = new JHttp(); $response = $client->post(self::$api, $posts + $posts_default, array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8')); if ($response->code != '200') { N2Message::error(n2_('Unable to contact with the licensing server, please try again later!')); return array('status' => 'ERROR_HANDLED'); } if (isset($response->headers['Content-Type'])) { $contentType = $response->headers['Content-Type']; } $data = $response->body; } if (!isset($data)) { if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, self::$api); $posts_default = array('platform' => N2Platform::getPlatform()); curl_setopt($ch, CURLOPT_POSTFIELDS, $posts + $posts_default); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $error = curl_error($ch); $curlErrorNumber = curl_errno($ch); curl_close($ch); if ($curlErrorNumber) { N2Message::error($curlErrorNumber . $error); return array('status' => 'ERROR_HANDLED'); } } else { $posts_default = array('platform' => N2Platform::getPlatform()); $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($posts + $posts_default))); $context = stream_context_create($opts); $data = file_get_contents(self::$api, false, $context); if ($data === false) { N2Message::error(n2_('CURL disabled in your php.ini configuration. Please enable it!')); return array('status' => 'ERROR_HANDLED'); } $headers = self::parseHeaders($http_response_header); if ($headers['status'] != '200') { N2Message::error(n2_('Unable to contact with the licensing server, please try again later!')); return array('status' => 'ERROR_HANDLED'); } if (isset($headers['content-type'])) { $contentType = $headers['content-type']; } } } switch ($contentType) { case 'application/json': return json_decode($data, true); } return $data; }
public function actionDuplicate() { if ($this->validateToken() && $this->validatePermission('smartslider_edit')) { if ($slideId = N2Request::getInt('slideid')) { $slidesModel = new N2SmartsliderSlidesModel(); $newSlideId = $slidesModel->duplicate($slideId); N2Message::success(n2_('Slide duplicated.')); $this->redirect(array("slides/edit", array("sliderid" => N2Request::getInt("sliderid"), "slideid" => $newSlideId))); } $this->redirect(array("sliders/index")); } }
public function actionDuplicate() { if ($this->validateToken() && $this->validatePermission('smartslider_edit')) { $slidersModel = new N2SmartsliderSlidersModel(); if (($sliderid = N2Request::getInt('sliderid')) && $slidersModel->get($sliderid)) { $newSliderId = $slidersModel->duplicate($sliderid); N2Message::success(n2_('Slider duplicated.')); $this->redirect(array("slider/edit", array("sliderid" => $newSliderId))); } $this->redirectToSliders(); } }
public function actionChangeVisual() { $this->validateToken(); $visualId = N2Request::getInt('visualId'); $this->validateVariable($visualId > 0, 'image'); $model = $this->getModel(); if ($visual = $model->changeVisual($visualId, N2Request::getVar('value'))) { $this->response->respond(array('visual' => $visual)); } N2Message::error(n2_('Unexpected error')); $this->response->error(); }
public function hasSlides() { //check slide number if (count($this->slides) === 0) { if (N2Platform::$isAdmin) { N2Message::error(n2_('0 slides available for this slider.')); } $this->slider->norender = true; return false; } return true; }
public function deAuthorize() { if ($this->hasKey()) { $status = $this->checkKey($this->key, 'licensedeauthorize'); if ($status == 'OK' || $status == 'LICENSE_EXPIRED' || $status == 'PLATFORM_NOT_ALLOWED') { $this->setKey(''); N2Message::notice('Smart Slider deauthorized on this site!'); } return $status; } return false; }
public function respond($data = null, $showNotification = true) { $this->response['data'] = $data; self::fix_output_buffer(); if ($showNotification) { $this->response['notification'] = N2Message::showAjax(); } header("Content-Type: application/json"); if ($this->isError) { header("HTTP/1.0 403 Forbidden"); } echo json_encode($this->response); n2_exit(true); }
public function actionClearCache() { if ($this->validatePermission('smartslider_config')) { if ($this->validateToken()) { $slidersModel = new N2SmartsliderSlidersModel(); foreach ($slidersModel->getAll() as $slider) { $slidersModel->refreshCache($slider['id']); } N2Cache::clearGroup('n2-ss-0'); N2Cache::clearGroup('combined'); N2Message::success(n2_('Cache cleared.')); } $this->redirect(array("settings/default")); } }
public function renderPlaceholder($sizes) { if (!$this->slider->isAdmin && $this->fadeOnLoad && ($this->slider->features->responsive->scaleDown || $this->slider->features->responsive->scaleUp)) { if (N2SystemHelper::testMemoryLimit()) { if ($sizes['width'] + $sizes['marginHorizontal'] > 0 && $sizes['height'] > 0 && function_exists('imagecreatetruecolor')) { return N2Html::tag("div", array("id" => $this->slider->elementId . "-placeholder", "encode" => false, "style" => 'position: relative;z-index:2;'), $this->makeImage($sizes)); } else { N2CSS::addCode("#{$this->slider->elementId} .n2-ss-load-fade{position: relative !important;}", $this->slider->cacheId); } } else { N2Message::error(n2_("It seems like the <a href='http://php.net/manual/en/ini.core.php#ini.memory-limit'>memory_limit</a> on the server is too low for the fade on load feature. Please set it minimum 60M and reload the page! You can disable this message in <a href='" . N2Form::$documentation . "#Troubleshooting-G-Server'>global configuration</a> 'Frontend debug message' option.")); } } else { N2CSS::addCode("#{$this->slider->elementId}.n2-ss-load-fade{position: relative !important;}", $this->slider->cacheId); } return ''; }
public function actionUpdate() { if ($this->validateToken()) { $status = N2SmartsliderUpdateModel::getInstance()->update(); $hasError = N2SS3::hasApiError($status); if (is_array($hasError)) { $this->redirect($hasError); } else { if ($hasError === false) { N2Message::success(n2_('Smart Slider 3 updated to the latest version!')); } } $this->redirectToSliders(); } else { $this->refresh(); } }
public function actionFonts() { if ($this->canDo('nextend_config')) { $fonts = N2Request::getVar('fonts', false); if ($fonts) { if ($this->validateToken()) { N2Fonts::storeSettings($fonts); N2Message::success(n2_('Saved.')); N2Request::redirect($this->appType->router->createUrl(array("settings/fonts"))); } else { $this->refresh(); } } $this->addView("../../inline/sidebar/settings", array("appObj" => $this), "sidebar"); $this->addView("fonts"); $this->render(); } }
public static function hasApiError($status, $data = array()) { extract($data); switch ($status) { case 'OK': return false; case 'PRODUCT_ASSET_NOT_AVAILABLE': N2Message::error(sprintf(n2_('Demo slider is not available with the following ID: %s'), $key)); case 'ASSET_PREMIUM': N2Message::error('Premium sliders are available in PRO version only!'); break; case 'LICENSE_EXPIRED': N2Message::error('Your license key expired!'); break; case 'DOMAIN_REGISTER_FAILED': N2Message::error('Your license key authorized on a different domain!'); break; case 'LICENSE_INVALID': N2Message::error('Your license key invalid, please enter again!'); N2SmartsliderLicenseModel::getInstance()->setKey(''); return array("sliders/index"); break; case 'UPDATE_ERROR': N2Message::error('Update error, please update manually!'); break; case 'PLATFORM_NOT_ALLOWED': N2Message::error(sprintf('Your license key is not valid for Smart Slider3 - %s!', N2Platform::getPlatformName())); break; case 'ERROR_HANDLED': break; case null: N2Message::error('Licensing server not reachable, try again later!'); break; default: N2Message::error('Debug: ' . $status); N2Message::error('Licensing server not reachable, try again later!'); break; } return true; }
public function actionSaveImage() { $this->validateToken(); N2Loader::import('libraries.image.aviary'); $image = N2Request::getVar('aviaryUrl'); $this->validateVariable(!empty($image), 'image'); require_once dirname(__FILE__) . '/Browse.php'; $root = N2Filesystem::getImagesFolder(); $folder = 'aviary'; $path = N2Filesystem::realpath($root . '/' . $folder); if ($path === false || $path == '') { N2Filesystem::createFolder($root . '/' . $folder); $path = N2Filesystem::realpath($root . '/' . $folder); } $tmp = tempnam(sys_get_temp_dir(), 'image-'); file_put_contents($tmp, file_get_contents($image)); $src = null; // Set variables for storage // fix file filename for query strings preg_match('/([^\\?]+)\\.(jpe?g|gif|png)\\b/i', $image, $matches); $file_array['name'] = basename($matches[1]); $file_array['tmp_name'] = $tmp; $file_array['size'] = filesize($tmp); $file_array['error'] = 0; try { $fileName = preg_replace('/[^a-zA-Z0-9_-]/', '', $file_array['name']); $upload = new N2BulletProof(); $file = $upload->uploadDir($path)->upload($file_array, $fileName); $src = N2ImageHelper::dynamic(N2Filesystem::pathToAbsoluteURL($file)); } catch (Exception $e) { N2Message::error($e->getMessage()); $this->response->error(); } if ($src) { $this->response->respond(array('image' => $src)); } else { N2Message::error(sprintf(n2_('Unexpected error: %s'), $image)); $this->response->error(); } }
public function render() { $slider = $this->slider; $params = $slider->params; $width = intval($params->get('width', 900)); $height = intval($params->get('height', 500)); if ($width < 10) { N2Message::error(n2_('Slider width is not valid number!')); } if ($height < 10) { N2Message::error(n2_('Slider height is not valid number!')); } $context = array('id' => "~'#{$slider->elementId}'", 'width' => $width . 'px', 'height' => $height . 'px', 'canvas' => 0, 'count' => count($slider->slides), 'margin' => '0px 0px 0px 0px', 'clear' => $params->get('weaker-selector', 0) ? 'clearv2.less' : 'clear.less'); $this->renderType($context); if ($params->get('imageload', 0)) { N2LESS::addFile(NEXTEND_SMARTSLIDER_ASSETS . '/less/spinner.less', $slider->cacheId, $context, NEXTEND_SMARTSLIDER_ASSETS . '/less' . NDS); } $this->sizes['marginVertical'] = 0; $this->sizes['marginHorizontal'] = 0; $this->sizes['width'] = intval($context['width']); $this->sizes['height'] = intval($context['height']); $this->sizes['canvasWidth'] = intval($context['canvaswidth']); $this->sizes['canvasHeight'] = intval($context['canvasheight']); }
* @var $widget Nav */ $logoUrl = N2Base::getApplication('system')->getLogo(); $cmd = N2Request::getVar("nextendcontroller", "dashboard"); echo $this->widget->init('nav', array('logoUrl' => $this->appType->router->createUrl("dashboard/index"), 'logoImageUrl' => $logoUrl, 'views' => array(N2Html::tag('a', array('href' => $this->appType->router->createUrl("dashboard/index"), 'class' => 'n2-h4 n2-uc ' . ($cmd == "dashboard" ? "n2-active" : "")), n2_('Dashboard')), N2Html::tag('a', array('href' => $this->appType->router->createUrl("settings/index"), 'class' => 'n2-h4 n2-uc ' . ($cmd == "settings" ? "n2-active" : "")), n2_('Settings')), N2Html::tag('a', array('href' => $this->appType->router->createUrl("help/index"), 'class' => 'n2-h4 n2-uc ' . ($cmd == "help" ? "n2-active" : "")), n2_('Help'))), 'actions' => $this->getFragmentValue('actions'))); ?> <div class="n2-table n2-table-fixed n2-content"> <div class="n2-tr"> <div class="n2-td n2-sidebar n2-sidebar-base-bg"> <?php $this->renderFragmentBlock('nextend_sidebar'); ?> </div> <div class="n2-td n2-content-base-bg"> <!-- Begin Content --> <div class="n2-content-area n2-border-radius-br"> <?php $this->renderFragmentBlock('nextend_content'); ?> </div> <!-- End Content --> </div> </div> </div> </div> <?php N2Message::show(); N2JS::addInline("new NextendExpertMode('nextend', 1);");
public function actionGetData() { $this->validateToken(); $this->validatePermission('smartslider_edit'); $group = N2Request::getVar('group'); $type = N2Request::getVar('type'); $generatorModel = new N2SmartsliderGeneratorModel(); $info = $generatorModel->getGeneratorInfo($group, $type); $configuration = $info->getConfiguration(); try { $this->response->respond(call_user_func(array($configuration, N2Request::getCmd('method')))); } catch (Exception $e) { N2Message::error($e->getMessage()); $this->response->error(); } }
protected function validateDatabase($condition) { if (!$condition) { N2Message::error(n2_('Database error')); $this->response->error(); } }
public function actionImportDemo() { $this->validateToken(); $this->validatePermission('smartslider_edit'); $key = 'http:' . base64_decode(N2Request::getVar('key')); if (strpos($key, 'http://smartslider3.com/') !== 0) { N2Message::error(sprintf(n2_('Import url is not valid: %s'), $key)); $this->response->error(); } $posts = array('action' => 'asset', 'asset' => $key); $result = N2SS3::api($posts); if (!is_string($result)) { $hasError = N2SS3::hasApiError($result['status'], array('key' => $key)); if (is_array($hasError)) { $this->redirect($hasError); } else { if ($hasError !== false) { $this->response->error(); } } } else { N2Loader::import(array('models.Sliders', 'models.Slides'), 'smartslider'); N2Loader::import('libraries.import', 'smartslider'); $import = new N2SmartSliderImport(); $sliderId = $import->import($result, 'clone', 1, false); if ($sliderId !== false) { N2Message::success(n2_('Slider imported.')); $this->response->redirect(array("slider/edit", array("sliderid" => $sliderId))); } else { N2Message::error(n2_('Import error!')); $this->response->error(); } } $this->response->respond(); }
public function actionQuickEdit() { $this->validateToken(); $this->validatePermission('smartslider_edit'); $sliderId = N2Request::getInt('sliderid'); $this->validateVariable($sliderId > 0, 'Slider'); $slidesModel = new N2SmartsliderSlidesModel(); $slides = $slidesModel->getAll($sliderId); $changed = json_decode(base64_decode(N2Request::getVar('changed')), true); if (!$changed || !is_array($changed)) { $changed = array(); } foreach ($slides as $slide) { if (!empty($changed[$slide['id']])) { $slidesModel->quickSlideUpdate($slide, $changed[$slide['id']]['name'], $changed[$slide['id']]['description'], $changed[$slide['id']]['link']); } } $sliderObj = new N2SmartSlider($sliderId, array()); $slides = $slidesModel->getAll($sliderId); $slidesObj = array(); foreach ($slides as $i => $slide) { if (!empty($changed[$slide['id']])) { $slidesObj[$i] = new N2SmartSliderSlide($sliderObj, $slide); $slidesObj[$i]->initGenerator(); } } $updateSlideBox = array(); /** @var N2SmartSliderSlide $slideObj */ foreach ($slidesObj as $slideObj) { $slideObj->fillSample(); $updateSlideBox[$slideObj->id] = array('title' => $slideObj->getTitle() . ($slideObj->hasGenerator() ? ' [' . $slideObj->getSlideStat() . ']' : ''), 'rawTitle' => $slideObj->getRawTitle(), 'rawDescription' => $slideObj->getRawDescription(), 'rawLink' => $slideObj->getRawLink()); } N2Message::success(sprintf(n2_('%d slide(s) modified!'), count($slidesObj))); $this->response->respond($updateSlideBox); }
public function import($filePathOrData, $imageImportMode = 'clone', $linkedVisuals = 1, $isFilePath = true) { $zip = new N2ZipRead(); $importData = $zip->read_zip($filePathOrData, $isFilePath); if (!isset($importData['data'])) { if (array_key_exists("slider.ss2", $importData)) { N2Message::error(n2_('You can\'t import sliders from Smart Slider 2.')); } return false; } $this->backup = unserialize($importData['data']); $this->sectionTranslation = array(); $this->importVisuals($this->backup->visuals, $linkedVisuals); $sliderModel = new N2SmartsliderSlidersModel(); if ($this->restore) { $this->sliderId = $sliderModel->restore($this->backup->slider); } else { $this->sliderId = $sliderModel->import($this->backup->slider); } if (!$this->sliderId) { return false; } switch ($imageImportMode) { case 'clone': $images = $importData['images']; $imageStore = new N2StoreImage('slider' . $this->sliderId, true); foreach ($images as $file => $content) { $localImage = $imageStore->makeCache($file, $content); if ($localImage) { $this->imageTranslation[$file] = N2ImageHelper::dynamic(N2Uri::pathToUri($localImage)); } else { $this->imageTranslation[$file] = $file; } if (!$this->imageTranslation[$file]) { $this->imageTranslation[$file] = array_search($file, $this->backup->imageTranslation); } } break; case 'update': $keys = array_keys($this->backup->NextendImageHelper_Export); $values = array_values($this->backup->NextendImageHelper_Export); foreach ($this->backup->imageTranslation as $image => $value) { $this->imageTranslation[$value] = str_replace($keys, $values, $image); } break; default: break; } foreach ($this->backup->NextendImageManager_ImageData as $image => $data) { $data['tablet']['image'] = $this->fixImage($data['tablet']['image']); $data['mobile']['image'] = $this->fixImage($data['mobile']['image']); N2ImageManager::addImageData($this->fixImage($image), $data); } unset($importData); 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, 'import'), 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, 'prepareImport'), array($this, $params)); } else { unset($enabledWidgets); } } $sliderModel->importUpdate($this->sliderId, $params); $generatorTranslation = array(); N2Loader::import("models.generator", "smartslider"); $generatorModel = new N2SmartsliderGeneratorModel(); foreach ($this->backup->generators as $generator) { $generatorTranslation[$generator['id']] = $generatorModel->import($generator); } $slidesModel = new N2SmartsliderSlidesModel(); for ($i = 0; $i < count($this->backup->slides); $i++) { $slide = $this->backup->slides[$i]; $slide['params'] = new N2Data($slide['params'], true); $slide['thumbnail'] = $this->fixImage($slide['thumbnail']); $slide['params']->set('backgroundImage', $this->fixImage($slide['params']->get('backgroundImage'))); $slide['params']->set('link', $this->fixLightbox($slide['params']->get('link'))); $slide['slide'] = N2SmartSliderLayer::prepareImport($this, $slide['slide']); if (isset($generatorTranslation[$slide['generator_id']])) { $slide['generator_id'] = $generatorTranslation[$slide['generator_id']]; } $slidesModel->import($slide, $this->sliderId); } return $this->sliderId; }
public function actionFinishAuth() { if ($this->validatePermission('smartslider_config')) { $generatorModel = new N2SmartsliderGeneratorModel(); $group = N2Request::getVar('group'); $type = N2Request::getVar('type'); $info = $generatorModel->getGeneratorInfo($group, $type); $configuration = $info->getConfiguration(); $result = $configuration->finishAuth(); if ($result === true) { N2Message::success(n2_('Authentication successful.')); echo '<script>window.opener.location.reload();self.close();</script>'; } else { if ($result instanceof Exception) { $message = $result->getMessage(); } else { $message = 'Something wrong with the credentials'; } echo '<script>window.opener.nextend.notificationCenter.error("' . htmlspecialchars($message) . '");self.close();</script>'; } n2_exit(true); } }
public static function showAjax() { self::loadSessionError(); $messages = array(); if (is_array(self::$error) && count(self::$error)) { $messages['error'] = array(); foreach (self::$error as $error) { $messages['error'][] = $error; } self::$error = array(); } self::loadSessionSuccess(); if (is_array(self::$success) && count(self::$success)) { $messages['success'] = array(); foreach (self::$success as $success) { $messages['success'][] = $success; } self::$success = array(); } self::loadSessionNotice(); if (is_array(self::$notice) && count(self::$notice)) { $messages['notice'] = array(); foreach (self::$notice as $notice) { $messages['notice'][] = $notice; } self::$notice = array(); } self::$flushed = true; if (count($messages)) { return $messages; } return false; }
public function actionUpload() { if (defined('N2_IMAGE_UPLOAD_DISABLE')) { N2Message::error(n2_('You are not allowed to upload!')); $this->response->error(); } $this->validateToken(); $root = N2Filesystem::getImagesFolder(); $folder = ltrim(rtrim(N2Request::getVar('path', ''), '/'), '/'); $path = N2Filesystem::realpath($root . '/' . $folder); if ($path === false || $path == '') { $folder = preg_replace("/[^A-Za-z0-9]/", '', $folder); if (empty($folder)) { N2Message::error(n2_('Folder is missing!')); $this->response->error(); } else { N2Filesystem::createFolder($root . '/' . $folder); $path = N2Filesystem::realpath($root . '/' . $folder); } } $relativePath = $this->relative($path, $root); if (!$relativePath) { $relativePath = ''; } $response = array('path' => $relativePath); try { if (isset($_FILES) && isset($_FILES['image']) && isset($_FILES['image']['name'])) { $info = pathinfo($_FILES['image']['name']); $fileName = preg_replace('/[^a-zA-Z0-9_-]/', '', $info['filename']); if (strlen($fileName) == 0) { $fileName = ''; } $upload = new N2BulletProof(); $file = $upload->uploadDir($path)->upload($_FILES['image'], $fileName); $response['name'] = basename($file); $response['url'] = N2ImageHelper::dynamic(N2Filesystem::pathToAbsoluteURL($file)); } } catch (Exception $e) { N2Message::error($e->getMessage()); $this->response->error(); } $this->response->respond($response); }
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(); } }