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_cachemodify.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Inline Runtime Methods render, setSourceByUid, setupSubTemplate
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsInternal
  7. * @author Uwe Tews
  8. *
  9. **/
  10. class Smarty_Internal_Runtime_CacheModify
  11. {
  12. /**
  13. * check client side cache
  14. *
  15. * @param Smarty_Internal_Template $_template
  16. * @param string $content
  17. */
  18. public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
  19. {
  20. $_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
  21. $_last_modified_date =
  22. @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
  23. if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) {
  24. switch (PHP_SAPI) {
  25. case 'cgi': // php-cgi < 5.3
  26. case 'cgi-fcgi': // php-cgi >= 5.3
  27. case 'fpm-fcgi': // php-fpm >= 5.3.3
  28. header('Status: 304 Not Modified');
  29. break;
  30. case 'cli':
  31. if ( /* ^phpunit */
  32. !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
  33. ) {
  34. $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
  35. }
  36. break;
  37. default:
  38. if ( /* ^phpunit */
  39. !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
  40. ) {
  41. $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
  42. } else {
  43. header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
  44. }
  45. break;
  46. }
  47. } else {
  48. switch (PHP_SAPI) {
  49. case 'cli':
  50. if ( /* ^phpunit */
  51. !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
  52. ) {
  53. $_SERVER['SMARTY_PHPUNIT_HEADERS'][] =
  54. 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT';
  55. }
  56. break;
  57. default:
  58. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT');
  59. break;
  60. }
  61. echo $content;
  62. }
  63. }
  64. }