html.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. /**
  3. * imap.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,
  15. $align = '',
  16. $bgcolor = '',
  17. $xtra = '' ) {
  18. GLOBAL $languages, $language;
  19. $align = strtolower( $align );
  20. $dir = strtolower( $dir );
  21. if ( isset( $languages[$language]['DIR']) ) {
  22. $dir = $languages[$language]['DIR'];
  23. } else {
  24. $dir = 'ltr';
  25. }
  26. if ( $dir == 'ltr' ) {
  27. $rgt = 'right';
  28. $lft = 'left';
  29. } else {
  30. $rgt = 'left';
  31. $lft = 'right';
  32. }
  33. if ( $bgcolor <> '' ) {
  34. $bgc = " BGCOLOR=\"$bgcolor\"";
  35. }
  36. switch ( $align ) {
  37. case '':
  38. $alg = '';
  39. break;
  40. case 'right':
  41. $alg = " ALIGN=\"$rgt\"";
  42. break;
  43. default:
  44. $alg = " ALIGN=\"$lft\"";
  45. }
  46. return( "<$tag DIR=\"$dir\"$bgc$alg $xtra>" );
  47. }
  48. /*
  49. * Zookeeper
  50. * Copyright (c) 2001 Partridge
  51. * Licensed under the GNU GPL. For full terms see the file COPYING.
  52. *
  53. * $Id$
  54. */
  55. /**
  56. * ZkSvc_html
  57. *
  58. * The ZkSvc_html class manages html output.
  59. */
  60. class ZkSvc_html {
  61. /* Constants */
  62. var $name = 'html'; // Module name
  63. var $ver = '$Id$';
  64. /* Properties */
  65. var $buffer; // Buffered output
  66. var $htmlmod; // Module handler
  67. var $title; // Page title
  68. var $head_extras; // Extra header tags
  69. var $bgcolor; // Background color
  70. var $text; // Text color
  71. var $link; // Link color
  72. var $vlink; // Visited link color
  73. var $alink; // Active link color
  74. var $onload; // Onload event
  75. var $onunload; // OnUnload event
  76. var $dir; // Text direction
  77. var $tag_options; // Array of tag options array
  78. /** CONSTRUCTOR
  79. */
  80. function ZkSvc_html() {
  81. GLOBAL $languages, $language;
  82. $this->spool = FALSE;
  83. $this->buffer = '';
  84. $this->title = 'Default zkHTML Title';
  85. $this->head_extras = '';
  86. $this->bgcolor = '#FFFFFF';
  87. $this->text = '#000000';
  88. $this->link = '#3300CC';
  89. $this->vlink = '#993333';
  90. $this->alink = '#993333';
  91. $this->onload = '';
  92. $this->onunload = '';
  93. /* To know if a tag exists we check that it has got a place in the following array */
  94. $this->tag_options = array( 'table' => array( 'tag_name' => 'table',
  95. 'tag_closed' => TRUE ),
  96. 'tr' => array( 'tag_name' => 'tr',
  97. 'tag_closed' => TRUE ),
  98. 'th' => array( 'tag_name' => 'th',
  99. 'tag_closed' => TRUE ),
  100. 'td' => array( 'tag_name' => 'td',
  101. 'tag_closed' => TRUE ),
  102. 'li' => array( 'tag_name' => 'li',
  103. 'tag_closed' => TRUE ),
  104. 'ol' => array( 'tag_name' => 'ol',
  105. 'tag_closed' => TRUE ),
  106. 'form' => array( 'tag_name' => 'form',
  107. 'tag_closed' => TRUE ),
  108. 'input' => array( 'tag_name' => 'input',
  109. 'tag_closed' => FALSE ),
  110. 'br' => array( 'tag_name' => 'br',
  111. 'tag_closed' => FALSE ),
  112. 'textarea' => array( 'tag_name' => 'textarea',
  113. 'tag_closed' => TRUE ),
  114. 'p' => array( 'tag_name' => 'p',
  115. 'tag_closed' => TRUE ),
  116. 'a' => array( 'tag_name' => 'a',
  117. 'tag_closed' => TRUE ),
  118. 'center' => array( 'name' => 'center',
  119. 'tag_closed' => TRUE ),
  120. 'img' => array( 'name' => 'img',
  121. 'tag_closed' => FALSE ),
  122. 'font' => array( 'tag_closed' => TRUE ),
  123. 'blockquote' => array( 'tag_name' => 'blockquote',
  124. 'tag_closed' => TRUE )
  125. );
  126. if ( isset( $languages[$language]['DIR']) ) {
  127. $this->dir = strtolower( $languages[$language]['DIR'] );
  128. } else {
  129. $this->dir = 'ltr';
  130. }
  131. }
  132. /**
  133. * Return the name of this service.
  134. *
  135. * @return string the name of this service
  136. */
  137. function getServiceName() {
  138. return( $this->name );
  139. }
  140. /**
  141. * Replace the Zookeeper html module loaded for this service. (no modules yet)
  142. *
  143. */
  144. function loadModule(&$module) {
  145. $this->htmlmod = &$module;
  146. }
  147. /**
  148. * Outputs the buffer and re-initialize it.
  149. *
  150. */
  151. function flush( $string = '' ) {
  152. echo $this->buffer . $string;
  153. flush();
  154. $this->buffer = '';
  155. }
  156. /**
  157. * Builds a header string
  158. *
  159. */
  160. function header( $string = '' ) {
  161. // It initializes the buffer.
  162. $this->buffer = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' .
  163. "\n<HTML>\n";
  164. if( $this->head_extras <> '' || $this->title <> '' ) {
  165. $this->buffer .= "<HEAD>\n";
  166. if( $this->title <> '' )
  167. $this->buffer .= "<TITLE>$this->title</TITLE>\n";
  168. $this->buffer .= "$this->head_extras</HEAD>\n";
  169. }
  170. $xtra = '';
  171. if ( $this->onload <> '' ) {
  172. $xtra .= ' onload="' . $this->onload . '" ';
  173. }
  174. if ( $this->onunload <> '' ) {
  175. $xtra .= ' onunload="' . $this->onunload . '" ';
  176. }
  177. $this->buffer .= "<BODY TEXT=\"$this->text\" BGCOLOR=\"$this->bgcolor\" LINK=\"$this->link\" VLINK=\"$this->vlink\" ALINK=\"$this->alink\" $xtra>\n";
  178. /* See if we're asking for a closed strcuture */
  179. if( $string == '' ) {
  180. $this->flush();
  181. } else {
  182. $this->buffer .= $string . '</BODY></HTML>';
  183. }
  184. }
  185. /**
  186. * Builds a footer string
  187. *
  188. */
  189. function footer() {
  190. $this->buffer .= "\n</body>\n</html>\n";
  191. $this->flush();
  192. }
  193. /**
  194. * Builds a tag string
  195. *
  196. */
  197. function tag( $tag, $string = '', $options = '' ) {
  198. $ret = '';
  199. if( $this->tag_options[$tag] <> NULL ) {
  200. if( $options == '' ) {
  201. $options = $this->tag_options[$tag];
  202. }
  203. switch( strtolower( $tag ) ) {
  204. case 'td':
  205. case 'th':
  206. if ( $this->dir == 'rtl' && isset( $options['align'] ) ) {
  207. }
  208. case 'table':
  209. if ( $this->dir <> '' ) {
  210. $options['DIR'] = $this->dir;
  211. }
  212. break;
  213. }
  214. $ret = zkTag_html( $tag, $string, $options, $this->tag_options[$tag]['tag_closed'] );
  215. }
  216. return( $ret );
  217. }
  218. /**
  219. * Builds a header string
  220. *
  221. */
  222. function h( $string, $level = '1' ) {
  223. $buffer = "<h$level>";
  224. /* See if we're asking for a closed strcuture */
  225. if( $string == '' ) {
  226. $this->$buffer .= $buffer;
  227. } else {
  228. $buffer .= $string . "</h$level>";
  229. }
  230. return( $buffer );
  231. }
  232. }
  233. /**
  234. * Converts an array into a parameters tag list.
  235. *
  236. */
  237. function zkGetParms_html( $parms ) {
  238. $buffer = '';
  239. foreach( $parms as $key => $opt ) {
  240. if( substr( $key, 0, 3 ) <> 'tag' ) {
  241. $buffer .= " $key";
  242. if ($opt <> '' ) {
  243. $buffer .= "=\"$opt\"";
  244. }
  245. }
  246. }
  247. return( $buffer );
  248. }
  249. /**
  250. * Composes a tag string with all its parameters.
  251. *
  252. */
  253. function zkTag_html( $tag, $string, $options, $closed ) {
  254. /*
  255. We must check direction tag in case we have table, td or th
  256. */
  257. $ret = "<$tag" .
  258. zkGetParms_html( $options ) .
  259. '>' .
  260. $string;
  261. if ( $closed ) {
  262. $ret .= "</$tag>";
  263. }
  264. return( $ret );
  265. }
  266. function optionize( $name, $opts, $default, $xtra = '' ) {
  267. $ret = "<select name=\"$name\" $xtra>\n";
  268. foreach( $opts as $key => $opt ) {
  269. if( $opt == $default ) {
  270. $chk = ' SELECTED';
  271. } else {
  272. $chk = '';
  273. }
  274. $ret .= "<option value=\"$opt\"$chk>$opt</option>\n";
  275. }
  276. $ret .= "</select>\n";
  277. return( $ret );
  278. }
  279. ?>