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_resource_php.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource PHP
  4. * Implements the file system as resource for PHP templates
  5. *
  6. * @package Smarty
  7. * @subpackage TemplateResources
  8. * @author Uwe Tews
  9. * @author Rodney Rehm
  10. */
  11. class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
  12. {
  13. /**
  14. * Flag that it's an uncompiled resource
  15. *
  16. * @var bool
  17. */
  18. public $uncompiled = true;
  19. /**
  20. * Resource does implement populateCompiledFilepath() method
  21. *
  22. * @var bool
  23. */
  24. public $hasCompiledHandler = true;
  25. /**
  26. * container for short_open_tag directive's value before executing PHP templates
  27. *
  28. * @var string
  29. */
  30. protected $short_open_tag;
  31. /**
  32. * Create a new PHP Resource
  33. */
  34. public function __construct()
  35. {
  36. $this->short_open_tag = function_exists('ini_get') ? ini_get('short_open_tag') : 1;
  37. }
  38. /**
  39. * Load template's source from file into current template object
  40. *
  41. * @param Smarty_Template_Source $source source object
  42. *
  43. * @return string template source
  44. * @throws SmartyException if source cannot be loaded
  45. */
  46. public function getContent(Smarty_Template_Source $source)
  47. {
  48. if ($source->exists) {
  49. return '';
  50. }
  51. throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
  52. }
  53. /**
  54. * populate compiled object with compiled filepath
  55. *
  56. * @param Smarty_Template_Compiled $compiled compiled object
  57. * @param Smarty_Internal_Template $_template template object (is ignored)
  58. */
  59. public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
  60. {
  61. $compiled->filepath = $_template->source->filepath;
  62. $compiled->timestamp = $_template->source->timestamp;
  63. $compiled->exists = $_template->source->exists;
  64. $compiled->file_dependency[ $_template->source->uid ] =
  65. array($compiled->filepath,
  66. $compiled->timestamp,
  67. $_template->source->type,);
  68. }
  69. /**
  70. * Render and output the template (without using the compiler)
  71. *
  72. * @param Smarty_Template_Source $source source object
  73. * @param Smarty_Internal_Template $_template template object
  74. *
  75. * @return void
  76. * @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
  77. */
  78. public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
  79. {
  80. if (!$source->smarty->allow_php_templates) {
  81. throw new SmartyException('PHP templates are disabled');
  82. }
  83. if (!$source->exists) {
  84. throw new SmartyException("Unable to load template '{$source->type}:{$source->name}'" .
  85. ($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : ''));
  86. }
  87. // prepare variables
  88. extract($_template->getTemplateVars());
  89. // include PHP template with short open tags enabled
  90. if (function_exists('ini_set')) {
  91. ini_set('short_open_tag', '1');
  92. }
  93. /** @var Smarty_Internal_Template $_smarty_template
  94. * used in included file
  95. */
  96. $_smarty_template = $_template;
  97. include($source->filepath);
  98. if (function_exists('ini_set')) {
  99. ini_set('short_open_tag', $this->short_open_tag);
  100. }
  101. }
  102. }