1: <?php
2: 3: 4: 5: 6: 7:
8:
9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36: function smarty_block_textformat($params, $content, $template, &$repeat)
37: {
38: if (is_null($content)) {
39: return;
40: }
41:
42: $style = null;
43: $indent = 0;
44: $indent_first = 0;
45: $indent_char = ' ';
46: $wrap = 80;
47: $wrap_char = "\n";
48: $wrap_cut = false;
49: $assign = null;
50:
51: foreach ($params as $_key => $_val) {
52: switch ($_key) {
53: case 'style':
54: case 'indent_char':
55: case 'wrap_char':
56: case 'assign':
57: $$_key = (string) $_val;
58: break;
59:
60: case 'indent':
61: case 'indent_first':
62: case 'wrap':
63: $$_key = (int) $_val;
64: break;
65:
66: case 'wrap_cut':
67: $$_key = (bool) $_val;
68: break;
69:
70: default:
71: trigger_error("textformat: unknown attribute '$_key'");
72: }
73: }
74:
75: if ($style == 'email') {
76: $wrap = 72;
77: }
78:
79: $_paragraphs = preg_split('![\r\n]{2}!', $content);
80:
81: foreach ($_paragraphs as &$_paragraph) {
82: if (!$_paragraph) {
83: continue;
84: }
85:
86: $_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph);
87:
88: if ($indent_first > 0) {
89: $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
90: }
91:
92: if (Smarty::$_MBSTRING) {
93: require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
94: $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
95: } else {
96: $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
97: }
98:
99: if ($indent > 0) {
100: $_paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraph);
101: }
102: }
103: $_output = implode($wrap_char . $wrap_char, $_paragraphs);
104:
105: if ($assign) {
106: $template->assign($assign, $_output);
107: } else {
108: return $_output;
109: }
110: }
111: