Changeset 2872

Show
Ignore:
Timestamp:
11/24/08 17:42:02 (6 weeks ago)
Author:
MattRead
Message:

branch:adminhandler use the action handler_var for calling different action methods

Location:
branches/adminhandler/htdocs/system/classes
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/adminhandler/htdocs/system/classes/adminhandler.php

    r2870 r2872  
    9090        if ( class_exists($admin_page) ) { 
    9191            $admin_page = new $admin_page( $request_method, $this, $this->theme ); 
    92             $fn = 'act_request_' . strtolower($request_method); 
    93             $admin_page->$fn(); 
     92            $action = isset($this->handler_vars['action']) ? $this->handler_vars['action'] : 'request'; 
     93            $admin_page->act( $action, $request_method ); 
    9494        } 
    9595        else { 
     
    110110        if ( class_exists($admin_page) ) { 
    111111            $admin_page = new $admin_page( $request_method, $this ); 
    112             $fn = 'act_ajax_' . strtolower($request_method); 
    113             $admin_page->$fn( $this->handler_vars ); 
     112            $action = isset($this->handler_vars['action']) ? $this->handler_vars['action'] : 'request'; 
     113            $admin_page->act_ajax( $action, $request_method ); 
    114114        } 
    115115        else { 
  • branches/adminhandler/htdocs/system/classes/adminpage.php

    r2870 r2872  
    55    protected $request_method; 
    66    protected $handler; 
     7    protected $handler_vars = array(); 
    78    protected $theme; 
    89     
     
    1516    } 
    1617     
     18    // @todo fix allow list for new action methods. 
    1719    public function __call( $method, $args ) 
    1820    { 
    1921        $class = get_class($this); 
    20         Plugins::act( "{$class}_{$this->request_method}", $this, $args ); 
     22        Plugins::act( "{$class}_{$method}", $this, $args ); 
    2123        header( 'HTTP/1.1 405 Method Not Allowed', true, 405 ); 
    2224        // Build list of accepted methods and send allow header as per spec.. 
     
    3840    } 
    3941     
     42    public function act( $action, $method ) 
     43    { 
     44        $this->{"act_{$action}_{$method}"}(); 
     45    } 
     46     
     47    public function act_ajax( $action, $method ) 
     48    { 
     49        $this->{"act_ajax_{$action}_{$method}"}(); 
     50    } 
     51     
    4052    protected function display( $template_name ) 
    4153    { 
  • branches/adminhandler/htdocs/system/classes/dashboardadminpage.php

    r2870 r2872  
    130130     
    131131    /** 
    132      * Handles ajax requests from the dashboard 
    133      */ 
    134     public function act_ajax_post( $handler_vars ) 
    135     { 
    136         $theme_dir = Plugins::filter( 'admin_theme_dir', Site::get_dir( 'admin_theme', TRUE ) ); 
    137         $this->theme = Themes::create( 'admin', 'RawPHPEngine', $theme_dir ); 
    138  
    139         switch ( $handler_vars['action'] ) { 
    140         case 'updateModules': 
    141             $modules = array(); 
    142             foreach($_POST as $key => $module ) { 
    143                 // skip POST elements which are not module names 
    144                 if ( preg_match( '/^module\d+$/', $key ) ) { 
    145                     list( $module_id, $module_name ) = split( ':', $module, 2 ); 
    146                     // remove non-sortable modules from the list 
    147                     if ( $module_id != 'nosort' ) { 
    148                         $modules[$module_id] = $module_name; 
    149                     } 
    150                 } 
    151             } 
    152  
    153             Modules::set_active( $modules ); 
    154             echo json_encode( true ); 
    155             break; 
    156         case 'addModule': 
    157             $id = Modules::add( $handler_vars['module_name'] ); 
    158             $this->fetch_dashboard_modules(); 
    159             $result = array( 
    160                 'message' => "Added module {$handler_vars['module_name']}.", 
    161                 'modules' => $this->theme->fetch( 'dashboard_modules' ), 
    162             ); 
    163             echo json_encode( $result ); 
    164             break; 
    165         case 'removeModule': 
    166             Modules::remove( $handler_vars['moduleid'] ); 
    167             $this->fetch_dashboard_modules(); 
    168             $result = array( 
    169                 'message' => 'Removed module', 
    170                 'modules' => $this->theme->fetch( 'dashboard_modules' ), 
    171             ); 
    172             echo json_encode( $result ); 
    173             break; 
    174         } 
    175     } 
    176      
    177     /** 
    178132     * Adds a module to the user's dashboard 
    179133     * @param object form FormUI object 
     
    187141        return false; 
    188142    } 
     143     
     144    // AJAX Methods 
     145     
     146    public function act_ajax( $action, $method ) 
     147    { 
     148        $theme_dir = Plugins::filter( 'admin_theme_dir', Site::get_dir( 'admin_theme', TRUE ) ); 
     149        $this->theme = Themes::create( 'admin', 'RawPHPEngine', $theme_dir ); 
     150         
     151        parent::act_ajax( $action, $method ); 
     152    } 
     153     
     154    public function act_ajax_updateModules_post() 
     155    { 
     156        $modules = array(); 
     157        foreach($_POST as $key => $module ) { 
     158            // skip POST elements which are not module names 
     159            if ( preg_match( '/^module\d+$/', $key ) ) { 
     160                list( $module_id, $module_name ) = split( ':', $module, 2 ); 
     161                // remove non-sortable modules from the list 
     162                if ( $module_id != 'nosort' ) { 
     163                    $modules[$module_id] = $module_name; 
     164                } 
     165            } 
     166        } 
     167 
     168        Modules::set_active( $modules ); 
     169        echo json_encode( true ); 
     170    } 
     171     
     172    public function act_ajax_addModule_post() 
     173    { 
     174        $id = Modules::add( $this->handler_vars['module_name'] ); 
     175        $this->fetch_dashboard_modules(); 
     176        $result = array( 
     177            'message' => "Added module {$this->handler_vars['module_name']}.", 
     178            'modules' => $this->theme->fetch( 'dashboard_modules' ), 
     179        ); 
     180        echo json_encode( $result ); 
     181    } 
     182     
     183    public function act_ajax_removeModule_post() 
     184    { 
     185        Modules::remove( $this->handler_vars['moduleid'] ); 
     186        $this->fetch_dashboard_modules(); 
     187        $result = array( 
     188            'message' => 'Removed module', 
     189            'modules' => $this->theme->fetch( 'dashboard_modules' ), 
     190        ); 
     191        echo json_encode( $result ); 
     192    } 
    189193} 
  • branches/adminhandler/htdocs/system/classes/pluginsadminpage.php

    r2870 r2872  
    33class PluginsAdminPage extends AdminPage 
    44{ 
    5         /** 
     5    /** 
    66     * A POST handler for the admin plugins page that simply passes those options through. 
    77     */ 
    8     public function post_plugins() 
     8    public function act_request_post() 
    99    { 
    10         return $this->get_plugins(); 
     10        return $this->act_request_get(); 
    1111    } 
    1212 
    13     public function get_plugins() 
     13    public function act_request_get() 
    1414    { 
    1515        $all_plugins = Plugins::list_all(); 
     
    6969    } 
    7070     
    71         /** 
    72      * Handles plugin activation or deactivation. 
    73      */ 
    74     public function get_plugin_toggle() 
    75     { 
    76         $extract = $this->handler_vars->filter_keys('plugin_id', 'action'); 
    77         foreach($extract as $key => $value) { 
    78             $$key = $value; 
    79         } 
    80  
    81         $plugins = Plugins::list_all(); 
    82         foreach($plugins as $file) { 
    83             if(Plugins::id_from_file($file) == $plugin_id) { 
    84                 switch ( strtolower($action) ) { 
    85                     case 'activate': 
    86                         if ( Plugins::activate_plugin($file) ) { 
    87                             $plugins = Plugins::get_active(); 
    88                             Session::notice( 
    89                                 _t( "Activated plugin '%s'", array($plugins[Plugins::id_from_file( $file )]->info->name) ), 
    90                                 $plugins[Plugins::id_from_file($file)]->plugin_id 
    91                             ); 
    92                         } 
    93                     break; 
    94                     case 'deactivate': 
    95                         if ( Plugins::deactivate_plugin($file) ) { 
    96                             $plugins = Plugins::get_active(); 
    97                             Session::notice( 
    98                                 _t( "Deactivated plugin '%s'", array($plugins[Plugins::id_from_file( $file )]->info->name) ), 
    99                                 $plugins[Plugins::id_from_file($file)]->plugin_id 
    100                             ); 
    101                         } 
    102                     break; 
    103                     default: 
    104                         Plugins::act( 
    105                             'adminhandler_get_plugin_toggle_action', 
    106                             $action, 
    107                             $file, 
    108                             $plugin_id, 
    109                             $plugins 
    110                         ); 
    111                     break; 
    112                 } 
    113             } 
    114         } 
    115         Utils::redirect( URL::get( 'admin', 'page=plugins' ) ); 
    116     } 
    117      
    118         /** 
     71    /** 
    11972     * Handles plugin activation or deactivation. 
    12073     */ 
  • branches/adminhandler/htdocs/system/classes/publishadminpage.php

    r2870 r2872  
    101101    } 
    102102 
    103     public function form_publish($post, $newpost = true) 
     103    public function form_publish( Post $post, $newpost = true) 
    104104    { 
    105105        $form = new FormUI('create-content');