public function testReturnsCorrectImageProcessorClass() { /** @var $image Varien_Image */ $image = $this->_model->getImageProcessor(); $adapterClass = EcomDev_Utils_Reflection::invokeRestrictedMethod($image, '_getAdapter'); $this->assertInstanceOf('Varien_Image_Adapter_Abstract', $adapterClass); }
/** * @return Mage_Catalog_Model_Product_Image */ public function saveFile() { parent::saveFile(); /* added for Kraken Image Optimization */ Mage::dispatchEvent('catalog_product_image_save_after', array($this->_eventObject => $this)); return $this; }
public function getUrl() { if ($this->_imageShouldComeFromCloudinary($this->_newFile)) { $imageProvider = CloudinaryImageProvider::fromConfiguration($this->_getConfigHelper()->buildConfiguration()); return (string) $imageProvider->transformImage(Image::fromPath($this->_newFile)); } return parent::getUrl(); }
/** * Clears the images on the CDN and the local cache. * * @return string */ public function clearCache() { parent::clearCache(); $cds = Mage::Helper('imagecdn')->factory(); if ($cds->useCdn()) { $cds->clearCache(); } }
/** * @param null $file * @return bool */ protected function _checkMemory($file = null) { if ($this->getDisableMemoryCheck()) { return true; } else { return parent::_checkMemory($file = null); } }
/** * First check this file on FS * If it doesn't exist - try to download it from CDN * * @param string $filename * @return bool */ protected function _fileExists($filename) { if (!Mage::getStoreConfig('mycdn/general/enabled')) { return parent::_fileExists($filename); } if (Mage::helper('mycdn')->isFileExists($filename)) { return true; } Mage::helper('mycdn')->addLog('[NEED TO DOWNLOAD] no source on server -> ' . $filename); return Mage::helper('mycdn')->getCdnFile($filename); }
/** * 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; }
public function getImageProcessor() { if (!Mage::helper('magefm_cdn')->isEnabled()) { return parent::getImageProcessor(); } $originalUrl = $this->imageUrl; $tmpExt = explode('.', $originalUrl); $ext = array_pop($tmpExt); $tmpFile = tempnam(sys_get_temp_dir(), 'magefm_cdn_'); $newFile = "{$tmpFile}.{$ext}"; unlink($tmpFile); file_put_contents($newFile, file_get_contents($originalUrl)); $this->_baseFile = $newFile; return parent::getImageProcessor(); }
/** * 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("watermarkplus_options/settings/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("watermarkplus_options/settings/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; }
/** * Overrides the parent method. It checks the base file change time, * and if cached file is older - we concider an image is not cached * * @return bool */ public function isCached() { if (Mage::getStoreConfig("catalog/nicerimagenames/disable_ext")) { // use parent method if nicerimagenames disabled return parent::isCached(); } if (!$this->_fileExists($this->_newFile)) { return false; } if (!file_exists($this->_baseFile)) { return true; } if (filemtime($this->_newFile) < filemtime($this->_baseFile)) { // checks the base file change time, and if cached file is older - we concider an image is not cached return false; } return true; }
/** * First check this file on FS or DB. If it doesn't then download it from S3 * * @param string $filename * * @return bool */ protected function _fileExists($filename) { return parent::_fileExists($filename) || Mage::helper('cdn')->download($filename); }
/** * @param Mage_Catalog_Model_Product_Image $model * @depends testSetBaseFilePlaceholder */ public function testGetUrlPlaceholder($model) { $this->assertStringMatchesFormat('http://localhost/pub/media/skin/frontend/%s/Mage_Catalog/images/product/placeholder/image.jpg', $model->getUrl()); }
/** * @return string */ public function getUrl() { if ($this->_newFile === true) { $url = Mage::getDesign()->getSkinUrl('Mage_XmlConnect::images/catalog/category/placeholder/' . $this->getDestinationSubdir() . '.jpg'); } else { $url = parent::getUrl(); } return $url; }
protected function _rgbToString($rgbArray) { if (version_compare(Mage::getVersion(), '1.4.0.1') > 0) { return parent::_rgbToString($rgbArray); } else { $result = array(); foreach ($rgbArray as $value) { if (null === $value) { $result[] = 'null'; } else { $result[] = sprintf('%02s', dechex($value)); } } return implode($result); } }
/** * @see Varien_Image_Adapter_Abstract * @return Mage_Catalog_Model_Product_Image */ public function resize() { parent::resize(); return $this; }
/** * Clear product image cache directory */ public function clearCache() { if (!Mage::helper('uaudio_storage')->isEnabled()) { return parent::clearCache(); } $directory = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . DS . 'cache' . DS; $this->_getStorageModel()->deleteDir($directory); }