Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/05/2011 08:53:31 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Add moderation keys and blacklist keys filters to Activity stream component. Introduce function for gathering the activity types that should be checked, and default to updates and comments per the Akismet extension. See #3732.

File:
1 edited

Legend:

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

    r5259 r5277  
    1010// Exit if accessed directly
    1111if ( !defined( 'ABSPATH' ) ) exit;
     12
     13/** Filters *******************************************************************/
    1214
    1315// Apply WordPress defined filters
    … …  
    8789
    8890add_filter( 'bp_get_activity_parent_content',        'bp_create_excerpt' );
     91
     92add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
     93add_filter( 'bp_get_activity_content',      'bp_activity_truncate_entry', 5 );
     94
     95/** Actions *******************************************************************/
     96
     97// At-name filter
     98add_action( 'bp_activity_after_save', 'bp_activity_at_name_filter_updates' );
     99
     100// Activity stream moderation
     101add_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 );
     102add_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys',  2, 1 );
     103
     104/** Functions *****************************************************************/
     105
     106/**
     107 * Types of activity stream items to check against
     108 *
     109 * @since BuddyPress (1.6)
     110 */
     111function bp_activity_get_moderated_activity_types() {
     112        $types = array(
     113                'activity_comment',
     114                'activity_update'
     115        );
     116        return apply_filters( 'bp_activity_check_activity_types', $types );
     117}
     118
     119/**
     120 * Check activity stream for moderation keys
     121 *
     122 * @since BuddyPress (1.6)
     123 * @param BP_Activity_Activity $activity
     124 * @return If activity type is not an update or comment
     125 */
     126function bp_activity_check_moderation_keys( $activity ) {
     127
     128        // Only check specific types of activity updates
     129        if ( !in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
     130                return;
     131
     132        // Unset the activity component so activity stream update fails
     133        // @todo This is temporary until some kind of moderation is built
     134        if ( !bp_core_check_for_moderation( $activity->user_id, '', $activity->content ) )
     135                $activity->component = false;
     136}
     137
     138/**
     139 * Check activity stream for blacklisted keys
     140 *
     141 * @since BuddyPress (1.6)
     142 * @param BP_Activity_Activity $activity
     143 * @return If activity type is not an update or comment
     144 */
     145function bp_activity_check_blacklist_keys( $activity ) {
     146
     147        // Only check specific types of activity updates
     148        if ( !in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
     149                return;
     150
     151        // Unset the activity component so activity stream update fails
     152        if ( !bp_core_check_for_blacklist( $activity->user_id, '', $activity->content ) )
     153                $activity->component = false;
     154}
    89155
    90156/**
    … …  
    199265        $activity->save();
    200266}
    201 add_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter_updates' );
    202267
    203268/**
    … …  
    270335        return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
    271336}
    272 add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
    273 add_filter( 'bp_get_activity_content', 'bp_activity_truncate_entry', 5 );
    274337
    275338?>
Note: See TracChangeset for help on using the changeset viewer.