Add a generic way to catch some informations from the subject...
[banana.git] / banana / misc.inc.php
index 5f35d80..25a9246 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) {
@@ -79,17 +83,20 @@ function makeLink($params)
 /** Format a link to be use in a link
  * @ref makeLink
  */
-function makeHREF($params, $text = null)
+function makeHREF($params, $text = null, $popup = null)
 {
     $link = makeLink($params);
     if (is_null($text)) {
         $text = $link;
     }
+    if (!is_null($popup)) {
+        $popup = ' title="' . $popup . '"';
+    }
     $target = null;
     if (isset($params['action']) && $params['action'] == 'view') {
         $target = ' target="_blank"';
     }
-    return '<a href="' . htmlentities($link) . $target . '">' . $text . '</a>';
+    return '<a href="' . htmlentities($link) . $target . '"' . $popup . '>' . $text . '</a>';
 }
 
 /** Format tree images links
@@ -99,23 +106,26 @@ function makeHREF($params, $text = null)
  *
  * This function can be overloaded by defining hook_makeImg()
  */
-function makeImg($img, $alt, $width = null)
+function makeImg($img, $alt, $height = null, $width = null)
 {
     if (function_exists('hook_makeImg')
-            && $res = hook_makeImg($img, $alt, $width)) {
+            && $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 . '"' . $width . ' alt="' . $alt . '" />';
+    return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
 }
 
 /********************************************************************************
@@ -278,7 +288,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')
@@ -351,17 +361,20 @@ function displayshortcuts($first = -1) {
                                _b_('Nouveau message'))
               . '] ';
         if (sizeof($banana->spool->overview)>$banana->tmax) {
-            $res .= '<br />';
+            $res .= '<br />Page : ';
             $n = intval(log(count($banana->spool->overview), 10))+1;
-            for ($ndx=1; $ndx <= sizeof($banana->spool->overview); $ndx += $banana->tmax) {
+            $i = 1;
+            for ($ndx = 1 ; $ndx <= sizeof($banana->spool->overview) ; $ndx += $banana->tmax) {
                 if ($first==$ndx) {
-                    $fmt = "[%0{$n}u-%0{$n}u] ";
+                    $fmt = $i . ' ';
                 } else {
-                    $fmt = '[' . makeHREF(Array('group' => $group,
-                                                'first' => $ndx),
-                                          '%0' . $n . 'u-%0' . $n . 'u')
-                         . '] ';
+                    $fmt = makeHREF(Array('group' => $group,
+                                          'first' => $ndx),
+                                    $i, 
+                                    '%0' . $n . 'u-%0' . $n . 'u')
+                         . ' ';
                 }
+                $i++;
                 $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)));
             }
         }
@@ -487,7 +500,9 @@ function formatbody($_text, $format='plain', $flowed=false)
                             '_' => 'u',
                             '/' => 'em');
         foreach ($formatting as $limit=>$mark) {
-            $res = preg_replace('@' . $limit . '([^\s]+)' . $limit . '@', "<$mark>\\1</$mark>", $res);
+            $res = preg_replace('@(\W)' . $limit . '(\w+)' . $limit . '(\W)@'
+                                ,'\1<' . $mark . '>\2</' . $mark . '>\3'
+                                , $res);
         }
     }