X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplmodule.php;h=4f30acd4ff67605c04c55d82f1563c330d607cb2;hb=75b5406387c0c362517dd905d561f7b616dddc96;hp=4e1229bb38d771c8e8e09a64dd286b99465a672c;hpb=ac2f544d3ee0cfe67fc61759f0f6f72dec7e1cc9;p=platal.git diff --git a/classes/plmodule.php b/classes/plmodule.php index 4e1229b..4f30acd 100644 --- a/classes/plmodule.php +++ b/classes/plmodule.php @@ -1,6 +1,6 @@ array($this, 'handler_'.$fun), - 'auth' => $auth, - 'perms' => $perms, - 'type' => $type); + 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 + * request, and the unmatched path components + * @param auth authentification level required, when not token-authentified + * @param perms permission required to run this handler + * @param type additionnal flags + * + * See {@link make_hook} above for details on permissions and additional + * flags. Note that DO_AUTH has no effect here, as the request will always + * be passively identified. + * + * This hook requires that the first two unmatched path components form a + * valid (user, token) pair; if not, a session-based authentification will + * be attempted, in which case $auth will be honored. + * Note that because token-based authentication is weak, it should only be + * used for readonly handlers normally served in AUTH_COOKIE. + */ + public function make_token_hook($fun, $auth, $perms = 'user', $type = NO_HTTPS) + { + return new PlTokenHook(array($this, 'handler_' . $fun), $auth, $perms, $type); + } + + /** Register a hook that points to a wiki page. + */ + public function make_wiki_hook($auth = AUTH_PUBLIC, $perms = 'user', $type = DO_AUTH) + { + return new PlWikiHook($auth, $perms, $type); } /** Include a 'module-specific' file. @@ -70,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; } @@ -89,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: ?>