]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - plugins.php
Make Plugins page accessible only to permission holders
[irc/unrealircd/unrealircd-webpanel.git] / plugins.php
CommitLineData
90dc8f2b 1<?php
c06c1713 2require_once "inc/common.php";
90dc8f2b
VP
3require_once "Classes/class-message.php";
4
5
6/** Check for plugins and load them.
7 *
8 * This expects your plugin folder to be located in `plugins/` and that the directory name,
9 * constructor file name and class name are identical.
10 * For example:
11 * You must have a file structure like this: plugins/myplugin/myplugin.php
12 * Which contains a class like this:
13 * ```
14 * class myplugin {
55fd88eb
VP
15 * $name = "My plugin";
16 * $author = "Joe Bloggs";
17 * $version "1.0";
18 * $desc = "This is my plugin and it does stuff";
19 *
20 * // rest of code here...
90dc8f2b
VP
21 * }
22 * ```
23 * Your plugin class must be constructable and contain the following public variables:
55fd88eb 24 * $name The name or title of your plugin.
90dc8f2b
VP
25 * $author The name of the author
26 * $version The version of the plugin
55fd88eb 27 * $description A short description of the plugin
90dc8f2b
VP
28*/
29class Plugins
30{
55fd88eb 31 static $list = [];
90dc8f2b 32
55fd88eb
VP
33 static function load($modname)
34 {
35 $plugin = new Plugin($modname);
36 if ($plugin->error)
37 {
38 Message::Fail("Warning: Plugin \"$modname\" failed to load: $plugin->error");
39 }
40 else
41 {
42 self::$list[] = $plugin;
43 }
44 }
4f3f84af
VP
45 static function plugin_exists($name, $version = NULL)
46 {
47 foreach(self::$list as $p)
e47cb29f 48 if (!strcmp($p->name,$name) && (!$version || ($version >= $p->version)))
4f3f84af
VP
49 return true;
50
51 return false;
52 }
53
90dc8f2b
VP
54}
55
56class Plugin
57{
55fd88eb
VP
58 public $name;
59 public $author;
60 public $version;
61 public $description;
62 public $handle;
b65f0496 63 public $email;
90dc8f2b 64
55fd88eb
VP
65 public $error = NULL;
66 function __construct($handle)
67 {
195214b2
VP
68 if (!is_dir(UPATH."/plugins/$handle"))
69 $this->error = "Plugin directory \"".UPATH."/plugins/$handle\" doesn't exist";
90dc8f2b 70
195214b2
VP
71 else if (!is_file(UPATH."/plugins/$handle/$handle.php"))
72 $this->error = "Plugin file \"".UPATH."/plugins/$handle/$handle.php\" doesn't exist";
90dc8f2b 73
55fd88eb
VP
74 else
75 {
93a3dfcb 76 require_once UPATH."/plugins/$handle/$handle.php";
90dc8f2b 77
55fd88eb
VP
78 if (!class_exists($handle))
79 $this->error = "Class \"$handle\" doesn't exist";
90dc8f2b 80
55fd88eb
VP
81 else
82 {
83 $plugin = new $handle();
84
85 if (!isset($plugin->name))
86 $this->error = "Plugin name not defined";
87 elseif (!isset($plugin->author))
88 $this->error = "Plugin author not defined";
89 elseif (!isset($plugin->version))
90 $this->error = "Plugin version not defined";
91 elseif (!isset($plugin->description))
92 $this->error = "Plugin description not defined";
b65f0496
VP
93 elseif (!isset($plugin->email))
94 $this->error = "Plugin email not defined";
55fd88eb
VP
95 else
96 {
97 $this->handle = $handle;
98 $this->name = $plugin->name;
99 $this->author = $plugin->author;
100 $this->version = $plugin->version;
101 $this->description = $plugin->description;
b65f0496 102 $this->email = $plugin->email;
55fd88eb
VP
103 }
104 }
105 }
106 }
90dc8f2b
VP
107}
108
ea90b321 109if (get_config("plugins"))
90dc8f2b 110{
ea90b321 111 foreach(get_config("plugins") as $plugin)
55fd88eb 112 Plugins::load($plugin);
4f3f84af
VP
113}
114
115/* Requires the plugin */
116function require_plugin($name, $version)
117{
118 if (!Plugins::plugin_exists($name,$version))
119 die("Missing plugin: $name v$version");
c00c34d2
VP
120}
121
c00c34d2
VP
122/* I'm not a fan of globals */
123class AuthModLoaded
124{
125 public static $status = 0;
126}
127
128function is_auth_provided()
129{
130 return AuthModLoaded::$status;
c51ca81c 131}