Changeset 3760 for trunk/bp-messages/bp-messages-classes.php
- Timestamp:
- 01/20/2011 11:43:41 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/bp-messages/bp-messages-classes.php (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-messages/bp-messages-classes.php
r3713 r3760 21 21 22 22 $this->messages_order = $order; 23 $this->thread_id = $thread_id;23 $this->thread_id = $thread_id; 24 24 25 25 if ( !$this->messages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE thread_id = %d ORDER BY date_sent " . $order, $this->thread_id ) ) ) … … 29 29 $this->sender_ids[$message->sender_id] = $message->sender_id; 30 30 31 / * Fetch the recipients */31 // Fetch the recipients 32 32 $this->recipients = $this->get_recipients(); 33 33 34 / * Get the unread count for the logged in user */34 // Get the unread count for the logged in user 35 35 if ( isset( $this->recipients[$bp->loggedin_user->id] ) ) 36 36 $this->unread_count = $this->recipients[$bp->loggedin_user->id]->unread_count; … … 68 68 69 69 if ( empty( $recipients ) ) { 70 / * Delete all the messages */70 // Delete all the messages 71 71 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); 72 72 73 / * Delete all the recipients */73 // Delete all the recipients 74 74 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) ); 75 75 } … … 81 81 global $wpdb, $bp; 82 82 83 $pag_sql = '';83 $pag_sql = $type_sql = ''; 84 84 if ( $limit && $page ) 85 85 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 86 86 87 $type_sql = '';88 87 if ( $type == 'unread' ) 89 88 $type_sql = $wpdb->prepare( " AND r.unread_count != 0 " ); … … 102 101 return false; 103 102 104 / * Sort threads by date_sent */105 foreach( (array)$thread_ids as $thread ) {106 $sorted_threads[$thread->thread_id] = strtotime( $thread->date_sent);107 } 108 arsort( $sorted_threads);103 // Sort threads by date_sent 104 foreach( (array)$thread_ids as $thread ) 105 $sorted_threads[$thread->thread_id] = strtotime( $thread->date_sent ); 106 107 arsort( $sorted_threads ); 109 108 110 109 $threads = false; … … 173 172 174 173 $count = 0; 175 for ( $i = 0; $i < count( $unread_counts); $i++ ) {174 for ( $i = 0; $i < count( $unread_counts ); $i++ ) { 176 175 $count += $unread_counts[$i]->unread_count; 177 176 } … … 180 179 } 181 180 182 function check_access( $thread_id, $user_id = false) {183 global $wpdb, $bp; 184 185 if ( !$user_id)181 function check_access( $thread_id, $user_id = 0 ) { 182 global $wpdb, $bp; 183 184 if ( empty( $user_id ) ) 186 185 $user_id = $bp->loggedin_user->id; 187 186 … … 199 198 return count( $recipients ) . __(' Recipients', 'buddypress'); 200 199 201 foreach ( (array)$recipients as $recipient ) {200 foreach ( (array)$recipients as $recipient ) 202 201 $recipient_links[] = bp_core_get_userlink( $recipient->user_id ); 203 }204 202 205 203 return implode( ', ', (array) $recipient_links ); 206 204 } 207 205 208 / * Update Functions */206 // Update Functions 209 207 210 208 function update_tables() { … … 214 212 $threads = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}bp_messages_threads" ) ); 215 213 216 / * Nothing to update, just return true to remove the table */214 // Nothing to update, just return true to remove the table 217 215 if ( empty( $threads ) ) 218 216 return true; … … 224 222 $message_ids = implode( ',', $message_ids ); 225 223 226 / * Add the thread_id to the messages table */224 // Add the thread_id to the messages table 227 225 if ( !$wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_messages} SET thread_id = %d WHERE id IN ({$message_ids})", $thread->id ) ) ) 228 226 $errors = true; … … 253 251 $this->sender_id = $bp->loggedin_user->id; 254 252 255 if ( $id ) { 256 $this->populate($id); 257 } 253 if ( !empty( $id ) ) 254 $this->populate( $id ); 258 255 } 259 256 … … 262 259 263 260 if ( $message = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE id = %d", $id ) ) ) { 264 $this->id = $message->id;261 $this->id = $message->id; 265 262 $this->thread_id = $message->thread_id; 266 263 $this->sender_id = $message->sender_id; 267 $this->subject = $message->subject;268 $this->message = $message->message;264 $this->subject = $message->subject; 265 $this->message = $message->message; 269 266 $this->date_sent = $message->date_sent; 270 267 } … … 276 273 $this->sender_id = apply_filters( 'messages_message_sender_id_before_save', $this->sender_id, $this->id ); 277 274 $this->thread_id = apply_filters( 'messages_message_thread_id_before_save', $this->thread_id, $this->id ); 278 $this->subject = apply_filters( 'messages_message_subject_before_save', $this->subject, $this->id );279 $this->message = apply_filters( 'messages_message_content_before_save', $this->message, $this->id );275 $this->subject = apply_filters( 'messages_message_subject_before_save', $this->subject, $this->id ); 276 $this->message = apply_filters( 'messages_message_content_before_save', $this->message, $this->id ); 280 277 $this->date_sent = apply_filters( 'messages_message_date_sent_before_save', $this->date_sent, $this->id ); 281 278 282 279 do_action( 'messages_message_before_save', $this ); 283 280 284 / * Make sure we have at least one recipient before sending. */281 // Make sure we have at least one recipient before sending. 285 282 if ( empty( $this->recipients ) ) 286 283 return false; … … 288 285 $new_thread = false; 289 286 290 / * If we have no thread_id then this is the first message of a new thread. */287 // If we have no thread_id then this is the first message of a new thread. 291 288 if ( empty( $this->thread_id ) ) { 292 289 $this->thread_id = (int)$wpdb->get_var( $wpdb->prepare( "SELECT MAX(thread_id) FROM {$bp->messages->table_name_messages}" ) ) + 1; … … 299 296 300 297 if ( $new_thread ) { 301 / * Add an recipient entry for all recipients */298 // Add an recipient entry for all recipients 302 299 foreach ( (array)$this->recipients as $recipient ) 303 300 $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count ) VALUES ( %d, %d, 1 )", $recipient->user_id, $this->thread_id ) ); 304 301 305 / * Add a sender recipient entry if the sender is not in the list of recipients */302 // Add a sender recipient entry if the sender is not in the list of recipients 306 303 if ( !in_array( $this->sender_id, $this->recipients ) ) 307 304 $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, sender_only ) VALUES ( %d, %d, 1 )", $this->sender_id, $this->thread_id ) ); 308 305 } else { 309 / * Update the unread count for all recipients */306 // Update the unread count for all recipients 310 307 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = unread_count + 1, sender_only = 0, is_deleted = 0 WHERE thread_id = %d AND user_id != %d", $this->thread_id, $this->sender_id ) ); 311 308 } … … 365 362 var $is_active; 366 363 367 function bp_messages_notice( $id = null) {364 function bp_messages_notice( $id = null ) { 368 365 if ( $id ) { 369 366 $this->id = $id; … … 378 375 379 376 if ( $notice ) { 380 $this->subject = $notice->subject;381 $this->message = $notice->message;377 $this->subject = $notice->subject; 378 $this->message = $notice->message; 382 379 $this->date_sent = $notice->date_sent; 383 380 $this->is_active = $notice->is_active; … … 393 390 do_action( 'messages_notice_before_save', $this ); 394 391 395 if ( !$this->id ) {392 if ( empty( $this->id ) ) 396 393 $sql = $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_notices} (subject, message, date_sent, is_active) VALUES (%s, %s, %s, %d)", $this->subject, $this->message, $this->date_sent, $this->is_active ); 397 } else {394 else 398 395 $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_notices} SET subject = %s, message = %s, is_active = %d WHERE id = %d", $this->subject, $this->message, $this->is_active, $this->id ); 399 } 400 401 if ( !$wpdb->query($sql) ) 396 397 if ( !$wpdb->query( $sql ) ) 402 398 return false; 403 399 … … 436 432 $sql = $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id ); 437 433 438 if ( !$wpdb->query( $sql) )434 if ( !$wpdb->query( $sql ) ) 439 435 return false; 440 436 … … 463 459 464 460 $notice_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_notices} WHERE is_active = 1") ); 465 return new BP_Messages_Notice( $notice_id);461 return new BP_Messages_Notice( $notice_id ); 466 462 } 467 463 }
Note: See TracChangeset
for help on using the changeset viewer.