html.php 4.7 KB

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