/
ubbtext.php
566 lines (483 loc) · 13.6 KB
/
ubbtext.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
<?php
class UbbText extends XUBBP
{
// 解析at通知信息时得到的url
public $atMsgUrl = null;
/*注册显示回调函数*/
protected $display = array(
/*开启markdown*/
'markdown' => 'markdown',
/*markdown受保护内容(不被XUBBP解析器干扰)*/
'mdpre' => 'mdpre',
/*text 纯文本*/
'text' => 'text',
/*newline 换行*/
'newline' => 'newline',
'tab' => 'tab',
'empty' => 'emptyTag',
/*link 链接*/
'url' => 'url',
'urlzh' => 'url',
'urlout' => 'urlout',
'urlname' => 'urlname',
/*img 图片*/
'img' => 'img',
'imgzh' => 'img',
'thumb' => 'thumb',
/*code 代码高亮*/
'code' => 'code',
/*markdown风格代码高亮*/
'mdcode' => 'mdcode',
/*time 时间标记*/
'time' => 'time',
/*video 视频*/
'video' => 'video',
'videoStream' => 'video',
/*audio 音频*/
'audio' => 'video',
'audioStream' => 'video',
/*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',
/*at通知信息(用于推送通知)*/
'atMsg' => 'atMsg',
/*face 表情*/
'face' => 'face',
/*iframe 网页嵌入*/
'iframe' => 'iframe',
/* html 通过iframe的srcdoc属性实现的HTML内容嵌入 */
'html' => 'html',
/* textbox 文本框 */
'textbox' => 'textbox',
/*管理员操作*/
'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 '用户被禁言,发言自动屏蔽。';
}
return parent::display($ubbArray, $serialize, $maxLen, $page);
}
/*text 纯文本*/
public function text($data)
{
return $data['value'];
}
/*开启markdown模式*/
public function markdown($text){
return $text['data'];
}
/*markdown受保护内容(不被XUBBP解析器干扰)*/
public function mdpre($data){
return $data['data'];
}
/*代码高亮*/
public function code($data)
{
return "\n\n".$data['data']."\n\n";
}
/*markdown风格代码高亮*/
public function mdcode($data)
{
return "\n\n".$data['data']."\n\n";
}
/*time 时间*/
public function time($data)
{
if ($data['tag'] == '') {
$data['tag'] = 'Y-m-d H:i:s';
}
return date($data['tag']);
}
/*link 链接*/
public function url($data)
{
if ($this->getOpt('text.noUrl')) {
if (empty($data['title'])) {
return $data['url'];
} else {
if (is_array($data['title'])) {
$data['title'] = $this->display($data['title']);
}
return $data['title'];
}
}
if ($data['title'] == '') {
$html = $data['url'];
} else {
if (is_array($data['title'])) {
$data['title'] = $this->display($data['title']);
}
$html = $data['title'].': '.$data['url'];
}
return $html;
}
public function urlout($data)
{
if ($this->getOpt('text.noUrl')) {
if (empty($data['title'])) {
return $data['url'];
} else {
return $data['title'];
}
}
if ($data['title'] == '') {
$html = 'http://'.$data['url'];
} else {
if (is_array($data['title'])) {
$data['title'] = $this->display($data['title']);
}
$html = $data['title'].': http://'.$data['url'];
}
return $html;
}
public function urlname($data)
{
return '';
}
/*img 图片*/
public function img($data)
{
if ($this->getOpt('text.noUrl')) {
if (empty($data['alt'])) {
return basename(parse_url($data['src'], PHP_URL_PATH));
} else {
return $data['alt'];
}
}
if ($data['alt'] == '') {
$html = $data['src'];
} else {
$html = $data['alt'].': '.$data['src'];
}
return $html;
}
/*thumb 缩略图*/
public function thumb($data)
{
if ($this->getOpt('text.noUrl')) {
return basename(parse_url($data['src'], PHP_URL_PATH));
}
return $data['src'];
}
/*video 视频*/
public function video($data)
{
if ($this->getOpt('text.noUrl')) {
if (empty($data['title'])) {
return basename(parse_url('http://'.$data['url'], PHP_URL_PATH));
} else {
return $data['title'];
}
}
if (empty($data['title'])) {
return $data['url'];
} else {
return $data['title'] . ':' . $data['url'];
}
}
/*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 '本作品采用知识共享' . $cn . '3.0许可协议进行许可。';
}
if ($x == 'gfdl') {
return '本作品采用GNU自由文档许可证进行许可。';
}
if ($x == '公有领域' or $x == '公共领域') {
return '本作品属于公有领域。';
}
return '本作品采用' . $data['tag'] . '进行许可。';
}
/*battlenet 战网*/
public function battlenet($data)
{
$name = $data['name'];
if ($data['server'] != '') {
$name .= '@' . $data['server'];
}
if ($data['display'] != null) {
$name .= "," . $data['display'];
}
return '《战网:' . $name . '》';
}
/*math 数学公式*/
public function math($data) {
$content = $data['data'];
if ($data['type'] == 'math') {
return '[math]'.$content.'[/math]';
}
return '《公式:'.$content.'》';
}
/*newline 换行*/
public function newline($data)
{
if (in_array($data['tag'], ['hr', '<<<'])) {
return "\n--------\n";
} else {
return '\n';
}
}
/* [tab] */
public function tab($data)
{
return ' ';
}
/* [empty] */
public function emptyTag($data)
{
return '';
}
/*layout 布局*/
public function layout($data)
{
return '';
}
/*style 风格*/
public function style($data)
{
return '';
}
/*at消息*/
public function at($data)
{
global $PAGE;
$uinfo = new UserInfo();
$ok = $uinfo->uid($data['uid']);
if ($ok && $uinfo->name != $data['tag']) {
return '@'.$uinfo->name;
} else {
return '@'.$data['tag'];
}
}
/*face 表情*/
public function face($data)
{
return '{' . $data['face'] . '}';
}
/*iframe 网页嵌入*/
public function iframe($data) {
$data = $data['data'];
if (isset($data['src'])) {
return $data['src'];
}
if (isset($data['srcdoc'])) {
return strip_tags($data['srcdoc']);
}
return '';
}
/*html 通过iframe的srcdoc属性实现的HTML内容嵌入*/
public function html($data) {
return strip_tags($data['data']);
}
/*textbox 文本框*/
public function textbox($data) {
return $data['data'];
}
/*urltxt 链接文本*/
public function urltxt($data)
{
return $data['url'];
}
/*mailtxt 邮件链接文本*/
public function mailtxt($data)
{
return $data['mail'];
}
/*at通知信息(用于推送通知)*/
public function atMsg($data)
{
global $PAGE;
$opt = $this->getOpt('atMsg');
$uinfo = new UserInfo();
$uinfo->uid($opt['fromSelf'] ? $opt['touid'] : $data['uid']);
$url = str_replace('{$BID}', $PAGE->bid, $data['url']);
$this->setOpt('atMsg.Url', $url);
$pos = $data['pos'];
if (!$this->getOpt('display.textWithoutUrl')) {
$url = SITE_URL_BASE.$url;
$pos .= " $url";
}
if (is_array($data['msg'])) {
$uinfo->setUbbOpt($this);
$msg = $this->display($data['msg']);
$msg = trim(preg_replace("#^<!--\s*markdown\s*-->\s+#s", '', $msg));
} else {
$msg = trim($data['msg']);
}
if ($opt['fromSelf']) {
return <<<HTML
我在 $pos @{$uinfo->name}:
{$msg}
HTML;
} else {
return <<<HTML
@{$uinfo->name} 在 $pos @你:
{$msg}
HTML;
}
}
/*管理员编辑通知信息*/
public function adminEditNotice($data)
{
$pos = $data['pos'];
if (!$this->getOpt('display.textWithoutUrl')) {
$url = SITE_URL_BASE.$data['url'];
$pos .= " $url";
}
$reason = $data['reason'];
$uinfo = new UserInfo();
$uinfo->uid($data['uid']);
$oriData = $this->display($data['oriData']);
return <<<HTML
管理员 {$uinfo->name} 编辑了您在 {$pos} 的发言,编辑理由如下:
{$reason}
您发言的原始内容如下:
{$oriData}
HTML;
}
/*管理员删除通知信息*/
public function adminDelNotice($data)
{
$pos = $data['pos'];
if (!$this->getOpt('display.textWithoutUrl')) {
$url = SITE_URL_BASE.$data['url'];
$pos .= " $url";
}
$reason = $data['reason'];
$uinfo = new UserInfo();
$uinfo->uid($data['uid']);
$oriData = $this->display($data['oriData']);
if ($data['uid'] == $data['ownUid']) {
$own = "您";
$reason = "。";
} else {
$who = ($data['uid'] == $data['topicUid']) ? '楼主' : '管理员';
$own = "$who {$uinfo->name} ";
$reason = <<<HTML
,理由如下:
{$reason}
HTML;
}
return <<<HTML
{$own}删除了您在 {$pos} 的发言{$reason}
您发言的原始内容如下:
{$oriData}
HTML;
}
/*管理员操作通知信息*/
public function adminActionNotice($data)
{
$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 => '取消精华',
bbs::ACTION_REPLY_LOCK => '关闭评论',
bbs::ACTION_REPLY_UNLOCK => '开放评论',
];
$act = $actName[$data['act']];
$pos = $data['pos'];
if (!$this->getOpt('display.textWithoutUrl')) {
$url = SITE_URL_BASE.$data['url'];
$pos .= " $url";
}
$reason = $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
管理员 {$uinfo->name} {$act},理由如下:
{$reason}
HTML;
}
else {
if ($data['uid'] == $data['ownUid']) {
$own = "您";
$reason = "。";
} else {
$own = "管理员 {$uinfo->name} ";
$reason = <<<HTML
,理由如下:
{$reason}
HTML;
}
return <<<HTML
{$own}将您的 {$pos} {$act}{$reason}
HTML;
}
}
/*管理员删除的内容*/
public function adminDelContent($data)
{
$reason = $data['reason'];
$uinfo = new UserInfo();
$uinfo->uid($data['uid']);
$admin = $uinfo->name === null ? $data['tag'] : $uinfo->name;
$time = '';
if (isset($data['time'])) {
$time = '于 ' . date('Y-m-d H:i ', $data['time']);
}
if ($data['uid'] == $data['ownUid']) {
$own = '层主';
} elseif ($data['uid'] == $data['topicUid']) {
$own = '楼主';
} else {
$own = '管理员';
}
if (!empty($reason)) {
$reason = <<<HTML
,理由如下:
{$reason}
HTML;
} else {
$reason = '。';
}
return <<<HTML
{$own} {$admin} {$time}删除了该楼层{$reason}
HTML;
}
/*待审核的内容*/
public function postNeedReviewNotice($data) {
$stat = bbs::getReviewStatMessage($data['stat']);
return <<<HTML
{$stat}
HTML;
}
}