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 * @author Monte Ohrt <monte at ohrt dot com>
27 * @param string contents of the block
28 * @param Smarty clever simulation of a method
29 * @return string string $content re-formatted
31 function smarty_block_textformat($params, $content, &$smarty)
33 if (is_null($content)) {
46 foreach ($params as $_key => $_val) {
52 $
$_key = (string)$_val;
66 $smarty->trigger_error("textformat: unknown attribute '$_key'");
70 if ($style == 'email') {
74 // split into paragraphs
75 $_paragraphs = preg_split('![\r\n][\r\n]!',$content);
78 for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++
) {
79 if ($_paragraphs[$_x] == '') {
82 // convert mult. spaces & special chars to single space
83 $_paragraphs[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]);
85 if($indent_first > 0) {
86 $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
89 $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
92 $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
95 $_output = implode($wrap_char . $wrap_char, $_paragraphs);
97 return $assign ?
$smarty->assign($assign, $_output) : $_output;
101 /* vim: set expandtab: */
This page took 0.309791 seconds and 4 git commands to generate.