pluginutil.inc.php
2.77 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
class KTPluginResourceRegistry {
var $aResources = array();
function &getSingleton() {
if (!KTUtil::arrayGet($GLOBALS, 'oKTPluginResourceRegistry')) {
$GLOBALS['oKTPluginResourceRegistry'] = new KTPluginResourceRegistry;
}
return $GLOBALS['oKTPluginResourceRegistry'];
}
function registerResource($sPath) {
$this->aResources[$sPath] = true;
}
function isRegistered($sPath) {
if (KTUtil::arrayGet($this->aResources, $sPath)) {
return true;
}
$sPath = dirname($sPath);
if (KTUtil::arrayGet($this->aResources, $sPath)) {
return true;
}
return false;
}
}
class KTPluginUtil {
function loadPlugins () {
$files = array();
KTPluginUtil::_walk(KT_DIR . '/plugins', $files);
foreach ($files as $sFile) {
$plugin_ending = "Plugin.php";
if (substr($sFile, -strlen($plugin_ending)) === $plugin_ending) {
require_once($sFile);
}
}
}
function _walk ($path, &$files) {
if (!is_dir($path)) {
return;
}
$dirh = opendir($path);
while (($entry = readdir($dirh)) !== false) {
if (in_array($entry, array('.', '..'))) {
continue;
}
$newpath = $path . '/' . $entry;
if (is_dir($newpath)) {
KTPluginUtil::_walk($newpath, $files);
}
if (!is_file($newpath)) {
continue;
}
$files[] = $newpath;
}
}
function resourceIsRegistered($path) {
$oRegistry =& KTPluginResourceRegistry::getSingleton();
return $oRegistry->isRegistered($path);
}
function registerResource($path) {
$oRegistry =& KTPluginResourceRegistry::getSingleton();
$oRegistry->registerResource($path);
}
function readResource($sPath) {
global $default;
$php_file = ".php";
if (substr($sPath, -strlen($php_file)) === $php_file) {
require_once($php_file);
} else {
$pi = pathinfo($sPath);
$mime_type = "";
$sExtension = KTUtil::arrayGet($pi, 'extension');
if (!empty($sExtension)) {
$mime_type = DBUtil::getOneResultKey(array("SELECT mimetypes FROM " . $default->mimetypes_table . " WHERE LOWER(filetypes) = ?", $sExtension), "mimetypes");
}
if (empty($mime_type)) {
$mime_type = "application/octet-stream";
}
$sFullPath = KT_DIR . '/plugins' . $sPath;
header("Content-Type: $mime_type");
header("Content-Length: " . filesize($sFullPath));
readfile($sFullPath);
}
}
}
?>