PHP Classes

File: menu_button.php

Recommend this page to a friend!
  Classes of Russell Nash   Expandable Menu   menu_button.php   Download  
File: menu_button.php
Role: Application script
Content type: text/plain
Description: Generates graphics for menu
Class: Expandable Menu
Generate an expandable menu of links
Author: By
Last change: better handling of data and sessions added
Date: 18 years ago
Size: 3,750 bytes
 

Contents

Class file image Download
<?php
header
("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
//again... by Avram
session_start(); //initialize session
//function to convert hexadecimal color values to r g b values
 
function hex2rgb($hex, $asString = false)
   {
       if (
0 === strpos($hex, '#')) {
          
$hex = substr($hex, 1);
       } else if (
0 === strpos($hex, '&H')) {
          
$hex = substr($hex, 2);
       }
      
$cutpoint = ceil(strlen($hex) / 2)-1;
      
$rgb = explode(':', wordwrap($hex, $cutpoint, ':', $cutpoint), 3);
      
$rgb[0] = (isset($rgb[0]) ? hexdec($rgb[0]) : 0);
      
$rgb[1] = (isset($rgb[1]) ? hexdec($rgb[1]) : 0);
      
$rgb[2] = (isset($rgb[2]) ? hexdec($rgb[2]) : 0);
       return (
$asString ? "{$rgb[0]} {$rgb[1]} {$rgb[2]}" : $rgb);
   }
//get data from session
$data = $_SESSION['MenuData'];
//create variables
$MenuWidth = $data['MenuWidth'];
$MenuItemHeight = $data['MenuItemHeight'];
$MainMenuColor = $data['MainMenuColor'];
$MainMenuHoverColor = $data['MainMenuHoverColor'];
$SubMenuColor = $data['SubMenuColor'];
$SubMenuHoverColor = $data['SubMenuHoverColor'];
$MenuSeperatorColor = $data['MenuSeperatorColor'];
$MenuFontMainColor = $data['MenuFontMainColor'];
$MenuFontShadowColor = $data['MenuFontShadowColor'];
$MenuFontSize = $data['MenuFontSize'];
//eo code by Avram
//following block of code is modified by Avram (to the eof)
$string = stripslashes($_GET['text']);
$typ = $_GET['typ'];
$extra = $_GET['extra'];
$image = imagecreate($MenuWidth, $MenuItemHeight);
$rgb = hex2rgb($MainMenuColor);
$col_MainMenuA = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
$rgb = hex2rgb($MainMenuHoverColor);
$col_MainMenuB = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
$rgb = hex2rgb($SubMenuColor);
$col_SubMenuA = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
$rgb = hex2rgb($SubMenuHoverColor);
$col_SubMenuB = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
$rgb = hex2rgb($MenuFontMainColor);
$col_Text = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
$rgb = hex2rgb($MenuFontShadowColor);
$col_Shadow = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
if(
$typ == '_std' && $extra != "sub") {
   
$Border = $col_MainMenuA;
   
$Fill = $col_MainMenuA;
} else {
   
$Border = $col_MainMenuB;
   
$Fill = $col_MainMenuB;
}
if(
$typ == '_std' && $extra == "sub") {
   
$string = " ". $string;
   
$Border = $col_SubMenuA;
   
$Fill = $col_SubMenuA;
} elseif(
$typ == '_hov' && $extra == "sub") {
   
$string = " ". $string;
   
$Border = $col_SubMenuB;
   
$Fill = $col_SubMenuB;
}
imagerectangle($image, 0, 0, $MenuWidth-1, $MenuItemHeight-1, $Border);
imagefilledrectangle($image, 1, 1, $MenuWidth-2, $MenuItemHeight-2, $Fill);
if (
$MenuFontShadowColor != 0) {
   
imagestring($image, $MenuFontSize, 6, 2, $string, $col_Shadow);
}
imagestring($image, $MenuFontSize, 5, 1, $string, $col_Text);
if(
$typ == '_std' && $extra == "par") {
    if (
$MenuFontShadowColor != 0) {
       
imagestring($image, $MenuFontSize, $MenuWidth-20, 2, ">>", $col_Shadow);
    }
   
imagestring($image, $MenuFontSize, $MenuWidth-21, 1, ">>", $col_Text);
} elseif(
$typ == '_hov' && $extra == "par") {
    if (
$MenuFontShadowColor != 0) {
       
imagestringup($image, $MenuFontSize, $MenuWidth-20, 16, "<<", $col_Shadow);
    }
   
imagestringup($image, $MenuFontSize, $MenuWidth-21, 17, "<<", $col_Text);
}
if (
function_exists("imagegif")) {
   
header("Content-type: image/gif");
   
imagegif($image);
} else {
   
header("Content-type: image/png");
   
imagepng($image);
}
imagedestroy($image);
?>