From: Michael M Slusarz Date: Mon, 20 Dec 2010 18:52:37 +0000 (-0700) Subject: Cleanup registry.php.dist file X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8c5b14dc83ec38cb27890f847afae2da80b618c0;p=horde.git Cleanup registry.php.dist file Format remains the same, so no need to alter current config file. But offers the following improvements: Use one array to eliminate duplicative/confusing $this->applications[] instances scattered throughout. 'status' no longer required; defaults to 'active'. 'fileroot' and 'webroot' no longer required; defaults to HORDE_BASE and web auto-detection respectively. Move web auto-detection into Horde_Registry. If auto-detection doesn't work for an admin, it makes more sense for them to just enter the proper webroot rather than trying to tweak the detection function. Additionally, registry.php can now be loaded multiple times in an access - since the registry needs to be completely rebuilt for things like a forced config change or langauge switch. Thus, this prevents the need for a function_exists() check. Add optional variables to allow for definition of app fileroot/webroot if different than Horde's. Very useful for dev's - no need to hardcode fileroot values for each application if using links. --- diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index d18f4b660..900a2fef8 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -510,6 +510,7 @@ class Horde_Registry if (!file_exists(HORDE_BASE . '/config/registry.php')) { throw new Horde_Exception('Missing registry.php configuration file'); } + require HORDE_BASE . '/config/registry.php'; $files = glob(HORDE_BASE . '/config/registry.d/*.php'); foreach ($files as $r) { @@ -520,27 +521,47 @@ class Horde_Registry include $this->_vhost; } + if (!isset($this->applications['horde']['fileroot'])) { + $this->applications['horde']['fileroot'] = HORDE_BASE; + } + if (!isset($app_fileroot)) { + $app_fileroot = $this->applications['horde']['fileroot']; + } + + if (!isset($this->applications['horde']['webroot'])) { + $this->applications['horde']['webroot'] = $this->_detectWebroot(); + } + if (!isset($app_webroot)) { + $app_webroot = $this->applications['horde']['webroot']; + } + /* Scan for all APIs provided by each app, and set other common * defaults like templates and graphics. */ foreach (array_keys($this->applications) as $appName) { $app = &$this->applications[$appName]; - if ($app['status'] == 'heading') { + + if (!isset($app['status'])) { + $app['status'] = 'active'; + } elseif ($app['status'] == 'heading') { continue; } - if (isset($app['fileroot'])) { - $app['fileroot'] = rtrim($app['fileroot'], ' /'); - if (!file_exists($app['fileroot']) || - (file_exists($app['fileroot'] . '/config/conf.xml') && - !file_exists($app['fileroot'] . '/config/conf.php'))) { - $app['status'] = 'inactive'; - Horde::logMessage('Setting ' . $appName . ' inactive because the fileroot does not exist or the application is not configured yet.', 'DEBUG'); - } + $app['fileroot'] = isset($app['fileroot']) + ? rtrim($app['fileroot'], ' /') + : $app_fileroot . '/' . $appName; + + if (!isset($app['name'])) { + $app['name'] = ''; + } elseif (!file_exists($app['fileroot']) || + (file_exists($app['fileroot'] . '/config/conf.xml') && + !file_exists($app['fileroot'] . '/config/conf.php'))) { + $app['status'] = 'inactive'; + Horde::logMessage('Setting ' . $appName . ' inactive because the fileroot does not exist or the application is not configured yet.', 'DEBUG'); } - if (isset($app['webroot'])) { - $app['webroot'] = rtrim($app['webroot'], ' /'); - } + $app['webroot'] = isset($app['webroot']) + ? rtrim($app['webroot'], ' /') + : $app_webroot . '/' . $appName; if (($app['status'] != 'inactive') && isset($app['provides']) && @@ -578,6 +599,40 @@ class Horde_Registry } /** + * Attempt to auto-detect the Horde webroot. + * + * @return string The webroot. + */ + protected function _detectWebroot() + { + // Note for Windows: the below assumes the PHP_SELF variable uses + // forward slashes. + if (isset($_SERVER['SCRIPT_URL']) || isset($_SERVER['SCRIPT_NAME'])) { + $path = empty($_SERVER['SCRIPT_URL']) + ? $_SERVER['SCRIPT_NAME'] + : $_SERVER['SCRIPT_URL']; + $hordedir = basename(str_replace(DIRECTORY_SEPARATOR, '/', realpath(HORDE_BASE))); + return (preg_match(';/' . $hordedir . ';', $path)) + ? preg_replace(';/' . $hordedir . '.*;', '/' . $hordedir, $path) + : ''; + } + + if (!isset($_SERVER['PHP_SELF'])) { + return '/horde'; + } + + $webroot = preg_split(';/;', $_SERVER['PHP_SELF'], 2, PREG_SPLIT_NO_EMPTY); + $webroot = strstr(realpath(HORDE_BASE), DIRECTORY_SEPARATOR . array_shift($webroot)); + if ($webroot !== false) { + return preg_replace(array('/\\\\/', ';/config$;'), array('/', ''), $webroot); + } + + return ($webroot === false) + ? '' + : '/horde'; + } + + /** * Load the list of available external services. * * @throws Horde_Exception diff --git a/horde/config/registry.php.dist b/horde/config/registry.php.dist index 971980019..127f63d84 100644 --- a/horde/config/registry.php.dist +++ b/horde/config/registry.php.dist @@ -1,53 +1,43 @@ applications['horde'] = array( - 'fileroot' => dirname(__FILE__) . '/..', - 'webroot' => _detect_webroot(), - 'initial_page' => 'services/portal/index.php', - 'name' => _("Horde"), - 'status' => 'active', - 'templates' => dirname(__FILE__) . '/../templates', - 'provides' => 'horde', -); - -$this->applications['imp'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/imp', - 'webroot' => $this->applications['horde']['webroot'] . '/imp', - 'name' => _("Mail"), - 'status' => 'active', - 'provides' => array('mail', 'contacts/favouriteRecipients') -); - -$this->applications['ingo'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/ingo', - 'webroot' => $this->applications['horde']['webroot'] . '/ingo', - 'name' => _("Filters"), - 'status' => 'active', - 'provides' => array('filter', 'mail/blacklistFrom', 'mail/showBlacklist', 'mail/whitelistFrom', 'mail/showWhitelist', 'mail/applyFilters', 'mail/canApplyFilters', 'mail/showFilters'), - 'menu_parent' => 'imp' -); - -$this->applications['sam'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/sam', - 'webroot' => $this->applications['horde']['webroot'] . '/sam', - 'name' => _("Spam"), - 'status' => 'active', - // Uncomment this line if you want Sam to handle the blacklist filter - // instead of Ingo: - // 'provides' => array('mail/blacklistFrom', 'mail/showBlacklist', 'mail/whitelistFrom', 'mail/showWhitelist'), - 'menu_parent' => 'imp' -); - -$this->applications['forwards'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/forwards', - 'webroot' => $this->applications['horde']['webroot'] . '/forwards', - 'name' => _("Forwards"), - 'status' => 'active', - 'provides' => 'forwards', - 'menu_parent' => 'imp', -); +// By default, applications are assumed to live within the base Horde +// directory (e.g. their fileroot/webroot will be automatically determined +// by appending the application name to Horde's 'fileroot'/'webroot' setting. +// If your applications live in a different base directory, defining these +// variables will change the default directory without the need to change +// every application's 'fileroot'/'webroot' settings. +// $app_fileroot = dirname(__FILE__) . '../'; +// $app_webroot = $this->_detectWebroot(); + +$this->applications = array( + 'horde' => array( + 'initial_page' => 'services/portal/index.php', + 'name' => _("Horde"), + 'provides' => 'horde', + ), -$this->applications['vacation'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/vacation', - 'webroot' => $this->applications['horde']['webroot'] . '/vacation', - 'name' => _("Vacation"), - 'status' => 'active', - 'provides' => 'vacation', - 'menu_parent' => 'imp' -); + 'imp' => array( + 'name' => _("Mail"), + 'provides' => array( + 'mail', + 'contacts/favouriteRecipients' + ) + ), -$this->applications['imp-menu'] = array( - 'status' => 'sidebar', - 'app' => 'imp', - 'menu_parent' => 'imp', -); + 'ingo' => array( + 'name' => _("Filters"), + 'provides' => array( + 'filter', + 'mail/blacklistFrom', + 'mail/showBlacklist', + 'mail/whitelistFrom', + 'mail/showWhitelist', + 'mail/applyFilters', + 'mail/canApplyFilters', + 'mail/showFilters' + ), + 'menu_parent' => 'imp' + ), -$this->applications['organizing'] = array( - 'name' => _("Organizing"), - 'status' => 'heading', -); + 'imp-menu' => array( + 'app' => 'imp', + 'menu_parent' => 'imp', + 'status' => 'sidebar', + ), -$this->applications['turba'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/turba', - 'webroot' => $this->applications['horde']['webroot'] . '/turba', - 'name' => _("Address Book"), - 'status' => 'active', - 'provides' => array('contacts', 'clients/getClientSource', 'clients/clientFields', 'clients/getClient', 'clients/getClients', 'clients/addClient', 'clients/updateClient', 'clients/deleteClient', 'clients/searchClients'), - 'menu_parent' => 'organizing' -); + 'organizing' => array( + 'name' => _("Organizing"), + 'status' => 'heading', + ), -$this->applications['turba-menu'] = array( - 'status' => 'sidebar', - 'app' => 'turba', - 'menu_parent' => 'turba', -); + 'turba' => array( + 'name' => _("Address Book"), + 'provides' => array( + 'contacts', + 'clients/getClientSource', + 'clients/clientFields', + 'clients/getClient', + 'clients/getClients', + 'clients/addClient', + 'clients/updateClient', + 'clients/deleteClient', + 'clients/searchClients' + ), + 'menu_parent' => 'organizing' + ), -$this->applications['kronolith'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/kronolith', - 'webroot' => $this->applications['horde']['webroot'] . '/kronolith', - 'name' => _("Calendar"), - 'status' => 'active', - 'provides' => 'calendar', - 'menu_parent' => 'organizing' -); + 'turba-menu' => array( + 'app' => 'turba', + 'menu_parent' => 'turba', + 'status' => 'sidebar', + ), -$this->applications['kronolith-alarms'] = array( - 'status' => 'sidebar', - 'app' => 'kronolith', - 'sidebar_params' => array( - 'id' => 'alarms' + 'kronolith' => array( + 'name' => _("Calendar"), + 'provides' => 'calendar', + 'menu_parent' => 'organizing' ), - 'menu_parent' => 'kronolith', -); -$this->applications['kronolith-menu'] = array( - 'status' => 'sidebar', - 'app' => 'kronolith', - 'sidebar_params' => array( - 'id' => 'menu' + 'kronolith-alarms' => array( + 'status' => 'sidebar', + 'app' => 'kronolith', + 'sidebar_params' => array( + 'id' => 'alarms' + ), + 'menu_parent' => 'kronolith', ), - 'menu_parent' => 'kronolith', -); -$this->applications['nag'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/nag', - 'webroot' => $this->applications['horde']['webroot'] . '/nag', - 'name' => _("Tasks"), - 'status' => 'active', - 'provides' => 'tasks', - 'menu_parent' => 'organizing' -); + 'kronolith-menu' => array( + 'status' => 'sidebar', + 'app' => 'kronolith', + 'sidebar_params' => array( + 'id' => 'menu' + ), + 'menu_parent' => 'kronolith', + ), -$this->applications['nag-alarms'] = array( - 'status' => 'sidebar', - 'app' => 'nag', - 'sidebar_params' => array( - 'id' => 'alarms' + 'nag' => array( + 'name' => _("Tasks"), + 'provides' => 'tasks', + 'menu_parent' => 'organizing' ), - 'menu_parent' => 'nag', -); -$this->applications['nag-menu'] = array( - 'status' => 'sidebar', - 'app' => 'nag', - 'sidebar_params' => array( - 'id' => 'menu' + 'nag-alarms' => array( + 'status' => 'sidebar', + 'app' => 'nag', + 'sidebar_params' => array( + 'id' => 'alarms' + ), + 'menu_parent' => 'nag', ), - 'menu_parent' => 'nag', -); -$this->applications['mnemo'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/mnemo', - 'webroot' => $this->applications['horde']['webroot'] . '/mnemo', - 'name' => _("Notes"), - 'status' => 'active', - 'provides' => 'notes', - 'menu_parent' => 'organizing' -); + 'nag-menu' => array( + 'status' => 'sidebar', + 'app' => 'nag', + 'sidebar_params' => array( + 'id' => 'menu' + ), + 'menu_parent' => 'nag', + ), -$this->applications['mnemo-menu'] = array( - 'status' => 'sidebar', - 'app' => 'mnemo', - 'menu_parent' => 'mnemo', -); + 'mnemo' => array( + 'name' => _("Notes"), + 'provides' => 'notes', + 'menu_parent' => 'organizing' + ), -$this->applications['trean'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/trean', - 'webroot' => $this->applications['horde']['webroot'] . '/trean', - 'name' => _("Bookmarks"), - 'status' => 'active', - 'provides' => 'bookmarks', - 'menu_parent' => 'organizing' -); + 'mnemo-menu' => array( + 'status' => 'sidebar', + 'app' => 'mnemo', + 'menu_parent' => 'mnemo', + ), -$this->applications['trean-menu'] = array( - 'status' => 'sidebar', - 'app' => 'trean', - 'menu_parent' => 'trean', -); + 'trean' => array( + 'name' => _("Bookmarks"), + 'provides' => 'bookmarks', + 'menu_parent' => 'organizing' + ), -$this->applications['devel'] = array( - 'name' => _("Development"), - 'status' => 'heading', -); + 'trean-menu' => array( + 'status' => 'sidebar', + 'app' => 'trean', + 'menu_parent' => 'trean', + ), -$this->applications['chora'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/chora', - 'webroot' => $this->applications['horde']['webroot'] . '/chora', - 'name' => _("Version Control"), - 'status' => 'active', - 'menu_parent' => 'devel' -); + 'devel' => array( + 'name' => _("Development"), + 'status' => 'heading', + ), -$this->applications['chora-menu'] = array( - 'status' => 'sidebar', - 'app' => 'chora', - 'menu_parent' => 'chora', -); + 'chora' => array( + 'name' => _("Version Control"), + 'menu_parent' => 'devel' + ), -$this->applications['whups'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/whups', - 'webroot' => $this->applications['horde']['webroot'] . '/whups', - 'name' => _("Tickets"), - 'status' => 'active', - 'provides' => 'tickets', - 'menu_parent' => 'devel', -); + 'chora-menu' => array( + 'status' => 'sidebar', + 'app' => 'chora', + 'menu_parent' => 'chora', + ), -$this->applications['whups-menu'] = array( - 'status' => 'sidebar', - 'app' => 'whups', - 'menu_parent' => 'whups', -); + 'whups' => array( + 'name' => _("Tickets"), + 'provides' => 'tickets', + 'menu_parent' => 'devel', + ), -$this->applications['luxor'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/luxor', - 'webroot' => $this->applications['horde']['webroot'] . '/luxor', - 'name' => _("X-Ref"), - 'status' => 'active', - 'menu_parent' => 'devel' -); + 'whups-menu' => array( + 'status' => 'sidebar', + 'app' => 'whups', + 'menu_parent' => 'whups', + ), -$this->applications['info'] = array( - 'name' => _("Information"), - 'status' => 'heading', -); + 'luxor' => array( + 'name' => _("X-Ref"), + 'menu_parent' => 'devel' + ), -$this->applications['jonah'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/jonah', - 'webroot' => $this->applications['horde']['webroot'] . '/jonah', - 'name' => _("News"), - 'status' => 'active', - 'provides' => 'news', - 'menu_parent' => 'info' -); + 'info' => array( + 'name' => _("Information"), + 'status' => 'heading', + ), -$this->applications['jonah-menu'] = array( - 'status' => 'sidebar', - 'app' => 'jonah', - 'menu_parent' => 'jonah', -); + 'jonah' => array( + 'name' => _("News"), + 'provides' => 'news', + 'menu_parent' => 'info' + ), -$this->applications['office'] = array( - 'name' => _("Office"), - 'status' => 'heading', -); + 'jonah-menu' => array( + 'status' => 'sidebar', + 'app' => 'jonah', + 'menu_parent' => 'jonah', + ), -$this->applications['hermes'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/hermes', - 'webroot' => $this->applications['horde']['webroot'] . '/hermes', - 'name' => _("Time Tracking"), - 'status' => 'active', - 'menu_parent' => 'office', - 'provides' => 'time' -); + 'office' => array( + 'name' => _("Office"), + 'status' => 'heading', + ), -$this->applications['hermes-stopwatch'] = array( - 'status' => 'sidebar', - 'app' => 'hermes', - 'sidebar_params' => array( - 'id' => 'stopwatch', + 'hermes' => array( + 'name' => _("Time Tracking"), + 'menu_parent' => 'office', + 'provides' => 'time' ), - 'menu_parent' => 'hermes', -); -$this->applications['hermes-menu'] = array( - 'status' => 'sidebar', - 'app' => 'hermes', - 'sidebar_params' => array( - 'id' => 'menu' + 'hermes-stopwatch' => array( + 'status' => 'sidebar', + 'app' => 'hermes', + 'sidebar_params' => array( + 'id' => 'stopwatch', + ), + 'menu_parent' => 'hermes', ), - 'menu_parent' => 'hermes', -); -$this->applications['myaccount'] = array( - 'name' => _("My Account"), - 'status' => 'heading', -); + 'hermes-menu' => array( + 'status' => 'sidebar', + 'app' => 'hermes', + 'sidebar_params' => array( + 'id' => 'menu' + ), + 'menu_parent' => 'hermes', + ), -$this->applications['gollem'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/gollem', - 'webroot' => $this->applications['horde']['webroot'] . '/gollem', - 'name' => _("File Manager"), - 'status' => 'active', - 'menu_parent' => 'myaccount', - 'provides' => 'files', -); + 'myaccount' => array( + 'name' => _("My Account"), + 'status' => 'heading', + ), -$this->applications['gollem-menu'] = array( - 'status' => 'sidebar', - 'app' => 'gollem', - 'menu_parent' => 'gollem', -); + 'gollem' => array( + 'name' => _("File Manager"), + 'menu_parent' => 'myaccount', + 'provides' => 'files', + ), -$this->applications['passwd'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/passwd', - 'webroot' => $this->applications['horde']['webroot'] . '/passwd', - 'name' => _("Password"), - 'status' => 'active', - 'menu_parent' => 'myaccount' -); + 'gollem-menu' => array( + 'status' => 'sidebar', + 'app' => 'gollem', + 'menu_parent' => 'gollem', + ), -$this->applications['jeta'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/jeta', - 'webroot' => $this->applications['horde']['webroot'] . '/jeta', - 'name' => _("SSH"), - 'status' => 'active', - 'menu_parent' => 'myaccount' -); + 'passwd' => array( + 'name' => _("Password"), + 'menu_parent' => 'myaccount' + ), -$this->applications['website'] = array( - 'name' => _("Web Site"), - 'status' => 'heading', -); + 'website' => array( + 'name' => _("Web Site"), + 'status' => 'heading', + ), -$this->applications['agora'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/agora', - 'webroot' => $this->applications['horde']['webroot'] . '/agora', - 'name' => _("Forums"), - 'status' => 'active', - 'provides' => 'forums', - 'menu_parent' => 'website' -); + 'agora' => array( + 'name' => _("Forums"), + 'provides' => 'forums', + 'menu_parent' => 'website' + ), -$this->applications['ansel'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/ansel', - 'webroot' => $this->applications['horde']['webroot'] . '/ansel', - 'name' => _("Photos"), - 'status' => 'active', - 'provides' => 'images', - 'menu_parent' => 'website' -); + 'ansel' => array( + 'name' => _("Photos"), + 'provides' => 'images', + 'menu_parent' => 'website' + ), -$this->applications['wicked'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/wicked', - 'webroot' => $this->applications['horde']['webroot'] . '/wicked', - 'name' => _("Wiki"), - 'status' => 'active', - 'provides' => 'wiki', - 'menu_parent' => 'website' -); + 'wicked' => array( + 'name' => _("Wiki"), + 'provides' => 'wiki', + 'menu_parent' => 'website' + ), -$this->applications['vilma'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/vilma', - 'webroot' => $this->applications['horde']['webroot'] . '/vilma', - 'name' => _("Mail Admin"), - 'status' => 'active', - 'menu_parent' => 'administration' -); + 'vilma' => array( + 'name' => _("Mail Admin"), + 'menu_parent' => 'administration' + ), -$this->applications['content'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/content', - 'status' => 'hidden' -); + 'content' => array( + 'status' => 'hidden' + ), -$this->applications['timeobjects'] = array( - 'fileroot' => $this->applications['horde']['fileroot'] . '/timeobjects', - 'status' => 'hidden' + 'timeobjects' => array( + 'status' => 'hidden' + ) ); - -function _detect_webroot() -{ - // Note for Windows users: the below assumes that your PHP_SELF variable - // uses forward slashes. If it does not, you'll have to tweak this. - if (isset($_SERVER['SCRIPT_URL']) || isset($_SERVER['SCRIPT_NAME'])) { - $path = empty($_SERVER['SCRIPT_URL']) ? - $_SERVER['SCRIPT_NAME'] : - $_SERVER['SCRIPT_URL']; - $hordedir = str_replace(DIRECTORY_SEPARATOR, '/', __FILE__); - $hordedir = basename(preg_replace(';/config/registry.php$;', '', $hordedir)); - if (preg_match(';/' . $hordedir . ';', $path)) { - $webroot = preg_replace(';/' . $hordedir . '.*;', '/' . $hordedir, $path); - } else { - $webroot = ''; - } - } elseif (isset($_SERVER['PHP_SELF'])) { - $webroot = preg_split(';/;', $_SERVER['PHP_SELF'], 2, PREG_SPLIT_NO_EMPTY); - $webroot = strstr(dirname(__FILE__), DIRECTORY_SEPARATOR . array_shift($webroot)); - if ($webroot !== false) { - $webroot = preg_replace(array('/\\\\/', ';/config$;'), array('/', ''), $webroot); - } elseif ($webroot === false) { - $webroot = ''; - } else { - $webroot = '/horde'; - } - } else { - $webroot = '/horde'; - } - - return $webroot; -}