+/** Redirect to the page with the given parameter
+ * @ref makeLink
+ */
+function redirect($params)
+{
+ header('Location: ' . makeLink($params));
+}
+
+/** Make a link using the given parameters
+ * @param ARRAY params, the parameters with
+ * key => value
+ * Known key are:
+ * - group = group name
+ * - artid/first = article id the the group
+ * - subscribe = to show the subscription page
+ * - action = action to do (new, cancel, view)
+ * - part = to show the given MIME part of the article
+ * - pj = to get the given attachment
+ *
+ * Can be overloaded by defining a hook_makeLink function
+ */
+function makeLink($params)
+{
+ if (function_exists('hook_makeLink')
+ && $res = hook_makeLink($params)) {
+ return $res;
+ }
+ $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
+ $host = $_SERVER['HTTP_HOST'];
+ $file = $_SERVER['PHP_SELF'];
+
+ if (count($params) != 0) {
+ $get = '?';
+ foreach ($params as $key=>$value) {
+ if (strlen($get) != 1) {
+ $get .= '&';
+ }
+ $get .= $key . '=' . $value;
+ }
+ } else {
+ $get = '';
+ }
+
+ return $proto . $host . $file . $get;
+}
+
+/** Format a link to be use in a link
+ * @ref makeLink
+ */
+function makeHREF($params, $text = null)
+{
+ $link = makeLink($params);
+ if (is_null($text)) {
+ $text = $link;
+ }
+ if ($params['action'] == 'view') {
+ $target = ' target="_blank"';
+ }
+ return '<a href="' . htmlentities($link) . $target . '">' . $text . '</a>';
+}
+