]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - Classes/class-hook.php
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)
11 * Receives an array of pages. For example:
12 * $pages = ["Overview" => ""];
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');
18 * function add_navbar_item(&$pages) // remember the & to use by reference
19 * { insert_hacks_here(); }
21 define('HOOKTYPE_NAVBAR', 100);
23 /** HOOKTYPE_PRE_HEADER
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 =]
28 * Putting HTML in this hook is not a good idea.
30 define('HOOKTYPE_PRE_HEADER', 101);
34 * This is run after/during the header is sent. You can call your global scripts, global css or whatnot from here.
36 define('HOOKTYPE_HEADER', 119);
38 /** HOOKTYPE_PRE_OVERVIEW_CARD
40 * @param object $stats
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.
46 * The parameter is an object containing stats used in the overview.
47 * See "index.php" to see how it's used.
50 define('HOOKTYPE_PRE_OVERVIEW_CARD', 102);
52 /** HOOKTYPE_OVERVIEW_CARD
54 * @param object $stats
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.
60 * The parameter is an object containing stats used in the overview.
61 * See "index.php" to see how it's used.
64 define('HOOKTYPE_OVERVIEW_CARD', 103);
66 /** HOOKTYPE_NOTIFICATION
68 * @param array $notification
69 * The array should contain:
71 * "name" - The name of the recipient
72 * "message" - The notification message
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.
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
85 define('HOOKTYPE_NOTIFICATION', 104);
88 /** HOOKTYPE_PRE_FOOTER
89 * @param array $empty - Doesn't do anything
91 * This runs inside the footer body before anything else.
93 define('HOOKTYPE_PRE_FOOTER', 105);
96 * @param array $empty - Doesn't do anything
98 * This runs inside the footer body after everything else.
100 define('HOOKTYPE_FOOTER', 106);
102 /** HOOKTYPE_USER_LOOKUP
103 * @param array $user [name, id]
105 define('HOOKTYPE_USER_LOOKUP', 107);
107 /** HOOKTYPE_USERMETA_ADD
108 * @param array $meta [[id, key, value], (object)PanelUser]
110 define('HOOKTYPE_USERMETA_ADD', 108);
112 /** HOOKTYPE_USERMETA_ADD
113 * @param array $meta [id, key, value]
115 define('HOOKTYPE_USERMETA_DEL', 109);
117 /** HOOKTYPE_USERMETA_ADD
118 * @param array $meta [id, key, value]
120 define('HOOKTYPE_USERMETA_GET', 110);
122 /** HOOKTYPE_USER_CREATE
123 * @param array $userinfo []
125 define('HOOKTYPE_USER_CREATE', 111);
127 /** HOOKTYPE_GET_USER_LIST
128 * @param array $userlist []
130 define('HOOKTYPE_GET_USER_LIST', 112);
132 define('HOOKTYPE_USER_DELETE', 113);
134 define('HOOKTYPE_USER_LOGIN', 114);
136 define('HOOKTYPE_USER_LOGIN_FAIL', 115);
138 define('HOOKTYPE_USER_PERMISSION_LIST', 116);
140 define('HOOKTYPE_EDIT_USER', 117);
142 define('HOOKTYPE_RIGHTCLICK_MENU', 118);
144 /* 119 = HOOKTYPE_HEADER (See under HOOKTYPE_PRE_HEADER) */
146 define('HOOKTYPE_GENERAL_SETTINGS', 120);
148 /* Array passed is $_POST[] */
149 define('HOOKTYPE_GENERAL_SETTINGS_POST', 121);
153 /** Send out a request to ask if there are any plugins which provide authentication */
154 define('HOOKTYPE_AUTH_MOD', 200);
156 /** An upgrade has been detected.
157 * @param array $versioninfo[]
158 * Array contains: "old_version" and "new_version"
160 define('HOOKTYPE_UPGRADE', 201);
164 * This is the main function which gets called whenever you want to use a Hook.
167 * Calling the Hook using a function:
168 * Hook::func(HOOKTYPE_NAVBAR, 'bob');
170 * This Hook references the function 'bob', and will run this
173 * echo "We rehashed!";
177 * Calling the Hook using an initialized object class method:
178 * Hook::func(HOOKTYPE_NAVBAR, [$this, 'method']);
181 * Calling the Hook using a static class method:
182 * Hook::func(HOOKTYPE_NAVBAR, 'classname::method');
187 /** A static list of Hooks and their associated functions */
188 private static $actions = [];
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.
197 public static function run($Hook, &$args = array())
199 if (!empty(self
::$actions[$Hook]))
200 foreach (self
::$actions[$Hook] as &$f)
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.
210 public static function func($Hook, $function)
212 self
::$actions[$Hook][] = $function;
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.
220 public static function del($Hook, $function)
222 for ($i = 0; isset(self
::$actions[$Hook][$i]); $i++
)
223 if (self
::$actions[$Hook][$i] == $function)
224 array_splice(self
::$actions[$Hook],$i);