Example #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');
 }
Example #2
0
 private function _generatePreviewOption()
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Website');
     $pageHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Page');
     $files = Tools_Filesystem_Tools::findFilesByExtension($websiteHelper->getPath() . $websiteHelper->getPreview(), '(jpg|gif|png|jpeg)', false, false, false);
     $pagePreviews = array_values(preg_grep('~^' . $pageHelper->clean(preg_replace('~/+~', '-', $this->_toasterOptions['url'])) . '\\.(png|jpg|gif|jpeg)$~', $files));
     if (!empty($pagePreviews)) {
         $path = isset($this->_options) && end($this->_options) == 'crop' ? $websiteHelper->getPreviewCrop() : $websiteHelper->getPreview();
         return '<img class="page-teaser-image" src="' . $websiteHelper->getUrl() . $path . $pagePreviews[0] . '" alt="' . $pageHelper->clean($this->_toasterOptions['url']) . '" />';
     }
     return;
 }
Example #3
0
 public static function getNames()
 {
     $includePath = explode(PATH_SEPARATOR, get_include_path());
     $widgetsNames = array();
     foreach ($includePath as $path) {
         if (is_readable($path . DIRECTORY_SEPARATOR . 'Widgets')) {
             $widgetsNames = array_merge($widgetsNames, Tools_Filesystem_Tools::scanDirectoryForDirs($path . DIRECTORY_SEPARATOR . 'Widgets'));
         }
     }
     sort($widgetsNames);
     return $widgetsNames;
 }
Example #4
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');
 }
Example #5
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);
     }
 }
Example #6
0
 protected function _load()
 {
     if (!file_exists($this->_themeFullPath . '/' . self::FILENAME) || $this->_refresh) {
         $concatContent = '';
         $cssFiles = $this->_sortCss(Tools_Filesystem_Tools::findFilesByExtension($this->_themeFullPath, self::FILES_EXTENSION, true));
         foreach ($cssFiles as $key => $cssFile) {
             if (in_array(basename($cssFile), $this->_excludeFiles)) {
                 continue;
             }
             $concatContent .= $this->_addCss($cssFile);
         }
         try {
             Tools_Filesystem_Tools::saveFile($this->_themeFullPath . '/' . self::FILENAME, $concatContent);
         } catch (Exceptions_SeotoasterException $ste) {
             return $ste->getMessage();
         }
     }
     return '<link href="' . $this->_toasterOptions['websiteUrl'] . $this->_themeFullPath . '/' . self::FILENAME . '" rel="stylesheet" type="text/css" media="screen" />';
 }
Example #7
0
 /**
  * Returns a list of available translation languages
  * @param $detailed boolean Fetch additional info for translation
  * @return array List of translations
  */
 public function getLanguages($detailed = true)
 {
     $websiteConfigHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('website');
     $languageIcons = Tools_Filesystem_Tools::findFilesByExtension($websiteConfigHelper->getPath() . $this->_langFlagsDir, 'png', false, true, false);
     $this->_languages = array();
     $loadedList = Zend_Registry::get('Zend_Translate')->getAdapter()->getList();
     foreach ($languageIcons as $country => $imgFile) {
         $locale = new Zend_Locale(Zend_Locale::getLocaleToTerritory($country));
         $lang = $locale->getLanguage();
         $langTitle = Zend_Locale::getTranslation($lang, 'language');
         if (!in_array($locale->getLanguage(), $loadedList)) {
             continue;
         }
         if ($detailed) {
             $this->_languages[$country] = array('locale' => $locale->toString(), 'language' => $langTitle, 'name' => $country, 'flag' => $this->_langFlagsDir . $imgFile);
         } else {
             $this->_languages[$country] = $langTitle;
         }
         unset($locale);
     }
     return $this->_languages;
 }
Example #8
0
 public static function processPagePreviewImage($pageUrl, $tmpPreviewFile = null)
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website');
     $pageHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('page');
     $websiteConfig = Zend_Registry::get('website');
     $pageUrl = str_replace(DIRECTORY_SEPARATOR, '-', $pageHelper->clean($pageUrl));
     $previewPath = $websiteHelper->getPath() . $websiteHelper->getPreview();
     //        $filelist           = Tools_Filesystem_Tools::findFilesByExtension($previewPath, '(jpg|gif|png)', false, false, false);
     $currentPreviewList = glob($previewPath . $pageUrl . '.{jpg,jpeg,png,gif}', GLOB_BRACE);
     if ($tmpPreviewFile) {
         $tmpPreviewFile = str_replace($websiteHelper->getUrl(), $websiteHelper->getPath(), $tmpPreviewFile);
         if (is_file($tmpPreviewFile) && is_readable($tmpPreviewFile)) {
             preg_match('/\\.[\\w]{2,6}$/', $tmpPreviewFile, $extension);
             $newPreviewImageFile = $previewPath . $pageUrl . $extension[0];
             //cleaning form existing page previews
             if (!empty($currentPreviewList)) {
                 foreach ($currentPreviewList as $key => $file) {
                     if (file_exists($file)) {
                         if (Tools_Filesystem_Tools::deleteFile($file)) {
                             //                                unset($currentPreviewList[$key]);
                         }
                     }
                 }
             }
             if (is_writable($newPreviewImageFile)) {
                 $status = @rename($tmpPreviewFile, $newPreviewImageFile);
             } else {
                 $status = @copy($tmpPreviewFile, $newPreviewImageFile);
             }
             if ($status && file_exists($tmpPreviewFile)) {
                 Tools_Filesystem_Tools::deleteFile($tmpPreviewFile);
             }
             $miscConfig = Zend_Registry::get('misc');
             //check for the previews crop folder and try to create it if not exists
             $cropPreviewDirPath = $websiteHelper->getPath() . $websiteHelper->getPreviewCrop();
             if (!is_dir($cropPreviewDirPath)) {
                 @mkdir($cropPreviewDirPath);
             } else {
                 // unlink old croped page previews
                 if (!empty($currentPreviewList)) {
                     foreach ($currentPreviewList as $fileToUnlink) {
                         $unlinkPath = str_replace($previewPath, $cropPreviewDirPath, $fileToUnlink);
                         if (file_exists($unlinkPath)) {
                             unlink($unlinkPath);
                         }
                     }
                 }
             }
             Tools_Image_Tools::resize($newPreviewImageFile, $miscConfig['pageTeaserCropSize'], false, $cropPreviewDirPath, true);
             unset($miscConfig);
             return $pageUrl . $extension[0];
             //                return $websiteHelper->getUrl() . $websiteConfig['preview'] . $pageUrl . $extension[0];
         }
     }
     if (sizeof($currentPreviewList) == 0) {
         return false;
     } else {
         $pagePreviewImage = str_replace($websiteHelper->getPath(), $websiteHelper->getUrl(), reset($currentPreviewList));
     }
     return $pagePreviewImage;
 }
 /**
  * @param $fileNameWithPath
  * @param bool $needle
  * @return string
  */
 protected function _getFileContent($fileNameWithPath, $needle = false)
 {
     if ($needle) {
         return stristr(trim(Tools_Filesystem_Tools::getFile($fileNameWithPath)), $needle);
     } else {
         return trim(Tools_Filesystem_Tools::getFile($fileNameWithPath));
     }
 }
Example #10
0
 /**
  * Method removes images with given name in the given directory via recursive scan of subfolders
  * such as, small, medium, etc.
  * @param string $imageName Name of image to be deleted
  * @param string $folderName Name of folder where image is
  * @return mixed  Boolean true on success of all operations array with errors
  * @return mixed  Boolean false on empty parameters given
  * @return mixed  Array with errors if something went wrong
  */
 public static function removeImageFromFilesystem($imageName, $folderName)
 {
     $imageName = trim($imageName);
     $folderName = trim($folderName);
     if (empty($imageName) || empty($folderName)) {
         return false;
     }
     $websiteConfig = Zend_Registry::get('website');
     $folderPath = $websiteConfig['path'] . $websiteConfig['media'] . $folderName;
     if (!is_dir($folderPath)) {
         throw new Exceptions_SeotoasterException('Wrong folder name specified');
     }
     $errorCount = 0;
     $subFoldersList = array_merge(self::$imgResizedFolders, array('original'));
     //list of file that can be removed
     $removable = array();
     foreach ($subFoldersList as $key => $subfolder) {
         if (!is_dir($folderPath . DIRECTORY_SEPARATOR . $subfolder)) {
             error_log('Not a folder:' . $folderPath . DIRECTORY_SEPARATOR . $subfolder);
             unset($subFoldersList[$key]);
             continue;
         }
         $filename = $folderPath . DIRECTORY_SEPARATOR . $subfolder . DIRECTORY_SEPARATOR . $imageName;
         //checking if enough permission to remove file
         if (is_file($filename)) {
             array_push($removable, $filename);
         }
     }
     /**
      * checking if we can remove all files at once
      * if not - returning with error
      */
     foreach ($removable as $file) {
         if (!is_writable($file)) {
             return 'Permission denied';
         }
     }
     foreach ($removable as $file) {
         try {
             Tools_Filesystem_Tools::deleteFile($file);
         } catch (Exceptions_SeotoasterException $e) {
             $errorCount++;
             error_log($file . ': ' . $e->getMessage());
         }
     }
     if ($errorCount) {
         return false;
     }
     return true;
 }
 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;
 }
Example #12
0
 /**
  * Method exports zipped theme
  * @param string $themeName Theme name
  * @param bool   $full      Set true to dump data and media files
  */
 protected function _exportTheme($themeName = '', $full = false, $noZip = false)
 {
     if (!$themeName) {
         $themeName = $this->_configHelper->getConfig('currentTheme');
     }
     $themePath = $this->_websiteHelper->getPath() . $this->_themesConfig['path'] . $themeName . DIRECTORY_SEPARATOR;
     $websitePath = $this->_websiteHelper->getPath();
     if ($full) {
         /**
          * @var $dbAdapter Zend_Db_Adapter_Abstract
          */
         $dbAdapter = Zend_Registry::get('dbAdapter');
         // exporting themes data for the full theme
         // init empty array for export data
         $data = array('page' => array());
         // and for media files
         $mediaFiles = array();
         // fetching index page and main menu pages
         $pagesSqlWhere = "SELECT * FROM `page` WHERE system = '0' AND draft = '0' AND (\n\t\t\turl = 'index.html' OR (parent_id = '0' AND show_in_menu = '1') OR (parent_id = '-1' AND show_in_menu = '2')\n\t\t    OR (parent_id = '0' OR parent_id IN (SELECT DISTINCT `page`.`id` FROM `page` WHERE (parent_id = '0') AND (system = '0') AND (show_in_menu = '1')) )\n\t\t    OR id IN ( SELECT DISTINCT `page_id` FROM `page_fa` )\n\t\t    OR id IN ( SELECT DISTINCT `page_id` FROM `page_has_option` )\n\t\t    ) ORDER BY `order` ASC";
         $pages = $dbAdapter->fetchAll($pagesSqlWhere);
         if (is_array($pages) && !empty($pages)) {
             $data['page'] = $pages;
             unset($pages);
         }
         // combining list of queries for export others tables content
         $queryList = array();
         $enabledPlugins = Tools_Plugins_Tools::getEnabledPlugins(true);
         foreach ($enabledPlugins as $plugin) {
             $pluginsData = Tools_Plugins_Tools::runStatic(self::PLUGIN_EXPORT_METHOD, $plugin);
             if (!$pluginsData) {
                 continue;
             }
             if (isset($pluginsData['pages']) && is_array($pluginsData['pages']) && !empty($pluginsData['pages'])) {
                 $data['page'] = array_merge($data['page'], $pluginsData['pages']);
             }
             if (isset($pluginsData['tables']) && is_array($pluginsData['tables']) && !empty($pluginsData['tables'])) {
                 foreach ($pluginsData['tables'] as $table => $query) {
                     if (array_key_exists($table, $this->_fullThemesSqlMap)) {
                         continue;
                     }
                     $queryList[$table] = $query;
                     unset($table, $query);
                 }
             }
             if (isset($pluginsData['media']) && is_array($pluginsData['media']) && !empty($pluginsData['media'])) {
                 $mediaFiles = array_unique(array_merge($mediaFiles, $pluginsData['media']));
             }
         }
         unset($enabledPlugins);
         // getting list of pages ids for export
         $pagesIDs = array_map(function ($page) {
             return $page['id'];
         }, $data['page']);
         // building list of dump queries and executing it with page IDS substitution
         $queryList = array_merge($this->_fullThemesSqlMap, $queryList);
         foreach ($queryList as $table => $query) {
             $data[$table] = $dbAdapter->fetchAll($dbAdapter->quoteInto($query, $pagesIDs));
         }
         unset($queryList, $pagesIDs);
         if (!empty($data)) {
             $exportData = new Zend_Config($data);
             $themeDataFile = new Zend_Config_Writer_Json(array('config' => $exportData, 'filename' => $themePath . self::THEME_DATA_FILE));
             $themeDataFile->write();
         }
         // exporting list of media files
         $totalFileSize = 0;
         // initializing files size counter
         $previewFolder = $this->_websiteHelper->getPreview();
         $pagePreviews = array_filter(array_map(function ($page) use($previewFolder) {
             return !empty($page['preview_image']) ? $previewFolder . $page['preview_image'] : false;
         }, $data['page']));
         $contentImages = array();
         // list of images from containers
         if (!empty($data['container'])) {
             foreach ($data['container'] as $container) {
                 preg_match_all('~media[^"\']*\\.(?:jpe?g|gif|png)~iu', $container['content'], $matches);
                 if (!empty($matches[0])) {
                     $contentImages = array_merge($contentImages, array_map(function ($file) {
                         $file = explode(DIRECTORY_SEPARATOR, $file);
                         if ($file[2] !== 'original') {
                             $file[2] = 'original';
                         }
                         return implode(DIRECTORY_SEPARATOR, $file);
                     }, $matches[0]));
                 }
                 unset($matches, $container);
             }
         }
         $mediaFiles = array_merge($pagePreviews, $contentImages, $mediaFiles);
         $mediaFiles = array_unique(array_filter($mediaFiles));
         if (!empty($mediaFiles)) {
             clearstatcache();
             foreach ($mediaFiles as $key => $file) {
                 if (!is_file($websitePath . $file)) {
                     $mediaFiles[$key] = null;
                     continue;
                 }
                 $totalFileSize += filesize($websitePath . $file);
             }
         }
         if ($totalFileSize > self::THEME_FULL_MAX_FILESIZE) {
             $this->_error('Too many images');
         } else {
             $mediaFiles = array_filter($mediaFiles);
         }
     }
     // if requested name is current one we create system file with template types
     if ($themeName === $this->_configHelper->getConfig('currentTheme')) {
         // saving template types into theme.ini. @see Tools_Template_Tools::THEME_CONFIGURATION_FILE
         $themeIniConfig = new Zend_Config(array(), true);
         foreach (Application_Model_Mappers_TemplateMapper::getInstance()->fetchAll() as $template) {
             $themeIniConfig->{$template->getName()} = $template->getType();
         }
         if (!empty($themeIniConfig)) {
             try {
                 $iniWriter = new Zend_Config_Writer_Ini(array('config' => $themeIniConfig, 'filename' => $themePath . Tools_Template_Tools::THEME_CONFIGURATION_FILE));
                 $iniWriter->write();
             } catch (Exception $e) {
                 Tools_System_Tools::debugMode() && error_log($e->getMessage());
             }
         }
         unset($themeIniConfig, $iniWriter);
     }
     //defining list files that needs to be excluded
     $excludeFiles = array();
     if (!$full) {
         array_push($excludeFiles, self::THEME_DATA_FILE);
     }
     if ($noZip === true) {
         // backup media files to theme subfolder
         if (!empty($mediaFiles)) {
             if (!is_dir($themePath . 'previews')) {
                 Tools_Filesystem_Tools::mkDir($themePath . 'previews');
             }
             if (!is_dir($themePath . 'media')) {
                 Tools_Filesystem_Tools::mkDir($themePath . 'media');
             }
             foreach ($mediaFiles as $file) {
                 if (!is_file($websitePath . $file)) {
                     continue;
                 }
                 $path = explode(DIRECTORY_SEPARATOR, $file);
                 if (!is_array($path) || empty($path)) {
                     continue;
                 }
                 switch ($path[0]) {
                     case 'previews':
                         list($folder, $filename) = $path;
                         break;
                     case 'media':
                         $folder = 'media' . DIRECTORY_SEPARATOR . $path[1];
                         if (!is_dir($themePath . $folder)) {
                             Tools_Filesystem_Tools::mkDir($themePath . $folder);
                         }
                         $filename = end($path);
                         break;
                     default:
                         continue;
                         break;
                 }
                 $destination = $themePath . $folder . DIRECTORY_SEPARATOR . $filename;
                 try {
                     $r = Tools_Filesystem_Tools::copy($websitePath . $file, $destination);
                 } catch (Exception $e) {
                     Tools_System_Tools::debugMode() && error_log($e->getMessage());
                 }
             }
         }
         return true;
     } else {
         //create theme zip archive
         $themeArchive = Tools_Theme_Tools::zip($themeName, isset($mediaFiles) ? $mediaFiles : false, $excludeFiles);
         if ($themeArchive) {
             $body = file_get_contents($themeArchive);
             if (false !== $body) {
                 Tools_Filesystem_Tools::deleteFile($themeArchive);
             } else {
                 $this->_error('Unable to read website archive file');
             }
         } else {
             $this->_error('Can\'t create website archive');
         }
         //outputting theme zip
         $this->_response->clearAllHeaders()->clearBody();
         $this->_response->setHeader('Content-Disposition', 'attachment; filename=' . $themeName . '.zip')->setHeader('Content-Type', 'application/zip', true)->setHeader('Content-Transfer-Encoding', 'binary', true)->setHeader('Expires', date(DATE_RFC1123), true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Pragma', 'public', true)->setBody($body)->sendResponse();
         exit;
     }
 }
Example #13
0
 public static function minifyJs($jsList)
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('website');
     $cacheHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('cache');
     if (null === ($hashStack = $cacheHelper->load(strtolower(__CLASS__), ''))) {
         $hashStack = array();
     }
     $container = $jsList->getContainer();
     foreach ($container->getArrayCopy() as $js) {
         if (isset($js->attributes['src'])) {
             if (strpos($js->attributes['src'], $websiteHelper->getUrl()) === false) {
                 continue;
                 //ignore file if file from remote
             }
             if (isset($js->attributes['nominify']) || preg_match('/min\\.js$/', $js->attributes['src']) != false) {
                 continue;
                 //ignore file if special attribute given or src ends with 'min.js'
             }
             $path = str_replace($websiteHelper->getUrl(), '', $js->attributes['src']);
             if (!file_exists($websiteHelper->getPath() . $path)) {
                 continue;
             }
             $hash = sha1_file($websiteHelper->getPath() . $path);
             if (!isset($hashStack[$path]) || $hashStack[$path]['hash'] !== $hash) {
                 $hashStack[$path] = array('hash' => $hash, 'content' => JSMin::minify(Tools_Filesystem_Tools::getFile($websiteHelper->getPath() . $path)));
                 Tools_Filesystem_Tools::saveFile($websiteHelper->getPath() . $websiteHelper->getTmp() . $hash . '.min.js', $hashStack[$path]['content']);
             }
             $js->attributes['src'] = $websiteHelper->getUrl() . $websiteHelper->getTmp() . $hash . '.min.js?' . Tools_Filesystem_Tools::basename($path);
         } elseif (!empty($js->source)) {
             if (!isset($js->attributes['nominify'])) {
                 $js->source = JSMin::minify($js->source);
             }
         }
     }
     $cacheHelper->save(strtolower(__CLASS__), $hashStack, '', array(), Helpers_Action_Cache::CACHE_LONG);
     return $jsList;
 }
 /**
  * Method which delete template (AJAX)
  */
 public function deletetemplateAction()
 {
     if ($this->getRequest()->isPost()) {
         $mapper = Application_Model_Mappers_TemplateMapper::getInstance();
         $templateId = $this->getRequest()->getPost('id');
         if ($templateId) {
             $template = $mapper->find($templateId);
             if ($template instanceof Application_Model_Models_Template && !in_array($template->getName(), $this->_protectedTemplates)) {
                 $result = $mapper->delete($template);
                 if ($result) {
                     $currentThemePath = realpath($this->_websiteConfig['path'] . $this->_themeConfig['path'] . $this->_helper->config->getConfig('currentTheme'));
                     $filename = $currentThemePath . DIRECTORY_SEPARATOR;
                     if ($template->getType() === Application_Model_Models_Template::TYPE_MOBILE && preg_match('~^mobile_~', $template->getName())) {
                         $filename .= preg_replace('~^mobile_~', 'mobile' . DIRECTORY_SEPARATOR, $template->getName());
                     } else {
                         $filename .= $template->getName();
                     }
                     $filename .= '.html';
                     Tools_Filesystem_Tools::deleteFile($filename);
                     $status = $this->_translator->translate('Template deleted.');
                 } else {
                     $status = $this->_translator->translate('Can\'t delete template or template doesn\'t exists.');
                 }
                 $this->_helper->response->response($status, false);
             }
         }
         $this->_helper->response->response($this->_translator->translate('Template doesn\'t exists'), false);
     }
 }
 public function exportAction()
 {
     if ($this->getRequest()->isPost()) {
         if (Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_USERS)) {
             $users = Application_Model_Mappers_UserMapper::getInstance()->fetchAll();
             $dataToExport = array();
             foreach ($users as $user) {
                 $usrData = $user->toArray();
                 unset($usrData['password']);
                 unset($usrData['id']);
                 unset($usrData['attributes']);
                 $dataToExport[] = $usrData;
             }
             $exportResult = Tools_System_Tools::arrayToCsv($dataToExport, array($this->_helper->language->translate('E-mail'), $this->_helper->language->translate('Role'), $this->_helper->language->translate('Full name'), $this->_helper->language->translate('Last login date'), $this->_helper->language->translate('Registration date'), $this->_helper->language->translate('IP address')));
             if ($exportResult) {
                 $usersArchive = Tools_System_Tools::zip($exportResult);
                 $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename=' . Tools_Filesystem_Tools::basename($usersArchive))->setHeader('Content-type', 'application/force-download');
                 readfile($usersArchive);
                 $this->getResponse()->sendResponse();
             }
             exit;
         }
     }
 }
 public function refreshfoldersAction()
 {
     $websiteData = Zend_Registry::get('website');
     $this->_helper->response->success(Tools_Filesystem_Tools::scanDirectoryForDirs($websiteData['path'] . $websiteData['media']));
 }
Example #17
0
 public static function getSystemVersion()
 {
     try {
         return Tools_Filesystem_Tools::getFile('version.txt');
     } catch (Exceptions_SeotoasterException $se) {
         if (self::debugMode()) {
             error_log($se->getMessage());
         }
     }
     return '';
 }
 public function deleteAction()
 {
     if ($this->getRequest()->isPost()) {
         $plugin = Tools_Plugins_Tools::findPluginByName($this->getRequest()->getParam('id'));
         $plugin->registerObserver(new Tools_Plugins_GarbageCollector(array('action' => Tools_System_GarbageCollector::CLEAN_ONDELETE)));
         $miscData = Zend_Registry::get('misc');
         $sqlFilePath = $this->_helper->website->getPath() . $miscData['pluginsPath'] . $plugin->getName() . '/system/' . Application_Model_Models_Plugin::UNINSTALL_FILE_NAME;
         if (file_exists($sqlFilePath)) {
             $sqlFileContent = Tools_Filesystem_Tools::getFile($sqlFilePath);
             if (strlen($sqlFileContent)) {
                 $queries = Tools_System_SqlSplitter::split($sqlFileContent);
             }
         }
         $delete = Tools_Filesystem_Tools::deleteDir($this->_helper->website->getPath() . 'plugins/' . $plugin->getName());
         if (!$delete) {
             $this->_helper->response->fail('Can\'t remove plugin\'s directory (not enough permissions). Plugin was uninstalled.');
             exit;
         }
         if (is_array($queries) && !empty($queries)) {
             $dbAdapter = Zend_Registry::get('dbAdapter');
             try {
                 array_walk($queries, function ($query, $key, $adapter) {
                     if (strlen(trim($query))) {
                         $adapter->query($query);
                     }
                 }, $dbAdapter);
                 Application_Model_Mappers_PluginMapper::getInstance()->delete($plugin);
             } catch (Exception $e) {
                 error_log($e->getMessage());
                 $this->_helper->response->fail($e->getMessage());
             }
         }
         $this->_helper->cache->clean(null, null, array('plugins'));
         $this->_helper->cache->clean('admin_addmenu', $this->_helper->session->getCurrentUser()->getRoleId());
         $this->_helper->response->success('Removed');
     }
 }
Example #19
0
 private function _createFile($content)
 {
     $filePath = $this->_folderŠ”ssPath . self::FILE_NAME_PREFIX . $this->_fileCode . '.css';
     try {
         Tools_Filesystem_Tools::saveFile($filePath, $content);
     } catch (Exceptions_SeotoasterException $ste) {
         return $ste->getMessage();
     }
     return str_replace(' ', '%20', $filePath);
 }
 public function receiveformAction()
 {
     if ($this->getRequest()->isPost()) {
         $xmlHttpRequest = $this->_request->isXmlHttpRequest();
         $formParams = $this->getRequest()->getParams();
         $sessionHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Session');
         if (!empty($formParams)) {
             $websiteConfig = Zend_Controller_Action_HelperBroker::getExistingHelper('config')->getConfig();
             $formMapper = Application_Model_Mappers_FormMapper::getInstance();
             // get the form details
             $form = $formMapper->findByName($formParams['formName']);
             $useCaptcha = $form->getCaptcha();
             //hidden input validation
             $formName = $form->getName();
             $formId = $form->getId();
             if (!isset($formParams[md5($formName . $formId)]) || $formParams[md5($formName . $formId)] != '') {
                 if ($xmlHttpRequest) {
                     $this->_helper->response->success($form->getMessageSuccess());
                 }
                 $this->_redirect($formParams['formUrl']);
             }
             unset($formParams[md5($formName . $formId)]);
             //validating recaptcha
             if ($useCaptcha == 1) {
                 if (!empty($websiteConfig) && !empty($websiteConfig[Tools_System_Tools::RECAPTCHA_PUBLIC_KEY]) && !empty($websiteConfig[Tools_System_Tools::RECAPTCHA_PRIVATE_KEY]) && isset($formParams['recaptcha_challenge_field']) || isset($formParams['captcha'])) {
                     if (isset($formParams['recaptcha_challenge_field']) && isset($formParams['recaptcha_response_field'])) {
                         if ($formParams['recaptcha_response_field'] == '') {
                             if ($xmlHttpRequest) {
                                 $this->_helper->response->fail($this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.'));
                             }
                             $sessionHelper->toasterFormError = $this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.');
                             $this->_redirect($formParams['formUrl']);
                         }
                         $recaptcha = new Zend_Service_ReCaptcha($websiteConfig[Tools_System_Tools::RECAPTCHA_PUBLIC_KEY], $websiteConfig[Tools_System_Tools::RECAPTCHA_PRIVATE_KEY]);
                         $result = $recaptcha->verify($formParams['recaptcha_challenge_field'], $formParams['recaptcha_response_field']);
                         if (!$result->isValid()) {
                             if ($xmlHttpRequest) {
                                 $this->_helper->response->fail($this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.'));
                             }
                             $sessionHelper->toasterFormError = $this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.');
                             $this->_redirect($formParams['formUrl']);
                         }
                         unset($formParams['recaptcha_challenge_field']);
                         unset($formParams['recaptcha_response_field']);
                     } else {
                         //validating captcha
                         if (!$this->_validateCaptcha(strtolower($formParams['captcha']), $formParams['captchaId'])) {
                             if ($xmlHttpRequest) {
                                 $this->_helper->response->fail($this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.'));
                             }
                             $sessionHelper->toasterFormError = $this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.');
                             $this->_redirect($formParams['formUrl']);
                         }
                     }
                 } else {
                     if ($xmlHttpRequest) {
                         $this->_helper->response->fail($this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.'));
                     }
                     $sessionHelper->toasterFormError = $this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.');
                     $this->_redirect($formParams['formUrl']);
                 }
             }
             $sessionHelper->formName = $formParams['formName'];
             $sessionHelper->formPageId = $formParams['formPageId'];
             unset($formParams['formPageId']);
             unset($formParams['submit']);
             if (isset($formParams['conversionPageUrl'])) {
                 $conversionPageUrl = $formParams['conversionPageUrl'];
                 unset($formParams['conversionPageUrl']);
             }
             $attachment = array();
             if (!$xmlHttpRequest) {
                 //Adding attachments to email
                 $websitePathTemp = $this->_helper->website->getPath() . $this->_helper->website->getTmp();
                 $uploader = new Zend_File_Transfer_Adapter_Http();
                 $uploader->setDestination($websitePathTemp);
                 $uploader->addValidator('Extension', false, self::ATTACHMENTS_FILE_TYPES);
                 //Adding Size limitation
                 $uploader->addValidator('Size', false, $formParams['uploadLimitSize'] * 1024 * 1024);
                 //Adding mime types validation
                 $uploader->addValidator('MimeType', true, array('application/pdf', 'application/xml', 'application/zip', 'text/csv', 'text/plain', 'image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'application/msword', 'application/vnd.ms-excel'));
                 $files = $uploader->getFileInfo();
                 foreach ($files as $file => $fileInfo) {
                     if ($fileInfo['name'] != '') {
                         if ($uploader->isValid($file)) {
                             $uploader->receive($file);
                             $at = new Zend_Mime_Part(file_get_contents($uploader->getFileName($file)));
                             $at->type = $uploader->getMimeType($file);
                             $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
                             $at->encoding = Zend_Mime::ENCODING_BASE64;
                             $at->filename = $fileInfo['name'];
                             $attachment[] = $at;
                             unset($at);
                             Tools_Filesystem_Tools::deleteFile($this->_helper->website->getPath() . $this->_helper->website->getTmp() . $fileInfo['name']);
                         } else {
                             $validationErrors = $uploader->getErrors();
                             $errorMessage = '';
                             foreach ($validationErrors as $errorType) {
                                 if ($errorType == 'fileMimeTypeFalse') {
                                     $errorMessage .= 'Invalid file format type. ';
                                 }
                                 if ($errorType == 'fileSizeTooBig') {
                                     $errorMessage .= $this->_helper->language->translate('Maximum size upload') . ' ' . $formParams['uploadLimitSize'] . 'mb.';
                                 }
                                 if ($errorType == 'fileExtensionFalse') {
                                     $errorMessage .= 'File extension not valid. ';
                                 }
                             }
                             $sessionHelper->toasterFormError = $this->_helper->language->translate($errorMessage);
                             $this->_redirect($formParams['formUrl']);
                         }
                     }
                 }
             }
             unset($formParams['uploadLimitSize']);
             // sending mails
             $sysMailWatchdog = new Tools_Mail_SystemMailWatchdog(array('trigger' => Tools_Mail_SystemMailWatchdog::TRIGGER_FORMSENT, 'data' => $formParams, 'attachment' => $attachment));
             $mailWatchdog = new Tools_Mail_Watchdog(array('trigger' => Tools_Mail_SystemMailWatchdog::TRIGGER_FORMSENT, 'data' => $formParams, 'attachment' => $attachment));
             $mailWatchdog->notify($form);
             $mailsSent = $sysMailWatchdog->notify($form);
             if ($mailsSent) {
                 $form->notifyObservers();
                 if ($xmlHttpRequest) {
                     $this->_helper->response->success($form->getMessageSuccess());
                 }
                 //redirect to conversion page
                 if ($conversionPageUrl) {
                     $this->_redirect($conversionPageUrl);
                 }
                 $sessionHelper->toasterFormSuccess = $form->getMessageSuccess();
                 $this->_redirect($formParams['formUrl']);
             }
             if ($xmlHttpRequest) {
                 $this->_helper->response->fail($form->getMessageError());
             }
             $sessionHelper->toasterFormError = $form->getMessageError();
             $this->_redirect($formParams['formUrl']);
         }
     }
 }
 private function _getFoldersList($imagesOnly = false)
 {
     $listFolders = Tools_Filesystem_Tools::scanDirectoryForDirs($this->_websiteConfig['path'] . $this->_websiteConfig['media']);
     if (!empty($listFolders)) {
         if ($imagesOnly) {
             foreach ($listFolders as $key => $folder) {
                 if (!is_dir($this->_websiteConfig['path'] . $this->_websiteConfig['media'] . $folder . '/small')) {
                     unset($listFolders[$key]);
                 }
             }
         }
         $listFolders = array_combine($listFolders, $listFolders);
     }
     return $listFolders;
 }
Example #22
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;
 }
Example #23
0
 /**
  * Serve sitemaps
  *
  */
 public function sitemapAction()
 {
     //disable renderer
     $this->_helper->viewRenderer->setNoRender(true);
     //get sitemap type from the params
     if (($sitemapType = $this->getRequest()->getParam('type', '')) == Tools_Content_Feed::SMFEED_TYPE_REGULAR) {
         //regular sitemap.xml requested
         if (null === ($this->view->pages = $this->_helper->cache->load('sitemappages', 'sitemaps_'))) {
             if (in_array('newslog', Tools_Plugins_Tools::getEnabledPlugins(true))) {
                 $this->view->newsPageUrlPath = Newslog_Models_Mapper_ConfigurationMapper::getInstance()->fetchConfigParam('folder');
             }
             $pages = Application_Model_Mappers_PageMapper::getInstance()->fetchAll();
             if (is_array($pages) && !empty($pages)) {
                 $quoteInstalled = Tools_Plugins_Tools::findPluginByName('quote')->getStatus() == Application_Model_Models_Plugin::ENABLED;
                 $pages = array_filter($pages, function ($page) use($quoteInstalled) {
                     if ($page->getExtraOption(Application_Model_Models_Page::OPT_PROTECTED) || $page->getDraft() || $page->getIs404page() || $quoteInstalled && intval($page->getParentId()) === Quote::QUOTE_CATEGORY_ID) {
                         return false;
                     }
                     return true;
                 });
             } else {
                 $pages = array();
             }
             $this->view->pages = $pages;
             $this->_helper->cache->save('sitemappages', $this->view->pages, 'sitemaps_', array('sitemaps'));
         }
     } else {
         if ($sitemapType == Tools_Content_Feed::SMFEED_TYPE_INDEX) {
             //default sitemaps
             $sitemaps = array('sitemap' => array('extension' => 'xml', 'lastmod' => date(DATE_ATOM)), 'sitemapnews' => array('extension' => 'xml', 'lastmod' => date(DATE_ATOM)));
             //real sitemaps (in the toaster root)
             $sitemapFiles = Tools_Filesystem_Tools::findFilesByExtension($this->_helper->website->getPath(), 'xml', false, false, false);
             if (is_array($sitemapFiles) && !empty($sitemapFiles)) {
                 foreach ($sitemapFiles as $sitemapFile) {
                     if (preg_match('~sitemap.*\\.xml.*~', $sitemapFile)) {
                         $fileInfo = pathinfo($this->_helper->website->getPath() . $sitemapFile);
                         if (is_array($fileInfo)) {
                             $sitemaps[$fileInfo['filename']] = array('extension' => $fileInfo['extension'], 'lastmod' => date(DATE_ATOM, fileatime($this->_helper->website->getPath() . $sitemapFile)));
                         }
                     }
                 }
             }
             $this->view->sitemaps = $sitemaps;
         }
     }
     $template = 'sitemap' . $sitemapType . '.xml.phtml';
     if (null === ($sitemapContent = $this->_helper->cache->load($sitemapType, Helpers_Action_Cache::PREFIX_SITEMAPS))) {
         try {
             $sitemapContent = $this->view->render('backend/seo/' . $template);
         } catch (Zend_View_Exception $zve) {
             // Try to find plugin's sitemap
             try {
                 $sitemapContent = Tools_Plugins_Tools::runStatic('getSitemap', $sitemapType);
                 if (!$sitemapContent) {
                     $sitemapContent = Tools_Plugins_Tools::runStatic('getSitemap' . ucfirst($sitemapType));
                 }
             } catch (Exception $e) {
                 Tools_System_Tools::debugMode() && error_log($e->getMessage());
                 $sitemapContent = false;
             }
             if ($sitemapContent === false) {
                 $this->getResponse()->setHeader('Content-Type', 'text/html', true);
                 return $this->forward('index', 'index', null, array('page' => 'sitemap' . $sitemapType . '.xml'));
             }
         }
         $this->_helper->cache->save($sitemapType, $sitemapContent, Helpers_Action_Cache::PREFIX_SITEMAPS, array('sitemaps'), Helpers_Action_Cache::CACHE_WEEK);
     }
     echo $sitemapContent;
 }
Example #24
0
 public static function removeIndex()
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website');
     $searchIndexFolder = $websiteHelper->getPath() . 'cache/' . Widgets_Search_Search::INDEX_FOLDER;
     if (!is_dir($searchIndexFolder)) {
         return false;
     }
     Tools_Filesystem_Tools::deleteDir($searchIndexFolder);
 }