Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/12/2015 05:45:14 AM (9 years ago)
Author:
tw2113
Message:

Further documentation cleanup for Activity Component.

See #6396.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-filters.php

    r10077 r10253  
    77 */
    88
    9 // Exit if accessed directly
     9// Exit if accessed directly.
    1010defined( 'ABSPATH' ) || exit;
    1111
    1212/** Filters *******************************************************************/
    1313
    14 // Apply WordPress defined filters
     14// Apply WordPress defined filters.
    1515add_filter( 'bp_get_activity_action',                'bp_activity_filter_kses', 1 );
    1616add_filter( 'bp_get_activity_content_body',          'bp_activity_filter_kses', 1 );
     
    7878add_filter( 'bp_activity_primary_link_before_save',  'esc_url_raw' );
    7979
    80 // Apply BuddyPress-defined filters
     80// Apply BuddyPress-defined filters.
    8181add_filter( 'bp_get_activity_content',               'bp_activity_make_nofollow_filter' );
    8282add_filter( 'bp_get_activity_content_body',          'bp_activity_make_nofollow_filter' );
     
    101101/** Actions *******************************************************************/
    102102
    103 // At-name filter
     103// At-name filter.
    104104add_action( 'bp_activity_before_save', 'bp_activity_at_name_filter_updates' );
    105105
    106 // Activity stream moderation
     106// Activity stream moderation.
    107107add_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 );
    108108add_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys',  2, 1 );
     
    142142function bp_activity_check_moderation_keys( $activity ) {
    143143
    144     // Only check specific types of activity updates
     144    // Only check specific types of activity updates.
    145145    if ( !in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
    146146        return;
    147147
    148148    // 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.
    150150    if ( !bp_core_check_for_moderation( $activity->user_id, '', $activity->content ) )
    151151        $activity->component = false;
     
    161161function bp_activity_check_blacklist_keys( $activity ) {
    162162
    163     // Only check specific types of activity updates
     163    // Only check specific types of activity updates.
    164164    if ( ! in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
    165165        return;
    166166
    167     // Mark as spam
     167    // Mark as spam.
    168168    if ( ! bp_core_check_for_blacklist( $activity->user_id, '', $activity->content ) )
    169169        bp_activity_mark_as_spam( $activity, 'by_blacklist' );
     
    179179 *
    180180 * @param string $content The activity content.
    181  *
    182181 * @return string $content Filtered activity content.
    183182 */
     
    223222 * @param string $content     The contents of a given item.
    224223 * @param int    $activity_id The activity id. Deprecated.
    225  *
    226224 * @return string $content Content filtered for mentions.
    227225 */
     
    233231    }
    234232
    235     // Try to find mentions
     233    // Try to find mentions.
    236234    $usernames = bp_activity_find_mentions( $content );
    237235
     
    241239
    242240    // We don't want to link @mentions that are inside of links, so we
    243     // temporarily remove them
     241    // temporarily remove them.
    244242    $replace_count = 0;
    245243    $replacements = array();
    246244    foreach ( $usernames as $username ) {
    247         // prevent @ name linking inside <a> tags
     245        // Prevent @ name linking inside <a> tags.
    248246        preg_match_all( '/(<a.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches );
    249247        if ( ! empty( $content_matches[1] ) ) {
     
    256254    }
    257255
    258     // Linkify the mentions with the username
     256    // Linkify the mentions with the username.
    259257    foreach ( (array) $usernames as $user_id => $username ) {
    260258        $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
    261259    }
    262260
    263     // put everything back
     261    // Put everything back.
    264262    if ( ! empty( $replacements ) ) {
    265263        foreach ( $replacements as $placeholder => $original ) {
     
    268266    }
    269267
    270     // Return the content
     268    // Return the content.
    271269    return $content;
    272270}
     
    282280 * @uses bp_activity_find_mentions()
    283281 *
    284  * @param BP_Activity_Activity $activity
     282 * @param BP_Activity_Activity $activity Activity Object.
    285283 */
    286284function bp_activity_at_name_filter_updates( $activity ) {
     
    294292        return;
    295293
    296     // Try to find mentions
     294    // Try to find mentions.
    297295    $usernames = bp_activity_find_mentions( $activity->content );
    298296
    299297    // We have mentions!
    300298    if ( ! empty( $usernames ) ) {
    301         // Replace @mention text with userlinks
     299        // Replace @mention text with userlinks.
    302300        foreach( (array) $usernames as $user_id => $username ) {
    303301            $activity->content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $activity->content );
    304302        }
    305303
    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.
    307305        add_action( 'bp_activity_after_save', 'bp_activity_at_name_send_emails' );
    308306
    309         // temporary variable to avoid having to run bp_activity_find_mentions() again
     307        // Temporary variable to avoid having to run bp_activity_find_mentions() again.
    310308        buddypress()->activity->mentioned_users = $usernames;
    311309    }
     
    332330        return;
    333331
    334     // Grab our temporary variable from bp_activity_at_name_filter_updates()
     332    // Grab our temporary variable from bp_activity_at_name_filter_updates().
    335333    $usernames = buddypress()->activity->mentioned_users;
    336334
    337     // Get rid of temporary variable
     335    // Get rid of temporary variable.
    338336    unset( buddypress()->activity->mentioned_users );
    339337
    340     // Send @mentions and setup BP notifications
     338    // Send @mentions and setup BP notifications.
    341339    foreach( (array) $usernames as $user_id => $username ) {
    342340
     
    353351        }
    354352
    355         // Updates mention count for the user
     353        // Updates mention count for the user.
    356354        bp_activity_update_mention_count_for_user( $user_id, $activity->id );
    357355    }
     
    364362 *
    365363 * @param string $text Activity text.
    366  *
    367364 * @return string $text Text with rel=nofollow added to any links.
    368365 */
     
    377374     *
    378375     * @param array $matches Items matched by preg_replace_callback() in bp_activity_make_nofollow_filter().
    379      *
    380376     * @return string $text Link with rel=nofollow added.
    381377     */
     
    402398 *
    403399 * @param string $text The original activity entry text.
    404  *
    405400 * @return string $excerpt The truncated text.
    406401 */
     
    420415    );
    421416
    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.
    423418    if ( ! $maybe_truncate_text || bp_is_single_activity() ) {
    424419        return $text;
     
    443438    $excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 );
    444439
    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.
    447441    $excerpt        = bp_create_excerpt( $text, $excerpt_length, array( 'ending' => __( '&hellip;', 'buddypress' ) ) );
    448442
    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     */
    452448    if ( $excerpt != strip_shortcodes( $text ) ) {
    453449        $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
     
    476472 *
    477473 * @param array $js_handles The original dependencies.
    478  *
    479474 * @return array $js_handles The new dependencies.
    480475 */
     
    496491 * @since 2.0.0
    497492 *
    498  * @param string $classes
    499  *
     493 * @param string $classes Array of classes for most recent activity item.
    500494 * @return string $classes
    501495 */
     
    516510 * @since 2.0.0
    517511 *
    518  * @param string $classes
    519  *
     512 * @param string $classes Array of classes for timestamp.
    520513 * @return string $classes
    521514 */
     
    545538 * @uses bp_activity_get_last_updated() to get the recorded date of the last activity.
    546539 *
    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.
    550542 * @return array $response
    551543 */
     
    556548
    557549    // 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.
    559551    $activity_latest_args = bp_parse_args(
    560552        bp_ajax_querystring( 'activity' ),
     
    570562    $last_activity_recorded = 0;
    571563
    572     // Temporarily add a just-posted class for new activity items
     564    // Temporarily add a just-posted class for new activity items.
    573565    add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
    574566
     
    591583    ob_end_clean();
    592584
    593     // Remove the temporary filter
     585    // Remove the temporary filter.
    594586    remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
    595587
     
    609601 *
    610602 * @param array $strings Localized strings.
    611  *
    612603 * @return array $strings
    613604 */
     
    672663 * @param array $retval Empty array by default.
    673664 * @param array $filter Current activity arguments.
    674  *
    675  * @return array
     665 * @return array $retval
    676666 */
    677667function bp_activity_filter_just_me_scope( $retval = array(), $filter = array() ) {
    678668
    679     // Determine the user_id
     669    // Determine the user_id.
    680670    if ( ! empty( $filter['user_id'] ) ) {
    681671        $user_id = $filter['user_id'];
     
    703693        $show_hidden,
    704694
    705         // overrides
     695        // Overrides.
    706696        'override' => array(
    707697            'display_comments' => 'stream',
     
    722712 * @param array $retval Empty array by default.
    723713 * @param array $filter Current activity arguments.
    724  *
    725  * @return array
     714 * @return array $retval
    726715 */
    727716function bp_activity_filter_favorites_scope( $retval = array(), $filter = array() ) {
    728717
    729     // Determine the user_id
     718    // Determine the user_id.
    730719    if ( ! empty( $filter['user_id'] ) ) {
    731720        $user_id = $filter['user_id'];
     
    736725    }
    737726
    738     // Determine the favorites
     727    // Determine the favorites.
    739728    $favs = bp_activity_get_user_favorites( $user_id );
    740729    if ( empty( $favs ) ) {
     
    760749        $show_hidden,
    761750
    762         // overrides
     751        // Overrides.
    763752        'override' => array(
    764753            'display_comments' => true,
     
    780769 * @param array $retval Empty array by default.
    781770 * @param array $filter Current activity arguments.
    782  *
    783  * @return array
     771 * @return array $retval
    784772 */
    785773function bp_activity_filter_mentions_scope( $retval = array(), $filter = array() ) {
     
    790778    }
    791779
    792     // Determine the user_id
     780    // Determine the user_id.
    793781    if ( ! empty( $filter['user_id'] ) ) {
    794782        $user_id = $filter['user_id'];
     
    819807        $show_hidden,
    820808
    821         // overrides
     809        // Overrides.
    822810        'override' => array(
    823811
    824             // clear search terms so 'mentions' scope works with other scopes
     812            // Clear search terms so 'mentions' scope works with other scopes.
    825813            'search_terms' => false,
    826814
Note: See TracChangeset for help on using the changeset viewer.