[racktables-users] buildRedirectURL modification

  • From: "Jonathan Thurman" <jthurman42@xxxxxxxxx>
  • To: racktables-users@xxxxxxxxxxxxx
  • Date: Tue, 17 Jun 2008 21:07:47 -0700

> It may sound completely odd, but each time someone suggests a cleanup
> patch, I discover a load of drastic changes in my working copies (there
> are multiple), that conflict with it. This time it's about finishing
> the "tags" epic feature by implementing a free-text access control
> (RackCode, to be particular). I'm afraid, that the priority of this
> feature is quite high and beyond my control, but as soon as tested and
> released (in a matter of a week, I guess), it's going to significantly
> change things. However, your suggestion above has been merged in a
> slightly different way (see the buildRedirectURL() function in current
> trunk) and will be eventually used as a standard code pattern.
>
> I would like to release the next tags-driven version as 0.16.0 and to
> expect a couple of cleanup-focused releases in 0.16 line after that.
> This settlement phase would perfectly allow focusing on the usability
> issues you have pointed out. I would like to start designing the 2D maps
> feature at the same time.
>
> Thank you.
>
> --
>    DO4-UANIC
>
>

The new buildRedirectURL function looks great, but I would like to
extend it a little further.  Right now it allows for you to add One
variable and value to the URL, which is not enough for many of the
functions.  I created a patch against svn 1981 that allows for a
variable number of arguments to be sent to the function.  The first
two are still required, but only those two.  From then on arguments
must be in pairs.  It will ignore a single argument alone at the end,
but if you make a mistake in the middle everything would be shifted!
I didn't include updating any of the old functions to use
buildRedirectURL as I didn't want to mess up any of your working
copies (I only have two...)  If you want I can go ahead and do that at
some point.

I have also been working on a "Container" that would support
subdividing into multiple pieces to handle the 2D mapping.  Nothing
that is usable beyond my tests so far, but it is working out to be
quite flexible and is abstract in design.  Once I get a little closer
to actually being usable I will submit it.

-Jonathan
Index: functions.php
===================================================================
--- functions.php       (revision 1981)
+++ functions.php       (working copy)
@@ -1539,13 +1539,43 @@
        return $ret;
 }
 
-function buildRedirectURL ($pageno, $tabno, $what, $text)
+/*
+ *   Author:  Jonathan Thurman
+ * Modified:  2008-06-17
+ *
+ * Re-written to take a variable number of arguments, at least 2 are required
+ *  - $pageno
+ *  - $tabno
+ *
+ * All other arguments must be in pairs
+ *  - First is a string that will be the variable
+ *  - Second is the value
+ *
+ * Examples:
+ *  buildRedirectURL($pageno, $tabno, "message", "this is the message");
+ *  buildRedirectURL($pageno, $tabno);
+ *  buildRedirectURL($pageno, $tabno, "message", "another message", "error", 
"this works too");
+ */
+function buildRedirectURL ($pageno, $tabno /*, ... */)
 {
        global $root, $page;
        $url = "${root}?page=${pageno}&tab=${tabno}";
        if (isset ($page[$pageno]['bypass']))
                $url .= '&' . $page[$pageno]['bypass'] . '=' . 
$_REQUEST[$page[$pageno]['bypass']];
-       $url .= "&${what}=" . urlencode ($text);
+
+       $argc = func_num_args();
+       if ($argc > 2)
+       {
+               $argv = func_get_args(); // JT: returns an array
+               for ($x = 2; $x < $argc; $x++)  // JT: Start with the 3rd 
argument (handled 1 & 2 above)
+               {
+                       if (isset($argv[$x]) && isset($argv[$x + 1]))   // JT: 
You have to have them both!
+                       {
+                               $url .= "&${argv[$x]}=" . urlencode($argv[$x + 
1]);
+                               $x++;                                   // JT: 
Skip an extra argument
+                       }
+               }
+       }
        return $url;
 }
 

Other related posts:

  • » [racktables-users] buildRedirectURL modification