PHP Class Habari\Theme

The Theme class is the behind-the-scenes representation of of a set of UI files that compose the visual theme of the blog
Inheritance: extends Pluggable
Show file Open project: habari/system

Public Properties

Property Type Description
$config_vars
$context
$name
$template_engine TemplateEngine
$theme_dir
$valid_filters We build the Post filters by analyzing the handler_var data which is assigned to the handler ( by the Controller and also, optionally, by the Theme )
$version

Public Methods

Method Description
__call ( string $function, array $params ) Handle methods called on this class or its descendants that are not defined by this class.
__construct ( $themedata ) Constructor for theme
__get ( string $key ) : mixed Get a template variable value
__isset ( string $key ) : boolean Detects if a variable is assigned to the template engine for use in constructing the template's output.
__set ( string $key, mixed $value ) Set a template variable, a property alias for assign() This can only affect the current stack level!
__unset ( string $key ) Remove a template variable value This can only affect the current stack level!
act_display ( $paramarray = ['user_filters' => []] ) Grabs post data and inserts that data into the internal handler_vars array, which eventually gets extracted into the theme's ( and thereby the template_engine's ) local symbol table for use in the theme's templates
act_display_404 ( array $user_filters = [] ) Helper function: Display a 404 template
act_display_date ( array $user_filters = [] ) Helper function: Display the posts for a specific date
act_display_entries ( array $user_filters = [] ) Helper function: Displays multiple entries
act_display_home ( array $user_filters = [] ) Helper function: Displays the home page
act_display_post ( array $user_filters = [] ) Helper function: Display a post
act_display_tag ( array $user_filters = [] ) Helper function: Display the posts for a tag
act_search ( array $user_filters = [] ) Helper function: Display the posts for a specific criteria
action_template_footer_9 ( ) Load assets and add the javascript ones to the footer on the template_footer_javascript action hook.
action_template_header_9 ( ) Load assets and add the CSS ones to the header on the template_stylesheet action hook.
add_script ( string $value, string $where = 'header', string $name = null, string | array $requires = null ) : boolean Add javascript to the stack to be output in the theme.
add_style ( string $value, string $where = 'header', string $name = null, string | array $requires = null ) : boolean Add a stylesheet to the stack to be output in the theme.
add_template ( string $name, string $file, boolean $replace = false ) Add a template to the list of available templates
add_template_vars ( ) Assign the default variables that would be used in every template
assign ( $key, $value ) Helper function: Avoids having to call $theme->template_engine->key= 'value';
check_scope_criteria ( array $criteria ) : boolean Matches the scope criteria against the current request
dir_to_url ( string $dir ) : boolean | string Convert a theme directory or resource into a URL
display ( string $template_name ) Helper function: Avoids having to call $theme->template_engine->display( 'template_name' );
display_fallback ( array $template_list, $display_function = 'display' ) Find the first template that matches from the list provided and display it
end_buffer ( ) End the current template variable buffer
fetch ( string $template_name, boolean $unstack = false ) : string Helper function: Avoids having to call $theme->template_engine->fetch( 'template_name' );
fetch_unassigned ( string $template_name ) : string Calls the template engine's fetch() method without pre-assigning template variables.
filter_provided ( array $provided = [] ) : array Provide default Habari features for curious plugins
get_blocks ( string $area, string $scope, Theme $theme ) : array Retrieve the block objects for the current scope and specified area Incomplete!
get_scopes ( string $area ) : array Retrieve current scope data from the database based on the requested area
get_url ( boolean | string $resource = false, boolean $overrideok = true ) : string Get the URL for a resource in one of the directories used by the active theme, child theme directory first
get_version ( ) : string Provide a method to return the version number from the theme xml
info ( ) Loads a theme's metadata from an XML file in theme's directory.
load_assets ( boolean $refresh = false ) : array Load and return a list of all assets in the current theme chain's /assets/ directory
sort_scopes ( StdObject $scope1, StdObject $scope2 ) : integer Sort function for ordering scope object rows by priority
start_buffer ( ) Start a new template variable buffer
template_exists ( string $template_name ) : boolean Determine if a template exists in the current theme
theme_area ( Theme $theme, string $area, string $context = null, string $scope = null ) : string Displays blocks associated to the specified area and current scope.
theme_body_class ( Theme $theme, mixed $args = [] ) : string A theme function for outputting CSS classes based on the requested content
theme_comment_author_link ( Theme $theme, Comment $comment ) : string Returns a humane commenter's link for a comment if a URL is supplied, or just display the comment author's name
theme_comment_form_action ( Theme $theme, Post $post ) : string Returns the feedback URL to which comments should be submitted for the indicated Post
theme_comments_count ( Theme $theme, Post $post, string $zero = '', string $one = '', string $many = '' ) : string Returns a full qualified URL of the specified post based on the comments count.
theme_comments_link ( Theme $theme, Post $post, string $zero = '', string $one = '', string $many = '', string $fragment = 'comments' ) : string Returns a full qualified URL of the specified post based on the comments count, and links to the post.
theme_content ( Theme $theme, object $object, string $context = null ) Display an object using a template designed for the type of object it is The $object is assigned into the theme using the $content template variable
theme_feed_alternate ( Theme $theme ) : string Returns the appropriate alternate feed based on the currently matched rewrite rule.
theme_footer ( $theme ) Aggregates and echos the additional footer code by combining Plugins and Stack calls.
theme_has_context ( $theme, string $context ) : boolean Check to see if the theme is currently rendering a specific context
theme_header ( $theme ) Aggregates and echos the additional header code by combining Plugins and Stack calls.
theme_next_page_link ( $theme, string $text = null, $classes = ['next-page'] ) Provides a link to the next page
theme_page_selector ( $theme, $rr_name = null, $settings = [] ) : string Build a collection of paginated URLs to be used for pagination.
theme_page_title ( Theme $theme ) A Theme function to provide a page title
theme_prev_page_link ( $theme, string $text = null, $classes = ['prev-page'] ) Provides a link to the previous page
theme_query_count ( ) : integer Returns the count of queries executed
theme_query_time ( ) : float Returns total query execution time in seconds

Protected Methods

Method Description
play_var_stack ( ) Play back the full stack of template variables to assign them into the template

Method Details

__call() public method

Allow plugins to provide additional theme actions, like a custom act_display_*()
public __call ( string $function, array $params )
$function string The method that was called.
$params array An array of parameters passed to the method

__construct() public method

If no parameter is supplied, then the constructor Loads the active theme from the database. If no theme option is set, a fatal error is thrown
public __construct ( $themedata )

__get() public method

Get a template variable value
public __get ( string $key ) : mixed
$key string The template variable name to get
return mixed The value of the variable

__isset() public method

Detects if a variable is assigned to the template engine for use in constructing the template's output.
public __isset ( string $key ) : boolean
$key string name of variable
return boolean true if name is set, false if not set

__set() public method

Set a template variable, a property alias for assign() This can only affect the current stack level!
public __set ( string $key, mixed $value )
$key string The template variable to set
$value mixed The value of the variable

__unset() public method

Remove a template variable value This can only affect the current stack level!
public __unset ( string $key )
$key string The template variable name to unset

act_display() public method

This is the default, generic function to grab posts. To "filter" the posts retrieved, simply pass any filters to the handler_vars variables associated with the post retrieval. For instance, to filter by tag, ensure that handler_vars['tag'] contains the tag to filter by. Simple as that.
public act_display ( $paramarray = ['user_filters' => []] )

act_display_404() public method

Helper function: Display a 404 template
public act_display_404 ( array $user_filters = [] )
$user_filters array Additional arguments user to get the page content

act_display_date() public method

Helper function: Display the posts for a specific date
public act_display_date ( array $user_filters = [] )
$user_filters array Additional arguments used to get the page content

act_display_entries() public method

Helper function: Displays multiple entries
public act_display_entries ( array $user_filters = [] )
$user_filters array Additional arguments used to get the page content

act_display_home() public method

Helper function: Displays the home page
public act_display_home ( array $user_filters = [] )
$user_filters array Additional arguments used to get the page content

act_display_post() public method

Helper function: Display a post
public act_display_post ( array $user_filters = [] )
$user_filters array Additional arguments used to get the page content

act_display_tag() public method

Helper function: Display the posts for a tag
public act_display_tag ( array $user_filters = [] )
$user_filters array Additional arguments used to get the page content

action_template_header_9() public method

Load assets and add the CSS ones to the header on the template_stylesheet action hook.

add_script() public method

Add javascript to the stack to be output in the theme.
public add_script ( string $value, string $where = 'header', string $name = null, string | array $requires = null ) : boolean
$value string Either a URL or raw JS to be output inline.
$where string Where should it be output? Options are header and footer.
$name string A name to reference this script by. Used for removing or using in $requires by other scripts.
$requires string | array Either a string or an array of strings of $name's for scripts this script requires.
return boolean True if added successfully, false otherwise.

add_style() public method

Add a stylesheet to the stack to be output in the theme.
public add_style ( string $value, string $where = 'header', string $name = null, string | array $requires = null ) : boolean
$value string Either a URL or raw CSS to be output inline.
$where string Where should it be output? Options are header and footer.
$name string A name to reference this script by. Used for removing or using in $after by other scripts.
$requires string | array Either a string or an array of strings of $name's for scripts this script requires.
return boolean True if added successfully, false otherwise.

add_template() public method

Add a template to the list of available templates
public add_template ( string $name, string $file, boolean $replace = false )
$name string Name of the new template
$file string File of the template to add
$replace boolean If true, replace any existing template with this name

add_template_vars() public method

Assign the default variables that would be used in every template
public add_template_vars ( )

assign() public method

Helper function: Avoids having to call $theme->template_engine->key= 'value';
public assign ( $key, $value )

check_scope_criteria() public method

Matches the scope criteria against the current request
public check_scope_criteria ( array $criteria ) : boolean
$criteria array An array of scope criteria data in RPN, where values are arrays and operators are strings
return boolean True if the criteria matches the current request

dir_to_url() public method

Convert a theme directory or resource into a URL
public dir_to_url ( string $dir ) : boolean | string
$dir string The pathname to convert
return boolean | string The URL to use, or false if none was found

display() public method

Helper function: Avoids having to call $theme->template_engine->display( 'template_name' );
public display ( string $template_name )
$template_name string The name of the template to display

display_fallback() public method

Find the first template that matches from the list provided and display it
public display_fallback ( array $template_list, $display_function = 'display' )
$template_list array The list of templates to search for

end_buffer() public method

End the current template variable buffer
public end_buffer ( )

fetch() public method

Helper function: Avoids having to call $theme->template_engine->fetch( 'template_name' );
public fetch ( string $template_name, boolean $unstack = false ) : string
$template_name string The name of the template to display
$unstack boolean If true, end the current template variable buffer upon returning
return string The content of the template

fetch_unassigned() public method

Assumes that the template variables have already been set.
public fetch_unassigned ( string $template_name ) : string
$template_name string The name of the template to display
return string The content of the template

filter_provided() public static method

Provide default Habari features for curious plugins
public static filter_provided ( array $provided = [] ) : array
$provided array Features already collected from interrogated plugins
return array Plugin Features plus Habari Features

get_blocks() public method

Retrieve the block objects for the current scope and specified area Incomplete!
public get_blocks ( string $area, string $scope, Theme $theme ) : array
$area string The area to which blocks will be output
$scope string The scope to which blocks will be output
$theme Theme The theme that is outputting these blocks
return array An array of Block instances to render

get_scopes() public method

Retrieve current scope data from the database based on the requested area
public get_scopes ( string $area ) : array
$area string The area for which a scope may be applied
return array An array of scope data

get_url() public method

Get the URL for a resource in one of the directories used by the active theme, child theme directory first
public get_url ( boolean | string $resource = false, boolean $overrideok = true ) : string
$resource boolean | string The resource name
$overrideok boolean If false, find only the parent theme resources
return string The URL of the requested resource

get_version() public method

Provide a method to return the version number from the theme xml
public get_version ( ) : string
return string The theme version from XML

info() public method

Loads a theme's metadata from an XML file in theme's directory.
public info ( )

load_assets() public method

Load and return a list of all assets in the current theme chain's /assets/ directory
public load_assets ( boolean $refresh = false ) : array
$refresh boolean If True, clear and reload all assets
return array An array of URLs of assets in the assets directories of the active theme chain

play_var_stack() protected method

Play back the full stack of template variables to assign them into the template
protected play_var_stack ( )

sort_scopes() public method

Sort function for ordering scope object rows by priority
public sort_scopes ( StdObject $scope1, StdObject $scope2 ) : integer
$scope1 StdObject A scope to compare
$scope2 StdObject A scope to compare
return integer A sort return value, -1 to 1

start_buffer() public method

Start a new template variable buffer
public start_buffer ( )

template_exists() public method

Determine if a template exists in the current theme
public template_exists ( string $template_name ) : boolean
$template_name string The name of the template to detect
return boolean True if template exists

theme_area() public method

Displays blocks associated to the specified area and current scope.
public theme_area ( Theme $theme, string $area, string $context = null, string $scope = null ) : string
$theme Theme The theme with which this area will be output
$area string The area to which blocks will be output
$context string The area of context within the theme that could adjust the template used
$scope string Used to force a specific scope
return string the output of all the blocks

theme_body_class() public method

A theme function for outputting CSS classes based on the requested content
public theme_body_class ( Theme $theme, mixed $args = [] ) : string
$theme Theme A Theme object instance
$args mixed Additional classes that should be added to the ones generated
return string The resultant classes

theme_comment_form_action() public method

Returns the feedback URL to which comments should be submitted for the indicated Post
public theme_comment_form_action ( Theme $theme, Post $post ) : string
$theme Theme The current theme
$post Post The post object to get the feedback URL for
return string The URL to the feedback entrypoint for this comment

theme_comments_count() public method

Passed strings are localized prior to parsing therefore to localize "%d Comments" in french, it would be "%d Commentaires". Since we use sprintf() in the final concatenation, you must format passed strings accordingly.
public theme_comments_count ( Theme $theme, Post $post, string $zero = '', string $one = '', string $many = '' ) : string
$theme Theme The current theme object
$post Post Post object used to build the comments link
$zero string String to return when there are no comments
$one string String to return when there is one comment
$many string String to return when there are more than one comment
return string String to display for comment count

theme_content() public method

Display an object using a template designed for the type of object it is The $object is assigned into the theme using the $content template variable
public theme_content ( Theme $theme, object $object, string $context = null )
$theme Theme The theme used to display the object
$object object An object to display
$context string The context in which the object will be displayed

theme_feed_alternate() public method

Returns the appropriate alternate feed based on the currently matched rewrite rule.
public theme_feed_alternate ( Theme $theme ) : string
$theme Theme The current theme object
return string Link to the appropriate alternate Atom feed

theme_has_context() public method

Check to see if the theme is currently rendering a specific context
public theme_has_context ( $theme, string $context ) : boolean
$context string The context to check for.
return boolean True if the context is active.

theme_header() public method

Aggregates and echos the additional header code by combining Plugins and Stack calls.
public theme_header ( $theme )

theme_page_selector() public static method

Build a collection of paginated URLs to be used for pagination.
public static theme_page_selector ( $theme, $rr_name = null, $settings = [] ) : string
return string Collection of paginated URLs built by the RewriteRule.

theme_page_title() public method

A Theme function to provide a page title
public theme_page_title ( Theme $theme )
$theme Theme The current theme

theme_query_count() public method

Returns the count of queries executed
public theme_query_count ( ) : integer
return integer The query count

theme_query_time() public method

Returns total query execution time in seconds
public theme_query_time ( ) : float
return float Query execution time in seconds, with fractions.

Property Details

$config_vars public property

public $config_vars

$context public property

public $context

$name public property

public $name

$template_engine public property

public TemplateEngine,habari $template_engine
return TemplateEngine

$theme_dir public property

public $theme_dir

$valid_filters public property

We build the Post filters by analyzing the handler_var data which is assigned to the handler ( by the Controller and also, optionally, by the Theme )
public $valid_filters

$version public property

public $version