Rename PlatalPage to PlPage
[platal.git] / include / banana / hooks.inc.php
index 7aab3df..987de13 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -39,7 +39,7 @@ function hook_formatDisplayHeader($_header, $_text, $in_spool = false)
                         . '<img src="images/icons/user_suit.gif" title="fiche" alt="" /></a>';
                 } else {
                     return $address;
-                }    
+                }
             }
             if (!empty($text)) {
                 $text .= ', ';
@@ -141,26 +141,25 @@ function hook_makeLink($params)
             return $base . '/' . $params['page'];
         }
         if (@$params['action'] == 'subscribe') {
-            return $base . '/subscription';
+            return $base . '/subscribe';
         }
-    
+
         if (!isset($params['group'])) {
             return $base;
         }
         $base .= '/' . $params['group'];
     } else if (Banana::$protocole->name() == 'NNTP' && $xnet) {
         if ($feed) {
-            return 'http://www.polytechnique.org/banana' . hook_platalRSS(@$params['group']);
-        }   
-        $base = $globals->baseurl . '/' . $platal->ns . 'forum';        
+            return $globals->baseurl . '/banana' . hook_platalRSS(@$params['group']);
+        }
+        $base = $globals->baseurl . '/' . $platal->ns . 'forum';
     } else if (Banana::$protocole->name() == 'MLArchives') {
-        $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives';
         if ($feed) {
-            return $base . hook_platalRSS(MLBanana::$listname);
+            return $globals->baseurl . '/' . $platal->ns . hook_platalRSS(MLBanana::$listname);
         } elseif (php_sapi_name() == 'cli') {
             $base = "http://listes.polytechnique.org/archives/" . str_replace('@', '_', $params['group']);
         } else {
-            $base .= '/' . MLBanana::$listname;
+            $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives/' . MLBanana::$listname;
         }
     }
     $base = $base . hook_platalMessageLink($params);
@@ -171,6 +170,34 @@ function hook_makeLink($params)
 }
 }
 
+function hook_hasXFace($headers)
+{
+    return isset($headers['x-org-id']) || isset($headers['x-org-mail']);
+}
+
+function hook_getXFace($headers)
+{
+    $login = @$headers['x-org-id'];
+    if (!$login) {
+        @list($login, ) = explode('@', $headers['x-org-mail']);
+    }
+    if (!$login) {
+        return false;
+    }
+    if (isset($headers['x-face'])) {
+        $res = XDB::query("SELECT  p.uid
+                             FROM  forums.profils AS p
+                       INNER JOIN  aliases AS a ON (p.uid = a.id)
+                            WHERE  FIND_IN_SET('xface', p.flags) AND a.alias = {?}",
+                          $login);
+        if ($res->numRows()) {
+            return false;
+        }
+    }
+    global $globals;
+    http_redirect($global->baseurl . '/photo/' . $login);
+}
+
 function hook_makeJs($src)
 {
     global $page;
@@ -178,16 +205,51 @@ function hook_makeJs($src)
     return ' ';
 }
 
+function make_Organization()
+{
+    global $globals;
+    $perms = S::v('perms');
+    $group = $globals->asso('nom');
+    if (S::has_perms()) {
+        return "Administrateur de Polytechnique.org";
+    } else if ($group && $perms->hasFlag('groupadmin')) {
+        return "Animateur de $group";
+    } else if ($group && $perms->hasFlag('groupmember')) {
+        return "Membre de $group";
+    }
+    return "Utilisateur de Polytechnique.org";
+}
+
 function get_banana_params(array &$get, $group = null, $action = null, $artid = null)
 {
+    if ($group == 'forums') {
+        $group = null;
+    } else if ($group == 'thread') {
+        $group = S::v('banana_group');
+    } else if ($group == 'message') {
+        $action = 'read';
+        $group  = S::v('banana_group');
+        $artid  = S::i('banana_artid');
+    } else if ($action == 'message') {
+        $action = 'read';
+        $artid  = S::i('banana_artid');
+    } else if ($group == 'subscribe' || $group == 'subscription') {
+        $group  = null;
+        $action = null;
+        $get['action'] = 'subscribe';
+    } else if ($group == 'profile') {
+        $group  = null;
+        $action = null;
+        $get['action'] = 'profile';
+    }
     if (!is_null($group)) {
         $get['group'] = $group;
     }
     if (!is_null($action)) {
         if ($action == 'new') {
-            $get['action'] = 'new'; 
+            $get['action'] = 'new';
         } elseif (!is_null($artid)) {
-            $get['artid'] = $artid; 
+            $get['artid'] = $artid;
             if ($action == 'reply') {
                 $get['action'] = 'new';
             } elseif ($action == 'cancel') {
@@ -204,13 +266,61 @@ function get_banana_params(array &$get, $group = null, $action = null, $artid =
             } elseif ($action) {
                 $get['part'] = str_replace('.', '/', $action);
             }
-            if (Get::v('action') == 'showext') { 
-                $get['action'] = 'showext'; 
-            }   
+            if (Get::v('action') == 'showext') {
+                $get['action'] = 'showext';
+            }
         }
     }
 }
 
+class PlatalBananaPage extends BananaPage
+{
+    protected $handler;
+    protected $base;
+
+    public function __construct()
+    {
+        global $platal;
+        Banana::$withtabs = false;
+        $this->handler = 'BananaHandler';
+        $this->base    = $platal->pl_self(0);
+        parent::__construct();
+    }
+
+    protected function prepare()
+    {
+        $tpl = parent::prepare();
+        global $wiz, $page;
+        $wiz = new PlWizard('Banana', 'core/plwizard.tpl', true, false);
+        foreach ($this->pages as $name=>&$mpage) {
+            $wiz->addPage($this->handler, $mpage['text'], $name);
+        }
+        $wiz->apply($page, $this->base, $this->page);
+        return $tpl;
+    }
+}
+
+class BananaHandler
+{
+    public function __construct(PlWizard &$wiz)
+    {
+    }
+
+    public function template()
+    {
+        return 'banana/index.tpl';
+    }
+
+    public function prepare(PlPage &$page, $id)
+    {
+    }
+
+    public function process()
+    {
+        return PlWizard::CURRENT_PAGE;
+    }
+}
+
 function run_banana(&$page, $class, array $args)
 {
     $banana = new $class(S::v('forlife'), $args);
@@ -228,7 +338,7 @@ function run_banana(&$page, $class, array $args)
     $bt = $banana->backtrace();
     if ($bt) {
         new PlBacktrace(Banana::$protocole->name(), $banana->backtrace(), 'response', 'time');
-    }    
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: