netinfluence/secure-display-bundle

此包已被弃用且不再维护。未建议替代包。

NetinfluenceSecureDisplayBundle是一个小型简单的包,通过加密和JavaScript保护电子邮件和电话号码。

安装: 851

依赖项: 0

建议者: 0

安全性: 0

星标: 3

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

2.1.0 2019-03-19 10:11 UTC

This package is auto-updated.

Last update: 2022-02-01 12:46:30 UTC


README

NetinfluenceSecureDisplayBundle是一个小型简单的包,通过加密、Ajax和JavaScript保护电子邮件、电话号码和您想保护的任何文本,以防止垃圾邮件机器人。

SensioLabsInsight knpbundles.com Build Status

要求

在安装此包之前,您需要安装FOSJsRoutingBundle的工作安装。

1.x版本与Symfony 2兼容(2.3 - 2.8),2.x版本与Symfony 2.8、3.x和4.x兼容
代码已在PHP 5.6和PHP 7.0到PHP 7.3上进行了测试

安装

步骤 1: Composer

首先,您需要将netinfluence/secure-display-bundle添加到composer.json

{
   "require": {
        "netinfluence/secure-display-bundle": "dev-master"
    }
}

注意:将dev-master替换为此包的最后一个版本。

步骤 2: AppKernel

将包注册到Symfony AppKernel中

// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...
            new Netinfluence\SecureDisplayBundle\NetinfluenceSecureDisplayBundle()
        );

        return $bundles;
    }
}

步骤 3: 配置

在配置文件中定义包的配置

# app/config/config.yml
netinfluence_secure_display:
    # Required, key used to encrypt data
    key: "my_super_random_secure_key"
    # Optional, you can customize used template here
    template: 'NetinfluenceSecureDisplayBundle::secure_display.html.twig'

步骤 4: 路由

注册包的路由以执行Ajax请求

# app/config/routing.yml
netinfluence_secure_display:
    resource: "@NetinfluenceSecureDisplayBundle/Resources/config/routing.yml"
    prefix:   /

步骤 5: 资产

发布资产以使用JavaScript文件

$ php app/console assets:install --symlink web

在您的布局中添加此行

<script src="{{ asset('bundles/netinfluencesecuredisplay/js/display.js') }}"></script>

声明

{{ some.data|secureDisplay(label, action, attributes) }}

参数

  • label: 可选
    • type: 字符串
    • value: 如果JavaScript未启用,则显示的文本
  • action: 可选
    • type: 字符串
    • value: 添加到链接之前的行为(例如 "tel:012 345 67" 或 "mailto:john@doe.com")
  • attributes: 可选
    • type: 数组
    • value: 添加到文本的HTML属性

用法

<h4>Here are my personal informations</h4>

{# Default usage #}
<p>My name is : {{ contact.name|secureDisplay }}</p>

{# Custom label when JavaScript is not enabled #}
<p>You can find me at : {{ contact.address|secureDisplay('this address is protected') }}</p>

{# Transform phone number into clicable link #}
{# Can be 'tel', 'mailto', whatever you want #}
<p>My phone number is : {{ contact.phoneNumber|secureDisplay(null, 'tel') }}</p>

{# Custom html attributes #}
<p>My favorite color is : {{ contact.color|secureDisplay(null, null, { 'style': 'color: red' }) }}</p>

当然,您可以按需混合这三个参数中的任何一个。