Skip to content

Commit 74b3920

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

57 files changed

Lines changed: 692 additions & 1811 deletions

Some content is hidden

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

Sources/Actions/ActionInterface.php

Whitespace-only changes.

Sources/Actions/Activate.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use SMF\Lang;
2525
use SMF\Logging;
2626
use SMF\Mail;
27+
use SMF\ProvidesSubActionInterface;
28+
use SMF\ProvidesSubActionTrait;
2729
use SMF\Security;
2830
use SMF\Theme;
2931
use SMF\User;
@@ -32,9 +34,10 @@
3234
/**
3335
* Activates a user's account.
3436
*/
35-
class Activate implements ActionInterface
37+
class Activate implements ActionInterface, ProvidesSubActionInterface
3638
{
3739
use ActionTrait;
40+
use ProvidesSubActionTrait;
3841

3942
/*******************
4043
* Public properties
@@ -51,16 +54,6 @@ class Activate implements ActionInterface
5154
* Public static properties
5255
**************************/
5356

54-
/**
55-
* @var array
56-
*
57-
* Available sub-actions.
58-
*/
59-
public static array $subactions = [
60-
'activate' => 'activate',
61-
'resend' => 'resend',
62-
];
63-
6457
/****************
6558
* Public methods
6659
****************/
@@ -72,6 +65,9 @@ class Activate implements ActionInterface
7265
*/
7366
public function execute(): void
7467
{
68+
$this->addSubAction('activate', [$this, 'activate']);
69+
$this->addSubAction('resend', [$this, 'resend']);
70+
7571
if (empty($_REQUEST['u']) && empty($_POST['user'])) {
7672
if (empty(Config::$modSettings['registration_method']) || Config::$modSettings['registration_method'] == '3') {
7773
ErrorHandler::fatalLang('no_access', false);

Sources/Actions/Admin/Attachments.php

Lines changed: 23 additions & 52 deletions
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
/**
@@ -2572,7 +2551,7 @@ public static function manageAttachmentSettings(bool $return_config = false): ?a
25722551
}
25732552

25742553
self::load();
2575-
self::$obj->subaction = 'attachments';
2554+
self::$obj->setDefaultSubAction('attachments');
25762555
self::$obj->execute();
25772556

25782557
return null;
@@ -2591,7 +2570,7 @@ public static function manageAvatarSettings(bool $return_config = false): ?array
25912570
}
25922571

25932572
self::load();
2594-
self::$obj->subaction = 'avatars';
2573+
self::$obj->setDefaultSubAction('avatars');
25952574
self::$obj->execute();
25962575

25972576
return null;
@@ -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

Lines changed: 23 additions & 49 deletions
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,14 @@
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;
48+
use ProvidesSubActionTrait;
4649

4750
use BackwardCompatibility;
4851

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-
/****************
52+
/**************
8053
* Public methods
8154
****************/
8255

@@ -85,13 +58,28 @@ class Bans implements ActionInterface
8558
*/
8659
public function execute(): void
8760
{
61+
$this->addSubAction('list', [$this, 'list']);
62+
$this->addSubAction('edit', [$this, 'edit']);
63+
$this->addSubAction('add', [$this, 'edit']);
64+
$this->addSubAction('browse', [$this, 'browseTriggers']);
65+
$this->addSubAction('edittrigger', [$this, 'editTrigger']);
66+
$this->addSubAction('log', [$this, 'log']);
67+
8868
User::$me->isAllowedTo('manage_bans');
8969

90-
$call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]);
70+
IntegrationHook::call('integrate_manage_bans', [&$this->sub_actions]);
9171

92-
if (!empty($call)) {
93-
call_user_func($call);
72+
$this->findRequestedSubAction($_REQUEST['sa'] ?? null);
73+
74+
// Mark the appropriate menu entry as selected
75+
if (array_key_exists($this->subaction, Menu::$loaded['admin']->tab_data['tabs'])) {
76+
Menu::$loaded['admin']->tab_data['tabs'][$this->subaction]['is_selected'] = true;
9477
}
78+
79+
Utils::$context['page_title'] = Lang::$txt['ban_title'];
80+
Utils::$context['sub_action'] = $this->subaction;
81+
82+
$this->callSubAction();
9583
}
9684

9785
/**
@@ -1498,20 +1486,6 @@ protected function __construct()
14981486
],
14991487
];
15001488
}
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;
15151489
}
15161490

15171491
/**

Sources/Actions/Admin/Boards.php

Lines changed: 11 additions & 27 deletions
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,28 +39,13 @@
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;
45+
use ProvidesSubActionTrait;
4346

4447
use BackwardCompatibility;
4548

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-
6249
/**
6350
* @var array
6451
*
@@ -78,12 +65,6 @@ class Boards implements ActionInterface
7865
'settings' => ['settings', 'admin_forum'],
7966
];
8067

81-
/*********************
82-
* Internal properties
83-
*********************/
84-
85-
// code...
86-
8768
/****************
8869
* Public methods
8970
****************/
@@ -93,10 +74,13 @@ class Boards implements ActionInterface
9374
*/
9475
public function execute(): void
9576
{
77+
$this->setDefaultSubAction('main');
78+
79+
9680
// Have you got the proper permissions?
97-
User::$me->isAllowedTo(self::$subactions[$this->subaction][1]);
81+
User::$me->isAllowedTo($this->sub_actions[$this->subaction][1]);
9882

99-
$call = method_exists($this, self::$subactions[$this->subaction][0]) ? [$this, self::$subactions[$this->subaction][0]] : Utils::getCallable(self::$subactions[$this->subaction][0]);
83+
$call = method_exists($this, $this->sub_actions[$this->subaction][0]) ? [$this, $this->sub_actions[$this->subaction][0]] : Utils::getCallable($this->sub_actions[$this->subaction][0]);
10084

10185
if (!empty($call)) {
10286
call_user_func($call);
@@ -945,10 +929,10 @@ protected function __construct()
945929
],
946930
];
947931

948-
IntegrationHook::call('integrate_manage_boards', [&self::$subactions]);
932+
IntegrationHook::call('integrate_manage_boards', [&$this->sub_actions]);
949933

950934
// 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');
935+
$this->subaction = isset($_REQUEST['sa']) && isset($this->sub_actions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (User::$me->allowedTo('manage_boards') ? 'main' : 'settings');
952936
}
953937

954938
/*************************

0 commit comments

Comments
 (0)