Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 04:55:58 AM (9 years ago)
Author:
boonebgorges
Message:

Move bp-groups classes to their own files.

See #6870.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-widgets.php

    r10454 r10520  
    1111defined( 'ABSPATH' ) || exit;
    1212
     13require dirname( __FILE__ ) . '/classes/class-bp-groups-widget.php';
     14
    1315/**
    1416 * Register widgets for groups component.
     
    2022}
    2123add_action( 'bp_register_widgets', 'groups_register_widgets' );
    22 
    23 /**
    24  * Groups widget.
    25  *
    26  * @since 1.0.3
    27  */
    28 class BP_Groups_Widget extends WP_Widget {
    29 
    30     /**
    31      * Working as a group, we get things done better.
    32      *
    33      * @since 1.0.3
    34      */
    35     public function __construct() {
    36         $widget_ops = array(
    37             'description' => __( 'A dynamic list of recently active, popular, and newest groups', 'buddypress' ),
    38             'classname' => 'widget_bp_groups_widget buddypress widget',
    39         );
    40         parent::__construct( false, _x( '(BuddyPress) Groups', 'widget name', 'buddypress' ), $widget_ops );
    41 
    42         if ( is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
    43             $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    44             wp_enqueue_script( 'groups_widget_groups_list-js', buddypress()->plugin_url . "bp-groups/js/widget-groups{$min}.js", array( 'jquery' ), bp_get_version() );
    45         }
    46     }
    47 
    48     /**
    49      * Extends our frontend output method.
    50      *
    51      * @since 1.0.3
    52      *
    53      * @param array $args     Array of arguments for the widget.
    54      * @param array $instance Widget instance data.
    55      */
    56     public function widget( $args, $instance ) {
    57 
    58         /**
    59          * Filters the user ID to use with the widget instance.
    60          *
    61          * @since 1.5.0
    62          *
    63          * @param string $value Empty user ID.
    64          */
    65         $user_id = apply_filters( 'bp_group_widget_user_id', '0' );
    66 
    67         extract( $args );
    68 
    69         if ( empty( $instance['group_default'] ) ) {
    70             $instance['group_default'] = 'popular';
    71         }
    72 
    73         if ( empty( $instance['title'] ) ) {
    74             $instance['title'] = __( 'Groups', 'buddypress' );
    75         }
    76 
    77         /**
    78          * Filters the title of the Groups widget.
    79          *
    80          * @since 1.8.0
    81          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    82          *
    83          * @param string $title    The widget title.
    84          * @param array  $instance The settings for the particular instance of the widget.
    85          * @param string $id_base  Root ID for all widgets of this type.
    86          */
    87         $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
    88 
    89         /**
    90          * Filters the separator of the group widget links.
    91          *
    92          * @since 2.4.0
    93          *
    94          * @param string $separator Separator string. Default '|'.
    95          */
    96         $separator = apply_filters( 'bp_groups_widget_separator', '|' );
    97 
    98         echo $before_widget;
    99 
    100         $title = ! empty( $instance['link_title'] ) ? '<a href="' . bp_get_groups_directory_permalink() . '">' . $title . '</a>' : $title;
    101 
    102         echo $before_title . $title . $after_title;
    103 
    104         $max_groups = ! empty( $instance['max_groups'] ) ? (int) $instance['max_groups'] : 5;
    105 
    106         $group_args = array(
    107             'user_id'         => $user_id,
    108             'type'            => $instance['group_default'],
    109             'per_page'        => $max_groups,
    110             'max'             => $max_groups,
    111         );
    112 
    113         ?>
    114 
    115         <?php if ( bp_has_groups( $group_args ) ) : ?>
    116             <div class="item-options" id="groups-list-options">
    117                 <a href="<?php bp_groups_directory_permalink(); ?>" id="newest-groups"<?php if ( $instance['group_default'] == 'newest' ) : ?> class="selected"<?php endif; ?>><?php _e("Newest", 'buddypress') ?></a>
    118                 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span>
    119                 <a href="<?php bp_groups_directory_permalink(); ?>" id="recently-active-groups"<?php if ( $instance['group_default'] == 'active' ) : ?> class="selected"<?php endif; ?>><?php _e("Active", 'buddypress') ?></a>
    120                 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span>
    121                 <a href="<?php bp_groups_directory_permalink(); ?>" id="popular-groups" <?php if ( $instance['group_default'] == 'popular' ) : ?> class="selected"<?php endif; ?>><?php _e("Popular", 'buddypress') ?></a>
    122             </div>
    123 
    124             <ul id="groups-list" class="item-list">
    125                 <?php while ( bp_groups() ) : bp_the_group(); ?>
    126                     <li <?php bp_group_class(); ?>>
    127                         <div class="item-avatar">
    128                             <a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_avatar_thumb() ?></a>
    129                         </div>
    130 
    131                         <div class="item">
    132                             <div class="item-title"><a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a></div>
    133                             <div class="item-meta">
    134                                 <span class="activity">
    135                                 <?php
    136                                     if ( 'newest' == $instance['group_default'] ) {
    137                                         printf( __( 'created %s', 'buddypress' ), bp_get_group_date_created() );
    138                                     } elseif ( 'active' == $instance['group_default'] ) {
    139                                         printf( __( 'active %s', 'buddypress' ), bp_get_group_last_active() );
    140                                     } elseif ( 'popular' == $instance['group_default'] ) {
    141                                         bp_group_member_count();
    142                                     }
    143                                 ?>
    144                                 </span>
    145                             </div>
    146                         </div>
    147                     </li>
    148 
    149                 <?php endwhile; ?>
    150             </ul>
    151             <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?>
    152             <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo esc_attr( $max_groups ); ?>" />
    153 
    154         <?php else: ?>
    155 
    156             <div class="widget-error">
    157                 <?php _e('There are no groups to display.', 'buddypress') ?>
    158             </div>
    159 
    160         <?php endif; ?>
    161 
    162         <?php echo $after_widget; ?>
    163     <?php
    164     }
    165 
    166     /**
    167      * Extends our update method.
    168      *
    169      * @since 1.0.3
    170      *
    171      * @param array $new_instance New instance data.
    172      * @param array $old_instance Original instance data.
    173      * @return array
    174      */
    175     public function update( $new_instance, $old_instance ) {
    176         $instance = $old_instance;
    177 
    178         $instance['title']         = strip_tags( $new_instance['title'] );
    179         $instance['max_groups']    = strip_tags( $new_instance['max_groups'] );
    180         $instance['group_default'] = strip_tags( $new_instance['group_default'] );
    181         $instance['link_title']    = (bool) $new_instance['link_title'];
    182 
    183         return $instance;
    184     }
    185 
    186     /**
    187      * Extends our form method.
    188      *
    189      * @since 1.0.3
    190      *
    191      * @param array $instance Current instance.
    192      * @return mixed
    193      */
    194     public function form( $instance ) {
    195         $defaults = array(
    196             'title'         => __( 'Groups', 'buddypress' ),
    197             'max_groups'    => 5,
    198             'group_default' => 'active',
    199             'link_title'    => false
    200         );
    201         $instance = wp_parse_args( (array) $instance, $defaults );
    202 
    203         $title         = strip_tags( $instance['title'] );
    204         $max_groups    = strip_tags( $instance['max_groups'] );
    205         $group_default = strip_tags( $instance['group_default'] );
    206         $link_title    = (bool) $instance['link_title'];
    207         ?>
    208 
    209         <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" /></label></p>
    210 
    211         <p><label for="<?php echo $this->get_field_id('link_title') ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title') ?>" id="<?php echo $this->get_field_id('link_title') ?>" value="1" <?php checked( $link_title ) ?> /> <?php _e( 'Link widget title to Groups directory', 'buddypress' ) ?></label></p>
    212 
    213         <p><label for="<?php echo $this->get_field_id( 'max_groups' ); ?>"><?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 esc_attr( $max_groups ); ?>" style="width: 30%" /></label></p>
    214 
    215         <p>
    216             <label for="<?php echo $this->get_field_id( 'group_default' ); ?>"><?php _e('Default groups to show:', 'buddypress'); ?></label>
    217             <select name="<?php echo $this->get_field_name( 'group_default' ); ?>" id="<?php echo $this->get_field_id( 'group_default' ); ?>">
    218                 <option value="newest" <?php selected( $group_default, 'newest' ); ?>><?php _e( 'Newest', 'buddypress' ) ?></option>
    219                 <option value="active" <?php selected( $group_default, 'active' ); ?>><?php _e( 'Active', 'buddypress' ) ?></option>
    220                 <option value="popular"  <?php selected( $group_default, 'popular' ); ?>><?php _e( 'Popular', 'buddypress' ) ?></option>
    221             </select>
    222         </p>
    223     <?php
    224     }
    225 }
    22624
    22725/**
Note: See TracChangeset for help on using the changeset viewer.