libs/Smarty.class.php Quellcode

Smarty.class.php
gehe zur Dokumentation dieser Datei
1 <?php
36 if (!defined('DS')) {
37  define('DS', DIRECTORY_SEPARATOR);
38 }
39 
44 if (!defined('SMARTY_DIR')) {
45  define('SMARTY_DIR', dirname(__FILE__) . DS);
46 }
47 
52 if (!defined('SMARTY_SYSPLUGINS_DIR')) {
53  define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);
54 }
55 if (!defined('SMARTY_PLUGINS_DIR')) {
56  define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS);
57 }
58 if (!defined('SMARTY_MBSTRING')) {
59  define('SMARTY_MBSTRING', function_exists('mb_get_info'));
60 }
61 if (!defined('SMARTY_RESOURCE_CHAR_SET')) {
62  // UTF-8 can only be done properly when mbstring is available!
66  define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1');
67 }
68 if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
72  define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');
73 }
74 
80 if (!class_exists('Smarty_Autoloader', false)) {
81  if (!class_exists('Smarty_Internal_Data', true)) {
82  require_once 'Autoloader.php';
84  }
85 }
86 
91 if (!class_exists('Smarty_Internal_Data', false)) {
92  require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
93 }
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';
99 
106 {
114  const SMARTY_VERSION = '3.1.27';
115 
119  const SCOPE_LOCAL = 0;
120 
121  const SCOPE_PARENT = 1;
122 
123  const SCOPE_ROOT = 2;
124 
125  const SCOPE_GLOBAL = 3;
126 
130  const CACHING_OFF = 0;
131 
133 
135 
139  const CLEAR_EXPIRED = - 1;
140 
144  const COMPILECHECK_OFF = 0;
145 
146  const COMPILECHECK_ON = 1;
147 
149 
153  const DEBUG_OFF = 0;
154 
155  const DEBUG_ON = 1;
156 
157  const DEBUG_INDIVIDUAL = 2;
158 
162  const PHP_PASSTHRU = 0; //-> print tags as plain text
163 
164  const PHP_QUOTE = 1; //-> escape tags as entities
165 
166  const PHP_REMOVE = 2; //-> escape tags as entities
167 
168  const PHP_ALLOW = 3; //-> escape tags as entities
169 
173  const FILTER_POST = 'post';
174 
175  const FILTER_PRE = 'pre';
176 
177  const FILTER_OUTPUT = 'output';
178 
179  const FILTER_VARIABLE = 'variable';
180 
184  const PLUGIN_FUNCTION = 'function';
185 
186  const PLUGIN_BLOCK = 'block';
187 
188  const PLUGIN_COMPILER = 'compiler';
189 
190  const PLUGIN_MODIFIER = 'modifier';
191 
192  const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler';
193 
199  public static $global_tpl_vars = array();
200 
204  public static $_previous_error_handler = null;
205 
209  public static $_muted_directories = array('./templates_c/' => null, './cache/' => null);
210 
214  public static $_MBSTRING = SMARTY_MBSTRING;
215 
219  public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET;
220 
225  public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT;
226 
230  public static $_UTF8_MODIFIER = 'u';
231 
235  public static $_IS_WINDOWS = false;
236 
246  public $auto_literal = true;
247 
253  public $error_unassigned = false;
254 
260  public $use_include_path = false;
261 
267  private $template_dir = array('./templates/');
268 
274  public $joined_template_dir = './templates/';
275 
281  public $joined_config_dir = './configs/';
282 
289 
296 
303 
309  private $compile_dir = './templates_c/';
310 
316  private $plugins_dir = null;
317 
323  private $cache_dir = './cache/';
324 
330  private $config_dir = array('./configs/');
331 
337  public $force_compile = false;
338 
344  public $compile_check = true;
345 
351  public $use_sub_dirs = false;
352 
359 
365  public $merge_compiled_includes = false;
366 
373 
379  public $force_cache = false;
380 
386  public $left_delimiter = "{";
387 
393  public $right_delimiter = "}";
394 
405  public $security_class = 'Smarty_Security';
406 
412  public $security_policy = null;
413 
419  public $php_handling = self::PHP_PASSTHRU;
420 
426  public $allow_php_templates = false;
427 
436  public $direct_access_security = true;
437 
445  public $debugging = false;
446 
456  public $debugging_ctrl = 'NONE';
457 
465  public $smarty_debug_id = 'SMARTY_DEBUG';
466 
472  public $debug_tpl = null;
473 
479  public $error_reporting = null;
480 
486  public $get_used_tags = false;
487 
497  public $config_overwrite = true;
498 
504  public $config_booleanize = true;
505 
511  public $config_read_hidden = false;
512 
524  public $compile_locking = true;
525 
531  public $cache_locking = false;
532 
538  public $locking_timeout = 10;
539 
548  public $default_resource_type = 'file';
549 
556  public $caching_type = 'file';
557 
563  public $properties = array();
564 
570  public $default_config_type = 'file';
571 
577  public $source_objects = array();
578 
584  public $template_objects = array();
585 
591  public $resource_caching = false;
592 
599 
605  public $cache_modified_check = false;
606 
612  public $registered_plugins = array();
613 
619  public $plugin_search_order = array('function', 'block', 'compiler', 'class');
620 
626  public $registered_objects = array();
627 
633  public $registered_classes = array();
634 
640  public $registered_filters = array();
641 
647  public $registered_resources = array();
648 
654  public $_resource_handlers = array();
655 
661  public $registered_cache_resources = array();
662 
668  public $_cacheresource_handlers = array();
669 
675  public $autoload_filters = array();
676 
682  public $default_modifiers = array();
683 
689  public $escape_html = false;
690 
696  public static $_smarty_vars = array();
697 
703  public $start_time = 0;
704 
710  public $_file_perms = 0644;
711 
717  public $_dir_perms = 0771;
718 
724  public $_tag_stack = array();
725 
731  public $_current_file = null;
732 
738  public $_parserdebug = false;
739 
745  public $_is_file_cache = array();
746 
752  public function __construct()
753  {
754  if (is_callable('mb_internal_encoding')) {
755  mb_internal_encoding(Smarty::$_CHARSET);
756  }
757  $this->start_time = microtime(true);
758  // check default dirs for overloading
759  if ($this->template_dir[0] !== './templates/' || isset($this->template_dir[1])) {
760  $this->setTemplateDir($this->template_dir);
761  }
762  if ($this->config_dir[0] !== './configs/' || isset($this->config_dir[1])) {
763  $this->setConfigDir($this->config_dir);
764  }
765  if ($this->compile_dir !== './templates_c/') {
766  unset(self::$_muted_directories['./templates_c/']);
767  $this->setCompileDir($this->compile_dir);
768  }
769  if ($this->cache_dir !== './cache/') {
770  unset(self::$_muted_directories['./cache/']);
771  $this->setCacheDir($this->cache_dir);
772  }
773  if (isset($this->plugins_dir)) {
774  $this->setPluginsDir($this->plugins_dir);
775  } else {
776  $this->setPluginsDir(SMARTY_PLUGINS_DIR);
777  }
778  if (isset($_SERVER['SCRIPT_NAME'])) {
779  Smarty::$global_tpl_vars['SCRIPT_NAME'] = new Smarty_Variable($_SERVER['SCRIPT_NAME']);
780  }
781 
782  // Check if we're running on windows
783  Smarty::$_IS_WINDOWS = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
784 
785  // let PCRE (preg_*) treat strings as ISO-8859-1 if we're not dealing with UTF-8
786  if (Smarty::$_CHARSET !== 'UTF-8') {
788  }
789  }
790 
806  public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
807  {
808  if ($cache_id !== null && is_object($cache_id)) {
809  $parent = $cache_id;
810  $cache_id = null;
811  }
812  if ($parent === null) {
813  $parent = $this;
814  }
815  // get template object
816  $_template = is_object($template) ? $template : $this->createTemplate($template, $cache_id, $compile_id, $parent, false);
817  // set caching in template object
818  $_template->caching = $this->caching;
819  // fetch template content
820  return $_template->render(true, false, $display);
821  }
822 
831  public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
832  {
833  // display template
834  $this->fetch($template, $cache_id, $compile_id, $parent, true);
835  }
836 
844  public function templateExists($resource_name)
845  {
846  // create template object
847  $save = $this->template_objects;
848  $tpl = new $this->template_class($resource_name, $this);
849  // check if it does exists
850  $result = $tpl->source->exists;
851  $this->template_objects = $save;
852 
853  return $result;
854  }
855 
863  public function getGlobal($varname = null)
864  {
865  if (isset($varname)) {
866  if (isset(self::$global_tpl_vars[$varname])) {
867  return self::$global_tpl_vars[$varname]->value;
868  } else {
869  return '';
870  }
871  } else {
872  $_result = array();
873  foreach (self::$global_tpl_vars AS $key => $var) {
874  $_result[$key] = $var->value;
875  }
876 
877  return $_result;
878  }
879  }
880 
889  public function clearAllCache($exp_time = null, $type = null)
890  {
891  // load cache resource and call clearAll
892  $_cache_resource = Smarty_CacheResource::load($this, $type);
894 
895  return $_cache_resource->clearAll($this, $exp_time);
896  }
897 
909  public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
910  {
911  // load cache resource and call clear
912  $_cache_resource = Smarty_CacheResource::load($this, $type);
914 
915  return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
916  }
917 
926  public function enableSecurity($security_class = null)
927  {
928  if ($security_class instanceof Smarty_Security) {
929  $this->security_policy = $security_class;
930 
931  return $this;
932  } elseif (is_object($security_class)) {
933  throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
934  }
935  if ($security_class == null) {
937  }
938  if (!class_exists($security_class)) {
939  throw new SmartyException("Security class '$security_class' is not defined");
940  } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
941  throw new SmartyException("Class '$security_class' must extend Smarty_Security.");
942  } else {
943  $this->security_policy = new $security_class($this);
944  }
945 
946  return $this;
947  }
948 
954  public function disableSecurity()
955  {
956  $this->security_policy = null;
957 
958  return $this;
959  }
960 
968  public function setTemplateDir($template_dir)
969  {
970  $this->template_dir = array();
971  foreach ((array) $template_dir as $k => $v) {
972  $this->template_dir[$k] = rtrim($v, '/\\') . DS;
973  }
974  $this->joined_template_dir = join(' # ', $this->template_dir);
975  return $this;
976  }
977 
987  public function addTemplateDir($template_dir, $key = null)
988  {
989  $this->_addDir('template_dir', $template_dir, $key);
990  $this->joined_template_dir = join(' # ', $this->template_dir);
991  return $this;
992  }
993 
1001  public function getTemplateDir($index = null)
1002  {
1003  if ($index !== null) {
1004  return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null;
1005  }
1006  return (array) $this->template_dir;
1007  }
1008 
1016  public function setConfigDir($config_dir)
1017  {
1018  $this->config_dir = array();
1019  foreach ((array) $config_dir as $k => $v) {
1020  $this->config_dir[$k] = rtrim($v, '/\\') . DS;
1021  }
1022  $this->joined_config_dir = join(' # ', $this->config_dir);
1023  return $this;
1024  }
1025 
1034  public function addConfigDir($config_dir, $key = null)
1035  {
1036  $this->_addDir('config_dir', $config_dir, $key);
1037  $this->joined_config_dir = join(' # ', $this->config_dir);
1038  return $this;
1039  }
1040 
1048  public function getConfigDir($index = null)
1049  {
1050  if ($index !== null) {
1051  return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null;
1052  }
1053  return (array) $this->config_dir;
1054  }
1055 
1063  public function setPluginsDir($plugins_dir)
1064  {
1065  $this->plugins_dir = array();
1066  $this->addPluginsDir($plugins_dir);
1067  return $this;
1068  }
1069 
1077  public function addPluginsDir($plugins_dir)
1078  {
1079  // make sure we're dealing with an array
1080  $this->plugins_dir = (array) $this->plugins_dir;
1081  foreach ((array) $plugins_dir as $v) {
1082  $this->plugins_dir[] = rtrim($v, '/\\') . DS;
1083  }
1084  $this->plugins_dir = array_unique($this->plugins_dir);
1085  $this->_is_file_cache = array();
1086  return $this;
1087  }
1088 
1094  public function getPluginsDir()
1095  {
1096  return (array) $this->plugins_dir;
1097  }
1098 
1106  public function setCompileDir($compile_dir)
1107  {
1108  $this->compile_dir = rtrim($compile_dir, '/\\') . DS;
1109  if (!isset(Smarty::$_muted_directories[$this->compile_dir])) {
1111  }
1112 
1113  return $this;
1114  }
1115 
1121  public function getCompileDir()
1122  {
1123  return $this->compile_dir;
1124  }
1125 
1133  public function setCacheDir($cache_dir)
1134  {
1135  $this->cache_dir = rtrim($cache_dir, '/\\') . DS;
1136  if (!isset(Smarty::$_muted_directories[$this->cache_dir])) {
1138  }
1139  return $this;
1140  }
1141 
1147  public function getCacheDir()
1148  {
1149  return $this->cache_dir;
1150  }
1151 
1159  private function _addDir($dirName, $dir, $key = null)
1160  {
1161  // make sure we're dealing with an array
1162  $this->$dirName = (array) $this->$dirName;
1163 
1164  if (is_array($dir)) {
1165  foreach ($dir as $k => $v) {
1166  if (is_int($k)) {
1167  // indexes are not merged but appended
1168  $this->{$dirName}[] = rtrim($v, '/\\') . DS;
1169  } else {
1170  // string indexes are overridden
1171  $this->{$dirName}[$k] = rtrim($v, '/\\') . DS;
1172  }
1173  }
1174  } else {
1175  if ($key !== null) {
1176  // override directory at specified index
1177  $this->{$dirName}[$key] = rtrim($dir, '/\\') . DS;
1178  } else {
1179  // append new directory
1180  $this->{$dirName}[] = rtrim($dir, '/\\') . DS;
1181  }
1182  }
1183  }
1184 
1192  public function setDefaultModifiers($modifiers)
1193  {
1194  $this->default_modifiers = (array) $modifiers;
1195 
1196  return $this;
1197  }
1198 
1206  public function addDefaultModifiers($modifiers)
1207  {
1208  if (is_array($modifiers)) {
1209  $this->default_modifiers = array_merge($this->default_modifiers, $modifiers);
1210  } else {
1211  $this->default_modifiers[] = $modifiers;
1212  }
1213 
1214  return $this;
1215  }
1216 
1222  public function getDefaultModifiers()
1223  {
1224  return $this->default_modifiers;
1225  }
1226 
1236  public function setAutoloadFilters($filters, $type = null)
1237  {
1238  if ($type !== null) {
1239  $this->autoload_filters[$type] = (array) $filters;
1240  } else {
1241  $this->autoload_filters = (array) $filters;
1242  }
1243 
1244  return $this;
1245  }
1246 
1256  public function addAutoloadFilters($filters, $type = null)
1257  {
1258  if ($type !== null) {
1259  if (!empty($this->autoload_filters[$type])) {
1260  $this->autoload_filters[$type] = array_merge($this->autoload_filters[$type], (array) $filters);
1261  } else {
1262  $this->autoload_filters[$type] = (array) $filters;
1263  }
1264  } else {
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);
1268  } else {
1269  $this->autoload_filters[$key] = (array) $value;
1270  }
1271  }
1272  }
1273 
1274  return $this;
1275  }
1276 
1285  public function getAutoloadFilters($type = null)
1286  {
1287  if ($type !== null) {
1288  return isset($this->autoload_filters[$type]) ? $this->autoload_filters[$type] : array();
1289  }
1290 
1291  return $this->autoload_filters;
1292  }
1293 
1299  public function getDebugTemplate()
1300  {
1301  return $this->debug_tpl;
1302  }
1303 
1312  public function setDebugTemplate($tpl_name)
1313  {
1314  if (!is_readable($tpl_name)) {
1315  throw new SmartyException("Unknown file '{$tpl_name}'");
1316  }
1317  $this->debug_tpl = $tpl_name;
1318 
1319  return $this;
1320  }
1321 
1333  public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
1334  {
1335  if ($cache_id !== null && (is_object($cache_id) || is_array($cache_id))) {
1336  $parent = $cache_id;
1337  $cache_id = null;
1338  }
1339  if ($parent !== null && is_array($parent)) {
1340  $data = $parent;
1341  $parent = null;
1342  } else {
1343  $data = null;
1344  }
1345  $_templateId = $this->getTemplateId($template, $cache_id, $compile_id);
1346  if (isset($this->template_objects[$_templateId])) {
1347  if ($do_clone) {
1348  $tpl = clone $this->template_objects[$_templateId];
1349  $tpl->smarty = clone $tpl->smarty;
1350  } else {
1351  $tpl = $this->template_objects[$_templateId];
1352  }
1353  $tpl->parent = $parent;
1354  $tpl->tpl_vars = array();
1355  $tpl->config_vars = array();
1356  } else {
1357  $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
1358  if ($do_clone) {
1359  $tpl->smarty = clone $tpl->smarty;
1360  }
1361  $tpl->templateId = $_templateId;
1362  }
1363  // fill data if present
1364  if (!empty($data) && is_array($data)) {
1365  // set up variable values
1366  foreach ($data as $_key => $_val) {
1367  $tpl->tpl_vars[$_key] = new Smarty_Variable($_val);
1368  }
1369  }
1370  if ($this->debugging) {
1372  }
1373  return $tpl;
1374  }
1375 
1387  public function loadPlugin($plugin_name, $check = true)
1388  {
1389  // if function or class exists, exit silently (already loaded)
1390  if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) {
1391  return true;
1392  }
1393  // Plugin name is expected to be: Smarty_[Type]_[Name]
1394  $_name_parts = explode('_', $plugin_name, 3);
1395  // class name must have three parts to be valid plugin
1396  // count($_name_parts) < 3 === !isset($_name_parts[2])
1397  if (!isset($_name_parts[2]) || strtolower($_name_parts[0]) !== 'smarty') {
1398  throw new SmartyException("plugin {$plugin_name} is not a valid name format");
1399  }
1400  // if type is "internal", get plugin from sysplugins
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);
1405  return $file;
1406  } else {
1407  return false;
1408  }
1409  }
1410  // plugin filename is expected to be: [type].[name].php
1411  $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
1412 
1413  $_stream_resolve_include_path = function_exists('stream_resolve_include_path');
1414 
1415  // loop through plugin dirs and find the plugin
1416  foreach ($this->getPluginsDir() as $_plugin_dir) {
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);
1421  return $file;
1422  }
1423  if ($this->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
1424  // try PHP include_path
1425  if ($_stream_resolve_include_path) {
1426  $file = stream_resolve_include_path($file);
1427  } else {
1429  }
1430 
1431  if ($file !== false) {
1432  require_once($file);
1433 
1434  return $file;
1435  }
1436  }
1437  }
1438  }
1439  // no plugin loaded
1440  return false;
1441  }
1442 
1453  public function compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
1454  {
1455  return Smarty_Internal_Utility::compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, $this);
1456  }
1457 
1468  public function compileAllConfig($extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
1469  {
1470  return Smarty_Internal_Utility::compileAllConfig($extension, $force_compile, $time_limit, $max_errors, $this);
1471  }
1472 
1482  public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
1483  {
1484  return Smarty_Internal_Utility::clearCompiledTemplate($resource_name, $compile_id, $exp_time, $this);
1485  }
1486 
1494  public function getTags(Smarty_Internal_Template $template)
1495  {
1496  return Smarty_Internal_Utility::getTags($template);
1497  }
1498 
1506  public function testInstall(&$errors = null)
1507  {
1508  return Smarty_Internal_TestInstall::testInstall($this, $errors);
1509  }
1510 
1515  {
1516  $this->compile_check = $compile_check;
1517  }
1518 
1522  public function setUseSubDirs($use_sub_dirs)
1523  {
1524  $this->use_sub_dirs = $use_sub_dirs;
1525  }
1526 
1530  public function setCaching($caching)
1531  {
1532  $this->caching = $caching;
1533  }
1534 
1539  {
1540  $this->cache_lifetime = $cache_lifetime;
1541  }
1542 
1546  public function setCompileId($compile_id)
1547  {
1548  $this->compile_id = $compile_id;
1549  }
1550 
1554  public function setCacheId($cache_id)
1555  {
1556  $this->cache_id = $cache_id;
1557  }
1558 
1563  {
1564  $this->error_reporting = $error_reporting;
1565  }
1566 
1570  public function setEscapeHtml($escape_html)
1571  {
1572  $this->escape_html = $escape_html;
1573  }
1574 
1579  {
1580  $this->auto_literal = $auto_literal;
1581  }
1582 
1587  {
1588  $this->force_compile = $force_compile;
1589  }
1590 
1595  {
1596  $this->merge_compiled_includes = $merge_compiled_includes;
1597  }
1598 
1603  {
1604  $this->left_delimiter = $left_delimiter;
1605  }
1606 
1611  {
1612  $this->right_delimiter = $right_delimiter;
1613  }
1614 
1618  public function setDebugging($debugging)
1619  {
1620  $this->debugging = $debugging;
1621  }
1622 
1627  {
1628  $this->config_overwrite = $config_overwrite;
1629  }
1630 
1635  {
1636  $this->config_booleanize = $config_booleanize;
1637  }
1638 
1643  {
1644  $this->config_read_hidden = $config_read_hidden;
1645  }
1646 
1651  {
1652  $this->compile_locking = $compile_locking;
1653  }
1654 
1658  public function __destruct()
1659  {
1660  // intentionally left blank
1661  }
1662 
1672  public function __get($name)
1673  {
1674  $allowed = array('template_dir' => 'getTemplateDir', 'config_dir' => 'getConfigDir',
1675  'plugins_dir' => 'getPluginsDir', 'compile_dir' => 'getCompileDir',
1676  'cache_dir' => 'getCacheDir',);
1677 
1678  if (isset($allowed[$name])) {
1679  return $this->{$allowed[$name]}();
1680  } else {
1681  trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
1682  }
1683  }
1684 
1693  public function __set($name, $value)
1694  {
1695  $allowed = array('template_dir' => 'setTemplateDir', 'config_dir' => 'setConfigDir',
1696  'plugins_dir' => 'setPluginsDir', 'compile_dir' => 'setCompileDir',
1697  'cache_dir' => 'setCacheDir',);
1698 
1699  if (isset($allowed[$name])) {
1700  $this->{$allowed[$name]}($value);
1701  } else {
1702  trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
1703  }
1704  }
1705 
1719  public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
1720  {
1721  $_is_muted_directory = false;
1722 
1723  // add the SMARTY_DIR to the list of muted directories
1724  if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) {
1725  $smarty_dir = realpath(SMARTY_DIR);
1726  if ($smarty_dir !== false) {
1727  Smarty::$_muted_directories[SMARTY_DIR] = array('file' => $smarty_dir,
1728  'length' => strlen($smarty_dir),);
1729  }
1730  }
1731 
1732  // walk the muted directories and test against $errfile
1733  foreach (Smarty::$_muted_directories as $key => &$dir) {
1734  if (!$dir) {
1735  // resolve directory and length for speedy comparisons
1736  $file = realpath($key);
1737  if ($file === false) {
1738  // this directory does not exist, remove and skip it
1739  unset(Smarty::$_muted_directories[$key]);
1740  continue;
1741  }
1742  $dir = array('file' => $file, 'length' => strlen($file),);
1743  }
1744  if (!strncmp($errfile, $dir['file'], $dir['length'])) {
1745  $_is_muted_directory = true;
1746  break;
1747  }
1748  }
1749 
1750  // pass to next error handler if this error did not occur inside SMARTY_DIR
1751  // or the error was within smarty but masked to be ignored
1752  if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
1754  return call_user_func(Smarty::$_previous_error_handler, $errno, $errstr, $errfile, $errline, $errcontext);
1755  } else {
1756  return false;
1757  }
1758  }
1759  }
1760 
1766  public static function muteExpectedErrors()
1767  {
1768  /*
1769  error muting is done because some people implemented custom error_handlers using
1770  http://php.net/set_error_handler and for some reason did not understand the following paragraph:
1771 
1772  It is important to remember that the standard PHP error handler is completely bypassed for the
1773  error types specified by error_types unless the callback function returns FALSE.
1774  error_reporting() settings will have no effect and your error handler will be called regardless -
1775  however you are still able to read the current value of error_reporting and act appropriately.
1776  Of particular note is that this value will be 0 if the statement that caused the error was
1777  prepended by the @ error-control operator.
1778 
1779  Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include
1780  - @filemtime() is almost twice as fast as using an additional file_exists()
1781  - between file_exists() and filemtime() a possible race condition is opened,
1782  which does not exist using the simple @filemtime() approach.
1783  */
1784  $error_handler = array('Smarty', 'mutingErrorHandler');
1785  $previous = set_error_handler($error_handler);
1786 
1787  // avoid dead loops
1788  if ($previous !== $error_handler) {
1790  }
1791  }
1792 
1798  public static function unmuteExpectedErrors()
1799  {
1800  restore_error_handler();
1801  }
1802 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.