9cd67a0a |
1 | <?php |
2 | |
3 | /** |
8008456a |
4 | * html.php |
9cd67a0a |
5 | * |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
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 |
13cf639b |
17 | $val = '', // Value between tags (if empty only start tag is issued) |
8008456a |
18 | $align = '', // Alignment |
19 | $bgcolor = '', // Back color |
20 | $xtra = '' ) { // Extra options |
9cd67a0a |
21 | |
13cf639b |
22 | GLOBAL $languages, $squirrelmail_language; |
94ac35c6 |
23 | |
24 | $align = strtolower( $align ); |
02725e0b |
25 | $bgc = ''; |
8008456a |
26 | $tag = strtoupper( $tag ); |
94ac35c6 |
27 | |
13cf639b |
28 | if ( isset( $languages[$squirrelmail_language]['DIR']) ) { |
29 | $dir = $languages[$squirrelmail_language]['DIR']; |
94ac35c6 |
30 | } else { |
31 | $dir = 'ltr'; |
32 | } |
c1c17724 |
33 | |
94ac35c6 |
34 | if ( $dir == 'ltr' ) { |
35 | $rgt = 'right'; |
36 | $lft = 'left'; |
37 | } else { |
38 | $rgt = 'left'; |
39 | $lft = 'right'; |
40 | } |
41 | |
42 | if ( $bgcolor <> '' ) { |
43 | $bgc = " BGCOLOR=\"$bgcolor\""; |
44 | } |
c1c17724 |
45 | |
94ac35c6 |
46 | switch ( $align ) { |
47 | case '': |
48 | $alg = ''; |
49 | break; |
50 | case 'right': |
51 | $alg = " ALIGN=\"$rgt\""; |
52 | break; |
8008456a |
53 | case 'left': |
54 | $alg = " ALIGN=\"$lft\""; |
c1c17724 |
55 | break; |
94ac35c6 |
56 | default: |
8008456a |
57 | $alg = " ALIGN=\"$align\""; |
c1c17724 |
58 | break; |
94ac35c6 |
59 | } |
9cd67a0a |
60 | |
13cf639b |
61 | $ret = "<$tag"; |
8008456a |
62 | |
13cf639b |
63 | if ( $dir <> 'ltr' ) { |
64 | $ret .= " DIR=\"$dir\""; |
65 | } |
13cf639b |
66 | $ret .= "$bgc$alg"; |
8008456a |
67 | |
13cf639b |
68 | if ( $xtra <> '' ) { |
69 | $ret .= " $xtra"; |
70 | } |
71 | $ret .= '>'; |
8008456a |
72 | |
13cf639b |
73 | if ( $val <> '' ) { |
74 | $ret .= "$val</$tag>"; |
75 | } |
8008456a |
76 | |
94ac35c6 |
77 | return( $ret ); |
94ac35c6 |
78 | } |
79 | |
02725e0b |
80 | /* handy function to set url vars */ |
81 | /* especially usefull when $url = $PHP_SELF */ |
82 | function set_url_var($url, $var, $val=0) { |
83 | $k = ''; |
84 | $ret = ''; |
85 | $url = trim(preg_replace('/&/','&',$url)); |
86 | |
87 | $pat_a = array ( |
88 | '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */ |
89 | '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */ |
90 | '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */ |
91 | '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */ |
92 | ); |
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,'?')) { |
113 | |
114 | $url .= "&$var=$val"; |
115 | } else { |
116 | |
117 | $url .= "?$var=$val"; |
118 | } |
119 | } |
120 | break; |
121 | } |
122 | |
123 | if ($k) { |
124 | if ($val) { |
125 | $pat = "/$k=$v/"; |
126 | $rpl = "$k=$val"; |
127 | echo "<B>$pat , $rpl </b><BR>"; |
128 | $url = preg_replace($pat,$rpl,$url); |
129 | } else { |
130 | $pat = "/$k=$v/"; |
131 | $url = preg_replace($pat,'',$url); |
132 | } |
133 | } |
134 | return preg_replace('/&/','&',$url); |
135 | } |
136 | |
6330a306 |
137 | /* Temporary test function to proces template vars with formatting. |
138 | * I use it for viewing the message_header (view_header.php) with |
139 | * a sort of template. |
140 | */ |
141 | function echo_template_var($var, $format_ar = array() ) { |
142 | $frm_last = count($format_ar) -1; |
143 | |
144 | if (isset($format_ar[0])) echo $format_ar[0]; |
145 | $i = 1; |
146 | |
147 | switch (true) { |
148 | case (is_string($var)): |
149 | echo $var; |
150 | break; |
151 | case (is_array($var)): |
152 | $frm_a = array_slice($format_ar,1,$frm_last-1); |
153 | foreach ($var as $a_el) { |
154 | if (is_array($a_el)) { |
155 | echo_template_var($a_el,$frm_a); |
156 | } else { |
157 | echo $a_el; |
158 | if (isset($format_ar[$i])) echo $format_ar[$i]; |
159 | $i++; |
160 | } |
161 | } |
162 | break; |
163 | default: |
164 | break; |
165 | } |
166 | if (isset($format_ar[$frm_last]) && $frm_last>$i ) echo $format_ar[$frm_last]; |
167 | } |
168 | |
02725e0b |
169 | ?> |