b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: main ] [ index: main ] [ all elements ]

Source for file _maintenance.init.php

Documentation is available at _maintenance.init.php

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

Documentation generated on Sat, 06 Mar 2010 04:18:46 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).