开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
开源项目 > 建站系统 > CMS建站系统 &&
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
master
v7.0
master
分支 (2)
master
v7.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
master
v7.0
icms
/
app
/
patch
/
Patch.php
icms
/
app
/
patch
/
Patch.php
Patch.php 16.17 KB
一键复制 编辑 原始数据 按行查看 历史
iCMSdev 提交于 2026年06月09日 17:28 +08:00 . 同步更新
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
<?php
/**
* iCMS - i Content Management System
* Copyright (c) 2007-2017 iCMSdev.com. All rights reserved.
*
* @author icmsdev <master@icmsdev.com>
* @site https://www.icmsdev.com
* @licence https://www.icmsdev.com/LICENSE.html
*/
/**
* 自动更新类
*
* @author icmsdev
*/
define('PATCH_DIR', iPHP_APP_PATH . 'cache/iCMS/patch/'); //临时文件夹
Http::$CURLOPT_REFERER = $_SERVER['REQUEST_HOST'];
class Patch
{
public const PATCH_URL = 'https://patch.icmsdev.com/v8'; //自动更新服务器
public const APP = 'patch';
public const APPID = iCMS_APP_PATCH;
public static $version = '';
public static $release = '';
public static $zipName = '';
public static $gitFiles = [];
public static $upgrade = false;
public static $test = false;
public static function init($force = false)
{
$info = self::info($force);
$gitDate = date('Ymd', iCMS_GIT_TIME);
if (
$info &&
$info->app == iPHP_APP &&
version_compare($info->version, iCMS_VERSION, '>=') &&
$info->release > iCMS_RELEASE &&
$info->release > $gitDate
) {
self::$version = $info->version;
self::$release = $info->release;
self::$zipName = sprintf('iCMS.%s.patch.%s.zip', self::$version, self::$release);
return [self::$version, self::$release, $info->update, $info->changelog];
}
}
public static function setTime()
{
$release = strtotime(iCMS_RELEASE);
$gitTime = iCMS_GIT_TIME;
$_GET['iCMS_RELEASE'] && $release = strtotime($_GET['iCMS_RELEASE']);
$_GET['iCMS_GIT_TIME'] && $gitTime = $_GET['iCMS_GIT_TIME'];
Cache::set('patch.time', [$release, $gitTime], 3600);
}
public static function getTime()
{
return (array) Cache::get('patch.time');
}
public static function getUpgradeTime()
{
$time = Cache::get('patch.upgrade.time');
return $time ? $time : 0;
}
public static function git($do, $commit_id = null, $type = 'array')
{
$commit_id === null && $commit_id = iCMS_GIT_COMMIT;
$_GET['commit_id'] && $commit_id = Request::sget('commit_id');
$last_commit_id = Request::sget('last_commit_id');
$path = $_GET['path'];
$url = sprintf(
'%s/git?do=%s&VERSION=%s&RELEASE=%s&commit_id=%s&last_commit_id=%s',
Patch::PATCH_URL,
$do,
iCMS_VERSION,
iCMS_RELEASE,
$commit_id,
$last_commit_id
);
$path && $url .= '&path=' . urlencode($path);
$url .= '&t=' . time();
$data = Http::send($url);
if (is_null($data)) {
iPHP::alert('iCMS GIT版本服务出错请联系开发人员,谢谢!');
}
return $data;
}
public static function version($force = false)
{
$url = sprintf(
'%s/cms.version?VERSION=%s&RELEASE=%s&iCMS_GIT_COMMIT=%s&callback=?',
self::PATCH_URL,
iCMS_VERSION,
iCMS_RELEASE,
iCMS_GIT_COMMIT
);
$data = Http::send($url);
if (is_null($data)) {
iPHP::alert('iCMS版本服务出错请联系开发人员,谢谢!');
}
return $data;
}
public static function info($force = false)
{
File::mkdir(PATCH_DIR);
$tFilePath = PATCH_DIR . 'version.json'; //临时文件夹
if (File::exist($tFilePath) && time() - File::mtime($tFilePath) < 3600 && !$force) {
$FileData = File::get($tFilePath);
} else {
$url = sprintf(
'%s/version.%s.%s.patch.%s?t=%d',
self::PATCH_URL,
iPHP_APP,
iCMS_VERSION,
iCMS_RELEASE,
time()
);
$FileData = Http::remote($url);
File::put($tFilePath, $FileData);
}
return json_decode($FileData); //版本列表
}
public static function download(&$flag = true)
{
$zipFile = PATCH_DIR . self::$zipName; //临时文件
$zipHttp = self::PATCH_URL . '/' . self::$zipName;
$msg = '正在下载 [' . self::$release . '] 更新包 ' . $zipHttp . '<iCMS>';
$flag = true;
if (!File::exist($zipFile)) {
try {
$FileData = Http::remote($zipHttp);
if ($FileData) {
File::mkdir(PATCH_DIR);
File::put($zipFile, $FileData); //下载更新包
$msg .= '下载完成....<iCMS>';
} //code...
} catch (\Exception $ex) {
$flag = false;
$msg .= '下载失败....<iCMS>';
$msg .= $ex->getMessage();
}
} else {
$msg .= '更新包已存在....<iCMS>';
}
return $msg;
}
public static function update()
{
@set_time_limit(0);
// Unzip uses a lot of memory
@ini_set('memory_limit', '256M');
Vendor::run('PclZip'); //加载zip操作类
$zipFile = PATCH_DIR . self::$zipName; //临时文件
$msg = '正在对 [' . self::$zipName . '] 更新包进行解压缩<iCMS>';
$zip = new PclZip($zipFile);
if (false == ($archive_files = $zip->extract(PCLZIP_OPT_EXTRACT_AS_STRING))) {
exit('ZIP包错误');
}
if (0 == count($archive_files)) {
exit('空的ZIP文件');
}
$msg .= '解压完成<iCMS>';
$msg .= '开始测试目录权限<iCMS>';
$update = true;
if (!File::checkDir(iPHP_APP_PATH)) {
$update = false;
$msg .= iPHP_APP_PATH . ' 目录无写权限<iCMS>';
}
//测试目录文件是否写
foreach ($archive_files as $file) {
$folder = $file['folder'] ? $file['filename'] : dirname($file['filename']);
$dp = iPHP_APP_PATH . $folder;
if (!File::checkDir($dp) && File::isDir($dp)) {
$update = false;
$msg .= $dp . ' 目录无写权限<iCMS>';
}
if (empty($file['folder'])) {
$fp = iPHP_APP_PATH . $file['filename'];
if (file_exists($fp) && !@is_writable($fp)) {
$update = false;
$msg .= $fp . ' 文件无写权限<iCMS>';
}
}
}
if (self::$gitFiles) {
foreach (self::$gitFiles as $git) {
if ($git[0] == 'D') { //git删除资源
$fp = iPHP_APP_PATH . ltrim($git[1], '/');
if (file_exists($fp) && !@is_writable($fp)) {
$update = false;
$msg .= $fp . ' 文件无删除权限<iCMS>';
}
}
}
}
if (!$update) {
$msg .= '权限测试无法完成<iCMS>';
$msg .= '请设置好上面提示的文件写权限<iCMS>';
$msg .= '然后重新更新<iCMS>';
self::$upgrade = false;
$msg = Security::filterPath($msg);
return $msg;
}
$msg .= '权限测试通过<iCMS>';
//测试通过!
$msg .= '备份目录创建完成<iCMS>';
$bakdir = self::getBackupDir(self::$release);
File::mkdir($bakdir);
$msg .= '开始更新程序<iCMS>';
foreach ($archive_files as $file) {
preg_match('@^app/(\w+)/@', $file['filename'], $match);
if ($match[1]) {
if (!Apps::check($match[1]) && $match[1] != 'func') {
$msg .= '应用 [' . $match[1] . '] 不存在,跳过[' . $file['filename'] . ']更新<iCMS>';
continue;
}
}
$folder = $file['folder'] ? $file['filename'] : dirname($file['filename']);
$dp = iPHP_APP_PATH . $folder;
if (!File::isDir($dp)) {
$msg .= '创建 [' . $dp . '] 文件夹<iCMS>';
File::mkdir($dp);
}
if (empty($file['folder'])) {
$fp = iPHP_APP_PATH . $file['filename'];
$bfp = $bakdir . '/' . $file['filename'];
File::mkdir(dirname($bfp));
if (File::exist($fp)) {
$msg .= '备份 [' . $fp . '] 文件 到 [' . $bfp . ']<iCMS>';
File::copy($fp, $bfp); //备份旧文件
}
$msg .= '更新 [' . $fp . '] 文件<iCMS>';
if (self::$test) {
$msg .= '[' . $fp . '] 测试更新完成!<iCMS>';
} else {
File::put($fp, $file['content']);
$msg .= '[' . $fp . '] 更新完成!<iCMS>';
}
}
}
if (self::$gitFiles) {
foreach (self::$gitFiles as $git) {
if ($git[0] == 'D' && $git[1]) { //git删除资源
$fp = iPHP_APP_PATH . ltrim($git[1], '/');
if (file_exists($fp) && !@is_writable($fp)) {
$bfp = $bakdir . '/' . ltrim($git[1], '/');
File::mkdir(dirname($bfp));
if (File::exist($fp)) {
$msg .= '备份 [' . $fp . '] 文件 到 [' . $bfp . ']<iCMS>';
File::copy($fp, $bfp); //备份旧文件
$msg .= '删除 [' . $fp . '] 文件<iCMS>';
if (self::$test) {
$msg .= '[' . $fp . '] 测试删除完成!<iCMS>';
} else {
File::rm($fp);
$msg .= '[' . $fp . '] 删除完成!<iCMS>';
}
}
}
}
}
}
$msg .= '清除临时文件!<iCMS>';
$msg .= '注:原文件备份在 [' . $bakdir . '] 目录<iCMS>';
$msg .= '请暂时保留本次更新的备份,以备回滚使用!<iCMS>';
$msg = Security::filterPath($msg);
self::get_upgrade_files() && self::$upgrade = true;
if (!self::$test) {
Config::vset('patch.last', [iCMS_GIT_COMMIT, Patch::$release, time()]);
Cache::delete('patch/git.info');
}
return $msg;
}
public static function parsePartialDate($str)
{
$len = strlen($str);
$defaults = [
'year' => date('Y'),
'month' => '01',
'day' => '01',
'hour' => '00',
'minute' => '00',
'second' => '00'
];
$parts = [];
if ($len >= 4) $parts['year'] = substr($str, 0, 4);
if ($len >= 6) $parts['month'] = substr($str, 4, 2);
if ($len >= 8) $parts['day'] = substr($str, 6, 2);
if ($len >= 10) $parts['hour'] = substr($str, 8, 2);
if ($len >= 12) $parts['minute'] = substr($str, 10, 2);
if ($len >= 14) $parts['second'] = substr($str, 12, 2);
$merged = array_merge($defaults, $parts);
return sprintf('%s-%s-%s %s:%s:%s',
$merged['year'], $merged['month'], $merged['day'],
$merged['hour'], $merged['minute'], $merged['second']
);
}
public static function get_upgrade_files($flag = false)
{
$files = [];
$patch_dir = Application::path('patch/files');
$upgrade_time = self::getUpgradeTime();
foreach (glob($patch_dir . '*.{php,sql}', GLOB_BRACE) as $file) {
$d = str_replace([$patch_dir, 'db.', 'fs.', '.php', '.sql'], '', $file);
$t = strtotime(self::parsePartialDate($d));
if ($flag) {
$files[$t] = $file;
} else {
if ($t > $upgrade_time) {
$files[$t] = $file;
} else {
File::rm($file);
}
}
}
return $files;
}
public static function run()
{
$flag = isset($_GET['force']);
$files = self::get_upgrade_files($flag);
if ($files) {
self::$upgrade = true;
ksort($files);
foreach ($files as $t => $file) {
if (stripos($file, '.php') !== false) {
$name = str_replace(['.php', '.'], ['', '_'], basename($file));
$patch_name = 'patch_' . $name;
$patch_func = require_once $file;
$title = sprintf('%s[%s]', ($title ?: ''), $patch_name);
if (is_callable($patch_func)) {
$msg .= sprintf('执行%s升级程序<iCMS>', $title);
try {
if (self::$test) {
$msg .= '测试升级顺利完成!<iCMS>';
} else {
$msg .= call_user_func($patch_func);
$msg .= '升级顺利完成!<iCMS>';
self::$test or Cache::set('patch.upgrade.time', $t);
self::$test or File::rm($file);
}
$msg .= '删除升级程序!<iCMS>';
} catch (\Exception $ex) {
$msg = sprintf('%s升级出错<iCMS>', $title);
$msg .= $ex->getMessage() . '<iCMS>';
}
} else {
$msg = sprintf('%s升级出错<iCMS>', $title);
$msg .= '找不到升级程序<iCMS>';
}
} elseif (stripos($file, '.sql') !== false) {
$sql = file_get_contents($file);
$name = basename($file);
if ($sql) {
try {
if (self::$test) {
$msg .= '测试SQL执行顺利完成!<iCMS>';
} else {
$prefix = DB::getTablePrefix();
runQuery($sql, $prefix);
$msg .= 'SQL执行顺利完成!<iCMS>';
self::$test or Cache::set('patch.upgrade.time', $t);
self::$test or File::rm($file);
}
$msg .= '删除文件!<iCMS>';
} catch (\Exception $ex) {
$msg = '[' . $name . ']SQL执行出错<iCMS>';
$msg = $ex->getMessage() . '<iCMS>';
}
}
}
}
} else {
$msg = '升级顺利完成!';
}
self::$upgrade = false;
return $msg;
}
public static $check_login = true;
public static function getBackupDir($name)
{
return iPHP_APP_PATH . '.backup/patch.' . $name;
}
public static function upgrade($func)
{
if (is_null(self::$upgrade)) {
return;
}
if (self::$upgrade) {
return $func;
}
if (self::$check_login && !Admin::isLogin()) {
exit('请先登录');
}
$output = $func();
is_array($output) && $output = implode('<br />', $output);
$output = str_replace('<iCMS>', '<br />', $output);
$output = Security::filterPath($output);
echo $output;
$path = strtr(ADMINCP_URL, '\\', '/');
$path = ltrim($path, '/');
if (preg_match('@app/patch/files/\d+.php@', $path)) {
File::rm(iPHP_APP_PATH . $path);
}
}
public static function query($title, $sql)
{
$msg = $title . '<iCMS>';
try {
DB::query($sql);
} catch (PDOException $ex) {
$err = $ex->getMessage();
if (stripos($err, 'already exists') !== false) {
return $msg;
} else {
$msg .= '<span style="color:red;">';
$msg .= $title . '出错<br />';
$msg .= $ex->getMessage();
$msg .= '</span><iCMS>';
}
}
return $msg;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

iCMS 是一个采用 PHP 和 MySQL 数据库构建的高效内容管理系统,为中小型网站提供一个完美的解决方案。
取消

发行版

暂无发行版

开源评估指数源自 OSS-Compass 评估体系,评估体系围绕以下三个维度对项目展开评估:

1. 开源生态

  • 生产力:来评估开源项目输出软件制品和开源价值的能力。
  • 创新力:用于评估开源软件及其生态系统的多样化程度。
  • 稳健性:用于评估开源项目面对多变的发展环境,抵御内外干扰并自我恢复的能力。

2. 协作、人、软件

  • 协作:代表了开源开发行为中协作的程度和深度。
  • 人:观察开源项目核心人员在开源项目中的影响力,并通过第三方视角考察用户和开发者对开源项目的评价。
  • 软件:从开源项目对外输出的制品评估其价值最终落脚点。也是开源评估最"古老"的主流方向之一"开源软件" 的具体表现。

3. 评估模型

    基于"开源生态"与"协作、人、软件"的维度,找到与该目标直接或间接相关的可量化指标,对开源项目健康与生态进行量化评估,最终形成开源评估指数。

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/php/icms.git
git@gitee.com:php/icms.git
php
icms
iCMS
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /