Beatnik: Update to new H_R_A initialization
authorBen Klang <ben@alkaloid.net>
Mon, 22 Feb 2010 02:40:08 +0000 (21:40 -0500)
committerBen Klang <ben@alkaloid.net>
Mon, 22 Feb 2010 02:40:08 +0000 (21:40 -0500)
beatnik/autogenerate.php
beatnik/commit.php
beatnik/delete.php
beatnik/editrec.php
beatnik/lib/Application.php
beatnik/lib/Beatnik.php
beatnik/lib/Exception.php
beatnik/lib/base.php [deleted file]
beatnik/listzones.php
beatnik/viewzone.php

index 504a78a..ad5bc0e 100644 (file)
@@ -10,8 +10,9 @@
  * @author Duck <duck@obala.net>
  */
 
-define('BEATNIK_BASE', dirname(__FILE__));
-require_once BEATNIK_BASE . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+$beatnik = Horde_Registry::appInit('beatnik');
+
 require_once BEATNIK_BASE . '/lib/Forms/Autogenerate.php';
 
 $viewurl = Horde::applicationUrl('viewzone.php');
index b0004bb..23768b8 100644 (file)
@@ -6,8 +6,9 @@
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */
 
-define('BEATNIK_BASE', dirname(__FILE__));
-require_once BEATNIK_BASE . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+$beatnik = Horde_Registry::appInit('beatnik');
+
 require_once BEATNIK_BASE . '/lib/Forms/EditRecord.php';
 
 $domains = array();
@@ -17,7 +18,7 @@ if (Horde_Util::getGet('domain') == 'current') {
 } elseif (Horde_Util::getGet('domain') == 'all') {
     $url = Horde::applicationUrl('listzones.php');
     foreach (Beatnik::needCommit() as $domain) {
-        $domains[] = $beatnik_driver->getDomain($domain);
+        $domains[] = $beatnik->driver->getDomain($domain);
     }
 }
 
@@ -38,7 +39,7 @@ foreach ($domains as $domain) {
         $form->getInfo($vars, $info);
 
         try {
-            $result = $beatnik_driver->saveRecord($info);
+            $result = $beatnik->driver->saveRecord($info);
         } catch (Exception $e) {
             $notification->push($e->getMessage(), 'horde.error');
         }
index d975d4a..0c426c0 100644 (file)
@@ -8,12 +8,13 @@
  * did not receive this file, see http://cvs.horde.org/co.php/merk/LICENSE.
  */
 
-define('BEATNIK_BASE', dirname(__FILE__));
-require_once BEATNIK_BASE . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+$beatnik = Horde_Registry::appInit('beatnik');
+
 require_once BEATNIK_BASE . '/lib/Forms/DeleteRecord.php';
 
 $vars = Horde_Variables::getDefaultVariables();
-list($type, $record) = $beatnik_driver->getRecord(Horde_Util::getFormData('id'));
+list($type, $record) = $beatnik->driver->getRecord(Horde_Util::getFormData('id'));
 
 $form = new DeleteRecord($vars);
 
@@ -21,7 +22,7 @@ if ($form->validate($vars)) {
     $form->getInfo($vars, $info);
     if (Horde_Util::getFormData('submitbutton') == _("Delete")) {
         try {
-            $result = $beatnik_driver->deleteRecord($info);
+            $result = $beatnik->driver->deleteRecord($info);
         } catch (Exception $e) {
             $notification->push($e->getMessage(), 'horde.error');
             header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('viewzone.php'), $info));
index 11f5d98..e1afc6d 100644 (file)
@@ -6,13 +6,14 @@
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */
 
-define('BEATNIK_BASE', dirname(__FILE__));
-require_once BEATNIK_BASE . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+$beatnik = Horde_Registry::appInit('beatnik');
+
 require_once BEATNIK_BASE . '/lib/Forms/EditRecord.php';
 
 $vars = Horde_Variables::getDefaultVariables();
 $url = Horde::applicationUrl('editrec.php');
-list($type, $record) = $beatnik_driver->getRecord(Horde_Util::getFormData('id'));
+list($type, $record) = $beatnik->driver->getRecord(Horde_Util::getFormData('id'));
 
 $form = new EditRecord($vars);
 
@@ -20,7 +21,7 @@ if ($form->validate($vars)) {
     $form->getInfo($vars, $info);
 
     try {
-        $result = $beatnik_driver->saveRecord($info);
+        $result = $beatnik->driver->saveRecord($info);
     } catch (Exception $e) {
         $notification->push($e->getMessage(), 'horde.error');
     }
index 0cffe8e..d93d74e 100644 (file)
@@ -1,12 +1,82 @@
 <?php
 /**
- * Beatnik application API.
+ * Beatnik application interface.
  *
+ * This file defines Horde's application interface. Other Horde libraries
+ * and applications can interact with Beatnik through this API.
+ *
+ * Copyright 2006-2010 Alkaloid Networks, LLC (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 <ben@alkaloid.net>
  * @package Beatnik
  */
+
+if (!defined('BEATNIK_BASE')) {
+    define('BEATNIK_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(BEATNIK_BASE. '/config/horde.local.php')) {
+        include BEATNIK_BASE . '/config/horde.local.php';
+    } else {
+        define('HORDE_BASE', BEATNIK_BASE . '/..');
+    }
+}
+
+/* Load the Horde Framework core (needed to autoload
+ * Horde_Registry_Application::). */
+require_once HORDE_BASE . '/lib/core.php';
+
+
 class Beatnik_Application extends Horde_Registry_Application
 {
     public $version = 'H4 (1.0-git)';
+    public $driver = null;
+    public $domains = null;
+
+    function _init()
+    {
+        $this->driver = Beatnik_Driver::factory();
+
+        // Get a list of domains to work with
+        $this->domains = $this->driver->getDomains();
+
+        // Jump to new domain
+        if (Horde_Util::getFormData('curdomain') !== null && !empty($this->domains)) {
+            try {
+                $domain = $this->driver->getDomain(Horde_Util::getFormData('curdomain'));
+            } catch (Exception $e) {
+                $notification->push($e->getMessage(), 'horde.error');
+                $domain = $domains[0];
+            }
+
+            $_SESSION['beatnik']['curdomain'] = $domain;
+        }
+
+        // Determine if the user should see basic or advanced options
+        if (!isset($_SESSION['beatnik']['expertmode'])) {
+            $_SESSION['beatnik']['expertmode'] = false;
+        } elseif (Horde_Util::getFormData('expertmode') == 'toggle') {
+            if ($_SESSION['beatnik']['expertmode']) {
+                $notification->push(_('Expert Mode off'), 'horde.message');
+                $_SESSION['beatnik']['expertmode'] = false;
+            } else {
+                $notification->push(_('Expert Mode ON'), 'horde.warning');
+                $_SESSION['beatnik']['expertmode'] = true;
+            }
+        }
+
+        // Initialize the page marker
+        if (!isset($_SESSION['beatnik']['curpage'])) {
+            $_SESSION['beatnik']['curpage'] = 0;
+        }
+    }
 
     /**
      * Returns a list of available permissions.
@@ -26,7 +96,7 @@ class Beatnik_Application extends Horde_Registry_Application
     $perms['title']['beatnik:domains'] = _("Domains");
 
     // Run through every domain
-    foreach ($GLOBALS['beatnik_driver']->getDomains() as $domain) {
+    foreach ($beatnik->driver->getDomains() as $domain) {
         $perms['tree']['beatnik']['domains'][$domain['zonename']] = false;
         $perms['title']['beatnik:domains:' . $domain['zonename']] = $domain['zonename'];
     }
index 5e412a3..99166e1 100644 (file)
@@ -66,7 +66,7 @@ class Beatnik {
             'txt' => _("TXT (Text Record)"),
         );
 
-        return array_merge($records, $GLOBALS['beatnik_driver']->getRecDriverTypes());
+        return array_merge($records, $beatnik->driver->getRecDriverTypes());
     }
 
     /**
@@ -88,6 +88,8 @@ class Beatnik {
         // 'default': the default value of the field.
         // 'index': Crude sort ordering.  Lower means show higher in the group
 
+        global $beatnik;
+
         // Attempt to return cached results.
         static $recset = array();
 
@@ -375,7 +377,7 @@ class Beatnik {
             'default' => $GLOBALS['prefs']->getValue('default_ttl')
         );
 
-        $recset[$recordtype] = array_merge($recset[$recordtype], $GLOBALS['beatnik_driver']->getRecDriverFields($recordtype));
+        //$recset[$recordtype] = array_merge($recset[$recordtype], $beatnik->driver->getRecDriverFields($recordtype));
         uasort($recset[$recordtype], array('Beatnik', 'fieldSort'));
 
         return $recset[$recordtype];
@@ -484,11 +486,12 @@ class Beatnik {
      */
     function autogenerate(&$vars)
     {
+        global $beatnik;
 
         require BEATNIK_BASE . '/config/autogenerate.php';
         $template = $templates[$vars->get('template')];
         try {
-            $zonedata = $GLOBALS['beatnik_driver']->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
+            $zonedata = $beatnik->driver->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
         } catch (Exception $e) {
             $GLOBALS['notification']->push($e);
         }
@@ -501,7 +504,7 @@ class Beatnik {
                 case 'all':
                     foreach ($zonedata[$rectype] as $record) {
                         try {
-                        $result = $GLOBALS['beatnik_driver']->deleteRecord($record);
+                        $result = $beatnik->driver->deleteRecord($record);
                         } catch (Exception $e) {
                             $GLOBALS['notification']->push($e);
                         }
@@ -515,7 +518,7 @@ class Beatnik {
                         foreach ($definitions['records'] as $Trecord) {
                             if ($record['hostname'] == $Trecord['hostname']) {
                                 try {
-                                    $result = $GLOBALS['beatnik_driver']->deleteRecord($record);
+                                    $result = $beatnik->driver->deleteRecord($record);
                                 } catch (Exception $e) {
                                     $GLOBALS['notification']->push($e);
                                 }
@@ -532,12 +535,12 @@ class Beatnik {
             $defaults = array('rectype' => $rectype,
                               'zonename'=> $_SESSION['beatnik']['curdomain']['zonename']);
             foreach ($definitions['records'] as $info) {
-                if ($GLOBALS['beatnik_driver']->recordExists($info, $rectype)) {
+                if ($beatnik->driver->recordExists($info, $rectype)) {
                     $GLOBALS['notification']->push(_("Skipping existing identical record"));
                     continue;
                 }
                 try {
-                    $result = $GLOBALS['beatnik_driver']->saveRecord(array_merge($defaults, $info));
+                    $result = $beatnik->driver->saveRecord(array_merge($defaults, $info));
                 } catch (Exception $e) {
                     $GLOBALS['notification']->push($result->getMessage() . ': ' . $result->getDebugInfo(), 'horde.error');
                 }
index 56ff59e..bf2efcd 100644 (file)
@@ -1 +1 @@
-class Beatnik_Exception extends Horde_Exception {}
\ No newline at end of file
+<?php class Beatnik_Exception extends Horde_Exception {}
\ No newline at end of file
diff --git a/beatnik/lib/base.php b/beatnik/lib/base.php
deleted file mode 100644 (file)
index d17e49a..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-/**
- * Beatnik base inclusion file.
- *
- * Copyright 2005-2007 Alkaloid Networks <http://www.alkaloid.net>
- *
- * This file brings in all of the dependencies that every Beatnik
- * script will need and sets up objects that all scripts use.
- *
- * @author Ben Klang <ben@alkaloid.net>
- * @package Beatnik
- */
-
-// Check for a prior definition of HORDE_BASE (perhaps by an
-// auto_prepend_file definition for site customization).
-if (!defined('HORDE_BASE')) {
-    define('HORDE_BASE', dirname(__FILE__) . '/../..');
-}
-// Load the Horde Framework core, and set up inclusion paths.
-require_once HORDE_BASE . '/lib/core.php';
-
-// Registry.
-$registry = new Horde_Registry();
-
-try {
-    $registry->pushApp('beatnik', array('check_perms' => (Horde_Util::nonInputVar('beatnik_authentication') != 'none')));
-} catch (Horde_Exception $e) {
-    if ($e->getCode() == Horde_Registry::PERMISSION_DENIED) {
-        Horde_Auth::authenticateFailure('beatnik', $e);
-    }
-    Horde::fatal($e, __FILE__, __LINE__, false);
-}
-
-$conf = &$GLOBALS['conf'];
-define('BEATNIK_TEMPLATES', $registry->get('templates'));
-
-// Find the base file path of Beatnik.
-if (!defined('BEATNIK_BASE')) {
-    define('BEATNIK_BASE', dirname(__FILE__) . '/..');
-}
-
-// Beatnik base libraries.
-require_once BEATNIK_BASE . '/lib/Beatnik.php';
-require_once BEATNIK_BASE . '/lib/Driver.php';
-
-try {
-    $GLOBALS['beatnik_driver'] = Beatnik_Driver::factory();
-} catch (Exception $e) {
-    Horde::fatal($e, __FILE__, __LINE__);
-}
-
-// Get a list of domains to work with
-$domains = $GLOBALS['beatnik_driver']->getDomains();
-
-// Jump to new domain
-if (Horde_Util::getFormData('curdomain') !== null && !empty($domains)) {
-    try {
-        $domain = $GLOBALS['beatnik_driver']->getDomain(Horde_Util::getFormData('curdomain'));
-    } catch (Exception $e) {
-        $notification->push($e->getMessage(), 'horde.error');
-        $domain = $domains[0];
-    }
-
-    $_SESSION['beatnik']['curdomain'] = $domain;
-}
-
-// Determine if the user should see basic or advanced options
-if (!isset($_SESSION['beatnik']['expertmode'])) {
-    $_SESSION['beatnik']['expertmode'] = false;
-} elseif (Horde_Util::getFormData('expertmode') == 'toggle') {
-    if ($_SESSION['beatnik']['expertmode']) {
-        $notification->push(_('Expert Mode off'), 'horde.message');
-        $_SESSION['beatnik']['expertmode'] = false;
-    } else {
-        $notification->push(_('Expert Mode ON'), 'horde.warning');
-        $_SESSION['beatnik']['expertmode'] = true;
-    }
-}
-
-// Initialize the page marker
-if (!isset($_SESSION['beatnik']['curpage'])) {
-    $_SESSION['beatnik']['curpage'] = 0;
-}
-
-// Start output compression.
-if (!Horde_Util::nonInputVar('no_compress')) {
-    Horde::compressOutput();
-}
-
index 68451c7..432ab37 100644 (file)
@@ -6,7 +6,8 @@
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+$beatnik = Horde_Registry::appInit('beatnik');
 
 // Unset the current domain since we are generating a zone list
 $_SESSION['beatnik']['curdomain'] = null;
@@ -27,13 +28,13 @@ $pager_vars = Horde_Variables::getDefaultVariables();
 $pager_vars->set('page', $page);
 $perpage = $prefs->getValue('domains_perpage');
 $pager = new Horde_Ui_Pager('page', $pager_vars,
-                            array('num' => count($domains),
+                            array('num' => count($beatnik->domains),
                                   'url' => 'listzones.php',
                                   'page_count' => 10,
                                   'perpage' => $perpage));
 
 // Limit the domain list to the current page
-$domains = array_slice($domains, $page*$perpage, $perpage);
+$domains = array_slice($beatnik->domains, $page*$perpage, $perpage);
 
 $img_dir = $registry->getImageDir('horde');
 
index eceac13..f55eee7 100644 (file)
@@ -6,12 +6,11 @@
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */
 
-define('BEATNIK_BASE', dirname(__FILE__));
-require_once BEATNIK_BASE . '/lib/base.php';
-require_once BEATNIK_BASE . '/lib/Beatnik.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+$beatnik = Horde_Registry::appInit('beatnik');
 
 try {
-    $zonedata = $beatnik_driver->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
+    $zonedata = $beatnik->driver->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
 } catch (Exception $e) {
     $notification->push($e, 'horde.error');
     header('Location:' . Horde::applicationUrl('listzones.php'));