Source for file html.class.php

Documentation is available at html.class.php

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

Documentation generated on Mon, 13 Jan 2020 04:24:41 +0100 by phpDocumentor 1.4.3