Fix xface with last banana and make white region transparent
[platal.git] / include / banana.inc.php
index 8cef0d0..4f009f8 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
 
 require_once('banana/banana.inc.php');
 
-function hook_formatDisplayHeader($_header,$_text) {
-    global $banana;
-    if ($_header == 'x-org-id') {
-        return "$_text [<a href=\"../fiche.php?user=$_text\" class='popup2'>fiche</a>]";
+function hook_formatDisplayHeader($_header, $_text) {
+    global $globals, $banana;
+    if ($_header == 'from') {
+        $id = $banana->post->headers['x-org-id'];
+        $_text = formatFrom($_text);
+        return $_text . ' <a href="' . $globals->baseurl . '/profile/' 
+             . $id . '" class="popup2" title="' . $id . '">'
+             . '<img src="' . $globals->baseurl . '/images/loupe.gif" alt="fiche" title="fiche" />'
+             . '</a>';
     }
 }
 
-function hook_headerTranslate($hdr) {
-    if ($hdr == 'x-org-id') {
-        return 'Identité';
+function hook_checkcancel($_headers) {
+    return ($_headers['x-org-id'] == Session::get('forlife') or has_perms());
+}
+
+function hook_makeLink($params) {
+    global $globals;
+    $base = $globals->baseurl . '/banana'; 
+    if ($params['subscribe'] == 1) {
+        return $base . '/subscription';
+    }
+    if (isset($params['xface'])) {
+        return $base . '/xface/' . strtr(base64_encode($params['xface']), '+/', '.:');
+    }
+
+    if (!isset($params['group'])) {
+        return $base;
+    }
+    $base .= '/' . $params['group'];
+
+    if (isset($params['first'])) {
+        return $base . '/from/' . $params['first'];
+    }
+    if (isset($params['artid'])) {
+        if ($params['action'] == 'new') {
+            $base .= '/reply';
+        } elseif ($params['action'] == 'cancel') {
+            $base .= '/cancel';
+        } else {
+            $base .= '/read';
+        }
+        return $base . '/' . $params['artid'];
+    }
+    
+    if ($params['action'] == 'new') {
+        return $base . '/new';
     }
+    return $base;
 }
 
-function hook_checkcancel($_headers) {
-    return ($_headers['x-org-id'] == Session::get('forlife') or has_perms());
+function hook_makeImg($img, $alt, $height, $width)
+{
+    global $globals;
+    $url = $globals->baseurl . '/images/banana/' . $img . '.gif';
+
+    if (!is_null($width)) {
+        $width = ' width="' . $width . '"';
+    }
+    if (!is_null($height)) {
+        $height = ' height="' . $height . '"';
+    }
+    
+    return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
+}
+
+function hook_getSubject(&$subject)
+{
+    if (preg_match('!(.*\S)\s*\[=> ([^\]\s]+)\]!', $subject, $matches)) {
+        $subject = $matches[1];
+        global $banana;
+        if ($banana->state['group'] == $matches[2]) {
+            return ' [=> ' . $matches[2] . ']';
+        } else {
+            return ' [=> ' . makeHREF(Array('group' => $matches[2]), $matches[2]) . ']';
+        }
+    }
+    return null;
 }
 
 class PlatalBanana extends Banana
@@ -71,14 +134,14 @@ class PlatalBanana extends Banana
             $globals->xdb->execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}", gmdate("YmdHis"), $uid);
         }
 
-        $req = $globals->xdb->query(
-                "SELECT  nom
+        $req = $globals->xdb->query("
+                 SELECT  nom
                    FROM  {$globals->banana->table_prefix}abos
               LEFT JOIN  {$globals->banana->table_prefix}list ON list.fid=abos.fid
                   WHERE  uid={?}", $uid);
         $this->profile['subscribe'] = $req->fetchColumn();
 
-        array_splice($this->show_hdr,  count($this->show_hdr)  - 2, 0, 'x-org-id');
+        array_splice($this->show_hdr,  count($this->show_hdr)  - 2, 0);
         array_splice($this->parse_hdr, count($this->parse_hdr) - 2, 0, 'x-org-id');
 
         $this->host = 'news://web_'.Session::get('forlife')
@@ -87,16 +150,16 @@ class PlatalBanana extends Banana
         parent::Banana();
     }
 
-    function run()
+    function run($params = null)
     {
         global $banana, $globals;
 
-        if (Get::get('banana') == 'updateall') {
+        if (Get::get('banana') == 'updateall'
+                || (!is_null($params) && isset($params['banana']) && $params['banana'] == 'updateall')) {
             $globals->xdb->execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}', gmdate('YmdHis'), Session::getInt('uid'));
             $_SESSION['banana_last'] = time();
-            redirect($_SERVER['PHP_SELF']);
         }
-        return Banana::run('PlatalBanana');
+        return Banana::run('PlatalBanana', $params);
     }
 
     function action_saveSubs()