PHP Class ThemePlugin, pkp-lib

Inheritance: extends LazyLoadPlugin
显示文件 Open project: pkp/pkp-lib Class Usage Examples

Public Properties

Property Type Description
$options Theme-specific options
$parent Parent theme (optional)
$scripts Collection of scripts
$styles Collection of styles

Public Methods

Method Description
__construct ( ) Constructor
_getBaseDir ( $path = '' ) : string Get the base path to be used for file references
_getBaseUrl ( $path = '' ) : string Get the base URL to be used for file paths
_registerScripts ( ) : null Register script assets
addOption ( $name, $type, $args = [] ) Add a theme option
addScript ( $name, $script, $args = [] ) Add a script to load with this theme
addStyle ( $name, $style, $args = [] ) Add a stylesheet to load with this theme
getOption ( $name ) : mixed Get the value of an option or default if the option is not set
getOptionConfig ( $name ) : false | array Get an option's configuration settings
getOptionValues ( ) : array Get all option values
getOptionsConfig ( ) : array Get all options' configuration settings.
getScript ( $name ) : array | null Get a script from this theme or any parent theme
getStyle ( $name ) : array | null Get a style from this theme or any parent theme
init ( ) : null The primary method themes should use to add styles, scripts and fonts, or register hooks. This method is only fired for the currently active theme.
initAfter ( ) Perform actions after the theme has been initialized
isActive ( ) : boolean Determine whether or not this plugin is currently active
isColourDark ( $colour, $limit = 130 ) Check if the passed colour is dark
modifyOptionsConfig ( $name, $args = [] ) : boolean Modify option configuration settings
modifyScript ( $name, $args = [] ) : null Modify the params of an existing script
modifyStyle ( $name, $args = [] ) : null Modify the params of an existing stylesheet
readOptionsFormUserVars ( $hookName, $args ) Retrieve user-entered values for options from any form
register ( $category, $path )
removeOption ( $name ) : boolean Remove an option
removeScript ( $name ) : boolean Remove a registered script
removeStyle ( $name ) : boolean Remove a registered stylesheet
saveOption ( $name, $value, $contextId = null ) Sanitize and save a theme option
saveOptionsForm ( $hookName, $args ) Save options in any form
setParent ( $parent ) : null Set a parent theme for this theme
themeRegistered ( $themes ) : null Fire the init() method when a theme is registered

Private Methods

Method Description
_registerStyles ( ) : null Register stylesheets and font assets
_registerTemplates ( ) : null Register directories to search for template files

Method Details

__construct() public method

Constructor
public __construct ( )

_getBaseDir() public method

Get the base path to be used for file references
public _getBaseDir ( $path = '' ) : string
$path string An optional path to append to the base
return string

_getBaseUrl() public method

A base URL for loading LESS/CSS/JS files in elements. It will also be set to the @baseUrl variable before LESS files are compiloed so that images and fonts can be located.
public _getBaseUrl ( $path = '' ) : string
$path string An optional path to append to the base
return string

_registerScripts() public method

Passes scripts defined by the theme to the template manager for handling.
public _registerScripts ( ) : null
return null

addOption() public method

Theme options are added programmatically to the Settings > Website > Appearance form when this theme is activated. Common options are colour and typography selectors.
public addOption ( $name, $type, $args = [] )
$name string Unique name for this setting
$type string A pre-registered type of setting. Supported values: text|colour|radio. Default: `text`
$args array Optional parameters defining this setting. Some setting types may accept or require additional arguments. `label` string Locale key for a label for this field. `description` string Locale key for a description for this field. `default` mixed A default value. Default: ''

addScript() public method

Add a script to load with this theme
public addScript ( $name, $script, $args = [] )
$name string A name for this script
$script string The script to be included. Should be path relative to the theme or, if the `inline` argument is included, script data to be output.
$args array Optional arguments hash. Supported args: `context` string Whether to load this on the `frontend` or `backend`. default: frontend `priority` int Controls order in which scripts are printed default: STYLE_SEQUENCE_NORMAL `inline` bool Whether the $script value should be output directly as script data. Used to pass backend data to the scripts.

addStyle() public method

Style paths with a .less extension will be compiled and redirected to the compiled file.
public addStyle ( $name, $style, $args = [] )
$name string A name for this stylesheet
$style string The stylesheet. Should be a path relative to the theme directory or, if the `inline` argument is included, style data to be output.
$args array Optional arguments hash. Supported args: 'context': Whether to load this on the `frontend` or `backend`. default: `frontend` 'priority': Controls order in which styles are printed 'addLess': Additional LESS files to process before compiling. Array 'addLessVariables': A string containing additional LESS variables to parse before compiling. Example: "@bg:#000;" `inline` bool Whether the $style value should be output directly as style data.

getOption() public method

Get the value of an option or default if the option is not set
public getOption ( $name ) : mixed
$name The name of the option value to retrieve
return mixed The value of the option. Will return a default if set in the option config. False if no option exists

getOptionConfig() public method

This retrives option settings for any option attached to this theme or any parent theme.
public getOptionConfig ( $name ) : false | array
$name The name of the option config to retrieve
return false | array The config array for this option. Or false if no config is found.

getOptionValues() public method

This retrieves a single array containing option values for this theme and any parent themes.
public getOptionValues ( ) : array
return array

getOptionsConfig() public method

This retrieves a single array containing options settings for this theme and any parent themes.
public getOptionsConfig ( ) : array
return array

getScript() public method

Get a script from this theme or any parent theme
public getScript ( $name ) : array | null
$name string The name of the script to retrieve
return array | null Reference to the script or null if not found

getStyle() public method

Get a style from this theme or any parent theme
public getStyle ( $name ) : array | null
$name string The name of the style to retrieve
return array | null Reference to the style or null if not found

init() abstract public method

The primary method themes should use to add styles, scripts and fonts, or register hooks. This method is only fired for the currently active theme.
abstract public init ( ) : null
return null

initAfter() public method

Registers templates, styles and scripts that have been added by the theme or any parent themes
public initAfter ( )

isActive() public method

This only returns true if the theme is currently the selected theme in a given context. Use self::getEnabled() if you want to know if the theme is available for use on the site.
public isActive ( ) : boolean
return boolean

isColourDark() public method

This is a utility function to determine the darkness of a hex colour. This is designed to be used in theme colour options, so that text can be adjusted to ensure it's readable on light or dark backgrounds. You can specify the brightness threshold by passing in a $limit value. Higher values are brighter. Based on: http://stackoverflow.com/a/8468448/1723499
Since: 0.1
public isColourDark ( $colour, $limit = 130 )

modifyOptionsConfig() public method

Modify option configuration settings
public modifyOptionsConfig ( $name, $args = [] ) : boolean
$name The name of the option config to retrieve
$args The new configuration settings for this option
return boolean Whether the option was found and the config was updated.

modifyScript() public method

Modify the params of an existing script
See also: self::addScript()
public modifyScript ( $name, $args = [] ) : null
$name string The name of the script to modify
$args array Parameters to modify.
return null

modifyStyle() public method

Modify the params of an existing stylesheet
See also: self::addStyle()
public modifyStyle ( $name, $args = [] ) : null
$name string The name of the stylesheet to modify
$args array Parameters to modify.
return null

readOptionsFormUserVars() public method

This helper function allows you to hook into any form to add theme option values to the form's user input data.
See also: Form::readUserVar()
public readOptionsFormUserVars ( $hookName, $args )
$hookName string
$args array Arguments passed via the hook `form` Form The form object from which option values can be retrieved. `vars` Array Key/value store of the user vars read by the form

register() public method

public register ( $category, $path )

removeOption() public method

Remove an option
public removeOption ( $name ) : boolean
$name The name of the option to remove
return boolean Whether the option was found and removed

removeScript() public method

Remove a registered script
public removeScript ( $name ) : boolean
$name string The name of the script to remove
return boolean Whether or not the stylesheet was found and removed.

removeStyle() public method

Remove a registered stylesheet
public removeStyle ( $name ) : boolean
$name string The name of the stylesheet to remove
return boolean Whether or not the stylesheet was found and removed.

saveOption() public method

Sanitize and save a theme option
public saveOption ( $name, $value, $contextId = null )
$name string A unique id for the option to save
$value mixed The new value to save
$contextId int Optional context id. Defaults to the current context

saveOptionsForm() public method

This helper function allows you to save theme options attached to any form by hooking into the form's execute function.
See also: Form::execute()
public saveOptionsForm ( $hookName, $args )
$hookName string
$args array Arguments passed via the hook `form` Form The form object from which option values can be retrieved. `request` Request

setParent() public method

Set a parent theme for this theme
public setParent ( $parent ) : null
$parent string Key in the plugin registry for the parent theme
return null

themeRegistered() public method

Fire the init() method when a theme is registered
public themeRegistered ( $themes ) : null
$themes array List of all loaded themes
return null

Property Details

$options public_oe property

Theme-specific options
public $options

$parent public_oe property

Parent theme (optional)
public $parent

$scripts public_oe property

Collection of scripts
See also: self::_registerScripts
public $scripts

$styles public_oe property

Collection of styles
See also: self::_registerStyles
public $styles