Beispiel #1
0
 protected function _load()
 {
     if (!is_array($this->_options) || empty($this->_options) || !isset($this->_options[0]) || !$this->_options[0] || preg_match('~^\\s*$~', $this->_options[0])) {
         throw new Exceptions_SeotoasterException($this->_translator->translate('You should specify folder.'));
     }
     $configHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('config');
     $imageFolder = self::DEFAULT_PICS_FOLDER;
     $sliderWidth = isset($this->_options[3]) && $this->_options[3] ? $this->_options[3] : self::DEFAULT_SLIDER_WIDTH;
     if ($sliderWidth <= $configHelper->getConfig('imgSmall')) {
         $imageFolder = 'small';
     } elseif ($sliderWidth <= $configHelper->getConfig('imgMedium')) {
         $imageFolder = 'medium';
     } elseif ($sliderWidth <= $configHelper->getConfig('imgLarge')) {
         $imageFolder = 'large';
     }
     $fullPathToPics = $this->_websiteHelper->getPath() . $this->_websiteHelper->getMedia() . $this->_options[0] . '/' . $imageFolder . '/';
     $this->_view->mediaServersAllowed = $configHelper->getConfig('mediaServers');
     $this->_view->uniq = uniqid('rotator-');
     $this->_view->sliderWidth = isset($this->_options[3]) && $this->_options[3] ? $this->_options[3] : self::DEFAULT_SLIDER_WIDTH;
     $this->_view->sliderHeight = isset($this->_options[4]) && $this->_options[4] ? $this->_options[4] : self::DEFAULT_SLIDER_HEIGHT;
     $this->_view->swapTime = isset($this->_options[2]) && $this->_options[2] ? $this->_options[2] : self::DEFAULT_SWAP_TIME;
     $this->_view->slideShow = isset($this->_options[1]) && $this->_options[1] ? true : false;
     $files = Tools_Filesystem_Tools::scanDirectory($fullPathToPics, false, false);
     if ($this->_view->slideShow) {
         $this->_view->files = $files;
     } else {
         $this->_view->files = (array) $files[array_rand($files)];
     }
     //$this->_view->files        = ($this->_view->slideShow) ? $files : $files[0];
     $this->_view->folder = $this->_options[0] . '/' . $imageFolder . '/';
     $this->_view->effect = isset($this->_options[5]) && $this->_options[5] ? $this->_options[5] : self::DEFAULT_SWAP_EFFECT;
     return $this->_view->render('rotator.phtml');
 }
Beispiel #2
0
 protected function _load()
 {
     if (!is_array($this->_options) || empty($this->_options) || !isset($this->_options[0]) || !$this->_options[0] || preg_match('~^\\s*$~', $this->_options[0])) {
         throw new Exceptions_SeotoasterException($this->_translator->translate('You should specify folder.'));
     }
     $configHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('config');
     $path = $this->_websiteHelper->getPath() . $this->_websiteHelper->getMedia() . $this->_options[0] . '/';
     $mediaServersAllowed = $configHelper->getConfig('mediaServers');
     unset($configHelper);
     $websiteData = $mediaServersAllowed ? Zend_Registry::get('website') : null;
     $thumbSize = isset($this->_options[1]) ? $this->_options[1] : self::DEFAULT_THUMB_SIZE;
     $useCrop = isset($this->_options[2]) ? (bool) $this->_options[2] : false;
     $useCaption = isset($this->_options[3]) ? (bool) $this->_options[3] : false;
     if (!is_dir($path)) {
         throw new Exceptions_SeotoasterException($path . ' is not a directory.');
     }
     $sourceImages = Tools_Filesystem_Tools::scanDirectory($path . 'original/');
     $galFolder = $path . ($useCrop ? 'crop/' : 'thumbnails/');
     if (!is_dir($galFolder)) {
         @mkdir($galFolder);
     }
     foreach ($sourceImages as $key => $image) {
         if (is_file($galFolder . $image)) {
             $imgInfo = getimagesize($galFolder . $image);
             if ($imgInfo[0] != $thumbSize) {
                 Tools_Image_Tools::resize($path . 'original/' . $image, $thumbSize, !$useCrop, $galFolder, $useCrop);
             }
         } else {
             Tools_Image_Tools::resize($path . 'original/' . $image, $thumbSize, !$useCrop, $galFolder, $useCrop);
         }
         $sourcePart = str_replace($this->_websiteHelper->getPath(), $this->_websiteHelper->getUrl(), $galFolder);
         if ($mediaServersAllowed) {
             $mediaServer = Tools_Content_Tools::getMediaServer();
             $cleanWebsiteUrl = str_replace('www.', '', $websiteData['url']);
             $sourcePart = str_replace($websiteData['url'], $mediaServer . '.' . $cleanWebsiteUrl, $sourcePart);
         }
         $sourceImages[$key] = array('path' => $sourcePart . $image, 'name' => $image);
     }
     $this->_view->folder = $this->_options[0];
     $this->_view->original = str_replace($this->_websiteHelper->getPath(), $this->_websiteHelper->getUrl(), $path) . 'original/';
     $this->_view->images = $sourceImages;
     $this->_view->useCaption = $useCaption;
     $this->_view->galFolderPath = $galFolder;
     $this->_view->mediaServersAllowed = $mediaServersAllowed;
     $this->_view->galFolder = str_replace($this->_websiteHelper->getPath(), $this->_websiteHelper->getUrl(), $galFolder);
     return $this->_view->render('gallery.phtml');
 }
Beispiel #3
0
 public static function zip($themeName, $addFiles = false, $exclude = null)
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website');
     $configHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('config');
     $themesConfig = Zend_Registry::get('theme');
     $zip = new ZipArchive();
     $destinationFile = $websiteHelper->getPath() . $websiteHelper->getTmp() . $themeName . '.zip';
     $themePath = $websiteHelper->getPath() . $themesConfig['path'] . $themeName;
     if (true === $zip->open($destinationFile, ZIPARCHIVE::CREATE)) {
         $themeFiles = Tools_Filesystem_Tools::scanDirectory($themePath, true, true);
         foreach ($themeFiles as $file) {
             if (is_array($exclude) && in_array(Tools_Filesystem_Tools::basename($file), $exclude)) {
                 continue;
             }
             $localName = str_replace($themePath, '', $file);
             $localName = trim($localName, DIRECTORY_SEPARATOR);
             $zip->addFile($file, $localName);
             unset($localName);
         }
         if (!empty($addFiles)) {
             foreach ($addFiles as $file) {
                 $file = urldecode($file);
                 $realPath = $websiteHelper->getPath() . $file;
                 if (!file_exists($realPath)) {
                     continue;
                 } elseif (is_array($exclude) && in_array(Tools_Filesystem_Tools::basename($file), $exclude)) {
                     continue;
                 }
                 $pathParts = explode(DIRECTORY_SEPARATOR, $file);
                 if ($pathParts[0] === 'media' && sizeof($pathParts) === 4) {
                     // removing original folder level from zip
                     unset($pathParts[2]);
                     $zip->addFile($websiteHelper->getPath() . $file, implode(DIRECTORY_SEPARATOR, $pathParts));
                 } else {
                     // assume that this is a preview file
                     $zip->addFile($realPath, $file);
                 }
                 unset($realPath, $pathParts);
             }
         }
         $zip->close();
         return $destinationFile;
     } else {
         throw new Exceptions_SeotoasterException('Unable to write ' . $destinationFile);
     }
 }
Beispiel #4
0
 public static function zip($pathToFile, $name = '', $excludeFiles = array())
 {
     //extend script execution time limit
     $execTime = ini_get('max_execution_time');
     set_time_limit(self::EXECUTION_TIME_LIMIT);
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website');
     $zipArch = new ZipArchive();
     $files = array($pathToFile);
     $exploded = explode('/', $pathToFile);
     $localName = preg_replace('~\\.[\\w]+$~', '', end($exploded));
     $destinationFile = $websiteHelper->getPath() . 'tmp/' . ($name ? $name : $localName) . '.zip';
     if (file_exists($destinationFile)) {
         @unlink($destinationFile);
     }
     if (is_dir($pathToFile)) {
         $files = Tools_Filesystem_Tools::scanDirectory($pathToFile, true, true);
         $exclude = array();
         foreach ($excludeFiles as $excludePath) {
             if (is_dir($excludePath)) {
                 $exclude = array_merge(Tools_Filesystem_Tools::scanDirectory($excludePath, true, true), $exclude);
             } else {
                 array_push($exclude, $excludePath);
             }
         }
         $files = array_diff($files, $exclude);
     }
     $zipArch->open($destinationFile, ZipArchive::OVERWRITE);
     if (!empty($files)) {
         foreach ($files as $key => $path) {
             $zipArch->addFile($path, substr($path, strpos($path, $localName)));
         }
     }
     $zipArch->close();
     //set back default execution time limit
     set_time_limit($execTime);
     return $destinationFile;
 }
 private function _validatePlugin($pluginName)
 {
     $pluginFolder = realpath($this->_uploadHandler->getDestination() . '/' . $pluginName);
     if ($pluginFolder === false) {
         return 'Plugin directory don\'t match the archive name.';
     }
     if (!is_dir($pluginFolder)) {
         return 'Can not create folder for unpack zip file. 0peration not permitted.';
     }
     $listFiles = Tools_Filesystem_Tools::scanDirectory($pluginFolder);
     if (empty($listFiles)) {
         return 'Your plugin directory is empty.';
     }
     if (!preg_match("/^[a-zA-Z-0-9]{1,255}\$/", $pluginName)) {
         return 'Theme name is invalid. Only letters, digits and dashes allowed.';
     }
     if (!in_array(ucfirst($pluginName) . '.php', $listFiles)) {
         return 'Plugin main file doesn\'t exist or has a wrong name';
     }
     if (!in_array('readme.txt', $listFiles)) {
         return 'File "readme.txt" doesn\'t exist.';
     }
     return true;
 }
Beispiel #6
0
 /**
  * Get a list of themes or start theme download
  *
  * Supported params:
  * 1. name - Theme name. Tells API that this is an attempt to download a theme
  *     E.g. http://seotoaster.dev/api/toaster/themes/name/ecommerce
  * 2. kind [full|light] - Type of theme to download. Requires name param
  *     E.g. http://seotoaster.dev/api/toaster/themes/name/ecommerce/kind/full
  * 3. sql [1|0] - Tells API to include or not sql dump to the full theme. Requires name and kind=full
  *     E.g. http://seotoaster.dev/api/toaster/themes/name/ecommerce/kind/full/sql/0
  * 4. media [1|0] - Tells API to include or not media directory to the full theme. Requires name and kind=full
  *     E.g. http://seotoaster.dev/api/toaster/themes/name/ecommerce/kind/full/media/0
  * 5. teasers [1|0] - Tells API to include or not previews directory to the full theme. Requires name and kind=full
  *     E.g. http://seotoaster.dev/api/toaster/themes/name/ecommerce/kind/full/teasers/0
  * Full example
  *     http://seotoaster.dev/api/toaster/themes/name/ecommerce/kind/full/sql/0/media/1/teasers/1
  * @return array
  */
 public function getAction()
 {
     $themesPath = $this->_websiteHelper->getPath() . $this->_themesConfig['path'];
     // if parameter 'name' specified in the query, we assume user is trying to download a theme
     if ($this->_request->has('name')) {
         $themeName = filter_var($this->_request->getParam('name'), FILTER_SANITIZE_STRING);
         $themePath = $themesPath . $themeName;
         // check if full theme requested - perform necessary actions
         $isFull = $this->_request->has('kind') && $this->_request->getParam('kind') == self::THEME_KIND_FULL;
         // exporting theme
         $this->_exportTheme($themeName, $isFull);
     }
     // themes list request
     $themesList = array();
     $themesDirs = Tools_Filesystem_Tools::scanDirectoryForDirs($themesPath);
     // there are no themes in the theme directory
     if (empty($themesDirs)) {
         $this->_error($this->_translator->translate('Aw! No themes found!'), self::REST_STATUS_NOT_FOUND);
     }
     foreach ($themesDirs as $themeName) {
         $files = Tools_Filesystem_Tools::scanDirectory($themesPath . $themeName, false, false);
         $requiredFiles = preg_grep('/^(' . implode('|', $this->_protectedTemplates) . ')\\.html$/i', $files);
         if (sizeof($requiredFiles) != sizeof($this->_protectedTemplates)) {
             continue;
         }
         $previews = preg_grep('/^preview\\.(png|jpg|gif)$/i', $files);
         $hasData = file_exists($themesPath . $themeName . DIRECTORY_SEPARATOR . self::THEME_DATA_FILE) || is_dir($themesPath . $themeName . DIRECTORY_SEPARATOR . 'media/') || is_dir($themesPath . $themeName . DIRECTORY_SEPARATOR . 'previews/');
         array_push($themesList, array('name' => $themeName, 'preview' => !empty($previews) ? $this->_websiteHelper->getUrl() . $this->_themesConfig['path'] . $themeName . '/' . reset($previews) : $this->_websiteHelper->getUrl() . 'system/images/noimage.png', 'isCurrent' => $this->_configHelper->getConfig('currentTheme') == $themeName, 'hasData' => $hasData));
     }
     if (empty($themesList)) {
         $this->_error($this->_translator->translate('Aw! Looks like none of your themes are valid!'), self::REST_STATUS_NOT_FOUND);
     }
     return $themesList;
 }
 /**
  * Action used for removing images/files from media catalog
  * for AJAX request
  * @return JSON
  */
 public function removefileAction()
 {
     if ($this->getRequest()->isPost()) {
         $folderName = $this->getRequest()->getParam('folder');
         if (empty($folderName)) {
             $this->view->errorMsg = $this->_translator->translate('No folder specified');
             return false;
         }
         $removeImages = $this->getRequest()->getParam('removeImages');
         $removeFiles = $this->getRequest()->getParam('removeFiles');
         $errorList = array();
         $folderPath = realpath($this->_websiteConfig['path'] . $this->_websiteConfig['media'] . $folderName);
         if (!isset($removeFiles) && !isset($removeImages)) {
             $this->view->errorMsg = $this->_translator->translate('Nothing to remove');
         }
         if (!$folderPath || !is_dir($folderPath)) {
             $this->view->errorMsg = $this->_translator->translate('No such folder');
             return false;
         }
         //list of removed files
         $deleted = array();
         //processing images
         if (isset($removeImages) && is_array($removeImages)) {
             foreach ($removeImages as $imageName) {
                 //checking if this image in any container
                 $pages = $this->_checkFileInContent($folderName . '%' . $imageName);
                 if (!empty($pages)) {
                     array_push($errorList, array('name' => $imageName, 'errors' => $pages));
                 } else {
                     // going to remove image
                     try {
                         $result = Tools_Image_Tools::removeImageFromFilesystem($imageName, $folderName);
                         if ($result !== true) {
                             array_push($errorList, array('name' => $imageName, 'errors' => $result));
                         } else {
                             //cleaning out the images related widgets
                             $this->_helper->cache->clean(null, null, array('Widgets_Gal_Gal'));
                             array_push($deleted, $imageName);
                         }
                     } catch (Exceptions_SeotoasterException $e) {
                         error_log($e->getMessage() . PHP_EOL . $e->getTraceAsString());
                     }
                 }
             }
         }
         //processing files
         if (isset($removeFiles) && is_array($removeFiles)) {
             foreach ($removeFiles as $fileName) {
                 if (!is_file($folderPath . DIRECTORY_SEPARATOR . $fileName)) {
                     $errorList[$fileName] = $this->_translator->translate($folderPath . DIRECTORY_SEPARATOR . $fileName . ': file not found');
                 }
                 //checking if this image in any container
                 $pages = $this->_checkFileInContent($fileName);
                 if (!empty($pages)) {
                     array_push($errorList, array('name' => $fileName, 'errors' => $pages));
                 }
                 try {
                     $result = Tools_Filesystem_Tools::deleteFile($folderPath . DIRECTORY_SEPARATOR . $fileName);
                     if ($result !== true) {
                         array_push($errorList, array('name' => $fileName, 'errors' => $this->_translator->translate("Can't remove file. Permission denied")));
                     } else {
                         array_push($deleted, $fileName);
                     }
                 } catch (Exception $e) {
                     error_log($e->getMessage() . PHP_EOL . $e->getTraceAsString());
                 }
             }
         }
         if (!empty($deleted)) {
             $folderContent = Tools_Filesystem_Tools::scanDirectory($folderPath, false, true);
             if (empty($folderContent)) {
                 try {
                     $this->view->folderRemoved = Tools_Filesystem_Tools::deleteDir($folderPath);
                 } catch (Exception $e) {
                     error_log($e->getMessage());
                 }
             }
         }
         $this->view->errors = empty($errorList) ? false : $errorList;
         $this->view->deleted = $deleted;
     } else {
         $this->_redirect($this->_helper->website->getUrl(), array('exit' => true));
     }
 }
Beispiel #8
0
 public static function findPluginPreview($pluginName)
 {
     $website = Zend_Controller_Action_HelperBroker::getStaticHelper('Website');
     $misc = Zend_Registry::get('misc');
     $pluginsPath = $website->getPath() . $misc['pluginsPath'] . $pluginName;
     $files = Tools_Filesystem_Tools::scanDirectory($pluginsPath, false, false);
     array_walk($files, function ($file) {
         if (preg_match('~^preview\\.(jpg|gif|png)$~ui', $file)) {
             Zend_Registry::set('previewFile', $file);
         }
     });
     if (Zend_Registry::isRegistered('previewFile')) {
         return $website->getUrl() . $misc['pluginsPath'] . $pluginName . '/' . Zend_Registry::get('previewFile');
     }
     return false;
 }
 public function loadimagesAction()
 {
     //@todo add images to the cache?
     $this->_helper->getHelper('layout')->disableLayout();
     if ($this->getRequest()->isPost()) {
         $imagesData = array();
         $folderName = $this->getRequest()->getParam('folderName');
         $imagesPath = $this->_websiteData['path'] . $this->_websiteData['media'] . $folderName;
         try {
             $imagesData = array('small' => '<div class="images-preview list-images">' . $this->_proccessImages(Tools_Filesystem_Tools::scanDirectory($imagesPath . '/' . self::IMG_CONTENTTYPE_SMALL), $imagesPath, $folderName, self::IMG_CONTENTTYPE_SMALL) . '</div>', 'medium' => '<div class="images-preview list-images">' . $this->_proccessImages(Tools_Filesystem_Tools::scanDirectory($imagesPath . '/' . self::IMG_CONTENTTYPE_MEDIUM), $imagesPath, $folderName, self::IMG_CONTENTTYPE_MEDIUM) . '</div>', 'large' => '<div class="images-preview list-images">' . $this->_proccessImages(Tools_Filesystem_Tools::scanDirectory($imagesPath . '/' . self::IMG_CONTENTTYPE_LARGE), $imagesPath, $folderName, self::IMG_CONTENTTYPE_LARGE) . '</div>', 'original' => '<div class="images-preview list-images">' . $this->_proccessImages(Tools_Filesystem_Tools::scanDirectory($imagesPath . '/' . self::IMG_CONTENTTYPE_ORIGINAL), $imagesPath, $folderName, self::IMG_CONTENTTYPE_ORIGINAL) . '</div>');
         } catch (Exceptions_SeotoasterException $se) {
             $imagesData = array('small' => $this->_helper->language->translate('No images were found'), 'medium' => $this->_helper->language->translate('No images were found'), 'large' => $this->_helper->language->translate('No images were found'), 'original' => $this->_helper->language->translate('No images were found'));
         }
         $this->getResponse()->setBody(json_encode($imagesData))->sendResponse();
     }
     exit;
 }