Changeset 3893
- Timestamp:
- 08/31/2016 06:16:14 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/profiles.wordpress.org/public_html/wp-content/plugins/wporg-profiles-activity-handler/wporg-profiles-activity-handler.php
r3806 r3893 113 113 114 114 return $activated; 115 } 116 117 /** 118 * Checks that required POST arguments are defined and have a value. 119 * 120 * Ends request and reports on any missing arguments, if necessary. 121 * 122 * @param array $args The array of required POST arguments. 123 */ 124 protected function require_args( $args ) { 125 $missing = array(); 126 127 foreach ( $args as $arg ) { 128 if ( empty( $_POST[ $arg ] ) ) { 129 $missing[] = $arg; 130 } 131 } 132 133 if ( $missing ) { 134 die( '-1 Required argument(s) are missing: ' . implode( ', ', $missing ) ); 135 } 115 136 } 116 137 … … 195 216 * - Creating new topic 196 217 * - Replying to a topic 218 * - Removing a topic 219 * - Removing a topic reply 197 220 */ 198 221 private function handle_forum_activity() { 199 222 $user = $this->get_user( $_POST['user'] ); 200 223 $type = ''; 224 225 // Check for valid user. 201 226 if ( ! $user ) { 202 227 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $_POST['user'] ); 203 228 } 204 229 205 if ( '1' == $_POST['newTopic'] ) { 206 $action = sprintf( 207 __( 'Created a topic, <a href="%s">%s</a>, on the site %s', 'wporg' ), 208 esc_url( $_POST['url'] ), 209 $_POST['title'], 210 $_POST['site'] 211 ); 212 $type = 'forum_topic_create'; 230 // Check for valid forum activities. 231 $activities = array( 232 'create-topic' => 'forum_topic_create', 233 'remove-topic' => 'forum_topic_remove', 234 'create-reply' => 'forum_reply_create', 235 'remove-reply' => 'forum_reply_remove', 236 ); 237 if ( ! empty( $_POST['activity'] ) && ! empty( $activities[ $_POST['activity'] ] ) ) { 238 $type = $activities[ $_POST['activity'] ]; 213 239 } else { 214 $action = sprintf( 215 __( 'Posted a <a href="%s">reply</a> to %s, on the site %s', 'wporg' ), 216 esc_url( $_POST['url'] ), 217 $_POST['title'], 218 $_POST['site'] 219 ); 220 $type = 'forum_reply_create'; 221 } 222 240 return '-1 Unrecognized forum activity.'; 241 } 242 243 // Check for required args. 244 $required_args = array( 'forum_id' ); 245 if ( in_array( $type, array( 'forum_topic_create', 'forum_reply_create' ) ) ) { 246 $required_args[] = 'message'; 247 $required_args[] = 'url'; 248 $required_args = array_merge( $required_args, array( 'title', 'site', 'message', 'url' ) ); 249 } 250 if ( in_array( $type, array( 'forum_topic_create', 'forum_topic_remove' ) ) ) { 251 $required_args[] = 'topic_id'; 252 } else { 253 $required_args[] = 'post_id'; 254 } 255 $this->require_args( $required_args ); 256 257 // Determine 'item_id' value based on context. 258 $item_id = in_array( $type, array( 'forum_topic_create', 'forum_topic_remove' ) ) ? 259 intval( $_POST['topic_id'] ) : 260 intval( $_POST['post_id'] ); 261 262 // Find an existing activity uniquely identified by the reported criteria. 263 // For a creation, this prevents duplication and permits a previously 264 // trashed/spammed/unapproved activity to be restored. 265 // For a removal, this is used to find the activity to mark it as spam. 266 // Note: It's unlikely, but possible, that this is a non-unique request. 223 267 $args = array( 224 268 'user_id' => $user->ID, 225 'action' => $action,226 'content' => $_POST['message'],227 'primary_link' => $_POST['url'],228 269 'component' => 'forums', 229 'type' => $type,230 'item_id' => 'forum_topic_create' ? intval( $_POST['topic_id'] ) : intval( $_POST['post_id'] ),270 'type' => str_replace( 'remove', 'create', $type ), 271 'item_id' => $item_id, 231 272 'secondary_item_id' => intval( $_POST['forum_id'] ), 232 'hide_sitewide' => false,233 273 ); 234 235 return bp_activity_add( $args ); 274 $activity_id = bp_activity_get_activity_id( $args ); 275 $activity_obj = $activity_id ? new BP_Activity_Activity( $activity_id ) : false; 276 277 // Record the creation of a topic or reply. 278 if ( in_array( $type, array( 'forum_topic_create', 'forum_reply_create' ) ) ) { 279 if ( $activity_obj ) { 280 bp_activity_mark_as_ham( $activity_obj, 'by_source' ); 281 $activity_obj->save(); 282 283 return true; 284 } 285 286 // Action message for topic creation. 287 if ( 'forum_topic_create' === $type ) { 288 $action = sprintf( 289 __( 'Created a topic, <i><a href="%s">%s</a></i>, on the site %s', 'wporg' ), 290 esc_url( $_POST['url'] ), 291 esc_html( $_POST['title'] ), 292 esc_html( $_POST['site'] ) 293 ); 294 } 295 // Action message for reply creation. 296 else { 297 $action = sprintf( 298 __( 'Posted a <a href="%s">reply</a> to <i>%s</i>, on the site %s', 'wporg' ), 299 esc_url( $_POST['url'] ), 300 esc_html( $_POST['title'] ), 301 esc_html( $_POST['site'] ) 302 ); 303 } 304 305 $args = array( 306 'user_id' => $user->ID, 307 'action' => $action, 308 'content' => esc_html( $_POST['message'] ), 309 'primary_link' => esc_url( $_POST['url'] ), 310 'component' => 'forums', 311 'type' => $type, 312 'item_id' => $item_id, 313 'secondary_item_id' => intval( $_POST['forum_id'] ), 314 'hide_sitewide' => false, 315 ); 316 317 return bp_activity_add( $args ); 318 } 319 // Remove activity related to a topic or reply. 320 elseif ( in_array( $type, array( 'forum_topic_remove', 'forum_reply_remove' ) ) ) { 321 if ( ! $activity_obj ) { 322 return '-1 Activity not previously reported.'; 323 } 324 325 bp_activity_mark_as_spam( $activity_obj, 'by_source' ); 326 $activity_obj->save(); 327 328 return true; 329 } 236 330 } 237 331
Note: See TracChangeset
for help on using the changeset viewer.