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_compile_config_load.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Config Load
  4. * Compiles the {config load} tag
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Config Load Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
  17. {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $required_attributes = array('file');
  25. /**
  26. * Attribute definition: Overwrites base class.
  27. *
  28. * @var array
  29. * @see Smarty_Internal_CompileBase
  30. */
  31. public $shorttag_order = array('file', 'section');
  32. /**
  33. * Attribute definition: Overwrites base class.
  34. *
  35. * @var array
  36. * @see Smarty_Internal_CompileBase
  37. */
  38. public $optional_attributes = array('section', 'scope', 'bubble_up');
  39. /**
  40. * Valid scope names
  41. *
  42. * @var array
  43. */
  44. public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
  45. 'smarty' => true, 'tpl_root' => true);
  46. /**
  47. * Compiles code for the {config_load} tag
  48. *
  49. * @param array $args array with attributes from parser
  50. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  51. *
  52. * @return string compiled code
  53. * @throws \SmartyCompilerException
  54. */
  55. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
  56. {
  57. // check and get attributes
  58. $_attr = $this->getAttributes($compiler, $args);
  59. if ($_attr['nocache'] === true) {
  60. $compiler->trigger_template_error('nocache option not allowed', null, true);
  61. }
  62. // save possible attributes
  63. $conf_file = $_attr['file'];
  64. if (isset($_attr['section'])) {
  65. $section = $_attr['section'];
  66. } else {
  67. $section = 'null';
  68. }
  69. $_scope = Smarty::SCOPE_LOCAL;
  70. if (isset($_attr['scope'])) {
  71. $_attr['scope'] = trim($_attr['scope'], "'\"");
  72. if (!isset($this->valid_scopes[$_attr['scope']])) {
  73. $compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
  74. }
  75. if ($_attr['scope'] != 'local') {
  76. if ($_attr['scope'] == 'parent') {
  77. $_scope = Smarty::SCOPE_PARENT;
  78. } elseif ($_attr['scope'] == 'root') {
  79. $_scope = Smarty::SCOPE_ROOT;
  80. } elseif ($_attr['scope'] == 'global') {
  81. $_scope = Smarty::SCOPE_GLOBAL;
  82. } elseif ($_attr['scope'] == 'smarty') {
  83. $_scope = Smarty::SCOPE_SMARTY;
  84. } elseif ($_attr['scope'] == 'tpl_root') {
  85. $_scope = Smarty::SCOPE_TPL_ROOT;
  86. }
  87. $_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP;
  88. }
  89. }
  90. // create config object
  91. $_output =
  92. "<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
  93. return $_output;
  94. }
  95. }