Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/17/2011 03:33:32 PM (13 years ago)
Author:
boonebgorges
Message:

Prevents users from posting identical replies to the same forum topic, to prevent flooding and spam. Fixes #3556

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums/bp-forums-functions.php

    r5305 r5567  
    302302
    303303/**
     304 * Check to see whether a user has already left this particular reply on a given post.
     305 * Prevents dupes.
     306 *
     307 * @since 1.6
     308 *
     309 * @param str $text The text of the comment
     310 * @param int $topic_id The topic id
     311 * @param int $user_id The user id
     312 */
     313function bp_forums_reply_exists( $text = '', $topic_id = 0, $user_id = 0 ) {
     314    $reply_exists = false;
     315   
     316    if ( $text && $topic_id && $user_id ) {
     317        do_action( 'bbpress_init' );
     318       
     319        $args = array(
     320            'post_author_id' => $user_id,
     321            'topic_id'       => $topic_id
     322        );
     323       
     324        // BB_Query's post_text parameter does a MATCH, while we need exact matches
     325        add_filter( 'get_posts_where', create_function( '$q', 'return $q . " AND p.post_text = \'' . $text . '\'";' ) );
     326       
     327        $query = new BB_Query( 'post', $args );
     328       
     329        $reply_exists = !empty( $query->results );
     330    }
     331   
     332    return apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );
     333}
     334
     335/**
    304336 * Get a total "Topics Started" count for a given user
    305337 *
Note: See TracChangeset for help on using the changeset viewer.