Skip to content

Commit

Permalink
- bugfix Smarty version was not filled in header comment of compiled …
Browse files Browse the repository at this point in the history
…and cached files

  - optimization replace internal Smarty::$ds property by DIRECTORY_SEPARATOR (reverted from commit 1e787d0)
  • Loading branch information
uwetews committed Oct 26, 2017
1 parent 8e91085 commit f3950a4
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 257 deletions.
4 changes: 0 additions & 4 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
===== 3.1.32 - dev ===
26.10.2017 3.1.32-dev-28
- bugfix Smarty version was not filled in header comment of compiled and cached files
- optimization replace internal Smarty::$ds property by DIRECTORY_SEPARATOR

21.10.2017
- bugfix custom delimiters could fail since modification of version 3.1.32-dev-23
https://github.com/smarty-php/smarty/issues/394
Expand Down
158 changes: 82 additions & 76 deletions libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.32-dev-28';
const SMARTY_VERSION = '3.1.32-dev-27';
/**
* define variable scopes
*/
Expand Down Expand Up @@ -544,6 +544,12 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var Smarty_Internal_Debug
*/
public $_debug = null;
/**
* Directory separator
*
* @var string
*/
public $ds = DIRECTORY_SEPARATOR;
/**
* template directory
*
Expand Down Expand Up @@ -763,6 +769,27 @@ public function disableSecurity()
return $this;
}

/**
* Set template directory
*
* @param string|array $template_dir directory(s) of template sources
* @param bool $isConfig true for config_dir
*
* @return \Smarty current Smarty instance for chaining
*/
public function setTemplateDir($template_dir, $isConfig = false)
{
if ($isConfig) {
$this->config_dir = array();
$this->_processedConfigDir = array();
} else {
$this->template_dir = array();
$this->_processedTemplateDir = array();
}
$this->addTemplateDir($template_dir, null, $isConfig);
return $this;
}

/**
* Add template directory(s)
*
Expand Down Expand Up @@ -832,24 +859,15 @@ public function getTemplateDir($index = null, $isConfig = false)
}

/**
* Set template directory
* Set config directory
*
* @param string|array $template_dir directory(s) of template sources
* @param bool $isConfig true for config_dir
* @param $config_dir
*
* @return \Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
public function setTemplateDir($template_dir, $isConfig = false)
public function setConfigDir($config_dir)
{
if ($isConfig) {
$this->config_dir = array();
$this->_processedConfigDir = array();
} else {
$this->template_dir = array();
$this->_processedTemplateDir = array();
}
$this->addTemplateDir($template_dir, null, $isConfig);
return $this;
return $this->setTemplateDir($config_dir, true);
}

/**
Expand Down Expand Up @@ -878,15 +896,17 @@ public function getConfigDir($index = null)
}

/**
* Set config directory
* Set plugins directory
*
* @param $config_dir
* @param string|array $plugins_dir directory(s) of plugins
*
* @return Smarty current Smarty instance for chaining
*/
public function setConfigDir($config_dir)
public function setPluginsDir($plugins_dir)
{
return $this->setTemplateDir($config_dir, true);
$this->plugins_dir = (array)$plugins_dir;
$this->_pluginsDirNormalized = false;
return $this;
}

/**
Expand Down Expand Up @@ -922,7 +942,7 @@ public function getPluginsDir()
$this->plugins_dir = (array)$this->plugins_dir;
}
foreach ($this->plugins_dir as $k => $v) {
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true);
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . $this->ds, true);
}
$this->_cache[ 'plugin_files' ] = array();
$this->_pluginsDirNormalized = true;
Expand All @@ -931,16 +951,15 @@ public function getPluginsDir()
}

/**
* Set plugins directory
*
* @param string|array $plugins_dir directory(s) of plugins
* @param string $compile_dir directory to store compiled templates in
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
public function setPluginsDir($plugins_dir)
public function setCompileDir($compile_dir)
{
$this->plugins_dir = (array)$plugins_dir;
$this->_pluginsDirNormalized = false;
$this->_normalizeDir('compile_dir', $compile_dir);
$this->_compileDirNormalized = true;
return $this;
}

Expand All @@ -959,15 +978,16 @@ public function getCompileDir()
}

/**
* Set cache directory
*
* @param string $compile_dir directory to store compiled templates in
* @param string $cache_dir directory to store cached templates in
*
* @return Smarty current Smarty instance for chaining
*/
public function setCompileDir($compile_dir)
public function setCacheDir($cache_dir)
{
$this->_normalizeDir('compile_dir', $compile_dir);
$this->_compileDirNormalized = true;
$this->_normalizeDir('cache_dir', $cache_dir);
$this->_cacheDirNormalized = true;
return $this;
}

Expand All @@ -985,20 +1005,6 @@ public function getCacheDir()
return $this->cache_dir;
}

/**
* Set cache directory
*
* @param string $cache_dir directory to store cached templates in
*
* @return Smarty current Smarty instance for chaining
*/
public function setCacheDir($cache_dir)
{
$this->_normalizeDir('cache_dir', $cache_dir);
$this->_cacheDirNormalized = true;
return $this;
}

/**
* creates a template object
*
Expand Down Expand Up @@ -1127,24 +1133,24 @@ public function _getTemplateId($template_name,
*/
public function _realpath($path, $realpath = null)
{
$nds = DIRECTORY_SEPARATOR === '/' ? '\\' : '/';
// normalize DIRECTORY_SEPARATOR
$path = str_replace($nds, DIRECTORY_SEPARATOR, $path);
$nds = $this->ds == '/' ? '\\' : '/';
// normalize $this->ds
$path = str_replace($nds, $this->ds, $path);
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$path,
$parts);
$path = $parts[ 'path' ];
if ($parts[ 'root' ] === '\\') {
if ($parts[ 'root' ] == '\\') {
$parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
} else {
if ($realpath !== null && !$parts[ 'root' ]) {
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
$path = getcwd() . $this->ds . $path;
}
}
// remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns
$path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#u', DIRECTORY_SEPARATOR, $path);
$path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#u', $this->ds, $path);
// resolve '..DIRECTORY_SEPARATOR' pattern, smallest first
if (strpos($path, '..' . DIRECTORY_SEPARATOR) !== false &&
if (strpos($path, '..' . $this->ds) != false &&
preg_match_all('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#u', $path, $match)
) {
$counts = array();
Expand All @@ -1155,7 +1161,7 @@ public function _realpath($path, $realpath = null)
foreach ($counts as $count) {
$path = preg_replace('#(([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count .
'}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count . '})(?=[^.])#u',
DIRECTORY_SEPARATOR,
$this->ds,
$path);
}
}
Expand Down Expand Up @@ -1204,23 +1210,23 @@ public function setEscapeHtml($escape_html)
}

/**
* Return auto_literal flag
* Set auto_literal flag
*
* @return boolean
* @param boolean $auto_literal
*/
public function getAutoLiteral()
public function setAutoLiteral($auto_literal = true)
{
return $this->auto_literal;
$this->auto_literal = $auto_literal;
}

/**
* Set auto_literal flag
* Return auto_literal flag
*
* @param boolean $auto_literal
* @return boolean
*/
public function setAutoLiteral($auto_literal = true)
public function getAutoLiteral()
{
$this->auto_literal = $auto_literal;
return $this->auto_literal;
}

/**
Expand All @@ -1239,16 +1245,6 @@ public function setMergeCompiledIncludes($merge_compiled_includes)
$this->merge_compiled_includes = $merge_compiled_includes;
}

/**
* Get left delimiter
*
* @return string
*/
public function getLeftDelimiter()
{
return $this->left_delimiter;
}

/**
* Set left delimiter
*
Expand All @@ -1260,13 +1256,13 @@ public function setLeftDelimiter($left_delimiter)
}

/**
* Get right delimiter
* Get left delimiter
*
* @return string $right_delimiter
* @return string
*/
public function getRightDelimiter()
public function getLeftDelimiter()
{
return $this->right_delimiter;
return $this->left_delimiter;
}

/**
Expand All @@ -1279,6 +1275,16 @@ public function setRightDelimiter($right_delimiter)
$this->right_delimiter = $right_delimiter;
}

/**
* Get right delimiter
*
* @return string $right_delimiter
*/
public function getRightDelimiter()
{
return $this->right_delimiter;
}

/**
* @param boolean $debugging
*/
Expand Down Expand Up @@ -1401,7 +1407,7 @@ public function __set($name, $value)
*/
private function _normalizeDir($dirName, $dir)
{
$this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . DIRECTORY_SEPARATOR, true);
$this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . $this->ds, true);
if (!isset(Smarty::$_muted_directories[ $this->{$dirName} ])) {
Smarty::$_muted_directories[ $this->{$dirName} ] = null;
}
Expand All @@ -1427,7 +1433,7 @@ private function _normalizeTemplateConfig($isConfig)
}
foreach ($dir as $k => $v) {
if (!isset($processed[ $k ])) {
$dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true);
$dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . $this->ds, true);
$processed[ $k ] = true;
}
}
Expand Down
Loading

0 comments on commit f3950a4

Please sign in to comment.