Пример #1
0
 /**
  * Return content of default robot.txt
  *
  * @return bool|string
  */
 protected function _getDefaultValue()
 {
     $file = $this->_filePath;
     if ($this->_filesystem->isFile($file)) {
         return $this->_filesystem->read($file);
     }
     return false;
 }
Пример #2
0
 /**
  * Create .htaccess file and deny backups directory access from web
  */
 protected function _hideBackupsForApache()
 {
     $htaccessPath = $this->_baseDir . DS . '.htaccess';
     if (!$this->_filesystem->isFile($htaccessPath)) {
         $this->_filesystem->write($htaccessPath, 'deny from all');
         $this->_filesystem->changePermissions($htaccessPath, 0644);
     }
 }
Пример #3
0
 /**
  * Create thumbnail for image and save it to thumbnails directory
  *
  * @param string $source Image path to be resized
  * @param bool $keepRation Keep aspect ratio or not
  * @return bool|string Resized filepath or false if errors were occurred
  */
 public function resizeFile($source, $keepRation = true)
 {
     if (!$this->_filesystem->isFile($source) || !$this->_filesystem->isReadable($source)) {
         return false;
     }
     $targetDir = $this->getThumbsPath($source);
     if (!$this->_filesystem->isWritable($targetDir)) {
         $this->_filesystem->createDirectory($targetDir);
     }
     if (!$this->_filesystem->isWritable($targetDir)) {
         return false;
     }
     $adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType();
     $image = Varien_Image_Adapter::factory($adapter);
     $image->open($source);
     $width = $this->getConfigData('resize_width');
     $height = $this->getConfigData('resize_height');
     $image->keepAspectRatio($keepRation);
     $image->resize($width, $height);
     $dest = $targetDir . DS . pathinfo($source, PATHINFO_BASENAME);
     $image->save($dest);
     if ($this->_filesystem->isFile($dest)) {
         return $dest;
     }
     return false;
 }
Пример #4
0
 /**
  * First check this file on FS
  * If it doesn't exist - try to download it from DB
  *
  * @param string $filename
  * @return bool
  */
 protected function _fileExists($filename)
 {
     if ($this->_filesystem->isFile($filename)) {
         return true;
     } else {
         return Mage::helper('Mage_Core_Helper_File_Storage_Database')->saveFileToFilesystem($filename);
     }
 }
Пример #5
0
 /**
  * Delete Expired Captcha Images
  *
  * @return Mage_Captcha_Model_Observer
  */
 public function deleteExpiredImages()
 {
     foreach (Mage::app()->getWebsites(true) as $website) {
         $expire = time() - Mage::helper('Mage_Captcha_Helper_Data')->getConfigNode('timeout', $website->getDefaultStore()) * 60;
         $imageDirectory = Mage::helper('Mage_Captcha_Helper_Data')->getImgDir($website);
         foreach ($this->_filesystem->getNestedKeys($imageDirectory) as $filePath) {
             if ($this->_filesystem->isFile($filePath) && pathinfo($filePath, PATHINFO_EXTENSION) == 'png' && $this->_filesystem->getMTime($filePath) < $expire) {
                 $this->_filesystem->delete($filePath);
             }
         }
     }
     return $this;
 }
Пример #6
0
 /**
  * Directory structure initializing
  */
 protected function _initFilesystem()
 {
     $this->_createWriteableDir($this->getTargetDir());
     $this->_createWriteableDir($this->getQuoteTargetDir());
     $this->_createWriteableDir($this->getOrderTargetDir());
     // Directory listing and hotlink secure
     if (!$this->_filesystem->isFile($this->getTargetDir() . DS . '.htaccess')) {
         $stream = $this->_filesystem->createStream($this->getTargetDir() . DS . '.htaccess');
         $stream->open('w+');
         $stream->write("Order deny,allow\nDeny from all");
         $stream->close();
     }
 }
Пример #7
0
    /**
     * Retrieve block view from file (template)
     *
     * @param  string $fileName
     * @return string
     * @throws Exception
     */
    public function fetchView($fileName)
    {
        $viewShortPath = str_replace(Mage::getBaseDir(), '', $fileName);
        Magento_Profiler::start('TEMPLATE:' . $fileName, array('group' => 'TEMPLATE', 'file_name' => $viewShortPath));
        // EXTR_SKIP protects from overriding
        // already defined variables
        extract($this->_viewVars, EXTR_SKIP);
        $do = $this->getDirectOutput();
        if (!$do) {
            ob_start();
        }
        if ($this->getShowTemplateHints()) {
            echo <<<HTML
<div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;">
<div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'"
onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName}</div>
HTML;
            if (self::$_showTemplateHintsBlocks) {
                $thisClass = get_class($this);
                echo <<<HTML
<div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'" onmouseout="this.style.zIndex='998'"
title="{$thisClass}">{$thisClass}</div>
HTML;
            }
        }
        try {
            if ((Magento_Filesystem::isPathInDirectory($fileName, Mage::getBaseDir('app')) || Magento_Filesystem::isPathInDirectory($fileName, $this->_viewDir) || $this->_getAllowSymlinks()) && $this->_filesystem->isFile($fileName)) {
                include $fileName;
            } else {
                Mage::log("Invalid template file: '{$fileName}'", Zend_Log::CRIT, null, true);
            }
        } catch (Exception $e) {
            if (!$do) {
                ob_get_clean();
            }
            throw $e;
        }
        if ($this->getShowTemplateHints()) {
            echo '</div>';
        }
        if (!$do) {
            $html = ob_get_clean();
        } else {
            $html = '';
        }
        Magento_Profiler::stop('TEMPLATE:' . $fileName);
        return $html;
    }
Пример #8
0
 /**
  * Save file to storage
  *
  * @param string $filePath
  * @param string $content
  * @param bool $overwrite
  * @return bool
  */
 public function saveFile($filePath, $content, $overwrite = false)
 {
     if (strpos($filePath, $this->getMediaBaseDirectory()) !== 0) {
         $filePath = $this->getMediaBaseDirectory() . DS . $filePath;
     }
     try {
         if (!$this->_filesystem->isFile($filePath) || $overwrite && $this->_filesystem->delete($filePath)) {
             $this->_filesystem->write($filePath, $content);
             return true;
         }
     } catch (Magento_Filesystem_Exception $e) {
         $this->_logger->log($e->getMessage());
         Mage::throwException($this->_helper->__('Unable to save file: %s', $filePath));
     }
     return false;
 }
Пример #9
0
 /**
  * Copy image and return new filename.
  *
  * @param string $file
  * @return string
  */
 protected function _copyImage($file)
 {
     try {
         $destinationFile = $this->_getUniqueFileName($file);
         if (!$this->_filesystem->isFile($this->_getConfig()->getMediaPath($file), $this->_baseMediaPath)) {
             throw new Exception();
         }
         if (Mage::helper('Mage_Core_Helper_File_Storage_Database')->checkDbUsage()) {
             Mage::helper('Mage_Core_Helper_File_Storage_Database')->copyFile($this->_getConfig()->getMediaShortUrl($file), $this->_getConfig()->getMediaShortUrl($destinationFile));
             $this->_filesystem->delete($this->_getConfig()->getMediaPath($destinationFile), $this->_baseMediaPath);
         } else {
             $this->_filesystem->copy($this->_getConfig()->getMediaPath($file), $this->_getConfig()->getMediaPath($destinationFile), $this->_baseMediaPath);
         }
         return str_replace(DS, '/', $destinationFile);
     } catch (Exception $e) {
         $file = $this->_getConfig()->getMediaPath($file);
         Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Failed to copy file %s. Please, delete media with non-existing images and try again.', $file));
     }
 }
Пример #10
0
 protected function _addDir($pfm, $role, $roleDir, $path, $include, $ignore)
 {
     $roleDirLen = strlen($roleDir);
     $entries = $this->_filesystem->getNestedKeys($roleDir . $path . DS);
     if (!empty($entries)) {
         foreach ($entries as $entry) {
             $filePath = substr($entry, $roleDirLen);
             if (!empty($include) && !preg_match($include, $filePath)) {
                 continue;
             }
             if (!empty($ignore) && preg_match($ignore, $filePath)) {
                 continue;
             }
             if ($this->_filesystem->isFile($entry)) {
                 $pfm->addFile('/', $filePath, array('role' => $role, 'md5sum' => $this->_filesystem->getFileMd5($entry)));
             }
         }
     }
 }
Пример #11
0
 /**
  * Open backup file (write or read mode)
  *
  * @param bool $write
  * @return Mage_Backup_Model_Backup
  * @throws Mage_Backup_Exception_NotEnoughPermissions
  */
 public function open($write = false)
 {
     if (is_null($this->getPath())) {
         Mage::exception('Mage_Backup', $this->_helper->__('Backup file path was not specified.'));
     }
     if ($write && $this->_filesystem->isFile($this->_getFilePath())) {
         $this->_filesystem->delete($this->_getFilePath());
     }
     if (!$write && !$this->_filesystem->isFile($this->_getFilePath())) {
         Mage::exception('Mage_Backup', $this->_helper->__('Backup file "%s" does not exist.', $this->getFileName()));
     }
     $mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb';
     try {
         $compressStream = 'compress.zlib://';
         $workingDirectory = $this->_filesystem->getWorkingDirectory();
         $this->_stream = $this->_filesystem->createAndOpenStream($compressStream . $this->_getFilePath(), $mode, $compressStream . $workingDirectory);
     } catch (Magento_Filesystem_Exception $e) {
         throw new Mage_Backup_Exception_NotEnoughPermissions($this->_helper->__('Backup file "%s" cannot be read from or written to.', $this->getFileName()));
     }
     return $this;
 }
Пример #12
0
 /**
  * Load local package data array
  *
  * @param string $packageName without extension
  * @return array|false
  */
 public function loadLocalPackage($packageName)
 {
     //check LFI protection
     $this->checkLfiProtection($packageName);
     $path = $this->getLocalPackagesPath();
     $xmlFile = $path . $packageName . '.xml';
     $serFile = $path . $packageName . '.ser';
     if ($this->_filesystem->isFile($xmlFile) && $this->_filesystem->isReadable($xmlFile)) {
         $xml = simplexml_load_string($this->_filesystem->read($xmlFile));
         $data = Mage::helper('Mage_Core_Helper_Data')->xmlToAssoc($xml);
         if (!empty($data)) {
             return $data;
         }
     }
     if ($this->_filesystem->isFile($serFile) && $this->_filesystem->isReadable($xmlFile)) {
         $data = unserialize($this->_filesystem->read($serFile));
         if (!empty($data)) {
             return $data;
         }
     }
     return false;
 }
Пример #13
0
 /**
  * Parses .htaccess file and apply php settings to shell script
  *
  * @return Mage_Core_Model_ShellAbstract
  */
 protected function _applyPhpVariables()
 {
     $htaccess = $this->_getRootPath() . '.htaccess';
     if ($this->_filesystem->isFile($htaccess)) {
         // parse htaccess file
         $data = $this->_filesystem->read($htaccess);
         $matches = array();
         preg_match_all('#^\\s+?php_value\\s+([a-z_]+)\\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
         if ($matches) {
             foreach ($matches as $match) {
                 @ini_set($match[1], str_replace("\r", '', $match[2]));
             }
         }
         preg_match_all('#^\\s+?php_flag\\s+([a-z_]+)\\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
         if ($matches) {
             foreach ($matches as $match) {
                 @ini_set($match[1], str_replace("\r", '', $match[2]));
             }
         }
     }
     return $this;
 }
Пример #14
0
 /**
  * Constructor.
  * Following entries in $params are required: 'area', 'package', 'theme', 'locale', 'canSaveMap',
  * 'mapDir', 'baseDir'.
  *
  * @param Magento_Filesystem $filesystem
  * @param array $data
  */
 public function __construct(Magento_Filesystem $filesystem, array $data = array())
 {
     $this->_filesystem = $filesystem;
     $this->_area = $data['area'];
     $this->_theme = $data['themeModel'];
     $this->_locale = $data['locale'];
     $this->_canSaveMap = $data['canSaveMap'];
     $this->_mapDir = $data['mapDir'];
     $this->_basePath = $data['baseDir'] ? $data['baseDir'] . DIRECTORY_SEPARATOR : '';
     $this->_mapFile = "{$this->_mapDir}/{$this->_area}_{$this->_theme->getId()}_{$this->_locale}.ser";
     $this->_map = $this->_filesystem->isFile($this->_mapFile) ? unserialize($this->_filesystem->read($this->_mapFile)) : array();
 }
Пример #15
0
 /**
  * Load aliases to classes map from file
  *
  * @param string $pathToMapFile
  *
  * @return string
  */
 protected function _loadMap($pathToMapFile)
 {
     $pathToMapFile = $this->_baseDir . DS . $pathToMapFile;
     if ($this->_filesystem->isFile($pathToMapFile)) {
         return $this->_filesystem->read($pathToMapFile);
     }
     return '';
 }
Пример #16
0
 /**
  * Check, if requested theme file has public access, and move it to public folder, if the file has no public access
  *
  * @param  string $themeFile
  * @param  array $params
  * @return string
  * @throws Magento_Exception
  */
 protected function _publishViewFile($themeFile, $params)
 {
     $themeFile = $this->_extractScope($themeFile, $params);
     $sourcePath = $this->getViewFile($themeFile, $params);
     $minifiedSourcePath = $this->_minifiedPathForStaticFiles($sourcePath);
     if ($minifiedSourcePath && !Mage::getIsDeveloperMode() && $this->_filesystem->has($minifiedSourcePath)) {
         $sourcePath = $minifiedSourcePath;
         $themeFile = $this->_minifiedPathForStaticFiles($themeFile);
     }
     if (!$this->_filesystem->has($sourcePath)) {
         throw new Magento_Exception("Unable to locate theme file '{$sourcePath}'.");
     }
     if (!$this->_needToProcessFile($sourcePath)) {
         return $sourcePath;
     }
     $allowPublication = (string) Mage::getConfig()->getNode(self::XML_PATH_ALLOW_DUPLICATION);
     if ($allowPublication || $this->_getExtension($themeFile) == self::CONTENT_TYPE_CSS) {
         $targetPath = $this->_buildPublicViewRedundantFilename($themeFile, $params);
     } else {
         $targetPath = $this->_buildPublicViewSufficientFilename($sourcePath, $params);
         $this->_setPublicFileIntoCache($themeFile, $params, $targetPath);
     }
     $targetPath = $this->_buildPublicViewFilename($targetPath);
     /* Validate whether file needs to be published */
     if ($this->_getExtension($themeFile) == self::CONTENT_TYPE_CSS) {
         $cssContent = $this->_getPublicCssContent($sourcePath, dirname($targetPath), $themeFile, $params);
     }
     $fileMTime = $this->_filesystem->getMTime($sourcePath);
     if (!$this->_filesystem->has($targetPath) || $fileMTime != $this->_filesystem->getMTime($targetPath)) {
         $publicDir = dirname($targetPath);
         if (!$this->_filesystem->isDirectory($publicDir)) {
             $this->_filesystem->createDirectory($publicDir, 0777);
         }
         if (isset($cssContent)) {
             $this->_filesystem->write($targetPath, $cssContent);
             $this->_filesystem->touch($targetPath, $fileMTime);
         } elseif ($this->_filesystem->isFile($sourcePath)) {
             $this->_filesystem->copy($sourcePath, $targetPath);
             $this->_filesystem->touch($targetPath, $fileMTime);
         } elseif (!$this->_filesystem->isDirectory($targetPath)) {
             $this->_filesystem->createDirectory($targetPath, 0777);
         }
     }
     $this->_getFallback($params)->notifyViewFilePublished($targetPath, $themeFile, $params['module']);
     return $targetPath;
 }
Пример #17
0
 /**
  * Return logo URL for emails
  * Take logo from theme if custom logo is undefined
  *
  * @param  Mage_Core_Model_Store|int|string $store
  * @return string
  */
 protected function _getLogoUrl($store)
 {
     $store = Mage::app()->getStore($store);
     $fileName = $store->getConfig(self::XML_PATH_DESIGN_EMAIL_LOGO);
     if ($fileName) {
         $uploadDir = Mage_Backend_Model_Config_Backend_Email_Logo::UPLOAD_DIR;
         $fullFileName = Mage::getBaseDir('media') . DS . $uploadDir . DS . $fileName;
         if ($this->_filesystem->isFile($fullFileName)) {
             return Mage::getBaseUrl('media') . $uploadDir . '/' . $fileName;
         }
     }
     return Mage::getDesign()->getViewFileUrl('Mage_Core::logo_email.gif');
 }