]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - Classes/class-hook.php
Logs: show search pane (on desktop)
[irc/unrealircd/unrealircd-webpanel.git] / Classes / class-hook.php
CommitLineData
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 */
21define('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 *
ce25dde2 28 * Currently this is only used by the "sql_db" plugin by Valware in order to
440ff671
VP
29 * redirect users immediately to the login page.
30 *
31 * Putting HTML in this hook is not a good idea.
32 */
33define('HOOKTYPE_PRE_HEADER', 101);
34
35/** HOOKTYPE_PRE_OVERVIEW_CARD
36 *
37 * @param object $stats
38 *
39 * This is called before the initial cards have loaded in the overview.
40 * This lets you add your own HTML or whatever you like on the overview,
41 * new cards, whatever.
42 *
43 * The parameter is an object containing stats used in the overview.
44 * See "index.php" to see how it's used.
45 *
46 */
440ff671 47define('HOOKTYPE_PRE_OVERVIEW_CARD', 102);
33f512fa 48
440ff671
VP
49/** HOOKTYPE_OVERVIEW_CARD
50 *
51 * @param object $stats
52 *
53 * This is called after the initial cards have loaded in the overview.
54 * This lets you add your own HTML or whatever you like on the overview,
55 * new cards, whatever.
56 *
57 * The parameter is an object containing stats used in the overview.
58 * See "index.php" to see how it's used.
59 *
33f512fa
VP
60*/
61define('HOOKTYPE_OVERVIEW_CARD', 103);
440ff671 62
33f512fa
VP
63/** HOOKTYPE_NOTIFICATION
64 *
65 * @param array $notification
66 * The array should contain:
67 *
68 * "name" - The name of the recipient
69 * "message" - The notification message
70 *
71 * This does not do anything special by itself. It simply allows plugins
72 * to be able to use it with regards to notification sending.
73 * This is not run at any place, but should be run from your plugin.
74 *
75 * This hook is simple in design and only contains two elements in attempt
76 * to make it work cross-plugin. That is, if you have implemented your own
77 * notificiation system, you will be able to do whatever you like such as
78 * display a navbar list of notifications or send important emails by running
79 * this hook.
80 *
81*/
82define('HOOKTYPE_NOTIFICATION', 104);
0c2d6a6a 83
90dc8f2b 84
33f512fa 85/** HOOKTYPE_PRE_FOOTER
6930484c 86 * @param array $empty - Doesn't do anything
33f512fa
VP
87 *
88 * This runs inside the footer body before anything else.
89 */
90define('HOOKTYPE_PRE_FOOTER', 105);
91
92/** HOOKTYPE_FOOTER
6930484c 93 * @param array $empty - Doesn't do anything
33f512fa
VP
94 *
95 * This runs inside the footer body after everything else.
96 */
97define('HOOKTYPE_FOOTER', 106);
6930484c
VP
98
99/** HOOKTYPE_USER_LOOKUP
100 * @param array $user [name, id]
101 */
102define('HOOKTYPE_USER_LOOKUP', 107);
103
104/** HOOKTYPE_USERMETA_ADD
105 * @param array $meta [[id, key, value], (object)PanelUser]
106 */
107define('HOOKTYPE_USERMETA_ADD', 108);
108
109/** HOOKTYPE_USERMETA_ADD
110 * @param array $meta [id, key, value]
111 */
112define('HOOKTYPE_USERMETA_DEL', 109);
113
114/** HOOKTYPE_USERMETA_ADD
115 * @param array $meta [id, key, value]
116 */
117define('HOOKTYPE_USERMETA_GET', 110);
180b8ec1
VP
118
119/** HOOKTYPE_USER_CREATE
120 * @param array $userinfo []
121 */
122define('HOOKTYPE_USER_CREATE', 111);
123
124define('HOOKTYPE_GET_USER_LIST', 112);
125
126define('HOOKTYPE_USER_DELETE', 113);
c44f6efa
VP
127
128define('HOOKTYPE_USER_LOGIN', 114);
129
130define('HOOKTYPE_USER_LOGIN_FAIL', 115);
2405dc8e
VP
131
132define('HOOKTYPE_USER_PERMISSION_LIST', 116);
5a7f0cde
VP
133
134define('HOOKTYPE_EDIT_USER', 117);
c00c34d2 135
4b48b46f
VP
136define('HOOKTYPE_USER_ROLE_LIST', 118);
137
138define('HOOKTYPE_EDIT_ROLE', 119);
139
088733d4
VP
140define('HOOKTYPE_ADD_ROLE', 120);
141
142define('HOOKTYPE_DEL_ROLE', 121);
143
e1461204 144define('HOOKTYPE_AUTH_MOD', 200);
c00c34d2 145
e1461204
BM
146/** An upgrade has been detected.
147 * @param array $versioninfo[]
148 * Array contains: "old_version" and "new_version"
149 */
150define('HOOKTYPE_UPGRADE', 201);
c00c34d2 151
90dc8f2b
VP
152/**
153 * Class for "Hook"
154 * This is the main function which gets called whenever you want to use a Hook.
155 *
156 * Example:
157 * Calling the Hook using a function:
158 * Hook::func(HOOKTYPE_NAVBAR, 'bob');
159 *
160 * This Hook references the function 'bob', and will run this
161 * function bob
162 * {
163 * echo "We rehashed!";
164 * }
165 *
166 * Example 2:
167 * Calling the Hook using an initialized object class method:
168 * Hook::func(HOOKTYPE_NAVBAR, [$this, 'method']);
169 *
170 * Example 3:
171 * Calling the Hook using a static class method:
fe2a6f27 172 * Hook::func(HOOKTYPE_NAVBAR, 'classname::method');
90dc8f2b
VP
173 *
174 */
175class Hook {
176
177 /** A static list of Hooks and their associated functions */
178 private static $actions = [];
179
180 /** Runs a Hook.
181 * The parameter for $Hook should be a "HOOKTYPE_" as defined in hook.php
182 * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH.
183 * @param array &$args The array of information you are sending along in the Hook, so that other functions may see and modify things.
184 * @return void Does not return anything.
185 *
186 */
187 public static function run($Hook, &$args = array())
188 {
371aa651
VP
189 if (!empty(self::$actions[$Hook]))
190 foreach (self::$actions[$Hook] as &$f)
191 $f($args);
192
90dc8f2b
VP
193 }
194
195 /** Calls a Hook
196 * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH.
197 * @param string|Closure $function This is a string reference to a Closure function or a class method.
198 * @return void Does not return anything.
199 */
200 public static function func($Hook, $function)
371aa651 201 {
90dc8f2b
VP
202 self::$actions[$Hook][] = $function;
203 }
204
205 /** Deletes a Hook
206 * @param string $Hook The Hook from which we are removing a function reference.
207 * @param string $function The name of the function that we are removing.
208 * @return void Does not reuturn anything.
209 */
90dc8f2b 210 public static function del($Hook, $function)
371aa651 211 {
90dc8f2b 212 for ($i = 0; isset(self::$actions[$Hook][$i]); $i++)
371aa651
VP
213 if (self::$actions[$Hook][$i] == $function)
214 array_splice(self::$actions[$Hook],$i);
90dc8f2b
VP
215 }
216}