]>
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 * Currently this is only used by the "sql_auth" plugin by Valware in order to
29 * redirect users immediately to the login page.
31 * Putting HTML in this hook is not a good idea.
33 define('HOOKTYPE_PRE_HEADER', 101);
35 /** HOOKTYPE_PRE_OVERVIEW_CARD
37 * @param object $stats
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.
43 * The parameter is an object containing stats used in the overview.
44 * See "index.php" to see how it's used.
47 define('HOOKTYPE_PRE_OVERVIEW_CARD', 102);
49 /** HOOKTYPE_OVERVIEW_CARD
51 * @param object $stats
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.
57 * The parameter is an object containing stats used in the overview.
58 * See "index.php" to see how it's used.
61 define('HOOKTYPE_OVERVIEW_CARD', 103);
63 /** HOOKTYPE_NOTIFICATION
65 * @param array $notification
66 * The array should contain:
68 * "name" - The name of the recipient
69 * "message" - The notification message
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.
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
82 define('HOOKTYPE_NOTIFICATION', 104);
85 /** HOOKTYPE_PRE_FOOTER
86 * $param array $empty - Doesn't do anything
88 * This runs inside the footer body before anything else.
90 define('HOOKTYPE_PRE_FOOTER', 105);
93 * $param array $empty - Doesn't do anything
95 * This runs inside the footer body after everything else.
97 define('HOOKTYPE_FOOTER', 106);
101 * This is the main function which gets called whenever you want to use a Hook.
104 * Calling the Hook using a function:
105 * Hook::func(HOOKTYPE_NAVBAR, 'bob');
107 * This Hook references the function 'bob', and will run this
110 * echo "We rehashed!";
114 * Calling the Hook using an initialized object class method:
115 * Hook::func(HOOKTYPE_NAVBAR, [$this, 'method']);
118 * Calling the Hook using a static class method:
119 * Hook::func(HOOKTYPE_NAVBAR, 'classname::method');
124 /** A static list of Hooks and their associated functions */
125 private static $actions = [];
128 * The parameter for $Hook should be a "HOOKTYPE_" as defined in hook.php
129 * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH.
130 * @param array &$args The array of information you are sending along in the Hook, so that other functions may see and modify things.
131 * @return void Does not return anything.
134 public static function run($Hook, &$args = array())
136 if (!empty(self
::$actions[$Hook]))
137 foreach (self
::$actions[$Hook] as &$f)
143 * @param string $Hook The define or string name of the Hook. For example, HOOKTYPE_REHASH.
144 * @param string|Closure $function This is a string reference to a Closure function or a class method.
145 * @return void Does not return anything.
147 public static function func($Hook, $function)
149 self
::$actions[$Hook][] = $function;
153 * @param string $Hook The Hook from which we are removing a function reference.
154 * @param string $function The name of the function that we are removing.
155 * @return void Does not reuturn anything.
158 public static function del($Hook, $function)
160 for ($i = 0; isset(self
::$actions[$Hook][$i]); $i++
)
161 if (self
::$actions[$Hook][$i] == $function)
162 array_splice(self
::$actions[$Hook],$i);