Skip to content

Commit 10e6949

Browse files
committed
Start work on a dedicated sub-action interface
Signed-off-by: John Rayes <live627@gmail.com>
1 parent 585b3dc commit 10e6949

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+931
-2177
lines changed

Sources/Actions/ActionInterface.php

Whitespace-only changes.

Sources/Actions/Activate.php

+3-25
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,6 @@ class Activate implements ActionInterface
3636
{
3737
use ActionTrait;
3838

39-
/*******************
40-
* Public properties
41-
*******************/
42-
43-
/**
44-
* @var string
45-
*
46-
* The sub-action to call.
47-
*/
48-
public string $subaction = '';
49-
50-
/**************************
51-
* Public static properties
52-
**************************/
53-
54-
/**
55-
* @var array
56-
*
57-
* Available sub-actions.
58-
*/
59-
public static array $subactions = [
60-
'activate' => 'activate',
61-
'resend' => 'resend',
62-
];
63-
6439
/****************
6540
* Public methods
6641
****************/
@@ -72,6 +47,9 @@ class Activate implements ActionInterface
7247
*/
7348
public function execute(): void
7449
{
50+
$this->addSubAction('activate', [$this, 'activate']);
51+
$this->addSubAction('resend', [$this, 'resend']);
52+
7553
if (empty($_REQUEST['u']) && empty($_POST['user'])) {
7654
if (empty(Config::$modSettings['registration_method']) || Config::$modSettings['registration_method'] == '3') {
7755
ErrorHandler::fatalLang('no_access', false);

Sources/Actions/Admin/Attachments.php

+27-56
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
use SMF\ItemList;
3030
use SMF\Lang;
3131
use SMF\Menu;
32+
use SMF\ProvidesSubActionInterface;
33+
use SMF\ProvidesSubActionTrait;
3234
use SMF\Sapi;
3335
use SMF\SecurityToken;
3436
use SMF\Theme;
@@ -41,48 +43,14 @@
4143
/**
4244
* Maintains and manages attachments and avatars.
4345
*/
44-
class Attachments implements ActionInterface
46+
class Attachments implements ActionInterface, ProvidesSubActionInterface
4547
{
4648
use ActionTrait;
49+
use ProvidesSubActionTrait;
4750

4851
use BackwardCompatibility;
4952

50-
/*******************
51-
* Public properties
52-
*******************/
53-
54-
/**
55-
* @var string
56-
*
57-
* The requested sub-action.
58-
* This should be set by the constructor.
59-
*/
60-
public string $subaction = 'browse';
61-
62-
/**************************
63-
* Public static properties
64-
**************************/
65-
66-
/**
67-
* @var array
68-
*
69-
* Available sub-actions.
70-
*/
71-
public static array $subactions = [
72-
'attachments' => 'attachmentSettings',
73-
'avatars' => 'avatarSettings',
74-
'browse' => 'browse',
75-
'maintenance' => 'maintain',
76-
'remove' => 'remove',
77-
'byage' => 'removeByAge',
78-
'bysize' => 'removeBySize',
79-
'removeall' => 'removeAll',
80-
'repair' => 'repair',
81-
'attachpaths' => 'paths',
82-
'transfer' => 'transfer',
83-
];
84-
85-
/****************
53+
/**************
8654
* Public methods
8755
****************/
8856

@@ -91,11 +59,22 @@ class Attachments implements ActionInterface
9159
*/
9260
public function execute(): void
9361
{
94-
$call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]);
95-
96-
if (!empty($call)) {
97-
call_user_func($call);
98-
}
62+
$this->setDefaultSubAction('browse');
63+
$this->addSubAction('attachments', [$this, 'attachmentSettings']);
64+
$this->addSubAction('avatars', [$this, 'avatarSettings']);
65+
$this->addSubAction('browse', [$this, 'browse']);
66+
$this->addSubAction('maintenance', [$this, 'maintain']);
67+
$this->addSubAction('remove', [$this, 'remove']);
68+
$this->addSubAction('byage', [$this, 'removeByAge']);
69+
$this->addSubAction('bysize', [$this, 'removeBySize']);
70+
$this->addSubAction('removeall', [$this, 'removeAll']);
71+
$this->addSubAction('repair', [$this, 'repair']);
72+
$this->addSubAction('attachpaths', [$this, 'paths']);
73+
$this->addSubAction('transfer', [$this, 'transfer']);
74+
75+
IntegrationHook::call('integrate_manage_attachments', [&$this->sub_actions]);
76+
77+
$this->callSubAction($_REQUEST['sa'] ?? null);
9978
}
10079

10180
/**
@@ -2571,9 +2550,9 @@ public static function manageAttachmentSettings(bool $return_config = false): ?a
25712550
return self::attachConfigVars();
25722551
}
25732552

2574-
self::load();
2575-
self::$obj->subaction = 'attachments';
2576-
self::$obj->execute();
2553+
$obj = self::load();
2554+
$obj->setDefaultSubAction('attachments');
2555+
$obj->execute();
25772556

25782557
return null;
25792558
}
@@ -2590,9 +2569,9 @@ public static function manageAvatarSettings(bool $return_config = false): ?array
25902569
return self::avatarConfigVars();
25912570
}
25922571

2593-
self::load();
2594-
self::$obj->subaction = 'avatars';
2595-
self::$obj->execute();
2572+
$obj = self::load();
2573+
$obj->setDefaultSubAction('avatars');
2574+
$obj->execute();
25962575

25972576
return null;
25982577
}
@@ -2619,14 +2598,6 @@ protected function __construct()
26192598
'description' => Lang::$txt['attachments_desc'],
26202599
];
26212600

2622-
IntegrationHook::call('integrate_manage_attachments', [&self::$subactions]);
2623-
2624-
if (!empty($_REQUEST['sa']) && isset(self::$subactions[strtolower($_REQUEST['sa'])])) {
2625-
$this->subaction = strtolower($_REQUEST['sa']);
2626-
}
2627-
2628-
Utils::$context['sub_action'] = &$this->subaction;
2629-
26302601
// Default page title is good.
26312602
Utils::$context['page_title'] = Lang::$txt['attachments_avatars'];
26322603
}

Sources/Actions/Admin/Bans.php

+23-50
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
use SMF\Lang;
3232
use SMF\Logging;
3333
use SMF\Menu;
34+
use SMF\ProvidesSubActionInterface;
35+
use SMF\ProvidesSubActionTrait;
3436
use SMF\SecurityToken;
3537
use SMF\Theme;
3638
use SMF\Time;
@@ -40,43 +42,13 @@
4042
/**
4143
* This class contains all the methods used for the ban center.
4244
*/
43-
class Bans implements ActionInterface
45+
class Bans implements ActionInterface, ProvidesSubActionInterface
4446
{
4547
use ActionTrait;
46-
48+
use ProvidesSubActionTrait;
4749
use BackwardCompatibility;
4850

49-
/*******************
50-
* Public properties
51-
*******************/
52-
53-
/**
54-
* @var string
55-
*
56-
* The requested sub-action.
57-
* This should be set by the constructor.
58-
*/
59-
public string $subaction = 'list';
60-
61-
/**************************
62-
* Public static properties
63-
**************************/
64-
65-
/**
66-
* @var array
67-
*
68-
* Available sub-actions.
69-
*/
70-
public static array $subactions = [
71-
'list' => 'list',
72-
'edit' => 'edit',
73-
'add' => 'edit',
74-
'browse' => 'browseTriggers',
75-
'edittrigger' => 'editTrigger',
76-
'log' => 'log',
77-
];
78-
79-
/****************
51+
/**************
8052
* Public methods
8153
****************/
8254

@@ -85,13 +57,28 @@ class Bans implements ActionInterface
8557
*/
8658
public function execute(): void
8759
{
60+
$this->addSubAction('list', [$this, 'list']);
61+
$this->addSubAction('edit', [$this, 'edit']);
62+
$this->addSubAction('add', [$this, 'edit']);
63+
$this->addSubAction('browse', [$this, 'browseTriggers']);
64+
$this->addSubAction('edittrigger', [$this, 'editTrigger']);
65+
$this->addSubAction('log', [$this, 'log']);
66+
8867
User::$me->isAllowedTo('manage_bans');
8968

90-
$call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]);
69+
IntegrationHook::call('integrate_manage_bans', [&$this->sub_actions]);
70+
71+
$this->findRequestedSubAction($_REQUEST['sa'] ?? null);
9172

92-
if (!empty($call)) {
93-
call_user_func($call);
73+
// Mark the appropriate menu entry as selected
74+
if (array_key_exists($this->sub_action, Menu::$loaded['admin']->tab_data['tabs'])) {
75+
Menu::$loaded['admin']->tab_data['tabs'][$this->sub_action]['is_selected'] = true;
9476
}
77+
78+
Utils::$context['page_title'] = Lang::$txt['ban_title'];
79+
Utils::$context['sub_action'] = $this->sub_action;
80+
81+
$this->callSubAction();
9582
}
9683

9784
/**
@@ -1498,20 +1485,6 @@ protected function __construct()
14981485
],
14991486
];
15001487
}
1501-
1502-
IntegrationHook::call('integrate_manage_bans', [&self::$subactions]);
1503-
1504-
if (!empty($_REQUEST['sa']) && isset(self::$subactions[$_REQUEST['sa']])) {
1505-
$this->subaction = $_REQUEST['sa'];
1506-
}
1507-
1508-
// Mark the appropriate menu entry as selected
1509-
if (array_key_exists($this->subaction, Menu::$loaded['admin']->tab_data['tabs'])) {
1510-
Menu::$loaded['admin']->tab_data['tabs'][$this->subaction]['is_selected'] = true;
1511-
}
1512-
1513-
Utils::$context['page_title'] = Lang::$txt['ban_title'];
1514-
Utils::$context['sub_action'] = $this->subaction;
15151488
}
15161489

15171490
/**

Sources/Actions/Admin/Boards.php

+19-60
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
use SMF\IntegrationHook;
2929
use SMF\Lang;
3030
use SMF\Menu;
31+
use SMF\ProvidesSubActionInterface;
32+
use SMF\ProvidesSubActionTrait;
3133
use SMF\SecurityToken;
3234
use SMF\Theme;
3335
use SMF\Url;
@@ -37,53 +39,12 @@
3739
/**
3840
* Manages and maintains the boards and categories of the forum.
3941
*/
40-
class Boards implements ActionInterface
42+
class Boards implements ActionInterface, ProvidesSubActionInterface
4143
{
4244
use ActionTrait;
43-
45+
use ProvidesSubActionTrait;
4446
use BackwardCompatibility;
4547

46-
/*******************
47-
* Public properties
48-
*******************/
49-
50-
/**
51-
* @var string
52-
*
53-
* The requested sub-action.
54-
* This should be set by the constructor.
55-
*/
56-
public string $subaction = 'main';
57-
58-
/**************************
59-
* Public static properties
60-
**************************/
61-
62-
/**
63-
* @var array
64-
*
65-
* Available sub-actions.
66-
*
67-
* Format: 'sub-action' => array('function', 'permission')
68-
*/
69-
public static array $subactions = [
70-
'main' => ['main', 'manage_boards'],
71-
'board' => ['editBoard', 'manage_boards'],
72-
'board2' => ['editBoard2', 'manage_boards'],
73-
'cat' => ['editCategory', 'manage_boards'],
74-
'cat2' => ['editCategory2', 'manage_boards'],
75-
'move' => ['main', 'manage_boards'],
76-
'newcat' => ['editCategory', 'manage_boards'],
77-
'newboard' => ['editBoard', 'manage_boards'],
78-
'settings' => ['settings', 'admin_forum'],
79-
];
80-
81-
/*********************
82-
* Internal properties
83-
*********************/
84-
85-
// code...
86-
8748
/****************
8849
* Public methods
8950
****************/
@@ -93,14 +54,23 @@ class Boards implements ActionInterface
9354
*/
9455
public function execute(): void
9556
{
96-
// Have you got the proper permissions?
97-
User::$me->isAllowedTo(self::$subactions[$this->subaction][1]);
98-
99-
$call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]);
57+
if (User::$me->allowedTo('manage_boards')) {
58+
$this->addSubActon('main' [$this, 'main']);
59+
$this->addSubActon('board' [$this, 'editBoard']);
60+
$this->addSubActon('board2' [$this, 'editBoard2']);
61+
$this->addSubActon('cat' [$this, 'editCategory']);
62+
$this->addSubActon('cat2' [$this, 'editCategory2']);
63+
$this->addSubActon('move' [$this, 'main']);
64+
$this->addSubActon('newcat' [$this, 'editCategory']);
65+
$this->addSubActon('newboard' [$this, 'editBoard']);
66+
}
10067

101-
if (!empty($call)) {
102-
call_user_func($call);
68+
if (User::$me->allowedTo('admin_forum')) {
69+
$this->addSubActon('settings' [$this, 'settings']);
10370
}
71+
72+
IntegrationHook::call('integrate_manage_boards', [&$this->sub_actions]);
73+
$this->callSubAction($_REQUEST['sa'] ?? null);
10474
}
10575

10676
/**
@@ -944,18 +914,7 @@ protected function __construct()
944914
],
945915
],
946916
];
947-
948-
IntegrationHook::call('integrate_manage_boards', [&self::$subactions]);
949-
950-
// Default to sub action 'main' or 'settings' depending on permissions.
951-
$this->subaction = isset($_REQUEST['sa']) && isset(self::$subactions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (User::$me->allowedTo('manage_boards') ? 'main' : 'settings');
952917
}
953-
954-
/*************************
955-
* Internal static methods
956-
*************************/
957-
958-
// code...
959918
}
960919

961920
?>

0 commit comments

Comments
 (0)