Add Horde_Url::unique().
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 30 Jul 2010 06:21:06 +0000 (00:21 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 30 Jul 2010 08:54:09 +0000 (02:54 -0600)
Remove Horde::nocacheUrl().

17 files changed:
framework/Block/lib/Horde/Block/Layout.php
framework/Core/lib/Horde.php
framework/Core/package.xml
framework/Url/lib/Horde/Url.php
framework/Url/package.xml
imp/compose.php
imp/contacts.php
imp/lib/IMP.php
imp/lib/Ui/Mimp.php
kronolith/add.php
kronolith/attendees.php
kronolith/delete.php
kronolith/edit.php
kronolith/event.php
kronolith/templates/contacts/contacts.inc
turba/edit.php
turba/merge.php

index ce774f1..963d8e7 100644 (file)
@@ -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
+        ));
     }
 
     /**
index e0aab04..cc997df 100644 (file)
@@ -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
index 7838361..301d4dc 100644 (file)
@@ -34,7 +34,8 @@ Application Framework.</description>
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Absorb horde/Ui package.
+ <notes>* Remove Horde::nocacheUrl.
+ * Absorb horde/Ui package.
  * Absorb horde/Ajax package.
  * Import application auth driver from horde/Auth.
  * Import signup code from horde/Auth.
index 4551d74..8b2d8d5 100644 (file)
@@ -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.
index 7f3a43f..feeab51 100644 (file)
@@ -29,7 +29,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Add support for callback function for toString conversion.
+ <notes>* 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.
index 5ba6799..822e30c 100644 (file)
@@ -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) {
index 775e3cd..b3f725f 100644 (file)
@@ -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));
index e8a1c12..9d383de 100644 (file)
@@ -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') {
index 5287d94..16ec78f 100644 (file)
@@ -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'))) {
index 8baa25b..eedec33 100644 (file)
@@ -64,4 +64,4 @@ if (!empty($url)) {
 }
 
 // Make sure URL is unique.
-header('Location: ' . $url->add('unique', hash('md5', microtime())));
+header('Location: ' . $url->unique());
index 18b56ee..11dfea5 100644 (file)
@@ -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':
index 1aafd8f..453ab74 100644 (file)
@@ -104,4 +104,4 @@ if (!empty($url)) {
 }
 
 // Make sure URL is unique.
-header('Location: ' . $url->add('unique', hash('md5', microtime())));
+header('Location: ' . $url->unique());
index f320118..1bec575 100644 (file)
@@ -195,4 +195,4 @@ if (!empty($url)) {
 }
 
 // Make sure URL is unique.
-header('Location: ' . $url->add('unique', hash('md5', microtime())));
+header('Location: ' . $url->unique());
index 9b93c4c..253e2bf 100644 (file)
@@ -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;
index 3a55b45..05bd32e 100644 (file)
@@ -132,7 +132,7 @@ window.onload = function() {
 
 //-->
 </script>
-<form method="post" name="contacts" onsubmit="passAddresses();" action="contacts.php?nocache=<?php echo hash('md5', mt_rand()) ?>">
+<form method="post" name="contacts" onsubmit="passAddresses();" action="<?php echo Horde::applicationUrl('contacts.php')->unique() ?>">
 <input type="hidden" name="sa" />
 <?php Horde_Util::pformInput() ?>
 
index dc4a710..dd9893e 100644 (file)
@@ -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;
 }
 
index 5348d91..00b1a3e 100644 (file)
@@ -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);