From 5b0969a7d3fad81ae04676dc8731a70205943ec5 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 14 Apr 2010 14:55:46 -0600 Subject: [PATCH] Create Identity injector binder --- agora/messages/abuse.php | 2 +- agora/messages/index.php | 2 +- ansel/image.php | 2 +- ansel/lib/Ansel.php | 2 +- ansel/lib/Form/Ecard.php | 2 +- ansel/lib/Gallery.php | 2 +- ansel/lib/Image.php | 2 +- ansel/lib/Report.php | 2 +- ansel/lib/View/List.php | 2 +- ansel/rss.php | 2 +- fima/lib/Fima.php | 2 +- fima/lib/Forms/DeleteLedger.php | 2 +- folks/lib/Notification.php | 2 +- framework/Alarm/lib/Horde/Alarm.php | 2 +- framework/Core/lib/Horde/Core/Binder/Identity.php | 17 ++++ framework/Core/lib/Horde/Core/Factory/Identity.php | 95 +++++++++++++++++ framework/Core/lib/Horde/Core/Prefs/Ui.php | 4 +- framework/Core/lib/Horde/Registry.php | 1 + framework/Core/package.xml | 4 + framework/Mime/lib/Horde/Mime/Mdn.php | 2 +- framework/Prefs/lib/Horde/Prefs/Identity.php | 112 ++------------------- framework/Share/Share.php | 2 +- horde/admin/user.php | 4 +- horde/scripts/import_squirrelmail_prefs.php | 2 +- horde/services/confirm.php | 2 +- horde/services/portal/index.php | 2 +- horde/services/portal/mobile.php | 2 +- horde/services/problem.php | 2 +- imp/attachment.php | 6 +- imp/lib/Injector/Binder/Identity.php | 2 +- imp/lib/Prefs/Identity.php | 6 +- ingo/lib/Api.php | 2 +- ingo/lib/Application.php | 2 +- ingo/vacation.php | 2 +- kronolith/attendees.php | 2 +- kronolith/lib/FreeBusy.php | 2 +- kronolith/lib/Kronolith.php | 14 +-- kronolith/lib/View/EditEvent.php | 2 +- kronolith/scripts/agenda.php | 2 +- mnemo/lib/Mnemo.php | 4 +- nag/lib/Forms/task.php | 2 +- nag/lib/Nag.php | 14 +-- nag/tasklists/info.php | 2 +- turba/lib/Driver/Group.php | 2 +- turba/lib/Turba.php | 4 +- whups/lib/Mail.php | 2 +- whups/lib/Ticket.php | 2 +- whups/lib/Whups.php | 2 +- wicked/lib/Page.php | 2 +- wicked/lib/Wicked.php | 2 +- 50 files changed, 193 insertions(+), 166 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Binder/Identity.php create mode 100644 framework/Core/lib/Horde/Core/Factory/Identity.php diff --git a/agora/messages/abuse.php b/agora/messages/abuse.php index c989a6982..48eb007c2 100644 --- a/agora/messages/abuse.php +++ b/agora/messages/abuse.php @@ -57,7 +57,7 @@ if ($form->validate()) { /* Collect moderators emails, and send them the notify */ $emails = array(); foreach ($forum['moderators'] as $moderator) { - $identity = Horde_Prefs_Identity::singleton('none', $moderator); + $identity = $injector->getInstance('Horde_Prefs_Identity')->getOb($moderator); $address = $identity->getValue('from_addr'); if (!empty($address)) { $emails[] = $address; diff --git a/agora/messages/index.php b/agora/messages/index.php index 3f042a45c..b193dd4c0 100644 --- a/agora/messages/index.php +++ b/agora/messages/index.php @@ -77,7 +77,7 @@ $view = new Agora_View(); if (!$view_bodies) { /* Get the author's avatar. */ if ($conf['avatar']['allow_avatars']) { - $identity = Horde_Prefs_Identity::singleton('none', $message['message_author']); + $identity = $injector->getInstance('Horde_Prefs_Identity')->getOb($message['message_author']); $avatar_path = $identity->getValue('avatar_path'); $message_author_avatar = Agora::validateAvatar($avatar_path) ? Agora::getAvatarUrl($avatar_path) : false; $view->message_author_avatar = $message_author_avatar; diff --git a/ansel/image.php b/ansel/image.php index bf4547110..6d5ce8bd2 100644 --- a/ansel/image.php +++ b/ansel/image.php @@ -28,7 +28,7 @@ $date = Ansel::getDateParameter(); /* Are we watermarking the image? */ if ($watermark) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $injector->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (empty($name)) { $name = Horde_Auth::getAuth(); diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index d1c64be4d..363c9bd3a 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -704,7 +704,7 @@ class Ansel $owner, '', null, false); $fullname = $uprefs->getValue('grouptitle'); if (!$fullname) { - $identity = Horde_Prefs_Identity::singleton('none', $owner); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($owner); $fullname = $identity->getValue('fullname'); if (!$fullname) { $fullname = $owner; diff --git a/ansel/lib/Form/Ecard.php b/ansel/lib/Form/Ecard.php index 7a46d6a86..84f9d4fbe 100644 --- a/ansel/lib/Form/Ecard.php +++ b/ansel/lib/Form/Ecard.php @@ -23,7 +23,7 @@ class Ansel_Form_Ecard extends Horde_Form { if (empty($user)) { $this->addVariable(_("Use the following return address:"), 'ecard_retaddr', 'text', true); } else { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $from_addr = $identity->getDefaultFromAddress(); $vars->set('ecard_retaddr', $from_addr); $this->addHidden('', 'ecard_retaddr', 'text', true); diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index e8aecaabe..7d87899a2 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -446,7 +446,7 @@ class Ansel_Gallery extends Horde_Share_Object_sql_hierarchical */ public function getOwner() { - return Horde_Prefs_Identity::singleton('none', $this->data['share_owner']); + return $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($this->data['share_owner']); } /** diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index b6735c559..915b8c60b 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -1013,7 +1013,7 @@ class Ansel_Image Implements Iterator } if (empty($watermark)) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (empty($name)) { $name = Horde_Auth::getAuth(); diff --git a/ansel/lib/Report.php b/ansel/lib/Report.php index d9e59233d..dd0cb4f75 100644 --- a/ansel/lib/Report.php +++ b/ansel/lib/Report.php @@ -55,7 +55,7 @@ class Ansel_Report { */ function _getUserEmail($user = null) { - return Horde_Prefs_Identity::singleton('none', $user)->getValue('from_addr'); + return $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user)->getValue('from_addr'); } /** diff --git a/ansel/lib/View/List.php b/ansel/lib/View/List.php index 459b5c4ca..d83c20905 100644 --- a/ansel/lib/View/List.php +++ b/ansel/lib/View/List.php @@ -158,7 +158,7 @@ class Ansel_View_List extends Ansel_View_Base 'ansel', $this->_owner, '', null, false); $fullname = $uprefs->getValue('grouptitle'); if (!$fullname) { - $identity = Horde_Prefs_Identity::singleton('none', $this->_owner); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($this->_owner); $fullname = $identity->getValue('fullname'); if (!$fullname) { $fullname = $this->_owner; diff --git a/ansel/rss.php b/ansel/rss.php index 3be99289e..f72e0a05b 100644 --- a/ansel/rss.php +++ b/ansel/rss.php @@ -137,7 +137,7 @@ if (empty($rss)) { if (isset($galleries) && count($galleries)) { $images = $ansel_storage->getRecentImages($galleries); if (!is_a($images, 'PEAR_Error') && count($images)) { - $owner = Horde_Prefs_Identity::singleton('none', $id); + $owner = $injector->getInstance('Horde_Prefs_Identity')->getOb($id); $name = $owner->getValue('fullname'); $author = $owner->getValue('from_addr'); if (!$name) { diff --git a/fima/lib/Fima.php b/fima/lib/Fima.php index a2af48763..97de38f65 100644 --- a/fima/lib/Fima.php +++ b/fima/lib/Fima.php @@ -716,7 +716,7 @@ class Fima { /* If the user's personal ledger doesn't exist, then create it. */ if (!$GLOBALS['fima_shares']->exists(Horde_Auth::getAuth())) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (trim($name) == '') { $name = Horde_Auth::getOriginalAuth(); diff --git a/fima/lib/Forms/DeleteLedger.php b/fima/lib/Forms/DeleteLedger.php index 33afa756d..359808cfb 100644 --- a/fima/lib/Forms/DeleteLedger.php +++ b/fima/lib/Forms/DeleteLedger.php @@ -67,7 +67,7 @@ class Fima_DeleteLedgerForm extends Horde_Form { if (count(Fima::listLedgers(true)) == 0) { // If the default share doesn't exist then create it. if (!$GLOBALS['fima_shares']->exists(Horde_Auth::getAuth())) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (trim($name) == '') { $name = Horde_Auth::getOriginalAuth(); diff --git a/folks/lib/Notification.php b/folks/lib/Notification.php index b78d18f39..14517cd81 100644 --- a/folks/lib/Notification.php +++ b/folks/lib/Notification.php @@ -221,7 +221,7 @@ class Folks_Notification { */ protected function _getUserFromAddr($user) { - return Horde_Prefs_Identity::singleton('none', $user)->getValue('from_addr'); + return $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user)->getValue('from_addr'); } /** diff --git a/framework/Alarm/lib/Horde/Alarm.php b/framework/Alarm/lib/Horde/Alarm.php index 7c3cf71cd..8daaf854e 100644 --- a/framework/Alarm/lib/Horde/Alarm.php +++ b/framework/Alarm/lib/Horde/Alarm.php @@ -457,7 +457,7 @@ class Horde_Alarm if (empty($alarm['user'])) { return; } - $identity = Horde_Prefs_Identity::singleton('none', $alarm['user']); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($alarm['user']); $email = $identity->getDefaultFromAddress(true); } else { $email = $alarm['params']['mail']['email']; diff --git a/framework/Core/lib/Horde/Core/Binder/Identity.php b/framework/Core/lib/Horde/Core/Binder/Identity.php new file mode 100644 index 000000000..55167172c --- /dev/null +++ b/framework/Core/lib/Horde/Core/Binder/Identity.php @@ -0,0 +1,17 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ + +/** + * A Horde_Injector:: based Horde_Identity:: factory. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Core + * @author Michael Slusarz + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ +class Horde_Core_Factory_Identity +{ + /** + * Instances. + * + * @var array + */ + private $_instances = array(); + + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Return the Horde_Identity:: instance. + * + * @param string $user The user to use, if not the current user. + * @param string $driver The identity driver. Either empty (use default + * driver) or an application name. + * + * @return Horde_Identity The singleton identity instance. + * @throws Horde_Exception + */ + public function getOb($user = null, $driver = null) + { + $class = empty($driver) + ? 'Horde_Prefs_Identity' + : Horde_String::ucfirst($driver) . '_Prefs_Identity'; + $key = $class . '|' . $user; + + if (!isset($this->_instances[$key])) { + if (!class_exists($class)) { + throw new Horde_Exception('Class definition of ' . $class . ' not found.'); + } + + $params = array( + 'user' => is_null($user) ? Horde_Auth::getAuth() : $user, + ); + + if (isset($GLOBALS['prefs']) && + ($params['user'] == Horde_Auth::getAuth())) { + $params['prefs'] = $GLOBALS['prefs']; + } else { + $params['prefs'] = Horde_Prefs::singleton($GLOBALS['conf']['prefs']['driver'], $GLOBALS['registry']->getApp(), $user, '', null, false); + $params['prefs']->retrieve(); + } + + $this->_instances[$key] = new $class($params); + $this->_instances[$key]->init(); + } + + return $this->_instances[$key]; + } + +} diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui.php b/framework/Core/lib/Horde/Core/Prefs/Ui.php index 57861c546..c513e462e 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui.php @@ -706,7 +706,7 @@ class Horde_Core_Prefs_Ui */ protected function _identityHeader($members) { - $identity = Horde_Prefs_Identity::singleton(($this->app == 'horde') ? null : array($this->app, $this->app)); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(null, $this->app); $default_identity = $identity->getDefault(); $t = $GLOBALS['injector']->createInstance('Horde_Template'); @@ -778,7 +778,7 @@ class Horde_Core_Prefs_Ui { global $conf, $notification, $prefs; - $identity = Horde_Prefs_Identity::singleton(($this->app == 'horde') ? null : array($this->app, $this->app)); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(null, $this->app); if ($this->vars->delete_identity) { $id = intval($this->vars->id); diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 61941f478..9cc536f09 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -244,6 +244,7 @@ class Horde_Registry 'Horde_Memcache' => new Horde_Core_Binder_Memcache(), 'Horde_Notification' => new Horde_Core_Binder_Notification(), 'Horde_Perms' => new Horde_Core_Binder_Perms(), + 'Horde_Prefs_Identity' => new Horde_Core_Binder_Identity(), // 'Horde_Registry' - initialized below 'Horde_Secret' => new Horde_Core_Binder_Secret(), 'Horde_Template' => new Horde_Core_Binder_Template(), diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 59fd59c75..ea946b9ab 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -71,6 +71,7 @@ Application Framework. + @@ -84,6 +85,7 @@ Application Framework. + @@ -218,6 +220,7 @@ Application Framework. + @@ -229,6 +232,7 @@ Application Framework. + diff --git a/framework/Mime/lib/Horde/Mime/Mdn.php b/framework/Mime/lib/Horde/Mime/Mdn.php index 36651768f..6ca3c2982 100644 --- a/framework/Mime/lib/Horde/Mime/Mdn.php +++ b/framework/Mime/lib/Horde/Mime/Mdn.php @@ -141,7 +141,7 @@ class Horde_Mime_Mdn $mod = array(), $err = array()) { /* Set up some variables we use later. */ - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $from_addr = $identity->getDefaultFromAddress(); $to = $this->getMdnReturnAddr(); diff --git a/framework/Prefs/lib/Horde/Prefs/Identity.php b/framework/Prefs/lib/Horde/Prefs/Identity.php index b40795d20..39f771da5 100644 --- a/framework/Prefs/lib/Horde/Prefs/Identity.php +++ b/framework/Prefs/lib/Horde/Prefs/Identity.php @@ -18,13 +18,6 @@ class Horde_Prefs_Identity { /** - * Singleton instances. - * - * @var array - */ - static protected $_instances = array(); - - /** * Array containing all the user's identities. * * @var array @@ -64,30 +57,20 @@ class Horde_Prefs_Identity /** * Constructor. * - * Reads all the user's identities from the prefs object or builds a new - * identity from the standard values given in prefs.php. - * - * @param string $user If specified, we read another user's identities - * instead of the current user. + * @param array $params Parameters: + *
+     * 'prefs' - (Horde_Prefs) [REQUIRED] The prefs object to use.
+     * 'user' - (string) [REQUIRED] The user whose prefs we are handling.
+     * 
*/ - public function __construct($user = null) + public function __construct($params = array()) { - $this->_user = is_null($user) - ? Horde_Auth::getAuth() - : $user; - - if ((is_null($user) || $user == Horde_Auth::getAuth()) && - isset($GLOBALS['prefs'])) { - $this->_prefs = $GLOBALS['prefs']; - } else { - $this->_prefs = Horde_Prefs::singleton($GLOBALS['conf']['prefs']['driver'], $GLOBALS['registry']->getApp(), $user, '', null, false); - $this->_prefs->retrieve(); - } + $this->_prefs = $params['prefs']; + $this->_user = $params['user']; if (!($this->_identities = @unserialize($this->_prefs->getValue('identities', false)))) { - /* Convert identities from the old format. */ - $this->_identities = @unserialize($this->_prefs->getValue('identities')); - } elseif (is_array($this->_identities)) { + $this->_identities = $this->_prefs->getDefault('identities'); + } else { $this->_identities = $this->_prefs->convertFromDriver($this->_identities, Horde_Nls::getCharset()); } @@ -499,79 +482,4 @@ class Horde_Prefs_Identity return array(sprintf(_("The email address %s has been added to your identities. You can close this window now."), $verified['from_addr']), 'horde.success'); } - /** - * Attempts to return a concrete instance based on $type. - * - * @param mixed $driver The type of concrete Identity subclass to return. - * This is based on the storage driver. The code is - * dynamically included. If $type is an array, then - * we will look in $driver[0]/lib/Prefs/Identity/ - * for the subclass implementation named - * $driver[1].php. - * @param string $user If specified, we read another user's identities - * instead of the current user. - * - * @return Horde_Prefs_Identity The newly created instance. - * @throws Horde_Exception - */ - static public function factory($driver = 'None', $user = null) - { - if (is_array($driver)) { - list($app, $driv_name) = $driver; - $driver = basename($driv_name); - } else { - $driver = basename($driver); - } - - /* Return a base Identity object if no driver is specified. */ - if (empty($driver) || (strcasecmp($driver, 'none') == 0)) { - $instance = new self($user); - $instance->init(); - return $instance; - } - - $class = (empty($app) ? 'Horde' : $app) . '_Prefs_Identity'; - - if (class_exists($class)) { - $instance = new $class($user); - $instance->init(); - return $instance; - } - - throw new Horde_Exception('Class definition of ' . $class . ' not found.'); - } - - /** - * Attempts to return a reference to a concrete instance based on - * $type. It will only create a new instance if no instance with - * the same parameters currently exists. - * - * This should be used if multiple types of identities (and, thus, - * multiple instances) are required. - * - * This method must be invoked as: - * $var = Horde_Prefs_Identity::singleton() - * - * @param mixed $type The type of concrete subclass to return. - * This is based on the storage driver ($type). The - * code is dynamically included. If $type is an array, - * then we will look in $type[0]/lib/Prefs/Identity/ - * for the subclass implementation named - * $type[1].php. - * @param string $user If specified, we read another user's identities - * instead of the current user. - * - * @return Horde_Prefs_Identity The concrete reference. - * @throws Horde_Exception - */ - static public function singleton($type = 'None', $user = null) - { - $signature = hash('md5', serialize(array($type, $user))); - if (!isset(self::$_instances[$signature])) { - self::$_instances[$signature] = self::factory($type, $user); - } - - return self::$_instances[$signature]; - } - } diff --git a/framework/Share/Share.php b/framework/Share/Share.php index 8d058fc2a..ca0544d4b 100644 --- a/framework/Share/Share.php +++ b/framework/Share/Share.php @@ -505,7 +505,7 @@ class Horde_Share { } } - return Horde_Prefs_Identity::singleton('none', $share->get('owner')); + return $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($share->get('owner')); } /** diff --git a/horde/admin/user.php b/horde/admin/user.php index b3ec67ae4..a2979361c 100644 --- a/horde/admin/user.php +++ b/horde/admin/user.php @@ -170,7 +170,7 @@ case 'update': $notification->push(sprintf(_("There was a problem updating \"%s\": %s"), $user_name_1, $result->getMessage()), 'horde.error'); } else { - $identity = Horde_Prefs_Identity::singleton('none', $user_name_1); + $identity = $injector->getInstance('Horde_Prefs_Identity')->getOb($user_name_1); $identity->setValue('fullname', $fullname); $identity->setValue('from_addr', $email); $identity->save(); @@ -216,7 +216,7 @@ require HORDE_TEMPLATES . '/common-header.inc'; require HORDE_TEMPLATES . '/admin/menu.inc'; if (isset($update_form) && $auth->hasCapability('list')) { - $identity = Horde_Prefs_Identity::singleton('none', $f_user_name); + $identity = $injector->getInstance('Horde_Prefs_Identity')->getOb($f_user_name); require HORDE_TEMPLATES . '/admin/user/update.inc'; } elseif (isset($remove_form) && $auth->hasCapability('list') && diff --git a/horde/scripts/import_squirrelmail_prefs.php b/horde/scripts/import_squirrelmail_prefs.php index b2b4ea0cd..3caf0359b 100644 --- a/horde/scripts/import_squirrelmail_prefs.php +++ b/horde/scripts/import_squirrelmail_prefs.php @@ -26,7 +26,7 @@ function savePrefs($user, $basename, $prefs_cache) // Import identities if (isset($prefs_cache['identities']) && $prefs_cache['identities'] > 1) { - $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'), $user); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user, 'imp'); // Intentionally off-by-one for ($i = 1; $i < $prefs_cache['identities']; $i++) { $new_identity = array('id' => 'Identity #' . ($i + 1), diff --git a/horde/services/confirm.php b/horde/services/confirm.php index 182e45514..3684b1f88 100644 --- a/horde/services/confirm.php +++ b/horde/services/confirm.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('horde', array('nologintasks' => true)); -$identity = Horde_Prefs_Identity::singleton(); +$identity = $injector->getInstance('Horde_Prefs_Identity')->getOb(); list($message, $type) = $identity->confirmIdentity(Horde_Util::getFormData('h')); $notification->push($message, $type); diff --git a/horde/services/portal/index.php b/horde/services/portal/index.php index f48d76d39..2560216fc 100644 --- a/horde/services/portal/index.php +++ b/horde/services/portal/index.php @@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/../../lib/Application.php'; Horde_Registry::appInit('horde'); // Get full name. -$identity = Horde_Prefs_Identity::singleton(); +$identity = $injector->getInstance('Horde_Prefs_Identity')->getOb(); $fullname = $identity->getValue('fullname'); if (empty($fullname)) { $fullname = Horde_Auth::convertUsername(Horde_Auth::getAuth(), false); diff --git a/horde/services/portal/mobile.php b/horde/services/portal/mobile.php index cd487414f..1e44fac66 100644 --- a/horde/services/portal/mobile.php +++ b/horde/services/portal/mobile.php @@ -13,7 +13,7 @@ require_once dirname(__FILE__) . '/../../lib/Application.php'; Horde_Registry::appInit('horde'); -$identity = Horde_Prefs_Identity::singleton(); +$identity = $injector->getInstance('Horde_Prefs_Identity')->getOb(); $fullname = $identity->getValue('fullname'); if (empty($fullname)) { $fullname = Horde_Auth::getAuth(); diff --git a/horde/services/problem.php b/horde/services/problem.php index 833ece2d1..2559d2983 100644 --- a/horde/services/problem.php +++ b/horde/services/problem.php @@ -23,7 +23,7 @@ if (!Horde_Menu::showService('problem')) { _returnToPage(); } -$identity = Horde_Prefs_Identity::singleton(); +$identity = $injector->getInstance('Horde_Prefs_Identity')->getOb(); $email = $identity->getValue('from_addr'); if (!$email) { $email = Horde_Util::getFormData('email', Horde_Auth::getAuth()); diff --git a/imp/attachment.php b/imp/attachment.php index 767f8d4d6..2f48d18b9 100644 --- a/imp/attachment.php +++ b/imp/attachment.php @@ -74,7 +74,7 @@ if ($conf['compose']['link_attachments_notify']) { $prefs = Horde_Prefs::singleton($conf['prefs']['driver'], 'horde', $mail_user); $prefs->retrieve(); - $mail_identity = Horde_Prefs_Identity::singleton('none', $mail_user); + $mail_identity = $injector->getInstance('Horde_Prefs_Identity')->getOb($mail_user); $mail_address = $mail_identity->getDefaultFromAddress(); /* Ignore missing addresses, which are returned as <>. */ @@ -86,8 +86,8 @@ if ($conf['compose']['link_attachments_notify']) { /* Set up the mail headers and read the log file. */ $msg_headers = new Horde_Mime_Headers(); $msg_headers->addReceivedHeader(array( - 'dns' => $GLOBALS['injector']->getInstance('Net_DNS_Resolver'), - 'server' => $GLOBALS['conf']['server']['name'] + 'dns' => $injector->getInstance('Net_DNS_Resolver'), + 'server' => $conf['server']['name'] )); $msg_headers->addMessageIdHeader(); $msg_headers->addUserAgentHeader(); diff --git a/imp/lib/Injector/Binder/Identity.php b/imp/lib/Injector/Binder/Identity.php index bf91a11a9..30ae14e6c 100644 --- a/imp/lib/Injector/Binder/Identity.php +++ b/imp/lib/Injector/Binder/Identity.php @@ -16,7 +16,7 @@ class IMP_Injector_Binder_Identity implements Horde_Injector_Binder */ public function create(Horde_Injector $injector) { - return Horde_Prefs_Identity::singleton(array('imp', 'imp')); + return $injector->getInstance('Horde_Prefs_Identity')->getOb(null, 'imp'); } /** diff --git a/imp/lib/Prefs/Identity.php b/imp/lib/Prefs/Identity.php index 838a16f1f..71c45274e 100644 --- a/imp/lib/Prefs/Identity.php +++ b/imp/lib/Prefs/Identity.php @@ -33,10 +33,12 @@ class Imp_Prefs_Identity extends Horde_Prefs_Identity /** * Reads all the user's identities from the prefs object or builds * a new identity from the standard values given in prefs.php. + * + * @see Horde_Prefs_Identity::__construct() */ - public function __construct() + public function __construct($params) { - parent::__construct(); + parent::__construct($params); $this->_properties = array_merge( $this->_properties, diff --git a/ingo/lib/Api.php b/ingo/lib/Api.php index 17b9a3d74..e7278d1fd 100644 --- a/ingo/lib/Api.php +++ b/ingo/lib/Api.php @@ -127,7 +127,7 @@ class Ingo_Api extends Horde_Registry_Api /* Make sure we have at least one address. */ if (empty($info['addresses'])) { - $identity = Horde_Prefs_Identity::singleton('none'); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); /* Remove empty lines. */ $info['addresses'] = preg_replace('/\n{2,}/', "\n", implode("\n", $identity->getAll('from_addr'))); if (empty($addresses)) { diff --git a/ingo/lib/Application.php b/ingo/lib/Application.php index 99f021fb9..7a6638b6f 100644 --- a/ingo/lib/Application.php +++ b/ingo/lib/Application.php @@ -70,7 +70,7 @@ class Ingo_Application extends Horde_Registry_Application /* If personal share doesn't exist then create it. */ $signature = $_SESSION['ingo']['backend']['id'] . ':' . Horde_Auth::getAuth(); if (!$GLOBALS['ingo_shares']->exists($signature)) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (trim($name) == '') { $name = Horde_Auth::getOriginalAuth(); diff --git a/ingo/vacation.php b/ingo/vacation.php index 6ffafda7c..ed114058e 100644 --- a/ingo/vacation.php +++ b/ingo/vacation.php @@ -105,7 +105,7 @@ $form->appendButtons(_("Return to Rules List")); /* Make sure we have at least one address. */ if (!$vacation->getVacationAddresses()) { - $identity = Horde_Prefs_Identity::singleton('none'); + $identity = $injector->getInstance('Horde_Prefs_Identity')->getOb(); $addresses = implode("\n", $identity->getAll('from_addr')); /* Remove empty lines. */ $addresses = preg_replace('/\n+/', "\n", $addresses); diff --git a/kronolith/attendees.php b/kronolith/attendees.php index 3e347a27e..0bd8240cd 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -179,7 +179,7 @@ $view = Horde_Util::getFormData('view', 'Day'); // Pre-format our delete image/link. $delimg = Horde::img('delete.png', _("Remove Attendee")); -$ident = Horde_Prefs_Identity::singleton(); +$ident = $injector->getInstance('Horde_Prefs_Identity')->getOb(); $identities = $ident->getAll('id'); $vars = Horde_Variables::getDefaultVariables(); $tabs = new Horde_Ui_Tabs(null, $vars); diff --git a/kronolith/lib/FreeBusy.php b/kronolith/lib/FreeBusy.php index a335c3d9d..5806d4ed5 100644 --- a/kronolith/lib/FreeBusy.php +++ b/kronolith/lib/FreeBusy.php @@ -60,7 +60,7 @@ class Kronolith_FreeBusy } /* Get the Identity for the owner of the share. */ - $identity = Horde_Prefs_Identity::singleton('none', $user ? $user : $owner); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user ? $user : $owner); $email = $identity->getValue('from_addr'); $cn = $identity->getValue('fullname'); if (empty($mail) && empty($cn)) { diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 12556c306..b6f5242d7 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1097,7 +1097,7 @@ class Kronolith if (Horde_Auth::getAuth() && !count($GLOBALS['display_calendars']) && !$GLOBALS['kronolith_shares']->exists(Horde_Auth::getAuth())) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (trim($name) == '') { $name = Horde_Auth::getOriginalAuth(); @@ -1154,7 +1154,7 @@ class Kronolith static $names = array(); if (!isset($names[$uid])) { - $ident = Horde_Prefs_Identity::singleton('none', $uid); + $ident = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($uid); $ident->setDefault($ident->getDefault()); $names[$uid] = $ident->getValue('fullname'); if (empty($names[$uid])) { @@ -1173,7 +1173,7 @@ class Kronolith static $emails = array(); if (!isset($emails[$uid])) { - $ident = Horde_Prefs_Identity::singleton('none', $uid); + $ident = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($uid); $emails[$uid] = $ident->getValue('from_addr'); if (empty($emails[$uid])) { $emails[$uid] = $uid; @@ -1191,7 +1191,7 @@ class Kronolith static $emails = array(); if (!isset($emails[$uid])) { - $ident = Horde_Prefs_Identity::singleton('none', $uid); + $ident = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($uid); $addrs = $ident->getAll('from_addr'); $addrs[] = $uid; @@ -1968,7 +1968,7 @@ class Kronolith return; } - $ident = Horde_Prefs_Identity::singleton('none', $event->creator); + $ident = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($event->creator); $myemail = $ident->getValue('from_addr'); if (!$myemail) { @@ -2122,7 +2122,7 @@ class Kronolith throw new Kronolith_Exception($share); } - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $from = $identity->getDefaultFromAddress(true); $owner = $share->get('owner'); @@ -2158,7 +2158,7 @@ class Kronolith if (!$vals) { continue; } - $identity = Horde_Prefs_Identity::singleton('none', $user); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user); $email = $identity->getValue('from_addr'); if (strpos($email, '@') === false) { continue; diff --git a/kronolith/lib/View/EditEvent.php b/kronolith/lib/View/EditEvent.php index 06e4049b7..f50a58716 100644 --- a/kronolith/lib/View/EditEvent.php +++ b/kronolith/lib/View/EditEvent.php @@ -45,7 +45,7 @@ class Kronolith_View_EditEvent { exit; } - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); if ($this->event->hasPermission(Horde_Perms::EDIT)) { $calendar_id = $this->event->calendar; diff --git a/kronolith/scripts/agenda.php b/kronolith/scripts/agenda.php index 9ab6db40a..5fb3c1259 100755 --- a/kronolith/scripts/agenda.php +++ b/kronolith/scripts/agenda.php @@ -72,7 +72,7 @@ function send_agendas() } // try to find an email address for the user - $identity = Horde_Prefs_Identity::singleton('none', $user); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user); $email = $identity->getValue('from_addr'); if (strstr($email, '@')) { list($mailbox, $host) = explode('@', $email); diff --git a/mnemo/lib/Mnemo.php b/mnemo/lib/Mnemo.php index 51e9a00b4..68f7a921f 100644 --- a/mnemo/lib/Mnemo.php +++ b/mnemo/lib/Mnemo.php @@ -216,7 +216,7 @@ class Mnemo { static $names = array(); if (!isset($names[$uid])) { - $ident = Horde_Prefs_Identity::singleton('none', $uid); + $ident = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($uid); $ident->setDefault($ident->getDefault()); $names[$uid] = $ident->getValue('fullname'); if (empty($names[$uid])) { @@ -443,7 +443,7 @@ class Mnemo { /* If the user's personal notepad doesn't exist, then create it. */ if (!$GLOBALS['mnemo_shares']->exists(Horde_Auth::getAuth())) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (trim($name) == '') { $name = Horde_Auth::removeHook(Horde_Auth::getAuth()); diff --git a/nag/lib/Forms/task.php b/nag/lib/Forms/task.php index 15cb0d7fa..6639838bb 100644 --- a/nag/lib/Forms/task.php +++ b/nag/lib/Forms/task.php @@ -65,7 +65,7 @@ class Nag_TaskForm extends Horde_Form { } if (count($users)) { foreach (array_keys($users) as $user) { - $identity = Horde_Prefs_Identity::singleton('none', $user); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user); $fullname = $identity->getValue('fullname'); $users[$user] = strlen($fullname) ? $fullname : $user; } diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index 66a698ab6..96e1fa614 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -647,7 +647,7 @@ class Nag return ''; } - $identity = Horde_Prefs_Identity::singleton('none', $assignee); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($assignee); $fullname = $identity->getValue('fullname'); if (!strlen($fullname)) { $fullname = $assignee; @@ -720,7 +720,7 @@ class Nag /* If the user's personal tasklist doesn't exist, then create it. */ if (!$GLOBALS['nag_shares']->exists(Horde_Auth::getAuth())) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (trim($name) == '') { $name = Horde_Auth::getOriginalAuth(); @@ -838,7 +838,7 @@ class Nag $groups = Group::singleton(); $recipients = array(); - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $from = $identity->getDefaultFromAddress(true); $owner = $share->get('owner'); @@ -873,7 +873,7 @@ class Nag if (!$vals) { continue; } - $identity = Horde_Prefs_Identity::singleton('none', $user); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user); $email = $identity->getValue('from_addr'); if (strpos($email, '@') === false) { continue; @@ -953,12 +953,12 @@ class Nag $old_task->category, $task->category); } if ($old_task->assignee != $task->assignee) { - $identity = Horde_Prefs_Identity::singleton('none', $old_task->assignee); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($old_task->assignee); $old_name = $identity->getValue('fullname'); if (!strlen($old_name)) { $old_name = $old_task->assignee; } - $identity = Horde_Prefs_Identity::singleton('none', $task->assignee); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($task->assignee); $new_name = $identity->getValue('fullname'); if (!strlen($new_name)) { $new_name = $new_task->assignee; @@ -1050,7 +1050,7 @@ class Nag static $names = array(); if (!isset($names[$uid])) { - $ident = Horde_Prefs_Identity::singleton('none', $uid); + $ident = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($uid); $ident->setDefault($ident->getDefault()); $names[$uid] = $ident->getValue('fullname'); if (empty($names[$uid])) { diff --git a/nag/tasklists/info.php b/nag/tasklists/info.php index ca9782ed8..4fba0d99d 100644 --- a/nag/tasklists/info.php +++ b/nag/tasklists/info.php @@ -23,7 +23,7 @@ $subscribe_url = Horde::url($registry->get('webroot', 'horde') . '/rpc.php/nag/' . ($tasklist->get('owner') ? $tasklist->get('owner') : '') . '/' . $tasklist->getName() . '.ics'; -$identity = Horde_Prefs_Identity::singleton('none', $tasklist->get('owner')); +$identity = $injector->getInstance('Horde_Prefs_Identity')->getOb($tasklist->get('owner')); $owner_name = $identity->getValue('fullname'); if (trim($owner_name) == '') { $owner_name = Horde_Auth::getOriginalAuth(); diff --git a/turba/lib/Driver/Group.php b/turba/lib/Driver/Group.php index 94dcb8a7f..60466043e 100644 --- a/turba/lib/Driver/Group.php +++ b/turba/lib/Driver/Group.php @@ -135,7 +135,7 @@ class Turba_Driver_Group extends Turba_Driver $members = $groups->listAllUsers($this->_gid); $addressbook = array(); foreach ($members as $member) { - $identity = Horde_Prefs_Identity::singleton('none', $member); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($member); $name = $identity->getValue('fullname'); $email = $identity->getValue('from_addr'); // We use the email as the key since we could have multiple users diff --git a/turba/lib/Turba.php b/turba/lib/Turba.php index 1acabc57b..0fadf9789 100644 --- a/turba/lib/Turba.php +++ b/turba/lib/Turba.php @@ -278,7 +278,7 @@ class Turba { static $names = array(); if (!isset($names[$uid])) { - $ident = Horde_Prefs_Identity::singleton('none', $uid); + $ident = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($uid); $ident->setDefault($ident->getDefault()); $names[$uid] = $ident->getValue('fullname'); if (empty($names[$uid])) { @@ -536,7 +536,7 @@ class Turba { { if (!isset($params['name'])) { /* Sensible default for empty display names */ - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (trim($name) == '') { $name = Horde_Auth::getOriginalAuth(); diff --git a/whups/lib/Mail.php b/whups/lib/Mail.php index d2ba67843..1f96b7793 100644 --- a/whups/lib/Mail.php +++ b/whups/lib/Mail.php @@ -214,7 +214,7 @@ class Whups_Mail { if ($auth->hasCapability('list')) { foreach ($auth->listUsers() as $user) { - $identity = Horde_Prefs_Identity::singleton('none', $user); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user); $addrs = $identity->getAll('from_addr'); foreach ($addrs as $addr) { if (strcasecmp($from, $addr) == 0) { diff --git a/whups/lib/Ticket.php b/whups/lib/Ticket.php index 98a8daf22..d3e2cd36d 100644 --- a/whups/lib/Ticket.php +++ b/whups/lib/Ticket.php @@ -726,7 +726,7 @@ class Whups_Ticket { } /* Build message template. */ - $identity = &Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $name = $identity->getValue('fullname'); if (empty($name)) { $name = Horde_Auth::getBareAuth(); diff --git a/whups/lib/Whups.php b/whups/lib/Whups.php index 61a02c8c4..257342a92 100644 --- a/whups/lib/Whups.php +++ b/whups/lib/Whups.php @@ -571,7 +571,7 @@ class Whups { } } catch (Horde_Mime_Exception $e) {} } else { - $identity = &Horde_Prefs_Identity::singleton('none', $user); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($user); $results[$user]['name'] = $identity->getValue('fullname'); $results[$user]['email'] = $identity->getValue('from_addr'); diff --git a/wicked/lib/Page.php b/wicked/lib/Page.php index 0303171f3..afa4c4216 100644 --- a/wicked/lib/Page.php +++ b/wicked/lib/Page.php @@ -257,7 +257,7 @@ class Page { return _("Guest"); } - $identity = &Horde_Prefs_Identity::singleton(null, $modify); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb($modify); $name = $identity->getValue('fullname'); if (!empty($name)) { $modify = $name; diff --git a/wicked/lib/Wicked.php b/wicked/lib/Wicked.php index 63ce341a5..33473fead 100644 --- a/wicked/lib/Wicked.php +++ b/wicked/lib/Wicked.php @@ -160,7 +160,7 @@ class Wicked { $conf['wicked']['guest_address'] : $conf['wicked']['notify_address']; if (Horde_Auth::getAuth()) { - $identity = Horde_Prefs_Identity::singleton(); + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getOb(); $from = $identity->getValue('fullname'); if (empty($from)) { $from = $registry->get('name'); -- 2.11.0