1 | <?php |
---|
2 | function bp_core_directory_members_setup() { |
---|
3 | global $bp, $current_blog; |
---|
4 | |
---|
5 | if ( $bp['current_component'] == MEMBERS_SLUG && $bp['current_action'] == '' ) { |
---|
6 | add_action( 'bp_template_content', 'bp_core_directory_members_content' ); |
---|
7 | add_action( 'bp_template_sidebar', 'bp_core_directory_members_sidebar' ); |
---|
8 | |
---|
9 | wp_enqueue_script( 'bp-core-directory-members', site_url( MUPLUGINDIR . '/bp-core/js/directory-members.js' ), array( 'jquery', 'jquery-livequery-pack' ) ); |
---|
10 | wp_enqueue_style( 'bp-core-directory-members', site_url( MUPLUGINDIR . '/bp-core/css/directory-members.css' ) ); |
---|
11 | |
---|
12 | if ( file_exists( TEMPLATEPATH . '/plugin-template.php' ) ) |
---|
13 | bp_core_load_template('plugin-template'); |
---|
14 | else |
---|
15 | wp_die( __( 'To enable the member directory you must drop the "plugin-template.php and plugin-sidebar.php" files into your theme directory.', 'buddypress' ) ); |
---|
16 | } |
---|
17 | } |
---|
18 | add_action( 'wp', 'bp_core_directory_members_setup', 5 ); |
---|
19 | |
---|
20 | function bp_core_directory_members_content() { |
---|
21 | global $bp; |
---|
22 | |
---|
23 | $pag_page = isset( $_GET['page'] ) ? intval( $_GET['page'] ) : 1; |
---|
24 | $pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 10; |
---|
25 | |
---|
26 | if ( isset( $_GET['s'] ) ) |
---|
27 | $users = BP_Core_User::search_users( $_GET['s'], $pag_num, $pag_page ); |
---|
28 | else |
---|
29 | $users = BP_Core_User::get_active_users( $pag_num, $pag_page ); |
---|
30 | |
---|
31 | $pag_links = paginate_links( array( |
---|
32 | 'base' => add_query_arg( 'page', '%#%' ), |
---|
33 | 'format' => '', |
---|
34 | 'total' => ceil( $users['total'] / $pag_num ), |
---|
35 | 'current' => $pag_page, |
---|
36 | 'prev_text' => '«', |
---|
37 | 'next_text' => '»', |
---|
38 | 'mid_size' => 1 |
---|
39 | )); |
---|
40 | |
---|
41 | $from_num = intval( ( $pag_page - 1 ) * $pag_num ) + 1; |
---|
42 | $to_num = ( $from_num + 9 > $users['total'] ) ? $users['total'] : $from_num + 9; |
---|
43 | |
---|
44 | ?> |
---|
45 | <div id="content" class="narrowcolumn"> |
---|
46 | |
---|
47 | <form action="<?php echo site_url() . '/' ?>" method="post" id="members-directory-form"> |
---|
48 | <div class="widget"> |
---|
49 | <h2 class="widgettitle"><?php _e( 'Member Directory', 'buddypress' ) ?></h2> |
---|
50 | <ul id="letter-list"> |
---|
51 | <li><a href="#a" id="letter-a">A</a></li> |
---|
52 | <li><a href="#b" id="letter-b">B</a></li> |
---|
53 | <li><a href="#c" id="letter-c">C</a></li> |
---|
54 | <li><a href="#d" id="letter-d">D</a></li> |
---|
55 | <li><a href="#e" id="letter-e">E</a></li> |
---|
56 | <li><a href="#f" id="letter-f">F</a></li> |
---|
57 | <li><a href="#g" id="letter-g">G</a></li> |
---|
58 | <li><a href="#h" id="letter-h">H</a></li> |
---|
59 | <li><a href="#i" id="letter-i">I</a></li> |
---|
60 | <li><a href="#j" id="letter-j">J</a></li> |
---|
61 | <li><a href="#k" id="letter-k">K</a></li> |
---|
62 | <li><a href="#l" id="letter-l">L</a></li> |
---|
63 | <li><a href="#m" id="letter-m">M</a></li> |
---|
64 | <li><a href="#n" id="letter-n">N</a></li> |
---|
65 | <li><a href="#o" id="letter-o">O</a></li> |
---|
66 | <li><a href="#p" id="letter-p">P</a></li> |
---|
67 | <li><a href="#q" id="letter-q">Q</a></li> |
---|
68 | <li><a href="#r" id="letter-r">R</a></li> |
---|
69 | <li><a href="#s" id="letter-s">S</a></li> |
---|
70 | <li><a href="#t" id="letter-t">T</a></li> |
---|
71 | <li><a href="#u" id="letter-u">U</a></li> |
---|
72 | <li><a href="#v" id="letter-v">V</a></li> |
---|
73 | <li><a href="#w" id="letter-w">W</a></li> |
---|
74 | <li><a href="#x" id="letter-x">X</a></li> |
---|
75 | <li><a href="#y" id="letter-y">Y</a></li> |
---|
76 | <li><a href="#z" id="letter-z">Z</a></li> |
---|
77 | </ul> |
---|
78 | |
---|
79 | <div class="clear"></div> |
---|
80 | </div> |
---|
81 | |
---|
82 | <div class="widget"> |
---|
83 | <h2 class="widgettitle"><?php _e( 'Member Listing', 'buddypress' ) ?></h2> |
---|
84 | |
---|
85 | <div id="member-dir-list"> |
---|
86 | <?php if ( $users['users'] ) : ?> |
---|
87 | <div id="member-dir-count" class="pag-count"> |
---|
88 | <?php echo sprintf( __( 'Viewing member %d to %d (%d total active members)', 'buddypress' ), $from_num, $to_num, $users['total'] ); ?> |
---|
89 | <img id="ajax-loader-members" src="<?php echo $bp['core']['image_base'] ?>/ajax-loader.gif" height="7" alt="<?php _e( "Loading", "buddypress" ) ?>" style="display: none;" /> |
---|
90 | </div> |
---|
91 | |
---|
92 | <div class="pagination-links" id="member-dir-pag"> |
---|
93 | <?php echo $pag_links ?> |
---|
94 | </div> |
---|
95 | |
---|
96 | <ul id="members-list" class="item-list"> |
---|
97 | <?php foreach ( $users['users'] as $user ) : ?> |
---|
98 | <li> |
---|
99 | <div class="item-avatar"> |
---|
100 | <a href="<?php echo bp_core_get_userlink( $user->user_id, false, true ) ?>"><?php echo bp_core_get_avatar( $user->user_id, 1 ) ?></a> |
---|
101 | </div> |
---|
102 | |
---|
103 | <div class="item"> |
---|
104 | <div class="item-title"><?php echo bp_core_get_userlink( $user->user_id ) ?></div> |
---|
105 | <div class="item-meta"><span class="activity"><?php echo bp_core_get_last_activity( get_usermeta( $user->user_id, 'last_activity' ), __('active %s ago', 'buddypress') ) ?></span></div> |
---|
106 | </div> |
---|
107 | |
---|
108 | <div class="action"> |
---|
109 | <?php if ( function_exists( 'bp_add_friend_button' ) ) { ?> |
---|
110 | <?php bp_add_friend_button( $user->user_id ) ?> |
---|
111 | <?php } ?> |
---|
112 | <div class="meta"> |
---|
113 | <?php if ( $user_obj->total_friends ) echo $user_obj->total_friends ?><?php if ( $user_obj->total_blogs ) echo ', ' . $user_obj->total_blogs ?><?php if ( $user_obj->total_groups ) echo ', ' . $user_obj->total_groups ?> |
---|
114 | </div> |
---|
115 | </div> |
---|
116 | |
---|
117 | <div class="clear"></div> |
---|
118 | </li> |
---|
119 | <?php endforeach; ?> |
---|
120 | </ul> |
---|
121 | |
---|
122 | <?php |
---|
123 | if ( isset( $_GET['s'] ) ) { |
---|
124 | echo '<input type="hidden" id="search_terms" value="' . $_GET['s'] . '" name="search_terms" />'; |
---|
125 | } |
---|
126 | ?> |
---|
127 | |
---|
128 | <?php else: ?> |
---|
129 | <div id="message" class="info"> |
---|
130 | <p><?php _e( 'No members found. Members must fill in at least one piece of profile data to show in member lists.', 'buddypress' ) ?></p> |
---|
131 | </div> |
---|
132 | <?php endif; ?> |
---|
133 | </div> |
---|
134 | </div> |
---|
135 | |
---|
136 | <?php do_action( 'bp_core_directory_members_content' ) ?> |
---|
137 | |
---|
138 | <?php wp_nonce_field('directory_members', '_wpnonce-member-filter' ) ?> |
---|
139 | </form> |
---|
140 | |
---|
141 | </div> |
---|
142 | <?php |
---|
143 | } |
---|
144 | |
---|
145 | function bp_core_directory_members_sidebar() { |
---|
146 | global $bp; |
---|
147 | ?> |
---|
148 | <div class="widget"> |
---|
149 | <h2 class="widgettitle"><?php _e( 'Find Members', 'buddypress' ) ?></h2> |
---|
150 | <form action="<?php echo site_url() . '/' . MEMBERS_SLUG . '/search/' ?>" method="post" id="search-members-form"> |
---|
151 | <label><input type="text" name="members_search" id="members_search" value="<?php if ( isset( $_GET['s'] ) ) { echo $_GET['s']; } else { _e('Search anything...', 'buddypress' ); } ?>" onfocus="if (this.value == '<?php _e('Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e('Search anything...', 'buddypress' ) ?>';}" /></label> |
---|
152 | <input type="submit" id="members_search_submit" name="members_search_submit" value="Search" /> |
---|
153 | </form> |
---|
154 | </div> |
---|
155 | |
---|
156 | <div class="widget"> |
---|
157 | <h2 class="widgettitle"><?php _e( 'Featured Members', 'buddypress' ) ?></h2> |
---|
158 | |
---|
159 | <?php $users = BP_Core_User::get_random_users( 3, 1 ) ?> |
---|
160 | |
---|
161 | <?php if ( $users['users'] ) { ?> |
---|
162 | <ul id="featured-member-list" class="item-list"> |
---|
163 | <?php foreach( $users['users'] as $user ) : ?> |
---|
164 | <li> |
---|
165 | <div class="item-avatar"> |
---|
166 | <a href="<?php echo bp_core_get_userlink( $user->user_id, false, true ) ?>"><?php echo bp_core_get_avatar( $user->user_id, 1 ) ?></a> |
---|
167 | </div> |
---|
168 | |
---|
169 | <div class="item"> |
---|
170 | <div class="item-title"><?php echo bp_core_get_userlink( $user->user_id ) ?></div> |
---|
171 | <div class="item-meta"><span class="activity"><?php echo bp_core_get_last_activity( get_usermeta( $user->user_id, 'last_activity' ), __('active %s ago', 'buddypress') ) ?></span></div> |
---|
172 | |
---|
173 | <?php if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?> |
---|
174 | <?php $random_data = xprofile_get_random_profile_data( $user->user_id, true ); ?> |
---|
175 | <div class="item-title profile-data"> |
---|
176 | <p class="field-name"><?php echo $random_data[0]->name ?></p> |
---|
177 | <?php echo $random_data[0]->value ?> |
---|
178 | </div> |
---|
179 | <?php } ?> |
---|
180 | </div> |
---|
181 | </li> |
---|
182 | <?php endforeach; ?> |
---|
183 | </ul> |
---|
184 | <?php } else { ?> |
---|
185 | <div id="message" class="info"> |
---|
186 | <p><?php _e( 'There are no members to feature.', 'buddypress' ) ?></p> |
---|
187 | </div> |
---|
188 | <?php } ?> |
---|
189 | </div> |
---|
190 | |
---|
191 | <?php do_action( 'bp_core_directory_members_sidebar' ) ?> |
---|
192 | <?php |
---|
193 | } |
---|