forked from mapkyca/ifttt-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
50 lines (35 loc) · 1.23 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Plugin superclass.
*/
abstract class Plugin {
abstract function execute($plugin, $object, $raw);
}
/**
* Execute a plugin
* @param type $plugin
* @param type $object
* @param type $raw
* @return stdClass
*/
function executePlugin($plugin, $object, $raw) {
global $ALLOW_PLUGINS;
if (!$ALLOW_PLUGINS) return $object;
$plugins = explode(':', $plugin);
if (!$plugins[0] == 'plugin') return false;
$plugin = trim($plugins[1]);
$plugin = preg_replace("/[^a-zA-Z0-9\s]/", "", $plugin);
$file = strtolower($plugin);
if (!file_exists(dirname(__FILE__) . "/plugins/$file.php")) {
__log("Plugin file $file.php could not be located");
return false;
}
require_once(dirname(__FILE__) . "/plugins/$file.php");
$plugin_class = new $plugin();
if ($plugin_class) {
__log("Plugin $plugin triggered");
return $plugin_class->execute ($plugin, $object, $raw);
}
__log("Plugin is invalid");
return false;
}