From: Ben Klang Date: Mon, 22 Feb 2010 02:40:08 +0000 (-0500) Subject: Beatnik: Update to new H_R_A initialization X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=82ba9c5a9a2b9b6e01659406ce46ebc5e388e782;p=horde.git Beatnik: Update to new H_R_A initialization --- diff --git a/beatnik/autogenerate.php b/beatnik/autogenerate.php index 504a78a05..ad5bc0ef1 100644 --- a/beatnik/autogenerate.php +++ b/beatnik/autogenerate.php @@ -10,8 +10,9 @@ * @author Duck */ -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'); diff --git a/beatnik/commit.php b/beatnik/commit.php index b0004bb00..23768b850 100644 --- a/beatnik/commit.php +++ b/beatnik/commit.php @@ -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'); } diff --git a/beatnik/delete.php b/beatnik/delete.php index d975d4a66..0c426c091 100644 --- a/beatnik/delete.php +++ b/beatnik/delete.php @@ -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)); diff --git a/beatnik/editrec.php b/beatnik/editrec.php index 11f5d988f..e1afc6d50 100644 --- a/beatnik/editrec.php +++ b/beatnik/editrec.php @@ -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'); } diff --git a/beatnik/lib/Application.php b/beatnik/lib/Application.php index 0cffe8eff..d93d74ea7 100644 --- a/beatnik/lib/Application.php +++ b/beatnik/lib/Application.php @@ -1,12 +1,82 @@ * @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']; } diff --git a/beatnik/lib/Beatnik.php b/beatnik/lib/Beatnik.php index 5e412a30d..99166e127 100644 --- a/beatnik/lib/Beatnik.php +++ b/beatnik/lib/Beatnik.php @@ -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'); } diff --git a/beatnik/lib/Exception.php b/beatnik/lib/Exception.php index 56ff59ecc..bf2efcd4d 100644 --- a/beatnik/lib/Exception.php +++ b/beatnik/lib/Exception.php @@ -1 +1 @@ -class Beatnik_Exception extends Horde_Exception {} \ No newline at end of file + - * - * 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 - * @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(); -} - diff --git a/beatnik/listzones.php b/beatnik/listzones.php index 68451c7b3..432ab375f 100644 --- a/beatnik/listzones.php +++ b/beatnik/listzones.php @@ -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'); diff --git a/beatnik/viewzone.php b/beatnik/viewzone.php index eceac13b9..f55eee730 100644 --- a/beatnik/viewzone.php +++ b/beatnik/viewzone.php @@ -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'));