5 * @subpackage plugins
\r
9 * Smarty {textformat}{/textformat} block plugin
\r
11 * Type: block function<br>
\r
12 * Name: textformat<br>
\r
13 * Purpose: format text a certain way with preset styles
\r
14 * or custom wrap/indent settings<br>
\r
15 * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
\r
16 * (Smarty online manual)
\r
19 * Params: style: string (email)
\r
20 * indent: integer (0)
\r
21 * wrap: integer (80)
\r
22 * wrap_char string ("\n")
\r
23 * indent_char: string (" ")
\r
24 * wrap_boundary: boolean (true)
\r
26 * @param string contents of the block
\r
27 * @param Smarty clever simulation of a method
\r
28 * @return string string $content re-formatted
\r
30 function smarty_block_textformat($params, $content, &$smarty)
\r
41 if($content == null) {
\r
47 if($style == 'email') {
\r
51 // split into paragraphs
\r
52 $paragraphs = preg_split('![\r\n][\r\n]!',$content);
\r
55 foreach($paragraphs as $paragraph) {
\r
56 if($paragraph == '') {
\r
59 // convert mult. spaces & special chars to single space
\r
60 $paragraph = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'),array(' ',''),$paragraph);
\r
61 // indent first line
\r
62 if($indent_first > 0) {
\r
63 $paragraph = str_repeat($indent_char,$indent_first) . $paragraph;
\r
65 // wordwrap sentences
\r
66 $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
\r
69 $paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);
\r
71 $output .= $paragraph . $wrap_char . $wrap_char;
\r
74 if($assign != null) {
\r
75 $smarty->assign($assign,$output);
\r
81 /* vim: set expandtab: */
\r