2 require_once "class-message.php";
5 /** Check for plugins and load them.
7 * This expects your plugin folder to be located in `plugins/` and that the directory name,
8 * constructor file name and class name are identical.
10 * You must have a file structure like this: plugins/myplugin/myplugin.php
11 * Which contains a class like this:
14 * $name = "My plugin";
15 * $author = "Joe Bloggs";
17 * $desc = "This is my plugin and it does stuff";
19 * // rest of code here...
22 * Your plugin class must be constructable and contain the following public variables:
23 * $name The name or title of your plugin.
24 * $author The name of the author
25 * $version The version of the plugin
26 * $description A short description of the plugin
32 static function load($modname)
34 $plugin = new Plugin($modname);
37 Message
::Fail("Warning: Plugin \"$modname\" failed to load: $plugin->error");
41 self
::$list[] = $plugin;
44 static function plugin_exists($name, $version = NULL)
46 foreach(self
::$list as $p)
47 if (!strcmp($p->name
,$name) && (!$version || ($version >= $p->version
)))
65 function __construct($handle)
67 if (!is_dir(UPATH
."/plugins/$handle"))
68 $this->error = "Plugin directory \"
".UPATH."/plugins
/$handle\" doesn
't exist";
70 else if (!is_file(UPATH."/plugins/$handle/$handle.php"))
71 $this->error = "Plugin file \"".UPATH."/plugins/$handle/$handle.php\" doesn't exist
";
75 require_once UPATH."/plugins
/$handle/$handle.php
";
77 if (!class_exists($handle))
78 $this->error = "Class \"$handle\" doesn
't exist";
82 $plugin = new $handle();
84 if (!isset($plugin->name))
85 $this->error = "Plugin name not defined";
86 elseif (!isset($plugin->author))
87 $this->error = "Plugin author not defined";
88 elseif (!isset($plugin->version))
89 $this->error = "Plugin version not defined";
90 elseif (!isset($plugin->description))
91 $this->error = "Plugin description not defined";
92 elseif (!isset($plugin->email))
93 $this->error = "Plugin email not defined";
96 $this->handle = $handle;
97 $this->name = $plugin->name;
98 $this->author = $plugin->author;
99 $this->version = $plugin->version;
100 $this->description = $plugin->description;
101 $this->email = $plugin->email;
108 if (get_config("plugins"))
110 foreach(get_config("plugins") as $plugin)
111 Plugins::load($plugin);
114 /* Requires the plugin */
115 function require_plugin($name, $version)
117 if (!Plugins::plugin_exists($name,$version))
118 die("Missing plugin: $name v$version");
121 /* I'm not a fan of globals */
124 public static $status = 0;
127 function is_auth_provided()
129 return AuthModLoaded
::$status;