3  * Smarty plugin to format text blocks
 
   6  * @subpackage PluginsBlock
 
  10  * Smarty {textformat}{/textformat} block plugin
 
  12  * Type:     block function<br>
 
  13  * Name:     textformat<br>
 
  14  * Purpose:  format text a certain way with preset styles
 
  15  *            or custom wrap/indent settings<br>
 
  17  * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
 
  18  *       (Smarty online manual)
 
  19  * @param array $params parameters
 
  21  * Params:   style: string (email)
 
  24  *            wrap_char string ("\n")
 
  25  *            indent_char: string (" ")
 
  26  *            wrap_boundary: boolean (true)
 
  28  * @author Monte Ohrt <monte at ohrt dot com> 
 
  29  * @param string $content contents of the block
 
  30  * @param object $template template object
 
  31  * @param boolean &$repeat repeat flag
 
  32  * @return string content re-formatted
 
  34 function smarty_block_textformat($params, $content, $template, &$repeat)
 
  36     if (is_null($content)) {
 
  49     foreach ($params as $_key => $_val) {
 
  55                 $$_key = (string)$_val;
 
  69                 trigger_error("textformat: unknown attribute '$_key'");
 
  73     if ($style == 'email') {
 
  76     // split into paragraphs
 
  77     $_paragraphs = preg_split('![\r\n][\r\n]!', $content);
 
  80     for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) {
 
  81         if ($_paragraphs[$_x] == '') {
 
  84         // convert mult. spaces & special chars to single space
 
  85         $_paragraphs[$_x] = preg_replace(array('!\s+!', '!(^\s+)|(\s+$)!'), array(' ', ''), $_paragraphs[$_x]); 
 
  87         if ($indent_first > 0) {
 
  88             $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
 
  91         $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); 
 
  94             $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
 
  97     $_output = implode($wrap_char . $wrap_char, $_paragraphs);
 
  99     return $assign ? $template->assign($assign, $_output) : $_output;