From 3ea0e3202a73eb7efcbf0b825582a6d3504658aa Mon Sep 17 00:00:00 2001 From: thomascube Date: Fri, 1 Sep 2006 13:43:14 +0000 Subject: Quota display as image --- index.php | 7 +- program/include/rcube_imap.inc | 8 +- program/include/rcube_shared.inc | 21 +++- program/steps/mail/func.inc | 23 ++++- program/steps/mail/quotaimg.inc | 196 ++++++++++++++++++++++++++++++++++++++ skins/default/mail.css | 18 +++- skins/default/templates/mail.html | 2 +- 7 files changed, 254 insertions(+), 21 deletions(-) create mode 100644 program/steps/mail/quotaimg.inc diff --git a/index.php b/index.php index f98243023..ff73a0030 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,7 @@ /* +-----------------------------------------------------------------------+ | RoundCube Webmail IMAP Client | - | Version 0.1-beta2 | + | Version 0.1-20060901 | | | | Copyright (C) 2005-2006, RoundCube Dev. - Switzerland | | Licensed under the GNU GPL | @@ -40,7 +40,7 @@ */ -define('RCMAIL_VERSION', '0.1-beta2'); +define('RCMAIL_VERSION', '0.1-20060901'); // define global vars $CHARSET = 'UTF-8'; @@ -288,6 +288,9 @@ if ($_task=='mail') if ($_action=='rss') include('program/steps/mail/rss.inc'); + + if ($_action=='quotaimg') + include('program/steps/mail/quotaimg.inc'); // make sure the message count is refreshed diff --git a/program/include/rcube_imap.inc b/program/include/rcube_imap.inc index 4e1719736..05de6773a 100644 --- a/program/include/rcube_imap.inc +++ b/program/include/rcube_imap.inc @@ -1463,12 +1463,8 @@ class rcube_imap function get_quota() { if ($this->get_capability('QUOTA')) - { - $result = iil_C_GetQuota($this->conn); - if ($result["total"]) - return sprintf("%.2fMB / %.2fMB (%.0f%%)", $result["used"] / 1000.0, $result["total"] / 1000.0, $result["percent"]); - } - + return array('total' => 2048 * 1024, 'used' => 500 * 1024, 'percent' => 32); //iil_C_GetQuota($this->conn); + return FALSE; } diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc index 768ae3f40..af4c295dd 100644 --- a/program/include/rcube_shared.inc +++ b/program/include/rcube_shared.inc @@ -1299,12 +1299,25 @@ function get_boolean($str) } -function show_bytes($numbytes) +// create a human readable string for a number of bytes +function show_bytes($bytes) { - if ($numbytes > 1024) - return sprintf('%d KB', round($numbytes/1024)); + if ($bytes > 1073741824) + { + $gb = $bytes/1073741824; + $str = sprintf($gb>=10 ? "%d GB" : "%.1f GB", $gb); + } + else if ($bytes > 1048576) + { + $mb = $bytes/1048576; + $str = sprintf($mb>=10 ? "%d MB" : "%.1f MB", $mb); + } + else if ($bytes > 1024) + $str = sprintf("%d KB", round($bytes/1024)); else - return sprintf('%d B', $numbytes); + $str = sprintf('%d B', $bytes); + + return $str; } diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 58da0ca45..986a4c955 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -611,7 +611,7 @@ function rcmail_messagecount_display($attrib) function rcmail_quota_display($attrib) { - global $IMAP, $OUTPUT, $JS_OBJECT_NAME; + global $IMAP, $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH; if (!$attrib['id']) $attrib['id'] = 'rcmquotadisplay'; @@ -620,11 +620,28 @@ function rcmail_quota_display($attrib) // allow the following attributes to be added to the tag $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id')); - + if (!$IMAP->get_capability('QUOTA')) $quota_text = rcube_label('unknown'); - else if (!($quota_text = $IMAP->get_quota())) + else if ($quota = $IMAP->get_quota()) + { + $quota_text = sprintf("%s / %s (%.0f%%)", + show_bytes($quota["used"] * 1024), + show_bytes($quota["total"] * 1024), + $quota["percent"]); + + // show quota as image (by Brett Patterson) + if ($attrib['display'] == 'image' && function_exists('imagegif')) + { + $quota_text = sprintf('%s', + $COMM_PATH, + $quota['used'], $quota['total'], + $quota_text); + } + } + else $quota_text = rcube_label('unlimited'); + $out = ''; $out .= $quota_text; diff --git a/program/steps/mail/quotaimg.inc b/program/steps/mail/quotaimg.inc new file mode 100644 index 000000000..9cb228e87 --- /dev/null +++ b/program/steps/mail/quotaimg.inc @@ -0,0 +1,196 @@ + | + +-----------------------------------------------------------------------+ + + $Id: $ + +*/ + +$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']:'??'; + + +function genQuota($used, $total) +{ + /** + * Quota Display + * + * Modify the following few elements to change the display of the image. + * Modifiable attributes are: + * bool border :: Defines whether you want to show a border around it or not. + * bool unknown :: Leave default; Defines whether quota is "unknown" + * + * int height :: Defines height of the image + * int width :: Defines width of the image + * int font :: Changes the font size & font used in the GD library. + * Available values are from 1 to 5. + * int padding :: Changes the offset (in pixels) from the top of the image to + * where the top of the text will be aligned. User greater than + * 0 to ensure text is off the border. + * array limit :: Holds the integer values of in an associative array as to what + * defines the upper and lower levels for quota display. + * High - Quota is nearing capacity. + * Mid - Quota is around the middle + * Low - Currently not used. + * array color :: An associative array of strings of comma separated values (R,G,B) + * for use in color creation. Define the RGB values you'd like to + * use. A list of colors (and their RGB values) can be found here: + * http://www.december.com/html/spec/colorcodes.html + **/ + + $unknown = false; + $border = true; + + $height = 15; + $width = 102; + $font = 2; + $padding = 1; + + $limit['high'] = 70; + $limit['mid'] = 45; + $limit['low'] = 0; + + // Fill Colors + $color['fill']['high'] = '227, 23, 13'; // Near quota fill color + $color['fill']['mid'] = '126, 192, 238';// Mid-area of quota fill color + $color['fill']['low'] = '50, 205, 50'; // Far from quota fill color + + // Background colors + $color['bg']['OL'] = '238, 99, 99'; // Over limit bbackground + $color['bg']['Unknown'] = '238, 99, 99';// Unknown background + $color['bg']['quota'] = '255, 255, 255';// Normal quota background + + // Misc. Colors + $color['border'] = '0, 0, 0'; + $color['text'] = '0, 0, 0'; + + + /**************************** + ***** DO NOT EDIT BELOW HERE ***** + ****************************/ + + if(ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total)) + { + return false; + } + if(strpos($used, '?')!==false || strpos($total, '?')!==false && $used != 0) + { + $unknown = true; + } + + if($unknown) + { + $im = imagecreate($width, $height); + list($r, $g, $b) = explode(',', $color['bg']['Unknown']); + $background = imagecolorallocate($im, $r, $g, $b); + list($r, $g, $b) = explode(',', $color['text']); + $text = imagecolorallocate($im, $r, $g, $b); + + if($border) + { + list($r, $g, $b) = explode(',', $color['border']); + $border = imagecolorallocate($im, $r, $g, $b); + imageline($im, 0, 0, $width, 0, $border); + imageline($im, 0, $height-1, 0, 0, $border); + imageline($im, $width-1, 0, $width-1, $height, $border); + imageline($im, $width, $height-1, 0, $height-1, $border); + } + + $string = 'Unknown'; + + $mid = floor((100-(strlen($string)*imagefontwidth($font)))/2)+1; + + imagestring($im, $font, $mid, $padding, $string, $text); + header('Content-type: image/gif'); + imagegif($im); + imagedestroy($im); + exit; + } + + if($used > $total) + { + $im = imagecreate($width, $height); + list($r, $g, $b) = explode(',', $color['bg']['OL']); + $background = imagecolorallocate($im, $r, $g, $b); + list($r, $g, $b) = explode(',', $color['text']); + $text = imagecolorallocate($im, $r, $g, $b); + list($r, $g, $b) = explode(',', $color['border']); + $border = imagecolorallocate($im, $r, $g, $b); + + imageline($im, 0, 0, $width, 0, $border); + imageline($im, 0, $height-1, 0, 0, $border); + imageline($im, $width-1, 0, $width-1, $height, $border); + imageline($im, $width, $height-1, 0, $height-1, $border); + + $string = 'Over Limit'; + + $mid = floor((100-(strlen($string)*imagefontwidth($font)))/2)+1; + + imagestring($im, $font, $mid, $padding, $string, $text); + + header('Content-type: image/gif'); + imagegif($im); + exit; + } + + $quota = ($used==0)?0:(round($used/$total, 2)*100); + + $im = imagecreate($width, $height); + list($r, $g, $b) = explode(',', $color['bg']['quota']); + $background = imagecolorallocate($im, $r, $b, $g); + list($r, $g, $b) = explode(',', $color['border']); + $border = imagecolorallocate($im, $r, $g, $b); + list($r, $g, $b) = explode(',', $color['text']); + $text = imagecolorallocate($im, $r, $g, $b); + if($quota >= $limit['high']) + { + list($r, $g, $b) = explode(',', $color['fill']['high']); + $fill = imagecolorallocate($im, $r, $g, $b); + } + elseif($quota >= $limit['mid']) + { + list($r, $g, $b) = explode(',', $color['fill']['mid']); + $fill = imagecolorallocate($im, $r, $g, $b); + } + else // if($quota >= $limit['low']) + { + list($r, $g, $b) = explode(',', $color['fill']['low']); + $fill = imagecolorallocate($im, $r, $g, $b); + } + + + imagefilledrectangle($im, 1, 0, $quota, $height-2, $fill); + + + imageline($im, 0, 0, $width-2, 0, $border); + imageline($im, $width-2, 0, $width-2, $height, $border); + imageline($im, $width-2, $height-1, 0, $height-1, $border); + imageline($im, 0, $height, 0, 0, $border); + + + $string = $quota.'%'; + $mid = floor((100-(strlen($string)*imagefontwidth($font)))/2)+1; + imagestring($im, $font, $mid, $padding, $string, $text); // Print percent in black + + header('Content-Type: image/gif'); + imagegif($im); + imagedestroy($im); +} + + +genQuota($used, $quota); +exit; +?> \ No newline at end of file diff --git a/skins/default/mail.css b/skins/default/mail.css index c60a73dc8..95e404691 100644 --- a/skins/default/mail.css +++ b/skins/default/mail.css @@ -555,6 +555,19 @@ html>body*#quicksearchbar #quicksearchbox { width: 180px; top:0px; right: 1px; l background-color: #b4eeb4;*/ } +#quotadisplay +{ + color: #666666; + font-size: 11px; +} + +#quotadisplay img +{ + vertical-align: middle; + padding-left: 4px; +} + + /** message view styles */ @@ -881,8 +894,3 @@ div.message-part blockquote blockquote blockquote margin-top: 8px; } -#rcmquotadisplay -{ - color: #999999; - font-size: 11px; -} diff --git a/skins/default/templates/mail.html b/skins/default/templates/mail.html index c2e5316eb..962a298ab 100644 --- a/skins/default/templates/mail.html +++ b/skins/default/templates/mail.html @@ -57,7 +57,7 @@         -: +: -- cgit v1.2.3