From e5121354ec05594eeffda5a773f0c9f63a167a6b Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 30 Jul 2010 00:21:06 -0600 Subject: [PATCH] Add Horde_Url::unique(). Remove Horde::nocacheUrl(). --- framework/Block/lib/Horde/Block/Layout.php | 15 +++++++-------- framework/Core/lib/Horde.php | 30 ++++-------------------------- framework/Core/package.xml | 3 ++- framework/Url/lib/Horde/Url.php | 10 ++++++++++ framework/Url/package.xml | 3 ++- imp/compose.php | 2 +- imp/contacts.php | 2 +- imp/lib/IMP.php | 2 +- imp/lib/Ui/Mimp.php | 2 +- kronolith/add.php | 2 +- kronolith/attendees.php | 2 +- kronolith/delete.php | 2 +- kronolith/edit.php | 2 +- kronolith/event.php | 2 +- kronolith/templates/contacts/contacts.inc | 2 +- turba/edit.php | 2 +- turba/merge.php | 3 +-- 17 files changed, 37 insertions(+), 49 deletions(-) diff --git a/framework/Block/lib/Horde/Block/Layout.php b/framework/Block/lib/Horde/Block/Layout.php index ce774f1c1..963d8e7f3 100644 --- a/framework/Block/lib/Horde/Block/Layout.php +++ b/framework/Block/lib/Horde/Block/Layout.php @@ -77,17 +77,16 @@ class Horde_Block_Layout * @param integer $row A layout row. * @param integer $col A layout column. * - * @return string An URL with all necessary parameters. + * @return Horde_Url An URL with all necessary parameters. */ public function getActionUrl($action, $row, $col) { - return Horde_Util::addParameter( - Horde::url($this->_editUrl), - array('col' => $col, - 'row' => $row, - 'action' => $action, - 'url' => $this->_viewUrl, - 'nocache' => base_convert(microtime(), 10, 36))) . '#block'; + return Horde::url($this->_editUrl)->unique()->setAnchor('block')->add(array( + 'col' => $col, + 'row' => $row, + 'action' => $action, + 'url' => $this->_viewUrl + )); } /** diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index e0aab04bf..cc997dffc 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -1245,7 +1245,8 @@ HTML; * * @param boolean $script_params Include script parameters like * QUERY_STRING and PATH_INFO? - * @param boolean $nocache Include a nocache parameter in the URL? + * @param boolean $nocache Include a cache-buster parameter in the + * URL? * @param boolean $full Return a full URL? * @param boolean $force_ssl Ignore $conf['use_ssl'] and force creation * of a SSL URL? @@ -1280,35 +1281,12 @@ HTML; $url = self::url($url, $full, 0, $force_ssl); - return $nocache - ? self::nocacheUrl($url) + return ($nocache && $GLOBALS['browser']->hasQuirk('cache_same_url')) + ? $url->unique() : $url; } /** - * Returns a url with the 'nocache' parameter added, if the browser is - * buggy and caches old URLs. - * - * @param Horde_Url|string $url The URL to modify. - * - * @return Horde_Url The requested URL. - */ - static public function nocacheUrl($url) - { - if (!$url instanceof Horde_Url) { - $url = new Horde_Url($url); - } - - /* We may need to set a dummy parameter 'nocache' since some - * browsers do not always honor the 'no-cache' header. */ - if ($GLOBALS['browser']->hasQuirk('cache_same_url')) { - $url->add('nocache', uniqid()); - } - - return $url; - } - - /** * Constructs a correctly-pathed link to an image. * * @param mixed $src The image file (either a string or a diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 7838361fb..301d4dc00 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -34,7 +34,8 @@ Application Framework. beta LGPL - * Absorb horde/Ui package. + * Remove Horde::nocacheUrl. + * Absorb horde/Ui package. * Absorb horde/Ajax package. * Import application auth driver from horde/Auth. * Import signup code from horde/Auth. diff --git a/framework/Url/lib/Horde/Url.php b/framework/Url/lib/Horde/Url.php index 4551d74a6..8b2d8d514 100644 --- a/framework/Url/lib/Horde/Url.php +++ b/framework/Url/lib/Horde/Url.php @@ -301,6 +301,16 @@ class Horde_Url } /** + * Add a unique parameter to the URL to aid in cache-busting. + * + * @return Horde_Url This (modified) object, to allow chaining. + */ + public function unique() + { + return $this->add('u', uniqid(mt_rand())); + } + + /** * URL-safe base64 encoding, with trimmed '='. * * @param string $string String to encode. diff --git a/framework/Url/package.xml b/framework/Url/package.xml index 7f3a43fd5..feeab5156 100644 --- a/framework/Url/package.xml +++ b/framework/Url/package.xml @@ -29,7 +29,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Add support for callback function for toString conversion. + * Add Horde_Url::unique(). + * Add support for callback function for toString conversion. * Add support for URL anchors. * Added Horde_Url::uriB64Encode() and Horde_Url::uriB64Decode(). * Initial package. diff --git a/imp/compose.php b/imp/compose.php index 5ba6799c1..822e30c2c 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -694,7 +694,7 @@ if (!$redirect) { /* Set up the base template now. */ $t = $injector->createInstance('Horde_Template'); $t->setOption('gettext', true); -$t->set('post_action', Horde::applicationUrl('compose.php')->add('uniq', uniqid(mt_rand()))); +$t->set('post_action', Horde::applicationUrl('compose.php')->unique()); $t->set('allow_compose', !$compose_disable); if ($redirect) { diff --git a/imp/contacts.php b/imp/contacts.php index 775e3cdbc..b3f725f1d 100644 --- a/imp/contacts.php +++ b/imp/contacts.php @@ -73,7 +73,7 @@ foreach (explode('|', $vars->sa) as $addr) { $template = $injector->createInstance('Horde_Template'); $template->setOption('gettext', true); -$template->set('action', Horde::applicationUrl('contacts.php')->add(array('uniq' => uniqid(mt_rand())))); +$template->set('action', Horde::applicationUrl('contacts.php')->unique()); $template->set('formname', $vars->formname); $template->set('formInput', Horde_Util::formInput()); $template->set('search', htmlspecialchars($vars->search)); diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index e8a1c1282..9d383de66 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -590,7 +590,7 @@ class IMP } if ($conf['user']['allow_folders']) { - $menu->add(Horde::nocacheUrl(Horde::applicationUrl('folders.php')), _("_Folders"), 'folders/folder.png'); + $menu->add(Horde::applicationUrl('folders.php')->unique(), _("_Folders"), 'folders/folder.png'); } if ($_SESSION['imp']['protocol'] != 'pop') { diff --git a/imp/lib/Ui/Mimp.php b/imp/lib/Ui/Mimp.php index 5287d947f..16ec78fbb 100644 --- a/imp/lib/Ui/Mimp.php +++ b/imp/lib/Ui/Mimp.php @@ -32,7 +32,7 @@ class IMP_Ui_Mimp } if (!in_array($page, array('compose', 'search')) && IMP::canCompose()) { - $items[] = array(_("New Message"), Horde::applicationUrl('compose-mimp.php')->add('u', uniqid(mt_rand()))); + $items[] = array(_("New Message"), Horde::applicationUrl('compose-mimp.php')->unique()); } if (!in_array($page, array('folders', 'search'))) { diff --git a/kronolith/add.php b/kronolith/add.php index 8baa25b9a..eedec33fa 100644 --- a/kronolith/add.php +++ b/kronolith/add.php @@ -64,4 +64,4 @@ if (!empty($url)) { } // Make sure URL is unique. -header('Location: ' . $url->add('unique', hash('md5', microtime()))); +header('Location: ' . $url->unique()); diff --git a/kronolith/attendees.php b/kronolith/attendees.php index 18b56ee0d..11dfea519 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -163,7 +163,7 @@ case 'dismiss': } // Make sure URL is unique. - header('Location: ' . $url->add('unique', hash('md5', microtime()))); + header('Location: ' . $url->unique()); exit; case 'clear': diff --git a/kronolith/delete.php b/kronolith/delete.php index 1aafd8f5b..453ab7462 100644 --- a/kronolith/delete.php +++ b/kronolith/delete.php @@ -104,4 +104,4 @@ if (!empty($url)) { } // Make sure URL is unique. -header('Location: ' . $url->add('unique', hash('md5', microtime()))); +header('Location: ' . $url->unique()); diff --git a/kronolith/edit.php b/kronolith/edit.php index f3201186a..1bec575f4 100644 --- a/kronolith/edit.php +++ b/kronolith/edit.php @@ -195,4 +195,4 @@ if (!empty($url)) { } // Make sure URL is unique. -header('Location: ' . $url->add('unique', hash('md5', microtime()))); +header('Location: ' . $url->unique()); diff --git a/kronolith/event.php b/kronolith/event.php index 9b93c4c9d..253e2bf2b 100644 --- a/kronolith/event.php +++ b/kronolith/event.php @@ -45,7 +45,7 @@ case 'EditEvent': } else { $url = Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true); } - header('Location: ' . $url->add('unique', hash('md5', microtime()))); + header('Location: ' . $url->unique()); exit; } break; diff --git a/kronolith/templates/contacts/contacts.inc b/kronolith/templates/contacts/contacts.inc index 3a55b4515..05bd32e64 100644 --- a/kronolith/templates/contacts/contacts.inc +++ b/kronolith/templates/contacts/contacts.inc @@ -132,7 +132,7 @@ window.onload = function() { //--> -
+ diff --git a/turba/edit.php b/turba/edit.php index dc4a71030..dd9893ec6 100644 --- a/turba/edit.php +++ b/turba/edit.php @@ -86,7 +86,7 @@ if (!is_a($edited, 'PEAR_Error')) { } else { $url = new Horde_Url($url, true); } - header('Location: ' . $url->add('unique', hash('md5', microtime()))); + header('Location: ' . $url->unique()); exit; } diff --git a/turba/merge.php b/turba/merge.php index 5348d91d7..00b1a3edc 100644 --- a/turba/merge.php +++ b/turba/merge.php @@ -19,8 +19,7 @@ $mergeInto = Horde_Util::getFormData('merge_into'); $driver = Turba_Driver::singleton($source); if ($url = Horde_Util::getFormData('url')) { - $url = new Horde_Url($url, true); - $url->add('unique', hash('md5', microtime())); + $url = new Horde_Url($url, true)->unique(); } $contact = $driver->getObject($mergeInto); -- 2.11.0