/** * Initialize component */ public static function initialize() { self::$initialized = true; if (property_exists(Yii::app(), 'settings')) { self::$db_settings = Yii::app()->settings->get(self::$settings_key); } else { self::$db_settings = self::$defaults; } }
/** * Get url to product image. Enter $size to resize image. * @param mixed $size New size of the image. e.g. '150x150' * @param mixed $resizeMethod Resize method name to override config. resize/adaptiveResize * @param mixed $random Add random number to the end of the string * @return string */ public function getUrl($subfolder = '', $id, $size = false, $resizeMethod = false, $random = false) { // Path to source image $fullPath = Yii::getPathOfAlias(FileImageConfig::get('path')); if($subfolder) $fullPath .= '/'.$subfolder.'/'; if($id) $fullPath .= '/'.$id; $fullPath .= '/'.$this->id_photo.'.'.$this->extention; if($size !== false) { //$thumbPath = Yii::getPathOfAlias(Yii::app()->params['storeImages']['thumbPath']).'/'.$size; $thumbPath = Yii::getPathOfAlias(FileImageConfig::get('thumbPath')).'/'.$size; if(!file_exists($thumbPath)){ CFileHelper:: createDirectory($thumbPath, Yii::app()->params['storeImages']['dirMode']); } // Path to thumb $thumbPath = $thumbPath.'/'.$this->id_photo.'.'.$this->extention; if(!file_exists($fullPath)){ return false; } if(!file_exists($thumbPath) && file_exists($fullPath)) { // Resize if needed Yii::import('ext.phpthumb.PhpThumbFactory'); $sizes = explode('x', $size); $thumb = PhpThumbFactory::create($fullPath); if($resizeMethod === false) $resizeMethod = FileImageConfig::get('resizeThumbMethod'); if(!empty($sizes[1])){ $thumb->$resizeMethod($sizes[0],$sizes[1])->save($thumbPath); } else { $thumb->$resizeMethod($size)->save($thumbPath); } } return ImagesConfig::get('thumbUrl').$size.'/'.$this->id_photo.'.'.$this->extention; } if ($random === true){ return $fullPath.'?'.rand(1, 10000); } return $fullPath; }