From 9c7d62d47e1353bcb43899f1c843b619ff4c1d45 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 11 Feb 2010 14:16:06 -0700 Subject: [PATCH] Bug #8867: refactor Horde::getServiceLink() for general use, not just menu-related use --- ansel/templates/image/upload.inc | 2 +- framework/Core/lib/Horde.php | 52 ++++---------------------------- framework/Core/lib/Horde/Help.php | 2 +- framework/Core/lib/Horde/Menu.php | 56 +++++++++++++++++++++++++++++++---- horde/services/portal/sidebar.php | 6 ++-- horde/services/problem.php | 2 +- imp/templates/index/index-dimp.inc | 4 +-- kronolith/templates/calendar_info.php | 2 +- 8 files changed, 65 insertions(+), 61 deletions(-) diff --git a/ansel/templates/image/upload.inc b/ansel/templates/image/upload.inc index 1dfcb498c..e83490268 100644 --- a/ansel/templates/image/upload.inc +++ b/ansel/templates/image/upload.inc @@ -3,7 +3,7 @@ renderActive(null, null, 'upload.php', 'post', 'multipart/form-data'); -if ($browser->getPlatform() == 'win' && Horde::showService('help')) { +if ($browser->getPlatform() == 'win' && Horde_Menu::showService('help')) { echo '

' . Horde_Help::link('ansel', 'xppublish') . ' ' . _("Learn how to publish photos directly from Windows.") . '

'; } diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 1b7aaf1dd..ba9cb9326 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -546,31 +546,20 @@ HTML; } /** - * Checks if services link should be shown and returns the necessary code. + * Returns the URL to various Horde services. * - * @param string $type Type of link to display + * @param string $type The service to display. *
-     * The following must be defined in Horde's menu config, or else $override
-     * must be true:
-     * 'help', 'problem', 'logout', 'login', 'options'
-     *
-     * The following are service links only and do not need to be defined
-     * in Horde's menu config.
+     * TODO
      * 'ajax', 'cache', 'download', 'go', 'prefsapi'
+     * 'help', 'problem', 'logout', 'login', 'options'
      * 
* @param string $app The name of the current Horde application. - * @param boolean $override Override Horde settings? * * @return Horde_Url|boolean The HTML to create the link. */ - static public function getServiceLink($type, $app = null, - $override = false) + static public function getServiceLink($type, $app = null) { - if (!in_array($type, array('ajax', 'cache', 'download', 'go', 'prefsapi')) && - !self::showService($type, $override)) { - return false; - } - $webroot = $GLOBALS['registry']->get('webroot', 'horde'); switch ($type) { @@ -761,37 +750,6 @@ HTML; } /** - * TODO - * - * @param string $type The type of link. - * @param boolean $override Override Horde settings? - * - * @return boolean True if the link is to be shown. - */ - static public function showService($type, $override = false) - { - global $conf; - - if (empty($conf['menu']['links'][$type])) { - return false; - } - - switch ($conf['menu']['links'][$type]) { - case 'all': - return true; - - case 'never': - return $override; - - case 'authenticated': - return $override || (bool)Horde_Auth::getAuth(); - - default: - return $override; - } - } - - /** * Loads global and vhost specific configuration files. * * @param string $config_file The name of the configuration file. diff --git a/framework/Core/lib/Horde/Help.php b/framework/Core/lib/Horde/Help.php index 1695b4642..1aa95adf2 100644 --- a/framework/Core/lib/Horde/Help.php +++ b/framework/Core/lib/Horde/Help.php @@ -177,7 +177,7 @@ class Horde_Help */ static public function link($module, $topic) { - if (!Horde::showService('help')) { + if (!Horde_Menu::showService('help')) { return ' '; } diff --git a/framework/Core/lib/Horde/Menu.php b/framework/Core/lib/Horde/Menu.php index 6943b3dd7..1a8c07217 100644 --- a/framework/Core/lib/Horde/Menu.php +++ b/framework/Core/lib/Horde/Menu.php @@ -160,17 +160,23 @@ class Horde_Menu } /* Add settings link. */ - if ($this->_mask & self::MASK_PREFS && $url = Horde::getServiceLink('options', $app)) { + if (($this->_mask & self::MASK_PREFS) && + $this->showService('options') && + ($url = Horde::getServiceLink('options', $app))) { $this->add($url, _("_Options"), 'prefs.png', $graphics); } /* Add problem link. */ - if ($this->_mask & self::MASK_PROBLEM && $problem_link = Horde::getServiceLink('problem', $app)) { + if (($this->_mask & self::MASK_PROBLEM) && + $this->showService('problem') && + ($problem_link = Horde::getServiceLink('problem', $app))) { $this->add($problem_link, _("Problem"), 'problem.png', $graphics); } /* Add help link. */ - if ($this->_mask & self::MASK_HELP && $help_link = Horde::getServiceLink('help', $app)) { + if (($this->_mask & self::MASK_HELP) && + $this->showService('help') && + ($help_link = Horde::getServiceLink('help', $app))) { Horde:: $this->add($help_link, _("Help"), 'help_index.png', $graphics, 'help', Horde::popupJs($help_link, array('urlencode' => true)) . 'return false;', 'helplink'); } @@ -186,11 +192,13 @@ class Horde_Menu } if (Horde_Auth::getAuth()) { - if ($logout_link = Horde::getServiceLink('logout', $app, !$prefs->getValue('show_sidebar'))) { + if ((!$prefs->getValue('show_sidebar') || $this->showService('logout')) && + ($logout_link = Horde::getServiceLink('logout', $app))) { $this->add($logout_link, _("_Log out"), 'logout.png', $graphics, $auth_target, null, '__noselection'); } } else { - if ($login_link = Horde::getServiceLink('login', $app)) { + if ($this->showService('login') && + ($login_link = Horde::getServiceLink('login', $app))) { $this->add(Horde_Util::addParameter($login_link, array('url' => Horde::selfUrl(true, true, true))), _("_Log in"), 'login.png', $graphics, $auth_target, null, '__noselection'); } } @@ -322,4 +330,42 @@ class Horde_Menu return false; } + /** + * TODO + * + * @param string $type The type of link. + *
+     * The following must be defined in Horde's menu config, or else they
+     * won't be displayed in the menu:
+     * 'help', 'problem', 'logout', 'login', 'options'
+     * 
+ * @param boolean $override Override Horde settings? + * + * @return boolean True if the link is to be shown. + */ + static public function showService($type) + { + global $conf; + + if (!in_array($type, array('help', 'problem', 'logout', 'login', 'options'))) { + return true; + } + + if (empty($conf['menu']['links'][$type])) { + return false; + } + + switch ($conf['menu']['links'][$type]) { + case 'all': + return true; + + case 'authenticated': + return (bool)Horde_Auth::getAuth(); + + default: + case 'never': + return false; + } + } + } diff --git a/horde/services/portal/sidebar.php b/horde/services/portal/sidebar.php index db1728aa5..96be19072 100644 --- a/horde/services/portal/sidebar.php +++ b/horde/services/portal/sidebar.php @@ -136,7 +136,7 @@ function buildMenu() } catch (Horde_Exception $e) {} } - if (Horde::showService('options') && + if (Horde_Menu::showService('options') && $conf['prefs']['driver'] != '' && $conf['prefs']['driver'] != 'none') { $menu['options'] = array('name' => _("Options"), 'status' => 'active', @@ -190,13 +190,13 @@ function buildMenu() $menu['logout'] = array('name' => _("Log out"), 'status' => 'active', 'icon' => $registry->getImageDir() . '/logout.png', - 'url' => Horde::getServiceLink('logout', 'horde', true), + 'url' => Horde::getServiceLink('logout', 'horde'), 'target' => '_parent'); } else { $menu['login'] = array('name' => _("Log in"), 'status' => 'active', 'icon' => $registry->getImageDir() . '/login.png', - 'url' => Horde::getServiceLink('login', 'horde', true, false)); + 'url' => Horde::getServiceLink('login', 'horde')); } return $menu; diff --git a/horde/services/problem.php b/horde/services/problem.php index 84462b4d1..4a068eb07 100644 --- a/horde/services/problem.php +++ b/horde/services/problem.php @@ -19,7 +19,7 @@ function _returnToPage() require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('horde', array('authentication' => 'none')); -if (!Horde::showService('problem')) { +if (!Horde_Menu::showService('problem')) { _returnToPage(); } diff --git a/imp/templates/index/index-dimp.inc b/imp/templates/index/index-dimp.inc index 2c0567ed5..183482cf4 100644 --- a/imp/templates/index/index-dimp.inc +++ b/imp/templates/index/index-dimp.inc @@ -59,10 +59,10 @@ function _simpleButton($id, $text, $image, $nodisplay = false) get('status', 'horde') != 'hidden') && ($registry->get('status', 'horde') != 'notoolbar')): ?> - + - + diff --git a/kronolith/templates/calendar_info.php b/kronolith/templates/calendar_info.php index 71fc545ec..bcded016f 100644 --- a/kronolith/templates/calendar_info.php +++ b/kronolith/templates/calendar_info.php @@ -34,7 +34,7 @@

getName())); ?>

-' . Horde_Help::link('kronolith', 'embed') . ' ' . _("Learn how to embed other calendar views.") . '

'; } ?> -- 2.11.0