9cd67a0a |
1 | <?php |
2 | |
3 | /** |
8008456a |
4 | * html.php |
9cd67a0a |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
9cd67a0a |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * The idea is to inlcude here some functions to make easier |
10 | * the right to left implementation by "functionize" some |
11 | * html outputs. |
12 | * |
13 | * $Id$ |
14 | */ |
15 | |
8008456a |
16 | function html_tag( $tag, // Tag to output |
d68323ff |
17 | $val = '', // Value between tags |
8008456a |
18 | $align = '', // Alignment |
19 | $bgcolor = '', // Back color |
20 | $xtra = '' ) { // Extra options |
892b98c9 |
21 | |
22 | GLOBAL $languages, $squirrelmail_language; |
23 | |
24 | $align = strtolower( $align ); |
25 | $bgc = ''; |
d68323ff |
26 | $tag = strtolower( $tag ); |
892b98c9 |
27 | |
28 | if ( isset( $languages[$squirrelmail_language]['DIR']) ) { |
d68323ff |
29 | $dir = $languages[$squirrelmail_language]['DIR']; |
892b98c9 |
30 | } else { |
31 | $dir = 'ltr'; |
32 | } |
33 | |
34 | if ( $dir == 'ltr' ) { |
35 | $rgt = 'right'; |
36 | $lft = 'left'; |
37 | } else { |
38 | $rgt = 'left'; |
39 | $lft = 'right'; |
40 | } |
41 | |
42 | if ( $bgcolor <> '' ) { |
d68323ff |
43 | $bgc = " bgcolor=\"$bgcolor\""; |
892b98c9 |
44 | } |
45 | |
46 | switch ( $align ) { |
47 | case '': |
48 | $alg = ''; |
49 | break; |
50 | case 'right': |
d68323ff |
51 | $alg = " align=\"$rgt\""; |
892b98c9 |
52 | break; |
53 | case 'left': |
d68323ff |
54 | $alg = " align=\"$lft\""; |
892b98c9 |
55 | break; |
56 | default: |
d68323ff |
57 | $alg = " align=\"$align\""; |
892b98c9 |
58 | break; |
59 | } |
60 | |
61 | $ret = "<$tag"; |
62 | |
63 | if ( $dir <> 'ltr' ) { |
d68323ff |
64 | $ret .= " dir=\"$dir\""; |
892b98c9 |
65 | } |
d68323ff |
66 | $ret .= $bgc . $alg; |
892b98c9 |
67 | |
68 | if ( $xtra <> '' ) { |
69 | $ret .= " $xtra"; |
70 | } |
892b98c9 |
71 | |
72 | if ( $val <> '' ) { |
d68323ff |
73 | $ret .= ">$val</$tag>"; |
74 | } else { |
1eebcf25 |
75 | $ret .= '>'; |
d68323ff |
76 | } |
892b98c9 |
77 | |
94ac35c6 |
78 | return( $ret ); |
94ac35c6 |
79 | } |
80 | |
02725e0b |
81 | /* handy function to set url vars */ |
82 | /* especially usefull when $url = $PHP_SELF */ |
59be1a75 |
83 | function set_url_var($url, $var, $val=0, $link=true) { |
892b98c9 |
84 | $k = ''; |
85 | $ret = ''; |
892b98c9 |
86 | $pat_a = array ( |
02725e0b |
87 | '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */ |
892b98c9 |
88 | '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */ |
89 | '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */ |
90 | '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */ |
91 | ); |
59be1a75 |
92 | preg_replace('/&/','&',$url); |
892b98c9 |
93 | switch (true) { |
94 | case (preg_match($pat_a[0],$url,$regs)): |
95 | $k = $regs[1]; |
96 | $v = $regs[2]; |
97 | break; |
98 | case (preg_match($pat_a[1],$url,$regs)): |
99 | $k = $regs[1]; |
100 | $v = $regs[2]; |
101 | break; |
102 | case (preg_match($pat_a[2],$url,$regs)): |
103 | $k = $regs[1]; |
104 | $v = $regs[2]; |
105 | break; |
106 | case (preg_match($pat_a[3],$url,$regs)): |
107 | $k = $regs[1]; |
108 | $v = $regs[2]; |
109 | break; |
110 | default: |
111 | if ($val) { |
112 | if (strpos($url,'?')) { |
6c359ab4 |
113 | $url .= "&$var=$val"; |
892b98c9 |
114 | } else { |
115 | $url .= "?$var=$val"; |
116 | } |
117 | } |
118 | break; |
119 | } |
120 | |
121 | if ($k) { |
122 | if ($val) { |
123 | $rpl = "$k=$val"; |
59be1a75 |
124 | if ($link) { |
125 | $rpl = preg_replace('/&/','&',$rpl); |
126 | } |
892b98c9 |
127 | } else { |
128 | $rpl = ''; |
129 | } |
130 | $pat = "/$k=$v/"; |
131 | $url = preg_replace($pat,$rpl,$url); |
02725e0b |
132 | } |
c9aa0b45 |
133 | return $url; |
892b98c9 |
134 | } |
02725e0b |
135 | |
6330a306 |
136 | /* Temporary test function to proces template vars with formatting. |
892b98c9 |
137 | * I use it for viewing the message_header (view_header.php) with |
6330a306 |
138 | * a sort of template. |
892b98c9 |
139 | */ |
6330a306 |
140 | function echo_template_var($var, $format_ar = array() ) { |
892b98c9 |
141 | $frm_last = count($format_ar) -1; |
142 | |
143 | if (isset($format_ar[0])) echo $format_ar[0]; |
144 | $i = 1; |
6330a306 |
145 | |
892b98c9 |
146 | switch (true) { |
147 | case (is_string($var)): |
148 | echo $var; |
149 | break; |
150 | case (is_array($var)): |
151 | $frm_a = array_slice($format_ar,1,$frm_last-1); |
152 | foreach ($var as $a_el) { |
153 | if (is_array($a_el)) { |
154 | echo_template_var($a_el,$frm_a); |
155 | } else { |
156 | echo $a_el; |
157 | if (isset($format_ar[$i])) { |
158 | echo $format_ar[$i]; |
159 | } |
160 | $i++; |
161 | } |
162 | } |
163 | break; |
164 | default: |
165 | break; |
166 | } |
167 | if (isset($format_ar[$frm_last]) && $frm_last>$i ) { |
168 | echo $format_ar[$frm_last]; |
169 | } |
170 | } |
02725e0b |
171 | ?> |