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