Source for file html.class.php

Documentation is available at html.class.php

  1. <?php
  2. /**
  3. * html.class.php
  4. *
  5. * This contains functions needed to generate html output.
  6. *
  7. * @copyright 2003-2020 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id: html.class.php 14840 2020年01月07日 07:42:38Z pdontthink $
  10. * @package squirrelmail
  11. */
  12. /**
  13. * Undocumented class
  14. * @package squirrelmail
  15. */
  16. class html {
  17. var $tag , $text , $style , $class ,
  18. $id , $html_el = array(), $javascript , $xtr_prop ;
  19. /**
  20. * Constructor (PHP5 style, required in some future version of PHP)
  21. */
  22. function __construct ($tag='', $text='', $style ='', $class='', $id='',
  23. $xtr_prop = '', $javascript = '') {
  24. $this->tag = $tag;
  25. $this->text = $text;
  26. $this->style = $style;
  27. $this->class = $class;
  28. $this->id = $id;
  29. $this->xtr_prop = $xtr_prop;
  30. $this->javascript = $javascript;
  31. }
  32. /**
  33. * Constructor (PHP4 style, kept for compatibility reasons)
  34. */
  35. function html ($tag='', $text='', $style ='', $class='', $id='',
  36. $xtr_prop = '', $javascript = '') {
  37. self::__construct($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
  38. }
  39. function htmlAdd ($el, $last=true) {
  40. if ($last) {
  41. $this->html_el [] = $el;
  42. } else {
  43. $new_html_el = array();
  44. $new_html_el[] = $el;
  45. foreach ($this->html_el as $html_el) {
  46. $new_html_el[] = $html_el;
  47. }
  48. $this->html_el = $new_html_el;
  49. }
  50. }
  51. function AddChild ($tag='', $text='', $style ='', $class='', $id='',
  52. $xtr_prop = '', $javascript = '') {
  53. $el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
  54. $this->htmlAdd ($el);
  55. }
  56. function FindId ($id) {
  57. $cnt = count ($this->html_el );
  58. $el = false;
  59. if ($cnt) {
  60. for ($i = 0 ; $i < $cnt; $i++) {
  61. if ($this->html_el [$i]->id == $id) {
  62. $ret = $this->html_el [$i];
  63. return $ret;
  64. } else if (count ($this->html_el [$i]->html_el)) {
  65. $el = $this->html_el [$i]->FindId($id);
  66. }
  67. if ($el) return $el;
  68. }
  69. }
  70. return $el;
  71. }
  72. function InsToId ( $el, $id, $last=true) {
  73. $html_el = &$this->FindId ($id);
  74. if ($html_el) {
  75. $html_el->htmlAdd($el, $last);
  76. }
  77. }
  78. function scriptAdd ($script) {
  79. $s = "\n".'<!--'."\n".
  80. $script .
  81. "\n".'// -->'."\n";
  82. $el = new html ('script',$s,'','','',array('language' => 'JavaScript',
  83. 'type' => 'text/javascript'));
  84. $this->htmlAdd ($el);
  85. }
  86. function echoHtml ( $usecss=false, $indent='x') {
  87. if ($indent == 'x') {
  88. $indent = ''; $indentmore = '';
  89. } else {
  90. $indentmore = $indent . ' ';
  91. }
  92. $tag = $this->tag ;
  93. $text = $this->text ;
  94. $class = $this->class ;
  95. $id = $this->id ;
  96. $style = $this->style ;
  97. $javascript = $this->javascript ;
  98. $xtr_prop = $this->xtr_prop ;
  99. if ($xtr_prop) {
  100. $prop = '';
  101. foreach ($xtr_prop as $k => $v) {
  102. if (is_string ($k)) {
  103. $prop.=' '.$k.'="'.$v.'"';
  104. } else {
  105. $prop.=' '.$v;
  106. }
  107. }
  108. }
  109. if ($javascript) {
  110. $js = '';
  111. foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */
  112. $js.=' '.$k.'="'.$v.'";';
  113. }
  114. }
  115. if ($tag) {
  116. echo $indent . '<' . $tag;
  117. } else {
  118. echo $indent;
  119. }
  120. if ($class) {
  121. echo ' class="'.$class.'"';
  122. }
  123. if ($id) {
  124. echo ' id="'.$id.'"';
  125. }
  126. if ($xtr_prop) {
  127. echo ' '.$prop;
  128. }
  129. if ($style && !$usecss && !is_array ($style)) {
  130. /* last premisse is to prevent 'style="Array"' in the output */
  131. echo ' style="'.$style.'"';
  132. }
  133. if ($javascript) {
  134. echo ' '.$js;
  135. }
  136. if ($tag) echo '>';
  137. $openstyles = '';
  138. $closestyles = '';
  139. if ($style && !$usecss) {
  140. foreach ($style as $k => $v) {
  141. $openstyles .= '<'.$k.'>';
  142. }
  143. foreach ($style as $k => $v) {
  144. /* if value of key value = true close the tag */
  145. if ($v) {
  146. $closestyles .= '</'.$k.'>';
  147. }
  148. }
  149. }
  150. echo $openstyles;
  151. if ($text) {
  152. echo $text;
  153. }
  154. $cnt = count ($this->html_el );
  155. if ($cnt) {
  156. echo "\n";
  157. for($i = 0;$i<$cnt;$i++) {
  158. $el = $this->html_el [$i];
  159. $el->echoHtml($usecss,$indentmore);
  160. }
  161. echo $indent;
  162. }
  163. echo $closestyles;
  164. if ($tag) {
  165. echo '</'.$tag.'>'."\n";
  166. } else {
  167. echo "\n";
  168. }
  169. }
  170. }

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

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