Kaynağa Gözat

class file for storing/handling html-structures. If we use this class to
store our html objects (tables etc) then we can easy make use of css with
full support of the non-css browsers.
Also very usefull for future templates.

stekkel 23 yıl önce
ebeveyn
işleme
be5376fcaf
1 değiştirilmiş dosya ile 106 ekleme ve 0 silme
  1. 106 0
      class/html.class

+ 106 - 0
class/html.class

@@ -0,0 +1,106 @@
+<?php
+/**
+ * html.class
+ *
+ * Copyright (c) 2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ *
+ * This contains functions needed to generate html output.
+ *
+ * $Id$
+ */
+
+
+class html {
+  var $tag, $text, $style, $class,  
+      $id, $html_el = array(), $javascript, $xtr_prop;
+
+  function html($tag='', $text='', $style ='', $class='', $id='',
+                  $xtr_prop = '', $javascript = '') {
+     $this->tag = $tag;
+     $this->text = $text;
+     $this->style = $style;
+     $this->class = $class;
+     $this->id = $id;
+     $this->xtr_prop = $xtr_prop;
+     $this->javascript = $javascript;
+  }
+  
+  function htmlAdd($el) {
+     $this->html_el[] = $el;
+  }
+  
+  
+  function echoHtml( $usecss=false, $indent='') {
+    $tag = $this->tag;
+    $text = $this->text;
+    $class = $this->class;
+    $id = $this->id;
+    $style = $this->style;
+    $javascript = $this->javascript;
+    $xtr_prop = $this->xtr_prop;
+    if ($xtr_prop) {
+       $prop = '';
+       foreach ($xtr_prop as $k => $v) {
+          if (is_string($k)) {
+             $prop.=' '.$k.'="'.$v.'"';
+	  } else {
+	     $prop.=' '.$v;
+	  }
+       }
+    }   
+    if ($javascript) {
+       $js = '';
+       foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */
+          $js.=' '.$k.'="'.$v.'";';
+       }
+    }
+       	  
+    echo $indent . '<' . $tag;
+    if ($class) {
+       echo ' class="'.$class.'"';
+    }  
+    if ($id) {
+       echo ' id="'.$id.'"';
+    }
+    if ($xtr_prop) {
+       echo ' '.$prop;
+    }
+    if ($style && !$usecss) {
+       echo ' style="'.$style.'"';  
+    }
+    if ($javascript) {
+       echo ' '.$js;
+    }
+    echo '>';
+    if ($text) {
+       if ($style && !$usecss) { /* if use css then fallback to stylesheet for layout */
+          foreach ($style as $k => $v) {
+            echo '<'.$k.'>';
+	  }
+	  echo $text;
+          foreach ($style as $k => $v) { /* if value of key value = true close the tag */
+	    if ($v) {
+               echo '</'.$v.'>';
+	    }   
+	  }
+       } else {
+         echo $text;
+       }
+    }
+    $cnt = count($this->html_el);
+    if ($cnt) {
+       echo "\n";
+       $indent.='  ';
+       for($i = 0;$i<$cnt;$i++) {
+          $el = $this->html_el[$i];
+	  $el->echoHtml($usecss,$indent);
+       }
+    }
+    echo '</'.$tag.'>'."\n";
+  }
+}
+ 
+
+?>