init
[garradin.git] / include / libs / template_lite / plugins / block.textformat.php
1 <?php
2
3 /*
4 * Template Lite plugin
5 * -------------------------------------------------------------
6 * Type: block function
7 * Name: textformat
8 * Purpose: format text a certain way with preset styles
9 * or custom wrap/indent settings
10 * Params: style: string (email)
11 * indent: integer (0)
12 * wrap: integer (80)
13 * wrap_char string ("\n")
14 * indent_char: string (" ")
15 * wrap_boundary: boolean (true)
16 * Taken from the original Smarty
17 * http://smarty.php.net
18 * -------------------------------------------------------------
19 */
20 function tpl_block_textformat($params, $content, &$template_object)
21 {
22 $style = null;
23 $indent = 0;
24 $indent_first = 0;
25 $indent_char = ' ';
26 $wrap = 80;
27 $wrap_char = "\n";
28 $wrap_cut = false;
29 $assign = null;
30
31 if($content == null)
32 {
33 return true;
34 }
35
36 extract($params);
37
38 if($style == 'email')
39 {
40 $wrap = 72;
41 }
42 // split into paragraphs
43 $paragraphs = preg_split('![\r\n][\r\n]!',$content);
44
45 foreach($paragraphs as $paragraph)
46 {
47 if($paragraph == '')
48 {
49 continue;
50 }
51 // convert mult. spaces & special chars to single space
52 $paragraph = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'),array(' ',''),$paragraph);
53 // indent first line
54 if($indent_first > 0)
55 {
56 $paragraph = str_repeat($indent_char,$indent_first) . $paragraph;
57 }
58 // wordwrap sentences
59 $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
60 // indent lines
61 if($indent > 0)
62 {
63 $paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);
64 }
65 $output .= $paragraph . $wrap_char . $wrap_char;
66 }
67 if($assign != null)
68 {
69 $template_object->assign($assign,$output);
70 }
71 else
72 {
73 echo $output;
74 }
75 //echo $content;
76 }
77
78 ?>