9 * Smarty {textformat}{/textformat} block plugin
11 * Type: block function<br>
12 * Name: textformat<br>
13 * Purpose: format text a certain way with preset styles
14 * or custom wrap/indent settings<br>
15 * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
16 * (Smarty online manual)
19 * Params: style: string (email)
22 * wrap_char string ("\n")
23 * indent_char: string (" ")
24 * wrap_boundary: boolean (true)
26 * @param string contents of the block
27 * @param Smarty clever simulation of a method
28 * @return string string $content re-formatted
30 function smarty_block_textformat($params, $content, &$smarty)
32 if (is_null($content)) {
45 foreach ($params as $_key => $_val) {
51 $
$_key = (string)$_val;
65 $smarty->trigger_error("textformat: unknown attribute '$_key'");
69 if ($style == 'email') {
73 // split into paragraphs
74 $_paragraphs = preg_split('![\r\n][\r\n]!',$content);
77 for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++
) {
78 if ($_paragraphs[$_x] == '') {
81 // convert mult. spaces & special chars to single space
82 $_paragraphs[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]);
84 if($indent_first > 0) {
85 $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
88 $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
91 $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
94 $_output = implode($wrap_char . $wrap_char, $_paragraphs);
96 return $assign ?
$smarty->assign($assign, $_output) : $_output;
100 /* vim: set expandtab: */