resource.extendsall.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Extends All Resource
  4. *
  5. * Resource Implementation modifying the extends-Resource to walk
  6. * through the template_dirs and inherit all templates of the same name
  7. *
  8. * @package Resource-examples
  9. * @author Rodney Rehm
  10. */
  11. class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends {
  12. /**
  13. * populate Source Object with meta data from Resource
  14. *
  15. * @param Smarty_Template_Source $source source object
  16. * @param Smarty_Internal_Template $_template template object
  17. * @return void
  18. */
  19. public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
  20. {
  21. $uid = '';
  22. $sources = array();
  23. $exists = true;
  24. foreach ($_template->smarty->getTemplateDir() as $key => $directory) {
  25. try {
  26. $s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name );
  27. if (!$s->exists) {
  28. continue;
  29. }
  30. $sources[$s->uid] = $s;
  31. $uid .= $s->filepath;
  32. }
  33. catch (SmartyException $e) {}
  34. }
  35. if (!$sources) {
  36. $source->exists = false;
  37. $source->template = $_template;
  38. return;
  39. }
  40. $sources = array_reverse($sources, true);
  41. reset($sources);
  42. $s = current($sources);
  43. $source->components = $sources;
  44. $source->filepath = $s->filepath;
  45. $source->uid = sha1($uid);
  46. $source->exists = $exists;
  47. if ($_template && $_template->smarty->compile_check) {
  48. $source->timestamp = $s->timestamp;
  49. }
  50. // need the template at getContent()
  51. $source->template = $_template;
  52. }
  53. }
  54. ?>