forked from wehaox/Typecho-Butterfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
1601 lines (1482 loc) · 64.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
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
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
function themeConfig($form) {
?>
<link rel="stylesheet" href="<?php Helper::options()->themeUrl('css/themedash.css?v1.5.3'); ?>">
<div class='set_toc' >
<div class='mtoc'>
<a href='#themeBackup'>主题备份与还原</a>
<a href='#cids'>文章置顶及公共部分</a>
<a href='#pjax'>pjax设置</a>
<a href='#friends'>友情链接设置</a>
<a href='#reward'>打赏功能</a>
<a href='#aside'>侧边栏显示设置</a>
<a href='#beautifyBlock'>美化选项</a>
<a href='#ShowLive2D'>Live2D设置</a>
<a href='#otherCustom'>其他自定义内容</a>
<a href='#CustomColor'>自定义颜色</a>
<a href='#NULL' id='point'>返回上次保存设置时的锚点</a>
</div></div>
<form class="protected" action="?butterflybf" method="post" id="themeBackup">
<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>
<script src='https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js'></script>
<script src="<?php Helper::options()->themeUrl('js/themecustom.js?v1.5.3'); ?>"></script>
<script src='https://gcore.jsdelivr.net/gh/wehaox/CDN@main/postdomai.js'></script>
<?php
$sticky_cids = new Typecho_Widget_Helper_Form_Element_Text('sticky_cids', NULL, NULL,'置顶文章的 cid', '<div style="font-family:arial; background:#E8EFD1; padding:8px">按照排序输入, 请以半角逗号或空格分隔 cid</div>');
$sticky_cids->setAttribute('id', 'cids');
$form->addInput($sticky_cids);
$StaticFile = new Typecho_Widget_Helper_Form_Element_Select('StaticFile',
array(
'CDN' => 'CDN加载(默认)',
'local' => '本地加载',
),
'CDN',
'博客静态资源加载方式',
'介绍:无网络服务器或者CDN炸了可开启此项<br>
将博客静态资源,如js、css、图片从服务器加载(会稍微增加服务器流量消耗)<br>
注意:你需要额外<a href="https://raw.githubusercontents.com/wehaox/CDN/main/static.zip">下载</a>静态资源放进主题根目录解压<br>
此文件与下方的自定义CDN文件通用'
);
$form->addInput($StaticFile->multiMode());
$CDNURL = new Typecho_Widget_Helper_Form_Element_Text('CDNURL',NULL,NULL,
'自定义CDNURL(由@origami-tech提供)',
'需要选择博客静态资源加载方式为CDN加载 此项才会生效 且<b>本地加载>自定义CDNURL>jsdelivr源</b><br>
注意:你需要额外<a href="http://pub-gcdn.starsdust.cn/libs/butterfly/static/static.zip">下载</a>静态资源放CDN解压<br>不填则使用jsdelivrCDN<br>
链接填写规则:填写static文件夹的父文件夹 无需最后的/ 例如 https://pub-gcdn.starsdust.cn/libs/butterfly '
);
$form->addInput($CDNURL);
$jsdelivrLink = new Typecho_Widget_Helper_Form_Element_Select('jsdelivrLink',
array(
'cdn.jsdelivr.net' => '官方默认源',
'gcore.jsdelivr.net' => 'gcore源',
'fastly.jsdelivr.net' => 'fastly源',
'raw.fastgit.org' => 'fastgit源',
),
'gcore.jsdelivr.net',
'jsdelivr提供的cdn源切换(默认采用gcore源)',
'需要开启上方的CDN加载'
);
$form->addInput($jsdelivrLink->multiMode());
$NewTabLink = new Typecho_Widget_Helper_Form_Element_Select('NewTabLink',
array(
'on' => '开启(默认)',
'off' => '关闭',
),
'on',
'是否开启新标签打开外部链接',
'介绍:非站内链接在新标签打开'
);
$form->addInput($NewTabLink->multiMode());
$showFramework = new Typecho_Widget_Helper_Form_Element_Select('showFramework',
array(
'on' => '开启(默认)',
'off' => '关闭',
),
'on',
'是否显示底部博客框架和主题',
'介绍:如果你是小白自行修改主题名会导致侵权提示,你可以在这里关闭同时希望你可以<b>尊重本主题</b>'
);
$form->addInput($showFramework->multiMode());
$Defend = new Typecho_Widget_Helper_Form_Element_Select(
'Defend',
array('off' => '关闭(默认)', 'on' => '开启'),
'off',
'是否开启网站维护或密码访问',
'介绍:开启后,网站所有页面将会显示维护或者输入密码访问,登录用户不受限制'
);
$form->addInput($Defend->multiMode());
$ThemePassword = new Typecho_Widget_Helper_Form_Element_Text('ThemePassword', NULL,NULL, _t('全站密码访问(非必填)'), _t('输入访问网站的密码,<b>需要在上方开启网站维护或密码访问</b>'));
$form->addInput($ThemePassword);
$NoQQ = new Typecho_Widget_Helper_Form_Element_Select(
'NoQQ',
array('off' => '关闭(默认)', 'on' => '开启'),
'off',
'是否开启网站禁止手机QQ访问',
'介绍:烦人的QQ'
);
$form->addInput($NoQQ->multiMode());
$SiteLogo = new Typecho_Widget_Helper_Form_Element_Text('SiteLogo', NULL, NULL, _t('站点名称设置为图片logo(非必填)'), _t('当设置此项时站点名称将不会在导航栏左上角显示,使用png格式'));
$form->addInput($SiteLogo);
$Sitefavicon = new Typecho_Widget_Helper_Form_Element_Text('Sitefavicon', NULL, NULL, _t('网站图标'), _t('网站图标,使用png格式,大小建议不超过64x64'));
$form->addInput($Sitefavicon);
$logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL,_t('#null'), _t('作者头像'), _t('在这里填入图片地址,它会显示在右侧栏的作者头像'));
$form->addInput($logoUrl);
$author_description = new Typecho_Widget_Helper_Form_Element_Text('author_description', NULL, _t('作者描述'), _t('作者描述'), _t('在这里填入站点描述,它会显示在右侧栏的作者信息'));
$form->addInput($author_description);
$author_site_description = new Typecho_Widget_Helper_Form_Element_Text('author_site_description', NULL,_t('个人网站'), _t('作者链接描述'), _t('作者链接描述'));
$form->addInput($author_site_description);
$author_site = new Typecho_Widget_Helper_Form_Element_Text('author_site', NULL, _t('#null'), _t('作者链接'), _t('在这里填入作者链接,它会显示在右侧栏的作者信息的个人网站上'));
$form->addInput($author_site);
$author_bottom = new Typecho_Widget_Helper_Form_Element_Textarea('author_bottom', NULL, _t(''), _t('侧栏作者信息最底部内容(非必填)'), _t('这里填入html代码,不会勿填'));
$form->addInput($author_bottom);
$announcement = new Typecho_Widget_Helper_Form_Element_Textarea('announcement', NULL, _t('这里是公告<br>'), _t('公告'), _t('在这里填入公告,它会显示在右侧栏的公告上,采用html写法'));
$form->addInput($announcement);
$headerimg = new Typecho_Widget_Helper_Form_Element_Text('headerimg', NULL,_t('https://tva1.sinaimg.cn/large/007X0Rdyly1ghm1qiihrdj31hc0u07jk.jpg'), _t('主页顶图(banner image)'), _t('填入主页头图链接'));
$form->addInput($headerimg);
$buildtime = new Typecho_Widget_Helper_Form_Element_Text('buildtime', NULL,_t('2021/04/05'), _t('建站时间'), _t('按照输入框内格式填写'));
$form->addInput($buildtime);
$outoftime = new Typecho_Widget_Helper_Form_Element_Text('outoftime', NULL,_t('15'), _t('文章过时提醒'), _t('设置文章过时提醒最大天数,默认15天,可在文章管理单独设置是否显示过期提醒'));
$form->addInput($outoftime);
$archivelink = new Typecho_Widget_Helper_Form_Element_Text('archivelink', NULL,_t('#null'), _t('侧栏文章(归档)链接'), _t('需在独立页面创建并手动填入链接'));
$form->addInput($archivelink);
$tagslink = new Typecho_Widget_Helper_Form_Element_Text('tagslink', NULL,_t('#null'), _t('侧栏标签链接'), _t('需在独立页面创建并手动填入链接'));
$form->addInput($tagslink);
$categorylink = new Typecho_Widget_Helper_Form_Element_Text('categorylink', NULL,_t('#null'), _t('侧栏分类链接'), _t('需在独立页面创建并手动填入链接'));
$form->addInput($categorylink);
$CloseComments = new Typecho_Widget_Helper_Form_Element_Select('CloseComments',
array(
'off' => '关闭(默认)',
"on" => '开启'
),
'off',
'全站关闭评论',
'介绍:开启后所有文章不能评论'
);
$form->addInput($CloseComments->multiMode());
$EnableCommentsLogin = new Typecho_Widget_Helper_Form_Element_Select('EnableCommentsLogin',
array(
'off' => '关闭(默认)',
"on" => '开启'
),
'off',
'开启用户评论区登录',
'介绍:开启后在评论区会显示登录按钮
'
);
$form->addInput($EnableCommentsLogin->multiMode());
$EnablePjax = new Typecho_Widget_Helper_Form_Element_Select('EnablePjax',
array(
'off' => '关闭(默认)',
"on" => '开启'
),
'off',
'开启PJAX',
'介绍:页面无刷新加载,有效提高页面加载速度<br>
请先查看<a href="https://blog.wehaox.com/archives/typecho-butterfly.html#cl-13">使用文档</a>'
);
$EnablePjax->setAttribute('id', 'pjax');
$form->addInput($EnablePjax->multiMode());
$PjaxCallBack = new Typecho_Widget_Helper_Form_Element_Textarea('PjaxCallBack',NULL,NULL,
'Pjax回调函数(非必填)',
'用于解决开启pjax导致js丢失问题'
);
$form->addInput($PjaxCallBack);
/* 友链设置 */
$Friends = new Typecho_Widget_Helper_Form_Element_Textarea('Friends',NULL,NULL,
'友情链接(非必填)',
'介绍:用于填写友情链接 <br />
注意:需在独立页面创建友链,该项才会生效 <br />
格式:博客名称 || 博客地址 || 博客头像 || 博客简介 <br />
其他:一行一个,一行代表一个友链'
);
$Friends->setAttribute('id', 'friends');
$form->addInput($Friends);
$LazyLoad = new Typecho_Widget_Helper_Form_Element_Text('LazyLoad',
NULL,
NULL,
'全局懒加载图(非必填)',
'介绍:用于修改懒加载图片 格式:base64 或者 图片url'
);
$form->addInput($LazyLoad);
$ShowGlobalReward = new Typecho_Widget_Helper_Form_Element_Select('ShowGlobalReward',
array(
'off' => '关闭(默认)',
'show' => '开启打赏',
),
'off',
'是否开启全局文章打赏',
'介绍:开启此功能所有文章将显示打赏'
);
$ShowGlobalReward->setAttribute('id', 'reward');
$form->addInput($ShowGlobalReward->multiMode());
/* 打赏设置 */
$RewardInfo = new Typecho_Widget_Helper_Form_Element_Textarea('RewardInfo',NULL,_t('微信 || https://cdn.jsdelivr.net/gh/wehaox/CDN@main/reward/wechat.jpg
支付宝 || https://cdn.jsdelivr.net/gh/wehaox/CDN@main/reward/alipay.jpg'),
'打赏信息(非必填)',
'注意:需在开启打赏功能,该项才会显示 <br />
格式:打赏名称 || 图片地址 <br />一行一个'
);
$form->addInput($RewardInfo);
$sidebarBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('sidebarBlock',
array(
'ShowAnnounce' => _t('显示公告'),
'ShowRecentPosts' => _t('显示最新文章'),
'ShowRecentComments' => _t('显示最近回复'),
'ShowCategory' => _t('显示分类'),
'ShowTag' => _t('显示标签'),
'ShowArchive' => _t('显示归档'),
'ShowWebinfo' => _t('显示网站咨询'),
'ShowOther' => _t('显示其它杂项'),
'ShowMobileSide' => _t('手机端显示侧栏')
),
array('ShowAnnounce','ShowRecentPosts', 'ShowRecentComments', 'ShowCategory','ShowTag', 'ShowArchive', 'ShowWebinfo', 'ShowOther','ShowMobileSide'), _t('侧边栏显示'));
$sidebarBlock->setAttribute('id', 'aside');
$form->addInput($sidebarBlock->multiMode());
// 在线人数显示
$ShowOnlinePeople = new Typecho_Widget_Helper_Form_Element_Select('ShowOnlinePeople',
array(
'on' => '开启',
'off' => '关闭(默认)',
),
'off',
'是否显示在线人数',
'介绍:侧栏网站咨询模块在线人数统计,防止某些虚拟主机无法开启导致500错误'
);
$form->addInput($ShowOnlinePeople->multiMode());
// 文章侧边栏设置
$PostSidebarBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('PostSidebarBlock',
array(
// 'ShowAuthorInfo' => _t('显示作者信息'),
// 'ShowAnnounce' => _t('显示公告'),
'ShowRecentPosts' => _t('显示最新文章'),
'ShowWebinfo' => _t('显示网站咨询'),
'ShowOther' => _t('显示其它杂项')),
array('ShowRecentPosts', 'ShowWebinfo', 'ShowOther'), _t('文章侧边栏显示'),_t('说明:单独设置文章内侧栏'));
$form->addInput($PostSidebarBlock->multiMode());
// 美化选项
$beautifyBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('beautifyBlock',
array(
'ShowBeautifyChange' => _t('是否开启美化(基于butterfly小康的魔改)'),
'ShowColorTags' => _t('是否开启彩色标签云'),
'ShowTopimg' => _t('是否显示主页顶图'),
'PostShowTopimg' => _t('是否显示文章示顶图'),
'PageShowTopimg' => _t('是否显示独立页面顶图'),
'showLineNumber' => _t('是否显示代码块行号'),
'showSnackbar' => _t('是否显示主题以及简繁切换弹窗'),
'showLazyloadBlur' => _t('是否开启懒加载模糊效果'),
),
array('ShowTopimg','PostShowTopimg','PageShowTopimg','showLineNumber','showSnackbar','showLazyloadBlur'), _t('美化选项'));
$beautifyBlock->setAttribute('id', 'beautifyBlock');
$form->addInput($beautifyBlock->multiMode());
$ShowLive2D = new Typecho_Widget_Helper_Form_Element_Select('ShowLive2D',
array(
'off' => '关闭(默认)',
"on" => '开启(GitHub默认)'
),
'off',
'开启Live2D人物模型(仅通过GitHub默认样式且不会在手机显示)',
'介绍:开启后会在右下角显示一个小人,该功能采用远程调用不会消耗性能'
);
$ShowLive2D->setAttribute('id', 'ShowLive2D');
$form->addInput($ShowLive2D->multiMode());
// 弹窗提示
$SnackbarPosition = new Typecho_Widget_Helper_Form_Element_Select('SnackbarPosition',
array(
'top-left' => '左上(默认)',
'top-center' => '上中',
'top-right' => '右上',
'bottom-left' => '左下',
'bottom-center' => '下中',
'bottom-right' => '右下',
),
'top-left',
'主题以及简繁切换弹窗位置',
'选择其中一个,需要开启是否显示主题以及简繁切换弹窗 '
);
$form->addInput($SnackbarPosition->multiMode());
$CursorEffects = new Typecho_Widget_Helper_Form_Element_Select('CursorEffects',
array(
'off' => '关闭(默认)',
'heart' => '鼠标点击效果:爱心',
'fireworks' => '烟火效果',
),
'off',
'选择鼠标点击特效',
'介绍:用于切换鼠标点击特效 '
);
$form->addInput($CursorEffects->multiMode());
// 自定义subtitle
$CustomSubtitle = new Typecho_Widget_Helper_Form_Element_Text(
'CustomSubtitle',
NULL,
NULL,
'自定义主页副标题/subtitle(非必填)',
'介绍:不填则使用默认的一言api。'
);
$form->addInput($CustomSubtitle);
$SubtitleLoop = new Typecho_Widget_Helper_Form_Element_Select('SubtitleLoop',
array(
'true' => '开启循环打字(默认)',
"false" => '关闭循环打字'
),
'true',
'副标题循环打字',
'介绍:开启后主页副标题循环打字'
);
$form->addInput($SubtitleLoop->multiMode());
$EnableAutoHeaderLink = new Typecho_Widget_Helper_Form_Element_Select('EnableAutoHeaderLink',
array(
'on' => '开启(默认)',
"off" => '关闭'
),
'on',
'自动生成导航栏独立页面链接',
'介绍:如果你要自定义导航栏链接部分,你可以选择关闭此项'
);
$form->addInput($EnableAutoHeaderLink->multiMode());
// 自定义导航栏链接
$CustomHeaderLink = new Typecho_Widget_Helper_Form_Element_Textarea(
'CustomHeaderLink',
NULL,
NULL,
'自定义导航栏链接',
'介绍:目前使用html写法 <b style="color:red">完全自定义链接记得关闭上方选项</b>'
);
$CustomHeaderLink->setAttribute('id', 'otherCustom');
$form->addInput($CustomHeaderLink);
// 自定义认证用户
$CustomAuthenticated = new Typecho_Widget_Helper_Form_Element_Textarea(
'CustomAuthenticated',
NULL,
NULL,
'自定义认证用户',
'介绍:评论区认证用户专属头衔<br>
格式:邮箱||认证头衔 如:<br> xxx@xxx.com||xxx认证<br>
(一行一个)'
);
$form->addInput($CustomAuthenticated);
// 自定义css和js
$CustomCSS = new Typecho_Widget_Helper_Form_Element_Textarea(
'CustomCSS',
NULL,
NULL,
'自定义CSS样式(非必填)',
'介绍:请填写自定义CSS内容,填写时无需填写style标签。'
);
$form->addInput($CustomCSS);
$CustomScript = new Typecho_Widget_Helper_Form_Element_Textarea(
'CustomScript',
NULL,
NULL,
'自定义JS代码(非必填,请看下方介绍)',
'介绍:请填写自定义JS内容,填写时无需填写script标签。<br />
非专业人士请勿填写!'
);
$form->addInput($CustomScript);
$CustomHead = new Typecho_Widget_Helper_Form_Element_Textarea(
'CustomHead',
NULL,
NULL,
'自定义head标签内位置内容',
'介绍:填写如cdn的<link>标签、百度统计代码等等'
);
$form->addInput($CustomHead);
$CustomBodyEnd = new Typecho_Widget_Helper_Form_Element_Textarea(
'CustomBodyEnd',
NULL,
NULL,
'自定义body标签末尾位置内容',
'介绍:填写如cdn的<script></script>标签等等'
);
$form->addInput($CustomBodyEnd);
$Customfooter = new Typecho_Widget_Helper_Form_Element_Textarea(
'Customfooter',
NULL,
NULL,
'自定义Footer内容',
'介绍:网页底部的信息,如备案号等等(可使用html)'
);
$form->addInput($Customfooter);
//自定义颜色
$EnableCustomColor = new Typecho_Widget_Helper_Form_Element_Select('EnableCustomColor',
array(
"false" => '关闭(默认)',
'true' => '开启'
),
'false',
'开启主题自定义颜色(实验性功能)',
'介绍:需要开启此选项下面的自定义颜色才能生效,且下面关于颜色的必填'
);
$EnableCustomColor->setAttribute('id', 'CustomColor');
$form->addInput($EnableCustomColor->multiMode());
$CustomColorMain = new Typecho_Widget_Helper_Form_Element_Text(
'CustomColorMain',
NULL,
_t('#49b1f5'),
'自定主题主要颜色',
'介绍:使用hex格式或者颜色英文,如#fff、white'
);
$form->addInput($CustomColorMain);
$CustomColorButtonBG = new Typecho_Widget_Helper_Form_Element_Text(
'CustomColorButtonBG',
NULL,
_t('#49b1f5'),
'自定按钮颜色',
'介绍:同上'
);
$form->addInput($CustomColorButtonBG);
$CustomColorButtonHover = new Typecho_Widget_Helper_Form_Element_Text(
'CustomColorButtonHover',
NULL,
_t('#ff7242'),
'自定按钮悬停色',
'介绍:同上'
);
$form->addInput($CustomColorButtonHover);
$CustomColorSelection = new Typecho_Widget_Helper_Form_Element_Text(
'CustomColorSelection',
NULL,
_t('#00c4b6'),
'自定文本选择色',
'介绍:同上'
);
$form->addInput($CustomColorSelection);
//自定义颜色end
$siteKey = new Typecho_Widget_Helper_Form_Element_Text('siteKey',
NULL,
null,
'评论区谷歌验证码 <br> Site Key for reCAPTCHAv2:',
'<a href="https://www.google.com/recaptcha/admin/create">点击获取密钥</a>'
);
$secretKey = new Typecho_Widget_Helper_Form_Element_Text('secretKey', NULL, null, _t('Serect Key for reCAPTCHAv2:'), _t('填写两处密钥评论区自动开启谷歌验证码'));
$form->addInput($siteKey);
$form->addInput($secretKey);
$db = Typecho_Db::get();
$sjdq=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:butterfly'));
$ysj = $sjdq['value'];
if(isset($_POST['type']))
{
if($_POST["type"]=="备份主题数据"){
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:butterflybf'))){
$update = $db->update('table.options')->rows(array('value'=>$ysj))->where('name = ?', 'theme:butterflybf');
$updateRows= $db->query($update);
echo '<div class="tongzhi">备份已更新,请等待自动刷新!如果等不到请点击';
?>
<a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div>
<script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);</script>
<?php
}else{
if($ysj){
$insert = $db->insert('table.options')->rows(array('name' => 'theme:butterflybf','user' => '0','value' => $ysj));
$insertId = $db->query($insert);
echo '<div class="tongzhi">备份完成,请等待自动刷新!如果等不到请点击';
?>
<a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div>
<script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);</script>
<?php
}
}
}
if($_POST["type"]=="还原主题数据"){
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:butterflybf'))){
$sjdub=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:butterflybf'));
$bsj = $sjdub['value'];
$update = $db->update('table.options')->rows(array('value'=>$bsj))->where('name = ?', 'theme:butterfly');
$updateRows= $db->query($update);
echo '<div class="tongzhi">检测到主题备份数据,恢复完成,请等待自动刷新!如果等不到请点击';
?>
<a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div>
<script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2000);</script>
<?php
}else{
echo '<div class="tongzhi">没有主题备份数据,恢复不了哦!</div>';
}
}
if($_POST["type"]=="删除备份数据"){
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:butterflybf'))){
$delete = $db->delete('table.options')->where ('name = ?', 'theme:butterflybf');
$deletedRows = $db->query($delete);
echo '<div class="tongzhi">删除成功,请等待自动刷新,如果等不到请点击';
?>
<a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div>
<script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);</script>
<?php
}else{
echo '<div class="tongzhi">不用删了!备份不存在!!!</div>';
}
}
}
// 结束
}
function themeFields($layout)
{
$thumb = new Typecho_Widget_Helper_Form_Element_Text(
'thumb',
NULL,
NULL,
'自定义文章缩略图',
'填写时:将会显示填写的文章缩略图 <br>不填写时采用默认图片'
);
$layout->addItem($thumb);
$desc = new Typecho_Widget_Helper_Form_Element_Text(
'desc',
NULL,
NULL,
'SEO描述',
'用于填写文章或独立页面的SEO描述,如果不填写则没有'
);
$layout->addItem($desc);
$keywords = new Typecho_Widget_Helper_Form_Element_Text(
'keywords',
NULL,
NULL,
'SEO关键词',
'用于填写文章或独立页面的SEO关键词,如果不填写则没有'
);
$layout->addItem($keywords);
$showTimeWarning = new Typecho_Widget_Helper_Form_Element_Select(
'showTimeWarning',
array(
'on' => '开启(默认)',
'off' => '关闭'
),
'on',
'是否开启当前页面的文章过期警告',
'用于单独设置当前文章的过期警告 <br /> <b>仅在文章内作用,独立页面无需改动</b> <br />'
);
$layout->addItem($showTimeWarning);
$ShowReward = new Typecho_Widget_Helper_Form_Element_Select('ShowReward',
array(
'off' => '关闭(默认)',
'show' => '开启打赏',
),
'off',
'是否开启文章打赏',
'介绍:开启此功能需要在主题设置中添加二维码图片'
);
$layout->addItem($ShowReward);
$ShowToc = new Typecho_Widget_Helper_Form_Element_Select('ShowToc',
array(
'show' => '开启(默认)',
'off' => '关闭',
),
'show',
'是否显示文章目录',
'介绍:或许有的文章不需要目录功能,默认是开启的,一般不需要设置'
);
$layout->addItem($ShowToc);
}
// 新文章缩略图
function get_ArticleThumbnail($widget){
// 当文章无图片时的随机缩略图
// $rand = mt_rand(1, 26); // 随机 1-9 张缩略图
// // 缩略图加速
// $rand_url;
// if(!empty(Helper::options()->articleImgSpeed)){
// $rand_url = Helper::options()->articleImgSpeed;
// }else {
// $rand_url = $widget->widget('Widget_Options')->themeUrl . '/images/articles/';
// }
// $random = $rand_url . $rand . '.jpg'; // 随机缩略图路径
// $random = 'https://static01.imgkr.com/temp/517e5d14c312427dbf93304563869279.png';
// $attach = $widget->attachments(1)->attachment;
$random = '/usr/themes/butterfly/img/DefualtThumbnail.jpg';
$pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i';
//如果有自定义缩略图
if($widget->fields->thumb) {
return $widget->fields->thumb;
}else if (preg_match_all($pattern, $widget->content, $thumbUrl) && strlen($thumbUrl[1][0]) > 7) {
return $thumbUrl[1][0];
}else {
return $random;
}
};
// 主页文章缩略图
function GetRandomThumbnail($widget)
{
// $random = 'https://i.loli.net/2020/05/01/gkihqEjXxJ5UZ1C.jpg';
$random = '/usr/themes/butterfly/img/DefualtThumbnail.jpg';
if (Helper::options()->futureRandom) {
$moszu = explode("\r\n", Helper::options()->futureRandom);
$random = $moszu[array_rand($moszu, 1)] . "?futureRandom=" . mt_rand(0, 1000000);
}
$pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i';
$patternMD = '/\!\[.*?\]\((http(s)?:\/\/.*?(jpg|jpeg|gif|png|webp))/i';
$patternMDfoot = '/\[.*?\]:\s*(http(s)?:\/\/.*?(jpg|jpeg|gif|png|webp))/i';
$t = preg_match_all($pattern, $widget->content, $thumbUrl);
$img = $random;
if ($widget->fields->thumb) {
$img = $widget->fields->thumb;
} elseif ($t) {
$img = $thumbUrl[1][0];
} elseif (preg_match_all($patternMD, $widget->content, $thumbUrl)) {
$img = $thumbUrl[1][0];
} elseif (preg_match_all($patternMDfoot, $widget->content, $thumbUrl)) {
$img = $thumbUrl[1][0];
}
echo $img;
}
// 文章封面缩略图
function GetRandomThumbnailPost($widget)
{
if ($widget->fields->thumb) {
$img = $widget->fields->thumb;
}
echo $img;
}
// 文章字数统计
function art_count ($cid){
$db=Typecho_Db::get ();
$rs=$db->fetchRow ($db->select ('table.contents.text')->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1));
echo mb_strlen($rs['text'], 'UTF-8');
}
// 文章字数统计2
function charactersNum($archive) {
return mb_strlen($archive->text,'UTF-8');
}
// 全站字数统计
function allOfCharacters() {
$showPrivate = 0;
$chars = 0;
$db = Typecho_Db::get();
if($showPrivate == 0){
$select = $db ->select('text')->from('table.contents')->where('table.contents.status = ?','publish');
}else {
$select = $db ->select('text')->from('table.contents');
}
$rows = $db->fetchAll($select);
foreach ($rows as $row){
$chars += mb_strlen($row['text'], 'UTF-8');
}
$unit = '';
if($chars >= 10000) {
$chars /= 10000;
$unit = 'W';
}else if($chars >= 1000) {
$chars /= 1000;
$unit = 'K';
}
$out = sprintf('%.2lf %s',$chars, $unit);
echo $out;
}
function thumb($cid) {
if (empty($imgurl)) {
$rand_num = 10; //随机图片数量,根据图片目录中图片实际数量设置
if ($rand_num == 0) {
$imgurl = "img/0.jpg";
//如果$rand_num = 0,则显示默认图片,须命名为"0.jpg",注意是绝对地址
}else{
$imgurl = "img/".rand(1,$rand_num).".jpg";
//随机图片,须按"1.jpg","2.jpg","3.jpg"...的顺序命名,注意是绝对地址
}
}
$db = Typecho_Db::get();
$rs = $db->fetchRow($db->select('table.contents.text')
->from('table.contents')
->where('table.contents.type = ?', 'attachment')
->where('table.contents.parent= ?', $cid)
->order('table.contents.cid', Typecho_Db::SORT_ASC)
->limit(1));
$img = unserialize($rs['text']);
if (empty($img)){
echo $imgurl;
}
else{
echo '你的博客地址'.$img['path'];
}
}
// 评论时间
function timesince($older_date,$comment_date = false) {
$chunks = array(
array(86400 , '天'),
array(3600 , '小时'),
array(60 , '分'),
array(1 , '秒'),
);
$newer_date = time();
$since = abs($newer_date - $older_date);
if($since < 2592000){
for ($i = 0, $j = count($chunks); $i < $j; $i++){
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
if (($count = floor($since / $seconds)) != 0) break;
}
$output = $count.$name.'前';
}else{
$output = !$comment_date ? (date('Y-m-j G:i', $older_date)) : (date('Y-m-j', $older_date));
}
return $output;
}
// 文章内获取第一张图做封面
function getPostImg($archive) {
$img = array();
// 匹配 img 的 src 的正则表达式
preg_match_all("/<img.*?src=\"(.*?)\".*?\/?>/i", $archive->content, $img);
// 判断是否匹配到图片
if (count($img) > 0 && count($img[0]) > 0) {
// 返回图片
return $img[1][0];
} else {
// 如果没有匹配到就返回 none
return 'none';
}
}
function createCatalog($obj) { //为文章标题添加锚点
global $catalog;
global $catalog_count;
$catalog = array();
$catalog_count = 0;
$obj = preg_replace_callback('/<h([1-6])(.*?)>(.*?)<\/h\1>/i', function($obj) {
global $catalog;
global $catalog_count;
$catalog_count ++;
$catalog[] = array('text' => trim(strip_tags($obj[3])), 'depth' => $obj[1], 'count' => $catalog_count);
return '<h'.$obj[1].$obj[2].' id="cl-'.$catalog_count.'"><a class="markdownIt-Anchor" href="#cl-'.$catalog_count.'"></a>'.$obj[3].'</h'.$obj[1].'>';
}, $obj);
return $obj;
}
// 目录树
function getCatalog() { //输出文章目录容器
global $catalog;
$index = '';
if ($catalog) {
$prev_depth = '';
$to_depth = 0;
foreach($catalog as $catalog_item) {
$catalog_depth = $catalog_item['depth'];
if ($prev_depth) {
if ($catalog_depth == $prev_depth) {
$index .= '</li >'."\n";
} elseif ($catalog_depth > $prev_depth) {
$to_depth++;
$index .= '<ol class="toc-child">'."\n";
} else {
$to_depth2 = ($to_depth > ($prev_depth - $catalog_depth)) ? ($prev_depth - $catalog_depth) : $to_depth;
if ($to_depth2) {
for ($i=0; $i<$to_depth2; $i++) {
$index .= '</li>'."\n".'</ol>'."\n";
$to_depth--;
}
}
$index .= '</li>';
}
}
$index .= '<li class="toc-item">
<a class="toc-link" href="#cl-'.$catalog_item['count'].'">
<span class="toc-number"></span>
<span class="toc-text">'.$catalog_item['text'].'</span>
</a>';
$prev_depth = $catalog_item['depth'];
}
for ($i=0; $i<=$to_depth; $i++) {
$index .= '</li>'."\n";
}
// $index = '<div >'."\n".'<div >'."\n"."\n".$index.'</div>'."\n".'</div>'."\n";
}
echo $index;
}
/* 获取懒加载图片 */
function GetLazyLoad()
{
if (Helper::options()->LazyLoad) {
return Helper::options()->LazyLoad;
} else {
return "data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=";
}
}
/* 格式化标签 */
function ParseCode($text)
{
$text = Short_Tabs($text);
$text = Note_Fsm($text);
$text = Note_Ico($text);
$text = Hide_Lnline($text);
$text = Hide_Block($text);
$text = Hide_Toggle($text);
$text = Button($text);
$text = Cheak_Box($text);
$text = inline_Tag($text);
$text = Bf_Radio($text);
$text = Bf_Mark($text);
$text = PostImage($text);
return $text;
}
// 标签外挂-Tabs
function Short_Tabs($text)
{
$text = preg_replace_callback('/<p>\[tabs\](.*?)\[\/tabs\]<\/p>/ism', function ($text) {
return '[tabs]' . $text[1] . '[/tabs]';
}, $text);
$text = preg_replace_callback('/\[tabs\](.*?)\[\/tabs\]/ism', function ($text) {
return preg_replace('~<br.*?>~', '', $text[0]);
}, $text);
$text = preg_replace_callback('/\[tabs\](.*?)\[\/tabs\]/ism', function ($text) {
$tabname = '';
preg_match_all('/label=\"(.*?)\"\]/i', $text[1], $tabnamearr);
for ($i = 0; $i < count($tabnamearr[1]); $i++) {
if ($i === 0) {
$tabname .= '<li class="tab active"><button type="button" data-href="' . $i . '">' . $tabnamearr[1][$i] . '</button></li>';
} else {
$tabname .= '<li class="tab" data-href="' . $i . '"><button type="button" data-href="' . $i . '">' . $tabnamearr[1][$i] . '</button></li>';
}
}
$tabcon = '';
preg_match_all('/"\](.*?)\[\//i', $text[1], $tabconarr);
for ($i = 0; $i < count($tabconarr[1]); $i++) {
if ($i === 0) {
$tabcon .= '<div class="tab-item-content active" id="' . $i . '">' . $tabconarr[1][$i] . ' <button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div>';
} else {
$tabcon .= '<div class="tab-item-content" id="' . $i . '">' . $tabconarr[1][$i] . '<button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div>';
}
}
return '
<div class="tabs" id="tags"><ul class="nav-tabs">' . $tabname . '</ul><div class="tab-contents">' . $tabcon . '</div></div>';
}, $text);
return $text;
}
// 标签外挂-btn
function Button($text)
{
$text = preg_replace_callback('/\[btn href=\"(.*?)\" type=\"(.*?)\".*?\ ico=\"(.*?)\"](.*?)\[\/btn\]/ism', function ($text) {
return '<a href="' . $text[1] . '" class="btn-beautify button--animated ' . $text[2] . '">
<i class=" ' . $text[3] . '"></i><span>' . $text[4] . '</span></a>';
}, $text);
return $text;
}
// 标签外挂-note
function Note_Fsm($text)
{
$text = preg_replace_callback('/\[note type=\"(.*?)\".*?\](.*?)\[\/note\]/ism', function ($text) {
return '<div class="note ' . $text[1] . '"> <p>' . $text[2] . '</p></div>';
}, $text);
return $text;
}
// 标签外挂-note_ico
function Note_Ico($text)
{
$text = preg_replace_callback('/\[note-ico type=\"(.*?)\".*?\ ico=\"(.*?)\"](.*?)\[\/note-ico\]/ism', function ($text) {
return '<div class="note ' . $text[1] . '"><i class="' . $text[2] . '"></i><p>' . $text[3] . '</p></div>';
}, $text);
return $text;
}
// hide-inline
function Hide_Lnline($text)
{
$text = preg_replace_callback('/\[hide-inline name=\"(.*?)\".*?\](.*?)\[\/hide-inline\]/ism', function ($text) {
return '<span class="hide-inline"><button type="button" class="hide-button button--animated">' . $text[1] . '</button><span class="hide-content">' . $text[2] . '</span></span>';
}, $text);
return $text;
}
// hide-block
function Hide_Block($text)
{
$text = preg_replace_callback('/\[hide-block name=\"(.*?)\".*?\](.*?)\[\/hide-block\]/ism', function ($text) {
return '<div class="hide-block"><button type="button" class="hide-button button--animated">' . $text[1] . '</button><div class="hide-content">' . $text[2] . '</div></div>';
}, $text);
return $text;
}
// hide-toggle
function Hide_Toggle($text)
{
$text = preg_replace_callback('/\[hide-toggle name=\"(.*?)\".*?\](.*?)\[\/hide-toggle\]/ism', function ($text) {
return '<details class="toggle"><summary class="toggle-button">' . $text[1] . '</summary><div class="toggle-content">' . $text[2] . '</div></details>';
}, $text);
return $text;
}
// 复选框
function Cheak_Box($text)
{
$text = preg_replace_callback('/\[cb type=\"(.*?)\".*?\ checked=\"(.*?)"\](.*?)\[\/cb\]/ism', function ($text) {
return '<div class="checkbox '. $text[1] .' checked"><input type="checkbox" '. $text[2] .'>'. $text[3] .'</div>';
}, $text);
return $text;
}
// 行内标签
function inline_Tag($text)
{
$text = preg_replace_callback('/\[in-tag color=\"(.*?)\"](.*?)\[\/in-tag\]/ism', function ($text) {
return '<span class="inline-tag '. $text[1] .'">'. $text[2] .'</span>';
}, $text);
return $text;
}
// 单选框-radio
function Bf_Radio($text)
{
$text = preg_replace_callback('/\[radio color=\"(.*?)\".*?\ checked=\"(.*?)"\](.*?)\[\/radio\]/ism', function ($text) {
return '<div class="checkbox '. $text[1] .' checked"><input type="radio" '. $text[2] .'>'. $text[3] .'</div>';
}, $text);
return $text;
}
function Bf_Mark($text)
{
$text = preg_replace_callback('/\[label color=\"(.*?)\".*?\](.*?)\[\/label\]/ism', function ($text) {
return '<mark class="hl-label '. $text[1] .'">'. $text[2] .'</mark>';
}, $text);
return $text;
}
// 重写文章图片加载
function PostImage($text)
{
$text = preg_replace_callback('/<img src=\"(.*?)\".*?alt\=\"(.*?)\".*?>/ism', function ($text) {
return '<img class="" title="'.$text[2].'" alt="'.$text[2].'" data-lazy-src="'.$text[1].'" src="'.GetLazyLoad().'" />';
}, $text);
return $text;
}
function themeInit($archive) {