BB_User_Search

The BuddyPress BB User Search class.

Defined (1)

The class is defined in the following location(s).

/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php  
  1. class BB_User_Search { 
  2. var $results; 
  3. var $search_term; 
  4. var $page; 
  5. var $raw_page; 
  6. var $users_per_page = 50; 
  7. var $first_user; 
  8. var $last_user; 
  9. var $query_limit; 
  10. var $total_users_for_query = 0; 
  11. var $search_errors; 
  12. var $paging_text; 
  13. var $paging_text_bottom; 
  14.  
  15. function __construct($search_term = false, $page = 1, $roles = false ) { // constructor 
  16. $this->search_term = $search_term ? stripslashes($search_term) : false; 
  17. $this->raw_page = ( '' == $page ) ? false : (int) $page; 
  18. $page = (int) $page; 
  19. $this->page = $page < 2 ? 1 : $page; 
  20. $roles = (array) $roles; 
  21. $_roles = array(); 
  22. foreach ( $roles as $role ) { 
  23. if ( false !== $role ) { 
  24. $_roles[] = stripslashes( $role ); 
  25. $this->roles = empty( $_roles ) ? false : $_roles; 
  26.  
  27. $this->prepare_query(); 
  28. $this->query(); 
  29. $this->prepare_vars_for_template_usage(); 
  30. $this->do_paging(); 
  31.  
  32. function BB_User_Search( $search_term = false, $page = 1, $roles = false ) { 
  33. $this->__construct( $search_term, $page, $roles ); 
  34.  
  35. function prepare_query() { 
  36. $this->first_user = ($this->page - 1) * $this->users_per_page; 
  37.  
  38. function query() { 
  39. $users = bb_user_search( array( 
  40. 'query' => $this->search_term,  
  41. 'user_email' => true,  
  42. 'users_per_page' => $this->users_per_page,  
  43. 'page' => $this->page,  
  44. 'roles' => $this->roles 
  45. ) ); 
  46.  
  47. if ( is_wp_error($users) ) 
  48. $this->search_errors = $users; 
  49. else if ( $users ) 
  50. $this->results = $users; 
  51. // foreach ( (array) $users as $user ) 
  52. // $this->results[] = $user->ID; 
  53.  
  54. if ( $this->results ) 
  55. $this->total_users_for_query = bb_count_last_query(); 
  56. elseif ( !is_wp_error($this->search_errors) ) 
  57. $this->search_errors = new WP_Error( 'no_matching_users_found', __( '<strong>No matching users were found!</strong>' ) ); 
  58.  
  59. if ( is_wp_error( $this->search_errors ) ) 
  60. bb_admin_notice( $this->search_errors ); 
  61.  
  62. function prepare_vars_for_template_usage() { 
  63. $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone 
  64.  
  65. function do_paging() { 
  66. global $bb_current_submenu; 
  67. $displaying_num = sprintf( 
  68. __( '%1$s to %2$s of %3$s' ),  
  69. bb_number_format_i18n( ( $this->page - 1 ) * $this->users_per_page + 1 ),  
  70. $this->page * $this->users_per_page < $this->total_users_for_query ? bb_number_format_i18n( $this->page * $this->users_per_page ) : '<span class="total-type-count">' . bb_number_format_i18n( $this->total_users_for_query ) . '</span>',  
  71. '<span class="total-type-count">' . bb_number_format_i18n( $this->total_users_for_query ) . '</span>' 
  72. ); 
  73. $page_number_links = $this->total_users_for_query > $this->users_per_page ? get_page_number_links( $this->page, $this->total_users_for_query, $this->users_per_page, false ) : ''; 
  74. $this->paging_text = "<div class='tablenav-pages'><span class='displaying-num'>$displaying_num</span><span class=\"displaying-pages\">$page_number_links</span><div class=\"clear\"></div></div>\n"; 
  75. $this->paging_text_bottom = "<div class='tablenav-pages'><span class=\"displaying-pages\">$page_number_links</span><div class=\"clear\"></div></div>\n"; 
  76.  
  77. function get_results() { 
  78. return (array) $this->results; 
  79.  
  80. function page_links() { 
  81. echo $this->paging_text; 
  82.  
  83. function results_are_paged() { 
  84. if ( isset($this->paging_text) && $this->paging_text ) 
  85. return true; 
  86. return false; 
  87.  
  88. function is_search() { 
  89. if ( $this->search_term ) 
  90. return true; 
  91. return false; 
  92.  
  93. function display( $show_search = true, $show_email = false ) { 
  94. global $wp_roles; 
  95.  
  96. $r = ''; 
  97.  
  98. if ( isset($this->title) ) 
  99. $title = $this->title; 
  100. elseif ( $this->is_search() ) 
  101. $title = sprintf(__('Users Matching "%s" by Role'), esc_html( $this->search_term )); 
  102.  
  103. $h2_search = $this->search_term; 
  104. $h2_role = $this->roles[0]; 
  105.  
  106. $roles = $wp_roles->get_names(); 
  107. if ( in_array( $h2_role, array_keys( $roles ) ) ) { 
  108. $h2_role = $roles[$h2_role]; 
  109.  
  110. $h2_search = $h2_search ? ' ' . sprintf( __('containing “%s”'), esc_html( $h2_search ) ) : ''; 
  111. $h2_role = $h2_role ? ' ' . sprintf( __('with role “%s”'), esc_html( $h2_role ) ) : ''; 
  112.  
  113. $h2_span = '<span class="subtitle">'; 
  114. $h2_span .= apply_filters( 'bb_user_search_description', sprintf( __( '%1$s%2$s' ), $h2_search, $h2_role ), $h2_search, $h2_role, $this ); 
  115. $h2_span .= '</span>'; 
  116.  
  117. echo "<h2 class=\"first\">" . apply_filters( 'bb_user_search_title', __('Users') ) . $h2_span . "</h2>\n"; 
  118. do_action( 'bb_admin_notices' ); 
  119.  
  120. if ( $show_search ) { 
  121. $roles = apply_filters( 'bb_user_search_form_roles', $wp_roles->get_names() ); 
  122.  
  123. $r .= "<form action='' method='get' id='search' class='search-form'>\n"; 
  124. $r .= "<fieldset>\n"; 
  125. $r .= "<div>\n"; 
  126. $r .= "\t\t<label for='usersearch'>" . __('Search term') . "</label>"; 
  127. $r .= "\t\t<div><input type='text' name='usersearch' id='usersearch' class='text-input' value='" . esc_html( $this->search_term, 1) . "' /></div>\n"; 
  128. $r .= "</div>\n"; 
  129. $r .= "<div>\n"; 
  130. $r .= "\t\t<label for='userrole'>" . __('Role') . "</label>"; 
  131. $r .= "\t\t<div><select name='userrole[]' id='userrole'>\n"; 
  132. $r .= "\t\t\t<option value=''>" . _x( 'All', 'user roles' ) . "</option>\n"; 
  133.  
  134. foreach ( $roles as $role => $display ) { 
  135. $selected = ''; 
  136. if ( is_array( $this->roles ) && in_array( $role, $this->roles ) ) { 
  137. $selected = ' selected="selected"'; 
  138. $value = esc_attr($role); 
  139. $display = esc_html(translate($display)); 
  140. $r .= "\t\t\t<option value='$value'$selected>$display</option>\n"; 
  141.  
  142. $r .= "\t\t</select></div>\n"; 
  143. $r .= "</div>\n"; 
  144.  
  145. $r = apply_filters( 'bb_user_search_form_inputs', $r, $this ); 
  146.  
  147. $r .= "<div class=\"submit\">\n"; 
  148. $r .= "\t\t<label class='hidden' for='submit'>" . __('Search') . "</label>"; 
  149. $r .= "\t\t<div><input type='submit' id='submit' class='button submit-input' value='" . __('Filter') . "' /></div>\n"; 
  150. $r .= "</div>\n"; 
  151. $r .= "</fieldset>\n"; 
  152. $r .= "</form>\n\n"; 
  153.  
  154. if ( $this->get_results() ) { 
  155. if ( $this->results_are_paged() ) 
  156. $r .= "<div class='tablenav'>\n" . $this->paging_text . "</div><div class=\"clear\"></div>\n\n"; 
  157.  
  158. //foreach($roleclasses as $role => $roleclass) { 
  159. //ksort($roleclass); 
  160. //if ( !empty($role) ) 
  161. // $r .= "\t\t<h3>{$wp_roles->role_names[$role]}</h3>\n"; 
  162. //else 
  163. // $r .= "\t\t<h3><em>" . __('Users with no role in these forums') . "</h3>\n"; 
  164. $r .= "<table class='widefat'>\n"; 
  165. $r .= "<thead>\n"; 
  166. $r .= "\t<tr>\n"; 
  167. if ( $show_email ) { 
  168. $r .= "\t\t<th style='width:30%;'>" . __('Username') . "</th>\n"; 
  169. $r .= "\t\t<th style='width:20%;'>" . __('Name') . "</th>\n"; 
  170. $r .= "\t\t<th style='width:20%;'>" . __('E-mail') . "</th>\n"; 
  171. } else { 
  172. $r .= "\t\t<th style='width:40%;'>" . __('Username') . "</th>\n"; 
  173. $r .= "\t\t<th style='width:30%;'>" . __('Name') . "</th>\n"; 
  174. $r .= "\t\t<th style='width:15%;'>" . __('Registered') . "</th>\n"; 
  175. $r .= "\t\t<th style='width:15%;'>" . __('Role') . "</th>\n"; 
  176. $r .= "\t</tr>\n"; 
  177. $r .= "</thead>\n\n"; 
  178. $r .= "<tfoot>\n"; 
  179. $r .= "\t<tr>\n"; 
  180. if ( $show_email ) { 
  181. $r .= "\t\t<th style='width:30%;'>" . __('Username') . "</th>\n"; 
  182. $r .= "\t\t<th style='width:20%;'>" . __('Name') . "</th>\n"; 
  183. $r .= "\t\t<th style='width:20%;'>" . __('E-mail') . "</th>\n"; 
  184. } else { 
  185. $r .= "\t\t<th style='width:40%;'>" . __('Username') . "</th>\n"; 
  186. $r .= "\t\t<th style='width:30%;'>" . __('Name') . "</th>\n"; 
  187. $r .= "\t\t<th style='width:15%;'>" . __('Registered') . "</th>\n"; 
  188. $r .= "\t\t<th style='width:15%;'>" . __('Role') . "</th>\n"; 
  189. $r .= "\t</tr>\n"; 
  190. $r .= "</tfoot>\n\n"; 
  191.  
  192. $r .= "<tbody id='role-$role'>\n"; 
  193. foreach ( (array) $this->get_results() as $user_object ) 
  194. $r .= bb_user_row($user_object, $role, $show_email); 
  195. $r .= "</tbody>\n"; 
  196. $r .= "</table>\n\n"; 
  197. //} 
  198.  
  199. if ( $this->results_are_paged() ) 
  200. $r .= "<div class='tablenav bottom'>\n" . $this->paging_text_bottom . "</div><div class=\"clear\"></div>\n\n"; 
  201. echo $r; 
  202.