/** * 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; }
/** * Check file system full path * * @param string $fullPath * @param bool $recursive * @param bool $existence * @return bool */ protected function _checkFullPath($fullPath, $recursive, $existence) { $result = true; if ($recursive && $this->_filesystem->isDirectory($fullPath)) { $pathsToCheck = $this->_filesystem->getNestedKeys($fullPath); array_unshift($pathsToCheck, $fullPath); } else { $pathsToCheck = array($fullPath); } $skipFileNames = array('.svn', '.htaccess'); foreach ($pathsToCheck as $pathToCheck) { if (in_array(basename($pathToCheck), $skipFileNames)) { continue; } if ($existence) { $setError = !$this->_filesystem->isWritable($fullPath); } else { $setError = $this->_filesystem->has($fullPath) && !$this->_filesystem->isWritable($fullPath); } if ($setError) { $this->_getInstaller()->getDataModel()->addError(Mage::helper('Mage_Install_Helper_Data')->__('Path "%s" must be writable.', $pathToCheck)); $result = false; } } return $result; }
/** * Return path of the current selected directory or root directory for startup * Try to create target directory if it doesn't exist * * @throws Mage_Core_Exception * @return string */ public function getCurrentPath() { if (!$this->_currentPath) { $currentPath = $this->getStorageRoot(); $path = $this->_getRequest()->getParam($this->getTreeNodeName()); if ($path) { $path = $this->convertIdToPath($path); if ($this->_filesystem->isDirectory($path)) { $currentPath = $path; } } try { if (!$this->_filesystem->isWritable($currentPath)) { $this->_filesystem->createDirectory($currentPath); } } catch (Magento_Filesystem_Exception $e) { $message = Mage::helper('Mage_Cms_Helper_Data')->__('The directory %s is not writable by server.', $currentPath); Mage::throwException($message); } $this->_currentPath = $currentPath; } return $this->_currentPath; }