diff --git src/bp-messages/bp-messages-classes.php src/bp-messages/bp-messages-classes.php
index 088fefc..21306d0 100644
|
|
class BP_Messages_Thread { |
285 | 285 | public static function get_current_threads_for_user( $user_id, $box = 'inbox', $type = 'all', $limit = null, $page = null, $search_terms = '' ) { |
286 | 286 | global $wpdb, $bp; |
287 | 287 | |
288 | | $user_id_sql = $pag_sql = $type_sql = $search_sql = ''; |
| 288 | $user_id_sql = $pag_sql = $type_sql = $search_sql = $total_threads = ''; |
| 289 | $thread_ids = array(); |
| 290 | $box = apply_filters( 'messages_thread_current_threads_box', $box ); |
| 291 | $type = apply_filters( 'messages_thread_current_threads_type', $type ); |
| 292 | $search_terms = apply_filters( 'messages_thread_current_threads_search_terms', $search_terms ); |
289 | 293 | |
290 | 294 | if ( $limit && $page ) { |
291 | 295 | $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); |
… |
… |
class BP_Messages_Thread { |
297 | 301 | $type_sql = " AND r.unread_count = 0 "; |
298 | 302 | } |
299 | 303 | |
| 304 | $type_sql = apply_filters( 'messages_thread_current_threads_type_sql', $type_sql ); |
| 305 | |
300 | 306 | if ( ! empty( $search_terms ) ) { |
301 | 307 | $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%'; |
302 | 308 | $search_sql = $wpdb->prepare( "AND ( subject LIKE %s OR message LIKE %s )", $search_terms_like, $search_terms_like ); |
303 | 309 | } |
304 | 310 | |
| 311 | $search_sql = apply_filters( 'messages_thread_current_threads_search_sql', $search_sql ); |
| 312 | |
305 | 313 | if ( 'sentbox' == $box ) { |
306 | | $user_id_sql = $wpdb->prepare( 'm.sender_id = %d', $user_id ); |
307 | | $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}" ); |
| 314 | $user_id_sql = $wpdb->prepare( 'm.sender_id = %d', $user_id ); |
| 315 | $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}" ); |
308 | 316 | $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} " ); |
309 | | } else { |
310 | | $user_id_sql = $wpdb->prepare( 'r.user_id = %d', $user_id ); |
311 | | $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}" ); |
| 317 | } elseif ( 'inbox' == $box ) { |
| 318 | $user_id_sql = $wpdb->prepare( 'r.user_id = %d', $user_id ); |
| 319 | $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}" ); |
312 | 320 | $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}" ); |
313 | 321 | } |
314 | 322 | |
| 323 | $thread_ids = apply_filters( 'messages_thread_current_threads_thread_ids', $thread_ids ); |
| 324 | $total_threads = apply_filters( 'messages_thread_current_threads_total_threads', $total_threads ); |
| 325 | |
315 | 326 | if ( empty( $thread_ids ) ) { |
316 | 327 | return false; |
317 | 328 | } |
… |
… |
class BP_Messages_Thread { |
347 | 358 | * @since BuddyPress (1.0.0) |
348 | 359 | * |
349 | 360 | * @param int $thread_id The message thread ID. |
| 361 | * @return mixed False of failure, interger on success updating |
350 | 362 | */ |
351 | 363 | public static function mark_as_read( $thread_id ) { |
352 | 364 | global $wpdb, $bp; |
353 | 365 | |
354 | | $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 ); |
355 | | $wpdb->query($sql); |
| 366 | $user_id = bp_loggedin_user_id(); |
| 367 | |
| 368 | $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 ); |
| 369 | $result = $wpdb->query($sql); |
| 370 | |
| 371 | do_action( 'messages_thread_marked_as_read', $user_id, $thread_id ); |
| 372 | |
| 373 | wp_cache_delete( $user_id, 'bp_messages_unread_count' ); |
356 | 374 | |
357 | | wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); |
| 375 | return $result; |
358 | 376 | } |
359 | 377 | |
360 | 378 | /** |
… |
… |
class BP_Messages_Thread { |
363 | 381 | * @since BuddyPress (1.0.0) |
364 | 382 | * |
365 | 383 | * @param int $thread_id The message thread ID. |
| 384 | * @return mixed False of failure, interger on success updating |
366 | 385 | */ |
367 | 386 | public static function mark_as_unread( $thread_id ) { |
368 | 387 | global $wpdb, $bp; |
369 | 388 | |
370 | | $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 ); |
371 | | $wpdb->query($sql); |
| 389 | $user_id = bp_loggedin_user_id(); |
372 | 390 | |
373 | | wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); |
| 391 | $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 ); |
| 392 | $result = $wpdb->query($sql); |
| 393 | |
| 394 | do_action( 'messages_thread_marked_as_unread', $user_id, $thread_id ); |
| 395 | |
| 396 | wp_cache_delete( $user_id, 'bp_messages_unread_count' ); |
| 397 | |
| 398 | return $result; |
374 | 399 | } |
375 | 400 | |
376 | 401 | /** |
… |
… |
class BP_Messages_Thread { |
388 | 413 | public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) { |
389 | 414 | global $wpdb, $bp; |
390 | 415 | |
391 | | $exclude_sender = ''; |
392 | | if ( $box != 'sentbox' ) |
393 | | $exclude_sender = ' AND sender_only != 1'; |
| 416 | $exclude_sender_sql = $type_sql = ''; |
| 417 | |
| 418 | if ( $box != 'sentbox' ) { |
| 419 | $exclude_sender_sql = ' AND sender_only != 1'; |
| 420 | } |
| 421 | |
| 422 | $exclude_sender_sql = apply_filters( 'messages_thread_total_threads_for_user_exclude_sender_sql', $exclude_sender_sql, $user_id ); |
394 | 423 | |
395 | | if ( $type == 'unread' ) |
| 424 | if ( $type == 'unread' ) { |
396 | 425 | $type_sql = " AND unread_count != 0 "; |
397 | | else if ( $type == 'read' ) |
| 426 | } else if ( $type == 'read' ) { |
398 | 427 | $type_sql = " AND unread_count = 0 "; |
| 428 | } |
| 429 | |
| 430 | $type_sql = apply_filters( 'messages_thread_total_threads_for_user_type_sql', $type_sql, $user_id ); |
399 | 431 | |
400 | | 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 ) ); |
| 432 | 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 ); |
401 | 433 | } |
402 | 434 | |
403 | 435 | /** |
… |
… |
class BP_Messages_Thread { |
487 | 519 | if ( empty( $user_id ) ) |
488 | 520 | $user_id = bp_loggedin_user_id(); |
489 | 521 | |
490 | | 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 ) ); |
| 522 | 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 ); |
491 | 523 | } |
492 | 524 | |
493 | 525 | /** |
… |
… |
class BP_Messages_Thread { |
508 | 540 | |
509 | 541 | $bp = buddypress(); |
510 | 542 | |
511 | | return $wpdb->get_var( $wpdb->prepare( "SELECT thread_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d LIMIT 1", $thread_id ) ); |
| 543 | 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 ); |
512 | 544 | } |
513 | 545 | |
514 | 546 | /** |
… |
… |
class BP_Messages_Thread { |
525 | 557 | * @return string |
526 | 558 | */ |
527 | 559 | public static function get_recipient_links( $recipients ) { |
528 | | if ( count( $recipients ) >= 5 ) |
529 | | return sprintf( __( '%s Recipients', 'buddypress' ), number_format_i18n( count( $recipients ) ) ); |
| 560 | if ( count( $recipients ) >= 5 ) { |
| 561 | return sprintf(__('%s Recipients', 'buddypress'), number_format_i18n(count($recipients))); |
| 562 | } |
530 | 563 | |
531 | 564 | $recipient_links = array(); |
532 | 565 | |
… |
… |
class BP_Messages_Thread { |
540 | 573 | $recipient_links[] = $recipient_link; |
541 | 574 | } |
542 | 575 | |
| 576 | $recipient_links = apply_filters( 'messages_thread_recipient_links', $recipient_links ); |
| 577 | |
543 | 578 | return implode( ', ', (array) $recipient_links ); |
544 | 579 | } |
545 | 580 | |
… |
… |
class BP_Messages_Message { |
660 | 695 | |
661 | 696 | if ( $message = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE id = %d", $id ) ) ) { |
662 | 697 | $this->id = $message->id; |
663 | | $this->thread_id = $message->thread_id; |
664 | | $this->sender_id = $message->sender_id; |
665 | | $this->subject = $message->subject; |
666 | | $this->message = $message->message; |
667 | | $this->date_sent = $message->date_sent; |
| 698 | $this->thread_id = apply_filters( 'messages_message_populate_thread_id', $message->thread_id ); |
| 699 | $this->sender_id = apply_filters( 'messages_message_populate_sender_id', $message->sender_id ); |
| 700 | $this->subject = apply_filters( 'messages_message_populate_subject', $message->subject ); |
| 701 | $this->message = apply_filters( 'messages_message_populate_message', $message->message ); |
| 702 | $this->date_sent = apply_filters( 'messages_message_populate_date_sent', $message->date_sent ); |
668 | 703 | } |
669 | 704 | } |
670 | 705 | |
… |
… |
class BP_Messages_Message { |
686 | 721 | do_action_ref_array( 'messages_message_before_save', array( &$this ) ); |
687 | 722 | |
688 | 723 | // Make sure we have at least one recipient before sending. |
689 | | if ( empty( $this->recipients ) ) |
| 724 | if ( empty( $this->recipients ) ) { |
690 | 725 | return false; |
| 726 | } |
691 | 727 | |
692 | 728 | $new_thread = false; |
693 | 729 | |
… |
… |
class BP_Messages_Message { |
698 | 734 | } |
699 | 735 | |
700 | 736 | // First insert the message into the messages table |
701 | | 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 ) ) ) |
| 737 | 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 ) ) ) { |
702 | 738 | return false; |
| 739 | } |
703 | 740 | |
704 | 741 | $this->id = $wpdb->insert_id; |
705 | 742 | |
… |
… |
class BP_Messages_Message { |
734 | 771 | */ |
735 | 772 | public function get_recipients() { |
736 | 773 | global $bp, $wpdb; |
737 | | return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) ); |
| 774 | 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 ); |
738 | 775 | } |
739 | 776 | |
740 | 777 | /** Static Functions **************************************************/ |
… |
… |
class BP_Messages_Message { |
746 | 783 | * @return array |
747 | 784 | */ |
748 | 785 | public static function get_recipient_ids( $recipient_usernames ) { |
749 | | if ( !$recipient_usernames ) |
| 786 | if ( !$recipient_usernames ) { |
750 | 787 | return false; |
| 788 | } |
| 789 | |
| 790 | $recipient_ids = array(); |
751 | 791 | |
752 | 792 | if ( is_array( $recipient_usernames ) ) { |
753 | 793 | for ( $i = 0, $count = count( $recipient_usernames ); $i < $count; ++$i ) { |
… |
… |
class BP_Messages_Message { |
757 | 797 | } |
758 | 798 | } |
759 | 799 | |
760 | | return $recipient_ids; |
| 800 | return apply_filters( 'messages_message_get_recipient_ids', $recipient_ids, $recipient_usernames ); |
761 | 801 | } |
762 | 802 | |
763 | 803 | /** |
… |
… |
class BP_Messages_Message { |
768 | 808 | */ |
769 | 809 | public static function get_last_sent_for_user( $thread_id ) { |
770 | 810 | global $wpdb, $bp; |
771 | | 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 ) ); |
| 811 | 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 ); |
772 | 812 | } |
773 | 813 | |
774 | 814 | /** |
… |
… |
class BP_Messages_Message { |
781 | 821 | */ |
782 | 822 | public static function is_user_sender( $user_id, $message_id ) { |
783 | 823 | global $wpdb, $bp; |
784 | | 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 ) ); |
| 824 | 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 ); |
785 | 825 | } |
786 | 826 | |
787 | 827 | /** |
… |
… |
class BP_Messages_Message { |
792 | 832 | */ |
793 | 833 | public static function get_message_sender( $message_id ) { |
794 | 834 | global $wpdb, $bp; |
795 | | return $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE id = %d", $message_id ) ); |
| 835 | 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 ); |
796 | 836 | } |
797 | 837 | } |
798 | 838 | |
… |
… |
class BP_Messages_Notice { |
865 | 905 | $notice = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id ) ); |
866 | 906 | |
867 | 907 | if ( $notice ) { |
868 | | $this->subject = $notice->subject; |
869 | | $this->message = $notice->message; |
870 | | $this->date_sent = $notice->date_sent; |
871 | | $this->is_active = $notice->is_active; |
| 908 | $this->subject = apply_filters( 'messages_notice_populate_subject', $notice->subject ); |
| 909 | $this->message = apply_filters( 'messages_notice_populate_message', $notice->message ); |
| 910 | $this->date_sent = apply_filters( 'messages_notice_populate_date_sent', $notice->date_sent ); |
| 911 | $this->is_active = apply_filters( 'messages_notice_populate_is_active', $notice->is_active ); |
872 | 912 | } |
873 | 913 | } |
874 | 914 | |
… |
… |
class BP_Messages_Notice { |
919 | 959 | * @return bool |
920 | 960 | */ |
921 | 961 | public function activate() { |
922 | | $this->is_active = 1; |
| 962 | $this->is_active = apply_filters( 'messages_notice_activate', 1 ); |
923 | 963 | return (bool) $this->save(); |
924 | 964 | } |
925 | 965 | |
… |
… |
class BP_Messages_Notice { |
931 | 971 | * @return bool |
932 | 972 | */ |
933 | 973 | public function deactivate() { |
934 | | $this->is_active = 0; |
| 974 | $this->is_active = apply_filters( 'messages_notice_deactivate', 0 ); |
935 | 975 | return (bool) $this->save(); |
936 | 976 | } |
937 | 977 | |
… |
… |
class BP_Messages_Notice { |
953 | 993 | return false; |
954 | 994 | } |
955 | 995 | |
| 996 | do_action( 'messages_notice_after_delete' ); |
| 997 | |
956 | 998 | return true; |
957 | 999 | } |
958 | 1000 | |
… |
… |
class BP_Messages_Notice { |
980 | 1022 | 'pag_page' => 1 // Page number |
981 | 1023 | ) ); |
982 | 1024 | |
| 1025 | $r = apply_filters( 'messages_notice_get_notices_arg', $r); |
| 1026 | |
983 | 1027 | $limit_sql = ''; |
984 | 1028 | if ( (int) $r['pag_num'] >= 0 ) { |
985 | 1029 | $limit_sql = $wpdb->prepare( "LIMIT %d, %d", (int) ( ( $r['pag_page'] - 1 ) * $r['pag_num'] ), (int) $r['pag_num'] ); |
… |
… |
class BP_Messages_Notice { |
1002 | 1046 | |
1003 | 1047 | $notice_count = $wpdb->get_var( "SELECT COUNT(id) FROM " . $bp->messages->table_name_notices ); |
1004 | 1048 | |
1005 | | return $notice_count; |
| 1049 | return apply_filters( 'messages_notice_total_count', $notice_count ); |
1006 | 1050 | } |
1007 | 1051 | |
1008 | 1052 | /** |
diff --git src/bp-messages/bp-messages-functions.php src/bp-messages/bp-messages-functions.php
index 3709533..8af9ca4 100644
|
|
function messages_check_thread_access( $thread_id, $user_id = 0 ) { |
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 ); |
… |
… |
function messages_mark_thread_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 ); |
diff --git src/bp-messages/bp-messages-template.php src/bp-messages/bp-messages-template.php
index d71e9a1..2b9f6ff 100644
|
|
class BP_Messages_Box_Template { |
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']; |
… |
… |
class BP_Messages_Box_Template { |
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 => '%#%', |
… |
… |
class BP_Messages_Box_Template { |
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. |
… |
… |
function bp_has_message_threads( $args = '' ) { |
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(), |
… |
… |
function bp_message_thread_unread_count() { |
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 ); |
… |
… |
function bp_message_thread_total_count( $thread_id = false ) { |
716 | 723 | * |
717 | 724 | * @since BuddyPress (2.2.0) |
718 | 725 | * |
719 | | * @param int $thread_id Optional. ID of the thread. Defaults to |
| 726 | * @param int|bool $thread_id Optional. ID of the thread. Defaults to |
720 | 727 | * current thread ID. |
721 | 728 | * @return int |
722 | 729 | */ |
… |
… |
function bp_message_thread_total_count( $thread_id = false ) { |
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 ); |
… |
… |
function bp_message_thread_total_and_unread_count( $thread_id = false ) { |
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 ) { |
… |
… |
function bp_message_thread_last_post_date() { |
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 ); |
… |
… |
function bp_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()}. |
… |
… |
function bp_message_thread_avatar( $args = '' ) { |
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; |
… |
… |
function bp_messages_pagination() { |
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 | } |
… |
… |
function bp_messages_username_value() { |
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 | | return apply_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 | | return apply_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 | /** |
… |
… |
function bp_messages_content_value() { |
1001 | 1012 | * Output the markup for the message type dropdown. |
1002 | 1013 | */ |
1003 | 1014 | function bp_messages_options() { |
1004 | | ?> |
| 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 | ?> |
1005 | 1023 | |
1006 | 1024 | <label for="message-type-select" class="bp-screen-reader-text"> |
1007 | 1025 | <?php _e( 'Select:', 'buddypress' ) ?> |
1008 | | </label> |
| 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> |
… |
… |
function bp_messages_options() { |
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 | |
… |
… |
function bp_message_get_notices() { |
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 ); |
… |
… |
class BP_Messages_Thread_Template { |
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 | /** |
… |
… |
class BP_Messages_Thread_Template { |
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 |
… |
… |
function bp_thread_has_messages( $args = '' ) { |
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 | /** |
… |
… |
function bp_thread_messages_order() { |
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 | /** |
… |
… |
function bp_get_the_thread_recipients(){ |
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 | /** |
… |
… |
function bp_the_thread_message_sender_id() { |
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 = '' ) { |
… |
… |
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'. |