Changeset 833
- Timestamp:
- 02/05/08 22:15:08 (10 months ago)
- Files:
-
- bb-ratings/trunk/bb-ratings.css (modified) (2 diffs)
- bb-ratings/trunk/bb-ratings.js (modified) (1 diff)
- bb-ratings/trunk/bb-ratings.php (modified) (11 diffs)
- bb-ratings/trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
bb-ratings/trunk/bb-ratings.css
r19 r833 1 1 div.star-holder { 2 2 position: relative; 3 height: 1 6px;4 width: 85px;5 font-size: 1 6px;3 height: 19px; 4 width: 100px; 5 font-size: 19px; 6 6 } 7 7 … … 39 39 40 40 div.star img { 41 width: 1 6px;42 height: 1 6px;41 width: 19px; 42 height: 19px; 43 43 border-left: 1px solid #fff; 44 44 border-right: 1px solid #fff; 45 45 } 46 46 47 48 .rating-holder { 49 width: 100px; 50 position: relative; 51 } 52 53 td .rating-holder { 54 margin: 0 auto; 55 padding-right: 3ex; 56 } 57 58 span.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 17 17 rateAjax.request(rateAjax.url); 18 18 $$( '.star-rating.select' ).each( function(i) { 19 i.style.width = 85* rate / 5 + 'px';19 i.style.width = 100 * rate / 5 + 'px'; 20 20 } ); 21 21 } bb-ratings/trunk/bb-ratings.php
r227 r833 6 6 Author: Michael D Adams 7 7 Author URI: http://blogwaffe.com/ 8 Version: 0.8 8 Version: 0.8.3 9 9 */ 10 10 11 11 /* Template Functions */ 12 13 function bb_get_rating_plugin_version() { return '0.8.3'; } 12 14 13 15 function bb_rating( $topic_id = 0 ) { … … 21 23 global $topic; 22 24 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 : '' ); 25 29 } 26 30 … … 39 43 <div id="rate-response"></div> 40 44 <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> 42 46 <?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; ?> 44 49 </div> 45 50 <?php … … 60 65 61 66 function 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; 76 69 } 77 70 … … 89 82 90 83 $user = bb_get_user( $user_id ? $user_id : $bb_post->poster_id ); 91 92 84 if ( isset($user->rating[$topic->topic_id]) ) 93 85 return $user->rating[$topic->topic_id]; … … 99 91 /* Backend Functions */ 100 92 93 function 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 101 99 function bb_do_rating() { 102 100 global $topic, $bb_current_user; 103 101 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() ); 105 103 106 104 if ( !isset($_GET['rate']) ) … … 142 140 return new WP_Error( 'rating', __('Invalid rating.', 'bb-rating') ); 143 141 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 144 147 if ( is_array($topic->rating) ) 145 148 $topic->rating[$user_id] = $rating; … … 150 153 bb_update_topicmeta( $topic_id, 'rating', $topic->rating ); 151 154 bb_update_topicmeta( $topic_id, 'avg_rating', $avg ); 155 bb_update_topicmeta( $topic_id, 'rating_score', ( $avg - 3 ) * count($topic->rating) ); 152 156 153 157 if ( is_array($user->rating) ) … … 175 179 function bb_display_rating( $rating, $current_user = false ) { ?> 176 180 <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> 178 182 <?php for ( $r = 5; $r > 0; $r-- ) : ?> 179 183 <div class="star star<?php echo $r; ?>"><img src="<?php echo bb_path_to_url( dirname(__FILE__) . '/star.gif' ); ?>" /></div> … … 187 191 } 188 192 193 function 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 199 function 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 218 add_action( 'bb_init', 'bb_rating_init' ); 219 189 220 add_action( 'bb_topic.php_pre_db', 'bb_do_rating' ); 190 221 add_action( 'bb_head', 'bb_rating_stylesheet' ); … … 194 225 add_action( 'bb_delete_topic', 'bb_rating_bb_delete_topic', 10, 3 ); 195 226 227 add_action( 'bb_recount_list', 'bb_rating_add_recount_list' ); 196 228 ?> bb-ratings/trunk/readme.txt
r227 r833 2 2 Tags: rating, rate, vote 3 3 Contributors: mdawaffe 4 Requires at least: 0.8 5 Tested up to: 0.8 6 Stable Tag: 0.8 4 Requires at least: 0.8.3 5 Tested up to: 0.8.3.1 6 Stable Tag: 0.8.3 7 7 8 8 Allows users to rate topics on a simple 1-5 star scale.
