PHP Classes
elePHPant
Icontem

ezhtml: Framework to generate HTML head, body and divs

Recommend this page to a friend!
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2006-01-09 (10 years ago) RSS 2.0 feedStarStarStar 53%Total: 1,457 All time: 2,595 This week: 909Up
Version License Categories
ezhtml 1.0Freely DistributableHTML
Description Author

Debugging Helper, meta tag helper, fast html page building, changing query_strings, "folders" fold parts of the page away, div helper.

Picture of Peter Klauer
Name: Peter Klauer <contact>
Classes: 18 packages by
Country: Germany Germany
Innovation award
Innovation award
Nominee: 3x

Details
ezhtml readme.txt doc file
Peter Klauer, September 3 2003
updated on May 20 2004

Themes covered by this document:

Functions in the class
Variables in the class
Example

This class is called "ezhtml" (spoken: easy html) because of its ease of use 
and the name "html" already being used for another class (not from the author).

This class is tested with "register_globals" set to "ON".
Passing the folder variables may not work if "register_globals" is set to "OFF"
in the php.ini file. Please look up "register_folders()" and place it before a 
folder is used.

********************************************************************************
********************************************************************************
Functions in the class:
********************************************************************************
********************************************************************************

constructor html()
function head()
function body()
function foot()
function db()
function h()
function br()
function isempty()
function notisempty()
function adjust_query_string()
function folder()
function register_folders()

********************************************************************************
constructor html( $title = 'no name', $path = '' )
********************************************************************************

The constructor is called with an optional $title and $path value. The $path
is used to find cssfile, jsfile and iconfile if the web site is made of code
within directories. Anyway, it is assumed that cssfile, jsfile and iconfile
lie within the same directory to have it work properly.

********************************************************************************
function head()
********************************************************************************

The function html::head() is called without any parameters at all. Please look
at the variables that can be set and set them before making a call to head().
This function returns a value. Per default this value is TRUE.

This function fills a html <head>... </head> section - nearly. The finishing
</head> tag is not written yet. The function leaves an open <head>, waiting
to be closed by the following body() function. This gives opportunity to fill
in lots of metas or style sheet links or other external script links.

If the var html::onhead is the name of a user defined function, this function
is executed at the end of head() and the returning value of the user defined
function is returned from html::head().

The following vars cause html::head() to do something. All of them have to
be set before html::head() is called or left as preset:

title path ob obhandler refresh debug cssfile iconfile jsfile language 
imagetoolbar onhead

********************************************************************************
function body()
********************************************************************************

The function html::body() is also to be called without any argument. The first
thing this function does is: It closes the <head> section with a </head> tag and
opens the <body> section. The body section is left open and is assumed to
become closed by the foot() function.

If the var html::onbody is the name of a user defined function, this function
is executed at the end of body() and the returning value of the user defined
function is returned from html::body().

The following vars cause html::body() to do something. All of them have to
be set before html::body() is called or left as preset:

bodyextra onbody

********************************************************************************
function foot()
********************************************************************************

The function html::foot() is called without argument. 

If the var html::onfoot is the name of a user defined function, this function
is executed at the very beginning of foot().

Then foot() will close the </body> and still open </html> tag and the returning 
value of the user defined function ( if any ) is returned from html::foot().

The following vars cause html::foot() to do something. All of them have to
be set before html::foot() is called or left as preset:

onfoot ob

********************************************************************************
function db( $s )
********************************************************************************

The function db() outputs debugging information if html::debug is set to TRUE.
This debugging info can be any string and is fully under programmer's control.

Example: $html->db("$PHP_SELF" );

********************************************************************************
function h( $ebene, $text )
********************************************************************************

The function h() generates <h1>,<h2> ... and so on tags. 

Example: $html->h(1, 'Big heading'); // outputs: '<H1>Big heading</H1>'

********************************************************************************
function br( $count )
********************************************************************************

Generates $count <br>s.

********************************************************************************
function isempty( $string )
********************************************************************************

Used internally to determine wether a given string is empty or not.
Returns TRUE if $string is empty. 

********************************************************************************
function notisempty( $string )
********************************************************************************

Used internally to determine wether a given string is empty or not.
Returs TRUE if the $string is not empty.

********************************************************************************
function adjust_query_string( $query_string, $newvalue )
********************************************************************************

This function is intended to manipulate a $QUERY_STRING. $QUERY_STRING is a PHP
variable containing all arguments of the page separated by the & ampersand.
$newvalue is something like "folder1=open".
It searches the $query_string for "folder1=" and deletes it from the string 
when the new values identifier is found. Then it adds the new value and returns
a newly build $query_string, where all separators now are tidy save "&amp;"
entities.
This function is of good use even outside of this class.

********************************************************************************
function folder( $caption, $text='' )
********************************************************************************

This is a very easy way to have folders on a html web page. It is like
"fire and forget". No need to remember anything about folder management.

There are two ways to have folders, depending on the second variable $text.
If $text is empty then the folder is used this way:

  if( $html->folder( 'Afoldercaption' ) )
  {
    echo "Now I declare this folder open!";
    # put anything here that works, even plain html (see test_class_html.php)
  }
  
If $text is not empty it will be even simpler:

  $html->folder( 'Anotherfoldercaption', $text );
  
The class keeps track of all vars and creates the global values 
folder1 .. folderX when needed.

********************************************************************************
function register_folders()
********************************************************************************

This function is only of use when "register_globals" is set to "OFF" in the
php.ini.

This function is meant to put the vars $folder1 ... $folderX from the 
$_GET array into global program space. The argument is the number of folder vars 
you wish to transfer. This should be the same number as the count of folders you 
have on your page.

Use this function before the first folder is used.
  
********************************************************************************
********************************************************************************
Variables in the class
********************************************************************************
********************************************************************************

title        string, is shown in the <title>...</title> tag.
 
path         string, used to find external data (css, js and icon)

ob           bool,   output buffering. Off by default.

obhandler    string, output handler. 'ob_gzhandler' by default.

refresh      bool,   set to TRUE to force the browser to reload the page
                     and do not cache it.
                     
debug        bool,   set to TRUE to have html::db() show its output.

cssfile      string, name of a cascaded style sheet file.

iconfile     string, name of an icon
  
jsfile       string, name of a javascript file

language     string, indicates the web pages language.

imagetoolbar bool,   set this one to FALSE to switch off the IE6 image toolbar.
                     TRUE by default.
                      
onhead       string, Name of an external function which shall be executed when 
                     calling head().
                     
onbody       string, Name of an external function which shall be executed when 
                     calling body().
                     
onfoot       string, Name of an external function which shall be executed when 
                     calling foot().

bodyextra    string, Extra information to be put right into the <body> tag.
                     Example: $html->bodyextra= ' bgcolor="navy"';
                     
********************************************************************************
********************************************************************************
Example:
********************************************************************************
********************************************************************************

# This example uses a onbody-Function to connect to the sql database

function connect2sqlserver()
{
  $host = 'mysqlhost.de';
  $db   = 'mydatabase';
  $user = 'myusername';
  $pw   = 'mypassword';
  
  $link = @mysql_pconnect( $host, $user, $pw );
  $dbhandle  = @mysql_select_db( $db, $link );
 
  return ( $dbhandle ); // is TRUE or FALSE
}

function myfoot()
{
  echo '<div class="footer">Copyright (c) 2003 by me.</div>';
}

$h = new html('SQL-Test');
$h->onbody = 'connect2sqlserver';
$h->onfoot = 'myfoot';

$h->head();
 
$sqlok = $h->body();

if( $sqlok == true )
{
  # SQL is ok, mysql_query at will
  ...
}
else
{
  echo 'Sorry, no SQL at this time.';
}

$h->foot();
  Files folder image Files  
File Role Description
Plain text file class_html.php Class The class file
Plain text file inc_strato_html.php Class Class to deal with SSL from STRATO (German Provider) extends base class in inc_html.php
Accessible without login Plain text file inc_strato_html.txt Doc. How to use the ssl extension with ezhtml
Accessible without login Plain text file readme.txt Doc. Doc file for inc_html.php
Accessible without login Plain text file test_class_html.php Example Testfile, Demo

 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,457
This week:0
All time:2,595
This week:909Up
 User Ratings  
 
 All time
Utility:62%StarStarStarStar
Consistency:66%StarStarStarStar
Documentation:75%StarStarStarStar
Examples:79%StarStarStarStar
Tests:-
Videos:-
Overall:53%StarStarStar
Rank:1786