Changeset 23004
- Timestamp:
- 10/13/09 16:28:28 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfDoctrineThumbnailablePlugin/trunk/lib/DoctrineThumbnailable.class.php
r23002 r23004 20 20 21 21 protected $options = array( 22 'config_key' => null, 23 'thumb_dir' => 'thumbnails', 24 'path_method' => null, 25 'keep_original' => true, 26 'on_demand' => true, 27 'on_save' => true, 28 'strict' => false, 29 'fields' => array(), 22 'config_key' => null, 23 'thumb_dir' => '%s/thumbnails', 24 'path_method' => null, 25 'keep_original' => true, 26 'on_demand' => true, 27 'on_save' => true, 28 'strict' => false, 29 'fail_silently' => false, 30 'path_to_url_method' => array('Thumbnailable', 'pathToUrl'), 31 'fields' => array(), 30 32 ); 33 34 /** 35 * Converts an absolute path to an url based 36 * on default symfony directories 37 * 38 * @param string $string 39 * @return string 40 */ 41 public static function pathToUrl($string) 42 { 43 return str_replace(sfConfig::get('sf_web_dir'), '', $string); 44 } 31 45 32 46 /** … … 168 182 */ 169 183 170 protected function getThumbnailPath($field, $format , $absolute = false)184 protected function getThumbnailPath($field, $format) 171 185 { 172 186 $image_path = $this->getFilePath($field); … … 174 188 $thumb_path = sprintf('%s/%s_%s', $thumb_dir, $format, basename($image_path)); 175 189 176 return ($absolute ? $thumb_path : str_replace(sfConfig::get('sf_web_dir'), '', $thumb_path));190 return $thumb_path; 177 191 } 178 192 … … 199 213 200 214 $abs_file_path = $this->getFilePath($field); 201 215 202 216 if (!file_exists($abs_file_path) || is_dir($abs_file_path)) 203 217 { 204 throw new sfException(sprintf('Cannot create thumbnail for non-existent file "%s"', $this->getInvoker()->get($field))); 205 } 206 207 if (!file_exists($this->getThumbnailPath($field, $format, true))) 218 if ($this->getOption('fail_silently', $field)) 219 { 220 return '#'; 221 } 222 223 throw new sfException(sprintf('Cannot create thumbnail for non-existent file "%s"', $abs_file_path)); 224 } 225 226 if (!file_exists($this->getThumbnailPath($field, $format))) 208 227 { 209 228 if (!$this->getOption('on_demand', $field)) … … 226 245 } 227 246 228 return $this->getThumbnailPath($field, $format);247 return call_user_func($this->getOption('path_to_url_method', $field), $this->getThumbnailPath($field, $format)); 229 248 } 230 249 … … 247 266 $thumbnail->loadFile($this->getFilePath($field)); 248 267 249 $thumbnail_path = $this->getThumbnailPath($field, $format , true);268 $thumbnail_path = $this->getThumbnailPath($field, $format); 250 269 $thumbnail_dir = dirname($thumbnail_path); 251 270 … … 415 434 416 435 $method = sprintf($path_method, Doctrine_Inflector::classify($field)); 417 436 418 437 if (!method_exists($object, $method)) 419 438 {