Guest User

Untitled

a guest
Jul 11th, 2010
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function bp_enhanced_widgets_popular_init() {
  5. add_action('widgets_init', create_function('', 'return register_widget("BP_Enhanced_Groups_Widget_Popular");') );
  6. }
  7. add_action( 'plugins_loaded', 'bp_enhanced_widgets_popular_init', 15 );
  8.  
  9.  
  10.  
  11.  
  12.  
  13. class BP_Enhanced_Groups_Widget_Popular extends WP_Widget {
  14. function bp_enhanced_groups_widget_popular() {
  15. parent::WP_Widget( false, $name = __( 'Most Popular Resturants', 'buddypress' ) );
  16.  
  17. if ( is_active_widget( false, false, $this->id_base ) )
  18. wp_enqueue_script( 'groups_widget_groups_list-js', BP_PLUGIN_URL . 'widget-groups-popular.js', array('jquery') );
  19. }
  20.  
  21. function widget($args, $instance) {
  22. global $bp;
  23.  
  24. extract( $args );
  25.  
  26. echo $before_widget;
  27. echo $before_title
  28. . $widget_name
  29. . $after_title; ?>
  30.  
  31.  
  32. <?php if ( bp_has_groups( 'type=' . $instance['group_default'] . '&max=' . $instance['max_groups'] ) ) : ?>
  33. <ul id="groups-list" class="item-list">
  34. <?php while ( bp_groups() ) : bp_the_group(); ?>
  35. <li>
  36. <div class="item-avatar">
  37. <a href="<?php bp_group_permalink() ?>"><?php bp_group_avatar_thumb() ?></a>
  38. </div>
  39.  
  40.  
  41. <div class="item">
  42. <div class="item-title"><a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a></div>
  43. <div class="item-meta"><span class="activity">
  44. <?php
  45. if ( $instance['group_default'] == 'newest') {
  46. echo "Created " . bp_get_group_date_created() . " ago";
  47. }
  48. if ( $instance['group_default'] == 'active')
  49. echo bp_get_group_last_active();
  50. if ( $instance['group_default'] == 'popular')
  51. echo bp_group_member_count();
  52.  
  53. ?></span></div>
  54. </div>
  55. </li>
  56.  
  57. <?php endwhile; ?>
  58. </ul>
  59. <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?>
  60. <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo attribute_escape( $instance['max_groups'] ); ?>" />
  61.  
  62. <?php else: ?>
  63.  
  64. <div class="widget-error">
  65. <?php _e('There are no resturants to display.', 'buddypress') ?>
  66. </div>
  67.  
  68. <?php endif; ?>
  69.  
  70. <?php echo $after_widget; ?>
  71. <?php
  72. }
  73.  
  74. function update( $new_instance, $old_instance ) {
  75. $instance = $old_instance;
  76. $instance['max_groups'] = strip_tags( $new_instance['max_groups'] );
  77. $instance['group_default'] = strip_tags( $new_instance['group_default'] );
  78.  
  79. return $instance;
  80. }
  81.  
  82. function form( $instance ) {
  83. $instance = wp_parse_args( (array) $instance, array( 'max_groups' => 5, 'group_default' => 'popular' ) );
  84. $max_groups = strip_tags( $instance['max_groups'] );
  85. $group_default = strip_tags( $instance['group_default'] );
  86. ?>
  87.  
  88. <p><label for="bp-groups-widget-groups-max"><?php _e('Max groups to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_groups' ); ?>" name="<?php echo $this->get_field_name( 'max_groups' ); ?>" type="text" value="<?php echo attribute_escape( $max_groups ); ?>" style="width: 30%" /></label></p>
  89.  
  90. <p><label for="bp-groups-widget-groups-default"><?php _e('Default groups to show:', 'buddypress'); ?> <br />
  91. <input id="<?php echo $this->get_field_id( 'group_default' )-newest; ?>" name="<?php echo $this->get_field_name( 'group_default' ); ?>" type="radio" value="newest" <?php if ($group_default == "newest") echo "checked"; ?> /></label> Newest<br />
  92.  
  93. <input id="<?php echo $this->get_field_id( 'group_default' )-active; ?>" name="<?php echo $this->get_field_name( 'group_default' ); ?>" type="radio" value="active" <?php if ($group_default == "active") echo "checked"; ?>/></label> Recently Active<br />
  94. <input id="<?php echo $this->get_field_id( 'group_default' )-popular; ?>" name="<?php echo $this->get_field_name( 'group_default' ); ?>" type="radio" value="popular" <?php if ($group_default == "popular") echo "checked"; ?>/></label> Popular
  95. </p>
  96.  
  97. <?php
  98. }
  99. }
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment