*近有个客户来咨询广告敏感词的问题,客户使用的是ASPCMS系统,这个系统已经被我放弃了,推荐客户使用PbootCms来做,客户不愿意,实在提不起兴趣搞考古研究。

但是呢这个想法是不错的,可以做进pbootCms扩展里啊。

Ps: Pb后台有敏感词过滤,但是并没有替换,比如将*,替换为更佳,诸如此类。

准备工作

这些词没地方放是个问题。我们就放在PbootCms的定制标签中吧。

新建一个定制标签,标签名字一定是:disablewords,选择多行文本,新建好之后,填入

*,更佳

*具,更具

.....

前面是需要过滤的,后面是替换词,替换词留空就是直接过滤掉。

文章末尾会提供一个较为完整的过滤文本。

执行代码

前提条件是需要做一个操作,请移步:PbootCms扩展控制器源码分享,照着这个教程中,修改/apps/home/controller/ParserController.php文件中的扩展标签代码顺序。

修改完之后我们来写本教程的代码

文件位置:apps\home\controller\ExtLabelController.php

    //禁用词

    private function disablewords(){

        $words = \core\basic\Db::table('ay_label')->field('value')->where("name='disablewords'")->find();

        if(!!$words){

            $textlist = explode('<br>', $words->value);

            foreach ($textlist as $k => $v) {

                $jg = strpos($v, ",") ? "," : ',';

                $ciar = explode($jg, $v);

                $this->content = str_replace($ciar[0], (isset($ciar[1]) ? $ciar[1] : ''), $this->content);

            }

        }

    }

在上面的run方法中,加入该方法

    /* 必备启动函数 */

    public function run($content)

    {

        // 接收数据

        $this->content = $content;

        //广告词违禁词替换

        $this->disablewords();

        // 返回数据

        return $this->content;

    }

这样就完成了广告敏感词的过滤。如果不需要使用这个功能,可以讲

//$this->disablewords();

这一行注释掉即可。

稍后我会将代码增加到PbootCms扩展控制器源码分享这个帖子中,方便大家使用。

附上广告极限词和敏感词


1587117597166461.txt