Bug #8867: refactor Horde::getServiceLink() for general use, not just menu-related use
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 11 Feb 2010 21:16:06 +0000 (14:16 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 11 Feb 2010 21:16:06 +0000 (14:16 -0700)
ansel/templates/image/upload.inc
framework/Core/lib/Horde.php
framework/Core/lib/Horde/Help.php
framework/Core/lib/Horde/Menu.php
horde/services/portal/sidebar.php
horde/services/problem.php
imp/templates/index/index-dimp.inc
kronolith/templates/calendar_info.php

index 1dfcb49..e834902 100644 (file)
@@ -3,7 +3,7 @@
 <tr><td style="vertical-align:top;padding:0;">
 <?php
 $form->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 '<div class="box" style="margin:8px; padding:8px"><h3>' . Horde_Help::link('ansel', 'xppublish') . ' ' . _("Learn how to publish photos directly from Windows.") . '</h3></div>';
 }
 
index 1b7aaf1..ba9cb93 100644 (file)
@@ -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.
      * <pre>
-     * 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'
      * </pre>
      * @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.
index 1695b46..1aa95ad 100644 (file)
@@ -177,7 +177,7 @@ class Horde_Help
      */
     static public function link($module, $topic)
     {
-        if (!Horde::showService('help')) {
+        if (!Horde_Menu::showService('help')) {
             return '&nbsp;';
         }
 
index 6943b3d..1a8c072 100644 (file)
@@ -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.
+     * <pre>
+     * 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'
+     * </pre>
+     * @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;
+        }
+    }
+
 }
index db1728a..96be190 100644 (file)
@@ -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;
index 84462b4..4a068eb 100644 (file)
@@ -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();
 }
 
index 2c0567e..183482c 100644 (file)
@@ -59,10 +59,10 @@ function _simpleButton($id, $text, $image, $nodisplay = false)
 <?php if (($registry->get('status', 'horde') != 'hidden') && ($registry->get('status', 'horde') != 'notoolbar')): ?>
     <?php echo _simpleButton('appportal', _("_Portal"), 'hordeIcon') ?>
 <?php endif; ?>
-<?php if (Horde::showService('options')): ?>
+<?php if (Horde_Menu::showService('options')): ?>
     <?php echo _simpleButton('appoptions', _("_Options"), 'prefsIcon') ?>
 <?php endif; ?>
-<?php if (Horde::showService('logout')): ?>
+<?php if (Horde_Menu::showService('logout')): ?>
     <?php echo _simpleButton('applogout', _("_Log Out"), 'logoutIcon') ?>
 <?php endif; ?>
    </ul>
index 71fc545..bcded01 100644 (file)
@@ -34,7 +34,7 @@
 <p class="calendar-info-url">
 <?php echo htmlspecialchars(Kronolith::embedCode($calendar->getName())); ?>
 </p>
-<?php if (Horde::showService('help')) {
+<?php if (Horde_Menu::showService('help')) {
     echo '<p>' . Horde_Help::link('kronolith', 'embed') . ' ' . _("Learn how to embed other calendar views.") . '</p>';
 } ?>
 <?php endif; ?>