/** * @TODO generate placeholder if file does not exists * @TODO support watermark */ public function setBaseFile($file) { if (!Mage::helper('magefm_cdn')->isEnabled()) { return parent::setBaseFile($file); } $this->_isBaseFilePlaceholder = false; // build new filename (most important params) $path = array(Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrlAddition(), 'cache', Mage::app()->getStore()->getId(), $path[] = $this->getDestinationSubdir()); if (!empty($this->_width) || !empty($this->_height)) { $path[] = "{$this->_width}x{$this->_height}"; } // add misk params as a hash $miscParams = array(($this->_keepAspectRatio ? '' : 'non') . 'proportional', ($this->_keepFrame ? '' : 'no') . 'frame', ($this->_keepTransparency ? '' : 'no') . 'transparency', ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly', $this->_rgbToString($this->_backgroundColor), 'angle' . $this->_angle, 'quality' . $this->_quality); // if has watermark add watermark params to hash if ($this->getWatermarkFile()) { $miscParams[] = $this->getWatermarkFile(); $miscParams[] = $this->getWatermarkImageOpacity(); $miscParams[] = $this->getWatermarkPosition(); $miscParams[] = $this->getWatermarkWidth(); $miscParams[] = $this->getWatermarkHeigth(); } $path[] = md5(implode('_', $miscParams)); // append prepared filename $this->_newFile = implode('/', $path) . $file; $this->imageUrl = Mage::getSingleton('catalog/product_media_config')->getMediaUrl(substr($file, 0, 1) == '/' ? substr($file, 1) : $file); return $this; }
/** * Set filenames for base file and new file * * @param string $file * @return Mage_Catalog_Model_Product_Image * @throws Mage_Core_Exception */ public function setBaseFile($file) { parent::setBaseFile($file); if (!Mage::getStoreConfig("catalog/nicerimagenames/disable_ext")) { // The $_newFile property is set during parent::setBaseFile() list($path, $file) = $this->_getFilePathAndName($this->_newFile); $file = $this->_getNiceFileName($file); if (Mage::getStoreConfig("catalog/nicerimagenames/lowercase")) { $file = strtolower($file); } $this->_newFile = $path . $file; // the $file contains heading slash } return $this; }
/** * Set filenames for base file and new file * * @param string $file * @return Mage_Catalog_Model_Product_Image * @throws Mage_Core_Exception */ public function setBaseFile($file) { parent::setBaseFile($file); if (!Mage::getStoreConfig("catalog/nicerimagenames/disable_ext") && !$this->_isBaseFilePlaceholder) { // The $_newFile property is set during parent::setBaseFile() list($path, $file) = $this->_getFilePathAndName($this->_newFile); $file = $this->_getNiceFileName($file); if (Mage::getStoreConfig("catalog/nicerimagenames/lowercase")) { $file = strtolower($file); } list($pathExt, $extension) = $this->_getFileNameParts($file); // Check that generated filename is not longer than 255 $maxfilelen = 255; if (strlen(basename($file) . $extension) > $maxfilelen) { $file = substr($file, 0, $maxfilelen - strlen($extension) + strlen(dirname($file))); $file = $file . '.' . $extension; } $this->_newFile = $path . $file; // the $file contains heading slash if (defined('PHP_MAXPATHLEN')) { $maxlen = PHP_MAXPATHLEN; } else { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $maxlen = 255; // NTFS sucks } else { $maxlen = 1024; // Safe assumption, probably more } } if (strlen($this->_newFile) > $maxlen) { // hack off as much as necessary to make it fit. Urg. // See https://github.com/Vinai/nicer-image-names/issues/14 for more info // This is no real solution, as there is no check if the resulting image // still is in the right directory. // The proper thing to do is to not use Windows for hosting, // or, not use attributes with looog values in the name template. $pathExt = substr($path . rtrim($pathExt, '/\\') . $pathExt, 0, $maxlen - strlen($extension) - 2); $this->_newFile = rtrim($pathExt, '/\\') . '.' . $extension; } } return $this; }
/** * Set filenames for base file and new file * * @param string $file * @return self */ public function setBaseFile($file) { if (!Mage::helper('uaudio_storage')->isEnabled()) { return parent::setBaseFile($file); } $this->_isBaseFilePlaceholder = false; if ($file && 0 !== strpos($file, '/', 0)) { $file = '/' . $file; } $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(); if ('/no_selection' == $file) { $file = null; } if ($file) { $path = $this->_getPathParameters(); // check if cached file already exists if ($this->_fileExists(implode('/', $path) . $file)) { $this->_newFile = implode('/', $path) . $file; } else { if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) { $file = null; } } } if (!$file) { $isConfigPlaceholder = Mage::getStoreConfig("catalog/placeholder/{$this->getDestinationSubdir()}_placeholder"); $configPlaceholder = '/placeholder/' . $isConfigPlaceholder; if ($isConfigPlaceholder && $this->_fileExists($baseDir . $configPlaceholder)) { $file = $configPlaceholder; } else { // replace file with skin or default skin placeholder $skinBaseDir = Mage::getDesign()->getSkinBaseDir(); $skinPlaceholder = "/images/catalog/product/placeholder/{$this->getDestinationSubdir()}.jpg"; $file = $skinPlaceholder; if (file_exists($skinBaseDir . $file)) { $baseDir = $skinBaseDir; } else { $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default')); if (!file_exists($baseDir . $file)) { $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default', '_package' => 'base')); } } } $this->_isBaseFilePlaceholder = true; } $this->_fileName = $file; $baseFile = $baseDir . $file; if (!$file || !$this->_fileExists($baseFile)) { throw new Exception(Mage::helper('catalog')->__('Image file was not found.')); } $this->_baseFile = $baseFile; // build new filename (most important params) $path = $this->_getPathParameters(); // append prepared filename $this->_newFile = implode('/', $path) . $file; // the $file contains heading slash if ($this->isCached() && $this->_tmpName) { unlink($this->_tmpName); $this->_tmpName = null; } return $this; }