forked from mapkyca/ifttt-webhook
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplugin.php
48 lines (35 loc) · 1.2 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
<?php
/**
* Plugin superclass.
*/
abstract class Plugin {
abstract function execute($object);
}
/**
* Execute a plugin
* @param type $plugin
* @param type $object
* @param type $raw
* @return stdClass
*/
function execute_plugin($plugin, $object) {
//$plugin = preg_replace("/[^a-zA-Z0-9\s]/", "", $plugin);
// Camel case to underscored
$plugin = strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1_', $plugin));
// Space to underscore
$plugin = preg_replace('/\s+/', '_', $plugin);
if (!file_exists(dirname(__FILE__) . "/plugins/$plugin.php")) {
__log("Plugin file $plugin.php could not be located");
return false;
}
require_once(dirname(__FILE__) . "/plugins/$plugin.php");
// Underscored to camel case
$class_name = str_replace(' ', '', ucwords(str_replace('_', ' ', $plugin))) . "Plugin";
if (!class_exists($class_name)) {
__log("Plugin class '" . $class_name . "' couldn't be loaded");
return false;
}
$plugin_class = new $class_name();
__log("Executing plugin " . $class_name);
return $plugin_class->execute( $object );
}