summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorCallan Barrett <wizzomafizzo@gmail.com>2008-12-22 14:55:10 +0100
committerLoui Chang <louipc.ist@gmail.com>2008-12-29 23:29:53 +0100
commit520d1e2a3503ba9fd706babfe057f7ffc4a06eac (patch)
treef46fedb26ac38f01cda89918154db5e4d99ae09c /web
parentd4b80de492285255297e9d492e9b0a597e8c2379 (diff)
downloadaur-520d1e2a3503ba9fd706babfe057f7ffc4a06eac.tar.gz
aur-520d1e2a3503ba9fd706babfe057f7ffc4a06eac.tar.xz
Add function to generate clean urls
Signed-off-by: Callan Barrett <wizzomafizzo@gmail.com> Signed-off-by: Loui Chang <louipc.ist@gmail.com>
Diffstat (limited to 'web')
-rw-r--r--web/lib/aur.inc34
1 files changed, 34 insertions, 0 deletions
diff --git a/web/lib/aur.inc b/web/lib/aur.inc
index e82f0ea0..22bd4e72 100644
--- a/web/lib/aur.inc
+++ b/web/lib/aur.inc
@@ -438,3 +438,37 @@ function uid_from_username($username="")
return $row[0];
}
+/**
+ * Generate clean url with edited/added user values
+ *
+ * Makes a clean string of variables for use in URLs based on current $_GET and
+ * list of values to edit/add to that. Any empty variables are discarded.
+ *
+ * ex. print "http://example.com/test.php?" . mkurl("foo=bar&bar=baz")
+ *
+ * @param string $append string of variables and values formatted as in URLs
+ * ex. mkurl("foo=bar&bar=baz")
+ * @return string clean string of variables to append to URL, urlencoded
+ * @author Callan Barrett
+ */
+function mkurl($append) {
+ $get = $_GET;
+ $append = explode('&', $append);
+ $uservars = array();
+ $out = '';
+
+ foreach ($append as $i) {
+ $ex = explode('=', $i);
+ $uservars[$ex[0]] = $ex[1];
+ }
+
+ foreach ($uservars as $k => $v) { $get[$k] = $v; }
+
+ foreach ($get as $k => $v) {
+ if ($v !== '') {
+ $out .= '&amp;' . urlencode($k) . '=' . urlencode($v);
+ }
+ }
+
+ return substr($out, 5);
+}