public function init($calling_from_hook = FALSE)
{
// make sure we have a Template object to work with, in case Stash is being invoked outside of a template
if (!class_exists('EE_Template')) {
$this->_load_EE_TMPL();
}
// initialise internal flags
$this->parse_complete = FALSE;
$this->_update = FALSE;
$this->_append = TRUE;
$this->_embed_nested = FALSE;
$this->process = 'inline';
// postpone the parsing of the called stash tag?
if (FALSE === $calling_from_hook) {
/* process stage:
start = called prior to template parsing in the current template
inline = process as a normal tag within the natural parse order of the template
end = called after all tag parsing has completed
*/
$this->process = $this->EE->TMPL->fetch_param('process', 'inline');
// start | inline | end
$this->priority = $this->EE->TMPL->fetch_param('priority', '1');
// ensure a priority is set
}
// legacy: make 'final' the same as 'end'
if ($this->process == "final") {
$this->process = "end";
}
// tags can't be processed on start, only stash embeds
if ($this->process == "start") {
$this->process = "inline";
}
// allow the site_id to be overridden, for e.g. shared variables across mutliple sites
$this->site_id = (int) $this->EE->TMPL->fetch_param('site_id', $this->site_id);
// selected bundle
$bundle = $this->EE->TMPL->fetch_param('bundle', 'default');
// lookup the id of an existing bundle, or map to one of the preset bundles
if (!($this->bundle_id = $this->EE->stash_model->get_bundle_by_name($bundle))) {
// not found, fallback to the default
$this->bundle_id = 1;
}
// xss scripting protection
$this->xss_clean = (bool) preg_match('/1|on|yes|y/i', $this->EE->TMPL->fetch_param('xss_clean'));
// if the variable is already set, do we want to replace it's value? Default = yes
$this->replace = (bool) preg_match('/1|on|yes|y/i', $this->EE->TMPL->fetch_param('replace', 'yes'));
// parse="yes"?
$this->set_parse_params();
// do we want to parse any tags and variables inside tagdata? Default = no
$this->parse_tags = (bool) preg_match('/1|on|yes|y/i', $this->EE->TMPL->fetch_param('parse_tags'));
$this->parse_vars = $this->EE->TMPL->fetch_param('parse_vars', NULL);
// legacy behaviour: if parse_vars is null but parse tags is true, we should make sure vars are parsed too
if ($this->parse_tags && $this->parse_vars == NULL) {
$this->parse_vars = TRUE;
} else {
$this->parse_vars = (bool) preg_match('/1|on|yes|y/i', $this->parse_vars);
}
// parsing: how many passes of the template should we make? (more passes = more overhead). Default = 1
$this->parse_depth = preg_replace('/[^0-9]/', '', $this->EE->TMPL->fetch_param('parse_depth', 1));
// parsing: parse advanced conditionals. Default = no
$this->parse_conditionals = (bool) preg_match('/1|on|yes|y/i', $this->EE->TMPL->fetch_param('parse_conditionals'));
// stash type, default to 'variable'
$this->type = strtolower($this->EE->TMPL->fetch_param('type', 'variable'));
// create a stash array in the session if we don't have one
if (!array_key_exists('stash', $this->EE->session->cache)) {
$this->EE->session->cache['stash'] = array();
}
// determine the memory storage location
if ($this->type === 'variable') {
// we're setting/getting a 'native' stash variable
$this->_stash =& $this->EE->session->cache['stash'];
} elseif ($this->type === 'snippet' || $this->type === 'global') {
// we're setting/getting a global variable {snippet}
$this->_stash =& $this->EE->config->_global_vars;
} else {
$this->EE->output->show_user_error('general', $this->EE->lang->line('unknown_stash_type') . $this->type);
}
}