-
Notifications
You must be signed in to change notification settings - Fork 0
/
direct.php
58 lines (52 loc) · 1.5 KB
/
direct.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
51
52
53
54
55
56
57
58
<?php
// make sure a method name is provided
if (!isset($_GET['method'])) {
echo json_encode(array("error" => "'method' GET variable must be specified."));
exit;
}
// magic function that looks for an un-loaded class and tries to load it
function __autoload( $className ) {
$names = array(
strtolower($className),
strtoupper($className[0]) . substr($className,1)
);
$suffixes = array(
".php",
".class.php",
".direct.class.php"
);
$found = false;
foreach ($names as $name) {
foreach($suffixes as $suffix) {
if (is_file(__DIR__ . "/classes/" . $name . $suffix)) {
include_once(__DIR__ . "/classes/" . $name . $suffix);
return;
}
}
}
$handle = opendir(__DIR__ . "/classes/");
while($file = readdir($handle)){
if($file == "." || $file == "..") continue;
foreach($suffixes as $suffix){
if(strtolower($className) . $suffix == strtolower($file)){
include_once(__DIR__ . "/classes/" . $file);
break 2; // break out so the file handle gets closed
}
}
}
closedir($handle);
}
// see if the class can be found
if (class_exists($_GET['method'], true) === false) {
echo json_encode(array("error" => "The direct class '".$_GET['method']."' does not exist or could not be found"));
exit;
}
// create a new instance of the direct class and call its 'run' method
$method = new $_GET['method']($_GET['method']);
$return = $method->run();
// if the method returned anything, json encode it and pass it back to Javascript
if(isset($return)){
echo json_encode($return);
exit;
}
?>