Skip to:
Content

bbPress.org

Ticket #2036: 2036.3.diff

File 2036.3.diff, 46.8 KB (added by jmdodd, 10 years ago)

One setting instead of two for threading.

  • includes/admin/metaboxes.php

     
    402402        // Get some meta
    403403        $reply_topic_id = bbp_get_reply_topic_id( $post_id );
    404404        $reply_forum_id = bbp_get_reply_forum_id( $post_id );
     405        $reply_to       = bbp_get_reply_to(       $post_id );
    405406
    406407        // Allow individual manipulation of reply forum
    407408        if ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate' ) ) : ?>
     
    438439                <input name="parent_id" id="bbp_topic_id" type="text" value="<?php echo esc_attr( $reply_topic_id ); ?>" />
    439440        </p>
    440441
     442        <p>
     443                <strong class="label"><?php _e( 'Reply To:', 'bbpress' ); ?></strong>
     444                <label class="screen-reader-text" for="bbp_reply_to"><?php _e( 'Reply To', 'bbpress' ); ?></label>
     445                <input name="bbp_reply_to" id="bbp_reply_to" type="text" value="<?php echo esc_attr( $reply_to ); ?>" />
     446        </p>
     447
    441448        <?php
    442449        wp_nonce_field( 'bbp_reply_metabox_save', 'bbp_reply_metabox' );
    443450        do_action( 'bbp_reply_metabox', $post_id );
  • includes/admin/replies.php

     
    224224                                '<ul>' .
    225225                                        '<li>' . __( '<strong>Forum</strong> dropdown determines the parent forum that the reply belongs to. Select the forum, or leave the default (Use Forum of Topic) to post the reply in forum of the topic.', 'bbpress' ) . '</li>' .
    226226                                        '<li>' . __( '<strong>Topic</strong> determines the parent topic that the reply belongs to.', 'bbpress' ) . '</li>' .
     227                                        '<li>' . __( '<strong>Reply To</strong> determines the threading of the reply.', 'bbpress' ) . '</li>' .
    227228                                '</ul>'
    228229                ) );
    229230
     
    312313                // Get the reply meta post values
    313314                $topic_id = !empty( $_POST['parent_id']    ) ? (int) $_POST['parent_id']    : 0;
    314315                $forum_id = !empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id );
     316                $reply_to = !empty( $_POST['bbp_reply_to'] ) ? (int) $_POST['bbp_reply_to'] : 0;
    315317
    316318                // Formally update the reply
    317                 bbp_update_reply( $reply_id, $topic_id, $forum_id );
     319                bbp_update_reply( $reply_id, $topic_id, $forum_id, false, 0, false, $reply_to );
    318320
    319321                // Allow other fun things to happen
    320                 do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id );
     322                do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id, $reply_to );
    321323
    322324                return $reply_id;
    323325        }
  • includes/admin/settings.php

     
    169169
    170170                'bbp_settings_theme_compat' => array(
    171171
    172                         // Replies per page setting
     172                        // Theme package setting
    173173                        '_bbp_theme_package_id' => array(
    174174                                'title'             => __( 'Current Package', 'bbpress' ),
    175175                                'callback'          => 'bbp_admin_setting_callback_subtheme_id',
     
    196196                                'callback'          => 'bbp_admin_setting_callback_replies_per_page',
    197197                                'sanitize_callback' => 'intval',
    198198                                'args'              => array()
     199                        ),
     200
     201                        // Set reply threading level
     202                        '_bbp_thread_replies_depth' => array(
     203                                'title'             => __( 'Thread level', 'bbpress' ),
     204                                'callback'          => 'bbp_admin_setting_callback_thread_replies_depth',
     205                                'sanitize_callback' => 'intval',
     206                                'args'              => array()
    199207                        )
    200208                ),
    201209
     
    461469}
    462470
    463471/**
     472 * Hierarchical reply max depth level setting field; replies will be threaded
     473 * if depth is 2 or greater
     474 *
     475 * @since bbPress (r####)
     476 *
     477 * @uses apply_filters() Calls 'bbp_thread_replies_depth_max' to set a
     478 *                        maximum displayed level
     479 * @uses selected() To display the selected attribute
     480 */
     481function bbp_admin_setting_callback_thread_replies_depth() {
     482
     483        // Set maximum depth for dropdown
     484        $max_depth = (int) apply_filters( 'bbp_thread_replies_depth_max', 10 );
     485        $current_depth = get_option( '_bbp_thread_replies_depth' );
     486
     487?>
     488        <label for="_bbp_thread_replies_depth">
     489                <select id="_bbp_thread_replies_depth" name="_bbp_thread_replies_depth">
     490                <?php for ( $i = 0; $i <= $max_depth; $i++ ) : ?>
     491
     492                        <option value="<?php echo esc_attr( $i ); ?>" <?php selected( $i, $current_depth ); ?>><?php echo esc_html( $i ); ?></option>
     493
     494                <?php endfor; ?>
     495                </select>
     496        <?php _e( ' levels deep', 'bbpress' ); ?>
     497        </label>
     498<?php
     499}
     500
     501/**
    464502 * Allow topic and reply revisions
    465503 *
    466504 * @since bbPress (r3412)
  • includes/common/classes.php

     
    259259        }
    260260}
    261261
     262/**
     263 * Create hierarchical list of bbPress replies.
     264 *
     265 * @package bbPress
     266 * @subpackage Classes
     267 *
     268 * @since bbPress (r####)
     269 */
     270class Walker_Reply extends Walker {
     271
     272        /**
     273         * @see Walker::$tree_type
     274         *
     275         * @since bbPress (r####)
     276         *
     277         * @var string
     278         */
     279        var $tree_type = 'reply';
     280
     281        /**
     282         * @see Walker::$db_fields
     283         *
     284         * @since bbPress (r####)
     285         *
     286         * @var array
     287         */
     288        var $db_fields = array(
     289                'parent' => 'reply_to',
     290                'id'     => 'ID'
     291        );
     292
     293        /**
     294         * @see Walker::start_lvl()
     295         *
     296         * @since bbPress (r####)
     297         *
     298         * @param string $output Passed by reference. Used to append additional content
     299         * @param int $depth Depth of reply
     300         * @param array $args Uses 'style' argument for type of HTML list
     301         */
     302        public function start_lvl( &$output, $depth = 0, $args = array() ) {
     303                $GLOBALS['reply_depth'] = $depth + 1;
     304
     305                switch ( $args['style'] ) {
     306                        case 'div':
     307                                break;
     308                        case 'ol':
     309                                echo "<ol class='children'>\n";
     310                                break;
     311                        case 'ul':
     312                        default:
     313                                echo "<ul class='children'>\n";
     314                                break;
     315                }
     316        }
     317
     318        /**
     319         * @see Walker::end_lvl()
     320         *
     321         * @since bbPress (r####)
     322         *
     323         * @param string $output Passed by reference. Used to append additional content
     324         * @param int $depth Depth of reply
     325         * @param array $args Will only append content if style argument value is 'ol' or 'ul'
     326         */
     327        public function end_lvl( &$output, $depth = 0, $args = array() ) {
     328                $GLOBALS['reply_depth'] = $depth + 1;
     329
     330                switch ( $args['style'] ) {
     331                        case 'div':
     332                                break;
     333                        case 'ol':
     334                                echo "</ol>\n";
     335                                break;
     336                        case 'ul':
     337                        default:
     338                                echo "</ul>\n";
     339                                break;
     340                }
     341        }
     342
     343        /**
     344         * @since bbPress (r####)
     345         */
     346        public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
     347
     348                if ( !$element )
     349                        return;
     350
     351                // Get element's id
     352                $id_field = $this->db_fields['id'];
     353                $id       = $element->$id_field;
     354
     355                // Display element
     356                parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
     357
     358                // If we're at the max depth and the current element still has children, loop over those
     359                // and display them at this level to prevent them being orphaned to the end of the list.
     360                if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
     361                        foreach ( $children_elements[ $id ] as $child )
     362                                $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
     363
     364                        unset( $children_elements[ $id ] );
     365                }
     366        }
     367
     368        /**
     369         * @see Walker:start_el()
     370         *
     371         * @since bbPress (r####)
     372         */
     373        public function start_el( &$output, $reply, $depth, $args, $id = 0 ) {
     374
     375                // Set up reply
     376                $depth++;
     377                $GLOBALS['reply_depth'] = $depth;
     378                bbpress()->reply_query->post = $reply;
     379                bbpress()->current_reply_id = $reply->ID;
     380
     381                // Check for a callback and use it if specified
     382                if ( !empty($args['callback']) ) {
     383                        call_user_func( $args['callback'], $reply, $args, $depth );
     384                        return;
     385                }
     386
     387                // Style for div or list element
     388                if ( 'div' == $args['style'] ) {
     389                        $tag = 'div';
     390                        $add_below = 'reply';
     391                } else {
     392                        $tag = 'li';
     393                        $add_below = 'div-reply';
     394                } ?>
     395
     396                <<?php echo $tag ?>>
     397
     398                <div id="reply-<?php bbp_reply_ID(); ?>">
     399
     400                        <?php bbp_get_template_part( 'loop', 'single-reply' ); ?>
     401
     402                        <?php if ( $reply->post_type == bbp_get_reply_post_type() ) : ?>
     403
     404                        <div class="bbp-reply-to"><?php bbp_reply_to_link( array_merge( $args, array( 'depth' => $depth ) ), $reply ); ?></div>
     405
     406                        <?php endif; ?>
     407
     408                </div>
     409
     410                <?php
     411        }
     412
     413        /**
     414         * @since bbPress (r####)
     415         */
     416        public function end_el( &$output, $reply, $depth = 0, $args = array() ) {
     417
     418                // Check for a callback and use it if specified
     419                if ( !empty($args['end-callback']) ) {
     420                        call_user_func( $args['end-callback'], $reply, $args, $depth );
     421                        return;
     422                }
     423
     424                // Style for div or list element
     425                if ( 'div' == $args['style'] )
     426                        echo "</div>\n";
     427                else
     428                        echo "</li>\n";
     429
     430        }
     431}
     432
    262433endif; // class_exists check
  • includes/common/template-tags.php

     
    15341534
    15351535                <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php bbp_reply_title(); ?>" />
    15361536                <input type="hidden" name="bbp_reply_id"    id="bbp_reply_id"    value="<?php bbp_reply_id(); ?>" />
     1537                <input type="hidden" name="bbp_reply_to"    id="bbp_reply_to"    value="<?php bbp_form_reply_to(); ?>" />
    15371538                <input type="hidden" name="action"          id="bbp_post_action" value="bbp-edit-reply" />
    15381539
    15391540                <?php if ( current_user_can( 'unfiltered_html' ) )
     
    15451546
    15461547                <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" />
    15471548                <input type="hidden" name="bbp_topic_id"    id="bbp_topic_id"    value="<?php bbp_topic_id(); ?>" />
     1549                <input type="hidden" name="bbp_reply_to"    id="bbp_reply_to"    value="<?php bbp_form_reply_to(); ?>" />
    15481550                <input type="hidden" name="action"          id="bbp_post_action" value="bbp-new-reply" />
    15491551
    15501552                <?php if ( current_user_can( 'unfiltered_html' ) )
  • includes/core/actions.php

     
    174174add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 );
    175175
    176176// New/Edit Reply
    177 add_action( 'bbp_new_reply',  'bbp_update_reply', 10, 6 );
    178 add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 6 );
     177add_action( 'bbp_new_reply',  'bbp_update_reply', 10, 7 );
     178add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 7 );
    179179
    180180// Before Delete/Trash/Untrash Reply
    181181add_action( 'wp_trash_post', 'bbp_trash_reply'   );
  • includes/core/options.php

     
    3434                '_bbp_enable_favorites'     => 1,                          // Favorites
    3535                '_bbp_enable_subscriptions' => 1,                          // Subscriptions
    3636                '_bbp_allow_topic_tags'     => 1,                          // Topic Tags
     37                '_bbp_thread_replies_depth' => 0,                          // Thread replies depth
    3738                '_bbp_allow_anonymous'      => 0,                          // Allow anonymous posting
    3839                '_bbp_allow_global_access'  => 1,                          // Users from all sites can post
    3940                '_bbp_use_wp_editor'        => 1,                          // Use the WordPress editor if available
     
    224225}
    225226
    226227/**
     228 * Are replies threaded
     229 *
     230 * @since bbPress (r####)
     231 *
     232 * @param bool $default Optional. Default value true
     233 * @uses apply_filters() Calls 'bbp_thread_replies' with the calculated value and
     234 *                        the thread replies depth
     235 * @uses get_option() To get thread replies option
     236 * @return bool Are replies threaded?
     237 */
     238function bbp_thread_replies() {
     239        $retval = false;
     240        $depth = bbp_thread_replies_depth();
     241        if ( $depth > 1 )
     242                $retval = true;
     243        return (bool) apply_filters( 'bbp_thread_replies', $retval, $depth );
     244}
     245
     246/**
     247 * Maximum reply thread depth
     248 *
     249 * @since bbPress (r####)
     250 *
     251 * @param int $default Thread replies depth
     252 * @uses apply_filters() Calls 'bbp_thread_replies_depth' with the option value and
     253 *                       the default depth
     254 * @uses get_option() To get the thread replies depth
     255 * @return int Thread replies depth
     256 */
     257function bbp_thread_replies_depth( $default = 0 ) {
     258        return (int) apply_filters( 'bbp_thread_replies_depth', (int) get_option( '_bbp_thread_replies_depth', $default ) );
     259}
     260
     261/**
    227262 * Are topic and reply revisions allowed
    228263 *
    229264 * @since bbPress (r3412)
     
    280315 * @return bool Use WP editor?
    281316 */
    282317function bbp_use_wp_editor( $default = 1 ) {
     318        // Disable if replies are threaded
     319        if ( bbp_thread_replies() )
     320                return false;
    283321        return (bool) apply_filters( 'bbp_use_wp_editor', (bool) get_option( '_bbp_use_wp_editor', $default ) );
    284322}
    285323
  • includes/replies/functions.php

     
    9797 * @uses wp_set_post_terms() To set the topic tags
    9898 * @uses wp_insert_post() To insert the reply
    9999 * @uses do_action() Calls 'bbp_new_reply' with the reply id, topic id, forum
    100  *                    id, anonymous data and reply author
     100 *                    id, anonymous data, reply author, edit (false), and
     101 *                    the reply to id
    101102 * @uses bbp_get_reply_url() To get the paginated url to the reply
    102103 * @uses wp_safe_redirect() To redirect to the reply url
    103104 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
     
    116117        }
    117118
    118119        // Define local variable(s)
    119         $topic_id = $forum_id = $reply_author = $anonymous_data = 0;
     120        $topic_id = $forum_id = $reply_author = $anonymous_data = $reply_to = 0;
    120121        $reply_title = $reply_content = $terms = '';
    121122
    122123        /** Reply Author **********************************************************/
     
    165166                bbp_add_error( 'bbp_reply_forum_id', __( '<strong>ERROR</strong>: Forum ID is missing.', 'bbpress' ) );
    166167        }
    167168
     169        /** Reply To **************************************************************/
     170
     171        // Handle Reply To of the reply; $_REQUEST for non-JS submissions
     172        if ( isset( $_REQUEST['bbp_reply_to'] ) ) {
     173                $reply_to = (int) $_REQUEST['bbp_reply_to'];
     174        }
     175
     176        $reply_to = bbp_get_reply_id( $reply_to );
     177
    168178        /** Unfiltered HTML *******************************************************/
    169179
    170180        // Remove wp_filter_kses filters from title and content for capable users and if the nonce is verified
     
    326336
    327337                /** Update counts, etc... *********************************************/
    328338
    329                 do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author );
     339                do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to );
    330340
    331341                /** Additional Actions (After Save) ***********************************/
    332342
     
    383393 * @uses wp_update_post() To update the reply
    384394 * @uses bbp_get_reply_topic_id() To get the reply topic id
    385395 * @uses bbp_get_topic_forum_id() To get the topic forum id
     396 * @uses bbp_get_reply_to() To get the reply to id
    386397 * @uses do_action() Calls 'bbp_edit_reply' with the reply id, topic id, forum
    387  *                    id, anonymous data, reply author and bool true (for edit)
     398 *                    id, anonymous data, reply author, bool true (for edit),
     399 *                    and the reply to id
    388400 * @uses bbp_get_reply_url() To get the paginated url to the reply
    389401 * @uses wp_safe_redirect() To redirect to the reply url
    390402 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
     
    462474
    463475        $forum_id = bbp_get_topic_forum_id( $topic_id );
    464476
     477        /** Reply To **************************************************************/
     478
     479        $reply_to = bbp_get_reply_to( $reply_id );
     480
    465481        // Forum exists
    466482        if ( !empty( $forum_id ) && ( $forum_id !== bbp_get_reply_forum_id( $reply_id ) ) ) {
    467483
     
    611627        if ( !empty( $reply_id ) && !is_wp_error( $reply_id ) ) {
    612628
    613629                // Update counts, etc...
    614                 do_action( 'bbp_edit_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author , true /* Is edit */ );
     630                do_action( 'bbp_edit_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author , true /* Is edit */, $reply_to );
    615631
    616632                /** Additional Actions (After Save) ***********************************/
    617633
     
    653669 * @param bool|array $anonymous_data Optional logged-out user data.
    654670 * @param int $author_id Author id
    655671 * @param bool $is_edit Optional. Is the post being edited? Defaults to false.
     672 * @param int $reply_to Optional. Reply to id
    656673 * @uses bbp_get_reply_id() To get the reply id
    657674 * @uses bbp_get_topic_id() To get the topic id
    658675 * @uses bbp_get_forum_id() To get the forum id
     
    669686 * @uses bbp_add_user_subscription() To add the user's subscription
    670687 * @uses bbp_update_reply_forum_id() To update the reply forum id
    671688 * @uses bbp_update_reply_topic_id() To update the reply topic id
     689 * @uses bbp_update_reply_to() To update the reply to id
    672690 * @uses bbp_update_reply_walker() To update the reply's ancestors' counts
    673691 */
    674 function bbp_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) {
     692function bbp_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) {
    675693
    676694        // Validate the ID's passed from 'bbp_new_reply' action
    677         $reply_id = bbp_get_reply_id( $reply_id );
    678         $topic_id = bbp_get_topic_id( $topic_id );
    679         $forum_id = bbp_get_forum_id( $forum_id );
     695        $reply_id    = bbp_get_reply_id( $reply_id );
     696        $topic_id    = bbp_get_topic_id( $topic_id );
     697        $forum_id    = bbp_get_forum_id( $forum_id );
     698        $reply_to    = bbp_get_reply_id( $reply_to );
    680699
    681700        // Bail if there is no reply
    682701        if ( empty( $reply_id ) )
     
    740759        // Reply meta relating to reply position in tree
    741760        bbp_update_reply_forum_id( $reply_id, $forum_id );
    742761        bbp_update_reply_topic_id( $reply_id, $topic_id );
     762        bbp_update_reply_to(       $reply_id, $reply_to );
    743763
    744764        // Update associated topic values if this is a new reply
    745765        if ( empty( $is_edit ) ) {
     
    977997        return apply_filters( 'bbp_update_reply_topic_id', (int) $topic_id, $reply_id );
    978998}
    979999
     1000/*
     1001 * Update the reply's meta data with its reply to id
     1002 *
     1003 * @since bbPress (r####)
     1004 *
     1005 * @param int $reply_id Reply id to update
     1006 * @param int $reply_to Optional. Reply to id
     1007 * @uses bbp_get_reply_id() To get the reply id
     1008 * @uses update_post_meta() To update the reply to meta
     1009 * @uses apply_filters() Calls 'bbp_update_reply_to' with the reply id and
     1010 *                        and reply to id
     1011 * @return bool Reply's parent reply id
     1012 */
     1013function bbp_update_reply_to( $reply_id = 0, $reply_to = 0 ) {
     1014
     1015        // Validation
     1016        $reply_id = bbp_get_reply_id( $reply_id );
     1017        $reply_to = bbp_get_reply_id( $reply_to );
     1018
     1019        // Return if no reply
     1020        if ( empty( $reply_id ) )
     1021                return;
     1022
     1023        // Return if no reply to
     1024        if ( empty( $reply_to ) )
     1025                return;
     1026
     1027        // Set the reply to
     1028        update_post_meta( $reply_id, '_bbp_reply_to', $reply_to );
     1029
     1030        return (int) apply_filters( 'bbp_update_reply_to', (int) $reply_to, $reply_id );
     1031}
     1032
    9801033/**
    9811034 * Update the revision log of the reply
    9821035 *
     
    19992052
    20002053        return (int) $reply_position;
    20012054}
     2055
     2056/** Hierarchical Replies ******************************************************/
     2057
     2058/**
     2059 * List replies
     2060 *
     2061 * @since bbPress (r####)
     2062 */
     2063function bbp_list_replies( $args = array(), $replies = null ) {
     2064        global $reply_alt, $reply_depth, $reply_thread_alt;
     2065
     2066        // In reply loop
     2067        bbpress()->reply_query->in_the_loop = true;
     2068
     2069        // Initialize variables
     2070        $reply_alt = $reply_thread_alt = 0;
     2071        $reply_depth = 1;
     2072
     2073        $defaults = array(
     2074                'walker'       => null,
     2075                'max_depth'    => bbp_thread_replies_depth(),
     2076                'style'        => 'ul',
     2077                'callback'     => null,
     2078                'end_callback' => null,
     2079                'page'         => bbp_get_paged(),
     2080                'per_page'     => bbp_get_replies_per_page()
     2081        );
     2082
     2083        $r = wp_parse_args( $args, $defaults );
     2084
     2085        // Get replies to loop through in $_replies
     2086        if ( null !== $replies ) {
     2087                $replies = (array) $replies;
     2088                if ( empty( $replies ) )
     2089                        return;
     2090                $_replies = $replies;
     2091        } else {
     2092                if ( empty( bbpress()->reply_query->posts ) )
     2093                        return;
     2094                $_replies = bbpress()->reply_query->posts;
     2095        }
     2096
     2097        if ( empty( $walker ) )
     2098                $walker = new Walker_Reply;
     2099
     2100        $walker->paged_walk( $_replies, $r['max_depth'], $r['page'], $r['per_page'], $r );
     2101        bbpress()->max_num_pages = $walker->max_pages;
     2102
     2103        bbpress()->reply_query->in_the_loop = false;
     2104}
     2105
     2106/**
     2107 * Update the hierarchical position of the reply.
     2108 *
     2109 * The hierarchical reply position is stored as _bbp_reply_position in the postmeta
     2110 * table. This is done to prevent repeated complex queries to sort out reply
     2111 * position.
     2112 *
     2113 * @since bbPress (r####)
     2114 *
     2115 * @param int $reply_id The reply id
     2116 * @param int $reply_hierarchical_position Optional. The reply position
     2117 * @return int The reply's hierarchical position (technically, the position of the reply's
     2118 *              ancestor in the uppermost level of the hierarchy).
     2119 */
     2120function bbp_update_reply_hierarchical_position( $reply_id = 0, $reply_hierarchical_position = 0 ) {
     2121
     2122        // Bail if reply_id is empty
     2123        $reply_id = bbp_get_reply_id( $reply_id );
     2124        if ( empty( $reply_id ) )
     2125                return false;
     2126
     2127        // If no position was passed, get it from the db and update the menu_order
     2128        if ( empty( $reply_hierarchical_position ) ) {
     2129                $reply_hierarchical_position = bbp_get_reply_hierarchical_position_raw( $reply_id, bbp_get_reply_topic_id( $reply_id ) );
     2130        }
     2131
     2132        // Update the reply's meta _bbp_reply_position with the reply position
     2133        update_post_meta( $reply_id, '_bbp_reply_position', $reply_hierarchical_position );
     2134
     2135        return (int) $reply_hierarchical_position;
     2136}
     2137
     2138/**
     2139 * Get the hierarchical position of a reply by querying the DB directly for the
     2140 * replies of a given topic. This function uses the time of the ancestor reply, as
     2141 * that is the defining branch of the hierarchy of replies.
     2142 *
     2143 * @since bbPress (r####)
     2144 *
     2145 * @param int $reply_id The reply id
     2146 * @param int $topic_id
     2147 */
     2148function bbp_get_reply_hierarchical_position_raw( $reply_id = 0, $topic_id = 0 ) {
     2149
     2150        // Get required data
     2151        $reply_id                    = bbp_get_reply_id( $reply_id );
     2152        $topic_id                    = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id );
     2153        $reply_hierarchical_position = 0;
     2154
     2155        // If reply is actually the first post in a topic, return 0
     2156        if ( $reply_id != $topic_id ) {
     2157
     2158                // Make sure the topic has replies before running another query
     2159                $reply_count = bbp_get_topic_reply_count( $topic_id, false );
     2160                if ( !empty( $reply_count ) ) {
     2161                        global $wpdb;
     2162
     2163                        // Use ancestor for date calculations
     2164                        $ancestor_id   = bbp_get_reply_ancestor_id( $reply_id );
     2165                        $post_date_gmt = get_post_time( 'Y-m-d H:i:s', true, $ancestor_id );
     2166
     2167                        // Post stati
     2168                        $post_stati = array(
     2169                                bbp_get_public_status_id()
     2170                        );
     2171
     2172                        // Clean up for query
     2173                        $post_status_in_array = array();
     2174                        foreach( $post_stati as $post_status )
     2175                                $post_status_in_array[] = $wpdb->prepare( "%s", $post_status );
     2176
     2177                        // Join post statuses together
     2178                        $post_status_in_array = implode( ',', $post_status_in_array );
     2179
     2180                        // Direct SQL query for post meta values
     2181                        $sql = $wpdb->prepare( "
     2182                                SELECT COUNT(*) FROM {$wpdb->posts} p
     2183                                WHERE p.post_parent = %d
     2184                                        AND p.post_type = %s
     2185                                        AND p.post_date_gmt < %s
     2186                                        AND p.post_status IN ( {$post_status_in_array} )
     2187                                        AND (
     2188                                                NOT EXISTS (
     2189                                                        SELECT pm.* FROM {$wpdb->postmeta} pm WHERE p.ID = pm.post_id AND pm.meta_key = '_bbp_reply_to'
     2190                                                ) OR EXISTS (
     2191                                                        SELECT pm.* FROM {$wpdb->postmeta} pm WHERE p.ID = pm.post_id AND pm.meta_key = '_bbp_reply_to' AND pm.meta_value = 0
     2192                                                ) OR EXISTS (
     2193                                                        SELECT pm.* FROM {$wpdb->postmeta} pm WHERE p.ID = pm.post_id AND pm.meta_key = '_bbp_reply_to' AND pm.meta_value = %d
     2194                                ) ) ORDER BY p.post_date_gmt ASC",
     2195                                $topic_id, bbp_get_reply_post_type(), $post_date_gmt, $topic_id
     2196                        );
     2197                        $reply_hierarchical_position = (int) $wpdb->get_var( $sql );
     2198
     2199                        // Bump the position to compensate for the lead topic post
     2200                        $reply_hierarchical_position++;
     2201                }
     2202        }
     2203
     2204        return (int) $reply_hierarchical_position;
     2205}
  • includes/replies/template-tags.php

     
    8181                'paged'          => bbp_get_paged(),            // On this page
    8282                'orderby'        => 'date',                     // Sorted by date
    8383                'order'          => 'ASC',                      // Oldest to newest
     84                'hierarchical'   => false,                      // Hierarchical replies
    8485                's'              => $default_reply_search,      // Maybe search
    8586        );
    8687
     
    113114        // Parse arguments against default values
    114115        $r = bbp_parse_args( $args, $default, 'has_replies' );
    115116
     117        // Set posts_per_page value if replies are threaded
     118        $replies_per_page = $r['posts_per_page'];
     119        if ( $r['hierarchical'] ) {
     120                $r['posts_per_page'] = -1;
     121        }
     122
    116123        // Get bbPress
    117124        $bbp = bbpress();
    118125
    119126        // Call the query
    120127        $bbp->reply_query = new WP_Query( $r );
    121        
     128
    122129        // Add pagination values to query object
    123         $bbp->reply_query->posts_per_page = $r['posts_per_page'];
     130        $bbp->reply_query->posts_per_page = $replies_per_page;
    124131        $bbp->reply_query->paged          = $r['paged'];
    125132
    126133        // Never home, regardless of what parse_query says
     
    131138                $bbp->reply_query->is_single = true;
    132139        }
    133140
     141        // Only add reply to if query returned results
     142        if ( (int) $bbp->reply_query->found_posts ) {
     143
     144                // Get reply to for each reply
     145                foreach ( $bbp->reply_query->posts as &$post ) {
     146
     147                        // Check for reply post type
     148                        if ( $post->post_type == bbp_get_reply_post_type() ) {
     149                                $reply_to = bbp_get_reply_to( $post->ID );
     150
     151                                // Make sure it's a reply to a reply
     152                                if ( empty( $reply_to ) || ( bbp_get_reply_topic_id( $post->ID ) == $reply_to ) )
     153                                        $reply_to = 0;
     154                                $post->reply_to = $reply_to;
     155                        }
     156                }
     157        }
     158
    134159        // Only add pagination if query returned results
    135160        if ( (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) {
    136161
     
    157182                        $base = add_query_arg( 'paged', '%#%' );
    158183                }
    159184
     185                // Figure out total pages
     186                if ( $r['hierarchical'] ) {
     187                        $walker      = new Walker_Reply;
     188                        $total_pages = ceil( (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / (int) $replies_per_page );
     189                } else {
     190                        $total_pages = ceil( (int) $bbp->reply_query->found_posts / (int) $replies_per_page );
     191                }
     192
    160193                // Add pagination to query object
    161194                $bbp->reply_query->pagination_links = paginate_links(
    162195                        apply_filters( 'bbp_replies_pagination', array(
    163196                                'base'      => $base,
    164197                                'format'    => '',
    165                                 'total'     => ceil( (int) $bbp->reply_query->found_posts / (int) $r['posts_per_page'] ),
     198                                'total'     => $total_pages,
    166199                                'current'   => (int) $bbp->reply_query->paged,
    167200                                'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
    168201                                'next_text' => is_rtl() ? '&larr;' : '&rarr;',
     
    382415                // Set needed variables
    383416                $reply_id   = bbp_get_reply_id      ( $reply_id );
    384417                $topic_id   = bbp_get_reply_topic_id( $reply_id );
    385                 $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() );
     418
     419                // Hierarchical reply page
     420                if ( bbp_thread_replies() ) {
     421                        $reply_page = ceil( (int) bbp_get_reply_hierarchical_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() );
     422
     423                // Standard reply page
     424                } else {
     425                        $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() );
     426                }
     427
    386428                $reply_hash = '#post-' . $reply_id;
    387429                $topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to );
    388430                $topic_url  = remove_query_arg( 'view', $topic_link );
     
    13621404        }
    13631405
    13641406/**
     1407 * Output the reply's ancestor reply id
     1408 *
     1409 * @since bbPress (r####)
     1410 *
     1411 * @param int $reply_id Optional. Reply id
     1412 * @uses bbp_get_reply_ancestor_id() To get the reply's ancestor id
     1413 */
     1414function bbp_reply_ancestor_id( $reply_id = 0 ) {
     1415        echo bbp_get_reply_ancestor_id( $reply_id );
     1416}
     1417        /**
     1418         * Return the reply's ancestor reply id
     1419         *
     1420         * @since bbPress (r####)
     1421         *
     1422         * @param in $reply_id Reply id
     1423         * @uses bbp_get_reply_id() To get the reply id
     1424         */
     1425        function bbp_get_reply_ancestor_id( $reply_id = 0 ) {
     1426
     1427                // Validation
     1428                $reply_id = bbp_get_reply_id( $reply_id );
     1429                if ( empty( $reply_id ) )
     1430                        return false;
     1431
     1432                // Find highest reply ancestor
     1433                $ancestor_id = $reply_id;
     1434                while ( $parent_id = bbp_get_reply_to( $ancestor_id ) ) {
     1435                        if ( empty( $parent_id ) || $parent_id == $ancestor_id || $parent_id == bbp_get_reply_topic_id( $reply_id ) || $parent_id == $reply_id )
     1436                                break;
     1437                        $ancestor_id = $parent_id;
     1438                }
     1439
     1440                return (int) $ancestor_id;
     1441        }
     1442
     1443/**
     1444 * Output the reply to id of a reply
     1445 *
     1446 * @since bbPress (r####)
     1447 *
     1448 * @param int $reply_id Optional. Reply id
     1449 * @uses bbp_get_reply_to() To get the reply to id
     1450 */
     1451function bbp_reply_to( $reply_id = 0 ) {
     1452        echo bbp_get_reply_to( $reply_id );
     1453}
     1454        /**
     1455         * Return the reply to id of a reply
     1456         *
     1457         * @since bbPress (r####)
     1458         *
     1459         * @param int $reply_id Optional. Reply id
     1460         * @uses bbp_get_reply_id() To get the reply id
     1461         * @uses get_post_meta() To get the reply to id
     1462         * @uses apply_filters() Calls 'bbp_get_reply_to' with the reply to id and
     1463         *                        reply id
     1464         * @return int Reply's reply to id
     1465         */
     1466        function bbp_get_reply_to( $reply_id = 0 ) {
     1467
     1468                // Assume there is no reply_to set
     1469                $reply_to = 0;
     1470
     1471                // Check that reply_id is valid
     1472                if ( $reply_id = bbp_get_reply_id( $reply_id ) )
     1473
     1474                        // Get reply_to value
     1475                        $reply_to = (int) get_post_meta( $reply_id, '_bbp_reply_to', true );
     1476
     1477                return (int) apply_filters( 'bbp_get_reply_to', $reply_to, $reply_id );
     1478        }
     1479
     1480/**
     1481 * Output the link for the reply to
     1482 *
     1483 * @since bbPress (r####)
     1484 *
     1485 * @param array $args
     1486 * @param int $reply
     1487 * @uses bbp_get_reply_to_link() To get the reply to link
     1488 */
     1489function bbp_reply_to_link( $args = array(), $reply = 0 ) {
     1490        echo bbp_get_reply_to_link( $args, $reply );
     1491}
     1492
     1493        /**
     1494         * Return the link for a reply to a reply
     1495         *
     1496         * @since bbPress (r####)
     1497         *
     1498         * @param array $args Arguments
     1499         * @param int $reply_id Reply id
     1500         * @uses bbp_current_user_can_access_create_reply_form() To check permissions
     1501         * @uses bbp_get_reply_id() To validate the reply id
     1502         * @uses bbp_get_reply() To get the reply
     1503         * @uses apply_filters() Calls 'bbp_get_reply_to_link' with the formatted link,
     1504         *                        the arguments array, and the reply
     1505         * @return string Link for a reply to a reply
     1506         */
     1507        function bbp_get_reply_to_link( $args = array(), $reply_id = 0 ) {
     1508
     1509                // Permissions check
     1510                if ( !bbp_current_user_can_access_create_reply_form() )
     1511                        return;
     1512
     1513                // Validate
     1514                $reply_id = bbp_get_reply_id( $reply_id );
     1515                if ( empty( $reply_id ) )
     1516                        $reply_id = bbp_get_reply_id();
     1517
     1518                if ( empty( $reply_id ) )
     1519                        return;
     1520
     1521                // Set defaults
     1522                $reply    = bbp_get_reply( $reply_id );
     1523                $defaults = array(
     1524                        'add_below'  => 'reply',
     1525                        'respond_id' => 'new-reply-' . bbp_get_topic_id(),
     1526                        'reply_text' => __( 'Reply to this', 'bbpress' ),
     1527                        'depth' => 0,
     1528                        'before' => '',
     1529                        'after' => ''
     1530                );
     1531
     1532                $r = wp_parse_args( $args, $defaults );
     1533
     1534                // Don't display for deeply nested replies
     1535                if ( 0 == $r['depth'] || $r['max_depth'] <= $r['depth'] )
     1536                        return;
     1537
     1538                // Non-JS compat
     1539                remove_query_arg( array( 'bbp_reply_to' ) );
     1540
     1541                // Assemble
     1542                $link = "<a class='bbp-reply-to-link' href='" . esc_url( add_query_arg( array( 'bbp_reply_to' => $reply->ID ) ) ) .
     1543                        "#" . $r['respond_id'] . "' onclick='return addReply.moveForm(\"" . $r['add_below'] . '-' . $reply->ID .
     1544                        '","' . $reply->ID . '","' . $r['respond_id'] . '","' . $reply->post_parent .  '")\'>' . $r['reply_text'] . '</a>';
     1545
     1546                return apply_filters( 'bpp_get_reply_to_link', $link, $args, $reply );
     1547        }
     1548
     1549/**
     1550 * Output the reply to a reply cancellation link
     1551 *
     1552 * @since bbPress (r####)
     1553 *
     1554 * @uses bbp_get_cancel_reply_to_link() To get the reply cancellation link
     1555 */
     1556function bbp_cancel_reply_to_link( $text = '' ) {
     1557        echo bbp_get_cancel_reply_to_link( $text );
     1558}
     1559        /**
     1560         * Return the cancellation link for a reply to a reply
     1561         *
     1562         * @since bbPress (r####)
     1563         *
     1564         * @param string $text The cancel text
     1565         * @uses apply_filters() Calls 'bbp_get_cancel_reply_to_link' with the cancellation
     1566         *                        link and the cancel text
     1567         * @return string The cancellation link
     1568         */
     1569        function bbp_get_cancel_reply_to_link( $text = '' ) {
     1570
     1571                // Set default text
     1572                if ( empty( $text ) )
     1573                        $text = __( 'Click here to cancel reply.', 'bbpress' );
     1574
     1575                // Set visibility
     1576                $style = isset( $_GET['bbp_reply_to'] ) ? '' : ' style="display:none;"';
     1577                $link  = esc_html( remove_query_arg( array( 'bbp_reply_to' ) ) ) . '#respond';
     1578
     1579                return apply_filters( 'bbp_get_cancel_reply_to_link', '<a rel="nofollow" id="bbp-cancel-reply-to-link" href="' . $link . '"' . $style . '>' . $text . '</a>', $link, $text );
     1580        }
     1581
     1582/**
    13651583 * Output the numeric position of a reply within a topic
    13661584 *
    13671585 * @since bbPress (r2984)
     
    14241642                return (int) apply_filters( 'bbp_get_reply_position', $reply_position, $reply_id, $topic_id );
    14251643        }
    14261644
     1645/**
     1646 * Output the numeric position of a threaded reply within a topic
     1647 *
     1648 * @since bbPress (r####)
     1649 *
     1650 * @param int $reply_id Optional. Reply id
     1651 * @param int $topic_id Optional. Topic id
     1652 * @uses bbp_get_reply_hierarchical_position() To get the reply position
     1653 */
     1654function bbp_reply_hierarchical_position( $reply_id = 0, $topic_id = 0 ) {
     1655        echo bbp_get_reply_hierarchical_position( $reply_id, $topic_id );
     1656}
     1657
     1658        /**
     1659         * Return the numeric position of a threaded reply within a topic. Technically,
     1660         * get the position of the reply's ancestor in the context of other top-level
     1661         * replies to the topic.
     1662         *
     1663         * @since bbPress (r####)
     1664         *
     1665         * @param int $reply_id Optional. Reply id
     1666         * @param int $topic_id Optional. Topic id
     1667         * @uses bbp_get_reply_id() To get the reply id
     1668         * @uses bbp_get_reply_topic_id() Get the topic id of the reply id
     1669         * @uses bbp_get_reply_hierarchical_position_raw() To get calculate the reply position
     1670         * @uses bbp_update_reply_hierarchical_position() To update the reply position
     1671         * @uses bbp_show_lead_topic() Bump the count if lead topic is included
     1672         * @uses apply_filters() Calls 'bbp_get_reply_hierarchical_position' with the reply
     1673         *                        position, reply id and topic id
     1674         * @return int Reply hierarchical position
     1675         */
     1676        function bbp_get_reply_hierarchical_position( $reply_id = 0, $topic_id = 0 ) {
     1677
     1678                // Validate
     1679                $reply_id                    = bbp_get_reply_id( $reply_id );
     1680                $reply_hierarchical_position = get_post_meta( '_bbp_reply_position', $reply_id );
     1681
     1682                // Calculate and save the position
     1683                if ( empty( $reply_hierarchical_position ) ) {
     1684                        $topic_id = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id );
     1685
     1686                        // Post is not the topic
     1687                        if ( $reply_id != $topic_id ) {
     1688                                $reply_hierarchical_position = bbp_get_reply_hierarchical_position_raw( $reply_id, $topic_id );
     1689
     1690                                // Update the reply position in the posts table to avoid expensive
     1691                                // queries.
     1692                                if ( !empty( $reply_hierarchical_position ) ) {
     1693                                        bbp_update_reply_hierarchical_position( $reply_id, $reply_hierarchical_position );
     1694                                }
     1695
     1696                        // Topic's position is always 0
     1697                        } else {
     1698                                $reply_hierarchical_position = 0;
     1699                        }
     1700                }
     1701
     1702                // Bump the position by one if the lead topic is in the replies loop
     1703                if ( ! bbp_show_lead_topic() )
     1704                        $reply_hierarchical_position++;
     1705
     1706                return (int) apply_filters( 'bbp_get_reply_hierarchical_position', $reply_hierarchical_position, $reply_id, $topic_id );
     1707        }
     1708
    14271709/** Reply Admin Links *********************************************************/
    14281710
    14291711/**
     
    20912373        }
    20922374
    20932375/**
     2376 * Output the value of the reply to field
     2377 *
     2378 * @since bbPress (r####)
     2379 *
     2380 * @uses bbp_get_form_reply_to() To get value of the reply to field
     2381 */
     2382function bbp_form_reply_to() {
     2383        echo bbp_get_form_reply_to();
     2384}
     2385
     2386        /**
     2387         * Return the value of reply to field
     2388         *
     2389         * @since bbPress (r####)
     2390         *
     2391         * @uses bbp_get_reply_id() To validate the reply to
     2392         * @uses apply_filters() Calls 'bbp_get_form_reply_to' with the reply to
     2393         * @return string Value of reply to field
     2394         */
     2395        function bbp_get_form_reply_to() {
     2396
     2397                // Set initial value
     2398                $reply_to = 0;
     2399
     2400                // Get $_REQUEST data
     2401                if ( isset( $_REQUEST['bbp_reply_to'] ) )
     2402                        $reply_to = (int) $_REQUEST['bbp_reply_to'];
     2403
     2404                // If empty, get from meta
     2405                if ( empty( $reply_to ) )
     2406                        $reply_to = bbp_get_reply_to();
     2407
     2408                // Validate
     2409                $reply_to = bbp_get_reply_id( $reply_to );
     2410
     2411                return (int) apply_filters( 'bbp_get_form_reply_to', $reply_to );
     2412        }
     2413
     2414/**
    20942415 * Output checked value of reply log edit field
    20952416 *
    20962417 * @since bbPress (r31301)
  • includes/topics/functions.php

     
    12321232                        bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID                           );
    12331233                        bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) );
    12341234
     1235                        // Adjust reply to values
     1236                        $reply_to = bbp_get_reply_to( $reply->ID );
     1237                        if ( empty( $reply_to ) )
     1238                                bbp_update_reply_to( $reply->ID, $source_topic->ID );
     1239
    12351240                        // Do additional actions per merged reply
    12361241                        do_action( 'bbp_merged_topic_reply', $reply->ID, $destination_topic->ID );
    12371242                }
     
    15651570                                break;
    15661571                }
    15671572
     1573                // Save reply ids
     1574                $reply_ids = array();
     1575
    15681576                // Change the post_parent of each reply to the destination topic id
    15691577                foreach ( $replies as $reply ) {
    15701578
     
    15841592                        // Update the reply
    15851593                        wp_update_post( $postarr );
    15861594
     1595                        // Gather reply ids
     1596                        $reply_ids[] = $reply->ID;
     1597
    15871598                        // Adjust reply meta values
    15881599                        bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID                           );
    15891600                        bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) );
    15901601
     1602                        // Adjust reply to values
     1603                        $reply_to = bbp_get_reply_to( $reply->ID );
     1604
     1605                        // Not a reply to a reply that moved over
     1606                        if ( !in_array( $reply_to, $reply_ids ) )
     1607                                bbp_update_reply_to( $reply->ID, 0 );
     1608
     1609                        // New topic from reply can't be a reply to
     1610                        if ( ( $from_reply->ID == $destination_topic->ID && $from_reply->ID == $reply_to ) )
     1611                                bbp_update_reply_to( $reply->ID, 0 );
     1612
    15911613                        // Do additional actions per split reply
    15921614                        do_action( 'bbp_split_topic_reply', $reply->ID, $destination_topic->ID );
    15931615                }
    15941616
     1617                // Remove reply to from new topic
     1618                if ( $from_reply->ID == $destination_topic->ID )
     1619                        delete_post_meta( $from_reply->ID, '_bbp_reply_to' );
     1620
    15951621                // Set the last reply ID and freshness
    15961622                $last_reply_id = $reply->ID;
    15971623                $freshness     = $reply->post_date;
  • templates/default/bbpress/content-single-topic.php

     
    3131
    3232                <?php endif; ?>
    3333
    34                 <?php if ( bbp_has_replies() ) : ?>
     34                <?php if ( bbp_has_replies( array( 'hierarchical' => bbp_thread_replies() ) ) ) : ?>
    3535
    3636                        <?php bbp_get_template_part( 'pagination', 'replies' ); ?>
    3737
  • templates/default/bbpress/form-reply.php

     
    2828                        <fieldset class="bbp-form">
    2929                                <legend><?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?></legend>
    3030
     31                                <?php if ( bbp_thread_replies() && !bbp_is_reply_edit() ) : ?>
     32
     33                                        <div id="bbp-cancel-reply-to"><?php bbp_cancel_reply_to_link(); ?></div>
     34
     35                                <?php endif; ?>
     36
    3137                                <?php do_action( 'bbp_theme_before_reply_form_notices' ); ?>
    3238
    3339                                <?php if ( !bbp_is_topic_open() && !bbp_is_reply_edit() ) : ?>
  • templates/default/bbpress/loop-replies.php

     
    3939
    4040        <li class="bbp-body">
    4141
    42                 <?php while ( bbp_replies() ) : bbp_the_reply(); ?>
     42                <?php if ( bbp_thread_replies() ) : ?>
    4343
    44                         <?php bbp_get_template_part( 'loop', 'single-reply' ); ?>
     44                        <?php bbp_list_replies(); ?>
    4545
    46                 <?php endwhile; ?>
     46                <?php else : ?>
    4747
     48                        <?php while ( bbp_replies() ) : bbp_the_reply(); ?>
     49
     50                                <?php bbp_get_template_part( 'loop', 'single-reply' ); ?>
     51
     52                        <?php endwhile; ?>
     53
     54                <?php endif; ?>
     55
    4856        </li><!-- .bbp-body -->
    4957
    5058        <li class="bbp-footer">
  • templates/default/bbpress/pagination-replies.php

     
    1212<?php do_action( 'bbp_template_before_pagination_loop' ); ?>
    1313
    1414<div class="bbp-pagination">
    15         <div class="bbp-pagination-count">
    1615
    17                 <?php bbp_topic_pagination_count(); ?>
     16        <?php if ( !bbp_thread_replies() ) : ?>
    1817
    19         </div>
     18                <div class="bbp-pagination-count">
    2019
     20                        <?php bbp_topic_pagination_count(); ?>
     21
     22                </div>
     23
     24        <?php endif; ?>
     25
    2126        <div class="bbp-pagination-links">
    2227
    2328                <?php bbp_topic_pagination_links(); ?>
  • templates/default/bbpress-functions.php

     
    179179                        wp_enqueue_script( 'jquery' );
    180180                }
    181181
    182                 // Topic favorite/subscribe
     182                // Topic-specific scripts
    183183                if ( bbp_is_single_topic() ) {
     184
     185                        // Topic favorite/unsubscribe
    184186                        wp_enqueue_script( 'bbpress-topic', $this->url . 'js/topic.js', array( 'jquery' ), $this->version );
     187
     188                        // Hierarchical replies
     189                        if ( bbp_thread_replies() )
     190                                wp_enqueue_script( 'bbpress-reply', $this->url . 'js/reply.js', array(), $this->version );
    185191                }
    186192
    187193                // User Profile edit
  • templates/default/css/bbpress-rtl.css

     
    6060        padding: 0;
    6161}
    6262
     63#bbpress-forums ul.children {
     64        margin-right: 2em;
     65}
     66
    6367#bbpress-forums li {
    6468        margin: 0;
    6569        list-style: none;
     
    345349        background-color: transparent;
    346350}
    347351
     352/* =Reply to
     353-------------------------------------------------------------- */
     354
     355#bbpress-forums div.bbp-reply-to {
     356        margin-right: 130px;
     357        padding: 12px 0px 12px 12px;
     358        text-align: left;
     359}
     360
     361#bbpress-forums div#bbp-cancel-reply-to {
     362        text-align: left;
     363}
     364
    348365/* =Breadcrumb and Tags
    349366-------------------------------------------------------------- */
    350367
  • templates/default/css/bbpress.css

     
    6060        padding: 0;
    6161}
    6262
     63#bbpress-forums ul.children {
     64        margin-left: 2em;
     65}
     66
    6367#bbpress-forums li {
    6468        margin: 0;
    6569        list-style: none;
     
    345349        background-color: transparent;
    346350}
    347351
     352/* =Reply to
     353-------------------------------------------------------------- */
     354
     355#bbpress-forums div.bbp-reply-to {
     356        margin-left: 130px;
     357        padding: 12px 12px 12px 0;
     358        text-align: right;
     359}
     360
     361#bbpress-forums div#bbp-cancel-reply-to {
     362        text-align: right;
     363}
     364
    348365/* =Breadcrumb and Tags
    349366-------------------------------------------------------------- */
    350367
  • templates/default/js/reply.js

     
     1addReply = {
     2        moveForm : function(replyId, parentId, respondId, postId) {
     3                var t = this, div, reply = t.I(replyId), respond = t.I(respondId), cancel = t.I('bbp-cancel-reply-to-link'), parent = t.I('bbp_reply_to'), post = t.I('bbp_topic_id');
     4
     5                if ( ! reply || ! respond || ! cancel || ! parent )
     6                        return;
     7
     8                t.respondId = respondId;
     9                postId = postId || false;
     10
     11                if ( ! t.I('bbp-temp-form-div') ) {
     12                        div = document.createElement('div');
     13                        div.id = 'bbp-temp-form-div';
     14                        div.style.display = 'none';
     15                        respond.parentNode.insertBefore(div, respond);
     16                }
     17
     18                reply.parentNode.insertBefore(respond, reply.nextSibling);
     19                if ( post && postId )
     20                        post.value = postId;
     21                parent.value = parentId;
     22                cancel.style.display = '';
     23
     24                cancel.onclick = function() {
     25                        var t = addReply, temp = t.I('bbp-temp-form-div'), respond = t.I(t.respondId);
     26
     27                        if ( ! temp || ! respond )
     28                                return;
     29
     30                        t.I('bbp_reply_to').value = '0';
     31                        temp.parentNode.insertBefore(respond, temp);
     32                        temp.parentNode.removeChild(temp);
     33                        this.style.display = 'none';
     34                        this.onclick = null;
     35                        return false;
     36                }
     37
     38                try { t.I('bbp_reply_content').focus(); }
     39                catch(e) {}
     40
     41                return false;
     42        },
     43
     44        I : function(e) {
     45                return document.getElementById(e);
     46        }
     47}