From 8c5982998d22e7511767b7e2fb907044b07fc3ab Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Thu, 3 Dec 2009 16:17:46 +0100 Subject: [PATCH] Add Horde_Url#link(). More Horde_Url usage. --- framework/Core/lib/Horde.php | 47 +++++++++++++++++++---------------------- framework/Url/lib/Horde/Url.php | 29 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index b6c83a392..caa911e93 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -544,7 +544,7 @@ HTML; * @param string $app The name of the current Horde application. * @param boolean $override Override Horde settings? * - * @return string The HTML to create the link. + * @return Horde_Url|boolean The HTML to create the link. */ static public function getServiceLink($type, $app, $override = false) { @@ -557,11 +557,11 @@ HTML; switch ($type) { case 'help': - return Horde_Util::addParameter(self::url($webroot . '/services/help/'), array('module' => $app)); + return self::url($webroot . '/services/help/')->add('module', $app); case 'problem': - $url = self::url($webroot . '/services/problem.php'); - return Horde_Util::addParameter($url, array('return_url' => urlencode(self::selfUrl(true, true, true)))); + return self::url($webroot . '/services/problem.php') + ->add('return_url', urlencode(self::selfUrl(true, true, true))); case 'logout': return Horde_Auth::getLogoutUrl(array('reason' => Horde_Auth::REASON_LOGOUT)); @@ -572,8 +572,8 @@ HTML; case 'options': case 'prefsapi': if (!in_array($GLOBALS['conf']['prefs']['driver'], array('', 'none'))) { - $url = self::url($webroot . ($type == 'options' ? '/services/prefs.php' : '/services/prefs/')); - return Horde_Util::addParameter($url, array('app' => $app)); + return self::url($webroot . ($type == 'options' ? '/services/prefs.php' : '/services/prefs/')) + ->add('app', $app); } break; @@ -581,7 +581,8 @@ HTML; return self::url($webroot . '/services/cache.php', false, -1); case 'download': - return Horde_Util::addParameter(self::url($webroot . '/services/download/'), array('module' => $app)); + return self::url($webroot . '/services/download/') + ->add('module', $app); case 'go': return self::url($webroot . '/services/go.php'); @@ -1252,22 +1253,24 @@ HTML; $accesskey = '', $attributes = array(), $escape = true) { - if (!empty($title2)) { - $title = $title2; + if (!($url instanceof Horde_Url)) { + $url = new Horde_Url($url); } - $ret = ' $value) { - $ret .= ' ' . htmlspecialchars($name) . '="' - . htmlspecialchars($value) . '"'; } - return "$ret>"; + return $url->link($attributes); } /** diff --git a/framework/Url/lib/Horde/Url.php b/framework/Url/lib/Horde/Url.php index 327504f98..0c95f2a3c 100644 --- a/framework/Url/lib/Horde/Url.php +++ b/framework/Url/lib/Horde/Url.php @@ -186,4 +186,33 @@ class Horde_Url return $url; } + /** + * Generates a HTML link tag out of this URL. + * + * @param array $attributes A hash with any additional attributes to be + * added to the link. If the attribute name is + * suffixed with ".raw", the attribute value + * won't be HTML-encoded. + * + * @return string An tag representing this URL. + */ + public function link(array $attributes = array()) + { + $url = (string)$this; + $link = ' $value) { + if (substr($name, -4) == '.raw') { + $link .= ' ' . htmlspecialchars(substr($name, 0, -4)) + . '="' . $value . '"'; + } else { + $link .= ' ' . htmlspecialchars($name) + . '="' . htmlspecialchars($value) . '"'; + } + } + return $link . '>'; + } + } -- 2.11.0