Skip to:
Content

BuddyPress.org


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

Move bp-friends classes to their own files.

See #6870.

File:
1 edited

Legend:

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

    r10323 r10519  
    11<?php
    22/**
    3  * BuddyPress Widgets.
     3 * BuddyPress Friends Widgets.
    44 *
    55 * @package BuddyPress
     
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
     12
     13require dirname( __FILE__ ) . '/classes/class-bp-friends-widget.php';
    1214
    1315/**
     
    3133}
    3234add_action( 'bp_register_widgets', 'bp_friends_register_widgets' );
    33 
    34 /*** MEMBER FRIENDS WIDGET *****************/
    35 
    36 /**
    37  * The User Friends widget class.
    38  *
    39  * @since 1.9.0
    40  */
    41 class BP_Core_Friends_Widget extends WP_Widget {
    42 
    43     /**
    44      * Class constructor.
    45      */
    46     function __construct() {
    47         $widget_ops = array(
    48             'description' => __( 'A dynamic list of recently active, popular, and newest Friends of the displayed member.  Widget is only shown when viewing a member profile.', 'buddypress' ),
    49             'classname' => 'widget_bp_core_friends_widget buddypress widget',
    50         );
    51         parent::__construct( false, $name = _x( '(BuddyPress) Friends', 'widget name', 'buddypress' ), $widget_ops );
    52 
    53     }
    54 
    55     /**
    56      * Display the widget.
    57      *
    58      * @param array $args Widget arguments.
    59      * @param array $instance The widget settings, as saved by the user.
    60      */
    61     function widget( $args, $instance ) {
    62         extract( $args );
    63 
    64         if ( ! bp_displayed_user_id() ) {
    65             return;
    66         }
    67 
    68         $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    69         wp_enqueue_script( 'bp_core_widget_friends-js', buddypress()->plugin_url . "bp-friends/js/widget-friends{$min}.js", array( 'jquery' ), bp_get_version() );
    70 
    71         $user_id = bp_displayed_user_id();
    72         $link = trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() );
    73         $instance['title'] = sprintf( __( "%s's Friends", 'buddypress' ), bp_get_displayed_user_fullname() );
    74 
    75         if ( empty( $instance['friend_default'] ) ) {
    76             $instance['friend_default'] = 'active';
    77         }
    78 
    79         /**
    80          * Filters the Friends widget title.
    81          *
    82          * @since 1.8.0
    83          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    84          *
    85          * @param string $title    The widget title.
    86          * @param array  $instance The settings for the particular instance of the widget.
    87          * @param string $id_base  Root ID for all widgets of this type.
    88          */
    89         $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
    90 
    91         echo $before_widget;
    92 
    93         $title = $instance['link_title'] ? '<a href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>' : esc_html( $title );
    94 
    95         echo $before_title . $title . $after_title;
    96 
    97         $members_args = array(
    98             'user_id'         => absint( $user_id ),
    99             'type'            => sanitize_text_field( $instance['friend_default'] ),
    100             'max'             => absint( $instance['max_friends'] ),
    101             'populate_extras' => 1,
    102         );
    103 
    104         ?>
    105 
    106         <?php if ( bp_has_members( $members_args ) ) : ?>
    107             <div class="item-options" id="friends-list-options">
    108                 <a href="<?php bp_members_directory_permalink(); ?>" id="newest-friends" <?php if ( $instance['friend_default'] == 'newest' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ); ?></a>
    109                 | <a href="<?php bp_members_directory_permalink(); ?>" id="recently-active-friends" <?php if ( $instance['friend_default'] == 'active' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ); ?></a>
    110                 | <a href="<?php bp_members_directory_permalink(); ?>" id="popular-friends" <?php if ( $instance['friend_default'] == 'popular' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ); ?></a>
    111             </div>
    112 
    113             <ul id="friends-list" class="item-list">
    114                 <?php while ( bp_members() ) : bp_the_member(); ?>
    115                     <li class="vcard">
    116                         <div class="item-avatar">
    117                             <a href="<?php bp_member_permalink(); ?>" title="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a>
    118                         </div>
    119 
    120                         <div class="item">
    121                             <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>" title="<?php bp_member_name(); ?>"><?php bp_member_name(); ?></a></div>
    122                             <div class="item-meta">
    123                                 <span class="activity">
    124                                 <?php
    125                                     if ( 'newest' == $instance['friend_default'] )
    126                                         bp_member_registered();
    127                                     if ( 'active' == $instance['friend_default'] )
    128                                         bp_member_last_active();
    129                                     if ( 'popular' == $instance['friend_default'] )
    130                                         bp_member_total_friend_count();
    131                                 ?>
    132                                 </span>
    133                             </div>
    134                         </div>
    135                     </li>
    136 
    137                 <?php endwhile; ?>
    138             </ul>
    139             <?php wp_nonce_field( 'bp_core_widget_friends', '_wpnonce-friends' ); ?>
    140             <input type="hidden" name="friends_widget_max" id="friends_widget_max" value="<?php echo absint( $instance['max_friends'] ); ?>" />
    141 
    142         <?php else: ?>
    143 
    144             <div class="widget-error">
    145                 <?php _e( 'Sorry, no members were found.', 'buddypress' ); ?>
    146             </div>
    147 
    148         <?php endif; ?>
    149 
    150         <?php echo $after_widget; ?>
    151     <?php
    152     }
    153 
    154     /**
    155      * Process a widget save.
    156      *
    157      * @param array $new_instance The parameters saved by the user.
    158      * @param array $old_instance The parameters as previously saved to the database.
    159      * @return array $instance The processed settings to save.
    160      */
    161     function update( $new_instance, $old_instance ) {
    162         $instance = $old_instance;
    163 
    164         $instance['max_friends']    = absint( $new_instance['max_friends'] );
    165         $instance['friend_default'] = sanitize_text_field( $new_instance['friend_default'] );
    166         $instance['link_title']     = (bool) $new_instance['link_title'];
    167 
    168         return $instance;
    169     }
    170 
    171     /**
    172      * Render the widget edit form.
    173      *
    174      * @param array $instance The saved widget settings.
    175      * @return void
    176      */
    177     function form( $instance ) {
    178         $defaults = array(
    179             'max_friends'    => 5,
    180             'friend_default' => 'active',
    181             'link_title'     => false
    182         );
    183         $instance = wp_parse_args( (array) $instance, $defaults );
    184 
    185         $max_friends    = $instance['max_friends'];
    186         $friend_default = $instance['friend_default'];
    187         $link_title = (bool) $instance['link_title'];
    188         ?>
    189 
    190         <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 Members directory', 'buddypress' ); ?></label></p>
    191 
    192         <p><label for="<?php echo $this->get_field_id( 'max_friends' ); ?>"><?php _e( 'Max friends to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_friends' ); ?>" name="<?php echo $this->get_field_name( 'max_friends' ); ?>" type="text" value="<?php echo absint( $max_friends ); ?>" style="width: 30%" /></label></p>
    193 
    194         <p>
    195             <label for="<?php echo $this->get_field_id( 'friend_default' ) ?>"><?php _e( 'Default friends to show:', 'buddypress' ); ?></label>
    196             <select name="<?php echo $this->get_field_name( 'friend_default' ); ?>" id="<?php echo $this->get_field_id( 'friend_default' ); ?>">
    197                 <option value="newest" <?php selected( $friend_default, 'newest' ); ?>><?php _e( 'Newest', 'buddypress' ); ?></option>
    198                 <option value="active" <?php selected( $friend_default, 'active' );?>><?php _e( 'Active', 'buddypress' ); ?></option>
    199                 <option value="popular"  <?php selected( $friend_default, 'popular' ); ?>><?php _e( 'Popular', 'buddypress' ); ?></option>
    200             </select>
    201         </p>
    202 
    203     <?php
    204     }
    205 }
    20635
    20736/** Widget AJAX ***************************************************************/
Note: See TracChangeset for help on using the changeset viewer.