+++ /dev/null
-<?php\r
-/**\r
- * Smarty plugin\r
- * @package Smarty\r
- * @subpackage plugins\r
- */\r
-\r
-/**\r
- * Smarty {textformat}{/textformat} block plugin\r
- *\r
- * Type: block function<br>\r
- * Name: textformat<br>\r
- * Purpose: format text a certain way with preset styles\r
- * or custom wrap/indent settings<br>\r
- * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}\r
- * (Smarty online manual)\r
- * @param array\r
- * <pre>\r
- * Params: style: string (email)\r
- * indent: integer (0)\r
- * wrap: integer (80)\r
- * wrap_char string ("\n")\r
- * indent_char: string (" ")\r
- * wrap_boundary: boolean (true)\r
- * </pre>\r
- * @param string contents of the block\r
- * @param Smarty clever simulation of a method\r
- * @return string string $content re-formatted\r
- */\r
-function smarty_block_textformat($params, $content, &$smarty)\r
-{\r
- $style = null;\r
- $indent = 0;\r
- $indent_first = 0;\r
- $indent_char = ' ';\r
- $wrap = 80;\r
- $wrap_char = "\n";\r
- $wrap_cut = false;\r
- $assign = null;\r
- \r
- if($content == null) {\r
- return true;\r
- }\r
-\r
- extract($params);\r
-\r
- if($style == 'email') {\r
- $wrap = 72;\r
- } \r
- \r
- // split into paragraphs \r
- $paragraphs = preg_split('![\r\n][\r\n]!',$content);\r
- $output = '';\r
-\r
- foreach($paragraphs as $paragraph) {\r
- if($paragraph == '') {\r
- continue;\r
- }\r
- // convert mult. spaces & special chars to single space\r
- $paragraph = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'),array(' ',''),$paragraph);\r
- // indent first line\r
- if($indent_first > 0) {\r
- $paragraph = str_repeat($indent_char,$indent_first) . $paragraph;\r
- }\r
- // wordwrap sentences\r
- $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);\r
- // indent lines\r
- if($indent > 0) {\r
- $paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);\r
- }\r
- $output .= $paragraph . $wrap_char . $wrap_char;\r
- }\r
- \r
- if($assign != null) {\r
- $smarty->assign($assign,$output);\r
- } else {\r
- return $output;\r
- }\r
-}\r
-\r
-/* vim: set expandtab: */\r
-\r
-?>\r