/** * 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; }
/** * Fetches and outputs file to user browser * $info is array with following indexes: * - 'path' - full file path * - 'type' - mime type of file * - 'size' - size of file * - 'title' - user-friendly name of file (usually - original name as uploaded in Magento) * * @param Mage_Core_Controller_Response_Http $response * @param string $filePath * @param array $info * @return bool */ public function downloadFileOption($response, $filePath, $info) { try { $response->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $info['type'], true)->setHeader('Content-Length', $info['size'])->setHeader('Content-Disposition', 'inline' . '; filename=' . $info['title'])->clearBody(); $response->sendHeaders(); echo $this->_filesystem->read($filePath); } catch (Exception $e) { return false; } return true; }
/** * Return content of backup file * * @return string */ public function &getFile() { if (!$this->exists()) { Mage::throwException($this->_helper->__("Backup file does not exist.")); } return $this->_filesystem->read($this->_getFilePath()); }
public function replaceTmpEncryptKey($key = null) { if (!$key) { $key = md5(Mage::helper('Mage_Core_Helper_Data')->getRandomString(10)); } $localXml = $this->_filesystem->read($this->_localConfigFile); $localXml = str_replace(self::TMP_ENCRYPT_KEY_VALUE, $key, $localXml); $this->_filesystem->write($this->_localConfigFile, $localXml); return $this; }
/** * 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; }
/** * 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; }
/** * Validate file * * @throws Mage_Core_Exception * @param array $optionValue * @return Mage_Catalog_Model_Product_Option_Type_Default */ protected function _validateFile($optionValue) { $option = $this->getOption(); /** * @see Mage_Catalog_Model_Product_Option_Type_File::_validateUploadFile() * There setUserValue() sets correct fileFullPath only for * quote_path. So we must form both full paths manually and * check them. */ $checkPaths = array(); if (isset($optionValue['quote_path'])) { $checkPaths[] = Mage::getBaseDir() . $optionValue['quote_path']; } if (isset($optionValue['order_path']) && !$this->getUseQuotePath()) { $checkPaths[] = Mage::getBaseDir() . $optionValue['order_path']; } $fileFullPath = null; foreach ($checkPaths as $path) { if (!$this->_filesystem->isFile($path)) { if (!Mage::helper('Mage_Core_Helper_File_Storage_Database')->saveFileToFilesystem($fileFullPath)) { continue; } } $fileFullPath = $path; break; } if ($fileFullPath === null) { return false; } $validatorChain = new Zend_Validate(); $_dimentions = array(); if ($option->getImageSizeX() > 0) { $_dimentions['maxwidth'] = $option->getImageSizeX(); } if ($option->getImageSizeY() > 0) { $_dimentions['maxheight'] = $option->getImageSizeY(); } if (count($_dimentions) > 0 && !$this->_isImage($fileFullPath)) { return false; } if (count($_dimentions) > 0) { $validatorChain->addValidator(new Zend_Validate_File_ImageSize($_dimentions)); } // File extension $_allowed = $this->_parseExtensionsString($option->getFileExtension()); if ($_allowed !== null) { $validatorChain->addValidator(new Zend_Validate_File_Extension($_allowed)); } else { $_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions')); if ($_forbidden !== null) { $validatorChain->addValidator(new Zend_Validate_File_ExcludeExtension($_forbidden)); } } // Maximum file size $maxFileSize = $this->getFileSizeService()->getMaxFileSize(); $validatorChain->addValidator(new Zend_Validate_File_FilesSize(array('max' => $maxFileSize))); if ($validatorChain->isValid($fileFullPath)) { $ok = $this->_filesystem->isReadable($fileFullPath) && isset($optionValue['secret_key']) && substr(md5($this->_filesystem->read($fileFullPath)), 0, 20) == $optionValue['secret_key']; return $ok; } elseif ($validatorChain->getErrors()) { $errors = $this->_getValidatorErrors($validatorChain->getErrors(), $optionValue); if (count($errors) > 0) { $this->setIsValid(false); Mage::throwException(implode("\n", $errors)); } } else { $this->setIsValid(false); Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Please specify the product required option(s)')); } }
/** * 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 ''; }
/** * Look for base template and read its contents * * @param string $module A fully qualified module name (<Namespace>_<Name>) * @param string $filename File path relative to module/view folder * @return string * @throws Exception if the requested filename is not found */ public function loadBaseContents($module, $filename) { $includeFilename = Mage::getConfig()->getModuleDir('view', $module) . DIRECTORY_SEPARATOR . $filename; $contents = $this->_filesystem->read($includeFilename); if (!$contents) { throw new Exception(sprintf('Failed to include file "%s".', $includeFilename)); } return $contents; }
/** * 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(); }
/** * Merge files, located under the same folder, into one and return file name of merged file * * @param array $files list of names relative to the same folder * @param string $contentType * @return string * @throws Magento_Exception if not existing file requested for merge */ protected function _mergeFiles($files, $contentType) { $filesToMerge = array(); $mergedFile = array(); $jsDir = Mage::getBaseDir('js'); $publicDir = $this->_buildPublicViewFilename(''); foreach ($files as $file) { $params = array(); $this->_updateParamDefaults($params); $filesToMerge[$file] = $this->_publishViewFile($file, $params); $mergedFile[] = str_replace('\\', '/', str_replace(array($jsDir, $publicDir), '', $filesToMerge[$file])); } $mergedFile = self::PUBLIC_MERGE_DIR . DS . md5(implode('|', $mergedFile)) . ".{$contentType}"; $mergedFile = $this->_buildPublicViewFilename($mergedFile); $mergedMTimeFile = $mergedFile . '.dat'; $filesMTimeData = ''; foreach ($filesToMerge as $file) { $filesMTimeData .= $this->_filesystem->getMTime($file); } if ($this->_filesystem->has($mergedFile) && $this->_filesystem->has($mergedMTimeFile) && $filesMTimeData == $this->_filesystem->read($mergedMTimeFile)) { return $mergedFile; } if (!$this->_filesystem->isDirectory(dirname($mergedFile))) { $this->_filesystem->createDirectory(dirname($mergedFile), 0777); } $result = array(); foreach ($filesToMerge as $file) { if (!$this->_filesystem->has($file)) { throw new Magento_Exception("Unable to locate file '{$file}' for merging."); } $content = $this->_filesystem->read($file); if ($contentType == self::CONTENT_TYPE_CSS) { $offset = $this->_getFilesOffset($file, dirname($mergedFile)); $content = $this->_applyCssUrlOffset($content, $offset); } $result[] = $content; } $result = ltrim(implode($result)); if ($contentType == self::CONTENT_TYPE_CSS) { $result = $this->_popCssImportsUp($result); } $this->_filesystem->write($mergedFile, $result); $this->_filesystem->write($mergedMTimeFile, $filesMTimeData); return $mergedFile; }