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)
41 if($content == null) {
47 if($style == 'email') {
51 // split into paragraphs
52 $paragraphs = preg_split('![\r\n][\r\n]!',$content);
55 foreach($paragraphs as $paragraph) {
56 if($paragraph == '') {
59 // convert mult. spaces & special chars to single space
60 $paragraph = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'),array(' ',''),$paragraph);
62 if($indent_first > 0) {
63 $paragraph = str_repeat($indent_char,$indent_first) . $paragraph;
66 $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
69 $paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);
71 $output .= $paragraph . $wrap_char . $wrap_char;
75 $smarty->assign($assign,$output);
81 /* vim: set expandtab: */
This page took 0.76964 seconds and 4 git commands to generate.