Skip to content
Browse files

Quota display as image

  • Loading branch information...
1 parent ea206d3 commit 3ea0e3202a73eb7efcbf0b825582a6d3504658aa @thomascube thomascube committed Sep 1, 2006
View
7 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 ($_action=='rss')
include('program/steps/mail/rss.inc');
+
+ if ($_action=='quotaimg')
+ include('program/steps/mail/quotaimg.inc');
// make sure the message count is refreshed
View
8 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;
}
View
21 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;
}
View
23 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 <span> 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('<img src="%s&amp;_action=quotaimg&amp;u=%s&amp;q=%d" alt="%s" width="102" height="15" />',
+ $COMM_PATH,
+ $quota['used'], $quota['total'],
+ $quota_text);
+ }
+ }
+ else
$quota_text = rcube_label('unlimited');
+
$out = '<span' . $attrib_str . '>';
$out .= $quota_text;
View
196 program/steps/mail/quotaimg.inc
@@ -0,0 +1,196 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/mail/quotaimg.inc |
+ | |
+ | This file is part of the RoundCube Webmail client |
+ | Copyright (C) 2005, RoundCube Dev. - Switzerland |
+ | Licensed under the GNU GPL |
+ | |
+ | PURPOSE: |
+ | Create a GIF image showing the mailbox quot as bar |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Brett Patterson <brett2@umbc.edu> |
+ +-----------------------------------------------------------------------+
+
+ $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;
+?>
View
18 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;
-}
View
2 skins/default/templates/mail.html
@@ -57,7 +57,7 @@
<roundcube:button command="select-all" label="all" classAct="active" />&nbsp;
<roundcube:button command="select-all" prop="unread" label="unread" classAct="active" />&nbsp;
<roundcube:button command="select-none" label="none" classAct="active" /> &nbsp;&nbsp;&nbsp;
-<roundcube:label name="quota" />: <roundcube:object name="quotaDisplay" />
+<roundcube:label name="quota" />: <roundcube:object name="quotaDisplay" display="text" id="quotadisplay" />
</div>
</body>

0 comments on commit 3ea0e32

Please sign in to comment.
Something went wrong with that request. Please try again.