Improve new URL format for banana using the hook_makeLink introduced in rev61 of...
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 9 Jul 2006 11:57:48 +0000 (11:57 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 9 Jul 2006 11:57:48 +0000 (11:57 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@402 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
include/banana.inc.php
modules/banana.php
templates/banana/index.tpl

index 556f349..2925b96 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,7 +7,7 @@ New:
         - Work hard to add nice URI's into Platal.                          -MC
 
     * Banana:
-        - Switch to the new URI scheme.                                     -MC
+        - Switch to the new URI scheme.                                 -MC/FRU
 
     * Emails:
         - Switch to the new URI scheme.                                     -MC
index 8bcc704..c48d173 100644 (file)
@@ -22,7 +22,6 @@
 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>]";
     }
@@ -38,6 +37,38 @@ 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['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;
+}
+
 class PlatalBanana extends Banana
 {
     var $profile    = Array( 'name' => '', 'sig'  => '', 'org'  => 'Utilisateur de Polytechnique.org',
@@ -87,16 +118,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()
index b853065..6ffbda5 100644 (file)
@@ -24,27 +24,35 @@ class BananaModule extends PLModule
     function handlers()
     {
         return array(
-            'banana' => $this->make_hook('banana', AUTH_COOKIE),
-            'banana/profile' => $this->make_hook('profile', AUTH_MDP),
-        );
+            'banana'              => $this->make_hook('banana', AUTH_COOKIE),
+            'banana/profile'      => $this->make_hook('profile', AUTH_MDP),
+                       'banana/subscription' => $this->make_hook('subscription', AUTH_COOKIE),
+                       'banana/updateall'    => $this->make_hook('updateall', AUTH_COOKIE),
+               );
     }
 
-    function handler_banana(&$page)
+    function handler_banana(&$page, $group = null, $action = null, $artid = null)
     {
-        $page->changeTpl('banana/index.tpl');
-        $page->addCssLink('css/banana.css');
-        $page->assign('xorg_title','Polytechnique.org - Forums & PA');
-
-        require_once 'banana.inc.php';
-
-        $res = PlatalBanana::run();
-        $page->assign_by_ref('banana', $banana);
-        $page->assign('banana_res', $res);
-
-        return PL_OK;
+               $get = Array();
+               if (!is_null($group)) {
+                       $get['group'] = $group;
+               }
+               if (!is_null($action)) {
+                       if ($action == 'new') {
+                               $get['action'] = 'new';
+                       } elseif (($action == 'reply' || $action == 'cancel') && !is_null($artid)) {
+                               $get['action'] = $action;
+                               $get['artid']  = $artid;
+                       } elseif ($action == 'from' && !is_null($artid)) {
+                               $get['first'] = $artid;
+                       } elseif ($action == 'read' && !is_null($artid)) {
+                               $get['artid'] = $artid;
+                       }
+               }
+               return BananaModule::run_banana($page, $get);
     }
 
-    function handler_profile(&$page)
+    function handler_profile(&$page, $action = null)
     {
         global $globals;
 
@@ -82,6 +90,31 @@ class BananaModule extends PLModule
 
         return PL_OK;
     }
+
+       function handler_updateall(&$page)
+       {
+               return BananaModule::run_banana($page, Array('banana' => 'updateall'));
+       }
+
+       function handler_subscription(&$page)
+       {
+               return $this->run_banana($page, Array('subscribe' => 1));
+       }
+
+       function run_banana(&$page, $params = null)
+       {
+        $page->changeTpl('banana/index.tpl');
+        $page->addCssLink('css/banana.css');
+        $page->assign('xorg_title','Polytechnique.org - Forums & PA');
+
+        require_once('banana.inc.php');
+
+        $res = PlatalBanana::run($params);
+        $page->assign_by_ref('banana', $banana);
+        $page->assign('banana_res', $res);
+
+        return PL_OK;
+       }       
 }
 
 ?>
index 33ed913..f2315c9 100644 (file)
@@ -23,7 +23,7 @@
 <h1>Options</h1>
 
 {if !$banana->profile.autoup}
-[<a href="?banana=updateall">Mettre à jour</a>]
+[<a href="{rel}/banana/updateall">Mettre à jour</a>]
 {/if}
 [<a href="{rel}/banana/profile">Profil</a>]