mirror of
https://github.com/ZeroDream-CN/PHPMC7
synced 2026-05-18 03:36:29 +08:00
7.3.1709 发布
增加更新检测功能,现在可以自动下载最新版本的 PHPMC 了。 修正部分逻辑判断问题。 修改了部分 AJAX 请求超时时间 增加操作过渡动画效果
This commit is contained in:
@@ -436,4 +436,10 @@ class Event {
|
||||
echo "系统设置更改成功!";
|
||||
exit;
|
||||
}
|
||||
|
||||
public function updateEvent() {
|
||||
if(PHPMC::Update()->checkUpdate()) {
|
||||
PHPMC::Update()->updateExecute();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
define("PHPMC_VERSION", "7.2.1926-Beta"); // Don't Change This!
|
||||
define("PHPMC_VERSION", "7.3.1709"); // Don't Change This!
|
||||
include(ROOT . "/include/core/PHPMC/Event.php");
|
||||
include(ROOT . "/include/core/PHPMC/User.php");
|
||||
include(ROOT . "/include/core/PHPMC/Utils.php");
|
||||
@@ -11,6 +11,7 @@ include(ROOT . "/include/core/PHPMC/System.php");
|
||||
include(ROOT . "/include/core/PHPMC/Http.php");
|
||||
include(ROOT . "/include/core/PHPMC/Option.php");
|
||||
include(ROOT . "/include/core/PHPMC/Permission.php");
|
||||
include(ROOT . "/include/core/PHPMC/Update.php");
|
||||
class PHPMC {
|
||||
public static function Event() {
|
||||
return new Event();
|
||||
@@ -44,6 +45,10 @@ class PHPMC {
|
||||
return new Permission();
|
||||
}
|
||||
|
||||
public static function Update() {
|
||||
return new Update();
|
||||
}
|
||||
|
||||
public static function Error() {
|
||||
return new WebError();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
class Update {
|
||||
|
||||
public function checkUpdate() {
|
||||
$data = json_decode(PHPMC::Http()->Request("https://www.phpmc.cn/update.php?version=" . PHPMC_VERSION), true);
|
||||
if(!$data) {
|
||||
return false;
|
||||
} else {
|
||||
if($data['version'] == PHPMC_VERSION) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getUpdateInfo() {
|
||||
$data = json_decode(PHPMC::Http()->Request("https://www.phpmc.cn/update.php?version=" . PHPMC_VERSION), true);
|
||||
if(!$data) {
|
||||
return false;
|
||||
} else {
|
||||
if($data['version'] == PHPMC_VERSION) {
|
||||
return false;
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateExecute() {
|
||||
$data = $this->getUpdateInfo();
|
||||
if(!$data) {
|
||||
PHPMC::Error()->Println("无法更新,请检查网络是否正常。");
|
||||
} elseif(!$this->checkPermission("./")) {
|
||||
PHPMC::Error()->Println("网站目录不可写,请修改权限或手动更新。");
|
||||
} elseif(!class_exists("ZipArchive")) {
|
||||
PHPMC::Error()->Println("未检测到 ZipArchive 组件,请先修改 php.ini 启用 php_zip 扩展。");
|
||||
} else {
|
||||
$file = @PHPMC::Http()->Request($data['download']);
|
||||
if(strlen($file) == 0) {
|
||||
PHPMC::Error()->Println("下载的文件长度为 0,请检查网络是否正常。");
|
||||
} elseif(file_put_contents('update-temp.zip', $file) === false) {
|
||||
PHPMC::Error()->Println("写入文件时发生错误,请检查目录是否有读写权限。");
|
||||
} elseif(md5_file('update-temp.zip') !== $data['filemd5']) {
|
||||
@unlink('update-temp.zip');
|
||||
PHPMC::Error()->Println("文件 MD5 验证失败,请尝试重新更新。");
|
||||
} else {
|
||||
if($this->unzipUpdateFiles('update-temp.zip', './')) {
|
||||
@unlink('update-temp.zip');
|
||||
PHPMC::Error()->Println("PHPMC 更新成功,请刷新网页。");
|
||||
} else {
|
||||
@unlink('update-temp.zip');
|
||||
PHPMC::Error()->Println("解压文件时发生错误,无法打开文件或解压失败。");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function checkPermission($file) {
|
||||
if(is_dir($file)){
|
||||
$dir = $file;
|
||||
if($fp = @fopen("{$dir}/.writetest", 'w')) {
|
||||
@fclose($fp);
|
||||
@unlink("{$dir}/.writetest");
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if($fp = @fopen($file, 'a+')) {
|
||||
@fclose($fp);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function unzipUpdateFiles($fileName, $unzipPath) {
|
||||
$zip = new ZipArchive();
|
||||
$open = $zip->open($fileName);
|
||||
if($open === true) {
|
||||
return $zip->extractTo($unzipPath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user