-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin.php
More file actions
executable file
·939 lines (889 loc) · 52.9 KB
/
Copy pathadmin.php
File metadata and controls
executable file
·939 lines (889 loc) · 52.9 KB
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
<?php
// 引入配置项
include './assets/function.php';
if (!empty($SecurityEntrance) && ($_GET['SE'] !== $SecurityEntrance && $_GET['SE'] !== $SecurityEntrance)) {
echo '安全入口错误';
exit;
}
session_start();
if (!empty($_GET['loginout']) && $_GET['loginout'] == "true") {
$_SESSION['RD_Password'] = "";
}
if (isset($_POST['password'])) {
$_SESSION['RD_Password'] = $_POST['password'];
}
// POST请求处理
if ($_SERVER['REQUEST_METHOD'] == "POST" && password_verify($_SESSION['RD_Password'], $AdminPassword)) {
if (!empty($_POST['action']) && $_POST['action'] == "editSet") {
foreach ($_POST as $key => $value) {
if ($key !== 'action' && $key !== "AdminPassword") {
addConfig($key, htmlspecialchars($value));
}
if ($key == "AdminPassword" && !empty($value) && isset($value)) {
addConfig('AdminPassword', password_hash($value, PASSWORD_DEFAULT));
header('location: ' . $_SERVER['HTTP_REFERER']);
}
}
header("location: ./admin.php?mode=editSet&SE=" . $_POST['SecurityEntrance']);
include './assets/config.php';
} elseif (!empty($_POST['action']) && $_POST['action'] == "newCategory") {
$categoryName = trim($_POST['categoryName']);
if (!empty($categoryName)) {
$categoryPath = DOCS_DIRECTORY . $categoryName;
if (!is_dir($categoryPath)) {
mkdir($categoryPath, 0777, true);
echo '<script>createMessage("分类创建成功", "success");</script>';
} else {
echo '<script>createMessage("分类已存在", "danger");</script>';
}
}
} elseif (!empty($_POST['action']) && $_POST['action'] == "editPost") {
$category = $_POST['category'];
if ($_POST['title'] == 'home' && $category != 'default') {
echo '$(document).ready(function() { setTimeout(createMessage("非default分类下文章名不能为home", "danger"), 100); });';
exit;
}
if ($_POST['title'] == 'index') {
echo '$(document).ready(function() { setTimeout(createMessage("文章名不能为index", "danger"), 100); });';
exit;
}
if ($_GET['article'] == '') {
echo '$(document).ready(function() { setTimeout(createMessage("文章名称不可为空", "danger"), 100); });';
} elseif ($_GET['article'] == 'newPost') {
forceFilePutContents(DOCS_DIRECTORY . $category . '/' . $_POST['title'] . '.md', $_POST['content']);
$docs = ['title' => $_POST['title'], 'content' => $_POST['content']];
} else {
$oldPath = explode('/', $_GET['article']);
$oldCategory = count($oldPath) > 1 ? $oldPath[0] : 'default';
$oldTitle = end($oldPath);
if ($oldCategory != $category || $_POST['title'] !== $oldTitle) {
$oldFilePath = DOCS_DIRECTORY . $_GET['article'] . '.md';
$newFilePath = DOCS_DIRECTORY . $category . '/' . $_POST['title'] . '.md';
rename($oldFilePath, $newFilePath);
forceFilePutContents($newFilePath, $_POST['content']);
header('location: ./admin.php?mode=editPost&article=' . $category . '/' . $_POST['title'] . '&SE=' . $_GET['SE'] . "&category=" . $_GET['category']);
} else {
if ($_GET['category'] == 'default' && $_GET['article'] == 'home') {
forceFilePutContents(DOCS_DIRECTORY . 'home.md', $_POST['content']);
} else {
forceFilePutContents(DOCS_DIRECTORY . $category . '/' . $_GET['article'] . '.md', $_POST['content']);
}
}
$docs = ['title' => $_POST['title'], 'content' => $_POST['content']];
}
includePlugin('docsPost', json_encode($docs));
} elseif (!empty($_POST['action']) && $_POST['action'] == "deletePost") {
$file = $_POST['file'];
if (strrpos($file, '/index') === strlen($file) - strlen('/index')) {
$file = substr($file, 0, strlen($file) - strlen('/index'));
}
// Split into category and filename
$parts = explode('/', $file);
$category = $parts[0];
$filename = end($parts);
$fullPath = DOCS_DIRECTORY . $file;
if (is_dir($fullPath)) {
deleteDirectory($fullPath);
} else {
$fullPath = DOCS_DIRECTORY . $file . ".md";
if (file_exists($fullPath)) {
unlink($fullPath);
$categoryPath = DOCS_DIRECTORY . $category;
if (is_dir($categoryPath) && count(glob($categoryPath . "/*.md")) === 0) {
rmdir($categoryPath);
}
}
}
} elseif (!empty($_POST['action']) && $_POST['action'] == "editPluginSet") {
foreach ($_POST as $key => $value) {
if ($key !== 'action') {
addConfig($key, $value, __DIR__ . '/assets/plugins/' . $_GET['plugin'] . '/config.php');
}
}
header("location: ./admin.php?mode=plugins&plugin=" . $_GET['plugin'] . "&SE=" . $_POST['SecurityEntrance']);
include __DIR__ . '/assets/plugins/' . $_GET['plugin'] . '/config.php';
} elseif (!empty($_POST['action']) && $_POST['action'] == "installPlugin") {
if (isset($_POST['url']) && isset($_POST['type']) && isset($_POST['id'])) {
$url = urldecode($_POST["url"]);
$type = $_POST['type'];
$id = $_POST['id'];
if (extension_loaded('zip')) {
$targetDirectory = "./assets/plugins/$id/";
} else {
$targetDirectory = "./";
}
if (!file_exists($targetDirectory)) {
mkdir($targetDirectory, 0777, true);
}
$fileName = basename($url);
$filePath = $targetDirectory . $fileName;
$ch = curl_init($url);
$fp = fopen($filePath, 'w');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
if (curl_errno($ch)) {
echo "<script>alert('cURL 错误: " . curl_error($ch) . "');</script>";
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
fclose($fp);
if ($httpCode == 200 && extension_loaded('zip')) {
$zip = new ZipArchive;
$res = $zip->open($filePath);
if ($res === TRUE) {
$totalFiles = $zip->numFiles;
$extractedFiles = 0;
for ($i = 0; $i < $totalFiles; $i++) {
$zip->extractTo($targetDirectory, array($zip->getNameIndex($i)));
$extractedFiles++;
$extractProgress = ($extractedFiles / $totalFiles) * 100;
flush();
ob_flush();
}
$zip->close();
} else {
echo "<script>alert('解压缩失败: " . $res . "');</script>";
}
} else {
echo "<script>alert('文件下载失败,错误码$httpCode');</script>";
}
} else {
echo "<script>alert('缺少必要的参数');</script>";
}
} elseif (!empty($_POST['action']) && $_POST['action'] == "uninstallPlugin") {
deleteDirectory('./assets/plugins/' . $_POST['id']);
}
}
?>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Language" content="zh-CN">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo '后台管理 - ' . $WebName ?></title>
<script src="https://assets.3r60.top/v3/package.js"></script>
<link rel="stylesheet" href="./assets/style.css">
</head>
<body>
<topbar data-homeUrl='.' data-showExpendButton='true'>
</topbar>
<main <?php echo !empty($_GET['mode']) && ($_GET['mode'] == "editPost" || $_GET['mode'] == "plugins") ? 'class="flex pb-0"' : ''; ?>>
<?php if (!empty($_GET['mode']) && $_GET['mode'] == "editPost"): ?>
<lead>
<div class="flex items-center mb-10 p-10">
<button onclick="createNewCategory()" class="btn btn-white btn-md mr-5"
style="font-size: 16px;height:40px;padding: 0px 10px;"><i class="bi bi-plus"></i>新分类</button>
<select id="categorySelector" class="textEditor textEditor-success" style="flex:1;margin: 0;">
<?php
$categories = getCategories();
$currentCategory = isset($_GET['category']) ? $_GET['category'] : 'default';
foreach ($categories as $category) {
echo '<option value="' . $category . '"' .
($category == $currentCategory ? ' selected' : '') .
'>' . $category . '</option>';
}
?>
</select>
</div>
<ul class="list" data-loadFromFile='false' data-changeTitle='false'>
<li><a href='./admin.php?mode=editPost&article=home&category=default&SE=<?php echo $_GET['SE'] ?>'><i
class="bi bi-house"></i> 首页门户</a></li>
<li><a
href='./admin.php?mode=editPost&article=newPost&category=<?php echo $currentCategory ?>&SE=<?php echo $_GET['SE'] ?>'><i
class="bi bi-plus-square"></i> 新建文章</a></li>
<?php
function loadDirectoryByCategory($category)
{
$categoryPath = DOCS_DIRECTORY . $category;
if (is_dir($categoryPath)) {
loadDirectory('admin', $category);
}
}
loadDirectoryByCategory($currentCategory);
?>
</ul>
<script>
function bindEvent() {
$('.list a').off('click contextmenu');
$('.list a').on('contextmenu', deletePostHandler);
$('.list a').on('click', function (event) {
event.preventDefault();
history.pushState('', '', this.href);
fetchAndReplaceContent(this.href, 'title,content', 'title,content', () => {
setActiveLinkInList($('.list'));
});
});
}
function deletePostHandler(e) {
e.preventDefault();
const article = $(this).attr('href').split('article=')[1].split('&')[0];
createDialog('confirm', 'danger', '删除确认', '确定要删除这篇文章吗?', () => {
const formData = {
action: 'deletePost',
file: '<?php echo $currentCategory ?>/' + decodeURIComponent(article)
};
fetchAndReplaceContent(
window.location.href,
'.list',
'.list',
bindEvent,
formData
);
});
}
bindEvent();
function createNewCategory() {
createDialog('type', 'primary', '新建分类', '请输入分类名称', function (value) {
if (value) {
const formData = {
action: 'newCategory',
categoryName: value
};
fetchAndReplaceContent(
window.location.href,
'#categorySelector',
'#categorySelector',
function () {
$('#categorySelector').val(value);
$('#categorySelector').trigger('change');
bindEvent();
},
formData
);
}
});
}
$('#categorySelector').change(function () {
var category = $(this).val();
var currentUrl = new URL(window.location.href);
currentUrl.searchParams.set('category', category);
history.pushState({}, '', currentUrl);
fetchAndReplaceContent(currentUrl.toString(), '.list', '.list', bindEvent);
});
</script>
<footer></footer>
</lead>
<?php elseif (!empty($_GET['mode']) && $_GET['mode'] == 'plugins'): ?>
<lead>
<ul class="list" data-loadFromFile='false' data-changeTitle='false'>
<li><a href='./admin.php?mode=plugins&SE=<?php echo $_GET['SE'] ?>#/'><i
class="bi bi-plugin"></i> 本地插件</a></li>
<li><a href='./admin.php?mode=plugins&plugin=shop&SE=<?php echo $_GET['SE'] ?>'><i
class="bi bi-shop"></i> 插件商店</a></li>
<?php
$baseDir = './assets/plugins';
$dirs = scandir($baseDir);
foreach ($dirs as $dir) {
if ($dir == '.' || $dir == '..') {
continue;
}
$subDir = $baseDir . '/' . $dir;
if (is_dir($subDir)) {
$infoFile = $subDir . '/info.json';
if (file_exists($infoFile)) {
$infoContent = file_get_contents($infoFile);
$infoData = json_decode($infoContent, true);
// 检查JSON是否有效
if ($infoData !== null) {
echo '
<li><a href="./admin.php?mode=plugins&plugin=' . $dir . '&SE=' . $_GET['SE'] . '"><i class="' . (isset($infoData['pluginIcon']) ? $infoData['pluginIcon'] : 'bi bi-plugin') . '"></i> ' . $infoData['pluginName'] . '-' . $infoData['pluginVersion'] . '</a></li>';
} else {
echo "无法解析 $infoFile 中的 JSON 数据\n\n";
}
} else {
echo "在 $subDir 中找不到 info.json 文件\n\n";
}
}
}
?>
</ul>
<footer></footer>
</lead>
<?php endif; ?>
<!-- 主要部分 -->
<link rel="stylesheet" type="text/css" href="https://assets.3r60.top/other/editormd/css/editormd.css">
<?php echo !empty($_GET['mode']) && ($_GET['mode'] == "editPost" || $_GET['mode'] == "plugins") ? '<content>' : ''; ?>
<?php includePlugin('admin'); ?>
<?php if (password_verify($_SESSION['RD_Password'], $AdminPassword)): ?>
<?php if (isset($_GET['mode'])): ?>
<?php if ($_GET['mode'] == "editSet"): ?>
<span class="text-center">
<br>
<h2 class="text-left m-0A" style="max-width: 650px;"><i class="bi bi-gear"></i> 站点设置</h2>
<form method="POST" id="configForm" action="" class="text-left m-0A" style="max-width: 650px;">
<input type="hidden" name="action" value="editSet">
<label for="WebName"><br>网站名称:</label><br>
<input type="text" id="WebName" name="WebName" class="textEditor textEditor-success textEditor-maxWidth"
placeholder="请输入网站名称" value="<?php echo $WebName ?>">
<br>
<label for="copyRight">版权信息:</label><br>
<input type="text" id="copyRight" name="copyRight"
class="textEditor textEditor-success textEditor-maxWidth" placeholder="请输入版权信息"
value="<?php echo htmlspecialchars($copyRight) ?>" required>
<br>
<label for="AdminPassword">验证密码:</label><br>
<input type="password" id="AdminPassword" name="AdminPassword"
class="textEditor textEditor-success textEditor-maxWidth" placeholder="留空则不更改密码">
<br>
<label for="SecurityEntrance">安全入口:</label><br>
<input type="text" id="SecurityEntrance" name="SecurityEntrance"
class="textEditor textEditor-success textEditor-maxWidth" placeholder="请输入安全入口"
value="<?php echo $SecurityEntrance ?>">
<button type="button" class="btn btn-shadow btn-circle"
onclick="createDialog('alert','success','安全入口','若填写此项,进入admin.php时需附带?SE=安全密码的 GET参数')">?</button>
<br>
<label for="Rewrite">伪静态:</label><br>
<input type="text" id="Rewrite" name="Rewrite" class="textEditor textEditor-success textEditor-maxWidth"
placeholder="请输入伪静态开关状态" value="<?php echo $Rewrite ?>">
<button type="button" class="btn btn-shadow btn-circle"
onclick="createDialog('alert','success','伪静态设置','开启前请先设置网站伪静态,方法点击下方连接查看<br><a href=\'https://docs.3r60.top/Project/?article=伪静态使用方法\'>伪静态使用方法</a>')">?</button>
更改站点图标仅需替换favicon.ico文件即可
<br><br>
<button type="submit" class="btn btn-shadow btn-success btn-md">保存设置</button>
</form>
<script>
$('#configForm').on('submit', function (event) {
event.preventDefault();
const formData = formInputsToKeyPairs($(this));
console.log(formData);
fetchAndReplaceContent(
window.location.href,
'main',
'main',
null,
formData
);
});
</script>
</span>
<?php elseif ($_GET['mode'] == "editPost"): ?>
<h2><i class="bi bi-pen"></i> 编辑文章</h2>
<?php if (empty($_GET['article'])): ?>
<h4>在左侧单击一个文章即可编辑</h4>
<?php else: ?>
<form id="passage" method="POST" action="">
<span class="flex items-baseline mb-10">
<input type="hidden" name="category" value="<?php echo $currentCategory ?>">
标题: <input type="text" id="postTitle" name="title" class="textEditor textEditor-success w-a"
style="flex:1" placeholder="请输入文章标题" required <?php
if ($_GET['article'] == 'newPost') {
echo 'value="新建文章"';
} else {
$path = explode('/', $_GET['article']);
echo 'value="' . end($path) . '"';
}
?>>
<button id="saveButton" type="submit" class="btn btn-shadow btn-success btn-md">提交更改</button>
</span>
<input type="hidden" name="action" value="editPost">
<div id="md-content">
<textarea id="content" name="content"><?php
if ($_GET['article'] == 'newPost') {
echo '新建空文章';
} else {
if ($_GET['category'] == 'default' && $_GET['article'] == 'home') {
$filePath = DOCS_DIRECTORY . '/home.md';
} else {
$filePath = DOCS_DIRECTORY . $_GET['category'] . '/' . $_GET['article'] . '.md';
}
if (file_exists($filePath)) {
echo file_get_contents($filePath);
} else {
echo '文章不存在';
}
}
?></textarea>
</div>
</form>
<script src="https://assets.3r60.top/Jquery/jquery-3.5.1.js"></script>
<script src="https://assets.3r60.top/other/editormd/editormd.min.js"></script>
<script type="text/javascript">
var saving = false;
$('#passage').on('submit', function (event) {
event.preventDefault();
if (saving) return;
saving = true;
const formData = formInputsToKeyPairs($(this));
fetchAndReplaceContent(
window.location.href,
'#postTitle,.list',
'#postTitle,.list',
() => {
const urlParams = new URLSearchParams(new URL(window.location.href).search);
urlParams.set('article', $('#postTitle').val());
urlParams.set('category', $('#categorySelector').val());
history.pushState({}, '', window.location.href.split('?')[0] + '?' + urlParams.toString());
setActiveLinkInList($('.list'));
// 重新绑定事件
bindEvent();
saving = false;
},
formData
);
});
$(document).keydown(function (event) {
if ((event.ctrlKey || event.metaKey) && (event.keyCode == 83 || event.keyCode == 115)) {
event.preventDefault();
$('#saveButton').click();
}
});
var contentEditor;
$(document).ready(function () {
contentEditor = editormd("md-content", {
width: "100%",
height: 500,
syncScrolling: "single",
path: "https://assets.3r60.top/other/editormd/lib/",
imageUpload: true, // 开启图片上传功能
imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"], // 支持的图片格式
imageUploadURL: "./assets/imageUpload.php?password=<?php echo $_SESSION['RD_Password'] ?>", // 上传图片的服务端地址
toc: true,
tocm: true,
emoji: true,
htmlDecode: true,
taskList: true,
tex: true,
flowChart: true,
sequenceDiagram: true,
theme: getColorMode() ? 'dark' : 'default',
editorTheme: getColorMode() ? '3024-night' : '3024-day',
previewTheme: getColorMode() ? 'dark' : 'default'
});
})
function setupPasteImage() {
var editorElement = $('#' + contentEditor.id);
editorElement.on("paste", function (event) {
handlePastedImage(event);
});
}
function handlePastedImage(event) {
// 检查粘贴板中的数据是否包含图片
var items = (event.originalEvent || event).clipboardData.items;
if (items) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.kind === "file" && item.type.match(/image\//)) {
var blob = item.getAsFile();
uploadImage(blob);
return;
}
}
}
}
function uploadImage(file) {
var formData = new FormData();
formData.append("editormd-image-file", file);
fetch('./assets/imageUpload.php?password=<?php
echo $_SESSION['RD_Password'] ?>', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
var imageUrl = data.url;
contentEditor.insertValue('');
} else {
console.error('图片上传失败:', data.message);
createMessage('图片上传失败:', data.message, 'danger');
}
})
.catch(error => {
console.error('图片上传失败:', error);
createMessage('图片上传失败:', data.message, 'danger');
});
}
$(document).on('colorModeChanged', function (event, colorMode) {
if (contentEditor !== null) {
if (colorMode == 'dark') {
contentEditor.setTheme('dark');
contentEditor.setEditorTheme('3024-night');
contentEditor.setPreviewTheme('dark')
} else {
contentEditor.setTheme('default');
contentEditor.setEditorTheme('3024-day');
contentEditor.setPreviewTheme('default')
}
}
});
setupPasteImage();
$(document).keydown(function (event) {
if ((event.ctrlKey || event.metaKey) && (event.keyCode == 83 || event.keyCode == 115)) {
event.preventDefault();
if (!saving) {
$('#saveButton').click();
saving = false;
}
}
});
$(document).ready(function () {
var editorContainer = $('#md-content');
var fullscreenButton = $('[name="fullscreen"]').parent();
fullscreenButton.on('click', function () {
var isFullscreen = fullscreenButton.hasClass('active');
editorContainer.css('z-index', isFullscreen ? 1000 : 1);
});
})
</script>
<?php endif; ?>
<?php elseif ($_GET['mode'] == "plugins"): ?>
<?php if (empty($_GET['plugin'])): ?>
<h2><i class="bi bi-plugin"></i> 本地插件</h2>
<?php
$baseDir = './assets/plugins';
$dirs = scandir($baseDir);
$api = "https://backend.3r60.top/project/risDocs/plugins/shop.json";
$remotePlugins = json_decode(file_get_contents($api), true);
foreach ($dirs as $dir) {
if ($dir == '.' || $dir == '..') {
continue;
}
$subDir = $baseDir . '/' . $dir;
if (is_dir($subDir)) {
$infoFile = $subDir . '/info.json';
if (file_exists($infoFile)) {
$infoContent = file_get_contents($infoFile);
$infoData = json_decode($infoContent, true);
if ($infoData !== null) {
// 查找远程插件信息
$remotePlugin = null;
foreach ($remotePlugins as $rp) {
if ($rp['pluginID'] === $dir) {
$remotePlugin = $rp;
break;
}
}
// 检查是否有更新
$updateAvailable = false;
if ($remotePlugin && version_compare($infoData['pluginVersion'], $remotePlugin['pluginVersion']) < 0) {
$updateAvailable = true;
}
// 显示插件信息
echo '
<form id="localPlugin_' . $dir . '" action="" method="POST">
<input type="hidden" name="action" value="uninstallPlugin">
<input type="hidden" name="id" value="' . $dir . '">
<card class="flex items-center">
<i class="text-large ml-5 mr-20 ' . (isset($infoData['pluginIcon']) ? $infoData['pluginIcon'] : 'bi bi-plugin') . '"></i>
<span class="flex flex-column" style="flex:1">
<span class="text-large">' . $infoData['pluginName'] . '</span>
<span class="text-small">' . $infoData['pluginDescribe'] . '</span>
</span><span class="flex flex-column">
<span class="text-small">作者:' . $infoData['pluginAuthor'] . '</span>
<span class="text-small">版本:' . $infoData['pluginVersion'];
if ($updateAvailable) {
echo ' (有更新:' . $remotePlugin['pluginVersion'] . ')';
}
echo '</span>
</span>
<div>
<button type="submit" class="btn btn-shadow btn-danger btn-md ml-20">卸载</button><a type="button" href="./admin.php?mode=plugins&plugin=' . $dir . '&SE=" class="btn btn-shadow btn-primary btn-md ml-10">配置</a>';
if ($updateAvailable) {
echo '<a type="button" href="./admin.php?mode=plugins&plugin=shop" class="btn btn-shadow btn-warning btn-md ml-10">升级</a>';
}
echo '</div>
</card>
</form>';
echo "<script>
$('#localPlugin_" . $dir . "').on('submit', function(event) {
event.preventDefault();
const formData = formInputsToKeyPairs($(this));
console.log(formData);
fetchAndReplaceContent(
window.location.href,
'main',
'main',
null,
formData
);
refreshMarkdownContent();
});</script>";
} else {
echo "无法解析 $infoFile 中的 JSON 数据\n\n";
}
} else {
echo "在 $subDir 中找不到 info.json 文件\n\n";
}
}
}
?>
<?php elseif ($_GET['plugin'] == 'shop'): ?>
<h2><i class="bi bi-shop"></i> 插件商店</h2>
<?php
if (version_compare(PHP_VERSION, '8.0.0', '>=') && !extension_loaded('zip')) {
echo "尊敬的 PHP " . PHP_VERSION . " 用户,您未安装zip扩展,插件zip将会下载到主目录,请手动解压他们";
}
$baseDir = './assets/plugins';
$dirs = scandir($baseDir);
$localPlugins = [];
// 读取本地插件信息
foreach ($dirs as $dir) {
if ($dir == '.' || $dir == '..') {
continue;
}
$subDir = $baseDir . '/' . $dir;
if (is_dir($subDir)) {
$infoFile = $subDir . '/info.json';
if (file_exists($infoFile)) {
$infoContent = file_get_contents($infoFile);
$infoData = json_decode($infoContent, true);
if ($infoData !== null) {
$localPlugins[$dir] = $infoData;
} else {
echo "无法解析 $infoFile 中的 JSON 数据\n\n";
}
} else {
echo "在 $subDir 中找不到 info.json 文件\n\n";
}
}
}
$api = "https://backend.3r60.top/project/risDocs/plugins/shop.json";
$plugins = json_decode(file_get_contents($api), true);
if (isset($plugins)) {
foreach ($plugins as $plugin) {
$pluginLocalVersion = isset($localPlugins[$plugin['pluginID']]['pluginVersion']) ? $localPlugins[$plugin['pluginID']]['pluginVersion'] : null;
// 比较版本
$versionInfo = '';
$buttonText = '';
$buttonClass = '';
if ($pluginLocalVersion === null) { // 插件未安装
$versionInfo = "版本:{$plugin['pluginVersion']}";
$buttonText = '安装';
$buttonClass = 'btn-success';
} elseif (version_compare($pluginLocalVersion, $plugin['pluginVersion']) < 0) { // 需要升级
$versionInfo = "版本:$pluginLocalVersion =>{$plugin['pluginVersion']}";
$buttonText = '升级';
$buttonClass = 'btn-warning';
} else { // 版本一致
$versionInfo = "版本:{$plugin['pluginVersion']}";
$buttonText = '重装';
$buttonClass = 'btn-danger';
}
echo '
<form id="onlinePlugin_' . $plugin['pluginID'] . '" action="" method="POST">
<input type="hidden" name="action" value="installPlugin">
<input type="hidden" name="type" value="plugin">
<input type="hidden" name="url" value="' . $plugin['downloadURL'] . '">
<input type="hidden" name="id" value="' . $plugin['pluginID'] . '">
<card class="flex items-center">
<i class="text-large ml-5 mr-20 ' . $plugin['pluginIcon'] . '"></i>
<span class="flex flex-column" style="flex:1">
<span class="text-large">' . $plugin['pluginName'] . '</span>
<span class="text-small">' . $plugin['pluginDescribe'] . '</span>
</span><span class="flex flex-column">
<span class="text-small">作者:' . $plugin['pluginAuthor'] . '</span>
<span class="text-small">' . $versionInfo . '</span>
</span>
<button class="btn btn-shadow ' . $buttonClass . ' btn-md ml-15">' . $buttonText . '</button>
</card>
</form>';
echo "<script>
$('#onlinePlugin_" . $plugin['pluginID'] . "').on('submit', function(event) {
event.preventDefault();
const formData = formInputsToKeyPairs($(this));
console.log(formData);
fetchAndReplaceContent(
window.location.href,
'main',
'main',
null,
formData
);
refreshMarkdownContent();
});</script>";
}
} else {
echo "<b>这里什么也没有</b>";
}
?>
<?php else: ?>
<?php
$infoFileIndex = "./assets/plugins/" . $_GET['plugin'] . '/info.json';
$infoContentIndex = file_get_contents($infoFileIndex);
$infoDataIndex = json_decode($infoContentIndex, true);
?>
<h2><i
class="<?php echo $infoDataIndex['pluginIcon'] ?? 'bi bi-plugin' ?>"></i> <?php echo $infoDataIndex['pluginName'] ?>
</h2>
<form action="" method="POST">
<input type="hidden" name="action" value="editPluginSet">
<?php
$setFileIndex = "./assets/plugins/" . $_GET['plugin'] . '/set.json';
$setContentIndex = file_get_contents($setFileIndex);
$setData = json_decode($setContentIndex, true);
@include "./assets/plugins/" . $_GET['plugin'] . '/config.php';
foreach ($setData as $item) {
$name = $item['name'];
switch ($item['type']) {
case 'textinput':
echo '<label for="' . $item['name'] . '">' . $item['label'] . ':</label>';
echo '<input name="' . $item['name'] . '" type="text" class="textEditor textEditor-' . ($item['theme'] ?? 'success') . '" value="' . $$name . '" placeholder="' . $item['show']['placeholder'] . '">';
break;
case 'textarea':
echo '<label for="' . $item['name'] . '">' . $item['label'] . ':</label>';
echo '<textarea name="' . $item['name'] . '" class="textEditor textEditor-' . ($item['theme'] ?? 'success') . '" placeholder="' . $item['show']['placeholder'] . '">' . $$name . '</textarea>';
break;
case 'select':
echo '<label for="' . $item['name'] . '">' . $item['label'] . ':</label>';
echo '<select name="' . $item['name'] . '" class="textEditor textEditor-' . ($item['theme'] ?? 'success') . '">';
foreach ($item['show'] as $option) {
if ($$name == $option['value']) {
echo '<option value="' . $option['value'] . '" selected>' . $option['text'] . '</option>';
} else {
echo '<option value="' . $option['value'] . '">' . $option['text'] . '</option>';
}
}
echo '</select>';
break;
case 'checkbox':
$checked = ($$name == 'on') ? 'checked' : '';
echo '<input type="hidden" name="' . $item['name'] . '" value="off">';
echo '<div class="checkbox-container">';
echo '<input type="checkbox" name="' . $item['name'] . '" id="' . $item['name'] . '"' . $checked . '>';
echo '<label for="' . $item['name'] . '">' . $item['show']['text'] . '</label>';
echo '</div>';
break;
case 'text':
echo '<p>';
echo $item['text'];
echo '</p>';
break;
}
}
echo '<br><button type="submit" class="btn btn-shadow btn-success btn-md">保存</button></form>';
?>
<?php endif; ?>
<?php endif; ?>
<?php else: ?>
<index>
<h1><?php echo $WebName ?></h1>
<h3>后台管理</h3>
</index>
<footer></footer>
<?php endif; ?>
<?php else: ?>
<div id="main-display">
<div class="moudle" style="width:320px;margin:auto">
<form method="POST" action="" name="AdminAuth">
<div class="dialog-overlay"></div>
<div class="dialog-box" style="border-top-color: var(--color-primary);">
<div class="dialog-header">
<h3>验证您的身份</h3>
</div>
<div class="dialog-body">
<p>请输入密码</p>
</div>
<div class="dialog-footer">
<input type="password" id="password" class="textEditor" name="password" placeholder="密码"
value="<?php echo $_SESSION['RD_Password'] ?>"><br>
<button class="btn btn-primary btn-md">登录</button>
</div>
</div>
</form>
</div>
</div>
<? endif; ?>
<?php echo !empty($_GET['mode']) && ($_GET['mode'] == "editPost" || $_GET['mode'] == "plugins") ? '</content>' : '' ?>
<?php if (!empty($_GET['mode']) && $_GET['mode'] == 'editPost'): ?>
<?php elseif (!empty($_GET['mode']) && $_GET['mode'] == 'plugins'): ?>
<script>
$('.onlinePlugin').on('submit', function (event) {
event.preventDefault();
const formData = formInputsToKeyPairs($(this));
console.log(formData);
fetchAndReplaceContent(
window.location.href,
'main',
'main',
null,
formData
);
refreshMarkdownContent();
});
</script>
<?php endif; ?>
</main>
<script>
let defaultTitle = '<?php echo $WebName ?>';
let defaultNavItems = [{
text: '<i class="bi bi-house"></i> 管理中心',
href: 'admin.php?SE=<?php echo $_GET['SE'] ?? null ?>#'
},
{
text: '<i class="bi bi-gear"></i> 站点设置',
href: 'admin.php?mode=editSet&SE=<?php echo $_GET['SE'] ?? null ?>#'
},
{
text: '<i class="bi bi-pen"></i> 编辑文章',
href: 'admin.php?mode=editPost&SE=<?php echo $_GET['SE'] ?? null ?>#'
},
{
text: '<i class="bi bi-plugin"></i> 插件管理',
href: 'admin.php?mode=plugins&SE=<?php echo $_GET['SE'] ?? null ?>#'
},
{
text: '<i class="bi bi-box-arrow-right"></i> 退出登录',
href: 'admin.php?loginout=true&SE=<?php echo $_GET['SE'] ?? null ?>#'
}
];
let defaultNavRightItems = [{
"text": "<i class=\"bi bi-info-circle\"></i>",
"href": `javascript:createDialog(\"alert\", \"primary\", \"关于<?php echo addslashes($WebName) ?>\", \"<?php echo $copyRight ? str_replace('"', "'", htmlspecialchars_decode($copyRight)) . '<br>' : '' ?>软件版本:<?php echo $localVersion; ?><br><a href=\\\"https://docs.3r60.top/Project\\\">Ris_Docs</a>提供软件服务\")`
}];
let defaultFooterLinks = [];
let defaultCopyright = `<?php echo $copyRight ? htmlspecialchars_decode($copyRight) : '版权所有 © 2025 腾瑞思智' ?>`;
let webTitle = '<?php echo addslashes($WebName) ?? '瑞思文档' ?>';
$(document).ready(function () {
setTimeout('<?php
if ($_SESSION['RD_Password'] == '' || empty($_SESSION['RD_Password']) || !isset($_SESSION['RD_Password'])) {
echo 'createMessage("请验证身份后继续","")';
} elseif (!password_verify($_SESSION['RD_Password'], $AdminPassword)) {
echo 'createMessage("密码错误","danger")';
} elseif (!empty($_GET['mode']) && $_GET['mode'] !== 'editPost') {
echo 'createMessage("欢迎回来,Admin","success")';
}
$vers = file_get_contents("https://app.3r60.top/assets/projects.json");
$projects = json_decode($vers);
$ver = $projects->Ris_Docs->version;
$update = str_replace(PHP_EOL, '<br>', $projects->Ris_Docs->update->{$ver}->changeLog);
if ($ver !== $localVersion && ($_GET['mode'] ?? null !== 'editPost')) {
echo ';createDialog("confirm","success","版本更新","' . $localVersion . '=>' . $ver . '<br>更新日志:' . $update . '<br>点击确定前往更新",()=>{location.href="./install.php"})';
}
?>', 500)
})
function formInputsToKeyPairs(formElement) {
const formData = new FormData(formElement[0]);
const dataObject = {};
for (let [key, value] of formData.entries()) {
dataObject[key] = value;
}
return dataObject;
}
function refreshMarkdownContent() {
contentEditor = editormd("md-content", {
width: "100%",
height: 500,
syncScrolling: "single",
path: "https://assets.3r60.top/other/editormd/lib/",
htmlDecode: true,
toc: true,
imageUpload: true, // 开启图片上传功能
imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"], // 支持的图片格式
imageUploadURL: "./assets/imageUpload.php?password=<?php echo $_SESSION['RD_Password'] ?>", // 上传图片的服务端地址
tocm: true,
emoji: true,
taskList: true,
tex: true,
flowChart: true,
sequenceDiagram: true,
});
saving = false;
}
</script>
<script src="https://assets.3r60.top/other/editormd/lib/marked.min.js"></script>
</body>
</html>