Development

Changeset 23004

You must first sign up to be able to contribute.

Changeset 23004

Show
Ignore:
Timestamp:
10/13/09 16:28:28 (4 years ago)
Author:
geoffrey
Message:

[sfDoctrineThumbnailablePlugin] fixed a bunch of stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfDoctrineThumbnailablePlugin/trunk/lib/DoctrineThumbnailable.class.php

    r23002 r23004  
    2020 
    2121  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(), 
    3032  ); 
     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  } 
    3145 
    3246  /** 
     
    168182   */ 
    169183 
    170   protected function getThumbnailPath($field, $format, $absolute = false
     184  protected function getThumbnailPath($field, $format
    171185  { 
    172186    $image_path = $this->getFilePath($field); 
     
    174188    $thumb_path = sprintf('%s/%s_%s', $thumb_dir, $format, basename($image_path)); 
    175189 
    176     return ($absolute ? $thumb_path : str_replace(sfConfig::get('sf_web_dir'), '', $thumb_path))
     190    return $thumb_path
    177191  } 
    178192 
     
    199213 
    200214    $abs_file_path = $this->getFilePath($field); 
    201      
     215 
    202216    if (!file_exists($abs_file_path) || is_dir($abs_file_path)) 
    203217    { 
    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))) 
    208227    { 
    209228      if (!$this->getOption('on_demand', $field)) 
     
    226245    } 
    227246 
    228     return $this->getThumbnailPath($field, $format); 
     247    return call_user_func($this->getOption('path_to_url_method', $field), $this->getThumbnailPath($field, $format)); 
    229248  } 
    230249 
     
    247266    $thumbnail->loadFile($this->getFilePath($field)); 
    248267 
    249     $thumbnail_path = $this->getThumbnailPath($field, $format, true); 
     268    $thumbnail_path = $this->getThumbnailPath($field, $format); 
    250269    $thumbnail_dir  = dirname($thumbnail_path); 
    251270 
     
    415434     
    416435    $method = sprintf($path_method, Doctrine_Inflector::classify($field)); 
    417        
     436 
    418437    if (!method_exists($object, $method)) 
    419438    {