Changeset 2115899
- Timestamp:
- 07/02/2019 05:13:49 AM (7 years ago)
- Location:
- serious-toxic-comments/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (2 diffs)
-
admin/partials/class-serious-toxic-comments-admin-settings.php (modified) (2 diffs)
-
includes/class-serious-toxic-comments-ext.php (modified) (1 diff)
-
public/class-serious-toxic-comments-public-ext.php (modified) (3 diffs)
-
public/class-serious-toxic-comments-public.php (modified) (1 diff)
-
serious-toxic-comments.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
serious-toxic-comments/trunk/README.txt
r2090619 r2115899 1 1 === Serious Toxic Comments === 2 2 Contributors: softmodeling, seriouswp 3 Tags: comments, toxic, toxicity, AI, tensorflow, insults, offensive, threats, machine learning 3 Tags: comments, toxic, toxicity, AI, tensorflow, insults, offensive, threats, machine learning, bbpress, forum 4 4 Requires at least: 4.3 5 Tested up to: 5.2 5 Tested up to: 5.2.2 6 6 Requires PHP: 5.6 7 7 Stable tag: trunk … … 48 48 == Changelog == 49 49 50 = 1.1 = 51 * Added support for bbPress 52 * Possibility to configure the warning message when a toxic comment is detected 53 50 54 = 1.0 = 51 55 * 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 64 64 ); 65 65 66 add_settings_field( 67 'toxicmessage', 68 'Start checking comments', 69 array($this,'render_toxicmessage_field'), 70 'discussion', 71 'toxicconfig' 72 ); 73 66 74 } 67 75 … … 85 93 echo '<input type="range" name="settingsToxic[threshold]" size="10" value="' . esc_attr( $value ).'" min="1" max="100" />'; 86 94 } 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 } 87 103 } 88 104 -
serious-toxic-comments/trunk/includes/class-serious-toxic-comments-ext.php
r2090613 r2115899 16 16 17 17 protected function define_additional_public_hooks($plugin_public){ 18 $this->loader->add_action( 'wp_footer', $plugin_public, 'c omment_toxicity' );18 $this->loader->add_action( 'wp_footer', $plugin_public, 'check_text_toxicity' ); 19 19 } 20 20 -
serious-toxic-comments/trunk/public/class-serious-toxic-comments-public-ext.php
r2090613 r2115899 25 25 26 26 27 public function check_text_toxicity() 28 { 29 $this->comment_toxicity(); 30 $this->bbpress_toxicity(); 31 } 32 27 33 public function comment_toxicity() 28 34 { 29 35 $options = get_option( 'settingsToxic' ); 30 36 $threshold = $options['threshold']/100; 37 $message = $options['toxicmessage']; 31 38 if(is_single() && comments_open() && isset($options['toxicdetection']) ) { 32 39 … … 53 60 54 61 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 } 66 79 }) 67 80 … … 71 84 } 72 85 } 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 73 143 } 74 144 -
serious-toxic-comments/trunk/public/class-serious-toxic-comments-public.php
r2090613 r2115899 65 65 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/serious-toxic-comments-public.js', array( 'jquery' ), $this->version, false ); 66 66 $this->define_additional_enqueue_scripts(); 67 $this->define_additional_enqueue_styles(); 67 68 } 68 69 69 70 protected function define_additional_enqueue_scripts(){} 71 protected function define_additional_enqueue_styles(){} 70 72 } 71 73 -
serious-toxic-comments/trunk/serious-toxic-comments.php
r2090613 r2115899 17 17 * Plugin URI: https://wordpress.org/plugins/serious-toxic-comments 18 18 * Description: Flag and block toxic comments on your site 19 * Version: 1. 0.019 * Version: 1.1 20 20 * Author: Jordi Cabot 21 21 * Author URI: https://seriouswp.com
Note: See TracChangeset
for help on using the changeset viewer.