Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions css/bbpress-threaded-replies.css
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
/* Modifications for threading; tested under bbp-theme-compat and bbp-twentyten. */
#content .replylist {
#bbpress-forums div.reply.even div.even,
#bbpress-forums div.reply.even ul.even,
#bbpress-forums div.reply.even div.odd,
#bbpress-forums div.reply.even ul.odd {
background-color: #fff;
}

#bbpress-forums div.reply.odd div.odd,
#bbpress-forums div.reply.odd ul.odd,
#bbpress-forums div.reply.odd div.even,
#bbpress-forums div.reply.odd ul.even {
background-color: #fbfbfb;
}

#bbpress-forums .replylist {
list-style: none;
margin: 0;
}
#content .replylist table,
#content .replylist tbody,
#content .replylist tr,
#content .replylist td {
#bbpress-forums .replylist table,
#bbpress-forums .replylist tbody,
#bbpress-forums .replylist tr,
#bbpress-forums .replylist td {
border-collapse: collapse;
}
#content .replylist ul.children {
#bbpress-forums .replylist ul.children {
list-style: none;
margin: 0 0 0 2.0em ;
}
#content .replylist li,
#content .replylist li div.reply {
#bbpress-forums .replylist li,
#bbpress-forums .replylist li div.reply {
padding-bottom: 0;
}
#content table.bbp-replies,
#content .replylist table.bbp-replies {
#bbpress-forums table.bbp-replies,
#bbpress-forums .replylist table.bbp-replies {
margin: -1px 0 0 0;
}
#content .replylist .ucc-bbp-in-reply-to {
#bbpress-forums .replylist .ucc-bbp-in-reply-to {
padding: 0 1.625em 1.625em 1.625em;
border-top: 0px;
text-align: right;
}
#content .replylist .bbp-reply-form {
#bbpress-forums .replylist .bbp-reply-form {
margin-bottom: 0;
-moz-border-radius: 0px;
border-radius: 0px;
border: 0;
width: auto;
position: relative;
}
#content .replylist #cancel-in-reply-to-link {
#bbpress-forums .replylist #cancel-in-reply-to-link {
position: absolute;
right: 1.625em;
top: 0.7em;
Expand All @@ -47,8 +61,8 @@
color: #fff;
text-transform: uppercase;
}
#content fieldset.bbp-form,
#container fieldset.bbp-form,
#bbpress-forums fieldset.bbp-form,
#container fieldset.bbp-form,
#wrapper fieldset.bbp-form {
border-color: #ddd;
}
77 changes: 42 additions & 35 deletions includes/bbpress-threaded-replies.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct() {
} // __construct

public function init() {
// Input handling (metabox, reply input form).
// Input handling (metabox, reply input form)
if ( is_admin() ) {
add_action( 'bbp_reply_metabox', array( $this, 'extend_reply_metabox' ), 10, 1 );
add_action( 'bbp_reply_attributes_metabox_save', array( $this, 'extend_reply_attributes_metabox_save' ), 10, 3 );
Expand All @@ -25,17 +25,18 @@ public function init() {
add_action( 'bbp_theme_before_reply_form', array( $this, 'add_cancel_link' ) );
}

// bbPress action/filter hooks.
// bbPress action/filter hooks
add_filter( 'bbp_has_replies', array( $this, 'has_replies' ), 10, 2 );
add_filter( 'bbp_new_reply_pre_set_terms', array( $this, 'save_post' ), 10, 3 );
add_filter( 'bbp_get_reply_url', array( $this, 'reply_url' ), 15, 3 );
add_filter( 'bbp_get_replies_per_page', array( $this, 'replies_per_page' ), 10, 2 );
add_filter( 'bbp_replies_pagination', array( $this, 'replies_pagination' ) );
add_filter( 'bbp_get_topic_pagination', array( $this, 'get_topic_pagination' ), 10, 2 );
add_filter( 'bbp_get_topic_pagination_count', array( $this, 'get_topic_pagination_count' ) );
add_action( 'bbp_merge_topic', array( $this, 'merge_topic' ), 10, 2 );
add_action( 'bbp_pre_split_topic', array( $this, 'split_topic' ), 10, 3 );
add_action( 'bbp_pre_split_topic', array( $this, 'split_topic' ), 10, 3 );

// Caching interactions.
// Caching interactions
add_action( 'bbp_new_reply_pre_extras', array( $this, 'clean_cache' ) );
add_action( 'bbp_edit_reply_pre_extras', array( $this, 'clean_cache' ) );
add_action( 'bbp_spam_reply', array( $this, 'clean_cache' ) );
Expand All @@ -56,7 +57,7 @@ public function init() {
add_action( 'bbp_untrashed_topic', array( $this, 'clean_cache' ) );
} // init

// Admin-side edit functionality and input handling.
// Admin-side edit functionality and input handling
public function extend_reply_metabox( $reply_id ) {
$value = absint( get_post_meta( $reply_id, '_ucc_btr_in_reply_to', true ) );
?>
Expand All @@ -73,7 +74,7 @@ public function extend_reply_metabox( $reply_id ) {
public function extend_reply_attributes_metabox_save( $reply_id, $topic_id, $forum_id ) {
$in_reply_to = !empty( $_REQUEST['inreplyto'] ) ? (int) $_REQUEST['inreplyto'] : 0;

// Trust but verify.
// Trust but verify
if ( !isset( $_REQUEST['inreplyto_nonce'] ) )
return;
if ( !check_admin_referer( 'inreplyto_metabox', 'inreplyto_nonce' ) )
Expand All @@ -82,15 +83,15 @@ public function extend_reply_attributes_metabox_save( $reply_id, $topic_id, $for
update_post_meta( $reply_id, '_ucc_btr_in_reply_to', $in_reply_to );
} // extend_reply_attributes_metabox_save

// Add hidden replyto form field and nonce to reply form.
// Add hidden replyto form field and nonce to reply form
public function add_form_field() {
if ( bbp_is_reply_edit() )
return;

// We have to set this for non-JS replies.
// We have to set this for non-JS replies
$in_reply_to = !empty( $_REQUEST['inreplyto'] ) ? (int) $_REQUEST['inreplyto'] : 0;

// Trust but verify.
// Trust but verify
if ( !isset( $_REQUEST['inreplyto_nonce'] ) ) {
$in_reply_to = 0;
} else {
Expand All @@ -102,30 +103,30 @@ public function add_form_field() {
echo "\t\t\t\t\t\t<input type='hidden' name='inreplyto_nonce' id='inreplyto_nonce' value='" . wp_create_nonce( 'inreplyto-nonce' ) . "' />\n";
} // add_form_field

// Add cancel link to reply form.
// Add cancel link to reply form
public function add_cancel_link() {
if ( bbp_is_reply_edit() )
return;

echo "<h3><small>" . ucc_btr_get_cancel_in_reply_to_link( 'Cancel reply' ) . "</small></h3>";
} // add_cancel_link

// Set up replies for threading on bbPress has_replies().
// Set up replies for threading on bbPress has_replies()
public function has_replies( $have_posts, $reply_query ) {
global $bbp, $wp_rewrite, $overridden_rpage;

if ( is_object( $bbp ) ) {
// bbPress version < 2.1 or already initialized.
// bbPress version < 2.1 or already initialized
} elseif ( function_exists( 'bbpress' ) ) {
$bbp = bbpress();
}

// Heavy lifting for future calls.
// Heavy lifting for future calls
$posts = $reply_query->posts;
$replies = array();
if ( !empty( $posts ) ) {
foreach( $posts as &$post ) {
// Ignore the topic if included.
// Ignore the topic if included
if ( bbp_get_reply_post_type() == $post->post_type ) {
$in_reply_to = get_post_meta( $post->ID, '_ucc_btr_in_reply_to', true );
if ( empty( $in_reply_to ) || ( bbp_get_reply_topic_id( $post->ID ) == $in_reply_to ) )
Expand All @@ -140,7 +141,7 @@ public function has_replies( $have_posts, $reply_query ) {
$bbp->reply_query->posts = $posts;
$bbp->replies = $replies;

// Set up based on options.
// Set up based on options
$options = get_option( '_ucc_btr_options' );
$roots = ucc_btr_get_root_element_count( $bbp->current_topic_id );
if ( $options['page_replies'] ) {
Expand All @@ -157,7 +158,7 @@ public function has_replies( $have_posts, $reply_query ) {
$bbp->reply_query->posts_per_page = $replies_per_page;
$bbp->reply_query->max_num_pages = $max_num_pages;

// Deal with reply pagination here.
// Deal with reply pagination here
$topic_id = bbp_get_topic_id();
if ( $wp_rewrite->using_permalinks() )
$base = trailingslashit( get_permalink( $topic_id ) ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
Expand All @@ -179,11 +180,11 @@ public function has_replies( $have_posts, $reply_query ) {
return $have_posts;
} // has_replies

// Add post_meta for in_reply_to on save.
// Add post_meta for in_reply_to on save
public function save_post( $terms, $topic_id, $reply_id ) {
$in_reply_to = !empty( $_REQUEST['inreplyto'] ) ? (int) $_REQUEST['inreplyto'] : 0;

// Trust but verify.
// Trust but verify
if ( !isset( $_REQUEST['inreplyto_nonce'] ) )
return;
if ( !wp_verify_nonce( $_REQUEST['inreplyto_nonce'], 'inreplyto-nonce' ) )
Expand All @@ -194,7 +195,7 @@ public function save_post( $terms, $topic_id, $reply_id ) {
return $terms;
} // save_post

// Reply URL for non-JS users.
// Reply URL for non-JS users
public function reply_url( $url, $reply_id, $redirect_to ) {
$reply = get_post( $reply_id );
if ( bbp_get_reply_post_type() == $reply->post_type ) {
Expand All @@ -203,15 +204,15 @@ public function reply_url( $url, $reply_id, $redirect_to ) {
return $url;
} // reply_url

// Return all replies if on a single topic view.
public function replies_per_page( $retval, $per ) {
// Return all replies if on a single topic view
public function replies_per_page( $retval, $default ) {
if ( bbp_is_single_topic() && !( bbp_is_topic_merge() || bbp_is_topic_split() || bbp_is_topic_edit() ) )
return -1;
else
return $retval;
} // replies_per_page

// Pagination for threaded replies.
// Pagination for threaded replies
public function replies_pagination( $args ) {
global $wp_rewrite;

Expand All @@ -224,7 +225,7 @@ public function replies_pagination( $args ) {
return $args;
} // replies_pagination

// Fix topic pagination for display on forum pages.
// Fix topic pagination for display on forum pages
public function get_topic_pagination( $links, $args ) {
global $wp_rewrite;

Expand Down Expand Up @@ -271,7 +272,13 @@ public function get_topic_pagination( $links, $args ) {
return $pagination_links;
} // get_topic_pagination

// Handle inheritance on merges.
// Remove topic pagination count for display on topic pages
// @todo Fix with actual numbers
public function get_topic_pagination_count( $retstr ) {
return '';
} // get_topic_pagination_count

// Handle inheritance on merges
public function merge_topic( $destination_topic_id, $source_topic_id ) {
$replies = (array) get_posts( array(
'post_parent' => $source_topic_id,
Expand All @@ -280,7 +287,7 @@ public function merge_topic( $destination_topic_id, $source_topic_id ) {
'order' => 'ASC'
) );

// Clean up orphans by setting them as replies to the source topic.
// Clean up orphans by setting them as replies to the source topic
if ( !empty( $replies ) ) {
foreach ( $replies as $reply ) {
$in_reply_to = get_post_meta( $reply->ID, '_ucc_btr_in_reply_to', true );
Expand All @@ -289,37 +296,37 @@ public function merge_topic( $destination_topic_id, $source_topic_id ) {
}
}

// Fix the source topic.
// Fix the source topic
update_post_meta( $source_topic_id, '_ucc_btr_in_reply_to', '0' );
} // merge_topic

// Handle inheritance on splits.
// Handle inheritance on splits
public function split_topic( $from_reply_id, $source_topic_id, $destination_topic_id ) {
global $wpdb;
$from_reply = get_post( $from_reply_id );

// get_posts() is not used because it does not have the >= comparison for post_date.
// get_posts() is not used because it does not have the >= comparison for post_date
$replies = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_parent = %d AND {$wpdb->posts}.post_type = %s ORDER BY {$wpdb->posts}.post_date ASC", $from_reply->post_date, $source_topic_id, bbp_get_reply_post_type() ) );

// Clean up orphans.
// Clean up orphans
$ids = array();
if ( !empty( $replies ) && !is_wp_error( $replies ) ) {
foreach ( $replies as $reply ) {
$ids[] = $reply->ID;
$in_reply_to = get_post_meta( $reply->ID, '_ucc_btr_in_reply_to', true );
if ( !in_array( $in_reply_to, $ids ) )
update_post_meta( $reply->ID, '_ucc_btr_in_reply_to', 0 );
// Special case for new topic from reply.
// Special case for new topic from reply
if ( ( $from_reply_id == $destination_topic_id ) && ( $from_reply_id == $in_reply_to ) )
update_post_meta( $reply->ID, '_ucc_btr_in_reply_to', 0 );
}
}

// Fix the parent reply.
// Fix the parent reply
update_post_meta( $from_reply_id, '_ucc_btr_in_reply_to', 0 );
} // split_topic

// Tidy up topic information after major changes.
// Tidy up topic information after major changes
public function clean_cache() {
$group = 'ucc_btr';
$expires = ucc_btr_get_expires();
Expand All @@ -346,16 +353,16 @@ public function clean_cache() {
$cache = wp_cache_get( $key, $group );

if ( is_array( $cache ) && !empty( $cache ) ) {
if ( array_key_exists( $topic_id, $cache ) ) {
unset( $cache[$topic_id] );
if ( array_key_exists( $topic_id, $cache ) ) {
unset( $cache[$topic_id] );
wp_cache_set( $key, $cache, $group, $expires );
}
}
}
}
}

// Wipe cache completely (when settings change, etc.).
// Wipe cache completely (when settings change, etc.)
public function clear_cache() {
$group = 'ucc_btr';

Expand Down
Loading