b2evolution PHP Cross Reference Blogging Systems

Source: /inc/files/model/_fileroot.class.php - 232 lines - 6291 bytes - Summary - Text - Print

Description: This file implements the FileRoot class. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the FileRoot class.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * {@internal License choice
  11   * - If you have received this file as part of a package, please find the license.txt file in
  12   *   the same folder or the closest folder above for complete license terms.
  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14   *   then you must choose one of the following licenses before using the file:
  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17   * }}
  18   *
  19   * {@internal Open Source relicensing agreement:
  20   * }}
  21   *
  22   * @package evocore
  23   *
  24   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  25   * @author fplanque: Francois PLANQUE.
  26   *
  27   * @version $Id: _fileroot.class.php 6136 2014-03-08 07:59:48Z manuel $
  28   */
  29  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  30  
  31  
  32  /**
  33   * This class provides info about a File Root.
  34   *
  35   * A FileRoot describes a directory available for media file storage, under access permission.
  36   *
  37   * @package evocore
  38   */
  39  class FileRoot
  40  {
  41      /**
  42       * Type: 'user', 'group' or 'collection'.
  43       *
  44       * Note: group is not implemented yet. Absolute will probably be deprecated.
  45       */
  46      var $type;
  47  
  48      /**
  49       * ID of user, group or collection.
  50       */
  51      var $in_type_ID;
  52  
  53      /**
  54       * Unique Root ID constructed from type and in_type_ID
  55       * @var string
  56       */
  57      var $ID;
  58  
  59      /**
  60       * Name of the root
  61       */
  62      var $name;
  63  
  64      /**
  65       * Absolute path, ending with slash
  66       */
  67      var $ads_path;
  68  
  69      /**
  70       * Absolute URL, ending with slash
  71       */
  72      var $ads_url;
  73  
  74  
  75      /**
  76       * Constructor
  77       *
  78       * Will fail if non existent User or Blog is requested.
  79       * But specific access permissions on (threfore existence of) this User or Blog should have been tested before anyway.
  80       *
  81       * @param string Root type: 'user', 'group' or 'collection'
  82       * @param integer ID of the user, the group or the collection the file belongs to...
  83       * @param boolean Create the directory, if it does not exist yet?
  84       */
  85  	function FileRoot( $root_type, $root_in_type_ID, $create = true )
  86      {
  87          /**
  88           * @var User
  89           */
  90          global $current_User;
  91          global $Messages;
  92          global $Settings, $Debuglog;
  93          global $Blog;
  94  
  95          // Store type:
  96          $this->type = $root_type;
  97          // Store ID in type:
  98          $this->in_type_ID = $root_in_type_ID;
  99          // Generate unique ID:
 100          $this->ID = FileRoot::gen_ID( $root_type, $root_in_type_ID );
 101  
 102          switch( $root_type )
 103          {
 104              case 'user':
 105                  $UserCache = & get_UserCache();
 106                  if( ! $User = & $UserCache->get_by_ID( $root_in_type_ID, false, false ) )
 107                  {    // User not found
 108                      return false;
 109                  }
 110                  $this->name = $User->get( 'login' ); //.' ('. /* TRANS: short for "user" */ T_('u').')';
 111                  $this->ads_path = $User->get_media_dir( $create );
 112                  $this->ads_url = $User->get_media_url();
 113                  return;
 114  
 115              case 'collection':
 116                  $BlogCache = & get_BlogCache();
 117                  if( ! $Blog = & $BlogCache->get_by_ID( $root_in_type_ID, false, false ) )
 118                  {    // Blog not found
 119                      return false;
 120                  }
 121                  $this->name = $Blog->get( 'shortname' ); //.' ('. /* TRANS: short for "blog" */ T_('b').')';
 122                  $this->ads_path = $Blog->get_media_dir( $create );
 123                  $this->ads_url = $Blog->get_media_url();
 124                  return;
 125  
 126              case 'shared':
 127                  // fp> TODO: handle multiple shared directories
 128                  global $media_path, $media_url;
 129                  $rds_shared_subdir = 'shared/global/';
 130                  $ads_shared_dir = $media_path.$rds_shared_subdir;
 131  
 132                  if( ! $Settings->get( 'fm_enable_roots_shared' ) )
 133                  { // Shared dir is disabled:
 134                      $Debuglog->add( 'Attempt to access shared dir, but this feature is globally disabled', 'files' );
 135                  }
 136                  /* Try to create shared directory if it doesn't exist.
 137                   * Note: mkdir_r() already checks if the dir to create exists.
 138                   */
 139                  elseif( ! mkdir_r( $ads_shared_dir ) )
 140                  {
 141                      // Only display error on an admin page:
 142                      if( is_admin_page() )
 143                      {
 144                          $Messages->add( sprintf( T_('The directory &laquo;%s&raquo; could not be created.'), $rds_shared_subdir ).get_manual_link('directory_creation_error'), 'error' );
 145                      }
 146                  }
 147                  else
 148                  {
 149                      $this->name = T_('Shared');
 150                      $this->ads_path = $ads_shared_dir;
 151                      if( isset($Blog) )
 152                      {    // (for now) Let's make shared files appear as being part of the currently displayed blog:
 153                          $this->ads_url = $Blog->get_local_media_url().'shared/global/';
 154                      }
 155                      else
 156                      {
 157                          $this->ads_url = $media_url.'shared/global/';
 158                      }
 159                  }
 160                  return;
 161  
 162              case 'skins':
 163                  // fp> some stuff here should go out of here... but I don't know where to put it yet. I'll see after the Skin refactoring.
 164                  if( ! $Settings->get( 'fm_enable_roots_skins' ) )
 165                  { // Skins root is disabled:
 166                      $Debuglog->add( 'Attempt to access skins dir, but this feature is globally disabled', 'files' );
 167                  }
 168                  elseif( empty( $current_User ) || ( ! $current_User->check_perm( 'templates' ) ) )
 169                  { // No perm to access templates:
 170                      $Debuglog->add( 'Attempt to access skins dir, but no permission', 'files' );
 171                  }
 172                  else
 173                  {
 174                      global $skins_path, $skins_url;
 175                      $this->name = T_('Skins');
 176                      $this->ads_path = $skins_path;
 177                      if( isset($Blog) )
 178                      { // (for now) Let's make skin files appear as being part of the currently displayed blog:
 179                          $this->ads_url = $Blog->get_local_skins_url();
 180                      }
 181                      else
 182                      {
 183                          $this->ads_url = $skins_url;
 184                      }
 185                  }
 186                  return;
 187          }
 188  
 189          debug_die( "Invalid root type" );
 190      }
 191  
 192  
 193  	function get_typegroupname()
 194      {
 195          switch( $this->type )
 196          {
 197              case 'user':
 198                  return NT_('User roots');
 199  
 200              case 'collection':
 201                  return NT_('Blog roots');
 202  
 203              default:
 204                  return NT_('Special roots');
 205          }
 206      }
 207  
 208      /**
 209       * @static
 210       */
 211  	function gen_ID( $root_type, $root_in_type_ID )
 212      {
 213          if( !is_number( $root_in_type_ID ) )
 214          {
 215              debug_die( "Invalid root type ID" );
 216          }
 217  
 218          switch( $root_type )
 219          {
 220              case 'user':
 221              case 'shared':
 222              case 'collection':
 223              case 'skins':
 224                  return $root_type.'_'.$root_in_type_ID;
 225          }
 226  
 227          debug_die( "Invalid root type" );
 228      }
 229  
 230  }
 231  
 232  ?>

title

Description

title

Description

title

Description

title

title

Body