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_extends.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource Extends
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. * @author Uwe Tews
  8. * @author Rodney Rehm
  9. */
  10. /**
  11. * Smarty Internal Plugin Resource Extends
  12. * Implements the file system as resource for Smarty which {extend}s a chain of template files templates
  13. *
  14. * @package Smarty
  15. * @subpackage TemplateResources
  16. */
  17. class Smarty_Internal_Resource_Extends extends Smarty_Resource
  18. {
  19. /**
  20. * mbstring.overload flag
  21. *
  22. * @var int
  23. */
  24. public $mbstring_overload = 0;
  25. /**
  26. * populate Source Object with meta data from Resource
  27. *
  28. * @param Smarty_Template_Source $source source object
  29. * @param Smarty_Internal_Template $_template template object
  30. *
  31. * @throws SmartyException
  32. */
  33. public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
  34. {
  35. $uid = '';
  36. $sources = array();
  37. $components = explode('|', $source->name);
  38. $smarty = &$source->smarty;
  39. $exists = true;
  40. foreach ($components as $component) {
  41. /* @var \Smarty_Template_Source $_s */
  42. $_s = Smarty_Template_Source::load(null, $smarty, $component);
  43. if ($_s->type === 'php') {
  44. throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
  45. }
  46. $sources[ $_s->uid ] = $_s;
  47. $uid .= $_s->filepath;
  48. if ($_template) {
  49. $exists = $exists && $_s->exists;
  50. }
  51. }
  52. $source->components = $sources;
  53. $source->filepath = $_s->filepath;
  54. $source->uid = sha1($uid . $source->smarty->_joined_template_dir);
  55. $source->exists = $exists;
  56. if ($_template) {
  57. $source->timestamp = $_s->timestamp;
  58. }
  59. }
  60. /**
  61. * populate Source Object with timestamp and exists from Resource
  62. *
  63. * @param Smarty_Template_Source $source source object
  64. */
  65. public function populateTimestamp(Smarty_Template_Source $source)
  66. {
  67. $source->exists = true;
  68. /* @var \Smarty_Template_Source $_s */
  69. foreach ($source->components as $_s) {
  70. $source->exists = $source->exists && $_s->exists;
  71. }
  72. $source->timestamp = $source->exists ? $_s->getTimeStamp() : false;
  73. }
  74. /**
  75. * Load template's source from files into current template object
  76. *
  77. * @param Smarty_Template_Source $source source object
  78. *
  79. * @return string template source
  80. * @throws SmartyException if source cannot be loaded
  81. */
  82. public function getContent(Smarty_Template_Source $source)
  83. {
  84. if (!$source->exists) {
  85. throw new SmartyException("Unable to load template '{$source->type}:{$source->name}'");
  86. }
  87. $_components = array_reverse($source->components);
  88. $_content = '';
  89. /* @var \Smarty_Template_Source $_s */
  90. foreach ($_components as $_s) {
  91. // read content
  92. $_content .= $_s->getContent();
  93. }
  94. return $_content;
  95. }
  96. /**
  97. * Determine basename for compiled filename
  98. *
  99. * @param Smarty_Template_Source $source source object
  100. *
  101. * @return string resource's basename
  102. */
  103. public function getBasename(Smarty_Template_Source $source)
  104. {
  105. return str_replace(':', '.', basename($source->filepath));
  106. }
  107. /*
  108. * Disable timestamp checks for extends resource.
  109. * The individual source components will be checked.
  110. *
  111. * @return bool
  112. */
  113. /**
  114. * @return bool
  115. */
  116. public function checkTimestamps()
  117. {
  118. return false;
  119. }
  120. }