]>
Commit | Line | Data |
---|---|---|
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 { | |
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... | |
25 | * } | |
26 | * ``` | |
27 | * Your plugin class must be constructable and contain the following public variables: | |
28 | * $name The name or title of your plugin. | |
29 | * $author The name of the author | |
30 | * $version The version of the plugin | |
31 | * $description A short description of the plugin | |
32 | */ | |
33 | class Plugins | |
34 | { | |
35 | static $list = []; | |
36 | ||
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 | } | |
49 | } | |
50 | ||
51 | class Plugin | |
52 | { | |
53 | public $name; | |
54 | public $author; | |
55 | public $version; | |
56 | public $description; | |
57 | public $handle; | |
58 | ||
59 | public $error = NULL; | |
60 | function __construct($handle) | |
61 | { | |
62 | if (!is_dir(UPATH."/plugins/$handle")) | |
63 | $this->error = "Plugin directory \"".UPATH."/plugins/$handle\" doesn't exist"; | |
64 | ||
65 | else if (!is_file(UPATH."/plugins/$handle/$handle.php")) | |
66 | $this->error = "Plugin file \"".UPATH."/plugins/$handle/$handle.php\" doesn't exist"; | |
67 | ||
68 | else | |
69 | { | |
70 | require_once UPATH."/plugins/$handle/$handle.php"; | |
71 | ||
72 | if (!class_exists($handle)) | |
73 | $this->error = "Class \"$handle\" doesn't exist"; | |
74 | ||
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 | } | |
98 | } | |
99 | ||
100 | if (defined('PLUGINS')) | |
101 | { | |
102 | foreach(PLUGINS as $plugin) | |
103 | Plugins::load($plugin); | |
104 | } |