Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 11 additions & 36 deletions Sources/Actions/Activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use SMF\Lang;
use SMF\Logging;
use SMF\Mail;
use SMF\ProvidesSubActionInterface;
use SMF\ProvidesSubActionTrait;
use SMF\Routable;
use SMF\Security;
use SMF\Theme;
Expand All @@ -34,35 +36,11 @@
/**
* Activates a user's account.
*/
class Activate implements ActionInterface, Routable
class Activate implements ActionInterface, ProvidesSubActionInterface, Routable
{
use ActionRouter;
use ActionTrait;

/*******************
* Public properties
*******************/

/**
* @var string
*
* The sub-action to call.
*/
public string $subaction = '';

/**************************
* Public static properties
**************************/

/**
* @var array
*
* Available sub-actions.
*/
public static array $subactions = [
'activate' => 'activate',
'resend' => 'resend',
];
use ProvidesSubActionTrait;

/*********************
* Internal properties
Expand Down Expand Up @@ -106,17 +84,15 @@ public function execute(): void
return;
}

if (empty($this->subaction)) {
$this->findRequestedSubAction($_REQUEST['sa'] ?? null);

if (empty($this->sub_action)) {
$this->showResendRequest();

return;
}

$call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call)) {
call_user_func($call);
}
$this->callSubAction($_REQUEST['sa'] ?? null);
}

/**
Expand Down Expand Up @@ -234,6 +210,9 @@ public static function parseRoute(array $route, array $params = []): array
*/
protected function __construct()
{
$this->addSubAction('activate', [$this, 'activate']);
$this->addSubAction('resend', [$this, 'resend']);

// Logged in users should not bother to activate their accounts
if (!empty(User::$me->id)) {
Utils::redirectexit('action=profile');
Expand All @@ -259,10 +238,6 @@ protected function __construct()
if (!empty($_REQUEST['code'])) {
$_REQUEST['sa'] = 'activate';
}

if (!empty($_REQUEST['sa']) && isset(self::$subactions[$_REQUEST['sa']])) {
$this->subaction = $_REQUEST['sa'];
}
}

/**
Expand Down
68 changes: 19 additions & 49 deletions Sources/Actions/Admin/Attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use SMF\ItemList;
use SMF\Lang;
use SMF\Menu;
use SMF\ProvidesSubActionInterface;
use SMF\ProvidesSubActionTrait;
use SMF\Sapi;
use SMF\SecurityToken;
use SMF\Theme;
Expand All @@ -41,47 +43,12 @@
/**
* Maintains and manages attachments and avatars.
*/
class Attachments implements ActionInterface
class Attachments implements ActionInterface, ProvidesSubActionInterface
{
use ActionTrait;

use ProvidesSubActionTrait;
use BackwardCompatibility;

/*******************
* Public properties
*******************/

/**
* @var string
*
* The requested sub-action.
* This should be set by the constructor.
*/
public string $subaction = 'browse';

/**************************
* Public static properties
**************************/

/**
* @var array
*
* Available sub-actions.
*/
public static array $subactions = [
'attachments' => 'attachmentSettings',
'avatars' => 'avatarSettings',
'browse' => 'browse',
'maintenance' => 'maintain',
'remove' => 'remove',
'byage' => 'removeByAge',
'bysize' => 'removeBySize',
'removeall' => 'removeAll',
'repair' => 'repair',
'attachpaths' => 'paths',
'transfer' => 'transfer',
];

/****************
* Public methods
****************/
Expand All @@ -91,11 +58,9 @@ class Attachments implements ActionInterface
*/
public function execute(): void
{
$call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]);
IntegrationHook::call('integrate_manage_attachments', [&$this->sub_actions]);

if (!empty($call)) {
call_user_func($call);
}
$this->callSubAction($_REQUEST['sa'] ?? null);
}

/**
Expand Down Expand Up @@ -2572,6 +2537,19 @@ public static function attachDirStatus(string $dir, int $expected_files): array
*/
protected function __construct()
{
$this->setDefaultSubAction('browse');
$this->addSubAction('attachments', [$this, 'attachmentSettings']);
$this->addSubAction('avatars', [$this, 'avatarSettings']);
$this->addSubAction('browse', [$this, 'browse']);
$this->addSubAction('maintenance', [$this, 'maintain']);
$this->addSubAction('remove', [$this, 'remove']);
$this->addSubAction('byage', [$this, 'removeByAge']);
$this->addSubAction('bysize', [$this, 'removeBySize']);
$this->addSubAction('removeall', [$this, 'removeAll']);
$this->addSubAction('repair', [$this, 'repair']);
$this->addSubAction('attachpaths', [$this, 'paths']);
$this->addSubAction('transfer', [$this, 'transfer']);

// You have to be able to moderate the forum to do this.
User::$me->isAllowedTo('manage_attachments');

Expand All @@ -2585,14 +2563,6 @@ protected function __construct()
'description' => Lang::$txt['attachments_desc'],
];

IntegrationHook::call('integrate_manage_attachments', [&self::$subactions]);

if (!empty($_REQUEST['sa']) && isset(self::$subactions[strtolower($_REQUEST['sa'])])) {
$this->subaction = strtolower($_REQUEST['sa']);
}

Utils::$context['sub_action'] = &$this->subaction;

// Default page title is good.
Utils::$context['page_title'] = Lang::$txt['attachments_avatars'];
}
Expand Down
71 changes: 22 additions & 49 deletions Sources/Actions/Admin/Bans.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use SMF\Lang;
use SMF\Logging;
use SMF\Menu;
use SMF\ProvidesSubActionInterface;
use SMF\ProvidesSubActionTrait;
use SMF\SecurityToken;
use SMF\Theme;
use SMF\Time;
Expand All @@ -40,42 +42,12 @@
/**
* This class contains all the methods used for the ban center.
*/
class Bans implements ActionInterface
class Bans implements ActionInterface, ProvidesSubActionInterface
{
use ActionTrait;

use ProvidesSubActionTrait;
use BackwardCompatibility;

/*******************
* Public properties
*******************/

/**
* @var string
*
* The requested sub-action.
* This should be set by the constructor.
*/
public string $subaction = 'list';

/**************************
* Public static properties
**************************/

/**
* @var array
*
* Available sub-actions.
*/
public static array $subactions = [
'list' => 'list',
'edit' => 'edit',
'add' => 'edit',
'browse' => 'browseTriggers',
'edittrigger' => 'editTrigger',
'log' => 'log',
];

/****************
* Public methods
****************/
Expand All @@ -87,11 +59,19 @@ public function execute(): void
{
User::$me->isAllowedTo('manage_bans');

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

$this->findRequestedSubAction($_REQUEST['sa'] ?? null);

if (!empty($call)) {
call_user_func($call);
// Mark the appropriate menu entry as selected
if (array_key_exists($this->sub_action, Menu::$loaded['admin']->tab_data['tabs'])) {
Menu::$loaded['admin']->tab_data['tabs'][$this->sub_action]['is_selected'] = true;
}

Utils::$context['page_title'] = Lang::$txt['ban_title'];
Utils::$context['sub_action'] = $this->sub_action;

$this->callSubAction();
}

/**
Expand Down Expand Up @@ -1472,6 +1452,13 @@ public static function list_getNumBanLogEntries(): int
*/
protected function __construct()
{
$this->addSubAction('list', [$this, 'list']);
$this->addSubAction('edit', [$this, 'edit']);
$this->addSubAction('add', [$this, 'edit']);
$this->addSubAction('browse', [$this, 'browseTriggers']);
$this->addSubAction('edittrigger', [$this, 'editTrigger']);
$this->addSubAction('log', [$this, 'log']);

Theme::loadTemplate('ManageBans');

// Tab data might already be set if this was called from Logs::execute().
Expand Down Expand Up @@ -1502,20 +1489,6 @@ protected function __construct()
],
];
}

IntegrationHook::call('integrate_manage_bans', [&self::$subactions]);

if (!empty($_REQUEST['sa']) && isset(self::$subactions[$_REQUEST['sa']])) {
$this->subaction = $_REQUEST['sa'];
}

// Mark the appropriate menu entry as selected
if (array_key_exists($this->subaction, Menu::$loaded['admin']->tab_data['tabs'])) {
Menu::$loaded['admin']->tab_data['tabs'][$this->subaction]['is_selected'] = true;
}

Utils::$context['page_title'] = Lang::$txt['ban_title'];
Utils::$context['sub_action'] = $this->subaction;
}

/**
Expand Down
Loading
Loading