/www/shop/engine/Library/Enlight/Template/Plugins/resource.parent.php

https://bitbucket.org/weberlars/sot-shopware · PHP · 108 lines · 45 code · 8 blank · 55 comment · 6 complexity · e1beb94c08cb75ffc3af79a183fd5289 MD5 · raw file

  1. <?php
  2. /**
  3. * Enlight
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://enlight.de/license
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@shopware.de so we can send you a copy immediately.
  14. *
  15. * @category Enlight
  16. * @package Enlight_Template_Plugins
  17. * @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
  18. * @license http://enlight.de/license New BSD License
  19. * @version $Id$
  20. * @author Heiner Lohaus
  21. * @author $Author$
  22. */
  23. /**
  24. * @category Enlight
  25. * @package Enlight_Template
  26. * @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
  27. * @license http://enlight.de/license New BSD License
  28. */
  29. class Smarty_Resource_Parent extends Smarty_Internal_Resource_File
  30. {
  31. protected $index;
  32. /**
  33. * build template filepath by traversing the template_dir array
  34. *
  35. * @param Smarty_Template_Source $source source object
  36. * @param Smarty_Internal_Template $_template template object
  37. * @return string fully qualified filepath
  38. * @throws SmartyException if default template handler is registered but not callable
  39. */
  40. protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
  41. {
  42. $this->index++;
  43. $file = $source->name;
  44. $hit = false;
  45. foreach ($source->smarty->getTemplateDir() as $_directory) {
  46. $_filePath = realpath($_directory . $file);
  47. if ($this->fileExists($source, $_filePath)) {
  48. if ($hit) {
  49. return $_filePath;
  50. }
  51. if($_template->parent->source->filepath == $_filePath) {
  52. $hit = true;
  53. }
  54. }
  55. }
  56. return parent::buildFilepath($source, $_template);
  57. }
  58. /**
  59. * modify resource_name according to resource handlers specifications
  60. *
  61. * @param Smarty $smarty Smarty instance
  62. * @param string $resource_name resource_name to make unique
  63. * @return string unique resource name
  64. */
  65. protected function buildUniqueResourceName(Smarty $smarty, $resource_name)
  66. {
  67. $resource_name .= $this->index;
  68. return get_class($this) . '#' . $smarty->joined_template_dir . '#' . $resource_name;
  69. }
  70. /**
  71. * populate Source Object with meta data from Resource
  72. *
  73. * @param Smarty_Template_Source $source source object
  74. * @param Smarty_Internal_Template $_template template object
  75. */
  76. public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
  77. {
  78. $filePath = $this->buildFilepath($source, $_template);
  79. $s = Smarty_Resource::source(null, $source->smarty, $filePath);
  80. $source->components = $s;
  81. $source->filepath = $s->filepath;
  82. $source->uid = $s->uid;
  83. if ($_template && $_template->smarty->compile_check) {
  84. $source->timestamp = $s->timestamp;
  85. $source->exists = $s->exists;
  86. }
  87. $source->template = $_template;
  88. }
  89. /**
  90. * Load template's source from files into current template object
  91. *
  92. * @param Smarty_Template_Source $source source object
  93. * @return string template source
  94. * @throws SmartyException if source cannot be loaded
  95. */
  96. public function getContent(Smarty_Template_Source $source)
  97. {
  98. return $source->components->handler->getContent($source->components);
  99. }
  100. }