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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. * container for short_open_tag directive's value before executing PHP templates
  21. *
  22. * @var string
  23. */
  24. protected $short_open_tag;
  25. /**
  26. * Resource does implement populateCompiledFilepath() method
  27. *
  28. * @var bool
  29. */
  30. public $hasCompiledHandler = true;
  31. /**
  32. * Create a new PHP Resource
  33. */
  34. public function __construct()
  35. {
  36. $this->short_open_tag = ini_get('short_open_tag');
  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. * Render and output the template (without using the compiler)
  55. *
  56. * @param Smarty_Template_Source $source source object
  57. * @param Smarty_Internal_Template $_template template object
  58. *
  59. * @return void
  60. * @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
  61. */
  62. public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
  63. {
  64. if (!$source->smarty->allow_php_templates) {
  65. throw new SmartyException("PHP templates are disabled");
  66. }
  67. if (!$source->exists) {
  68. if (isset($_template->parent) && $_template->parent->_objType == 2) {
  69. $parent_resource = " in '{$_template->parent->template_resource}'";
  70. } else {
  71. $parent_resource = '';
  72. }
  73. throw new SmartyException("Unable to load template {$source->type} '{$source->name}'{$parent_resource}");
  74. }
  75. // prepare variables
  76. extract($_template->getTemplateVars());
  77. // include PHP template with short open tags enabled
  78. ini_set('short_open_tag', '1');
  79. /** @var Smarty_Internal_Template $_smarty_template
  80. * used in included file
  81. */
  82. $_smarty_template = $_template;
  83. include($source->filepath);
  84. ini_set('short_open_tag', $this->short_open_tag);
  85. }
  86. /**
  87. * populate compiled object with compiled filepath
  88. *
  89. * @param Smarty_Template_Compiled $compiled compiled object
  90. * @param Smarty_Internal_Template $_template template object (is ignored)
  91. */
  92. public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
  93. {
  94. $compiled->filepath = false;
  95. $compiled->timestamp = false;
  96. $compiled->exists = false;
  97. }
  98. }