f3462c211f06f16c0f830e8e1fa191e8f15f84e9
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / plugins / block.textformat.php
1 <?php\r
2 /**\r
3  * Smarty plugin\r
4  * @package Smarty\r
5  * @subpackage plugins\r
6  */\r
7 \r
8 /**\r
9  * Smarty {textformat}{/textformat} block plugin\r
10  *\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
17  * @param array\r
18  * <pre>\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
25  * </pre>\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
29  */\r
30 function smarty_block_textformat($params, $content, &$smarty)\r
31 {\r
32         $style = null;\r
33         $indent = 0;\r
34         $indent_first = 0;\r
35         $indent_char = ' ';\r
36         $wrap = 80;\r
37         $wrap_char = "\n";\r
38         $wrap_cut = false;\r
39         $assign = null;\r
40         \r
41         if($content == null) {\r
42                 return true;\r
43         }\r
44 \r
45     extract($params);\r
46 \r
47         if($style == 'email') {\r
48                 $wrap = 72;\r
49         }       \r
50         \r
51         // split into paragraphs        \r
52         $paragraphs = preg_split('![\r\n][\r\n]!',$content);\r
53         $output = '';\r
54 \r
55         foreach($paragraphs as $paragraph) {\r
56                 if($paragraph == '') {\r
57                         continue;\r
58                 }\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
64                 }\r
65                 // wordwrap sentences\r
66                 $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);\r
67                 // indent lines\r
68                 if($indent > 0) {\r
69                         $paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);\r
70                 }\r
71                 $output .= $paragraph . $wrap_char . $wrap_char;\r
72         }\r
73                                 \r
74         if($assign != null) {\r
75                 $smarty->assign($assign,$output);\r
76         } else {\r
77                 return $output;\r
78         }\r
79 }\r
80 \r
81 /* vim: set expandtab: */\r
82 \r
83 ?>\r