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