Use link abstraction for xface
[banana.git] / banana / misc.inc.php
index 3a086cf..7a782c4 100644 (file)
@@ -48,6 +48,7 @@ function redirectInBanana($params)
  *  - 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
  */
@@ -61,7 +62,10 @@ function makeLink($params)
     $host  = $_SERVER['HTTP_HOST'];
     $file  = $_SERVER['PHP_SELF'];
 
-    if (count($params) != 0) {
+    if (isset($params['xface'])) {
+        $file = dirname($file) . '/xface.php';
+        $get  = 'face=' . $params['xface'];
+    } else if (count($params) != 0) {
         $get = '?';
         foreach ($params as $key=>$value) {
             if (strlen($get) != 1) {
@@ -92,6 +96,35 @@ function makeHREF($params, $text = null)
     return '<a href="' . htmlentities($link) . $target . '">' . $text . '</a>';
 }
 
+/** 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 . '.gif';
+    $url   = $proto . $host . $file; 
+
+    return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
+}
+
 /********************************************************************************
  * HTML STUFF
  * Taken from php.net
@@ -252,7 +285,7 @@ function formatDisplayHeader($_header,$_text) {
             return $rsl;
 
         case "x-face":
-            return '<img src="xface.php?face='.urlencode(base64_encode($_text)).'"  alt="x-face" />';
+            return '<img src="' . makeLink(Array('xface' => urlencode(base64_encode($_text)))) .'"  alt="x-face" />';
         
         default:
             if (function_exists('hook_formatDisplayHeader')