Version: 0.9

Type: Class

Category: HTML

License: GNU Library Public License

Description: A set of classes that will allow you to build HTML documents completely w/ objects in PHP. This is only the most basic layer but it is easy to build onto.



<?	/* Object HTML v.0.9	(LGPL)			*/
	/* An object oriented way of working w/ HTML.	*/
	/* Michael Ogmios <mogmios@mlug.missouri.edu>	*/

class plaintext {
 /* An object for storing a chunk of text until needed. */

 var $text;

 function plaintext ( $text = "" ) {
  $this->text = $text;
 }

 function fetch() {
  return $this->text . "\n";
 }
}

class html_element {
 /* An object for building HTML documents, allows you to specify the type
    of tag, it's arguments, and embed other HTML tags and text as objects
    inside of it. */

 var $tag;
 var $arguments;
 var $is_container;
 var $contents = array();

 function html_element( $tag = "HTML", $arguments = array(), $is_container = TRUE ) {
  $this->tag = $tag;	// Name of the tag.
  $this->arguments = $arguments;	// Array of argument/value pairs.
  $this->is_container = $is_container;	// Is this a containing object?
 }

 function add_element( $element ) {
  $this->contents[] = $element;
 }

 function fetch() {
  $html = $this->build_opening_tag() . "\n";

  if( $this->is_container ) {
   $html = $html . $this->fetch_content();
   $html = $html . $this->build_closing_tag() . "\n";
  }

  return $html;
 }

 function fetch_content() {
  $html = "";

  foreach( $this->contents as $element ) {
   $html = $html . $element->fetch();
  }

  return $html;
 }

 function build_arguments() {
  $arg_str = "";

  while( list( $key, $value ) = each( $this->arguments ) ) {
   $arg_str = $arg_str . " " . $key . "=" . $value;
  }

  return $arg_str;
 }

 function build_opening_tag() {
  return "<" . $this->tag . $this->build_arguments() . ">";
 }

 function build_closing_tag() {
  return "</" . $this->tag . ">";
 }
}

class head_element extends html_element {

 function head_element() {
  $this->html_element( "HEAD" );
 }
}

class body_element extends html_element {

 function body_element( $arguments = array() ) {
  $this->html_element( "BODY", $arguments );
 }
}

class title_element extends html_element {

 function title_element() {
  $this->html_element( "TITLE" );
 }
}

class base_element extends html_element {

 function base_element( $arguments = array() ) {
  $this->html_element( "BASE" , $arguments, FALSE );
 }
}

class meta_element extends html_element {

 function meta_element( $arguments = array() ) {
  $this->html_element( "META", $arguments, FALSE );
 }
}

class style_element extends html_element {

 function style_element( $arguments = array() ) {
  $this->html_element( "STYLE", $arguments );
 }
}

class link_element extends html_element {

 function link_element( $arguments = array() ) {
  $this->html_element( "LINK", $arguments );
 }
}

class address_element extends html_element {

 function address_element( $arguments = array() ) {
  $this->html_element( "ADDRESS", $arguments );
 }
}

class blockquote_element extends html_element {

 function blockquote_element( $arguments = array() ) {
  $this->html_element( "BLOCKQUOTE", $arguments );
 }
}

class div_element extends html_element {

 function div_element( $arguments = array() ) {
  $this->html_element( "DIV", $arguments );
 }
}

class h1_element extends html_element {

 function h1_element( $arguments = array() ) {
  $this->html_element( "H1", $arguments );
 }
}

class h2_element extends html_element {

 function h2_element( $arguments = array() ) {
  $this->html_element( "H2", $arguments );
 }
}

class h3_element extends html_element {

 function h3_element( $arguments = array() ) {
  $this->html_element( "H3", $arguments );
 }
}

class h4_element extends html_element {

 function h4_element( $arguments = array() ) {
  $this->html_element( "H4", $arguments );
 }
}

class h5_element extends html_element {

 function h5_element( $arguments = array() ) {
  $this->html_element( "H5", $arguments );
 }
}

class h6_element extends html_element {

 function h6_element( $arguments = array() ) {
  $this->html_element( "H6", $arguments );
 }
}

class p_element extends html_element {

 function p_element( $arguments = array() ) {
  $this->html_element( "P", $arguments );
 }
}

class pre_element extends html_element {

 function pre_element( $arguments = array() ) {
  $this->html_element( "PRE", $arguments );
 }
}

class xmp_element extends html_element {

 function xmp_element( $arguments = array() ) {
  $this->html_element( "XMP", $arguments );
 }
}

class dir_element extends html_element {

 function dir_element( $arguments = array() ) {
  $this->html_element( "DIR", $arguments );
 }
}

class dl_element extends html_element {

 function dl_element( $arguments = array() ) {
  $this->html_element( "DL", $arguments );
 }
}

class dt_element extends html_element {

 function dt_element( $arguments = array() ) {
  $this->html_element( "DT", $arguments, FALSE );
 }
}

class dd_element extends html_element {

 function dd_element( $arguments = array() ) {
  $this->html_element( "DD", $arguments );
 }
}

class menu_element extends html_element {

 function menu_element( $arguments = array() ) {
  $this->html_element( "MENU", $arguments );
 }
}

class ol_element extends html_element {

 function ol_element( $arguments = array() ) {
  $this->html_element( "OL", $arguments );
 }
}

class ul_element extends html_element {

 function ul_element( $arguments = array() ) {
  $this->html_element( "UL", $arguments );
 }
}

class li_element extends html_element {

 function li_element( $arguments = array() ) {
  $this->html_element( "LI", $arguments );
 }
}

class b_element extends html_element {

 function b_element( $arguments = array() ) {
  $this->html_element( "B", $arguments );
 }
}

class basefont_element extends html_element {

 function basefont_element( $arguments = array() ) {
  $this->html_element( "BASEFONT", $arguments, FALSE );
 }
}

class big_element extends html_element {

 function big_element() {
  $this->html_element( "BIG" );
 }
}

class blink_element extends html_element {

 function blink_element() {
  $this->html_element( "BLINK" );
 }
}

class cite_element extends html_element {

 function cite_element() {
  $this->html_element( "CITE" );
 }
}

class code_element extends html_element {

 function code_element() {
  $this->html_element( "CODE" );
 }
}

class em_element extends html_element {

 function em_element() {
  $this->html_element( "EM" );
 }
}

class font_element extends html_element {

 function font_element( $arguments = array() ) {
  $this->html_element( "FONT", $arguments );
 }
}

class i_element extends html_element {

 function i_element() {
  $this->html_element( "I" );
 }
}

class kbd_element extends html_element {

 function kbd_element() {
  $this->html_element( "KBD" );
 }
}

class plaintext_element extends html_element {

 function plaintext_element() {
  $this->html_element( "PLAINTEXT" );
 }
}

class s_element extends html_element {

 function s_element() {
  $this->html_element( "S" );
 }
}

class small_element extends html_element {

 function small_element() {
  $this->html_element( "SMALL" );
 }
}

class strike_element extends html_element {

 function strike_element() {
  $this->html_element( "STRIKE" );
 }
}

class strong_element extends html_element {

 function strong_element() {
  $this->html_element( "STRONG" );
 }
}

class sub_element extends html_element {

 function sub_element() {
  $this->html_element( "SUB" );
 }
}

class sup_element extends html_element {

 function sup_element() {
  $this->html_element( "SUP" );
 }
}

class tt_element extends html_element {

 function tt_element() {
  $this->html_element( "TT" );
 }
}

class u_element extends html_element {

 function u_element() {
  $this->html_element( "U" );
 }
}

class var_element extends html_element {

 function var_element() {
  $this->html_element( "VAR" );
 }
}

class a_element extends html_element {

 function a_element( $arguments = array() ) {
  $this->html_element( "A", $arguments );
 }
}

class img_element extends html_element {

 function img_element( $arguments = array() ) {
  $this->html_element( "IMG", $arguments, FALSE );
 }
}

class area_element extends html_element {

 function area_element( $arguments = array() ) {
  $this->html_element( "AREA", $arguments, FALSE );
 }
}

class map_element extends html_element {

 function map_element( $arguments = array() ) {
  $this->html_element( "MAP", $arguments );
 }
}

class table_element extends html_element {

 function table_element( $arguments = array() ) {
  $this->html_element( "TABLE", $arguments );
 }
}

class caption_element extends html_element {

 function caption_element( $arguments = array() ) {
  $this->html_element( "CAPTION", $arguments );
 }
}

class tr_element extends html_element {

 function tr_element( $arguments = array() ) {
  $this->html_element( "TR", $arguments );
 }
}

class td_element extends html_element {

 function td_element( $arguments = array() ) {
  $this->html_element( "TD", $arguments );
 }
}

class th_element extends html_element {

 function th_element( $arguments = array() ) {
  $this->html_element( "TH", $arguments );
 }
}

class form_element extends html_element {

 function form_element( $arguments = array() ) {
  $this->html_element( "FORM", $arguments );
 }
}

class input_element extends html_element {

 function input_element( $arguments = array() ) {
  $this->html_element( "INPUT", $arguments, FALSE );
 }
}

class select_element extends html_element {

 function select_element( $arguments = array() ) {
  $this->html_element( "SELECT", $arguments );
 }
}

class option_element extends html_element {

 function option_element( $arguments = array() ) {
  $this->html_element( "OPTION", $arguments );
 }
}

class textarea_element extends html_element {

 function textarea_element( $arguments = array() ) {
  $this->html_element( "TEXTAREA", $arguments );
 }
}

class keygen_element extends html_element {

 function keygen_element( $arguments = array() ) {
  $this->html_element( "KEYGEN", $arguments );
 }
}

class isindex_element extends html_element {

 function isindex_element( $arguments = array() ) {
  $this->html_element( "ISINDEX", $arguments );
 }
}

class frame_element extends html_element {

 function frame_element( $arguments = array() ) {
  $this->html_element( "FRAME", $arguments );
 }
}

class frameset_element extends html_element {

 function frameset_element( $arguments = array() ) {
  $this->html_element( "FRAMESET", $arguments );
 }
}

class noframes_element extends html_element {

 function noframes_element() {
  $this->html_element( "NOFRAMES" );
 }
}

class layer_element extends html_element {

 function layer_element( $arguments = array() ) {
  $this->html_element( "LAYER", $arguments );
 }
}

class ilayer_element extends html_element {

 function ilayer_element( $arguments = array() ) {
  $this->html_element( "ILAYER", $arguments );
 }
}

class nolayer_element extends html_element {

 function nolayer_element() {
  $this->html_element( "NOLAYER" );
 }
}

class script_element extends html_element {

 function script_element( $arguments = array() ) {
  $this->html_element( "SCRIPT", $arguments );
 }
}

class noscript_element extends html_element {

 function noscript_element() {
  $this->html_element( "NOSCRIPT" );
 }
}

class server_element extends html_element {

 function server_element() {
  $this->html_element( "SERVER" );
 }
}

class applet_element extends html_element {

 function applet_element( $arguments = array() ) {
  $this->html_element( "APPLET", $arguments );
 }
}

class param_element extends html_element {

 function param_element( $arguments = array() ) {
  $this->html_element( "PARAM", $arguments, FALSE );
 }
}

class embed_element extends html_element {

 function embed_element( $arguments = array() ) {
  $this->html_element( "EMBED", $arguments );
 }
}

class noembed_element extends html_element {

 function noembed_element() {
  $this->html_element( "NOEMBED" );
 }
}

class object_element extends html_element {

 function object_element( $arguments = array() ) {
  $this->html_element( "OBJECT", $arguments, FALSE );
 }
}

class br_element extends html_element {

 function br_element( $arguments = array() ) {
  $this->html_element( "BR", $arguments, FALSE );
 }
}

class center_element extends html_element {

 function _element( $arguments = array() ) {
  $this->html_element( "CENTER", $arguments );
 }
}

class hr_element extends html_element {

 function hr_element( $arguments = array() ) {
  $this->html_element( "HR", $arguments, FALSE );
 }
}

class multicol_element extends html_element {

 function multicol_element( $arguments = array() ) {
  $this->html_element( "MULTICOL", $arguments );
 }
}

class nobr_element extends html_element {

 function nobr_element() {
  $this->html_element( "NOBR" );
 }
}

class spacer_element extends html_element {

 function spacer_element( $arguments = array() ) {
  $this->html_element( "SPACER", $arguments, FALSE );
 }
}

class span_element extends html_element {

 function span_element( $arguments = array() ) {
  $this->html_element( "SPAN", $arguments );
 }
}

class wbr_element extends html_element {

 function wbr_element() {
  $this->html_element( "WBR" );
 }
}

?>