37 define(
'DS', DIRECTORY_SEPARATOR);
44 if (!defined(
'SMARTY_DIR')) {
45 define(
'SMARTY_DIR', dirname(__FILE__) . DS);
52 if (!defined(
'SMARTY_SYSPLUGINS_DIR')) {
53 define(
'SMARTY_SYSPLUGINS_DIR', SMARTY_DIR .
'sysplugins' . DS);
55 if (!defined(
'SMARTY_PLUGINS_DIR')) {
56 define(
'SMARTY_PLUGINS_DIR', SMARTY_DIR .
'plugins' . DS);
58 if (!defined(
'SMARTY_MBSTRING')) {
59 define(
'SMARTY_MBSTRING', function_exists(
'mb_get_info'));
61 if (!defined(
'SMARTY_RESOURCE_CHAR_SET')) {
66 define(
'SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ?
'UTF-8' :
'ISO-8859-1');
68 if (!defined(
'SMARTY_RESOURCE_DATE_FORMAT')) {
72 define(
'SMARTY_RESOURCE_DATE_FORMAT',
'%b %e, %Y');
80 if (!class_exists(
'Smarty_Autoloader',
false)) {
81 if (!class_exists(
'Smarty_Internal_Data',
true)) {
82 require_once
'Autoloader.php';
91 if (!class_exists(
'Smarty_Internal_Data',
false)) {
92 require_once SMARTY_SYSPLUGINS_DIR .
'smarty_internal_data.php';
94 require_once SMARTY_SYSPLUGINS_DIR .
'smarty_internal_templatebase.php';
95 require_once SMARTY_SYSPLUGINS_DIR .
'smarty_internal_template.php';
96 require_once SMARTY_SYSPLUGINS_DIR .
'smarty_resource.php';
97 require_once SMARTY_SYSPLUGINS_DIR .
'smarty_variable.php';
98 require_once SMARTY_SYSPLUGINS_DIR .
'smarty_template_source.php';
754 if (is_callable(
'mb_internal_encoding')) {
757 $this->start_time = microtime(
true);
759 if ($this->template_dir[0] !==
'./templates/' || isset($this->template_dir[1])) {
762 if ($this->config_dir[0] !==
'./configs/' || isset($this->config_dir[1])) {
765 if ($this->compile_dir !==
'./templates_c/') {
766 unset(self::$_muted_directories[
'./templates_c/']);
769 if ($this->cache_dir !==
'./cache/') {
770 unset(self::$_muted_directories[
'./cache/']);
773 if (isset($this->plugins_dir)) {
778 if (isset($_SERVER[
'SCRIPT_NAME'])) {
820 return $_template->render(
true,
false, $display);
848 $tpl =
new $this->template_class($resource_name, $this);
850 $result = $tpl->source->exists;
851 $this->template_objects = $save;
865 if (isset($varname)) {
866 if (isset(self::$global_tpl_vars[$varname])) {
867 return self::$global_tpl_vars[$varname]->value;
873 foreach (self::$global_tpl_vars AS $key => $var) {
874 $_result[$key] = $var->value;
895 return $_cache_resource->clearAll($this, $exp_time);
939 throw new SmartyException(
"Security class '$security_class' is not defined");
941 throw new SmartyException(
"Class '$security_class' must extend Smarty_Security.");
956 $this->security_policy = null;
970 $this->template_dir = array();
972 $this->template_dir[$k] = rtrim($v,
'/\\') . DS;
974 $this->joined_template_dir = join(
' # ', $this->template_dir);
990 $this->joined_template_dir = join(
' # ', $this->template_dir);
1003 if ($index !== null) {
1004 return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null;
1018 $this->config_dir = array();
1020 $this->config_dir[$k] = rtrim($v,
'/\\') . DS;
1022 $this->joined_config_dir = join(
' # ', $this->config_dir);
1037 $this->joined_config_dir = join(
' # ', $this->config_dir);
1050 if ($index !== null) {
1051 return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null;
1065 $this->plugins_dir = array();
1080 $this->plugins_dir = (array) $this->plugins_dir;
1082 $this->plugins_dir[] = rtrim($v,
'/\\') . DS;
1084 $this->plugins_dir = array_unique($this->plugins_dir);
1085 $this->_is_file_cache = array();
1135 $this->cache_dir = rtrim(
$cache_dir,
'/\\') . DS;
1159 private function _addDir($dirName, $dir, $key = null)
1162 $this->$dirName = (array) $this->$dirName;
1164 if (is_array($dir)) {
1165 foreach ($dir as $k => $v) {
1168 $this->{$dirName}[] = rtrim($v,
'/\\') . DS;
1171 $this->{$dirName}[$k] = rtrim($v,
'/\\') . DS;
1175 if ($key !== null) {
1177 $this->{$dirName}[$key] = rtrim($dir,
'/\\') . DS;
1180 $this->{$dirName}[] = rtrim($dir,
'/\\') . DS;
1194 $this->default_modifiers = (array) $modifiers;
1208 if (is_array($modifiers)) {
1209 $this->default_modifiers = array_merge($this->default_modifiers, $modifiers);
1211 $this->default_modifiers[] = $modifiers;
1238 if ($type !== null) {
1239 $this->autoload_filters[$type] = (array) $filters;
1241 $this->autoload_filters = (array) $filters;
1258 if ($type !== null) {
1259 if (!empty($this->autoload_filters[$type])) {
1260 $this->autoload_filters[$type] = array_merge($this->autoload_filters[$type], (array) $filters);
1262 $this->autoload_filters[$type] = (array) $filters;
1265 foreach ((array) $filters as $key => $value) {
1266 if (!empty($this->autoload_filters[$key])) {
1267 $this->autoload_filters[$key] = array_merge($this->autoload_filters[$key], (array) $value);
1269 $this->autoload_filters[$key] = (array) $value;
1287 if ($type !== null) {
1288 return isset($this->autoload_filters[$type]) ? $this->autoload_filters[$type] : array();
1314 if (!is_readable($tpl_name)) {
1317 $this->debug_tpl = $tpl_name;
1346 if (isset($this->template_objects[$_templateId])) {
1348 $tpl = clone $this->template_objects[$_templateId];
1349 $tpl->smarty = clone $tpl->smarty;
1351 $tpl = $this->template_objects[$_templateId];
1354 $tpl->tpl_vars = array();
1355 $tpl->config_vars = array();
1359 $tpl->smarty = clone $tpl->smarty;
1361 $tpl->templateId = $_templateId;
1364 if (!empty($data) && is_array($data)) {
1366 foreach ($data as $_key => $_val) {
1370 if ($this->debugging) {
1390 if ($check && (is_callable($plugin_name) || class_exists($plugin_name,
false))) {
1394 $_name_parts = explode(
'_', $plugin_name, 3);
1397 if (!isset($_name_parts[2]) || strtolower($_name_parts[0]) !==
'smarty') {
1398 throw new SmartyException(
"plugin {$plugin_name} is not a valid name format");
1401 if (strtolower($_name_parts[1]) ==
'internal') {
1402 $file = SMARTY_SYSPLUGINS_DIR . strtolower($plugin_name) .
'.php';
1403 if (isset($this->_is_file_cache[$file]) ? $this->_is_file_cache[$file] : $this->_is_file_cache[$file] = is_file($file)) {
1404 require_once($file);
1411 $_plugin_filename =
"{$_name_parts[1]}.{$_name_parts[2]}.php";
1413 $_stream_resolve_include_path = function_exists(
'stream_resolve_include_path');
1417 $names = array($_plugin_dir . $_plugin_filename, $_plugin_dir . strtolower($_plugin_filename),);
1418 foreach ($names as $file) {
1419 if (isset($this->_is_file_cache[$file]) ? $this->_is_file_cache[$file] : $this->_is_file_cache[$file] = is_file($file)) {
1420 require_once($file);
1423 if ($this->use_include_path && !preg_match(
'/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
1425 if ($_stream_resolve_include_path) {
1426 $file = stream_resolve_include_path($file);
1431 if ($file !==
false) {
1432 require_once($file);
1674 $allowed = array(
'template_dir' =>
'getTemplateDir',
'config_dir' =>
'getConfigDir',
1675 'plugins_dir' =>
'getPluginsDir',
'compile_dir' =>
'getCompileDir',
1676 'cache_dir' =>
'getCacheDir',);
1678 if (isset($allowed[$name])) {
1679 return $this->{$allowed[$name]}();
1681 trigger_error(
'Undefined property: ' . get_class($this) .
'::$' . $name, E_USER_NOTICE);
1695 $allowed = array(
'template_dir' =>
'setTemplateDir',
'config_dir' =>
'setConfigDir',
1696 'plugins_dir' =>
'setPluginsDir',
'compile_dir' =>
'setCompileDir',
1697 'cache_dir' =>
'setCacheDir',);
1699 if (isset($allowed[$name])) {
1700 $this->{$allowed[$name]}($value);
1702 trigger_error(
'Undefined property: ' . get_class($this) .
'::$' . $name, E_USER_NOTICE);
1721 $_is_muted_directory =
false;
1725 $smarty_dir = realpath(SMARTY_DIR);
1726 if ($smarty_dir !==
false) {
1728 'length' => strlen($smarty_dir),);
1736 $file = realpath($key);
1737 if ($file ===
false) {
1742 $dir = array(
'file' => $file,
'length' => strlen($file),);
1744 if (!strncmp($errfile, $dir[
'file'], $dir[
'length'])) {
1745 $_is_muted_directory =
true;
1752 if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
1784 $error_handler = array(
'Smarty',
'mutingErrorHandler');
1785 $previous = set_error_handler($error_handler);
1788 if ($previous !== $error_handler) {
1800 restore_error_handler();