Forum
in package
The root Forum class. Used when browsing the forum normally.
This, as you have probably guessed, is the crux on which SMF functions.
The most interesting part of this file for modification authors is the action array. It is formatted as so:
'action-in-url' => array('Source-File.php', 'FunctionToCall'),
Then, you can access the FunctionToCall() function from Source-File.php with the URL index.php?action=action-in-url. Relatively simple, no?
MOD AUTHORS:
To add a new action, do the following:
- Create a class that implements SMF\ActionInterface and uses SMF\ActionTrait. Put your code in its execute() method.
- Either use the integrate_actions hook or call SMF\Forum:::addAction() from the integrate_pre_load hook to add information about your action to SMF\Forum::$actions.
Deprecations:
-
integrate_pre_log_stats (modifying SMF\Forum::$unlogged_actions) Implement SMF\ActionInterface::canBeLogged() to manage logging at the action level.
-
integrate_guest_actions (modifying SMF\Forum::$guest_access_actions) Implement SMF\ActionInterface::isRestrictedGuestAccessAllowed() for guest access control.
Table of Contents
Properties
- $actions : array<string|int, mixed>
- $guest_access_actions : array<string|int, mixed>
- $unlogged_actions : array<string|int, mixed>
- $current_action : ActionInterface|null
Methods
- __construct() : mixed
- Constructor
- addAction() : void
- Adds a new action to the $actions array.
- execute() : void
- Executes the main forum action.
- getCurrentAction() : ActionInterface|null
- Get the current action.
- removeAction() : void
- Removes an action from the $actions array.
- findAction() : string|callable|false
- Resolves the appropriate action to execute based on the current request context.
- init() : void
- The main forum loader.
- inMaintenance() : void
- Display a message about the forum being in maintenance mode.
- preflight() : void
- Runs various checks that are required before calling the action.
- requireAgreement() : void
- If necessary, redirect to the agreement or privacy policy so that we can force the user to accept the current version.
Properties
$actions
public
static array<string|int, mixed>
$actions
= [
'agreement' => ['', \SMF\Actions\Agreement::class],
'acceptagreement' => ['', \SMF\Actions\AgreementAccept::class],
'activate' => ['', \SMF\Actions\Activate::class],
'admin' => ['', \SMF\Actions\Admin\ACP::class],
'announce' => ['', \SMF\Actions\Announce::class],
'attachapprove' => ['', \SMF\Actions\AttachmentApprove::class],
'boardindex' => ['', \SMF\Actions\BoardIndex::class],
'buddy' => ['', \SMF\Actions\BuddyListToggle::class],
'calendar' => ['', \SMF\Actions\Calendar::class],
// Deprecated; is now a sub-action
'clock' => ['', \SMF\Actions\Calendar::class],
'coppa' => ['', \SMF\Actions\CoppaForm::class],
'credits' => ['', \SMF\Actions\Credits::class],
'deletemsg' => ['', \SMF\Actions\MsgDelete::class],
'display' => ['', \SMF\Actions\Display::class],
'dlattach' => ['', \SMF\Actions\AttachmentDownload::class],
'editpoll' => ['', \SMF\Actions\PollEdit::class],
'editpoll2' => ['', \SMF\Actions\PollEdit2::class],
'groups' => ['', \SMF\Actions\Groups::class],
'help' => ['', \SMF\Actions\Help::class],
'helpadmin' => ['', \SMF\Actions\HelpAdmin::class],
'jsmodify' => ['', \SMF\Actions\JavaScriptModify::class],
'jsoption' => ['', \SMF\Actions\ThemeSetOption::class],
'likes' => ['', \SMF\Actions\Like::class],
'lock' => ['', \SMF\Actions\TopicLock::class],
'lockvoting' => ['', \SMF\Actions\PollLock::class],
'login' => ['', \SMF\Actions\Login::class],
'login2' => ['', \SMF\Actions\Login2::class],
'logintfa' => ['', \SMF\Actions\LoginTFA::class],
'logout' => ['', \SMF\Actions\Logout::class],
'markasread' => ['', \SMF\Actions\MarkRead::class],
'mergetopics' => ['', \SMF\Actions\TopicMerge::class],
'messageindex' => ['', \SMF\Actions\MessageIndex::class],
'mlist' => ['', \SMF\Actions\Memberlist::class],
'moderate' => ['', \SMF\Actions\Moderation\Main::class],
// Deprecated; is now a sub-action
'modifycat' => ['', \SMF\Actions\Admin\Boards::class],
'movetopic' => ['', \SMF\Actions\TopicMove::class],
'movetopic2' => ['', \SMF\Actions\TopicMove2::class],
'notifyannouncements' => ['', \SMF\Actions\NotifyAnnouncements::class],
'notifyboard' => ['', \SMF\Actions\NotifyBoard::class],
'notifytopic' => ['', \SMF\Actions\NotifyTopic::class],
'pm' => ['', \SMF\Actions\PersonalMessage::class],
'post' => ['', \SMF\Actions\Post::class],
'post2' => ['', \SMF\Actions\Post2::class],
'printpage' => ['', \SMF\Actions\TopicPrint::class],
'profile' => ['', \SMF\Actions\Profile\Main::class],
'quotefast' => ['', \SMF\Actions\QuoteFast::class],
'quickmod' => ['', \SMF\Actions\QuickModeration::class],
'quickmod2' => ['', \SMF\Actions\QuickModerationInTopic::class],
'recent' => ['', \SMF\Actions\Recent::class],
'reminder' => ['', \SMF\Actions\Reminder::class],
'removepoll' => ['', \SMF\Actions\PollRemove::class],
'removetopic2' => ['', \SMF\Actions\TopicRemove::class],
'reporttm' => ['', \SMF\Actions\ReportToMod::class],
'requestmembers' => ['', \SMF\Actions\RequestMembers::class],
'restoretopic' => ['', \SMF\Actions\TopicRestore::class],
'search' => ['', \SMF\Actions\Search::class],
'search2' => ['', \SMF\Actions\Search2::class],
'sendactivation' => ['', \SMF\Actions\SendActivation::class],
'signup' => ['', \SMF\Actions\Register::class],
'signup2' => ['', \SMF\Actions\Register2::class],
'smstats' => ['', \SMF\Actions\SmStats::class],
'suggest' => ['', \SMF\Actions\AutoSuggest::class],
'splittopics' => ['', \SMF\Actions\TopicSplit::class],
'stats' => ['', \SMF\Actions\Stats::class],
'sticky' => ['', \SMF\Actions\TopicSticky::class],
// Deprecated; will be redirected to the correct location.
'theme' => ['', \SMF\Actions\Admin\Themes::class],
'themechooser' => ['', \SMF\Actions\ThemeChooser::class],
'trackip' => ['', \SMF\Actions\TrackIP::class],
'about:unknown' => ['', \SMF\Actions\Unknown::class],
'unread' => ['', \SMF\Actions\Unread::class],
'unreadreplies' => ['', \SMF\Actions\UnreadReplies::class],
'uploadAttach' => ['', \SMF\Actions\AttachmentUpload::class],
'verificationcode' => ['', \SMF\Actions\VerificationCode::class],
'viewprofile' => ['', \SMF\Actions\Profile\Main::class],
'vote' => ['', \SMF\Actions\PollVote::class],
'viewquery' => ['', \SMF\Actions\ViewQuery::class],
'viewsmfile' => ['', \SMF\Actions\DisplayAdminFile::class],
'who' => ['', \SMF\Actions\Who::class],
'.xml' => ['', \SMF\Actions\Feed::class],
'xmlhttp' => ['', \SMF\Actions\XmlHttp::class],
]
This array defines what file to load and what to call for each possible value of $_REQUEST['action'].
Keys are action names as found in $_REQUEST['action'].
Values are arrays containing two elements:
- The relative path of a file to load. When calling an autoloading class, the file can be left empty.
- A callable or a class that implements SMF\ActionInterface.
Mod authors can add new actions to this via the integrate_actions hook.
$guest_access_actions
public
static array<string|int, mixed>
$guest_access_actions
= []
Actions that guests are always allowed to do. This allows users to log in when guest access is disabled.
$unlogged_actions
public
static array<string|int, mixed>
$unlogged_actions
= ['calendar' => ['sa' => ['clock']], 'clock' => true, 'modifycat' => true]
This array defines actions, sub-actions, and/or areas where user activity should not be logged. For example, if the user downloads an attachment via the dlattach action, that's not something we want to log.
Array keys are actions. Array values are either:
-
true, which means the action as a whole should not be logged.
-
a multidimensional array indicating specific sub-actions or areas that should not be logged.
For example, 'pm' => array('sa' => array('popup')) means that we won't log visits to index.php?action=pm;sa=popup, but other sub-actions like index.php?action=pm;sa=send will be logged.
$current_action
protected
static ActionInterface|null
$current_action
= null
Stores the current action.
Methods
__construct()
Constructor
public
__construct() : mixed
Initializes the forum by setting up database connections, loading settings, and handling maintenance mode.
addAction()
Adds a new action to the $actions array.
public
static addAction(string $action, string $file, string|callable $handler) : void
This method allows you to add a new action to the forum's action array, which maps URL actions to their corresponding handlers.
Parameters
- $action : string
-
The action name as it appears in the URL (e.g., 'newaction').
- $file : string
-
The file that contains the action's handler class. If using an autoloading class, this can be an empty string.
- $handler : string|callable
-
The class name that implements ActionInterface or a callable handler.
execute()
Executes the main forum action.
public
execute() : void
This method serves as the main dispatcher for determining the appropriate action in various scenarios, ensuring proper handling of the following cases:
-
Maintenance Mode: If the forum is in maintenance mode, only login and logout actions are allowed for non-administrators. All other actions are redirected to a maintenance page.
-
Guest Access Restrictions: If guest access is disabled, guests are redirected to the login page unless the requested action explicitly allows guest access.
-
Default Actions: When no specific action is requested, a default or fallback action is determined:
- If both the board and topic are empty, the default action (e.g., BoardIndex) is executed.
- If only the topic is empty, the MessageIndex action is executed.
- Otherwise, the Display action is executed.
-
Custom Actions: Resolves user-requested actions using the defined
$actions
array or fallback logic, including support for theme-level catch actions or configured fallback actions.
getCurrentAction()
Get the current action.
public
static getCurrentAction() : ActionInterface|null
Return values
ActionInterface|null —The current action or null if not set.
removeAction()
Removes an action from the $actions array.
public
static removeAction(string $action) : void
This method allows you to remove an action from the forum's action array, effectively disabling that action.
Parameters
- $action : string
-
The action name to remove (e.g., 'oldaction').
findAction()
Resolves the appropriate action to execute based on the current request context.
protected
findAction(string|null $action) : string|callable|false
Parameters
- $action : string|null
Return values
string|callable|false —Returns one of the following:
- A string representing a class implementing ActionInterface.
- A callable string representing a static method (e.g.,
'Class::method'
).
init()
The main forum loader.
protected
init() : void
This method initializes various components and settings required for the forum to operate, such as security headers, user permissions, and theme loading.
inMaintenance()
Display a message about the forum being in maintenance mode.
protected
static inMaintenance() : void
- Display a login screen with sub template 'maintenance'.
- Sends a 503 header, so search engines don't bother indexing while we're in maintenance mode.
preflight()
Runs various checks that are required before calling the action.
protected
preflight() : void
requireAgreement()
If necessary, redirect to the agreement or privacy policy so that we can force the user to accept the current version.
protected
requireAgreement() : void