Skip to content

Commit

Permalink
Merge pull request #687 from norv/actions
Browse files Browse the repository at this point in the history
Actions standardization (admin)
  • Loading branch information
norv committed Jul 19, 2013
2 parents db062e4 + 691edbe commit 26203d9
Show file tree
Hide file tree
Showing 29 changed files with 1,011 additions and 870 deletions.
14 changes: 13 additions & 1 deletion sources/admin/Admin.php
Expand Up @@ -110,12 +110,24 @@ public function action_index()
'class' => 'admin_img_packages',
'subsections' => array(
'browse' => array($txt['browse_packages']),
'packageget' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packages;sa=packageget;get'),
'installed' => array($txt['installed_packages']),
'perms' => array($txt['package_file_perms']),
'options' => array($txt['package_settings']),
),
),
'packageservers' => array(
'label' => $txt['package_servers'],
'file' => 'PackageServers.php',
'controller' => 'PackageServers_Controller',
'function' => 'action_index',
'permission' => array('admin_forum'),
'icon' => 'transparent.png',
'class' => 'admin_img_packages',
'subsections' => array(
'servers' => array($txt['download_packages']),
'upload' => array($txt['upload_packages']),
),
),
'search' => array(
'controller' => 'Admin_Controller',
'function' => 'action_search',
Expand Down
2 changes: 1 addition & 1 deletion sources/admin/AdminLog.php
Expand Up @@ -40,7 +40,7 @@ public function action_index()
$log_functions = array(
'errorlog' => array(
'file' => 'ManageErrors.php',
'function' => 'action_log',
'function' => 'action_index',
'controller' => 'ManageErrors_Controller'),
'adminlog' => array(
'file' => 'Modlog.php',
Expand Down
2 changes: 1 addition & 1 deletion sources/admin/ManageBadBehavior.php
Expand Up @@ -27,7 +27,7 @@ public function action_index()
* View the forum's badbehavior log.
* This function sets all the context up to show the badbehavior log for review.
* It requires the maintain_forum permission.
* It is accessed from ?action=admin;area=logs;sa=errorlog.
* It is accessed from ?action=admin;area=logs;sa=badbehaviorlog.
*
* @uses the BadBehavior template and badbehavior_log sub template.
*/
Expand Down
29 changes: 16 additions & 13 deletions sources/admin/ManageBans.php
Expand Up @@ -38,21 +38,24 @@ public function action_index()
require_once(SUBSDIR . '/Bans.subs.php');

$subActions = array(
'add' => 'action_edit',
'browse' => 'action_browse',
'edittrigger' => 'action_edittrigger',
'edit' => 'action_edit',
'list' => 'action_list',
'log' => 'action_log',
'add' => array($this, 'action_edit'),
'browse' => array($this, 'action_browse'),
'edittrigger' => array($this, 'action_edittrigger'),
'edit' => array($this, 'action_edit'),
'list' => array($this, 'action_list'),
'log' => array($this, 'action_log'),
);

$action = new Action();
$action->initialize($subActions);

call_integration_hook('integrate_manage_bans', array(&$subActions));

// Default the sub-action to 'view ban list'.
$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'list';
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'list';

$context['page_title'] = $txt['ban_title'];
$context['sub_action'] = $_REQUEST['sa'];
$context['sub_action'] = $subAction;

// Tabs for browsing the different ban functions.
$context[$context['admin_menu_name']]['tab_data'] = array(
Expand All @@ -63,29 +66,29 @@ public function action_index()
'list' => array(
'description' => $txt['ban_description'],
'href' => $scripturl . '?action=admin;area=ban;sa=list',
'is_selected' => $_REQUEST['sa'] == 'list' || $_REQUEST['sa'] == 'edit' || $_REQUEST['sa'] == 'edittrigger',
'is_selected' => $subAction == 'list' || $subAction == 'edit' || $subAction == 'edittrigger',
),
'add' => array(
'description' => $txt['ban_description'],
'href' => $scripturl . '?action=admin;area=ban;sa=add',
'is_selected' => $_REQUEST['sa'] == 'add',
'is_selected' => $subAction == 'add',
),
'browse' => array(
'description' => $txt['ban_trigger_browse_description'],
'href' => $scripturl . '?action=admin;area=ban;sa=browse',
'is_selected' => $_REQUEST['sa'] == 'browse',
'is_selected' => $subAction == 'browse',
),
'log' => array(
'description' => $txt['ban_log_description'],
'href' => $scripturl . '?action=admin;area=ban;sa=log',
'is_selected' => $_REQUEST['sa'] == 'log',
'is_selected' => $subAction == 'log',
'is_last' => true,
),
),
);

// Call the right function for this sub-action.
$this->{$subActions[$_REQUEST['sa']]}();
$action->dispatch($subAction);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sources/admin/ManageCalendar.php
Expand Up @@ -58,7 +58,7 @@ public function action_index()

call_integration_hook('integrate_manage_calendar', array(&$subActions));

$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'holidays';
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'holidays';

// Set up the two tabs here...
$context[$context['admin_menu_name']]['tab_data'] = array(
Expand All @@ -77,7 +77,7 @@ public function action_index()

$action = new Action();
$action->initialize($subActions);
$action->dispatch($_REQUEST['sa']);
$action->dispatch($subAction);
}

/**
Expand Down
13 changes: 12 additions & 1 deletion sources/admin/ManageCoreFeatures.php
Expand Up @@ -29,6 +29,17 @@
*/
class ManageCoreFeatures_Controller extends Action_Controller
{
/**
* Default handler.
*
* @see Action_Controller::action_index()
*/
public function action_index()
{
// just delegate to our preferred default
$this->action_features();
}

/**
* This is an overall control panel enabling/disabling lots of the forums key features.
*
Expand All @@ -41,7 +52,7 @@ class ManageCoreFeatures_Controller extends Action_Controller
* save_callback - Function called on save, takes state as parameter.
*
*/
public function action_index()
public function action_features()
{
global $txt, $scripturl, $context, $settings, $modSettings;

Expand Down
38 changes: 22 additions & 16 deletions sources/admin/ManageErrors.php
Expand Up @@ -28,38 +28,44 @@ class ManageErrors_Controller extends Action_Controller
{
/**
* Calls the right handler.
* Requires admin_forum permission.
*
* @see Action_Controller::action_index()
*/
public function action_index()
{
// view error log
$this->action_log();
// Check for the administrative permission to do this.
isAllowedTo('admin_forum');

// The error log. View the list or view a file?
if (isset($_REQUEST['activity']))
$activity = $_REQUEST['activity'];

// Some code redundancy... and we only take this!
if (isset($activity) && $activity == 'file')
// view the file with the error
$this->action_viewfile();
else
// view error log
$this->action_log();
}

/**
* View the forum's error log.
* This function sets all the context up to show the error log for maintenance.
* It requires the maintain_forum permission.
* This method sets all the context up to show the error log for maintenance.
* It requires the admin_forum permission.
* It is accessed from ?action=admin;area=logs;sa=errorlog.
*
* @uses the Errors template and error_log sub template.
*/
public function action_log()
protected function action_log()
{
global $scripturl, $txt, $context, $modSettings, $user_profile, $filter;

$db = database();

require_once(SUBSDIR . '/Error.subs.php');

// Viewing contents of a file?
if (isset($_GET['file']))
return $this->action_viewfile();

// Check for the administrative permission to do this.
isAllowedTo('admin_forum');

// Templates, etc...
loadLanguage('ManageMaintenance');
loadTemplate('Errors');
Expand Down Expand Up @@ -214,16 +220,16 @@ public function action_log()
* Preconditions:
* - file must be readable,
* - full file path must be base64 encoded,
* - user must have admin_forum permission.
* The line number number is specified by $_REQUEST['line']...
* The function will try to get the 20 lines before and after the specified line.
*/
public function action_viewfile()
protected function action_viewfile()
{
global $context;

// Check for the administrative permission to do this.
isAllowedTo('admin_forum');
// We can't help you if you don't spell it out loud :P
if (!isset($_REQUEST['file']))
redirectexit();

// Decode the file and get the line
$filename = base64_decode($_REQUEST['file']);
Expand Down
29 changes: 9 additions & 20 deletions sources/admin/ManageFeatures.php
Expand Up @@ -72,49 +72,38 @@ public function action_index()
$subActions = array(
'basic' => array(
'controller' => $this,
'function' => 'action_basicSettings_display',
'default' => true),
'function' => 'action_basicSettings_display'),
'layout' => array(
'controller' => $this,
'function' => 'action_layoutSettings_display'),
'karma' => array(
'controller' => $this,
'function' => 'action_karmaSettings_display'),
'function' => 'action_karmaSettings_display',
'enabled' => in_array('k', $context['admin_features'])),
'likes' => array(
'controller' => $this,
'function' => 'action_likesSettings_display'),
'function' => 'action_likesSettings_display',
'enabled' => in_array('l', $context['admin_features'])),
'sig' => array(
'controller' => $this,
'function' => 'action_signatureSettings_display'),
'profile' => array(
'controller' => $this,
'function' => 'action_profile'),
'function' => 'action_profile',
'enabled' => in_array('cp', $context['admin_features'])),
'profileedit' => array(
'controller' => $this,
'function' => 'action_profileedit'),
);

call_integration_hook('integrate_modify_features', array(&$subActions));

// If Advanced Profile Fields are disabled don't show the setting page
if (!in_array('cp', $context['admin_features']))
unset($subActions['profile']);

// Same for Karma
if (!in_array('k', $context['admin_features']))
unset($subActions['karma']);

// And likes
if (!in_array('l', $context['admin_features']))
unset($subActions['likes']);

// By default do the basic settings.
$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'basic';
$subAction = $_REQUEST['sa'];
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'basic';

// Set up action/subaction stuff.
$action = new Action();
$action->initialize($subActions);
$action->initialize($subActions, 'basic');

loadLanguage('Help');
loadLanguage('ManageSettings');
Expand Down
8 changes: 4 additions & 4 deletions sources/admin/ManageLanguages.php
Expand Up @@ -62,8 +62,8 @@ public function action_index()
call_integration_hook('integrate_manage_languages', array(&$subActions));

// By default we're managing languages.
$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'edit';
$context['sub_action'] = $_REQUEST['sa'];
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'edit';
$context['sub_action'] = $subAction;

// Load up all the tabs...
$context[$context['admin_menu_name']]['tab_data'] = array(
Expand All @@ -73,8 +73,8 @@ public function action_index()

// Call the right function for this sub-action.
$action = new Action();
$action->initialize($subActions);
$action->dispatch($_REQUEST['sa']);
$action->initialize($subActions, 'edit');
$action->dispatch($subAction);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions sources/admin/ManageMail.php
Expand Up @@ -61,8 +61,8 @@ public function action_index()
call_integration_hook('integrate_manage_mail', array(&$subActions));

// By default we want to browse
$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'browse';
$context['sub_action'] = $_REQUEST['sa'];
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'browse';
$context['sub_action'] = $subAction;

// Load up all the tabs...
$context[$context['admin_menu_name']]['tab_data'] = array(
Expand All @@ -73,8 +73,8 @@ public function action_index()

// Call the right function for this sub-action.
$action = new Action();
$action->initialize($subActions);
$action->dispatch($_REQUEST['sa']);
$action->initialize($subActions, 'browse');
$action->dispatch($subAction);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion sources/admin/ManageMaillist.php
Expand Up @@ -58,7 +58,7 @@ public function action_index()

// Set up the action class
$action = new Action();
$action->initialize($subActions);
$action->initialize($subActions, 'emaillist');

// Default to sub action 'emaillist' if none was given
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) && (empty($subActions[$_REQUEST['sa']][1]) || allowedTo($subActions[$_REQUEST['sa']][1])) ? $_REQUEST['sa'] : 'emaillist';
Expand Down
6 changes: 3 additions & 3 deletions sources/admin/ManageMembers.php
Expand Up @@ -66,14 +66,14 @@ public function action_index()

call_integration_hook('integrate_manage_members', array(&$subActions));

// Default to sub action 'index' or 'settings' depending on permissions.
// Default to sub action 'all'.
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'all';

$action = new Action();
$action->initialize($subActions);
$action->initialize($subActions, 'all');

// You can't pass!
$action->isAllowedTo($subAction); // this isn't the simplest way, but lets accept it
$action->isAllowedTo($subAction);

// Load the essentials.
loadLanguage('ManageMembers');
Expand Down
4 changes: 2 additions & 2 deletions sources/admin/ManageRegistration.php
Expand Up @@ -72,11 +72,11 @@ public function action_index()
call_integration_hook('integrate_manage_registrations', array(&$subActions));

// Work out which to call...
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('moderate_forum') ? 'register' : 'settings');
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'register';

// Set up action/subaction stuff.
$action = new Action();
$action->initialize($subActions);
$action->initialize($subActions, 'register');

// You way will end here if you don't have permission.
$action->isAllowedTo($subAction);
Expand Down
2 changes: 1 addition & 1 deletion sources/admin/ManageScheduledTasks.php
Expand Up @@ -58,7 +58,7 @@ public function action_index()

// Set up action/subaction stuff.
$action = new Action();
$action->initialize($subActions);
$action->initialize($subActions, 'tasks');

// Now for the lovely tabs. That we all love.
$context[$context['admin_menu_name']]['tab_data'] = array(
Expand Down

0 comments on commit 26203d9

Please sign in to comment.