Skip to content

Commit

Permalink
v2.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
croxton committed Mar 5, 2015
1 parent 4a1dff3 commit 9e30363
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

* Author: [Mark Croxton](http://hallmark-design.co.uk/)

### Version 2.6.1
### Version 2.6.2

This is the development version of Stash. Test thoroughly before using in production.

Expand Down
2 changes: 1 addition & 1 deletion system/expressionengine/third_party/stash/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
if (! defined('STASH_VER'))
{
define('STASH_NAME', 'Stash');
define('STASH_VER', '2.6.1');
define('STASH_VER', '2.6.2');
define('STASH_AUTHOR', 'Mark Croxton');
define('STASH_DOCS', 'http://github.com/croxton/Stash/');
define('STASH_DESC', 'Stash: save text and code snippets for reuse throughout your templates.');
Expand Down
39 changes: 32 additions & 7 deletions system/expressionengine/third_party/stash/mod.stash.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function __construct($calling_from_hook = FALSE)
$this->stash_cookie = $this->EE->config->item('stash_cookie') ? $this->EE->config->item('stash_cookie') : 'stashid';
$this->stash_cookie_expire = $this->EE->config->item('stash_cookie_expire') ? $this->EE->config->item('stash_cookie_expire') : 0;
$this->default_scope = $this->EE->config->item('stash_default_scope') ? $this->EE->config->item('stash_default_scope') : 'user';
$this->default_refresh = $this->EE->config->item('stash_default_refresh') ? $this->EE->config->item('stash_default_refresh') : 0; // minutes
$this->limit_bots = $this->EE->config->item('stash_limit_bots') ? $this->EE->config->item('stash_limit_bots') : FALSE;

// cache pruning can cache stampede mitigation defaults
Expand All @@ -90,6 +91,9 @@ public function __construct($calling_from_hook = FALSE)

// Support {if var1 IN (var2) }...{/if} style conditionals in Stash templates / tagdata?
$this->parse_if_in = $this->EE->config->item('stash_parse_if_in') ? $this->EE->config->item('stash_parse_if_in') : FALSE;

// include query string when using the @URI context (full page caching)?
$this->include_query_str = $this->EE->config->item('stash_query_strings') ? $this->EE->config->item('stash_query_strings') : FALSE;

// initialise tag parameters
if (FALSE === $calling_from_hook)
Expand Down Expand Up @@ -513,12 +517,14 @@ public function set($params=array(), $value='', $type='variable', $scope='user')
// get params
$label = $this->EE->TMPL->fetch_param('label', $name);
$save = (bool) preg_match('/1|on|yes|y/i', $this->EE->TMPL->fetch_param('save'));
$refresh = (int) $this->EE->TMPL->fetch_param('refresh', 1440); // minutes (1440 = 1 day)
$match = $this->EE->TMPL->fetch_param('match', NULL); // regular expression to test value against
$against = $this->EE->TMPL->fetch_param('against', $this->EE->TMPL->tagdata); // text to apply test against
$filter = $this->EE->TMPL->fetch_param('filter', NULL); // regex pattern to search for
$default = $this->EE->TMPL->fetch_param('default', NULL); // default value
$delimiter = $this->EE->TMPL->fetch_param('delimiter', '|'); // implode arrays using this delimiter

// cache refresh time
$refresh = (int) $this->EE->TMPL->fetch_param('refresh', $this->default_refresh);

// do we want to set a placeholder somewhere in this template ?
$set_placeholder = (bool) preg_match('/1|on|yes|y/i', $this->EE->TMPL->fetch_param('set_placeholder'));
Expand Down Expand Up @@ -1614,6 +1620,17 @@ private function _update_list($append=TRUE)
$name = $this->EE->TMPL->fetch_param('name');
$context = $this->EE->TMPL->fetch_param('context', NULL);
$this->EE->TMPL->tagdata = $this->_parse_output($this->EE->TMPL->tagdata);
$this->parse_complete = TRUE; // make sure we don't run parsing again

// get stash variable pairs (note: picks up outer pairs, nested pairs and singles are ignored)
preg_match_all('#'.LD.'(stash:[a-z0-9\-_]+)'.RD.'.*?'.LD.'/\g{1}'.RD.'#ims', $this->EE->TMPL->tagdata, $matches);

if (isset($matches[1]))
{
$this->EE->TMPL->var_pair = array_flip(array_unique($matches[1]));
}

// format our list
$this->_serialize_stash_tag_pairs();

if ( $this->not_empty($this->EE->TMPL->tagdata))
Expand Down Expand Up @@ -2551,7 +2568,7 @@ public function cache()
// thus context is always @URI, and name must be set to context:name
if ( $context = $this->EE->TMPL->fetch_param('context', FALSE))
{
$this->EE->TMPL->tagparams['name'] = $this->_parse_context($context) . ':' . $this->EE->TMPL->tagparams['name'];
$this->EE->TMPL->tagparams['name'] = $this->_parse_context($context . ':') . $this->EE->TMPL->tagparams['name'];
}

// context parameter MUST be set to the page URI pointer
Expand Down Expand Up @@ -2638,9 +2655,15 @@ public function static_cache($output='')
// thus context is always @URI, and name must be set to context:name
if ( $context = $this->EE->TMPL->fetch_param('context', FALSE))
{
$this->EE->TMPL->tagparams['name'] = $this->_parse_context($context) . ':' . $this->EE->TMPL->tagparams['name'];
if ($context !== '@URI')
{
$this->EE->TMPL->tagparams['name'] = $context . ':' . $this->EE->TMPL->tagparams['name'];
}
}

// parse cache key, making sure query strings are excluded from the @URI
$this->EE->TMPL->tagparams['name'] = $this->_parse_context('@URI:' . $this->EE->TMPL->tagparams['name'], TRUE);

$this->process = 'end';
$this->priority = '999999'; // should be the last thing post-processed (by Stash)

Expand All @@ -2666,7 +2689,7 @@ public function static_cache($output='')
public function save_output($output='')
{
// mandatory parameter values for cached output
$this->EE->TMPL->tagparams['context'] = "@URI";
$this->EE->TMPL->tagparams['context'] = NULL;
$this->EE->TMPL->tagparams['scope'] = 'site';
$this->EE->TMPL->tagparams['save'] = 'yes';
$this->EE->TMPL->tagparams['refresh'] = "0"; // static cached items can't expire
Expand Down Expand Up @@ -3782,7 +3805,7 @@ private function _lcd($array, $x=1)
* @param string $name The variable name
* @return string
*/
private function _parse_context($name)
private function _parse_context($name, $disable_query_str = FALSE)
{
// replace '@:' with current context name
if (strncmp($name, '@:', 2) == 0)
Expand All @@ -3803,8 +3826,10 @@ private function _parse_context($name)
$uri = empty($uri) ? $this->EE->stash_model->get_index_key() : $uri;

// append query string?
if ($query_str = $this->EE->input->server('QUERY_STRING'))
{
if ($this->include_query_str
&& ! $disable_query_str
&& $query_str = $this->EE->input->server('QUERY_STRING')
){
$uri = $uri . '?' . $query_str;
}

Expand Down

0 comments on commit 9e30363

Please sign in to comment.