Répertoire de codes source

Générer du html
déposé par sekaijin
le 16/02/2008
nombre de visites : 4997
voici deux classes pour générer automatiquement du html. il conviens de les amméliorer pour utiliser au mieux ZF entre autre Zend_Form e Zend_Layout
<?php
// la classe pour créer le document HTML
require_once dirname(__FILE__).'/Html/Element.php';
 
 
class Document_Html {
   protected $_doctype;
   protected $_head;
   protected $_body;
   protected $_attributes = array ();
   protected $_nameSpaces = array();
 
   protected $_ElementClassName = 'Document_Html_Element';
 
   /**
   * Constructor
   * 
   * @param string $doctype Document Type (HTML|XHTML)
   * @param string $dtd Document Type Definition (Transitional...)
   * @param string $version Document Type Version (1.0...)
   * @return void
   */
   public function __construct($doctype = 'XHTML', $dtd = 'Transitional', $version ='1.0')
   {
      $this->setDocType($doctype, $dtd, $version);
      $this->_head = new $this->_ElementClassName($this, 'head', null, null, false, true, true);
      $this->_body = new $this->_ElementClassName($this, 'body', null, null, false, true, true);
   }
 
   public function setDocType($doctype = 'XHTML', $dtd = 'Transitional', $version ='1.0') {
      //TODO définir les règles pour générer les différente version du doctype
      /*
         <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">
         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      */
 
      $this->_doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; 
      $this->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
   }
 
   public function addNameSpace($prefix, $urn) {
      $this->setAttribute('xmlns:'.$prefix, $urn);
      $this->_nameSpaces[$prefix] = $urn;
      return $this;
   }
 
   public function setLanguage($lang) {
      $this->setAttribute('lang', $lang);
      $this->setAttribute('xml:lang', $lang);
      return $this;
   }
 
   public function setNSAtrribute($prefix, $name, $value) {
      if (!array_key_exists($prefix, $this->_nameSpaces)) {
         $this->addNameSpace($prefix, 'Undefined_Urn_'.rand());
      }
      $this->setAttribute($prefix.':'.$name, $value);
      return $this;
   }
 
   public function setAttribute($name, $value) {
      $this->_attributes[$name] = $value;
      return $this;
   }
 
   public function getHead() {
      return $this->_head;
   }
 
   public function getBody() {
      return $this->_body;
   }
 
   public function getHtml() {
      $src = $this->_doctype."\n";
      $src.= '<html '."\n";
      foreach ($this->_attributes as $name=>$value) {
         $src.= '   '.$name."='".$value."'\n";
      }
      $src.= ">";
      $src.= $this->getHead()->getHtml();
      $src.= $this->getBody()->getHtml();
      $src.= "\n</html>";
      return $src;
   }
 
   public function display() {
      echo $this->getHtml();
   }
}
?>
<?php
//La classe pour créer tout le reste
 
class Document_Html_Element {
   protected $_parent;
   protected $_tag;
   protected $_attributes = array ();
   protected $_styles = array();
   protected $_content = array();
 
   //indent system
   protected $_tab = '   ';
   protected $_indent = true;
   protected $_singleLine = false;
   protected $_indentContent = true;
 
   protected $_autoClose = true; //accepte <tag />
 
   /**
   * Constructor
   * 
   * @param Document_Html_Element $parent
   * @param string $tagName
   * @param string $attributes
   * @param string $styles
   * @return void
   */
   public function __construct($parent, 
                               $tagName = null, 
                               $attributes = null, 
                               $styles = null,
                               $singleLine = null,
                               $indent = null,
                               $identContent = null)
   {
      $this->_parent = $parent;
      if ($tagName)               $this->_tag = $tagName;
      if (is_array($attributes))  array_merge($this->_attributes = $attributes);
      if (is_array($styles))      array_merge($this->_styles = $styles);
      if (null !== $singleLine)   $this->_singleLine = $singleLine;
      if (null !== $identContent) $this->_indentContent = $identContent;
      if (null !== $indent)       $this->_indent = $indent;
   }
 
   public function getParent() {
      return $this->_parent;
   }
 
   public function getDocument() {
      require_once dirname(dirname(__FILE__)).'/Html.php';
      if ($this->_parent instanceOF Document_Html) {
         return $this->_parent;
      } else {
         return $this->_parent-> getDocument();
      }
   }
 
   public function forceClose() {
      $this->_autoClose = false;
      return $this;
   }
 
   public function setAttribute($name, $value) {
      $this->_attributes[$name] = $value;
      return $this;
   }
 
   Public function addContent($content) {
      $this->_content[] = $content;
      return $this;
   }
 
   function getHtml($tab = null) {
      $style = '';
      foreach ($this->_styles as $key=>$value) {
         $style.= $key.': '.$value.';';
      }
 
      if (null === $tab) $tab = $this->_tab;
      if ($this->_indent) {
         $src = "\n".$tab;
      } else {
         $src = '';
      }
      $src.= '<'.$this->_tag;
      foreach ($this->_attributes as $name=>$value) {
         $src.= ' '.$name."='".$value."'";
      }
      if ('' != $style) {
         $src.= " style='".$style."'";
      }
      if ($this->_autoClose&&(is_array($this->_content)&&(0 == count($this->_content)))) {
         $src.= ' />';
      } else {
         $src.= '>';
      }
 
      if (!(is_array($this->_content)&&(0 == count($this->_content)))||!$this->_autoClose){
         if ((is_array($this->_content))||
             (is_string($this->_content))) $src.= $this->_getHtmlContent($tab.$this->_tab);
 
         if ($this->_indent&&!$this->_singleLine) {
            $src.= "\n".$tab;
         }
         $src.= '</'.$this->_tag.'>';
      }
      return $src;
   }
 
   function _getHtmlContent($tab = null) {
      if (null === $tab) $tab = $this->_tab;
      if(is_array($this->_content)) {
         $src = '';
         foreach ($this->_content as $content) {
            if ($content instanceOf Document_Html_Element) {
               $src.= $content->getHtml($tab);
            } elseif (is_string($content)) {
               if ($this->_indentContent) {
                  $src.= "\n".$tab.$content;
               } else {
                  $src.= $content;
               }
            }
         }
         return $src;
      }
   }
 
   Public function _shift(&$text, &$attributes, &$styles) {
      if (is_array($text)) {
         //shift args
         $style = $attributes;
         $attributes = $text;
         $text = null;
      }
   }
 
   //Methodes pour créer des éléments.
 
   Public function Text($text = null) {
      $this->addContent(htmlentities($text));
      return $this;
   }
 
   Public function Space() {
      $this->addContent(' ');
      return $this;
   }
 
   Public function noBreakSpace() {
      $this->addContent('&nbsp;');
      return $this;
   }
 
   Public function aName($text = null, $name = null, $attributes = null, $styles = null) {
      $attributes['name'] = $name;
      $a = $this->inlineElement($this, 'a', $text, $attributes, $styles, true, true, false);
      $this->addContent($a);
      return $a;
   }
 
   Public function aHref($text = null, $href = null, $attributes = null, $styles = null) {
      $attributes['href'] = $href;
      $a = $this->inlineElement($this, 'a', $text, $attributes, $styles, true, true, false);
      $this->addContent($a);
      return $a;
   }
 
   Public function abbr($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'abbr', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function acronym($text = null, $title = null, $attributes = null, $styles = null) {
      $attributes['title'] = $title;
      $tag = $this->inlineElement($this, 'acronym', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function address($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'address', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function applet($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'applet', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function area($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'area', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function b($text= null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'strong', $text, $attributes, $styles, true, false, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function base($text= null, $href = null, $attributes = null, $styles = null) {
      $attributes['href'] = $href;
      $tag = $this->inlineElement($this, 'base', $text, $attributes, $styles, true, true, false);
      $this->getDocument()->getHead()->addContent($tag);
      return $this;
   }
 
   Public function baseFont($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'basefont', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function bdo($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'bdo', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function big($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'big', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function blockquote($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'blockquote', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function br($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'br', $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $this;
   }
 
   Public function nobr($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'nobr', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function button($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'button', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function caption($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'caption', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function center($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'center', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function cite($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'cite', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function code($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'code', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function col($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'col', $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $this;
   }
 
   Public function colgroup($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'colgroup', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function dd($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'dd', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function del($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'del', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function dfn($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'dfn', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function dir($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'dir', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function div($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'div', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function dl($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'dl', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function dt($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'dt', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function em($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'em', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function fieldset($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'fieldset', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function font($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'font', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function form($action = null, $method = null, $attributes = null, $styles = null) {
      $attributes['action'] = $action;
      $attributes['method'] = $method;
      $tag = new Document_Html_Element($this, 'form', $attributes, $styles, false, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function frame($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'frame', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function frameset($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'frameset', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function h1($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'h1', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function h2($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'h2', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function h3($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'h3', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function h4($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'h4', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function h5($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'h5', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function h6($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'h6', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function hr($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'hr', $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $this;
   }
 
   Public function i($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'i', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function iframe($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'iframe', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function image($src = null, $attributes = null, $styles = null) {
      $attributes['src'] = $src;
      $img = new Document_Html_Element($this, 'img', $attributes, $styles, true, false, false);
      $this->addContent($img);
      return $this;
   }
 
   Public function input($type = null, $name = null, $value = null, $attributes = null, $styles = null) {
      $attributes['name'] = $name;
      $attributes['type'] = $type;
      $attributes['value'] = $value;
      $tag = new Document_Html_Element($this, 'input', $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $this;
   }
 
   Public function inputText($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('text', $name, $value, $attributes, $styles);
   }
 
   Public function inputPassword($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('password', $name, $value, $attributes, $styles);
   }
 
   Public function inputCheckBox($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('checkbox', $name, $value, $attributes, $styles);
   }
 
   Public function inputRadio($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('radio', $name, $value, $attributes, $styles);
   }
 
   Public function inputSubmit($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('submit', $name, $value, $attributes, $styles);
   }
 
   Public function inputReset($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('reset', $name, $value, $attributes, $styles);
   }
 
   Public function inputFile($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('file', $name, $value, $attributes, $styles);
   }
 
   Public function inputHidden($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('hidden', $name, $value, $attributes, $styles);
   }
 
   Public function inputImage($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('image', $name, $value, $attributes, $styles);
   }
 
   Public function inputButton($name = null, $value = null, $attributes = null, $styles = null) {
      return $this->input('button', $name, $value, $attributes, $styles);
   }
 
   Public function ins($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'ins', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function isindex($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'isindex', $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $this;
   }
 
   Public function kbd($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'kbd', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function label($text = null, $forId = null, $attributes = null, $styles = null) {
      $attributes['for'] = $forId;
      $tag = $this->inlineElement($this, 'label', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function legend($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'legend', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function li($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'li', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function link($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'link', $attributes, $styles, false, true, false);
      $this->getDocument()->getHead()->addContent($tag);
      return $this;
   }
 
   Public function linkStyle($source = null, $media= null, $attributes = null, $styles = null) {
      $attributes['href'] = $source;
      $attributes['media'] = $media;
      $attributes['rel'] = 'stylesheet';
      $attributes['type'] = 'text/css';
      $tag = new Document_Html_Element($this, 'link', $attributes, $styles, false, true, false);
      $this->getDocument()->getHead()->addContent($tag);
      return $this;
   }
 
   Public function map($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'map', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function menu($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'menu', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function meta($name='', $content='', $attributes = null, $styles = null) {
      $attributes['name'] = $name;
      $attributes['content'] = $content;
      $tag = new Document_Html_Element($this, 'meta', $attributes, $styles, true, true, false);
      $this->getDocument()->getHead()->addContent($tag);
      return $this;
   }
 
   Public function contentType($content='text/html; charset=iso-8859-1', $attributes = null, $styles = null) {
      $attributes['http-equiv'] = 'Content-Type';
      $attributes['content'] = $content;
      $tag = new Document_Html_Element($this, 'meta', $attributes, $styles, true, true, false);
      $this->getDocument()->getHead()->addContent($tag);
      return $this;
   }
 
   Public function noframes($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'noframes', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function noscript($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'noscript', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function object($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'object', $attributes, $styles, false, true, true);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function ol($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'ol', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function optgroup($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'optgroup', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function option($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'option', $attributes, $styles, false, true, true);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function p($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'p', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function param($name = null, $value = null, $attributes = null, $styles = null) {
      $attributes['name'] = $name;
      $attributes['value'] = $value;
      $tag = new Document_Html_Element($this, 'param', $attributes, $styles, false, true, false);
      $this->getDocument()->getHead()->addContent($tag);
      return $this;
   }
 
   Public function pre($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'pre', $text, $attributes, $styles, true, false, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function q($text = null, $cite = null, $attributes = null, $styles = null) {
      $attributes['cite'] = $cite;
      $tag = $this->inlineElement($this, 'q', $text, $attributes, $styles, true, false, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function s($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 's', $text, $attributes, $styles, true, false, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function samp($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'samp', $text, $attributes, $styles, true, false, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function inlineScript($text = null, $attributes = null, $styles = null) {
      $tag = $this->inlineElement($this, 'script', $text, null, $attributes, $styles, true, true, true);
      $tag->forceClose();
      $this->addContent($tag);
      return $tag;
   }
 
   Public function script($source = null, $attributes = null, $styles = null) {
      $attributes['src'] = $source;
      $tag = new Document_Html_Element($this, 'script', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->addContent($tag);
      return $this;
   }
 
   /*
   Public function addInlineScript($text = null, $attributes = null, $styles = null) {
      $tag = $this->inlineElement($this, 'script', $text, null, $attributes, $styles, true, true, true);
      $tag->forceClose();
      $this->getDocument()->getHead()->addContent($tag);
      return $this; //TODO rupture de fux 
      return $tag;
   }
   */
 
   Public function addScript($source = null, $attributes = null, $styles = null) {
      $attributes['src'] = $source;
      $tag = new Document_Html_Element($this, 'script', $attributes, $styles, true, true, false);
      $tag->forceClose();
      $this->getDocument()->getHead()->addContent($tag);
      return $this;
   }
 
   Public function select($name = null, $value = null, $attributes = null, $styles = null) {
      $attributes['name'] = $name;
      $attributes['value'] = $value;
      $tag = new Document_Html_Element($this, 'select', $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function small($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'small', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function span($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'span', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function strike($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'strike', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function strong($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'strong', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function addInlineStyle($text = null, $media= null, $attributes = null, $styles = null) {
      $tag = $this->inlineElement($this, 'style', $text, null, $media, $attributes, $styles, false, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function sub($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'sub', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function sup($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'sup', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function table($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'table', $attributes, $styles, false, true, true);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function tbody($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'tbody', $attributes, $styles, false, true, true);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function td($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'td', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function textarea($name = null, $text = null, $attributes = null, $styles = null) {
      $attributes['name'] = $name;
      $tag = $this->inlineElement($this, 'textarea', $text, $attributes, $styles, true, false, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function tfoot($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'tfoot', $attributes, $styles, false, true, true);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function th($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'th', $text, $attributes, $styles, true, true, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function thead($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'thead', $attributes, $styles, false, true, true);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function title($title = null, $attributes = null, $styles = null) {
      $this->_shift($title, $attributes, $styles);
      $tag = $this->inlineElement($this, 'title', $title, $attributes, $styles,true, true, false);
      $this->addContent($tag);
      return $this;
   }
 
   Public function tr($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'tr', $attributes, $styles, false, true, true);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function tt($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'tt', $text, $attributes, $styles, true, false, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function u($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'u', $text, $attributes, $styles, true, false, false);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function ul($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'ul', $attributes, $styles, false, true, true);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function varriable($text = null, $attributes = null, $styles = null) {
      $this->_shift($text, $attributes, $styles);
      $tag = $this->inlineElement($this, 'var', $text, $attributes, $styles, true, false, false);
      $this->addContent($tag);
      return $tag;
   }
 
 
   Public function body($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'body', $attributes, $styles, false, true, true);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function head($attributes = null, $styles = null) {
      $tag = new Document_Html_Element($this, 'head', $attributes, $styles, false, true, true);
      $this->addContent($tag);
      return $tag;
   }
 
   Public function inlineElement($parent, 
                                 $tagName = null,
                                 $text = null, 
                                 $attributes = null, 
                                 $styles = null,
                                 $singleLine = null,
                                 $indent = null,
                                 $identContent = null)
   {
      $tag = new Document_Html_Element($parent, $tagName, $attributes, $styles, $singleLine, $indent, $identContent);
      $tag->addContent($text);
      return $tag;
   }
 
   Public function append($object, $method) {
      try {
         $object->$method($this);
      } catch (Exception $e) {}
      return $this;
   }
 
   public function __call($method, $params) {
      $doc = $this->getDocument();
      if (method_exists($doc, $method)) {
         #Fast_Debug::show('call_user_func_array',array(array(&$component, $method), $params));
         $res = $this->append($doc, $method);
      }
      return $this;
   }
}
?><?php
//et un exemple d'utilisation
Zend_Loader::loadClass('Document_Html');
 
class View_Main extends Document_Html
{
   public function __construct()
   {
      #Fast_Debug::show('$this->data',$this->data);   
      //parent::__construct($doctype , $dtd, $version);
      parent::__construct();
   }
 
   public function make () {
      #Fast_Debug::show('$this->data',$this->data);   
      $this
         ->addNameSpace('fast', 'urn:org.jquery.fast')
         ->setNSAtrribute('fast','includepath', $this->data->baseUrl.'/public/scripts/org.jquery.fast/components/')
         ->setLanguage('fr')
         ->makeHead()
         ->getBody()
            ->div(array('id'=> 'page'))
               ->aName(' ','top')->getParent()
               ->makeBanner()
               ->makeMenu()
               ->makeMessage()
               ->makeContent()
               ->makeFooter()
 
      ;
   }
 
   public function makeHead () {
      $this->getHead()
            ->contentType()
            ->title($this->data->title)
            ->addScript($this->data->baseUrl.'/public/scripts/org.jquery.fast/jquery-latest.js')
            ->addScript($this->data->baseUrl.'/public/scripts/org.jquery.fast/org.jquery.fast.js')
            ->addScript($this->data->baseUrl.'/public/scripts/org.jquery.fast/components/cascadingselect.js')
            ->linkStyle($this->data->baseUrl.'/public/styles/default.css', 'screen')
      ;
      return $this;
   }
 
   public function makeBanner ($element) {
      $banner = $element->div(array('id'=> 'banner'));
      $banner->table(array('width'=>'100%', 
                   'border'=>0, 
                   'cellspacing'=>0, 
                   'cellpadding'=>0))
        ->tbody()
           ->tr()
              ->td(array('align'=>'left', 'height'=>52, 'valign'=>'top'))
                 ->image($this->data->baseUrl.'/public/images/orange_logo.gif', array('width'=>40, 'height'=>40))
                 ->getParent()
              ->td(array('class'=>'title', 'height'=>52, 'align'=>'center', 'valign'=>'top'))
                 ->span('Fast', array('class'=>'left'))
                    ->getParent()
                 ->text(' Application')
                    ->getParent()
              ->td(array('align'=>'right', 'height'=>52, 'valign'=>'top'))
                 ->image($this->data->baseUrl.'/public/images/esperluette.gif', array('width'=>32, 'height'=>35));
 
      $banner->table(array('width'=>'100%', 
                   'border'=>0, 
                   'cellspacing'=>0, 
                   'cellpadding'=>0))
        ->tbody()
           ->tr()
              ->td()
                 ->image($this->data->baseUrl.'/public/images/bureauxVitres.jpg', array('width'=>590, 'height'=>73))
                 ->getParent()
              ->td()
                 ->makeStats()
      ;
   }
 
   public function makeFooter ($element) {
      $footer = $element->div(array('id'=> 'piedDePage'))
         ->table(array('width'=>'100%', 
                      'border'=>0, 
                      'cellspacing'=>0, 
                      'cellpadding'=>0))
           ->tbody()
              ->tr();
 
      $footer->td(array('nowrap' => 'nowrap'))
         ->span(array('class' => 'diffusion'))
            ->text('interne Groupe France Télécom');
 
      $footer->td(array('class' => 'separateur'))->noBreakSpace();
 
      $bonhomme = $footer->td(array('nowrap' => 'nowrap'));
      if($this->data->user) {
         $bonhomme->homme();
      } else {
         $bonhomme->hommeGris();
      }
 
      $footer->td(array('class' => 'separateur'))->noBreakSpace();
 
      if($this->data->user) {
         $footer->td(array('nowrap' => 'nowrap'))
            ->flecheDroiteGris()
            ->text($this->data->user->usr_firstname . ' ' . $this->data->user->usr_name)
            ->br()
            ->aHref(null, $this->data->baseUrl.'/login/auth/newpwd')
               ->flecheDroite()
               ->text('Changer de mot de passe')
         ;
         $footer->td(array('class' => 'separateur'))->noBreakSpace();
 
         if ($this->data->user->profile) {
            $footer->td(array('nowrap' => 'nowrap'))
               ->flecheDroiteGris()
               ->text($this->data->user->profile->rol_label)
               ->br()
               ->flecheDroiteGris()
               ->text($this->data->user->profile->wkg_label);
         }
      }
 
      $connexion = $footer->td(array('nowrap' => 'nowrap'));
      if($this->data->user) {
         $connexion->flecheDroite()
               ->aHref('Déconnexion', $this->data->baseUrl.'/login/auth/logout')
               ->br()
               ->flecheDroite()
               ->aHref('Changer de profil', $this->data->baseUrl.'/login/auth/showRoles');
      } else {
         $connexion->flecheDroite()
               ->aHref('Connexion', $this->data->baseUrl.'/login/auth/showLogin');
      }
 
      $footer->td(array('class' => 'separateur'))->noBreakSpace();
 
      $footer->td(array('nowrap' => 'nowrap'))
         ->flecheDroite()
         ->aHref('Réalisé par ', 'http://metiertransverse.vente.francetelecom.fr/Site.do?position=FAST&site=Processus_France', array('target' => '_blank'))
            ->fastLogo();
 
      $footer->td(array('class' => 'separateur'))->noBreakSpace();
 
      $footer->td(array('nowrap' => 'nowrap'))
         ->flecheDoubleHaut()
         ->aHref('haut de page', '#top');
 
   }
 
 
   public function makeStats ($element) {
      $element->table(array( 'width'       => '90%',
                             'height'      => 73,
                             'align'       => 'right', 
                             'cellspacing' => 0, 
                             'cellpadding' => 3),
                      array('background-color' => '#EEEEEE', 
                            'border'           => 'solid 1px #DDDDDD',
                            'margin-bottom'    => '3px')
                     )
         ->tbody()
            ->tr()
               ->td('My App en chiffres', null, 
                  array('background-color'=>'#DDDDDD', 
                        'font-weight' => 'bold'))
                  ->getParent()
               ->getParent()
            ->tr()
               ->td('(x) remontées déposées')
                  ->getParent()
               ->getParent()
            ->tr()
               ->td('(x) remontées concrétisées')
                  ->getParent()
               ->getParent()
 
      ;
   }
 
   public function makeMenu ($element) {
      if (isset($this->data->menus)) {
         $nmuContent = $element
            ->table(array('class'       => 'menus', 
                          'border'      => 0, 
                          'cellspacing' => 0, 
                          'cellpadding' => 0))
               ->tbody()
                  ->tr();
         foreach ($this->data->menus as $menu) {
            $mnuItem = $nmuContent->td(array('title', $menu->help));
            if ('true' == $menu->actif) {
               $mnuItem->aHref(null,$this->data->baseUrl.'/'.$menu->url)
                  ->flecheDroite()
                  ->text($menu->label);
            } else {
               $mnuItem->aHref(null,'#', array('onClick' => 'return false;',
                                               'class' => 'inactif'
                                              ))
                  ->flecheDroite()
                  ->text($menu->label);
            }
         }
      }
   }
 
   public function makeMessage($element) {
      $msg = $element->div(array('id' => 'message'));
      if ($this->data->messages) {
         $msg->div(array('class' => 'hd'))
            ->div(array('class' => 'c'));
 
         $msgitem = $msg->div(array('class' => 'bd'))
            ->div(array('class' => 'c'))
               ->div(array('class' => 's'));
 
         foreach ($this->data->messages as $message) {
            $msgitem->li($message->label, array('class'=>'type'));
         }
 
         $msg->div(array('class' => 'ft'))
            ->div(array('class' => 'c'));
      }              
   }
 
   public function flecheDoubleHaut ($element) {
      $element->image($this->data->baseUrl.'/public/images/flecheDoubleHaut.gif', array('width'=>8, 'height'=>8));
   }
 
   public function flecheDroite ($element) {
      $element->image($this->data->baseUrl.'/public/images/flecheDroite.gif', array('width'=>8, 'height'=>8));
   }
 
   public function flecheDroiteGris ($element) {
      $element->image($this->data->baseUrl.'/public/images/flecheDroiteGris.gif', array('width'=>8, 'height'=>8));
   }
 
   public function flecheGauche ($element) {
      $element->image($this->data->baseUrl.'/public/images/flecheGauche.gif', array('width'=>8, 'height'=>8));
   }
 
   public function homme ($element) {
      $element->image($this->data->baseUrl.'/public/images/bonhomme.gif', array('width'=>18, 'height'=>24, 'align'=>'left'));
   }
 
   public function hommeGris ($element) {
      $element->image($this->data->baseUrl.'/public/images/bonhommeGris.gif', array('width'=>18, 'height'=>24, 'align'=>'left'));
   }
 
   public function fastLogo ($element) {
      $element->image($this->data->baseUrl.'/public/images/logo_fast_h10.gif', array('width'=>29, 'height'=>10, 'alt'=>'fast'));
   }
 
   public function makeContent($content) {
      include $this->data->_content;
   }
 
}
 
Graphisme réalisé par l'agence Rodolphe Eveilleau
Développement par Kitpages