]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | /* Hook Definitions | |
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 | */ | |
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 | * | |
28 | * Putting HTML in this hook is not a good idea. | |
29 | */ | |
30 | define('HOOKTYPE_PRE_HEADER', 101); | |
31 | ||
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 | ||
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 | */ | |
50 | define('HOOKTYPE_PRE_OVERVIEW_CARD', 102); | |
51 | ||
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 | * | |
63 | */ | |
64 | define('HOOKTYPE_OVERVIEW_CARD', 103); | |
65 | ||
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); | |
86 | ||
87 | ||
88 | /** HOOKTYPE_PRE_FOOTER | |
89 | * @param array $empty - Doesn't do anything | |
90 | * | |
91 | * This runs inside the footer body before anything else. | |
92 | */ | |
93 | define('HOOKTYPE_PRE_FOOTER', 105); | |
94 | ||
95 | /** HOOKTYPE_FOOTER | |
96 | * @param array $empty - Doesn't do anything | |
97 | * | |
98 | * This runs inside the footer body after everything else. | |
99 | */ | |
100 | define('HOOKTYPE_FOOTER', 106); | |
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); | |
121 | ||
122 | /** HOOKTYPE_USER_CREATE | |
123 | * @param array $userinfo [] | |
124 | */ | |
125 | define('HOOKTYPE_USER_CREATE', 111); | |
126 | ||
127 | /** HOOKTYPE_GET_USER_LIST | |
128 | * @param array $userlist [] | |
129 | */ | |
130 | define('HOOKTYPE_GET_USER_LIST', 112); | |
131 | ||
132 | define('HOOKTYPE_USER_DELETE', 113); | |
133 | ||
134 | define('HOOKTYPE_USER_LOGIN', 114); | |
135 | ||
136 | define('HOOKTYPE_USER_LOGIN_FAIL', 115); | |
137 | ||
138 | define('HOOKTYPE_USER_PERMISSION_LIST', 116); | |
139 | ||
140 | define('HOOKTYPE_EDIT_USER', 117); | |
141 | ||
142 | define('HOOKTYPE_RIGHTCLICK_MENU', 118); | |
143 | ||
144 | /* 119 = HOOKTYPE_HEADER (See under HOOKTYPE_PRE_HEADER) */ | |
145 | ||
146 | define('HOOKTYPE_GENERAL_SETTINGS', 120); | |
147 | ||
148 | /* Array passed is $_POST[] */ | |
149 | define('HOOKTYPE_GENERAL_SETTINGS_POST', 121); | |
150 | ||
151 | ||
152 | ||
153 | /** Send out a request to ask if there are any plugins which provide authentication */ | |
154 | define('HOOKTYPE_AUTH_MOD', 200); | |
155 | ||
156 | /** An upgrade has been detected. | |
157 | * @param array $versioninfo[] | |
158 | * Array contains: "old_version" and "new_version" | |
159 | */ | |
160 | define('HOOKTYPE_UPGRADE', 201); | |
161 | ||
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: | |
182 | * Hook::func(HOOKTYPE_NAVBAR, 'classname::method'); | |
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 | { | |
199 | if (!empty(self::$actions[$Hook])) | |
200 | foreach (self::$actions[$Hook] as &$f) | |
201 | $f($args); | |
202 | ||
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) | |
211 | { | |
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 | */ | |
220 | public static function del($Hook, $function) | |
221 | { | |
222 | for ($i = 0; isset(self::$actions[$Hook][$i]); $i++) | |
223 | if (self::$actions[$Hook][$i] == $function) | |
224 | array_splice(self::$actions[$Hook],$i); | |
225 | } | |
226 | } |