]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - plugins.php
3 require_once "config.php";
5 require_once "common.php";
7 require_once "Classes/class-message.php";
10 /** Check for plugins and load them.
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.
15 * You must have a file structure like this: plugins/myplugin/myplugin.php
16 * Which contains a class like this:
19 * $name = "My plugin";
20 * $author = "Joe Bloggs";
22 * $desc = "This is my plugin and it does stuff";
24 * // rest of code here...
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
37 static function load($modname)
39 $plugin = new Plugin($modname);
42 Message
::Fail("Warning: Plugin \"$modname\" failed to load: $plugin->error");
46 self
::$list[] = $plugin;
49 static function plugin_exists($name, $version = NULL)
51 foreach(self
::$list as $p)
52 if (!strcasecmp($p->name
,$name) && (!$version || ($version >= $p->version
)))
70 function __construct($handle)
72 if (!is_dir(UPATH
."/plugins/$handle"))
73 $this->error = "Plugin directory \"
".UPATH."/plugins
/$handle\" doesn
't exist";
75 else if (!is_file(UPATH."/plugins/$handle/$handle.php"))
76 $this->error = "Plugin file \"".UPATH."/plugins/$handle/$handle.php\" doesn't exist
";
80 require_once UPATH."/plugins
/$handle/$handle.php
";
82 if (!class_exists($handle))
83 $this->error = "Class \"$handle\" doesn
't exist";
87 $plugin = new $handle();
89 if (!isset($plugin->name))
90 $this->error = "Plugin name not defined";
91 elseif (!isset($plugin->author))
92 $this->error = "Plugin author not defined";
93 elseif (!isset($plugin->version))
94 $this->error = "Plugin version not defined";
95 elseif (!isset($plugin->description))
96 $this->error = "Plugin description not defined";
97 elseif (!isset($plugin->email))
98 $this->error = "Plugin email not defined";
101 $this->handle = $handle;
102 $this->name = $plugin->name;
103 $this->author = $plugin->author;
104 $this->version = $plugin->version;
105 $this->description = $plugin->description;
106 $this->email = $plugin->email;
113 if (defined('PLUGINS
'))
115 foreach(PLUGINS as $plugin)
116 Plugins::load($plugin);
119 /* Requires the plugin */
120 function require_plugin($name, $version)
122 if (!Plugins::plugin_exists($name,$version))
123 die("Missing plugin: $name v$version");