PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
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.

89 lines
2.9 KiB

  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Include PHP
  4. *
  5. * Compiles the {include_php} tag
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Insert Class
  13. */
  14. class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase {
  15. // attribute definitions
  16. public $required_attributes = array('file');
  17. public $shorttag_order = array('file');
  18. public $optional_attributes = array('once', 'assign');
  19. /**
  20. * Compiles code for the {include_php} tag
  21. *
  22. * @param array $args array with attributes from parser
  23. * @param object $compiler compiler object
  24. * @return string compiled code
  25. */
  26. public function compile($args, $compiler)
  27. {
  28. if (!$compiler->smarty->allow_php_tag) {
  29. throw new SmartyException("{include_php} is deprecated, set allow_php_tag = true to enable");
  30. }
  31. $this->compiler = $compiler;
  32. // check and get attributes
  33. $_attr = $this->_get_attributes($args);
  34. $_output = '<?php ';
  35. $_smarty_tpl = $compiler->template;
  36. $_filepath = false;
  37. eval('$_file = ' . $_attr['file'] . ';');
  38. if (!isset($this->compiler->smarty->security_policy) && file_exists($_file)) {
  39. $_filepath = $_file;
  40. } else {
  41. if (isset($this->compiler->smarty->security_policy)) {
  42. $_dir = $this->compiler->smarty->security_policy->trusted_dir;
  43. } else {
  44. $_dir = $this->compiler->smarty->trusted_dir;
  45. }
  46. if (!empty($_dir)) {
  47. foreach((array)$_dir as $_script_dir) {
  48. if (strpos('/\\', substr($_script_dir, -1)) === false) {
  49. $_script_dir .= DS;
  50. }
  51. if (file_exists($_script_dir . $_file)) {
  52. $_filepath = $_script_dir . $_file;
  53. break;
  54. }
  55. }
  56. }
  57. }
  58. if ($_filepath == false) {
  59. $this->compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $this->compiler->lex->taglineno);
  60. }
  61. if (isset($this->compiler->smarty->security_policy)) {
  62. $this->compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
  63. }
  64. if (isset($_attr['assign'])) {
  65. // output will be stored in a smarty variable instead of being displayed
  66. $_assign = $_attr['assign'];
  67. }
  68. $_once = '_once';
  69. if (isset($_attr['once'])) {
  70. if ($_attr['once'] == 'false') {
  71. $_once = '';
  72. }
  73. }
  74. if (isset($_assign)) {
  75. return "<?php ob_start(); include{$_once} ('{$_filepath}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>";
  76. } else {
  77. return "<?php include{$_once} ('{$_filepath}');?>\n";
  78. }
  79. }
  80. }
  81. ?>