You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_runtime_validatecompiled.php 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Runtime Methods decodeProperties
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsInternal
  7. * @author Uwe Tews
  8. *
  9. **/
  10. class Smarty_Internal_Runtime_ValidateCompiled
  11. {
  12. /**
  13. * This function is executed automatically when a compiled or cached template file is included
  14. * - Decode saved properties from compiled template and cache files
  15. * - Check if compiled or cache file is valid
  16. *
  17. * @param array $properties special template properties
  18. * @param bool $cache flag if called from cache file
  19. *
  20. * @return bool flag if compiled or cache file is valid
  21. */
  22. public function decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false)
  23. {
  24. $is_valid = true;
  25. if (Smarty::SMARTY_VERSION != $properties['version']) {
  26. // new version must rebuild
  27. $is_valid = false;
  28. } elseif ($is_valid && !empty($properties['file_dependency']) &&
  29. ((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1)
  30. ) {
  31. // check file dependencies at compiled code
  32. foreach ($properties['file_dependency'] as $_file_to_check) {
  33. if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') {
  34. if ($tpl->source->filepath == $_file_to_check[0]) {
  35. // do not recheck current template
  36. continue;
  37. //$mtime = $tpl->source->getTimeStamp();
  38. } else {
  39. // file and php types can be checked without loading the respective resource handlers
  40. $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false;
  41. }
  42. } elseif ($_file_to_check[2] == 'string') {
  43. continue;
  44. } else {
  45. $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]);
  46. if ($handler->checkTimestamps()) {
  47. $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]);
  48. $mtime = $source->getTimeStamp();
  49. } else {
  50. continue;
  51. }
  52. }
  53. if (!$mtime || $mtime > $_file_to_check[1]) {
  54. $is_valid = false;
  55. break;
  56. }
  57. }
  58. }
  59. if ($cache) {
  60. // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
  61. if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 &&
  62. (time() > ($tpl->cached->timestamp + $properties['cache_lifetime']))
  63. ) {
  64. $is_valid = false;
  65. }
  66. $tpl->cached->cache_lifetime = $properties['cache_lifetime'];
  67. $tpl->cached->valid = $is_valid;
  68. $resource = $tpl->cached;
  69. } else {
  70. $tpl->mustCompile = !$is_valid;
  71. $resource = $tpl->compiled;
  72. $resource->includes = isset($properties['includes']) ? $properties['includes'] : array();
  73. }
  74. if ($is_valid) {
  75. $resource->unifunc = $properties['unifunc'];
  76. $resource->has_nocache_code = $properties['has_nocache_code'];
  77. // $tpl->compiled->nocache_hash = $properties['nocache_hash'];
  78. $resource->file_dependency = $properties['file_dependency'];
  79. if (isset($properties['tpl_function'])) {
  80. $tpl->tpl_function = $properties['tpl_function'];
  81. }
  82. }
  83. return $is_valid && !function_exists($properties['unifunc']);
  84. }
  85. }