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