Changeset 833

Show
Ignore:
Timestamp:
02/05/08 22:15:08 (10 months ago)
Author:
mdawaffe
Message:

update to 0.8.3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bb-ratings/trunk/bb-ratings.css

    r19 r833  
    11div.star-holder { 
    22        position: relative; 
    3         height: 16px; 
    4         width: 85px; 
    5         font-size: 16px; 
     3        height: 19px; 
     4        width: 100px; 
     5        font-size: 19px; 
    66} 
    77 
     
    3939 
    4040div.star img { 
    41         width: 16px; 
    42         height: 16px; 
     41        width: 19px; 
     42        height: 19px; 
    4343        border-left: 1px solid #fff; 
    4444        border-right: 1px solid #fff; 
    4545} 
    4646 
     47 
     48.rating-holder { 
     49        width: 100px; 
     50        position: relative; 
     51} 
     52 
     53td .rating-holder { 
     54        margin: 0 auto; 
     55        padding-right: 3ex; 
     56} 
     57 
     58span.count { 
     59        position: absolute; 
     60        left: 100px; 
     61        top: 0; 
     62} 
     63 
     64#bb-rating { 
     65        float: right; 
     66        padding-right: 1ex; 
     67} 
     68 
     69#bb-rating h4 { 
     70        margin-bottom: 0; 
     71} 
  • bb-ratings/trunk/bb-ratings.js

    r20 r833  
    1717        rateAjax.request(rateAjax.url); 
    1818        $$( '.star-rating.select' ).each( function(i) { 
    19                 i.style.width = 85 * rate / 5 + 'px'; 
     19                i.style.width = 100 * rate / 5 + 'px'; 
    2020        } ); 
    2121} 
  • bb-ratings/trunk/bb-ratings.php

    r227 r833  
    66Author: Michael D Adams 
    77Author URI: http://blogwaffe.com/ 
    8 Version: 0.8 
     8Version: 0.8.3 
    99*/ 
    1010 
    1111/* Template Functions */ 
     12 
     13function bb_get_rating_plugin_version() { return '0.8.3'; } 
    1214 
    1315function bb_rating( $topic_id = 0 ) { 
     
    2123        global $topic; 
    2224        if ( $topic_id ) 
    23                 $topic = get_topic( $topic_id ); 
    24         echo is_array($topic->rating) ? count($topic->rating) : ( $show_zero ? 0 : '' ); 
     25                $_topic = get_topic( $topic_id ); 
     26        else 
     27                $_topic =& $topic; 
     28        echo is_array($_topic->rating) ? count($_topic->rating) : ( $show_zero ? 0 : '' ); 
    2529} 
    2630 
     
    3943        <div id="rate-response"></div> 
    4044        <div class="star-holder select"> 
    41                 <div class="star star-rating select" style="width: <?php echo ( 85 * $rating / 5 ); ?>px"></div> 
     45                <div class="star star-rating select" style="width: <?php echo ( 100 * $rating / 5 ); ?>px"></div> 
    4246<?php for ( $r = 5; $r > 0; $r-- ) : ?> 
    43                 <div class="star star<?php echo $r; ?> select"><a href="<?php echo bb_nonce_url( add_query_arg( 'rate', $r ), 'rate-topic_' . $topic->topic_id ); ?>" title="<?php echo $title_array[$r]; ?>"><img src="<?php echo bb_path_to_url( dirname(__FILE__) . '/star.gif'); ?>" /></a></div> <?php endfor; ?> 
     47                <div class="star star<?php echo $r; ?> select"><a href="<?php echo bb_nonce_url( add_query_arg( array('rate' => $r, 'topic_id' => $topic->topic_id) ), 'rate-topic_' . $topic->topic_id ); ?>" title="<?php echo $title_array[$r]; ?>"><img src="<?php echo bb_path_to_url( dirname(__FILE__) . '/star.gif'); ?>" /></a></div> 
     48<?php endfor; ?> 
    4449        </div> 
    4550<?php 
     
    6065 
    6166function bb_top_topics( $number = 0 ) { 
    62         global $bbdb, $page, $bb_last_countable_query; 
    63  
    64         $limit = $number ? $number : bb_get_option('page_topics'); 
    65         if ( 1 < $page ) 
    66                 $limit = ($limit * ($page - 1)) . ", $limit"; 
    67  
    68         $bb_last_countable_query = "SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key = 'avg_rating' ORDER BY meta_value DESC LIMIT $limit"; 
    69  
    70         if ( !$top = (array) $bbdb->get_col( $bb_last_countable_query) ) 
    71                 return get_latest_topics(); 
    72  
    73         $top = join(',', $top); 
    74         $topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE topic_id IN ($top) AND topic_status = 0 ORDER BY FIELD(topic_id, $top)"); 
    75         return bb_append_meta( $topics, 'topic' ); 
     67        $top_topics_query = bb_view_query( 'top-rated', array( 'per_page' => $number ) ); 
     68        return $top_topics_query->results; 
    7669} 
    7770 
     
    8982 
    9083        $user = bb_get_user( $user_id ? $user_id : $bb_post->poster_id ); 
    91  
    9284        if ( isset($user->rating[$topic->topic_id]) ) 
    9385                return $user->rating[$topic->topic_id]; 
     
    9991/* Backend Functions */ 
    10092 
     93function bb_rating_init() { 
     94        bb_register_view( 'top-rated', __('Highest Rated', 'bb-rating'), 
     95                array( 'meta_key' => 'avg_rating', 'order_by' => '0 + tm.meta_value' ) 
     96        ); 
     97} 
     98 
    10199function bb_do_rating() { 
    102100        global $topic, $bb_current_user; 
    103101 
    104         bb_enqueue_script( 'bb_rating', bb_path_to_url( dirname(__FILE__) . '/bb-ratings.js' ), array('wp-ajax') ); 
     102        bb_enqueue_script( 'bb_rating', bb_path_to_url( dirname(__FILE__) . '/bb-ratings.js' ), array('wp-ajax'), bb_get_rating_plugin_version() ); 
    105103 
    106104        if ( !isset($_GET['rate']) ) 
     
    142140                return new WP_Error( 'rating', __('Invalid rating.', 'bb-rating') ); 
    143141 
     142        if ( !is_array($topic->rating) || !isset($topic->rating[$user_id]) ) { 
     143                $total_votes = bb_get_option( 'bb_ratings_total_votes' ) + 1; 
     144                bb_update_option( 'bb_ratings_total_votes', $total_votes ); 
     145        } 
     146 
    144147        if ( is_array($topic->rating) ) 
    145148                $topic->rating[$user_id] = $rating; 
     
    150153        bb_update_topicmeta( $topic_id, 'rating', $topic->rating ); 
    151154        bb_update_topicmeta( $topic_id, 'avg_rating', $avg ); 
     155        bb_update_topicmeta( $topic_id, 'rating_score', ( $avg - 3 ) * count($topic->rating) ); 
    152156 
    153157        if ( is_array($user->rating) ) 
     
    175179function bb_display_rating( $rating, $current_user = false ) { ?> 
    176180        <div class="star-holder"> 
    177                 <div class="star star-rating<?php if ( $current_user ) echo ' select'; ?>" style="width: <?php echo ( 85 * $rating / 5 ); ?>px"></div> 
     181                <div class="star star-rating<?php if ( $current_user ) echo ' select'; ?>" style="width: <?php echo ( 100 * $rating / 5 ); ?>px"></div> 
    178182<?php for ( $r = 5; $r > 0; $r-- ) : ?> 
    179183                <div class="star star<?php echo $r; ?>"><img src="<?php echo bb_path_to_url( dirname(__FILE__) . '/star.gif' ); ?>" /></div> 
     
    187191} 
    188192 
     193function bb_rating_add_recount_list() { 
     194        global $recount_list; 
     195        $recount_list[] = array('bb-ratings', __('Recount Ratings', 'bb-rating'), 'bb_rating_recount'); 
     196        return; 
     197} 
     198 
     199function bb_rating_recount() { 
     200        global $bbdb; 
     201        if ( isset($_POST['bb-ratings']) && 1 == $_POST['bb-ratings'] ): 
     202                $total = 0; 
     203                echo "\t<li>\n"; 
     204                if ( $topics = (array) $bbdb->get_col("SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key = 'rating'") ) : 
     205                        echo "\t\t" . __('Recounting ratings...', 'bb-rating') . "<br />\n"; 
     206                        foreach ( $topics as $topic_id ) : 
     207                                $topic = get_topic( $topic_id ); 
     208                                $total += $count = count($topic->rating); 
     209                                bb_update_topicmeta( $topic_id, 'rating_score', ( $topic->avg_rating - 3 ) * $count ); 
     210                        endforeach; 
     211                        bb_update_option( 'bb_ratings_total_votes', $total ); 
     212                endif; 
     213                echo "\t\t" . __('Done recounting ratings.', 'bb-rating'); 
     214                echo "\n\t</li>"; 
     215        endif; 
     216} 
     217 
     218add_action( 'bb_init', 'bb_rating_init' ); 
     219 
    189220add_action( 'bb_topic.php_pre_db', 'bb_do_rating' ); 
    190221add_action( 'bb_head', 'bb_rating_stylesheet' ); 
     
    194225add_action( 'bb_delete_topic', 'bb_rating_bb_delete_topic', 10, 3 ); 
    195226 
     227add_action( 'bb_recount_list', 'bb_rating_add_recount_list' ); 
    196228?> 
  • bb-ratings/trunk/readme.txt

    r227 r833  
    22Tags: rating, rate, vote 
    33Contributors: mdawaffe 
    4 Requires at least: 0.8 
    5 Tested up to: 0.8 
    6 Stable Tag: 0.8 
     4Requires at least: 0.8.3 
     5Tested up to: 0.8.3.1 
     6Stable Tag: 0.8.3 
    77 
    88Allows users to rate topics on a simple 1-5 star scale.