modifiercompiler.unescape.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Smarty plugin
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsModifierCompiler
  7. */
  8. /**
  9. * Smarty unescape modifier plugin
  10. *
  11. * Type: modifier<br>
  12. * Name: unescape<br>
  13. * Purpose: unescape html entities
  14. *
  15. * @author Rodney Rehm
  16. * @param array $params parameters
  17. * @return string with compiled code
  18. */
  19. function smarty_modifiercompiler_unescape($params, $compiler)
  20. {
  21. if (!isset($params[1])) {
  22. $params[1] = 'html';
  23. }
  24. if (!isset($params[2])) {
  25. $params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\'';
  26. } else {
  27. $params[2] = "'" . $params[2] . "'";
  28. }
  29. switch (trim($params[1], '"\'')) {
  30. case 'entity':
  31. case 'htmlall':
  32. if (Smarty::$_MBSTRING) {
  33. return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')';
  34. }
  35. return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')';
  36. case 'html':
  37. return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)';
  38. case 'url':
  39. return 'rawurldecode(' . $params[0] . ')';
  40. default:
  41. return $params[0];
  42. }
  43. }
  44. ?>