Ticket #4821: 4821.patch
File 4821.patch, 11.3 KB (added by , 6 years ago) |
---|
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-report-topic.php
5 5 class Report_Topic { 6 6 7 7 public function __construct() { 8 add_action( 'wporg_support_after_topic_info', array( $this, 'add_sidebar_link' ) ); 8 add_action( 'wporg_support_after_topic_info', array( $this, 'add_sidebar_form' ) ); 9 10 add_action( 'set_object_terms', array( $this, 'detect_manual_modlook' ), 10, 6 ); 9 11 10 12 add_action( 'init', array( $this, 'capture_topic_report' ) ); 11 13 } 12 14 13 public function capture_topic_report() { 14 // Do not process anything if the user is not logged in. 15 if ( ! is_user_logged_in() ) { 16 return; 15 public function detect_manual_modlook( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) { 16 $modlook = null; 17 18 /* 19 * Loop over the submitted terms to get the modlook taxonomy ID. 20 * it's slightly less ideal than a `in_array()` check, but is needed as users 21 * may have put spaces around the term somehow for example, and we need the ID 22 * later for processing. 23 */ 24 foreach ( $terms as $term_id => $term_slug ) { 25 if ( 'modlook' === trim( $term_slug ) ) { 26 $modlook = $tt_ids[ $term_id ]; 27 break; 28 } 17 29 } 18 30 19 if ( isset( $_GET['wporg-support-report-topic'] ) ) { 20 $action = sprintf( 21 'report-topic-%d', 22 $_GET['wporg-support-report-topic'] 23 ); 24 25 // Verify that the nonce is valid. 26 if ( ! wp_verify_nonce( $_GET['_wpnonce'], $action ) ) { 27 return; 28 } 31 // If no modlook tag was found, or if the tag already existed from a previous reply, don't record it again. 32 if ( null === $modlook || in_array( $modlook, $old_tt_ids ) ) { 33 return; 34 } 29 35 30 wp_add_object_terms( $_GET['wporg-support-report-topic'], 'modlook', 'topic-tag' ); 36 // Translators: Default string to show when a topic is reported outside the report form feature. 37 $this->add_modlook_history( $object_id, __( '[Manually added when replying]', 'wporg-forums' ), true ); 38 } 31 39 32 $reporter = $this->get_previous_reports( $_GET['wporg-support-report-topic'] ); 33 if ( empty( $reporter ) ) { 34 $reporter = array(); 35 } 40 public function add_modlook_history( $topic, $reason = null ) { 41 $reporter = $this->get_previous_reports( $topic ); 42 if ( empty( $reporter ) ) { 43 $reporter = array(); 44 } 36 45 37 46 $current_user = get_current_user_id(); 38 47 39 40 41 42 48 // In those odd cases where the same user reports a topic multiple times, let's increment them, so we can track each report time. 49 $report_id = $current_user; 50 if ( isset( $reporter[ $report_id ] ) ) { 51 $increment = 1; 43 52 44 45 46 47 48 53 $report_id = sprintf( 54 '%d-%d', 55 $current_user, 56 $increment 57 ); 49 58 50 51 59 while ( isset( $reporter[ $report_id ] ) ) { 60 $increment++; 52 61 53 54 55 56 57 58 59 62 /* 63 * If someone reports the same topic repeatedly, let's just stop logging it to avoid 64 * a never ending incremental loop, our moderators are smart enough to pick up on such behavior. 65 */ 66 if ( $increment > 10 ) { 67 return; 68 } 60 69 61 62 63 64 65 66 67 70 $report_id = sprintf( 71 '%d-%d', 72 $current_user, 73 $increment 74 ); 75 } 76 } 68 77 69 $reporter[ $report_id ] = array( 70 'time' => current_time( 'mysql' ), 71 'user' => $current_user, 72 ); 78 $reporter[ $report_id ] = array( 79 'time' => current_time( 'mysql' ), 80 'user' => $current_user, 81 'reason' => $reason, 82 ); 73 83 74 update_post_meta( $_GET['wporg-support-report-topic'], '_wporg_topic_reported_by', $reporter ); 84 update_post_meta( $topic, '_wporg_topic_reported_by', $reporter ); 85 86 } 75 87 76 wp_safe_redirect( get_the_permalink( $_GET['wporg-support-report-topic'] ) ); 88 public function capture_topic_report() { 89 // Do not process anything if the user is not logged in. 90 if ( ! is_user_logged_in() ) { 91 return; 92 } 93 94 if ( isset( $_POST['wporg-support-report-topic'] ) ) { 95 $action = sprintf( 96 'report-topic-%d', 97 $_POST['wporg-support-report-topic'] 98 ); 99 100 // Verify that the nonce is valid. 101 if ( ! wp_verify_nonce( $_POST['_wpnonce'], $action ) ) { 102 return; 103 } 104 105 wp_add_object_terms( $_POST['wporg-support-report-topic'], 'modlook', 'topic-tag' ); 106 107 $reason = $_POST['topic-report-reason']; 108 109 if ( 'other-input' === $reason ) { 110 $reason = $_POST['topic-report-reason-other']; 111 } 112 113 $this->add_modlook_history( $_POST['wporg-support-report-topic'], $reason ); 114 115 wp_safe_redirect( get_the_permalink( $_POST['wporg-support-report-topic'] ) ); 77 116 78 117 exit(); 79 118 } … … 97 136 } 98 137 } 99 138 100 public function add_sidebar_ link() {139 public function add_sidebar_form() { 101 140 // We don't want to allow anonymous users to report topics, we want to track who reports them. 102 141 if ( ! is_user_logged_in() ) { 103 142 return; … … 112 151 return; 113 152 } 114 153 115 $current_user = get_current_user_id();116 154 $previous_reports = $this->get_previous_reports(); 117 155 $is_reported = has_term( 'modlook', 'topic-tag', $topic_id ); 118 156 119 $report_text = '';120 121 157 if ( $is_reported ) { 122 158 $report_text = __( 'This topic has been reported', 'wporg-forums' ); 123 159 } 124 160 else { 125 if ( isset( $previous_reports[ $current_user ] ) ) { 126 $report_text = sprintf( 127 '<a href="%s">%s</a>', 128 esc_url( $this->get_report_topic_url() ), 129 __( 'Report this topic again', 'wporg-forums' ) 130 ); 131 } 132 else { 133 $report_text = sprintf( 134 '<a href="%s">%s</a>', 135 esc_url( $this->get_report_topic_url() ), 136 __( 'Report this topic', 'wporg-forums' ) 137 ); 138 } 161 $action = sprintf( 162 'report-topic-%d', 163 bbp_get_topic_id() 164 ); 165 166 ob_start(); 167 ?> 168 169 <form action="" method="post"> 170 <?php wp_nonce_field( $action ); ?> 171 <input type="hidden" name="wporg-support-report-topic" value="<?php echo esc_attr( bbp_get_topic_id() ); ?>"> 172 173 <label for="topic-report-reason"><?php _e( 'Report this topic for:', 'wporg-forums' ); ?></label> 174 <select name="topic-report-reason" id="topic-report-reason" required="required" onchange="wporg_report_topic_change()"> 175 <option value=""><?php _ex( '— Choose one —', 'Report a topic reason', 'wporg-forums' ); ?></option> 176 <option><?php _ex( 'Guideline violation', 'Report a topic reason', 'wporg-forums' ); ?></option> 177 <option><?php _ex( 'Security related', 'Report a topic reason', 'wporg-forums' ); ?></option> 178 <option><?php _ex( 'Spam', 'Report a topic reason', 'wporg-forums' ); ?></option> 179 <option><?php _ex( 'NSFW (Not Safe For Work) link', 'Report a topic reason', 'wporg-forums' ); ?></option> 180 <option value="other-input"><?php _ex( 'Other', 'Report a topic reason', 'wporg-forums' ); ?></option> 181 </select> 182 <aside id="report-topic-other" style="display: none;"> 183 <label for="topic-report-reason-other"><?php _e( 'Your own reason:', 'wporg-forums' ); ?></label> 184 <input type="text" name="topic-report-reason-other" id="topic-report-reason-other"> 185 </aside> 186 <input type="submit" name="submit" value="<?php esc_attr_e( 'Report', 'wporg-forums' ); ?>"> 187 </form> 188 189 <script type="text/javascript"> 190 function wporg_report_topic_change() { 191 if ( 'other-input' === document.getElementById('topic-report-reason').value ) { 192 document.getElementById( 'report-topic-other' ).style.display = 'block'; 193 } else { 194 document.getElementById( 'report-topic-other' ).style.display = 'none'; 195 } 196 } 197 </script> 198 <?php 199 $report_text = ob_get_clean(); 139 200 } 140 201 141 202 if ( $is_reported && current_user_can( 'moderate' ) ) { … … 156 217 if ( current_user_can( 'moderate' ) && ! empty( $previous_reports ) ) { 157 218 $lines = array(); 158 219 220 // List the latest report first. 221 $previous_reports = array_reverse( $previous_reports ); 222 159 223 foreach( $previous_reports as $report ) { 160 224 $lines[] = sprintf( 161 '<li><a href="%s">%s</a></li>', 162 esc_url( bbp_get_user_profile_url( $report['user']) ), 225 '<li>%s</li>', 163 226 sprintf( 164 /* translators: %1$s: Reporters display name, %2$s: date, %3$s: time */ 165 '%1$s on %2$s at %3$s', 166 get_the_author_meta( 'display_name', $report['user'] ), 227 /* translators: 1: Reporters display name, 2: date, 3: time, 4: reason (when provided) */ 228 '%1$s on %2$s at %3$s %4$s', 229 sprintf( 230 '<a href="%s">%s</a>', 231 esc_url( bbp_get_user_profile_url( $report['user']) ), 232 get_the_author_meta( 'display_name', $report['user'] ) 233 ), 167 234 /* translators: localized date format, see https://secure.php.net/date */ 168 235 mysql2date( __( 'F j, Y', 'wporg-forums' ), $report['time'] ), 169 236 /* translators: localized time format, see https://secure.php.net/date */ 170 mysql2date( __( 'g:i a', 'wporg-forums' ), $report['time'] ) 237 mysql2date( __( 'g:i a', 'wporg-forums' ), $report['time'] ), 238 ( ! isset( $report['reason'] ) || empty( $report['reason'] ) ? '' : sprintf( 239 /* translators: %s: The reason this topic was reported. */ 240 'reason: %s', 241 esc_html( $report['reason'] ) 242 ) ) 171 243 ) 172 244 ); 173 245 } … … 194 266 return $reporters; 195 267 } 196 268 197 public function get_report_topic_url() {198 $url = add_query_arg( array(199 'wporg-support-report-topic' => bbp_get_topic_id(),200 ), get_the_permalink() );201 202 $action = sprintf(203 'report-topic-%d',204 bbp_get_topic_id()205 );206 207 return wp_nonce_url( $url, $action );208 }209 210 269 public function remove_topic_modlook_url() { 211 270 $url = add_query_arg( array( 212 271 'wporg-support-remove-modlook' => bbp_get_topic_id(), -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/sass/site/_bbpress.scss
1041 1041 content: "\f487"; 1042 1042 } 1043 1043 1044 .topic-info li.topic-report::before { 1045 content: "\f227"; 1046 } 1044 .topic-info li.topic-report { 1045 1046 &::before { 1047 content: "\f227"; 1048 } 1047 1049 1050 select, 1051 input[type="text"] { 1052 width: 100%; 1053 padding: 0.2rem 0.5rem 0.1rem; 1054 margin: 0; 1055 } 1056 } 1057 1048 1058 .topic-info li.topic-previous-reports { 1049 1059 1050 1060 .previous-reports {