2014-02-25 12:51:07 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-17 20:24:27 -05:00
|
|
|
namespace LibreNMS;
|
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
class Plugins {
|
2014-02-25 12:51:07 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
private static $plugins = array();
|
|
|
|
|
|
|
|
|
|
|
|
public static function start() {
|
|
|
|
global $config;
|
|
|
|
if (file_exists($config['plugin_dir'])) {
|
|
|
|
// $plugin_files = scandir($config['plugin_dir']);
|
|
|
|
$plugin_files = dbFetchRows("SELECT * FROM `plugins` WHERE `plugin_active` = '1'");
|
|
|
|
foreach ($plugin_files as $plugins) {
|
|
|
|
$plugin_info = pathinfo($config['plugin_dir'].'/'.$plugins['plugin_name'].'/'.$plugins['plugin_name'].'.php');
|
|
|
|
if ($plugin_info['extension'] == 'php') {
|
|
|
|
if (is_file($config['plugin_dir'].'/'.$plugins['plugin_name'].'/'.$plugins['plugin_name'].'.php')) {
|
|
|
|
self::load($config['plugin_dir'].'/'.$plugins['plugin_name'].'/'.$plugins['plugin_name'].'.php', $plugin_info['filename']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
2014-02-25 12:51:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
}//end start()
|
2014-02-25 12:51:07 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
public static function load($file, $pluginName)
|
2014-02-25 12:51:07 +00:00
|
|
|
{
|
2015-07-13 20:10:26 +02:00
|
|
|
include $file;
|
2016-08-17 20:24:27 -05:00
|
|
|
$pluginFullName = 'LibreNMS\\Plugins\\' . $pluginName;
|
|
|
|
if (class_exists($pluginFullName)) {
|
|
|
|
$plugin = new $pluginFullName;
|
|
|
|
} elseif (class_exists($pluginName)) {
|
|
|
|
$plugin = new $pluginName;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
$hooks = get_class_methods($plugin);
|
|
|
|
|
|
|
|
foreach ($hooks as $hookName) {
|
|
|
|
if ($hookName{0} != '_') {
|
|
|
|
self::$plugins[$hookName][] = $pluginName;
|
|
|
|
}
|
2014-02-25 12:51:07 +00:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
return $plugin;
|
|
|
|
|
|
|
|
}//end load()
|
|
|
|
|
|
|
|
|
|
|
|
public static function call($hook, $params=false) {
|
|
|
|
if (count(self::$plugins[$hook]) != 0) {
|
|
|
|
foreach (self::$plugins[$hook] as $name) {
|
|
|
|
if (!is_array($params)) {
|
|
|
|
call_user_func(array($name, $hook));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
call_user_func_array(array($name, $hook), $params);
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 12:51:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
}//end call()
|
|
|
|
}//end class
|