<?php
/*
+-----------------------------------------------------------------------+
- | program/bin/quotaimg.php |
+ | bin/quotaimg.php |
| |
| This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
+ | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
| Author: Brett Patterson <brett2@umbc.edu> |
+-----------------------------------------------------------------------+
- $Id: $
+ $Id: quotaimg.php 2187 2008-12-24 14:19:27Z thomasb $
*/
-$used = ((isset($_GET['u']) && !empty($_GET['u'])) || $_GET['u']=='0')?(int)$_GET['u']:'??';
-$quota = ((isset($_GET['q']) && !empty($_GET['q'])) || $_GET['q']=='0')?(int)$_GET['q']:'??';
-$width = empty($_GET['w']) ? 100 : (int)$_GET['w'];
-$height = empty($_GET['h']) ? 14 : (int)$_GET['h'];
+define('INSTALL_PATH', realpath(dirname(__FILE__).'/..') . '/');
+require INSTALL_PATH . 'program/include/iniset.php';
+
+$RCMAIL = rcmail::get_instance();
+
+$used = isset($_GET['u']) ? intval($_GET['u']) : '??';
+$quota = isset($_GET['q']) ? intval($_GET['q']) : '??';
+$width = empty($_GET['w']) ? 100 : min(300, intval($_GET['w']));
+$height = empty($_GET['h']) ? 14 : min(50, intval($_GET['h']));
/**
* Quota display
$font = 2;
$padding = 0;
- $limit['high'] = 70;
- $limit['mid'] = 45;
+ $limit['high'] = 80;
+ $limit['mid'] = 55;
$limit['low'] = 0;
// Fill Colors
- $color['fill']['high'] = '215, 13, 13'; // Near quota fill color
- $color['fill']['mid'] = '126, 192, 238'; // Mid-area of quota fill color
- $color['fill']['low'] = '147, 225, 100'; // Far from quota fill color
+ $color['fill']['high'] = '243, 49, 49'; // Near quota fill color
+ $color['fill']['mid'] = '245, 173, 60'; // Mid-area of quota fill color
+ $color['fill']['low'] = '145, 225, 100'; // Far from quota fill color
// Background colors
$color['bg']['OL'] = '215, 13, 13'; // Over limit bbackground
// Misc. Colors
$color['border'] = '0, 0, 0';
- $color['text'] = '102, 102, 102';
+ $color['text']['high'] = '255, 255, 255'; // white text for red background
+ $color['text']['mid'] = '102, 102, 102';
+ $color['text']['low'] = '102, 102, 102';
+ $color['text']['normal'] = '102, 102, 102';
/************************************
***** DO NOT EDIT BELOW HERE *****
***********************************/
- // @todo: Set to "??" instead?
+ // @todo: Set to "??" instead?
if (ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total)) {
return false;
- }
+ }
- if (strpos($used, '?') !== false || strpos($total, '?') !== false
- && $used != 0) {
+ if (strpos($used, '?') !== false || strpos($total, '?') !== false && $used != 0) {
$unknown = true;
- }
+ }
$im = imagecreate($width, $height);
imageline($im, $width, $height-$border, 0, $height-$border, $borderc);
}
- list($r, $g, $b) = explode(',', $color['text']);
- $text = imagecolorallocate($im, $r, $g, $b);
-
if ($unknown) {
+ list($r, $g, $b) = explode(',', $color['text']['normal']);
+ $text = imagecolorallocate($im, $r, $g, $b);
list($r, $g, $b) = explode(',', $color['bg']['Unknown']);
$background = imagecolorallocate($im, $r, $g, $b);
+
imagefilledrectangle($im, 0, 0, $width, $height, $background);
$string = 'Unknown';
$mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
imagestring($im, $font, $mid, $padding, $string, $text);
} else if ($used > $total) {
+ list($r, $g, $b) = explode(',', $color['text']['normal']);
+ $text = imagecolorallocate($im, $r, $g, $b);
list($r, $g, $b) = explode(',', $color['bg']['OL']);
-
$background = imagecolorallocate($im, $r, $g, $b);
imagefilledrectangle($im, 0, 0, $width, $height, $background);
imagestring($im, $font, $mid, $padding, $string, $text);
} else {
list($r, $g, $b) = explode(',', $color['bg']['quota']);
-
$background = imagecolorallocate($im, $r, $b, $g);
imagefilledrectangle($im, 0, 0, $width, $height, $background);
$quota = ($used==0)?0:(round($used/$total, 2)*100);
if ($quota >= $limit['high']) {
+ list($r, $g, $b) = explode(',', $color['text']['high']);
+ $text = imagecolorallocate($im, $r, $g, $b);
list($r, $g, $b) = explode(',', $color['fill']['high']);
$fill = imagecolorallocate($im, $r, $g, $b);
} elseif($quota >= $limit['mid']) {
+ list($r, $g, $b) = explode(',', $color['text']['mid']);
+ $text = imagecolorallocate($im, $r, $g, $b);
list($r, $g, $b) = explode(',', $color['fill']['mid']);
$fill = imagecolorallocate($im, $r, $g, $b);
} else {
- // if($quota >= $limit['low'])
+ // if($quota >= $limit['low'])
+ list($r, $g, $b) = explode(',', $color['text']['low']);
+ $text = imagecolorallocate($im, $r, $g, $b);
list($r, $g, $b) = explode(',', $color['fill']['low']);
$fill = imagecolorallocate($im, $r, $g, $b);
}
$quota_width = $quota / 100 * $width;
- imagefilledrectangle($im, $border, 0, $quota, $height-2*$border, $fill);
+ imagefilledrectangle($im, $border, 0, $quota_width, $height-2*$border, $fill);
$string = $quota . '%';
$mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
- // Print percent in black
+ // Print percent in black
imagestring($im, $font, $mid, $padding, $string, $text);
}
header('Content-Type: image/gif');
-
- // @todo is harcoding GMT necessary?
- header('Expires: ' . gmdate('D, d M Y H:i:s', mktime()+86400) . ' GMT');
- header('Cache-Control: ');
- header('Pragma: ');
+
+ // cache for 1 hour
+ $maxage = 3600;
+ header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$maxage). ' GMT');
+ header('Cache-Control: max-age=' . $maxage);
imagegif($im);
imagedestroy($im);
}
-genQuota($used, $quota, $width, $height);
+if (!empty($RCMAIL->user->ID) && $width > 1 && $height > 1) {
+ genQuota($used, $quota, $width, $height);
+}
+else {
+ header("HTTP/1.0 403 Forbidden");
+ echo "Requires a valid user session and positive values";
+}
+
exit;
-?>
\ No newline at end of file
+?>