Changeset 13362
- Timestamp:
- 11/26/08 21:20:27 (1 year ago)
- Files:
-
- plugins/sfAssetsLibraryPlugin/branches/jillelaine/README (modified) (11 diffs)
- plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/model/sfAsset.php (modified) (1 diff)
- plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/model/sfAssetFolder.php (modified) (1 diff)
- plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/sfAssetsLibraryTools.class.php (modified) (20 diffs)
- plugins/sfAssetsLibraryPlugin/branches/jillelaine/modules/sfAsset/lib/BasesfAssetActions.class.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfAssetsLibraryPlugin/branches/jillelaine/README
r13152 r13362 20 20 21 21 1 - Install the plugin. 22 22 23 23 The easiest way to install `sfAssetsLibraryPlugin` is to use the symfony command line: 24 24 {{{ … … 26 26 }}} 27 27 28 Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's `plugins/` directory. You can also refer to the plugin's Subversion repository by doing a checkout or an `svn:externals` of http://svn.symfony-project.com/plugins/sfAssetsLibraryPlugin. 29 28 Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's `plugins/` directory. You can also refer to the plugin's Subversion repository by doing a checkout or an `svn:externals` of http://svn.symfony-project.com/plugins/sfAssetsLibraryPlugin. 29 30 30 If you use one of these alternative methods, you must copy or symlink the contents of the `myproject/plugins/sfAssetsLibraryPlugin/web/` directory into a `myproject/web/sfAssetsLibraryPlugin/` directory. 31 31 32 32 2 - Build the data structures 33 33 34 34 Rebuild the model and generate the SQL code for the new tables: 35 35 {{{ … … 47 47 Enable the `sfAsset` module in your backend application, via the `settings.yml` file. 48 48 {{{ 49 //in myproject/apps/backend/config/settings.yml49 # in myproject/apps/backend/config/settings.yml 50 50 all: 51 51 .settings: … … 53 53 }}} 54 54 55 Configure the path to the root assets directory in the `app.yml` file :56 {{{ 57 // in myproject/config/app.yml55 Configure the path to the root assets directory in the `app.yml` file. Optionally, configure directory and asset permissions in `app.yml`: 56 {{{ 57 # in myproject/apps/backend/config/app.yml 58 58 all: 59 59 sfAssetsLibrary: 60 60 upload_dir: media 61 }}} 62 63 In the above example, uploaded files will be stored under the `web/media` directory. 61 dir_permissions: 0770 # default setting 0770 - Examples 0700, 0755, 0777 62 asset_permissions: 0644 # default setting 0644 - Examples 0600, 0644, 0666 63 }}} 64 65 In the above example, uploaded files will be stored under the `web/media` directory. Permissions settings must be in `octal notation`. For more information, research `chmod permissions`. 64 66 65 67 4 - Clear the cache to enable the autoloading to find the new classes: … … 72 74 > php symfony sfassetlibrary-create-root backend 73 75 }}} 74 76 75 77 Note: *nix users must call this command with the same user group as the http server, because it will need write access to this directory. 76 78 77 79 6 - You can now start using the plugin by browsing to the backend module's default page: 78 {{{ 80 {{{ 79 81 http://myproject/backend_dev.php/sfAsset 80 82 }}} … … 84 86 You can modify the plugin settings by way of the configuration. Here is a list of the settings you can change in your application's `app.yml`: 85 87 {{{ 86 # in apps/backend/config/app.yml88 # in myproject/apps/backend/config/app.yml 87 89 all: 88 90 sfAssetsLibrary: … … 90 92 check_type: false # Set to true if you want to restrict the type of assets 91 93 types: ['image', txt, archive, pdf, xls, doc, ppt] # Accepted asset types if check_type is true 94 dir_permissions: 0770 # default setting 0770 - Examples 0700, 0755, 0777 95 asset_permissions: 0644 # default setting 0644 - Examples 0600, 0644, 0666 92 96 thumbnail_dir: thumbnail # Where the image thumbnails are stored 93 97 use_ImageMagick: false # Set to true if you have the convert command … … 171 175 model_class: Post 172 176 theme: default 173 177 174 178 edit: 175 179 fields: … … 197 201 <?php echo input_sf_asset_tag('my_asset_field', '', array('images_only' => true)) ?> 198 202 }}} 203 204 == Troubleshooting == 205 206 If your image thumbnails do not display in sfAsset `list` and `edit` views, adjust the `dir_permissions` in `app.yml`. If you are not able to download or view your assets, adjust the `asset_permissions` in `app.yml`. If you need help with these settings, or have other problems with this plugin, please post to the General Plugins forum: 207 http://www.symfony-project.org/forum/index.php/f/12/ 199 208 200 209 == TODO == … … 209 218 == Changelog == 210 219 220 === 2008-11-26 | Branches/jillelaine === 221 222 * jillelaine: Added user configurable directory and asset permissions 223 211 224 === 2008-06-25 | Trunk === 212 225 … … 218 231 * francois: Fixed missing layout file in package 219 232 * francois: Fixed layout inclusion in Windows 220 233 221 234 === 2008-06-12 | 0.8.1 Beta === 222 235 plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/model/sfAsset.php
r13224 r13362 221 221 throw new sfAssetException('Filetype "%type%" not allowed', array('%type%' => $this->getType())); 222 222 } 223 223 // Make asset permissions user configurable 224 $asset_perms = sfAssetsLibraryTools::getUserSetPermissions('asset_perms'); 225 // Save orig umask value and set umask to 0 to prepare for chmod 226 $old = umask(0); 224 227 if ($move) 225 228 { 229 // Add chmod to set permissions 230 chmod($asset_path, $asset_perms); 226 231 rename($asset_path, $this->getFullPath()); 227 232 } 228 233 else 229 234 { 235 chmod($asset_path, $asset_perms); 230 236 copy($asset_path, $this->getFullPath()); 231 237 } 238 // Restore orig umask value 239 umask($old); 232 240 233 241 if ($this->supportsThumbnails()) plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/model/sfAssetFolder.php
r13280 r13362 205 205 if (!is_dir($new_path) || !is_writable($new_path)) 206 206 { 207 //Added user configurable directory permissions 207 208 $old = umask(0); 208 mkdir($new_path, 0770); 209 $dir_perms = sfAssetsLibraryTools::getUserSetPermissions('dir_perms'); 210 mkdir($new_path, $dir_perms); 211 //mkdir($new_path, 0770); //original line 209 212 umask($old); 210 213 } plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/sfAssetsLibraryTools.class.php
r10500 r13362 2 2 /* 3 3 * This file is part of the sfAssetsLibrary package. 4 * 4 * 5 5 * (c) 2007 William Garcia <wgarcia@clever-age.com> 6 * 6 * 7 7 * For the full copyright and license information, please view the LICENSE 8 8 * file that was distributed with this source code. … … 11 11 /** 12 12 * sfAssetsLibraryToolkit toolkit class 13 * 13 * 14 14 * @author William Garcia 15 15 */ 16 16 class sfAssetsLibraryTools 17 17 { 18 18 19 19 /** 20 20 * @return string … … 45 45 } 46 46 } 47 47 48 48 public static function isImage($ext) 49 49 { 50 50 return in_array(strtolower($ext), array('png', 'jpg', 'jpeg', 'gif')); 51 51 } 52 52 53 53 public static function isText($ext) 54 54 { … … 60 60 return in_array(strtolower($ext), array('zip', 'gz', 'tgz', 'rar')); 61 61 } 62 62 63 63 public static function getInfo($dir, $filename) 64 64 { … … 91 91 return $info; 92 92 } 93 93 94 94 public static function sanitizeName($file) 95 95 { 96 96 return preg_replace('/[^a-z0-9_\.-]/i', '_', $file); 97 97 } 98 98 99 99 public static function mkdir($dirName, $parentDirName) 100 100 { 101 101 $dirName = rtrim($dirName, '/'); 102 102 103 103 if (!is_dir(self::getMediaDir(true) . $parentDirName)) 104 104 { … … 113 113 } 114 114 } 115 115 116 116 if (!$dirName) 117 117 { … … 124 124 try 125 125 { 126 //Added user configurable directory permissions 127 $dir_perms = sfAssetsLibraryTools::getUserSetPermissions('dir_perms'); //validation function 126 128 $old = umask(0); 127 129 if (!is_dir($absCurrentDir)) 128 130 { 129 mkdir($absCurrentDir, 0770); 131 mkdir($absCurrentDir, $dir_perms); 132 //mkdir($absCurrentDir, 0770); //original line 130 133 } 131 134 if (!is_dir($absThumbDir)) 132 135 { 133 mkdir($absThumbDir, 0770); 136 mkdir($absThumbDir, $dir_perms); 137 //mkdir($absThumbDir, 0770); //original line 134 138 } 135 139 umask($old); … … 143 147 } 144 148 145 public static function deleteTree($root) 146 { 147 if (!is_dir($root)) 149 /** 150 * Retrieve, validate and convert 151 * dir_permissions or asset_permissions from app.yml 152 * Or set default permissions for dirs and assets 153 * @return integer 154 */ 155 public static function getUserSetPermissions($perm_type) 156 { 157 if ($perm_type == 'dir_perms') 158 { 159 $perms = sfConfig::get('app_sfAssetsLibrary_dir_permissions'); 160 } 161 else 162 { 163 $perms = sfConfig::get('app_sfAssetsLibrary_asset_permissions'); 164 } 165 166 if ($perms != '') 167 { 168 // Validate user settings - integers only, length, most restrictive allowed setting 169 // and only numbers of 7 or less (octal notation allowed values) 170 // Note: any leading zero is stripped off when value is retrieved from app.yml 171 // so a valid length will be 3 172 if ((is_int($perms)) && (strlen($perms) == 3) && ($perms >= 400)) 173 { 174 foreach (str_split($perms, 1) as $value) 175 { 176 if ($value <= 7) 177 { 178 $user_settings = 'okay'; 179 } 180 else 181 { 182 $user_settings = 'broken'; 183 } 184 } 185 } 186 else 187 { 188 $user_settings = 'broken'; 189 } 190 } 191 else 192 { 193 $user_settings = 'none'; 194 } 195 196 if ($user_settings == 'okay') 197 { 198 // Note: must convert octal to decimal before return, as any leading zero is stripped off 199 // and value without leading zero is interpreted as decimal by mkdir and chmod 200 $perms = octdec($perms); 201 } 202 else 203 { 204 // If the user configured permissions were not set or not valid, use the default 205 if ($perm_type == 'dir_perms') 206 { 207 $perms = 0770; //default directory permissions, leading zero is not stripped off in this case 208 } 209 else 210 { 211 $perms = 0644; //default asset permissions, leading zero is not stripped off in this case 212 } 213 } 214 215 // Set request parameter to give user useful feedback in BasesfAssetActions.class.php 216 sfContext::getInstance()->getRequest()->setParameter('user_settings', $user_settings); 217 return $perms; 218 } 219 220 public static function deleteTree($root) 221 { 222 if (!is_dir($root)) 148 223 { 149 224 return false; 150 225 } 151 foreach(glob($root.'/*', GLOB_ONLYDIR) as $dir) 152 { 153 if (!is_link($dir)) 226 foreach(glob($root.'/*', GLOB_ONLYDIR) as $dir) 227 { 228 if (!is_link($dir)) 154 229 { 155 230 self::deleteTree($dir); 156 231 } 157 232 } 158 233 159 234 return rmdir($root); 160 235 } … … 164 239 if ($thumbnail_type == 'full') 165 240 { 166 return self::getMediaDir($file_system) . $path . DIRECTORY_SEPARATOR . $filename; 241 return self::getMediaDir($file_system) . $path . DIRECTORY_SEPARATOR . $filename; 167 242 } 168 243 else … … 170 245 return self::getMediaDir($file_system) . self::getThumbnailDir($path) . $thumbnail_type . '_' . $filename; 171 246 } 172 } 173 247 } 248 174 249 public function getAssetImageTag($sf_media, $thumbnail_type = 'full', $file_system = false, $options = array()) 175 250 { … … 178 253 'title' => $sf_media->getCopyright() 179 254 )); 180 255 181 256 return image_tag(self::getAssetUrl($sf_media, $thumbnail_type, $file_system), $options); 182 257 } 183 258 184 259 /** 185 260 * Retrieves a sfMedia object from a relative URL like … … 188 263 */ 189 264 public static function getAssetFromUrl($url) 190 { 191 265 { 266 192 267 $url = str_replace(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media'), '', $url); 193 268 $url = rtrim($url, '/'); … … 195 270 $filename = array_pop($parts); 196 271 $relPath = '/' . implode('/', $parts); 197 272 198 273 $c = new Criteria(); 199 274 $c->add(sfMediaPeer::FILENAME, $filename); 200 275 $c->add(sfMediaPeer::REL_PATH, $relPath ? $relPath : null); 201 276 202 277 return sfMediaPeer::doSelectOne($c); 203 278 } 204 279 205 280 public static function getMediaDir($file_system = false) 206 281 { … … 217 292 218 293 /** 219 * Gives thumbnails folder for a folder 294 * Gives thumbnails folder for a folder 220 295 * 221 296 * @param string $path … … 225 300 { 226 301 $thumb_dir = $path . '/' . sfConfig::get('app_sfAssetsLibrary_thumbnail_dir', 'thumbnail'); 227 302 228 303 return rtrim($thumb_dir, '/').'/'; 229 304 } 230 305 231 306 public static function getThumbnailPath($path, $filename, $thumbnail_type = 'full') 232 307 { … … 240 315 } 241 316 } 242 317 243 318 /** 244 319 * Create the thumbnails for image assets … … 264 339 } 265 340 } 266 267 /** 268 * Resize automatically an image 341 342 /** 343 * Resize automatically an image 269 344 * Options : shave_all 270 345 * Recommanded when "image source HEIGHT" < "image source WIDTH" … … 303 378 return false; 304 379 } 305 380 306 381 public static function getParent($path) 307 382 { 308 383 $dirs = explode('/', $path); 309 384 array_pop($dirs); 310 385 311 386 return join('/', $dirs); 312 387 } … … 324 399 $name = array_pop($dirs); 325 400 $relative_path = implode($separator, $dirs); 326 401 327 402 return array($relative_path, $name); 328 403 } 329 404 330 405 public static function log($message, $color = '') 331 406 { … … 346 421 fwrite(STDOUT, $message); 347 422 } 348 423 349 424 } plugins/sfAssetsLibraryPlugin/branches/jillelaine/modules/sfAsset/lib/BasesfAssetActions.class.php
r13227 r13362 244 244 $folder->insertAsLastChildOf($this->parentFolder); 245 245 $folder->save(); 246 247 // Give the user useful feedback, user_settings set in sfAssetsLibraryTools > getUserSetPermissions() 248 if ($this->getRequestParameter('user_settings') == 'broken') 249 { 250 $this->setFlash('notice', 'The folder was successfully created, but your app.yml permissions are invalid. The default permissions were used instead. Contact your system administrator.'); 251 } 252 else 253 { 254 $this->setFlash('notice', 'The folder was successfully created.'); 255 } 246 256 247 257 $this->redirectToPath('sfAsset/list?dir='.$folder->getRelativePath());

