From: Michael M Slusarz Date: Wed, 20 Jan 2010 06:26:46 +0000 (-0700) Subject: Convert Shout to updated Horde_Registry_Application usage X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a3246513d90ed33b0248fe26ff0ddac1866d8637;p=horde.git Convert Shout to updated Horde_Registry_Application usage --- diff --git a/shout/ajax.php b/shout/ajax.php index bc7b9d725..cf0a4e171 100644 --- a/shout/ajax.php +++ b/shout/ajax.php @@ -13,10 +13,9 @@ * @package Shout */ -// Need to load Horde_Util:: to give us access to Horde_Util::getPathInfo(). require_once dirname(__FILE__) . '/lib/Application.php'; -$action = Horde_Util::getFormData('action'); +$action = Horde_Util::getFormData('action'); if (empty($action)) { // This is the only case where we really don't return anything, since // the frontend can be presumed not to make this request on purpose. @@ -25,7 +24,7 @@ if (empty($action)) { } try { - $shout = new Shout_Application(array('init' => true)); + $shout = Horde_Registry::appInit('shout', array('authentication' => 'throw')); } catch (Horde_Exception $e) { /* Handle session timeouts when they come from an AJAX request. */ if (($e->getCode() == Horde_Registry::AUTH_FAILURE) && diff --git a/shout/devices.php b/shout/devices.php index 198e6fe32..7dc827edd 100644 --- a/shout/devices.php +++ b/shout/devices.php @@ -8,13 +8,13 @@ * * @author Ben Klang */ -require_once dirname(__FILE__) . '/lib/Application.php'; -$shout = new Shout_Application(array('init' => true)); -$context = $_SESSION['shout']['context']; +require_once dirname(__FILE__) . '/lib/Application.php'; +$shout = Horde_Registry::appInit('shout'); require_once SHOUT_BASE . '/lib/Forms/DeviceForm.php'; +$context = $_SESSION['shout']['context']; $action = Horde_Util::getFormData('action'); $vars = Horde_Variables::getDefaultVariables(); diff --git a/shout/extensions.php b/shout/extensions.php index a63a6a5a2..8e69baaf0 100644 --- a/shout/extensions.php +++ b/shout/extensions.php @@ -8,14 +8,14 @@ * * @author Ben Klang */ -require_once dirname(__FILE__) . '/lib/Application.php'; -$shout = new Shout_Application(array('init' => true)); -$context = $_SESSION['shout']['context']; +require_once dirname(__FILE__) . '/lib/Application.php'; +$shout = Horde_Registry::appInit('shout'); require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php'; $action = Horde_Util::getFormData('action'); +$context = $_SESSION['shout']['context']; //$tabs = Shout::getTabs($context, $vars); diff --git a/shout/index.php b/shout/index.php index 7eb250dde..8491e14bb 100644 --- a/shout/index.php +++ b/shout/index.php @@ -8,9 +8,5 @@ * * @author Ben Klang */ -// Will redirect to login page if not authenticated. -require_once dirname(__FILE__) . '/lib/Application.php'; -new Shout_Application(); -// Load initial page as defined by view mode & preferences. -require 'extensions.php'; +require dirname(__FILE__) . '/extensions.php'; diff --git a/shout/lib/Application.php b/shout/lib/Application.php index 7a4ec9676..210996198 100644 --- a/shout/lib/Application.php +++ b/shout/lib/Application.php @@ -2,17 +2,19 @@ /** * Shout application interface. * - * This file defines Shout's application interface. + * This file defines Horde's core API interface. Other core Horde libraries + * can interact with Shout through this API. * * Copyright 2006-2010 Alkaloid Networks (http://projects.alkaloid.net/) * * See the enclosed file LICENSE for license information (BSD). If you did not * did not receive this file, see * http://www.opensource.org/licenses/bsd-license.html. - * + * * @author Ben Klang * @package Shout */ + if (!defined('SHOUT_BASE')) { define('SHOUT_BASE', dirname(__FILE__). '/..'); } @@ -33,76 +35,79 @@ require_once HORDE_BASE . '/lib/core.php'; class Shout_Application extends Horde_Registry_Application { + /** + * The application's version. + * + * @var string + */ public $version = 'H4 (1.0-git)'; + + /** + * TODO + */ public $contexts = null; + + /** + * TODO + */ public $extensions = null; + + /** + * TODO + */ public $devices = null; - public function __construct($args = array()) + /** + * TODO + */ + static protected $_perms = array(); + + /** + * Initialization function. + * + * Global variables defined: + */ + protected function _init() { - if (!empty($args['init'])) { - $GLOBALS['registry'] = &Horde_Registry::singleton(); - $registry = &$GLOBALS['registry']; - try { - $registry->pushApp('shout'); - } catch (Horde_Exception $e) { - if ($e->getCode() == 'permission_denied') { - Horde::authenticationFailureRedirect(); - } - Horde::fatal($e, __FILE__, __LINE__, false); - } - $conf = &$GLOBALS['conf']; - - // Notification system. - $GLOBALS['notification'] = &Horde_Notification::singleton(); - $notification = &$GLOBALS['notification']; - $notification->attach('status'); - - define('SHOUT_TEMPLATES', $registry->get('templates')); - - $this->contexts = Shout_Driver::factory('storage'); - $this->extensions = Shout_Driver::factory('extensions'); - $this->devices = Shout_Driver::factory('devices'); - - try { - $contexts = $this->contexts->getContexts(); - } catch (Shout_Exception $e) { - $notification->push($e); - $contexts = false; - } - - if (count($contexts) == 1) { - // Default to the user's only context - if (!empty($context) && $context != $contexts[0]) { - $notification->push(_("You do not have permission to access that context."), 'horde.error'); - } - $context = $contexts[0]; - } elseif (!empty($context) && !in_array($context, $contexts)) { - $notification->push(_("You do not have permission to access that context."), 'horde.error'); - $context = false; - } elseif (!empty($context)) { - $notification->push("Please select a context to continue.", 'horde.info'); - $context = false; - } + $this->contexts = Shout_Driver::factory('storage'); + $this->extensions = Shout_Driver::factory('extensions'); + $this->devices = Shout_Driver::factory('devices'); + + try { + $contexts = $this->contexts->getContexts(); + } catch (Shout_Exception $e) { + $GLOBALS['notification']->push($e); + $contexts = false; + } - $_SESSION['shout']['context'] = $context; - - /* Start compression. */ - if (!Horde_Util::nonInputVar('no_compress')) { - Horde::compressOutput(); + if (count($contexts) == 1) { + // Default to the user's only context + if (!empty($context) && $context != $contexts[0]) { + $GLOBALS['notification']->push(_("You do not have permission to access that context."), 'horde.error'); } + $context = $contexts[0]; + } elseif (!empty($context) && !in_array($context, $contexts)) { + $GLOBALS['notification']->push(_("You do not have permission to access that context."), 'horde.error'); + $context = false; + } elseif (!empty($context)) { + $GLOBALS['notification']->push("Please select a context to continue.", 'horde.info'); + $context = false; } + + $_SESSION['shout']['context'] = $context; } + /** + * TODO + */ public function perms() { - static $perms = array(); - if (!empty($perms)) { - return $perms; + if (!empty(self::$_perms)) { + return self::$_perms; } - $perms['tree']['shout']['superadmin'] = false; - $perms['title']['shout:superadmin'] = _("Super Administrator"); + self::$_perms['tree']['shout']['superadmin'] = false; + self::$_perms['title']['shout:superadmin'] = _("Super Administrator"); if (empty($this->contexts)) { $this->__construct(array('init' => true)); @@ -110,13 +115,13 @@ class Shout_Application extends Horde_Registry_Application $contexts = $this->contexts->getContexts(); - $perms['tree']['shout']['contexts'] = false; - $perms['title']['shout:contexts'] = _("Contexts"); + self::$_perms['tree']['shout']['contexts'] = false; + self::$_perms['title']['shout:contexts'] = _("Contexts"); // Run through every contact source. foreach ($contexts as $context) { - $perms['tree']['shout']['contexts'][$context] = false; - $perms['title']['shout:contexts:' . $context] = $context; + self::$_perms['tree']['shout']['contexts'][$context] = false; + self::$_perms['title']['shout:contexts:' . $context] = $context; foreach( array( @@ -125,11 +130,12 @@ class Shout_Application extends Horde_Registry_Application 'conferences' => 'Conference Rooms', ) as $module => $modname) { - $perms['tree']['shout']['contexts'][$context][$module] = false; - $perms['title']["shout:contexts:$context:$module"] = $modname; + self::$_perms['tree']['shout']['contexts'][$context][$module] = false; + self::$_perms['title']["shout:contexts:$context:$module"] = $modname; } } - return $perms; + return self::$_perms; } + }