]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Add some more hooks: overview
authorValerie Pond <redacted>
Thu, 19 Jan 2023 00:56:52 +0000 (00:56 +0000)
committerValerie Pond <redacted>
Thu, 19 Jan 2023 00:56:52 +0000 (00:56 +0000)
Added HOOKTYPE_PRE_OVERVIEW_CARD and HOOKTYPE_OVERVIEW_CARD

This lets plugins use these hooks in order to add their own displays to the overview.

Classes/class-hook.php
index.php

index a5e1220dd2c0f43083277c00ecd75251610802c3..2e9eb868fc37febc45bae64d91c2d8c616858b86 100644 (file)
@@ -1,7 +1,66 @@
 <?php
 
-define('HOOKTYPE_NAVBAR', 100); /* The Hook for the navigation bar */
-define('HOOKTYPE_PRE_HEADER', 101); /* The hook for pre-header */
+/* Hook Definitions
+ * 
+ * Hooks let you do things in your plugin, like add nav items for your
+ * own pages, add extra cards to the overview and more (to come)
+ */
+/** HOOKTYPE_NAVBAR
+ * 
+ * @param array $pages
+ * Receives an array of pages. For example:
+ * $pages = ["Overview" => ""];
+ * 
+ * So when you call this hook, you must refer to the
+ * parameter by reference. For example:
+ * Hook::func(HOOKTYPE_NAVBAR, 'add_navbar_item');
+ * 
+ * function add_navbar_item(&$pages) // remember the & to use by reference
+ * { insert_hacks_here(); }
+ */
+define('HOOKTYPE_NAVBAR', 100); 
+
+/** HOOKTYPE_PRE_HEADER
+ * 
+ * This doesn't receive anything, however you must still specify an
+ * parameter for your hook function, because it's referring to memory. Sorry =]
+ * 
+ * Currently this is only used by the "sql_auth" plugin by Valware in order to
+ * redirect users immediately to the login page.
+ * 
+ * Putting HTML in this hook is not a good idea.
+ */
+define('HOOKTYPE_PRE_HEADER', 101);
+
+/** HOOKTYPE_PRE_OVERVIEW_CARD
+ * 
+ * @param object $stats
+ * 
+ * This is called before the initial cards have loaded in the overview.
+ * This lets you add your own HTML or whatever you like on the overview,
+ * new cards, whatever.
+ * 
+ * The parameter is an object containing stats used in the overview.
+ * See "index.php" to see how it's used.
+ * 
+ */
+
+define('HOOKTYPE_PRE_OVERVIEW_CARD', 102);
+/** HOOKTYPE_OVERVIEW_CARD
+ * 
+ * @param object $stats
+ * 
+ * This is called after the initial cards have loaded in the overview.
+ * This lets you add your own HTML or whatever you like on the overview,
+ * new cards, whatever.
+ * 
+ * The parameter is an object containing stats used in the overview.
+ * See "index.php" to see how it's used.
+ * 
+ */
+
+define('HOOKTYPE_OVERVIEW_CARD', 102);
 
 /** 
  *  Class for "Hook"
index 32b849dd69e7df173598c3620599dc416e131ea1..fb2cd8e49d7bf013ec7d6ee7fb4c4e89ca9dfb50 100644 (file)
--- a/index.php
+++ b/index.php
@@ -7,6 +7,8 @@ $stats = $rpc->query("stats.get", []);
 
 <h2>Network Overview</h2>
 
+<?php Hook::run(HOOKTYPE_PRE_OVERVIEW_CARD, $stats);
+
 <div class="container mt-5">
 
        <div class="row">
@@ -20,7 +22,7 @@ $stats = $rpc->query("stats.get", []);
                                                </span>
                                                </div>
                                                <div class="col">
-                                                       <h3 class="display-4"><?php echo $stats->user->total - $stats->user->ulined; ?></h3>
+                                                       <h3 class="display-4"><?php echo $stats->user->total; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -75,7 +77,6 @@ $stats = $rpc->query("stats.get", []);
                                                <div class="col">
                                                        <h6>Opers</h6>
                                                </div>
-                                               <!-- TODO: Filter opers in user list and make this do that -->
                                                <div class="col"><a class="btn btn-primary" href="<?php echo BASE_URL."users/?operonly"; ?>">View</a></div>
                                        </div>
                                </div>
@@ -217,4 +218,6 @@ $stats = $rpc->query("stats.get", []);
 
 <?php
 
+Hook::run(HOOKTYPE_OVERVIEW_CARD, $stats);
+
 require_once "footer.php";