Development

Changeset 3858

You must first sign up to be able to contribute.

Changeset 3858

Show
Ignore:
Timestamp:
04/24/07 09:32:48 (6 years ago)
Author:
francois
Message:

sfMediaLibraryPlugin: Use sfThumbnailPlugin when available

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfMediaLibraryPlugin/README

    r3832 r3858  
    4949{{{ 
    5050<?php echo image_tag('/uploads/assets/path_to_asset.suffix') ?> 
     51}}} 
     52 
     53== Interface with the `sfThumbnailPlugin` == 
     54 
     55If the [wiki:sfThumbnailPlugin] is installed in your project, `sfMediaLibrary` will automatically use it to create thumbnail images of the images you upload. To deactivate this behavior, change the following setting in the `app.yml`: 
     56 
     57{{{ 
     58all: 
     59  sfMediaLibrary: 
     60    use_thumbnails: true 
     61}}} 
     62 
     63By default, thumbnail images are stored under a `thumbnail/` subdirectory of the image directory. You can change the name of this directory through another setting of the `app.yml`: 
     64 
     65{{{ 
     66all: 
     67  sfMediaLibrary: 
     68    thumbnails_dir: thumbnail 
    5169}}} 
    5270 
     
    108126 
    109127 * Add screenshots to the wiki description 
    110  * Use [wiki:sfThumbnailPlugin] when available 
    111128 * Improve CSS and design 
    112129 * Improve compatibility 
     
    119136=== Trunk === 
    120137 
     138 * francois: Use [wiki:sfThumbnailPlugin] when available 
    121139 * Jose.Luis.Di.Biase: Added Spanish translation 
    122140 
  • plugins/sfMediaLibraryPlugin/modules/sfMediaLibrary/lib/BasesfMediaLibraryActions.class.php

    r3804 r3858  
    1818class BasesfMediaLibraryActions extends sfActions 
    1919{ 
     20  public function preExecute() 
     21  { 
     22    $this->use_thumbnails = false; 
     23    if(sfConfig::get('app_sfMediaLibrary_use_thumbnails', true) && class_exists('sfThumbnail')) 
     24    { 
     25      $this->use_thumbnails = true; 
     26      $this->thumbnails_dir = sfConfig::get('app_sfMediaLibrary_thumbnails_dir', 'thumbnail'); 
     27    }  
     28  } 
     29   
    2030  public function executeIndex() 
    2131  { 
     
    2838    $this->forward404Unless(is_dir($this->absCurrentDir)); 
    2939 
    30     $dirs  = sfFinder::type('dir')->maxdepth(0)->prune('.*')->discard('.*')->relative()->in($this->absCurrentDir); 
     40    // directories 
     41    $dirsQuery = sfFinder::type('dir')->maxdepth(0)->prune('.*')->discard('.*')->relative(); 
     42    if($this->use_thumbnails) 
     43    { 
     44      $dirsQuery = $dirsQuery->discard($this->thumbnails_dir); 
     45    } 
     46    $dirs  = $dirsQuery->in($this->absCurrentDir); 
     47    sort($dirs); 
     48    $this->dirs = $dirs; 
     49     
     50    // files, with stats 
    3151    $files = sfFinder::type('file')->maxdepth(0)->prune('.*')->discard('.*')->relative()->in($this->absCurrentDir); 
    32  
    33     sort($dirs); 
    3452    sort($files); 
    35  
    36     $this->dirs = $dirs; 
    37  
    38     // compute some stats for each file 
    3953    $infos = array(); 
    4054    foreach ($files as $file) 
    4155    { 
    42       $info = array(); 
    43  
    44       $info['ext']  = substr($file, strpos($file, '.') - strlen($file) + 1); 
    45       if ($this->getRequestParameter('images_only') && !$this->isImage($info['ext'])) 
    46       { 
    47         continue; 
    48       } 
    49       $stats = stat($this->absCurrentDir.'/'.$file); 
    50       $info['size'] = $stats['size']; 
    51       $info['icon'] = $this->isImage($info['ext']) ? $this->webAbsCurrentDir.'/'.$file : (is_readable(sfConfig::get('sf_web_dir').'/sfMediaLibraryPlugin/images/'.$info['ext'].'.png') ? '/sfMediaLibraryPlugin/images/'.$info['ext'].'.png' : '/sfMediaLibraryPlugin/images/unknown.png'); 
    52       $infos[$file] = $info; 
     56      $ext  = substr($file, strpos($file, '.') - strlen($file) + 1); 
     57      if (!$this->getRequestParameter('images_only') || $this->isImage($ext)) 
     58      { 
     59        $infos[$file] = $this->getInfo($file); 
     60      } 
    5361    } 
    5462    $this->files = $infos; 
     
    7280  public function executeRename() 
    7381  { 
    74     $current_path = $this->dot2slash($this->getRequestParameter('current_path')); 
    75     $this->current_path = $this->getRequestParameter('current_path'); 
     82    $currentDir = $this->dot2slash($this->getRequestParameter('current_path')); 
     83    $this->currentDir = $this->getRequestParameter('current_path'); 
    7684    $type = $this->getRequestParameter('type'); 
    7785    $this->count = $this->getRequestParameter('count'); 
    78  
    79     $this->abs_current_path = sfConfig::get('sf_upload_dir').'/assets/'.$current_path; 
    80     $this->web_abs_current_path = '/'.sfConfig::get('sf_upload_dir_name').'/assets/'.$current_path; 
     86    $this->webAbsCurrentDir = '/'.sfConfig::get('sf_upload_dir_name').'/assets/'.$currentDir; 
     87    $absCurrentDir = sfConfig::get('sf_upload_dir').'/assets/'.$currentDir; 
     88     
     89    $this->forward404Unless(is_dir($absCurrentDir)); 
    8190 
    8291    $name = $this->getRequestParameter('name'); 
     
    8594    { 
    8695      $new_name = $this->sanitizeDir($new_name); 
    87       $this->forward404Unless(is_dir($this->abs_current_path.'/'.$name)); 
     96      $this->forward404Unless(is_dir($absCurrentDir.'/'.$name)); 
    8897    } 
    8998    else 
    9099    { 
    91100      $new_name = $this->sanitizeFile($new_name); 
    92       $this->forward404Unless(is_file($this->abs_current_path.'/'.$name)); 
    93     } 
    94  
    95     @rename($this->abs_current_path.'/'.$name, $this->abs_current_path.'/'.$new_name); 
    96  
     101      $this->forward404Unless(is_file($absCurrentDir.'/'.$name)); 
     102    } 
     103 
     104    @rename($absCurrentDir.'/'.$name, $absCurrentDir.'/'.$new_name); 
     105     
     106    if($this->use_thumbnails && ($type === 'file') && file_exists($absCurrentDir.'/'.$this->thumbnails_dir.'/'.$name)) 
     107    { 
     108      @rename($absCurrentDir.'/'.$this->thumbnails_dir.'/'.$name, $absCurrentDir.'/'.$this->thumbnails_dir.'/'.$new_name); 
     109    } 
     110 
     111    $this->absCurrentDir = $absCurrentDir; 
    97112    $this->info = array(); 
    98     if (is_dir($this->abs_current_path.'/'.$new_name) and ($type === 'folder')) 
     113    if (is_dir($absCurrentDir.'/'.$new_name) and ($type === 'folder')) 
    99114    { 
    100115      $this->name = $new_name; 
    101116    } 
    102     else if (is_file($this->abs_current_path.'/'.$new_name) and ($type === 'file')) 
     117    else if (is_file($absCurrentDir.'/'.$new_name) and ($type === 'file')) 
    103118    { 
    104119      $this->name = $new_name; 
    105       $this->getInfo($new_name); 
     120      $this->info = $this->getInfo($new_name); 
    106121    } 
    107122    else 
    108123    { 
    109124      $this->name = $name; 
    110       $this->getInfo($name); 
    111     } 
     125      $this->info = $this->getInfo($name); 
     126    } 
     127     
    112128    $this->type = $type; 
    113129  } 
     
    115131  protected function getInfo($filename) 
    116132  { 
    117     $this->info['ext']  = substr($filename, strpos($filename, '.') - strlen($filename) + 1); 
    118     $stats = stat($this->abs_current_path.'/'.$filename); 
    119     $this->info['size'] = $stats['size']; 
    120     $this->info['icon'] = $this->isImage($this->info['ext']) ? $this->web_abs_current_path.'/'.$filename : (is_readable(sfConfig::get('sf_web_dir').'/sfMediaLibraryPlugin/images/'.$this->info['ext'].'.png') ? '/sfMediaLibraryPlugin/images/'.$this->info['ext'].'.png' : '/sfMediaLibraryPlugin/images/unknown.png'); 
     133    $info = array(); 
     134    $info['ext']  = substr($filename, strpos($filename, '.') - strlen($filename) + 1); 
     135    $stats = stat($this->absCurrentDir.'/'.$filename); 
     136    $info['size'] = $stats['size']; 
     137    if($this->isImage($info['ext'])) 
     138    { 
     139      if($this->use_thumbnails && is_readable(sfConfig::get('sf_web_dir').$this->webAbsCurrentDir.'/'.$this->thumbnails_dir.'/'.$filename)) 
     140      { 
     141        $info['icon'] = $this->webAbsCurrentDir.'/'.$this->thumbnails_dir.'/'.$filename; 
     142        $info['size'] = 0; 
     143      } 
     144      else 
     145      { 
     146        $info['icon'] = $this->webAbsCurrentDir.'/'.$filename; 
     147      } 
     148    } 
     149    else 
     150    { 
     151      if(is_readable(sfConfig::get('sf_web_dir').'/sfMediaLibraryPlugin/images/'.$info['ext'].'.png')) 
     152      { 
     153        $info['icon'] = '/sfMediaLibraryPlugin/images/'.$info['ext'].'.png'; 
     154      } 
     155      else 
     156      { 
     157        $info['icon'] = '/sfMediaLibraryPlugin/images/unknown.png'; 
     158      } 
     159    } 
     160     
     161    return $info; 
    121162  } 
    122163 
     
    131172    $fileName = $this->sanitizeFile($this->getRequest()->getFileName('file')); 
    132173 
     174    if($this->use_thumbnails) 
     175    { 
     176      if(!is_dir($absCurrentDir.'/'.$this->thumbnails_dir)) 
     177      { 
     178        // If the thumbnails directory doesn't exist, create it now 
     179        $old = umask(0000); 
     180        @mkdir($absCurrentDir.'/'.$this->thumbnails_dir, 0777); 
     181        umask($old); 
     182      } 
     183      $thumbnail = new sfThumbnail(64, 64); 
     184      $thumbnail->loadFile($this->getRequest()->getFilePath('file')); 
     185      $thumbnail->save($absCurrentDir.'/'.$this->thumbnails_dir.'/'.$fileName); 
     186    } 
    133187    $this->getRequest()->moveFile('file', $absCurrentDir.'/'.$fileName); 
    134188 
     
    145199 
    146200    unlink($absCurrentFile); 
     201     
     202    if($this->use_thumbnails) 
     203    { 
     204      $absThumbnailFile = sfConfig::get('sf_upload_dir').'/assets/'.$currentDir.'/'.$this->thumbnails_dir.'/'.$currentFile; 
     205      if(is_readable($absThumbnailFile)) 
     206      { 
     207        unlink($absThumbnailFile); 
     208      } 
     209    } 
    147210 
    148211    $this->redirect('sfMediaLibrary/index?dir='.$this->getRequestParameter('current_path')); 
     
    157220    $old = umask(0000); 
    158221    @mkdir($absCurrentDir, 0777); 
     222    if($this->use_thumbnails) 
     223    { 
     224      @mkdir($absCurrentDir.'/'.$this->thumbnails_dir, 0777); 
     225    } 
    159226    umask($old); 
    160227 
     
    169236    $this->forward404Unless(is_dir($absCurrentDir)); 
    170237 
     238    if($this->use_thumbnails && is_readable($absCurrentDir.'/'.$this->thumbnails_dir)) 
     239    { 
     240      rmdir($absCurrentDir.'/'.$this->thumbnails_dir); 
     241    } 
     242     
    171243    rmdir($absCurrentDir); 
    172244 
  • plugins/sfMediaLibraryPlugin/modules/sfMediaLibrary/templates/renameSuccess.php

    r3780 r3858  
    33<?php include_partial('sfMediaLibrary/block', array( 
    44  'name' => $name, 
    5   'current_path' => $current_path
    6   'web_abs_current_path' => $web_abs_current_path
     5  'current_path' => $currentDir
     6  'web_abs_current_path' => $webAbsCurrentDir
    77  'type' => $type, 
    88  'info' => $info,