]>
Commit | Line | Data |
---|---|---|
90dc8f2b VP |
1 | <?php |
2 | ||
440ff671 | 3 | /* Hook Definitions |
33f512fa VP |
4 | * |
5 | * Hooks let you do things in your plugin, like add nav items for your | |
6 | * own pages, add extra cards to the overview and more (to come) | |
7 | */ | |
440ff671 VP |
8 | /** HOOKTYPE_NAVBAR |
9 | * | |
10 | * @param array $pages | |
11 | * Receives an array of pages. For example: | |
12 | * $pages = ["Overview" => ""]; | |
13 | * | |
14 | * So when you call this hook, you must refer to the | |
15 | * parameter by reference. For example: | |
16 | * Hook::func(HOOKTYPE_NAVBAR, 'add_navbar_item'); | |
17 | * | |
18 | * function add_navbar_item(&$pages) // remember the & to use by reference | |
19 | * { insert_hacks_here(); } | |
20 | */ | |
21 | define('HOOKTYPE_NAVBAR', 100); | |
22 | ||
23 | /** HOOKTYPE_PRE_HEADER | |
24 | * | |
25 | * This doesn't receive anything, however you must still specify an | |
26 | * parameter for your hook function, because it's referring to memory. Sorry =] | |
27 | * | |
440ff671 VP |
28 | * Putting HTML in this hook is not a good idea. |
29 | */ | |
30 | define('HOOKTYPE_PRE_HEADER', 101); | |
31 | ||
e847862e VP |
32 | /** HOOKTYPE_HEADER |
33 | * | |
34 | * This is run after/during the header is sent. You can call your global scripts, global css or whatnot from here. | |
35 | */ | |
36 | define('HOOKTYPE_HEADER', 119); | |
37 | ||
440ff671 VP |
38 | /** HOOKTYPE_PRE_OVERVIEW_CARD |
39 | * | |
40 | * @param object $stats | |
41 | * | |
42 | * This is called before the initial cards have loaded in the overview. | |
43 | * This lets you add your own HTML or whatever you like on the overview, | |
44 | * new cards, whatever. | |
45 | * | |
46 | * The parameter is an object containing stats used in the overview. | |
47 | * See "index.php" to see how it's used. | |
48 | * | |
49 | */ | |
440ff671 | 50 | define('HOOKTYPE_PRE_OVERVIEW_CARD', 102); |
33f512fa | 51 | |
440ff671 VP |
52 | /** HOOKTYPE_OVERVIEW_CARD |
53 | * | |
54 | * @param object $stats | |
55 | * | |
56 | * This is called after the initial cards have loaded in the overview. | |
57 | * This lets you add your own HTML or whatever you like on the overview, | |
58 | * new cards, whatever. | |
59 | * | |
60 | * The parameter is an object containing stats used in the overview. | |
61 | * See "index.php" to see how it's used. | |
62 | * | |
33f512fa VP |
63 | */ |
64 | define('HOOKTYPE_OVERVIEW_CARD', 103); | |
440ff671 | 65 | |
33f512fa VP |
66 | /** HOOKTYPE_NOTIFICATION |
67 | * | |
68 | * @param array $notification | |
69 | * The array should contain: | |
70 | * | |
71 | * "name" - The name of the recipient | |
72 | * "message" - The notification message | |
73 | * | |
74 | * This does not do anything special by itself. It simply allows plugins | |
75 | * to be able to use it with regards to notification sending. | |
76 | * This is not run at any place, but should be run from your plugin. | |
77 | * | |
78 | * This hook is simple in design and only contains two elements in attempt | |
79 | * to make it work cross-plugin. That is, if you have implemented your own | |
80 | * notificiation system, you will be able to do whatever you like such as | |
81 | * display a navbar list of notifications or send important emails by running | |
82 | * this hook. | |
83 | * | |
84 | */ | |
85 | define('HOOKTYPE_NOTIFICATION', 104); | |
0c2d6a6a | 86 | |
90dc8f2b | 87 | |
33f512fa | 88 | /** HOOKTYPE_PRE_FOOTER |
6930484c | 89 | * @param array $empty - Doesn't do anything |
33f512fa VP |
90 | * |
91 | * This runs inside the footer body before anything else. | |
92 | */ | |
93 | define('HOOKTYPE_PRE_FOOTER', 105); | |
94 | ||
95 | /** HOOKTYPE_FOOTER | |
6930484c | 96 | * @param array $empty - Doesn't do anything |
33f512fa VP |
97 | * |
98 | * This runs inside the footer body after everything else. | |
99 | */ | |
100 | define('HOOKTYPE_FOOTER', 106); | |
6930484c VP |
101 | |
102 | /** HOOKTYPE_USER_LOOKUP | |
103 | * @param array $user [name, id] | |
104 | */ | |
105 | define('HOOKTYPE_USER_LOOKUP', 107); | |
106 | ||
107 | /** HOOKTYPE_USERMETA_ADD | |
108 | * @param array $meta [[id, key, value], (object)PanelUser] | |
109 | */ | |
110 | define('HOOKTYPE_USERMETA_ADD', 108); | |
111 | ||
112 | /** HOOKTYPE_USERMETA_ADD | |
113 | * @param array $meta [id, key, value] | |
114 | */ | |
115 | define('HOOKTYPE_USERMETA_DEL', 109); | |
116 | ||
117 | /** HOOKTYPE_USERMETA_ADD | |
118 | * @param array $meta [id, key, value] | |
119 | */ | |
120 | define('HOOKTYPE_USERMETA_GET', 110); | |
180b8ec1 VP |
121 | |
122 | /** HOOKTYPE_USER_CREATE | |
123 | * @param array $userinfo [] | |
124 | */ | |
125 | define('HOOKTYPE_USER_CREATE', 111); | |
126 | ||
e8b225fd VP |
127 | /** HOOKTYPE_GET_USER_LIST |
128 | * @param array $userlist [] | |
129 | */ | |
180b8ec1 VP |
130 | define('HOOKTYPE_GET_USER_LIST', 112); |
131 | ||
132 | define('HOOKTYPE_USER_DELETE', 113); | |
c44f6efa VP |
133 | |
134 | define('HOOKTYPE_USER_LOGIN', 114); | |
135 | ||
136 | define('HOOKTYPE_USER_LOGIN_FAIL', 115); | |
2405dc8e VP |
137 | |
138 | define('HOOKTYPE_USER_PERMISSION_LIST', 116); | |
5a7f0cde VP |
139 | |
140 | define('HOOKTYPE_EDIT_USER', 117); | |
c00c34d2 | 141 | |
e8b225fd VP |
142 | define('HOOKTYPE_RIGHTCLICK_MENU', 118); |
143 | ||
e847862e VP |
144 | /* 119 = HOOKTYPE_HEADER (See under HOOKTYPE_PRE_HEADER) */ |
145 | ||
ee8927ad VP |
146 | define('HOOKTYPE_GENERAL_SETTINGS', 120); |
147 | ||
f2e07243 VP |
148 | /* Array passed is $_POST[] */ |
149 | define('HOOKTYPE_GENERAL_SETTINGS_POST', 121); | |
150 | ||
151 | ||
152 | ||
e847862e | 153 | /** Send out a request to ask if there are any plugins which provide authentication */ |
e1461204 | 154 | define('HOOKTYPE_AUTH_MOD', 200); |
c00c34d2 | 155 | |
e1461204 BM |
156 | /** An upgrade has been detected. |
157 | * @param array $versioninfo[] | |
158 | * Array contains: "old_version" and "new_version" | |
159 | */ | |
160 | define('HOOKTYPE_UPGRADE', 201); | |
c00c34d2 | 161 | |
90dc8f2b VP |
162 | /** |
163 | * Class for "Hook" | |
164 | * This is the main function which gets called whenever you want to use a Hook. | |
165 | * | |
166 | * Example: | |
167 | * Calling the Hook using a function: | |
168 | * Hook::func(HOOKTYPE_NAVBAR, 'bob'); | |
169 | * | |
170 | * This Hook references the function 'bob', and will run this | |
171 | * function bob | |
172 | * { | |
173 | * echo "We rehashed!"; | |
174 | * } | |
175 | * | |
176 | * Example 2: | |
177 | * Calling the Hook using an initialized object class method: | |
178 | * Hook::func(HOOKTYPE_NAVBAR, [$this, 'method']); | |
179 | * | |
180 | * Example 3: | |
181 | * Calling the Hook using a static class method: | |
fe2a6f27 | 182 | * Hook::func(HOOKTYPE_NAVBAR, 'classname::method'); |
90dc8f2b VP |
183 | * |
184 | */ | |
185 | class Hook { | |
186 | ||
187 | /** A static list of Hooks and their associated functions */ | |
188 | private static $actions = []; | |
189 | ||
190 | /** Runs a Hook. | |
191 | * The parameter for $Hook should be a "HOOKTYPE_" as defined in hook.php | |
192 | * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH. | |
193 | * @param array &$args The array of information you are sending along in the Hook, so that other functions may see and modify things. | |
194 | * @return void Does not return anything. | |
195 | * | |
196 | */ | |
197 | public static function run($Hook, &$args = array()) | |
198 | { | |
371aa651 VP |
199 | if (!empty(self::$actions[$Hook])) |
200 | foreach (self::$actions[$Hook] as &$f) | |
201 | $f($args); | |
202 | ||
90dc8f2b VP |
203 | } |
204 | ||
205 | /** Calls a Hook | |
206 | * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH. | |
207 | * @param string|Closure $function This is a string reference to a Closure function or a class method. | |
208 | * @return void Does not return anything. | |
209 | */ | |
210 | public static function func($Hook, $function) | |
371aa651 | 211 | { |
90dc8f2b VP |
212 | self::$actions[$Hook][] = $function; |
213 | } | |
214 | ||
215 | /** Deletes a Hook | |
216 | * @param string $Hook The Hook from which we are removing a function reference. | |
217 | * @param string $function The name of the function that we are removing. | |
218 | * @return void Does not reuturn anything. | |
219 | */ | |
90dc8f2b | 220 | public static function del($Hook, $function) |
371aa651 | 221 | { |
90dc8f2b | 222 | for ($i = 0; isset(self::$actions[$Hook][$i]); $i++) |
371aa651 VP |
223 | if (self::$actions[$Hook][$i] == $function) |
224 | array_splice(self::$actions[$Hook],$i); | |
90dc8f2b VP |
225 | } |
226 | } |