modifiercompiler.wordwrap.php 1.5 KB

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