Source for file html.php

Documentation is available at html.php

  1. <?php
  2. /**
  3. * html.php
  4. *
  5. * The idea is to inlcude here some functions to make easier
  6. * the right to left implementation by "functionize" some
  7. * html outputs.
  8. *
  9. * @copyright 1999-2020 The SquirrelMail Project Team
  10. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11. * @version $Id: html.php 14840 2020年01月07日 07:42:38Z pdontthink $
  12. * @package squirrelmail
  13. * @since 1.3.0
  14. */
  15. /**
  16. * Generate html tags
  17. *
  18. * NOTE! If $val is non-empty, a closing tag will be added after $val
  19. * Otherwise, NO closing tag is provided!
  20. *
  21. * @param string $tag Tag to output
  22. * @param string $val Value between tags
  23. * @param string $align Alignment (left, center, etc)
  24. * @param string $bgcolor Back color in hexadecimal
  25. * @param string $xtra Extra options
  26. * @return string HTML ready for output
  27. */
  28. function html_tag ( $tag, // Tag to output
  29. $val = '', // Value between tags
  30. $align = '', // Alignment
  31. $bgcolor = '', // Back color
  32. $xtra = '' ) { // Extra options
  33. GLOBAL $languages , $squirrelmail_language;
  34. $align = strtolower ( $align );
  35. $bgc = '';
  36. $tag = strtolower ( $tag );
  37. if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
  38. $dir = $languages[$squirrelmail_language]['DIR'];
  39. } else {
  40. $dir = 'ltr';
  41. }
  42. if ( $dir == 'ltr' ) {
  43. $rgt = 'right';
  44. $lft = 'left';
  45. } else {
  46. $rgt = 'left';
  47. $lft = 'right';
  48. }
  49. if ( $bgcolor <> '' ) {
  50. $bgc = " bgcolor=\"$bgcolor\"";
  51. }
  52. switch ( $align ) {
  53. case '':
  54. $alg = '';
  55. break;
  56. case 'right':
  57. $alg = " align=\"$rgt\"";
  58. break;
  59. case 'left':
  60. $alg = " align=\"$lft\"";
  61. break;
  62. default:
  63. $alg = " align=\"$align\"";
  64. break;
  65. }
  66. $ret = "<$tag";
  67. if ( $dir <> 'ltr' ) {
  68. $ret .= " dir=\"$dir\"";
  69. }
  70. $ret .= $bgc . $alg;
  71. if ( $xtra <> '' ) {
  72. $ret .= " $xtra";
  73. }
  74. if ( $val <> '' ) {
  75. $ret .= ">$val</$tag>\n";
  76. } else {
  77. $ret .= '>' . "\n";
  78. }
  79. return( $ret );
  80. }
  81. /**
  82. * This function is used to add, modify or delete GET variables in a URL.
  83. * It is especially useful when $url = $PHP_SELF
  84. *
  85. * Set $val to NULL to remove $var from $url.
  86. * To ensure compatibility with older versions, use $val='0' to set $var to 0.
  87. *
  88. * @param string $url url that must be modified
  89. * @param string $var GET variable name
  90. * @param string $val variable value (CANNOT be an array)
  91. * @param boolean $link controls sanitizing of ampersand in urls (since 1.3.2)
  92. * @param boolean $treat_as_array When TRUE, if $var is an array (it occurs one
  93. * or more times with square brackets after it,
  94. * e.g. "var[1]"), the whole array will be removed
  95. * (when $val is NULL) or the given value will be
  96. * added to the next array slot (@since 1.4.23/1.5.2)
  97. *
  98. * @return string $url modified url
  99. *
  100. * @since 1.3.0
  101. *
  102. */
  103. function set_url_var ($url, $var, $val=null, $link=true, $treat_as_array=false) {
  104. $url = str_replace ('&amp;','&',$url);
  105. if (strpos ($url, '?') === false) {
  106. $url .= '?';
  107. }
  108. list($uri, $params) = explode ('?', $url, 2);
  109. $newpar = array();
  110. $params = explode ('&', $params);
  111. $array_names = array();
  112. foreach ($params as $p) {
  113. if (trim ($p)) {
  114. $p = explode ('=', $p);
  115. $newpar[$p[0]] = (isset($p[1]) ? $p[1] : '');
  116. if ($treat_as_array && preg_match ('/(.*)\[(\d+)]$/', $p[0], $matches)) {
  117. if (!isset($array_names[$matches[1]])) $array_names[$matches[1]] = array();
  118. $array_names[$matches[1]][$matches[2]] = $p[1];
  119. }
  120. }
  121. }
  122. if (is_null ($val)) {
  123. if ($treat_as_array && !empty($array_names[$var])) {
  124. foreach ($array_names[$var] as $key => $ignore)
  125. unset($newpar[$var . '[' . $key . ']']);
  126. } else {
  127. unset($newpar[$var]);
  128. }
  129. } else {
  130. if ($treat_as_array && !empty($array_names[$var])) {
  131. $max_key = 0;
  132. foreach ($array_names[$var] as $key => $ignore)
  133. if ($key >= $max_key) $max_key = $key + 1;
  134. $newpar[$var . '[' . $max_key . ']'] = $val;
  135. } else {
  136. $newpar[$var] = $val;
  137. }
  138. }
  139. if (!count ($newpar)) {
  140. return $uri;
  141. }
  142. $url = $uri . '?';
  143. foreach ($newpar as $name => $value) {
  144. $url .= "$name=$value&";
  145. }
  146. $url = substr ($url, 0, -1);
  147. if ($link) {
  148. $url = str_replace ('&','&amp;',$url);
  149. }
  150. return $url;
  151. }
  152. /* Temporary test function to proces template vars with formatting.
  153. * I use it for viewing the message_header (view_header.php) with
  154. * a sort of template.
  155. */
  156. function echo_template_var ($var, $format_ar = array() ) {
  157. $frm_last = count ($format_ar) -1;
  158. if (isset($format_ar[0])) echo $format_ar[0];
  159. $i = 1;
  160. switch (true) {
  161. case (is_string ($var)):
  162. echo $var;
  163. break;
  164. case (is_array ($var)):
  165. $frm_a = array_slice ($format_ar,1,$frm_last-1);
  166. foreach ($var as $a_el) {
  167. if (is_array ($a_el)) {
  168. echo_template_var ($a_el,$frm_a);
  169. } else {
  170. echo $a_el;
  171. if (isset($format_ar[$i])) {
  172. echo $format_ar[$i];
  173. }
  174. $i++;
  175. }
  176. }
  177. break;
  178. default:
  179. break;
  180. }
  181. if (isset($format_ar[$frm_last]) && $frm_last>$i ) {
  182. echo $format_ar[$frm_last];
  183. }
  184. }

Documentation generated on 2020年1月13日 04:24:41 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /