Skip to:
Content

BuddyPress.org

Ticket #6721: 6721.patch

File 6721.patch, 6.2 KB (added by sbrajesh, 9 years ago)

Remove php4 constructor and cleanup the code a little bit

  • src/bp-groups/bp-groups-widgets.php

     
    2626        /**
    2727         * Working as a group, we get things done better.
    2828         */
    29         function __construct() {
     29        public function __construct() {
    3030                $widget_ops = array(
    3131                        'description' => __( 'A dynamic list of recently active, popular, and newest groups', 'buddypress' ),
    3232                        'classname' => 'widget_bp_groups_widget buddypress widget',
     
    3333                );
    3434                parent::__construct( false, _x( '(BuddyPress) Groups', 'widget name', 'buddypress' ), $widget_ops );
    3535
    36                 if ( is_active_widget( false, false, $this->id_base ) && !is_admin() && !is_network_admin() ) {
     36                if ( is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
    3737                        $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    3838                        wp_enqueue_script( 'groups_widget_groups_list-js', buddypress()->plugin_url . "bp-groups/js/widget-groups{$min}.js", array( 'jquery' ), bp_get_version() );
    3939                }
     
    4040        }
    4141
    4242        /**
    43          * PHP4 constructor
    44          *
    45          * For backward compatibility only
    46          */
    47         function bp_groups_widget() {
    48                 $this->_construct();
    49         }
    50 
    51         /**
    5243         * Extends our frontend output method.
    5344         *
    5445         * @param array $args     Array of arguments for the widget.
    5546         * @param array $instance Widget instance data.
    5647         */
    57         function widget( $args, $instance ) {
     48        public function widget( $args, $instance ) {
    5849
    5950                /**
    6051                 * Filters the user ID to use with the widget instance.
     
    6758
    6859                extract( $args );
    6960
    70                 if ( empty( $instance['group_default'] ) )
     61                if ( empty( $instance['group_default'] ) ) {
    7162                        $instance['group_default'] = 'popular';
     63                }
    7264
    73                 if ( empty( $instance['title'] ) )
     65                if ( empty( $instance['title'] ) ) {
    7466                        $instance['title'] = __( 'Groups', 'buddypress' );
    75 
     67                }
     68               
    7669                /**
    7770                 * Filters the title of the Groups widget.
    7871                 *
     
    9689
    9790                echo $before_widget;
    9891
    99                 $title = !empty( $instance['link_title'] ) ? '<a href="' . bp_get_groups_directory_permalink() . '">' . $title . '</a>' : $title;
     92                $title = ! empty( $instance['link_title'] ) ? '<a href="' . bp_get_groups_directory_permalink() . '">' . $title . '</a>' : $title;
    10093
    10194                echo $before_title . $title . $after_title;
    10295
     
    132125                                                        <div class="item-meta">
    133126                                                                <span class="activity">
    134127                                                                <?php
    135                                                                         if ( 'newest' == $instance['group_default'] )
     128                                                                        if ( 'newest' == $instance['group_default'] ) {
    136129                                                                                printf( __( 'created %s', 'buddypress' ), bp_get_group_date_created() );
    137                                                                         if ( 'active' == $instance['group_default'] )
    138                                                                                 printf( __( 'active %s', 'buddypress' ), bp_get_group_last_active() );
    139                                                                         elseif ( 'popular' == $instance['group_default'] )
     130                                                                        } elseif ( 'active' == $instance['group_default'] ) {
     131                                                                                printf( __( 'active %s', 'buddypress' ), bp_get_group_last_active() ); 
     132                                                                        } elseif ( 'popular' == $instance['group_default'] ) {
    140133                                                                                bp_group_member_count();
     134                                                                        }
    141135                                                                ?>
    142136                                                                </span>
    143137                                                        </div>
     
    168162         * @param array $old_instance Original instance data.
    169163         * @return array
    170164         */
    171         function update( $new_instance, $old_instance ) {
     165        public function update( $new_instance, $old_instance ) {
    172166                $instance = $old_instance;
    173167
    174168                $instance['title']         = strip_tags( $new_instance['title'] );
    175169                $instance['max_groups']    = strip_tags( $new_instance['max_groups'] );
    176170                $instance['group_default'] = strip_tags( $new_instance['group_default'] );
    177                 $instance['link_title']    = (bool)$new_instance['link_title'];
     171                $instance['link_title']    = (bool) $new_instance['link_title'];
    178172
    179173                return $instance;
    180174        }
     
    185179         * @param array $instance Current instance.
    186180         * @return mixed
    187181         */
    188         function form( $instance ) {
     182        public function form( $instance ) {
    189183                $defaults = array(
    190184                        'title'         => __( 'Groups', 'buddypress' ),
    191185                        'max_groups'    => 5,
     
    197191                $title         = strip_tags( $instance['title'] );
    198192                $max_groups    = strip_tags( $instance['max_groups'] );
    199193                $group_default = strip_tags( $instance['group_default'] );
    200                 $link_title    = (bool)$instance['link_title'];
     194                $link_title    = (bool) $instance['link_title'];
    201195                ?>
    202196
    203197                <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>
     
    209203                <p>
    210204                        <label for="<?php echo $this->get_field_id( 'group_default' ); ?>"><?php _e('Default groups to show:', 'buddypress'); ?></label>
    211205                        <select name="<?php echo $this->get_field_name( 'group_default' ); ?>" id="<?php echo $this->get_field_id( 'group_default' ); ?>">
    212                                 <option value="newest" <?php if ( $group_default == 'newest' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></option>
    213                                 <option value="active" <?php if ( $group_default == 'active' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></option>
    214                                 <option value="popular"  <?php if ( $group_default == 'popular' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></option>
     206                                <option value="newest" <?php selected( $group_default, 'newest' );?>><?php _e( 'Newest', 'buddypress' ) ?></option>
     207                                <option value="active" <?php selected( $group_default, 'active' );?>><?php _e( 'Active', 'buddypress' ) ?></option>
     208                                <option value="popular"  <?php selected( $group_default, 'popular' );?>><?php _e( 'Popular', 'buddypress' ) ?></option>
    215209                        </select>
    216210                </p>
    217211        <?php
     
    220214
    221215function groups_ajax_widget_groups_list() {
    222216
    223         check_ajax_referer('groups_widget_groups_list');
     217        check_ajax_referer( 'groups_widget_groups_list' );
    224218
    225219        switch ( $_POST['filter'] ) {
    226220                case 'newest-groups':
     
    275269
    276270        <?php else: ?>
    277271
    278                 <?php echo "-1[[SPLIT]]<li>" . __("No groups matched the current filter.", 'buddypress'); ?>
     272                <?php echo "-1[[SPLIT]]<li>" . __( "No groups matched the current filter.", 'buddypress' ); ?>
    279273
    280274        <?php endif;
    281275