Ticket #1484857: quotaimg.php.diff

File quotaimg.php.diff, 1.4 kB (added by lancey, 9 months ago)

Patch which fixes the quota width issue, and also adds an URL option to show used/total size in MB next to the percents, e.g. 2% (2/100 MB)

  • quotaimg.php

    <html><head></head><body>Index: quotaimg.php
     
    2222$quota  = ((isset($_GET['q']) &amp;&amp; !empty($_GET['q'])) || $_GET['q']=='0')?(int)$_GET['q']:'??'; 
    2323$width  = empty($_GET['w']) ? 100 : (int)$_GET['w']; 
    2424$height = empty($_GET['h']) ? 14 : (int)$_GET['h']; 
     25$showsizes = ( isset($_GET['showsizes']) ? ($_GET['showsizes']=='true') : false); 
    2526 
    2627/** 
    2728 * Quota display 
     
    6263 *  
    6364 * @todo Make colors a config option. 
    6465 */ 
    65 function genQuota($used, $total, $width, $height) 
     66function genQuota($used, $total, $width, $height, $showsizes) 
    6667{ 
    6768        $unknown = false; 
    6869        $border  = 0; 
     
    159160                } 
    160161 
    161162                $quota_width = $quota / 100 * $width; 
    162                 imagefilledrectangle($im, $border, 0, $quota, $height-2*$border, $fill); 
     163                imagefilledrectangle($im, $border, 0, $quota_width, $height-2*$border, $fill); 
    163164 
    164165                $string = $quota . '%'; 
     166                if ($showsizes) 
     167                        $string .= ' (' . round($used/1000,0) . '/' . round($total/1000,0) . 'MB)'; 
     168 
    165169                $mid    = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; 
    166170        // Print percent in black 
    167171                imagestring($im, $font, $mid, $padding, $string, $text);  
     
    178182        imagedestroy($im); 
    179183} 
    180184 
    181 genQuota($used, $quota, $width, $height); 
     185genQuota($used, $quota, $width, $height, $showsizes); 
    182186exit;