Plugin Directory

Changeset 2115899


Ignore:
Timestamp:
07/02/2019 05:13:49 AM (7 years ago)
Author:
softmodeling
Message:

Release of version 1.1

Location:
serious-toxic-comments/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • serious-toxic-comments/trunk/README.txt

    r2090619 r2115899  
    11=== Serious Toxic Comments ===
    22Contributors: softmodeling, seriouswp
    3 Tags: comments, toxic, toxicity, AI, tensorflow, insults, offensive, threats, machine learning
     3Tags: comments, toxic, toxicity, AI, tensorflow, insults, offensive, threats, machine learning, bbpress, forum
    44Requires at least: 4.3
    5 Tested up to: 5.2
     5Tested up to: 5.2.2
    66Requires PHP: 5.6
    77Stable tag: trunk
     
    4848== Changelog ==
    4949
     50= 1.1 =
     51* Added support for bbPress
     52* Possibility to configure the warning message when a toxic comment is detected
     53
    5054= 1.0 =
    5155* Initial release
     56
     57== Upgrade Notice ==
     58
     59= 1.1 =
     60* Added bbPress support and configuration of the alert toxic message
  • serious-toxic-comments/trunk/admin/partials/class-serious-toxic-comments-admin-settings.php

    r2090613 r2115899  
    6464        );
    6565                                   
     66        add_settings_field(
     67            'toxicmessage',
     68            'Start checking comments',
     69            array($this,'render_toxicmessage_field'),
     70            'discussion',
     71            'toxicconfig'
     72        );
     73                                   
    6674    }
    6775       
     
    8593        echo '<input type="range" name="settingsToxic[threshold]" size="10" value="' . esc_attr( $value ).'" min="1" max="100" />';
    8694    }
     95    public function render_toxicmessage_field() {
     96        // Retrieve the full set of options
     97        $options = get_option( 'settingsToxic' );
     98        // Field output.
     99        // Set default value for this particular option in the group
     100        $value = isset( $options['toxicmessage'] ) ? $options['toxicmessage'] : 'Your text has been flagged as toxic and cannot be submitted as it is. This can happen due to a variety of reasons (insults, obscenity,...). Please, edit it and try again';
     101        echo '<textarea name="settingsToxic[toxicmessage]" rows="3" cols="80">' .esc_attr( $value ).' </textarea>';
     102    }
    87103}
    88104       
  • serious-toxic-comments/trunk/includes/class-serious-toxic-comments-ext.php

    r2090613 r2115899  
    1616
    1717    protected function define_additional_public_hooks($plugin_public){
    18         $this->loader->add_action( 'wp_footer', $plugin_public, 'comment_toxicity' );
     18        $this->loader->add_action( 'wp_footer', $plugin_public, 'check_text_toxicity' );
    1919    }
    2020
  • serious-toxic-comments/trunk/public/class-serious-toxic-comments-public-ext.php

    r2090613 r2115899  
    2525
    2626
     27    public function check_text_toxicity()
     28    {
     29        $this->comment_toxicity();
     30        $this->bbpress_toxicity();
     31    }
     32
    2733    public function comment_toxicity()
    2834    {
    2935        $options = get_option( 'settingsToxic' );
    3036        $threshold = $options['threshold']/100;
     37        $message = $options['toxicmessage'];
    3138        if(is_single() && comments_open() && isset($options['toxicdetection']) ) {
    3239
     
    5360
    5461                       event.preventDefault();
    55                        const textComment = document.getElementById('comment').value;
    56                        classify([textComment]).then(result => {
    57                            if (result) {
    58                               alert('Your comment has been flagged as toxic and cannot be submitted as it is. This can happen due to a variety of reasons (insults, obscenity,...). Please, edit your comment and try again');
    59                            }
    60                            else  {
    61                                //console.log(commentForm);
    62                                HTMLFormElement.prototype.submit.call(commentForm)
    63                                //commentForm.submit(); <- This doesn't work due to https://stackoverflow.com/questions/56106508/submit-comment-form-inside-an-async-await-then-javascript-block-in-wordpress
    64                            }
    65                        })
     62                       try {
     63                           const textComment = document.getElementById('comment').value;
     64                           classify([textComment]).then(result => {
     65                               if (result) {
     66                                   alert('<?php echo $message; ?>');
     67                               } else {
     68                                   //console.log(commentForm);
     69                                   HTMLFormElement.prototype.submit.call(commentForm)
     70                                   //commentForm.submit(); <- This doesn't work due to https://stackoverflow.com/questions/56106508/submit-comment-form-inside-an-async-await-then-javascript-block-in-wordpress
     71                               }
     72                           })
     73                       }
     74                       catch(error)
     75                       {
     76                           console.error(error);
     77                           HTMLFormElement.prototype.submit.call(commentForm)
     78                       }
    6679                    })
    6780
     
    7184        }
    7285    }
     86
     87
     88    public function bbpress_toxicity()
     89    {
     90        $options = get_option( 'settingsToxic' );
     91        $threshold = $options['threshold']/100;
     92        $message = $options['toxicmessage'];
     93        if(is_bbpress() && bbp_is_single_topic() && isset($options['toxicdetection']) ) {
     94
     95            ?>
     96            <script>
     97                window.onload=function() {
     98                    var commentForm = document.getElementById('new-post');
     99                    commentForm.addEventListener('submit', function(event){
     100
     101                        async function classify(input) {
     102                            let toxic=false;
     103                            const model = await toxicity.load(<?php echo $threshold; ?>);
     104                            const results = await model.classify(input);
     105
     106                            for (const r of results) {
     107                                if (r.results[0].match) {
     108                                    toxic = true;
     109                                    break;
     110                                }
     111                            }
     112                            return toxic;
     113                        }
     114
     115                        event.preventDefault();
     116                        try {
     117
     118                            const textComment = document.getElementById('bbp_reply_content').value; //name of the text area with the replu
     119                            classify([textComment]).then(result => {
     120                                if (result) {
     121                                    alert('<?php echo $message; ?>');
     122                                } else {
     123                                    HTMLFormElement.prototype.submit.call(commentForm)
     124                                }
     125                            })
     126                        }
     127                        catch(error)
     128                        {
     129                            console.error(error);
     130                            HTMLFormElement.prototype.submit.call(commentForm)
     131                       }
     132                    })
     133
     134                }
     135            </script>
     136            <?php
     137        }
     138    }
     139
     140
     141
     142
    73143}
    74144
  • serious-toxic-comments/trunk/public/class-serious-toxic-comments-public.php

    r2090613 r2115899  
    6565        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/serious-toxic-comments-public.js', array( 'jquery' ), $this->version, false );
    6666        $this->define_additional_enqueue_scripts();
     67        $this->define_additional_enqueue_styles();
    6768    }
    6869
    6970    protected function define_additional_enqueue_scripts(){}
     71    protected function define_additional_enqueue_styles(){}
    7072}
    7173
  • serious-toxic-comments/trunk/serious-toxic-comments.php

    r2090613 r2115899  
    1717 * Plugin URI:        https://wordpress.org/plugins/serious-toxic-comments
    1818 * Description:       Flag and block toxic comments on your site
    19  * Version:           1.0.0
     19 * Version:           1.1
    2020 * Author:            Jordi Cabot
    2121 * Author URI:        https://seriouswp.com
Note: See TracChangeset for help on using the changeset viewer.