PHP Class Stash

Author: Mark Croxton ([email protected])
显示文件 Open project: croxton/stash Class Usage Examples

Public Properties

Property Type Description
$EE
$context
$default_scope
$file_sync
$limit_bots
$path
$site_id
$stash_cookie
$stash_cookie_expire
$version

Protected Properties

Property Type Description
$bundle_id
$bundles
$parse_complete
$parse_conditionals
$parse_depth
$parse_tags
$parse_vars
$priority
$process
$replace
$type
$xss_clean

Public Methods

Method Description
__call ( string $name, array $arguments ) : void Shortcut to stash:get or stash:set
__construct ( $calling_from_hook = FALSE ) * Constructor
_no_results ( ) : String parse and return no_results content
_prep_no_results ( string $prefix ) : String prep a prefixed no_results block in current template tagdata
append ( ) : void Append the specified value to an already existing variable.
append_list ( ) : string Append to array
append_value ( ) : void Single tag version of append()
block ( ) : string Define default/fallback content for a stash variable from enclosed tagdata
bundle ( array $params = [], array $dynamic = [] ) : void Bundle up a collection of variables and save in the database
cache ( ) : string Cache tagdata to db and link it to the current URL context
context ( ) : void Set the current context
copy ( ) : string Clone a variable / list
destroy ( mixed $params = [], string $type = 'variable', string $scope = 'user' ) : void Unset variable(s) in the current session, optionally flush from db
embed ( ) : string Embed a Stash template file in the current template
embed_extend ( ) : string Pass variables to an embed via variable pairs in tagdata
extend ( ) : string | void Inject a stash embed into a variable or block
final_output ( $output = '' ) : string Final parsing/cleanup of template tagdata before output
finish ( ) : string Tagb for cleaning up specific placeholders before final output
flatten_list ( $array ) : string Flattens an array into a quasi-serialized format suitable for saving as a stash variable
flush_cache ( ) : string Flush the variables database cache for the current site (Super Admins only)
get ( mixed $params = '', string $type = 'variable', string $scope = 'user' ) : string Get content from session, database, $_POST/$_GET superglobals or file
get_bundle ( $set = TRUE ) : string Restore values for a given bundle
get_list ( $params = [], $value = '', $type = 'variable', $scope = 'user' ) : string Retrieve a serialised array of items, explode and replace into tagdata
init ( boolean $calling_from_hook = FALSE ) : void Initialise tag parameters
is_empty ( $string = NULL ) : integer Checks if a variable or string has any content, handy for conditionals
join_lists ( ) : string Create a union of two or more existing lists Lists *must* share the same keys and be *already in memory*
list_count ( ) : string Retrieve the item count for a given list
not_empty ( $string = NULL ) : integer Checks if a variable or string is empty or non-existent, handy for conditionals
not_found ( ) : string Output the 404 template with the correct header and exit
parse ( array $params = [], string $value = NULL ) : string Parse tagdata
prepend ( ) : void Prepend the specified value to an already existing variable.
prepend_list ( ) : string Prepend to array
prepend_value ( ) : void Single tag version of prepend()
rebuild_list ( mixed $params = '', string $type = 'variable', string $scope = 'user' ) : array Retrieve and rebuild list, or optionally part of a list
save_output ( string $output = '' ) : string Save the final rendered template output to a static file
set ( mixed $params = [], string $value = '', string $type = 'variable', string $scope = 'user' ) : void Set content in the current session, optionally save to the database
set_bundle ( ) : void Set values into a bundle
set_list ( ) : string Serialize a multidimenisional array and save as a variable
set_parse_params ( ) : String set individual parse parameters if parse="yes"
set_value ( ) : void Single tag version of set(), for when you need to use a plugin as a tag parameter (always use with parse="inward")
shuffle_list_key ( $arr, $key ) : void Shuffle a stash list key
sort_by_key ( $arr, $key, $cmp = 'sort_by_integer' ) : void Sort a multi-dimensional array by key
split_list ( )
static_cache ( string $output = '' ) : string Cache a template to file and link it to the current URL context

Protected Methods

Method Description
sort_by_integer ( $a, $b ) Sort callback function: sort by integer
sort_by_string ( $a, $b ) Sort callback function: sort by string

Private Methods

Method Description
_api_call ( string $method, mixed $params, string $type = 'variable', string $scope = 'user', string $value = NULL ) : void API: call a Stash method directly
_api_static_call ( string $method, mixed $params, string $type = 'variable', string $scope = 'user', string $value = NULL ) : void API: call a Stash method statically (DEPRECATED, PHP <5.6 only)
_clean_string ( string $value = NULL ) : string String manipulations
_get_boolean_config_item ( string $item, boolean $default = TRUE ) : boolean get the boolean value of a config item, with the desired fallback value
_get_stash_cookie ( ) : boolean/array get the stash cookie
_get_users_vars ( ) : array return the standard set of user variables
_is_bot ( ) : void Check if the user agent is a bot
_is_cacheable ( boolean $check_request_type = TRUE ) : string Check to see if a template (not a fragment) is suitable for caching
_lcd ( $array, $x = 1 ) : integer get the least common denominator for a given array of numbers
_list_row_explode ( string $string ) : array
_list_row_implode ( array $array ) : string
_load_EE_TMPL ( ) : void Load the EE Template class and register the Stash module Used when Stash is instantiated outside of an EE template
_matches ( string $match, string/array $against ) : boolean Match a regex against a string or array of strings
_normalize ( $str ) : string Normalize characters in a string (the dirty way)
_parse_context ( string $name, $disable_query_str = FALSE ) : string Replace the current context in a variable name
_parse_fraction ( $fraction, $offset, $total ) : integer get a fraction from a parameter value
_parse_output ( string $value = NULL, string $match = NULL, string $filter = NULL, string $default = NULL ) : string Final parsing of the stash variable before output to the template
_parse_sub_template ( boolean $tags = TRUE, boolean $vars = TRUE, boolean $conditionals = FALSE, integer $depth = 1, $nocache_id = FALSE ) : string Parse template data
_parse_template_vars ( string $template = '' ) : string Parse global vars inside a string
_placeholders ( array $matches ) : string Replaces nested tag content with placeholders
_post_parse ( $method ) : Mixed Delay processing a tag until template_post_parse hook
_prep_in_conditionals ( string $tagdata = '' ) : String Prep {if var IN (array)} conditionals
_run_tag ( string $method, array $params = [] ) : string Run a Stash module tag with a known set of parameters
_serialize_stash_tag_pairs ( ) : void Retrieve {stash:var}{/stash:var} tag pairs and serialize
_set_stash_cookie ( string $unique_id ) : void set the stash cookie
_un_prefix ( string $prefix, string $template ) : String remove a given prefix from common variables in the template tagdata
_update_list ( boolean $append = TRUE ) : string Append / prepend to array

Method Details

__call() public method

Shortcut to stash:get or stash:set
public __call ( string $name, array $arguments ) : void
$name string The method name being called or context if third tagpart
$arguments array The method call arguments
return void

__construct() public method

* Constructor
public __construct ( $calling_from_hook = FALSE )

_no_results() public method

parse and return no_results content
public _no_results ( ) : String
return String

_prep_no_results() public method

prep a prefixed no_results block in current template tagdata
public _prep_no_results ( string $prefix ) : String
$prefix string
return String

append() public method

Append the specified value to an already existing variable.
public append ( ) : void
return void

append_list() public method

Append to array
public append_list ( ) : string
return string

append_value() public method

Single tag version of append()
public append_value ( ) : void
return void

block() public method

Define default/fallback content for a stash variable from enclosed tagdata
public block ( ) : string
return string

bundle() public method

Bundle up a collection of variables and save in the database
public bundle ( array $params = [], array $dynamic = [] ) : void
$params array
$dynamic array
return void

cache() public method

Cache tagdata to db and link it to the current URL context
public cache ( ) : string
return string

context() public method

Set the current context
public context ( ) : void
return void

copy() public method

Clone a variable / list
public copy ( ) : string
return string

destroy() public method

Unset variable(s) in the current session, optionally flush from db
public destroy ( mixed $params = [], string $type = 'variable', string $scope = 'user' ) : void
$params mixed The name of the variable to unset, or an array of key => value pairs
$type string The type of variable
$scope string The scope of the variable
return void

embed() public method

Embed a Stash template file in the current template
public embed ( ) : string
return string

embed_extend() public method

Pass variables to an embed via variable pairs in tagdata
public embed_extend ( ) : string
return string

extend() public method

Inject a stash embed into a variable or block
public extend ( ) : string | void
return string | void

final_output() public method

Final parsing/cleanup of template tagdata before output
public final_output ( $output = '' ) : string
return string

finish() public method

Tagb for cleaning up specific placeholders before final output
public finish ( ) : string
return string

flatten_list() public static method

Flattens an array into a quasi-serialized format suitable for saving as a stash variable
public static flatten_list ( $array ) : string
return string The imploded string

flush_cache() public method

Flush the variables database cache for the current site (Super Admins only)
public flush_cache ( ) : string
return string

get() public method

Get content from session, database, $_POST/$_GET superglobals or file
public get ( mixed $params = '', string $type = 'variable', string $scope = 'user' ) : string
$params mixed The name of the variable to retrieve, or an array of key => value pairs
$type string The type of variable
$scope string The scope of the variable
return string

get_bundle() public method

Restore values for a given bundle
public get_bundle ( $set = TRUE ) : string
return string

get_list() public method

Retrieve a serialised array of items, explode and replace into tagdata
public get_list ( $params = [], $value = '', $type = 'variable', $scope = 'user' ) : string
return string

init() public method

Initialise tag parameters
public init ( boolean $calling_from_hook = FALSE ) : void
$calling_from_hook boolean Is method being called by an extension hook?
return void

is_empty() public method

Checks if a variable or string has any content, handy for conditionals
public is_empty ( $string = NULL ) : integer
$string a string to test
return integer

join_lists() public method

Create a union of two or more existing lists Lists *must* share the same keys and be *already in memory*
public join_lists ( ) : string
return string

list_count() public method

Retrieve the item count for a given list
public list_count ( ) : string
return string

not_empty() public method

Checks if a variable or string is empty or non-existent, handy for conditionals
public not_empty ( $string = NULL ) : integer
$string a string to test
return integer

not_found() public method

Output the 404 template with the correct header and exit
public not_found ( ) : string
return string

parse() public method

Parse tagdata
public parse ( array $params = [], string $value = NULL ) : string
$params array an array of key => value pairs representing tag parameters
$value string string to parse, defaults to template tagdata
return string

prepend() public method

Prepend the specified value to an already existing variable.
public prepend ( ) : void
return void

prepend_list() public method

Prepend to array
public prepend_list ( ) : string
return string

prepend_value() public method

Single tag version of prepend()
public prepend_value ( ) : void
return void

rebuild_list() public method

Retrieve and rebuild list, or optionally part of a list
public rebuild_list ( mixed $params = '', string $type = 'variable', string $scope = 'user' ) : array
$params mixed The name of the variable to retrieve, or an array of key => value pairs
$type string The type of variable
$scope string The scope of the variable
return array

save_output() public method

Save the final rendered template output to a static file
public save_output ( string $output = '' ) : string
$output string the rendered template
return string

set() public method

Set content in the current session, optionally save to the database
public set ( mixed $params = [], string $value = '', string $type = 'variable', string $scope = 'user' ) : void
$params mixed The name of the variable to retrieve, or an array of key => value pairs
$value string The value of the variable
$type string The type of variable
$scope string The scope of the variable
return void

set_bundle() public method

Set values into a bundle
public set_bundle ( ) : void
return void

set_list() public method

Serialize a multidimenisional array and save as a variable
public set_list ( ) : string
return string

set_parse_params() public method

set individual parse parameters if parse="yes"
public set_parse_params ( ) : String
return String

set_value() public method

Single tag version of set(), for when you need to use a plugin as a tag parameter (always use with parse="inward")
public set_value ( ) : void
return void

shuffle_list_key() public method

Shuffle a stash list key
public shuffle_list_key ( $arr, $key ) : void
return void

sort_by_integer() protected method

Sort callback function: sort by integer
protected sort_by_integer ( $a, $b )

sort_by_key() public method

Sort a multi-dimensional array by key
public sort_by_key ( $arr, $key, $cmp = 'sort_by_integer' ) : void
return void

sort_by_string() protected method

Sort callback function: sort by string
protected sort_by_string ( $a, $b )

split_list() public method

public split_list ( )

static_cache() public method

Cache a template to file and link it to the current URL context
public static_cache ( string $output = '' ) : string
$output string additional tagdata to return to the template along with the placeholder
return string

Property Details

$EE public_oe property

public $EE

$bundle_id protected_oe property

protected $bundle_id

$bundles protected_oe static_oe property

protected static $bundles

$context public_oe static_oe property

public static $context

$default_scope public_oe property

public $default_scope

$file_sync public_oe property

public $file_sync

$limit_bots public_oe property

public $limit_bots

$parse_complete protected_oe property

protected $parse_complete

$parse_conditionals protected_oe property

protected $parse_conditionals

$parse_depth protected_oe property

protected $parse_depth

$parse_tags protected_oe property

protected $parse_tags

$parse_vars protected_oe property

protected $parse_vars

$path public_oe property

public $path

$priority protected_oe property

protected $priority

$process protected_oe property

protected $process

$replace protected_oe property

protected $replace

$site_id public_oe property

public $site_id

$type protected_oe property

protected $type

$version public_oe property

public $version

$xss_clean protected_oe property

protected $xss_clean