Changeset 1608 for trunk/bp-groups/bp-groups-widgets.php
- Timestamp:
- 07/15/2009 07:29:57 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/bp-groups/bp-groups-widgets.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-widgets.php
r1599 r1608 3 3 /* Register widgets for groups component */ 4 4 function groups_register_widgets() { 5 global $current_blog; 6 7 /* Site welcome widget */ 8 wp_register_sidebar_widget( 'buddypress-groups', __( 'Groups', 'buddypress' ), 'groups_widget_groups_list' ); 9 wp_register_widget_control( 'buddypress-groups', __( 'Groups', 'buddypress' ), 'groups_widget_groups_list_control' ); 10 11 /* Include the javascript needed for activated widgets only */ 12 if ( is_active_widget( 'groups_widget_groups_list' ) ) { 13 wp_enqueue_script( 'groups_widget_groups_list-js', BP_PLUGIN_URL . '/bp-groups/js/widget-groups.js', array('jquery', 'jquery-livequery-pack') ); 14 wp_enqueue_style( 'groups_widget_members-css', BP_PLUGIN_URL . '/bp-groups/css/widget-groups.css' ); 15 } 5 add_action('widgets_init', create_function('', 'return register_widget("BP_Groups_Widget");') ); 16 6 } 17 7 add_action( 'plugins_loaded', 'groups_register_widgets' ); … … 19 9 /*** GROUPS WIDGET *****************/ 20 10 21 function groups_widget_groups_list($args) { 22 global $current_blog, $bp; 23 24 extract($args); 25 $options = get_blog_option( $current_blog->blog_id, 'groups_widget_groups_list' ); 26 ?> 27 <?php echo $before_widget; ?> 28 <?php echo $before_title 29 . $widget_name 30 . $after_title; ?> 31 32 <?php 33 if ( empty( $options['max_groups'] ) || !$options['max_groups'] ) 34 $options['max_groups'] = 5; 35 36 if ( !$groups = wp_cache_get( 'popular_groups', 'bp' ) ) { 37 $groups = groups_get_popular( $options['max_groups'], 1 ); 38 wp_cache_set( 'popular_groups', $groups, 'bp' ); 39 } 40 ?> 41 42 <?php if ( $groups['groups'] ) : ?> 43 <div class="item-options" id="groups-list-options"> 44 <img id="ajax-loader-groups" src="<?php echo $bp->groups->image_base ?>/ajax-loader.gif" height="7" alt="<?php _e( 'Loading', 'buddypress' ) ?>" style="display: none;" /> 45 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="newest-groups"><?php _e("Newest", 'buddypress') ?></a> | 46 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="recently-active-groups"><?php _e("Active", 'buddypress') ?></a> | 47 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="popular-groups" class="selected"><?php _e("Popular", 'buddypress') ?></a> 48 </div> 49 <ul id="groups-list" class="item-list"> 50 <?php foreach ( $groups['groups'] as $group_id ) : ?> 51 <?php 52 if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_id->group_id, 'bp' ) ) { 53 $group = new BP_Groups_Group( $group_id->group_id, false, false ); 54 wp_cache_set( 'groups_group_nouserdata_' . $group_id->group_id, $group, 'bp' ); 55 } 56 ?> 57 <li> 58 <div class="item-avatar"> 59 <a href="<?php echo bp_get_group_permalink( $group ) ?>" title="<?php echo bp_get_group_name( $group ) ?>"><?php echo bp_get_group_avatar_thumb( $group ); ?></a> 60 </div> 61 62 <div class="item"> 63 <div class="item-title"><a href="<?php echo bp_get_group_permalink( $group ) ?>" title="<?php echo bp_get_group_name( $group ) ?>"><?php echo bp_get_group_name( $group ) ?></a></div> 64 <div class="item-meta"> 65 <span class="activity"> 66 <?php 67 if ( 1 == $group->total_member_count ) 68 echo $group->total_member_count . __(' member', 'buddypress'); 69 else 70 echo $group->total_member_count . __(' members', 'buddypress'); 71 ?> 72 </span></div> 73 </div> 74 </li> 75 <?php $counter++; ?> 76 <?php endforeach; ?> 77 </ul> 78 79 <?php 80 if ( function_exists('wp_nonce_field') ) 81 wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); 82 ?> 83 84 <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo attribute_escape( $options['max_groups'] ); ?>" /> 85 86 <?php else: ?> 87 <div class="widget-error"> 88 <?php _e('There are no groups to display.', 'buddypress') ?> 89 </div> 90 <?php endif; ?> 91 92 <?php echo $after_widget; ?> 93 <?php 94 } 95 96 function groups_widget_groups_list_control() { 97 global $current_blog; 98 99 $options = $newoptions = get_blog_option( $current_blog->blog_id, 'groups_widget_groups_list'); 100 101 if ( $_POST['groups-widget-groups-list-submit'] ) { 102 $newoptions['max_groups'] = strip_tags( stripslashes( $_POST['groups-widget-groups-list-max'] ) ); 103 } 104 105 if ( $options != $newoptions ) { 106 $options = $newoptions; 107 update_blog_option( $current_blog->blog_id, 'groups_widget_groups_list', $options ); 11 class BP_Groups_Widget extends WP_Widget { 12 function bp_groups_widget() { 13 parent::WP_Widget( false, $name = 'Groups' ); 14 wp_enqueue_script( 'groups_widget_groups_list-js', BP_PLUGIN_URL . '/bp-groups/js/widget-groups.js', array('jquery', 'jquery-livequery-pack') ); 15 wp_enqueue_style( 'groups_widget_members-css', BP_PLUGIN_URL . '/bp-groups/css/widget-groups.css' ); 108 16 } 109 17 18 function widget($args, $instance) { 19 global $bp; 20 21 extract( $args ); 22 23 echo $before_widget; 24 echo $before_title 25 . $widget_name 26 . $after_title; ?> 27 28 <?php 29 if ( empty( $instance['max_groups'] ) || !$instance['max_groups'] ) 30 $instance['max_groups'] = 5; ?> 31 32 <?php if ( bp_has_site_groups( 'type=popular&max=' . $instance['max_groups'] ) ) : ?> 33 <div class="item-options" id="groups-list-options"> 34 <img id="ajax-loader-groups" src="<?php echo $bp->groups->image_base ?>/ajax-loader.gif" height="7" alt="<?php _e( 'Loading', 'buddypress' ) ?>" style="display: none;" /> 35 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="newest-groups"><?php _e("Newest", 'buddypress') ?></a> | 36 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="recently-active-groups"><?php _e("Active", 'buddypress') ?></a> | 37 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="popular-groups" class="selected"><?php _e("Popular", 'buddypress') ?></a> 38 </div> 39 40 <ul id="groups-list" class="item-list"> 41 <?php while ( bp_site_groups() ) : bp_the_site_group(); ?> 42 <li> 43 <div class="item-avatar"> 44 <a href="<?php bp_the_site_group_link() ?>"><?php bp_the_site_group_avatar_thumb() ?></a> 45 </div> 46 47 <div class="item"> 48 <div class="item-title"><a href="<?php bp_the_site_group_link() ?>" title="<?php bp_the_site_group_name() ?>"><?php bp_the_site_group_name() ?></a></div> 49 <div class="item-meta"><span class="activity"><?php bp_the_site_group_member_count() ?></span></div> 50 </div> 51 </li> 52 53 <?php endwhile; ?> 54 </ul> 55 <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?> 56 <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo attribute_escape( $instance['max_groups'] ); ?>" /> 57 58 <?php else: ?> 59 60 <div class="widget-error"> 61 <?php _e('There are no groups to display.', 'buddypress') ?> 62 </div> 63 64 <?php endif; ?> 65 66 <?php echo $after_widget; ?> 67 <?php 68 } 69 70 function update( $new_instance, $old_instance ) { 71 $instance = $old_instance; 72 $instance['max_groups'] = strip_tags( $new_instance['max_groups'] ); 73 74 return $instance; 75 } 76 77 function form( $instance ) { 78 $instance = wp_parse_args( (array) $instance, array( 'max_groups' => 5 ) ); 79 $max_groups = strip_tags( $instance['max_groups'] ); 80 ?> 81 82 <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> 83 <?php 84 } 85 } 110 86 ?> 111 <p><label for="groups-widget-groups-list-max"><?php _e('Maximum number of groups to show:', 'buddypress'); ?><br /> <input class="widefat" id="groups-widget-groups-list-max" name="groups-widget-groups-list-max" type="text" value="<?php echo attribute_escape( $options['max_groups'] ); ?>" style="width: 30%" /></label></p>112 <input type="hidden" id="groups-widget-groups-list-submit" name="groups-widget-groups-list-submit" value="1" />113 <?php114 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)