Skip to:
Content

bbPress.org


Ignore:
Timestamp:
02/07/2011 01:51:29 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Rename topic_id, forum_id, and reply_id global vars to _post_type to more accurately describe what they are. Include template functions to retrieve those values, and use them through-out the project. Normalize component updater functions and remove surplus calculations from them. Temporarily unhook filters from split/join/deletion actions until new routines can be created to handle forum and topic recounts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-reply-functions.php

    r2818 r2858  
    77 * @subpackage Functions
    88 */
     9
     10/**
     11 * Update the reply with its forum ID it is in
     12 *
     13 * @since bbPress (r2855)
     14 *
     15 * @param int $reply_id Optional. Reply id to update
     16 * @param int $forum_id Optional. Forum id
     17 * @uses bbp_get_reply_id() To get the reply id
     18 * @uses bbp_get_forum_id() To get the forum id
     19 * @uses update_post_meta() To update the reply forum id meta
     20 * @return bool True on success, false on failure
     21 */
     22function bbp_update_reply_forum_id( $reply_id = 0, $forum_id = 0 ) {
     23    $reply_id = bbp_get_reply_id( $reply_id );
     24    $forum_id = bbp_get_forum_id( $forum_id );
     25
     26    // Update the last reply ID
     27    if ( !empty( $reply_id ) )
     28        return update_post_meta( $reply_id, '_bbp_reply_forum_id', $forum_id );
     29
     30    return false;
     31}
     32
     33/**
     34 * Update the reply with its topic ID it is in
     35 *
     36 * @since bbPress (r2855)
     37 *
     38 * @param int $reply_id Optional. Reply id to update
     39 * @param int $topic_id Optional. Topic id
     40 * @uses bbp_get_reply_id() To get the reply id
     41 * @uses bbp_get_topic_id() To get the topic id
     42 * @uses update_post_meta() To update the reply topic id meta
     43 * @return bool True on success, false on failure
     44 */
     45function bbp_update_reply_topic_id( $reply_id = 0, $topic_id = 0 ) {
     46    $reply_id = bbp_get_reply_id( $reply_id );
     47    $topic_id = bbp_get_topic_id( $topic_id );
     48
     49    // Update the last reply ID
     50    if ( !empty( $reply_id ) )
     51        return update_post_meta( $reply_id, '_bbp_reply_topic_id', $topic_id );
     52
     53    return false;
     54}
    955
    1056/** Post Form Handlers ********************************************************/
     
    98144
    99145        // Check for duplicate
    100         if ( !bbp_check_for_duplicate( array( 'post_type' => $bbp->reply_id, 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data ) ) )
     146        if ( !bbp_check_for_duplicate( array( 'post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data ) ) )
    101147            $bbp->errors->add( 'bbp_reply_duplicate', __( '<strong>ERROR</strong>: Duplicate reply detected; it looks as though you&#8217;ve already said that!', 'bbpress' ) );
    102148
     
    119165                'post_parent'  => $topic_id,
    120166                'post_status'  => 'publish',
    121                 'post_type'    => $bbp->reply_id
     167                'post_type'    => bbp_get_reply_post_type()
    122168            );
    123169
     
    286332 * @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
    287333 */
    288 function bbp_new_reply_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) {
    289     global $bbp;
    290 
     334function bbp_reply_updater( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) {
    291335    // Validate the ID's passed from 'bbp_new_reply' action
    292336    $reply_id = bbp_get_reply_id( $reply_id );
     
    296340        $author_id = bbp_get_current_user_id();
    297341
    298     // If anonymous post, store name, email, website and ip in post_meta. It expects anonymous_data to be sanitized. Check bbp_filter_anonymous_post_data() for sanitization.
     342    // If anonymous post, store name, email, website and ip in post_meta.
     343    // It expects anonymous_data to be sanitized.
     344    // Check bbp_filter_anonymous_post_data() for sanitization.
    299345    if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) {
    300346        extract( $anonymous_data );
     
    303349        update_post_meta( $reply_id, '_bbp_anonymous_email', $bbp_anonymous_email, false );
    304350
    305         // Set transient for throttle check and update ip address meta (only when the reply is not being edited)
     351        // Set transient for throttle check and update ip address meta
     352        // (only when the reply is not being edited)
    306353        if ( empty( $is_edit ) ) {
    307354            update_post_meta( $reply_id, '_bbp_anonymous_ip', $bbp_anonymous_ip, false );
     
    319366    // Handle Subscription Checkbox
    320367    if ( bbp_is_subscriptions_active() && !empty( $author_id ) ) {
    321         $subscribed = bbp_is_user_subscribed( $author_id, $topic_id ) ? true : false;
     368        $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
    322369        $subscheck  = ( !empty( $_POST['bbp_topic_subscription'] ) && 'bbp_subscribe' == $_POST['bbp_topic_subscription'] ) ? true : false;
    323370
     
    331378    }
    332379
     380    // Update associated topic values if this is a new reply
    333381    if ( empty( $is_edit ) ) {
    334         // Topic meta relating to most recent reply
    335         bbp_update_topic_last_reply_id( $topic_id, $reply_id );
    336         bbp_update_topic_last_active  ( $topic_id            );
    337 
    338         // Forum meta relating to most recent topic
    339         bbp_update_forum_last_topic_id( $forum_id, $topic_id );
    340         bbp_update_forum_last_reply_id( $forum_id, $reply_id );
    341         bbp_update_forum_last_active  ( $forum_id            );
     382        // Last active time
     383        $last_active = current_time( 'mysql' );
     384
     385        // Reply meta relating to reply position in tree
     386        bbp_update_reply_forum_id   ( $reply_id, $forum_id );
     387        bbp_update_reply_topic_id   ( $reply_id, $topic_id );
     388
     389        global $bbp;
     390
     391        foreach ( get_post_ancestors( $reply_id ) as $ancestor ) {
     392            // Topic meta relating to most recent reply
     393            if ( bbp_get_topic_post_type() == get_post_field( 'post_type', $ancestor ) ) {
     394                bbp_update_topic_last_reply_id( $ancestor, $reply_id    );
     395                bbp_update_topic_last_active  ( $ancestor, $last_active );
     396                bbp_update_topic_reply_count  ( $ancestor               );
     397                bbp_update_topic_voice_count  ( $ancestor               );
     398
     399            // Forum meta relating to most recent topic
     400            } elseif ( bbp_get_forum_post_type() == get_post_field( 'post_type', $ancestor ) ) {
     401                bbp_update_forum_last_topic_id( $ancestor, $topic_id    );
     402                bbp_update_forum_last_reply_id( $ancestor, $reply_id    );
     403                bbp_update_forum_last_active  ( $ancestor, $last_active );
     404                bbp_update_forum_reply_count  ( $ancestor               );
     405                bbp_update_forum_voice_count  ( $ancestor               );
     406            }
     407        }
    342408    }
    343409}
     
    409475                switch ( $sub_action ) {
    410476                    case 'trash':
    411                         check_ajax_referer( 'trash-' . $bbp->reply_id . '_' . $reply_id );
     477                        check_ajax_referer( 'trash-' . bbp_get_reply_post_type() . '_' . $reply_id );
    412478
    413479                        $success = wp_trash_post( $reply_id );
     
    417483
    418484                    case 'untrash':
    419                         check_ajax_referer( 'untrash-' . $bbp->reply_id . '_' . $reply_id );
     485                        check_ajax_referer( 'untrash-' . bbp_get_reply_post_type() . '_' . $reply_id );
    420486
    421487                        $success = wp_untrash_post( $reply_id );
     
    425491
    426492                    case 'delete':
    427                         check_ajax_referer( 'delete-' . $bbp->reply_id . '_' . $reply_id );
     493                        check_ajax_referer( 'delete-' . bbp_get_reply_post_type() . '_' . $reply_id );
    428494
    429495                        $success = wp_delete_post( $reply_id );
Note: See TracChangeset for help on using the changeset viewer.