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