Plugin Directory

Changeset 2114935


Ignore:
Timestamp:
06/30/2019 09:30:55 AM (7 years ago)
Author:
nath4n
Message:

Update to 20190630

Location:
censorship/trunk
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • censorship/trunk/ReadMe.txt

    r2085462 r2114935  
    66Stable tag: trunk
    77
    8 A Simple Censorship For Comments (Replace Bad Language) and Use the Database
     8Censorship Plugin For Page & Post (Title, Content & Comments)
    99
    1010== Description ==
    1111
    12 A Wordpress Plugin to Censor your WordPress Post Comments From the Bad Word or Bad Language.
    13 Replace the Bad Words without changing the database (e.g. wp_comments).
    14 This Plugin is Use the database for manage the Censor List.
     12A Wordpress Plugin to Censor your WordPress Pages, Posts & Comments From the Bad Word or Bad Language.
     13Replace the Bad Words without changing the database (e.g. wp_posts & wp_comments).
    1514
    1615== Installation ==
    1716
    18 1. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly.
    19 2. Activate the plugin through the 'Plugins' screen in WordPress
    20 3. Use the Settings->Plugin Name screen to see the Censor List
     171. Upload the plugin files to the `/wp-content/plugins/censorship` directory, or install the plugin through the WordPress plugins screen directly.
     182. Activate the plugin through the `Plugins` screen in WordPress
     193. Use the `WP Censorship` menu to update the Settings (WP Censorship Configuration)
    2120
    2221== Screenshots ==
     
    25242. You can also update the word
    26253. The cencored comments (Replace badword with *****)
    27 
    28 == Changelog ==
    29 
    30 = 1.0 =
    31 * First Public Release
  • censorship/trunk/init.php

    r1743072 r2114935  
    22/*
    33Plugin Name:  Censorship Plugin
    4 Plugin URI:   http://wordpress-plugins.org/censorship/
    5 Description:  A Simple Censorship For Comments (Replace Bad Language) and Use Database
    6 Version:      20170310
     4Plugin URI:   https://wordpress.org/plugins/wp-censorship
     5Description:  Censorship Plugin For Page & Post (Title, Content & Comments)
     6Version:      20190630
    77Author:       nath4n
    8 Author URI:   http://thinknesia.com
     8Author URI:   https://profiles.wordpress.org/nath4n
    99License:      GPL2
    1010License URI:  https://www.gnu.org/licenses/gpl-2.0.html
     
    1212Domain Path:  /languages
    1313*/
    14 function censorship_options_install() {
    15 
    16     global $wpdb;
    17 
    18     $table_name = $wpdb->prefix . "censorship";
    19     $charset_collate = $wpdb->get_charset_collate();
    20     $sql = "CREATE TABLE $table_name (
    21             `id` mediumint(9) NOT NULL AUTO_INCREMENT,
    22             `badword` tinytext NOT NULL,
    23             PRIMARY KEY (`id`)
    24           ) $charset_collate; ";
    25 
    26     require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    27     dbDelta($sql);
    28    
    29     $badwords = array(
    30            'fuck',
    31            'cunt',
    32            'shit',
    33            'ass',
    34            'dick',
    35            'cock',
    36            'cum'
    37            );
    38     foreach ($badwords AS $word) {
    39         censorship_install_data($word);
    40     }   
     14
     15define( 'WP_DEBUG', true );
     16define( 'WP_DEBUG_LOG', true );
     17define( 'WP_DEBUG_DISPLAY', false );
     18
     19function wp_censorship_options_install() {
     20    $arrFilters = array();
     21    $arrFilters['filters'] = array(
     22                    'fuck',
     23                    'cunt',
     24                    'shit',
     25                    'ass',
     26                    'dick',
     27                    'cock',
     28                    'cum'
     29                );
     30   
     31    $arrFilters['types'] = array(
     32                            'pages',
     33                            'posts',
     34                            'comments'
     35                        );
     36                       
     37    $arrFilters['chrReplace'] = '*****';
     38   
     39    update_option( 'censorship-settings', maybe_serialize( $arrFilters ) );
    4140}
    4241
    43 register_activation_hook(__FILE__, 'censorship_options_install');
    44 
    45 function censorship_options_remove() {
    46 
    47     global $wpdb;
    48    
    49     $table_name = $wpdb->prefix . 'censorship';
    50 
    51     $sql = "DROP TABLE IF EXISTS $table_name;";
    52    
    53     $wpdb->query($sql);
     42register_activation_hook(__FILE__, 'wp_censorship_options_install');
     43
     44add_action( 'admin_enqueue_scripts', function() {
     45    wp_enqueue_script( 'jquery-3.3.1', PLUGINS_URL( 'jquery/jquery-3.3.1.min.js' , __FILE__  ) );   
     46    wp_enqueue_style( 'style-tags-input', PLUGINS_URL( 'tags-input/jquery.tagsinput-revisited.min.css' , __FILE__  ) );
     47    wp_enqueue_script( 'script-tags-input', PLUGINS_URL( 'tags-input/jquery.tagsinput-revisited.min.js' , __FILE__  ) );
     48}, 10, 2 );
     49
     50add_action( 'init', function(){
     51    $currSettings = array();
     52    $currSettings = maybe_unserialize( get_option( 'censorship-settings' ) );
     53    if( in_array('pages', $currSettings['types']) ) {
     54        add_filter( 'the_title', 'filter_page', 10 );       // Filter & Replace Pages Title
     55        add_filter( 'the_content', 'filter_page', 10 );     // Filter & Replace Pages Content
     56    }
     57   
     58    if( in_array('posts', $currSettings['types']) ) {
     59        add_filter( 'the_title', 'filter_post', 10 );       // Filter & Replace Posts Title
     60        add_filter( 'the_content', 'filter_post', 10 );     // Filter & Replace Posts Content
     61    }
     62   
     63    if( in_array('comments', $currSettings['types']) ) add_filter( 'comment_text', 'filter_comment', 10 ); // Filter & Replace Comments Text   
     64}, 10, 2 );
     65
     66add_action( 'admin_menu', function() {
     67    add_menu_page( 'WP Censorship', 'WP Censorship', 'manage_options', 'wp_censorship_page', 'wp_censorship_page', 'dashicons-dismiss', '25' );
     68}, 10, 2 );
     69
     70function filter_page( $content ) {
     71    global $wpdb, $post;
     72    $currSettings = $marketPlace = $arrTitle = $arrContent = $edited_post = array();
     73   
     74    if ( $post->post_type == "page" ) {
     75        $currSettings = maybe_unserialize( get_option( 'censorship-settings' ) );
     76           
     77        foreach ( $currSettings['filters'] as $filter ) {
     78            $marketPlace[] = strtolower( $filter );
     79        }
     80       
     81        $arrContent = explode(' ', $content);
     82       
     83        // Filter & Replace Page Content
     84        foreach($arrContent as $key => $word)
     85        {
     86            $word = strtolower(str_replace('.', '', strip_tags($word)));
     87            if(in_array($word, $marketPlace))
     88            {
     89                $arrContent[$key] = $currSettings['chrReplace'][0];
     90            }
     91        }
     92
     93        $content = implode(' ', $arrContent);
     94    }
     95    return $content;
    5496}
    5597
    56 register_deactivation_hook( __FILE__,'censorship_options_remove' );
    57 
    58 add_action('admin_menu','censorship_modifymenu');
    59 function censorship_modifymenu() {
    60    
    61     //this is the main item for the menu
    62     add_menu_page('Censorship', //page title
    63     'Censorship', //menu title
    64     'manage_options', //capabilities
    65     'censorship_list', //menu slug
    66     'censorship_list' //function
    67     );
    68    
    69     //this is a submenu
    70     add_submenu_page('censorship_list', //parent slug
    71     'Add New BadWord', //page title
    72     'Add New', //menu title
    73     'manage_options', //capability
    74     'censorship_create', //menu slug
    75     'censorship_create'); //function
    76    
    77     //this submenu is HIDDEN, however, we need to add it anyways
    78     add_submenu_page(null, //parent slug
    79     'Update BadWord', //page title
    80     'Update', //menu title
    81     'manage_options', //capability
    82     'censorship_update', //menu slug
    83     'censorship_update'); //function
     98function filter_post( $content ) {
     99    global $wpdb, $post;
     100    $currSettings = $marketPlace = $arrTitle = $arrContent = $edited_post = array();
     101   
     102    if ( $post->post_type == "post" ) {
     103        $currSettings = maybe_unserialize( get_option( 'censorship-settings' ) );
     104           
     105        foreach ( $currSettings['filters'] as $filter ) {
     106            $marketPlace[] = strtolower( $filter );
     107        }
     108       
     109        $arrContent = explode(' ', $content);
     110       
     111        // Filter & Replace Post Content
     112        foreach($arrContent as $key => $word)
     113        {
     114            $word = strtolower(str_replace('.', '', strip_tags($word)));
     115            if(in_array($word, $marketPlace))
     116            {
     117                $arrContent[$key] = $currSettings['chrReplace'][0];
     118            }
     119        }
     120
     121        $content = implode(' ', $arrContent);
     122    }
     123    return $content;
    84124}
    85125
    86 function censorship_install_data($word) {
    87    
    88     global $wpdb;
    89    
    90     $table_name = $wpdb->prefix . 'censorship';
    91    
    92     $wpdb->insert(
    93         $table_name, //table
    94         array('badword' => $word), //data
    95         array('%s') //data format           
    96     );
    97 }
    98 
    99 function censorship($text) {
    100    
    101     global $wpdb;
    102    
    103     $table_name = $wpdb->prefix . 'censorship';
    104    
    105     $rows = $wpdb->get_results("SELECT id, badword from $table_name");
    106    
    107     foreach($rows as $row){
    108         $BadWords[]= strtolower($row->badword);
    109     }
    110 
    111     $arr = explode(' ', $text);
    112 
    113     foreach($arr as $key => $word)
     126function filter_comment( $content ) {
     127    global $wpdb, $post;
     128    $currSettings = $marketPlace = $arrTitle = $arrContent = $edited_post = array();
     129    $currSettings = maybe_unserialize( get_option( 'censorship-settings' ) );
     130       
     131    foreach ( $currSettings['filters'] as $filter ) {
     132        $marketPlace[] = strtolower( $filter );
     133    }
     134
     135    $arrContent = explode(' ', $content);
     136
     137    // Filter & Replace Comments Text
     138    foreach($arrContent as $key => $word)
    114139    {
    115140        $word = strtolower(str_replace('.', '', strip_tags($word)));
    116         if(in_array($word, $BadWords))
     141        if(in_array($word, $marketPlace))
    117142        {
    118             $arr[$key] = '*****';
    119         }
    120     }
    121 
    122     $output = implode(' ', $arr);
    123     return $output;
     143            $arrContent[$key] = $currSettings['chrReplace'][0];
     144        }
     145    }
     146
     147    $content = implode(' ', $arrContent);
     148    return $content;
    124149}
    125150
    126 add_filter('comment_author', 'censorship', 10);
    127 add_filter('comment_email', 'censorship', 10);
    128 add_filter('comment_excerpt', 'censorship', 10);
    129 add_filter('comment_url', 'censorship', 10);
    130 add_filter('comment_text', 'censorship', 10);
    131 
    132 wp_enqueue_style('prefix-style', plugins_url('style-admin.css', __FILE__));
    133 
    134 define('CENSORSHIP_ROOTDIR', plugin_dir_path(__FILE__));
    135 require_once(CENSORSHIP_ROOTDIR . 'censorship-list.php');
    136 require_once(CENSORSHIP_ROOTDIR . 'censorship-create.php');
    137 require_once(CENSORSHIP_ROOTDIR . 'censorship-update.php');
    138 ?>
     151function wp_censorship_page() {
     152    $editedPost = $tempArray = $arrSettings = $currSettings = array();
     153    $nonce = $_REQUEST['_wpnonce'];
     154    // Get entire array
     155    $currSettings = maybe_unserialize( get_option( 'censorship-settings' ) );
     156
     157    if ( current_user_can( 'manage_options' ) ) {
     158        if ( isset( $_POST['updateFilters'] ) && wp_verify_nonce( $nonce, 'wp-filters-nonce' ) ) {         
     159            $txtfilters = trim( $_POST['filters'] );
     160            $tempArray = explode( ',', $txtfilters );
     161           
     162            foreach( $tempArray as $key => $filter ) {
     163                $arrSettings['filters'][] = sanitize_text_field( trim( $filter ) );
     164            }
     165           
     166            foreach ( $currSettings['types'] as $key => $type ) {
     167                $arrSettings['types'][] = sanitize_text_field( trim( $type ) );
     168            }
     169           
     170            $arrSettings['chrReplace'][] = sanitize_text_field( trim( $currSettings['chrReplace'][0] ) );
     171            // Save Settings           
     172            update_option( 'censorship-settings', maybe_serialize( $arrSettings ) );
     173        } elseif ( isset( $_POST['updateReplacement'] ) && wp_verify_nonce( $nonce, 'wp-replacement-nonce' ) ) {
     174            $tempArray = $_POST['replacement'];
     175            $txtCustom = trim( $_POST['txtCustom'] );
     176            if ( $tempArray[0] == 'custom' ) {
     177                if ( !empty( $txtCustom ) ) {
     178                    $arrSettings['chrReplace'][] = sanitize_text_field( $txtCustom );
     179                } else {
     180                    $arrSettings['chrReplace'][] = '*****';
     181                }
     182            } else {
     183                $arrSettings['chrReplace'][] = sanitize_text_field( trim( $tempArray[0] ) );
     184            }
     185           
     186            foreach ( $currSettings['filters'] as $key => $filter ) {
     187                $arrSettings['filters'][] = sanitize_text_field( trim( $filter ) );
     188            }
     189           
     190            foreach ( $currSettings['types'] as $key => $type ) {
     191                $arrSettings['types'][] = sanitize_text_field( trim( $type ) );
     192            }
     193            // Save Settings
     194            update_option( 'censorship-settings', maybe_serialize( $arrSettings ) );
     195        } elseif ( isset( $_POST['updateTypes'] ) && wp_verify_nonce( $nonce, 'wp-types-nonce' ) ) {
     196            $tempArray = $_POST['postType'];
     197           
     198            foreach( $tempArray as $key => $type ) {
     199                $arrSettings['types'][] = sanitize_text_field( trim( $type ) );
     200            }
     201           
     202            foreach ( $currSettings['filters'] as $key => $filter ) {
     203                $arrSettings['filters'][] = sanitize_text_field( trim( $filter ) );
     204            }
     205           
     206            $arrSettings['chrReplace'][] = sanitize_text_field( trim( $currSettings['chrReplace'][0] ) );
     207            // Save Settings
     208            update_option( 'censorship-settings', maybe_serialize( $arrSettings ) );
     209        }
     210    }
     211    ?>
     212    <style>
     213    .postbox {     
     214        border-radius: 5px;
     215        border:1px solid #CCC;
     216        padding:0 10px;margin-top:5px;     
     217        -moz-border-radius:5px;
     218        -webkit-border-radius:5px;     
     219    }
     220    </style>
     221<div class="wrap">
     222    <h2>WP Censorship Configuration</h2>
     223    <div id="poststuff">
     224        <div id="post-body" class="metabox-holder columns-2">
     225            <!-- main content -->
     226            <div id="post-body-content">
     227                <div class="meta-box-sortables ui-sortable">
     228                    <div class="postbox" style="border-radius:5px;background: #ECECEC;">
     229                        <div class="inside">
     230                            <h3><strong>WordPress Content Censorship Plugin</strong></h3>
     231                            <ul class="description">
     232                                <li>A WordPress Plugin to Censor your WordPress Post Comments From the Bad Word or Bad Language</li>
     233                                <li>Replace the Bad Words without changing the WordPress Database</li>
     234                                <li>This Plugin is not use the database</li>
     235                            </ul>
     236                        </div>
     237                    </div>
     238                </div>
     239            </div>
     240        </div>
     241    </div>
     242    <div id="poststuff">           
     243        <div id="post-body" class="metabox-holder columns-2">
     244            <!-- main content -->
     245            <div id="post-body-content">
     246                <div class="meta-box-sortables ui-sortable">
     247                    <div class="postbox">
     248                        <div class="inside">
     249                            <form id="filters-form" method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
     250                                <?php wp_nonce_field( 'wp-filters-nonce' ); ?>
     251                                <table class="form-table">
     252                                    <tbody>
     253                                        <tr>
     254                                            <td colspan=2>
     255                                                <h3>Add Filters</h3>
     256                                            </td>       
     257                                        </tr>
     258                                        <tr>
     259                                            <th>
     260                                                <label>Filters input:</label>                                               
     261                                            </th>
     262                                            <td>
     263                                                <?php
     264                                                    $currSettings = maybe_unserialize( get_option( 'censorship-settings' ) );
     265                                                    foreach ( $currSettings['filters'] as $filter ) {
     266                                                        $dataToInsert .= $filter . ',';
     267                                                    }
     268                                                ?>
     269                                                <input id="filters" name="filters" type="text" value="<?php echo $dataToInsert; ?>">
     270                                            </td>
     271                                        </tr>
     272                                        <tr>
     273                                            <th>&nbsp;</th>
     274                                            <td colspan=2>
     275                                                <input type='submit' name="updateFilters" id="updateFilters" value='Update Filters' class='button button-primary'>
     276                                            </td>       
     277                                        </tr>
     278                                    </tbody>
     279                                </table>
     280                            </form>
     281                        </div>
     282                    </div>
     283                </div>
     284            </div>
     285        </div>
     286    </div>
     287    <div id="poststuff">           
     288        <div id="post-body" class="metabox-holder columns-2">
     289            <!-- main content -->
     290            <div id="post-body-content">
     291                <div class="meta-box-sortables ui-sortable">
     292                    <div class="postbox">
     293                        <div class="inside">
     294                            <form id="replacement-form" method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
     295                                <?php wp_nonce_field( 'wp-replacement-nonce' ); ?>
     296                                <table class="form-table">
     297                                    <tbody>
     298                                        <tr>
     299                                            <td>
     300                                                <h3>Replacement</h3>
     301                                            </td>
     302                                        </tr>
     303                                        <tr>
     304                                            <th>
     305                                                <label>Replace Censored Words With:</label>                                             
     306                                            </th>
     307                                            <td>
     308                                            <?php
     309                                                $currSettings = maybe_unserialize( get_option( 'censorship-settings' ) );
     310                                                if( in_array('*****', $currSettings['chrReplace']) ) {
     311                                                    echo '<input type="radio" name="replacement[]" value="*****" checked>';
     312                                                } else {
     313                                                    echo '<input type="radio" name="replacement[]" value="*****">';
     314                                                }
     315                                                echo '<i>Stars</i> ( "<b>*****</b>" )<br>';
     316                                               
     317                                                if( !in_array('*****', $currSettings['chrReplace']) && !in_array('#####', $currSettings['chrReplace']) ) {
     318                                                    echo '<input type="radio" name="replacement[]" value="custom" checked>';
     319                                                } else {
     320                                                    echo '<input type="radio" name="replacement[]" value="custom">';
     321                                                }
     322                                                echo '<i>Custom</i> : <input type="text" name="txtCustom" value="' . $currSettings['chrReplace'][0] . '" placeholder="%@!#%&amp;">';
     323                                            ?>
     324                                            </td>
     325                                        </tr>
     326                                        <tr>
     327                                            <th>&nbsp;</th>
     328                                            <td colspan=2>
     329                                                <input type='submit' name="updateReplacement" id="updateReplacement" value='Update Replacement' class='button button-primary'>
     330                                            </td>       
     331                                        </tr>
     332                                    </tbody>
     333                                </table>
     334                            </form>
     335                        </div>
     336                    </div>
     337                </div>
     338            </div>
     339        </div>
     340    </div>
     341    <div id="poststuff">           
     342        <div id="post-body" class="metabox-holder columns-2">
     343            <!-- main content -->
     344            <div id="post-body-content">
     345                <div class="meta-box-sortables ui-sortable">
     346                    <div class="postbox">
     347                        <div class="inside">                       
     348                            <form id="posts-form" method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
     349                                <?php wp_nonce_field( 'wp-types-nonce' ); ?>
     350                                <table class="form-table">
     351                                    <tbody>
     352                                        <tr>
     353                                            <td colspan=2>
     354                                                <h3>Select Post Types</h3>
     355                                            </td>       
     356                                        </tr>
     357                                        <tr>
     358                                            <th>
     359                                                <label>Post Types:</label>                 
     360                                            </th>
     361                                            <td>
     362                                                <?php
     363                                                    $currSettings = maybe_unserialize( get_option( 'censorship-settings' ) );
     364                                                    if( in_array('pages', $currSettings['types']) ) {
     365                                                        echo '<input type="checkbox" name="postType[]" value="pages" checked>';
     366                                                    } else {
     367                                                        echo '<input type="checkbox" name="postType[]" value="pages">';
     368                                                    }
     369                                                    echo '<span><b>Filter All <i>Pages</i></b></span><br>';
     370                                                   
     371                                                    if( in_array('posts', $currSettings['types']) ) {
     372                                                        echo '<input type="checkbox" name="postType[]" value="posts" checked>';
     373                                                    } else {
     374                                                        echo '<input type="checkbox" name="postType[]" value="posts">';
     375                                                    }
     376                                                    echo '<span><b>Filter All <i>Posts</i></b></span><br>';
     377                                                   
     378                                                    if( in_array('comments', $currSettings['types']) ) {
     379                                                        echo '<input type="checkbox" name="postType[]" value="comments" checked>';
     380                                                    } else {
     381                                                        echo '<input type="checkbox" name="postType[]" value="comments">';
     382                                                    }
     383                                                    echo '<span><b>Filter All <i>Comments</i></b></span><br>'
     384                                                ?>
     385                                            </td>
     386                                        </tr>
     387                                        <tr>
     388                                            <th>&nbsp;</th>
     389                                            <td colspan=2>
     390                                                <input type='submit' name="updateTypes" id="updateTypes" value='Update Post Types' class='button button-primary'>
     391                                            </td>       
     392                                        </tr>
     393                                    </tbody>
     394                                </table>
     395                                <script>
     396                                jQuery(function() {
     397                                    $('#filters').tagsInput();
     398                                });
     399                                </script>
     400                            </form>
     401                        </div>
     402                    </div>
     403                </div>
     404            </div>
     405        </div>
     406    </div>
     407</div>
     408    <?php
     409}
Note: See TracChangeset for help on using the changeset viewer.