2 require_once "inc/common.php";
3 require_once "Classes/class-message.php";
6 /** Check for plugins and load them.
8 * This expects your plugin folder to be located in `plugins/` and that the directory name,
9 * constructor file name and class name are identical.
11 * You must have a file structure like this: plugins/myplugin/myplugin.php
12 * Which contains a class like this:
15 * $name = "My plugin";
16 * $author = "Joe Bloggs";
18 * $desc = "This is my plugin and it does stuff";
20 * // rest of code here...
23 * Your plugin class must be constructable and contain the following public variables:
24 * $name The name or title of your plugin.
25 * $author The name of the author
26 * $version The version of the plugin
27 * $description A short description of the plugin
33 static function load($modname)
35 $plugin = new Plugin($modname);
38 Message
::Fail("Warning: Plugin \"$modname\" failed to load: $plugin->error");
42 self
::$list[] = $plugin;
45 static function plugin_exists($name, $version = NULL)
47 foreach(self
::$list as $p)
48 if (!strcmp($p->name
,$name) && (!$version || ($version >= $p->version
)))
66 function __construct($handle)
68 if (!is_dir(UPATH
."/plugins/$handle"))
69 $this->error = "Plugin directory \"
".UPATH."/plugins
/$handle\" doesn
't exist";
71 else if (!is_file(UPATH."/plugins/$handle/$handle.php"))
72 $this->error = "Plugin file \"".UPATH."/plugins/$handle/$handle.php\" doesn't exist
";
76 require_once UPATH."/plugins
/$handle/$handle.php
";
78 if (!class_exists($handle))
79 $this->error = "Class \"$handle\" doesn
't exist";
83 $plugin = new $handle();
85 if (!isset($plugin->name))
86 $this->error = "Plugin name not defined";
87 elseif (!isset($plugin->author))
88 $this->error = "Plugin author not defined";
89 elseif (!isset($plugin->version))
90 $this->error = "Plugin version not defined";
91 elseif (!isset($plugin->description))
92 $this->error = "Plugin description not defined";
93 elseif (!isset($plugin->email))
94 $this->error = "Plugin email not defined";
97 $this->handle = $handle;
98 $this->name = $plugin->name;
99 $this->author = $plugin->author;
100 $this->version = $plugin->version;
101 $this->description = $plugin->description;
102 $this->email = $plugin->email;
109 if (get_config("plugins"))
111 foreach(get_config("plugins") as $plugin)
112 Plugins::load($plugin);
115 /* Requires the plugin */
116 function require_plugin($name, $version)
118 if (!Plugins::plugin_exists($name,$version))
119 die("Missing plugin: $name v$version");
122 /* I'm not a fan of globals */
125 public static $status = 0;
128 function is_auth_provided()
130 return AuthModLoaded
::$status;