private function _parse_template_vars($template = '')
{
// globals vars {name}
if (count($this->EE->config->_global_vars) > 0 && strpos($template, LD) !== FALSE) {
foreach ($this->EE->config->_global_vars as $key => $val) {
$template = str_replace(LD . $key . RD, $val, $template);
}
}
// stash vars {stash:var}
// note: due to the order we're doing this, global vars can themselves contain stash vars...
if (count($this->EE->session->cache['stash']) > 0 && strpos($template, LD . 'stash:') !== FALSE) {
// We only want to replace single stash placeholder tags,
// NOT tag pairs such as {stash:var}whatever{/stash:var}
$tag_vars = array();
preg_match_all('#' . LD . '(stash:[a-z0-9\\-_]+)' . RD . '(?!.+\\1' . RD . ')#ims', $template, $matches);
if (isset($matches[1])) {
$tag_vars = array_flip($matches[1]);
}
foreach ($this->EE->session->cache['stash'] as $key => $val) {
if (isset($tag_vars['stash:' . $key])) {
$template = str_replace(LD . 'stash:' . $key . RD, $val, $template);
}
}
}
// user variables, in the form {logged_in_[variable]}
if (strpos($template, LD . 'logged_in_') !== FALSE) {
$user_vars = $this->_get_users_vars();
foreach ($user_vars as $val) {
if (isset($this->EE->session->userdata[$val]) and ($val == 'group_description' or strval($this->EE->session->userdata[$val]) != '')) {
$template = str_replace(LD . 'logged_in_' . $val . RD, $this->EE->session->userdata[$val], $template);
}
}
}
// Parse date format string "constants"
if (strpos($template, LD . 'DATE_') !== FALSE) {
$date_constants = array('DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q', 'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC', 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%Q', 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', 'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i UTC', 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O', 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O', 'DATE_RFC2822' => '%D, %d %M %Y %H:%i:%s %O', 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O', 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q');
foreach ($date_constants as $key => $val) {
$template = str_replace(LD . $key . RD, $val, $template);
}
}
// Current time {current_time format="%Y %m %d %H:%i:%s"} - thanks @objectivehtml
if (strpos($template, LD . 'current_time') !== FALSE) {
if (preg_match_all("/" . LD . "current_time\\s+format=([\"\\'])([^\\1]*?)\\1" . RD . "/", $template, $matches)) {
for ($j = 0; $j < count($matches[0]); $j++) {
if (version_compare(APP_VER, '2.6', '>=')) {
$template = str_replace($matches[0][$j], $this->EE->localize->format_date($matches[2][$j]), $template);
} else {
$template = str_replace($matches[0][$j], $this->EE->localize->decode_date($matches[2][$j], $this->EE->localize->now), $template);
}
}
}
}
// segment vars {segment_1} etc
if (strpos($template, LD . 'segment_') !== FALSE) {
for ($i = 1; $i < 10; $i++) {
$template = str_replace(LD . 'segment_' . $i . RD, $this->EE->uri->segment($i), $template);
}
}
return $template;
}