/bp-friends/bp-friends-widgets.php

  1. <?php 
  2. /** 
  3. * BuddyPress Friends Widgets. 
  4. * 
  5. * @package BuddyPress 
  6. * @subpackage Friends 
  7. * @since 1.9.0 
  8. */ 
  9.  
  10. // Exit if accessed directly. 
  11. defined( 'ABSPATH' ) || exit; 
  12.  
  13. /** 
  14. * Register the friends widget. 
  15. * 
  16. * @since 1.9.0 
  17. */ 
  18. function bp_friends_register_widgets() { 
  19. if ( ! bp_is_active( 'friends' ) ) { 
  20. return; 
  21.  
  22. // The Friends widget works only when looking an a displayed user,  
  23. // and the concept of "displayed user" doesn't exist on non-root blogs,  
  24. // so we don't register the widget there. 
  25. if ( ! bp_is_root_blog() ) { 
  26. return; 
  27.  
  28. add_action( 'widgets_init', function() { register_widget( 'BP_Core_Friends_Widget' ); } ); 
  29. add_action( 'bp_register_widgets', 'bp_friends_register_widgets' ); 
  30.  
  31. /** Widget AJAX ***************************************************************/ 
  32.  
  33. /** 
  34. * Process AJAX pagination or filtering for the Friends widget. 
  35. * 
  36. * @since 1.9.0 
  37. */ 
  38. function bp_core_ajax_widget_friends() { 
  39.  
  40. check_ajax_referer( 'bp_core_widget_friends' ); 
  41.  
  42. switch ( $_POST['filter'] ) { 
  43. case 'newest-friends': 
  44. $type = 'newest'; 
  45. break; 
  46.  
  47. case 'recently-active-friends': 
  48. $type = 'active'; 
  49. break; 
  50.  
  51. case 'popular-friends': 
  52. $type = 'popular'; 
  53. break; 
  54.  
  55. $members_args = array( 
  56. 'user_id' => bp_displayed_user_id(),  
  57. 'type' => $type,  
  58. 'max' => absint( $_POST['max-friends'] ),  
  59. 'populate_extras' => 1,  
  60. ); 
  61.  
  62. if ( bp_has_members( $members_args ) ) : ?> 
  63. <?php echo '0[[SPLIT]]'; // Return valid result. TODO: remove this. ?> 
  64. <?php while ( bp_members() ) : bp_the_member(); ?> 
  65. <li class="vcard"> 
  66. <div class="item-avatar"> 
  67. <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a> 
  68. </div> 
  69.  
  70. <div class="item"> 
  71. <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div> 
  72. <?php if ( 'active' == $type ) : ?> 
  73. <div class="item-meta"><span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_last_active( array( 'relative' => false ) ) ); ?>"><?php bp_member_last_active(); ?></span></div> 
  74. <?php elseif ( 'newest' == $type ) : ?> 
  75. <div class="item-meta"><span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_registered( array( 'relative' => false ) ) ); ?>"><?php bp_member_registered(); ?></span></div> 
  76. <?php elseif ( bp_is_active( 'friends' ) ) : ?> 
  77. <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count(); ?></span></div> 
  78. <?php endif; ?> 
  79. </div> 
  80. </li> 
  81. <?php endwhile; ?> 
  82.  
  83. <?php else: ?> 
  84. <?php echo "-1[[SPLIT]]<li>"; ?> 
  85. <?php _e( 'There were no members found, please try another filter.', 'buddypress' ); ?> 
  86. <?php echo "</li>"; ?> 
  87. <?php endif; 
  88. add_action( 'wp_ajax_widget_friends', 'bp_core_ajax_widget_friends' ); 
  89. add_action( 'wp_ajax_nopriv_widget_friends', 'bp_core_ajax_widget_friends' ); 
.