/includes/smarty/sysplugins/smarty_internal_resource_registered.php

https://github.com/ACCORD5/TrellisDesk · PHP · 137 lines · 74 code · 7 blank · 56 comment · 9 complexity · 63086b4a0d4bee6c785588b6fef634ea MD5 · raw file

  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource Registered
  4. *
  5. * Implements the registered resource for Smarty template
  6. *
  7. * @package Smarty
  8. * @subpackage TemplateResources
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Resource Registered
  13. */
  14. class Smarty_Internal_Resource_Registered {
  15. public function __construct($smarty)
  16. {
  17. $this->smarty = $smarty;
  18. }
  19. // classes used for compiling Smarty templates from file resource
  20. public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
  21. public $template_lexer_class = 'Smarty_Internal_Templatelexer';
  22. public $template_parser_class = 'Smarty_Internal_Templateparser';
  23. // properties
  24. public $usesCompiler = true;
  25. public $isEvaluated = false;
  26. /**
  27. * Return flag if template source is existing
  28. *
  29. * @return boolean true
  30. */
  31. public function isExisting($_template)
  32. {
  33. if (is_integer($this->getTemplateTimestamp($_template))) {
  34. return true;
  35. } else {
  36. return false;
  37. }
  38. }
  39. /**
  40. * Get filepath to template source
  41. *
  42. * @param object $_template template object
  43. * @return string return 'string' as template source is not a file
  44. */
  45. public function getTemplateFilepath($_template)
  46. {
  47. // no filepath for strings
  48. // return "string" for compiler error messages
  49. $_filepath = $_template->resource_type .':'.$_template->resource_name;
  50. $_template->templateUid = sha1($_filepath);
  51. return $_filepath;
  52. }
  53. /**
  54. * Get timestamp to template source
  55. *
  56. * @param object $_template template object
  57. * @return boolean false as string resources have no timestamp
  58. */
  59. public function getTemplateTimestamp($_template)
  60. {
  61. // return timestamp
  62. $time_stamp = false;
  63. call_user_func_array($this->smarty->_plugins['resource'][$_template->resource_type][0][1],
  64. array($_template->resource_name, &$time_stamp, $this->smarty));
  65. return is_numeric($time_stamp) ? (int)$time_stamp : $time_stamp;
  66. }
  67. /**
  68. * Get timestamp to template source by type and name
  69. *
  70. * @param object $_template template object
  71. * @return boolean false as string resources have no timestamp
  72. */
  73. public function getTemplateTimestampTypeName($_resource_type, $_resource_name)
  74. {
  75. // return timestamp
  76. $time_stamp = false;
  77. call_user_func_array($this->smarty->_plugins['resource'][$_resource_type][0][1],
  78. array($_resource_name, &$time_stamp, $this->smarty));
  79. return is_numeric($time_stamp) ? (int)$time_stamp : $time_stamp;
  80. }
  81. /**
  82. * Retuen template source from resource name
  83. *
  84. * @param object $_template template object
  85. * @return string content of template source
  86. */
  87. public function getTemplateSource($_template)
  88. {
  89. // return template string
  90. return call_user_func_array($this->smarty->_plugins['resource'][$_template->resource_type][0][0],
  91. array($_template->resource_name, &$_template->template_source, $this->smarty));
  92. }
  93. /**
  94. * Get filepath to compiled template
  95. *
  96. * @param object $_template template object
  97. * @return boolean return false as compiled template is not stored
  98. */
  99. public function getCompiledFilepath($_template)
  100. {
  101. $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!','_',$_template->compile_id) : null;
  102. // calculate Uid if not already done
  103. if ($_template->templateUid == '') {
  104. $_template->getTemplateFilepath();
  105. }
  106. $_filepath = $_template->templateUid;
  107. // if use_sub_dirs, break file into directories
  108. if ($_template->smarty->use_sub_dirs) {
  109. $_filepath = substr($_filepath, 0, 2) . DS
  110. . substr($_filepath, 2, 2) . DS
  111. . substr($_filepath, 4, 2) . DS
  112. . $_filepath;
  113. }
  114. $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
  115. if (isset($_compile_id)) {
  116. $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
  117. }
  118. if ($_template->caching) {
  119. $_cache = '.cache';
  120. } else {
  121. $_cache = '';
  122. }
  123. $_compile_dir = $_template->smarty->compile_dir;
  124. if (strpos('/\\', substr($_compile_dir, -1)) === false) {
  125. $_compile_dir .= DS;
  126. }
  127. return $_compile_dir . $_filepath . '.' . $_template->resource_type . '.' . basename($_template->resource_name) . $_cache . '.php';
  128. }
  129. }
  130. ?>