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