b2evolution PHP Cross Reference Blogging Systems

Source: /inc/files/_files.init.php - 466 lines - 12756 bytes - Summary - Text - Print

Description: This is the init file for the files module

   1  <?php
   2  /**
   3   * This is the init file for the files module
   4   *
   5   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   6   *
   7   * @package admin
   8   *
   9   * @version $Id: _files.init.php 6136 2014-03-08 07:59:48Z manuel $
  10   */
  11  if( !defined('EVO_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' );
  12  
  13  /**
  14   * Minimum PHP version required for files module to function properly
  15   */
  16  $required_php_version[ 'files' ] = '5.0';
  17  
  18  /**
  19   * Minimum MYSQL version required for files module to function properly
  20   */
  21  $required_mysql_version[ 'files' ] = '5.0.3';
  22  
  23  /**
  24   * Aliases for table names:
  25   *
  26   * (You should not need to change them.
  27   *  If you want to have multiple b2evo installations in a single database you should
  28   *  change {@link $tableprefix} in _basic_config.php)
  29   */
  30  $db_config['aliases'] = array_merge( $db_config['aliases'], array(
  31          'T_files'               => $tableprefix.'files',
  32          'T_filetypes'           => $tableprefix.'filetypes',
  33          'T_files__vote'         => $tableprefix.'files__vote',
  34      ) );
  35  
  36  /**
  37   * Controller mappings.
  38   *
  39   * For each controller name, we associate a controller file to be found in /inc/ .
  40   * The advantage of this indirection is that it is easy to reorganize the controllers into
  41   * subdirectories by modules. It is also easy to deactivate some controllers if you don't
  42   * want to provide this functionality on a given installation.
  43   *
  44   * Note: while the controller mappings might more or less follow the menu structure, we do not merge
  45   * the two tables since we could, at any time, decide to make a skin with a different menu structure.
  46   * The controllers however would most likely remain the same.
  47   *
  48   * @global array
  49   */
  50  $ctrl_mappings = array_merge( $ctrl_mappings, array(
  51          'files'        => 'files/files.ctrl.php',
  52          'fileset'      => 'files/file_settings.ctrl.php',
  53          'filetypes'    => 'files/file_types.ctrl.php',
  54          'filemod'      => 'files/file_moderation.ctrl.php',
  55      ) );
  56  
  57  
  58  
  59  /**
  60   * Get the FileCache
  61   *
  62   * @return FileCache
  63   */
  64  function & get_FileCache()
  65  {
  66      global $FileCache;
  67  
  68      if( ! isset( $FileCache ) )
  69      {    // Cache doesn't exist yet:
  70          load_class( 'files/model/_filecache.class.php', 'FileCache' );
  71          $FileCache = new FileCache(); // COPY (FUNC)
  72      }
  73  
  74      return $FileCache;
  75  }
  76  
  77  /**
  78   * Get the FileRootCache
  79   *
  80   * @return FileRootCache
  81   */
  82  function & get_FileRootCache()
  83  {
  84      global $Plugins, $FileRootCache;
  85  
  86      if( ! isset( $FileRootCache ) )
  87      {    // Cache doesn't exist yet:
  88          load_class( 'files/model/_filerootcache.class.php', 'FileRootCache' );
  89          $Plugins->get_object_from_cacheplugin_or_create( 'FileRootCache' );
  90      }
  91  
  92      return $FileRootCache;
  93  }
  94  
  95  /**
  96   * Get the FiletypeCache
  97   *
  98   * @return FiletypeCache
  99   */
 100  function & get_FiletypeCache()
 101  {
 102      global $Plugins;
 103      global $FiletypeCache;
 104  
 105      if( ! isset( $FiletypeCache ) )
 106      {    // Cache doesn't exist yet:
 107          load_class( 'files/model/_filetypecache.class.php', 'FiletypeCache' );
 108          $Plugins->get_object_from_cacheplugin_or_create( 'FiletypeCache' );
 109      }
 110  
 111      return $FiletypeCache;
 112  }
 113  
 114  /**
 115   * adsense_Module definition
 116   */
 117  class files_Module extends Module
 118  {
 119      /**
 120       * Do the initializations. Called from in _main.inc.php.
 121       * This is typically where classes matching DB tables for this module are registered/loaded.
 122       *
 123       * Note: this should only load/register things that are going to be needed application wide,
 124       * for example: for constructing menus.
 125       * Anything that is needed only in a specific controller should be loaded only there.
 126       * Anything that is needed only in a specific view should be loaded only there.
 127       */
 128  	function init()
 129      {
 130          $this->check_required_php_version( 'files' );
 131  
 132          load_class( 'files/model/_file.class.php', 'File' );
 133          load_class( 'files/model/_filetype.class.php', 'FileType' );
 134          load_class( 'files/model/_filetypecache.class.php', 'FileTypeCache' );
 135      }
 136  
 137      /**
 138       * Get default module permissions
 139       *
 140       * @param integer Group ID
 141       * @return array
 142       */
 143  	function get_default_group_permissions( $grp_ID )
 144      {
 145          switch( $grp_ID )
 146          {
 147              case 1: // Administrators group ID equals 1
 148                  $permfiles = 'all';
 149                  $permshared = 'edit';
 150                  break;
 151              case 2: // Privileged Bloggers group equals 2
 152                  $permfiles = 'add';
 153                  $permshared = 'add';
 154                  break;
 155              case 3: // Bloggers group ID equals 3
 156                  $permfiles = 'view';
 157                  $permshared = 'view';
 158                  break;
 159              default: // Other groups
 160                  $permfiles = 'none';
 161                  $permshared = 'none';
 162                  break;
 163          }
 164  
 165          // We can return as many default permissions as we want:
 166          // e.g. array ( permission_name => permission_value, ... , ... )
 167          return $permissions = array( 'perm_files' => $permfiles, 'perm_shared_root' => $permshared );
 168      }
 169  
 170      /**
 171       * Get available group permissions
 172       *
 173       * @return array
 174       */
 175  	function get_available_group_permissions()
 176      {
 177          global $current_User;
 178          // fp> todo perm check
 179          $filetypes_linkstart = '<a href="?ctrl=filetypes" title="'.T_('Edit locked file types...').'">';
 180          $filetypes_linkend = '</a>';
 181          $filetypes_allowed = '';
 182          $filetypes_not_allowed = '';
 183          if( isset( $current_User ) && $current_User->check_perm( 'options', 'edit' ) ) {
 184              $filetypes_allowed = $filetypes_linkstart.get_icon('file_allowed').$filetypes_linkend;
 185              $filetypes_not_allowed = $filetypes_linkstart.get_icon('file_not_allowed').$filetypes_linkend;
 186          }
 187          // 'label' is used in the group form as label for radio buttons group
 188          // 'user_func' is used to check user permission. This function should be defined in module initializer.
 189          // 'group_func' is used to check group permission. This function should be defined in module initializer.
 190          // 'perm_block' group form block where this permissions will be displayed. Now available, the following blocks: additional, system
 191          // 'options' is permission options
 192          $permissions = array(
 193              'perm_files' => array(
 194                  'label' => T_('Files'),
 195                  'user_func'  => 'check_files_user_perm',
 196                  'group_func' => 'check_files_group_perm',
 197                  'perm_block' => 'additional',
 198                  'options'  => array(
 199                          // format: array( radio_button_value, radio_button_label, radio_button_note )
 200                          array( 'none', T_('No Access') ),
 201                          array( 'view', T_('View files for all allowed roots') ),
 202                          array( 'add', T_('Add/Upload files to allowed roots') ),
 203                          array( 'edit', sprintf( T_('Edit %sunlocked files'), $filetypes_linkstart.get_icon('file_allowed').$filetypes_linkend ) ),
 204                          array( 'all', sprintf( T_('Edit all files, including %slocked ones'), $filetypes_linkstart.get_icon('file_not_allowed').$filetypes_linkend ), T_('Needed for editing PHP files in skins.') ),
 205                      ),
 206                  'perm_type' => 'radiobox',
 207                  'field_lines' => true,
 208                  'field_note' => T_('This setting will further restrict any media file permissions on specific blogs.'),
 209                  ),
 210              'perm_shared_root' => array(
 211                  'label' => T_('Access to shared root'),
 212                  'user_func'  => 'check_sharedroot_user_perm',
 213                  'group_func' => 'check_sharedroot_group_perm',
 214                  'perm_block' => 'additional',
 215                  'options'  => array(
 216                          // format: array( radio_button_value, radio_button_label, radio_button_note )
 217                          array( 'none', T_('No Access') ),
 218                          array( 'view', T_('Read only') ),
 219                          array( 'add', T_('Add/Upload') ),
 220                          array( 'edit', T_('Edit') ),
 221                      ),
 222                  'perm_type' => 'radiobox',
 223                  'field_lines' => false,
 224                  ),
 225          );
 226          // We can return as many permissions as we want.
 227          // In other words, one module can return many pluggable permissions.
 228          return $permissions;
 229      }
 230  
 231      /**
 232       * Check a permission for the user. ( see 'user_func' in get_available_group_permissions() function  )
 233       *
 234       * @param string Requested permission level
 235       * @param string Permission value
 236       * @param mixed Permission target (blog ID, array of cat IDs...)
 237       * @return boolean True on success (permission is granted), false if permission is not granted
 238       */
 239  	function check_files_user_perm( $permlevel, $permvalue, $permtarget )
 240      {
 241          return true;
 242      }
 243  
 244      /**
 245       * Check a permission for the group. ( see 'group_func' in get_available_group_permissions() function )
 246       *
 247       * @param string Requested permission level
 248       * @param string Permission value
 249       * @param mixed Permission target (blog ID, array of cat IDs...)
 250       * @return boolean True on success (permission is granted), false if permission is not granted
 251       */
 252  	function check_files_group_perm( $permlevel, $permvalue, $permtarget )
 253      {
 254          $perm = false;
 255          switch ( $permvalue )
 256          {
 257              case 'all':
 258                  global $demo_mode;
 259                  if( ( ! $demo_mode ) && ( $permlevel == 'all' ) )
 260                  { // All permissions granted
 261                      $perm = true;
 262                      break;
 263                  }
 264  
 265              case 'edit':
 266                  // User can ask for normal edit perm...
 267                  if( $permlevel == 'edit' )
 268                  {
 269                      $perm = true;
 270                      break;
 271                  }
 272  
 273              case 'add':
 274                  // User can ask for add perm...
 275                  if( $permlevel == 'add' )
 276                  {
 277                      $perm = true;
 278                      break;
 279                  }
 280  
 281              case 'view':
 282                  // User can ask for view perm...
 283                  if( $permlevel == 'view' )
 284                  {
 285                      $perm = true;
 286                      break;
 287                  }
 288          }
 289  
 290          if( $perm && isset($permtarget) && ( is_a( $permtarget, 'FileRoot' ) ) )
 291          {
 292              global $current_User;
 293              switch( $permtarget->type )
 294              {
 295                  case 'shared':
 296                      return $current_User->check_perm( 'shared_root', $permlevel );
 297                  case 'user':
 298                      return $permtarget->in_type_ID == $current_User->ID;
 299              }
 300          }
 301  
 302          return $perm;
 303      }
 304  
 305  	function check_sharedroot_group_perm( $permlevel, $permvalue, $permtarget )
 306      {
 307          $perm = false;
 308          switch ( $permvalue )
 309          {
 310              case 'edit':
 311                  if( $permlevel == 'edit' )
 312                  { // User can ask for normal edit perm...
 313                      $perm = true;
 314                      break;
 315                  }
 316  
 317              case 'add':
 318                  // User can ask for normal add perm...
 319                  if( $permlevel == 'add' )
 320                  {
 321                      $perm = true;
 322                      break;
 323                  }
 324  
 325              case 'view':
 326                  // User can ask for normal view perm...
 327                  if( $permlevel == 'view' )
 328                  {
 329                      $perm = true;
 330                      break;
 331                  }
 332          }
 333          return $perm;
 334      }
 335  
 336      /**
 337       * Build the evobar menu
 338       */
 339  	function build_evobar_menu()
 340      {
 341          /**
 342           * @var Menu
 343           */
 344          global $topleft_Menu;
 345          global $current_User;
 346          global $admin_url;
 347          global $Blog;
 348  
 349          if( $current_User->check_perm( 'admin', 'standard' ) )
 350          {
 351              if( !empty($Blog) && $current_User->check_perm( 'files', 'view', false, $Blog->ID ) )
 352              {    // Manage blog files:
 353  
 354                  // TODO: this is hackish and would require a proper function call
 355                  $topleft_Menu->_menus['entries']['blog']['disabled'] = false;
 356  
 357                  // FM enabled and permission to view files:
 358                  $entries['files'] = array(
 359                          'text' => T_('Files').'&hellip;',
 360                          'href' => $admin_url.'?ctrl=files',
 361                      );
 362  
 363                  $topleft_Menu->add_menu_entries( 'blog', $entries );
 364              }
 365          }
 366  
 367          if( $current_User->check_perm( 'admin', 'restricted' ) )
 368          {
 369              if( $current_User->check_perm( 'files', 'view', false, NULL ) )
 370              {    // Manage files generally:
 371  
 372                  // TODO: this is hackish and would require a proper function call
 373                  $topleft_Menu->_menus['entries']['tools']['disabled'] = false;
 374  
 375                  // FM enabled and permission to view files:
 376                  $entries['files'] = array(
 377                          'text' => T_('Files').'&hellip;',
 378                          'href' => $admin_url.'?ctrl=files',
 379                      );
 380  
 381                  $topleft_Menu->add_menu_entries( 'tools', $entries );
 382              }
 383          }
 384      }
 385  
 386  
 387      /**
 388       * Builds the 1st half of the menu. This is the one with the most important features
 389       */
 390  	function build_menu_1()
 391      {
 392          global $blog, $dispatcher;
 393          /**
 394           * @var User
 395           */
 396          global $current_User;
 397          global $Blog;
 398          global $Settings;
 399          /**
 400           * @var AdminUI_general
 401           */
 402          global $AdminUI;
 403  
 404          if( !$current_User->check_perm( 'admin', 'restricted' ) )
 405          {
 406              return;
 407          }
 408  
 409          if( $current_User->check_perm( 'files', 'view', false, $blog ? $blog : NULL ) )
 410          {    // FM enabled and permission to view files:
 411              $AdminUI->add_menu_entries( NULL, array(
 412                          'files' => array(
 413                              'text' => T_('Files'),
 414                              'title' => T_('File management'),
 415                              'href' => $dispatcher.'?ctrl=files',
 416                              // Controller may add subtabs
 417                          ),
 418                      ) );
 419          }
 420  
 421      }
 422  
 423      /**
 424       * Builds the 3rd half of the menu. This is the one with the configuration features
 425       *
 426       * At some point this might be displayed differently than the 1st half.
 427       */
 428  	function build_menu_3()
 429      {
 430      }
 431  }
 432  
 433  $files_Module = new files_Module();
 434  
 435  
 436  /*
 437   * _files.init.php,v
 438   * Revision 1.16  2011/09/13 15:31:35  fplanque
 439   * Enhanced back-office navigation.
 440   *
 441   * Revision 1.15  2011/09/04 22:13:15  fplanque
 442   * copyright 2011
 443   *
 444   * Revision 1.14  2011/04/05 12:41:39  efy-asimo
 445   * file perms check and file delete - fix
 446   *
 447   * Revision 1.13  2011/02/15 15:37:00  efy-asimo
 448   * Change access to admin permission
 449   *
 450   * Revision 1.12  2011/01/18 16:23:02  efy-asimo
 451   * add shared_root perm and refactor file perms - part1
 452   *
 453   * Revision 1.11  2010/10/19 02:00:54  fplanque
 454   * MFB
 455   *
 456   * Revision 1.9.2.3  2010/10/19 01:04:48  fplanque
 457   * doc
 458   *
 459   * Revision 1.3  2009/08/30 12:31:44  tblue246
 460   * Fixed CVS keywords
 461   *
 462   * Revision 1.1  2009/08/30 00:30:52  fplanque
 463   * increased modularity
 464   *
 465   */
 466  ?>

title

Description

title

Description

title

Description

title

title

Body