Changeset 3260 for branches/1.2/bp-friends/bp-friends-templatetags.php
- Timestamp:
- 09/13/2010 01:08:31 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.2/bp-friends/bp-friends-templatetags.php
r3162 r3260 105 105 <form action="<?php echo $action ?>" id="friend-search-form" method="post"> 106 106 107 <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>108 <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />109 110 <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>111 <input type="hidden" name="initiator" id="initiator" value="<?php echo esc_attr( $bp->displayed_user->id ) ?>" />107 <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label> 108 <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> /> 109 110 <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?> 111 <input type="hidden" name="initiator" id="initiator" value="<?php echo esc_attr( $bp->displayed_user->id ) ?>" /> 112 112 113 113 </form> … … 115 115 } 116 116 117 function bp_add_friend_button( $potential_friend_id = false, $friend_status = false ) { 117 function bp_member_add_friend_button() { 118 global $members_template; 119 120 if ( null === $members_template->member->is_friend ) 121 $friend_status = 'not_friends'; 122 else 123 $friend_status = ( 0 == $members_template->member->is_friend ) ? 'pending' : 'is_friend'; 124 125 echo bp_get_add_friend_button( $members_template->member->id, $friend_status ); 126 } 127 add_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' ); 128 129 function bp_member_total_friend_count() { 130 global $members_template; 131 132 echo bp_get_member_total_friend_count(); 133 } 134 function bp_get_member_total_friend_count() { 135 global $members_template; 136 137 if ( 1 == (int) $members_template->member->total_friend_count ) 138 return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friend', 'buddypress' ), (int) $members_template->member->total_friend_count ) ); 139 else 140 return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friends', 'buddypress' ), (int) $members_template->member->total_friend_count ) ); 141 } 142 143 /** 144 * bp_potential_friend_id( $user_id ) 145 * 146 * Outputs the ID of the potential friend 147 * 148 * @uses bp_get_potential_friend_id() 149 * @param <type> $user_id 150 */ 151 function bp_potential_friend_id( $user_id = 0 ) { 152 echo bp_get_potential_friend_id( $user_id ); 153 } 154 /** 155 * bp_get_potential_friend_id( $user_id ) 156 * 157 * Returns the ID of the potential friend 158 * 159 * @global object $bp 160 * @global object $friends_template 161 * @param int $user_id 162 * @return int ID of potential friend 163 */ 164 function bp_get_potential_friend_id( $user_id = 0 ) { 165 global $bp, $friends_template; 166 167 if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) ) 168 $user_id = $friends_template->friendship->friend->id; 169 else if ( empty( $user_id ) && !isset( $friends_template->friendship->friend ) ) 170 $user_id = $bp->displayed_user->id; 171 172 return apply_filters( 'bp_get_potential_friend_id', (int)$user_id ); 173 } 174 175 /** 176 * bp_is_friend( $user_id ) 177 * 178 * Returns - 'is_friend', 'not_friends', 'pending' 179 * 180 * @global object $bp 181 * @param int $potential_friend_id 182 * @return string 183 */ 184 function bp_is_friend( $user_id = 0 ) { 185 global $bp; 186 187 if ( !is_user_logged_in() ) 188 return false; 189 190 if ( empty( $user_id ) ) 191 $user_id = bp_get_potential_friend_id( $user_id ); 192 193 if ( $bp->loggedin_user->id == $user_id ) 194 return false; 195 196 return apply_filters( 'bp_is_friend', friends_check_friendship_status( $bp->loggedin_user->id, $user_id ), $user_id ); 197 } 198 199 function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false ) { 118 200 echo bp_get_add_friend_button( $potential_friend_id, $friend_status ); 119 201 } 120 function bp_get_add_friend_button( $potential_friend_id = false, $friend_status = false ) {202 function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) { 121 203 global $bp, $friends_template; 122 204 123 if ( !is_user_logged_in() ) 205 if ( empty( $potential_friend_id ) ) 206 $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id ); 207 208 $is_friend = bp_is_friend( $potential_friend_id ); 209 210 if ( empty( $is_friend ) ) 124 211 return false; 125 212 126 if ( !$potential_friend_id && $friends_template->friendship->friend ) 127 $potential_friend_id = $friends_template->friendship->friend->id; 128 else if ( !$potential_friend_id && !$friends_template->friendship->friend ) 129 $potential_friend_id = $bp->displayed_user->id; 130 131 if ( $bp->loggedin_user->id == $potential_friend_id ) 132 return false; 133 134 if ( empty( $friend_status ) ) 135 $friend_status = friends_check_friendship_status( $bp->loggedin_user->id, $potential_friend_id ); 136 137 $button = '<div class="generic-button friendship-button ' . $friend_status . '" id="friendship-button-' . $potential_friend_id . '">'; 138 139 if ( 'pending' == $friend_status ) 140 $button .= '<a class="requested" href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/">' . __( 'Friendship Requested', 'buddypress' ) . '</a>'; 141 else if ( 'is_friend' == $friend_status ) 142 $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ) . '" title="' . __('Cancel Friendship', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="remove" class="remove">' . __('Cancel Friendship', 'buddypress') . '</a>'; 143 else 144 $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ) . '" title="' . __('Add Friend', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="add" class="add">' . __('Add Friend', 'buddypress') . '</a>'; 145 146 $button .= '</div>'; 147 148 return apply_filters( 'bp_get_add_friend_button', $button, $potential_friend_id, $friend_status ); 213 switch ( $is_friend ) { 214 case 'pending' : 215 $button = array( 216 'id' => 'pending', 217 'component' => 'friends', 218 'must_be_logged_in' => true, 219 'block_self' => true, 220 'wrapper_class' => 'friendship-button pending', 221 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 222 'link_class' => 'requested', 223 'link_href' => trailingslashit( $bp->loggedin_user->domain . $bp->friends->slug ), 224 'link_text' => __( 'Friendship Requested', 'buddypress' ), 225 'link_title' => __( 'Friendship Requested', 'buddypress' ) 226 ); 227 break; 228 229 case 'is_friend' : 230 $button = array( 231 'id' => 'is_friend', 232 'component' => 'friends', 233 'must_be_logged_in' => true, 234 'block_self' => true, 235 'wrapper_class' => 'friendship-button is_friend', 236 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 237 'link_class' => '', 238 'link_href' => wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ), 239 'link_text' => __( 'Cancel Friendship', 'buddypress' ), 240 'link_title' => __( 'Cancel Friendship', 'buddypress' ), 241 'link_id' => 'friend-' . $potential_friend_id, 242 'link_rel' => 'remove', 243 'link_class' => 'remove' 244 ); 245 break; 246 247 default: 248 $button = array( 249 'id' => 'not_friends', 250 'component' => 'friends', 251 'must_be_logged_in' => true, 252 'block_self' => true, 253 'wrapper_class' => 'friendship-button not_friends', 254 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 255 'link_class' => '', 256 'link_href' => wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ), 257 'link_text' => __( 'Add Friend', 'buddypress' ), 258 'link_title' => __( 'Add Friend', 'buddypress' ), 259 'link_id' => 'friend-' . $potential_friend_id, 260 'link_rel' => 'add', 261 'link_class' => 'add' 262 ); 263 break; 264 } 265 266 // Filter and return the HTML button 267 return bp_get_button( apply_filters( 'bp_get_add_friend_button', $button ) ); 149 268 } 150 269 … … 210 329 } 211 330 212 function bp_total_friend_count( $user_id = false) {331 function bp_total_friend_count( $user_id = 0 ) { 213 332 echo bp_get_total_friend_count( $user_id ); 214 333 } 215 function bp_get_total_friend_count( $user_id = false) {334 function bp_get_total_friend_count( $user_id = 0 ) { 216 335 return apply_filters( 'bp_get_total_friend_count', friends_get_total_friend_count( $user_id ) ); 217 336 } 218 337 add_filter( 'bp_get_total_friend_count', 'bp_core_number_format' ); 219 338 220 function bp_friend_total_requests_count( $user_id = false) {339 function bp_friend_total_requests_count( $user_id = 0 ) { 221 340 echo bp_friend_get_total_requests_count( $user_id ); 222 341 } 223 function bp_friend_get_total_requests_count( $user_id = false) {342 function bp_friend_get_total_requests_count( $user_id = 0 ) { 224 343 global $bp; 225 344 226 if ( !$user_id)345 if ( empty( $user_id ) ) 227 346 $user_id = $bp->loggedin_user->id; 228 347
Note: See TracChangeset
for help on using the changeset viewer.