modifiercompiler.unescape.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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] = "SMARTY_RESOURCE_CHAR_SET";
  26. } else {
  27. $params[2] = "'" . $params[2] . "'";
  28. }
  29. switch (trim($params[1], '"\'')) {
  30. case 'entity':
  31. return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')';
  32. case 'htmlall':
  33. if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
  34. return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')';
  35. }
  36. return 'html_entity_decode(' . $params[0] . ', ENT_QUOTES, ' . $params[2] . ')';
  37. case 'html':
  38. return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)';
  39. default:
  40. return $params[0];
  41. }
  42. }
  43. ?>