Commit | Line | Data |
---|---|---|
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 | 22 | abstract 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 | { |
46ca2746 FB |
53 | return new PlStdHook(array($this, 'handler_' . $fun), |
54 | $auth, $perms, $type); | |
b62f8858 | 55 | } |
56 | ||
bfb9093b FB |
57 | /** Register a hook that points to a wiki page. |
58 | */ | |
59 | public function make_wiki_hook($auth = AUTH_PUBLIC, $perms = 'user', $type = DO_AUTH) | |
60 | { | |
46ca2746 | 61 | return new PlWikiHook($auth, $perms, $type); |
bfb9093b FB |
62 | } |
63 | ||
24173926 FB |
64 | /** Include a 'module-specific' file. |
65 | * Module specific includes must be in the in the path modules/{modulename}. | |
66 | */ | |
67 | public function load($file) | |
68 | { | |
69 | require_once $this->modIncludePath . $file; | |
70 | } | |
71 | ||
b62f8858 | 72 | /* static functions */ |
73 | ||
ac2f544d | 74 | public static function path($modname) |
b62f8858 | 75 | { |
1edb5aa5 FB |
76 | global $globals; |
77 | if ($modname == 'core') { | |
24173926 | 78 | $mod_path = $globals->spoolroot . '/core/modules/' . $modname; |
1edb5aa5 | 79 | } else { |
24173926 | 80 | $mod_path = $globals->spoolroot . '/modules/' . $modname; |
1edb5aa5 | 81 | } |
ac2f544d FB |
82 | return $mod_path; |
83 | } | |
84 | ||
85 | public static function factory($modname) | |
86 | { | |
87 | $mod_path = self::path($modname); | |
a18afbdc | 88 | $class = ucfirst($modname) . 'Module'; |
b62f8858 | 89 | |
24173926 FB |
90 | require_once $mod_path . '.php'; |
91 | $module = new $class(); | |
92 | $module->modIncludePath = $mod_path . '/'; | |
93 | return $module; | |
b62f8858 | 94 | } |
95 | } | |
96 | ||
a7de4ef7 | 97 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
b62f8858 | 98 | ?> |