Ticket #5193: 5193.04.patch
File 5193.04.patch, 31.8 KB (added by , 10 years ago) |
---|
-
src/bp-messages/bp-messages-classes.php
109 109 * 110 110 * @since BuddyPress (1.0.0) 111 111 * 112 * @param int $thread_id The message thread ID.112 * @param bool|int $thread_id The message thread ID. 113 113 * @param string $order The order to sort the messages. Either 'ASC' or 'DESC'. 114 114 */ 115 115 public function __construct( $thread_id = false, $order = 'ASC' ) { … … 127 127 * 128 128 * @param int $thread_id The message thread ID. 129 129 * @param string $order The order to sort the messages. Either 'ASC' or 'DESC'. 130 * @return bool False on failure 130 131 */ 131 132 public function populate( $thread_id, $order ) { 132 133 global $wpdb, $bp; … … 135 136 $order= 'ASC'; 136 137 } 137 138 138 $this->messages_order = $order;139 $this->messages_order = apply_filters( 'messages_thread_populate_order', $order ); 139 140 $this->thread_id = $thread_id; 140 141 141 142 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 ) ) ) { 142 143 return false; 143 144 } 144 145 146 $this->messages = apply_filters( 'messages_thread_messages', $this->messages ); 147 145 148 foreach ( (array) $this->messages as $key => $message ) { 146 149 $this->sender_ids[$message->sender_id] = $message->sender_id; 147 150 } 148 151 152 $this->sender_ids = apply_filters( 'messages_thread_populate_sender_ids', $this->sender_ids ); 153 149 154 // Fetch the recipients 150 $this->recipients = $this->get_recipients();155 $this->recipients = apply_filters( 'messages_thread_populate_recipients', $this->get_recipients() ); 151 156 152 157 // Get the unread count for the logged in user 153 158 if ( isset( $this->recipients[bp_loggedin_user_id()] ) ) { 154 $this->unread_count = $this->recipients[bp_loggedin_user_id()]->unread_count;159 $this->unread_count = apply_filters( 'messages_thread_populate_unread_count', $this->recipients[bp_loggedin_user_id()]->unread_count ); 155 160 } 156 161 } 157 162 … … 190 195 $recipients = array(); 191 196 $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) ); 192 197 193 foreach ( (array) $results as $recipient ) 198 foreach ( (array) $results as $recipient ) { 194 199 $recipients[$recipient->user_id] = $recipient; 200 } 195 201 196 return $recipients;202 return apply_filters( 'messages_thread_get_recipients', $recipients, $this->thread_id ); 197 203 } 198 204 199 205 /** Static Functions ******************************************************/ … … 209 215 public static function delete( $thread_id ) { 210 216 global $wpdb, $bp; 211 217 218 do_action( 'messages_thread_delete_thread_before', $thread_id ); 219 212 220 // Mark messages as deleted 213 221 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, bp_loggedin_user_id() ) ); 214 222 … … 250 258 public static function get_current_threads_for_user( $user_id, $box = 'inbox', $type = 'all', $limit = null, $page = null, $search_terms = '' ) { 251 259 global $wpdb, $bp; 252 260 253 $user_id_sql = $pag_sql = $type_sql = $search_sql = ''; 261 $user_id_sql = $pag_sql = $type_sql = $search_sql = $total_threads = ''; 262 $thread_ids = array(); 263 $box = apply_filters( 'messages_thread_current_threads_box', $box ); 264 $type = apply_filters( 'messages_thread_current_threads_type', $type ); 265 $search_terms = apply_filters( 'messages_thread_current_threads_search_terms', $search_terms ); 254 266 255 267 if ( $limit && $page ) { 256 268 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 262 274 $type_sql = " AND r.unread_count = 0 "; 263 275 } 264 276 277 $type_sql = apply_filters( 'messages_thread_current_threads_type_sql', $type_sql ); 278 265 279 if ( ! empty( $search_terms ) ) { 266 280 $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%'; 267 281 $search_sql = $wpdb->prepare( "AND ( subject LIKE %s OR message LIKE %s )", $search_terms_like, $search_terms_like ); 268 282 } 269 283 284 $search_sql = apply_filters( 'messages_thread_current_threads_search_sql', $search_sql ); 285 270 286 if ( 'sentbox' == $box ) { 271 $user_id_sql = $wpdb->prepare( 'm.sender_id = %d', $user_id );272 $thread_ids = $wpdb->get_results( "SELECT m.thread_id, MAX(m.date_sent) AS date_sent FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND m.sender_id = r.user_id AND {$user_id_sql} AND r.is_deleted = 0 {$search_sql} GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}" );287 $user_id_sql = $wpdb->prepare( 'm.sender_id = %d', $user_id ); 288 $thread_ids = $wpdb->get_results( "SELECT m.thread_id, MAX(m.date_sent) AS date_sent FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND m.sender_id = r.user_id AND {$user_id_sql} AND r.is_deleted = 0 {$search_sql} GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}" ); 273 289 $total_threads = $wpdb->get_var( "SELECT COUNT( DISTINCT m.thread_id ) FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND m.sender_id = r.user_id AND {$user_id_sql} AND r.is_deleted = 0 {$search_sql} " ); 274 } else {275 $user_id_sql = $wpdb->prepare( 'r.user_id = %d', $user_id );276 $thread_ids = $wpdb->get_results( "SELECT m.thread_id, MAX(m.date_sent) AS date_sent FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND r.is_deleted = 0 AND {$user_id_sql} AND r.sender_only = 0 {$type_sql} {$search_sql} GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}" );290 } elseif ( 'inbox' == $box ) { 291 $user_id_sql = $wpdb->prepare( 'r.user_id = %d', $user_id ); 292 $thread_ids = $wpdb->get_results( "SELECT m.thread_id, MAX(m.date_sent) AS date_sent FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND r.is_deleted = 0 AND {$user_id_sql} AND r.sender_only = 0 {$type_sql} {$search_sql} GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}" ); 277 293 $total_threads = $wpdb->get_var( "SELECT COUNT( DISTINCT m.thread_id ) FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_messages} m WHERE m.thread_id = r.thread_id AND r.is_deleted = 0 AND {$user_id_sql} AND r.sender_only = 0 {$type_sql} {$search_sql}" ); 278 294 } 279 295 296 $thread_ids = apply_filters( 'messages_thread_current_threads_thread_ids', $thread_ids ); 297 $total_threads = apply_filters( 'messages_thread_current_threads_total_threads', $total_threads ); 298 280 299 if ( empty( $thread_ids ) ) { 281 300 return false; 282 301 } … … 293 312 $threads[] = new BP_Messages_Thread( $thread_id ); 294 313 } 295 314 296 return a rray( 'threads' => &$threads, 'total' => (int) $total_threads);315 return apply_filters( 'messages_thread_current_threads', array( 'threads' => &$threads, 'total' => (int) $total_threads ) ); 297 316 } 298 317 299 318 /** … … 302 321 * @since BuddyPress (1.0.0) 303 322 * 304 323 * @param int $thread_id The message thread ID. 324 * @return mixed False of failure, interger on success updating 305 325 */ 306 326 public static function mark_as_read( $thread_id ) { 307 327 global $wpdb, $bp; 308 328 309 $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id ); 310 $wpdb->query($sql); 329 $user_id = bp_loggedin_user_id(); 311 330 312 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); 331 $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ); 332 $result = $wpdb->query($sql); 333 334 do_action( 'messages_thread_marked_as_read', $user_id, $thread_id ); 335 336 wp_cache_delete( $user_id, 'bp_messages_unread_count' ); 337 338 return $result; 313 339 } 314 340 315 341 /** … … 318 344 * @since BuddyPress (1.0.0) 319 345 * 320 346 * @param int $thread_id The message thread ID. 347 * @return mixed False of failure, interger on success updating 321 348 */ 322 349 public static function mark_as_unread( $thread_id ) { 323 350 global $wpdb, $bp; 324 351 325 $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id ); 326 $wpdb->query($sql); 352 $user_id = bp_loggedin_user_id(); 327 353 328 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); 354 $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ); 355 $result = $wpdb->query($sql); 356 357 do_action( 'messages_thread_marked_as_unread', $user_id, $thread_id ); 358 359 wp_cache_delete( $user_id, 'bp_messages_unread_count' ); 360 361 return $result; 329 362 } 330 363 331 364 /** … … 343 376 public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) { 344 377 global $wpdb, $bp; 345 378 346 $exclude_sender = ''; 347 if ( $box != 'sentbox' ) 348 $exclude_sender = ' AND sender_only != 1'; 379 $exclude_sender_sql = $type_sql = ''; 349 380 350 if ( $type == 'unread' ) 381 if ( $box != 'sentbox' ) { 382 $exclude_sender_sql = ' AND sender_only != 1'; 383 } 384 385 $exclude_sender_sql = apply_filters( 'messages_thread_total_threads_for_user_exclude_sender_sql', $exclude_sender_sql, $user_id ); 386 387 if ( $type == 'unread' ) { 351 388 $type_sql = " AND unread_count != 0 "; 352 else if ( $type == 'read' )389 } else if ( $type == 'read' ) { 353 390 $type_sql = " AND unread_count = 0 "; 391 } 354 392 355 return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(thread_id) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0{$exclude_sender} {$type_sql}", $user_id ) ); 393 $type_sql = apply_filters( 'messages_thread_total_threads_for_user_type_sql', $type_sql, $user_id ); 394 395 return apply_filters( 'messages_thread_total_threads_for_user', (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(thread_id) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0{$exclude_sender_sql} {$type_sql}", $user_id ) ), $user_id, $box, $type ); 356 396 } 357 397 358 398 /** … … 361 401 * @since BuddyPress (1.0.0) 362 402 * 363 403 * @param int $thread_id The message thread ID. 364 * @ parambool404 * @return bool 365 405 */ 366 406 public static function user_is_sender( $thread_id ) { 367 407 global $wpdb, $bp; … … 416 456 wp_cache_set( $user_id, $unread_count, 'bp_messages_unread_count' ); 417 457 } 418 458 419 return (int) $unread_count;459 return apply_filters( 'messages_thread_get_inbox_count', (int) $unread_count ); 420 460 } 421 461 422 462 /** … … 434 474 if ( empty( $user_id ) ) 435 475 $user_id = bp_loggedin_user_id(); 436 476 437 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0 AND user_id = %d", $thread_id, $user_id ));477 return apply_filters( 'messages_thread_check_access', $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0 AND user_id = %d", $thread_id, $user_id ) ), $thread_id, $user_id ); 438 478 } 439 479 440 480 /** … … 455 495 456 496 $bp = buddypress(); 457 497 458 return $wpdb->get_var( $wpdb->prepare( "SELECT thread_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d LIMIT 1", $thread_id ));498 return apply_filters( 'messages_thread_is_valid', $wpdb->get_var( $wpdb->prepare( "SELECT thread_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d LIMIT 1", $thread_id ) ), $thread_id ); 459 499 } 460 500 461 501 /** … … 468 508 * 469 509 * @since BuddyPress (1.0.0) 470 510 * 471 * @param object $recipients Object containing the message recipients.511 * @param array $recipients Array containing the message recipients (array of objects). 472 512 * @return string 473 513 */ 474 514 public static function get_recipient_links( $recipients ) { 475 if ( count( $recipients ) >= 5 ) 476 return sprintf( __( '%s Recipients', 'buddypress' ), number_format_i18n( count( $recipients ) ) ); 515 if ( count( $recipients ) >= 5 ) { 516 return sprintf(__('%s Recipients', 'buddypress'), number_format_i18n(count($recipients))); 517 } 477 518 478 519 $recipient_links = array(); 479 520 … … 487 528 $recipient_links[] = $recipient_link; 488 529 } 489 530 531 $recipient_links = apply_filters( 'messages_thread_recipient_links', $recipient_links ); 532 490 533 return implode( ', ', (array) $recipient_links ); 491 534 } 492 535 … … 607 650 608 651 if ( $message = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE id = %d", $id ) ) ) { 609 652 $this->id = $message->id; 610 $this->thread_id = $message->thread_id;611 $this->sender_id = $message->sender_id;612 $this->subject = $message->subject;613 $this->message = $message->message;614 $this->date_sent = $message->date_sent;653 $this->thread_id = apply_filters( 'messages_message_populate_thread_id', $message->thread_id ); 654 $this->sender_id = apply_filters( 'messages_message_populate_sender_id', $message->sender_id ); 655 $this->subject = apply_filters( 'messages_message_populate_subject', $message->subject ); 656 $this->message = apply_filters( 'messages_message_populate_message', $message->message ); 657 $this->date_sent = apply_filters( 'messages_message_populate_date_sent', $message->date_sent ); 615 658 } 616 659 } 617 660 … … 633 676 do_action_ref_array( 'messages_message_before_save', array( &$this ) ); 634 677 635 678 // Make sure we have at least one recipient before sending. 636 if ( empty( $this->recipients ) ) 679 if ( empty( $this->recipients ) ) { 637 680 return false; 681 } 638 682 639 683 $new_thread = false; 640 684 … … 645 689 } 646 690 647 691 // First insert the message into the messages table 648 if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, %s )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent ) ) ) 692 if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, %s )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent ) ) ) { 649 693 return false; 694 } 650 695 651 696 $this->id = $wpdb->insert_id; 652 697 … … 681 726 */ 682 727 public function get_recipients() { 683 728 global $bp, $wpdb; 684 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ));729 return apply_filters( 'messages_message_get_recipients', $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) ), $this->thread_id ); 685 730 } 686 731 687 732 /** Static Functions **************************************************/ … … 693 738 * @return array 694 739 */ 695 740 public static function get_recipient_ids( $recipient_usernames ) { 696 if ( !$recipient_usernames ) 741 if ( !$recipient_usernames ) { 697 742 return false; 743 } 698 744 745 $recipient_ids = array(); 746 699 747 if ( is_array( $recipient_usernames ) ) { 700 748 for ( $i = 0, $count = count( $recipient_usernames ); $i < $count; ++$i ) { 701 749 if ( $rid = bp_core_get_userid( trim($recipient_usernames[$i]) ) ) { … … 704 752 } 705 753 } 706 754 707 return $recipient_ids;755 return apply_filters( 'messages_message_get_recipient_ids', $recipient_ids, $recipient_usernames ); 708 756 } 709 757 710 758 /** … … 715 763 */ 716 764 public static function get_last_sent_for_user( $thread_id ) { 717 765 global $wpdb, $bp; 718 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ));766 return apply_filters( 'messages_message_last_sent_for_user', $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ) ), $thread_id ); 719 767 } 720 768 721 769 /** … … 728 776 */ 729 777 public static function is_user_sender( $user_id, $message_id ) { 730 778 global $wpdb, $bp; 731 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND id = %d", $user_id, $message_id ));779 return apply_filters( 'messages_message_is_user_sender', $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND id = %d", $user_id, $message_id ) ), $user_id, $message_id ); 732 780 } 733 781 734 782 /** … … 739 787 */ 740 788 public static function get_message_sender( $message_id ) { 741 789 global $wpdb, $bp; 742 return $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE id = %d", $message_id ));790 return apply_filters( 'messages_message_get_message_sender', $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE id = %d", $message_id ) ), $message_id ); 743 791 } 744 792 } 745 793 … … 790 838 * Constructor. 791 839 * 792 840 * @since BuddyPress (1.0.0) 841 * @param null $id 793 842 */ 794 843 public function __construct( $id = null ) { 795 844 if ( $id ) { … … 811 860 $notice = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id ) ); 812 861 813 862 if ( $notice ) { 814 $this->subject = $notice->subject;815 $this->message = $notice->message;816 $this->date_sent = $notice->date_sent;817 $this->is_active = $notice->is_active;863 $this->subject = apply_filters( 'messages_notice_populate_subject', $notice->subject ); 864 $this->message = apply_filters( 'messages_notice_populate_message', $notice->message ); 865 $this->date_sent = apply_filters( 'messages_notice_populate_date_sent', $notice->date_sent ); 866 $this->is_active = apply_filters( 'messages_notice_populate_is_active', $notice->is_active ); 818 867 } 819 868 } 820 869 … … 865 914 * @return bool 866 915 */ 867 916 public function activate() { 868 $this->is_active = 1;917 $this->is_active = apply_filters( 'messages_notice_activate', 1 ); 869 918 return (bool) $this->save(); 870 919 } 871 920 … … 877 926 * @return bool 878 927 */ 879 928 public function deactivate() { 880 $this->is_active = 0;929 $this->is_active = apply_filters( 'messages_notice_deactivate', 0 ); 881 930 return (bool) $this->save(); 882 931 } 883 932 … … 899 948 return false; 900 949 } 901 950 951 do_action( 'messages_notice_after_delete' ); 952 902 953 return true; 903 954 } 904 955 … … 911 962 * 912 963 * @since BuddyPress (1.0.0) 913 964 * 914 * @param array $ data{965 * @param array $args { 915 966 * Array of parameters. 916 967 * @type int $pag_num Number of notices per page. Defaults to 20. 917 968 * @type int $pag_page The page number. Defaults to 1. … … 926 977 'pag_page' => 1 // Page number 927 978 ) ); 928 979 980 $r = apply_filters( 'messages_notice_get_notices_arg', $r); 981 929 982 $limit_sql = ''; 930 983 if ( (int) $r['pag_num'] >= 0 ) { 931 984 $limit_sql = $wpdb->prepare( "LIMIT %d, %d", (int) ( ( $r['pag_page'] - 1 ) * $r['pag_num'] ), (int) $r['pag_num'] ); … … 948 1001 949 1002 $notice_count = $wpdb->get_var( "SELECT COUNT(id) FROM " . $bp->messages->table_name_notices ); 950 1003 951 return $notice_count;1004 return apply_filters( 'messages_notice_total_count', $notice_count ); 952 1005 } 953 1006 954 1007 /** -
src/bp-messages/bp-messages-functions.php
245 245 * Wrapper for {@link BP_Messages_Thread::mark_as_read()}. 246 246 * 247 247 * @param int $thread_id ID of the thread. 248 * @return mixed 248 249 */ 249 250 function messages_mark_thread_read( $thread_id ) { 250 251 return BP_Messages_Thread::mark_as_read( $thread_id ); … … 256 257 * Wrapper for {@link BP_Messages_Thread::mark_as_unread()}. 257 258 * 258 259 * @param int $thread_id ID of the thread. 260 * @return mixed 259 261 */ 260 262 function messages_mark_thread_unread( $thread_id ) { 261 263 return BP_Messages_Thread::mark_as_unread( $thread_id ); -
src/bp-messages/bp-messages-template.php
130 130 $this->pag_page = isset( $_GET[$page_arg] ) ? intval( $_GET[$page_arg] ) : 1; 131 131 $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page; 132 132 133 $this->user_id = $user_id;134 $this->box = $box;135 $this->type = $type;136 $this->search_terms = $search_terms;133 $this->user_id = apply_filters( 'bp_messages_box_template_user_id', $user_id ); 134 $this->box = apply_filters( 'bp_messages_box_template_box', $box ); 135 $this->type = apply_filters( 'bp_messages_box_template_type', $type ); 136 $this->search_terms = apply_filters( 'bp_messages_box_template_search_terms', $search_terms ); 137 137 138 138 if ( 'notices' == $this->box ) { 139 139 $this->threads = BP_Messages_Notice::get_notices( array( 140 140 'pag_num' => $this->pag_num, 141 141 'pag_page' => $this->pag_page 142 142 ) ); 143 } else {143 } elseif ( 'sentbox' == $this->box || 'inbox' == $this->box ) { 144 144 $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page, $this->search_terms ); 145 145 146 146 $this->threads = $threads['threads']; … … 172 172 } 173 173 } 174 174 175 // These hooks needed for other boxes, which might not be processed above 176 $this->threads = apply_filters( 'messages_box_template_threads', $this->threads ); 177 $this->thread_count = apply_filters( 'messages_box_template_thread_count', $this->thread_count ); 178 $this->total_thread_count = apply_filters( 'messages_box_template_total_thread_count', $this->total_thread_count ); 179 175 180 if ( (int) $this->total_thread_count && (int) $this->pag_num ) { 176 181 $pag_args = array( 177 182 $page_arg => '%#%', … … 323 328 * 324 329 * @global BP_Messages_Box_Template $messages_template 325 330 * 326 * @param array $args {331 * @param array|string $args { 327 332 * Array of arguments. All are optional. 328 333 * @type int $user_id ID of the user whose threads are being loaded. 329 334 * Default: ID of the logged-in user. … … 350 355 $default_box = 'inbox'; 351 356 } 352 357 358 $default_box = apply_filters( 'messages_has_message_threads_default_box', $default_box ); 359 353 360 // Parse the arguments 354 361 $r = bp_parse_args( $args, array( 355 362 'user_id' => bp_loggedin_user_id(), … … 706 713 * 707 714 * @since BuddyPress (2.2.0) 708 715 * 709 * @param int $thread_id Optional. ID of the thread. Defaults to current thread ID.716 * @param int|bool $thread_id Optional. ID of the thread. Defaults to current thread ID. 710 717 */ 711 718 function bp_message_thread_total_count( $thread_id = false ) { 712 719 echo bp_get_message_thread_total_count( $thread_id ); … … 716 723 * 717 724 * @since BuddyPress (2.2.0) 718 725 * 719 * @param int $thread_id Optional. ID of the thread. Defaults to726 * @param int|bool $thread_id Optional. ID of the thread. Defaults to 720 727 * current thread ID. 721 728 * @return int 722 729 */ … … 740 747 * 741 748 * @since Buddypress (2.2.0) 742 749 * 743 * @param int $thread_id Optional. ID of the thread. Default: current thread ID.750 * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID. 744 751 */ 745 752 function bp_message_thread_total_and_unread_count( $thread_id = false ) { 746 753 echo bp_get_message_thread_total_and_unread_count( $thread_id ); … … 748 755 /** 749 756 * Get markup for the current thread's total and unread count. 750 757 * 751 * @param int $thread_id Optional. ID of the thread. Default: current thread ID.758 * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID. 752 759 * @return string Markup displaying the total and unread count for the thread. 753 760 */ 754 761 function bp_get_message_thread_total_and_unread_count( $thread_id = false ) { … … 803 810 * 804 811 * @see bp_get_message_thread_avatar() for a description of arguments. 805 812 * 806 * @param array $args See {@link bp_get_message_thread_avatar()}.813 * @param array|string $args See {@link bp_get_message_thread_avatar()}. 807 814 */ 808 815 function bp_message_thread_avatar( $args = '' ) { 809 816 echo bp_get_message_thread_avatar( $args ); … … 814 821 * @see bp_core_fetch_avatar() For a description of arguments and 815 822 * return values. 816 823 * 817 * @param array $args {824 * @param array|string $args { 818 825 * Arguments are listed here with an explanation of their defaults. 819 826 * For more information about the arguments, see 820 827 * {@link bp_core_fetch_avatar()}. … … 825 832 * @type string|bool $id Default: false. 826 833 * @type string $alt Default: 'Profile picture of [display name]'. 827 834 * } 828 * @return User avatar string.835 * @return string User avatar string. 829 836 */ 830 837 function bp_get_message_thread_avatar( $args = '' ) { 831 838 global $messages_template; … … 892 899 function bp_messages_pagination_count() { 893 900 global $messages_template; 894 901 895 $start_num = intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1;896 $from_num = bp_core_number_format($start_num );897 $to_num = bp_core_number_format( ( $start_num + ( $messages_template->pag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num - 1 ));898 $total = bp_core_number_format( $messages_template->total_thread_count);902 $start_num = apply_filters( 'bp_messages_pagination_count_start_num', intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1, $messages_template ); 903 $from_num = apply_filters( 'bp_messages_pagination_count_from_number', bp_core_number_format( $start_num ), $start_num ); 904 $to_num = apply_filters( 'bp_messages_pagination_count_to_num', bp_core_number_format( ( $start_num + ( $messages_template->pag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num - 1 ) ), $start_num, $messages_template ); 905 $total = apply_filters( 'bp_messages_pagination_count_total', bp_core_number_format( $messages_template->total_thread_count ), $messages_template ); 899 906 900 907 echo sprintf( _n( 'Viewing 1 message', 'Viewing %1$s - %2$s of %3$s messages', $total, 'buddypress' ), $from_num, $to_num, number_format_i18n( $total ) ); 901 908 } … … 945 952 * @return string 946 953 */ 947 954 function bp_get_messages_username_value() { 955 $user_name = ''; 956 948 957 if ( isset( $_COOKIE['bp_messages_send_to'] ) ) { 949 returnapply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] );958 $user_name = apply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] ); 950 959 } else if ( isset( $_GET['r'] ) && !isset( $_COOKIE['bp_messages_send_to'] ) ) { 951 returnapply_filters( 'bp_get_messages_username_value', $_GET['r'] );960 $user_name = apply_filters( 'bp_get_messages_username_value', $_GET['r'] ); 952 961 } 962 963 return $user_name; 953 964 } 954 965 955 966 /** … … 1001 1012 * Output the markup for the message type dropdown. 1002 1013 */ 1003 1014 function bp_messages_options() { 1004 ?>1005 1015 1016 $messages_types = apply_filters( 'bp_messages_options_types', array( 1017 '' => _x( 'Select', 'Message dropdown filter', 'buddypress' ), 1018 'read' => _x( 'Read', 'Message dropdown filter', 'buddypress' ), 1019 'unread' => _x( 'Unread', 'Message dropdown filter', 'buddypress' ), 1020 'all' => _x( 'All', 'Message dropdown filter', 'buddypress' ) 1021 ) ); 1022 ?> 1023 1006 1024 <label for="message-type-select" class="bp-screen-reader-text"> 1007 1025 <?php _e( 'Select:', 'buddypress' ) ?> 1008 1026 </label> 1009 1027 1010 1028 <select name="message-type-select" id="message-type-select"> 1011 <option value=""><?php _e( 'Select', 'buddypress' ); ?></option> 1012 <option value="read"><?php _ex('Read', 'Message dropdown filter', 'buddypress') ?></option> 1013 <option value="unread"><?php _ex('Unread', 'Message dropdown filter', 'buddypress') ?></option> 1014 <option value="all"><?php _ex('All', 'Message dropdown filter', 'buddypress') ?></option> 1029 1030 <?php foreach($messages_types as $value => $label) : ?> 1031 1032 <option value="<?php echo $value; ?>"><?php echo $label; ?></option> 1033 1034 <?php endforeach; ?> 1035 1015 1036 </select> 1016 1037 1038 <?php do_action( 'bp_messages_options_before_actions' ); ?> 1039 1017 1040 <?php if ( ! bp_is_current_action( 'sentbox' ) && ! bp_is_current_action( 'notices' ) ) : ?> 1018 1041 1019 1042 <a href="#" id="mark_as_read"><?php _ex('Mark as Read', 'Message management markup', 'buddypress') ?></a> … … 1023 1046 1024 1047 <a href="#" id="delete_<?php echo bp_current_action(); ?>_messages"><?php _e( 'Delete Selected', 'buddypress' ); ?></a> 1025 1048 1049 <?php do_action( 'bp_messages_options_after_actions' ); ?> 1050 1026 1051 <?php 1027 1052 } 1028 1053 … … 1243 1268 $notice = BP_Messages_Notice::get_active(); 1244 1269 1245 1270 if ( empty( $notice ) ) { 1246 return false;1271 return; 1247 1272 } 1248 1273 1249 1274 $closed_notices = bp_get_user_meta( bp_loggedin_user_id(), 'closed_notices', true ); … … 1475 1500 $this->message_count = count( $this->thread->messages ); 1476 1501 1477 1502 $last_message_index = $this->message_count - 1; 1478 $this->thread->last_message_id = $this->thread->messages[ $last_message_index ]->id;1479 $this->thread->last_message_date = $this->thread->messages[ $last_message_index ]->date_sent;1480 $this->thread->last_sender_id = $this->thread->messages[ $last_message_index ]->sender_id;1481 $this->thread->last_message_subject = $this->thread->messages[ $last_message_index ]->subject;1482 $this->thread->last_message_content = $this->thread->messages[ $last_message_index ]->message;1503 $this->thread->last_message_id = apply_filters( 'messages_thread_template_id', $this->thread->messages[ $last_message_index ]->id ); 1504 $this->thread->last_message_date = apply_filters( 'messages_thread_template_date_sent', $this->thread->messages[ $last_message_index ]->date_sent ); 1505 $this->thread->last_sender_id = apply_filters( 'messages_thread_template_sender_id', $this->thread->messages[ $last_message_index ]->sender_id ); 1506 $this->thread->last_message_subject = apply_filters( 'messages_thread_template_subject', $this->thread->messages[ $last_message_index ]->subject ); 1507 $this->thread->last_message_content = apply_filters( 'messages_thread_template_message', $this->thread->messages[ $last_message_index ]->message ); 1483 1508 } 1484 1509 1485 1510 /** … … 1566 1591 /** 1567 1592 * Initialize the messages template loop for a specific thread. 1568 1593 * 1569 * @param array $args {1594 * @param array|string $args { 1570 1595 * Array of arguments. All are optional. 1571 1596 * @type int $thread_id ID of the thread whose messages you are displaying. 1572 1597 * Default: if viewing a thread, the thread ID will be parsed from … … 1589 1614 1590 1615 $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'] ); 1591 1616 1592 return $thread_template->has_messages();1617 return apply_filters( 'bp_thread_has_messages', $thread_template->has_messages(), $thread_template ); 1593 1618 } 1594 1619 1595 1620 /** … … 1605 1630 */ 1606 1631 function bp_get_thread_messages_order() { 1607 1632 global $thread_template; 1608 return $thread_template->thread->messages_order;1633 return apply_filters( 'bp_get_thread_messages_order', $thread_template->thread->messages_order ); 1609 1634 } 1610 1635 1611 1636 /** … … 1692 1717 */ 1693 1718 function bp_get_thread_recipients_count() { 1694 1719 global $thread_template; 1695 return count( $thread_template->thread->recipients);1720 return apply_filters( 'bp_get_thread_recipients_count', count( $thread_template->thread->recipients ) ); 1696 1721 } 1697 1722 1698 1723 /** … … 1842 1867 /** 1843 1868 * Output the avatar for the current message sender. 1844 1869 * 1845 * @param array $args See {@link bp_get_the_thread_message_sender_avatar_thumb()}1870 * @param array|string $args See {@link bp_get_the_thread_message_sender_avatar_thumb()} 1846 1871 * for a description. 1847 1872 */ 1848 1873 function bp_the_thread_message_sender_avatar( $args = '' ) { … … 1851 1876 /** 1852 1877 * Get the avatar for the current message sender. 1853 1878 * 1854 * @param array $args {1879 * @param array|string $args { 1855 1880 * Array of arguments. See {@link bp_core_fetch_avatar()} for more 1856 1881 * complete details. All arguments are optional. 1857 1882 * @type string $type Avatar type. Default: 'thumb'.