[dev] [PATCH] IMP_Quota patch reworked
Etienne Goyer
etienne.goyer at linuxquebec.com
Wed Sep 24 08:17:38 PDT 2003
Here is a second revision of the patch I sent yesterday that rework the
IMP_Quota class. I addressed the concern raised by Jan (thanks for your
feedback). I still don't understand the meaning of :
IMP::checkAuthentication(OP_HALFOPEN, true);
in folders.php, but I leaved it there to not break anything. This may
have to be verified by somebody more knowledgeable to make sure it's
correct.
Also, as I said, I only tested the cyrus driver. My modification to
other drivers look good to me, but ...
Thanks for your feedback.
--
Etienne Goyer Linux Québec Technologies Inc.
http://www.LinuxQuebec.com etienne.goyer at linuxquebec.com
-------------- next part --------------
--- lib/Quota.php.orig Tue Sep 23 15:27:24 2003
+++ lib/Quota.php Wed Sep 24 10:39:22 2003
@@ -104,60 +104,18 @@
}
/**
- * Get quota HTML to push to user.
+ * Get quota information (used/allocated), in kB.
*
* @access public
*
- * @return string The HTML representation of the quota data.
+ * @return mixed An associative array with the value 'limit' for the
+ * maximum quota allowed and the value 'usage' for the
+ * currently used portion of the quota (in bytes), or
+ * a PEAR_Error on failure.
*/
- function quotaHTML()
+ function getQuota()
{
- return '';
- }
-
- /**
- * Created the html used to display the quota to the user.
- *
- * @access private
- *
- * @param integer $used Number of bytes used in the mailbox.
- * @param integer $total Total quota allowance for mailbox (in bytes).
- *
- * @return string HTML code to push to user.
- */
- function _quotaHtml($used, $total)
- {
- if ($total != 0) {
- $used = $used / (1024 * 1024.0);
- $total = $total / (1024 * 1024.0);
- $percent = ($used * 100) / $total;
- if ($percent >= 90) {
- $class = 'quotaalert';
- } elseif ($percent >= 75) {
- $class = 'quotawarn';
- } else {
- $class = 'control';
- }
- $message = sprintf(_("Quota status: %.2fMB / %.2fMB (%.2f%%)"), $used, $total, $percent);
- } else {
- $class = 'control';
- $message = sprintf(_("Quota status: NO LIMIT"));
- }
-
- require IMP_TEMPLATES . '/quota/quota.inc';
- }
-
- /**
- * Display Error Message.
- *
- * @access private
- *
- * @param string $message The error message to display.
- */
- function _quotaError($message)
- {
- $class = 'quotawarn';
- require IMP_TEMPLATES . '/quota/quota.inc';
+ return array('usage' => 0, 'limit' => 0);
}
}
--- lib/Quota/command.php.orig Tue Sep 23 15:35:07 2003
+++ lib/Quota/command.php Wed Sep 24 10:41:19 2003
@@ -51,13 +51,16 @@
}
/**
- * Get quota HTML to push to user.
+ * Get quota information (allocated/used), in kB.
*
* @access public
*
- * @return string The HTML representation of the quota data.
+ * @return mixed An associative array with the value 'limit' for the
+ * maximum quota allowed and the value 'usage' for the
+ * currently used portion of the quota (in bytes), or
+ * a PEAR_Error on failure.
*/
- function quotaHTML()
+ function getQuota()
{
global $imp;
@@ -69,9 +72,8 @@
$junk = exec($cmdline, $quota_data, $return_code);
if (($return_code == 0) && (count($quota_data) == 1)) {
$quota = split("[[:blank:]]+", trim($quota_data[0]));
- return $this->_quotaHTML($quota[1] * 1024, $quota[2] * 1024);
+ return array('usage' => $quota[1] * 1024, 'limit' => $quota[2] * 1024);
}
- return $this->_quotaError(_("Unable to retrieve quota"));
+ return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
}
-
}
--- lib/Quota/courier.php.orig Tue Sep 23 15:35:17 2003
+++ lib/Quota/courier.php Wed Sep 24 10:44:41 2003
@@ -17,13 +17,16 @@
class IMP_Quota_courier extends IMP_Quota {
/**
- * Get quota HTML to push to user.
+ * Get quota information (used/allocated), in kB.
*
* @access public
*
- * @return string The HTML representation of the quota data.
+ * @return mixed An associative array with the value 'limit' for the
+ * maximum quota allowed and the value 'usage' for the
+ * currently used portion of the quota (in bytes), or
+ * a PEAR_Error on failure.
*/
- function quotaHTML()
+ function getQuota()
{
$quota = null;
@@ -41,14 +44,14 @@
}
if (is_array($quota) && !empty($quota)) {
if (!empty($quota['limit'])) {
- return $this->_quotaHTML($quota['usage'] * 1024, $quota['limit'] * 1024);
+ return array('usage' => $quota['usage'] * 1024, 'limit' => $quota['limit'] * 1024);
} elseif (!empty($quota['STORAGE']['limit'])) {
- return $this->_quotaHTML($quota['STORAGE']['usage'] * 1024, $quota['STORAGE']['limit'] * 1024);
+ return array('usage' => $quota['STORAGE']['usage'] * 1024, 'limit' => $quota['STORAGE']['limit'] * 1024);
}
- return $this->_quotaHTML(0, 0);
+ return array('usage' => 0, 'limit' => 0);
}
- return $this->_quotaError(_("Unable to retrieve quota"));
+ return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
}
}
--- lib/Quota/cyrus.php.orig Tue Sep 23 15:35:24 2003
+++ lib/Quota/cyrus.php Wed Sep 24 10:45:31 2003
@@ -41,13 +41,16 @@
}
/**
- * Get quota HTML to push to user.
+ * Get quota information (used/allocated), in kB.
*
* @access public
*
- * @return string The HTML representation of the quota data.
+ * @return mixed An associative array with the value 'limit' for the
+ * maximum quota allowed and the value 'usage' for the
+ * currently used portion of the quota (in bytes), or
+ * a PEAR_Error on failure.
*/
- function quotaHTML()
+ function getQuota()
{
$mbox = 'user' . $this->_params['delimiter'] . $_SESSION['imp']['user'];
@@ -64,14 +67,14 @@
}
if (is_array($quota)) {
if (isset($quota['limit'])) {
- return $this->_quotaHTML($quota['usage'] * 1024, $quota['limit'] * 1024);
+ return array('usage' => $quota['usage'] * 1024, 'limit' => $quota['limit'] * 1024);
} elseif (isset($quota['STORAGE']['limit'])) {
- return $this->_quotaHTML($quota['STORAGE']['usage'] * 1024, $quota['STORAGE']['limit'] * 1024);
+ return array('usage' => $quota['STORAGE']['usage'] * 1024, 'limit' => $quota['STORAGE']['limit'] * 1024);
}
- return $this->_quotaHTML(0, 0);
+ return array('usage' => 0, 'limit' => 0);
}
- return $this->_quotaError(_("Unable to retrieve quota"));
+ return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
}
}
--- lib/Quota/logfile.php.orig Tue Sep 23 15:37:36 2003
+++ lib/Quota/logfile.php Wed Sep 24 10:10:03 2003
@@ -62,13 +62,16 @@
}
/**
- * Get quota HTML to push to user.
+ * Get quota information (used/allocated), in kB.
*
* @access public
*
- * @return string The HTML representation of the quota data.
+ * @return mixed An associative array with the value 'limit' for the
+ * maximum quota allowed and the value 'usage' for the
+ * currently used portion of the quota (in kilobytes),
+ * or a PEAR_Error on failure.
*/
- function quotaHTML()
+ function getQuota()
{
global $imp;
@@ -85,9 +88,9 @@
strpos("$virtline[0]", $this->_params['midocc']));
$storage = substr("$virtline[0]", strpos("$virtline[0]", $this->_params['midocc']) + strlen($this->_params['midocc']),
strpos("$virtline[0]", $this->_params['endocc']));
- return $this->_quotaHTML($usage, $storage);
+ return array('usage' => $usage, 'limit' => $storage);
}
- return $this->_quotaError(_("Unable to retrieve quota"));
+ return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
}
}
--- lib/Quota/mdaemon.php.orig Tue Sep 23 15:37:47 2003
+++ lib/Quota/mdaemon.php Wed Sep 24 10:47:30 2003
@@ -18,15 +18,18 @@
* @package imp.quota
*/
class IMP_Quota_mdaemon extends IMP_Quota {
-
+
/**
- * Get quota HTML to push to user.
+ * Get quota information (used/allocated), in kB.
*
* @access public
*
- * @return string The HTML representation of the quota data.
+ * @return mixed An associative array with the value 'limit' for the
+ * maximum quota allowed and the value 'usage' for the
+ * currently used portion of the quota (in bytes), or
+ * a PEAR_Error on failure.
*/
- function quotaHTML()
+ function getQuota()
{
global $imp;
@@ -37,17 +40,17 @@
$total = intval(substr($userDetails, 229, 6)) * 1024;
if ($total == 0) {
- return $this->_quotaHTML(0, 0);
+ return array('usage' => 0, 'limit' => 0);
}
if (($taken = $this->_mailboxSize($userHome)) !== false) {
- return $this->_quotaHTML($taken, $total);
+ return array('usage' => $taken, 'limit' => $total);
}
}
- return $this->_quotaError(_("Unable to retrieve quota"));
+ return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
}
-
+
/**
* Get the size of a mailbox
*
--- mailbox.php.orig Tue Sep 23 16:03:21 2003
+++ mailbox.php Tue Sep 23 18:18:36 2003
@@ -402,7 +402,8 @@
require_once IMP_BASE . '/lib/Quota.php';
$quotaDriver = &IMP_Quota::singleton($imp['quota']['driver'], $imp['quota']['params']);
if ($quotaDriver !== false) {
- $quotaDriver->quotaHTML();
+ $quota = $quotaDriver->getQuota();
+ require IMP_TEMPLATES . '/quota/quota.inc';
}
}
--- message.php.orig Tue Sep 23 17:36:17 2003
+++ message.php Tue Sep 23 18:18:48 2003
@@ -501,10 +501,11 @@
require_once IMP_BASE . '/lib/Quota.php';
$quotaDriver = &IMP_Quota::singleton($imp['quota']['driver'], $imp['quota']['params']);
if ($quotaDriver !== false) {
- $quotaDriver->quotaHTML();
+ $quota = $quotaDriver->getQuota();
+ require IMP_TEMPLATES . '/quota/quota.inc';
}
}
-
+
if ($browser->hasFeature('javascript')) {
require_once IMP_TEMPLATES . '/javascript/open_print_win.js';
}
--- folders.php.orig Tue Sep 23 17:38:35 2003
+++ folders.php Wed Sep 24 11:06:42 2003
@@ -69,7 +69,7 @@
require_once IMP_BASE . '/lib/Quota.php';
$quotaDriver = &IMP_Quota::singleton($imp['quota']['driver'], $imp['quota']['params']);
if ($quotaDriver !== false) {
- $quota_html = Horde::bufferOutput(array($quotaDriver, 'quotaHTML'));
+ $quota = $quotaDriver->getQuota();
}
IMP::checkAuthentication(OP_HALFOPEN, true);
}
@@ -274,8 +274,8 @@
IMP::status();
/* Print quota information. */
-if (isset($quota_html)) {
- echo $quota_html;
+if (isset($quota)) {
+ require IMP_TEMPLATES . '/quota/quota.inc';
}
/* Default to the very top of the hierarchy */
--- templates/quota/quota.inc.orig Tue Sep 23 16:05:49 2003
+++ templates/quota/quota.inc Wed Sep 24 10:50:09 2003
@@ -1,3 +1,26 @@
+<?php
+if (is_array($quota)) {
+ if ($quota['limit'] != 0) {
+ $quota['usage'] = $quota['usage'] / (1024 * 1024.0);
+ $quota['limit'] = $quota['limit'] / (1024 * 1024.0);
+ $percent = ($quota['usage'] * 100) / $quota['limit'];
+ if ($percent >= 90) {
+ $class = 'quotaalert';
+ } elseif ($percent >= 75) {
+ $class = 'quotawarn';
+ } else {
+ $class = 'control';
+ }
+ $message = sprintf(_("Quota status: %.2fMB / %.2fMB (%.2f%%)"), $quota['usage'], $quota['limit'], $percent);
+ } else {
+ $class = 'control';
+ $message = sprintf(_("Quota status: NO LIMIT"));
+ }
+} else {
+ $class = 'quotawarn';
+ $message = $quota;
+}
+?>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr><td class="<?php echo $class ?>" align="center">
<?php echo $message ?>
More information about the dev
mailing list