diff --git a/admin/update.php b/admin/update.php new file mode 100644 index 00000000..399dd06c --- /dev/null +++ b/admin/update.php @@ -0,0 +1,125 @@ +is_admin) header('Location: ../index.php?msg=看起来你并不是管理员'); +View::show('admin/header', array('page_title' => "检查更新")); +$db = new Database\Database(); +?> + +
+ +
+

+ 检查更新 + Check Updates +

+
+ + +
+
+
+
+
+

更新信息

+
+
+ newVersionAvailable()): ?> +
有更新可用。
+ + + + + + + + + + + + + + + + + + + + + + + + +
最新版本: + vlatest_version; ?> +
当前版本: + vcurrent_version; ?> +
发布时间: + update_time; ?> +
更新日志: + getUpdateInfo()['releases'][$updater->latest_version]['release_note']); ?> +
下载地址: + @GitHub +
+ +
已更新至最新版本。
+ + + + + + + + + + + +
当前版本: + vcurrent_version; ?> +
发布时间: + getUpdateInfo()['releases'][$updater->current_version]['release_time']); ?> +
+ +
+ +
+
+ +
+
+
+

更新流程

+
+
+

1. 下载新版源码

+

2. 完全覆盖旧版目录

+

3. 运行 /setup/update-from-2.3.3-to-2.3.4.php

+

4. 升级完成

+
+
+ +
+
+

关于

+
+
+

自动升级正在开发中,开发者现在忙于应考,可能要过几个星期才能发布。

+
+
+
+ +
+ +
+
+ diff --git a/libraries/Updater.class.php b/libraries/Updater.class.php new file mode 100644 index 00000000..46bb27df --- /dev/null +++ b/libraries/Updater.class.php @@ -0,0 +1,66 @@ +current_version = $current_version; + } + + public function getUpdateInfo() { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->update_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + // quick fix for accessing https resources + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + curl_close($ch); + + return json_decode($result, true); + } + + public function checkUpdate() { + $info = $this->getUpdateInfo(); + $this->latest_version = $info['latest_version']; + $this->update_time = date('Y-m-d H:i:s', $info['update_time']); + } + + /** + * Check if a new version is available + * + * @return bool + */ + public function newVersionAvailable() { + $this->checkUpdate(); + return $this->compareVersion($this->latest_version, $this->current_version); + } + + /** + * Compare version string + * + * @param string $v1 + * @param string $v2 + * @return boolean + */ + private function compareVersion($v1, $v2) { + if (strnatcasecmp($v1, $v2) > 0) { + // v1 > v2 + return true; + } else { + // v1 < v2 || v1 = v2 + return false; + } + } +} diff --git a/setup/update-from-2.3.3-to-2.3.4.php b/setup/update-from-2.3.3-to-2.3.4.php new file mode 100644 index 00000000..9ce6327d --- /dev/null +++ b/setup/update-from-2.3.3-to-2.3.4.php @@ -0,0 +1,15 @@ + "用户管理", 3 => "添加用户", 4 => "个性化", - 5 => "站点配置"); - for ($i = 1; $i <= 5; $i++) { + 5 => "站点配置", + 6 => "检查更新"); + for ($i = 1; $i <= 6; $i++) { if ($data['page_title'] == $pages[$i]) { echo '
  • '; } else { @@ -116,6 +117,9 @@ case 5: echo ' '.$pages[$i].''; break; + case 6: + echo ' '.$pages[$i].''; + break; } echo '
  • '; } ?>