PHP Classes
elePHPant
Icontem

File: class.htRoundedMenus.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Harry  >  htRoundedMenus  >  class.htRoundedMenus.php  >  Download  
File: class.htRoundedMenus.php
Role: Class source
Content type: text/plain
Description: Contains the menu class.
Class: htRoundedMenus
Generate table-based menus with rounded corners.
Author: By
Last change: Added ability to set HTML for menu body instead of options. Added support for menus without a body -- only the headings appear (they kind of look like tabs).
Date: 11 years ago
Size: 5,799 bytes
 

Contents

Class file image Download
<?php
//////////////////////////////////////////////////////////////////////////////
// Class: htRoundedMenus
//
// Make sure you get the GIFs for the corners and the 1x1 transparent pixel.
// Otherwise, the menus won't look right.
// The GIFs, this file, and example usage are available at:
// http://www.harrytravis.com/htRoundedMenus/htRoundedMenus.zip
//
// Add menus with rounded corners to your web page.
// See rounded.php for example usage.
// This is fairly procedural instead of OO, but some things should be...
//
// This is absolutely free.
// Use it at your own risk.
// Do whatever you want with it.
//
// I'd be interested to hear if you find it useful.
//
// Author: Harry Travis, me@harrytravis.com
//////////////////////////////////////////////////////////////////////////////
class htRoundedMenus
{
  
///////////////////////////////////////////////////////////////////////////
   // Instantiate one htRoundedMenus object per page.
  
function htRoundedMenus()
   {
     
// overwrite these values to customize your menus
     
$this->background_color = "99CCCC";
     
$this->foreground_color = "FFFF99";
     
$this->title_font_style = "color:ffff99; text-decoration:none; font-weight:bold; font-size:12pt; font-family:trebuchet,trebuchet MS,arial,sans-serif;";
     
$this->option_font_style = "color:99cccc; text-decoration:none; font-size:12pt; font-family:trebuchet,trebuchet MS,arial,sans-serif;";

     
// width of the menu (pixels)
     
$this->menu_width = 150;

     
// space between menus
     
$this->menu_padding = 3;

     
// URLs for left and right rounded corners
     
$this->left_corner = "left_corner.gif";
     
$this->right_corner = "right_corner.gif";
     
$this->one_by_one = "1x1.gif";
   }

  
///////////////////////////////////////////////////////////////////////////
   // For each menu on your page, call this method.
   // URL is optional.
  
function NewMenu($title_text,$title_url="")
   {
     
$this->title_text = $title_text;
     
$this->title_url = $title_url;
     
$this->options = array();
     
$this->inner_html = "";
   }

  
///////////////////////////////////////////////////////////////////////////
   // For each option on a menu, call this method.
   // URL is optional.
   // Do not add two options with same title to a menu.
  
function AddOption($text,$url="")
   {
     
$this->options[$text] = $url;
   }

  
///////////////////////////////////////////////////////////////////////////
   // Setting inner HTML replaces all options.
   // Options and inner HTML are mutually exclusive.
  
function SetInnerHTML($html)
   {
     
$this->inner_html = $html;
   }

  
///////////////////////////////////////////////////////////////////////////
  
function OpenMenu()
   {
      if (
$this->title_url )
      {
        
$title = "<a style='".$this->title_font_style."' ".
                 
"href='".$this->title_url."'>".$this->title_text."</a>";
      }
      else
      {
        
$title = "<font style='".$this->title_font_style."'>".
                 
$this->title_text."</font>";
      }
     
?>
<table border=0 cellpadding=0 cellspacing=0 bgcolor="<?=$this->background_color?>">
         <tr>
            <?php // each corner is 4 pixels wide, so subtract 8 from menu width for title cell ?>
<td><img src="<?=$this->left_corner?>" width=4 height=25 border=0></td>
            <td width="<?=$this->menu_width-8?>" style="<?=$this->title_font_style?>" valign="middle">
               <?=$title?>
</td>
            <td><img src="<?=$this->right_corner?>" width=4 height=25 border=0></td>
         </tr>
      <?php
  
}

  
///////////////////////////////////////////////////////////////////////////
  
function CloseMenu()
   {
     
// the height of this img sets the spacing between menus
     
?>
<tr><td colspan=3><img src="<?=$this->one_by_one?>" width="<?=$this->menu_width?>" height="<?=$this->menu_padding?>" border=0></td></tr>
      </table>
      <?php
  
}
  
  
///////////////////////////////////////////////////////////////////////////
  
function WriteMenuBody()
   {
     
// do nothing if no options and no HTML
     
if ( !$this->inner_html && count($this->options) == 0 )
      {
         return;
      }

     
// open menu body
     
?>
<tr>
         <td colspan=3>
            <table bordercolor="<?=$this->background_color?>" bgcolor="<?=$this->foreground_color?>" border=1 borderstyle="solid" cellpadding=3 cellspacing=0 width="100%">
               <tr><td>
      <?php

     
// write inner HTML
     
if ( $this->inner_html )
      {
         echo
"<font style='".$this->option_font_style."'>";
         echo
$this->inner_html;
         echo
"</font>\n";
      }
     
// write options
     
else if ( count($this->options) > 0 )
      {
         foreach (
$this->options as $text => $url )
         {
            if (
$url )
            {
              
$op = "<a style='".$this->option_font_style."' href='$url'>$text</a>\n";
            }
            else
            {
              
$op = "<font style='".$this->option_font_style."'>$text</font>";
            }
            echo
"&nbsp;$op<br>";
         }
      }

     
// close menu body
     
?>
</td></tr>
            </table>
         </td>
      </tr>
      <?php
  
}

  
///////////////////////////////////////////////////////////////////////////
   // After all options have been added to a menu, call this method.
   // It prints out the HTML for the menu.
  
function WriteMenu()
   {
     
$this->OpenMenu();
     
$this->WriteMenuBody();
     
$this->CloseMenu();
      return;
   }
}
?>