Allow parenthesis before hasPerm in smarty templates
[platal.git] / classes / plmodule.php
index 92071b8..4f30acd 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -55,6 +55,29 @@ abstract class PLModule
         return new PlStdHook(array($this, 'handler_' . $fun), $auth, $perms, $type);
     }
 
+    /** Register an API hook.
+     * @param fun name of the handler (the exact name will be handler_$fun); the
+     *   handler will be invoked with a PlPage, the authenticated PlUser, the
+     *   JSON-decoded payload (if any), and the unmatched path components
+     * @param auth authentification level required, when not API-authenticated
+     * @param perms permission required to run this handler
+     * @param type additionnal flags (only NO_HTTPS is supported at the moment)
+     *
+     * See {@link make_hook} above for details on permissions.
+     *
+     * WARNING: It is expected that the API authentication mechanism will not be
+     * protected against short-term replay of requests (for instance replay of a
+     * given request within 5-10 seconds).
+     *
+     * You are explicitly advised to make any API request idempotent (eg. use
+     * "DELETE /api/email/foo@example.com" instead of "DELETE /api/email/0" to
+     * delete the first email in a list).
+     */
+    public function make_api_hook($fun, $auth, $perms = 'user', $type = NO_AUTH)
+    {
+        return new PlApiHook(array($this, 'handler_' . $fun), $auth, $perms, $type);
+    }
+
     /** Register a token-authentified hook (rss, csv, ical, ...)
      * @param fun name of the handler (the exact name will be handler_$fun); the
      *   handler will be invoked with the PlPage object, the PlUser of the
@@ -99,7 +122,7 @@ abstract class PLModule
     {
         global $globals;
         if ($modname == 'core') {
-            $mod_path = $globals->spoolroot  . '/core/modules/' . $modname;
+            $mod_path = $globals->coreroot  . '/modules/' . $modname;
         } else {
             $mod_path = $globals->spoolroot . '/modules/' . $modname;
         }
@@ -118,5 +141,5 @@ abstract class PLModule
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>