compile.compile_config.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Template Lite compile config variables - template internal module
  4. *
  5. * Type: template
  6. * Name: compile_config
  7. */
  8. function compile_compile_config($variable, &$object)
  9. {
  10. $_result = "";
  11. // remove the beginning and ending #
  12. $variable = substr($variable, 1, -1);
  13. // get [foo] and .foo and (...) pieces
  14. preg_match_all('!(?:^\w+)|(?:' . $object->_var_bracket_regexp . ')|\.\$?\w+|\S+!', $variable, $_match);
  15. $variable = $_match[0];
  16. $var_name = array_shift($variable);
  17. $_result = "\$this->_confs['$var_name']";
  18. foreach ($variable as $var)
  19. {
  20. if ($var{0} == '[')
  21. {
  22. $var = substr($var, 1, -1);
  23. if (is_numeric($var))
  24. {
  25. $_result .= "[$var]";
  26. }
  27. elseif ($var{0} == '$')
  28. {
  29. $_result .= "[" . $object->_compile_variable($var) . "]";
  30. }
  31. elseif ($var{0} == '#')
  32. {
  33. $_result .= "[" . $object->_compile_config($var) . "]";
  34. }
  35. else
  36. {
  37. $_result .= "['$var']";
  38. }
  39. }
  40. else if ($var{0} == '.')
  41. {
  42. if ($var{1} == '$')
  43. {
  44. $_result .= "[\$this->_TPL['" . substr($var, 2) . "']]";
  45. }
  46. else
  47. {
  48. $_result .= "['" . substr($var, 1) . "']";
  49. }
  50. }
  51. else if (substr($var,0,2) == '->')
  52. {
  53. if(substr($var,2,2) == '__')
  54. {
  55. $object->trigger_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
  56. }
  57. else if (substr($var, 2, 1) == '$')
  58. {
  59. $_output .= '->{(($var=$this->_TPL[\''.substr($var,3).'\']) && substr($var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$var\\"")}';
  60. }
  61. }
  62. else
  63. {
  64. $object->trigger_error('#' . $var_name.implode('', $variable) . '# is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
  65. }
  66. }
  67. return $_result;
  68. }
  69. ?>