Shout: Convert base.php to Application.php
authorBen Klang <ben@alkaloid.net>
Sun, 3 Jan 2010 03:39:39 +0000 (22:39 -0500)
committerBen Klang <ben@alkaloid.net>
Sun, 3 Jan 2010 03:39:39 +0000 (22:39 -0500)
shout/devices.php
shout/extensions.php
shout/lib/Application.php
shout/lib/Forms/ExtensionForm.php
shout/lib/base.php [deleted file]

index 3a2ec55..5133c4f 100644 (file)
@@ -8,8 +8,11 @@
  *
  * @author  Ben Klang <ben@alkaloid.net>
  */
-@define('SHOUT_BASE', dirname(__FILE__));
-require_once SHOUT_BASE . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+
+$shout = new Shout_Application(array('init' => true));
+$context = $_SESSION['shout']['context'];
+
 require_once SHOUT_BASE . '/lib/Forms/DeviceForm.php';
 
 $action = Horde_Util::getFormData('action');
@@ -50,7 +53,7 @@ case 'edit':
 
     // Create a new add/edit form
     $devid = Horde_Util::getFormData('devid');
-    $devices = $shout_devices->getDevices($context);
+    $devices = $shout->devices->getDevices($context);
     $vars = new Horde_Variables($devices[$devid]);
 
     $vars->set('action', $action);
@@ -96,7 +99,7 @@ default:
 }
 
 // Fetch the (possibly updated) list of extensions
-$devices = $shout_devices->getDevices($context);
+$devices = $shout->devices->getDevices($context);
 
 Horde::addScriptFile('stripe.js', 'horde');
 require SHOUT_TEMPLATES . '/common-header.inc';
index 48a7f73..821e06a 100644 (file)
@@ -8,10 +8,12 @@
  *
  * @author  Ben Klang <ben@alkaloid.net>
  */
-@define('SHOUT_BASE', dirname(__FILE__));
-require_once SHOUT_BASE . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+
+$shout = new Shout_Application(array('init' => true));
+$context = $_SESSION['shout']['context'];
+
 require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php';
-//require_once SHOUT_BASE . '/lib/Shout.php';
 
 $action = Horde_Util::getFormData('action');
 
@@ -48,7 +50,7 @@ case 'edit':
 
     // Create a new add/edit form
     $extension = Horde_Util::getFormData('extension');
-    $extensions = $shout_extensions->getExtensions($context);
+    $extensions = $shout->extensions->getExtensions($context);
     $vars = new Horde_Variables($extensions[$extension]);
     if ($action == 'edit') {
         $vars->set('oldextension', $extension);
@@ -98,7 +100,7 @@ default:
 }
 
 // Fetch the (possibly updated) list of extensions
-$extensions = $shout_extensions->getExtensions($context);
+$extensions = $shout->extensions->getExtensions($context);
 
 Horde::addScriptFile('stripe.js', 'horde');
 require SHOUT_TEMPLATES . '/common-header.inc';
index 069c8ba..a7353e9 100644 (file)
  * @author  Ben Klang <ben@alkaloid.net>
  * @package Shout
  */
-define('SHOUT_BASE', dirname(__FILE__) . '/..');
+if (!defined('SHOUT_BASE')) {
+    define('SHOUT_BASE', dirname(__FILE__). '/..');
+}
+
+if (!defined('HORDE_BASE')) {
+    /* If horde does not live directly under the app directory, the HORDE_BASE
+     * constant should be defined in config/horde.local.php. */
+    if (file_exists(SHOUT_BASE. '/config/horde.local.php')) {
+        include SHOUT_BASE . '/config/horde.local.php';
+    } else {
+        define('HORDE_BASE', SHOUT_BASE . '/..');
+    }
+}
+
+/* Load the Horde Framework core (needed to autoload
+ * Horde_Registry_Application::). */
+require_once HORDE_BASE . '/lib/core.php';
 
 class Shout_Application extends Horde_Registry_Application
 {
     public $version = 'H4 (1.0-git)';
-    protected $_contexts = null;
-    protected $_extensions = null;
-    protected $_devices = null;
+    public $contexts = null;
+    public $extensions = null;
+    public $devices = null;
 
     public function __construct($args = array())
     {
+        if (!empty($args['init'])) {
+            $GLOBALS['registry'] = &Horde_Registry::singleton();
+            $registry = &$GLOBALS['registry'];
+            try {
+                $registry->pushApp('shout', array('check_perms' => true,
+                                                             'logintasks' => true));
+            } catch (Horde_Exception $e) {
+                Horde::authenticationFailure('shout', $e);
+            }
+
+            // Ensure Shout is properly configured before use
+            $shout_configured = (@is_readable(SHOUT_BASE . '/config/conf.php'));
+            if (!$shout_configured) {
+                Horde_Test::configFilesMissing('Shout', SHOUT_BASE, array('conf.php'));
+            }
+
+            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;
+            }
+
+            $notification = Horde_Notification::singleton();
+            $GLOBALS['notification'] = $notification;
+            $notification->attach('status');
+
+            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;
+            }
+
+            $_SESSION['shout']['context'] = $context;
+        }
     }
 
     public function perms()
@@ -35,12 +99,11 @@ class Shout_Application extends Horde_Registry_Application
         }
         
         require_once dirname(__FILE__) . '/base.php';
-        $shout_contexts = Shout_Driver::factory('storage');
 
         $perms['tree']['shout']['superadmin'] = false;
         $perms['title']['shout:superadmin'] = _("Super Administrator");
 
-        $contexts = $shout_contexts->getContexts();
+        $contexts = $this->contexts->getContexts();
 
         $perms['tree']['shout']['contexts'] = false;
         $perms['title']['shout:contexts'] = _("Contexts");
@@ -62,9 +125,6 @@ class Shout_Application extends Horde_Registry_Application
             }
         }
 
-    //     function _shout_getContexts($searchfilters = SHOUT_CONTEXT_ALL,
-    //                          $filterperms = null)
-
         return $perms;
     }
 }
index 20da7a8..b633ad2 100644 (file)
@@ -17,13 +17,13 @@ class ExtensionDetailsForm extends Horde_Form {
     /**
      * ExtensionDetailsForm constructor.
      *
-     * @global <type> $shout_extensions
+     * @global <type> $shout->extensions
      * @param <type> $vars
      * @return <type>
      */
     function __construct(&$vars)
     {
-        global $shout_extensions;
+        global $shout;
 
         $context = $_SESSION['shout']['context'];
         $action = $vars->get('action');
@@ -52,11 +52,11 @@ class ExtensionDetailsForm extends Horde_Form {
      * Process this form, saving its information to the backend.
      *
      * @param string $context  Context in which to execute this save
-     * FIXME: is there a better way to get the $context and $shout_extensions?
+     * FIXME: is there a better way to get the $context and $shout->extensions?
      */
     function execute()
     {
-        global $shout_extensions;
+        global $shout;
 
         $extension = $this->_vars->get('extension');
         $context = $this->_vars->get('context');
@@ -70,7 +70,7 @@ class ExtensionDetailsForm extends Horde_Form {
             'mailboxpin' => $this->_vars->get('mailboxpin'),
             );
 
-        $shout_extensions->saveExtension($context, $extension, $details);
+        $shout->extensions->saveExtension($context, $extension, $details);
     }
 
 }
@@ -94,9 +94,9 @@ class ExtensionDeleteForm extends Horde_Form
 
     function execute()
     {
-        global $shout_extensions;
+        global $shout;
         $context = $this->_vars->get('context');
         $extension = $this->_vars->get('extension');
-        $shout_extensions->deleteExtension($context, $extension);
+        $shout->extensions->deleteExtension($context, $extension);
     }
 }
diff --git a/shout/lib/base.php b/shout/lib/base.php
deleted file mode 100644 (file)
index d3e2737..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-<?php
-/**
- * Shout base inclusion file.
- *
- * Copyright 2005-2010 Alkaloid Networks LLC (http://projects.alkaloid.net)
- *
- * See the enclosed file COPYING for license information (BSD). If you
- * did not receive this file, see
- * http://www.opensource.org/licenses/bsd-license.php.
- *
- * @author  Ben Klang <ben@alkaloid.net>
- * @since   Shout 0.1
- * @package Shout
- */
-
-if (!defined('SHOUT_BASE')) {
-    define('SHOUT_BASE', dirname(__FILE__). '/..');
-}
-
-if (!defined('HORDE_BASE')) {
-    /* If horde does not live directly under the app directory, the HORDE_BASE
-     * constant should be defined in config/horde.local.php. */
-    if (file_exists(SHOUT_BASE. '/config/horde.local.php')) {
-        include SHOUT_BASE . '/config/horde.local.php';
-    } else {
-        define('HORDE_BASE', SHOUT_BASE . '/..');
-    }
-}
-
-// Load the Horde Framework core, and set up inclusion paths.
-require_once HORDE_BASE . '/lib/core.php';
-
-$registry = &Horde_Registry::singleton();
-try {
-    $registry->pushApp('shout', array('check_perms' => true, 'logintasks' => true));
-} catch (Horde_Exception $e) {
-    Horde::authenticationFailureRedirect('shout', $e);
-}
-
-$conf = &$GLOBALS['conf'];
-@define('SHOUT_TEMPLATES', $registry->get('templates'));
-
-// Ensure Shout is properly configured before use
-$shout_configured = (@is_readable(SHOUT_BASE . '/config/conf.php'));
-if (!$shout_configured) {
-    Horde_Test::configFilesMissing('Shout', SHOUT_BASE, array('conf.php'));
-}
-
-$notification = Horde_Notification::singleton();
-$notification->attach('status');
-
-//// Shout base libraries.
-//require_once SHOUT_BASE . '/lib/Shout.php';
-//require_once SHOUT_BASE . '/lib/Driver.php';
-//
-//// Form libraries.
-//require_once 'Horde/Form.php';
-//require_once 'Horde/Form/Renderer.php';
-//
-//// Variable handling libraries
-//require_once 'Horde/Variables.php';
-//require_once 'Horde/Text/Filter.php';
-//
-//// UI classes.
-//require_once 'Horde/UI/Tabs.php';
-
-$shout_contexts = Shout_Driver::factory('storage');
-$shout_extensions = Shout_Driver::factory('extensions');
-$shout_devices = Shout_Driver::factory('devices');
-
-$context = Horde_Util::getFormData('context');
-$section = Horde_Util::getFormData('section');
-
-try {
-    $contexts = $shout_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;
-}
-
-$_SESSION['shout']['context'] = $context;