1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+ /**
5
+ * This file is part of zhuchunshu.
6
+ * @link https://github.com/zhuchunshu
7
+ * @document https://github.com/zhuchunshu/super-forum
8
+ * @contact laravel@88.com
9
+ * @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10
+ */
3
11
namespace App \Plugins \Topic \src ;
4
12
5
13
use Hyperf \Utils \Arr ;
6
14
use Zhuchunshu \EmojiParse \Emoji ;
7
15
8
16
class ContentParse
9
17
{
10
- /**
11
- * @param string $content 内容
12
- * @param array $data 数据
13
- */
14
- public function parse (string $ content , array $ data = [])
15
- {
16
- $ content = $ this ->ShortCode ($ content , $ data );
17
- $ content = $ this ->twemoji ($ content );
18
- $ content = $ this ->owo ($ content );
19
- return $ content ;
20
- }
21
-
22
- /**
23
- * ShortCode 处理
24
- * @param string $content 内容
25
- * @param array $data 数据
26
- */
27
- private function ShortCode (string $ content , array $ data = []): string
28
- {
29
- // 要删除的ShortCode
30
- // 要删除的ShortCode
31
- $ shortCode = [];
32
- if (count (Itf ()->get ('topic_shortCode_remove ' ))) {
33
- $ shortCode = array_merge ($ shortCode , Itf ()->get ('topic_shortCode_remove ' ));
34
- }
35
- if (Arr::has ($ data , 'RemoveshortCode ' ) && count ($ data ['RemoveshortCode ' ])) {
36
- $ shortCode = array_merge ($ shortCode , $ data ['RemoveshortCode ' ]);
37
- }
38
- $ shortCode = array_unique ($ shortCode );
39
- return ShortCodeR ()->setRemove ($ shortCode )->handle ($ content , $ data );
40
- }
41
-
42
- /**
43
- * TwEmoji 处理
44
- * @param string $content
45
- * @return string
46
- */
47
- private function twemoji (string $ content ): string
48
- {
49
- if (get_options ("contentParse_twemoji " , "开启 " ) === "开启 " ) {
50
- return (new Emoji ())->twemoji ($ content )->svg ()->base (get_options ("contentParse_twemoji_cdn " , "https://lib.baomitu.com/twemoji/1.4.2 " ))->toHtml (null , ['width ' => get_options ("contentParse_twemoji_contentParse_width " , 25 ), 'height ' => get_options ("contentParse_twemoji_contentParse_height " , 25 )]);
51
- }
52
- return $ content ;
53
- }
54
-
55
- /**
56
- * 渲染owo表情
57
- * @param string $content
58
- * @return string
59
- */
60
- private function owo (string $ content ): string
61
- {
62
- if (get_options ('contentParse_owo ' , '开启 ' ) === "开启 " ) {
63
- return (new \App \Plugins \Core \src \Lib \Emoji ())->parse ($ content );
64
- }
65
- return $ content ;
66
- }
67
- }
18
+ /**
19
+ * @param string $content 内容
20
+ * @param array $data 数据
21
+ */
22
+ public function parse (string $ content , array $ data = [])
23
+ {
24
+ $ content = $ this ->ShortCode ($ content , $ data );
25
+ $ content = $ this ->twemoji ($ content );
26
+ return $ this ->owo ($ content );
27
+ }
28
+
29
+ /**
30
+ * ShortCode 处理.
31
+ * @param string $content 内容
32
+ * @param array $data 数据
33
+ */
34
+ private function ShortCode (string $ content , array $ data = []): string
35
+ {
36
+ // 要删除的ShortCode
37
+ // 要删除的ShortCode
38
+ $ shortCode = [];
39
+ if (count (Itf ()->get ('topic_shortCode_remove ' ))) {
40
+ $ shortCode = array_merge ($ shortCode , Itf ()->get ('topic_shortCode_remove ' ));
41
+ }
42
+ if (Arr::has ($ data , 'RemoveshortCode ' ) && count ($ data ['RemoveshortCode ' ])) {
43
+ $ shortCode = array_merge ($ shortCode , $ data ['RemoveshortCode ' ]);
44
+ }
45
+ $ shortCode = array_unique ($ shortCode );
46
+ return ShortCodeR ()->setRemove ($ shortCode )->handle ($ content , $ data );
47
+ }
48
+
49
+ /**
50
+ * TwEmoji 处理.
51
+ */
52
+ private function twemoji (string $ content ): string
53
+ {
54
+ if (get_options ('contentParse_twemoji ' , '开启 ' ) === '开启 ' ) {
55
+ return (new Emoji ())->twemoji ($ content )->svg ()->base (get_options ('contentParse_twemoji_cdn ' , 'https://lib.baomitu.com/twemoji/1.4.2 ' ))->toHtml (null , ['width ' => get_options ('contentParse_twemoji_contentParse_width ' , 25 ), 'height ' => get_options ('contentParse_twemoji_contentParse_height ' , 25 )]);
56
+ }
57
+ return $ content ;
58
+ }
59
+
60
+ /**
61
+ * 渲染owo表情.
62
+ */
63
+ private function owo (string $ content ): string
64
+ {
65
+ if (get_options ('contentParse_owo ' , '开启 ' ) === '开启 ' ) {
66
+ return (new \App \Plugins \Core \src \Lib \Emoji ())->parse ($ content );
67
+ }
68
+ return $ content ;
69
+ }
70
+ }
0 commit comments