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 foreach ($paragraphs as $paragraph) {
78 if ($paragraph == '') {
81 // convert mult. spaces & special chars to single space
82 $paragraph = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'),array(' ',''),$paragraph);
84 if($indent_first > 0) {
85 $paragraph = str_repeat($indent_char,$indent_first) . $paragraph;
88 $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
91 $paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);
93 $output .= $paragraph . $wrap_char . $wrap_char;
97 $smarty->assign($assign,$output);
103 /* vim: set expandtab: */