Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves code for handling redirects and unexpected request URLs out of Theme and into more appropriate locations #8427

Merged
Merged
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
6 changes: 3 additions & 3 deletions Sources/Actions/Activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public function isRestrictedGuestAccessAllowed(): bool
*/
public function execute(): void
{
Lang::load('Login');
Theme::loadTemplate('Login');

if (!isset($this->member)) {
if (empty($_REQUEST['u']) && empty($_POST['user'])) {
$this->showResendRequest();
Expand Down Expand Up @@ -239,9 +242,6 @@ protected function __construct()
Utils::redirectexit('action=profile');
}

Lang::load('Login');
Theme::loadTemplate('Login');

// We can't activate anyone without knowing whom to activate.
if (empty($_REQUEST['u']) && empty($_POST['user'])) {
return;
Expand Down
18 changes: 4 additions & 14 deletions Sources/Actions/Admin/ACP.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use SMF\Lang;
use SMF\Mail;
use SMF\Menu;
use SMF\OutputTypeInterface;
use SMF\OutputTypes;
use SMF\Parser;
use SMF\Routable;
use SMF\SecurityToken;
Expand Down Expand Up @@ -726,16 +724,6 @@ class ACP implements ActionInterface, Routable
* Public methods
****************/

public function isSimpleAction(): bool
{
return isset($_REQUEST['preview']);
}

public function getOutputType(): OutputTypeInterface
{
return isset($_REQUEST['preview']) ? new OutputTypes\Xml() : new OutputTypes\Html();
}

/**
* The main admin handling function.
*
Expand All @@ -745,6 +733,8 @@ public function getOutputType(): OutputTypeInterface
*/
public function execute(): void
{
$this->init();

// Make sure the administrator has a valid session...
User::$me->validateSession();

Expand Down Expand Up @@ -1863,9 +1853,9 @@ public static function adminLogin(string $type = 'admin'): void
******************/

/**
* Constructor. Protected to force instantiation via self::load().
* Does some initial setup.
*/
protected function __construct()
protected function init()
{
// Load the language and templates....
Lang::load('Admin');
Expand Down
6 changes: 4 additions & 2 deletions Sources/Actions/Admin/Attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class Attachments implements ActionInterface
*/
public function execute(): void
{
$this->init();

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

if (!empty($call)) {
Expand Down Expand Up @@ -2568,9 +2570,9 @@ public static function attachDirStatus(string $dir, int $expected_files): array
******************/

/**
* Constructor. Protected to force instantiation via self::load().
* Does some initial setup.
*/
protected function __construct()
protected function init()
{
// You have to be able to moderate the forum to do this.
User::$me->isAllowedTo('manage_attachments');
Expand Down
6 changes: 4 additions & 2 deletions Sources/Actions/Admin/Bans.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class Bans implements ActionInterface
*/
public function execute(): void
{
$this->init();

User::$me->isAllowedTo('manage_bans');

$call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]);
Expand Down Expand Up @@ -1468,9 +1470,9 @@ public static function list_getNumBanLogEntries(): int
******************/

/**
* Constructor. Protected to force instantiation via self::load().
* Does some initial setup.
*/
protected function __construct()
protected function init()
{
Theme::loadTemplate('ManageBans');

Expand Down
48 changes: 24 additions & 24 deletions Sources/Actions/Admin/Boards.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ class Boards implements ActionInterface
*/
public function execute(): void
{
// Special handling for modifycat.
if (($_REQUEST['action'] ?? '') === 'modifycat') {
self::modifyCat();
}

// Everything's gonna need this.
Lang::load('ManageBoards');

// Create the tabs for the template.
Menu::$loaded['admin']->tab_data = [
'title' => Lang::$txt['boards_and_cats'],
'help' => 'manage_boards',
'description' => Lang::$txt['boards_and_cats_desc'],
'tabs' => [
'main' => [
],
'newcat' => [
],
'settings' => [
'description' => Lang::$txt['mboards_settings_desc'],
],
],
];

// Have you got the proper permissions?
User::$me->isAllowedTo(self::$subactions[$this->subaction][1]);

Expand Down Expand Up @@ -930,30 +954,6 @@ public static function getConfigVars(): array
*/
protected function __construct()
{
// Special handling for modifycat.
if (($_REQUEST['action'] ?? '') === 'modifycat') {
self::modifyCat();
}

// Everything's gonna need this.
Lang::load('ManageBoards');

// Create the tabs for the template.
Menu::$loaded['admin']->tab_data = [
'title' => Lang::$txt['boards_and_cats'],
'help' => 'manage_boards',
'description' => Lang::$txt['boards_and_cats_desc'],
'tabs' => [
'main' => [
],
'newcat' => [
],
'settings' => [
'description' => Lang::$txt['mboards_settings_desc'],
],
],
];

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

// Default to sub action 'main' or 'settings' depending on permissions.
Expand Down
50 changes: 25 additions & 25 deletions Sources/Actions/Admin/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ class Calendar implements ActionInterface
*/
public function execute(): void
{
// Everything's gonna need this.
Lang::load('Calendar+ManageCalendar');

// Set up the two tabs here...
Menu::$loaded['admin']->tab_data = [
'title' => Lang::$txt['manage_calendar'],
'help' => 'calendar',
'description' => Lang::$txt['calendar_settings_desc'],
];

if (!empty(Config::$modSettings['cal_enabled'])) {
Menu::$loaded['admin']->tab_data['tabs'] = [
'holidays' => [
'description' => Lang::$txt['manage_holidays_desc'],
],
'import' => [
'description' => Lang::$txt['calendar_import_desc'],
],
'settings' => [
'description' => Lang::$txt['calendar_settings_desc'],
],
];
}

User::$me->isAllowedTo('admin_forum');

$call = method_exists($this, self::$subactions[$this->subaction]) ? [$this, self::$subactions[$this->subaction]] : Utils::getCallable(self::$subactions[$this->subaction]);
Expand Down Expand Up @@ -634,35 +658,11 @@ public static function getConfigVars(): array
*/
protected function __construct()
{
// Everything's gonna need this.
Lang::load('Calendar+ManageCalendar');

if (empty(Config::$modSettings['cal_enabled'])) {
unset(self::$subactions['holidays'], self::$subactions['editholiday']);
unset(self::$subactions['holidays'], self::$subactions['editholiday'], self::$subactions['import']);
$this->subaction = 'settings';
}

// Set up the two tabs here...
Menu::$loaded['admin']->tab_data = [
'title' => Lang::$txt['manage_calendar'],
'help' => 'calendar',
'description' => Lang::$txt['calendar_settings_desc'],
];

if (!empty(Config::$modSettings['cal_enabled'])) {
Menu::$loaded['admin']->tab_data['tabs'] = [
'holidays' => [
'description' => Lang::$txt['manage_holidays_desc'],
],
'import' => [
'description' => Lang::$txt['calendar_import_desc'],
],
'settings' => [
'description' => Lang::$txt['calendar_settings_desc'],
],
];
}

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

if (!empty($_REQUEST['sa']) && isset(self::$subactions[$_REQUEST['sa']])) {
Expand Down
22 changes: 8 additions & 14 deletions Sources/Actions/Admin/ErrorLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class ErrorLog implements ActionInterface
*/
public function execute(): void
{
// Templates, etc...
Lang::load('ManageMaintenance');
Theme::loadTemplate('Errors');

foreach ($this->filters as &$filter) {
$filter['txt'] = Lang::$txt[$filter['txt']];
}

// Check for the administrative permission to do this.
User::$me->isAllowedTo('admin_forum');

Expand Down Expand Up @@ -488,20 +496,6 @@ public function viewBacktrace(): void
* Internal methods
******************/

/**
* Constructor. Protected to force instantiation via self::load().
*/
protected function __construct()
{
// Templates, etc...
Lang::load('ManageMaintenance');
Theme::loadTemplate('Errors');

foreach ($this->filters as &$filter) {
$filter['txt'] = Lang::$txt[$filter['txt']];
}
}

/**
* Delete all or some of the errors in the error log.
*
Expand Down
20 changes: 14 additions & 6 deletions Sources/Actions/Admin/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class Features implements ActionInterface
*/
public function execute(): void
{
$this->init();

// You need to be an admin to edit settings!
User::$me->isAllowedTo('admin_forum');

Expand Down Expand Up @@ -1882,6 +1884,18 @@ public static function list_getProfileFieldSize(): int
* Constructor. Protected to force instantiation via self::load().
*/
protected function __construct()
{
IntegrationHook::call('integrate_modify_features', [&self::$subactions]);

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

/**
* Does some initial setup.
*/
protected function init()
{
Lang::load('Help');
Lang::load('ManageSettings');
Expand Down Expand Up @@ -1917,12 +1931,6 @@ protected function __construct()
],
],
];

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

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

/**
Expand Down
24 changes: 12 additions & 12 deletions Sources/Actions/Admin/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ class Languages implements ActionInterface
*/
public function execute(): void
{
Theme::loadTemplate('ManageLanguages');
Lang::load('ManageSettings');

Utils::$context['page_title'] = Lang::$txt['edit_languages'];
Utils::$context['sub_template'] = 'show_settings';

// Load up all the tabs...
Menu::$loaded['admin']->tab_data = [
'title' => Lang::$txt['language_configuration'],
'description' => Lang::$txt['language_description'],
];

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

if (!empty($call)) {
Expand Down Expand Up @@ -1614,18 +1626,6 @@ public static function list_getLanguages(): array
*/
protected function __construct()
{
Theme::loadTemplate('ManageLanguages');
Lang::load('ManageSettings');

Utils::$context['page_title'] = Lang::$txt['edit_languages'];
Utils::$context['sub_template'] = 'show_settings';

// Load up all the tabs...
Menu::$loaded['admin']->tab_data = [
'title' => Lang::$txt['language_configuration'],
'description' => Lang::$txt['language_description'],
];

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

// By default we're managing languages.
Expand Down
Loading