Changeset 3858
- Timestamp:
- 04/24/07 09:32:48 (6 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfMediaLibraryPlugin/README
r3832 r3858 49 49 {{{ 50 50 <?php echo image_tag('/uploads/assets/path_to_asset.suffix') ?> 51 }}} 52 53 == Interface with the `sfThumbnailPlugin` == 54 55 If 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 {{{ 58 all: 59 sfMediaLibrary: 60 use_thumbnails: true 61 }}} 62 63 By 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 {{{ 66 all: 67 sfMediaLibrary: 68 thumbnails_dir: thumbnail 51 69 }}} 52 70 … … 108 126 109 127 * Add screenshots to the wiki description 110 * Use [wiki:sfThumbnailPlugin] when available111 128 * Improve CSS and design 112 129 * Improve compatibility … … 119 136 === Trunk === 120 137 138 * francois: Use [wiki:sfThumbnailPlugin] when available 121 139 * Jose.Luis.Di.Biase: Added Spanish translation 122 140 plugins/sfMediaLibraryPlugin/modules/sfMediaLibrary/lib/BasesfMediaLibraryActions.class.php
r3804 r3858 18 18 class BasesfMediaLibraryActions extends sfActions 19 19 { 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 20 30 public function executeIndex() 21 31 { … … 28 38 $this->forward404Unless(is_dir($this->absCurrentDir)); 29 39 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 31 51 $files = sfFinder::type('file')->maxdepth(0)->prune('.*')->discard('.*')->relative()->in($this->absCurrentDir); 32 33 sort($dirs);34 52 sort($files); 35 36 $this->dirs = $dirs;37 38 // compute some stats for each file39 53 $infos = array(); 40 54 foreach ($files as $file) 41 55 { 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 } 53 61 } 54 62 $this->files = $infos; … … 72 80 public function executeRename() 73 81 { 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'); 76 84 $type = $this->getRequestParameter('type'); 77 85 $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)); 81 90 82 91 $name = $this->getRequestParameter('name'); … … 85 94 { 86 95 $new_name = $this->sanitizeDir($new_name); 87 $this->forward404Unless(is_dir($ this->abs_current_path.'/'.$name));96 $this->forward404Unless(is_dir($absCurrentDir.'/'.$name)); 88 97 } 89 98 else 90 99 { 91 100 $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; 97 112 $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')) 99 114 { 100 115 $this->name = $new_name; 101 116 } 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')) 103 118 { 104 119 $this->name = $new_name; 105 $this-> getInfo($new_name);120 $this->info = $this->getInfo($new_name); 106 121 } 107 122 else 108 123 { 109 124 $this->name = $name; 110 $this->getInfo($name); 111 } 125 $this->info = $this->getInfo($name); 126 } 127 112 128 $this->type = $type; 113 129 } … … 115 131 protected function getInfo($filename) 116 132 { 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; 121 162 } 122 163 … … 131 172 $fileName = $this->sanitizeFile($this->getRequest()->getFileName('file')); 132 173 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 } 133 187 $this->getRequest()->moveFile('file', $absCurrentDir.'/'.$fileName); 134 188 … … 145 199 146 200 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 } 147 210 148 211 $this->redirect('sfMediaLibrary/index?dir='.$this->getRequestParameter('current_path')); … … 157 220 $old = umask(0000); 158 221 @mkdir($absCurrentDir, 0777); 222 if($this->use_thumbnails) 223 { 224 @mkdir($absCurrentDir.'/'.$this->thumbnails_dir, 0777); 225 } 159 226 umask($old); 160 227 … … 169 236 $this->forward404Unless(is_dir($absCurrentDir)); 170 237 238 if($this->use_thumbnails && is_readable($absCurrentDir.'/'.$this->thumbnails_dir)) 239 { 240 rmdir($absCurrentDir.'/'.$this->thumbnails_dir); 241 } 242 171 243 rmdir($absCurrentDir); 172 244 plugins/sfMediaLibraryPlugin/modules/sfMediaLibrary/templates/renameSuccess.php
r3780 r3858 3 3 <?php include_partial('sfMediaLibrary/block', array( 4 4 '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, 7 7 'type' => $type, 8 8 'info' => $info,