Close #407: RSS feed for Forums and MLs
[platal.git] / classes / platal.php
index e64e4c8..ac3f982 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -19,6 +19,7 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
+define('PL_DO_AUTH',   300);
 define('PL_FORBIDDEN', 403);
 define('PL_NOT_FOUND', 404);
 
@@ -94,6 +95,10 @@ class Platal
             return $key;
         }
 
+        if (($pos = strpos($key, '.php')) !== false) {
+            $key = substr($key, 0, $pos);
+        }
+
         $has_end = in_array("#final#", $keys);
         if (strlen($key) > 24 && $has_end) {
             return "#final#";
@@ -161,7 +166,10 @@ class Platal
                 return null;
             }
         }
-        return $link;
+        if ($link != $this->path) {
+            return $link;
+        }
+        return null;
     }
 
     function call_hook(&$page)
@@ -174,10 +182,6 @@ class Platal
         $args    = $this->argv;
         $args[0] = &$page;
 
-        if (!empty($hook['perms']) && $hook['perms'] != S::v('perms')) {
-            return PL_FORBIDDEN;
-        }
-
         if ($hook['auth'] > S::v('auth', AUTH_PUBLIC)) {
             if ($hook['type'] == DO_AUTH) {
                 global $globals;
@@ -190,7 +194,20 @@ class Platal
             }
         }
 
-        return call_user_func_array($hook['hook'], $args);
+        if (!empty($hook['perms']) && $hook['perms'] != S::v('perms')) {
+            return PL_FORBIDDEN;
+        }
+
+        $val = call_user_func_array($hook['hook'], $args);
+        if ($val == PL_DO_AUTH) {
+            global $globals;
+            // The handler need a better auth with the current args
+            if (!call_user_func(array($globals->session, 'doAuth'))) {
+                $this->force_login($page);
+            }
+            $val = call_user_func_array($hook['hook'], $args);
+        }
+        return $val;
     }
 
     function force_login(&$page)
@@ -201,7 +218,8 @@ class Platal
         } else {
             $page->changeTpl('core/password_prompt.tpl');
             $page->addJsLink('do_challenge_response.js');
-       }
+        }
+        $page->assign('platal', $this);
         $page->run();
     }
 
@@ -241,4 +259,5 @@ class Platal
     }
 }
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>