Date: 11/10/99
- Next message: Kristian Köhntopp: "Re: [PHPLIB-DEV] Re: [PHPLIB] active_sessions"
- Previous message: Charles P. Wright: "[PHPLIB-DEV] Re: [PHPLIB] active_sessions"
- Next in thread: athompso: "[PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: kk
Date: Wed Nov 10 14:26:14 1999
Removed files:
php-lib/pages/menu/button.php3
Modified files:
php-lib/CHANGES
php-lib/php/menu.inc
php-lib/php/menu_button.inc
Log message:
Got rid of button.php3 by integrating the button generation
into the Menu_Button class. Should have done it that way the first time.
Index: php-lib/CHANGES
diff -u php-lib/CHANGES:1.143 php-lib/CHANGES:1.144
--- php-lib/CHANGES:1.143 Sat Nov 6 21:40:24 1999
+++ php-lib/CHANGES Wed Nov 10 14:25:41 1999
@@ -1,4 +1,8 @@
-$Id: CHANGES,v 1.143 1999/11/06 20:40:24 kk Exp $
+$Id: CHANGES,v 1.144 1999/11/10 13:25:41 kk Exp $
+
+10-Nov-1999 kk
+ - Hey, it is much faster this way. We do not need to call a PHP
+ interpreter for each button we create!
06-Nov-1999 kk
- Menu_Button now has mouseover capabilities; button.php3
Index: php-lib/php/menu.inc
diff -u php-lib/php/menu.inc:1.5 php-lib/php/menu.inc:1.6
--- php-lib/php/menu.inc:1.5 Sat Nov 6 21:43:02 1999
+++ php-lib/php/menu.inc Wed Nov 10 14:25:43 1999
@@ -5,7 +5,7 @@
* Copyright (c) 1999 NetUSE GmbH
* Kristian Koehntopp
*
- * $Id: menu.inc,v 1.5 1999/11/06 20:43:02 kk Exp $
+ * $Id: menu.inc,v 1.6 1999/11/10 13:25:43 kk Exp $
*
*/
class Menu {
@@ -26,6 +26,9 @@
# $visible[1] = "/1";
var $visible = array();
+ # Class to render menu items in
+ var $class = "";
+
# Set true if you do not want to see the main menu
var $nomain = false;
@@ -71,7 +74,7 @@
$str .= $this->shift_out($oldlevel, $level);
$oldlevel = $level;
- $str .= $this->get_cell($i, $level);
+ $str .= $this->get_cell($i, $level, $this->class);
}
$str .= $this->end_menu();
@@ -80,14 +83,15 @@
/* public: show a single menu cell
*/
- function get_cell($n, $level) {
+ function get_cell($n, $level, $class = "") {
$bold = ($this->visible[$n] == $this->map);
for ($i=1; $i<$level; $i++)
$dent .= " ";
- $str = sprintf("%s<a href=%s>%s%s%s</a><br>\n",
+ $str = sprintf("%s<a href=\"%s\"%s>%s%s%s</a><br>\n",
$dent,
$this->item[$this->visible[$n]]["url"],
+ $class?" class=$class":"",
$bold?"<b>":"",
$this->item[$this->visible[$n]]["title"],
$bold?"</b>":""
Index: php-lib/php/menu_button.inc
diff -u php-lib/php/menu_button.inc:1.3 php-lib/php/menu_button.inc:1.4
--- php-lib/php/menu_button.inc:1.3 Sat Nov 6 21:43:02 1999
+++ php-lib/php/menu_button.inc Wed Nov 10 14:25:43 1999
@@ -5,31 +5,97 @@
* Copyright (c) 1999 NetUSE GmbH
* Kristian Koehntopp
*
- * $Id: menu_button.inc,v 1.3 1999/11/06 20:43:02 kk Exp $
+ * $Id: menu_button.inc,v 1.4 1999/11/10 13:25:43 kk Exp $
*
*/
class Menu_Button extends Menu {
- var $classname = "Menu_Button";
- var $button_path = "/menu/button.php3";
+ var $classname = "Menu_Button";
+ var $font = "$DOCUMENT_ROOT/fonts/arialbd.ttf";
+ var $fsize = array(16, 14, 12, 10, 8);
+ var $cache_dir = "$DOCUMENT_ROOT/cache";
+ var $cache_url = "/cache";
+ var $w = 160;
+ var $h = 20;
+
function Menu_Button() {
$this->setup();
}
+ function button($text, $level, $selected, $hilite) {
+ if ($level <1) $level = 1;
+ if ($level > count($this->fsize)) $level = count($this->fsize);
+ $selected = $selected?1:0;
+ $hilite = $hilite?1:0;
+ $level--;
+
+
+ ## Filename in cache directory
+ $hash = md5("$text:$level:$selected:$hilite");
+
+ ## Cache filename, do not change
+ $file = sprintf("%s/%s.gif", $this->cache_dir, $hash);
+ $url = sprintf("%s/%s.gif", $this->cache_url, $hash);
+
+ ## If cache does not exist, try to create it.
+ if (!file_exists($this->cache_dir) or !is_dir($this->cache_dir)) {
+ mkdir($this->cache_dir, 0755) or die;
+ }
+
+ ## If file is not in Cache, create it
+ $w = $this->w;
+ $h = $this->h;
+ if (!file_exists($file)) {
+ $im = Imagecreate($w, $h);
+
+ $tx_unselected = Imagecolorallocate($im, 0, 0, 0);
+ $tx_selected = Imagecolorallocate($im, 255, 255, 255);
+
+ $lo_selected = Imagecolorallocate($im, 64, 128, 64);
+ $hi_selected = Imagecolorallocate($im, 192, 128, 128);
+
+ $colbase = 255;
+ $colstep = -16;
+ for ($i=0; $i<count($this->fsize); $i++) {
+ $col = $colbase+$colstep*$i;
+ $locolor[$i] = Imagecolorallocate($im, $col, 255, $col);
+ $hicolor[$i] = Imagecolorallocate($im, 255, $col, $col);
+ }
+
+ if ($hilite)
+ $bg = $selected?$hi_selected:$hicolor[$level];
+ else
+ $bg = $selected?$lo_selected:$locolor[$level];
+
+ $tx = $selected?$tx_selected:$tx_unselected;
+
+ imagefilledrectangle($im, 0, 0, $w, $h, $bg);
+
+ imagettftext($im, $this->fsize[$level],
+ 0, 8*$level, $h-5, $tx,
+ $this->font, $text);
+
+ ## imagepng($im, $file); since a few weeks.
+ imagegif($im, $file);
+ }
+
+ return $url;
+ }
+
function get_cell($n, $level) {
$selected = ($this->visible[$n] == $this->map);
-
- $image_url = sprintf("%s?text=%s&level=%s&selected=%s",
- $this->button_path,
- urlencode($this->item[$this->visible[$n]]["title"]),
- $level,
- $selected);
- $image_url_low = "$image_url&hilite=0";
- $image_url_high = "$image_url&hilite=1";
+ $image_url_low = $this->button(
+ $this->item[$this->visible[$n]]["title"],
+ $level, $selected, 0
+ );
+ $image_url_high = $this->button(
+ $this->item[$this->visible[$n]]["title"],
+ $level, $selected, 1
+ );
$mouseover = "document.images[\"img$n\"].src = img${n}_h.src; return true";
$mouseout = "document.images[\"img$n\"].src = img${n}_l.src; return true";
-
+
$str .= sprintf("<script language=javascript><!--
img${n}_l = new Image(); img${n}_l.src = \"%s\";
img${n}_h = new Image(); img${n}_h.src = \"%s\";
-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.
- Next message: Kristian Köhntopp: "Re: [PHPLIB-DEV] Re: [PHPLIB] active_sessions"
- Previous message: Charles P. Wright: "[PHPLIB-DEV] Re: [PHPLIB] active_sessions"
- Next in thread: athompso: "[PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

