Unofficial SMF API Documentation

./Sources/Load.php

reloadSettings

function reloadSettings(): void

Load the $modSettings array.

Integration hooks
integrate_load_average
integrate_pre_load

loadUserSettings

function loadUserSettings(): void

Load all the important user information.

What it does:

Integration hooks
integrate_verify_user
integrate_force_tfasetup
integrate_verify_tfa
integrate_user_info

loadMinUserInfo

function loadMinUserInfo(int|array $user_ids = array()): array

Load minimal user info from members table.

Intended for use by background tasks that need to populate $user_info.

Type Parameter Description
int|array $user_ids The users IDs to get the data for.
Integration hooks
integrate_load_min_user_settings_columns
integrate_load_min_user_settings

loadBoard

function loadBoard(): void

Check for moderators and see if they have access to the board.

What it does:

Integration hooks
integrate_load_board
integrate_board_info

loadPermissions

function loadPermissions(): void

Load this user’s permissions.

loadMemberData

function loadMemberData(mixed $users, bool $is_name = false, string $set = 'normal'): array

Loads user data, either by id or member_name, and can load one or many users’ data together.

User data is loaded with minimal processing into the global $user_profiles array, keyed by user id.

Type Parameter Description
mixed $users This can be either a single value or an array, representing a single user or multiple users.
bool $is_name If this parameter is true, treat the value(s) in $users as user names, otherwise they are numeric user ids.
string $set Complexity of data to load, from minimal, normal, profile, each successively increasing in complexity.
Integration hooks
integrate_load_member_data

loadMemberContext

function loadMemberContext(int $user, bool $display_custom_fields = false): bool

Processes all the data previously loaded by {@link loadMemberData()} into a form more readily usable for SMF.

The results are stored in the global $memberContext array, keyed by user id.

Type Parameter Description
int $user The ID of a user previously loaded by {@link loadMemberData()}
bool $display_custom_fields Whether or not to display custom profile fields
Integration hooks
integrate_member_context

loadMemberCustomFields

function loadMemberCustomFields(int|array $users, string|array $params): array|bool

Loads the user’s custom profile fields

Type Parameter Description
int|array $users A single user ID or an array of user IDs
string|array $params Either a string or an array of strings with profile field names

detectBrowser

function detectBrowser(): void

Loads information about what browser the user is viewing with and places it in $context

isBrowser

function isBrowser(string $browser): bool

Are we using this browser?

Wrapper function for detectBrowser

Type Parameter Description
string $browser The browser we are checking for.

loadTheme

function loadTheme(int $id_theme = 0, bool $initialize = true): void

Load a theme, by ID.

Type Parameter Description
int $id_theme The ID of the theme to load
bool $initialize Whether or not to initialize a bunch of theme-related variables/settings
Integration hooks
integrate_pre_load_theme
integrate_simple_actions
integrate_load_theme

loadTemplate

function loadTemplate(string|false $template_name, array|string $style_sheets = array(), bool $fatal = true): bool

Load a template - if the theme doesn’t include it, use the default.

What this function does:

Type Parameter Description
string|false $template_name The name of the template to load
array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
bool $fatal If true, dies with an error message if the template cannot be found

loadSubTemplate

function loadSubTemplate(string $sub_template_name, bool|string $fatal = false): void

Load a sub-template.

What it does: - loads the sub template specified by sub_template_name, which must be in an already-loaded template.

Type Parameter Description
string $sub_template_name The name of the sub-template to load
bool|string $fatal Whether to die with an error if the sub-template can’t be loaded

loadCSSFile

function loadCSSFile(string $fileName, array $params = array(), string $id = ''): void

Add a CSS file for output later

Type Parameter Description
string $fileName The name of the file to load
array $params An array of parameters
    Keys are the following:
    - [‘external’] (true/false): define if the file is a externally located file. Needs to be set to true if you are loading an external file
    - [‘default_theme’] (true/false): force use of default theme url
    - [‘force_current’] (true/false): if this is false, we will attempt to load the file from the default theme if not found in the current theme
    - [‘validate’] (true/false): if true script will validate the local file exists
    - [‘rtl’] (string): additional file to load in RTL mode
    - [‘seed’] (true/false/string): if true or null, use cache stale, false do not, or used a supplied string
    - [‘minimize’] boolean to add your file to the main minimized file. Useful when you have a file thats loaded everywhere and for everyone.
    - [‘order_pos’] int define the load order, when not define it’s loaded in the middle, before index.css = -500, after index.css = 500, middle = 3000, end (i.e. after responsive.css) = 10000
    - [‘attributes’] array extra attributes to add to the element
string $id An ID to stick on the end of the filename for caching purposes

addInlineCss

function addInlineCss(string $css): void|bool

Add a block of inline css code to be executed later

Type Parameter Description
string $css Some css code

loadJavaScriptFile

function loadJavaScriptFile(string $fileName, array $params = array(), string $id = ''): void

Add a Javascript file for output later

Type Parameter Description
string $fileName The name of the file to load
array $params An array of parameter info
    Keys are the following:
    - [‘external’] (true/false): define if the file is a externally located file. Needs to be set to true if you are loading an external file
    - [‘default_theme’] (true/false): force use of default theme url
    - [‘defer’] (true/false): define if the file should load in <head> or before the closing <html> tag
    - [‘force_current’] (true/false): if this is false, we will attempt to load the file from the
    default theme if not found in the current theme
    - [‘async’] (true/false): if the script should be loaded asynchronously (HTML5)
    - [‘validate’] (true/false): if true script will validate the local file exists
    - [‘seed’] (true/false/string): if true or null, use cache stale, false do not, or used a supplied string
    - [‘minimize’] boolean to add your file to the main minimized file. Useful when you have a file thats loaded everywhere and for everyone.
    - [‘attributes’] array extra attributes to add to the element
string $id An ID to stick on the end of the filename

addJavaScriptVar

function addJavaScriptVar(string $key, string $value, bool $escape = false): void

Add a Javascript variable for output later (for feeding text strings and similar to JS) Cleaner and easier (for modders) than to use the function below.

Type Parameter Description
string $key The key for this variable
string $value The value
bool $escape Whether or not to escape the value

addInlineJavaScript

function addInlineJavaScript(string $javascript, bool $defer = false): void|bool

Add a block of inline Javascript code to be executed later

Type Parameter Description
string $javascript Some JS code
bool $defer Whether the script should load in <head> or before the closing <html> tag

loadLanguage

function loadLanguage(string $template_name, string $lang = '', bool $fatal = true, bool $force_reload = false): string

Load a language file. Tries the current and default themes as well as the user and global languages.

Type Parameter Description
string $template_name The name of a template file
string $lang A specific language to load this file from
bool $fatal Whether to die with an error if it can’t be loaded
bool $force_reload Whether to load the file again if it’s already loaded

getBoardParents

function getBoardParents(int $id_parent): array

Get all parent boards (requires first parent as parameter) It finds all the parents of id_parent, and that board itself.

Additionally, it detects the moderators of said boards.

Type Parameter Description
int $id_parent The ID of the parent board

getLanguages

function getLanguages(bool $use_cache = true): array

Attempt to reload our known languages.

It will try to choose only utf8 or non-utf8 languages.

Type Parameter Description
bool $use_cache Whether or not to use the cache

censorText

function censorText(string &$text, bool $force = false): string

Replace all vulgar words with respective proper words. (substring or whole words..) What this function does:

Type Parameter Description
string \&$text The text to censor
bool $force Whether to censor the text regardless of settings
Integration hooks
integrate_word_censor

template_include

function template_include(string $filename, bool $once = false): void

Load the template/language file using require - loads the template or language file specified by filename.

Type Parameter Description
string $filename The name of the file to include
bool $once If true only includes the file once (like include_once)

loadDatabase

function loadDatabase(): void

Initialize a database connection.

loadCacheAccelerator

function loadCacheAccelerator(string $overrideCache = '', bool $fallbackSMF = true): object|false

Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.

Type Parameter Description
string $overrideCache Try to use a different cache method other than that defined in $cache_accelerator.
bool $fallbackSMF Use the default SMF method if the accelerator fails.

cache_quick_get

function cache_quick_get(string $key, string $file, string $function, array $params, int $level = 1): string

Try to retrieve a cache entry. On failure, call the appropriate function.

Type Parameter Description
string $key The key for this entry
string $file The file associated with this entry
string $function The function to call
array $params Parameters to be passed to the specified function
int $level The cache level
Integration hooks
pre_cache_quick_get
post_cache_quick_get

cache_put_data

function cache_put_data(string $key, mixed $value, int $ttl = 120): void

Puts value in the cache under key for ttl seconds.

Type Parameter Description
string $key A key for this value
mixed $value The data to cache
int $ttl How long (in seconds) the data should be cached for
Integration hooks
cache_put_data

cache_get_data

function cache_get_data(string $key, int $ttl = 120): ?array

Gets the value from the cache specified by key, so long as it is not older than ttl seconds.

Type Parameter Description
string $key The key for the value to retrieve
int $ttl The maximum age of the cached data
Integration hooks
cache_get_data

clean_cache

function clean_cache(string $type = ''): void

Empty out the cache in use as best it can

It may only remove the files of a certain type (if the $type parameter is given) Type can be user, data or left blank - user clears out user data

Type Parameter Description
string $type The cache type (‘memcached’, ‘zend’ or something else for SMF’s file cache)
Integration hooks
integrate_clean_cache

set_avatar_data

function set_avatar_data(array $data = array()): array

Helper function to set an array of data for an user’s avatar.

Makes assumptions based on the data provided, the following keys are required:

Type Parameter Description
array $data An array of raw info
Integration hooks
integrate_set_avatar_data

get_auth_secret

function get_auth_secret(): string

Gets, and if necessary creates, the authentication secret to use for cookies, tokens, etc.

Note: Never use the $auth_secret variable directly. Always call this function instead.

Suggest an edit to this page on GitHub