]>
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 | } | |
90dc8f2b VP |
49 | } |
50 | ||
51 | class Plugin | |
52 | { | |
55fd88eb VP |
53 | public $name; |
54 | public $author; | |
55 | public $version; | |
56 | public $description; | |
57 | public $handle; | |
b65f0496 | 58 | public $email; |
90dc8f2b | 59 | |
55fd88eb VP |
60 | public $error = NULL; |
61 | function __construct($handle) | |
62 | { | |
195214b2 VP |
63 | if (!is_dir(UPATH."/plugins/$handle")) |
64 | $this->error = "Plugin directory \"".UPATH."/plugins/$handle\" doesn't exist"; | |
90dc8f2b | 65 | |
195214b2 VP |
66 | else if (!is_file(UPATH."/plugins/$handle/$handle.php")) |
67 | $this->error = "Plugin file \"".UPATH."/plugins/$handle/$handle.php\" doesn't exist"; | |
90dc8f2b | 68 | |
55fd88eb VP |
69 | else |
70 | { | |
93a3dfcb | 71 | require_once UPATH."/plugins/$handle/$handle.php"; |
90dc8f2b | 72 | |
55fd88eb VP |
73 | if (!class_exists($handle)) |
74 | $this->error = "Class \"$handle\" doesn't exist"; | |
90dc8f2b | 75 | |
55fd88eb VP |
76 | else |
77 | { | |
78 | $plugin = new $handle(); | |
79 | ||
80 | if (!isset($plugin->name)) | |
81 | $this->error = "Plugin name not defined"; | |
82 | elseif (!isset($plugin->author)) | |
83 | $this->error = "Plugin author not defined"; | |
84 | elseif (!isset($plugin->version)) | |
85 | $this->error = "Plugin version not defined"; | |
86 | elseif (!isset($plugin->description)) | |
87 | $this->error = "Plugin description not defined"; | |
b65f0496 VP |
88 | elseif (!isset($plugin->email)) |
89 | $this->error = "Plugin email not defined"; | |
55fd88eb VP |
90 | else |
91 | { | |
92 | $this->handle = $handle; | |
93 | $this->name = $plugin->name; | |
94 | $this->author = $plugin->author; | |
95 | $this->version = $plugin->version; | |
96 | $this->description = $plugin->description; | |
b65f0496 | 97 | $this->email = $plugin->email; |
55fd88eb VP |
98 | } |
99 | } | |
100 | } | |
101 | } | |
90dc8f2b VP |
102 | } |
103 | ||
104 | if (defined('PLUGINS')) | |
105 | { | |
55fd88eb VP |
106 | foreach(PLUGINS as $plugin) |
107 | Plugins::load($plugin); | |
90dc8f2b | 108 | } |