modifiercompiler.wordwrap.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Smarty plugin
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsModifierCompiler
  7. */
  8. /**
  9. * Smarty wordwrap modifier plugin
  10. * Type: modifier<br>
  11. * Name: wordwrap<br>
  12. * Purpose: wrap a string of text at a given length
  13. *
  14. * @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
  15. * @author Uwe Tews
  16. *
  17. * @param array $params parameters
  18. * @param $compiler
  19. *
  20. * @return string with compiled code
  21. */
  22. function smarty_modifiercompiler_wordwrap($params, $compiler)
  23. {
  24. if (!isset($params[ 1 ])) {
  25. $params[ 1 ] = 80;
  26. }
  27. if (!isset($params[ 2 ])) {
  28. $params[ 2 ] = '"\n"';
  29. }
  30. if (!isset($params[ 3 ])) {
  31. $params[ 3 ] = 'false';
  32. }
  33. $function = 'wordwrap';
  34. if (Smarty::$_MBSTRING) {
  35. if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
  36. $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'wordwrap' ][ 'modifier' ][ 'file' ] =
  37. SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
  38. $compiler->template->required_plugins[ 'nocache' ][ 'wordwrap' ][ 'modifier' ][ 'function' ] =
  39. 'smarty_mb_wordwrap';
  40. } else {
  41. $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'wordwrap' ][ 'modifier' ][ 'file' ] =
  42. SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
  43. $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'wordwrap' ][ 'modifier' ][ 'function' ] =
  44. 'smarty_mb_wordwrap';
  45. }
  46. $function = 'smarty_mb_wordwrap';
  47. }
  48. return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
  49. }