Skip to:
Content

bbPress.org

Changeset 2984


Ignore:
Timestamp:
04/03/2011 09:39:19 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Introduce bbp_reply_position() functions to help calculate reply permalinks and topic freshness links. Fixes #1495.

Location:
branches/plugin/bbp-includes
Files:
2 edited

Legend:

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

    r2953 r2984  
    499499
    500500            // Last reply and active ID's
    501             bbp_update_topic_last_reply_id( $ancestor, $reply_id );
     501            bbp_update_topic_last_reply_id  ( $ancestor, $reply_id );
    502502            bbp_update_topic_last_active_id ( $ancestor, $active_id );
    503503
  • branches/plugin/bbp-includes/bbp-reply-template.php

    r2982 r2984  
    351351
    352352        // Set needed variables
    353         $reply_id      = bbp_get_reply_id( $reply_id );
    354         $topic_id      = bbp_get_reply_topic_id( $reply_id );
    355         $topic_url     = bbp_get_topic_permalink( $topic_id );
    356         $topic_replies = bbp_get_topic_reply_count( $topic_id );
    357 
    358         // Add hidden replies to count
    359         if ( $count_hidden == true )
    360             $topic_replies += bbp_get_topic_hidden_reply_count( $topic_id );
    361 
    362         // Add 1 to the count if topic is included in reply loop
    363         if ( !bbp_show_lead_topic() )
    364             $topic_replies++;
    365 
    366         $reply_page    = ceil( $topic_replies / get_option( '_bbp_replies_per_page', 15 ) );
    367         $reply_hash    = !empty( $bbp->errors ) ? "#post-{$reply_id}" : '';
     353        $reply_id          = bbp_get_reply_id         ( $reply_id );
     354        $topic_id          = bbp_get_reply_topic_id   ( $reply_id );
     355        $topic_url         = bbp_get_topic_permalink  ( $topic_id );
     356        $topic_reply_count = bbp_get_topic_reply_count( $topic_id );
     357        $reply_position    = bbp_get_reply_position   ( $reply_id );
     358
     359        // Check if in query with pagination
     360        $reply_page = ceil( $reply_position / get_option( '_bbp_replies_per_page', 15 ) );
     361
     362        // Hash to add to end of URL
     363        $reply_hash     = !empty( $bbp->errors ) ? "#post-{$reply_id}" : '';
    368364
    369365        // Don't include pagination if on first page
     
    11381134    }
    11391135
     1136/**
     1137 * Output the numeric position of a reply within a topic
     1138 *
     1139 * @since bbPress (r2984)
     1140 *
     1141 * @uses bbp_get_reply_position()
     1142 * @param int $reply_id
     1143 */
     1144function bbp_reply_position( $reply_id = 0 ) {
     1145    echo bbp_get_reply_position( $reply_id );
     1146}
     1147    /**
     1148     * Return the numeric position of a reply within a topic
     1149     *
     1150     * @since bbPress (r2984)
     1151     *
     1152     * @uses bbp_get_reply_id() Get the reply id
     1153     * @uses bbp_get_reply_topic_id() Get the topic id of the reply id
     1154     * @uses bbp_get_public_child_ids() Get the reply ids of the topic id
     1155     * @uses bbp_show_lead_topic() Bump the count if lead topic is included
     1156     * @uses apply_filters() Allow position to be altered
     1157     * @param int $reply_id
     1158     */
     1159    function bbp_get_reply_position( $reply_id = 0 ) {
     1160
     1161        // Get required data
     1162        $reply_position  = 0;
     1163        $reply_id        = bbp_get_reply_id         ( $reply_id );
     1164        $topic_id        = bbp_get_reply_topic_id   ( $reply_id );
     1165
     1166        // Make sure the topic has replies before running another query
     1167        if ( $reply_count = bbp_get_topic_reply_count( $topic_id ) ) {
     1168
     1169            // Get reply id's
     1170            $topic_replies  = bbp_get_public_child_ids ( $topic_id, bbp_get_reply_post_type() );
     1171
     1172            // Reverse replies array and search for current reply position
     1173            $topic_replies  = array_reverse( $topic_replies );
     1174
     1175            // Position found
     1176            if ( $reply_position = array_search ( (string) $reply_id, $topic_replies ) ) {
     1177
     1178                // Bump if topic is in replies loop
     1179                if ( !bbp_show_lead_topic() )
     1180                    $reply_position++;
     1181
     1182                // Bump now so we don't need to do math later
     1183                $reply_position++;
     1184            }
     1185        }
     1186
     1187        return apply_filters( 'bbp_get_reply_position', (int) $reply_position, $reply_id, $topic_id );
     1188    }
     1189
    11401190/** Reply Admin Links *********************************************************/
    11411191
Note: See TracChangeset for help on using the changeset viewer.