This repository was archived by the owner on Sep 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfunctions.php
499 lines (454 loc) · 18.7 KB
/
functions.php
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
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
require_once __DIR__ . '/core/functions.php';
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('MDr', 'contentEx');
/* MDr Theme Config */
function themeConfig($form)
{
$db = Typecho_Db::get();
$nameQuery = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme'));
$name = isset($nameQuery['value']) ? $nameQuery['value'] : false;
$themeQuery = $db->fetchRow($db->select()->from('table.options')->where('name = ?', "theme:$name"));
/** 发送使用情况统计给开发团队 */
@mdrReportStatistics();
/**
* MDr Options Backup
* 主题设置备份
*
* @link https://qqdie.com/archives/typecho-templates-backup-and-restore.html
*/
if (isset($_GET['themeBackup']) && isset($_POST['type'])) :
$theme = $themeQuery ? $themeQuery['value'] : false;
$backupQuery = $db->fetchRow($db->select()->from('table.options')->where('name = ?', "theme:themeBackup-$name"));
$backup = $backupQuery ? $backupQuery['value'] : false;
if ($_POST["type"] == "备份主题设置") {
if ($theme) {
if ($backup) {
$update = $db->update('table.options')->rows(array('value' => $theme))->where('name = ?', "theme:themeBackup-$name");
$db->query($update);
Typecho_Widget::widget('Widget_Notice')->set(_t('主题设置备份已更新'), 'success');
} else {
$insert = $db->insert('table.options')->rows(array('name' => "theme:themeBackup-$name", 'user' => '0', 'value' => $theme));
$db->query($insert);
Typecho_Widget::widget('Widget_Notice')->set(_t('主题设置备份已完成'), 'success');
}
} else Typecho_Widget::widget('Widget_Notice')->set(_t('主题设置备份错误: 无法找到主题设置数据'), 'error');
} else if ($_POST["type"] == "还原主题设置") {
if ($backup) {
$update = $db->update('table.options')->rows(array('value' => $backup))->where('name = ?', "theme:$name");
$db->query($update);
Typecho_Widget::widget('Widget_Notice')->set(_t('主题设置已恢复,若浏览器没有自动刷新,请手动刷新页面'), 'success');
echo '<script language="JavaScript">window.setTimeout("location=\'\'", 2000);</script>';
} else Typecho_Widget::widget('Widget_Notice')->set(_t('没有找到主题设置备份'), 'notice');
} else if ($_POST["type"] == "删除备份设置") {
if ($backup) {
$delete = $db->delete('table.options')->where('name = ?', "theme:themeBackup-$name");
$db->query($delete);
Typecho_Widget::widget('Widget_Notice')->set(_t('主题设置备份已删除'), 'success');
} else Typecho_Widget::widget('Widget_Notice')->set(_t('没有找到主题设置备份'), 'notice');
} else Typecho_Widget::widget('Widget_Notice')->set(_t('主题设置备份错误: 未知操作'), 'error');
endif;
echo <<<EOF
<style> h2 {margin-bottom: 10px} h2 small {opacity: 0.5} .btn {margin: 2px 0} </style>
<p>
<span style="display: block;margin-bottom: 10px;margin-top: 10px;font-size: 16px;">MDr <small>书写你的篇章</small></span>
<span style="display: block;margin-bottom: 10px;margin-top: 10px;font-size: 14px;opacity:0.5">版本 <code id="mdr-version"></code></span>
</p>
<p>
<a href="https://blog.fsky7.com/archives/60/"><button class="btn primary">前往发布页</button></a>
<a href="https://mdr.docs.fsky7.com/"><button class="btn primary">查看文档</button></a>
</p>
<p>
<form class="protected" action="?themeBackup" method="post" id="mdr-backup">
<input type="submit" name="type" class="btn btn-s" value="备份主题设置" />
<input type="submit" name="type" class="btn btn-s" value="还原主题设置" />
<input type="submit" name="type" class="btn btn-s" value="删除备份设置" />
</form>
</p>
<textarea id="mdr-update-pre" class="w-100 mono" style="display:none" readonly></textarea>
<style>#mdr-update-pre{height:512px;}</style>
<p>
<a href="#mdr-color"><button class="btn btn-s">主题色</button></a>
<a href="#mdr-cdn"><button class="btn btn-s">CDN</button></a>
<a href="#mdr-nav"><button class="btn btn-s">边栏</button></a>
<a href="#mdr-pjax"><button class="btn btn-s">Ajax</button></a>
<a href="#mdr-func"><button class="btn btn-s">附加功能</button></a>
<a href="#mdr-custom"><button class="btn btn-s">自定义</button></a>
<a href="#mdr-end"><button class="btn btn-s">完成</button></a>
</p>
<script>
window.onload = function(){
$('form').last().find('[type="submit"]').first().parent().append('<button onclick="mdrInstantView();return false" class="btn primary">预览设置</button>')
};
function mdrInstantView() {
$.ajax({
url:'../?debug=start',
type:"POST",
data:$('form').last().serialize(),
success:function(){
window.open("../?debug=true","_blank")
}
})
}
</script>
EOF;
echo "<script>document.getElementById('mdr-version').innerHTML = '" . MDR_VERSION . "'</script>";
/* MDr Color 主题色设置 */
$mdrNotice = new Typecho_Widget_Helper_Form_Element_Text('mdrNotice', NULL, NULL, _t('<h2 id="mdr-color">主题色设置 <small>Color</small></h2>'));
$mdrNotice->input->setAttribute('style', 'display:none');
$form->addInput($mdrNotice);
$mdrPrimary = new Typecho_Widget_Helper_Form_Element_Select(
'mdrPrimary',
MDR_COLOR['primary'],
'indigo',
_t('主题主色'),
_t('默认为 indigo ,详情参见 <a href="https://www.mdui.org/docs/color" target="_blank">颜色和主题 - MDUI 文档</a>')
);
$form->addInput($mdrPrimary);
$mdrAccent = new Typecho_Widget_Helper_Form_Element_Select(
'mdrAccent',
MDR_COLOR['accent'],
'pink',
_t('主题强调色'),
_t('默认为 pink ,详情参见 <a href="https://www.mdui.org/docs/color" target="_blank">颜色和主题 - MDUI 文档</a>')
);
$form->addInput($mdrAccent);
/* MDr CDN 设置 */
$mdrNotice = new Typecho_Widget_Helper_Form_Element_Text('mdrNotice', NULL, NULL, _t('<h2 id="mdr-cdn">CDN 设置 <small>CDN</small></h2>'));
$mdrNotice->input->setAttribute('style', 'display:none');
$form->addInput($mdrNotice);
$mdrMDUICDN = new Typecho_Widget_Helper_Form_Element_Radio(
'mdrMDUICDN',
array(
'bootcss' => _t('BootCDN'),
'cdnjs' => _t('CDNJS'),
'cssnet' => _t('CSSnet'),
'jsdelivr' => _t('jsDelivr'),
'custom' => _t('自建')
),
'jsdelivr',
_t('MDUI 静态资源来源'),
_t('默认 jsDelivr ,请根据需求选择合适来源')
);
$form->addInput($mdrMDUICDN);
$cjCDN = new Typecho_Widget_Helper_Form_Element_Radio(
'cjCDN',
array(
'bc' => _t('BootCDN'),
'cf' => _t('CDNJS'),
'jd' => _t('jsDelivr'),
'custom' => _t('自建')
),
'bc',
_t('其他公共静态资源来源'),
_t('默认BootCDN,请根据需求选择合适来源')
);
$form->addInput($cjCDN);
$GravatarUrl = new Typecho_Widget_Helper_Form_Element_Radio(
'GravatarUrl',
array(
false => _t('官方'),
'https://gravatar.loli.net/avatar/' => _t('SM.MS'),
'https://cdn.v2ex.com/gravatar/' => _t('V2EX'),
'https://sdn.geekzu.org/avatar/' => _t('极客族'),
'https://use.sevencdn.com/avatar/' => _t('7ED.NET Public CDN')
),
false,
_t('Gravatar 头像源'),
_t('默认官方源,请根据需求选择合适来源')
);
$form->addInput($GravatarUrl);
/* MDr Nav 边栏设置 */
$mdrNotice = new Typecho_Widget_Helper_Form_Element_Text('mdrNotice', NULL, NULL, _t('<h2 id="mdr-nav">边栏设置 <small>Nav</small></h2>'));
$mdrNotice->input->setAttribute('style', 'display:none');
$form->addInput($mdrNotice);
$mdrNavDefOpen = new Typecho_Widget_Helper_Form_Element_Radio(
'mdrNavDefOpen',
array(
true => _t('启用'),
false => _t('关闭')
),
false,
_t('默认打开抽屉导航栏'),
_t('开启后默认打开抽屉导航栏,关闭后则不自动打开')
);
$form->addInput($mdrNavDefOpen);
$mdrNavColorBut = new Typecho_Widget_Helper_Form_Element_Radio(
'mdrNavColorBut',
array(
true => _t('启用'),
false => _t('关闭')
),
true,
_t('抽屉导航栏彩色按钮'),
_t('开启时抽屉导航栏图标为彩色,关闭后则为灰色')
);
$form->addInput($mdrNavColorBut);
$Navset = new Typecho_Widget_Helper_Form_Element_Checkbox(
'Navset',
array(
'ShowCategory' => _t('显示分类'),
'OpenCategory' => _t('默认打开分类列表'),
'ShowPage' => _t('显示页面'),
'OpenPage' => _t('默认打开页面列表'),
'ShowArchive' => _t('显示归档')
),
array(
'ShowCategory',
'ShowPage',
'OpenPage',
'ShowArchive'
),
_t('抽屉导航栏显示')
);
$form->addInput($Navset->multiMode());
/* MDr Pjax Ajax 设置 */
$mdrNotice = new Typecho_Widget_Helper_Form_Element_Text('mdrNotice', NULL, NULL, _t('<h2 id="mdr-pjax">Ajax 设置 <small>Ajax</small></h2>'));
$mdrNotice->input->setAttribute('style', 'display:none');
$form->addInput($mdrNotice);
$PjaxOption = new Typecho_Widget_Helper_Form_Element_Radio(
'PjaxOption',
array(
1 => _t('启用'),
0 => _t('关闭')
),
0,
_t('全站 Pjax'),
_t('默认关闭,启用则会强制关闭“反垃圾保护”,强制“将较新的的评论显示在前面”')
);
$form->addInput($PjaxOption);
$AjaxLoadTimes = new Typecho_Widget_Helper_Form_Element_Text(
'AjaxLoadTimes',
NULL,
'0',
_t('Ajax 自动翻页限制'),
_t('Ajax加载文章最多自动翻页~次,-1 则无限制')
);
$AjaxLoadTimes->input->setAttribute('class', 'mini');
$form->addInput($AjaxLoadTimes);
/* MDr Func 附加功能设置 */
$mdrNotice = new Typecho_Widget_Helper_Form_Element_Text('mdrNotice', NULL, NULL, _t('<h2 id="mdr-func">附加功能设置 <small>Func</small></h2>'));
$mdrNotice->input->setAttribute('style', 'display:none');
$form->addInput($mdrNotice);
$RandomLinks = new Typecho_Widget_Helper_Form_Element_Radio(
'RandomLinks',
array(
true => _t('启用'),
false => _t('关闭')
),
true,
_t('友情链接随机排序'),
_t('开启后友情链接将按照随机顺序排列')
);
$form->addInput($RandomLinks);
$mdrPray = new Typecho_Widget_Helper_Form_Element_Radio(
'mdrPray',
array(
true => _t('启用'),
false => _t('关闭')
),
false,
_t('全站暗淡'),
_t('开启后全站变黑白色调')
);
$form->addInput($mdrPray);
$mdrHitokoto = new Typecho_Widget_Helper_Form_Element_Radio(
'mdrHitokoto',
array(
true => _t('启用'),
false => _t('关闭')
),
true,
_t('一言 API 开关'),
_t('显示在网站底部,API by <a href="https://hitokoto.cn" target="_blank">hitokoto.cn</a>')
);
$form->addInput($mdrHitokoto);
$mdrHitokotoc = new Typecho_Widget_Helper_Form_Element_Radio(
'mdrHitokotoc',
array(
'' => _t('随机'),
'a' => _t('动画'),
'b' => _t('漫画'),
'c' => _t('游戏'),
'd' => _t('小说'),
'e' => _t('原创'),
'f' => _t('来自网络'),
'g' => _t('其他')
),
'',
_t('一言 API 分类'),
_t('默认随机显示')
);
$form->addInput($mdrHitokotoc);
$TimeNotice = new Typecho_Widget_Helper_Form_Element_Radio(
'TimeNotice',
array(
1 => _t('启用'),
0 => _t('关闭')
),
0,
_t('久远文章提醒'),
_t('默认关闭')
);
$form->addInput($TimeNotice);
$TimeNoticeLock = new Typecho_Widget_Helper_Form_Element_Text(
'TimeNoticeLock',
NULL,
'30',
_t('久远文章提醒阈值'),
_t('单位:天,默认30天')
);
$TimeNoticeLock->input->setAttribute('class', 'mini');
$form->addInput($TimeNoticeLock);
$SiteTime = new Typecho_Widget_Helper_Form_Element_Text(
'SiteTime',
NULL,
NULL,
_t('建站时间'),
_t('显示在网站底部,留空不显示。')
);
$SiteTime->input->setAttribute('class', 'mini');
$form->addInput($SiteTime);
$ViewImg = new Typecho_Widget_Helper_Form_Element_Radio(
'ViewImg',
array(
1 => _t('启用'),
0 => _t('关闭')
),
1,
_t('图片灯箱'),
_t('默认开启,采用的是 <a target="_blank" href="http://fancyapps.com/fancybox/3/">Fancybox</a>')
);
$form->addInput($ViewImg);
$mdrQrCode = new Typecho_Widget_Helper_Form_Element_Radio(
'mdrQrCode',
array(
1 => _t('启用'),
0 => _t('关闭')
),
1,
_t('当前页面二维码'),
_t('默认开启,开启后将显示当前页面二维码按钮')
);
$form->addInput($mdrQrCode);
/* MDr Custom 自定义设置 */
$mdrNotice = new Typecho_Widget_Helper_Form_Element_Text('mdrNotice', NULL, NULL, _t('<h2 id="mdr-custom">自定义内容 <small>Custom</small></h2>'));
$mdrNotice->input->setAttribute('style', 'display:none');
$form->addInput($mdrNotice);
$sitePic = new Typecho_Widget_Helper_Form_Element_Text(
'sitePic',
NULL,
NULL,
_t('自定义站点头图'),
_t('')
);
$form->addInput($sitePic);
$mdrPostAuthor = new Typecho_Widget_Helper_Form_Element_Radio(
'mdrPostAuthor',
array(
true => _t('显示'),
false => _t('隐藏')
),
false,
_t('文章内页显示作者'),
_t('默认不显示')
);
$form->addInput($mdrPostAuthor);
$subTitle = new Typecho_Widget_Helper_Form_Element_Text(
'subTitle',
NULL,
NULL,
_t('自定义站点副标题'),
_t('浏览器副标题,仅在当前页面为首页时显示,显示格式为:<b>标题 - 副标题</b>,留空则不显示副标题')
);
$form->addInput($subTitle);
$favicon = new Typecho_Widget_Helper_Form_Element_Text(
'favicon',
NULL,
NULL,
_t('Favicon 地址'),
_t('在这里填入一个图片 URL 地址, 以添加一个Favicon,留空则不单独设置Favicon')
);
$form->addInput($favicon);
$MyLinks = new Typecho_Widget_Helper_Form_Element_Textarea(
'MyLinks',
NULL,
NULL,
_t('自定义导航栏链接'),
_t('格式为 <b class="notice">文字=链接</b>,一行一个,留空则没有')
);
$form->addInput($MyLinks);
$ButtomText = new Typecho_Widget_Helper_Form_Element_Textarea(
'ButtomText',
NULL,
NULL,
_t('底部自定义内容'),
_t('位于底部版权下方建站时间上方')
);
$form->addInput($ButtomText);
$CustomContent = new Typecho_Widget_Helper_Form_Element_Textarea(
'CustomContent',
NULL,
NULL,
_t('底部自定义内容'),
_t('位于底部,footer之后body之前,适合放置一些JS内容,如网站统计代码等(若开启全站Pjax,目前支持Google和百度统计的回调,其余统计代码可能会不准确)')
);
$form->addInput($CustomContent);
/* MDr 后台设置结束 */
$mdrNotice = new Typecho_Widget_Helper_Form_Element_Text('mdrNotice', NULL, NULL, _t('<div id="mdr-end"></div>'));
$mdrNotice->input->setAttribute('style', 'display:none');
$form->addInput($mdrNotice);
}
/* MDr themeFields */
function themeFields($layout)
{
$thumb = new Typecho_Widget_Helper_Form_Element_Text(
'thumb',
NULL,
NULL,
_t('自定义缩略图'),
_t('在这里填入一个图片 URL 地址, 以添加本文的缩略图,若填入纯数字,例如 <b>3</b> ,则使用文章第三张图片作为缩略图(对应位置无图则不显示缩略图),留空则默认不显示缩略图')
);
$thumb->input->setAttribute('class', 'w-100');
$layout->addItem($thumb);
$catalog = new Typecho_Widget_Helper_Form_Element_Radio(
'catalog',
array(
true => _t('启用'),
false => _t('关闭')
),
false,
_t('文章目录'),
_t('默认关闭,启用则会在文章内显示“文章目录”(若文章内无任何标题,则不显示目录)')
);
$layout->addItem($catalog);
$licenses = new Typecho_Widget_Helper_Form_Element_Radio(
'linceses',
array(
'BY' => _t('CC BY'),
'BY-SA' => _t('CC BY-SA'),
'BY-ND' => _t('CC BY-ND'),
'BY-NC' => _t('CC BY-NC'),
'BY-NC-SA' => _t('CC BY-NC-SA'),
'BY-NC-ND' => _t('CC BY-NC-ND'),
'NONE' => _t('没有')
),
'NONE',
_t('许可协议'),
_t('默认没有协议,请前往 <a href="https://creativecommons.org/licenses/" target="_blank">CreativeCommons</a> 查看更多关于协议的内容,仅支持 4.0 ( 国际 ) 协议')
);
$layout->addItem($licenses);
}
/* MDr Theme Init */
function themeInit($archive)
{
$options = Helper::options();
$options->commentsAntiSpam = false;
$options->commentsOrder = 'DESC';
$options->commentsPageDisplay = 'first';
if ($archive->is('single')) {
$archive->content = hrefOpen($archive->content);
if ($archive->fields->catalog) {
$archive->content = createCatalog($archive->content);
}
}
}