function.eval.php 1014 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Smarty {eval} function plugin
  9. *
  10. * Type: function<br>
  11. * Name: eval<br>
  12. * Purpose: evaluate a template variable as a template<br>
  13. * @link http://smarty.php.net/manual/en/language.function.eval.php {eval}
  14. * (Smarty online manual)
  15. * @author Monte Ohrt <monte at ohrt dot com>
  16. * @param array
  17. * @param Smarty
  18. */
  19. function smarty_function_eval($params, &$smarty)
  20. {
  21. if (!isset($params['var'])) {
  22. $smarty->trigger_error("eval: missing 'var' parameter");
  23. return;
  24. }
  25. if($params['var'] == '') {
  26. return;
  27. }
  28. $smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
  29. ob_start();
  30. $smarty->_eval('?>' . $_var_compiled);
  31. $_contents = ob_get_contents();
  32. ob_end_clean();
  33. if (!empty($params['assign'])) {
  34. $smarty->assign($params['assign'], $_contents);
  35. } else {
  36. return $_contents;
  37. }
  38. }
  39. /* vim: set expandtab: */
  40. ?>