0337d704 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2004 Polytechnique.org * |
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 | |
22 | // {{{ class XOrgHook |
23 | |
24 | /** |
25 | * XOrg's Hooks API |
26 | * |
27 | * Hooks are used in modules to allow modules that depends upon us to hook |
28 | * themselves in our core functionnalities. |
29 | * |
30 | * Every module will use some hools, and define their names. |
31 | * Pretend « myhook » is one of those names, then : |
32 | * - hooks/myhook/API has to exists, and will explain the API of the hook |
33 | * - every module "mod" may have a file hooks/myhook/mod.inc.php that implements |
34 | * fully or partially the API of the hook. |
35 | * |
36 | * If the hook's API has to change, the functions that change MUST change their |
37 | * name to avoid any compatibility problem. |
38 | * |
39 | * @category XOrgCore |
40 | * @package XOrgCore |
41 | * @author Pierre Habouzit <pierre.habouzit@polytechnique.org> |
42 | * @access public |
43 | * @link http://doc.polytechnique.org/XOrgModule/#hook |
44 | * @since Classe available since 0.9.3 |
45 | */ |
46 | class XOrgHook |
47 | { |
48 | // {{{ properties |
49 | |
50 | /** |
51 | * list of all the modules names that have implemented some reactions to our triggers |
52 | * |
53 | * @var array |
54 | * @access private |
55 | */ |
56 | var $_mods = Array(); |
57 | |
58 | // }}} |
59 | // {{{ constructor XOrgHook() |
60 | |
61 | /** |
62 | * Instanciates our Hook. |
63 | * |
64 | * @param string $name the name of the hook |
65 | */ |
66 | function XOrgHook() |
67 | { |
68 | global $globals; |
69 | |
70 | foreach (glob($globals->root."/hooks/*.inc.php") as $file) { |
71 | require_once("$file"); |
72 | $this->_mods[] = basename($file, '.inc.php'); |
73 | } |
74 | } |
75 | |
76 | // }}} |
77 | // {{{ function config |
78 | |
79 | function config() |
80 | { |
81 | foreach ($this->_mods as $mod) { |
82 | if (!function_exists($mod.'_config')) continue; |
83 | call_user_func($mod.'_config'); |
84 | } |
85 | } |
86 | |
87 | // }}} |
88 | // {{{ function menu |
89 | |
90 | function menu() |
91 | { |
92 | foreach ($this->_mods as $mod) { |
93 | if (!function_exists($mod.'_menu')) continue; |
94 | call_user_func($mod.'_menu'); |
95 | } |
96 | } |
97 | |
98 | // }}} |
99 | // {{{ function subscribe |
100 | |
101 | function subscribe($forlife, $uid, $promo, $pass) |
102 | { |
103 | foreach ($this->_mods as $mod) { |
104 | if (!function_exists($mod.'_subscribe')) continue; |
105 | call_user_func($mod.'_subscribe', $forlife, $uid, $promo, $pass); |
106 | } |
107 | } |
108 | |
109 | // }}} |
110 | // {{{ function prefs |
111 | |
112 | function prefs() |
113 | { |
114 | $res = Array(); |
115 | foreach ($this->_mods as $mod) { |
116 | if (!function_exists($mod.'_prefs')) continue; |
117 | $res = array_merge($res, call_user_func($mod.'_prefs')); |
118 | } |
119 | usort($res, create_function('$a, $b', 'return strcmp($a["weight"], $b["weight"]);')); |
120 | return $res; |
121 | } |
122 | |
123 | // }}} |
124 | } |
125 | |
126 | // }}} |
127 | |
128 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
129 | ?> |