/
ubbdisplay.php
1085 lines (932 loc) · 36.1 KB
/
ubbdisplay.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
class UbbDisplay extends XUBBP
{
// markdown解析器
protected $Parsedown = NULL;
// 是否处于markdown模式
protected $markdownEnable = false;
// markdown受保护内容(防止markdown解析干扰这些内容)
protected $mdProtectTags = [];
protected $mdProtectTexts = [];
/*注册显示回调函数*/
protected $display = array(
/*开启markdown模式*/
'markdown'=>'markdown',
/*markdown受保护内容(不被XUBBP解析器干扰)*/
'mdpre' => 'mdpre',
/*text 纯文本*/
'text' => 'text',
/*newline 换行*/
'newline' => 'newline',
'tab' => 'tab',
'empty' => 'emptyTag',
/*link 链接*/
'url' => 'link',
'urlzh' => 'link',
'urlout' => 'link',
'urlname' => 'urlname',
/*img 图片*/
'img' => 'img',
'imgzh' => 'img',
'thumb' => 'thumb',
/*code 代码高亮*/
'code' => 'code',
'mdcode' => 'code',
/*time 时间标记*/
'time' => 'time',
/*video 视频*/
'video' => 'video',
'videoStream' => 'videoStream',
/*audio 视频*/
'audio' => 'audio',
'audioStream' => 'audioStream',
/*copyright 版权声明*/
'copyright' => 'copyright',
/*battlenet 战网*/
'battlenet' => 'battlenet',
/*math 数学公式*/
'math' => 'math',
'mathzh' => 'math',
/*layout 布局*/
'layout' => 'layout',
/*style 风格*/
'style' => 'style',
/*urltxt 网址文本*/
'urltxt' => 'urltxt',
/*mailtxt 邮箱文本*/
'mailtxt' => 'mailtxt',
/*at消息*/
'at' => 'at',
'atMsg' => 'atMsg',
/*face 表情*/
'face' => 'face',
/*iframe 网页嵌入*/
'iframe' => 'iframe',
/* html 通过iframe的srcdoc属性实现的HTML内容嵌入 */
'html' => 'html',
/*管理员操作*/
'adminEdit' => 'adminEditNotice',
'adminDel' => 'adminDelNotice',
'delContent' => 'adminDelContent',
'adminAction' => 'adminActionNotice',
'postNeedReview' => 'postNeedReviewNotice',
);
public function display($ubbArray, $serialize = false, $maxLen = null, $page = null)
{
$disable = $this->getOpt('all.blockPost');
if ($disable) {
return '<div class="tp info-box userblocked">用户被禁言,发言自动屏蔽。</div>';
}
if ($serialize) {
$ubbArray = unserialize($ubbArray);
}
$this->markdownEnable = false;
$html = parent::display($ubbArray, false, $maxLen, $page);
if ($this->markdownEnable) {
if (!$this->Parsedown) {
$this->Parsedown = new Parsedown();
$this->Parsedown->setBreaksEnabled(true); //自动换行
//$this->Parsedown->setMarkupEscaped(true); //转义html
//$this->Parsedown->setUrlsLinked(false); //不解析链接
}
$html = '<div class="markdown-body">' . $this->Parsedown->text($html) . '</div>';
// 还原被保护的内容
$html = str_replace($this->mdProtectTags, $this->mdProtectTexts, $html);
$this->mdProtectTags = [];
$this->mdProtectTexts = [];
}
//$html = nl2br(htmlspecialchars($html)); // debug
return $html;
}
/*开启markdown模式*/
public function markdown($data){
$this->markdownEnable = true;
return '';
}
/*markdown受保护内容(不被XUBBP解析器干扰)*/
public function mdpre($data){
return $data['data'];
}
/* 保护内容免受markdown解析的干扰 */
public function markdownProtect($html) {
if ($this->markdownEnable) {
$this->mdProtectTexts[] = $html;
/*
* 添加块级的<p>标签是为了确保上下文关系不被破坏,比如
*
* aaa
* ```
* xxx
* ```
* ------------
*
* 这条线本来应该原样保留,如果保护标记不是块级的,
* 保护后它和上面的aaa结合,就会使aaa成为二级标题。
*/
$html = "<p>\2".count($this->mdProtectTexts)."\3</p>";
$this->mdProtectTags[] = $html;
}
return "\n$html\n";
}
/* 保护inline内容免受markdown解析的干扰 */
public function markdownProtectInline($html) {
if ($this->markdownEnable) {
$this->mdProtectTexts[] = $html;
$html = "\2".count($this->mdProtectTexts)."\3";
$this->mdProtectTags[] = $html;
}
return $html;
}
/*text 纯文本*/
public function text($data)
{
$text = str::过滤滥用($data['value']);
if ($this->markdownEnable) {
return str::htmlTagToEntity($text);
}
else {
return code::html($text, '<br/>');
}
}
/*代码高亮*/
public function code($data)
{
global $PAGE;
//不再把代码高亮交给markdown引擎处理,而是由PHP统一处理
/*if (empty($data['lang']) && $this->markdownEnable) {
$quote = isset($data['quote']) ? $data['quote'] : '```';
return $quote . $data['data'] . $quote;
}*/
$code = $data['data'];
// 去除开头的第一个换行符
if (strlen($code) > 1) {
if ($code[0] == "\r") {
$code = substr($code, 1);
}
if ($code[0] == "\n") {
$code = substr($code, 1);
}
}
if ($data['lang'] == 'latex') {
$html = '<latex-js class="userlatex">'.htmlspecialchars($code).'</latex-js>';
} else {
$html = '<pre class="hu60_code"><code class="'.code::html($data['lang']).'">'.code::html($code).'</code></pre>';
}
/*if (isset($data['html'])) {
$html = $data['html'];
}
else {
$html = code::highlight($data['data'], $data['lang']);
}*/
return $this->markdownProtect($html);
}
/*time 时间*/
public function time($data)
{
if ($data['tag'] == '') {
$data['tag'] = 'Y-m-d H:i:s';
}
return code::html(date($data['tag']));
}
/*link 链接*/
public function link($data)
{
global $PAGE;
if (is_array($data['title'])) {
$ubb = new UbbDisplay;
$ubb->opt = $this->opt;
$data['title'] = $ubb->display($data['title']);
} else {
if (trim($data['title']) == '') $data['title'] = $data['url'];
$data['title'] = code::html($data['title']);
}
if ($data['type'] == 'urlout') $data['url'] = 'http://' . $data['url'];
if (JsonPage::isJsonPage() || $data['url'][0] == '#') {
$url = $data['url'];
} else {
$url = SITE_ROUTER_PATH . '/link.url.' . $PAGE->bid . '?url64=' . code::b64e($data['url']);
}
return '<a class="userlink" href="' . code::html($url) . '">' . $data['title'] . '</a>';
}
public function urlname($data)
{
return '<a class="usertarget" name="' . code::html($data['url']) . '">' . code::html($data['title']) . '</a><a name="/' . code::html($data['url']) . '"></a>';
}
/*从url中解析出图片大小、旋转参数,将参数转换为CSS或者七牛云图像处理URL*/
protected function parseImgStyleFromUrl(&$url, &$alt) {
$pos1 = strpos($url, '#'); // 半角#号
$pos1 = (FALSE !== $pos1) ? $pos1 : strpos($url, '#'); // 全角#号
$pos2 = strpos($alt, '#'); // 半角#号
$pos2 = (FALSE !== $pos2) ? $pos2 : strpos($alt, '#'); // 全角#号
if ($pos1 === FALSE && $pos2 === FALSE) {
return '';
}
if ($pos1 !== FALSE) {
$param = substr($url, $pos1);
$url = substr($url, 0, $pos1);
}
elseif ($pos2 !== FALSE) {
$param = substr($alt, $pos2);
$alt = substr($alt, 0, $pos2);
}
$orientation = 0; // 方向(度)
$flip = false; // 翻转
$width = 0; // 宽
$height = 0; // 高
if (strpos($param, '上') || strpos($param, '正')) {
$orientation = 0;
}
elseif (strpos($param, '下') || strpos($param, '倒')) {
$orientation = 180;
}
elseif (strpos($param, '左')) {
$orientation = 90;
}
elseif (strpos($param, '右')) {
$orientation = 270;
}
if (strpos($param, '翻')) {
$flip = true;
}
if (preg_match('/(\d+)x(\d+)/i', $param, $arr)) {
$width = (int)$arr[1];
$height = (int)$arr[2];
}
elseif (preg_match('/(\d+)/', $param, $arr)) {
$width = (int)$arr[1];
}
$css = [];
if ($orientation != 0) {
$url .= "?imageMogr2/rotate/$orientation";
}
if ($flip) {
$css[] = 'transform: scaleX(-1);';
}
if ($width > 0) {
$css[] = "width: {$width}px";
}
if ($height > 0) {
$css[] = "height: {$height}px";
}
return ' style="' . implode('; ', $css) . '"';
}
/*img 图片*/
public function img($data)
{
global $PAGE;
$url = $data['src'];
$alt = $data['alt'];
$style = $this->parseImgStyleFromUrl($url, $alt);
//百度输入法多媒体输入
if (preg_match('#^(https?://ci.baidu.com)/([a-zA-Z0-9]+)$#is', $url, $arr)) {
$prefix = $arr[1];
$imgId = $arr[2];
$url = $prefix . '/more?mm=' . $imgId;
}
if (!JsonPage::isJsonPage() && !preg_match('#^data:image/#is', $url)) {
$url = SITE_ROUTER_PATH . '/link.img.' . $PAGE->bid . '?url64=' . code::b64e($url);
}
if (!$data['in_link'])
return '<a class="userimglink" href="'.code::html($url).'"><img class="userimg" src="' . code::html($url) . '"' . $style . ($alt != '' ? ' alt="' . ($alt = code::html($alt)) . '" title="' . $alt . '"' : '') . '/></a>';
else
return '<img class="userimg" src="' . code::html($url) . '"' . $style . ($alt != '' ? ' alt="' . ($alt = code::html($alt)) . '" title="' . $alt . '"' : '') . '/>';
}
/*thumb 缩略图*/
public function thumb($data)
{
global $PAGE;
$src = code::html($data['src']);
//百度输入法多媒体输入
if (preg_match('#^(https?://ci\.baidu\.com)/([a-zA-Z0-9]+)$#is', $src, $arr)) {
$prefix = $arr[1];
$imgId = $arr[2];
$src = $prefix . '/more?mm=' . $imgId;
}
if (JsonPage::isJsonPage()) {
$url = $src;
$base = SITE_URL_BASE;
} else {
$url = SITE_ROUTER_PATH . '/link.img.' . $PAGE->bid . '?url64=' . code::b64e($src);
$base = '';
}
if (!$data['in_link']) {
return '<a class="userthumblink" href="' . $url . '"><img class="userthumb" src="' . $base . 'link.thumb.' . floor($data['w']) . '.' . floor($data['h']) . '.' . bin2hex($src) . '.png" alt="点击查看大图"/></a>';
}
else {
return '<img class="userthumb" src="' . $base . 'link.thumb.' . floor($data['w']) . '.' . floor($data['h']) . '.' . bin2hex($src) . '.png" alt="点击进入链接"/>';
}
}
/*video 视频*/
public function video($data)
{
global $PAGE;
static $id = 0;
$id ++;
$url = $data['url'];
$iframeUrl = null;
$heightJs = 'box.offsetWidth*2/3';
//优酷
if (preg_match('#\.youku\.com/.*/id_([a-zA-Z0-9=]+)#', $url, $arr)) {
$iframeUrl = 'https://player.youku.com/embed/'.$arr[1];
}
//土豆(失效)
//else if (preg_match('#\.tudou\.com/.*/([a-zA-Z0-9=]+)#', $url, $arr)) {
// $iframeUrl = 'https://www.tudou.com/programs/view/html5embed.action?code='.$arr[1];
//}
//全民K歌
else if (preg_match('#kg.*\.qq\.com/.*\bs=([a-zA-Z0-9=]+)#', $url, $arr)) {
$iframeUrl = 'https://kg.qq.com/node/play?s='.$arr[1];
$heightJs = 'box.offsetWidth';
}
//腾讯视频
else if (preg_match('#\.qq\.com/.*/([a-zA-Z0-9=]+)#', $url, $arr)) {
$iframeUrl = 'https://v.qq.com/txp/iframe/player.html?vid='.$arr[1];
}
//哔哩哔哩 av号
else if (preg_match('#\b(?:bilibili\.com|b23\.tv)\b.*\bav(\d+)(?:.*\bp=(\d+))?#', $url, $arr)) {
$iframeUrl = 'https://player.bilibili.com/player.html?aid='.$arr[1].'&page='.$arr[2];
}
//哔哩哔哩 BV号
else if (preg_match('#\b(?:bilibili\.com|b23\.tv)\b.*\b(BV[\w]+)(?:.*\bp=(\d+))?#', $url, $arr)) {
$iframeUrl = 'https://player.bilibili.com/player.html?bvid='.$arr[1].'&page='.$arr[2];
}
if (null !== $iframeUrl) {
$html = '<p class="video_box"><a class="uservideosite" target="_blank" href="'.code::html($url).'">视频链接</a><br/><iframe class="video" id="video_site_'.$id.'" src="'.code::html($iframeUrl).'" seamless allowfullscreen sandbox="allow-scripts allow-forms allow-same-origin allow-popups"><a href="'.code::html($url).'">'.code::html($url).'</a></iframe></p><script>(function(){var box=document.getElementById("video_site_'.$id.'");box.style.height=('.$heightJs.')+\'px\';})()</script>';
}
else {
if (JsonPage::isJsonPage()) {
$link = $url;
} else {
$link = SITE_ROUTER_PATH . '/link.url.' . $PAGE->bid . '?url64=' . code::b64e($data['url']);
}
$html = '<p class="video_box"><a class="uservideosite" target="_blank" href="'.code::html($link).'">'.code::html($url).'</a></p>';
}
return $this->markdownProtect($html);
}
/*audio 音频*/
public function audio($data)
{
global $PAGE;
$url = $data['url'];
$iframe = null;
if (preg_match('#kg.*\.qq\.com/.*\bs=([a-zA-Z0-9=]+)#', $url)) {
return $this->video($data);
}
elseif (preg_match('#music\.163\.com/.*\bid=(\d+)#', $url, $arr)) {
$iframe = '<iframe class="audio" height="86" seamless sandbox="allow-scripts allow-forms allow-same-origin allow-popups" src="https://music.163.com/outchain/player?type=2&id='.$arr[1].'&auto=0&height=66"></iframe>';
}
if (null === $iframe) {
if (JsonPage::isJsonPage()) {
$link = $url;
} else {
$link = SITE_ROUTER_PATH . '/link.url.' . $PAGE->bid . '?url64=' . code::b64e($data['url']);
}
$html = '<p class="audio_box"><a class="useraudiosite" target="_blank" href="'.code::html($link).'">'.code::html($url).'</a></p>';
} else {
$html = '<p class="audio_box"><a class="useraudiosite" target="_blank" href="'.code::html($url).'">音频链接</a><br/>'.$iframe.'</p>';
}
return $this->markdownProtect($html);
}
/*videoStream 视频流*/
public function videoStream($data)
{
global $PAGE;
$url = $data['url'];
if (CLOUD_STORAGE_USE_HTTPS) {
$url = preg_replace('#^http://'.CLOUD_STORAGE_DOWNLOAD_HOST.'/#i', 'https://'.CLOUD_STORAGE_DOWNLOAD_HOST.'/', $url);
}
//百度输入法多媒体输入
if (preg_match('#^(https?://ci.baidu.com)/([a-zA-Z0-9]+)$#is', $url, $arr)) {
$prefix = $arr[1];
$imgId = $arr[2];
$url = $prefix . '/more?mm=' . $imgId;
}
if (JsonPage::isJsonPage() || preg_match('#^data:(video|audio)/#is', $url)) {
$link = $data['url'];
} else {
$link = SITE_ROUTER_PATH . '/link.url.' . $PAGE->bid . '?url64=' . code::b64e($data['url']);
}
return '
<p class="video_box">
<a class="uservideolink" target="_blank" href="'.code::html($link).'">视频链接</a><br/>
<video class="video" src="'.code::html($url).'" controls></video>
</p>
';
}
/*audioStream 音频流*/
public function audioStream($data)
{
global $PAGE;
$url = $data['url'];
if (CLOUD_STORAGE_USE_HTTPS) {
$url = preg_replace('#^http://'.CLOUD_STORAGE_DOWNLOAD_HOST.'/#i', 'https://'.CLOUD_STORAGE_DOWNLOAD_HOST.'/', $url);
}
//百度输入法多媒体输入
if (preg_match('#^(https?://ci.baidu.com)/([a-zA-Z0-9]+)$#is', $url, $arr)) {
$prefix = $arr[1];
$imgId = $arr[2];
$url = $prefix . '/more?mm=' . $imgId;
}
if (JsonPage::isJsonPage() || preg_match('#^data:(video|audio)/#is', $url)) {
$link = $data['url'];
} else {
$link = SITE_ROUTER_PATH . '/link.url.' . $PAGE->bid . '?url64=' . code::b64e($data['url']);
}
return '
<p class="audio_box">
<a class="useraudiolink" target="_blank" href="'.code::html($link).'">音频链接</a><br/>
<audio class="audio" src="'.code::html($url).'" controls></audio>
</p>
';
}
/*copyright 版权声明*/
public function copyright($data)
{
$x = strtolower($data['tag']);
if (substr($x, 0, 3) == 'cc-') {
$en = 'by';
$cn = '署名';
if (strpos($x, '-nc')) {
$en .= '-nc';
$cn .= '-非商业性使用';
}
if (strpos($x, '-nd')) {
$en .= '-nd';
$cn .= '-禁止演绎';
} elseif (strpos($x, '-sa')) {
$en .= '-sa';
$cn .= '-相同方式共享';
}
return '<a rel="license" href="http://creativecommons.org/licenses/' . $en . '/3.0/cn/"><img alt="知识共享许可协议|Creative Commons" style="border-width:0" src="http://i.creativecommons.org/l/' . $en . '/3.0/cn/88x31.png" /></a><br/>本作品采用<a rel="license" href="http://creativecommons.org/licenses/' . $en . '/3.0/cn/">知识共享' . $cn . '3.0许可协议</a>进行许可。';
}
if ($x == 'gfdl') {
return '本作品采用<a rel="license" href="http://baike.baidu.com/view/20722.htm">GNU自由文档许可证</a>进行许可。';
}
if ($x == '公有领域' or $x == '公共领域') {
return '本作品属于<a rel="license" href="http://baike.baidu.com/view/556002.htm">公有领域</a>。';
}
return '本作品采用' . code::html($data['tag']) . '进行许可。';
}
/*battlenet 战网*/
public function battlenet($data)
{
if ($data['server'] != '') {
if ($data['display'] == null) {
$data['display'] = "{$data['name']}@{$data['server']}";
}
return '<a class="userbattlenet" href="http://www.battlenet.com.cn/wow/zh/character/' . urlencode($data['server']) . '/' . urlencode($data['name']) . '/simple">' . code::html($data['display']) . '</a>';
} else {
if ($data['display'] == null) {
$data['display'] = "{$data['name']}";
}
return '<a class="userbattlenet" href="http://www.battlenet.com.cn/wow/zh/search?q=' . urlencode($data['name']) . '&f=wowcharacter">' . code::html($data['display']) . '</a>';
}
}
/*math 数学公式*/
public function math($data) {
$html = '<hu60-math class="usermath">'.code::html($data['data']).'</hu60-math>';
return $this->markdownProtect($html);
}
/*newline 换行*/
public function newline($data)
{
if (in_array($data['tag'], ['hr', '<<<'])) {
return '<br/>--------<br/>';
} else {
return '<br/>';
}
}
/*tab 4em空格*/
public function tab($data)
{
return ' ';
}
/*empty UBB转义*/
public function emptyTag($data)
{
return '';
}
/*layout 布局*/
public function layout($data)
{
if ($data['tag'][0] != '/') {
$dataEnd = $data;
$dataEnd['tag'] = '/' . $data['tag'];
$this->regEndTag('/' . $data['tag'], 'layout', $dataEnd);
switch ($data['tag']) {
case 'b':
return '<span style="font-weight:bold">';
case 'i':
return '<span style="font-style:italic">';
case 'u':
return '<span style="text-decoration:underline">';
case 'center':
case 'left':
case 'right':
return '<span style="text-align:' . $data['tag'] . '">';
default:
return '<span>';
}
} else {
$html = '';
if ($this->rmEndTag($data['tag'], $html)) {
return $html . '</span>';
} else {
return '';
}
}
}
/*style 风格*/
public function style($data)
{
$disable = $this->getOpt('style.disable');
if ($data['tag'][0] != '/') {
if ($this->getOpt("style.hideUserCSS")) {
return '';
}
if ($disable) {
if ($disable !== 'noticed') {
$this->setOpt('style.disable', 'noticed');
return '<div class="tp info-box">由于该用户使用div和span标签破坏论坛版面,影响其他人正常的发言和聊天,该用户的div和span标签已被禁用。请大家引以为戒!</div>';
} else {
return '';
}
}
$dataEnd = $data;
$dataEnd['tag'] = '/' . $data['tag'];
$this->regEndTag('/' . $data['tag'], 'style', $dataEnd);
$opt = &$data['opt'];
if (!empty($opt)) {
$opt = preg_replace('#/\*.*\*/#sU', '', $opt);
$opt = preg_replace('#position\s*:[^;]*;?#is', '', $opt);
}
$uid = (int)($this->getOpt('uid'));
switch ($data['tag']) {
case 'color':
return '<span class="usercss uid-'.$uid.'" style="color:' . $this->markdownProtectInline(code::html($data['opt'], false, true)) . '">';
case 'div':
return '<div class="usercss uid-'.$uid.'" style="' . $this->markdownProtectInline(code::html($data['opt'], false, true)) . '">';
case 'span':
return '<span class="usercss uid-'.$uid.'" style="' . $this->markdownProtectInline(code::html($data['opt'], false, true)) . '">';
}
} else {
if ($this->getOpt("style.hideUserCSS")) {
return '';
}
if ($disable) {
return '';
}
$html = '';
if ($this->rmEndTag($data['tag'], $html)) {
switch ($data['tag']) {
case '/color':
$html .= '</span>';
break;
case '/div':
$html .= '</div>';
break;
case '/span':
$html .= '</span>';
break;
}
return $html;
} else {
return '';
}
}
}
/*urltxt 网址文本*/
public function urltxt($data)
{
global $PAGE;
//百度输入法多媒体输入
if (preg_match('#^(https?://ci.baidu.com)/([a-zA-Z0-9]+)$#is', $data['url'], $arr)) {
$prefix = $arr[1];
$imgId = $arr[2];
$url = code::html($data['url']);
$imgUrl = code::html($prefix . '/more?mm=' . $imgId);
static $id = 0;
$id ++;
return <<<HTML
<div class="baidu_media_box">
<p>多媒体输入(<a id="baidu_media_link_{$id}" href="{$url}">{$url}</a>)</p>
<img id="baidu_media_img_{$id}" src="{$imgUrl}" al="图片加载中" onerror="baidu_media_change({$id}, 'img', 'audio')" />
<audio id="baidu_media_audio_{$id}" class="audio" style="display:none" controls="controls" onerror="baidu_media_change({$id}, 'audio', 'txt')"></audio>
<span id="baidu_media_txt_{$id}" style="display:none">内容无法解析,请点击上方链接查看↑</span>
</div>
HTML;
} else {
if (JsonPage::isJsonPage()) {
$url = $data['url'];
} else {
$url = SITE_ROUTER_PATH . '/link.url.' . $PAGE->bid . '?url64=' . code::b64e($data['url']);
}
return '<a class="userlink" href="' . code::html($url) . '">' . code::html($data['url']) . '</a>';
}
}
/*mailtxt 邮箱文本*/
public function mailtxt($data)
{
return '<a class="usermail" href="mailto:' . code::html($data['mail']) . '">' . code::html($data['mail']) . '</a>';
}
/*at用户名*/
public function at($data)
{
global $PAGE;
$jsFunc = $this->getOpt('at.jsFunc');
$uid = (int)$data['uid'];
$uinfo = new UserInfo();
$uinfo->uid($uid);
$name = $uinfo->name === null ? $data['tag'] : $uinfo->name;
if ($jsFunc) {
return '<a class="userat" href="#" onclick="' . $jsFunc . '(\'' . $name . '\',this);return false">@</a><a class="userinfo" href="user.info.' . $uid . '.' . $PAGE->bid . '">' . code::html($name) . '</a>';
} else {
return '<a class="userinfo" href="user.info.' . $uid . '.' . $PAGE->bid . '">@' . code::html($name) . '</a>';
}
}
/*at通知信息*/
public function atMsg($data)
{
global $PAGE;
$uinfo = new UserInfo();
$uinfo->uid($data['uid']);
$url = code::html(str_replace('{$BID}', $PAGE->bid, $data['url']));
$pos = code::html($data['pos']);
if (is_array($data['msg'])) {
$uinfo->setUbbOpt($this);
$msg = $this->display($data['msg']);
} else {
$msg = code::html($data['msg']);
}
return <<<HTML
<a class="userinfo" href="user.info.{$uinfo->uid}.{$PAGE->bid}">{$uinfo->name}</a> 在 <a class="hu60_pos" href="{$url}">{$pos}</a> at你:
<blockquote>
{$msg}
</blockquote>
HTML;
}
/*管理员编辑通知信息*/
public function adminEditNotice($data)
{
global $PAGE;
$url = code::html(str_replace('{$BID}', $PAGE->bid, $data['url']));
$pos = code::html($data['pos']);
$reason = code::html($data['reason']);
$uinfo = new UserInfo();
$uinfo->uid($data['uid']);
$oriData = $this->display($data['oriData']);
return <<<HTML
管理员 <a class="userinfo" href="user.info.{$uinfo->uid}.{$PAGE->bid}">{$uinfo->name}</a> 编辑了您在 <a class="hu60_pos" href="{$url}">{$pos}</a> 的发言,编辑理由如下:
<blockquote>
{$reason}
</blockquote>
您发言的原始内容如下:
<blockquote>
{$oriData}
</blockquote>
HTML;
}
/*管理员删除通知信息*/
public function adminDelNotice($data)
{
global $PAGE, $USER;
$url = code::html(str_replace('{$BID}', $PAGE->bid, $data['url']));
$pos = code::html($data['pos']);
$reason = code::html($data['reason']);
$uinfo = new UserInfo();
$uinfo->uid($data['uid']);
$oriData = $this->display($data['oriData']);
if ($data['uid'] == $data['ownUid']) {
$own = "您";
$reason = "。";
} else {
$own = "管理员 <a class=\"userinfo\" href=\"user.info.{$uinfo->uid}.{$PAGE->bid}\">{$uinfo->name}</a> ";
$reason = <<<HTML
,理由如下:
<blockquote>
{$reason}
</blockquote>
HTML;
}
return <<<HTML
{$own}删除了您在 <a class="hu60_pos" href="{$url}">{$pos}</a> 的发言{$reason}
您发言的原始内容如下:
<blockquote>
{$oriData}
</blockquote>
HTML;
}
/*管理员操作通知信息*/
public function adminActionNotice($data)
{
global $PAGE, $USER;
$actName = [
bbs::ACTION_SINK_TOPIC => '下沉',
bbs::ACTION_ADD_BLOCK_POST => '已将您禁言',
bbs::ACTION_REMOVE_BLOCK_POST => '将您解除禁言',
bbs::ACTION_SET_ESSENCE_TOPIC => '加精',
bbs::ACTION_UNSET_ESSENCE_TOPIC => '取消精华',
];
$act = $actName[$data['act']];
$url = code::html(str_replace('{$BID}', $PAGE->bid, $data['url']));
$pos = code::html($data['pos']);
$reason = code::html($data['reason']);
$uinfo = new UserInfo();
$uinfo->uid($data['uid']);
if (in_array($data['act'], [bbs::ACTION_ADD_BLOCK_POST, bbs::ACTION_REMOVE_BLOCK_POST])) {
return <<<HTML
管理员 <a class="userinfo" href="user.info.{$uinfo->uid}.{$PAGE->bid}">{$uinfo->name}</a> {$act},理由如下:
<blockquote>
{$reason}
</blockquote>
HTML;
}
else {
if ($data['uid'] == $data['ownUid']) {
$own = "您";
$reason = "。";
} else {
$own = "管理员 <a class=\"userinfo\" href=\"user.info.{$uinfo->uid}.{$PAGE->bid}\">{$uinfo->name}</a> ";
$reason = <<<HTML
,理由如下:
<blockquote>
{$reason}
</blockquote>
HTML;
}
return <<<HTML
{$own}将您的 <a class="hu60_pos" href="{$url}">{$pos}</a> {$act}{$reason}
HTML;
}
}
/*管理员删除的内容*/
public function adminDelContent($data)
{
global $PAGE, $USER;
$reason = code::html($data['reason']);
$uinfo = new UserInfo();
$uinfo->uid($data['uid']);
$jsFunc = $this->getOpt('at.jsFunc');
$name = $uinfo->name === null ? $data['tag'] : $uinfo->name;
if ($jsFunc) {
$admin = '<a class="userat" href="#" onclick="' . $jsFunc . '(\'' . $name . '\',this);return false">@</a><a class="userinfo" href="user.info.' . code::html($data['uid']) . '.' . $PAGE->bid . '">' . code::html($name) . '</a>';
} else {
$admin = '<a class="userinfo" href="user.info.' . code::html($data['uid']) . '.' . $PAGE->bid . '">@' . code::html($name) . '</a>';
}
$time = '';
if (isset($data['time'])) {
$time = '于 ' . date('Y-m-d H:i ', $data['time']);
}
if ($data['uid'] == $data['ownUid']) {
$own = '层主';
} else {
$own = '管理员';
}
if (!empty($reason)) {
$reason = <<<HTML
,理由如下:
<p>{$reason}</p>
HTML;
} else {
$reason = '。';
}
return <<<HTML
<div class="tp info-box">
{$own} {$admin} {$time}删除了该楼层{$reason}
</div>
HTML;
}
/*待审核的内容*/
public function postNeedReviewNotice($data) {
global $PAGE;
$reviewForm = '';
if ($data['isAdmin']) {
$reviewForm = <<<HTML
<form class="hu60_review" action="bbs.review.$data[contentId].$data[topicId].$PAGE[bid]" method="post" data-content-id="$data[contentId]" data-topic-id="$data[topicId]">
<label><input id="hu60_review_pass_$data[contentId]" type="radio" name="pass" value="1" />审核通过</label>
<label><input id="hu60_review_nopass_$data[contentId]" type="radio" name="pass" value="0" checked />审核未通过</label>
<input type="input" name="comment" placeholder="审核未通过理由" onclick="document.querySelector('#hu60_review_nopass_$data[contentId]').checked = true" />
<input type="submit" value="确定" />
</form>
HTML;
}
$reviewLog = '';
if (!empty($data['reviewLog'])) {
$reviewLog = [];
foreach ($data['reviewLog'] as $v) {
$user = $this->at([ 'uid' => $v['uid'] ]);
$action = bbs::getReviewActionName($v['stat']);
$comment = code::html($v['comment'], false, true);
$time = str::ago($v['time']);
$reviewLog[] = <<<HTML
<div class="review_log_line">
<span class="review_log_time">[$time]</span>
<span class="review_log_user">$user</span>
<span class="review_log_action">$action</span>:
<div class="review_log_comment">$comment</div>
</div>
HTML;
}
$reviewLog = implode("\n", $reviewLog);
}
$stat = bbs::getReviewStatName($data['stat']);
// 注意:不要产生连续8个空格,否则markdown解析器会把后续内容当作代码块显示!
return <<<HTML
<div class="tp info-box">
发言{$stat},仅管理员和作者本人可见。
<div class="review_log">$reviewLog</div>
$reviewForm
</div>
HTML;
}
/*face 表情*/
public function face($data)
{
global $PAGE;
try {
$face = $data['face'];
if (preg_match('#^data:image/#is', $face)) {
$url = $face;
} elseif (preg_match('#^https?://#is', $face)) {
if (JsonPage::isJsonPage()) {
$url = $face;
} else {
$url = SITE_ROUTER_PATH . '/link.img.' . $PAGE->bid . '?url64=' . code::b64e($face);
}
} else {
$path = 'img/face/' . bin2hex($data['face']) . '.gif';
$url = $PAGE->getTplUrl($path).'?'.filemtime($path);