Changeset 10253
- Timestamp:
- 10/12/2015 05:45:14 AM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-actions.php
r10077 r10253 9 9 */ 10 10 11 // Exit if accessed directly 11 // Exit if accessed directly. 12 12 defined( 'ABSPATH' ) || exit; 13 13 … … 51 51 function bp_activity_action_permalink_router() { 52 52 53 // Not viewing activity 53 // Not viewing activity. 54 54 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) ) 55 55 return false; 56 56 57 // No activity to display 57 // No activity to display. 58 58 if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) ) 59 59 return false; 60 60 61 // Get the activity details 61 // Get the activity details. 62 62 $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) ); 63 63 … … 70 70 } 71 71 72 // Do not redirect at default 72 // Do not redirect at default. 73 73 $redirect = false; 74 74 75 // Redirect based on the type of activity 75 // Redirect based on the type of activity. 76 76 if ( bp_is_active( 'groups' ) && $activity->component == buddypress()->groups->id ) { 77 77 78 // Activity is a user update 78 // Activity is a user update. 79 79 if ( ! empty( $activity->user_id ) ) { 80 80 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 81 81 82 // Activity is something else 82 // Activity is something else. 83 83 } else { 84 84 85 // Set redirect to group activity stream 85 // Set redirect to group activity stream. 86 86 if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) { 87 87 $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/'; … … 89 89 } 90 90 91 // Set redirect to users' activity stream 91 // Set redirect to users' activity stream. 92 92 } elseif ( ! empty( $activity->user_id ) ) { 93 93 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 94 94 } 95 95 96 // If set, add the original query string back onto the redirect URL 96 // If set, add the original query string back onto the redirect URL. 97 97 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { 98 98 $query_frags = array(); … … 112 112 } 113 113 114 // Redirect to the actual activity permalink page 114 // Redirect to the actual activity permalink page. 115 115 bp_core_redirect( $redirect ); 116 116 } … … 121 121 * 122 122 * @since 1.1.0 123 *124 * @param int $activity_id Activity id to be deleted. Defaults to 0.125 123 * 126 124 * @uses bp_is_activity_component() … … 135 133 * @uses bp_core_redirect() 136 134 * 135 * @param int $activity_id Activity id to be deleted. Defaults to 0. 137 136 * @return bool False on failure. 138 137 */ 139 138 function bp_activity_action_delete_activity( $activity_id = 0 ) { 140 139 141 // Not viewing activity or action is not delete 140 // Not viewing activity or action is not delete. 142 141 if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) ) 143 142 return false; … … 146 145 $activity_id = (int) bp_action_variable( 0 ); 147 146 148 // Not viewing a specific activity item 147 // Not viewing a specific activity item. 149 148 if ( empty( $activity_id ) ) 150 149 return false; 151 150 152 // Check the nonce 151 // Check the nonce. 153 152 check_admin_referer( 'bp_activity_delete_link' ); 154 153 155 // Load up the activity item 154 // Load up the activity item. 156 155 $activity = new BP_Activity_Activity( $activity_id ); 157 156 158 // Check access 157 // Check access. 159 158 if ( ! bp_activity_user_can_delete( $activity ) ) 160 159 return false; … … 170 169 do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id ); 171 170 172 // Delete the activity item and provide user feedback 171 // Delete the activity item and provide user feedback. 173 172 if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) ) 174 173 bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) ); … … 186 185 do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id ); 187 186 188 // Check for the redirect query arg, otherwise let WP handle things 187 // Check for the redirect query arg, otherwise let WP handle things. 189 188 if ( !empty( $_GET['redirect_to'] ) ) 190 189 bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); … … 200 199 * 201 200 * @param int $activity_id Activity id to be deleted. Defaults to 0. 202 *203 201 * @return bool False on failure. 204 202 */ … … 206 204 $bp = buddypress(); 207 205 208 // Not viewing activity, or action is not spam, or Akismet isn't present 206 // Not viewing activity, or action is not spam, or Akismet isn't present. 209 207 if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) ) 210 208 return false; … … 213 211 $activity_id = (int) bp_action_variable( 0 ); 214 212 215 // Not viewing a specific activity item 213 // Not viewing a specific activity item. 216 214 if ( empty( $activity_id ) ) 217 215 return false; … … 221 219 return false; 222 220 223 // Load up the activity item 221 // Load up the activity item. 224 222 $activity = new BP_Activity_Activity( $activity_id ); 225 223 if ( empty( $activity->id ) ) 226 224 return false; 227 225 228 // Check nonce 226 // Check nonce. 229 227 check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id ); 230 228 … … 239 237 do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity ); 240 238 241 // Mark as spam 239 // Mark as spam. 242 240 bp_activity_mark_as_spam( $activity ); 243 241 $activity->save(); 244 242 245 // Tell the user the spamming has been successful 243 // Tell the user the spamming has been successful. 246 244 bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) ); 247 245 … … 256 254 do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id ); 257 255 258 // Check for the redirect query arg, otherwise let WP handle things 256 // Check for the redirect query arg, otherwise let WP handle things. 259 257 if ( !empty( $_GET['redirect_to'] ) ) 260 258 bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); … … 287 285 function bp_activity_action_post_update() { 288 286 289 // Do not proceed if user is not logged in, not viewing activity, or not posting 287 // Do not proceed if user is not logged in, not viewing activity, or not posting. 290 288 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) ) 291 289 return false; 292 290 293 // Check the nonce 291 // Check the nonce. 294 292 check_admin_referer( 'post_update', '_wpnonce_post_update' ); 295 293 … … 327 325 } 328 326 329 // No activity content so provide feedback and redirect 327 // No activity content so provide feedback and redirect. 330 328 if ( empty( $content ) ) { 331 329 bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' ); … … 333 331 } 334 332 335 // No existing item_id 333 // No existing item_id. 336 334 if ( empty( $item_id ) ) { 337 335 $activity_id = bp_activity_post_update( array( 'content' => $content ) ); 338 336 339 // Post to groups object 337 // Post to groups object. 340 338 } elseif ( 'groups' == $object && bp_is_active( 'groups' ) ) { 341 339 if ( (int) $item_id ) { … … 357 355 } 358 356 359 // Provide user feedback 357 // Provide user feedback. 360 358 if ( !empty( $activity_id ) ) 361 359 bp_core_add_message( __( 'Update Posted!', 'buddypress' ) ); … … 363 361 bp_core_add_message( __( 'There was an error when posting your update. Please try again.', 'buddypress' ), 'error' ); 364 362 365 // Redirect 363 // Redirect. 366 364 bp_core_redirect( wp_get_referer() ); 367 365 } … … 391 389 return false; 392 390 393 // Check the nonce 391 // Check the nonce. 394 392 check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' ); 395 393 … … 454 452 return false; 455 453 456 // Check the nonce 454 // Check the nonce. 457 455 check_admin_referer( 'mark_favorite' ); 458 456 … … 488 486 return false; 489 487 490 // Check the nonce 488 // Check the nonce. 491 489 check_admin_referer( 'unmark_favorite' ); 492 490 … … 518 516 return false; 519 517 520 // setup the feed518 // Setup the feed. 521 519 buddypress()->activity->feed = new BP_Activity_Feed( array( 522 520 'id' => 'sitewide', … … 548 546 } 549 547 550 // setup the feed548 // Setup the feed. 551 549 buddypress()->activity->feed = new BP_Activity_Feed( array( 552 550 'id' => 'personal', … … 581 579 } 582 580 583 // setup the feed581 // Setup the feed. 584 582 buddypress()->activity->feed = new BP_Activity_Feed( array( 585 583 'id' => 'friends', … … 614 612 } 615 613 616 // get displayed user's group IDs614 // Get displayed user's group IDs. 617 615 $groups = groups_get_user_groups(); 618 616 $group_ids = implode( ',', $groups['groups'] ); 619 617 620 // setup the feed618 // Setup the feed. 621 619 buddypress()->activity->feed = new BP_Activity_Feed( array( 622 620 'id' => 'mygroups', … … 657 655 } 658 656 659 // setup the feed657 // Setup the feed. 660 658 buddypress()->activity->feed = new BP_Activity_Feed( array( 661 659 'id' => 'mentions', … … 690 688 } 691 689 692 // get displayed user's favorite activity IDs690 // Get displayed user's favorite activity IDs. 693 691 $favs = bp_activity_get_user_favorites( bp_displayed_user_id() ); 694 692 $fav_ids = implode( ',', (array) $favs ); 695 693 696 // setup the feed694 // Setup the feed. 697 695 buddypress()->activity->feed = new BP_Activity_Feed( array( 698 696 'id' => 'favorites', … … 717 715 $bp = buddypress(); 718 716 719 // Bail if Akismet is not active 717 // Bail if Akismet is not active. 720 718 if ( ! defined( 'AKISMET_VERSION' ) ) { 721 719 return; 722 720 } 723 721 724 // Bail if older version of Akismet 722 // Bail if older version of Akismet. 725 723 if ( ! class_exists( 'Akismet' ) ) { 726 724 return; 727 725 } 728 726 729 // Bail if no Akismet key is set 727 // Bail if no Akismet key is set. 730 728 if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) ) { 731 729 return; … … 743 741 } 744 742 745 // Instantiate Akismet for BuddyPress 743 // Instantiate Akismet for BuddyPress. 746 744 $bp->activity->akismet = new BP_Akismet(); 747 745 } … … 828 826 // Unpublishing a previously published post. 829 827 } elseif ( 'publish' === $old_status ) { 830 // Some form of pending status - only remove the activity entry 828 // Some form of pending status - only remove the activity entry. 831 829 bp_activity_post_type_unpublish( $post->ID, $post ); 832 830 } -
trunk/src/bp-activity/bp-activity-admin.php
r10248 r10253 6 6 * help text, on which this implementation is heavily based. 7 7 * 8 * @since 1.6.09 8 * @package BuddyPress 10 9 * @subpackage ActivityAdmin 10 * @since 1.6.0 11 11 */ 12 12 13 // Exit if accessed directly 13 // Exit if accessed directly. 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 // Include WP's list table class 16 // Include WP's list table class. 17 17 if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); 18 18 19 // per_page screen option. Has to be hooked in extremely early.19 // Per_page screen option. Has to be hooked in extremely early. 20 20 if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] ) 21 21 add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 ); … … 28 28 function bp_activity_add_admin_menu() { 29 29 30 // Add our screen 30 // Add our screen. 31 31 $hook = add_menu_page( 32 32 _x( 'Activity', 'Admin Dashbord SWA page title', 'buddypress' ), … … 53 53 * 54 54 * @param array $custom_menus The list of top-level BP menu items. 55 *56 55 * @return array $custom_menus List of top-level BP menu items, with Activity added. 57 56 */ … … 71 70 */ 72 71 function bp_activity_admin_reply() { 73 // Check nonce 72 // Check nonce. 74 73 check_ajax_referer( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply' ); 75 74 … … 81 80 die( '-1' ); 82 81 83 // If $root_id not set (e.g. for root items), use $parent_id 82 // If $root_id not set (e.g. for root items), use $parent_id. 84 83 if ( empty( $root_id ) ) 85 84 $root_id = $parent_id; 86 85 87 // Check that a reply has been entered 86 // Check that a reply has been entered. 88 87 if ( empty( $_REQUEST['content'] ) ) 89 88 die( __( 'ERROR: Please type a reply.', 'buddypress' ) ); 90 89 91 // Check parent activity exists 90 // Check parent activity exists. 92 91 $parent_activity = new BP_Activity_Activity( $parent_id ); 93 92 if ( empty( $parent_activity->component ) ) … … 99 98 die( '-1' ); 100 99 101 // Add new activity comment 100 // Add new activity comment. 102 101 $new_activity_id = bp_activity_new_comment( array( 103 'activity_id' => $root_id, // ID of the root activity item 102 'activity_id' => $root_id, // ID of the root activity item. 104 103 'content' => $_REQUEST['content'], 105 'parent_id' => $parent_id, // ID of a parent comment 104 'parent_id' => $parent_id, // ID of a parent comment. 106 105 ) ); 107 106 108 // Fetch the new activity item, as we need it to create table markup to return 107 // Fetch the new activity item, as we need it to create table markup to return. 109 108 $new_activity = new BP_Activity_Activity( $new_activity_id ); 110 109 111 // This needs to be set for the BP_Activity_List_Table constructor to work 110 // This needs to be set for the BP_Activity_List_Table constructor to work. 112 111 set_current_screen( 'toplevel_page_bp-activity' ); 113 112 114 // Set up an output buffer 113 // Set up an output buffer. 115 114 ob_start(); 116 115 $list_table = new BP_Activity_List_Table(); 117 116 $list_table->single_row( (array) $new_activity ); 118 117 119 // Get table markup 118 // Get table markup. 120 119 $response = array( 121 120 'data' => ob_get_contents(), … … 126 125 ob_end_clean(); 127 126 128 // Send response 127 // Send response. 129 128 $r = new WP_Ajax_Response(); 130 129 $r->add( $response ); … … 143 142 * @param string $option Screen option name. 144 143 * @param string $new_value Screen option form value. 145 *146 144 * @return string Option value. False to abandon update. 147 145 */ … … 150 148 return $value; 151 149 152 // Per page 150 // Per page. 153 151 $new_value = (int) $new_value; 154 152 if ( $new_value < 1 || $new_value > 999 ) … … 165 163 * @param array $hidden Array of items to hide. 166 164 * @param WP_Screen $screen Screen identifier. 167 *168 165 * @return array Hidden Meta Boxes. 169 166 */ … … 172 169 return $hidden; 173 170 174 // Hide the primary link meta box by default 171 // Hide the primary link meta box by default. 175 172 $hidden = array_merge( (array) $hidden, array( 'bp_activity_itemids', 'bp_activity_link', 'bp_activity_type', 'bp_activity_userid', ) ); 176 173 … … 205 202 $bp = buddypress(); 206 203 207 // Decide whether to load the dev version of the CSS and JavaScript 204 // Decide whether to load the dev version of the CSS and JavaScript. 208 205 $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : 'min.'; 209 206 … … 219 216 do_action( 'bp_activity_admin_load', $doaction ); 220 217 221 // Edit screen 218 // Edit screen. 222 219 if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) { 223 // columns screen option220 // Columns screen option. 224 221 add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) ); 225 222 … … 243 240 ) ); 244 241 245 // Help panel - sidebar links 242 // Help panel - sidebar links. 246 243 get_current_screen()->set_help_sidebar( 247 244 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . … … 264 261 do_action( 'bp_activity_admin_meta_boxes' ); 265 262 266 // Enqueue JavaScript files 263 // Enqueue JavaScript files. 267 264 wp_enqueue_script( 'postbox' ); 268 265 wp_enqueue_script( 'dashboard' ); 269 266 wp_enqueue_script( 'comment' ); 270 267 271 // Index screen 268 // Index screen. 272 269 } else { 273 // Create the Activity screen list table 270 // Create the Activity screen list table. 274 271 $bp_activity_list_table = new BP_Activity_List_Table(); 275 272 276 // per_page screen option273 // The per_page screen option. 277 274 add_screen_option( 'per_page', array( 'label' => _x( 'Activity', 'Activity items per page (screen options)', 'buddypress' )) ); 278 275 279 // Help panel - overview text 276 // Help panel - overview text. 280 277 get_current_screen()->add_help_tab( array( 281 278 'id' => 'bp-activity-overview', … … 286 283 ) ); 287 284 288 // Help panel - moderation text 285 // Help panel - moderation text. 289 286 get_current_screen()->add_help_tab( array( 290 287 'id' => 'bp-activity-moderating', … … 295 292 ) ); 296 293 297 // Help panel - sidebar links 294 // Help panel - sidebar links. 298 295 get_current_screen()->set_help_sidebar( 299 296 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . … … 302 299 } 303 300 304 // Enqueue CSS and JavaScript 301 // Enqueue CSS and JavaScript. 305 302 wp_enqueue_script( 'bp_activity_admin_js', $bp->plugin_url . "bp-activity/admin/js/admin.{$min}js", array( 'jquery', 'wp-ajax-response' ), bp_get_version(), true ); 306 303 wp_localize_script( 'bp_activity_admin_js', 'bp_activity_admin_vars', array( … … 321 318 do_action( 'bp_activity_admin_enqueue_scripts' ); 322 319 323 // Handle spam/un-spam/delete of activities 320 // Handle spam/un-spam/delete of activities. 324 321 if ( !empty( $doaction ) && ! in_array( $doaction, array( '-1', 'edit', 'save', ) ) ) { 325 322 326 // Build redirection URL 323 // Build redirection URL. 327 324 $redirect_to = remove_query_arg( array( 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), wp_get_referer() ); 328 325 $redirect_to = add_query_arg( 'paged', $bp_activity_list_table->get_pagenum(), $redirect_to ); 329 326 330 // Get activity IDs 327 // Get activity IDs. 331 328 $activity_ids = array_map( 'absint', (array) $_REQUEST['aid'] ); 332 329 … … 342 339 // Is this a bulk request? 343 340 if ( 'bulk_' == substr( $doaction, 0, 5 ) && ! empty( $_REQUEST['aid'] ) ) { 344 // Check this is a valid form submission 341 // Check this is a valid form submission. 345 342 check_admin_referer( 'bulk-activities' ); 346 343 347 // Trim 'bulk_' off the action name to avoid duplicating a ton of code 344 // Trim 'bulk_' off the action name to avoid duplicating a ton of code. 348 345 $doaction = substr( $doaction, 5 ); 349 346 … … 351 348 } elseif ( !empty( $_REQUEST['aid'] ) ) { 352 349 353 // Check this is a valid form submission 350 // Check this is a valid form submission. 354 351 check_admin_referer( 'spam-activity_' . $activity_ids[0] ); 355 352 } 356 353 357 // Initialise counters for how many of each type of item we perform an action on 354 // Initialise counters for how many of each type of item we perform an action on. 358 355 $deleted = $spammed = $unspammed = 0; 359 356 360 // Store any errors that occurs when updating the database items 357 // Store any errors that occurs when updating the database items. 361 358 $errors = array(); 362 359 … … 365 362 // @todo: Check the permissions on each 366 363 //if ( ! current_user_can( 'bp_edit_activity', $activity_id ) ) 367 // 368 369 // Get the activity from the database 364 // continue; 365 366 // Get the activity from the database. 370 367 $activity = new BP_Activity_Activity( $activity_id ); 371 368 if ( empty( $activity->component ) ) { … … 395 392 $result = $activity->save(); 396 393 397 // Check for any error during activity save 394 // Check for any error during activity save. 398 395 if ( ! $result ) 399 396 $errors[] = $activity->id; … … 406 403 $result = $activity->save(); 407 404 408 // Check for any error during activity save 405 // Check for any error during activity save. 409 406 if ( ! $result ) 410 407 $errors[] = $activity->id; … … 417 414 } 418 415 419 // Release memory 416 // Release memory. 420 417 unset( $activity ); 421 418 } … … 444 441 $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to ); 445 442 446 // If an error occurred, pass back the activity ID that failed 443 // If an error occurred, pass back the activity ID that failed. 447 444 if ( ! empty( $errors ) ) 448 445 $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to ); … … 459 456 460 457 461 // Save the edit 458 // Save the edit. 462 459 } elseif ( $doaction && 'save' == $doaction ) { 463 // Build redirection URL 460 // Build redirection URL. 464 461 $redirect_to = remove_query_arg( array( 'action', 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] ); 465 462 466 // Get activity ID 463 // Get activity ID. 467 464 $activity_id = (int) $_REQUEST['aid']; 468 465 469 // Check this is a valid form submission 466 // Check this is a valid form submission. 470 467 check_admin_referer( 'edit-activity_' . $activity_id ); 471 468 472 // Get the activity from the database 469 // Get the activity from the database. 473 470 $activity = new BP_Activity_Activity( $activity_id ); 474 471 475 // If the activity doesn't exist, just redirect back to the index 472 // If the activity doesn't exist, just redirect back to the index. 476 473 if ( empty( $activity->component ) ) { 477 474 wp_redirect( $redirect_to ); … … 479 476 } 480 477 481 // Check the form for the updated properties 482 483 // Store any error that occurs when updating the database item 478 // Check the form for the updated properties. 479 // Store any error that occurs when updating the database item. 484 480 $error = 0; 485 481 486 // Activity spam status 482 // Activity spam status. 487 483 $prev_spam_status = $new_spam_status = false; 488 484 if ( ! empty( $_POST['activity_status'] ) ) { … … 491 487 } 492 488 493 // Activity action 489 // Activity action. 494 490 if ( isset( $_POST['bp-activities-action'] ) ) 495 491 $activity->action = $_POST['bp-activities-action']; 496 492 497 // Activity content 493 // Activity content. 498 494 if ( isset( $_POST['bp-activities-content'] ) ) 499 495 $activity->content = $_POST['bp-activities-content']; 500 496 501 // Activity primary link 497 // Activity primary link. 502 498 if ( ! empty( $_POST['bp-activities-link'] ) ) 503 499 $activity->primary_link = $_POST['bp-activities-link']; 504 500 505 // Activity user ID 501 // Activity user ID. 506 502 if ( ! empty( $_POST['bp-activities-userid'] ) ) 507 503 $activity->user_id = (int) $_POST['bp-activities-userid']; 508 504 509 // Activity item primary ID 505 // Activity item primary ID. 510 506 if ( isset( $_POST['bp-activities-primaryid'] ) ) 511 507 $activity->item_id = (int) $_POST['bp-activities-primaryid']; 512 508 513 // Activity item secondary ID 509 // Activity item secondary ID. 514 510 if ( isset( $_POST['bp-activities-secondaryid'] ) ) 515 511 $activity->secondary_item_id = (int) $_POST['bp-activities-secondaryid']; 516 512 517 // Activity type 513 // Activity type. 518 514 if ( ! empty( $_POST['bp-activities-type'] ) ) { 519 515 $actions = bp_activity_admin_get_activity_actions(); 520 516 521 // Check that the new type is a registered activity type 517 // Check that the new type is a registered activity type. 522 518 if ( in_array( $_POST['bp-activities-type'], $actions ) ) { 523 519 $activity->type = $_POST['bp-activities-type']; … … 525 521 } 526 522 527 // Activity timestamp 523 // Activity timestamp. 528 524 if ( ! empty( $_POST['aa'] ) && ! empty( $_POST['mm'] ) && ! empty( $_POST['jj'] ) && ! empty( $_POST['hh'] ) && ! empty( $_POST['mn'] ) && ! empty( $_POST['ss'] ) ) { 529 525 $aa = $_POST['aa']; … … 541 537 $ss = ( $ss > 59 ) ? $ss -60 : $ss; 542 538 543 // Reconstruct the date into a timestamp 539 // Reconstruct the date into a timestamp. 544 540 $gmt_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); 545 541 … … 555 551 } 556 552 557 // Save 553 // Save. 558 554 $result = $activity->save(); 559 555 560 // Clear the activity stream first page cache, in case this activity's timestamp was changed 556 // Clear the activity stream first page cache, in case this activity's timestamp was changed. 561 557 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 562 558 563 // Check for any error during activity save 559 // Check for any error during activity save. 564 560 if ( false === $result ) 565 561 $error = $activity->id; … … 574 570 do_action_ref_array( 'bp_activity_admin_edit_after', array( &$activity, $error ) ); 575 571 576 // If an error occurred, pass back the activity ID that failed 572 // If an error occurred, pass back the activity ID that failed. 577 573 if ( $error ) 578 574 $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to ); … … 604 600 */ 605 601 function bp_activity_admin() { 606 // Decide whether to load the index or edit screen 602 // Decide whether to load the index or edit screen. 607 603 $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; 608 604 609 // Display the single activity edit screen 605 // Display the single activity edit screen. 610 606 if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) 611 607 bp_activity_admin_edit(); 612 608 613 // Otherwise, display the Activity index screen 609 // Otherwise, display the Activity index screen. 614 610 else 615 611 bp_activity_admin_index(); … … 628 624 die( '-1' ); 629 625 630 // Get the activity from the database 626 // Get the activity from the database. 631 627 $activity = bp_activity_get( array( 632 628 'in' => ! empty( $_REQUEST['aid'] ) ? (int) $_REQUEST['aid'] : 0, … … 640 636 $activity = $activity['activities'][0]; 641 637 642 // Workaround to use WP's touch_time() without duplicating that function 638 // Workaround to use WP's touch_time() without duplicating that function. 643 639 $GLOBALS['comment'] = new stdClass; 644 640 $GLOBALS['comment']->comment_date = $activity->date_recorded; … … 647 643 } 648 644 649 // Construct URL for form 645 // Construct URL for form. 650 646 $form_url = remove_query_arg( array( 'action', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] ); 651 647 $form_url = add_query_arg( 'action', 'save', $form_url ); … … 741 737 <div class="misc-pub-section curtime misc-pub-section-last"> 742 738 <?php 743 // translators: Publish box date format, see http://php.net/date739 // Translators: Publish box date format, see http://php.net/date. 744 740 $datef = __( 'M j, Y @ G:i', 'buddypress' ); 745 741 $date = date_i18n( $datef, strtotime( $item->date_recorded ) ); … … 808 804 * @since 2.0.0 809 805 * 810 * @return array 806 * @return array $actions 811 807 */ 812 808 function bp_activity_admin_get_activity_actions() { … … 822 818 } 823 819 824 // This was a mis-named activity type from before BP 1.6 820 // This was a mis-named activity type from before BP 1.6. 825 821 unset( $actions['friends_register_activity_action'] ); 826 822 827 // Sort array by the human-readable value 823 // Sort array by the human-readable value. 828 824 natsort( $actions ); 829 825 … … 852 848 } 853 849 854 // This was a mis-named activity type from before BP 1.6 850 // This was a mis-named activity type from before BP 1.6. 855 851 unset( $actions['friends_register_activity_action'] ); 856 852 857 // Sort array by the human-readable value 853 // Sort array by the human-readable value. 858 854 natsort( $actions ); 859 855 860 // If the activity type is not registered properly (eg, a plugin has 861 // not called bp_activity_set_action()), add the raw type to the end 862 // of the list 856 /* 857 * If the activity type is not registered properly (eg, a plugin has 858 * not called bp_activity_set_action()), add the raw type to the end 859 * of the list. 860 */ 863 861 if ( ! isset( $actions[ $selected ] ) ) { 864 862 _doing_it_wrong( __FUNCTION__, sprintf( __( 'This activity item has a type (%s) that is not registered using bp_activity_set_action(), so no label is available.', 'buddypress' ), $selected ), '2.0.0' ); … … 912 910 $messages = array(); 913 911 914 // If the user has just made a change to an activity item, build status messages 912 // If the user has just made a change to an activity item, build status messages. 915 913 if ( ! empty( $_REQUEST['deleted'] ) || ! empty( $_REQUEST['spammed'] ) || ! empty( $_REQUEST['unspammed'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) ) { 916 914 $deleted = ! empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0; … … 922 920 $errors = array_map( 'absint', explode( ',', $errors ) ); 923 921 924 // Make sure we don't get any empty values in $errors 922 // Make sure we don't get any empty values in $errors. 925 923 for ( $i = 0, $errors_count = count( $errors ); $i < $errors_count; $i++ ) { 926 924 if ( 0 === $errors[$i] ) { … … 929 927 } 930 928 931 // Reindex array 929 // Reindex array. 932 930 $errors = array_values( $errors ); 933 931 … … 943 941 $error_msg .= '<ul class="activity-errors">'; 944 942 945 // Display each error as a list item 943 // Display each error as a list item. 946 944 foreach ( $errors as $error ) { 947 // Translators: This is a bulleted list of item IDs 945 // Translators: This is a bulleted list of item IDs. 948 946 $error_msg .= '<li>' . sprintf( __( '#%s', 'buddypress' ), number_format_i18n( $error ) ) . '</li>'; 949 947 } … … 964 962 } 965 963 966 // Prepare the activity items for display 964 // Prepare the activity items for display. 967 965 $bp_activity_list_table->prepare_items(); 968 966 … … 989 987 </h2> 990 988 991 <?php // If the user has just made a change to an activity item, display the status messages ?>989 <?php // If the user has just made a change to an activity item, display the status messages. ?> 992 990 <?php if ( !empty( $messages ) ) : ?> 993 991 <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div> 994 992 <?php endif; ?> 995 993 996 <?php // Display each activity on its own row ?>994 <?php // Display each activity on its own row. ?> 997 995 <?php $bp_activity_list_table->views(); ?> 998 996 … … 1003 1001 </form> 1004 1002 1005 <?php // This markup is used for the reply form ?>1003 <?php // This markup is used for the reply form. ?> 1006 1004 <table style="display: none;"> 1007 1005 <tr id="bp-activities-container" style="display: none;"> … … 1042 1040 * What type of view is being displayed? 1043 1041 * 1044 * e.g. "all", "pending", "approved", "spam"...1045 * 1046 * @since 1.6.0 1047 * @var string 1042 * E.g. "all", "pending", "approved", "spam"... 1043 * 1044 * @since 1.6.0 1045 * @var string $view 1048 1046 */ 1049 1047 public $view = 'all'; … … 1053 1051 * 1054 1052 * @since 1.6.0 1055 * @var int 1053 * @var int $spam_count 1056 1054 */ 1057 1055 public $spam_count = 0; … … 1061 1059 * 1062 1060 * @since 1.6.0 1063 * @var array 1061 * @var array $activity_user_id 1064 1062 */ 1065 1063 protected $activity_user_id = array(); … … 1068 1066 * If users can comment on blog & forum activity items. 1069 1067 * 1068 * @link https://buddypress.trac.wordpress.org/ticket/6277 1069 * 1070 1070 * @since 2.2.2 1071 * 1072 * @link https://buddypress.trac.wordpress.org/ticket/6277 1073 * 1074 * @var bool 1071 * @var bool $disable_blogforum_comments 1075 1072 */ 1076 1073 public $disable_blogforum_comments = false; … … 1083 1080 public function __construct() { 1084 1081 1085 // See if activity commenting is enabled for blog / forum activity items 1082 // See if activity commenting is enabled for blog / forum activity items. 1086 1083 $this->disable_blogforum_comments = bp_disable_blogforum_comments(); 1087 1084 … … 1102 1099 function prepare_items() { 1103 1100 1104 // Option defaults 1101 // Option defaults. 1105 1102 $filter = array(); 1106 1103 $include_id = false; … … 1109 1106 $spam = 'ham_only'; 1110 1107 1111 // Set current page 1108 // Set current page. 1112 1109 $page = $this->get_pagenum(); 1113 1110 1114 // Set per page from the screen options 1111 // Set per page from the screen options. 1115 1112 $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 1116 1113 1117 // Check if we're on the "Spam" view 1114 // Check if we're on the "Spam" view. 1118 1115 if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) { 1119 1116 $spam = 'spam_only'; … … 1121 1118 } 1122 1119 1123 // Sort order 1120 // Sort order. 1124 1121 if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] ) 1125 1122 $sort = 'ASC'; 1126 1123 1127 // Order by 1124 // Order by. 1128 1125 /*if ( !empty( $_REQUEST['orderby'] ) ) { 1129 1126 }*/ 1130 1127 1131 // Filter 1128 // Filter. 1132 1129 if ( !empty( $_REQUEST['activity_type'] ) ) 1133 1130 $filter = array( 'action' => $_REQUEST['activity_type'] ); … … 1141 1138 $include_id = (int) $_REQUEST['aid']; 1142 1139 1143 // Get the spam total (ignoring any search query or filter) 1140 // Get the spam total (ignoring any search query or filter). 1144 1141 $spams = bp_activity_get( array( 1145 1142 'display_comments' => 'stream', … … 1151 1148 unset( $spams ); 1152 1149 1153 // Get the activities from the database 1150 // Get the activities from the database. 1154 1151 $activities = bp_activity_get( array( 1155 1152 'display_comments' => 'stream', … … 1160 1157 'search_terms' => $search_terms, 1161 1158 'show_hidden' => true, 1162 // 'sort' => $sort,1159 // 'sort' => $sort, 1163 1160 'spam' => $spam, 1164 1161 'count_total' => 'count_query', … … 1170 1167 $activities['total'] = count( $activities['activities'] ); 1171 1168 1172 // Sort the array by the activity object's date_recorded value 1169 // Sort the array by the activity object's date_recorded value. 1173 1170 usort( $activities['activities'], create_function( '$a, $b', 'return $a->date_recorded > $b->date_recorded;' ) ); 1174 1171 } 1175 1172 1176 // bp_activity_getreturns an array of objects; cast these to arrays for WP_List_Table.1173 // The bp_activity_get function returns an array of objects; cast these to arrays for WP_List_Table. 1177 1174 $new_activities = array(); 1178 1175 foreach ( $activities['activities'] as $activity_item ) { 1179 1176 $new_activities[] = (array) $activity_item; 1180 1177 1181 // Build an array of activity-to-user ID mappings for better efficiency in the In Response To column 1178 // Build an array of activity-to-user ID mappings for better efficiency in the In Response To column. 1182 1179 $this->activity_user_id[$activity_item->id] = $activity_item->user_id; 1183 1180 } 1184 1181 1185 // Set raw data to display 1182 // Set raw data to display. 1186 1183 $this->items = $new_activities; 1187 1184 1188 // Store information needed for handling table pagination 1185 // Store information needed for handling table pagination. 1189 1186 $this->set_pagination_args( array( 1190 1187 'per_page' => $per_page, … … 1239 1236 * 1240 1237 * @since 1.6.0 1241 */1238 */ 1242 1239 function display() { 1243 1240 $this->display_tablenav( 'top' ); ?> … … 1398 1395 function extra_tablenav( $which ) { 1399 1396 1400 // Bail on bottom table nav 1397 // Bail on bottom table nav. 1401 1398 if ( 'bottom' === $which ) { 1402 1399 return; … … 1406 1403 $selected = ( ! empty( $_REQUEST['activity_type'] ) ) ? $_REQUEST['activity_type'] : ''; 1407 1404 1408 // Get the actions 1405 // Get the actions. 1409 1406 $activity_actions = bp_activity_get_actions(); ?> 1410 1407 … … 1422 1419 <?php 1423 1420 1424 // Skip the incorrectly named pre-1.6 action 1421 // Skip the incorrectly named pre-1.6 action. 1425 1422 if ( 'friends_register_activity_action' !== $action_key ) : ?> 1426 1423 … … 1452 1449 * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0. 1453 1450 * 1454 * @param array $actions The list of actions 1455 * @param bool $always_visible Whether the actions should be always visible1451 * @param array $actions The list of actions. 1452 * @param bool $always_visible Whether the actions should be always visible. 1456 1453 * @return string 1457 1454 */ … … 1531 1528 */ 1532 1529 function column_comment( $item ) { 1533 // Determine what type of item (row) we're dealing with 1530 // Determine what type of item (row) we're dealing with. 1534 1531 if ( $item['is_spam'] ) 1535 1532 $item_status = 'spam'; … … 1537 1534 $item_status = 'all'; 1538 1535 1539 // Preorder items: Reply | Edit | Spam | Delete Permanently 1536 // Preorder items: Reply | Edit | Spam | Delete Permanently. 1540 1537 $actions = array( 1541 1538 'reply' => '', … … 1545 1542 ); 1546 1543 1547 // Build actions URLs 1544 // Build actions URLs. 1548 1545 $base_url = bp_get_admin_url( 'admin.php?page=bp-activity&aid=' . $item['id'] ); 1549 1546 $spam_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'spam-activity_' . $item['id'] ) ); … … 1554 1551 $spam_url = $base_url . "&action=spam&$spam_nonce"; 1555 1552 1556 // Rollover actions 1557 1553 // Rollover actions. 1558 1554 // Reply - JavaScript only; implemented by AJAX. 1559 1555 if ( 'spam' != $item_status ) { … … 1564 1560 } 1565 1561 1566 // Edit 1562 // Edit. 1567 1563 $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) ); 1568 1564 } 1569 1565 1570 // Spam/unspam 1566 // Spam/unspam. 1571 1567 if ( 'spam' == $item_status ) 1572 1568 $actions['unspam'] = sprintf( '<a href="%s">%s</a>', $ham_url, __( 'Not Spam', 'buddypress' ) ); … … 1574 1570 $actions['spam'] = sprintf( '<a href="%s">%s</a>', $spam_url, __( 'Spam', 'buddypress' ) ); 1575 1571 1576 // Delete 1572 // Delete. 1577 1573 $actions['delete'] = sprintf( '<a href="%s" onclick="%s">%s</a>', $delete_url, "javascript:return confirm('" . esc_js( __( 'Are you sure?', 'buddypress' ) ) . "'); ", __( 'Delete Permanently', 'buddypress' ) ); 1578 1574 1579 // Start timestamp 1575 // Start timestamp. 1580 1576 echo '<div class="submitted-on">'; 1581 1577 … … 1598 1594 ); 1599 1595 1600 // End timestamp 1596 // End timestamp. 1601 1597 echo '</div>'; 1602 1598 1603 // Get activity content - if not set, use the action 1599 // Get activity content - if not set, use the action. 1604 1600 if ( ! empty( $item['content'] ) ) { 1605 1601 … … 1624 1620 1625 1621 /** 1626 * Filter here to add extra output to the activity content into the Administration 1622 * Filter here to add extra output to the activity content into the Administration. 1627 1623 * 1628 1624 * @since 2.4.0 1629 1625 * 1630 * @param string $content The activity content 1631 * @param array $item The activity object converted into an array 1626 * @param string $content The activity content. 1627 * @param array $item The activity object converted into an array. 1632 1628 */ 1633 1629 echo apply_filters( 'bp_activity_admin_comment_content', $content, $item ) . ' ' . $this->row_actions( $actions ); … … 1644 1640 */ 1645 1641 function column_response( $item ) { 1642 1646 1643 // Is $item is a root activity? 1647 1644 ?> … … 1670 1667 $root_activity_url = bp_get_admin_url( 'admin.php?page=bp-activity&aid=' . $item['id'] ); 1671 1668 1672 // If the activity has comments, display a link to the activity's permalink, with its comment count in a speech bubble 1669 // If the activity has comments, display a link to the activity's permalink, with its comment count in a speech bubble. 1673 1670 if ( $comment_count ) { 1674 1671 $title_attr = sprintf( _n( '%s related activity', '%s related activities', $comment_count, 'buddypress' ), number_format_i18n( $comment_count ) ); … … 1676 1673 } 1677 1674 1678 // For non-root activities, display a link to the replied-to activity's author's profile 1675 // For non-root activities, display a link to the replied-to activity's author's profile. 1679 1676 } else { 1680 1677 echo '<strong>' . get_avatar( $this->get_activity_user_id( $item['item_id'] ), '32' ) . ' ' . bp_core_get_userlink( $this->get_activity_user_id( $item['item_id'] ) ) . '</strong><br />'; … … 1695 1692 * @param array $item Information about the current row. 1696 1693 * @param string $column_name The column name. 1697 *1698 1694 * @return string 1699 1695 */ … … 1721 1717 * 1722 1718 * @param int $activity_id Activity ID to retrieve User ID for. 1723 *1724 1719 * @return int User ID of the activity item in question. 1725 1720 */ … … 1729 1724 return $this->activity_user_id[$activity_id]; 1730 1725 1731 /* *1726 /* 1732 1727 * We don't have a mapping. This means the $activity_id is not on the current 1733 1728 * page of results, so fetch its details from the database. … … 1736 1731 $activity = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) ); 1737 1732 1738 /* *1733 /* 1739 1734 * If, somehow, the referenced activity has been deleted, leaving its associated 1740 1735 * activities as orphans, use the logged in user's ID to avoid errors. … … 1743 1738 return bp_loggedin_user_id(); 1744 1739 1745 // Store the new activity/user ID mapping for any later re-use 1740 // Store the new activity/user ID mapping for any later re-use. 1746 1741 $this->activity_user_id[ $activity['activities'][0]->id ] = $activity['activities'][0]->user_id; 1747 1742 1748 // Return the user ID 1743 // Return the user ID. 1749 1744 return $activity['activities'][0]->user_id; 1750 1745 } … … 1762 1757 * 1763 1758 * @param array $item An array version of the BP_Activity_Activity object. 1764 * 1765 * @return bool 1759 * @return bool $can_comment 1766 1760 */ 1767 1761 protected function can_comment( $item ) { … … 1778 1772 } 1779 1773 1780 // activity comments supported1774 // Activity comments supported. 1781 1775 } else { 1782 // activity comment1776 // Activity comment. 1783 1777 if ( 'activity_comment' == $item['type'] ) { 1784 // blogs1778 // Blogs. 1785 1779 if ( bp_is_active( 'blogs' ) ) { 1786 // grab the parent activity entry1780 // Grab the parent activity entry. 1787 1781 $parent_activity = new BP_Activity_Activity( $item['item_id'] ); 1788 1782 1789 // fetch blog post comment depth and if the blog post's comments are open1783 // Fetch blog post comment depth and if the blog post's comments are open. 1790 1784 bp_blogs_setup_activity_loop_globals( $parent_activity ); 1791 1785 1792 // check if the activity item can be replied to1786 // Check if the activity item can be replied to. 1793 1787 if ( false === bp_blogs_can_comment_reply( true, $item ) ) { 1794 1788 $can_comment = false; … … 1796 1790 } 1797 1791 1798 // blog post1792 // Blog post. 1799 1793 } elseif ( 'new_blog_post' == $item['type'] ) { 1800 1794 if ( bp_is_active( 'blogs' ) ) { … … 1827 1821 * 1828 1822 * @param array $tree Source array. 1829 *1830 1823 * @return array Flattened array. 1831 1824 */ -
trunk/src/bp-activity/bp-activity-akismet.php
r10248 r10253 3 3 * Akismet support for BuddyPress' Activity Stream. 4 4 * 5 * @since 1.6.06 5 * @package BuddyPress 7 6 * @subpackage ActivityAkismet 7 * @since 1.6.0 8 8 */ 9 9 10 // Exit if accessed directly 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 … … 18 18 */ 19 19 class BP_Akismet { 20 20 21 /** 21 22 * The activity last marked as spam. 22 23 * 24 * @since 1.6.0 25 * 23 26 * @var BP_Activity_Activity 24 * @since 1.6.025 27 */ 26 28 protected $last_activity = null; … … 41 43 */ 42 44 protected function setup_actions() { 43 // Add nonces to activity stream lists 45 // Add nonces to activity stream lists. 44 46 add_action( 'bp_after_activity_post_form', array( $this, 'add_activity_stream_nonce' ) ); 45 47 add_action( 'bp_activity_entry_comments', array( $this, 'add_activity_stream_nonce' ) ); 46 48 47 // Add a "mark as spam" button to individual activity items 49 // Add a "mark as spam" button to individual activity items. 48 50 add_action( 'bp_activity_entry_meta', array( $this, 'add_activity_spam_button' ) ); 49 51 add_action( 'bp_activity_comment_options', array( $this, 'add_activity_comment_spam_button' ) ); 50 52 51 // Check activity for spam 53 // Check activity for spam. 52 54 add_action( 'bp_activity_before_save', array( $this, 'check_activity' ), 4, 1 ); 53 55 54 // Tidy up member's latest (activity) update 56 // Tidy up member's latest (activity) update. 55 57 add_action( 'bp_activity_posted_update', array( $this, 'check_member_activity_update' ), 1, 3 ); 56 58 57 // Hooks to extend Activity core spam/ham functions for Akismet 59 // Hooks to extend Activity core spam/ham functions for Akismet. 58 60 add_action( 'bp_activity_mark_as_spam', array( $this, 'mark_as_spam' ), 10, 2 ); 59 61 add_action( 'bp_activity_mark_as_ham', array( $this, 'mark_as_ham' ), 10, 2 ); 60 62 61 // Hook into the Activity wp-admin screen 63 // Hook into the Activity wp-admin screen. 62 64 add_action( 'bp_activity_admin_comment_row_actions', array( $this, 'comment_row_action' ), 10, 2 ); 63 65 add_action( 'bp_activity_admin_load', array( $this, 'add_history_metabox' ) ); … … 74 76 * @param array $actions The hover links. 75 77 * @param array $activity The activity for the current row being processed. 76 *77 78 * @return array The hover links. 78 79 */ … … 83 84 84 85 if ( !$user_result || $user_result == $akismet_result ) { 85 // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same 86 // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same. 86 87 if ( 'true' == $akismet_result && $activity['is_spam'] ) 87 88 $desc = __( 'Flagged as spam by Akismet', 'buddypress' ); … … 99 100 } 100 101 101 // add a History item to the hover links, just after Edit102 // Add a History item to the hover links, just after Edit. 102 103 if ( $akismet_result ) { 103 104 $b = array(); … … 139 140 $value = '_bp_as_nonce_' . bp_loggedin_user_id(); 140 141 141 // If we're in the activity stream loop, we can use the current item's ID to make the nonce unique 142 // If we're in the activity stream loop, we can use the current item's ID to make the nonce unique. 142 143 if ( 'bp_activity_entry_comments' == current_filter() ) { 143 144 $form_id .= '_' . bp_get_activity_id(); … … 245 246 * @static 246 247 * 247 * @return array List of activity types.248 * @return array $value List of activity types. 248 249 */ 249 250 public static function get_activity_types() { … … 270 271 */ 271 272 public function mark_as_spam( $activity, $source ) { 272 // Record this item so we can do some tidyup in BP_Akismet::check_member_activity_update() 273 // Record this item so we can do some tidyup in BP_Akismet::check_member_activity_update(). 273 274 $this->last_activity = $activity; 274 275 … … 325 326 * 326 327 * @param BP_Activity_Activity $activity Activity item data. 327 * 328 * @return array 328 * @return array $activity_data 329 329 */ 330 330 public static function build_akismet_data_package( $activity ) { … … 383 383 return; 384 384 385 // Make sure last_activity is clear to avoid any confusion 385 // Make sure last_activity is clear to avoid any confusion. 386 386 $this->last_activity = null; 387 387 388 // Build data package for Akismet 388 // Build data package for Akismet. 389 389 $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 390 390 391 // Check with Akismet to see if this is spam 391 // Check with Akismet to see if this is spam. 392 392 $activity_data = $this->send_akismet_request( $activity_data, 'check', 'spam' ); 393 393 394 // Record this item 394 // Record this item. 395 395 $this->last_activity = $activity; 396 396 397 // Store a copy of the data that was submitted to Akismet 397 // Store a copy of the data that was submitted to Akismet. 398 398 $this->last_activity->akismet_submission = $activity_data; 399 399 400 // Spam 400 // Spam. 401 401 if ( 'true' == $activity_data['bp_as_result'] ) { 402 402 /** … … 411 411 do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) ); 412 412 413 // Mark as spam 413 // Mark as spam. 414 414 bp_activity_mark_as_spam( $activity, 'by_akismet' ); 415 415 } 416 416 417 // Update activity meta after a spam check 417 // Update activity meta after a spam check. 418 418 add_action( 'bp_activity_after_save', array( $this, 'update_activity_akismet_meta' ), 1, 1 ); 419 419 } … … 461 461 */ 462 462 public function update_activity_akismet_meta( $activity ) { 463 // Check we're dealing with what was last updated by Akismet 463 // Check we're dealing with what was last updated by Akismet. 464 464 if ( empty( $this->last_activity ) || !empty( $this->last_activity ) && $activity->id != $this->last_activity->id ) 465 465 return; … … 469 469 return; 470 470 471 // Spam 471 // Spam. 472 472 if ( 'true' == $this->last_activity->akismet_submission['bp_as_result'] ) { 473 473 bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'true' ); 474 474 $this->update_activity_history( $activity->id, __( 'Akismet caught this item as spam', 'buddypress' ), 'check-spam' ); 475 475 476 // Not spam 476 // Not spam. 477 477 } elseif ( 'false' == $this->last_activity->akismet_submission['bp_as_result'] ) { 478 478 bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'false' ); … … 485 485 } 486 486 487 // Record the original data which was submitted to Akismet for checking 487 // Record the original data which was submitted to Akismet for checking. 488 488 bp_activity_update_meta( $activity->id, '_bp_akismet_submission', $this->last_activity->akismet_submission ); 489 489 } … … 499 499 * @param string $check "check" or "submit". 500 500 * @param string $spam "spam" or "ham". 501 *502 501 * @return array $activity_data Activity data, with Akismet data added. 503 502 */ … … 515 514 $activity_data['is_test'] = 'true'; 516 515 517 // Loop through _POST args and rekey strings 516 // Loop through _POST args and rekey strings. 518 517 foreach ( $_POST as $key => $value ) 519 518 if ( is_string( $value ) && 'cookie' != $key ) 520 519 $activity_data['POST_' . $key] = $value; 521 520 522 // Keys to ignore 521 // Keys to ignore. 523 522 $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ); 524 523 525 // Loop through _SERVER args and remove whitelisted keys 524 // Loop through _SERVER args and remove whitelisted keys. 526 525 foreach ( $_SERVER as $key => $value ) { 527 526 528 // Key should not be ignored 527 // Key should not be ignored. 529 528 if ( !in_array( $key, $ignore ) && is_string( $value ) ) { 530 529 $activity_data[$key] = $value; 531 530 532 // Key should be ignored 531 // Key should be ignored. 533 532 } else { 534 533 $activity_data[$key] = ''; … … 544 543 $path = 'submit-' . $spam; 545 544 546 // Send to Akismet 545 // Send to Akismet. 547 546 add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) ); 548 547 $response = Akismet::http_post( $query_string, $path ); 549 548 remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) ); 550 549 551 // Get the response 550 // Get the response. 552 551 if ( ! empty( $response[1] ) && ! is_wp_error( $response[1] ) ) 553 552 $activity_data['bp_as_result'] = $response[1]; … … 555 554 $activity_data['bp_as_result'] = false; 556 555 557 // Perform a daily tidy up 556 // Perform a daily tidy up. 558 557 if ( ! wp_next_scheduled( 'bp_activity_akismet_delete_old_metadata' ) ) 559 558 wp_schedule_event( time(), 'daily', 'bp_activity_akismet_delete_old_metadata' ); … … 568 567 * 569 568 * @param string $user_agent User agent string, as generated by Akismet. 570 *571 569 * @return string $user_agent Modified user agent string. 572 570 */ … … 584 582 */ 585 583 function add_history_metabox( $screen_action ) { 586 // Only proceed if we're on the edit screen 584 // Only proceed if we're on the edit screen. 587 585 if ( 'edit' != $screen_action ) 588 586 return; 589 587 590 // Display meta box with a low priority (low position on screen by default) 588 // Display meta box with a low priority (low position on screen by default). 591 589 add_meta_box( 'bp_activity_history', __( 'Activity History', 'buddypress' ), array( $this, 'history_metabox' ), get_current_screen()->id, 'normal', 'low' ); 592 590 } … … 630 628 ); 631 629 632 // Save the history data 630 // Save the history data. 633 631 bp_activity_update_meta( $activity_id, '_bp_akismet_history', $event ); 634 632 } … … 640 638 * 641 639 * @param int $activity_id Activity item ID. 642 *643 640 * @return array The activity item's Akismet history. 644 641 */ … … 648 645 $history = array(); 649 646 650 // Sort it by the time recorded 647 // Sort it by the time recorded. 651 648 usort( $history, 'akismet_cmp_time' ); 652 649 … … 679 676 $interval = apply_filters( 'bp_activity_akismet_delete_meta_interval', 15 ); 680 677 681 // Enforce a minimum of 1 day 678 // Enforce a minimum of 1 day. 682 679 $interval = max( 1, absint( $interval ) ); 683 680 -
trunk/src/bp-activity/bp-activity-cache.php
r10077 r10253 8 8 */ 9 9 10 // Exit if accessed directly 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 … … 19 19 * 20 20 * @param int|string|array|bool $activity_ids Accepts a single activity ID, or a comma- 21 * separated list or array of activity ids 21 * separated list or array of activity ids. 22 22 */ 23 23 function bp_activity_update_meta_cache( $activity_ids = false ) { … … 41 41 * @since 2.0.0 42 42 * 43 * @param BP_Activity_Activity $activity 43 * @param BP_Activity_Activity $activity Activity object. 44 44 */ 45 45 function bp_activity_clear_cache_for_activity( $activity ) { -
trunk/src/bp-activity/bp-activity-classes.php
r10077 r10253 1 1 <?php 2 2 /** 3 * BuddyPress Activity Classes 3 * BuddyPress Activity Classes. 4 4 * 5 5 * @package BuddyPress … … 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 -
trunk/src/bp-activity/bp-activity-cssjs.php
r10077 r10253 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 … … 20 20 } 21 21 22 // Special handling for New/Edit screens in wp-admin 22 // Special handling for New/Edit screens in wp-admin. 23 23 if ( is_admin() ) { 24 24 if ( … … 64 64 * @param array $settings An array with TinyMCE config. 65 65 * @param string $editor_id Unique editor identifier, e.g. 'content'. 66 *67 66 * @return array $mceInit An array with TinyMCE config. 68 67 */ -
trunk/src/bp-activity/bp-activity-filters.php
r10077 r10253 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 12 12 /** Filters *******************************************************************/ 13 13 14 // Apply WordPress defined filters 14 // Apply WordPress defined filters. 15 15 add_filter( 'bp_get_activity_action', 'bp_activity_filter_kses', 1 ); 16 16 add_filter( 'bp_get_activity_content_body', 'bp_activity_filter_kses', 1 ); … … 78 78 add_filter( 'bp_activity_primary_link_before_save', 'esc_url_raw' ); 79 79 80 // Apply BuddyPress-defined filters 80 // Apply BuddyPress-defined filters. 81 81 add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' ); 82 82 add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' ); … … 101 101 /** Actions *******************************************************************/ 102 102 103 // At-name filter 103 // At-name filter. 104 104 add_action( 'bp_activity_before_save', 'bp_activity_at_name_filter_updates' ); 105 105 106 // Activity stream moderation 106 // Activity stream moderation. 107 107 add_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 ); 108 108 add_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1 ); … … 142 142 function bp_activity_check_moderation_keys( $activity ) { 143 143 144 // Only check specific types of activity updates 144 // Only check specific types of activity updates. 145 145 if ( !in_array( $activity->type, bp_activity_get_moderated_activity_types() ) ) 146 146 return; 147 147 148 148 // Unset the activity component so activity stream update fails 149 // @todo This is temporary until some kind of moderation is built 149 // @todo This is temporary until some kind of moderation is built. 150 150 if ( !bp_core_check_for_moderation( $activity->user_id, '', $activity->content ) ) 151 151 $activity->component = false; … … 161 161 function bp_activity_check_blacklist_keys( $activity ) { 162 162 163 // Only check specific types of activity updates 163 // Only check specific types of activity updates. 164 164 if ( ! in_array( $activity->type, bp_activity_get_moderated_activity_types() ) ) 165 165 return; 166 166 167 // Mark as spam 167 // Mark as spam. 168 168 if ( ! bp_core_check_for_blacklist( $activity->user_id, '', $activity->content ) ) 169 169 bp_activity_mark_as_spam( $activity, 'by_blacklist' ); … … 179 179 * 180 180 * @param string $content The activity content. 181 *182 181 * @return string $content Filtered activity content. 183 182 */ … … 223 222 * @param string $content The contents of a given item. 224 223 * @param int $activity_id The activity id. Deprecated. 225 *226 224 * @return string $content Content filtered for mentions. 227 225 */ … … 233 231 } 234 232 235 // Try to find mentions 233 // Try to find mentions. 236 234 $usernames = bp_activity_find_mentions( $content ); 237 235 … … 241 239 242 240 // We don't want to link @mentions that are inside of links, so we 243 // temporarily remove them 241 // temporarily remove them. 244 242 $replace_count = 0; 245 243 $replacements = array(); 246 244 foreach ( $usernames as $username ) { 247 // prevent @ name linking inside <a> tags245 // Prevent @ name linking inside <a> tags. 248 246 preg_match_all( '/(<a.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches ); 249 247 if ( ! empty( $content_matches[1] ) ) { … … 256 254 } 257 255 258 // Linkify the mentions with the username 256 // Linkify the mentions with the username. 259 257 foreach ( (array) $usernames as $user_id => $username ) { 260 258 $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content ); 261 259 } 262 260 263 // put everything back261 // Put everything back. 264 262 if ( ! empty( $replacements ) ) { 265 263 foreach ( $replacements as $placeholder => $original ) { … … 268 266 } 269 267 270 // Return the content 268 // Return the content. 271 269 return $content; 272 270 } … … 282 280 * @uses bp_activity_find_mentions() 283 281 * 284 * @param BP_Activity_Activity $activity 282 * @param BP_Activity_Activity $activity Activity Object. 285 283 */ 286 284 function bp_activity_at_name_filter_updates( $activity ) { … … 294 292 return; 295 293 296 // Try to find mentions 294 // Try to find mentions. 297 295 $usernames = bp_activity_find_mentions( $activity->content ); 298 296 299 297 // We have mentions! 300 298 if ( ! empty( $usernames ) ) { 301 // Replace @mention text with userlinks 299 // Replace @mention text with userlinks. 302 300 foreach( (array) $usernames as $user_id => $username ) { 303 301 $activity->content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $activity->content ); 304 302 } 305 303 306 // Add our hook to send @mention emails after the activity item is saved 304 // Add our hook to send @mention emails after the activity item is saved. 307 305 add_action( 'bp_activity_after_save', 'bp_activity_at_name_send_emails' ); 308 306 309 // temporary variable to avoid having to run bp_activity_find_mentions() again307 // Temporary variable to avoid having to run bp_activity_find_mentions() again. 310 308 buddypress()->activity->mentioned_users = $usernames; 311 309 } … … 332 330 return; 333 331 334 // Grab our temporary variable from bp_activity_at_name_filter_updates() 332 // Grab our temporary variable from bp_activity_at_name_filter_updates(). 335 333 $usernames = buddypress()->activity->mentioned_users; 336 334 337 // Get rid of temporary variable 335 // Get rid of temporary variable. 338 336 unset( buddypress()->activity->mentioned_users ); 339 337 340 // Send @mentions and setup BP notifications 338 // Send @mentions and setup BP notifications. 341 339 foreach( (array) $usernames as $user_id => $username ) { 342 340 … … 353 351 } 354 352 355 // Updates mention count for the user 353 // Updates mention count for the user. 356 354 bp_activity_update_mention_count_for_user( $user_id, $activity->id ); 357 355 } … … 364 362 * 365 363 * @param string $text Activity text. 366 *367 364 * @return string $text Text with rel=nofollow added to any links. 368 365 */ … … 377 374 * 378 375 * @param array $matches Items matched by preg_replace_callback() in bp_activity_make_nofollow_filter(). 379 *380 376 * @return string $text Link with rel=nofollow added. 381 377 */ … … 402 398 * 403 399 * @param string $text The original activity entry text. 404 *405 400 * @return string $excerpt The truncated text. 406 401 */ … … 420 415 ); 421 416 422 // The full text of the activity update should always show on the single activity screen 417 // The full text of the activity update should always show on the single activity screen. 423 418 if ( ! $maybe_truncate_text || bp_is_single_activity() ) { 424 419 return $text; … … 443 438 $excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 ); 444 439 445 // Run the text through the excerpt function. If it's too short, the original text will be 446 // returned. 440 // Run the text through the excerpt function. If it's too short, the original text will be returned. 447 441 $excerpt = bp_create_excerpt( $text, $excerpt_length, array( 'ending' => __( '…', 'buddypress' ) ) ); 448 442 449 // If the text returned by bp_create_excerpt() is different from the original text (ie it's 450 // been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping 451 // shortcodes, so we have strip them from the $text before the comparison 443 /* 444 * If the text returned by bp_create_excerpt() is different from the original text (ie it's 445 * been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping 446 * shortcodes, so we have strip them from the $text before the comparison. 447 */ 452 448 if ( $excerpt != strip_shortcodes( $text ) ) { 453 449 $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id(); … … 476 472 * 477 473 * @param array $js_handles The original dependencies. 478 *479 474 * @return array $js_handles The new dependencies. 480 475 */ … … 496 491 * @since 2.0.0 497 492 * 498 * @param string $classes 499 * 493 * @param string $classes Array of classes for most recent activity item. 500 494 * @return string $classes 501 495 */ … … 516 510 * @since 2.0.0 517 511 * 518 * @param string $classes 519 * 512 * @param string $classes Array of classes for timestamp. 520 513 * @return string $classes 521 514 */ … … 545 538 * @uses bp_activity_get_last_updated() to get the recorded date of the last activity. 546 539 * 547 * @param array $response 548 * @param array $data 549 * 540 * @param array $response Array containing Heartbeat API response. 541 * @param array $data Array containing data for Heartbeat API response. 550 542 * @return array $response 551 543 */ … … 556 548 557 549 // Use the querystring argument stored in the cookie (to preserve 558 // filters), but force the offset to get only new items 550 // filters), but force the offset to get only new items. 559 551 $activity_latest_args = bp_parse_args( 560 552 bp_ajax_querystring( 'activity' ), … … 570 562 $last_activity_recorded = 0; 571 563 572 // Temporarily add a just-posted class for new activity items 564 // Temporarily add a just-posted class for new activity items. 573 565 add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 ); 574 566 … … 591 583 ob_end_clean(); 592 584 593 // Remove the temporary filter 585 // Remove the temporary filter. 594 586 remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 ); 595 587 … … 609 601 * 610 602 * @param array $strings Localized strings. 611 *612 603 * @return array $strings 613 604 */ … … 672 663 * @param array $retval Empty array by default. 673 664 * @param array $filter Current activity arguments. 674 * 675 * @return array 665 * @return array $retval 676 666 */ 677 667 function bp_activity_filter_just_me_scope( $retval = array(), $filter = array() ) { 678 668 679 // Determine the user_id 669 // Determine the user_id. 680 670 if ( ! empty( $filter['user_id'] ) ) { 681 671 $user_id = $filter['user_id']; … … 703 693 $show_hidden, 704 694 705 // overrides695 // Overrides. 706 696 'override' => array( 707 697 'display_comments' => 'stream', … … 722 712 * @param array $retval Empty array by default. 723 713 * @param array $filter Current activity arguments. 724 * 725 * @return array 714 * @return array $retval 726 715 */ 727 716 function bp_activity_filter_favorites_scope( $retval = array(), $filter = array() ) { 728 717 729 // Determine the user_id 718 // Determine the user_id. 730 719 if ( ! empty( $filter['user_id'] ) ) { 731 720 $user_id = $filter['user_id']; … … 736 725 } 737 726 738 // Determine the favorites 727 // Determine the favorites. 739 728 $favs = bp_activity_get_user_favorites( $user_id ); 740 729 if ( empty( $favs ) ) { … … 760 749 $show_hidden, 761 750 762 // overrides751 // Overrides. 763 752 'override' => array( 764 753 'display_comments' => true, … … 780 769 * @param array $retval Empty array by default. 781 770 * @param array $filter Current activity arguments. 782 * 783 * @return array 771 * @return array $retval 784 772 */ 785 773 function bp_activity_filter_mentions_scope( $retval = array(), $filter = array() ) { … … 790 778 } 791 779 792 // Determine the user_id 780 // Determine the user_id. 793 781 if ( ! empty( $filter['user_id'] ) ) { 794 782 $user_id = $filter['user_id']; … … 819 807 $show_hidden, 820 808 821 // overrides809 // Overrides. 822 810 'override' => array( 823 811 824 // clear search terms so 'mentions' scope works with other scopes812 // Clear search terms so 'mentions' scope works with other scopes. 825 813 'search_terms' => false, 826 814 -
trunk/src/bp-activity/bp-activity-functions.php
r10217 r10253 9 9 */ 10 10 11 // Exit if accessed directly 11 // Exit if accessed directly. 12 12 defined( 'ABSPATH' ) || exit; 13 13 … … 86 86 * @param string $content The content of the activity, usually found in 87 87 * $activity->content. 88 *89 88 * @return array|bool Associative array with user ID as key and username as 90 89 * value. Boolean false if no mentions found. … … 95 94 preg_match_all( $pattern, $content, $usernames ); 96 95 97 // Make sure there's only one instance of each username 96 // Make sure there's only one instance of each username. 98 97 $usernames = array_unique( $usernames[1] ); 99 98 100 // Bail if no usernames 99 // Bail if no usernames. 101 100 if ( empty( $usernames ) ) { 102 101 return false; … … 105 104 $mentioned_users = array(); 106 105 107 // We've found some mentions! Check to see if users exist 106 // We've found some mentions! Check to see if users exist. 108 107 foreach( (array) array_values( $usernames ) as $username ) { 109 108 $user_id = bp_activity_get_userid_from_mentionname( $username ); 110 109 111 // user ID exists, so let's add it to our array110 // The user ID exists, so let's add it to our array. 112 111 if ( ! empty( $user_id ) ) { 113 112 $mentioned_users[ $user_id ] = $username; … … 151 150 * @param int $activity_id The unique id for the activity item. 152 151 * @param string $action Can be 'delete' or 'add'. Defaults to 'add'. 153 *154 152 * @return bool 155 153 */ 156 154 function bp_activity_adjust_mention_count( $activity_id = 0, $action = 'add' ) { 157 155 158 // Bail if no activity ID passed 156 // Bail if no activity ID passed. 159 157 if ( empty( $activity_id ) ) { 160 158 return false; 161 159 } 162 160 163 // Get activity object 161 // Get activity object. 164 162 $activity = new BP_Activity_Activity( (int) $activity_id ); 165 163 166 // Try to find mentions 164 // Try to find mentions. 167 165 $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) ); 168 166 169 // Still empty? Stop now 167 // Still empty? Stop now. 170 168 if ( empty( $usernames ) ) { 171 169 return false; 172 170 } 173 171 174 // Increment mention count foreach mentioned user 172 // Increment mention count foreach mentioned user. 175 173 foreach( (array) array_keys( $usernames ) as $user_id ) { 176 174 bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action ); … … 192 190 * @param int $activity_id The unique ID for the activity item. 193 191 * @param string $action 'delete' or 'add'. Default: 'add'. 194 *195 192 * @return bool 196 193 */ … … 201 198 } 202 199 203 // Adjust the mention list and count for the member 200 // Adjust the mention list and count for the member. 204 201 $new_mention_count = (int) bp_get_user_meta( $user_id, 'bp_new_mention_count', true ); 205 202 $new_mentions = bp_get_user_meta( $user_id, 'bp_new_mentions', true ); 206 203 207 // Make sure new mentions is an array 204 // Make sure new mentions is an array. 208 205 if ( empty( $new_mentions ) ) { 209 206 $new_mentions = array(); … … 229 226 } 230 227 231 // Get an updated mention count 228 // Get an updated mention count. 232 229 $new_mention_count = count( $new_mentions ); 233 230 234 // Resave the user_meta 231 // Resave the user_meta. 235 232 bp_update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count ); 236 233 bp_update_user_meta( $user_id, 'bp_new_mentions', $new_mentions ); … … 245 242 * 246 243 * @param int|string $user_id ID of the user to get @-mention name for. 247 * 248 * @return string User name appropriate for @-mentions. 244 * @return string $mentionname User name appropriate for @-mentions. 249 245 */ 250 246 function bp_activity_get_user_mentionname( $user_id ) { … … 270 266 * 271 267 * @param string $mentionname Username of user in @-mentions. 272 *273 268 * @return int|bool ID of the user, if one is found. Otherwise false. 274 269 */ … … 276 271 $user_id = false; 277 272 278 // In username compatibility mode, hyphens are ambiguous between 279 // actual hyphens and converted spaces. 280 // 281 // @todo There is the potential for username clashes between 'foo bar' 282 // and 'foo-bar' in compatibility mode. Come up with a system for 283 // unique mentionnames. 273 /* 274 * In username compatibility mode, hyphens are ambiguous between 275 * actual hyphens and converted spaces. 276 * 277 * @todo There is the potential for username clashes between 'foo bar' 278 * and 'foo-bar' in compatibility mode. Come up with a system for 279 * unique mentionnames. 280 */ 284 281 if ( bp_is_username_compatibility_mode() ) { 285 // First, try the raw username 282 // First, try the raw username. 286 283 $userdata = get_user_by( 'login', $mentionname ); 287 284 … … 297 294 298 295 // When username compatibility mode is disabled, the mentionname is 299 // the same as the nicename 296 // the same as the nicename. 300 297 } else { 301 298 $user_id = bp_core_get_userid_from_nicename( $mentionname ); … … 332 329 * Values: 'activity', 'member', 'member_groups', 'group'. 333 330 * @param int $position Optional. The position of the action when listed in dropdowns. 334 *335 331 * @return bool False if any param is empty, otherwise true. 336 332 */ … … 338 334 $bp = buddypress(); 339 335 340 // Return false if any of the above values are not set 336 // Return false if any of the above values are not set. 341 337 if ( empty( $component_id ) || empty( $type ) || empty( $description ) ) { 342 338 return false; 343 339 } 344 340 345 // Set activity action 341 // Set activity action. 346 342 if ( ! isset( $bp->activity->actions ) || ! is_object( $bp->activity->actions ) ) { 347 343 $bp->activity->actions = new stdClass; 348 344 } 349 345 350 // Verify callback 346 // Verify callback. 351 347 if ( ! is_callable( $format_callback ) ) { 352 348 $format_callback = ''; … … 393 389 * @param array $args { 394 390 * An associative array of tracking parameters. All items are optional. 395 *396 391 * @type string $bp_activity_admin_filter String to use in the Dashboard > Activity dropdown. 397 392 * @type string $bp_activity_front_filter String to use in frontend dropdown. … … 415 410 * the post type does not natively support comments, otherwise false. 416 411 * } 417 *418 412 * @return bool 419 413 */ … … 445 439 * 446 440 * @param string $post_type Name of the post type. 447 *448 441 * @return object The tracking arguments of the post type. 449 442 */ … … 515 508 */ 516 509 function bp_activity_get_post_types_tracking_args() { 517 // Fetch all public post types 510 // Fetch all public post types. 518 511 $post_types = get_post_types( array( 'public' => true ), 'names' ); 519 512 … … 595 588 * @param string $component_id The unique string ID of the component. 596 589 * @param string $key The action key. 597 *598 590 * @return string|bool Action value if found, otherwise false. 599 591 */ 600 592 function bp_activity_get_action( $component_id, $key ) { 601 593 602 // Return false if any of the above values are not set 594 // Return false if any of the above values are not set. 603 595 if ( empty( $component_id ) || empty( $key ) ) { 604 596 return false; … … 643 635 } 644 636 645 // This was a mis-named activity type from before BP 1.6 637 // This was a mis-named activity type from before BP 1.6. 646 638 unset( $actions['friends_register_activity_action'] ); 647 639 … … 667 659 * 668 660 * @param int $user_id ID of the user whose favorites are being queried. 669 *670 661 * @return array IDs of the user's favorite activity items. 671 662 */ 672 663 function bp_activity_get_user_favorites( $user_id = 0 ) { 673 664 674 // Fallback to logged in user if no user_id is passed 665 // Fallback to logged in user if no user_id is passed. 675 666 if ( empty( $user_id ) ) { 676 667 $user_id = bp_displayed_user_id(); 677 668 } 678 669 679 // Get favorites for user 670 // Get favorites for user. 680 671 $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ); 681 672 … … 705 696 * @param int $activity_id ID of the activity item being favorited. 706 697 * @param int $user_id ID of the user favoriting the activity item. 707 *708 698 * @return bool True on success, false on failure. 709 699 */ 710 700 function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 711 701 712 // Favorite activity stream items are for logged in users only 702 // Favorite activity stream items are for logged in users only. 713 703 if ( ! is_user_logged_in() ) { 714 704 return false; 715 705 } 716 706 717 // Fallback to logged in user if no user_id is passed 707 // Fallback to logged in user if no user_id is passed. 718 708 if ( empty( $user_id ) ) { 719 709 $user_id = bp_loggedin_user_id(); … … 725 715 } 726 716 727 // Bail if the user has already favorited this activity item 717 // Bail if the user has already favorited this activity item. 728 718 if ( in_array( $activity_id, $my_favs ) ) { 729 719 return false; 730 720 } 731 721 732 // Add to user's favorites 722 // Add to user's favorites. 733 723 $my_favs[] = $activity_id; 734 724 735 // Update the total number of users who have favorited this activity 725 // Update the total number of users who have favorited this activity. 736 726 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); 737 727 $fav_count = !empty( $fav_count ) ? (int) $fav_count + 1 : 1; 738 728 739 // Update user meta 729 // Update user meta. 740 730 bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ); 741 731 742 // Update activity meta counts 732 // Update activity meta counts. 743 733 if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) { 744 734 … … 753 743 do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id ); 754 744 755 // Success 745 // Success. 756 746 return true; 757 747 758 // Saving meta was unsuccessful for an unknown reason 748 // Saving meta was unsuccessful for an unknown reason. 759 749 } else { 760 750 … … 787 777 * @param int $activity_id ID of the activity item being unfavorited. 788 778 * @param int $user_id ID of the user unfavoriting the activity item. 789 *790 779 * @return bool True on success, false on failure. 791 780 */ 792 781 function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) { 793 782 794 // Favorite activity stream items are for logged in users only 783 // Favorite activity stream items are for logged in users only. 795 784 if ( ! is_user_logged_in() ) { 796 785 return false; 797 786 } 798 787 799 // Fallback to logged in user if no user_id is passed 788 // Fallback to logged in user if no user_id is passed. 800 789 if ( empty( $user_id ) ) { 801 790 $user_id = bp_loggedin_user_id(); … … 805 794 $my_favs = array_flip( (array) $my_favs ); 806 795 807 // Bail if the user has not previously favorited the item 796 // Bail if the user has not previously favorited the item. 808 797 if ( ! isset( $my_favs[ $activity_id ] ) ) { 809 798 return false; 810 799 } 811 800 812 // Remove the fav from the user's favs 801 // Remove the fav from the user's favs. 813 802 unset( $my_favs[$activity_id] ); 814 803 $my_favs = array_unique( array_flip( $my_favs ) ); 815 804 816 // Update the total number of users who have favorited this activity 805 // Update the total number of users who have favorited this activity. 817 806 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); 818 807 if ( ! empty( $fav_count ) ) { 819 808 820 // Deduct from total favorites 809 // Deduct from total favorites. 821 810 if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ) ) { 822 811 823 // Update users favorites 812 // Update users favorites. 824 813 if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) { 825 814 … … 834 823 do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id ); 835 824 836 // Success 825 // Success. 837 826 return true; 838 827 839 // Error updating 828 // Error updating. 840 829 } else { 841 830 return false; 842 831 } 843 832 844 // Error updating favorite count 833 // Error updating favorite count. 845 834 } else { 846 835 return false; 847 836 } 848 837 849 // Error getting favorite count 838 // Error getting favorite count. 850 839 } else { 851 840 return false; … … 862 851 * 863 852 * @param string $content The content to filter by. 864 *865 853 * @return int|null The ID of the located activity item. Null if none is found. 866 854 */ … … 907 895 * 908 896 * @param int $user_id ID of the user whose favorite count is being requested. 909 *910 897 * @return int Total favorite count for the user. 911 898 */ 912 899 function bp_activity_total_favorites_for_user( $user_id = 0 ) { 913 900 914 // Fallback on displayed user, and then logged in user 901 // Fallback on displayed user, and then logged in user. 915 902 if ( empty( $user_id ) ) { 916 903 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); … … 937 924 * @param bool $delete_all Optional. If true, delete matching metadata entries 938 925 * for all objects, ignoring the specified object_id. Otherwise, 939 * only delete matching metadata entries for the specified 940 * activity item. Default: false. 941 * 926 * only delete matching metadata entries for the specified 927 * activity item. Default: false. 942 928 * @return bool True on success, false on failure. 943 929 */ 944 930 function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) { 945 931 946 // Legacy - if no meta_key is passed, delete all for the item 932 // Legacy - if no meta_key is passed, delete all for the item. 947 933 if ( empty( $meta_key ) ) { 948 934 $all_meta = bp_activity_get_meta( $activity_id ); 949 935 $keys = ! empty( $all_meta ) ? array_keys( $all_meta ) : array(); 950 936 951 // With no meta_key, ignore $delete_all 937 // With no meta_key, ignore $delete_all. 952 938 $delete_all = false; 953 939 } else { … … 978 964 * activity item will be fetched. 979 965 * @param bool $single Optional. If true, return only the first value of the 980 * specified meta_key. This parameter has no effect if meta_key is not 981 * specified. Default: true. 982 * 966 * specified meta_key. This parameter has no effect if meta_key is not 967 * specified. Default: true. 983 968 * @return mixed The meta value(s) being requested. 984 969 */ … … 1011 996 * @param mixed $prev_value Optional. If specified, only update existing metadata entries 1012 997 * with the specified value. Otherwise, update all entries. 1013 *1014 998 * @return bool|int Returns false on failure. On successful update of existing 1015 999 * metadata, returns true. On successful creation of new metadata, … … 1035 1019 * given key. If true, and the object already has a value for 1036 1020 * the key, no change will be made. Default: false. 1037 *1038 1021 * @return int|bool The meta ID on successful update, false on failure. 1039 1022 */ … … 1060 1043 * 1061 1044 * @param int $user_id ID of the user whose activity is being deleted. 1062 *1063 1045 * @return bool 1064 1046 */ 1065 1047 function bp_activity_remove_all_user_data( $user_id = 0 ) { 1066 1048 1067 // Do not delete user data unless a logged in user says so 1049 // Do not delete user data unless a logged in user says so. 1068 1050 if ( empty( $user_id ) || ! is_user_logged_in() ) { 1069 1051 return false; 1070 1052 } 1071 1053 1072 // Clear the user's activity from the sitewide stream and clear their activity tables 1054 // Clear the user's activity from the sitewide stream and clear their activity tables. 1073 1055 bp_activity_delete( array( 'user_id' => $user_id ) ); 1074 1056 1075 // Remove any usermeta 1057 // Remove any usermeta. 1076 1058 bp_delete_user_meta( $user_id, 'bp_latest_update' ); 1077 1059 bp_delete_user_meta( $user_id, 'bp_favorite_activities' ); … … 1100 1082 * 1101 1083 * @param int $user_id ID of the user whose activity is being spammed. 1102 *1103 1084 * @return bool 1104 1085 */ … … 1106 1087 global $wpdb; 1107 1088 1108 // Do not delete user data unless a logged in user says so 1089 // Do not delete user data unless a logged in user says so. 1109 1090 if ( empty( $user_id ) || ! is_user_logged_in() ) { 1110 1091 return false; … … 1120 1101 $bp = buddypress(); 1121 1102 1122 // Mark each as spam 1103 // Mark each as spam. 1123 1104 foreach ( (array) $activities['activities'] as $activity ) { 1124 1105 1125 // Create an activity object 1106 // Create an activity object. 1126 1107 $activity_obj = new BP_Activity_Activity; 1127 1108 foreach ( $activity as $k => $v ) { … … 1129 1110 } 1130 1111 1131 // Mark as spam 1112 // Mark as spam. 1132 1113 bp_activity_mark_as_spam( $activity_obj ); 1133 1114 … … 1143 1124 } 1144 1125 1145 // Tidy up 1126 // Tidy up. 1146 1127 unset( $activity_obj ); 1147 1128 } 1148 1129 1149 // Mark all of this user's activities as spam 1130 // Mark all of this user's activities as spam. 1150 1131 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) ); 1151 1132 … … 1170 1151 * 1171 1152 * @param int $user_id ID of the user whose activity is being hammed. 1172 *1173 1153 * @return bool 1174 1154 */ … … 1176 1156 global $wpdb; 1177 1157 1178 // Do not delete user data unless a logged in user says so 1158 // Do not delete user data unless a logged in user says so. 1179 1159 if ( empty( $user_id ) || ! is_user_logged_in() ) { 1180 1160 return false; … … 1191 1171 $bp = buddypress(); 1192 1172 1193 // Mark each as not spam 1173 // Mark each as not spam. 1194 1174 foreach ( (array) $activities['activities'] as $activity ) { 1195 1175 1196 // Create an activity object 1176 // Create an activity object. 1197 1177 $activity_obj = new BP_Activity_Activity; 1198 1178 foreach ( $activity as $k => $v ) { … … 1200 1180 } 1201 1181 1202 // Mark as not spam 1182 // Mark as not spam. 1203 1183 bp_activity_mark_as_ham( $activity_obj ); 1204 1184 … … 1214 1194 } 1215 1195 1216 // Tidy up 1196 // Tidy up. 1217 1197 unset( $activity_obj ); 1218 1198 } 1219 1199 1220 // Mark all of this user's activities as not spam 1200 // Mark all of this user's activities as not spam. 1221 1201 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) ); 1222 1202 … … 1276 1256 * 1277 1257 * @param object $activity Activity data object. 1278 *1279 1258 * @return string|bool Returns false if no callback is found, otherwise returns 1280 1259 * the formatted action string. … … 1282 1261 function bp_activity_generate_action_string( $activity ) { 1283 1262 1284 // Check for valid input 1263 // Check for valid input. 1285 1264 if ( empty( $activity->component ) || empty( $activity->type ) ) { 1286 1265 return false; 1287 1266 } 1288 1267 1289 // Check for registered format callback 1268 // Check for registered format callback. 1290 1269 $actions = bp_activity_get_actions(); 1291 1270 if ( empty( $actions->{$activity->component}->{$activity->type}['format_callback'] ) ) { … … 1293 1272 } 1294 1273 1295 // We apply the format_callback as a filter 1274 // We apply the format_callback as a filter. 1296 1275 add_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 ); 1297 1276 … … 1306 1285 $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity ); 1307 1286 1308 // Remove the filter for future activity items 1287 // Remove the filter for future activity items. 1309 1288 remove_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 ); 1310 1289 … … 1319 1298 * @param string $action Static activity action. 1320 1299 * @param object $activity Activity data object. 1321 * 1322 * @return string 1300 * @return string $action 1323 1301 */ 1324 1302 function bp_activity_format_activity_action_activity_update( $action, $activity ) { … … 1343 1321 * @param string $action Static activity action. 1344 1322 * @param object $activity Activity data object. 1345 * 1346 * @return string 1323 * @return string $action 1347 1324 */ 1348 1325 function bp_activity_format_activity_action_activity_comment( $action, $activity ) { … … 1367 1344 * @param string $action Static activity action. 1368 1345 * @param object $activity Activity data object. 1369 * 1370 * @return string 1346 * @return string $action 1371 1347 */ 1372 1348 function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) { … … 1418 1394 } 1419 1395 1420 /* *****************************************************************************1396 /* 1421 1397 * Business functions are where all the magic happens in BuddyPress. They will 1422 1398 * handle the actual saving or manipulation of information. Usually they will … … 1428 1404 * Retrieve an activity or activities. 1429 1405 * 1430 * bp_activity_get() shares all arguments with BP_Activity_Activity::get(). The1431 * following is a list of bp_activity_get() parameters that have different1406 * The bp_activity_get() function shares all arguments with BP_Activity_Activity::get(). 1407 * The following is a list of bp_activity_get() parameters that have different 1432 1408 * default values from BP_Activity_Activity::get() (value in parentheses is 1433 1409 * the default for the bp_activity_get()). … … 1446 1422 * 1447 1423 * @param array|string $args See BP_Activity_Activity::get() for description. 1448 *1449 1424 * @return array $activity See BP_Activity_Activity::get() for description. 1450 1425 */ … … 1464 1439 'filter_query' => false, 1465 1440 'show_hidden' => false, // Show activity items that are hidden site-wide? 1466 'exclude' => false, // Comma-separated list of activity IDs to exclude 1467 'in' => false, // Comma-separated list or array of activity IDs to which you want to limit the query 1441 'exclude' => false, // Comma-separated list of activity IDs to exclude. 1442 'in' => false, // Comma-separated list or array of activity IDs to which you 1443 // want to limit the query. 1468 1444 'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'. 1469 1445 'update_meta_cache' => true, … … 1474 1450 * Pass filters as an array -- all filter items can be multiple values comma separated: 1475 1451 * array( 1476 * 'user_id' => false, // user_id to filter on1477 * 'object' => false, // object to filter on e.g. groups, profile, status, friends1478 * 'action' => false, // action to filter on e.g. activity_update, profile_updated1479 * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.1480 * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id1452 * 'user_id' => false, // User ID to filter on. 1453 * 'object' => false, // Object to filter on e.g. groups, profile, status, friends. 1454 * 'action' => false, // Action to filter on e.g. activity_update, profile_updated. 1455 * 'primary_id' => false, // Object ID to filter on e.g. a group_id or forum_id or blog_id etc. 1456 * 'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id. 1481 1457 * ); 1482 1458 */ … … 1558 1534 * except for the following: 1559 1535 * @type string|int|array Single activity ID, comma-separated list of IDs, 1560 * or array of IDs.1536 * or array of IDs. 1561 1537 * } 1562 1538 * @return array $activity See BP_Activity_Activity::get() for description. … … 1566 1542 $r = bp_parse_args( $args, array( 1567 1543 'activity_ids' => false, // A single activity_id or array of IDs. 1568 'display_comments' => false, // true or false to display threaded comments for these specific activity items1569 'max' => false, // Maximum number of results to return 1570 'page' => 1, // page 1 without a per_page will result in no pagination.1571 'per_page' => false, // results per page1572 'show_hidden' => true, // When fetching specific items, show all 1573 'sort' => 'DESC', // sort ASC or DESC1574 'spam' => 'ham_only', // Retrieve items marked as spam 1544 'display_comments' => false, // True or false to display threaded comments for these specific activity items. 1545 'max' => false, // Maximum number of results to return. 1546 'page' => 1, // Page 1 without a per_page will result in no pagination. 1547 'per_page' => false, // Results per page. 1548 'show_hidden' => true, // When fetching specific items, show all. 1549 'sort' => 'DESC', // Sort ASC or DESC 1550 'spam' => 'ham_only', // Retrieve items marked as spam. 1575 1551 'update_meta_cache' => true, 1576 1552 ) ); … … 1650 1626 'action' => '', // The activity action - e.g. "Jon Doe posted an update" 1651 1627 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" 1652 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent 1653 'type' => false, // The activity type e.g. activity_update, profile_updated 1654 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink) 1628 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent. 1629 'type' => false, // The activity type e.g. activity_update, profile_updated. 1630 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink). 1655 1631 'user_id' => bp_loggedin_user_id(), // Optional: The user to record the activity for, can be false if this activity is not for a user. 1656 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id 1657 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id 1658 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded 1632 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id. 1633 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id. 1634 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded. 1659 1635 'hide_sitewide' => false, // Should this be hidden on the sitewide activity stream? 1660 1636 'is_spam' => false, // Is this activity item to be marked as spam? 1661 1637 ), 'activity_add' ); 1662 1638 1663 // Make sure we are backwards compatible 1639 // Make sure we are backwards compatible. 1664 1640 if ( empty( $r['component'] ) && !empty( $r['component_name'] ) ) { 1665 1641 $r['component'] = $r['component_name']; … … 1670 1646 } 1671 1647 1672 // Setup activity to be added 1648 // Setup activity to be added. 1673 1649 $activity = new BP_Activity_Activity( $r['id'] ); 1674 1650 $activity->user_id = $r['user_id']; … … 1690 1666 } 1691 1667 1692 // If this is an activity comment, rebuild the tree 1668 // If this is an activity comment, rebuild the tree. 1693 1669 if ( 'activity_comment' === $activity->type ) { 1694 // Also clear the comment cache for the parent activity ID 1670 // Also clear the comment cache for the parent activity ID. 1695 1671 wp_cache_delete( $activity->item_id, 'bp_activity_comments' ); 1696 1672 … … 1749 1725 } 1750 1726 1751 // Record this on the user's profile 1727 // Record this on the user's profile. 1752 1728 $activity_content = $r['content']; 1753 1729 $primary_link = bp_core_get_userlink( $r['user_id'], false, true ); … … 1771 1747 $add_primary_link = apply_filters( 'bp_activity_new_update_primary_link', $primary_link ); 1772 1748 1773 // Now write the values 1749 // Now write the values. 1774 1750 $activity_id = bp_activity_add( array( 1775 1751 'user_id' => $r['user_id'], … … 1815 1791 * @since 2.2.0 1816 1792 * 1817 * @param int $post_id ID of the new post. 1818 * @param WP_Post $post Post object. 1819 * @param int $user_id ID of the post author. 1820 * 1793 * @param int $post_id ID of the new post. 1794 * @param WP_Post $post Post object. 1795 * @param int $user_id ID of the post author. 1821 1796 * @return int|bool The ID of the activity on success. False on error. 1822 1797 */ … … 1953 1928 * @since 2.2.0 1954 1929 * 1955 * @param WP_Post $post Post item. 1956 * 1957 * @return bool True on success, false on failure. 1930 * @param WP_Post $post Post item. 1931 * @return bool True on success, false on failure. 1958 1932 */ 1959 1933 function bp_activity_post_type_update( $post = null ) { … … 2024 1998 * @param int $post_id ID of the post being unpublished. 2025 1999 * @param WP_Post $post Post object. 2026 * 2027 * @return bool True on success, false on failure. 2000 * @return bool True on success, false on failure. 2028 2001 */ 2029 2002 function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { … … 2033 2006 } 2034 2007 2035 // Get the post type tracking args 2008 // Get the post type tracking args. 2036 2009 $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type ); 2037 2010 … … 2106 2079 'content' => false, 2107 2080 'user_id' => bp_loggedin_user_id(), 2108 'activity_id' => false, // ID of the root activity item 2109 'parent_id' => false // ID of a parent comment (optional) 2081 'activity_id' => false, // ID of the root activity item. 2082 'parent_id' => false // ID of a parent comment (optional). 2110 2083 ) ); 2111 2084 2112 // Bail if missing necessary data 2085 // Bail if missing necessary data. 2113 2086 if ( empty( $r['content'] ) || empty( $r['user_id'] ) || empty( $r['activity_id'] ) ) { 2114 2087 $errors->add( 'missing_data', $feedback ); … … 2118 2091 } 2119 2092 2120 // Maybe set current activity ID as the parent 2093 // Maybe set current activity ID as the parent. 2121 2094 if ( empty( $r['parent_id'] ) ) { 2122 2095 $r['parent_id'] = $r['activity_id']; … … 2125 2098 $activity_id = $r['activity_id']; 2126 2099 2127 // Get the parent activity 2100 // Get the parent activity. 2128 2101 $activity = new BP_Activity_Activity( $activity_id ); 2129 2102 2130 // Bail if the parent activity does not exist 2103 // Bail if the parent activity does not exist. 2131 2104 if ( empty( $activity->date_recorded ) ) { 2132 2105 $errors->add( 'missing_activity', __( 'Sorry, the item you are replying to no longer exists.', 'buddypress' ) ); … … 2148 2121 $comment_content = apply_filters( 'bp_activity_comment_content', $r['content'] ); 2149 2122 2150 // Insert the activity comment 2123 // Insert the activity comment. 2151 2124 $comment_id = bp_activity_add( array( 2152 2125 'id' => $r['id'], … … 2160 2133 ) ); 2161 2134 2162 // Comment caches are stored only with the top-level item 2135 // Comment caches are stored only with the top-level item. 2163 2136 wp_cache_delete( $activity_id, 'bp_activity_comments' ); 2164 2137 2165 // Walk the tree to clear caches for all parent items 2138 // Walk the tree to clear caches for all parent items. 2166 2139 $clear_id = $r['parent_id']; 2167 2140 while ( $clear_id != $activity_id ) { … … 2202 2175 * 2203 2176 * @param array|string $args See BP_Activity_Activity::get() for description. 2204 *2205 2177 * @return int $activity_id The ID of the activity item found. 2206 2178 */ … … 2268 2240 * the same as BP_Activity_Activity::get(). 2269 2241 * See that method for a description. 2270 *2271 2242 * @return bool True on success, false on failure. 2272 2243 */ 2273 2244 function bp_activity_delete( $args = '' ) { 2274 2245 2275 // Pass one or more the of following variables to delete by those variables 2246 // Pass one or more the of following variables to delete by those variables. 2276 2247 $args = bp_parse_args( $args, array( 2277 2248 'id' => false, … … 2297 2268 do_action( 'bp_before_activity_delete', $args ); 2298 2269 2299 // Adjust the new mention count of any mentioned member 2270 // Adjust the new mention count of any mentioned member. 2300 2271 bp_activity_adjust_mention_count( $args['id'], 'delete' ); 2301 2272 … … 2305 2276 } 2306 2277 2307 // Check if the user's latest update has been deleted 2278 // Check if the user's latest update has been deleted. 2308 2279 $user_id = empty( $args['user_id'] ) 2309 2280 ? bp_loggedin_user_id() … … 2353 2324 * @param array|string $args See BP_Activity_Activity::get for a 2354 2325 * description of accepted arguments. 2355 *2356 2326 * @return bool True on success, false on failure. 2357 2327 */ … … 2377 2347 * 2378 2348 * @param int $activity_id ID of the activity item to be deleted. 2379 *2380 2349 * @return bool True on success, false on failure. 2381 2350 */ … … 2398 2367 * @param string $component The activity component. 2399 2368 * @param string $type The activity type. 2400 *2401 2369 * @return bool True on success, false on failure. 2402 2370 */ … … 2422 2390 * @param int $user_id The user id. 2423 2391 * @param string $component The activity component. 2424 *2425 2392 * @return bool True on success, false on failure. 2426 2393 */ … … 2450 2417 * oldest ancestor. 2451 2418 * @param int $comment_id The ID of the comment to be deleted. 2452 *2453 2419 * @return bool True on success, false on failure. 2454 2420 */ … … 2474 2440 bp_activity_delete_children( $activity_id, $comment_id ); 2475 2441 2476 // Delete the actual comment 2442 // Delete the actual comment. 2477 2443 if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) { 2478 2444 return false; 2479 2445 } 2480 2446 2481 // Purge comment cache for the root activity update 2447 // Purge comment cache for the root activity update. 2482 2448 wp_cache_delete( $activity_id, 'bp_activity_comments' ); 2483 2449 2484 // Recalculate the comment tree 2450 // Recalculate the comment tree. 2485 2451 BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id ); 2486 2452 … … 2513 2479 function bp_activity_delete_children( $activity_id, $comment_id ) { 2514 2480 2515 // Get activity children to delete 2481 // Get activity children to delete. 2516 2482 $children = BP_Activity_Activity::get_child_comments( $comment_id ); 2517 2483 … … 2523 2489 } 2524 2490 2525 // Delete the comment itself 2491 // Delete the comment itself. 2526 2492 bp_activity_delete( array( 2527 2493 'secondary_item_id' => $comment_id, … … 2547 2513 * @param int $activity_id The unique id of the activity object. 2548 2514 * @param object|bool $activity_obj Optional. The activity object. 2549 *2550 2515 * @return string $link Permalink for the activity item. 2551 2516 */ … … 2600 2565 * 2601 2566 * @param int $user_id The ID of the user whose activity is being hidden. 2602 *2603 2567 * @return bool True on success, false on failure. 2604 2568 */ … … 2629 2593 * @param array|bool $args Optional. The args passed to the activity 2630 2594 * creation function (eg bp_blogs_record_activity()). 2631 *2632 2595 * @return string $content The content with images stripped and replaced with a 2633 2596 * single thumb. … … 2637 2600 preg_match_all( '/<img[^>]*>/Ui', $content, $matches ); 2638 2601 2639 // Remove <img> tags. Also remove caption shortcodes and caption text if present 2602 // Remove <img> tags. Also remove caption shortcodes and caption text if present. 2640 2603 $content = preg_replace('|(\[caption(.*?)\])?<img[^>]*>([^\[\[]*\[\/caption\])?|', '', $content ); 2641 2604 2642 2605 if ( !empty( $matches ) && !empty( $matches[0] ) ) { 2643 2606 2644 // Get the SRC value 2607 // Get the SRC value. 2645 2608 preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src ); 2646 2609 2647 // Get the width and height 2610 // Get the width and height. 2648 2611 preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height ); 2649 2612 preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width ); … … 2702 2665 * @param array $activity The data passed to bp_activity_add() or the values 2703 2666 * from an Activity obj. 2704 * 2705 * @return string 2667 * @return string $summary 2706 2668 */ 2707 2669 function bp_activity_create_summary( $content, $activity ) { … … 2886 2848 $activity->is_spam = 1; 2887 2849 2888 // Clear the activity stream first page cache 2850 // Clear the activity stream first page cache. 2889 2851 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 2890 2852 2891 // Clear the activity comment cache for this activity item 2853 // Clear the activity comment cache for this activity item. 2892 2854 wp_cache_delete( $activity->id, 'bp_activity_comments' ); 2893 2855 2894 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity 2856 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 2895 2857 if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { 2896 2858 remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 ); 2897 2859 2898 // Build data package for Akismet 2860 // Build data package for Akismet. 2899 2861 $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 2900 2862 2901 // Tell Akismet this is spam 2863 // Tell Akismet this is spam. 2902 2864 $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' ); 2903 2865 2904 // Update meta 2866 // Update meta. 2905 2867 add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 ); 2906 2868 } … … 2933 2895 $activity->is_spam = 0; 2934 2896 2935 // Clear the activity stream first page cache 2897 // Clear the activity stream first page cache. 2936 2898 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 2937 2899 2938 // Clear the activity comment cache for this activity item 2900 // Clear the activity comment cache for this activity item. 2939 2901 wp_cache_delete( $activity->id, 'bp_activity_comments' ); 2940 2902 2941 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity 2903 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 2942 2904 if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { 2943 2905 remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 ); 2944 2906 2945 // Build data package for Akismet 2907 // Build data package for Akismet. 2946 2908 $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 2947 2909 2948 // Tell Akismet this is spam 2910 // Tell Akismet this is spam. 2949 2911 $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'ham' ); 2950 2912 2951 // Update meta 2913 // Update meta. 2952 2914 add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 ); 2953 2915 } … … 3072 3034 * @param int $id The ID of the activity item. 3073 3035 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 3074 *3075 3036 * @return mixed The cached embeds for this activity item. 3076 3037 */ … … 3093 3054 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 3094 3055 * @param int $id The ID of the activity item. 3095 *3096 * @return bool True on success, false on failure.3097 3056 */ 3098 3057 function bp_embed_activity_save_cache( $cache, $cachekey, $id ) { -
trunk/src/bp-activity/bp-activity-loader.php
r10110 r10253 9 9 */ 10 10 11 // Exit if accessed directly 11 // Exit if accessed directly. 12 12 defined( 'ABSPATH' ) || exit; 13 13 … … 47 47 public function includes( $includes = array() ) { 48 48 49 // Files to include 49 // Files to include. 50 50 $includes = array( 51 51 'cssjs', … … 60 60 ); 61 61 62 // Load Akismet support if Akismet is configured 62 // Load Akismet support if Akismet is configured. 63 63 $akismet_key = bp_get_option( 'wordpress_api_key' ); 64 64 … … 90 90 $bp = buddypress(); 91 91 92 // Define a slug, if necessary 92 // Define a slug, if necessary. 93 93 if ( ! defined( 'BP_ACTIVITY_SLUG' ) ) { 94 94 define( 'BP_ACTIVITY_SLUG', $this->id ); 95 95 } 96 96 97 // Global tables for activity component 97 // Global tables for activity component. 98 98 $global_tables = array( 99 99 'table_name' => $bp->table_prefix . 'bp_activity', … … 101 101 ); 102 102 103 // Metadata tables for groups component 103 // Metadata tables for groups component. 104 104 $meta_tables = array( 105 105 'activity' => $bp->table_prefix . 'bp_activity_meta', … … 138 138 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 139 139 140 // Stop if there is no user displayed or logged in 140 // Stop if there is no user displayed or logged in. 141 141 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 142 142 return; 143 143 } 144 144 145 // Determine user to use 145 // Determine user to use. 146 146 if ( bp_displayed_user_domain() ) { 147 147 $user_domain = bp_displayed_user_domain(); … … 155 155 $activity_link = trailingslashit( $user_domain . $slug ); 156 156 157 // Add 'Activity' to the main navigation 157 // Add 'Activity' to the main navigation. 158 158 $main_nav = array( 159 159 'name' => _x( 'Activity', 'Profile activity screen nav', 'buddypress' ), … … 165 165 ); 166 166 167 // Add the subnav items to the activity nav item if we are using a theme that supports this 167 // Add the subnav items to the activity nav item if we are using a theme that supports this. 168 168 $sub_nav[] = array( 169 169 'name' => _x( 'Personal', 'Profile activity screen sub nav', 'buddypress' ), … … 175 175 ); 176 176 177 // @ mentions177 // Check @mentions. 178 178 if ( bp_activity_do_mentions() ) { 179 179 $sub_nav[] = array( … … 188 188 } 189 189 190 // Favorite activity items 190 // Favorite activity items. 191 191 if ( bp_activity_can_favorite() ) { 192 192 $sub_nav[] = array( … … 201 201 } 202 202 203 // Additional menu if friends is active 203 // Additional menu if friends is active. 204 204 if ( bp_is_active( 'friends' ) ) { 205 205 $sub_nav[] = array( … … 214 214 } 215 215 216 // Additional menu if groups is active 216 // Additional menu if groups is active. 217 217 if ( bp_is_active( 'groups' ) ) { 218 218 $sub_nav[] = array( … … 250 250 public function setup_admin_bar( $wp_admin_nav = array() ) { 251 251 252 // Menus for logged in user 252 // Menus for logged in user. 253 253 if ( is_user_logged_in() ) { 254 254 255 // Setup the logged in user variables 255 // Setup the logged in user variables. 256 256 $activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() ); 257 257 258 // Unread message count 258 // Unread message count. 259 259 if ( bp_activity_do_mentions() ) { 260 260 $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() ); … … 266 266 } 267 267 268 // Add the "Activity" sub menu 268 // Add the "Activity" sub menu. 269 269 $wp_admin_nav[] = array( 270 270 'parent' => buddypress()->my_account_menu_id, … … 274 274 ); 275 275 276 // Personal 276 // Personal. 277 277 $wp_admin_nav[] = array( 278 278 'parent' => 'my-account-' . $this->id, … … 282 282 ); 283 283 284 // Mentions 284 // Mentions. 285 285 if ( bp_activity_do_mentions() ) { 286 286 $wp_admin_nav[] = array( … … 292 292 } 293 293 294 // Favorites 295 // Favorite activity items 294 // Favorite activity items. 296 295 if ( bp_activity_can_favorite() ) { 297 296 $wp_admin_nav[] = array( … … 338 337 public function setup_title() { 339 338 340 // Adjust title based on view 339 // Adjust title based on view. 341 340 if ( bp_is_activity_component() ) { 342 341 $bp = buddypress(); … … 364 363 public function setup_actions() { 365 364 366 // Spam prevention 365 // Spam prevention. 367 366 add_action( 'bp_include', 'bp_activity_setup_akismet' ); 368 367 … … 377 376 public function setup_cache_groups() { 378 377 379 // Global groups 378 // Global groups. 380 379 wp_cache_add_global_groups( array( 381 380 'bp_activity', -
trunk/src/bp-activity/bp-activity-notifications.php
r10077 r10253 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 … … 41 41 function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) { 42 42 43 // Don't leave multiple notifications for the same activity item 43 // Don't leave multiple notifications for the same activity item. 44 44 $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' ); 45 45 … … 56 56 $content = ''; 57 57 58 // Now email the user with the contents of the message (if they have enabled email notifications) 58 // Now email the user with the contents of the message (if they have enabled email notifications). 59 59 if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) { 60 60 $poster_name = bp_core_get_user_displayname( $activity->user_id ); … … 67 67 $content = bp_activity_filter_kses( strip_tags( stripslashes( $activity->content ) ) ); 68 68 69 // Set up and send the message 69 // Set up and send the message. 70 70 $ud = bp_core_get_core_userdata( $receiver_user_id ); 71 71 $to = $ud->user_email; … … 94 94 } 95 95 96 // Only show the disable notifications line if the settings component is enabled 96 // Only show the disable notifications line if the settings component is enabled. 97 97 if ( bp_is_active( 'settings' ) ) { 98 98 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); … … 175 175 * @param int $comment_id The comment id. 176 176 * @param int $commenter_id The ID of the user who posted the comment. 177 * @param array $params {@link bp_activity_new_comment()} 178 * 177 * @param array $params {@link bp_activity_new_comment()}. 179 178 * @return bool 180 179 */ 181 180 function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) { 182 181 183 // Set some default parameters 182 // Set some default parameters. 184 183 $activity_id = 0; 185 184 $parent_id = 0; … … 198 197 $content = bp_activity_filter_kses( stripslashes($content) ); 199 198 200 // Set up and send the message 199 // Set up and send the message. 201 200 $ud = bp_core_get_core_userdata( $original_activity->user_id ); 202 201 $to = $ud->user_email; … … 212 211 ', 'buddypress' ), $poster_name, $content, $thread_link ); 213 212 214 // Only show the disable notifications line if the settings component is enabled 213 // Only show the disable notifications line if the settings component is enabled. 215 214 if ( bp_is_active( 'settings' ) ) { 216 215 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); … … 266 265 } 267 266 268 /* **267 /* 269 268 * If this is a reply to another comment, send an email notification to the 270 269 * author of the immediate parent comment. … … 282 281 $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . $settings_slug . '/notifications/'; 283 282 284 // Set up and send the message 283 // Set up and send the message. 285 284 $ud = bp_core_get_core_userdata( $parent_comment->user_id ); 286 285 $to = $ud->user_email; … … 300 299 ', 'buddypress' ), $poster_name, $content, $thread_link ); 301 300 302 // Only show the disable notifications line if the settings component is enabled 301 // Only show the disable notifications line if the settings component is enabled. 303 302 if ( bp_is_active( 'settings' ) ) { 304 303 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); … … 360 359 * @since 1.9.0 361 360 * 362 * @param int $comment_id 363 * @param array $params 361 * @param int $comment_id ID of the comment being notified about. 362 * @param array $params Parameters to use with notification. 364 363 */ 365 364 function bp_activity_new_comment_notification_helper( $comment_id, $params ) { … … 387 386 * @param int $total_items The total number of notifications to format. 388 387 * @param string $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise. 389 *390 388 * @return string $return Formatted @mention notification. 391 389 */ … … 476 474 * @since 1.9.0 477 475 * 478 * @param object $activity 479 * @param string $subject (not used) 480 * @param string $message (not used) 481 * @param string $content (not used) 482 * @param int $receiver_user_id 476 * @param object $activity Activity object. 477 * @param string $subject (not used) Notification subject. 478 * @param string $message (not used) Notification message. 479 * @param string $content (not used) Notification content. 480 * @param int $receiver_user_id ID of user receiving notification. 483 481 */ 484 482 function bp_activity_at_mention_add_notification( $activity, $subject, $message, $content, $receiver_user_id ) { … … 509 507 } 510 508 511 // Only mark read if you're looking at your own mentions 509 // Only mark read if you're looking at your own mentions. 512 510 if ( ! bp_is_my_profile() ) { 513 511 return; … … 523 521 * @since 2.0.0 524 522 * 525 * @param object BP_Activity_Activity523 * @param BP_Activity_Activity $activity Activity object. 526 524 */ 527 525 function bp_activity_remove_screen_notifications_single_activity_permalink( $activity ) { … … 534 532 } 535 533 536 // Mark as read any notifications for the current user related to this 537 // activity item 534 // Mark as read any notifications for the current user related to this activity item. 538 535 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $activity->id, buddypress()->activity->id, 'new_at_mention' ); 539 536 } … … 549 546 function bp_activity_at_mention_delete_notification( $activity_ids_deleted = array() ) { 550 547 // Let's delete all without checking if content contains any mentions 551 // to avoid a query to get the activity 548 // to avoid a query to get the activity. 552 549 if ( bp_is_active( 'notifications' ) && ! empty( $activity_ids_deleted ) ) { 553 550 foreach ( $activity_ids_deleted as $activity_id ) { -
trunk/src/bp-activity/bp-activity-screens.php
r10081 r10253 11 11 */ 12 12 13 // Exit if accessed directly 13 // Exit if accessed directly. 14 14 defined( 'ABSPATH' ) || exit; 15 15 … … 253 253 $bp = buddypress(); 254 254 255 // No displayed user or not viewing activity component 255 // No displayed user or not viewing activity component. 256 256 if ( !bp_is_activity_component() ) 257 257 return false; … … 260 260 return false; 261 261 262 // Get the activity details 262 // Get the activity details. 263 263 $activity = bp_activity_get_specific( array( 'activity_ids' => bp_current_action(), 'show_hidden' => true, 'spam' => 'ham_only', ) ); 264 264 … … 272 272 } 273 273 274 // Default access is true 274 // Default access is true. 275 275 $has_access = true; 276 276 277 // If activity is from a group, do an extra cap check 277 // If activity is from a group, do an extra cap check. 278 278 if ( isset( $bp->groups->id ) && $activity->component == $bp->groups->id ) { 279 279 280 // Activity is from a group, but groups is currently disabled 280 // Activity is from a group, but groups is currently disabled. 281 281 if ( !bp_is_active( 'groups') ) { 282 282 bp_do_404(); … … 285 285 286 286 // Check to see if the group is not public, if so, check the 287 // user has access to see this activity 287 // user has access to see this activity. 288 288 if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) { 289 289 290 // Group is not public 290 // Group is not public. 291 291 if ( 'public' != $group->status ) { 292 292 293 // User is not a member of group 293 // User is not a member of group. 294 294 if ( !groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) { 295 295 $has_access = false; … … 318 318 do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access ); 319 319 320 // Access is specifically disallowed 320 // Access is specifically disallowed. 321 321 if ( false === $has_access ) { 322 322 323 // User feedback 323 // User feedback. 324 324 bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' ); 325 325 326 // Redirect based on logged in status 326 // Redirect based on logged in status. 327 327 if ( is_user_logged_in() ) { 328 328 $url = bp_loggedin_user_domain(); … … 442 442 public function is_activity() { 443 443 444 // Bail if not looking at a group 444 // Bail if not looking at a group. 445 445 if ( ! bp_is_activity_component() ) 446 446 return; 447 447 448 // Activity Directory 448 // Activity Directory. 449 449 if ( ! bp_displayed_user_id() && ! bp_current_action() ) { 450 450 bp_update_is_directory( true, 'activity' ); … … 457 457 add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) ); 458 458 459 // Single activity 459 // Single activity. 460 460 } elseif ( bp_is_single_activity() ) { 461 461 add_filter( 'bp_get_buddypress_template', array( $this, 'single_template_hierarchy' ) ); … … 475 475 * 476 476 * @param string $templates The templates from bp_get_theme_compat_templates(). 477 *478 477 * @return array $templates Array of custom templates to look for. 479 478 */ … … 492 491 493 492 // Merge new templates with existing stack 494 // @see bp_get_theme_compat_templates() 493 // @see bp_get_theme_compat_templates(). 495 494 $templates = array_merge( (array) $new_templates, $templates ); 496 495 … … 536 535 * 537 536 * @param string $templates The templates from bp_get_theme_compat_templates(). 538 *539 537 * @return array $templates Array of custom templates to look for. 540 538 */ … … 553 551 554 552 // Merge new templates with existing stack 555 // @see bp_get_theme_compat_templates() 553 // @see bp_get_theme_compat_templates(). 556 554 $templates = array_merge( (array) $new_templates, $templates ); 557 555 -
trunk/src/bp-activity/bp-activity-template.php
r10248 r10253 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 … … 114 114 */ 115 115 class BP_Activity_Template { 116 116 117 /** 117 118 * The loop iterator. … … 232 233 $bp = buddypress(); 233 234 234 // Backward compatibility with old method of passing arguments 235 // Backward compatibility with old method of passing arguments. 235 236 if ( !is_array( $args ) || func_num_args() > 1 ) { 236 237 _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); … … 285 286 $this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] ); 286 287 287 // Check if blog/forum replies are disabled 288 // Check if blog/forum replies are disabled. 288 289 $this->disable_blogforum_replies = (bool) bp_core_get_root_option( 'bp-disable-blogforum-comments' ); 289 290 290 // Get an array of the logged in user's favorite activities 291 // Get an array of the logged in user's favorite activities. 291 292 $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) ); 292 293 293 // Fetch specific activity items based on ID's 294 // Fetch specific activity items based on ID's. 294 295 if ( !empty( $include ) ) { 295 296 $this->activities = bp_activity_get_specific( array( … … 306 307 ) ); 307 308 308 // Fetch all activity items 309 // Fetch all activity items. 309 310 } else { 310 311 $this->activities = bp_activity_get( array( … … 330 331 331 332 // The total_activity_count property will be set only if a 332 // 'count_total' query has taken place 333 // 'count_total' query has taken place. 333 334 if ( ! is_null( $this->activities['total'] ) ) { 334 335 if ( ! $max || $max >= (int) $this->activities['total'] ) { … … 355 356 $this->full_name = bp_get_displayed_user_fullname(); 356 357 357 // Fetch parent content for activity comments so we do not have to query in the loop 358 // Fetch parent content for activity comments so we do not have to query in the loop. 358 359 foreach ( (array) $this->activities as $activity ) { 359 360 if ( 'activity_comment' != $activity->type ) { … … 451 452 do_action( 'activity_loop_end' ); 452 453 453 // Do some cleaning up after the loop 454 // Do some cleaning up after the loop. 454 455 $this->rewind_activities(); 455 456 } … … 478 479 } 479 480 480 // loop has just started481 // Loop has just started. 481 482 if ( $this->current_activity == 0 ) { 482 483 … … 605 606 global $activities_template; 606 607 607 // Get BuddyPress 608 // Get BuddyPress. 608 609 $bp = buddypress(); 609 610 610 /** Smart Defaults ********************************************************/ 611 612 // User filtering 611 /* 612 * Smart Defaults. 613 */ 614 615 // User filtering. 613 616 $user_id = bp_displayed_user_id() 614 617 ? bp_displayed_user_id() 615 618 : false; 616 619 617 // Group filtering 620 // Group filtering. 618 621 if ( bp_is_group() ) { 619 622 $object = $bp->groups->id; … … 626 629 } 627 630 628 // The default scope should recognize custom slugs 631 // The default scope should recognize custom slugs. 629 632 $scope = array_key_exists( bp_current_action(), (array) $bp->loaded_components ) 630 633 ? $bp->loaded_components[ bp_current_action() ] 631 634 : bp_current_action(); 632 635 633 // Support for permalinks on single item pages: /groups/my-group/activity/124/ 636 // Support for permalinks on single item pages: /groups/my-group/activity/124/. 634 637 $include = bp_is_current_action( bp_get_activity_slug() ) 635 638 ? bp_action_variable( 0 ) … … 642 645 } 643 646 644 /** Parse Args ************************************************************/ 647 /* 648 * Parse Args. 649 */ 645 650 646 651 // Note: any params used for filtering can be a single value, or multiple 647 652 // values comma separated. 648 653 $r = bp_parse_args( $args, array( 649 'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items650 'include' => $include, // pass an activity_id or string of IDs comma-separated651 'exclude' => false, // pass an activity_id or string of IDs comma-separated652 'in' => false, // comma-separated list or array of activity IDs among which to search653 'sort' => 'DESC', // sort DESC or ASC654 'page' => 1, // which page to load655 'per_page' => 20, // number of items per page656 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679 657 'max' => false, // max number to return654 'display_comments' => 'threaded', // False for none, stream/threaded - show comments in the stream or threaded under items. 655 'include' => $include, // Pass an activity_id or string of IDs comma-separated. 656 'exclude' => false, // Pass an activity_id or string of IDs comma-separated. 657 'in' => false, // Comma-separated list or array of activity IDs among which to search. 658 'sort' => 'DESC', // Sort DESC or ASC. 659 'page' => 1, // Which page to load. 660 'per_page' => 20, // Number of items per page. 661 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679. 662 'max' => false, // Max number to return. 658 663 'fields' => 'all', 659 664 'count_total' => false, 660 665 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide? 661 'spam' => 'ham_only', // Hide spammed items 662 663 // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions) 666 'spam' => 'ham_only', // Hide spammed items. 667 668 // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions). 664 669 'scope' => $scope, 665 670 666 671 // Filtering 667 'user_id' => $user_id, // user_id to filter on 668 'object' => $object, // object to filter on e.g. groups, profile, status, friends669 'action' => false, // action to filter on e.g. activity_update, new_forum_post, profile_updated670 'primary_id' => $primary_id, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.671 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id672 'offset' => false, // return only items >= this ID673 'since' => false, // return only items recorded since this Y-m-d H:i:s date674 675 'meta_query' => false, // filter on activity meta. See WP_Meta_Query for format676 'date_query' => false, // filter by date. See first parameter of WP_Date_Query for format677 'filter_query' => false, // advanced filtering. See BP_Activity_Query for format678 679 // Searching 672 'user_id' => $user_id, // user_id to filter on. 673 'object' => $object, // Object to filter on e.g. groups, profile, status, friends. 674 'action' => false, // Action to filter on e.g. activity_update, new_forum_post, profile_updated. 675 'primary_id' => $primary_id, // Object ID to filter on e.g. a group_id or forum_id or blog_id etc. 676 'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id. 677 'offset' => false, // Return only items >= this ID. 678 'since' => false, // Return only items recorded since this Y-m-d H:i:s date. 679 680 'meta_query' => false, // Filter on activity meta. See WP_Meta_Query for format. 681 'date_query' => false, // Filter by date. See first parameter of WP_Date_Query for format. 682 'filter_query' => false, // Advanced filtering. See BP_Activity_Query for format. 683 684 // Searching. 680 685 'search_terms' => $search_terms_default, 681 686 'update_meta_cache' => true, 682 687 ), 'has_activities' ); 683 688 684 /** Smart Overrides *******************************************************/ 689 /* 690 * Smart Overrides. 691 */ 685 692 686 693 // Translate various values for 'display_comments' 687 694 // This allows disabling comments via ?display_comments=0 688 // or =none or =false. Final true is a strict type check. See #5029 695 // or =none or =false. Final true is a strict type check. See #5029. 689 696 if ( in_array( $r['display_comments'], array( 0, '0', 'none', 'false' ), true ) ) { 690 697 $r['display_comments'] = false; 691 698 } 692 699 693 // Ignore pagination if an offset is passed 700 // Ignore pagination if an offset is passed. 694 701 if ( ! empty( $r['offset'] ) ) { 695 702 $r['page'] = 0; 696 703 } 697 704 698 // Search terms 705 // Search terms. 699 706 if ( ! empty( $_REQUEST['s'] ) && empty( $r['search_terms'] ) ) { 700 707 $r['search_terms'] = $_REQUEST['s']; 701 708 } 702 709 703 // Do not exceed the maximum per page 710 // Do not exceed the maximum per page. 704 711 if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) { 705 712 $r['per_page'] = $r['max']; … … 741 748 } 742 749 743 /** Query *****************************************************************/ 750 /* 751 * Query 752 */ 744 753 745 754 $activities_template = new BP_Activity_Template( $r ); … … 799 808 * 800 809 * @since 2.1.0 810 * 811 * @return string $link 801 812 */ 802 813 function bp_get_activity_load_more_link() { … … 1317 1328 * 1318 1329 * @todo Properly deprecate in favor of bp_activity_type() and 1319 * 1330 * remove redundant echo 1320 1331 * 1321 1332 * @uses bp_activity_type() … … 1461 1472 $bp = buddypress(); 1462 1473 1463 // On activity permalink pages, default to the full-size avatar 1474 // On activity permalink pages, default to the full-size avatar. 1464 1475 $type_default = bp_is_single_activity() ? 'full' : 'thumb'; 1465 1476 … … 1468 1479 $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity; 1469 1480 1470 // Activity user display name 1481 // Activity user display name. 1471 1482 $dn_default = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : ''; 1472 1483 1473 // Prepend some descriptive text to alt 1484 // Prepend some descriptive text to alt. 1474 1485 $alt_default = !empty( $dn_default ) ? sprintf( __( 'Profile picture of %s', 'buddypress' ), $dn_default ) : __( 'Profile picture', 'buddypress' ); 1475 1486 … … 1487 1498 if ( !isset( $height ) && !isset( $width ) ) { 1488 1499 1489 // Backpat 1500 // Backpat. 1490 1501 if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) { 1491 1502 $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height; … … 1494 1505 } 1495 1506 1496 // Backpat 1507 // Backpat. 1497 1508 if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) { 1498 1509 $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width; … … 1587 1598 * @type int|bool $user_id Default: ID of the activity's user. 1588 1599 * } 1589 * @return string The secondary avatar 1600 * @return string The secondary avatar. 1590 1601 */ 1591 1602 function bp_get_activity_secondary_avatar( $args = '' ) { … … 1604 1615 extract( $r, EXTR_SKIP ); 1605 1616 1606 // Set item_id and object (default to user) 1617 // Set item_id and object (default to user). 1607 1618 switch ( $activities_template->activity->component ) { 1608 1619 case 'groups' : … … 1616 1627 $name = ''; 1617 1628 1618 // Only if groups is active 1629 // Only if groups is active. 1619 1630 if ( bp_is_active( 'groups' ) ) { 1620 1631 $group = groups_get_group( array( … … 1691 1702 $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id ); 1692 1703 1693 // If we have no item_id or object, there is no avatar to display 1704 // If we have no item_id or object, there is no avatar to display. 1694 1705 if ( empty( $item_id ) || empty( $object ) ) { 1695 1706 return false; 1696 1707 } 1697 1708 1698 // Get the avatar 1709 // Get the avatar. 1699 1710 $avatar = bp_core_fetch_avatar( array( 1700 1711 'item_id' => $item_id, … … 1745 1756 * @since 1.2.0 1746 1757 * 1747 * @param array $args See bp_get_activity_action() 1758 * @param array $args See bp_get_activity_action(). 1748 1759 * @uses bp_get_activity_action() 1749 1760 */ … … 1758 1769 * 1759 1770 * @global object $activities_template {@link BP_Activity_Template} 1760 * @param array $args Only parameter is "no_timestamp". If true, timestamp is shown in output.1761 1771 * @uses apply_filters_ref_array() To call the 'bp_get_activity_action_pre_meta' hook. 1762 1772 * @uses bp_insert_activity_meta() … … 1789 1799 ) ); 1790 1800 1791 // Prepend the activity action meta (link, time since, etc...) 1801 // Prepend the activity action meta (link, time since, etc...). 1792 1802 if ( ! empty( $action ) && empty( $r['no_timestamp'] ) ) { 1793 1803 $action = bp_insert_activity_meta( $action ); … … 1833 1843 global $activities_template; 1834 1844 1835 // Backwards compatibility if action is not being used 1845 // Backwards compatibility if action is not being used. 1836 1846 if ( empty( $activities_template->activity->action ) && ! empty( $activities_template->activity->content ) ) { 1837 1847 $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content ); … … 1925 1935 * 1926 1936 * @param string $content The activity content. 1927 *1928 1937 * @return string The activity content with the metadata string attached. 1929 1938 */ … … 1931 1940 global $activities_template; 1932 1941 1933 // Strip any legacy time since placeholders from BP 1.0-1.1 1942 // Strip any legacy time since placeholders from BP 1.0-1.1. 1934 1943 $new_content = str_replace( '<span class="time-since">%s</span>', '', $content ); 1935 1944 1936 // Get the time since this activity was recorded 1945 // Get the time since this activity was recorded. 1937 1946 $date_recorded = bp_core_time_since( $activities_template->activity->date_recorded ); 1938 1947 … … 1949 1958 ) ); 1950 1959 1951 // Insert the permalink 1960 // Insert the permalink. 1952 1961 if ( ! bp_is_single_activity() ) { 1953 1962 1954 // Setup variables for activity meta 1963 // Setup variables for activity meta. 1955 1964 $activity_permalink = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 1956 1965 $activity_meta = sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', … … 1966 1975 * @since 1.2.0 1967 1976 * 1968 * @param array $value Array containing the html markup for the activity permalink, after being parsed by sprintf and current activity component. 1977 * @param array $value Array containing the html markup for the activity permalink, after being parsed by 1978 * sprintf and current activity component. 1969 1979 */ 1970 1980 $new_content = apply_filters_ref_array( 'bp_activity_permalink', array( … … 1995 2005 * 1996 2006 * @param object|bool $activity Optional. Falls back on the current item in the loop. 1997 *1998 2007 * @return bool True if can delete, false otherwise. 1999 2008 */ … … 2001 2010 global $activities_template; 2002 2011 2003 // Try to use current activity if none was passed 2012 // Try to use current activity if none was passed. 2004 2013 if ( empty( $activity ) && ! empty( $activities_template->activity ) ) { 2005 2014 $activity = $activities_template->activity; 2006 2015 } 2007 2016 2008 // If current_comment is set, we'll use that in place of the main activity 2017 // If current_comment is set, we'll use that in place of the main activity. 2009 2018 if ( isset( $activity->current_comment ) ) { 2010 2019 $activity = $activity->current_comment; 2011 2020 } 2012 2021 2013 // Assume the user cannot delete the activity item 2022 // Assume the user cannot delete the activity item. 2014 2023 $can_delete = false; 2015 2024 2016 // Only logged in users can delete activity 2025 // Only logged in users can delete activity. 2017 2026 if ( is_user_logged_in() ) { 2018 2027 2019 // Community moderators can always delete activity (at least for now) 2028 // Community moderators can always delete activity (at least for now). 2020 2029 if ( bp_current_user_can( 'bp_moderate' ) ) { 2021 2030 $can_delete = true; … … 2029 2038 } 2030 2039 2031 // Viewing a single item, and this user is an admin of that item 2040 // Viewing a single item, and this user is an admin of that item. 2032 2041 if ( bp_is_single_item() && bp_is_item_admin() ) { 2033 2042 $can_delete = true; … … 2069 2078 * 2070 2079 * @param string $args Unused. Left over from an earlier implementation. 2071 *2072 2080 * @return mixed False on failure, otherwise the activity parent content. 2073 2081 */ … … 2075 2083 global $activities_template; 2076 2084 2077 // Bail if no activity on no item ID 2085 // Bail if no activity on no item ID. 2078 2086 if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) { 2079 2087 return false; 2080 2088 } 2081 2089 2082 // Get the ID of the parent activity content 2090 // Get the ID of the parent activity content. 2083 2091 $parent_id = (int) $activities_template->activity->item_id; 2084 2092 2085 // Bail if no parent content 2093 // Bail if no parent content. 2086 2094 if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) { 2087 2095 return false; 2088 2096 } 2089 2097 2090 // Bail if no action 2098 // Bail if no action. 2091 2099 if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) { 2092 2100 return false; 2093 2101 } 2094 2102 2095 // Content always includes action 2103 // Content always includes action. 2096 2104 $content = $activities_template->activity_parents[ $parent_id ]->action; 2097 2105 2098 // Maybe append activity content, if it exists 2106 // Maybe append activity content, if it exists. 2099 2107 if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) { 2100 2108 $content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content; 2101 2109 } 2102 2110 2103 // Remove the time since content for backwards compatibility 2111 // Remove the time since content for backwards compatibility. 2104 2112 $content = str_replace( '<span class="time-since">%s</span>', '', $content ); 2105 2113 2106 // Remove images 2114 // Remove images. 2107 2115 $content = preg_replace( '/<img[^>]*>/Ui', '', $content ); 2108 2116 … … 2139 2147 global $activities_template; 2140 2148 2141 // Bail if no activity on no item ID 2149 // Bail if no activity on no item ID. 2142 2150 if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) { 2143 2151 return false; 2144 2152 } 2145 2153 2146 // Get the ID of the parent activity content 2154 // Get the ID of the parent activity content. 2147 2155 $parent_id = (int) $activities_template->activity->item_id; 2148 2156 2149 // Bail if no parent item 2157 // Bail if no parent item. 2150 2158 if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) { 2151 2159 return false; 2152 2160 } 2153 2161 2154 // Bail if no parent user ID 2162 // Bail if no parent user ID. 2155 2163 if ( empty( $activities_template->activity_parents[ $parent_id ]->user_id ) ) { 2156 2164 return false; … … 2222 2230 * 2223 2231 * @todo deprecate $args param 2224 *2225 2232 * @todo Given that checks for children already happen in bp_activity_recurse_comments(), 2226 * this function can probably be streamlined or removed. 2227 * 2228 * @param string $args Unused. Left over from an earlier implementation. 2233 * this function can probably be streamlined or removed. 2229 2234 * 2230 2235 * @global object $activities_template {@link BP_Activity_Template} 2231 2236 * @uses bp_activity_recurse_comments() 2232 2237 * 2238 * @param string $args Unused. Left over from an earlier implementation. 2233 2239 * @return bool 2234 2240 */ … … 2251 2257 * @since 1.2.0 2252 2258 * 2253 * @param object $comment The activity object currently being recursed.2254 *2255 2259 * @global object $activities_template {@link BP_Activity_Template} 2256 2260 * @uses locate_template() 2257 2261 * 2262 * @param object $comment The activity object currently being recursed. 2258 2263 * @return bool|string 2259 2264 */ … … 2279 2284 foreach ( (array) $comment->children as $comment_child ) { 2280 2285 2281 // Put the comment into the global so it's available to filters 2286 // Put the comment into the global so it's available to filters. 2282 2287 $activities_template->activity->current_comment = $comment_child; 2283 2288 … … 2475 2480 if ( isset( $activities_template->activity->current_comment->user_fullname ) ) { 2476 2481 2477 $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // backward compatibility2482 $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // Backward compatibility. 2478 2483 } else { 2479 2484 $name = $activities_template->activity->current_comment->display_name; … … 2661 2666 * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook. 2662 2667 * 2663 * @param array $deprecated Deprecated. 2664 * 2668 * @param array|null $deprecated Deprecated. 2665 2669 * @return int $count The activity comment count. 2666 2670 */ … … 2668 2672 global $activities_template; 2669 2673 2670 // Deprecated notice about $args 2674 // Deprecated notice about $args. 2671 2675 if ( ! empty( $deprecated ) ) { 2672 2676 _deprecated_argument( __FUNCTION__, '1.2', sprintf( __( '%1$s no longer accepts arguments. See the inline documentation at %2$s for more details.', 'buddypress' ), __FUNCTION__, __FILE__ ) ); 2673 2677 } 2674 2678 2675 // Get the count using the purpose-built recursive function 2679 // Get the count using the purpose-built recursive function. 2676 2680 $count = ! empty( $activities_template->activity->children ) 2677 2681 ? bp_activity_recurse_comment_count( $activities_template->activity ) … … 2701 2705 * @param object $comment Activity comment object. 2702 2706 * @param int $count The current iteration count. 2703 *2704 2707 * @return int $count The activity comment count. 2705 2708 */ 2706 2709 function bp_activity_recurse_comment_count( $comment, $count = 0 ) { 2707 2710 2708 // Copy the count 2711 // Copy the count. 2709 2712 $new_count = $count; 2710 2713 2711 // Loop through children and recursively count comments 2714 // Loop through children and recursively count comments. 2712 2715 if ( ! empty( $comment->children ) ) { 2713 2716 foreach ( (array) $comment->children as $comment ) { … … 2947 2950 global $activities_template; 2948 2951 2949 // Check that comment exists 2952 // Check that comment exists. 2950 2953 $comment_id = isset( $activities_template->activity->current_comment->id ) 2951 2954 ? $activities_template->activity->current_comment->id 2952 2955 : 0; 2953 2956 2954 // Setup the comment link 2957 // Setup the comment link. 2955 2958 $comment_link = ! empty( $comment_id ) 2956 2959 ? '#acomment-' .$comment_id 2957 2960 : false; 2958 2961 2959 // Append comment ID to end of activity permalink 2962 // Append comment ID to end of activity permalink. 2960 2963 $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . $comment_link; 2961 2964 … … 3141 3144 $class = 'delete-activity'; 3142 3145 3143 // Determine if we're on a single activity page, and customize accordingly 3146 // Determine if we're on a single activity page, and customize accordingly. 3144 3147 if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { 3145 3148 $class = 'delete-activity-single'; … … 3191 3194 $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id ); 3192 3195 3193 // Determine if we're on a single activity page, and customize accordingly 3196 // Determine if we're on a single activity page, and customize accordingly. 3194 3197 if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { 3195 3198 $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url ); … … 3237 3240 * 3238 3241 * @param int $user_id If empty, will fall back on displayed user. 3239 *3240 3242 * @return string|bool $latest_update The activity latest update link. 3241 3243 * False on failure. … … 3321 3323 ) ); 3322 3324 3323 // Define local variable 3325 // Define local variable. 3324 3326 $component_links = array(); 3325 3327 3326 // Fetch the names of components that have activity recorded in the DB 3328 // Fetch the names of components that have activity recorded in the DB. 3327 3329 $components = BP_Activity_Activity::get_recorded_components(); 3328 3330 … … 3333 3335 foreach ( (array) $components as $component ) { 3334 3336 3335 // Skip the activity comment filter 3337 // Skip the activity comment filter. 3336 3338 if ( 'activity' == $component ) { 3337 3339 continue; … … 3411 3413 $bp = buddypress(); 3412 3414 3413 // Assume activity can be commented on 3415 // Assume activity can be commented on. 3414 3416 $can_comment = true; 3415 3417 3416 // Determine ability to comment based on activity action name 3418 // Determine ability to comment based on activity action name. 3417 3419 $activity_action = bp_get_activity_action_name(); 3418 3420 … … 3466 3468 function bp_activity_can_comment_reply( $comment = false ) { 3467 3469 3468 // Assume activity can be commented on 3470 // Assume activity can be commented on. 3469 3471 $can_comment = true; 3470 3472 3471 // Check that comment exists 3473 // Check that comment exists. 3472 3474 if ( empty( $comment ) ) { 3473 3475 $comment = bp_activity_current_comment(); … … 3476 3478 if ( ! empty( $comment ) ) { 3477 3479 3478 // Fall back on current comment in activity loop 3480 // Fall back on current comment in activity loop. 3479 3481 $comment_depth = isset( $comment->depth ) 3480 3482 ? intval( $comment->depth ) 3481 3483 : bp_activity_get_comment_depth(); 3482 3484 3483 // Threading is turned on, so check the depth 3485 // Threading is turned on, so check the depth. 3484 3486 if ( get_option( 'thread_comments' ) ) { 3485 3487 $can_comment = (bool) ( $comment_depth < get_option( 'thread_comments_depth' ) ); 3486 3488 3487 // No threading for comment replies if no threading for comments 3489 // No threading for comment replies if no threading for comments. 3488 3490 } else { 3489 3491 $can_comment = false; … … 3548 3550 * 3549 3551 * @param int $user_id ID of user being queried. Default: displayed user ID. 3550 *3551 3552 * @return int The total favorite count for the specified user. 3552 3553 */ … … 3555 3556 3556 3557 if ( bp_activity_can_favorite() ) { 3557 // Default to displayed user if none is passed 3558 // Default to displayed user if none is passed. 3558 3559 $user_id = empty( $user_id ) 3559 3560 ? bp_displayed_user_id() 3560 3561 : $user_id; 3561 3562 3562 // Get user meta if user ID exists 3563 // Get user meta if user ID exists. 3563 3564 if ( ! empty( $user_id ) ) { 3564 3565 $retval = bp_activity_total_favorites_for_user( $user_id ); … … 3600 3601 * 3601 3602 * @param int $user_id ID of user being queried. Default: displayed user ID. 3602 *3603 3603 * @return int The total mention count for the specified user. 3604 3604 */ 3605 3605 function bp_get_total_mention_count_for_user( $user_id = 0 ) { 3606 3606 3607 // Default to displayed user if none is passed 3607 // Default to displayed user if none is passed. 3608 3608 $user_id = empty( $user_id ) 3609 3609 ? bp_displayed_user_id() 3610 3610 : $user_id; 3611 3611 3612 // Get user meta if user ID exists 3612 // Get user meta if user ID exists. 3613 3613 $retval = ! empty( $user_id ) 3614 3614 ? bp_get_user_meta( $user_id, 'bp_new_mention_count', true ) … … 3652 3652 function bp_get_send_public_message_link() { 3653 3653 3654 // No link if not logged in, not looking at someone else's profile 3654 // No link if not logged in, not looking at someone else's profile. 3655 3655 if ( ! is_user_logged_in() || ! bp_is_user() || bp_is_my_profile() ) { 3656 3656 $retval = ''; … … 3678 3678 * @param array $activity Array of activities generated from {@link bp_activity_get()}. 3679 3679 * @param array $activity_ids Used for recursion purposes in this function. 3680 *3681 3680 * @return array 3682 3681 */ … … 3721 3720 * @uses apply_filters() To call the 'bp_get_mentioned_user_display_name' hook. 3722 3721 * 3723 * @param int|string|bool User ID or username. 3724 * 3722 * @param int|string|bool $user_id_or_username User ID or username. 3725 3723 * @return string The mentioned user's display name. 3726 3724 */ 3727 3725 function bp_get_mentioned_user_display_name( $user_id_or_username = false ) { 3728 3726 3729 // Get user display name 3727 // Get user display name. 3730 3728 $name = bp_core_get_user_displayname( $user_id_or_username ); 3731 3729 3732 // If user somehow has no name, return this really lame string 3730 // If user somehow has no name, return this really lame string. 3733 3731 if ( empty( $name ) ) { 3734 3732 $name = __( 'a user', 'buddypress' ); … … 3868 3866 ) ); 3869 3867 3870 // Get the user IDs of everyone who has left a comment to the current activity item 3868 // Get the user IDs of everyone who has left a comment to the current activity item. 3871 3869 $user_ids = bp_activity_get_comments_user_ids(); 3872 3870 $output = array(); … … 3876 3874 foreach ( (array) $user_ids as $user_id ) { 3877 3875 3878 // Skip an empty user ID 3876 // Skip an empty user ID. 3879 3877 if ( empty( $user_id ) ) { 3880 3878 continue; 3881 3879 } 3882 3880 3883 // Get profile link for this user 3881 // Get profile link for this user. 3884 3882 $profile_link = bp_core_get_user_domain( $user_id ); 3885 3883 3886 // Get avatar for this user 3884 // Get avatar for this user. 3887 3885 $image_html = bp_core_fetch_avatar( array( 3888 3886 'item_id' => $user_id, … … 3893 3891 ) ); 3894 3892 3895 // If user has link & avatar, add them to the output array 3893 // If user has link & avatar, add them to the output array. 3896 3894 if ( ! empty( $profile_link ) && ! empty( $image_html ) ) { 3897 3895 $output[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $profile_link ), $image_html ); … … 3899 3897 } 3900 3898 3901 // If output array is not empty, wrap everything in some list items 3899 // If output array is not empty, wrap everything in some list items. 3902 3900 if ( ! empty( $output ) ) { 3903 3901 $retval = '<li>' . implode( '</li><li>', $output ) . '</li>'; … … 3947 3945 * 3948 3946 * @param array $comments Array of {@link BP_Activity_Activity} items. 3949 *3950 3947 * @return array Array of user IDs. 3951 3948 */ 3952 3949 function bp_activity_recurse_comments_user_ids( array $comments = array() ) { 3953 3950 3954 // Default user ID's array 3951 // Default user ID's array. 3955 3952 $user_ids = array(); 3956 3953 3957 // Loop through comments and try to get user ID's 3954 // Loop through comments and try to get user ID's. 3958 3955 if ( ! empty( $comments ) ) { 3959 3956 foreach ( $comments as $comment ) { … … 3965 3962 } 3966 3963 3967 // Add user ID to array 3964 // Add user ID to array. 3968 3965 $user_ids[] = $comment->user_id; 3969 3966 3970 // Check for commentception 3967 // Check for commentception. 3971 3968 if ( ! empty( $comment->children ) ) { 3972 3969 $user_ids = array_merge( $user_ids, bp_activity_recurse_comments_user_ids( $comment->children ) ); … … 4037 4034 natsort( $activities ); 4038 4035 4039 // Loop through the activity types and output markup 4036 // Loop through the activity types and output markup. 4040 4037 foreach ( $activities as $type => $description ) { 4041 4038 4042 // See if we need to preselect the current type 4039 // See if we need to preselect the current type. 4043 4040 $checked = checked( true, in_array( $type, (array) $args['selected'] ), false ); 4044 4041 $selected = selected( true, in_array( $type, (array) $args['selected'] ), false ); 4045 4042 4046 // Switch output based on the element 4043 // Switch output based on the element. 4047 4044 switch ( $output ) { 4048 4045 case 'select' : … … 4069 4066 } 4070 4067 4071 // Backpat with BP-Default for dropdown boxes only 4068 // Backpat with BP-Default for dropdown boxes only. 4072 4069 if ( 'select' === $output ) { 4073 4070 do_action( 'bp_activity_filter_options' ); … … 4153 4150 function bp_get_member_activity_feed_link() { 4154 4151 4155 // Single member activity feed link 4152 // Single member activity feed link. 4156 4153 if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) ) { 4157 4154 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/'; 4158 4155 4159 // Friend feed link 4156 // Friend feed link. 4160 4157 } elseif ( bp_is_active( 'friends' ) && bp_is_current_action( bp_get_friends_slug() ) ) { 4161 4158 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/'; 4162 4159 4163 // Group feed link 4160 // Group feed link. 4164 4161 } elseif ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) { 4165 4162 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/'; 4166 4163 4167 // Favorites activity feed link 4164 // Favorites activity feed link. 4168 4165 } elseif ( 'favorites' === bp_current_action() ) { 4169 4166 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/'; 4170 4167 4171 // Mentions activity feed link 4168 // Mentions activity feed link. 4172 4169 } elseif ( ( 'mentions' === bp_current_action() ) && bp_activity_do_mentions() ) { 4173 4170 $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/'; 4174 4171 4175 // No feed link 4172 // No feed link. 4176 4173 } else { 4177 4174 $link = ''; … … 4395 4392 global $activities_template; 4396 4393 4397 // Get the content, if exists 4394 // Get the content, if exists. 4398 4395 $content = ! empty( $activities_template->activity->content ) 4399 4396 ? $activities_template->activity->content 4400 4397 : ''; 4401 4398 4402 // Perform a few string conversions on the content, if it's not empty 4399 // Perform a few string conversions on the content, if it's not empty. 4403 4400 if ( ! empty( $content ) ) { 4404 4401 $content = ent2ncr( convert_chars( str_replace( '%s', '', $content ) ) ); … … 4438 4435 * 4439 4436 * @param string $context The current context. 'activity', 'member', 4440 * 4437 * 'member_groups', 'group'. 4441 4438 * @uses bp_get_activity_show_filters() 4442 4439 */ … … 4450 4447 * 4451 4448 * @param string $context The current context. 'activity', 'member', 4452 * 4449 * 'member_groups', 'group'. 4453 4450 * 4454 4451 * @return string HTML for <option> values. 4455 4452 */ 4456 4453 function bp_get_activity_show_filters( $context = '' ) { 4457 // Set default context based on current page 4454 // Set default context based on current page. 4458 4455 if ( empty( $context ) ) { 4459 4456 4460 4457 // On member pages, default to 'member', unless this 4461 // is a user's Groups activity 4458 // is a user's Groups activity. 4462 4459 if ( bp_is_user() ) { 4463 4460 if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) { … … 4467 4464 } 4468 4465 4469 // On individual group pages, default to 'group' 4466 // On individual group pages, default to 'group'. 4470 4467 } elseif ( bp_is_active( 'groups' ) && bp_is_group() ) { 4471 4468 $context = 'group'; 4472 4469 4473 // 'activity' everywhere else 4470 // 'activity' everywhere else. 4474 4471 } else { 4475 4472 $context = 'activity'; … … 4487 4484 } 4488 4485 4489 // Friends activity collapses two filters into one 4486 // Friends activity collapses two filters into one. 4490 4487 if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) { 4491 4488 $action['key'] = 'friendship_accepted,friendship_created'; … … 4506 4503 $filters = apply_filters( 'bp_get_activity_show_filters_options', $filters, $context ); 4507 4504 4508 // Build the options output 4505 // Build the options output. 4509 4506 $output = ''; 4510 4507 -
trunk/src/bp-activity/classes/class-bp-activity-activity.php
r10217 r10253 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 … … 164 164 } 165 165 166 // Generate dynamic 'action' when possible 166 // Generate dynamic 'action' when possible. 167 167 $action = bp_activity_generate_action_string( $this ); 168 168 if ( false !== $action ) { … … 170 170 171 171 // If no callback is available, use the literal string from 172 // the database row 172 // the database row. 173 173 } elseif ( ! empty( $row->action ) ) { 174 174 $this->action = $row->action; 175 175 176 // Provide a fallback to avoid PHP notices 176 // Provide a fallback to avoid PHP notices. 177 177 } else { 178 178 $this->action = ''; … … 235 235 } 236 236 237 // If this is a new activity item, set the $id property 237 // If this is a new activity item, set the $id property. 238 238 if ( empty( $this->id ) ) { 239 239 $this->id = $wpdb->insert_id; … … 271 271 * @param array $args { 272 272 * An array of arguments. All items are optional. 273 *274 273 * @type int $page Which page of results to fetch. Using page=1 without per_page will result 275 274 * in no pagination. Default: 1. … … 296 295 * } 297 296 * @return array The array returned has two keys: 298 * - 'total' is the count of located activities299 * - 'activities' is an array of the located activities297 * - 'total' is the count of located activities 298 * - 'activities' is an array of the located activities 300 299 */ 301 300 public static function get( $args = array() ) { 302 301 global $wpdb; 303 302 304 // Backward compatibility with old method of passing arguments 303 // Backward compatibility with old method of passing arguments. 305 304 if ( !is_array( $args ) || func_num_args() > 1 ) { 306 305 _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); … … 326 325 $bp = buddypress(); 327 326 $r = wp_parse_args( $args, array( 328 'page' => 1, // The current page 329 'per_page' => 25, // Activity items per page 330 'max' => false, // Max number of items to return 331 'fields' => 'all', 332 'sort' => 'DESC', // ASC or DESC 333 'exclude' => false, // Array of ids to exclude 334 'in' => false, // Array of ids to limit query by (IN) 335 'meta_query' => false, // Filter by activitymeta 336 'date_query' => false, // Filter by date 337 'filter_query' => false, // Advanced filtering - see BP_Activity_Query 338 'filter' => false, // See self::get_filter_sql() 339 'scope' => false, // Preset activity arguments 340 'search_terms' => false, // Terms to search by 341 'display_comments' => false, // Whether to include activity comments 342 'show_hidden' => false, // Show items marked hide_sitewide 343 'spam' => 'ham_only', // Spam status 344 'update_meta_cache' => true, 345 'count_total' => false, 327 'page' => 1, // The current page. 328 'per_page' => 25, // Activity items per page. 329 'max' => false, // Max number of items to return. 330 'fields' => 'all', // Fields to include. 331 'sort' => 'DESC', // ASC or DESC. 332 'exclude' => false, // Array of ids to exclude. 333 'in' => false, // Array of ids to limit query by (IN). 334 'meta_query' => false, // Filter by activitymeta. 335 'date_query' => false, // Filter by date. 336 'filter_query' => false, // Advanced filtering - see BP_Activity_Query. 337 'filter' => false, // See self::get_filter_sql(). 338 'scope' => false, // Preset activity arguments. 339 'search_terms' => false, // Terms to search by. 340 'display_comments' => false, // Whether to include activity comments. 341 'show_hidden' => false, // Show items marked hide_sitewide. 342 'spam' => 'ham_only', // Spam status. 343 'update_meta_cache' => true, // Whether or not to update meta cache. 344 'count_total' => false, // Whether or not to use count_total. 346 345 ) ); 347 346 348 // Select conditions 347 // Select conditions. 349 348 $select_sql = "SELECT DISTINCT a.id"; 350 349 … … 353 352 $join_sql = ''; 354 353 355 // Where conditions 354 // Where conditions. 356 355 $where_conditions = array(); 357 356 358 // Excluded types 357 // Excluded types. 359 358 $excluded_types = array(); 360 359 361 // Scope takes precedence 360 // Scope takes precedence. 362 361 if ( ! empty( $r['scope'] ) ) { 363 362 $scope_query = self::get_scope_query_sql( $r['scope'], $r ); 364 363 365 // Add our SQL conditions if matches were found 364 // Add our SQL conditions if matches were found. 366 365 if ( ! empty( $scope_query['sql'] ) ) { 367 366 $where_conditions['scope_query_sql'] = $scope_query['sql']; 368 367 } 369 368 370 // override some arguments if needed369 // Override some arguments if needed. 371 370 if ( ! empty( $scope_query['override'] ) ) { 372 371 $r = self::array_replace_recursive( $r, $scope_query['override'] ); 373 372 } 374 373 375 // Advanced filtering 374 // Advanced filtering. 376 375 } elseif ( ! empty( $r['filter_query'] ) ) { 377 376 $filter_query = new BP_Activity_Query( $r['filter_query'] ); … … 382 381 } 383 382 384 // Regular filtering 383 // Regular filtering. 385 384 if ( $r['filter'] && $filter_sql = BP_Activity_Activity::get_filter_sql( $r['filter'] ) ) { 386 385 $where_conditions['filter_sql'] = $filter_sql; 387 386 } 388 387 389 // Spam 388 // Spam. 390 389 if ( 'ham_only' == $r['spam'] ) { 391 390 $where_conditions['spam_sql'] = 'a.is_spam = 0'; … … 394 393 } 395 394 396 // Searching 395 // Searching. 397 396 if ( $r['search_terms'] ) { 398 397 $search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%'; … … 400 399 } 401 400 402 // Sorting 401 // Sorting. 403 402 $sort = $r['sort']; 404 403 if ( $sort != 'ASC' && $sort != 'DESC' ) { … … 411 410 } 412 411 413 // Exclude specified items 412 // Exclude specified items. 414 413 if ( ! empty( $r['exclude'] ) ) { 415 414 $exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) ); … … 417 416 } 418 417 419 // The specific ids to which you want to limit the query 418 // The specific ids to which you want to limit the query. 420 419 if ( ! empty( $r['in'] ) ) { 421 420 $in = implode( ',', wp_parse_id_list( $r['in'] ) ); … … 423 422 } 424 423 425 // Process meta_query into SQL 424 // Process meta_query into SQL. 426 425 $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] ); 427 426 … … 434 433 } 435 434 436 // Process date_query into SQL 435 // Process date_query into SQL. 437 436 $date_query_sql = self::get_date_query_sql( $r['date_query'] ); 438 437 … … 449 448 450 449 // Exclude 'last_activity' items unless the 'action' filter has 451 // been explicitly set 450 // been explicitly set. 452 451 if ( empty( $r['filter']['object'] ) ) { 453 452 $excluded_types[] = 'last_activity'; 454 453 } 455 454 456 // Build the excluded type sql part 455 // Build the excluded type sql part. 457 456 if ( ! empty( $excluded_types ) ) { 458 457 $not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'"; … … 473 472 $where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql ); 474 473 475 // Join the where conditions together 474 // Join the where conditions together. 476 475 $where_sql = 'WHERE ' . join( ' AND ', $where_conditions ); 477 476 … … 488 487 if ( false !== strpos( $where_sql, $index ) ) { 489 488 $the_index = $index; 490 break; // Take the first one we find 489 break; // Take the first one we find. 491 490 } 492 491 } … … 498 497 } 499 498 500 // Sanitize page and per_page parameters 499 // Sanitize page and per_page parameters. 501 500 $page = absint( $r['page'] ); 502 501 $per_page = absint( $r['per_page'] ); … … 521 520 if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) { 522 521 523 // Legacy queries joined against the user table 522 // Legacy queries joined against the user table. 524 523 $select_sql = "SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name"; 525 524 $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID"; … … 528 527 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page ); 529 528 530 /** this filter is documented in bp-activity/bp-activity-classes.php */529 /** This filter is documented in bp-activity/bp-activity-classes.php */ 531 530 $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) ); 532 531 } else { … … 548 547 549 548 } else { 550 // Query first for activity IDs 549 // Query first for activity IDs. 551 550 $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}"; 552 551 553 552 if ( ! empty( $per_page ) && ! empty( $page ) ) { 554 553 // We query for $per_page + 1 items in order to 555 // populate the has_more_items flag 554 // populate the has_more_items flag. 556 555 $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 ); 557 556 } … … 572 571 573 572 // If we've fetched more than the $per_page value, we 574 // can discard the extra now 573 // can discard the extra now. 575 574 if ( ! empty( $per_page ) && count( $activity_ids ) === $per_page + 1 ) { 576 575 array_pop( $activity_ids ); … … 585 584 586 585 if ( 'ids' !== $r['fields'] ) { 587 // Get the fullnames of users so we don't have to query in the loop 586 // Get the fullnames of users so we don't have to query in the loop. 588 587 $activities = self::append_user_fullnames( $activities ); 589 588 590 // Get activity meta 589 // Get activity meta. 591 590 $activity_ids = array(); 592 591 foreach ( (array) $activities as $activity ) { … … 602 601 } 603 602 604 // Pre-fetch data associated with activity users and other objects 603 // Pre-fetch data associated with activity users and other objects. 605 604 BP_Activity_Activity::prefetch_object_data( $activities ); 606 605 607 // Generate action strings 606 // Generate action strings. 608 607 $activities = BP_Activity_Activity::generate_action_strings( $activities ); 609 608 } … … 611 610 $retval['activities'] = $activities; 612 611 613 // If $max is set, only return up to the max results 612 // If $max is set, only return up to the max results. 614 613 if ( ! empty( $r['count_total'] ) ) { 615 614 … … 644 643 * 645 644 * @param array $activity_ids Array of activity IDs. 646 *647 645 * @return array 648 646 */ … … 650 648 global $wpdb; 651 649 652 // Bail if no activity ID's passed 650 // Bail if no activity ID's passed. 653 651 if ( empty( $activity_ids ) ) { 654 652 return array(); 655 653 } 656 654 657 // Get BuddyPress 655 // Get BuddyPress. 658 656 $bp = buddypress(); 659 657 … … 661 659 $uncached_ids = bp_get_non_cached_ids( $activity_ids, 'bp_activity' ); 662 660 663 // Prime caches as necessary 661 // Prime caches as necessary. 664 662 if ( ! empty( $uncached_ids ) ) { 665 // Format the activity ID's for use in the query below 663 // Format the activity ID's for use in the query below. 666 664 $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) ); 667 665 668 // Fetch data from activity table, preserving order 666 // Fetch data from activity table, preserving order. 669 667 $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$uncached_ids_sql})"); 670 668 671 669 // Put that data into the placeholders created earlier, 672 // and add it to the cache 670 // and add it to the cache. 673 671 foreach ( (array) $queried_adata as $adata ) { 674 672 wp_cache_set( $adata->id, $adata, 'bp_activity' ); … … 676 674 } 677 675 678 // Now fetch data from the cache 676 // Now fetch data from the cache. 679 677 foreach ( $activity_ids as $activity_id ) { 680 678 $activities[] = wp_cache_get( $activity_id, 'bp_activity' ); 681 679 } 682 680 683 // Then fetch user data 681 // Then fetch user data. 684 682 $user_query = new BP_User_Query( array( 685 683 'user_ids' => wp_list_pluck( $activities, 'user_id' ), … … 687 685 ) ); 688 686 689 // Associated located user data with activity items 687 // Associated located user data with activity items. 690 688 foreach ( $activities as $a_index => $a_item ) { 691 689 $a_user_id = intval( $a_item->user_id ); … … 709 707 * 710 708 * @param array $activities Activities array. 711 *712 709 * @return array 713 710 */ … … 750 747 * 751 748 * @param array $activities Array of activities. 752 *753 749 * @return array $activities Array of activities. 754 750 */ … … 776 772 * 777 773 * @param array $activities Array of activities. 778 *779 774 * @return array 780 775 */ … … 805 800 * @param array $meta_query An array of meta_query filters. See the 806 801 * documentation for WP_Meta_Query for details. 807 *808 802 * @return array $sql_array 'join' and 'where' clauses. 809 803 */ … … 820 814 821 815 // WP_Meta_Query expects the table name at 822 // $wpdb->activitymeta 816 // $wpdb->activitymeta. 823 817 $wpdb->activitymeta = buddypress()->activity->table_name_meta; 824 818