Development

Changeset 13362

You must first sign up to be able to contribute.

Changeset 13362

Show
Ignore:
Timestamp:
11/26/08 21:20:27 (1 year ago)
Author:
jillelaine
Message:

Added user configurable permissions to app.yml. Would apply to ticket 4580

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfAssetsLibraryPlugin/branches/jillelaine/README

    r13152 r13362  
    2020 
    2121 1 - Install the plugin. 
    22   
     22 
    2323 The easiest way to install `sfAssetsLibraryPlugin` is to use the symfony command line: 
    2424{{{ 
     
    2626}}} 
    2727 
    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 
    3030 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. 
    3131 
    3232 2 - Build the data structures 
    33   
     33 
    3434 Rebuild the model and generate the SQL code for the new tables: 
    3535{{{ 
     
    4747 Enable the `sfAsset` module in your backend application, via the `settings.yml` file. 
    4848{{{ 
    49 // in myproject/apps/backend/config/settings.yml 
     49# in myproject/apps/backend/config/settings.yml 
    5050all: 
    5151  .settings: 
     
    5353}}} 
    5454 
    55  Configure the path to the root assets directory in the `app.yml` file
    56 {{{ 
    57 // in myproject/config/app.yml 
     55 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 
    5858all: 
    5959  sfAssetsLibrary: 
    6060    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`. 
    6466 
    6567 4 - Clear the cache to enable the autoloading to find the new classes: 
     
    7274> php symfony sfassetlibrary-create-root backend 
    7375}}} 
    74   
     76 
    7577 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 
    7779 6 - You can now start using the plugin by browsing to the backend module's default page: 
    78 {{{  
     80{{{ 
    7981http://myproject/backend_dev.php/sfAsset 
    8082}}} 
     
    8486You 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`: 
    8587{{{ 
    86 # in apps/backend/config/app.yml 
     88# in myproject/apps/backend/config/app.yml 
    8789all: 
    8890  sfAssetsLibrary: 
     
    9092    check_type:       false                  # Set to true if you want to restrict the type of assets 
    9193    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 
    9296    thumbnail_dir:    thumbnail              # Where the image thumbnails are stored 
    9397    use_ImageMagick:  false                  # Set to true if you have the convert command 
     
    171175    model_class:      Post 
    172176    theme:            default 
    173          
     177 
    174178    edit: 
    175179      fields: 
     
    197201<?php echo input_sf_asset_tag('my_asset_field', '', array('images_only' => true)) ?> 
    198202}}} 
     203 
     204== Troubleshooting == 
     205 
     206If 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: 
     207http://www.symfony-project.org/forum/index.php/f/12/ 
    199208 
    200209== TODO == 
     
    209218== Changelog == 
    210219 
     220=== 2008-11-26 | Branches/jillelaine === 
     221 
     222 * jillelaine: Added user configurable directory and asset permissions 
     223 
    211224=== 2008-06-25 | Trunk === 
    212225 
     
    218231 * francois: Fixed missing layout file in package 
    219232 * francois: Fixed layout inclusion in Windows 
    220   
     233 
    221234=== 2008-06-12 | 0.8.1 Beta === 
    222235 
  • plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/model/sfAsset.php

    r13224 r13362  
    221221      throw new sfAssetException('Filetype "%type%" not allowed', array('%type%' => $this->getType())); 
    222222    } 
    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); 
    224227    if ($move) 
    225228    { 
     229      // Add chmod to set permissions 
     230      chmod($asset_path, $asset_perms); 
    226231      rename($asset_path, $this->getFullPath()); 
    227232    } 
    228233    else 
    229234    { 
     235      chmod($asset_path, $asset_perms); 
    230236      copy($asset_path, $this->getFullPath()); 
    231237    } 
     238    // Restore orig umask value 
     239    umask($old); 
    232240 
    233241    if ($this->supportsThumbnails()) 
  • plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/model/sfAssetFolder.php

    r13280 r13362  
    205205    if (!is_dir($new_path) || !is_writable($new_path)) 
    206206    { 
     207      //Added user configurable directory permissions 
    207208      $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 
    209212      umask($old); 
    210213    } 
  • plugins/sfAssetsLibraryPlugin/branches/jillelaine/lib/sfAssetsLibraryTools.class.php

    r10500 r13362  
    22/* 
    33 * This file is part of the sfAssetsLibrary package. 
    4  *  
     4 * 
    55 * (c) 2007 William Garcia <wgarcia@clever-age.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    1111/** 
    1212 * sfAssetsLibraryToolkit toolkit class 
    13  *  
     13 * 
    1414 * @author William Garcia 
    1515 */ 
    1616class sfAssetsLibraryTools 
    1717{ 
    18   
     18 
    1919  /** 
    2020   * @return string 
     
    4545    } 
    4646  } 
    47    
     47 
    4848  public static function isImage($ext) 
    4949  { 
    5050    return in_array(strtolower($ext), array('png', 'jpg', 'jpeg', 'gif')); 
    5151  } 
    52    
     52 
    5353  public static function isText($ext) 
    5454  { 
     
    6060    return in_array(strtolower($ext), array('zip', 'gz', 'tgz', 'rar')); 
    6161  } 
    62    
     62 
    6363  public static function getInfo($dir, $filename) 
    6464  { 
     
    9191    return $info; 
    9292  } 
    93    
     93 
    9494  public static function sanitizeName($file) 
    9595  { 
    9696    return preg_replace('/[^a-z0-9_\.-]/i', '_', $file); 
    9797  } 
    98    
     98 
    9999  public static function mkdir($dirName, $parentDirName) 
    100100  { 
    101101    $dirName = rtrim($dirName, '/'); 
    102      
     102 
    103103    if (!is_dir(self::getMediaDir(true) . $parentDirName)) 
    104104    { 
     
    113113      } 
    114114    } 
    115      
     115 
    116116    if (!$dirName) 
    117117    { 
     
    124124    try 
    125125    { 
     126      //Added user configurable directory permissions 
     127      $dir_perms = sfAssetsLibraryTools::getUserSetPermissions('dir_perms'); //validation function 
    126128      $old = umask(0); 
    127129      if (!is_dir($absCurrentDir)) 
    128130      { 
    129         mkdir($absCurrentDir, 0770); 
     131        mkdir($absCurrentDir, $dir_perms); 
     132        //mkdir($absCurrentDir, 0770);  //original line 
    130133      } 
    131134      if (!is_dir($absThumbDir)) 
    132135      { 
    133         mkdir($absThumbDir, 0770); 
     136        mkdir($absThumbDir, $dir_perms); 
     137        //mkdir($absThumbDir, 0770);  //original line 
    134138      } 
    135139      umask($old); 
     
    143147  } 
    144148 
    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)) 
    148223    { 
    149224      return false; 
    150225    } 
    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)) 
    154229      { 
    155230        self::deleteTree($dir); 
    156231      } 
    157232    } 
    158      
     233 
    159234    return rmdir($root); 
    160235  } 
     
    164239    if ($thumbnail_type == 'full') 
    165240    { 
    166       return self::getMediaDir($file_system) . $path . DIRECTORY_SEPARATOR . $filename;     
     241      return self::getMediaDir($file_system) . $path . DIRECTORY_SEPARATOR . $filename; 
    167242    } 
    168243    else 
     
    170245      return self::getMediaDir($file_system) . self::getThumbnailDir($path) . $thumbnail_type . '_' . $filename; 
    171246    } 
    172   }   
    173    
     247  } 
     248 
    174249  public function getAssetImageTag($sf_media, $thumbnail_type = 'full', $file_system = false, $options = array()) 
    175250  { 
     
    178253      'title' => $sf_media->getCopyright() 
    179254    )); 
    180      
     255 
    181256    return image_tag(self::getAssetUrl($sf_media, $thumbnail_type, $file_system), $options); 
    182257  } 
    183    
     258 
    184259  /** 
    185260   * Retrieves a sfMedia object from a relative URL like 
     
    188263   */ 
    189264  public static function getAssetFromUrl($url) 
    190   {  
    191      
     265  { 
     266 
    192267    $url = str_replace(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media'), '', $url); 
    193268    $url = rtrim($url, '/'); 
     
    195270    $filename = array_pop($parts); 
    196271    $relPath = '/' . implode('/', $parts); 
    197      
     272 
    198273    $c = new Criteria(); 
    199274    $c->add(sfMediaPeer::FILENAME, $filename); 
    200275    $c->add(sfMediaPeer::REL_PATH, $relPath ?  $relPath : null); 
    201      
     276 
    202277    return sfMediaPeer::doSelectOne($c); 
    203278  } 
    204    
     279 
    205280  public static function getMediaDir($file_system = false) 
    206281  { 
     
    217292 
    218293  /** 
    219    * Gives thumbnails folder for a folder  
     294   * Gives thumbnails folder for a folder 
    220295   * 
    221296   * @param string $path 
     
    225300  { 
    226301    $thumb_dir = $path . '/' . sfConfig::get('app_sfAssetsLibrary_thumbnail_dir', 'thumbnail'); 
    227      
     302 
    228303    return rtrim($thumb_dir, '/').'/'; 
    229304  } 
    230    
     305 
    231306  public static function getThumbnailPath($path, $filename, $thumbnail_type = 'full') 
    232307  { 
     
    240315    } 
    241316  } 
    242    
     317 
    243318  /** 
    244319   * Create the thumbnails for image assets 
     
    264339    } 
    265340  } 
    266    
    267   /** 
    268    * Resize automatically an image  
     341 
     342  /** 
     343   * Resize automatically an image 
    269344   * Options : shave_all 
    270345   * Recommanded when  "image source HEIGHT" < "image source WIDTH" 
     
    303378    return false; 
    304379  } 
    305    
     380 
    306381  public static function getParent($path) 
    307382  { 
    308383    $dirs = explode('/', $path); 
    309384    array_pop($dirs); 
    310      
     385 
    311386    return join('/', $dirs); 
    312387  } 
     
    324399    $name = array_pop($dirs); 
    325400    $relative_path =  implode($separator, $dirs); 
    326      
     401 
    327402    return array($relative_path, $name); 
    328403  } 
    329    
     404 
    330405  public static function log($message, $color = '') 
    331406  { 
     
    346421    fwrite(STDOUT, $message); 
    347422  } 
    348    
     423 
    349424} 
  • plugins/sfAssetsLibraryPlugin/branches/jillelaine/modules/sfAsset/lib/BasesfAssetActions.class.php

    r13227 r13362  
    244244      $folder->insertAsLastChildOf($this->parentFolder); 
    245245      $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      } 
    246256 
    247257      $this->redirectToPath('sfAsset/list?dir='.$folder->getRelativePath()); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.