vasadibt/yii2-protector

隐藏电子邮件和电话号码以防止垃圾邮件机器人

安装: 114

依赖项: 0

建议者: 0

安全性: 0

星标: 3

关注者: 2

分支: 0

公开问题: 0

类型:yii2-extension

1.0.3 2020-09-30 09:23 UTC

This package is auto-updated.

Last update: 2024-09-29 05:55:41 UTC


README

隐藏电子邮件和电话号码以防止垃圾邮件机器人

安装

安装此扩展的首选方式是通过composer

运行以下命令之一

php composer.phar require --prefer-dist vasadibt/yii2-protector "*"

或者在您的composer.json文件的require部分添加以下内容

"vasadibt/yii2-protector": "*"

配置

集成模块的简单示例

'bootstrap' => [
    // ...
    'protector',
],
'components' => [
    // ...
    'protector' => [
         'class' => '\vasadibt\protector\ProtectData',
    ],
],

使用方法

安装扩展后,只需在您的代码中以html格式使用它即可

<h2>Contact</h2>

<a href="tel:[[protect:0036 70 1111 222]]">[[protect:0036 70 1111 222]]</a>

<a href="mailto:[[protect:info@mycompany.com]]">[[protect:info@mycompany.com]]</a>

<h3>Write to me<span class="email">[[protect:info@company.com]]</span></h3>

或者使用PHP助手函数

<?= Yii::$app->protector->tel('0036 70 1111 222') ?>

<?= Yii::$app->protector->mailto('info@company.com') ?>

<span><?= Yii::$app->protector->protect('0036 70 1111 222') ?></span>

特性

自动检测模式

如果您想使用自动检测模式,请开启它

'protector' => [
    'class' => '\vasadibt\protector\ProtectData',
    'enableAutoDetect' => 'true',
    'autoDetectPatterns' => [ // Optional you can use custom regex list  
        "/[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+.[a-zA-Z]{2,4}/U",
        // etc ... 
    ],
    'autoDetectMatchCallback' => function($match){ // Optional, if you want to validate match  
        return $match != 'bad@match.com';
    },
],

插件禁用

如果您想禁用插件,请将enable设置为false

<?php Yii::$app->protector->enable = false; ?>

插件调试

如果您想查看生成的键值对列表,请启用debug模式并在HTML检查器中显示javascript变量protectorDebug

<?php Yii::$app->protector->debug = true; ?>
console.log(protectorDebug);