Add possibility to declare wiki hooks.
[platal.git] / classes / plmodule.php
CommitLineData
b62f8858 1<?php
2/***************************************************************************
2ab75571 3 * Copyright (C) 2003-2010 Polytechnique.org *
b62f8858 4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
bf517daf 22abstract class PLModule
b62f8858 23{
24173926
FB
24 /** Path of the includes of the module
25 * Internal use only.
26 */
27 private $modIncludePath;
28
29 /** Return an array associating pathes to the corresponding hook.
30 * array( '/my/path' => make_hook(...),
31 * ...);
32 * @ref make_hook
33 */
34 abstract public function handlers();
b62f8858 35
bf517daf 36 /** Register a hook
37 * @param fun name of the handler (the exact name will be handler_$fun)
38 * @param auth authentification level of needed to run this handler
39 * @param perms permission required to run this handler
40 * @param type additionnal flags
41 *
42 * Perms syntax is the following:
43 * perms = rights(,rights)*
44 * rights = right(:right)*
45 * right is an atomic right permission (like 'admin', 'user', 'groupadmin', 'groupmember'...)
46 *
47 * If type is set to NO_AUTH, the system will return 403 instead of asking auth data
8fc4efa3 48 * this is useful for Ajax handler
49 * If type is not set to NO_SKIN, the system will consider redirecting the user to https
bf517daf 50 */
51 public function make_hook($fun, $auth, $perms = 'user', $type = DO_AUTH)
b62f8858 52 {
4a5fb34b 53 return array('hook' => array($this, 'handler_'.$fun),
b62f8858 54 'auth' => $auth,
4a5fb34b 55 'perms' => $perms,
b62f8858 56 'type' => $type);
57 }
58
bfb9093b
FB
59 /** Register a hook that points to a wiki page.
60 */
61 public function make_wiki_hook($auth = AUTH_PUBLIC, $perms = 'user', $type = DO_AUTH)
62 {
63 return Platal::wiki_hook($auth, $perms, $type);
64 }
65
24173926
FB
66 /** Include a 'module-specific' file.
67 * Module specific includes must be in the in the path modules/{modulename}.
68 */
69 public function load($file)
70 {
71 require_once $this->modIncludePath . $file;
72 }
73
b62f8858 74 /* static functions */
75
ac2f544d 76 public static function path($modname)
b62f8858 77 {
1edb5aa5
FB
78 global $globals;
79 if ($modname == 'core') {
24173926 80 $mod_path = $globals->spoolroot . '/core/modules/' . $modname;
1edb5aa5 81 } else {
24173926 82 $mod_path = $globals->spoolroot . '/modules/' . $modname;
1edb5aa5 83 }
ac2f544d
FB
84 return $mod_path;
85 }
86
87 public static function factory($modname)
88 {
89 $mod_path = self::path($modname);
a18afbdc 90 $class = ucfirst($modname) . 'Module';
b62f8858 91
24173926
FB
92 require_once $mod_path . '.php';
93 $module = new $class();
94 $module->modIncludePath = $mod_path . '/';
95 return $module;
b62f8858 96 }
97}
98
a7de4ef7 99// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
b62f8858 100?>