src/Biz/Sensitive/Service/Impl/SensitiveServiceImpl.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Biz\Sensitive\Service\Impl;

use Biz\BaseService;
use Topxia\Service\Common\ServiceKernel;
use Biz\Sensitive\Service\SensitiveService;
use Biz\Sensitive\SensitiveException;

class SensitiveServiceImpl extends BaseService implements SensitiveService
{
    public function sensitiveCheck($text, $type = '')
    {
        $bannedResult = $this->bannedKeyword($text, $type);

        if ($bannedResult['success']) {
            $this->createNewException(SensitiveException::FORBIDDEN_WORDS());
        } else {
            return $this->replaceText($text, $type);
        }
    }

    protected function bannedKeyword($text, $type = '')
    {
        //预处理内容
        $text = strip_tags($text);
        $text = $this->semiangleTofullangle($text);
        $text = $this->plainTextFilter($text);

        $rows = $this->getSensitiveDao()->findByState('banned');

        if (empty($rows)) {
            return array('success' => false, 'text' => $text);
        }

        $keywords = array_column($rows, 'name');

        $chunkKeywords = array_chunk($keywords, 100);

        foreach ($chunkKeywords as $chunkKeyword) {
            $pattern = '/('.implode('|', $chunkKeyword).')/i';
            $matched = preg_match($pattern, $text, $match);
            if ($matched) {
                goto last;
            }
        }

        return array('success' => false, 'text' => $text);

        last :
        $keyword = $this->flagReplaceReverse($match[1]);

        $bannedKeyword = $this->getSensitiveDao()->getByName($keyword);

        if (empty($bannedKeyword)) {
            return array('success' => false, 'text' => $text);
        }

        $currentUser = $this->getCurrentUser();
        $user = $this->getUserService()->getUser($currentUser->id);

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。