X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fmisc.inc.php;h=5a76e82bdd62f5402143e90b1169d8d64f997ea5;hb=a205f5e35af586f946d887040a4f3c82f7777323;hp=1197c69bbeec7f94961a791f0ae56483d32c4b8c;hpb=5d133234c09c44ed143ab88a1d6c7b09a0b792cb;p=banana.git diff --git a/banana/misc.inc.php b/banana/misc.inc.php index 1197c69..5a76e82 100644 --- a/banana/misc.inc.php +++ b/banana/misc.inc.php @@ -30,6 +30,117 @@ function textFormat_translate($format) } } +/** Redirect to the page with the given parameter + * @ref makeLink + */ +function redirectInBanana($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 + * - xface = to make a link to an xface + * + * 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 (isset($params['xface'])) { + $file = dirname($file) . '/xface.php'; + $get = 'face=' . urlencode(base64_encode($params['xface'])); + } else 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, $popup = null, $class = null) +{ + $link = makeLink($params); + if (is_null($text)) { + $text = $link; + } + if (!is_null($popup)) { + $popup = ' title="' . $popup . '"'; + } + if (!is_null($class)) { + $class = ' class="' . $class . '"'; + } + $target = null; + if (isset($params['action']) && $params['action'] == 'view') { + $target = ' target="_blank"'; + } + return '' . $text . ''; +} + +/** Format tree images links + * @param img STRING Image name (without extension) + * @param alt STRING alternative string + * @param width INT to force width of the image (null if not defined) + * + * This function can be overloaded by defining hook_makeImg() + */ +function makeImg($img, $alt, $height = null, $width = null) +{ + if (function_exists('hook_makeImg') + && $res = hook_makeImg($img, $alt, $height, $width)) { + return $res; + } + + if (!is_null($width)) { + $width = ' width="' . $width . '"'; + } + if (!is_null($height)) { + $height = ' height="' . $height . '"'; + } + + $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; + $host = $_SERVER['HTTP_HOST']; + $file = dirname($_SERVER['PHP_SELF']) . '/img/' . $img; + $url = $proto . $host . $file; + + return '' . $alt . ''; +} + +/** Make a link using an image + */ +function makeImgLink($params, $img, $alt, $height = null, $width = null, $class = null) +{ + return makeHREF($params, + makeImg($img, ' [' . $alt . ']', $height, $width), + $alt, + $class); +} + /******************************************************************************** * HTML STUFF * Taken from php.net @@ -42,7 +153,8 @@ function textFormat_translate($format) */ function removeEvilTags($source) { - $allowedTags = '