| 1 |
<?php |
| 2 |
/** |
| 3 |
* Friend List Widget |
| 4 |
* |
| 5 |
* A widget that displays a list of your friends. |
| 6 |
* |
| 7 |
* @package Friends |
| 8 |
* @since 0.3 |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace Friends; |
| 12 |
|
| 13 |
/** |
| 14 |
* This is the class for the Friend List Widget. |
| 15 |
* |
| 16 |
* @package Friends |
| 17 |
* @author Alex Kirk |
| 18 |
*/ |
| 19 |
class Widget_Friends_List extends Widget_Base_Friends_List { |
| 20 |
/** |
| 21 |
* Constructor |
| 22 |
*/ |
| 23 |
public function __construct() { |
| 24 |
parent::__construct( |
| 25 |
'friends-widget-friend-list', |
| 26 |
__( 'Friend List', 'friends' ), |
| 27 |
array( |
| 28 |
'description' => __( 'Shows a list of your friends.', 'friends' ), |
| 29 |
) |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Render the widget. |
| 35 |
* |
| 36 |
* @param array $args Sidebar arguments. |
| 37 |
* @param array $instance Widget instance settings. |
| 38 |
*/ |
| 39 |
public function widget( $args, $instance ) { |
| 40 |
$instance = wp_parse_args( $instance, $this->defaults() ); |
| 41 |
|
| 42 |
echo $args['before_widget']; |
| 43 |
|
| 44 |
$all_friends = User_Query::all_friends(); |
| 45 |
$friend_requests = User_Query::all_friend_requests(); |
| 46 |
$subscriptions = User_Query::all_subscriptions(); |
| 47 |
|
| 48 |
// translators: %s is the number of your friends. |
| 49 |
$friends_title = sprintf( _n( '%s Friend', '%s Friends', $all_friends->get_total(), 'friends' ), '<span class="friend-count">' . $all_friends->get_total() . '</span>' ); |
| 50 |
|
| 51 |
if ( $all_friends->get_total() > 0 || ( ! $friend_requests->get_total() && ! $subscriptions->get_total() ) ) { |
| 52 |
$this->list_friends( |
| 53 |
$args, |
| 54 |
$friends_title, |
| 55 |
$all_friends |
| 56 |
); |
| 57 |
|
| 58 |
if ( ! $all_friends->get_total() ) { |
| 59 |
?> |
| 60 |
<ul class="menu menu-nav accordion-body"> |
| 61 |
<li class="menu-item"><a href="<?php echo esc_url( self_admin_url( 'admin.php?page=add-friend' ) ); ?>" class="normal"><?php esc_html_e( 'Add your first friend or subscription now!', 'friends' ); ?></a></li> |
| 62 |
</ul> |
| 63 |
<?php |
| 64 |
} |
| 65 |
} |
| 66 |
if ( $friend_requests->get_total() > 0 ) { |
| 67 |
$this->list_friends( |
| 68 |
$args, |
| 69 |
// translators: %1$s is the string "%s Friend", %2$s is a URL, %3$s is the number of open friend requests. |
| 70 |
sprintf( _n( '%1$s <a href=%2$s>(%3$s request)</a>', '%1$s <a href=%2$s>(%3$s requests)</a>', $friend_requests->get_total(), 'friends' ), $friends_title, '"' . esc_attr( self_admin_url( 'users.php?role=friend_request' ) ) . '" class="open-requests"', '<span class="friend-count">' . $friend_requests->get_total() . '</span>' ), |
| 71 |
$friend_requests |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
if ( 0 !== $subscriptions->get_total() ) { |
| 76 |
$this->list_friends( |
| 77 |
$args, |
| 78 |
sprintf( |
| 79 |
// translators: %s is the number of subscriptions. |
| 80 |
_n( '%s Subscription', '%s Subscriptions', $subscriptions->get_total(), 'friends' ), |
| 81 |
'<span class="subscription-count">' . $subscriptions->get_total() . '</span>' |
| 82 |
), |
| 83 |
$subscriptions |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
do_action( 'friends_widget_friend_list_after', $this, $args ); |
| 88 |
|
| 89 |
echo $args['after_widget']; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|