38 if(!defined(
'DIR_SEP')) {
48 if (!defined(
'SMARTY_DIR')) {
52 if (!defined(
'SMARTY_CORE_DIR')) {
56 define(
'SMARTY_PHP_PASSTHRU', 0);
57 define(
'SMARTY_PHP_QUOTE', 1);
58 define(
'SMARTY_PHP_REMOVE', 2);
59 define(
'SMARTY_PHP_ALLOW', 3);
230 'PHP_HANDLING' =>
false,
231 'IF_FUNCS' => array(
'array',
'list',
234 'in_array',
'is_array',
235 'true',
'false',
'null'),
236 'INCLUDE_ANY' =>
false,
238 'MODIFIER_FUNCS' => array(
'count'),
239 'ALLOW_CONSTANTS' =>
false,
240 'ALLOW_SUPER_GLOBALS' =>
true
454 var
$_config = array(array(
'vars' => array(),
'files' => array()));
532 'modifier' => array(),
533 'function' => array(),
535 'compiler' => array(),
536 'prefilter' => array(),
537 'postfilter' => array(),
538 'outputfilter' => array(),
539 'resource' => array(),
540 'insert' => array());
572 : @
$GLOBALS[
'HTTP_SERVER_VARS'][
'SCRIPT_NAME']);
583 if (is_array($tpl_var)){
584 foreach ($tpl_var as $key => $val) {
586 $this->_tpl_vars[$key] = $val;
591 $this->_tpl_vars[$tpl_var] = $value;
604 $this->_tpl_vars[$tpl_var] = &$value;
613 function append($tpl_var, $value=null, $merge=
false)
615 if (is_array($tpl_var)) {
617 foreach ($tpl_var as $_key => $_val) {
619 if(!@is_array($this->_tpl_vars[$_key])) {
620 settype($this->_tpl_vars[$_key],
'array');
622 if($merge && is_array($_val)) {
623 foreach($_val as $_mkey => $_mval) {
624 $this->_tpl_vars[$_key][$_mkey] = $_mval;
627 $this->_tpl_vars[$_key][] = $_val;
632 if ($tpl_var !=
'' && isset($value)) {
633 if(!@is_array($this->_tpl_vars[$tpl_var])) {
634 settype($this->_tpl_vars[$tpl_var],
'array');
636 if($merge && is_array($value)) {
637 foreach($value as $_mkey => $_mval) {
638 $this->_tpl_vars[$tpl_var][$_mkey] = $_mval;
641 $this->_tpl_vars[$tpl_var][] = $value;
655 if ($tpl_var !=
'' && isset($value)) {
656 if(!@is_array($this->_tpl_vars[$tpl_var])) {
657 settype($this->_tpl_vars[$tpl_var],
'array');
659 if ($merge && is_array($value)) {
660 foreach($value as $_key => $_val) {
661 $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key];
664 $this->_tpl_vars[$tpl_var][] = &$value;
677 if (is_array($tpl_var))
678 foreach ($tpl_var as $curr_var)
679 unset($this->_tpl_vars[$curr_var]);
681 unset($this->_tpl_vars[$tpl_var]);
693 $this->_plugins[
'function'][$function] =
694 array($function_impl, null, null,
false, $cacheable, $cache_attrs);
705 unset($this->_plugins[
'function'][$function]);
720 settype($smarty_args,
'boolean');
721 $this->_reg_objects[$object] =
722 array(&$object_impl,
$allowed, $smarty_args, $block_methods);
732 unset($this->_reg_objects[$object]);
744 $this->_plugins[
'block'][$block] =
745 array($block_impl, null, null,
false, $cacheable, $cache_attrs);
755 unset($this->_plugins[
'block'][$block]);
766 $this->_plugins[
'compiler'][$function] =
767 array($function_impl, null, null,
false, $cacheable);
777 unset($this->_plugins[
'compiler'][$function]);
788 $this->_plugins[
'modifier'][$modifier] =
789 array($modifier_impl, null, null,
false);
799 unset($this->_plugins[
'modifier'][$modifier]);
810 if (count($functions)==4) {
811 $this->_plugins[
'resource'][
$type] =
812 array($functions,
false);
814 } elseif (count($functions)==5) {
815 $this->_plugins[
'resource'][
$type] =
816 array(array(array(&$functions[0], $functions[1])
817 ,array(&$functions[0], $functions[2])
818 ,array(&$functions[0], $functions[3])
819 ,array(&$functions[0], $functions[4]))
823 $this->
trigger_error(
"malformed function-list for '$type' in register_resource");
835 unset($this->_plugins[
'resource'][
$type]);
847 = array($function, null, null,
false);
869 = array($function, null, null,
false);
891 = array($function, null, null,
false);
914 $_params = array(
'plugins' => array(array(
$type .
'filter', $name, null, null,
false)));
915 require_once(SMARTY_CORE_DIR .
'core.load_plugins.php');
921 if (!isset($this->_plugins[
$type .
'filter'][$name]))
922 $this->_plugins[
$type .
'filter'][$name] =
false;
942 if (!isset($tpl_file))
947 if (!empty($this->cache_handler_func)) {
948 return call_user_func_array($this->cache_handler_func,
949 array(
'clear', &$this, &$dummy, $tpl_file, $cache_id,
$compile_id, $exp_time));
951 $_params = array(
'auto_base' => $this->cache_dir,
952 'auto_source' => $tpl_file,
953 'auto_id' => $_auto_id,
954 'exp_time' => $exp_time);
955 require_once(SMARTY_CORE_DIR .
'core.rm_auto.php');
970 return $this->
clear_cache(null, null, null, $exp_time);
991 'tpl_file' => $tpl_file,
992 'cache_id' => $cache_id,
995 require_once(SMARTY_CORE_DIR .
'core.read_cache_file.php');
1006 $this->_tpl_vars = array();
1024 $_params = array(
'auto_base' => $this->compile_dir,
1025 'auto_source' => $tpl_file,
1027 'exp_time' => $exp_time,
1028 'extensions' => array(
'.inc',
'.php'));
1029 require_once(SMARTY_CORE_DIR .
'core.rm_auto.php');
1041 $_params = array(
'resource_name' => $tpl_file,
'quiet'=>
true,
'get_source'=>
false);
1056 } elseif(isset($this->_tpl_vars[$name])) {
1057 return $this->_tpl_vars[$name];
1074 if(!isset($name) && is_array($this->_config[0])) {
1075 return $this->_config[0][
'vars'];
1076 }
else if(isset($this->_config[0][
'vars'][$name])) {
1077 return $this->_config[0][
'vars'][$name];
1093 $msg = htmlentities($error_msg);
1122 $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting)
1123 ? $this->error_reporting : error_reporting() & ~E_NOTICE);
1125 if (!$this->debugging && $this->debugging_ctrl ==
'URL') {
1126 $_query_string = $this->request_use_auto_globals ?
$_SERVER[
'QUERY_STRING'] :
$GLOBALS[
'HTTP_SERVER_VARS'][
'QUERY_STRING'];
1127 if (@strstr($_query_string, $this->_smarty_debug_id)) {
1128 if (@strstr($_query_string, $this->_smarty_debug_id .
'=on')) {
1130 @setcookie(
'SMARTY_DEBUG',
true);
1131 $this->debugging =
true;
1132 } elseif (@strstr($_query_string, $this->_smarty_debug_id .
'=off')) {
1134 @setcookie(
'SMARTY_DEBUG',
false);
1135 $this->debugging =
false;
1138 $this->debugging =
true;
1141 $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE[
'SMARTY_DEBUG'] : @
$GLOBALS[
'HTTP_COOKIE_VARS'][
'SMARTY_DEBUG']);
1145 if ($this->debugging) {
1148 require_once(SMARTY_CORE_DIR .
'core.get_microtime.php');
1150 $this->_smarty_debug_info[] = array(
'type' =>
'template',
1151 'filename' => $resource_name,
1153 $_included_tpls_idx = count($this->_smarty_debug_info) - 1;
1161 $this->_inclusion_depth = 0;
1166 $this->_cache_info = array();
1168 'tpl_file' => $resource_name,
1169 'cache_id' => $cache_id,
1173 require_once(SMARTY_CORE_DIR .
'core.read_cache_file.php');
1175 $_smarty_results = $_params[
'results'];
1176 if (!empty($this->_cache_info[
'insert_tags'])) {
1177 $_params = array(
'plugins' => $this->_cache_info[
'insert_tags']);
1178 require_once(SMARTY_CORE_DIR .
'core.load_plugins.php');
1180 $_params = array(
'results' => $_smarty_results);
1181 require_once(SMARTY_CORE_DIR .
'core.process_cached_inserts.php');
1184 if (!empty($this->_cache_info[
'cache_serials'])) {
1185 $_params = array(
'results' => $_smarty_results);
1186 require_once(SMARTY_CORE_DIR .
'core.process_compiled_include.php');
1192 if ($this->debugging)
1196 require_once(SMARTY_CORE_DIR .
'core.get_microtime.php');
1197 $this->_smarty_debug_info[$_included_tpls_idx][
'exec_time'] =
smarty_core_get_microtime($_params, $this) - $_debug_start_time;
1198 require_once(SMARTY_CORE_DIR .
'core.display_debug_console.php');
1201 if ($this->cache_modified_check) {
1203 $_last_modified_date = @substr($_server_vars[
'HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars[
'HTTP_IF_MODIFIED_SINCE'],
'GMT') + 3);
1204 $_gmt_mtime = gmdate(
'D, d M Y H:i:s', $this->_cache_info[
'timestamp']).
' GMT';
1205 if (@count($this->_cache_info[
'insert_tags']) == 0
1206 && !$this->_cache_serials
1207 && $_gmt_mtime == $_last_modified_date) {
1208 if (php_sapi_name()==
'cgi')
1209 header(
'Status: 304 Not Modified');
1211 header(
'HTTP/1.1 304 Not Modified');
1214 header(
'Last-Modified: '.$_gmt_mtime);
1215 echo $_smarty_results;
1218 echo $_smarty_results;
1220 error_reporting($_smarty_old_error_level);
1225 error_reporting($_smarty_old_error_level);
1228 return $_smarty_results;
1231 $this->_cache_info[
'template'][$resource_name] =
true;
1232 if ($this->cache_modified_check && $display) {
1233 header(
'Last-Modified: '.gmdate(
'D, d M Y H:i:s', time()).
' GMT');
1239 if (count($this->autoload_filters)) {
1240 foreach ($this->autoload_filters as $_filter_type => $_filters) {
1241 foreach ($_filters as $_filter) {
1252 $this->_cache_including =
false;
1253 if ($display && !$this->
caching && count($this->_plugins[
'outputfilter']) == 0) {
1254 if ($this->
_is_compiled($resource_name, $_smarty_compile_path)
1257 include($_smarty_compile_path);
1261 if ($this->
_is_compiled($resource_name, $_smarty_compile_path)
1264 include($_smarty_compile_path);
1266 $_smarty_results = ob_get_contents();
1269 foreach ((array)$this->_plugins[
'outputfilter'] as $_output_filter) {
1270 $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));
1275 $_params = array(
'tpl_file' => $resource_name,
1276 'cache_id' => $cache_id,
1278 'results' => $_smarty_results);
1279 require_once(SMARTY_CORE_DIR .
'core.write_cache_file.php');
1281 require_once(SMARTY_CORE_DIR .
'core.process_cached_inserts.php');
1284 if ($this->_cache_serials) {
1286 $_smarty_results = preg_replace(
'!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'
1296 if (isset($_smarty_results)) { echo $_smarty_results; }
1297 if ($this->debugging) {
1300 require_once(SMARTY_CORE_DIR .
'core.get_microtime.php');
1301 $this->_smarty_debug_info[$_included_tpls_idx][
'exec_time'] = (
smarty_core_get_microtime($_params, $this) - $_debug_start_time);
1302 require_once(SMARTY_CORE_DIR .
'core.display_debug_console.php');
1305 error_reporting($_smarty_old_error_level);
1308 error_reporting($_smarty_old_error_level);
1309 if (isset($_smarty_results)) {
return $_smarty_results; }
1333 if (!isset($this->_reg_objects[$name]))
1336 if (!is_object($this->_reg_objects[$name][0]))
1339 return $this->_reg_objects[$name][0];
1351 $this->_config = array(array(
'vars' => array(),
1352 'files' => array()));
1354 unset($this->_config[0][
'vars'][
$var]);
1367 $_params = array(
'type' =>
$type,
'name' => $name);
1368 require_once(SMARTY_CORE_DIR .
'core.assemble_plugin_filepath.php');
1381 if (!$this->force_compile && file_exists($compile_path)) {
1382 if (!$this->compile_check) {
1387 $_params = array(
'resource_name' => $resource_name,
'get_source'=>
false);
1391 if ($_params[
'resource_timestamp'] <= filemtime($compile_path)) {
1415 $_params = array(
'resource_name' => $resource_name);
1420 $_source_content = $_params[
'source_content'];
1425 if ($this->_cache_include_info) {
1426 require_once(SMARTY_CORE_DIR .
'core.write_compiled_include.php');
1430 $_params = array(
'compile_path'=>$compile_path,
'compiled_content' => $_compiled_content);
1431 require_once(SMARTY_CORE_DIR .
'core.write_compiled_resource.php');
1449 function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)
1451 if (file_exists(
SMARTY_DIR . $this->compiler_file)) {
1452 require_once(
SMARTY_DIR . $this->compiler_file);
1455 require_once($this->compiler_file);
1484 if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) {
1485 $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path];
1487 $smarty_compiler->_cache_include = $cache_include_path;
1490 $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);
1492 if ($smarty_compiler->_cache_serial) {
1493 $this->_cache_include_info = array(
1494 'cache_serial'=>$smarty_compiler->_cache_serial
1495 ,
'plugins_code'=>$smarty_compiler->_plugins_code
1496 ,
'include_file_path' => $cache_include_path);
1499 $this->_cache_include_info = null;
1515 $this->_compile_id) .
'.php';
1534 if(!isset($params[
'get_source'])) { $params[
'get_source'] =
true; }
1535 if(!isset($params[
'quiet'])) { $params[
'quiet'] =
false; }
1538 $_params = array(
'resource_name' => $params[
'resource_name']) ;
1539 if (isset($params[
'resource_base_path']))
1540 $_params[
'resource_base_path'] = $params[
'resource_base_path'];
1545 $_resource_type = $_params[
'resource_type'];
1546 $_resource_name = $_params[
'resource_name'];
1547 switch ($_resource_type) {
1549 if ($params[
'get_source']) {
1550 $params[
'source_content'] = $this->
_read_file($_resource_name);
1552 $params[
'resource_timestamp'] = filemtime($_resource_name);
1553 $_return = is_file($_resource_name) && is_readable($_resource_name);
1558 if ($params[
'get_source']) {
1559 $_source_return = isset($this->_plugins[
'resource'][$_resource_type]) &&
1560 call_user_func_array($this->_plugins[
'resource'][$_resource_type][0][0],
1561 array($_resource_name, &$params[
'source_content'], &$this));
1563 $_source_return =
true;
1566 $_timestamp_return = isset($this->_plugins[
'resource'][$_resource_type]) &&
1567 call_user_func_array($this->_plugins[
'resource'][$_resource_type][0][1],
1568 array($_resource_name, &$params[
'resource_timestamp'], &$this));
1570 $_return = $_source_return && $_timestamp_return;
1577 if (!empty($this->default_template_handler_func)) {
1578 if (!is_callable($this->default_template_handler_func)) {
1579 $this->
trigger_error(
"default template handler function \"$this->default_template_handler_func\" doesn't exist.");
1581 $_return = call_user_func_array(
1582 $this->default_template_handler_func,
1583 array($_params[
'resource_type'], $_params[
'resource_name'], &$params[
'source_content'], &$params[
'resource_timestamp'], &$this));
1589 if (!$params[
'quiet']) {
1590 $this->
trigger_error(
'unable to read resource: "' . $params[
'resource_name'] .
'"');
1592 }
else if ($_return && $this->security) {
1593 require_once(SMARTY_CORE_DIR .
'core.is_secure.php');
1595 if (!$params[
'quiet'])
1596 $this->
trigger_error(
'(secure mode) accessing "' . $params[
'resource_name'] .
'" is not allowed');
1597 $params[
'source_content'] = null;
1598 $params[
'resource_timestamp'] = null;
1620 $_resource_name_parts = explode(
':', $params[
'resource_name'], 2);
1622 if (count($_resource_name_parts) == 1) {
1625 $params[
'resource_name'] = $_resource_name_parts[0];
1627 if(strlen($_resource_name_parts[0]) == 1) {
1630 $params[
'resource_name'] = $params[
'resource_name'];
1632 $params[
'resource_type'] = $_resource_name_parts[0];
1633 $params[
'resource_name'] = $_resource_name_parts[1];
1637 if ($params[
'resource_type'] ==
'file') {
1638 if (!preg_match(
'/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params[
'resource_name'])) {
1641 foreach ((array)$params[
'resource_base_path'] as $_curr_path) {
1643 if (file_exists($_fullpath) && is_file($_fullpath)) {
1644 $params[
'resource_name'] = $_fullpath;
1648 $_params = array(
'file_path' => $_fullpath);
1649 require_once(SMARTY_CORE_DIR .
'core.get_include_path.php');
1651 $params[
'resource_name'] = $_params[
'new_file_path'];
1658 return file_exists($params[
'resource_name']);
1660 } elseif (empty($this->_plugins[
'resource'][$params[
'resource_type']])) {
1661 $_params = array(
'type' => $params[
'resource_type']);
1662 require_once(SMARTY_CORE_DIR .
'core.load_resource_plugin.php');
1679 $_args = func_get_args();
1680 list($_modifier_name, $_map_array) = array_splice($_args, 0, 2);
1681 list($_func_name, $_tpl_file, $_tpl_line) =
1682 $this->_plugins[
'modifier'][$_modifier_name];
1685 foreach ($_var as $_key => $_val) {
1687 $_var[$_key] = call_user_func_array($_func_name, $_args);
1700 if ((substr($string, 0, 1) ==
"'" || substr($string, 0, 1) ==
'"') &&
1701 substr($string, -1) == substr($string, 0, 1))
1702 return substr($string, 1, -1);
1716 if ( file_exists($filename) && is_readable($filename) && ($fd = @fopen($filename,
'rb')) ) {
1718 while (!feof($fd)) {
1719 $contents .= fread($fd, 8192);
1743 if(isset($auto_id)) {
1745 $auto_id = str_replace(
'%7C',$_compile_dir_sep,(urlencode($auto_id)));
1747 $_return .= $auto_id . $_compile_dir_sep;
1750 if(isset($auto_source)) {
1752 $_filename = urlencode(basename($auto_source));
1753 $_crc32 = sprintf(
'%08X', crc32($auto_source));
1756 $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep .
1757 substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32;
1758 $_return .=
'%%' . $_crc32 .
'%%' . $_filename;
1772 if(isset($exp_time)) {
1773 if(time() - @filemtime($resource) >= $exp_time) {
1774 return @unlink($resource);
1777 return @unlink($resource);
1789 if (isset($cache_id))
1808 $file = null, $line = null, $error_type = E_USER_ERROR)
1810 if(isset(
$file) && isset($line)) {
1811 $info =
' ('.basename(
$file).
", line $line)";
1815 if (isset($tpl_line) && isset($tpl_file)) {
1816 $this->
trigger_error(
'[in ' . $tpl_file .
' line ' . $tpl_line .
"]: $error_msg$info", $error_type);
1828 $_func =
'_smarty_tplfunc_'.$match[2].
'_'.$match[3];
1831 $_ret = ob_get_contents();
1848 if ($this->debugging) {
1850 require_once(SMARTY_CORE_DIR .
'core.get_microtime.php');
1852 $this->_smarty_debug_info[] = array(
'type' =>
'template',
1853 'filename' => $params[
'smarty_include_tpl_file'],
1854 'depth' => ++$this->_inclusion_depth);
1855 $included_tpls_idx = count($this->_smarty_debug_info) - 1;
1858 $this->_tpl_vars = array_merge($this->_tpl_vars, $params[
'smarty_include_vars']);
1862 array_unshift($this->_config, $this->_config[0]);
1864 $_smarty_compile_path = $this->
_get_compile_path($params[
'smarty_include_tpl_file']);
1867 if ($this->
_is_compiled($params[
'smarty_include_tpl_file'], $_smarty_compile_path)
1868 || $this->
_compile_resource($params[
'smarty_include_tpl_file'], $_smarty_compile_path))
1870 include($_smarty_compile_path);
1874 array_shift($this->_config);
1876 $this->_inclusion_depth--;
1878 if ($this->debugging) {
1881 require_once(SMARTY_CORE_DIR .
'core.get_microtime.php');
1882 $this->_smarty_debug_info[$included_tpls_idx][
'exec_time'] =
smarty_core_get_microtime($_params, $this) - $debug_start_time;
1886 $this->_cache_info[
'template'][$params[
'smarty_include_tpl_file']] =
true;
1897 $_cache_attrs =& $this->_cache_info[
'cache_attrs'][$cache_serial][$count];
1899 if ($this->_cache_including) {
1901 $_return = current($_cache_attrs);
1902 next($_cache_attrs);
1907 $_cache_attrs[] = array();
1908 return $_cache_attrs[count($_cache_attrs)-1];
1919 function _include($filename, $once=
false, $params=null)
1922 return include_once($filename);
1924 return include($filename);
1946 if (is_array($function)) {
1947 $_class_name = (is_object($function[0]) ?
1948 get_class($function[0]) : $function[0]);
1949 return $_class_name .
'_' . $function[1];