summaryrefslogtreecommitdiff
path: root/url.class
diff options
context:
space:
mode:
authorChristian Schneider2007-02-13 16:28:13 +0000
committerChristian Schneider2007-02-13 16:28:13 +0000
commitcc4ddb57a83e2c5c922f03e1151680b3e59b1263 (patch)
treec4b246616acfef66bf44935077bd64d5a31beea4 /url.class
parent40c23e8e6ae2579fa279416b9f2fda5874b360a7 (diff)
downloaditools-cc4ddb57a83e2c5c922f03e1151680b3e59b1263.tar.gz
itools-cc4ddb57a83e2c5c922f03e1151680b3e59b1263.tar.bz2
itools-cc4ddb57a83e2c5c922f03e1151680b3e59b1263.zip
Added it_url::params (handles nested arrays) and use it in U() and search_url
Diffstat (limited to 'url.class')
-rw-r--r--url.class34
1 files changed, 34 insertions, 0 deletions
diff --git a/url.class b/url.class
index 105a28b..f414449 100644
--- a/url.class
+++ b/url.class
@@ -527,6 +527,40 @@ function encode($str)
return strtr(urlencode($str), array("%2C"=>",", "%28"=>"(", "%29"=>")"));
}
+/**
+ * Create GET request from params, optionally only using given fields
+ * @param $params Array to take values from, usually $_GET
+ * @param $keys Keys to use; default: all
+ */
+function params($params, $keys = null)
+{
+ return join("&", it_url::_params($params, $keys));
+}
+
+function _params($params, $keys = null)
+{
+ $result = array();
+
+ if (!isset($keys))
+ $keys = array_keys($params);
+
+ foreach ($keys as $key)
+ {
+ if (is_array($params[$key]))
+ {
+ foreach (it_url::_params($params[$key]) as $value)
+ {
+ if (strlen($value))
+ $result[] = it::replace('^([^=\[]*)' => $key . '[$1]', $value);
+ }
+ }
+ else if (strlen($params[$key]))
+ $result[] = urlencode($key) . "=" . it_url::encode($params[$key]);
+ }
+
+ return $result;
+}
+
}
?>