1
0
mirror of https://github.com/ZeroDream-CN/PHPMC7 synced 2026-05-16 18:42:33 +08:00

v7.3.3156 更新发布

增加插件系统
增加事件管理系统
修复错误页面的标题问题
This commit is contained in:
2018-09-16 01:49:48 +08:00
Unverified
parent 3117402098
commit f06e0bcb30
9 changed files with 161 additions and 30 deletions
+58
View File
@@ -1,6 +1,64 @@
<?php
class Event {
public $eventList;
public function registerClass($name, $class) {
$arr = $this->eventList;
$plug_one = @count($arr[$name]);
$arr[$name][$plug_one] = $class;
$this->eventList = $arr;
}
public function EventHandle($name, $args) {
try {
// 如果此事件已经注册
if(isset($this->eventList[$name])) {
$breaked = false;
// 遍历事件列表,将每个插件的事件处理函数执行一次
foreach($this->eventList[$name] as $class) {
$rs = call_user_func_array(array($class, $name), $args);
// 如果事件被取消
if($rs == true) {
$breaked = true;
break;
}
}
// 如果事件未被取消
if(!$breaked) {
@call_user_func_array(array($this, $name), $args);
}
} else {
// 如果事件未注册
call_user_func_array(array($this, $name), $args);
}
} catch(Exception $ex) {
// 出错时
call_user_func_array(array($this, $name), $args);
}
}
public function defaultActionEvent($data) {
$Loader = new Loader();
$Option = new Option();
echo $Loader->loadPage("404.html", ROOT . "/content/" . $Option->getOption("Theme") . "/error/");
exit;
}
public function defaultPageEvent($data) {
$Loader = new Loader();
$Option = new Option();
echo $Loader->loadPage("panel.html", ROOT . "/content/" . $Option->getOption("Theme") . "/");
exit;
}
public function viewPageEvent($data) {
$Loader = new Loader();
$Option = new Option();
echo $Loader->loadPage($data["page"] . ".html", ROOT . "/content/" . $Option->getOption("Theme") . "/");
exit;
}
public function LoginEvent($Data) {
if(preg_match("/^[A-Za-z0-9\-\_]+$/", $Data['username'])) {
if(PHPMC::User()->Login($Data['username'], $Data['password'])) {
+11 -1
View File
@@ -1,5 +1,8 @@
<?php
define("PHPMC_VERSION", "7.3.2105"); // Don't Change This!
// PHPMC 7 Version define
// Don't change this, because it will interfere your update.
define("PHPMC_VERSION", "7.3.3156");
include(ROOT . "/include/core/PHPMC/Event.php");
include(ROOT . "/include/core/PHPMC/User.php");
include(ROOT . "/include/core/PHPMC/Utils.php");
@@ -13,7 +16,10 @@ include(ROOT . "/include/core/PHPMC/Option.php");
include(ROOT . "/include/core/PHPMC/Permission.php");
include(ROOT . "/include/core/PHPMC/Update.php");
include(ROOT . "/include/core/PHPMC/Csrf.php");
include(ROOT . "/include/core/PHPMC/Plugin.php");
class PHPMC {
public static function Event() {
return new Event();
}
@@ -54,6 +60,10 @@ class PHPMC {
return new Update();
}
public static function Plugin() {
return new Plugin();
}
public static function Error() {
return new WebError();
}
+36
View File
@@ -0,0 +1,36 @@
<?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;
}
}