Changeset 362839
- Timestamp:
- 03/21/2011 12:06:19 PM (15 years ago)
- Location:
- rockhoist-badges
- Files:
-
- 6 added
- 2 edited
-
tags/1.1 (added)
-
tags/1.1/readme.txt (added)
-
tags/1.1/rh-badges.php (added)
-
tags/1.1/screenshot-1.png (added)
-
tags/1.1/screenshot-2.png (added)
-
tags/1.1/screenshot-3.png (added)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/rh-badges.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rockhoist-badges/trunk/readme.txt
r361587 r362839 23 23 1. The Badge management screen 24 24 2. The badge condition management screen 25 3. `<?php rhb_list_badges(); ?>`in action25 3. rhb_list_badges() in action 26 26 27 27 == Changelog == 28 28 29 = 1.1 = 30 * Added 'Latest Badges' widget. 31 * The original author is now checked for badges instead of the approver. 32 29 33 = 1.0 = 30 34 * First release. -
rockhoist-badges/trunk/rh-badges.php
r361580 r362839 2 2 /* 3 3 Plugin Name: Rockhoist Badges 4 Version: 1. 04 Version: 1.1 5 5 Plugin URI: http://blarrr.com/wordpress-badges-plugin/ 6 6 Description: A Stack Overflow inspired plugin which allows users to acquire badges. Badges are created and managed through the standard WordPress Dashboard. … … 28 28 */ 29 29 30 //Changelog 31 $current_version = array('1.0'); 32 33 //Install the plugin. 30 // Change Log 31 $current_version = array('1.1'); 32 33 // Database schema version 34 global $rhb_db_version; 35 $rhb_db_version = "1.0"; 36 37 // Install the plugin. 34 38 function rhb_installation() { 35 39 … … 87 91 dbDelta( $sql ); 88 92 } 89 } 90 91 92 // Hook for registering the install function upon plugin activation 93 94 add_option("rhb_db_version", $rhb_db_version); 95 } 96 97 98 // Hook for registering the install function upon plugin activation. 93 99 register_activation_hook(__FILE__,'rhb_installation'); 94 100 95 101 // Add the badge count to the Dashboard landing page. 96 add_action('right_now_content_table_end', 'rh _rhb_add_badge_counts');102 add_action('right_now_content_table_end', 'rhb_add_badge_counts'); 97 103 98 104 // Check for new badges after a post is published. 99 add_action('publish_post', 'rhb_check_ current_user');105 add_action('publish_post', 'rhb_check_author'); 100 106 101 107 // Check for new badges after a comment is published. 102 108 add_action('comment_post', 'rhb_check_current_user'); 103 109 104 function rh _rhb_add_badge_counts() {110 function rhb_add_badge_counts() { 105 111 106 112 $num = intval( rhb_count_badges() ); … … 112 118 $text = "<a href='edit.php?page=badges'>$text</a>"; 113 119 } 120 114 121 echo '<td class="first b b-badges">' . $num . '</td>'; 115 122 echo '<td class="t badges">' . $text . '</td>'; … … 181 188 } 182 189 190 function rhb_list_recent_badges() { 191 192 print '<div id="recent-badges-table"> 193 <table> 194 <tbody>'; 195 196 foreach (rhb_get_recent_badges() as $user_badge) { 197 198 print '<tr> 199 <td class="badge-cell"> 200 <a class="badge"> 201 <span class="'; 202 203 if ( 'gold' == $user_badge->type ) 204 echo 'badge3'; 205 elseif ( 'silver' == $user_badge->type ) 206 echo 'badge2'; 207 elseif ( 'bronze' == $user_badge->type ) 208 echo 'badge1'; 209 210 print '"></span> 211 ' . $user_badge->name . ' 212 </a> 213 </td> 214 <td>' . $user_badge->user_nicename. '</td> 215 </tr>'; 216 } 217 print '</tbody> 218 </table> 219 </div>'; 220 } 221 222 function rhb_get_recent_badges() { 223 224 global $wpdb; 225 226 if ( empty($filter ) ) { $filter = array(); } 227 $limit = ( isset( $filter['limit'] ) ? $filter['limit'] : 10 ); 228 229 $sql = 'SELECT u.id user_id, 230 u.user_nicename, 231 b.badge_id, 232 b.name, 233 b.type, 234 b.description 235 FROM ' . $wpdb->prefix . 'rh_user_badges ub, 236 ' . $wpdb->prefix . 'users u, 237 ' . $wpdb->prefix . 'rh_badges b 238 WHERE ub.badge_id = b.badge_id 239 AND ub.user_id = u.id 240 ORDER BY ub.time DESC 241 LIMIT 0, ' . $limit; 242 243 $recent_badges = $wpdb->get_results( $wpdb->prepare( $sql ) ); 244 245 return $recent_badges; 246 } 247 183 248 function rhb_get_badge_conditions( $filter = '' ) { 184 249 … … 213 278 'type' => $args['type']), 214 279 array( '%s', '%s', '%s' ) ); 215 216 280 } 217 281 … … 226 290 'count' => $args['count']), 227 291 array( '%d', '%s', '%s', '%d' ) ); 228 229 292 } 230 293 … … 267 330 268 331 $comment_count = $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) 269 FROM wp_comments332 FROM " . $wpdb->prefix . "comments 270 333 WHERE user_id = " . $args['user_ID'] . " 271 334 AND comment_approved = '1'" ) ); … … 279 342 280 343 $post_count = $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) 281 FROM wp_posts344 FROM " . $wpdb->prefix . "posts 282 345 WHERE post_author = " . $args['user_ID'] . " 283 346 AND post_status = 'publish' … … 313 376 } 314 377 378 function rhb_check_author() { 379 380 global $post; 381 382 $args = array('user_ID' => $post->post_author); 383 rhb_check_user_badges( $args ); 384 } 385 315 386 // Check whether an individual user has achieved any badges 316 387 function rhb_check_user_badges( $args = '' ) { … … 402 473 // Tags which have not been used are not returned. 403 474 $sql = "SELECT 'post_tag' rh_object_type, trm.name rh_value, COUNT( * ) rh_count 404 FROM wp_posts pst,405 wp_users usr,406 wp_term_taxonomy tax,407 wp_terms trm,408 wp_term_relationships rel475 FROM " . $wpdb->prefix . "posts pst, 476 " . $wpdb->prefix . "users usr, 477 " . $wpdb->prefix . "term_taxonomy tax, 478 " . $wpdb->prefix . "terms trm, 479 " . $wpdb->prefix . "term_relationships rel 409 480 WHERE pst.post_author = usr.ID 410 481 AND usr.ID = %d … … 617 688 618 689 // Check that the user can manage categories. 619 if ( !current_user_can('manage_categories'))690 if ( !current_user_can( 'manage_categories' ) ) 620 691 { 621 692 wp_die( __('You do not have sufficient permissions to access this page.') ); … … 639 710 <div class="updated"><p><strong><?php _e('Badge added successfully.', 'menu-badges' ); ?></strong></p></div> 640 711 <?php 641 642 712 } 643 713 … … 837 907 838 908 } // End rhb_badges_page function 839 840 } 909 } 910 911 /** 912 * LatestBadgesWidget Class 913 */ 914 class LatestBadgesWidget extends WP_Widget { 915 /** constructor */ 916 function LatestBadgesWidget() { 917 parent::WP_Widget(false, $name = 'Latest Badges'); 918 } 919 920 /** @see WP_Widget::widget */ 921 function widget($args, $instance) { 922 extract( $args ); 923 $title = apply_filters('widget_title', $instance['title']); 924 ?> 925 <?php echo $before_widget; ?> 926 <?php if ( $title ) 927 echo $before_title . $title . $after_title; 928 else 929 echo $before_title . 'Recent Badges' . $after_title; ?> 930 931 <?php rhb_list_recent_badges(); ?> 932 933 <?php echo $after_widget; ?> 934 <?php 935 } 936 937 /** @see WP_Widget::update */ 938 function update($new_instance, $old_instance) { 939 $instance = $old_instance; 940 $instance['title'] = strip_tags($new_instance['title']); 941 return $instance; 942 } 943 944 /** @see WP_Widget::form */ 945 function form($instance) { 946 $title = esc_attr($instance['title']); 947 ?> 948 <p> 949 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> 950 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> 951 </p> 952 <?php 953 } 954 955 } // class LatestBadgesWidget 956 957 // register LatestBadgesWidget widget 958 add_action('widgets_init', create_function('', 'return register_widget("LatestBadgesWidget");'));
Note: See TracChangeset
for help on using the changeset viewer.