Documentation

Themes
in package
implements ActionInterface Uses 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  : object
$backcompat  : array<string|int, mixed>

Methods

admin()  : mixed
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.
copy()  : mixed
Makes a copy of a template file in a new location
copyTemplate()  : void
Backward compatibility wrapper for the copy sub-action.
edit()  : mixed
Shows an interface for editing the templates.
editTheme()  : void
Backward compatibility wrapper for the edit sub-action.
enable()  : mixed
Handles enabling/disabling a theme from the admin center
enableTheme()  : void
Backward compatibility wrapper for the enable sub-action.
execute()  : void
Dispatcher to whichever sub-action method is necessary.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
install()  : mixed
Installs new themes, calls the respective function according to the install type.
list()  : mixed
This function lists the available themes and provides an interface to reset the paths of all the installed themes.
load()  : object
Static wrapper for constructor.
remove()  : mixed
Remove a theme from the database.
removeTheme()  : void
Backward compatibility wrapper for the remove sub-action.
setOptions()  : mixed
Administrative global settings.
setSettings()  : mixed
Administrative global settings.
setThemeOptions()  : void
Backward compatibility wrapper for the options sub-action.
themeAdmin()  : void
Backward compatibility wrapper for the admin sub-action.
themeInstall()  : void
Backward compatibility wrapper for the install sub-action.
themeList()  : void
Backward compatibility wrapper for the list sub-action.
__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()  : mixed
Loads and returns all installed themes.
getFileList()  : array<string|int, mixed>
Generates a list of files in a given directory.
getInstalledThemes()  : mixed
Loads and returns all installed themes.
getSingleTheme()  : array<string|int, mixed>
Gets a single theme's info.
getThemeInfo()  : 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 object $obj

An instance of this class. This is used by the load() method to prevent mulitple instantiations.

$backcompat

private static array<string|int, mixed> $backcompat = ['func_names' => ['call' => 'ThemesMain', 'themeAdmin' => 'ThemeAdmin', 'themeList' => 'ThemeList', 'setThemeOptions' => 'SetThemeOptions', 'removeTheme' => 'RemoveTheme', 'enableTheme' => 'EnableTheme', 'themeInstall' => 'ThemeInstall', 'editTheme' => 'EditTheme', 'copyTemplate' => 'CopyTemplate']]

BackwardCompatibility settings for this class.

Methods

admin()

This method allows administration of themes and their settings, as well as global theme settings.

public admin() : mixed
  • 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

copy()

Makes a copy of a template file in a new location

public copy() : mixed
Tags
uses
template_copy_template()

copyTemplate()

Backward compatibility wrapper for the copy sub-action.

public static copyTemplate() : void

edit()

Shows an interface for editing the templates.

public edit() : mixed
  • uses the Themes template and edit_template/edit_style sub template.
  • accessed via ?action=admin;area=theme;sa=edit

editTheme()

Backward compatibility wrapper for the edit sub-action.

public static editTheme() : void

enable()

Handles enabling/disabling a theme from the admin center

public enable() : mixed

enableTheme()

Backward compatibility wrapper for the enable sub-action.

public static enableTheme() : void

execute()

Dispatcher to whichever sub-action method is necessary.

public execute() : void

exportStatic()

Provides a way to export a class's public static properties and methods to global namespace.

public static exportStatic() : void

To do so:

  1. Use this trait in the class.
  2. At the END of the class's file, call its exportStatic() method.

Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.

Regarding the $backcompat items:

A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].

$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.

$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.

Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.

install()

Installs new themes, calls the respective function according to the install type.

public install() : mixed
  • 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.

list()

This function lists the available themes and provides an interface to reset the paths of all the installed themes.

public list() : mixed

load()

Static wrapper for constructor.

public static load() : object
Return values
object

An instance of this class.

remove()

Remove a theme from the database.

public remove() : mixed
  • removes an installed theme.
  • requires an administrator.
  • accessed with ?action=admin;area=theme;sa=remove.

removeTheme()

Backward compatibility wrapper for the remove sub-action.

public static removeTheme() : void

setOptions()

Administrative global settings.

public setOptions() : mixed

setSettings()

Administrative global settings.

public setSettings() : mixed
  • 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.

setThemeOptions()

Backward compatibility wrapper for the options sub-action.

public static setThemeOptions() : void

themeAdmin()

Backward compatibility wrapper for the admin sub-action.

public static themeAdmin() : void

themeInstall()

Backward compatibility wrapper for the install sub-action.

public static themeInstall() : void

themeList()

Backward compatibility wrapper for the list sub-action.

public static themeList() : void

__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 ]) : mixed

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() : mixed

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 = [] ]) : array<string|int, mixed>
Parameters
$id : int

The theme ID to get the info from.

$variables : array<string|int, string> = []
Return values
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) : 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
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.


        
On this page

Search results