1
0
mirror of https://github.com/ZeroDream-CN/PHPMC7 synced 2024-11-24 13:15:10 +08:00
PHPMC7/include/core/PHPMC/Plugin.php
KasuganoSoras f06e0bcb30 v7.3.3156 更新发布
增加插件系统
增加事件管理系统
修复错误页面的标题问题
2018-09-16 01:49:48 +08:00

37 lines
1003 B
PHP

<?php
class Plugin {
public function __construct() {
if(!file_exists("plugins/")) {
mkdir("plugins/", 0775);
}
}
public function load($path = "./") {
$realpath = realpath($path);
$handle = opendir($path);
while($file = readdir($handle)) {
if($file !== "." && $file !== ".." && pathinfo($file)['extension'] == "php") {
$target = pathinfo($file)['filename'] . ".json";
$data = $this->pluginReader("{$realpath}/{$target}");
$info = json_decode($data, true);
if(!$info) {
PHPMC::Error()->Println("Error when load plugin: " . $file . ": No such plugin info file: " . $target . "<br>" . $data);
}
include("{$realpath}/{$file}");
eval('$' . $info['main'] . ' = new ' . $info['main'] . '();');
eval('$' . $info['main'] . '->onload();');
}
}
closedir($handle);
}
public function pluginReader($name) {
$file = fopen($name, "r") or die("Unable to open file!");
$data = fread($file, filesize($name));
fclose($file);
return $data;
}
}