Ticket #5193: 5193.01.patch
File 5193.01.patch, 28.4 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 ) ) ) { … … 146 147 $this->sender_ids[$message->sender_id] = $message->sender_id; 147 148 } 148 149 150 $this->sender_ids = apply_filters( 'messages_thread_populate_sender_ids', $this->sender_ids ); 151 149 152 // Fetch the recipients 150 $this->recipients = $this->get_recipients();153 $this->recipients = apply_filters( 'messages_thread_populate_recipients', $this->get_recipients() ); 151 154 152 155 // Get the unread count for the logged in user 153 156 if ( isset( $this->recipients[bp_loggedin_user_id()] ) ) { 154 $this->unread_count = $this->recipients[bp_loggedin_user_id()]->unread_count;157 $this->unread_count = apply_filters( 'messages_thread_populate_unread_count', $this->recipients[bp_loggedin_user_id()]->unread_count ); 155 158 } 156 159 } 157 160 … … 190 193 $recipients = array(); 191 194 $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) ); 192 195 193 foreach ( (array) $results as $recipient ) 196 foreach ( (array) $results as $recipient ) { 194 197 $recipients[$recipient->user_id] = $recipient; 198 } 195 199 196 return $recipients;200 return apply_filters( 'messages_thread_get_recipients', $recipients, $this->thread_id ); 197 201 } 198 202 199 203 /** Static Functions ******************************************************/ … … 209 213 public static function delete( $thread_id ) { 210 214 global $wpdb, $bp; 211 215 216 do_action( 'messages_thread_delete_thread_before', $thread_id ); 217 212 218 // Mark messages as deleted 213 219 $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 220 … … 250 256 public static function get_current_threads_for_user( $user_id, $box = 'inbox', $type = 'all', $limit = null, $page = null, $search_terms = '' ) { 251 257 global $wpdb, $bp; 252 258 253 $user_id_sql = $pag_sql = $type_sql = $search_sql = ''; 259 $user_id_sql = $pag_sql = $type_sql = $search_sql = $total_threads = ''; 260 $thread_ids = array(); 261 $box = apply_filters( 'messages_thread_current_threads_box', $box ); 262 $type = apply_filters( 'messages_thread_current_threads_type', $type ); 263 $search_terms = apply_filters( 'messages_thread_current_threads_search_terms', $search_terms ); 254 264 255 265 if ( $limit && $page ) { 256 266 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 262 272 $type_sql = " AND r.unread_count = 0 "; 263 273 } 264 274 275 $type_sql = apply_filters( 'messages_thread_current_threads_type_sql', $type_sql ); 276 265 277 if ( ! empty( $search_terms ) ) { 266 278 $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%'; 267 279 $search_sql = $wpdb->prepare( "AND ( subject LIKE %s OR message LIKE %s )", $search_terms_like, $search_terms_like ); 268 280 } 269 281 282 $search_sql = apply_filters( 'messages_thread_current_threads_search_sql', $search_sql ); 283 270 284 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}" );285 $user_id_sql = $wpdb->prepare( 'm.sender_id = %d', $user_id ); 286 $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 287 $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}" );288 } elseif ( 'inbox' == $box ) { 289 $user_id_sql = $wpdb->prepare( 'r.user_id = %d', $user_id ); 290 $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 291 $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 292 } 279 293 294 $thread_ids = apply_filters( 'messages_thread_current_threads_thread_ids', $thread_ids ); 295 $total_threads = apply_filters( 'messages_thread_current_threads_total_threads', $total_threads ); 296 280 297 if ( empty( $thread_ids ) ) { 281 298 return false; 282 299 } … … 293 310 $threads[] = new BP_Messages_Thread( $thread_id ); 294 311 } 295 312 296 return a rray( 'threads' => &$threads, 'total' => (int) $total_threads);313 return apply_filters( 'messages_thread_current_threads', array( 'threads' => &$threads, 'total' => (int) $total_threads ) ); 297 314 } 298 315 299 316 /** … … 306 323 public static function mark_as_read( $thread_id ) { 307 324 global $wpdb, $bp; 308 325 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 ); 326 $user_id = bp_loggedin_user_id(); 327 328 $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 ); 310 329 $wpdb->query($sql); 311 330 312 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); 331 do_action( 'messages_thread_marked_as_read', $user_id, $thread_id ); 332 333 wp_cache_delete( $user_id, 'bp_messages_unread_count' ); 313 334 } 314 335 315 336 /** … … 322 343 public static function mark_as_unread( $thread_id ) { 323 344 global $wpdb, $bp; 324 345 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 ); 346 $user_id = bp_loggedin_user_id(); 347 348 $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 ); 326 349 $wpdb->query($sql); 327 350 328 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); 351 do_action( 'messages_thread_marked_as_unread', $user_id, $thread_id ); 352 353 wp_cache_delete( $user_id, 'bp_messages_unread_count' ); 329 354 } 330 355 331 356 /** … … 343 368 public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) { 344 369 global $wpdb, $bp; 345 370 346 $exclude_sender = ''; 347 if ( $box != 'sentbox' ) 348 $exclude_sender = ' AND sender_only != 1'; 371 $exclude_sender_sql = $type_sql = ''; 349 372 350 if ( $type == 'unread' ) 373 if ( $box != 'sentbox' ) { 374 $exclude_sender_sql = ' AND sender_only != 1'; 375 } 376 377 $exclude_sender_sql = apply_filters( 'messages_thread_total_threads_for_user_exclude_sender_sql', $exclude_sender_sql, $user_id ); 378 379 if ( $type == 'unread' ) { 351 380 $type_sql = " AND unread_count != 0 "; 352 else if ( $type == 'read' )381 } else if ( $type == 'read' ) { 353 382 $type_sql = " AND unread_count = 0 "; 383 } 354 384 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 ) ); 385 $type_sql = apply_filters( 'messages_thread_total_threads_for_user_type_sql', $type_sql, $user_id ); 386 387 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 388 } 357 389 358 390 /** … … 361 393 * @since BuddyPress (1.0.0) 362 394 * 363 395 * @param int $thread_id The message thread ID. 364 * @ parambool396 * @return bool 365 397 */ 366 398 public static function user_is_sender( $thread_id ) { 367 399 global $wpdb, $bp; … … 434 466 if ( empty( $user_id ) ) 435 467 $user_id = bp_loggedin_user_id(); 436 468 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 ));469 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 470 } 439 471 440 472 /** … … 455 487 456 488 $bp = buddypress(); 457 489 458 return $wpdb->get_var( $wpdb->prepare( "SELECT thread_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d LIMIT 1", $thread_id ));490 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 491 } 460 492 461 493 /** … … 468 500 * 469 501 * @since BuddyPress (1.0.0) 470 502 * 471 * @param object $recipients Object containing the message recipients.503 * @param array $recipients Array containing the message recipients (array of objects). 472 504 * @return string 473 505 */ 474 506 public static function get_recipient_links( $recipients ) { 475 if ( count( $recipients ) >= 5 ) 476 return sprintf( __( '%s Recipients', 'buddypress' ), number_format_i18n( count( $recipients ) ) ); 507 if ( count( $recipients ) >= 5 ) { 508 return sprintf(__('%s Recipients', 'buddypress'), number_format_i18n(count($recipients))); 509 } 477 510 478 511 $recipient_links = array(); 479 512 … … 487 520 $recipient_links[] = $recipient_link; 488 521 } 489 522 523 $recipient_links = apply_filters( 'messages_thread_recipient_links', $recipient_links ); 524 490 525 return implode( ', ', (array) $recipient_links ); 491 526 } 492 527 … … 607 642 608 643 if ( $message = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE id = %d", $id ) ) ) { 609 644 $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;645 $this->thread_id = apply_filters( 'messages_message_populate_thread_id', $message->thread_id ); 646 $this->sender_id = apply_filters( 'messages_message_populate_sender_id', $message->sender_id ); 647 $this->subject = apply_filters( 'messages_message_populate_subject', $message->subject ); 648 $this->message = apply_filters( 'messages_message_populate_message', $message->message ); 649 $this->date_sent = apply_filters( 'messages_message_populate_date_sent', $message->date_sent ); 615 650 } 616 651 } 617 652 … … 633 668 do_action_ref_array( 'messages_message_before_save', array( &$this ) ); 634 669 635 670 // Make sure we have at least one recipient before sending. 636 if ( empty( $this->recipients ) ) 671 if ( empty( $this->recipients ) ) { 637 672 return false; 673 } 638 674 639 675 $new_thread = false; 640 676 … … 645 681 } 646 682 647 683 // 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 ) ) ) 684 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 685 return false; 686 } 650 687 651 688 $this->id = $wpdb->insert_id; 652 689 … … 681 718 */ 682 719 public function get_recipients() { 683 720 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 ));721 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 722 } 686 723 687 724 /** Static Functions **************************************************/ … … 693 730 * @return array 694 731 */ 695 732 public static function get_recipient_ids( $recipient_usernames ) { 696 if ( !$recipient_usernames ) 733 if ( !$recipient_usernames ) { 697 734 return false; 735 } 698 736 737 $recipient_ids = array(); 738 699 739 if ( is_array( $recipient_usernames ) ) { 700 740 for ( $i = 0, $count = count( $recipient_usernames ); $i < $count; ++$i ) { 701 741 if ( $rid = bp_core_get_userid( trim($recipient_usernames[$i]) ) ) { … … 704 744 } 705 745 } 706 746 707 return $recipient_ids;747 return apply_filters( 'messages_message_get_recipient_ids', $recipient_ids, $recipient_usernames ); 708 748 } 709 749 710 750 /** … … 715 755 */ 716 756 public static function get_last_sent_for_user( $thread_id ) { 717 757 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 ));758 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 759 } 720 760 721 761 /** … … 790 830 * Constructor. 791 831 * 792 832 * @since BuddyPress (1.0.0) 833 * @param null $id 793 834 */ 794 835 public function __construct( $id = null ) { 795 836 if ( $id ) { … … 811 852 $notice = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id ) ); 812 853 813 854 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;855 $this->subject = apply_filters( 'messages_notice_populate_subject', $notice->subject ); 856 $this->message = apply_filters( 'messages_notice_populate_message', $notice->message ); 857 $this->date_sent = apply_filters( 'messages_notice_populate_date_sent', $notice->date_sent ); 858 $this->is_active = apply_filters( 'messages_notice_populate_is_active', $notice->is_active ); 818 859 } 819 860 } 820 861 … … 865 906 * @return bool 866 907 */ 867 908 public function activate() { 868 $this->is_active = 1;909 $this->is_active = apply_filters( 'messages_notice_activate', 1 ); 869 910 return (bool) $this->save(); 870 911 } 871 912 … … 877 918 * @return bool 878 919 */ 879 920 public function deactivate() { 880 $this->is_active = 0;921 $this->is_active = apply_filters( 'messages_notice_deactivate', 0 ); 881 922 return (bool) $this->save(); 882 923 } 883 924 … … 899 940 return false; 900 941 } 901 942 943 do_action( 'messages_notice_after_delete' ); 944 902 945 return true; 903 946 } 904 947 … … 911 954 * 912 955 * @since BuddyPress (1.0.0) 913 956 * 914 * @param array $ data{957 * @param array $args { 915 958 * Array of parameters. 916 959 * @type int $pag_num Number of notices per page. Defaults to 20. 917 960 * @type int $pag_page The page number. Defaults to 1. … … 926 969 'pag_page' => 1 // Page number 927 970 ) ); 928 971 972 $r = apply_filters( 'messages_notice_get_notices_arg', $r); 973 929 974 $limit_sql = ''; 930 975 if ( (int) $r['pag_num'] >= 0 ) { 931 976 $limit_sql = $wpdb->prepare( "LIMIT %d, %d", (int) ( ( $r['pag_page'] - 1 ) * $r['pag_num'] ), (int) $r['pag_num'] ); … … 948 993 949 994 $notice_count = $wpdb->get_var( "SELECT COUNT(id) FROM " . $bp->messages->table_name_notices ); 950 995 951 return $notice_count;996 return apply_filters( 'messages_notice_total_count', $notice_count ); 952 997 } 953 998 954 999 /** -
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 => '%#%', … … 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(), … … 656 663 * 657 664 * @see bp_get_message_thread_avatar() for a description of arguments. 658 665 * 659 * @param array $args See {@link bp_get_message_thread_avatar()}.666 * @param array|string $args See {@link bp_get_message_thread_avatar()}. 660 667 */ 661 668 function bp_message_thread_avatar( $args = '' ) { 662 669 echo bp_get_message_thread_avatar( $args ); … … 667 674 * @see bp_core_fetch_avatar() For a description of arguments and 668 675 * return values. 669 676 * 670 * @param array $args {677 * @param array|string $args { 671 678 * Arguments are listed here with an explanation of their defaults. 672 679 * For more information about the arguments, see 673 680 * {@link bp_core_fetch_avatar()}. … … 678 685 * @type string|bool $id Default: false. 679 686 * @type string $alt Default: 'Profile picture of [display name]'. 680 687 * } 681 * @return User avatar string.688 * @return string User avatar string. 682 689 */ 683 690 function bp_get_message_thread_avatar( $args = '' ) { 684 691 global $messages_template; … … 745 752 function bp_messages_pagination_count() { 746 753 global $messages_template; 747 754 748 $start_num = intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1;749 $from_num = bp_core_number_format($start_num );750 $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 ));751 $total = bp_core_number_format( $messages_template->total_thread_count);755 $start_num = apply_filters( 'bp_messages_pagination_count_start_num', intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1, $messages_template ); 756 $from_num = apply_filters( 'bp_messages_pagination_count_from_number', bp_core_number_format( $start_num ), $start_num ); 757 $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 ); 758 $total = apply_filters( 'bp_messages_pagination_count_total', bp_core_number_format( $messages_template->total_thread_count ), $messages_template ); 752 759 753 760 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 ) ); 754 761 } … … 763 770 $default_search_value = bp_get_search_default_text( 'messages' ); 764 771 $search_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?> 765 772 773 <!--suppress ALL --> 766 774 <form action="" method="get" id="search-message-form"> 767 775 <label><input type="text" name="s" id="messages_search" <?php if ( $search_value === $default_search_value ) : ?>placeholder="<?php echo esc_html( $search_value ); ?>"<?php endif; ?> <?php if ( $search_value !== $default_search_value ) : ?>value="<?php echo esc_html( $search_value ); ?>"<?php endif; ?> /></label> 768 776 <input type="submit" id="messages_search_submit" name="messages_search_submit" value="<?php esc_attr_e( 'Search', 'buddypress' ) ?>" /> … … 798 806 * @return string 799 807 */ 800 808 function bp_get_messages_username_value() { 809 $user_name = ''; 810 801 811 if ( isset( $_COOKIE['bp_messages_send_to'] ) ) { 802 returnapply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] );812 $user_name = apply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] ); 803 813 } else if ( isset( $_GET['r'] ) && !isset( $_COOKIE['bp_messages_send_to'] ) ) { 804 returnapply_filters( 'bp_get_messages_username_value', $_GET['r'] );814 $user_name = apply_filters( 'bp_get_messages_username_value', $_GET['r'] ); 805 815 } 816 817 return $user_name; 806 818 } 807 819 808 820 /** … … 854 866 * Output the markup for the message type dropdown. 855 867 */ 856 868 function bp_messages_options() { 857 ?>858 869 870 $messages_types = apply_filters( 'bp_messages_options_types', array( 871 'empty' => '', 872 'read' => _x('Read', 'Message dropdown filter', 'buddypress'), 873 'unread' => _x('Unread', 'Message dropdown filter', 'buddypress'), 874 'all' => _x('All', 'Message dropdown filter', 'buddypress') 875 ) ); 876 ?> 877 859 878 <?php _e( 'Select:', 'buddypress' ) ?> 860 879 861 880 <select name="message-type-select" id="message-type-select"> 862 <option value=""></option> 863 <option value="read"><?php _ex('Read', 'Message dropdown filter', 'buddypress') ?></option> 864 <option value="unread"><?php _ex('Unread', 'Message dropdown filter', 'buddypress') ?></option> 865 <option value="all"><?php _ex('All', 'Message dropdown filter', 'buddypress') ?></option> 881 882 <?php foreach($messages_types as $value => $label) : ?> 883 884 <option value="<?php echo $value; ?>"><?php echo $label; ?></option> 885 886 <?php endforeach; ?> 887 866 888 </select> 867 889 890 <?php do_action( 'bp_messages_options_before_actions' ); ?> 891 868 892 <?php if ( ! bp_is_current_action( 'sentbox' ) && ! bp_is_current_action( 'notices' ) ) : ?> 869 893 870 894 <a href="#" id="mark_as_read"><?php _ex('Mark as Read', 'Message management markup', 'buddypress') ?></a> … … 874 898 875 899 <a href="#" id="delete_<?php echo bp_current_action(); ?>_messages"><?php _e( 'Delete Selected', 'buddypress' ); ?></a> 876 900 901 <?php do_action( 'bp_messages_options_after_actions' ); ?> 902 877 903 <?php 878 904 } 879 905 … … 1308 1334 $this->message_count = count( $this->thread->messages ); 1309 1335 1310 1336 $last_message_index = $this->message_count - 1; 1311 $this->thread->last_message_id = $this->thread->messages[ $last_message_index ]->id;1312 $this->thread->last_message_date = $this->thread->messages[ $last_message_index ]->date_sent;1313 $this->thread->last_sender_id = $this->thread->messages[ $last_message_index ]->sender_id;1314 $this->thread->last_message_subject = $this->thread->messages[ $last_message_index ]->subject;1315 $this->thread->last_message_content = $this->thread->messages[ $last_message_index ]->message;1337 $this->thread->last_message_id = apply_filters( 'messages_thread_template_id', $this->thread->messages[ $last_message_index ]->id ); 1338 $this->thread->last_message_date = apply_filters( 'messages_thread_template_date_sent', $this->thread->messages[ $last_message_index ]->date_sent ); 1339 $this->thread->last_sender_id = apply_filters( 'messages_thread_template_sender_id', $this->thread->messages[ $last_message_index ]->sender_id ); 1340 $this->thread->last_message_subject = apply_filters( 'messages_thread_template_subject', $this->thread->messages[ $last_message_index ]->subject ); 1341 $this->thread->last_message_content = apply_filters( 'messages_thread_template_message', $this->thread->messages[ $last_message_index ]->message ); 1316 1342 } 1317 1343 1318 1344 /** … … 1399 1425 /** 1400 1426 * Initialize the messages template loop for a specific thread. 1401 1427 * 1402 * @param array $args {1428 * @param array|string $args { 1403 1429 * Array of arguments. All are optional. 1404 1430 * @type int $thread_id ID of the thread whose messages you are displaying. 1405 1431 * Default: if viewing a thread, the thread ID will be parsed from … … 1411 1437 function bp_thread_has_messages( $args = '' ) { 1412 1438 global $thread_template; 1413 1439 1414 $r = bp_parse_args( $args, array(1440 $r = apply_filters( 'messages_thread_has_messages_args', bp_parse_args( $args, array( 1415 1441 'thread_id' => false, 1416 1442 'order' => 'ASC' 1417 ), 'thread_has_messages' ) ;1443 ), 'thread_has_messages' ) ); 1418 1444 1419 1445 if ( empty( $r['thread_id'] ) && bp_is_messages_component() && bp_is_current_action( 'view' ) ) { 1420 1446 $r['thread_id'] = (int) bp_action_variable( 0 ); … … 1422 1448 1423 1449 $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'] ); 1424 1450 1425 return $thread_template->has_messages();1451 return apply_filters( 'bp_thread_has_messages', $thread_template->has_messages(), $thread_template ); 1426 1452 } 1427 1453 1428 1454 /** … … 1438 1464 */ 1439 1465 function bp_get_thread_messages_order() { 1440 1466 global $thread_template; 1441 return $thread_template->thread->messages_order;1467 return apply_filters( 'bp_get_thread_messages_order', $thread_template->thread->messages_order ); 1442 1468 } 1443 1469 1444 1470 /** … … 1525 1551 */ 1526 1552 function bp_get_thread_recipients_count() { 1527 1553 global $thread_template; 1528 return count( $thread_template->thread->recipients);1554 return apply_filters( 'bp_get_thread_recipients_count', count( $thread_template->thread->recipients ) ); 1529 1555 } 1530 1556 1531 1557 /** … … 1675 1701 /** 1676 1702 * Output the avatar for the current message sender. 1677 1703 * 1678 * @param array $args See {@link bp_get_the_thread_message_sender_avatar_thumb()}1704 * @param array|string $args See {@link bp_get_the_thread_message_sender_avatar_thumb()} 1679 1705 * for a description. 1680 1706 */ 1681 1707 function bp_the_thread_message_sender_avatar( $args = '' ) { … … 1684 1710 /** 1685 1711 * Get the avatar for the current message sender. 1686 1712 * 1687 * @param array $args {1713 * @param array|string $args { 1688 1714 * Array of arguments. See {@link bp_core_fetch_avatar()} for more 1689 1715 * complete details. All arguments are optional. 1690 1716 * @type string $type Avatar type. Default: 'thumb'.