Themes
in package
implements
ActionInterface
uses
ActionTrait, BackwardCompatibility
This class concerns itself almost completely with theme administration.
Its tasks include changing theme settings, installing and removing themes, choosing the current theme, and editing themes.
Creating and distributing theme packages: There isn't that much required to package and distribute your own themes... just do the following:
- create a theme_info.xml file, with the root element theme-info.
- its name should go in a name element, just like description.
- your name should go in author. (email in the email attribute.)
- any support website for the theme should be in website.
- layers and templates (non-default) should go in those elements ;).
- if the images dir isn't images, specify in the images element.
- any extra rows for themes should go in extra, serialized. (as in array(variable => value).)
- tar and gzip the directory - and you're done!
- please include any special license in a license.txt file.
Table of Contents
Interfaces
- ActionInterface
- Interface for all action classes.
Properties
- $subaction : string
- $subactions : array<string|int, mixed>
- $obj : static
Methods
- admin() : void
- This method allows administration of themes and their settings, as well as global theme settings.
- call() : void
- Convenience method to load() and execute() an instance of this class.
- canBeLogged() : bool
- Determines whether this action can be logged in the online log.
- canShowDebuggingInfo() : bool
- Determines whether debugging info should be shown.
- canShowInMaintenanceMode() : bool
- Determines whether this action allows access in maintenance mode.
- copy() : void
- Makes a copy of a template file in a new location
- edit() : string|null
- Shows an interface for editing the templates.
- enable() : void
- Handles enabling/disabling a theme from the admin center
- execute() : void
- Dispatcher to whichever sub-action method is necessary.
- getOutputType() : OutputTypeInterface
- Gets the output type for this action.
- install() : void
- Installs new themes, calls the respective function according to the install type.
- isAgreementAction() : bool
- Determines whether this action can be accessed without accepting the registration agreement and privacy policy.
- isRestrictedGuestAccessAllowed() : bool
- Determines whether this action allows access if guest access is restricted.
- isSimpleAction() : bool
- Determines whether this is a simple action.
- list() : void
- This function lists the available themes and provides an interface to reset the paths of all the installed themes.
- load() : static
- Static wrapper for constructor.
- remove() : void
- Remove a theme from the database.
- setOptions() : void
- Administrative global settings.
- setSettings() : void
- Administrative global settings.
- subActionProvider() : null|array<string|int, mixed>
- Called by Subs-Compat.php BackwardCompatibility wrapper functions to provide subaction execution for existing mods
- __construct() : mixed
- Constructor. Protected to force instantiation via self::load().
- addToDb() : int
- Inserts a theme's data to the DataBase.
- deltree() : bool
- Removes a directory from the themes dir.
- getAllThemes() : void
- Loads and returns all installed themes.
- getFileList() : array<string|int, mixed>
- Generates a list of files in a given directory.
- getInstalledThemes() : void
- Loads and returns all installed themes.
- getSingleTheme() : false|array<string|int, mixed>
- Gets a single theme's info.
- getThemeInfo() : false|array<string|int, mixed>
- Reads an .xml file and returns the data as an array
- installCopy() : array<string|int, mixed>
- Makes a copy from the default theme, assigns a name for it and installs it.
- installDir() : array<string|int, mixed>
- Install a theme from a specific dir
- installFile() : array<string|int, mixed>
- Installs a theme from a theme package.
- removeFromDb() : bool
- Removes a theme from the DB, includes all possible places where the theme might be used.
Properties
$subaction
public
string
$subaction
= 'admin'
The requested sub-action. This should be set by the constructor.
$subactions
public
static array<string|int, mixed>
$subactions
= ['admin' => 'admin', 'list' => 'list', 'reset' => 'setOptions', 'options' => 'setOptions', 'remove' => 'remove', 'enable' => 'enable', 'install' => 'install', 'edit' => 'edit', 'copy' => 'copy']
Available sub-actions.
$obj
protected
static static
$obj
An instance of this class. This is used by the load() method to prevent multiple instantiations.
Methods
admin()
This method allows administration of themes and their settings, as well as global theme settings.
public
admin() : void
- sets the settings theme_allow, theme_guests, and knownThemes.
- requires the admin_forum permission.
- accessed with ?action=admin;area=theme;sa=admin.
Uses Themes template Uses Admin language file
call()
Convenience method to load() and execute() an instance of this class.
public
static call() : void
canBeLogged()
Determines whether this action can be logged in the online log.
public
canBeLogged() : bool
Return values
boolcanShowDebuggingInfo()
Determines whether debugging info should be shown.
public
canShowDebuggingInfo() : bool
Return values
boolcanShowInMaintenanceMode()
Determines whether this action allows access in maintenance mode.
public
canShowInMaintenanceMode() : bool
Return values
bool —True if access is allowed, false otherwise.
copy()
Makes a copy of a template file in a new location
public
copy() : void
Tags
edit()
Shows an interface for editing the templates.
public
edit() : string|null
- uses the Themes template and edit_template/edit_style sub template.
- accessed via ?action=admin;area=theme;sa=edit
Return values
string|null —'no_themes' returned if we can't find the theme, otherwise nothing is returned.
enable()
Handles enabling/disabling a theme from the admin center
public
enable() : void
execute()
Dispatcher to whichever sub-action method is necessary.
public
execute() : void
getOutputType()
Gets the output type for this action.
public
getOutputType() : OutputTypeInterface
Return values
OutputTypeInterfaceinstall()
Installs new themes, calls the respective function according to the install type.
public
install() : void
- puts themes in Config::$boardurl/Themes.
- assumes the gzip has a root directory in it. (ie default.) Requires admin_forum. Accessed with ?action=admin;area=theme;sa=install.
isAgreementAction()
Determines whether this action can be accessed without accepting the registration agreement and privacy policy.
public
isAgreementAction() : bool
Return values
boolisRestrictedGuestAccessAllowed()
Determines whether this action allows access if guest access is restricted.
public
isRestrictedGuestAccessAllowed() : bool
Return values
bool —True if access is allowed, false otherwise.
isSimpleAction()
Determines whether this is a simple action.
public
isSimpleAction() : bool
Return values
boollist()
This function lists the available themes and provides an interface to reset the paths of all the installed themes.
public
list() : void
load()
Static wrapper for constructor.
public
static load() : static
Return values
static —An instance of this class.
remove()
Remove a theme from the database.
public
remove() : void
- removes an installed theme.
- requires an administrator.
- accessed with ?action=admin;area=theme;sa=remove.
setOptions()
Administrative global settings.
public
setOptions() : void
setSettings()
Administrative global settings.
public
setSettings() : void
- saves and requests global theme settings. (Theme::$current->settings)
- loads the Admin language file.
- calls admin() if no theme is specified. (the theme center.)
- requires admin_forum permission.
- accessed with ?action=admin;area=theme;sa=list&th=xx.
subActionProvider()
Called by Subs-Compat.php BackwardCompatibility wrapper functions to provide subaction execution for existing mods
public
static subActionProvider([null|string $sa = null ][, bool $return_config = false ][, string|null $activity = null ]) : null|array<string|int, mixed>
Parameters
- $sa : null|string = null
- $return_config : bool = false
- $activity : string|null = null
Return values
null|array<string|int, mixed>__construct()
Constructor. Protected to force instantiation via self::load().
protected
__construct() : mixed
addToDb()
Inserts a theme's data to the DataBase.
protected
addToDb([array<string|int, mixed> $to_install = [] ]) : int
Ends execution with ErrorHandler::fatalLang() if an error appears.
Parameters
- $to_install : array<string|int, mixed> = []
-
An array containing all values to be stored into the DB.
Return values
int —The newly created theme ID.
deltree()
Removes a directory from the themes dir.
protected
deltree(string $path) : bool
This is a recursive function, it will call itself if there are subdirs inside the main directory.
Parameters
- $path : string
-
The absolute path to the directory to be removed
Return values
bool —true when success, false on error.
getAllThemes()
Loads and returns all installed themes.
protected
getAllThemes([bool $enable_only = false ]) : void
Stores all themes on Utils::$context['themes'] for easier use.
Config::$modSettings['knownThemes'] stores themes that the user is able to select.
Parameters
- $enable_only : bool = false
-
Whether to fetch only enabled themes. Default is false.
getFileList()
Generates a list of files in a given directory.
protected
getFileList(string $path, string $relative) : array<string|int, mixed>
Parameters
- $path : string
-
The full path to the directory
- $relative : string
-
The relative path (relative to the Themes directory)
Return values
array<string|int, mixed> —An array of information about the files and directories found
getInstalledThemes()
Loads and returns all installed themes.
protected
getInstalledThemes() : void
Stores all themes on Utils::$context['themes'] for easier use.
Config::$modSettings['knownThemes'] stores themes that the user is able to select.
getSingleTheme()
Gets a single theme's info.
protected
getSingleTheme(int $id[, array<string|int, string> $variables = [] ]) : false|array<string|int, mixed>
Parameters
- $id : int
-
The theme ID to get the info from.
- $variables : array<string|int, string> = []
Return values
false|array<string|int, mixed> —The theme info as an array.
getThemeInfo()
Reads an .xml file and returns the data as an array
protected
getThemeInfo(string $path) : false|array<string|int, mixed>
Removes the entire theme if the .xml file couldn't be found or read.
Parameters
- $path : string
-
The absolute path to the xml file.
Return values
false|array<string|int, mixed> —An array with all the info extracted from the xml file.
installCopy()
Makes a copy from the default theme, assigns a name for it and installs it.
protected
installCopy() : array<string|int, mixed>
Creates a new .xml file containing all the theme's info.
Return values
array<string|int, mixed> —The newly created theme's info.
installDir()
Install a theme from a specific dir
protected
installDir() : array<string|int, mixed>
Assumes the dir is located on the main Themes dir. Ends execution with ErrorHandler::fatalLang() on any error.
Return values
array<string|int, mixed> —The newly created theme's info.
installFile()
Installs a theme from a theme package.
protected
installFile() : array<string|int, mixed>
Stores the theme files on a temp dir, on success it renames the dir to the new theme's name. Ends execution with ErrorHandler::fatalLang() on any error.
Return values
array<string|int, mixed> —The newly created theme's info.
removeFromDb()
Removes a theme from the DB, includes all possible places where the theme might be used.
protected
removeFromDb(int $themeID) : bool
Parameters
- $themeID : int
-
The theme ID
Return values
bool —true when success, false on error.