From: Jan Schneider Date: Mon, 23 Aug 2010 13:48:21 +0000 (+0200) Subject: Driver -> Base X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=618b889787d97cabcb906378074cfc8828e7f5ab;p=horde.git Driver -> Base --- diff --git a/framework/Lock/lib/Horde/Lock.php b/framework/Lock/lib/Horde/Lock.php index fd3588b0d..92219c8ae 100644 --- a/framework/Lock/lib/Horde/Lock.php +++ b/framework/Lock/lib/Horde/Lock.php @@ -27,7 +27,7 @@ class Horde_Lock * @param array $params A hash containing any additional configuration or * connection parameters a subclass might need. * - * @return Horde_Lock_Driver The newly created concrete instance. + * @return Horde_Lock_Base The newly created concrete instance. * @throws Horde_Lock_Exception */ static public function factory($driver, $params = array()) diff --git a/framework/Lock/lib/Horde/Lock/Driver.php b/framework/Lock/lib/Horde/Lock/Driver.php index 86f219789..b9b3e5acd 100644 --- a/framework/Lock/lib/Horde/Lock/Driver.php +++ b/framework/Lock/lib/Horde/Lock/Driver.php @@ -1,6 +1,6 @@ + * @category Horde + * @package SessionHandler + */ +abstract class Horde_SessionHandler_Base +{ + /** + * Hash containing connection parameters. + * + * @var array + */ + protected $_params = array(); + + /** + * Initial session data signature. + * + * @var string + */ + protected $_sig; + + /** + * Force saving the session data? + * + * @var boolean + */ + protected $_force = false; + + /** + * Has a connection been made to the backend? + * + * @var boolean + */ + protected $_connected = false; + + /** + * A logger instance. + * + * @var Horde_Log_Logger + */ + protected $_logger; + + /** + * Session variable name. + * + * @var string + */ + protected $_session = 'horde_sh'; + + /** + * Constructor. + * + * @param array $params Parameters: + *
+     * 'logger' - (Horde_Log_Logger) A logger instance.
+     *            DEFAULT: No logging
+     * 'noset' - (boolean) If true, don't set the save handler.
+     *           DEFAULT: false
+     * 'parse' - (callback) A callback function that parses session
+     *           information into an array. Is passed the raw session data
+     *           as the only argument; expects either false or an array of
+     *           session data as a return.
+     *           DEFAULT: No
+     * 
+ */ + public function __construct(array $params = array()) + { + $params = array_merge($this->_params, $params); + + if (isset($params['logger'])) { + $this->_logger = $params['logger']; + unset($params['logger']); + } + + $this->_params = $params; + + register_shutdown_function(array($this, 'shutdown')); + + if (empty($this->_params['noset'])) { + ini_set('session.save_handler', 'user'); + session_set_save_handler( + array($this, 'open'), + array($this, 'close'), + array($this, 'read'), + array($this, 'write'), + array($this, 'destroy'), + array($this, 'gc') + ); + } + } + + /** + * Destructor. + */ + public function __destruct() + { + /* This is necessary as of PHP 5.0.5 because objects are not available + * when the write() handler is called at the end of a session + * access. */ + session_write_close(); + } + + /** + * Shutdown function. + * + * Used to determine if we need to write the session to avoid a session + * timeout, even though the session is unchanged. + * Theory: On initial login, set the current time plus half of the max + * lifetime in the session. Then check this timestamp before saving. + * If we exceed, force a write of the session and set a new timestamp. + * Why half the maxlifetime? It guarantees that if we are accessing the + * server via a periodic mechanism (think folder refreshing in IMP) that + * we will catch this refresh. + */ + public function shutdown() + { + $curr_time = time(); + + if (!isset($_SESSION[$this->_session]) || + ($curr_time >= $_SESSION[$this->_session])) { + $_SESSION[$this->_session] = $curr_time + (ini_get('session.gc_maxlifetime') / 2); + $this->_force = true; + } + } + + /** + * Open the backend. + * + * @param string $save_path The path to the session object. + * @param string $session_name The name of the session. + * + * @return boolean True on success, false otherwise. + */ + public function open($save_path = null, $session_name = null) + { + if (!$this->_connected) { + try { + $this->_open($save_path, $session_name); + } catch (Horde_SessionHandler_Exception $e) { + if ($this->_logger) { + $this->_logger->log($e, 'ERR'); + } + return false; + } + + $this->_connected = true; + } + + return true; + } + + /** + * Open the backend. + * + * @param string $save_path The path to the session object. + * @param string $session_name The name of the session. + * + * @throws Horde_SessionHandler_Exception + */ + abstract protected function _open($save_path = null, $session_name = null); + + /** + * Close the backend. + * + * @return boolean True on success, false otherwise. + */ + public function close() + { + try { + $this->_close(); + } catch (Horde_SessionHandler_Exception $e) { + if ($this->_logger) { + $this->_logger->log($e, 'ERR'); + } + return false; + } + + $this->_connected = false; + return true; + } + + /** + * Close the backend. + * + * @throws Horde_SessionHandler_Exception + */ + abstract protected function _close(); + + /** + * Read the data for a particular session identifier from the backend. + * This method should only be called internally by PHP via + * session_set_save_handler(). + * + * @param string $id The session identifier. + * + * @return string The session data. + */ + public function read($id) + { + $result = $this->_read($id); + $this->_sig = md5($result); + return $result; + } + + /** + * Read the data for a particular session identifier from the backend. + * + * @param string $id The session identifier. + * + * @return string The session data. + */ + abstract protected function _read($id); + + /** + * Write session data to the backend. + * This method should only be called internally by PHP via + * session_set_save_handler(). + * + * @param string $id The session identifier. + * @param string $session_data The session data. + * + * @return boolean True on success, false otherwise. + */ + public function write($id, $session_data) + { + if (!$this->_force && ($this->_sig == md5($session_data))) { + if ($this->_logger) { + $this->_logger->log('Session data unchanged (id = ' . $id . ')', 'DEBUG'); + } + return true; + } + + return $this->_write($id, $session_data); + } + + /** + * Write session data to the backend. + * + * @param string $id The session identifier. + * @param string $session_data The session data. + * + * @return boolean True on success, false otherwise. + */ + abstract protected function _write($id, $session_data); + + /** + * Destroy the data for a particular session identifier in the backend. + * This method should only be called internally by PHP via + * session_set_save_handler(). + * + * @param string $id The session identifier. + * + * @return boolean True on success, false otherwise. + */ + abstract public function destroy($id); + + /** + * Garbage collect stale sessions from the backend. + * This method should only be called internally by PHP via + * session_set_save_handler(). + * + * @param integer $maxlifetime The maximum age of a session. + * + * @return boolean True on success, false otherwise. + */ + abstract public function gc($maxlifetime = 300); + + /** + * Get session data read-only. + * + * @param string $id The session identifier. + * + * @return string The session data. + */ + protected function _readOnly($id) + { + return $this->read($id); + } + + /** + * Get a list of the valid session identifiers. + * + * @return array A list of valid session identifiers. + * @throws Horde_SessionHandler_Exception + */ + abstract public function getSessionIDs(); + + /** + * Returns a list of authenticated users and data about their session. + * + * @return array For authenticated users, the sessionid as a key and the + * session information as value. If no parsing function + * was provided, will always return an empty array. + * @throws Horde_SessionHandler_Exception + */ + public function getSessionsInfo() + { + $info = array(); + + if (empty($this->_params['parse']) || + !is_callable($this->_params['parse'])) { + return $info; + } + + $sessions = $this->getSessionIDs(); + + foreach ($sessions as $id) { + try { + $data = $this->_readOnly($id); + } catch (Horde_SessionHandler_Exception $e) { + continue; + } + + $data = call_user_func($this->_params['parse'], $data); + if ($data !== false) { + $info[$id] = $data; + } + } + + return $info; + } + +} diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Builtin.php b/framework/SessionHandler/lib/Horde/SessionHandler/Builtin.php index 06f843456..7e9c95e9d 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Builtin.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Builtin.php @@ -1,6 +1,6 @@ - * @category Horde - * @package SessionHandler - */ -abstract class Horde_SessionHandler_Driver -{ - /** - * Hash containing connection parameters. - * - * @var array - */ - protected $_params = array(); - - /** - * Initial session data signature. - * - * @var string - */ - protected $_sig; - - /** - * Force saving the session data? - * - * @var boolean - */ - protected $_force = false; - - /** - * Has a connection been made to the backend? - * - * @var boolean - */ - protected $_connected = false; - - /** - * A logger instance. - * - * @var Horde_Log_Logger - */ - protected $_logger; - - /** - * Session variable name. - * - * @var string - */ - protected $_session = 'horde_sh'; - - /** - * Constructor. - * - * @param array $params Parameters: - *
-     * 'logger' - (Horde_Log_Logger) A logger instance.
-     *            DEFAULT: No logging
-     * 'noset' - (boolean) If true, don't set the save handler.
-     *           DEFAULT: false
-     * 'parse' - (callback) A callback function that parses session
-     *           information into an array. Is passed the raw session data
-     *           as the only argument; expects either false or an array of
-     *           session data as a return.
-     *           DEFAULT: No
-     * 
- */ - public function __construct(array $params = array()) - { - $params = array_merge($this->_params, $params); - - if (isset($params['logger'])) { - $this->_logger = $params['logger']; - unset($params['logger']); - } - - $this->_params = $params; - - register_shutdown_function(array($this, 'shutdown')); - - if (empty($this->_params['noset'])) { - ini_set('session.save_handler', 'user'); - session_set_save_handler( - array($this, 'open'), - array($this, 'close'), - array($this, 'read'), - array($this, 'write'), - array($this, 'destroy'), - array($this, 'gc') - ); - } - } - - /** - * Destructor. - */ - public function __destruct() - { - /* This is necessary as of PHP 5.0.5 because objects are not available - * when the write() handler is called at the end of a session - * access. */ - session_write_close(); - } - - /** - * Shutdown function. - * - * Used to determine if we need to write the session to avoid a session - * timeout, even though the session is unchanged. - * Theory: On initial login, set the current time plus half of the max - * lifetime in the session. Then check this timestamp before saving. - * If we exceed, force a write of the session and set a new timestamp. - * Why half the maxlifetime? It guarantees that if we are accessing the - * server via a periodic mechanism (think folder refreshing in IMP) that - * we will catch this refresh. - */ - public function shutdown() - { - $curr_time = time(); - - if (!isset($_SESSION[$this->_session]) || - ($curr_time >= $_SESSION[$this->_session])) { - $_SESSION[$this->_session] = $curr_time + (ini_get('session.gc_maxlifetime') / 2); - $this->_force = true; - } - } - - /** - * Open the backend. - * - * @param string $save_path The path to the session object. - * @param string $session_name The name of the session. - * - * @return boolean True on success, false otherwise. - */ - public function open($save_path = null, $session_name = null) - { - if (!$this->_connected) { - try { - $this->_open($save_path, $session_name); - } catch (Horde_SessionHandler_Exception $e) { - if ($this->_logger) { - $this->_logger->log($e, 'ERR'); - } - return false; - } - - $this->_connected = true; - } - - return true; - } - - /** - * Open the backend. - * - * @param string $save_path The path to the session object. - * @param string $session_name The name of the session. - * - * @throws Horde_SessionHandler_Exception - */ - abstract protected function _open($save_path = null, $session_name = null); - - /** - * Close the backend. - * - * @return boolean True on success, false otherwise. - */ - public function close() - { - try { - $this->_close(); - } catch (Horde_SessionHandler_Exception $e) { - if ($this->_logger) { - $this->_logger->log($e, 'ERR'); - } - return false; - } - - $this->_connected = false; - return true; - } - - /** - * Close the backend. - * - * @throws Horde_SessionHandler_Exception - */ - abstract protected function _close(); - - /** - * Read the data for a particular session identifier from the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param string $id The session identifier. - * - * @return string The session data. - */ - public function read($id) - { - $result = $this->_read($id); - $this->_sig = md5($result); - return $result; - } - - /** - * Read the data for a particular session identifier from the backend. - * - * @param string $id The session identifier. - * - * @return string The session data. - */ - abstract protected function _read($id); - - /** - * Write session data to the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. - */ - public function write($id, $session_data) - { - if (!$this->_force && ($this->_sig == md5($session_data))) { - if ($this->_logger) { - $this->_logger->log('Session data unchanged (id = ' . $id . ')', 'DEBUG'); - } - return true; - } - - return $this->_write($id, $session_data); - } - - /** - * Write session data to the backend. - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. - */ - abstract protected function _write($id, $session_data); - - /** - * Destroy the data for a particular session identifier in the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param string $id The session identifier. - * - * @return boolean True on success, false otherwise. - */ - abstract public function destroy($id); - - /** - * Garbage collect stale sessions from the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param integer $maxlifetime The maximum age of a session. - * - * @return boolean True on success, false otherwise. - */ - abstract public function gc($maxlifetime = 300); - - /** - * Get session data read-only. - * - * @param string $id The session identifier. - * - * @return string The session data. - */ - protected function _readOnly($id) - { - return $this->read($id); - } - - /** - * Get a list of the valid session identifiers. - * - * @return array A list of valid session identifiers. - * @throws Horde_SessionHandler_Exception - */ - abstract public function getSessionIDs(); - - /** - * Returns a list of authenticated users and data about their session. - * - * @return array For authenticated users, the sessionid as a key and the - * session information as value. If no parsing function - * was provided, will always return an empty array. - * @throws Horde_SessionHandler_Exception - */ - public function getSessionsInfo() - { - $info = array(); - - if (empty($this->_params['parse']) || - !is_callable($this->_params['parse'])) { - return $info; - } - - $sessions = $this->getSessionIDs(); - - foreach ($sessions as $id) { - try { - $data = $this->_readOnly($id); - } catch (Horde_SessionHandler_Exception $e) { - continue; - } - - $data = call_user_func($this->_params['parse'], $data); - if ($data !== false) { - $info[$id] = $data; - } - } - - return $info; - } - -} diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/External.php b/framework/SessionHandler/lib/Horde/SessionHandler/External.php index 147e4a5cf..8f4abe11b 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/External.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/External.php @@ -1,6 +1,6 @@ - + @@ -99,7 +99,7 @@ - + diff --git a/framework/Token/lib/Horde/Token/Base.php b/framework/Token/lib/Horde/Token/Base.php new file mode 100644 index 000000000..d6407f55e --- /dev/null +++ b/framework/Token/lib/Horde/Token/Base.php @@ -0,0 +1,112 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @package Token + */ +abstract class Horde_Token_Driver +{ + /** + * Logger. + * + * @var Horde_Log_Logger + */ + protected $_logger; + + /** + * Hash of parameters necessary to use the chosen backend. + * + * @var array + */ + protected $_params = array(); + + /** + * Constructor. + * + * @param array $params Optional parameters: + *
+     * 'logger' - (Horde_Log_Logger) A logger object.
+     * 
+ */ + public function __construct($params) + { + if (isset($params['logger'])) { + $this->_logger = $params['logger']; + unset($params['logger']); + } + + $this->_params = $params; + } + + /** + * Checks if the given token has been previously used. First + * purges all expired tokens. Then retrieves current tokens for + * the given ip address. If the specified token was not found, + * adds it. + * + * @param string $token The value of the token to check. + * + * @return boolean True if the token has not been used, false otherwise. + * @throws Horde_Token_Exception + */ + public function verify($token) + { + $this->purge(); + + if ($this->exists($token)) { + return false; + } + + $this->add($token); + return true; + } + + /** + * Does the token exist? + * + * @param string $tokenID Token ID. + * + * @return boolean True if the token exists. + * @throws Horde_Token_Exception + */ + abstract public function exists($tokenID); + + /** + * Add a token ID. + * + * @param string $tokenID Token ID to add. + * + * @throws Horde_Token_Exception + */ + abstract public function add($tokenID); + + /** + * Delete all expired connection IDs. + * + * @throws Horde_Token_Exception + */ + abstract public function purge(); + + /** + * Encodes the remote address. + * + * @return string Encoded address. + */ + protected function _encodeRemoteAddress() + { + return isset($_SERVER['REMOTE_ADDR']) + ? base64_encode($_SERVER['REMOTE_ADDR']) + : ''; + } + + +} diff --git a/framework/Token/lib/Horde/Token/Driver.php b/framework/Token/lib/Horde/Token/Driver.php deleted file mode 100644 index d6407f55e..000000000 --- a/framework/Token/lib/Horde/Token/Driver.php +++ /dev/null @@ -1,112 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @package Token - */ -abstract class Horde_Token_Driver -{ - /** - * Logger. - * - * @var Horde_Log_Logger - */ - protected $_logger; - - /** - * Hash of parameters necessary to use the chosen backend. - * - * @var array - */ - protected $_params = array(); - - /** - * Constructor. - * - * @param array $params Optional parameters: - *
-     * 'logger' - (Horde_Log_Logger) A logger object.
-     * 
- */ - public function __construct($params) - { - if (isset($params['logger'])) { - $this->_logger = $params['logger']; - unset($params['logger']); - } - - $this->_params = $params; - } - - /** - * Checks if the given token has been previously used. First - * purges all expired tokens. Then retrieves current tokens for - * the given ip address. If the specified token was not found, - * adds it. - * - * @param string $token The value of the token to check. - * - * @return boolean True if the token has not been used, false otherwise. - * @throws Horde_Token_Exception - */ - public function verify($token) - { - $this->purge(); - - if ($this->exists($token)) { - return false; - } - - $this->add($token); - return true; - } - - /** - * Does the token exist? - * - * @param string $tokenID Token ID. - * - * @return boolean True if the token exists. - * @throws Horde_Token_Exception - */ - abstract public function exists($tokenID); - - /** - * Add a token ID. - * - * @param string $tokenID Token ID to add. - * - * @throws Horde_Token_Exception - */ - abstract public function add($tokenID); - - /** - * Delete all expired connection IDs. - * - * @throws Horde_Token_Exception - */ - abstract public function purge(); - - /** - * Encodes the remote address. - * - * @return string Encoded address. - */ - protected function _encodeRemoteAddress() - { - return isset($_SERVER['REMOTE_ADDR']) - ? base64_encode($_SERVER['REMOTE_ADDR']) - : ''; - } - - -} diff --git a/framework/Token/package.xml b/framework/Token/package.xml index 0ff03e84b..2b1614744 100644 --- a/framework/Token/package.xml +++ b/framework/Token/package.xml @@ -27,7 +27,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> LGPL * Add Horde_Token_Exception::. - * Move driver code into Horde_Token_Driver::. + * Move driver code into sub-classes. * Use exceptions, not PEAR_Errors. * Initial Horde 4 package. @@ -36,7 +36,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - + @@ -81,7 +81,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - + diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index fe0b2d348..5a95ea9b6 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -769,7 +769,7 @@ class IMP_Compose $timelimit = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_timelimit'); if ($timelimit !== true) { $sentmail = $GLOBALS['injector']->getInstance('IMP_Sentmail'); - if (!is_subclass_of($sentmail, 'IMP_Sentmail_Driver')) { + if (!($sentmail instanceof IMP_Sentmail_Base)) { Horde::logMessage('The permission for the maximum number of recipients per time period has been enabled, but no backend for the sent-mail logging has been configured for IMP.', 'ERR'); throw new IMP_Compose_Exception(_("The system is not properly configured. A detailed error description has been logged for the administrator.")); } diff --git a/imp/lib/Quota/Base.php b/imp/lib/Quota/Base.php new file mode 100644 index 000000000..513882487 --- /dev/null +++ b/imp/lib/Quota/Base.php @@ -0,0 +1,107 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package IMP + */ +abstract class IMP_Quota_Base +{ + /** + * Driver parameters. + * + * @var array + */ + protected $_params = array( + 'unit' => 'MB' + ); + + /** + * Constructor. + * + * @param array $params Parameters: + *
+     * 'format' - (string) The formats of the quota messages in the user
+     *            interface. Must be a hash with the four possible elements
+     *            'long', 'short', 'nolimit_long', and 'nolimit_short'. The
+     *            strings will be passed through sprintf().
+     * 'unit' - (string) What storage unit the quota messages should be
+     *          displayed in. Either 'GB', 'MB', or 'KB'.
+     * 
+ */ + public function __construct(array $params = array()) + { + $this->_params = array_merge($this->_params, $params); + + $this->_params['format'] = array( + 'long' => isset($this->_params['format']['long']) + ? $this->_params['format']['long'] + : _("Quota status: %.2f %s / %.2f %s (%.2f%%)"), + 'short' => isset($this->_params['format']['short']) + ? $this->_params['format']['short'] + : _("%.0f%% of %.0f %s"), + 'nolimit_long' => isset($this->_params['format']['nolimit_long']) + ? $this->_params['format']['nolimit_long'] + : _("Quota status: %.2f %s / NO LIMIT"), + 'nolimit_short' => isset($this->_params['format']['nolimit_short']) + ? $this->_params['format']['nolimit_short'] + : _("%.0f %s") + ); + } + + /** + * Get quota information (used/allocated), in bytes. + * + * @return array An array with the following keys: + * 'limit' = Maximum quota allowed + * 'usage' = Currently used portion of quota (in bytes) + * @throws IMP_Exception + */ + abstract public function getQuota(); + + /** + * Returns the quota messages variants, including sprintf placeholders. + * + * @return array An array with quota message templates. + */ + public function getMessages() + { + return $this->_params['format']; + } + + /** + * Determine the units of storage to display in the quota message. + * + * @return array An array of size and unit type. + */ + public function getUnit() + { + $unit = $this->_params['unit']; + + switch ($unit) { + case 'GB': + $calc = 1024 * 1024 * 1024.0; + break; + + case 'KB': + $calc = 1024.0; + break; + + case 'MB': + default: + $calc = 1024 * 1024.0; + $unit = 'MB'; + break; + } + + return array($calc, $unit); + } + +} diff --git a/imp/lib/Quota/Command.php b/imp/lib/Quota/Command.php index 070b7c69e..624d1d9cb 100644 --- a/imp/lib/Quota/Command.php +++ b/imp/lib/Quota/Command.php @@ -17,7 +17,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Quota_Command extends IMP_Quota_Driver +class IMP_Quota_Command extends IMP_Quota_Base { /** * Constructor. diff --git a/imp/lib/Quota/Driver.php b/imp/lib/Quota/Driver.php deleted file mode 100644 index 96b11009b..000000000 --- a/imp/lib/Quota/Driver.php +++ /dev/null @@ -1,107 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -abstract class IMP_Quota_Driver -{ - /** - * Driver parameters. - * - * @var array - */ - protected $_params = array( - 'unit' => 'MB' - ); - - /** - * Constructor. - * - * @param array $params Parameters: - *
-     * 'format' - (string) The formats of the quota messages in the user
-     *            interface. Must be a hash with the four possible elements
-     *            'long', 'short', 'nolimit_long', and 'nolimit_short'. The
-     *            strings will be passed through sprintf().
-     * 'unit' - (string) What storage unit the quota messages should be
-     *          displayed in. Either 'GB', 'MB', or 'KB'.
-     * 
- */ - public function __construct(array $params = array()) - { - $this->_params = array_merge($this->_params, $params); - - $this->_params['format'] = array( - 'long' => isset($this->_params['format']['long']) - ? $this->_params['format']['long'] - : _("Quota status: %.2f %s / %.2f %s (%.2f%%)"), - 'short' => isset($this->_params['format']['short']) - ? $this->_params['format']['short'] - : _("%.0f%% of %.0f %s"), - 'nolimit_long' => isset($this->_params['format']['nolimit_long']) - ? $this->_params['format']['nolimit_long'] - : _("Quota status: %.2f %s / NO LIMIT"), - 'nolimit_short' => isset($this->_params['format']['nolimit_short']) - ? $this->_params['format']['nolimit_short'] - : _("%.0f %s") - ); - } - - /** - * Get quota information (used/allocated), in bytes. - * - * @return array An array with the following keys: - * 'limit' = Maximum quota allowed - * 'usage' = Currently used portion of quota (in bytes) - * @throws IMP_Exception - */ - abstract public function getQuota(); - - /** - * Returns the quota messages variants, including sprintf placeholders. - * - * @return array An array with quota message templates. - */ - public function getMessages() - { - return $this->_params['format']; - } - - /** - * Determine the units of storage to display in the quota message. - * - * @return array An array of size and unit type. - */ - public function getUnit() - { - $unit = $this->_params['unit']; - - switch ($unit) { - case 'GB': - $calc = 1024 * 1024 * 1024.0; - break; - - case 'KB': - $calc = 1024.0; - break; - - case 'MB': - default: - $calc = 1024 * 1024.0; - $unit = 'MB'; - break; - } - - return array($calc, $unit); - } - -} diff --git a/imp/lib/Quota/Hook.php b/imp/lib/Quota/Hook.php index 8dfcd7e48..6a0781313 100644 --- a/imp/lib/Quota/Hook.php +++ b/imp/lib/Quota/Hook.php @@ -19,7 +19,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Quota_Hook extends IMP_Quota_Driver +class IMP_Quota_Hook extends IMP_Quota_Base { /** * Get quota information (used/allocated), in bytes. diff --git a/imp/lib/Quota/Imap.php b/imp/lib/Quota/Imap.php index de52e90ae..404b67b4d 100644 --- a/imp/lib/Quota/Imap.php +++ b/imp/lib/Quota/Imap.php @@ -12,7 +12,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Quota_Imap extends IMP_Quota_Driver +class IMP_Quota_Imap extends IMP_Quota_Base { /** * Constructor. diff --git a/imp/lib/Quota/Maildir.php b/imp/lib/Quota/Maildir.php index 03aa4ec5e..885e59972 100644 --- a/imp/lib/Quota/Maildir.php +++ b/imp/lib/Quota/Maildir.php @@ -16,7 +16,7 @@ * @package IMP * @todo Add config param for storage vs message quota */ -class IMP_Quota_Maildir extends IMP_Quota_Driver +class IMP_Quota_Maildir extends IMP_Quota_Base { /** * Constructor. diff --git a/imp/lib/Quota/Mdaemon.php b/imp/lib/Quota/Mdaemon.php index 3e7817f43..4724f49e8 100644 --- a/imp/lib/Quota/Mdaemon.php +++ b/imp/lib/Quota/Mdaemon.php @@ -12,7 +12,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Quota_Mdaemon extends IMP_Quota_Driver +class IMP_Quota_Mdaemon extends IMP_Quota_Base { /** * Constructor. diff --git a/imp/lib/Quota/Mercury32.php b/imp/lib/Quota/Mercury32.php index 05764c65e..c0608d74b 100644 --- a/imp/lib/Quota/Mercury32.php +++ b/imp/lib/Quota/Mercury32.php @@ -30,7 +30,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Quota_Mercury32 extends IMP_Quota_Driver +class IMP_Quota_Mercury32 extends IMP_Quota_Base { /** * Constructor. diff --git a/imp/lib/Quota/Null.php b/imp/lib/Quota/Null.php index 20da3608b..bf768ee92 100644 --- a/imp/lib/Quota/Null.php +++ b/imp/lib/Quota/Null.php @@ -12,7 +12,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Quota_Null extends IMP_Quota_Driver +class IMP_Quota_Null extends IMP_Quota_Base { /** * Get quota information (used/allocated), in bytes. diff --git a/imp/lib/Quota/Sql.php b/imp/lib/Quota/Sql.php index 1657d4a72..8c24bfe59 100644 --- a/imp/lib/Quota/Sql.php +++ b/imp/lib/Quota/Sql.php @@ -15,7 +15,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Quota_Sql extends IMP_Quota_Driver +class IMP_Quota_Sql extends IMP_Quota_Base { /** * DB object. diff --git a/imp/lib/Sentmail/Base.php b/imp/lib/Sentmail/Base.php new file mode 100644 index 000000000..74c17928f --- /dev/null +++ b/imp/lib/Sentmail/Base.php @@ -0,0 +1,111 @@ + + * @author Michael Slusarz + * @category Horde + * @package IMP + */ +abstract class IMP_Sentmail_Base +{ + /** + * Hash containing configuration parameters. + * + * @var array + */ + protected $_params = array(); + + /** + * Constructor. + * + * @throws IMP_Exception + */ + public function __construct($params = array()) + { + $this->_params = array_merge($this->_params, $params); + } + + /** + * Logs an attempt to send a message. + * + * @param string $action Why the message was sent, i.e. "new", + * "reply", "forward", etc. + * @param string $message_id The Message-ID. + * @param string|array $recipients The list of message recipients. + * @param boolean $success Whether the attempt was successful. + */ + public function log($action, $message_id, $recipients, $success = true) + { + if (!is_array($recipients)) { + $recipients = array($recipients); + } + + foreach ($recipients as $addresses) { + $addresses = Horde_Mime_Address::bareAddress($addresses, $_SESSION['imp']['maildomain'], true); + foreach ($addresses as $recipient) { + $this->_log($action, $message_id, $recipient, $success); + } + } + } + + /** + * Garbage collect log entries. + */ + public function gc() + { + $this->_deleteOldEntries(time() - ((isset($this->_params['threshold']) ? $this->_params['threshold'] : 0) * 86400)); + } + + /** + * Logs an attempt to send a message per recipient. + * + * @param string $action Why the message was sent, i.e. "new", + * "reply", "forward", etc. + * @param string $message_id The Message-ID. + * @param string $recipients A message recipient. + * @param boolean $success Whether the attempt was successful. + */ + abstract protected function _log($action, $message_id, $recipient, + $success); + + /** + * Returns the favourite recipients. + * + * @param integer $limit Return this number of recipients. + * @param array $filter A list of messages types that should be returned. + * A value of null returns all message types. + * + * @return array A list with the $limit most favourite recipients. + * @throws IMP_Exception + */ + abstract public function favouriteRecipients($limit, + $filter = array('new', 'forward', 'reply', 'redirect')); + + /** + * Returns the number of recipients within a certain time period. + * + * @param integer $hours Time period in hours. + * @param boolean $user Return the number of recipients for the current + * user? + * + * @return integer The number of recipients in the given time period. + * @throws IMP_Exception + */ + abstract public function numberOfRecipients($hours, $user = false); + + /** + * Deletes all log entries older than a certain date. + * + * @param integer $before Unix timestamp before that all log entries + * should be deleted. + */ + abstract protected function _deleteOldEntries($before); + +} diff --git a/imp/lib/Sentmail/Driver.php b/imp/lib/Sentmail/Driver.php deleted file mode 100644 index d8c0bdf89..000000000 --- a/imp/lib/Sentmail/Driver.php +++ /dev/null @@ -1,111 +0,0 @@ - - * @author Michael Slusarz - * @category Horde - * @package IMP - */ -abstract class IMP_Sentmail_Driver -{ - /** - * Hash containing configuration parameters. - * - * @var array - */ - protected $_params = array(); - - /** - * Constructor. - * - * @throws IMP_Exception - */ - public function __construct($params = array()) - { - $this->_params = array_merge($this->_params, $params); - } - - /** - * Logs an attempt to send a message. - * - * @param string $action Why the message was sent, i.e. "new", - * "reply", "forward", etc. - * @param string $message_id The Message-ID. - * @param string|array $recipients The list of message recipients. - * @param boolean $success Whether the attempt was successful. - */ - public function log($action, $message_id, $recipients, $success = true) - { - if (!is_array($recipients)) { - $recipients = array($recipients); - } - - foreach ($recipients as $addresses) { - $addresses = Horde_Mime_Address::bareAddress($addresses, $_SESSION['imp']['maildomain'], true); - foreach ($addresses as $recipient) { - $this->_log($action, $message_id, $recipient, $success); - } - } - } - - /** - * Garbage collect log entries. - */ - public function gc() - { - $this->_deleteOldEntries(time() - ((isset($this->_params['threshold']) ? $this->_params['threshold'] : 0) * 86400)); - } - - /** - * Logs an attempt to send a message per recipient. - * - * @param string $action Why the message was sent, i.e. "new", - * "reply", "forward", etc. - * @param string $message_id The Message-ID. - * @param string $recipients A message recipient. - * @param boolean $success Whether the attempt was successful. - */ - abstract protected function _log($action, $message_id, $recipient, - $success); - - /** - * Returns the favourite recipients. - * - * @param integer $limit Return this number of recipients. - * @param array $filter A list of messages types that should be returned. - * A value of null returns all message types. - * - * @return array A list with the $limit most favourite recipients. - * @throws IMP_Exception - */ - abstract public function favouriteRecipients($limit, - $filter = array('new', 'forward', 'reply', 'redirect')); - - /** - * Returns the number of recipients within a certain time period. - * - * @param integer $hours Time period in hours. - * @param boolean $user Return the number of recipients for the current - * user? - * - * @return integer The number of recipients in the given time period. - * @throws IMP_Exception - */ - abstract public function numberOfRecipients($hours, $user = false); - - /** - * Deletes all log entries older than a certain date. - * - * @param integer $before Unix timestamp before that all log entries - * should be deleted. - */ - abstract protected function _deleteOldEntries($before); - -} diff --git a/imp/lib/Sentmail/Null.php b/imp/lib/Sentmail/Null.php index 7066a11ba..d73f4486e 100644 --- a/imp/lib/Sentmail/Null.php +++ b/imp/lib/Sentmail/Null.php @@ -12,7 +12,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Sentmail_Null extends IMP_Sentmail_Driver +class IMP_Sentmail_Null extends IMP_Sentmail_Base { /** * Garbage collect log entries. diff --git a/imp/lib/Sentmail/Sql.php b/imp/lib/Sentmail/Sql.php index 722079652..80c97a27a 100644 --- a/imp/lib/Sentmail/Sql.php +++ b/imp/lib/Sentmail/Sql.php @@ -32,7 +32,7 @@ * @license http://www.fsf.org/copyleft/gpl.html GPL * @package IMP */ -class IMP_Sentmail_Sql extends IMP_Sentmail_Driver +class IMP_Sentmail_Sql extends IMP_Sentmail_Base { /** * Handle for the current database connection.