diff options
author | Christian Schneider | 2007-02-13 16:28:13 +0000 |
---|---|---|
committer | Christian Schneider | 2007-02-13 16:28:13 +0000 |
commit | cc4ddb57a83e2c5c922f03e1151680b3e59b1263 (patch) | |
tree | c4b246616acfef66bf44935077bd64d5a31beea4 /url.class | |
parent | 40c23e8e6ae2579fa279416b9f2fda5874b360a7 (diff) | |
download | itools-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.class | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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; +} + } ?> |