-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Archive.php
2080 lines (1758 loc) · 60.9 KB
/
Archive.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
namespace Widget;
use Typecho\Common;
use Typecho\Config;
use Typecho\Cookie;
use Typecho\Db;
use Typecho\Db\Query;
use Typecho\Router;
use Typecho\Widget\Exception as WidgetException;
use Typecho\Widget\Helper\PageNavigator\Classic;
use Typecho\Widget\Helper\PageNavigator\Box;
use Widget\Base\Contents;
use Widget\Comments\Ping;
use Widget\Contents\Attachment\Related as AttachmentRelated;
use Widget\Contents\Related\Author as AuthorRelated;
use Widget\Contents\From as ContentsFrom;
use Widget\Contents\Related as ContentsRelated;
use Widget\Metas\From as MetasFrom;
use Widget\Contents\Page\Rows as PageRows;
use Widget\Users\Author;
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
/**
* 内容的文章基类
* 定义的css类
* p.more:阅读全文链接所属段落
*
* @package Widget
*/
class Archive extends Contents
{
/**
* 调用的风格文件
*
* @var string
*/
private string $themeFile;
/**
* 风格目录
*
* @var string
*/
private string $themeDir;
/**
* 分页计算对象
*
* @var Query
*/
private Query $countSql;
/**
* 所有文章个数
*
* @var int|null
*/
private ?int $total = null;
/**
* 标记是否为从外部调用
*
* @var boolean
*/
private bool $invokeFromOutside = false;
/**
* 是否由聚合调用
*
* @var boolean
*/
private bool $invokeByFeed = false;
/**
* 当前页
*
* @var integer
*/
private int $currentPage;
/**
* 生成分页的内容
*
* @var Router\ParamsDelegateInterface
*/
private Router\ParamsDelegateInterface $pageRow;
/**
* RSS 2.0聚合地址
*
* @var string
*/
private string $archiveFeedUrl;
/**
* RSS 1.0聚合地址
*
* @var string
*/
private string $archiveFeedRssUrl;
/**
* ATOM 聚合地址
*
* @var string
*/
private string $archiveFeedAtomUrl;
/**
* 本页关键字
*
* @var string|null
*/
private ?string $archiveKeywords = null;
/**
* 本页描述
*
* @var string|null
*/
private ?string $archiveDescription = null;
/**
* 归档标题
*
* @var string|null
*/
private ?string $archiveTitle = null;
/**
* 归档地址
*
* @var string|null
*/
private ?string $archiveUrl = null;
/**
* 归档类型
*
* @var string
*/
private string $archiveType = 'index';
/**
* 是否为单一归档
*
* @var boolean
*/
private bool $archiveSingle = false;
/**
* 是否为自定义首页, 主要为了标记自定义首页的情况
*
* (default value: false)
*
* @var boolean
* @access private
*/
private bool $makeSinglePageAsFrontPage = false;
/**
* 归档缩略名
*
* @access private
* @var string
*/
private string $archiveSlug;
/**
* @param Config $parameter
* @throws \Exception
*/
protected function initParameter(Config $parameter)
{
$parameter->setDefault([
'pageSize' => $this->options->pageSize,
'type' => null,
'checkPermalink' => true,
'preview' => false,
'commentPage' => 0
]);
/** 用于判断是路由调用还是外部调用 */
if (null == $parameter->type) {
if (!isset(Router::$current)) {
throw new WidgetException('Archive type is not set', 500);
}
$parameter->type = Router::$current;
} else {
$this->invokeFromOutside = true;
}
/** 用于判断是否为feed调用 */
if ($parameter->isFeed) {
$this->invokeByFeed = true;
}
/** 初始化皮肤路径 */
$this->themeDir = rtrim($this->options->themeFile($this->options->theme), '/') . '/';
}
/**
* 增加标题
* @param string $archiveTitle 标题
*/
public function addArchiveTitle(string $archiveTitle)
{
$current = $this->getArchiveTitle();
$current[] = $archiveTitle;
$this->setArchiveTitle($current);
}
/**
* @return string
*/
public function getArchiveTitle(): ?string
{
return $this->archiveTitle;
}
/**
* @param string $archiveTitle the $archiveTitle to set
*/
public function setArchiveTitle(string $archiveTitle)
{
$this->archiveTitle = $archiveTitle;
}
/**
* @return string|null
*/
public function getArchiveSlug(): ?string
{
return $this->archiveSlug;
}
/**
* @param string $archiveSlug the $archiveSlug to set
*/
public function setArchiveSlug(string $archiveSlug)
{
$this->archiveSlug = $archiveSlug;
}
/**
* @return string|null
*/
public function getArchiveType(): ?string
{
return $this->archiveType;
}
/**
* @param string $archiveType the $archiveType to set
*/
public function setArchiveType(string $archiveType)
{
$this->archiveType = $archiveType;
}
/**
* @return string|null
*/
public function getArchiveUrl(): ?string
{
return $this->archiveUrl;
}
/**
* @param string|null $archiveUrl
*/
public function setArchiveUrl(?string $archiveUrl): void
{
$this->archiveUrl = $archiveUrl;
}
/**
* @return string|null
*/
public function getArchiveDescription(): ?string
{
return $this->archiveDescription;
}
/**
* @param string $archiveDescription the $description to set
*/
public function setArchiveDescription(string $archiveDescription)
{
$this->archiveDescription = $archiveDescription;
}
/**
* @return string|null
*/
public function getArchiveKeywords(): ?string
{
return $this->archiveKeywords;
}
/**
* @param string $archiveKeywords the $keywords to set
*/
public function setArchiveKeywords(string $archiveKeywords)
{
$this->archiveKeywords = $archiveKeywords;
}
/**
* @return string
*/
public function getArchiveFeedAtomUrl(): string
{
return $this->archiveFeedAtomUrl;
}
/**
* @param string $archiveFeedAtomUrl the $feedAtomUrl to set
*/
public function setArchiveFeedAtomUrl(string $archiveFeedAtomUrl)
{
$this->archiveFeedAtomUrl = $archiveFeedAtomUrl;
}
/**
* @return string
*/
public function getArchiveFeedRssUrl(): string
{
return $this->archiveFeedRssUrl;
}
/**
* @param string $archiveFeedRssUrl the $feedRssUrl to set
*/
public function setArchiveFeedRssUrl(string $archiveFeedRssUrl)
{
$this->archiveFeedRssUrl = $archiveFeedRssUrl;
}
/**
* @return string
*/
public function getArchiveFeedUrl(): string
{
return $this->archiveFeedUrl;
}
/**
* @param string $archiveFeedUrl the $feedUrl to set
*/
public function setArchiveFeedUrl(string $archiveFeedUrl)
{
$this->archiveFeedUrl = $archiveFeedUrl;
}
/**
* Get the value of feed
* Deprecated since 1.3.0
*
* @deprecated 1.3.0
* @return null
*/
public function getFeed()
{
return null;
}
/**
* Set the value of feed
* Deprecated since 1.3.0
*
* @deprecated 1.3.0
* @param null $feed
*/
public function setFeed($feed)
{
}
/**
* @return Query|null
*/
public function getCountSql(): ?Query
{
return $this->countSql;
}
/**
* @param Query $countSql the $countSql to set
*/
public function setCountSql($countSql)
{
$this->countSql = $countSql;
}
/**
* @return int
*/
public function getCurrentPage(): int
{
return $this->currentPage;
}
/**
* _currentPage
*
* @return int
*/
public function ____currentPage(): int
{
return $this->getCurrentPage();
}
/**
* 获取页数
*
* @return integer
*/
public function getTotalPage(): int
{
return ceil($this->getTotal() / $this->parameter->pageSize);
}
/**
* @return int
* @throws Db\Exception
*/
public function getTotal(): int
{
if (!isset($this->total)) {
$this->total = $this->size($this->countSql);
}
return $this->total;
}
/**
* @param int $total the $total to set
*/
public function setTotal(int $total)
{
$this->total = $total;
}
/**
* @return string|null
*/
public function getThemeFile(): ?string
{
return $this->themeFile;
}
/**
* @param string $themeFile the $themeFile to set
*/
public function setThemeFile(string $themeFile)
{
$this->themeFile = $themeFile;
}
/**
* @return string|null
*/
public function getThemeDir(): ?string
{
return $this->themeDir;
}
/**
* @param string $themeDir the $themeDir to set
*/
public function setThemeDir(string $themeDir)
{
$this->themeDir = $themeDir;
}
/**
* 执行函数
*/
public function execute()
{
/** 避免重复取数据 */
if ($this->have()) {
return;
}
$handles = [
'index' => 'indexHandle',
'index_page' => 'indexHandle',
'archive' => 'archiveEmptyHandle',
'archive_page' => 'archiveEmptyHandle',
404 => 'error404Handle',
'single' => 'singleHandle',
'page' => 'singleHandle',
'post' => 'singleHandle',
'attachment' => 'singleHandle',
'category' => 'categoryHandle',
'category_page' => 'categoryHandle',
'tag' => 'tagHandle',
'tag_page' => 'tagHandle',
'author' => 'authorHandle',
'author_page' => 'authorHandle',
'archive_year' => 'dateHandle',
'archive_year_page' => 'dateHandle',
'archive_month' => 'dateHandle',
'archive_month_page' => 'dateHandle',
'archive_day' => 'dateHandle',
'archive_day_page' => 'dateHandle',
'search' => 'searchHandle',
'search_page' => 'searchHandle'
];
/** 处理搜索结果跳转 */
if ($this->request->is('s')) {
$filterKeywords = $this->request->filter('search')->get('s');
/** 跳转到搜索页 */
if (null != $filterKeywords) {
$this->response->redirect(
Router::url('search', ['keywords' => urlencode($filterKeywords)], $this->options->index)
);
}
}
/** 自定义首页功能 */
$frontPage = $this->options->frontPage;
if (!$this->invokeByFeed && ('index' == $this->parameter->type || 'index_page' == $this->parameter->type)) {
//显示某个页面
if (0 === strpos($frontPage, 'page:')) {
// 对某些变量做hack
$this->request->setParam('cid', intval(substr($frontPage, 5)));
$this->parameter->type = 'page';
$this->makeSinglePageAsFrontPage = true;
} elseif (0 === strpos($frontPage, 'file:')) {
// 显示某个文件
$this->setThemeFile(substr($frontPage, 5));
return;
}
}
if ('recent' != $frontPage && $this->options->frontArchive) {
$handles['archive'] = 'indexHandle';
$handles['archive_page'] = 'indexHandle';
$this->archiveType = 'front';
}
/** 初始化分页变量 */
$this->currentPage = $this->request->filter('int')->get('page', 1);
$hasPushed = false;
$this->pageRow = new class implements Router\ParamsDelegateInterface
{
public function getRouterParam(string $key): string
{
return '{' . $key . '}';
}
};
/** select初始化 */
$select = self::pluginHandle()->trigger($selectPlugged)->call('select', $this);
/** 定时发布功能 */
if (!$selectPlugged) {
$select = $this->select('table.contents.*');
if (!$this->parameter->preview) {
if ('post' == $this->parameter->type || 'page' == $this->parameter->type) {
if ($this->user->hasLogin()) {
$select->where(
'table.contents.status = ? OR table.contents.status = ?
OR (table.contents.status = ? AND table.contents.authorId = ?)',
'publish',
'hidden',
'private',
$this->user->uid
);
} else {
$select->where(
'table.contents.status = ? OR table.contents.status = ?',
'publish',
'hidden'
);
}
} else {
if ($this->user->hasLogin()) {
$select->where(
'table.contents.status = ? OR (table.contents.status = ? AND table.contents.authorId = ?)',
'publish',
'private',
$this->user->uid
);
} else {
$select->where('table.contents.status = ?', 'publish');
}
}
$select->where('table.contents.created < ?', $this->options->time);
}
}
/** handle初始化 */
self::pluginHandle()->call('handleInit', $this, $select);
/** 初始化其它变量 */
$this->archiveFeedUrl = $this->options->feedUrl;
$this->archiveFeedRssUrl = $this->options->feedRssUrl;
$this->archiveFeedAtomUrl = $this->options->feedAtomUrl;
$this->archiveKeywords = $this->options->keywords;
$this->archiveDescription = $this->options->description;
$this->archiveUrl = $this->options->siteUrl;
if (isset($handles[$this->parameter->type])) {
$handle = $handles[$this->parameter->type];
$this->{$handle}($select, $hasPushed);
} else {
$hasPushed = self::pluginHandle()->call('handle', $this->parameter->type, $this, $select);
}
/** 初始化皮肤函数 */
$functionsFile = $this->themeDir . 'functions.php';
if (
(!$this->invokeFromOutside || $this->parameter->type == 404 || $this->parameter->preview)
&& file_exists($functionsFile)
) {
require_once $functionsFile;
if (function_exists('themeInit')) {
themeInit($this);
}
}
/** 如果已经提前压入则直接返回 */
if ($hasPushed) {
return;
}
/** 仅输出文章 */
$this->countSql = clone $select;
$select->order('table.contents.created', Db::SORT_DESC)
->page($this->currentPage, $this->parameter->pageSize);
$this->query($select);
/** 处理超出分页的情况 */
if ($this->currentPage > 1 && !$this->have()) {
throw new WidgetException(_t('请求的地址不存在'), 404);
}
}
/**
* 重载select
*
* @param mixed $fields
* @return Query
* @throws Db\Exception
*/
public function select(...$fields): Query
{
if ($this->invokeByFeed) {
// 对feed输出加入限制条件
return parent::select(...$fields)->where('table.contents.allowFeed = ?', 1)
->where("table.contents.password IS NULL OR table.contents.password = ''");
} else {
return parent::select(...$fields);
}
}
/**
* 输出文章内容
*
* @param string $more 文章截取后缀
*/
public function content($more = null)
{
parent::content($this->is('single') ? false : $more);
}
/**
* 输出分页
*
* @param string $prev 上一页文字
* @param string $next 下一页文字
* @param int $splitPage 分割范围
* @param string $splitWord 分割字符
* @param string|array $template 展现配置信息
* @throws Db\Exception|WidgetException
*/
public function pageNav(
string $prev = '«',
string $next = '»',
int $splitPage = 3,
string $splitWord = '...',
$template = ''
) {
if ($this->have()) {
$hasNav = false;
$default = [
'wrapTag' => 'ol',
'wrapClass' => 'page-navigator'
];
if (is_string($template)) {
parse_str($template, $config);
} else {
$config = $template ?: [];
}
$template = array_merge($default, $config);
$total = $this->getTotal();
$query = Router::url(
$this->parameter->type .
(false === strpos($this->parameter->type, '_page') ? '_page' : null),
$this->pageRow,
$this->options->index
);
self::pluginHandle()->trigger($hasNav)->call(
'pageNav',
$this->currentPage,
$total,
$this->parameter->pageSize,
$prev,
$next,
$splitPage,
$splitWord,
$template,
$query
);
if (!$hasNav && $total > $this->parameter->pageSize) {
/** 使用盒状分页 */
$nav = new Box(
$total,
$this->currentPage,
$this->parameter->pageSize,
$query
);
echo '<' . $template['wrapTag'] . (empty($template['wrapClass'])
? '' : ' class="' . $template['wrapClass'] . '"') . '>';
$nav->render($prev, $next, $splitPage, $splitWord, $template);
echo '</' . $template['wrapTag'] . '>';
}
}
}
/**
* 前一页
*
* @param string $word 链接标题
* @param string $page 页面链接
* @throws Db\Exception|WidgetException
*/
public function pageLink(string $word = '« Previous Entries', string $page = 'prev')
{
static $nav;
if ($this->have()) {
if (!isset($nav)) {
$query = Router::url(
$this->parameter->type .
(false === strpos($this->parameter->type, '_page') ? '_page' : null),
$this->pageRow,
$this->options->index
);
/** 使用盒状分页 */
$nav = new Classic(
$this->getTotal(),
$this->currentPage,
$this->parameter->pageSize,
$query
);
}
$nav->{$page}($word);
}
}
/**
* 获取评论归档对象
*
* @access public
* @return \Widget\Comments\Archive
*/
public function comments(): \Widget\Comments\Archive
{
$parameter = [
'parentId' => $this->hidden ? 0 : $this->cid,
'parentContent' => $this,
'respondId' => $this->respondId,
'commentPage' => $this->parameter->commentPage,
'allowComment' => $this->allow('comment')
];
return \Widget\Comments\Archive::alloc($parameter);
}
/**
* 获取回响归档对象
*
* @return Ping
*/
public function pings(): Ping
{
return Ping::alloc([
'parentId' => $this->hidden ? 0 : $this->cid,
'parentContent' => $this->row,
'allowPing' => $this->allow('ping')
]);
}
/**
* 获取附件对象
*
* @param integer $limit 最大个数
* @param integer $offset 重新
* @return AttachmentRelated
*/
public function attachments(int $limit = 0, int $offset = 0): AttachmentRelated
{
return AttachmentRelated::allocWithAlias($this->cid . '-' . uniqid(), [
'parentId' => $this->cid,
'limit' => $limit,
'offset' => $offset
]);
}
/**
* 显示下一个内容的标题链接
*
* @param string $format 格式
* @param string|null $default 如果没有下一篇,显示的默认文字
* @param array $custom 定制化样式
*/
public function theNext(string $format = '%s', ?string $default = null, array $custom = [])
{
$query = $this->select()->where(
'table.contents.created > ? AND table.contents.created < ?',
$this->created,
$this->options->time
)
->where('table.contents.status = ?', 'publish')
->where('table.contents.type = ?', $this->type)
->where("table.contents.password IS NULL OR table.contents.password = ''")
->order('table.contents.created', Db::SORT_ASC)
->limit(1);
$this->theLink(
ContentsFrom::allocWithAlias('next:' . $this->cid, ['query' => $query]),
$format,
$default,
$custom
);
}
/**
* 显示上一个内容的标题链接
*
* @access public
* @param string $format 格式
* @param string|null $default 如果没有上一篇,显示的默认文字
* @param array $custom 定制化样式
* @return void
*/
public function thePrev(string $format = '%s', ?string $default = null, array $custom = [])
{
$query = $this->select()->where('table.contents.created < ?', $this->created)
->where('table.contents.status = ?', 'publish')
->where('table.contents.type = ?', $this->type)
->where("table.contents.password IS NULL OR table.contents.password = ''")
->order('table.contents.created', Db::SORT_DESC)
->limit(1);
$this->theLink(
ContentsFrom::allocWithAlias('prev:' . $this->cid, ['query' => $query]),
$format,
$default,
$custom
);
}
/**
* @param Contents $content
* @param string $format
* @param string|null $default
* @param array $custom
* @return void
*/
public function theLink(Contents $content, string $format = '%s', ?string $default = null, array $custom = [])
{
if ($content->have()) {
$default = [
'title' => null,
'tagClass' => null
];
$custom = array_merge($default, $custom);
$linkText = $custom['title'] ?? $content->title;
$linkClass = empty($custom['tagClass']) ? '' : 'class="' . $custom['tagClass'] . '" ';
$link = '<a ' . $linkClass . 'href="' . $content->permalink
. '" title="' . $content->title . '">' . $linkText . '</a>';
printf($format, $link);
} else {
echo $default;
}
}
/**
* 获取关联内容组件
*
* @param integer $limit 输出数量
* @param string|null $type 关联类型
* @return Contents
*/
public function related(int $limit = 5, ?string $type = null): Contents
{
$type = strtolower($type ?? '');
switch ($type) {
case 'author':
/** 如果访问权限被设置为禁止,则tag会被置为空 */
return AuthorRelated::alloc(
['cid' => $this->cid, 'type' => $this->type, 'author' => $this->author->uid, 'limit' => $limit]
);
default:
/** 如果访问权限被设置为禁止,则tag会被置为空 */
return ContentsRelated::alloc(
['cid' => $this->cid, 'type' => $this->type, 'tags' => $this->tags, 'limit' => $limit]
);
}
}
/**
* 输出头部元数据
*
* @param string|null $rule 规则
*/
public function header(?string $rule = null)
{
$rules = [];
$allows = [
'description' => htmlspecialchars($this->archiveDescription ?? ''),
'keywords' => htmlspecialchars($this->archiveKeywords ?? ''),
'generator' => $this->options->generator,
'template' => $this->options->theme,
'pingback' => $this->options->xmlRpcUrl,
'xmlrpc' => $this->options->xmlRpcUrl . '?rsd',
'wlw' => $this->options->xmlRpcUrl . '?wlw',
'rss2' => $this->archiveFeedUrl,
'rss1' => $this->archiveFeedRssUrl,
'commentReply' => 1,
'antiSpam' => 1,
'social' => 1,
'atom' => $this->archiveFeedAtomUrl
];
/** 头部是否输出聚合 */
$allowFeed = !$this->is('single') || $this->allow('feed') || $this->makeSinglePageAsFrontPage;
if (!empty($rule)) {
parse_str($rule, $rules);
$allows = array_merge($allows, $rules);
}
$allows = self::pluginHandle()->call('headerOptions', $allows, $this);
$title = (empty($this->archiveTitle) ? '' : $this->archiveTitle . ' » ') . $this->options->title;
$header = $this->is('single') ? '<link rel="canonical" href="' . $this->archiveUrl . '" />' . "\n" : '';
if (!empty($allows['pingback']) && 2 == $this->options->allowXmlRpc) {
$header .= '<link rel="pingback" href="' . $allows['pingback'] . '" />' . "\n";
}
if (!empty($allows['xmlrpc']) && 0 < $this->options->allowXmlRpc) {
$header .= '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="'
. $allows['xmlrpc'] . '" />' . "\n";
}
if (!empty($allows['wlw']) && 0 < $this->options->allowXmlRpc) {
$header .= '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
. $allows['wlw'] . '" />' . "\n";
}
if (!empty($allows['rss2']) && $allowFeed) {
$header .= '<link rel="alternate" type="application/rss+xml" title="'
. $title . ' » RSS 2.0" href="' . $allows['rss2'] . '" />' . "\n";
}
if (!empty($allows['rss1']) && $allowFeed) {
$header .= '<link rel="alternate" type="application/rdf+xml" title="'
. $title . ' » RSS 1.0" href="' . $allows['rss1'] . '" />' . "\n";
}
if (!empty($allows['atom']) && $allowFeed) {
$header .= '<link rel="alternate" type="application/atom+xml" title="'