GithubHelp home page GithubHelp logo

guoyu07 / laravel-censor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kamranahmedse/laravel-censor

0.0 0.0 0.0 11 KB

A middleware for Laravel 5.* to easily redact or replace the words from the pages you want.

License: MIT License

PHP 100.00%

laravel-censor's Introduction

Laravel Censor

Let's you easily redact or replace the occurences of words, sentences or %wildcards%

A laravel middleware that will automatically censor the words that you will specify. All you have to do is specify the things, that you want to redact or replace, in a configuration file and these words will automatically be redacted/replaced from the views on whose route you will specify the middleware.

Installation

Perform the following operations in order to use this middleware

  • Run composer require kamranahmedse/laravel-censor in your terminal

  • Add Service Provider Open config/app.php and add KamranAhmed\LaravelCensor\LaravelCensorServiceProvider::class to the end of providers array:

    'providers' => array(
        ....
        KamranAhmed\LaravelCensor\LaravelCensorServiceProvider::class,
    ),
    
  • Register the Middleware After that open the file app/Http/Kernel.php and add the following

    'censor' => \KamranAhmed\LaravelCensor\CensorMiddleware::class
    

    to the end of $routeMiddleware array

     protected $routeMiddleware = [
         ...
         'censor' => \KamranAhmed\LaravelCensor\CensorMiddleware::class
     ];
    
  • Publish Configuration Open terminal and run

    php artisan vendor:publish

How to use

  • After following the above steps, there will be a censor.php file inside the config directory. The file has two arrays, namely replace and redact.

  • You have to specify the words that you want to replace in the replace array with words or wildcards set to the keys of array and replacements as values i.e.

    'replace' => [
        'idiot'    => '(not a nice word)',
        'hate%'    => 'peace',      // Wildcard: Will replace the words beginning at hate e.g. hatered, hate, hated etc
        '%eograph%' =>  'some-graphy-word',         // Willcard: Will replace words containing `eograph` anywhere in the middle e.g. geographic, angeography etc
        'seventh'  => '7th',
        'monthly'  => 'every month',
        'yearly'   => 'every year',
        'weekly'   => 'every week',
    ],
  • For any words that you want to redact or completely remove, you have to specify them in the redact array

    'redact' => [
       'idiot%',        // e.g. idiot will be replaced with 5 asterisks, idiotic with 7 asterisks etc 
       'password',      // Will be replaced with 8 asterisks
       'word-that-i-really-dislike',
    ],

    The words specified in redact array will turn into asterisks. For example idiot will be turned into 5 asterisks (*****).

  • Now for any route from which you want these words to be redacted or replaced, place the middleware censor over it and it will automatically redact/replace those words from all of the page. For example, below is how you can specify it over the route e.g.

    Route::get('post-detail', ['middleware' => 'censor', 'uses' => 'PostController@detail', 'as' => 'postDetail']);

    Or specify it over the route group so that it may handle all the routes in that group e.g.

    Route::group(['prefix' => 'post', 'middleware' => 'censor'], function () {
        Route::get('detail', ['uses' => 'PostController@detail']);
        Route::get('add', ['uses' => 'PostController@add']);
    });

How to Contribute

  • Feel free to add some new functionality, improve some existing functionality etc and open up a pull request explaining what you did.
  • Report any issues in the issues section
  • Also you can reach me directly at [email protected] with any feedback

laravel-censor's People

Contributors

kamranahmedse avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.