Ticket #7218: 7218.activity-v3.patch
File 7218.activity-v3.patch, 81.4 KB (added by , 7 years ago) |
---|
-
src/bp-activity/bp-activity-actions.php
19 19 * 20 20 */ 21 21 function bp_register_activity_actions() { 22 23 22 /** 24 23 * Fires on bp_init to allow core components and dependent plugins to register activity actions. 25 24 * … … 33 32 * Catch and route requests for single activity item permalinks. 34 33 * 35 34 * @since 1.2.0 36 *37 * @return bool False on failure.38 35 */ 39 36 function bp_activity_action_permalink_router() { 40 41 37 // Not viewing activity. 42 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) ) 43 return false; 44 45 // No activity to display. 46 if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) ) 47 return false; 48 49 // Get the activity details. 50 $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) ); 51 52 // 404 if activity does not exist 53 if ( empty( $activity['activities'][0] ) ) { 54 bp_do_404(); 38 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) ) { 55 39 return; 56 } else {57 $activity = $activity['activities'][0];58 }59 60 // Do not redirect at default.61 $redirect = false;62 63 // Redirect based on the type of activity.64 if ( bp_is_active( 'groups' ) && $activity->component == buddypress()->groups->id ) {65 66 // Activity is a user update.67 if ( ! empty( $activity->user_id ) ) {68 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';69 70 // Activity is something else.71 } else {72 73 // Set redirect to group activity stream.74 if ( $group = groups_get_group( $activity->item_id ) ) {75 $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/';76 }77 }78 79 // Set redirect to users' activity stream.80 } elseif ( ! empty( $activity->user_id ) ) {81 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';82 40 } 83 41 84 // If set, add the original query string back onto the redirect URL. 85 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { 86 $query_frags = array(); 87 wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags ); 88 $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect ); 89 } 90 91 /** 92 * Filter the intended redirect url before the redirect occurs for the single activity item. 93 * 94 * @since 1.2.2 95 * 96 * @param array $value Array with url to redirect to and activity related to the redirect. 97 */ 98 if ( ! $redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) ) { 99 bp_core_redirect( bp_get_root_domain() ); 42 // No activity to display. 43 if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) ) { 44 return; 100 45 } 101 46 102 // Redirect to the actual activity permalink page.103 bp_core_redirect( $redirect);47 $action = new BP_Activity_Action_Permalink_Router(); 48 $action->init(); 104 49 } 105 50 add_action( 'bp_actions', 'bp_activity_action_permalink_router' ); 106 51 107 52 /** 108 * Delete specific activity item and redirect to previous page.53 * Delete activity item handler when JS is disabled. 109 54 * 110 55 * @since 1.1.0 111 56 * … … 113 58 * @return bool False on failure. 114 59 */ 115 60 function bp_activity_action_delete_activity( $activity_id = 0 ) { 116 117 61 // Not viewing activity or action is not delete. 118 if ( ! bp_is_activity_component() || !bp_is_current_action( 'delete' ) )62 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'delete' ) ) { 119 63 return false; 64 } 120 65 121 if ( empty( $activity_id ) && bp_action_variable( 0 ) ) 66 if ( empty( $activity_id ) && bp_action_variable( 0 ) ) { 122 67 $activity_id = (int) bp_action_variable( 0 ); 68 } 123 69 124 70 // Not viewing a specific activity item. 125 if ( empty( $activity_id ) ) 126 return false; 127 128 // Check the nonce. 129 check_admin_referer( 'bp_activity_delete_link' ); 130 131 // Load up the activity item. 132 $activity = new BP_Activity_Activity( $activity_id ); 133 134 // Check access. 135 if ( ! bp_activity_user_can_delete( $activity ) ) 71 if ( empty( $activity_id ) ) { 136 72 return false; 73 } 137 74 138 /** 139 * Fires before the deletion so plugins can still fetch information about it. 140 * 141 * @since 1.5.0 142 * 143 * @param int $activity_id The activity ID. 144 * @param int $user_id The user associated with the activity. 145 */ 146 do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id ); 147 148 // Delete the activity item and provide user feedback. 149 if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) ) 150 bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) ); 151 else 152 bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' ); 153 154 /** 155 * Fires after the deletion so plugins can act afterwards based on the activity. 156 * 157 * @since 1.1.0 158 * 159 * @param int $activity_id The activity ID. 160 * @param int $user_id The user associated with the activity. 161 */ 162 do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id ); 163 164 // Check for the redirect query arg, otherwise let WP handle things. 165 if ( !empty( $_GET['redirect_to'] ) ) 166 bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); 167 else 168 bp_core_redirect( wp_get_referer() ); 75 $action = new BP_Activity_Action_Delete(); 76 return $action->init( $activity_id ); 169 77 } 170 78 add_action( 'bp_actions', 'bp_activity_action_delete_activity' ); 171 79 172 80 /** 173 * Mark specific activity item as spam and redirect to previous page.81 * Mark activity item as spam handler when JS is disabled. 174 82 * 175 83 * @since 1.6.0 176 84 * 177 85 * @param int $activity_id Activity id to be deleted. Defaults to 0. 178 * @return bool False on failure.86 * @return bool|void False on failure. 179 87 */ 180 88 function bp_activity_action_spam_activity( $activity_id = 0 ) { 181 $bp = buddypress();182 183 89 // Not viewing activity, or action is not spam, or Akismet isn't present. 184 if ( ! bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )90 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'spam' ) || empty( buddypress()->activity->akismet ) ) { 185 91 return false; 92 } 186 93 187 if ( empty( $activity_id ) && bp_action_variable( 0 ) ) 94 if ( empty( $activity_id ) && bp_action_variable( 0 ) ) { 188 95 $activity_id = (int) bp_action_variable( 0 ); 96 } 189 97 190 98 // Not viewing a specific activity item. 191 if ( empty( $activity_id ) ) 192 return false; 193 194 // Is the current user allowed to spam items? 195 if ( !bp_activity_user_can_mark_spam() ) 196 return false; 197 198 // Load up the activity item. 199 $activity = new BP_Activity_Activity( $activity_id ); 200 if ( empty( $activity->id ) ) 99 if ( empty( $activity_id ) ) { 201 100 return false; 101 } 202 102 203 // Check nonce. 204 check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id ); 205 206 /** 207 * Fires before the marking activity as spam so plugins can modify things if they want to. 208 * 209 * @since 1.6.0 210 * 211 * @param int $activity_id Activity ID to be marked as spam. 212 * @param object $activity Activity object for the ID to be marked as spam. 213 */ 214 do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity ); 215 216 // Mark as spam. 217 bp_activity_mark_as_spam( $activity ); 218 $activity->save(); 219 220 // Tell the user the spamming has been successful. 221 bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) ); 222 223 /** 224 * Fires after the marking activity as spam so plugins can act afterwards based on the activity. 225 * 226 * @since 1.6.0 227 * 228 * @param int $activity_id Activity ID that was marked as spam. 229 * @param int $user_id User ID associated with activity. 230 */ 231 do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id ); 232 233 // Check for the redirect query arg, otherwise let WP handle things. 234 if ( !empty( $_GET['redirect_to'] ) ) 235 bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); 236 else 237 bp_core_redirect( wp_get_referer() ); 103 $action = new BP_Activity_Action_Spam(); 104 return $action->init( $activity_id ); 238 105 } 239 106 add_action( 'bp_actions', 'bp_activity_action_spam_activity' ); 240 107 241 108 /** 242 * Post user/group activity update .109 * Post user/group activity update handler when JS is disabled. 243 110 * 244 111 * @since 1.2.0 245 112 * 246 113 * @return bool False on failure. 247 114 */ 248 115 function bp_activity_action_post_update() { 249 250 116 // Do not proceed if user is not logged in, not viewing activity, or not posting. 251 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) ) 252 return false; 253 254 // Check the nonce. 255 check_admin_referer( 'post_update', '_wpnonce_post_update' ); 256 257 /** 258 * Filters the content provided in the activity input field. 259 * 260 * @since 1.2.0 261 * 262 * @param string $value Activity message being posted. 263 */ 264 $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] ); 265 266 if ( ! empty( $_POST['whats-new-post-object'] ) ) { 267 268 /** 269 * Filters the item type that the activity update should be associated with. 270 * 271 * @since 1.2.0 272 * 273 * @param string $value Item type to associate with. 274 */ 275 $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] ); 276 } 277 278 if ( ! empty( $_POST['whats-new-post-in'] ) ) { 279 280 /** 281 * Filters what component the activity is being to. 282 * 283 * @since 1.2.0 284 * 285 * @param string $value Chosen component to post activity to. 286 */ 287 $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] ); 288 } 289 290 // No activity content so provide feedback and redirect. 291 if ( empty( $content ) ) { 292 bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' ); 293 bp_core_redirect( wp_get_referer() ); 294 } 295 296 // No existing item_id. 297 if ( empty( $item_id ) ) { 298 $activity_id = bp_activity_post_update( array( 'content' => $content ) ); 299 300 // Post to groups object. 301 } elseif ( 'groups' == $object && bp_is_active( 'groups' ) ) { 302 if ( (int) $item_id ) { 303 $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) ); 304 } 305 306 } else { 307 308 /** 309 * Filters activity object for BuddyPress core and plugin authors before posting activity update. 310 * 311 * @since 1.2.0 312 * 313 * @param string $object Activity item being associated to. 314 * @param string $item_id Component ID being posted to. 315 * @param string $content Activity content being posted. 316 */ 317 $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content ); 117 if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'post' ) ) { 118 return; 318 119 } 319 120 320 // Provide user feedback. 321 if ( !empty( $activity_id ) ) 322 bp_core_add_message( __( 'Update Posted!', 'buddypress' ) ); 323 else 324 bp_core_add_message( __( 'There was an error when posting your update. Please try again.', 'buddypress' ), 'error' ); 325 326 // Redirect. 327 bp_core_redirect( wp_get_referer() ); 121 $action = new BP_Activity_Action_Post_Update(); 122 $action->init(); 328 123 } 329 124 add_action( 'bp_actions', 'bp_activity_action_post_update' ); 330 125 331 126 /** 332 * Post new activity comment .127 * Post new activity comment handler when JS is disabled. 333 128 * 334 129 * @since 1.2.0 335 130 * 336 131 * @return bool False on failure. 337 132 */ 338 133 function bp_activity_action_post_comment() { 339 340 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'reply' ) ) 341 return false; 342 343 // Check the nonce. 344 check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' ); 345 346 /** 347 * Filters the activity ID a comment will be in reply to. 348 * 349 * @since 1.2.0 350 * 351 * @param string $value ID of the activity being replied to. 352 */ 353 $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] ); 354 355 /** 356 * Filters the comment content for a comment reply. 357 * 358 * @since 1.2.0 359 * 360 * @param string $value Comment content being posted. 361 */ 362 $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] ); 363 364 if ( empty( $content ) ) { 365 bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' ); 366 bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id ); 134 if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'reply' ) ) { 135 return; 367 136 } 368 137 369 $comment_id = bp_activity_new_comment( array( 370 'content' => $content, 371 'activity_id' => $activity_id, 372 'parent_id' => false 373 )); 374 375 if ( !empty( $comment_id ) ) 376 bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) ); 377 else 378 bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' ); 379 380 bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id ); 138 $action = new BP_Activity_Action_Post_Comment(); 139 $action->init(); 381 140 } 382 141 add_action( 'bp_actions', 'bp_activity_action_post_comment' ); 383 142 … … 385 144 * Mark activity as favorite. 386 145 * 387 146 * @since 1.2.0 388 *389 * @return bool False on failure.390 147 */ 391 148 function bp_activity_action_mark_favorite() { 149 if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'favorite' ) ) { 150 return; 151 } 392 152 393 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'favorite' ) ) 394 return false; 395 396 // Check the nonce. 397 check_admin_referer( 'mark_favorite' ); 398 399 if ( bp_activity_add_user_favorite( bp_action_variable( 0 ) ) ) 400 bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) ); 401 else 402 bp_core_add_message( __( 'There was an error marking that activity as a favorite. Please try again.', 'buddypress' ), 'error' ); 403 404 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) ); 153 $action = new BP_Activity_Action_Favorite(); 154 $action->init(); 405 155 } 406 156 add_action( 'bp_actions', 'bp_activity_action_mark_favorite' ); 407 157 … … 413 163 * @return bool False on failure. 414 164 */ 415 165 function bp_activity_action_remove_favorite() { 416 417 if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'unfavorite' ) ) 418 return false; 419 420 // Check the nonce. 421 check_admin_referer( 'unmark_favorite' ); 422 423 if ( bp_activity_remove_user_favorite( bp_action_variable( 0 ) ) ) 424 bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) ); 425 else 426 bp_core_add_message( __( 'There was an error removing that activity as a favorite. Please try again.', 'buddypress' ), 'error' ); 427 428 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) ); 429 } 430 add_action( 'bp_actions', 'bp_activity_action_remove_favorite' ); 431 432 /** 433 * Load the sitewide activity feed. 434 * 435 * @since 1.0.0 436 * 437 * @return bool False on failure. 438 */ 439 function bp_activity_action_sitewide_feed() { 440 $bp = buddypress(); 441 442 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) ) 443 return false; 444 445 // Setup the feed. 446 buddypress()->activity->feed = new BP_Activity_Feed( array( 447 'id' => 'sitewide', 448 449 /* translators: Sitewide activity RSS title - "[Site Name] | Site Wide Activity" */ 450 'title' => sprintf( __( '%s | Site-Wide Activity', 'buddypress' ), bp_get_site_name() ), 451 452 'link' => bp_get_activity_directory_permalink(), 453 'description' => __( 'Activity feed for the entire site.', 'buddypress' ), 454 'activity_args' => 'display_comments=threaded' 455 ) ); 456 } 457 add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' ); 458 459 /** 460 * Load a user's personal activity feed. 461 * 462 * @since 1.0.0 463 * 464 * @return bool False on failure. 465 */ 466 function bp_activity_action_personal_feed() { 467 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'feed' ) ) { 468 return false; 469 } 470 471 // Setup the feed. 472 buddypress()->activity->feed = new BP_Activity_Feed( array( 473 'id' => 'personal', 474 475 /* translators: Personal activity RSS title - "[Site Name] | [User Display Name] | Activity" */ 476 'title' => sprintf( __( '%1$s | %2$s | Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 477 478 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() ), 479 'description' => sprintf( __( 'Activity feed for %s.', 'buddypress' ), bp_get_displayed_user_fullname() ), 480 'activity_args' => 'user_id=' . bp_displayed_user_id() 481 ) ); 482 } 483 add_action( 'bp_actions', 'bp_activity_action_personal_feed' ); 484 485 /** 486 * Load a user's friends' activity feed. 487 * 488 * @since 1.0.0 489 * 490 * @return bool False on failure. 491 */ 492 function bp_activity_action_friends_feed() { 493 if ( ! bp_is_active( 'friends' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_friends_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) { 494 return false; 495 } 496 497 // Setup the feed. 498 buddypress()->activity->feed = new BP_Activity_Feed( array( 499 'id' => 'friends', 500 501 /* translators: Friends activity RSS title - "[Site Name] | [User Display Name] | Friends Activity" */ 502 'title' => sprintf( __( '%1$s | %2$s | Friends Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 503 504 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() ), 505 'description' => sprintf( __( "Activity feed for %s's friends.", 'buddypress' ), bp_get_displayed_user_fullname() ), 506 'activity_args' => 'scope=friends' 507 ) ); 508 } 509 add_action( 'bp_actions', 'bp_activity_action_friends_feed' ); 510 511 /** 512 * Load the activity feed for a user's groups. 513 * 514 * @since 1.2.0 515 * 516 * @return bool False on failure. 517 */ 518 function bp_activity_action_my_groups_feed() { 519 if ( ! bp_is_active( 'groups' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_groups_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) { 520 return false; 521 } 522 523 // Get displayed user's group IDs. 524 $groups = groups_get_user_groups(); 525 $group_ids = implode( ',', $groups['groups'] ); 526 527 // Setup the feed. 528 buddypress()->activity->feed = new BP_Activity_Feed( array( 529 'id' => 'mygroups', 530 531 /* translators: Member groups activity RSS title - "[Site Name] | [User Display Name] | Groups Activity" */ 532 'title' => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 533 534 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() ), 535 'description' => sprintf( __( "Public group activity feed of which %s is a member.", 'buddypress' ), bp_get_displayed_user_fullname() ), 536 'activity_args' => array( 537 'object' => buddypress()->groups->id, 538 'primary_id' => $group_ids, 539 'display_comments' => 'threaded' 540 ) 541 ) ); 542 } 543 add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' ); 544 545 /** 546 * Load a user's @mentions feed. 547 * 548 * @since 1.2.0 549 * 550 * @return bool False on failure. 551 */ 552 function bp_activity_action_mentions_feed() { 553 if ( ! bp_activity_do_mentions() ) { 554 return false; 555 } 556 557 if ( !bp_is_user_activity() || ! bp_is_current_action( 'mentions' ) || ! bp_is_action_variable( 'feed', 0 ) ) { 558 return false; 166 if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'unfavorite' ) ) { 167 return; 559 168 } 560 169 561 // Setup the feed. 562 buddypress()->activity->feed = new BP_Activity_Feed( array( 563 'id' => 'mentions', 564 565 /* translators: User mentions activity RSS title - "[Site Name] | [User Display Name] | Mentions" */ 566 'title' => sprintf( __( '%1$s | %2$s | Mentions', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 567 568 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/', 569 'description' => sprintf( __( "Activity feed mentioning %s.", 'buddypress' ), bp_get_displayed_user_fullname() ), 570 'activity_args' => array( 571 'search_terms' => '@' . bp_core_get_username( bp_displayed_user_id() ) 572 ) 573 ) ); 170 $action = BP_Activity_Action_Unfavorite(); 171 $action->init(); 574 172 } 575 add_action( 'bp_actions', 'bp_activity_action_mentions_feed' ); 576 577 /** 578 * Load a user's favorites feed. 579 * 580 * @since 1.2.0 581 * 582 * @return bool False on failure. 583 */ 584 function bp_activity_action_favorites_feed() { 585 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'favorites' ) || ! bp_is_action_variable( 'feed', 0 ) ) { 586 return false; 587 } 588 589 // Get displayed user's favorite activity IDs. 590 $favs = bp_activity_get_user_favorites( bp_displayed_user_id() ); 591 $fav_ids = implode( ',', (array) $favs ); 592 593 // Setup the feed. 594 buddypress()->activity->feed = new BP_Activity_Feed( array( 595 'id' => 'favorites', 596 597 /* translators: User activity favorites RSS title - "[Site Name] | [User Display Name] | Favorites" */ 598 'title' => sprintf( __( '%1$s | %2$s | Favorites', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 599 600 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/', 601 'description' => sprintf( __( "Activity feed of %s's favorites.", 'buddypress' ), bp_get_displayed_user_fullname() ), 602 'activity_args' => 'include=' . $fav_ids 603 ) ); 604 } 605 add_action( 'bp_actions', 'bp_activity_action_favorites_feed' ); 173 add_action( 'bp_actions', 'bp_activity_action_remove_favorite' ); 606 174 607 175 /** 608 176 * AJAX endpoint for Suggestions API lookups. 609 177 * 610 178 * @since 2.1.0 179 * 180 * @todo This should be moved out of Activity and into Core or Members. 611 181 */ 612 182 function bp_ajax_get_suggestions() { 613 if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) { 614 wp_send_json_error( 'missing_parameter' ); 615 exit; 616 } 617 618 $args = array( 619 'term' => sanitize_text_field( $_GET['term'] ), 620 'type' => sanitize_text_field( $_GET['type'] ), 621 ); 622 623 // Support per-Group suggestions. 624 if ( ! empty( $_GET['group-id'] ) ) { 625 $args['group_id'] = absint( $_GET['group-id'] ); 626 } 627 628 $results = bp_core_get_suggestions( $args ); 629 630 if ( is_wp_error( $results ) ) { 631 wp_send_json_error( $results->get_error_message() ); 632 exit; 633 } 634 635 wp_send_json_success( $results ); 183 $action = new BP_Core_Ajax_Get_Suggestions(); 184 $action->init(); 636 185 } 637 186 add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' ); 638 187 … … 648 197 * @param object $post Post data. 649 198 */ 650 199 function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) { 651 if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) { 652 return; 653 } 654 655 // This is an edit. 656 if ( $new_status === $old_status ) { 657 // An edit of an existing post should update the existing activity item. 658 if ( $new_status == 'publish' ) { 659 $edit = bp_activity_post_type_update( $post ); 660 661 // Post was never recorded into activity stream, so record it now! 662 if ( null === $edit ) { 663 bp_activity_post_type_publish( $post->ID, $post ); 664 } 665 666 // Allow plugins to eventually deal with other post statuses. 667 } else { 668 /** 669 * Fires when editing the post and the new status is not 'publish'. 670 * 671 * This is a variable filter that is dependent on the post type 672 * being untrashed. 673 * 674 * @since 2.5.0 675 * 676 * @param WP_Post $post Post data. 677 * @param string $new_status New status for the post. 678 * @param string $old_status Old status for the post. 679 */ 680 do_action( 'bp_activity_post_type_edit_' . $post->post_type, $post, $new_status, $old_status ); 681 } 682 683 return; 684 } 685 686 // Publishing a previously unpublished post. 687 if ( 'publish' === $new_status ) { 688 // Untrashing the post type - nothing here yet. 689 if ( 'trash' == $old_status ) { 690 691 /** 692 * Fires if untrashing post in a post type. 693 * 694 * This is a variable filter that is dependent on the post type 695 * being untrashed. 696 * 697 * @since 2.2.0 698 * 699 * @param WP_Post $post Post data. 700 */ 701 do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); 702 } else { 703 // Record the post. 704 bp_activity_post_type_publish( $post->ID, $post ); 705 } 706 707 // Unpublishing a previously published post. 708 } elseif ( 'publish' === $old_status ) { 709 // Some form of pending status - only remove the activity entry. 710 bp_activity_post_type_unpublish( $post->ID, $post ); 711 712 // For any other cases, allow plugins to eventually deal with it. 713 } else { 714 /** 715 * Fires when the old and the new post status are not 'publish'. 716 * 717 * This is a variable filter that is dependent on the post type 718 * being untrashed. 719 * 720 * @since 2.5.0 721 * 722 * @param WP_Post $post Post data. 723 * @param string $new_status New status for the post. 724 * @param string $old_status Old status for the post. 725 */ 726 do_action( 'bp_activity_post_type_transition_status_' . $post->post_type, $post, $new_status, $old_status ); 727 } 200 $action = new BP_Activity_Transition_Post_Status(); 201 $action->init( $post, $new_status, $old_status ); 728 202 } 729 203 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); 730 204 … … 738 212 * @param WP_Comment $comment Comment data. 739 213 */ 740 214 function bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment ) { 741 $post_type = get_post_type( $comment->comment_post_ID ); 742 if ( ! $post_type ) { 743 return; 744 } 745 746 // Get the post type tracking args. 747 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 748 749 // Bail if the activity type does not exist 750 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 751 return false; 752 753 // Set the $activity_comment_object 754 } else { 755 $activity_comment_object = $activity_post_object->comments_tracking; 756 } 757 758 // Init an empty activity ID 759 $activity_id = 0; 760 761 /** 762 * Activity currently doesn't have any concept of a trash, or an unapproved/approved state. 763 * 764 * If a blog comment transitions to a "delete" or "hold" status, delete the activity item. 765 * If a blog comment transitions to trashed, or spammed, mark the activity as spam. 766 * If a blog comment transitions to approved (and the activity exists), mark the activity as ham. 767 * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam. 768 * Otherwise, record the comment into the activity stream. 769 */ 770 771 // This clause handles delete/hold. 772 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) { 773 return bp_activity_post_type_remove_comment( $comment->comment_ID, $activity_post_object ); 774 775 // These clauses handle trash, spam, and un-spams. 776 } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) { 777 $action = 'spam_activity'; 778 } elseif ( 'approved' == $new_status ) { 779 $action = 'ham_activity'; 780 } 781 782 // Get the activity 783 if ( bp_disable_blogforum_comments() ) { 784 $activity_id = bp_activity_get_activity_id( array( 785 'component' => $activity_comment_object->component_id, 786 'item_id' => get_current_blog_id(), 787 'secondary_item_id' => $comment->comment_ID, 788 'type' => $activity_comment_object->action_id, 789 ) ); 790 } else { 791 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ); 792 } 793 794 /** 795 * Leave a chance to plugins to manage activity comments differently. 796 * 797 * @since 2.5.0 798 * 799 * @param bool $value True to override BuddyPress management. 800 * @param string $post_type The post type name. 801 * @param int $activity_id The post type activity (0 if not found). 802 * @param string $new_status The new status of the post type comment. 803 * @param string $old_status The old status of the post type comment. 804 * @param WP_Comment $comment Comment data. 805 */ 806 if ( true === apply_filters( 'bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment ) ) { 807 return false; 808 } 809 810 // Check activity item exists 811 if ( empty( $activity_id ) ) { 812 // If no activity exists, but the comment has been approved, record it into the activity table. 813 if ( 'approved' == $new_status ) { 814 return bp_activity_post_type_comment( $comment->comment_ID, true, $activity_post_object ); 815 } 816 817 return; 818 } 819 820 // Create an activity object 821 $activity = new BP_Activity_Activity( $activity_id ); 822 if ( empty( $activity->component ) ) { 823 return; 824 } 825 826 // Spam/ham the activity if it's not already in that state 827 if ( 'spam_activity' === $action && ! $activity->is_spam ) { 828 bp_activity_mark_as_spam( $activity ); 829 } elseif ( 'ham_activity' == $action) { 830 bp_activity_mark_as_ham( $activity ); 831 } 832 833 // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated 834 $post_type_comment_action = $activity_comment_object->action_id; 835 $comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) { 836 $activity_types[] = $post_type_comment_action; 837 838 return $activity_types; 839 }; 840 add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 841 842 // Make sure the activity change won't edit the comment if sync is on 843 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 844 845 // Save the updated activity 846 $activity->save(); 847 848 // Restore the action 849 add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 850 851 // Remove the "new_blog_comment" activity type whitelist so we don't break anything 852 remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 215 $action = new BP_Activity_Transition_Comment_status(); 216 $action->init( $comment, $new_status, $old_status ); 853 217 } 854 218 add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 ); -
new file src/bp-activity/bp-activity-feeds.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Feeds. 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 /** 10 * Load the sitewide activity feed. 11 * 12 * @since 1.0.0 13 */ 14 function bp_activity_action_sitewide_feed() { 15 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( buddypress()->groups->current_group ) ) { 16 return; 17 } 18 19 $action = new BP_Activity_Action_Feed_Sitewide(); 20 $action->init(); 21 } 22 add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' ); 23 24 /** 25 * Load a user's personal activity feed. 26 * 27 * @since 1.0.0 28 */ 29 function bp_activity_action_personal_feed() { 30 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'feed' ) ) { 31 return; 32 } 33 34 $action = new BP_Activity_Action_Feed_Personal(); 35 $action->init(); 36 } 37 add_action( 'bp_actions', 'bp_activity_action_personal_feed' ); 38 39 /** 40 * Load a user's friends' activity feed. 41 * 42 * @since 1.0.0 43 * 44 * @return bool False on failure. 45 */ 46 function bp_activity_action_friends_feed() { 47 if ( ! bp_is_active( 'friends' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_friends_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) { 48 return; 49 } 50 51 $action = new BP_Activity_Action_Feed_Friends(); 52 $action->init(); 53 } 54 add_action( 'bp_actions', 'bp_activity_action_friends_feed' ); 55 56 /** 57 * Load the activity feed for a user's groups. 58 * 59 * @since 1.2.0 60 */ 61 function bp_activity_action_my_groups_feed() { 62 if ( ! bp_is_active( 'groups' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_groups_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) { 63 return; 64 } 65 66 $action = new BP_Activity_Action_Feed_Groups(); 67 $action->init(); 68 } 69 add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' ); 70 71 /** 72 * Load a user's @mentions feed. 73 * 74 * @since 1.2.0 75 */ 76 function bp_activity_action_mentions_feed() { 77 if ( ! bp_activity_do_mentions() || ! bp_is_user_activity() || ! bp_is_current_action( 'mentions' ) || ! bp_is_action_variable( 'feed', 0 ) ) { 78 return; 79 } 80 81 $action = new BP_Activity_Action_Feed_Mentions(); 82 $action->init(); 83 } 84 add_action( 'bp_actions', 'bp_activity_action_mentions_feed' ); 85 86 /** 87 * Load a user's favorites feed. 88 * 89 * @since 1.2.0 90 */ 91 function bp_activity_action_favorites_feed() { 92 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'favorites' ) || ! bp_is_action_variable( 'feed', 0 ) ) { 93 return; 94 } 95 96 $action = new BP_Activity_Action_Feed_Favorites(); 97 $action->init(); 98 } 99 add_action( 'bp_actions', 'bp_activity_action_favorites_feed' ); 100 No newline at end of file -
src/bp-activity/bp-activity-screens.php
21 21 * 22 22 */ 23 23 function bp_activity_screen_index() { 24 if ( bp_is_activity_directory() ) { 25 bp_update_is_directory( true, 'activity' ); 24 if ( ! bp_is_activity_directory() ) { 25 return; 26 } 26 27 27 /** 28 * Fires right before the loading of the Activity directory screen template file. 29 * 30 * @since 1.5.0 31 */ 32 do_action( 'bp_activity_screen_index' ); 28 bp_update_is_directory( true, 'activity' ); 33 29 34 /** 35 * Filters the template to load for the Activity directory screen. 36 * 37 * @since 1.5.0 38 * 39 * @param string $template Path to the activity template to load. 40 */ 41 bp_core_load_template( apply_filters( 'bp_activity_screen_index', 'activity/index' ) ); 42 } 30 /** 31 * Fires right before the loading of the Activity directory screen template file. 32 * 33 * @since 1.5.0 34 */ 35 do_action( 'bp_activity_screen_index' ); 36 37 /** 38 * Filters the template to load for the Activity directory screen. 39 * 40 * @since 1.5.0 41 * 42 * @param string $template Path to the activity template to load. 43 */ 44 bp_core_load_template( apply_filters( 'bp_activity_screen_index', 'activity/index' ) ); 43 45 } 44 46 add_action( 'bp_screens', 'bp_activity_screen_index' ); 45 47 … … 50 52 * 51 53 */ 52 54 function bp_activity_screen_my_activity() { 53 54 55 /** 55 56 * Fires right before the loading of the "My Activity" screen template file. 56 57 * … … 75 76 * 76 77 */ 77 78 function bp_activity_screen_friends() { 78 if ( !bp_is_active( 'friends' ) ) 79 return false; 79 if ( ! bp_is_active( 'friends' ) ) { 80 return; 81 } 80 82 81 83 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' ); 82 84 … … 104 106 * 105 107 */ 106 108 function bp_activity_screen_groups() { 107 if ( !bp_is_active( 'groups' ) ) 108 return false; 109 if ( ! bp_is_active( 'groups' ) ) { 110 return; 111 } 109 112 110 113 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' ); 111 114 … … 185 188 * 186 189 */ 187 190 function bp_activity_reset_my_new_mentions() { 188 if ( bp_is_my_profile() ) 191 if ( bp_is_my_profile() ) { 189 192 bp_activity_clear_new_mentions( bp_loggedin_user_id() ); 193 } 190 194 } 191 195 add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' ); 192 196 … … 198 202 * @return bool|string Boolean on false or the template for a single activity item on success. 199 203 */ 200 204 function bp_activity_screen_single_activity_permalink() { 201 // No displayed user or not viewing activity component. 202 if ( ! bp_is_activity_component() ) { 203 return false; 204 } 205 206 $action = bp_current_action(); 207 if ( ! $action || ! is_numeric( $action ) ) { 208 return false; 209 } 210 211 // Get the activity details. 212 $activity = bp_activity_get_specific( array( 213 'activity_ids' => $action, 214 'show_hidden' => true, 215 'spam' => 'ham_only', 216 ) ); 217 218 // 404 if activity does not exist 219 if ( empty( $activity['activities'][0] ) || bp_action_variables() ) { 220 bp_do_404(); 205 // Not on an activity permalink page? Bail. 206 if ( ! bp_is_activity_component() || ! bp_current_action() || ! is_numeric( bp_current_action() ) ) { 221 207 return; 222 223 } else {224 $activity = $activity['activities'][0];225 208 } 226 209 227 $user_id = bp_displayed_user_id(); 228 229 /** 230 * Check user access to the activity item. 231 * 232 * @since 3.0.0 233 */ 234 $has_access = bp_activity_user_can_read( $activity, $user_id ); 235 236 // If activity author does not match displayed user, block access. 237 // More info:https://buddypress.trac.wordpress.org/ticket/7048#comment:28 238 if ( true === $has_access && $user_id !== $activity->user_id ) { 239 $has_access = false; 240 } 241 242 /** 243 * Fires before the loading of a single activity template file. 244 * 245 * @since 1.2.0 246 * 247 * @param BP_Activity_Activity $activity Object representing the current activity item being displayed. 248 * @param bool $has_access Whether or not the current user has access to view activity. 249 */ 250 do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access ); 251 252 // Access is specifically disallowed. 253 if ( false === $has_access ) { 254 255 // User feedback. 256 bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' ); 257 258 // Redirect based on logged in status. 259 if ( is_user_logged_in() ) { 260 $url = bp_loggedin_user_domain(); 261 262 } else { 263 $url = sprintf( 264 wp_login_url( 'wp-login.php?redirect_to=%s' ), 265 esc_url_raw( bp_activity_get_permalink( $action ) ) 266 ); 267 } 268 269 bp_core_redirect( $url ); 270 } 271 272 /** 273 * Filters the template to load for a single activity screen. 274 * 275 * @since 1.0.0 276 * 277 * @param string $template Path to the activity template to load. 278 */ 279 $template = apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ); 280 281 // Load the template. 282 bp_core_load_template( $template ); 210 $action = new BP_Activity_Screen_Permalink(); 211 $action->init(); 283 212 } 284 213 add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' ); 285 214 … … 287 216 * Add activity notifications settings to the notifications settings page. 288 217 * 289 218 * @since 1.2.0 290 *291 219 */ 292 220 function bp_activity_screen_notification_settings() { 293 294 if ( bp_activity_do_mentions() ) { 295 if ( ! $mention = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_mention', true ) ) { 296 $mention = 'yes'; 297 } 298 } 299 300 if ( ! $reply = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_reply', true ) ) { 301 $reply = 'yes'; 302 } 303 304 ?> 305 306 <table class="notification-settings" id="activity-notification-settings"> 307 <thead> 308 <tr> 309 <th class="icon"> </th> 310 <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th> 311 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 312 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 313 </tr> 314 </thead> 315 316 <tbody> 317 <?php if ( bp_activity_do_mentions() ) : ?> 318 <tr id="activity-notification-settings-mentions"> 319 <td> </td> 320 <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) ?></td> 321 <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-yes" value="yes" <?php checked( $mention, 'yes', true ) ?>/><label for="notification-activity-new-mention-yes" class="bp-screen-reader-text"><?php 322 /* translators: accessibility text */ 323 _e( 'Yes, send email', 'buddypress' ); 324 ?></label></td> 325 <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-no" value="no" <?php checked( $mention, 'no', true ) ?>/><label for="notification-activity-new-mention-no" class="bp-screen-reader-text"><?php 326 /* translators: accessibility text */ 327 _e( 'No, do not send email', 'buddypress' ); 328 ?></label></td> 329 </tr> 330 <?php endif; ?> 331 332 <tr id="activity-notification-settings-replies"> 333 <td> </td> 334 <td><?php _e( "A member replies to an update or comment you've posted", 'buddypress' ) ?></td> 335 <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-yes" value="yes" <?php checked( $reply, 'yes', true ) ?>/><label for="notification-activity-new-reply-yes" class="bp-screen-reader-text"><?php 336 /* translators: accessibility text */ 337 _e( 'Yes, send email', 'buddypress' ); 338 ?></label></td> 339 <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-no" value="no" <?php checked( $reply, 'no', true ) ?>/><label for="notification-activity-new-reply-no" class="bp-screen-reader-text"><?php 340 /* translators: accessibility text */ 341 _e( 'No, do not send email', 'buddypress' ); 342 ?></label></td> 343 </tr> 344 345 <?php 346 347 /** 348 * Fires inside the closing </tbody> tag for activity screen notification settings. 349 * 350 * @since 1.2.0 351 */ 352 do_action( 'bp_activity_screen_notification_settings' ) ?> 353 </tbody> 354 </table> 355 356 <?php 221 $action = new BP_Activity_Screen_User_Settings_Notifications(); 222 $action->init(); 357 223 } 358 224 add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 ); 359 225 -
new file src/bp-activity/classes/class-bp-activity-action-delete.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Delete specific activity item and redirect to previous page. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_delete_activity() 18 */ 19 class BP_Activity_Action_Delete { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 * 25 * @param int $activity_id The activity ID. 26 * @return bool|void False on failure, nothing on success. 27 */ 28 public function init( $activity_id = 0 ) { 29 // Check the nonce. 30 check_admin_referer( 'bp_activity_delete_link' ); 31 32 // Load up the activity item. 33 $activity = new BP_Activity_Activity( $activity_id ); 34 35 // Check access. 36 if ( ! bp_activity_user_can_delete( $activity ) ) { 37 return false; 38 } 39 40 /** 41 * Fires before the deletion so plugins can still fetch information about it. 42 * 43 * @since 1.5.0 44 * 45 * @param int $activity_id The activity ID. 46 * @param int $user_id The user associated with the activity. 47 */ 48 do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id ); 49 50 // Delete the activity item and provide user feedback. 51 if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) ) { 52 bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) ); 53 } else { 54 bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' ); 55 } 56 57 /** 58 * Fires after the deletion so plugins can act afterwards based on the activity. 59 * 60 * @since 1.1.0 61 * 62 * @param int $activity_id The activity ID. 63 * @param int $user_id The user associated with the activity. 64 */ 65 do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id ); 66 67 // Check for the redirect query arg, otherwise let WP handle things. 68 if ( ! empty( $_GET['redirect_to'] ) ) { 69 bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); 70 } else { 71 bp_core_redirect( wp_get_referer() ); 72 } 73 } 74 } 75 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-favorite.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Mark activity as favorite. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_mark_favorite() 18 */ 19 class BP_Activity_Action_Favorite { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Check the nonce. 27 check_admin_referer( 'mark_favorite' ); 28 29 if ( bp_activity_add_user_favorite( bp_action_variable( 0 ) ) ) { 30 bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) ); 31 } else { 32 bp_core_add_message( __( 'There was an error marking that activity as a favorite. Please try again.', 'buddypress' ), 'error' ); 33 } 34 35 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) ); 36 } 37 } 38 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-feed-favorites.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * User's favorites RSS feed loader. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_favorites_feed() 18 */ 19 class BP_Activity_Action_Feed_Favorites { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Get displayed user's favorite activity IDs. 27 $favs = bp_activity_get_user_favorites( bp_displayed_user_id() ); 28 $fav_ids = implode( ',', (array) $favs ); 29 30 // Setup the feed. 31 buddypress()->activity->feed = new BP_Activity_Feed( array( 32 'id' => 'favorites', 33 34 /* translators: User activity favorites RSS title - "[Site Name] | [User Display Name] | Favorites" */ 35 'title' => sprintf( __( '%1$s | %2$s | Favorites', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 36 37 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/', 38 'description' => sprintf( __( "Activity feed of %s's favorites.", 'buddypress' ), bp_get_displayed_user_fullname() ), 39 'activity_args' => 'include=' . $fav_ids 40 ) ); 41 } 42 } 43 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-feed-friends.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * User's friend RSS feed loader. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_friends_feed() 18 */ 19 class BP_Activity_Action_Feed_Friends { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Setup the feed. 27 buddypress()->activity->feed = new BP_Activity_Feed( array( 28 'id' => 'friends', 29 30 /* translators: Friends activity RSS title - "[Site Name] | [User Display Name] | Friends Activity" */ 31 'title' => sprintf( __( '%1$s | %2$s | Friends Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 32 33 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() ), 34 'description' => sprintf( __( "Activity feed for %s's friends.", 'buddypress' ), bp_get_displayed_user_fullname() ), 35 'activity_args' => 'scope=friends' 36 ) ); 37 } 38 } 39 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-feed-groups.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * User's public group RSS feed loader. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_groups_feed() 18 */ 19 class BP_Activity_Action_Feed_Groups { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Get displayed user's group IDs. 27 $groups = groups_get_user_groups(); 28 $group_ids = implode( ',', $groups['groups'] ); 29 30 // Setup the feed. 31 buddypress()->activity->feed = new BP_Activity_Feed( array( 32 'id' => 'mygroups', 33 34 /* translators: Member groups activity RSS title - "[Site Name] | [User Display Name] | Groups Activity" */ 35 'title' => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 36 37 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() ), 38 'description' => sprintf( __( "Public group activity feed of which %s is a member.", 'buddypress' ), bp_get_displayed_user_fullname() ), 39 'activity_args' => array( 40 'object' => buddypress()->groups->id, 41 'primary_id' => $group_ids, 42 'display_comments' => 'threaded' 43 ) 44 ) ); 45 } 46 } 47 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-feed-mentions.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * User's mentions RSS feed loader. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_mentions_feed() 18 */ 19 class BP_Activity_Action_Feed_Mentions { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Setup the feed. 27 buddypress()->activity->feed = new BP_Activity_Feed( array( 28 'id' => 'mentions', 29 30 /* translators: User mentions activity RSS title - "[Site Name] | [User Display Name] | Mentions" */ 31 'title' => sprintf( __( '%1$s | %2$s | Mentions', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 32 33 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/', 34 'description' => sprintf( __( "Activity feed mentioning %s.", 'buddypress' ), bp_get_displayed_user_fullname() ), 35 'activity_args' => array( 36 'search_terms' => '@' . bp_core_get_username( bp_displayed_user_id() ) 37 ) 38 ) ); 39 } 40 } 41 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-feed-personal.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * User's personal RSS feed loader. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_personal_feed() 18 */ 19 class BP_Activity_Action_Feed_Personal { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Setup the feed. 27 buddypress()->activity->feed = new BP_Activity_Feed( array( 28 'id' => 'personal', 29 30 /* translators: Personal activity RSS title - "[Site Name] | [User Display Name] | Activity" */ 31 'title' => sprintf( __( '%1$s | %2$s | Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 32 33 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() ), 34 'description' => sprintf( __( 'Activity feed for %s.', 'buddypress' ), bp_get_displayed_user_fullname() ), 35 'activity_args' => 'user_id=' . bp_displayed_user_id() 36 ) ); 37 } 38 } 39 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-feed-sitewide.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Sitewide RSS feed loader. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_sitewide_feed() 18 */ 19 class BP_Activity_Action_Feed_Sitewide { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Setup the feed. 27 buddypress()->activity->feed = new BP_Activity_Feed( array( 28 'id' => 'sitewide', 29 30 /* translators: Sitewide activity RSS title - "[Site Name] | Site Wide Activity" */ 31 'title' => sprintf( __( '%s | Site-Wide Activity', 'buddypress' ), bp_get_site_name() ), 32 33 'link' => bp_get_activity_directory_permalink(), 34 'description' => __( 'Activity feed for the entire site.', 'buddypress' ), 35 'activity_args' => 'display_comments=threaded' 36 ) ); 37 } 38 } 39 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-permalink-router.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Catch and route requests for single activity item permalinks. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_permalink_router() 18 */ 19 class BP_Activity_Action_Permalink_Router { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Get the activity details. 27 $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) ); 28 29 // 404 if activity does not exist 30 if ( empty( $activity['activities'][0] ) ) { 31 bp_do_404(); 32 return; 33 } else { 34 $activity = $activity['activities'][0]; 35 } 36 37 // Do not redirect at default. 38 $redirect = false; 39 40 // Redirect based on the type of activity. 41 if ( bp_is_active( 'groups' ) && $activity->component == buddypress()->groups->id ) { 42 43 // Activity is a user update. 44 if ( ! empty( $activity->user_id ) ) { 45 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 46 47 // Activity is something else. 48 } else { 49 // Set redirect to group activity stream. 50 if ( $group = groups_get_group( $activity->item_id ) ) { 51 $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 52 } 53 } 54 55 // Set redirect to users' activity stream. 56 } elseif ( ! empty( $activity->user_id ) ) { 57 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 58 } 59 60 // If set, add the original query string back onto the redirect URL. 61 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { 62 $query_frags = array(); 63 wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags ); 64 $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect ); 65 } 66 67 /** 68 * Filter the intended redirect url before the redirect occurs for the single activity item. 69 * 70 * @since 1.2.2 71 * 72 * @param array $value Array with url to redirect to and activity related to the redirect. 73 */ 74 if ( ! $redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) ) { 75 bp_core_redirect( bp_get_root_domain() ); 76 } 77 78 // Redirect to the actual activity permalink page. 79 bp_core_redirect( $redirect ); 80 } 81 } 82 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-post-comment.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Post user/group activity update. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_post_comment() 18 */ 19 class BP_Activity_Action_Post_Comment { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Check the nonce. 27 check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' ); 28 29 /** 30 * Filters the activity ID a comment will be in reply to. 31 * 32 * @since 1.2.0 33 * 34 * @param string $value ID of the activity being replied to. 35 */ 36 $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] ); 37 38 /** 39 * Filters the comment content for a comment reply. 40 * 41 * @since 1.2.0 42 * 43 * @param string $value Comment content being posted. 44 */ 45 $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] ); 46 47 if ( empty( $content ) ) { 48 bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' ); 49 bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id ); 50 } 51 52 $comment_id = bp_activity_new_comment( array( 53 'content' => $content, 54 'activity_id' => $activity_id, 55 'parent_id' => false 56 ) ); 57 58 if ( ! empty( $comment_id ) ) { 59 bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) ); 60 } else { 61 bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' ); 62 } 63 64 bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id ); 65 } 66 } 67 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-post-update.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Post user/group activity update. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_post_update() 18 */ 19 class BP_Activity_Action_Post_Update { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Check the nonce. 27 check_admin_referer( 'post_update', '_wpnonce_post_update' ); 28 29 /** 30 * Filters the content provided in the activity input field. 31 * 32 * @since 1.2.0 33 * 34 * @param string $value Activity message being posted. 35 */ 36 $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] ); 37 38 if ( ! empty( $_POST['whats-new-post-object'] ) ) { 39 40 /** 41 * Filters the item type that the activity update should be associated with. 42 * 43 * @since 1.2.0 44 * 45 * @param string $value Item type to associate with. 46 */ 47 $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] ); 48 } 49 50 if ( ! empty( $_POST['whats-new-post-in'] ) ) { 51 52 /** 53 * Filters what component the activity is being to. 54 * 55 * @since 1.2.0 56 * 57 * @param string $value Chosen component to post activity to. 58 */ 59 $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] ); 60 } 61 62 // No activity content so provide feedback and redirect. 63 if ( empty( $content ) ) { 64 bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' ); 65 bp_core_redirect( wp_get_referer() ); 66 } 67 68 // No existing item_id. 69 if ( empty( $item_id ) ) { 70 $activity_id = bp_activity_post_update( array( 'content' => $content ) ); 71 72 // Post to groups object. 73 } elseif ( 'groups' == $object && bp_is_active( 'groups' ) ) { 74 if ( (int) $item_id ) { 75 $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) ); 76 } 77 78 } else { 79 80 /** 81 * Filters activity object for BuddyPress core and plugin authors before posting activity update. 82 * 83 * @since 1.2.0 84 * 85 * @param string $object Activity item being associated to. 86 * @param string $item_id Component ID being posted to. 87 * @param string $content Activity content being posted. 88 */ 89 $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content ); 90 } 91 92 // Provide user feedback. 93 if ( ! empty( $activity_id ) ) { 94 bp_core_add_message( __( 'Update Posted!', 'buddypress' ) ); 95 } else { 96 bp_core_add_message( __( 'There was an error when posting your update. Please try again.', 'buddypress' ), 'error' ); 97 } 98 99 // Redirect. 100 bp_core_redirect( wp_get_referer() ); 101 } 102 } 103 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-spam.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Mark specific activity item as spam and redirect to previous page. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_spam_activity() 18 */ 19 class BP_Activity_Action_Spam { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 * 25 * @param int $activity_id The activity ID. 26 * @return bool|void False on failure, void on success. 27 */ 28 public function init( $activity_id = 0 ) { 29 // Is the current user allowed to spam items? 30 if ( ! bp_activity_user_can_mark_spam() ) { 31 return false; 32 } 33 34 // Load up the activity item. 35 $activity = new BP_Activity_Activity( $activity_id ); 36 if ( empty( $activity->id ) ) { 37 return false; 38 } 39 40 // Check nonce. 41 check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id ); 42 43 /** 44 * Fires before the marking activity as spam so plugins can modify things if they want to. 45 * 46 * @since 1.6.0 47 * 48 * @param int $activity_id Activity ID to be marked as spam. 49 * @param object $activity Activity object for the ID to be marked as spam. 50 */ 51 do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity ); 52 53 // Mark as spam. 54 bp_activity_mark_as_spam( $activity ); 55 $activity->save(); 56 57 // Tell the user the spamming has been successful. 58 bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) ); 59 60 /** 61 * Fires after the marking activity as spam so plugins can act afterwards based on the activity. 62 * 63 * @since 1.6.0 64 * 65 * @param int $activity_id Activity ID that was marked as spam. 66 * @param int $user_id User ID associated with activity. 67 */ 68 do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id ); 69 70 // Check for the redirect query arg, otherwise let WP handle things. 71 if ( ! empty( $_GET['redirect_to'] ) ) { 72 bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); 73 } else { 74 bp_core_redirect( wp_get_referer() ); 75 } 76 } 77 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-action-unfavorite.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Unfavorite activity items. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_action_remove_favorite() 18 */ 19 class BP_Activity_Action_Unfavorite { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Check the nonce. 27 check_admin_referer( 'unmark_favorite' ); 28 29 if ( bp_activity_remove_user_favorite( bp_action_variable( 0 ) ) ) { 30 bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) ); 31 } else { 32 bp_core_add_message( __( 'There was an error removing that activity as a favorite. Please try again.', 'buddypress' ), 'error' ); 33 } 34 35 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) ); 36 } 37 } 38 No newline at end of file -
src/bp-activity/classes/class-bp-activity-component.php
85 85 parent::includes( $includes ); 86 86 } 87 87 88 /** 89 * Late includes. 90 * 91 * @since 3.0.0 92 */ 93 public function late_includes() { 94 // RSS feeds. 95 if ( bp_is_current_action( 'feed' ) || bp_is_action_variable( 'feed', 0 ) ) { 96 require $this->path . 'bp-activity/bp-activity-feeds.php'; 97 } 98 } 99 88 100 /** 89 101 * Set up component global variables. 90 102 * -
new file src/bp-activity/classes/class-bp-activity-screen-permalink.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Screen handler for activity permalinks. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_screen_single_activity_permalink() 18 */ 19 class BP_Activity_Screen_Permalink { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 // Get the activity details. 27 $activity = bp_activity_get_specific( array( 28 'activity_ids' => bp_current_action(), 29 'show_hidden' => true, 30 'spam' => 'ham_only', 31 ) ); 32 33 // 404 if activity does not exist 34 if ( empty( $activity['activities'][0] ) || bp_action_variables() ) { 35 bp_do_404(); 36 return; 37 38 } else { 39 $activity = $activity['activities'][0]; 40 } 41 42 $user_id = bp_displayed_user_id(); 43 44 /** 45 * Check user access to the activity item. 46 * 47 * @since 3.0.0 48 */ 49 $has_access = bp_activity_user_can_read( $activity, $user_id ); 50 51 // If activity author does not match displayed user, block access. 52 // More info:https://buddypress.trac.wordpress.org/ticket/7048#comment:28 53 if ( true === $has_access && $user_id !== $activity->user_id ) { 54 $has_access = false; 55 } 56 57 /** 58 * Fires before the loading of a single activity template file. 59 * 60 * @since 1.2.0 61 * 62 * @param BP_Activity_Activity $activity Object representing the current activity item being displayed. 63 * @param bool $has_access Whether or not the current user has access to view activity. 64 */ 65 do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access ); 66 67 // Access is specifically disallowed. 68 if ( false === $has_access ) { 69 // User feedback. 70 bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' ); 71 72 // Redirect based on logged in status. 73 if ( is_user_logged_in() ) { 74 $url = bp_loggedin_user_domain(); 75 76 } else { 77 $url = sprintf( 78 wp_login_url( 'wp-login.php?redirect_to=%s' ), 79 esc_url_raw( bp_activity_get_permalink( $action ) ) 80 ); 81 } 82 83 bp_core_redirect( $url ); 84 } 85 86 /** 87 * Filters the template to load for a single activity screen. 88 * 89 * @since 1.0.0 90 * 91 * @param string $template Path to the activity template to load. 92 */ 93 $template = apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ); 94 95 // Load the template. 96 bp_core_load_template( $template ); 97 } 98 } 99 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-screen-user-settings-notifications.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Render the Activity settings fields on the "Settings > Notifications" page. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_screen_notification_settings() 18 */ 19 class BP_Activity_Screen_User_Settings_Notifications { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 */ 25 public function init() { 26 if ( bp_activity_do_mentions() ) { 27 if ( ! $mention = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_mention', true ) ) { 28 $mention = 'yes'; 29 } 30 } 31 32 if ( ! $reply = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_reply', true ) ) { 33 $reply = 'yes'; 34 } 35 ?> 36 37 <table class="notification-settings" id="activity-notification-settings"> 38 <thead> 39 <tr> 40 <th class="icon"> </th> 41 <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th> 42 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 43 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 44 </tr> 45 </thead> 46 47 <tbody> 48 <?php if ( bp_activity_do_mentions() ) : ?> 49 <tr id="activity-notification-settings-mentions"> 50 <td> </td> 51 <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) ?></td> 52 <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-yes" value="yes" <?php checked( $mention, 'yes', true ) ?>/><label for="notification-activity-new-mention-yes" class="bp-screen-reader-text"><?php 53 /* translators: accessibility text */ 54 _e( 'Yes, send email', 'buddypress' ); 55 ?></label></td> 56 <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-no" value="no" <?php checked( $mention, 'no', true ) ?>/><label for="notification-activity-new-mention-no" class="bp-screen-reader-text"><?php 57 /* translators: accessibility text */ 58 _e( 'No, do not send email', 'buddypress' ); 59 ?></label></td> 60 </tr> 61 <?php endif; ?> 62 63 <tr id="activity-notification-settings-replies"> 64 <td> </td> 65 <td><?php _e( "A member replies to an update or comment you've posted", 'buddypress' ) ?></td> 66 <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-yes" value="yes" <?php checked( $reply, 'yes', true ) ?>/><label for="notification-activity-new-reply-yes" class="bp-screen-reader-text"><?php 67 /* translators: accessibility text */ 68 _e( 'Yes, send email', 'buddypress' ); 69 ?></label></td> 70 <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-no" value="no" <?php checked( $reply, 'no', true ) ?>/><label for="notification-activity-new-reply-no" class="bp-screen-reader-text"><?php 71 /* translators: accessibility text */ 72 _e( 'No, do not send email', 'buddypress' ); 73 ?></label></td> 74 </tr> 75 76 <?php 77 78 /** 79 * Fires inside the closing </tbody> tag for activity screen notification settings. 80 * 81 * @since 1.2.0 82 */ 83 do_action( 'bp_activity_screen_notification_settings' ) ?> 84 </tbody> 85 </table> 86 87 <?php 88 } 89 } 90 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-transition-comment-status.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Comment status handler for BuddyPress activity items. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_transition_post_type_comment_status() 18 */ 19 class BP_Activity_Transition_Comment_Status { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 * 25 * @param WP_Comment $comment Comment data. 26 * @param string $new_status New comment status. 27 * @param string $old_status Previous comment status. 28 */ 29 public function init( $comment, $new_status, $old_status ) { 30 $post_type = get_post_type( $comment->comment_post_ID ); 31 if ( ! $post_type ) { 32 return; 33 } 34 35 // Get the post type tracking args. 36 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 37 38 // Bail if the activity type does not exist 39 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 40 return false; 41 42 // Set the $activity_comment_object 43 } else { 44 $activity_comment_object = $activity_post_object->comments_tracking; 45 } 46 47 // Init an empty activity ID 48 $activity_id = 0; 49 50 /** 51 * Activity currently doesn't have any concept of a trash, or an unapproved/approved state. 52 * 53 * If a blog comment transitions to a "delete" or "hold" status, delete the activity item. 54 * If a blog comment transitions to trashed, or spammed, mark the activity as spam. 55 * If a blog comment transitions to approved (and the activity exists), mark the activity as ham. 56 * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam. 57 * Otherwise, record the comment into the activity stream. 58 */ 59 60 // This clause handles delete/hold. 61 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) { 62 return bp_activity_post_type_remove_comment( $comment->comment_ID, $activity_post_object ); 63 64 // These clauses handle trash, spam, and un-spams. 65 } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) { 66 $action = 'spam_activity'; 67 } elseif ( 'approved' == $new_status ) { 68 $action = 'ham_activity'; 69 } 70 71 // Get the activity 72 if ( bp_disable_blogforum_comments() ) { 73 $activity_id = bp_activity_get_activity_id( array( 74 'component' => $activity_comment_object->component_id, 75 'item_id' => get_current_blog_id(), 76 'secondary_item_id' => $comment->comment_ID, 77 'type' => $activity_comment_object->action_id, 78 ) ); 79 } else { 80 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ); 81 } 82 83 /** 84 * Leave a chance to plugins to manage activity comments differently. 85 * 86 * @since 2.5.0 87 * 88 * @param bool $value True to override BuddyPress management. 89 * @param string $post_type The post type name. 90 * @param int $activity_id The post type activity (0 if not found). 91 * @param string $new_status The new status of the post type comment. 92 * @param string $old_status The old status of the post type comment. 93 * @param WP_Comment $comment Comment data. 94 */ 95 if ( true === apply_filters( 'bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment ) ) { 96 return false; 97 } 98 99 // Check activity item exists 100 if ( empty( $activity_id ) ) { 101 // If no activity exists, but the comment has been approved, record it into the activity table. 102 if ( 'approved' == $new_status ) { 103 return bp_activity_post_type_comment( $comment->comment_ID, true, $activity_post_object ); 104 } 105 106 return; 107 } 108 109 // Create an activity object 110 $activity = new BP_Activity_Activity( $activity_id ); 111 if ( empty( $activity->component ) ) { 112 return; 113 } 114 115 // Spam/ham the activity if it's not already in that state 116 if ( 'spam_activity' === $action && ! $activity->is_spam ) { 117 bp_activity_mark_as_spam( $activity ); 118 } elseif ( 'ham_activity' == $action) { 119 bp_activity_mark_as_ham( $activity ); 120 } 121 122 // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated 123 $post_type_comment_action = $activity_comment_object->action_id; 124 $comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) { 125 $activity_types[] = $post_type_comment_action; 126 127 return $activity_types; 128 }; 129 add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 130 131 // Make sure the activity change won't edit the comment if sync is on 132 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 133 134 // Save the updated activity 135 $activity->save(); 136 137 // Restore the action 138 add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 139 140 // Remove the "new_blog_comment" activity type whitelist so we don't break anything 141 remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 142 } 143 } 144 No newline at end of file -
new file src/bp-activity/classes/class-bp-activity-transition-post-status.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Post type status handler for BuddyPress activity items. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_activity_catch_transition_post_type_status() 18 */ 19 class BP_Activity_Transition_Post_Status { 20 /** 21 * Init method. 22 * 23 * @since 3.0.0 24 * 25 * @param object $post Post data. 26 * @param string $new_status New status for the post. 27 * @param string $old_status Old status for the post. 28 */ 29 public function init( $post, $new_status, $old_status ) { 30 if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) { 31 return; 32 } 33 34 // This is an edit. 35 if ( $new_status === $old_status ) { 36 // An edit of an existing post should update the existing activity item. 37 if ( $new_status == 'publish' ) { 38 $edit = bp_activity_post_type_update( $post ); 39 40 // Post was never recorded into activity stream, so record it now! 41 if ( null === $edit ) { 42 bp_activity_post_type_publish( $post->ID, $post ); 43 } 44 45 // Allow plugins to eventually deal with other post statuses. 46 } else { 47 /** 48 * Fires when editing the post and the new status is not 'publish'. 49 * 50 * This is a variable filter that is dependent on the post type 51 * being untrashed. 52 * 53 * @since 2.5.0 54 * 55 * @param WP_Post $post Post data. 56 * @param string $new_status New status for the post. 57 * @param string $old_status Old status for the post. 58 */ 59 do_action( 'bp_activity_post_type_edit_' . $post->post_type, $post, $new_status, $old_status ); 60 } 61 62 return; 63 } 64 65 // Publishing a previously unpublished post. 66 if ( 'publish' === $new_status ) { 67 // Untrashing the post type - nothing here yet. 68 if ( 'trash' == $old_status ) { 69 70 /** 71 * Fires if untrashing post in a post type. 72 * 73 * This is a variable filter that is dependent on the post type 74 * being untrashed. 75 * 76 * @since 2.2.0 77 * 78 * @param WP_Post $post Post data. 79 */ 80 do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); 81 } else { 82 // Record the post. 83 bp_activity_post_type_publish( $post->ID, $post ); 84 } 85 86 // Unpublishing a previously published post. 87 } elseif ( 'publish' === $old_status ) { 88 // Some form of pending status - only remove the activity entry. 89 bp_activity_post_type_unpublish( $post->ID, $post ); 90 91 // For any other cases, allow plugins to eventually deal with it. 92 } else { 93 /** 94 * Fires when the old and the new post status are not 'publish'. 95 * 96 * This is a variable filter that is dependent on the post type 97 * being untrashed. 98 * 99 * @since 2.5.0 100 * 101 * @param WP_Post $post Post data. 102 * @param string $new_status New status for the post. 103 * @param string $old_status Old status for the post. 104 */ 105 do_action( 'bp_activity_post_type_transition_status_' . $post->post_type, $post, $new_status, $old_status ); 106 } 107 } 108 } 109 No newline at end of file -
src/bp-core/classes/class-bp-component.php
393 393 do_action( 'bp_' . $this->id . '_includes' ); 394 394 } 395 395 396 /** 397 * Late includes method. 398 * 399 * Components should include files here only on specific pages using 400 * conditionals such as {@link bp_is_current_component()}. Intentionally left 401 * empty. 402 * 403 * @since 2.9.0 404 */ 405 public function late_includes() {} 406 396 407 /** 397 408 * Set up the actions. 398 409 * … … 414 425 // extending this base class. 415 426 add_action( 'bp_include', array( $this, 'includes' ), 8 ); 416 427 428 // Late includes. 429 add_action( 'bp_setup_canonical_stack', array( $this, 'late_includes' ), 20 ); 430 417 431 // Setup navigation. 418 432 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 ); 419 433 -
new file src/bp-core/classes/class-bp-core-ajax-get-suggestions.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Classes 4 * 5 * @package BuddyPress 6 * @since 3.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * AJAX handler for Suggestions API lookups. 14 * 15 * @since 3.0.0 16 * 17 * @see bp_ajax_get_suggestions() 18 * @todo Add nonce check. 19 */ 20 class BP_Core_Ajax_Get_Suggestions { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) { 28 wp_send_json_error( 'missing_parameter' ); 29 exit; 30 } 31 32 $args = array( 33 'term' => sanitize_text_field( $_GET['term'] ), 34 'type' => sanitize_text_field( $_GET['type'] ), 35 ); 36 37 // Support per-Group suggestions. 38 if ( ! empty( $_GET['group-id'] ) ) { 39 $args['group_id'] = absint( $_GET['group-id'] ); 40 } 41 42 $results = bp_core_get_suggestions( $args ); 43 44 if ( is_wp_error( $results ) ) { 45 wp_send_json_error( $results->get_error_message() ); 46 exit; 47 } 48 49 wp_send_json_success( $results ); 50 } 51 } 52 No newline at end of file