Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
200443e
commit 6f10ed6
Showing
5 changed files
with
97 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of zhuchunshu. | ||
* @link https://github.com/zhuchunshu | ||
* @document https://github.com/zhuchunshu/super-forum | ||
* @contact laravel@88.com | ||
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE | ||
*/ | ||
namespace App\Plugins\Topic\src; | ||
|
||
use Hyperf\Utils\Arr; | ||
use Zhuchunshu\EmojiParse\Emoji; | ||
|
||
class ContentParse | ||
{ | ||
/** | ||
* @param string $content 内容 | ||
* @param array $data 数据 | ||
*/ | ||
public function parse(string $content, array $data = []) | ||
{ | ||
$content = $this->ShortCode($content, $data); | ||
$content = $this->twemoji($content); | ||
$content = $this->owo($content); | ||
return $content; | ||
} | ||
|
||
/** | ||
* ShortCode 处理 | ||
* @param string $content 内容 | ||
* @param array $data 数据 | ||
*/ | ||
private function ShortCode(string $content, array $data = []): string | ||
{ | ||
// 要删除的ShortCode | ||
// 要删除的ShortCode | ||
$shortCode = []; | ||
if(count(Itf()->get('topic_shortCode_remove'))) { | ||
$shortCode = array_merge($shortCode, Itf()->get('topic_shortCode_remove')); | ||
} | ||
if(Arr::has($data, 'RemoveshortCode') && count($data['RemoveshortCode'])) { | ||
$shortCode = array_merge($shortCode, $data['RemoveshortCode']); | ||
} | ||
$shortCode = array_unique($shortCode); | ||
return ShortCodeR()->setRemove($shortCode)->handle($content, $data); | ||
} | ||
|
||
/** | ||
* TwEmoji 处理 | ||
* @param string $content | ||
* @return string | ||
*/ | ||
private function twemoji(string $content): string | ||
{ | ||
if(get_options("contentParse_twemoji", "开启") === "开启") { | ||
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)]); | ||
} | ||
return $content; | ||
} | ||
|
||
/** | ||
* 渲染owo表情 | ||
* @param string $content | ||
* @return string | ||
*/ | ||
private function owo(string $content): string | ||
{ | ||
if(get_options('contentParse_owo', '开启') === "开启") { | ||
return (new \App\Plugins\Core\src\Lib\Emoji())->parse($content); | ||
} | ||
return $content; | ||
} | ||
} | ||
/** | ||
* @param string $content 内容 | ||
* @param array $data 数据 | ||
*/ | ||
public function parse(string $content, array $data = []) | ||
{ | ||
$content = $this->ShortCode($content, $data); | ||
$content = $this->twemoji($content); | ||
return $this->owo($content); | ||
} | ||
|
||
/** | ||
* ShortCode 处理. | ||
* @param string $content 内容 | ||
* @param array $data 数据 | ||
*/ | ||
private function ShortCode(string $content, array $data = []): string | ||
{ | ||
// 要删除的ShortCode | ||
// 要删除的ShortCode | ||
$shortCode = []; | ||
if (count(Itf()->get('topic_shortCode_remove'))) { | ||
$shortCode = array_merge($shortCode, Itf()->get('topic_shortCode_remove')); | ||
} | ||
if (Arr::has($data, 'RemoveshortCode') && count($data['RemoveshortCode'])) { | ||
$shortCode = array_merge($shortCode, $data['RemoveshortCode']); | ||
} | ||
$shortCode = array_unique($shortCode); | ||
return ShortCodeR()->setRemove($shortCode)->handle($content, $data); | ||
} | ||
|
||
/** | ||
* TwEmoji 处理. | ||
*/ | ||
private function twemoji(string $content): string | ||
{ | ||
if (get_options('contentParse_twemoji', '开启') === '开启') { | ||
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)]); | ||
} | ||
return $content; | ||
} | ||
|
||
/** | ||
* 渲染owo表情. | ||
*/ | ||
private function owo(string $content): string | ||
{ | ||
if (get_options('contentParse_owo', '开启') === '开启') { | ||
return (new \App\Plugins\Core\src\Lib\Emoji())->parse($content); | ||
} | ||
return $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters