Changeset 10253 for trunk/src/bp-activity/bp-activity-filters.php
- Timestamp:
- 10/12/2015 05:45:14 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.