Re: new plugin: BuddyPress Rate Forum Posts
At the moment, the classes are added to individual posts in a topic, by javascript. This results in extra server load, because wordpress has to do two whole startups for each such page. The trade-off is adding another apply_filter and a do_action to the theme, but as this plugin already benefits from one such proposed theme change, we can get two for the price of one.
Proposed change to buddypress/bp-themes/bp-default/groups/single/forum/topic.php, from line 26:
<ul id="topic-post-list" class="item-list">
<?php while ( bp_forum_topic_posts() ) : bp_the_forum_topic_post(); ?>
<li <?php
$topic_post_id = bp_get_the_topic_post_id();
echo "id='post-$topic_post_id' class='",
apply_filters('bp_single_forum_topic_post_css',array('class'=>'', 'post_id'=>$topic_post_id)),
"'";
?> >
<div class="poster-meta">
<a href="<?php bp_the_topic_post_poster_link() ?>">
<?php bp_the_topic_post_poster_avatar( 'width=40&height=40' ) ?>
</a>
<?php echo sprintf( __( '%s said %s ago:', 'buddypress' ), bp_get_the_topic_post_poster_name(), bp_get_the_topic_post_time_since() ) ?>
</div>
<div class="post-content">
<?php bp_the_topic_post_content() ?>
</div>
<div class="admin-links">
<?php
if ( bp_group_is_admin() || bp_group_is_mod() || bp_get_the_topic_post_is_mine() ) :
bp_the_topic_post_admin_links();
endif;
do_action( 'bp_single_forum_topic_links' , $topic_post_id );
?>
<a href="#post-<?php echo $topic_post_id; ?>" title="<?php _e( 'Permanent link to this post', 'buddypress' ) ?>">#</a>
</div>
</li>
<?php endwhile; ?>
</ul>
Proposed change to buddypress-rate-forum-posts/bp-rate-forum-posts.php, insert:
// modifies the css class for topics to highlight popular posts, and hide very unpopular ones
function rfp_css_class_for_post($args) {
global $rfp;
$class = $args['class'];
$post_rating = rfp_get_post_rating( $args['post_id'] );
$rfpclass = '';
error_log('rfp='.print_r($rfp,true));
if ( $post_rating == NULL )
$rfpclass = '';
else if ( $post_rating >= $rfp->superboost )
$rfpclass = 'rfp-superboost';
elseif ( $post_rating >= $rfp->boost )
$rfpclass = 'rfp-boost';
elseif ( $post_rating <= $rfp->hide )
$rfpclass = 'rfp-hide';
elseif ( $post_rating <= $rfp->diminish )
$rfpclass = 'rfp-diminish';
//error_log("in rfp_css_class_for_post rating '$post_rating' adding class '$rfpclass' to '$class' with args ".print_r($args,true));
return $class.($class?' ''').$rfpclass;
}
add_filter( 'bp_single_forum_topic_post_css', 'rfp_css_class_for_post', 3);
function rfp_echo_hidden_post_link($post_id) {
global $rfp;
$post_rating = rfp_get_post_rating( $post_id );
if ( $post_rating && $post_rating <= $rfp->hide )
echo "<span class='rfp-show' onclick='jQuery(this).remove();jQuery("#post-$post_id").removeClass( "rfp-hide" );'>Click to show this hidden post</span>";
}
add_action( 'bp_single_forum_topic_links', 'rfp_echo_hidden_post_link', 3);
And then the javascript section starting jQuery(document).ready( function()
can be removed from buddypress-rate-forum-posts/js, and the corresponding section can be removed from the end of buddypress-rate-forum-posts/rate.php