1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare API - Graphical * |
---|
4 | * This file written by Lars Kneschke <lars@kneschke.de> * |
---|
5 | * Allows the creation of graphical buttons * |
---|
6 | * Copyright (C) 2001 Lars Kneschke * |
---|
7 | * -------------------------------------------------------------------------* |
---|
8 | * This library is part of the eGroupWare API * |
---|
9 | * http://www.egroupware.org/api * |
---|
10 | * ------------------------------------------------------------------------ * |
---|
11 | * This library is free software; you can redistribute it and/or modify it * |
---|
12 | * under the terms of the GNU Lesser General Public License as published by * |
---|
13 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
14 | * or any later version. * |
---|
15 | * This library is distributed in the hope that it will be useful, but * |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
18 | * See the GNU Lesser General Public License for more details. * |
---|
19 | * You should have received a copy of the GNU Lesser General Public License * |
---|
20 | * along with this library; if not, write to the Free Software Foundation, * |
---|
21 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
22 | \**************************************************************************/ |
---|
23 | |
---|
24 | |
---|
25 | class graphics |
---|
26 | { |
---|
27 | /* put a valid font here */ |
---|
28 | var $font="/opt/future-project/src/management-server/ttf/arial.ttf"; |
---|
29 | |
---|
30 | function createImage($_text, $_fontsize=11) |
---|
31 | { |
---|
32 | /* create filename */ |
---|
33 | $filename = 'button_' . md5($_text) . '.png'; |
---|
34 | $filename = strtolower($filename); |
---|
35 | |
---|
36 | /* see if file exists already, we cache it */ |
---|
37 | if (file_exists(PHPGW_IMAGES_FILEDIR.'/'.$filename)) |
---|
38 | { |
---|
39 | return $filename; |
---|
40 | } |
---|
41 | |
---|
42 | $size = imagettfbbox($_fontsize,0,$this->font,$_text); |
---|
43 | $dx = abs($size[2]-$size[0]); |
---|
44 | $dy = abs($size[5]-$size[3]); |
---|
45 | $xpad=9; |
---|
46 | $ypad=9; |
---|
47 | $im = imagecreate($dx+$xpad,$dy+$ypad); |
---|
48 | $blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF); |
---|
49 | $black = ImageColorAllocate($im, 0,0,0); |
---|
50 | $white = ImageColorAllocate($im, 255,255,255); |
---|
51 | ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black); |
---|
52 | ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white); |
---|
53 | ImageTTFText($im, $_fontsize, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), -$black, $this->font, $_text); |
---|
54 | ImageTTFText($im, $_fontsize, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, -$white, $this->font, $_text); |
---|
55 | ImagePNG($im,PHPGW_IMAGES_FILEDIR.'/'.$filename); |
---|
56 | ImageDestroy($im); |
---|
57 | |
---|
58 | return $filename; |
---|
59 | } |
---|
60 | |
---|
61 | function createInputButton($_text, $_name, $_mode='graphic') |
---|
62 | { |
---|
63 | if ($_mode == 'graphic' && extension_loaded('gd')) |
---|
64 | { |
---|
65 | return '<input type="image" src="/phpgroupware/phpgwapi/templates/default/images/'.$this->createImage($_text).'" border="0" name="'.$_name.'">'; |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | return '<input type="submit" value="'.$_text.'" name="'.$_name.'">'; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | // this function checks, if there is a variable $aaa_x and $aaa_y |
---|
74 | // if so, it will create a new variable $aaa |
---|
75 | function parseHTTPPostVars() |
---|
76 | { |
---|
77 | // execute only if libgd support is enabled |
---|
78 | if (!extension_loaded('gd')) |
---|
79 | { |
---|
80 | return; |
---|
81 | } |
---|
82 | |
---|
83 | global $HTTP_POST_VARS; |
---|
84 | |
---|
85 | if (is_array($HTTP_POST_VARS)) |
---|
86 | { |
---|
87 | while( list($key, $val) = each($HTTP_POST_VARS)) |
---|
88 | { |
---|
89 | if (preg_match('/(.*)_x/',$key,$varName) && $HTTP_POST_VARS[$varName[1]."_y"]) |
---|
90 | { |
---|
91 | $name = $varName[1]; |
---|
92 | global $$name; |
---|
93 | $$name = "content generated by parseHTTPPostVars()"; |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|