b2evolution PHP Cross Reference Blogging Systems

Source: /inc/maintenance/_maintenance.init.php - 206 lines - 6143 bytes - Summary - Text - Print

Description: Controller mappings. For each controller name, we associate a controller file to be found in /inc/ . The advantage of this indirection is that it is easy to reorganize the controllers into subdirectories by modules. It is also easy to deactivate some controllers if you don't want to provide this functionality on a given installation.

   1  <?php
   2  /**
   3   * Controller mappings.
   4   *
   5   * For each controller name, we associate a controller file to be found in /inc/ .
   6   * The advantage of this indirection is that it is easy to reorganize the controllers into
   7   * subdirectories by modules. It is also easy to deactivate some controllers if you don't
   8   * want to provide this functionality on a given installation.
   9   *
  10   * Note: while the controller mappings might more or less follow the menu structure, we do not merge
  11   * the two tables since we could, at any time, decide to make a skin with a different menu structure.
  12   * The controllers however would most likely remain the same.
  13   *
  14   * @global array
  15   */
  16  if( !defined('EVO_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' );
  17  
  18  
  19  /**
  20   * Minimum PHP version required for maintenance module to function properly
  21   */
  22  $required_php_version[ 'maintenance' ] = '5.0';
  23  
  24  /**
  25   * Minimum MYSQL version required for maintenance module to function properly
  26   */
  27  $required_mysql_version[ 'maintenance' ] = '5.0.3';
  28  
  29  $ctrl_mappings['backup'] = 'maintenance/backup.ctrl.php';
  30  $ctrl_mappings['upgrade'] = 'maintenance/upgrade.ctrl.php';
  31  
  32  
  33  /**
  34   * maintenance_Module definition
  35   */
  36  class maintenance_Module extends Module
  37  {
  38      /**
  39       * Do the initializations. Called from in _main.inc.php.
  40       * This is typically where classes matching DB tables for this module are registered/loaded.
  41       *
  42       * Note: this should only load/register things that are going to be needed application wide,
  43       * for example: for constructing menus.
  44       * Anything that is needed only in a specific controller should be loaded only there.
  45       * Anything that is needed only in a specific view should be loaded only there.
  46       */
  47  	function init()
  48      {
  49          $this->check_required_php_version( 'maintenance' );
  50  
  51          load_funcs( 'maintenance/model/_maintenance.funcs.php' );
  52      }
  53  
  54  
  55      /**
  56       * Get default module permissions
  57       *
  58       * @param integer Group ID
  59       * @return array
  60       */
  61  	function get_default_group_permissions( $grp_ID )
  62      {
  63          switch( $grp_ID )
  64          {
  65              case 1: // Administrators group ID equals 1
  66                  $permname = 'upgrade';
  67                  break;
  68              case 2: // Privileged Bloggers group equals 2
  69                  $permname = 'none';
  70                  break;
  71              case 3: // Bloggers group ID equals 3
  72                  $permname = 'none';
  73                  break;
  74              default: // Other groups
  75                  $permname = 'none';
  76                  break;
  77          }
  78  
  79          // We can return as many default permissions as we want:
  80          // e.g. array ( permission_name => permission_value, ... , ... )
  81          return $permissions = array( 'perm_maintenance' => $permname );
  82      }
  83  
  84  
  85      /**
  86       * Get available group permissions
  87       *
  88       * @return array (may contain several permission blocks)
  89       */
  90  	function get_available_group_permissions()
  91      {
  92          // 'label' is used in the group form as label for radio buttons group
  93          // 'user_func' function used to check user permission. This function should be defined in Module.
  94          // 'group_func' function used to check group permission. This function should be defined in Module.
  95          // 'perm_block' group form block where this permissions will be displayed. Now available, the following blocks: additional, system
  96          // 'options' is permission options
  97          $permissions = array(
  98              'perm_maintenance' => array(
  99                  'label' => T_('Maintenance'),
 100                  'user_func'  => 'check_maintenance_user_perm',
 101                  'group_func' => 'check_maintenance_group_perm',
 102                  'perm_block' => 'system',
 103                  'options'  => array(
 104                          // format: array( radio_button_value, radio_button_label, radio_button_note )
 105                          array( 'none', T_( 'No Access' ), '' ),
 106                          array( 'backup', T_( 'Create backups' ), '' ),
 107                          array( 'upgrade', T_( 'Create backups & upgrade b2evolution' ), '' ),
 108                      ),
 109                  ),
 110              );
 111          return $permissions;
 112      }
 113  
 114  
 115      /**
 116       * Check a permission for the user. ( see 'user_func' in get_available_group_permissions() function  )
 117       *
 118       * @param string Requested permission level
 119       * @param string Permission value
 120       * @param mixed Permission target (blog ID, array of cat IDs...)
 121       * @return boolean True on success (permission is granted), false if permission is not granted
 122       */
 123  	function check_maintenance_user_perm( $permlevel, $permvalue, $permtarget )
 124      {
 125          return true;
 126      }
 127  
 128  
 129      /**
 130       * Check a permission for the group. ( see 'group_func' in get_available_group_permissions() function )
 131       *
 132       * @param string Requested permission level
 133       * @param string Permission value
 134       * @param mixed Permission target (blog ID, array of cat IDs...)
 135       * @return boolean True on success (permission is granted), false if permission is not granted
 136       */
 137  	function check_maintenance_group_perm( $permlevel, $permvalue, $permtarget )
 138      {
 139          $perm = false;
 140          switch ( $permvalue )
 141          {
 142              case 'upgrade':
 143                  // Users can create backups & upgrade the app.
 144                  if( $permlevel == 'upgrade' )
 145                  { // User can ask for delete perm...
 146                      $perm = true;
 147                      break;
 148                  }
 149  
 150              case 'backup':
 151                  //  Users can create backups
 152                  if( $permlevel == 'backup' )
 153                  {
 154                      $perm = true;
 155                      break;
 156                  }
 157          }
 158  
 159          return $perm;
 160      }
 161  
 162  
 163      /**
 164       * Builds the 3rd half of the menu. This is the one with the configuration features
 165       *
 166       * At some point this might be displayed differently than the 1st half.
 167       */
 168  	function build_menu_3()
 169      {
 170          global $AdminUI, $current_User;
 171  
 172          if( !$current_User->check_perm( 'admin', 'normal' ) )
 173          {
 174              return;
 175          }
 176  
 177          if( $current_User->check_perm( 'perm_maintenance', 'backup' ) )
 178          {
 179              // Display Backup tab in System -> Maintenance menu
 180              $AdminUI->add_menu_entries( array( 'options', 'misc' ), array(
 181                                      'backup' => array(
 182                                      'text' => T_('Backup'),
 183                                      'href' => '?ctrl=backup'    ),
 184                              ) );
 185          }
 186  
 187          if( $current_User->check_perm( 'perm_maintenance', 'upgrade' ) )
 188          {
 189              // Display Updates tab in System -> Maintenance menu
 190              $AdminUI->add_menu_entries( array( 'options', 'misc' ), array(
 191                                      'upgrade' => array(
 192                                      'text' => T_('Auto Upgrade'),
 193                                      'href' => '?ctrl=upgrade' ),
 194                              ) );
 195              $AdminUI->add_menu_entries( array( 'options', 'misc' ), array(
 196                                      'upgradesvn' => array(
 197                                      'text' => T_('Upgrade from SVN'),
 198                                      'href' => '?ctrl=upgrade&amp;tab=svn' ),
 199                              ) );
 200          }
 201      }
 202  }
 203  
 204  $maintenance_Module = new maintenance_Module();
 205  
 206  ?>

title

Description

title

Description

title

Description

title

title

Body