From 53c3063da3c50afb2cb6c28dd17d38515bdfb62b Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 24 Nov 2008 22:47:10 -0700 Subject: [PATCH] Some updates to PHP 5 style. --- imp/lib/Auth/imp.php | 16 +++--- imp/lib/Identity/imp.php | 55 ++++++++++--------- imp/lib/Imple.php | 22 ++++---- imp/lib/Imple/ContactAutoCompleter.php | 18 +++---- imp/lib/Imple/SpellChecker.php | 14 +++-- imp/lib/Sentmail.php | 98 ++++++++++++++++++---------------- imp/lib/Sentmail/sql.php | 21 ++++---- 7 files changed, 120 insertions(+), 124 deletions(-) diff --git a/imp/lib/Auth/imp.php b/imp/lib/Auth/imp.php index 1fc084391..22ed5adf5 100644 --- a/imp/lib/Auth/imp.php +++ b/imp/lib/Auth/imp.php @@ -28,8 +28,8 @@ class Auth_imp extends Auth * * @return boolean Whether or not the credentials are valid. */ - function authenticate($userID = null, $credentials = array(), - $login = false) + public function authenticate($userID = null, $credentials = array(), + $login = false) { return parent::authenticate($userID, $credentials, $login && ($this->getProvider() == 'imp')); } @@ -42,17 +42,15 @@ class Auth_imp extends Auth * * @return boolean Whether or not the credentials are valid. */ - function _authenticate($userID, $credentials) + protected function _authenticate($userID, $credentials) { - global $imp_imap; - // Check for valid IMAP Client object. - if (!$imp_imap->loadImapObject()) { + if (!$GLOBALS['imp_imap']->loadImapObject()) { // Attempt to create IMAP Client object $key = isset($credentials['server']) ? $credentials['server'] : IMP_Session::getAutoLoginServer(); if (is_null($key) || !isset($credentials['password']) || - !$imp_imap->createImapObject($userID, $credentials['password'], $key)) { + !$GLOBALS['imp_imap']->createImapObject($userID, $credentials['password'], $key)) { IMP::loginLogMessage('failed', __FILE__, __LINE__); $this->_setAuthError(AUTH_REASON_FAILED); return false; @@ -60,10 +58,10 @@ class Auth_imp extends Auth } try { - $imp_imap->ob->login(); + $GLOBALS['imp_imap']->ob->login(); return true; } catch (Horde_Imap_Client_Exception $e) { - IMP::loginLogMessage('failed', __FILE__, __LINE__); + IMP::loginLogMessage($e->getMessage(), __FILE__, __LINE__); $this->_setAuthError(AUTH_REASON_BADLOGIN); return false; } diff --git a/imp/lib/Identity/imp.php b/imp/lib/Identity/imp.php index da224e1dd..f622e83a5 100644 --- a/imp/lib/Identity/imp.php +++ b/imp/lib/Identity/imp.php @@ -13,48 +13,49 @@ * @author Chuck Hagenbuch * @package Horde_Identity */ -class Identity_imp extends Identity { - +class Identity_imp extends Identity +{ /** * Cached alias list. * * @var array */ - var $_aliases = array(); + protected $_aliases = array(); /** * Cached from address list. * * @var array */ - var $_fromList = array(); + protected $_fromList = array(); /** * Cached names list. * * @var array */ - var $_names = array(); + protected $_names = array(); /** * Cached signature list. * * @var array */ - var $_signatures = array(); + protected $_signatures = array(); /** * Reads all the user's identities from the prefs object or builds * a new identity from the standard values given in prefs.php. */ - function Identity_imp() + function __construct() { parent::Identity(); $this->_properties = array_merge( $this->_properties, array('replyto_addr', 'alias_addr', 'tieto_addr', 'bcc_addr', 'signature', 'sig_first', 'sig_dashes', 'save_sent_mail', - 'sent_mail_folder')); + 'sent_mail_folder') + ); } /** @@ -65,7 +66,7 @@ class Identity_imp extends Identity { * @return boolean|object True if the properties are valid or a PEAR_Error * with an error description otherwise. */ - function verify($identity = null) + public function verify($identity = null) { if (is_a($result = parent::verify($identity), 'PEAR_Error')) { return $result; @@ -126,7 +127,7 @@ class Identity_imp extends Identity { * @return string A full From: header in the format * 'Fullname '. */ - function getFromLine($ident = null, $from_address = '') + public function getFromLine($ident = null, $from_address = '') { static $froms = array(); @@ -170,7 +171,7 @@ class Identity_imp extends Identity { * * @return array The From: headers from all identities */ - function getAllFromLines() + public function getAllFromLines() { foreach (array_keys($this->_identities) as $ident) { $list[$ident] = $this->getFromAddress($ident); @@ -184,7 +185,7 @@ class Identity_imp extends Identity { * * @return array The array with the necessary strings */ - function getSelectList() + public function getSelectList() { $ids = $this->getAll('id'); foreach ($ids as $key => $id) { @@ -201,7 +202,7 @@ class Identity_imp extends Identity { * * @return boolean True if the address was found. */ - function hasAddress($address) + public function hasAddress($address) { static $list; @@ -222,7 +223,7 @@ class Identity_imp extends Identity { * * @return string A valid from address. */ - function getFromAddress($ident = null) + public function getFromAddress($ident = null) { if (!empty($this->_fromList[$ident])) { return $this->_fromList[$ident]; @@ -249,7 +250,7 @@ class Identity_imp extends Identity { * * @return array Aliases for the identity. */ - function getAliasAddress($ident) + public function getAliasAddress($ident) { if (empty($this->_aliases[$ident])) { $this->_aliases[$ident] = @array_merge($this->getValue('alias_addr', $ident), @@ -268,7 +269,7 @@ class Identity_imp extends Identity { * KEY - address * VAL - identity number */ - function getAllFromAddresses($alias = false) + public function getAllFromAddresses($alias = false) { $list = array(); @@ -297,7 +298,7 @@ class Identity_imp extends Identity { * KEY - address * VAL - identity number */ - function getAllTieAddresses() + public function getAllTieAddresses() { $list = array(); @@ -317,11 +318,9 @@ class Identity_imp extends Identity { * Returns the list of identities with the default identity positioned * last. * - * @access private - * * @return array The identities list with the default identity last. */ - function _identitiesWithDefaultLast() + protected function _identitiesWithDefaultLast() { $ids = $this->_identities; $default = $this->getDefault(); @@ -338,7 +337,7 @@ class Identity_imp extends Identity { * * @return array The array of objects (IMAP addresses). */ - function getBccAddresses($ident = null) + public function getBccAddresses($ident = null) { $bcc = $this->getValue('bcc_addr', $ident); if (empty($bcc)) { @@ -363,7 +362,7 @@ class Identity_imp extends Identity { * addresses match (one of) the passed addresses or * null if none matches. */ - function getMatchingIdentity($addresses, $search_ties = true) + public function getMatchingIdentity($addresses, $search_ties = true) { static $tie_addresses, $own_addresses; @@ -426,7 +425,7 @@ class Identity_imp extends Identity { * * @return string The user's full name. */ - function getFullname($ident = null) + public function getFullname($ident = null) { if (isset($this->_names[$ident])) { return $this->_names[$ident]; @@ -445,7 +444,7 @@ class Identity_imp extends Identity { * * @return string The full signature. */ - function getSignature($ident = null) + public function getSignature($ident = null) { if (isset($this->_signatures[$ident])) { return $this->_signatures[$ident]; @@ -481,7 +480,7 @@ class Identity_imp extends Identity { * * @return array The array with all the signatures. */ - function getAllSignatures() + public function getAllSignatures() { static $list; @@ -499,7 +498,7 @@ class Identity_imp extends Identity { /** * @see Identity::getValue() */ - function getValue($key, $identity = null) + public function getValue($key, $identity = null) { if ($key == 'sent_mail_folder') { $folder = parent::getValue('sent_mail_folder', $identity); @@ -514,7 +513,7 @@ class Identity_imp extends Identity { * * @return array The array with the folder names. */ - function getAllSentmailFolders() + public function getAllSentmailFolders() { $list = array(); foreach ($this->_identities as $key => $identity) { @@ -534,7 +533,7 @@ class Identity_imp extends Identity { * * @return boolean True if the sent mail should be saved. */ - function saveSentmail($ident = null) + public function saveSentmail($ident = null) { if (!$GLOBALS['conf']['user']['allow_folders']) { return false; diff --git a/imp/lib/Imple.php b/imp/lib/Imple.php index 2d05519cd..7cd809d7d 100644 --- a/imp/lib/Imple.php +++ b/imp/lib/Imple.php @@ -1,5 +1,7 @@ * @package IMP */ -class Imple { - +class Imple +{ /** * Parameters needed by the subclasses. * * @var array */ - var $_params = array(); + protected $_params = array(); /** * Attempts to return a concrete Imple instance based on $imple. @@ -28,7 +30,7 @@ class Imple { * @return mixed The newly created concrete Imple instance, or false on * error. */ - function factory($imple, $params = array()) + static public function factory($imple, $params = array()) { $imple = basename($imple); if (!$imple) { @@ -51,7 +53,7 @@ class Imple { * * @param array $params Any parameters needed by the class. */ - function Imple($params) + function __construct($params) { $this->_params = $params; $this->attach(); @@ -60,7 +62,7 @@ class Imple { /** * Attach the Imple object to a javascript event. */ - function attach() + public function attach() { Horde::addScriptFile('prototype.js', 'horde', true); Horde::addScriptFile('effects.js', 'horde', true); @@ -71,7 +73,7 @@ class Imple { * * @param TODO */ - function handle($args) + public function handle($args) { } @@ -80,18 +82,16 @@ class Imple { * * @return string The HTML code. */ - function html() + public function html() { } /** * Generate a random ID string. * - * @access private - * * @return string The random ID string. */ - function _randomid() + protected function _randomid() { return 'imple_' . uniqid(mt_rand()); } diff --git a/imp/lib/Imple/ContactAutoCompleter.php b/imp/lib/Imple/ContactAutoCompleter.php index 30b8284d5..523b9ca19 100644 --- a/imp/lib/Imple/ContactAutoCompleter.php +++ b/imp/lib/Imple/ContactAutoCompleter.php @@ -8,14 +8,14 @@ * @author Michael Slusarz * @package IMP */ -class Imple_ContactAutoCompleter extends Imple { - +class Imple_ContactAutoCompleter extends Imple +{ /** * The URL to use in attach(). * * @var string */ - var $_url; + protected $_url; /** * Constructor. @@ -26,7 +26,7 @@ class Imple_ContactAutoCompleter extends Imple { * 'resultsId' => TODO (optional) * */ - function Imple_ContactAutoCompleter($params) + function __construct($params) { if (empty($params['triggerId'])) { $params['triggerId'] = $this->_randomid(); @@ -35,13 +35,13 @@ class Imple_ContactAutoCompleter extends Imple { $params['resultsId'] = $params['triggerId'] . '_results'; } - parent::Imple($params); + parent::__construct($params); } /** * Attach the Imple object to a javascript event. */ - function attach() + public function attach() { static $list_output = false; @@ -61,7 +61,6 @@ class Imple_ContactAutoCompleter extends Imple { if (!isset($_SESSION['imp']['cache']['ac_ajax'])) { $success = $use_ajax = true; - require_once IMP_BASE . '/lib/Compose.php'; $sparams = IMP_Compose::getAddressSearchParams(); foreach ($sparams['fields'] as $val) { array_map('strtolower', $val); @@ -87,10 +86,8 @@ class Imple_ContactAutoCompleter extends Imple { } else { if (!$list_output) { if (!isset($addrlist)) { - require_once IMP_BASE . '/lib/Compose.php'; $addrlist = IMP_Compose::getAddressList(); } - require_once 'Horde/Serialize.php'; IMP::addInlineScript('if (!IMP) { var IMP = {}; } IMP.ac_list = '. Horde_Serialize::serialize(array_map('htmlspecialchars', $addrlist), SERIALIZE_JSON, NLS::getCharset())); $list_output = true; } @@ -111,7 +108,7 @@ class Imple_ContactAutoCompleter extends Imple { * * @return array The data to send to the autocompleter JS code. */ - function handle($args) + public function handle($args) { // Avoid errors if 'input' isn't set and short-circuit empty searches. if (empty($args['input']) || @@ -119,7 +116,6 @@ class Imple_ContactAutoCompleter extends Imple { return array(); } - require_once IMP_BASE . '/lib/Compose.php'; return array_map('htmlspecialchars', IMP_Compose::expandAddresses($input)); } diff --git a/imp/lib/Imple/SpellChecker.php b/imp/lib/Imple/SpellChecker.php index 3c3f75184..5bf13e7d0 100644 --- a/imp/lib/Imple/SpellChecker.php +++ b/imp/lib/Imple/SpellChecker.php @@ -8,8 +8,8 @@ * @author Michael Slusarz * @package IMP */ -class Imple_SpellChecker extends Imple { - +class Imple_SpellChecker extends Imple +{ /** * Constructor. * @@ -22,9 +22,8 @@ class Imple_SpellChecker extends Imple { * 'triggerId' => TODO (optional) * */ - function Imple_SpellChecker($params = array()) + function __construct($params = array()) { - require_once 'Horde/Serialize.php'; if (empty($params['id'])) { $params['id'] = $this->_randomid(); } @@ -48,12 +47,12 @@ class Imple_SpellChecker extends Imple { asort($params['locales'], SORT_LOCALE_STRING); $params['locales'] = Horde_Serialize::serialize($params['locales'], SERIALIZE_JSON, NLS::getCharset()); - parent::Imple($params); + parent::__construct($params); } /** */ - function attach() + public function attach() { parent::attach(); Horde::addScriptFile('KeyNavList.js', 'imp', true); @@ -64,7 +63,7 @@ class Imple_SpellChecker extends Imple { /** */ - function handle($args) + public function handle($args) { $spellArgs = array(); @@ -88,7 +87,6 @@ class Imple_SpellChecker extends Imple { $spellArgs['html'] = true; } - require_once 'Horde/SpellChecker.php'; $speller = Horde_SpellChecker::factory( $GLOBALS['conf']['spell']['driver'], $spellArgs); if ($speller === false) { diff --git a/imp/lib/Sentmail.php b/imp/lib/Sentmail.php index c0f1706bc..733cbe406 100644 --- a/imp/lib/Sentmail.php +++ b/imp/lib/Sentmail.php @@ -11,7 +11,47 @@ * @author Jan Schneider * @package IMP */ -class IMP_Sentmail { +class IMP_Sentmail +{ + /** + * Attempts to return a concrete IMP_Sentmail instance based on $driver. + * + * @param string $driver The type of the concrete IMP_Sentmail subclass + * to return. The class name is based on the + * storage driver ($driver). The code is + * dynamically included. + * + * @param array $params A hash containing any additional configuration + * or connection parameters a subclass might need. + * + * @return IMP_Sentmail The newly created concrete IMP_Sentmail instance. + */ + static public function factory($driver = null, $params = null) + { + if (is_null($driver)) { + $driver = $GLOBALS['conf']['sentmail']['driver']; + } + + if (is_null($params)) { + $params = Horde::getDriverConfig('sentmail', $driver); + } + + $driver = basename($driver); + $class = 'IMP_Sentmail_' . $driver; + if (!class_exists($class)) { + @include dirname(__FILE__) . '/Sentmail/' . $driver . '.php'; + } + + if (class_exists($class)) { + $sentmail = new $class($params); + $result = $sentmail->initialize(); + if (!is_a($result, 'PEAR_Error')) { + return $sentmail; + } + } + + return new IMP_Sentmail(); + } /** * Logs an attempt to send a message. @@ -22,17 +62,19 @@ class IMP_Sentmail { * @param string|array $recipients The list of message recipients. * @param boolean $success Whether the attempt was successful. */ - function log($action, $message_id, $recipients, $success = true) + 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); } } + $this->gc(); } @@ -45,12 +87,12 @@ class IMP_Sentmail { * @param string $recipients A message recipient. * @param boolean $success Whether the attempt was successful. */ - function _log($action, $message_id, $recipient, $success) + protected function _log($action, $message_id, $recipient, $success) { } /** - * Returns the most favourite recipients. + * Returns the favourite recipients. * * @param integer $limit Return this number of recipients. * @param array $filter A list of messages types that should be returned. @@ -58,7 +100,8 @@ class IMP_Sentmail { * * @return array A list with the $limit most favourite recipients. */ - function favouriteRecipients($limit, $filter = array('new', 'forward', 'reply', 'redirect')) + public function favouriteRecipients($limit, + $filter = array('new', 'forward', 'reply', 'redirect')) { return array(); } @@ -72,7 +115,7 @@ class IMP_Sentmail { * * @return integer The number of recipients in the given time period. */ - function numberOfRecipients($hours, $user = false) + public function numberOfRecipients($hours, $user = false) { return 0; } @@ -80,7 +123,7 @@ class IMP_Sentmail { /** * Garbage collect log entries with a probability of 1%. */ - function gc() + public function gc() { /* A 1% chance we will run garbage collection during a call. */ if (rand(0, 99) == 0) { @@ -94,47 +137,8 @@ class IMP_Sentmail { * @param integer $before Unix timestamp before that all log entries * should be deleted. */ - function _deleteOldEntries($before) - { - } - - /** - * Attempts to return a concrete IMP_Sentmail instance based on $driver. - * - * @param string $driver The type of the concrete IMP_Sentmail subclass - * to return. The class name is based on the - * storage driver ($driver). The code is - * dynamically included. - * - * @param array $params A hash containing any additional configuration - * or connection parameters a subclass might need. - * - * @return mixed The newly created concrete IMP_Sentmail instance, or - * false on an error. - */ - function factory($driver = null, $params = null) + protected function _deleteOldEntries($before) { - if ($driver === null) { - $driver = $GLOBALS['conf']['sentmail']['driver']; - } - if ($params === null) { - $params = Horde::getDriverConfig('sentmail', $driver); - } - - $driver = basename($driver); - $class = 'IMP_Sentmail_' . $driver; - if (!class_exists($class)) { - @include dirname(__FILE__) . '/Sentmail/' . $driver . '.php'; - } - if (class_exists($class)) { - $sentmail = new $class($params); - $result = $sentmail->initialize(); - if (!is_a($result, 'PEAR_Error')) { - return $sentmail; - } - } - - return new IMP_Sentmail(); } } diff --git a/imp/lib/Sentmail/sql.php b/imp/lib/Sentmail/sql.php index fdd64f751..979940afe 100644 --- a/imp/lib/Sentmail/sql.php +++ b/imp/lib/Sentmail/sql.php @@ -22,28 +22,28 @@ * @author Jan Schneider * @package IMP */ -class IMP_Sentmail_sql extends IMP_Sentmail { - +class IMP_Sentmail_sql extends IMP_Sentmail +{ /** * Hash containing connection parameters. * * @var array */ - var $_params = array(); + protected $_params = array(); /** * Handle for the current database connection. * * @var DB */ - var $_db; + protected $_db; /** * Constructor. * * @param array $params A hash containing connection parameters. */ - function IMP_Sentmail_sql($params = array()) + function __construct($params = array()) { $this->_params = $params; } @@ -57,7 +57,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail { * @param string $recipients A message recipient. * @param boolean $success Whether the attempt was successful. */ - function _log($action, $message_id, $recipient, $success) + protected function _log($action, $message_id, $recipient, $success) { /* Build the SQL query. */ $query = sprintf('INSERT INTO %s (sentmail_id, sentmail_who, sentmail_ts, sentmail_messageid, sentmail_action, sentmail_recipient, sentmail_success) VALUES (?, ?, ?, ?, ?, ?, ?)', @@ -92,7 +92,8 @@ class IMP_Sentmail_sql extends IMP_Sentmail { * * @return array A list with the $limit most favourite recipients. */ - function favouriteRecipients($limit, $filter = array('new', 'forward', 'reply', 'redirect')) + public function favouriteRecipients($limit, + $filter = array('new', 'forward', 'reply', 'redirect')) { /* Build the SQL query. */ $where = ''; @@ -136,7 +137,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail { * * @return integer The number of recipients in the given time period. */ - function numberOfRecipients($hours, $user = false) + public function numberOfRecipients($hours, $user = false) { /* Build the SQL query. */ $query = sprintf('SELECT COUNT(*) FROM %s WHERE sentmail_ts > ?', @@ -164,7 +165,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail { * @param integer $before Unix timestamp before that all log entries * should be deleted. */ - function _deleteOldEntries($before) + protected function _deleteOldEntries($before) { /* Build the SQL query. */ $query = sprintf('DELETE FROM %s WHERE sentmail_ts < ?', @@ -187,7 +188,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail { * * @return boolean True on success, PEAR_Error on failure. */ - function initialize() + public function initialize() { Horde::assertDriverConfig($this->_params, 'storage', array('phptype', 'table')); -- 2.11.0