[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-messages/ -> bp-messages-template.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Messages Template Tags.
   4   *
   5   * @package BuddyPress
   6   * @subpackage MessagesTemplate
   7   * @since 1.5.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Retrieve private message threads for display in inbox/sentbox/notices.
  15   *
  16   * Similar to WordPress's have_posts() function, this function is responsible
  17   * for querying the database and retrieving private messages for display inside
  18   * the theme via individual template parts for a member's inbox/sentbox/notices.
  19   *
  20   * @since 1.0.0
  21   *
  22   * @global BP_Messages_Box_Template $messages_template
  23   *
  24   * @param array|string $args {
  25   *     Array of arguments. All are optional.
  26   *     @type int    $user_id      ID of the user whose threads are being loaded.
  27   *                                Default: ID of the logged-in user.
  28   *     @type string $box          Current "box" view. If not provided here, the current
  29   *                                view will be inferred from the URL.
  30   *     @type int    $per_page     Number of results to return per page. Default: 10.
  31   *     @type int    $max          Max results to return. Default: false.
  32   *     @type string $type         Type of messages to return. Values: 'all', 'read', 'unread'
  33   *                                Default: 'all'
  34   *     @type string $search_terms Terms to which to limit results. Default:
  35   *                                the value of $_REQUEST['s'].
  36   *     @type string $page_arg     URL argument used for the pagination param.
  37   *                                Default: 'mpage'.
  38   *     @type array  $meta_query   Meta query arguments. Only applicable if $box is
  39   *                                not 'notices'. See WP_Meta_Query more details.
  40   * }
  41   * @return bool True if there are threads to display, otherwise false.
  42   */
  43  function bp_has_message_threads( $args = array() ) {
  44      global $messages_template;
  45  
  46      // The default box the user is looking at.
  47      $current_action = bp_current_action();
  48      switch ( $current_action ) {
  49          case 'sentbox' :
  50          case 'notices' :
  51          case 'inbox'   :
  52              $default_box = $current_action;
  53              break;
  54          default :
  55              $default_box = 'inbox';
  56              break;
  57      }
  58  
  59      // User ID
  60      // @todo displayed user for moderators that get this far?
  61      $user_id = bp_displayed_user_id();
  62  
  63      // Search Terms.
  64      $search_terms = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
  65  
  66      // Parse the arguments.
  67      $r = bp_parse_args( $args, array(
  68          'user_id'      => $user_id,
  69          'box'          => $default_box,
  70          'per_page'     => 10,
  71          'max'          => false,
  72          'type'         => 'all',
  73          'search_terms' => $search_terms,
  74          'page_arg'     => 'mpage', // See https://buddypress.trac.wordpress.org/ticket/3679.
  75          'meta_query'   => array()
  76      ), 'has_message_threads' );
  77  
  78      // Load the messages loop global up with messages.
  79      $messages_template = new BP_Messages_Box_Template( $r );
  80  
  81      /**
  82       * Filters if there are any message threads to display in inbox/sentbox/notices.
  83       *
  84       * @since 1.1.0
  85       *
  86       * @param bool                     $value             Whether or not the message has threads.
  87       * @param BP_Messages_Box_Template $messages_template Current message box template object.
  88       * @param array                    $r                 Array of parsed arguments passed into function.
  89       */
  90      return apply_filters( 'bp_has_message_threads', $messages_template->has_threads(), $messages_template, $r );
  91  }
  92  
  93  /**
  94   * Check whether there are more threads to iterate over.
  95   *
  96   * @return bool
  97   */
  98  function bp_message_threads() {
  99      global $messages_template;
 100      return $messages_template->message_threads();
 101  }
 102  
 103  /**
 104   * Set up the current thread inside the loop.
 105   *
 106   * @return object
 107   */
 108  function bp_message_thread() {
 109      global $messages_template;
 110      return $messages_template->the_message_thread();
 111  }
 112  
 113  /**
 114   * Output the ID of the current thread in the loop.
 115   */
 116  function bp_message_thread_id() {
 117      echo bp_get_message_thread_id();
 118  }
 119      /**
 120       * Get the ID of the current thread in the loop.
 121       *
 122       * @return int
 123       */
 124  	function bp_get_message_thread_id() {
 125          global $messages_template;
 126  
 127          /**
 128           * Filters the ID of the current thread in the loop.
 129           *
 130           * @since 1.0.0
 131           *
 132           * @param int $thread_id ID of the current thread in the loop.
 133           */
 134          return apply_filters( 'bp_get_message_thread_id', $messages_template->thread->thread_id );
 135      }
 136  
 137  /**
 138   * Output the subject of the current thread in the loop.
 139   */
 140  function bp_message_thread_subject() {
 141      echo bp_get_message_thread_subject();
 142  }
 143      /**
 144       * Get the subject of the current thread in the loop.
 145       *
 146       * @return string
 147       */
 148  	function bp_get_message_thread_subject() {
 149          global $messages_template;
 150  
 151          /**
 152           * Filters the subject of the current thread in the loop.
 153           *
 154           * @since 1.1.0
 155           *
 156           * @param string $value Subject of the current thread in the loop.
 157           */
 158          return apply_filters( 'bp_get_message_thread_subject', $messages_template->thread->last_message_subject );
 159      }
 160  
 161  /**
 162   * Output an excerpt from the current message in the loop.
 163   */
 164  function bp_message_thread_excerpt() {
 165      echo bp_get_message_thread_excerpt();
 166  }
 167      /**
 168       * Generate an excerpt from the current message in the loop.
 169       *
 170       * @return string
 171       */
 172  	function bp_get_message_thread_excerpt() {
 173          global $messages_template;
 174  
 175          /**
 176           * Filters the excerpt of the current thread in the loop.
 177           *
 178           * @since 1.0.0
 179           *
 180           * @param string $value Excerpt of the current thread in the loop.
 181           */
 182          return apply_filters( 'bp_get_message_thread_excerpt', strip_tags( bp_create_excerpt( $messages_template->thread->last_message_content, 75 ) ) );
 183      }
 184  
 185  /**
 186   * Output the thread's last message content.
 187   *
 188   * When viewing your Inbox, the last message is the most recent message in
 189   * the thread of which you are *not* the author.
 190   *
 191   * When viewing your Sentbox, last message is the most recent message in
 192   * the thread of which you *are* the member.
 193   *
 194   * @since 2.0.0
 195   */
 196  function bp_message_thread_content() {
 197      echo bp_get_message_thread_content();
 198  }
 199      /**
 200       * Return the thread's last message content.
 201       *
 202       * When viewing your Inbox, the last message is the most recent message in
 203       * the thread of which you are *not* the author.
 204       *
 205       * When viewing your Sentbox, last message is the most recent message in
 206       * the thread of which you *are* the member.
 207       *
 208       * @since 2.0.0
 209       *
 210       * @return string The raw content of the last message in the thread.
 211       */
 212  	function bp_get_message_thread_content() {
 213          global $messages_template;
 214  
 215          /**
 216           * Filters the content of the last message in the thread.
 217           *
 218           * @since 2.0.0
 219           *
 220           * @param string $last_message_content Content of the last message in the thread.
 221           */
 222          return apply_filters( 'bp_get_message_thread_content', $messages_template->thread->last_message_content );
 223      }
 224  
 225  /**
 226   * Output a link to the page of the current thread's last author.
 227   */
 228  function bp_message_thread_from() {
 229      echo bp_get_message_thread_from();
 230  }
 231      /**
 232       * Get a link to the page of the current thread's last author.
 233       *
 234       * @return string
 235       */
 236  	function bp_get_message_thread_from() {
 237          global $messages_template;
 238  
 239          /**
 240           * Filters the link to the page of the current thread's last author.
 241           *
 242           * @since 1.0.0
 243           *
 244           * @param string $value Link to the page of the current thread's last author.
 245           */
 246          return apply_filters( 'bp_get_message_thread_from', bp_core_get_userlink( $messages_template->thread->last_sender_id ) );
 247      }
 248  
 249  /**
 250   * Output links to the pages of the current thread's recipients.
 251   */
 252  function bp_message_thread_to() {
 253      echo bp_get_message_thread_to();
 254  }
 255      /**
 256       * Generate HTML links to the pages of the current thread's recipients.
 257       *
 258       * @return string
 259       */
 260  	function bp_get_message_thread_to() {
 261          global $messages_template;
 262  
 263          /**
 264           * Filters the HTML links to the pages of the current thread's recipients.
 265           *
 266           * @since 1.0.0
 267           *
 268           * @param string $value HTML links to the pages of the current thread's recipients.
 269           */
 270          return apply_filters( 'bp_message_thread_to', BP_Messages_Thread::get_recipient_links($messages_template->thread->recipients ) );
 271      }
 272  
 273  /**
 274   * Output the permalink for a particular thread.
 275   *
 276   * @since 2.9.0 Introduced `$user_id` parameter.
 277   *
 278   * @param int $thread_id Optional. ID of the thread. Default: current thread
 279   *                       being iterated on in the loop.
 280   * @param int $user_id   Optional. ID of the user relative to whom the link
 281   *                       should be generated. Default: ID of logged-in user.
 282   */
 283  function bp_message_thread_view_link( $thread_id = 0, $user_id = null ) {
 284      echo bp_get_message_thread_view_link( $thread_id, $user_id );
 285  }
 286      /**
 287       * Get the permalink of a particular thread.
 288       *
 289       * @since 2.9.0 Introduced `$user_id` parameter.
 290       *
 291       * @param int $thread_id Optional. ID of the thread. Default: current
 292       *                       thread being iterated on in the loop.
 293       * @param int $user_id   Optional. ID of the user relative to whom the link
 294       *                       should be generated. Default: ID of logged-in user.
 295       * @return string
 296       */
 297  	function bp_get_message_thread_view_link( $thread_id = 0, $user_id = null ) {
 298          global $messages_template;
 299  
 300          if ( empty( $messages_template ) && (int) $thread_id > 0 ) {
 301              $thread_id = (int) $thread_id;
 302          } elseif ( ! empty( $messages_template->thread->thread_id ) ) {
 303              $thread_id = $messages_template->thread->thread_id;
 304          }
 305  
 306          if ( null === $user_id ) {
 307              $user_id = bp_loggedin_user_id();
 308          }
 309  
 310          $domain = bp_core_get_user_domain( $user_id );
 311  
 312          /**
 313           * Filters the permalink of a particular thread.
 314           *
 315           * @since 1.0.0
 316           * @since 2.6.0 Added the `$thread_id` parameter.
 317           * @since 2.9.0 Added the `$user_id` parameter.
 318           *
 319           * @param string $value     Permalink of a particular thread.
 320           * @param int    $thread_id ID of the thread.
 321           * @param int    $user_id   ID of the user.
 322           */
 323          return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( $domain . bp_get_messages_slug() . '/view/' . $thread_id ), $thread_id, $user_id );
 324      }
 325  
 326  /**
 327   * Output the URL for deleting the current thread.
 328   *
 329   * @since 2.9.0 Introduced `$user_id` parameter.
 330   *
 331   * @param int $user_id Optional. ID of the user relative to whom the link
 332   *                     should be generated. Default: ID of logged-in user.
 333   */
 334  function bp_message_thread_delete_link( $user_id = null ) {
 335      echo esc_url( bp_get_message_thread_delete_link( $user_id ) );
 336  }
 337      /**
 338       * Generate the URL for deleting the current thread.
 339       *
 340       * @since 2.9.0 Introduced `$user_id` parameter.
 341       *
 342       * @param int $user_id Optional. ID of the user relative to whom the link
 343       *                     should be generated. Default: ID of logged-in user.
 344       * @return string
 345       */
 346  	function bp_get_message_thread_delete_link( $user_id = null ) {
 347          global $messages_template;
 348  
 349          if ( null === $user_id ) {
 350              $user_id = bp_loggedin_user_id();
 351          }
 352  
 353          $domain = bp_core_get_user_domain( $user_id );
 354  
 355          /**
 356           * Filters the URL for deleting the current thread.
 357           *
 358           * @since 1.0.0
 359           *
 360           * @param string $value   URL for deleting the current thread.
 361           * @param int    $user_id ID of the user relative to whom the link should be generated.
 362           */
 363          return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ), $user_id );
 364      }
 365  
 366  /**
 367   * Output the URL used for marking a single message thread as unread.
 368   *
 369   * Since this function directly outputs a URL, it is escaped.
 370   *
 371   * @since 2.2.0
 372   * @since 2.9.0 Introduced `$user_id` parameter.
 373   *
 374   * @param int $user_id Optional. ID of the user relative to whom the link
 375   *                     should be generated. Default: ID of logged-in user.
 376   */
 377  function bp_the_message_thread_mark_unread_url( $user_id = null ) {
 378      echo esc_url( bp_get_the_message_thread_mark_unread_url( $user_id ) );
 379  }
 380      /**
 381       * Return the URL used for marking a single message thread as unread.
 382       *
 383       * @since 2.2.0
 384       * @since 2.9.0 Introduced `$user_id` parameter.
 385       *
 386       * @param int $user_id Optional. ID of the user relative to whom the link
 387       *                     should be generated. Default: ID of logged-in user.
 388       * @return string
 389       */
 390  	function bp_get_the_message_thread_mark_unread_url( $user_id = null ) {
 391  
 392          // Get the message ID.
 393          $id = bp_get_message_thread_id();
 394  
 395          // Get the args to add to the URL.
 396          $args = array(
 397              'action'     => 'unread',
 398              'message_id' => $id
 399          );
 400  
 401          if ( null === $user_id ) {
 402              $user_id = bp_loggedin_user_id();
 403          }
 404  
 405          $domain = bp_core_get_user_domain( $user_id );
 406  
 407          // Base unread URL.
 408          $url = trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
 409  
 410          // Add the args to the URL.
 411          $url = add_query_arg( $args, $url );
 412  
 413          // Add the nonce.
 414          $url = wp_nonce_url( $url, 'bp_message_thread_mark_unread_' . $id );
 415  
 416          /**
 417           * Filters the URL used for marking a single message thread as unread.
 418           *
 419           * @since 2.2.0
 420           * @since 2.9.0 Added `$user_id` parameter.
 421           *
 422           * @param string $url     URL used for marking a single message thread as unread.
 423           * @param int    $user_id ID of the user relative to whom the link should be generated.
 424           */
 425          return apply_filters( 'bp_get_the_message_thread_mark_unread_url', $url, $user_id );
 426      }
 427  
 428  /**
 429   * Output the URL used for marking a single message thread as read.
 430   *
 431   * Since this function directly outputs a URL, it is escaped.
 432   *
 433   * @since 2.2.0
 434   * @since 2.9.0 Introduced `$user_id` parameter.
 435   *
 436   * @param int $user_id Optional. ID of the user relative to whom the link
 437   *                     should be generated. Default: ID of logged-in user.
 438   */
 439  function bp_the_message_thread_mark_read_url( $user_id = null ) {
 440      echo esc_url( bp_get_the_message_thread_mark_read_url( $user_id ) );
 441  }
 442      /**
 443       * Return the URL used for marking a single message thread as read.
 444       *
 445       * @since 2.2.0
 446       * @since 2.9.0 Introduced `$user_id` parameter.
 447       *
 448       * @param int $user_id Optional. ID of the user relative to whom the link
 449       *                     should be generated. Default: ID of logged-in user.
 450       * @return string
 451       */
 452  	function bp_get_the_message_thread_mark_read_url( $user_id = null ) {
 453  
 454          // Get the message ID.
 455          $id = bp_get_message_thread_id();
 456  
 457          // Get the args to add to the URL.
 458          $args = array(
 459              'action'     => 'read',
 460              'message_id' => $id
 461          );
 462  
 463          if ( null === $user_id ) {
 464              $user_id = bp_loggedin_user_id();
 465          }
 466  
 467          $domain = bp_core_get_user_domain( $user_id );
 468  
 469          // Base read URL.
 470          $url = trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
 471  
 472          // Add the args to the URL.
 473          $url = add_query_arg( $args, $url );
 474  
 475          // Add the nonce.
 476          $url = wp_nonce_url( $url, 'bp_message_thread_mark_read_' . $id );
 477  
 478          /**
 479           * Filters the URL used for marking a single message thread as read.
 480           *
 481           * @since 2.2.0
 482           *
 483           * @param string $url     URL used for marking a single message thread as read.
 484           * @param int    $user_id ID of the user relative to whom the link should be generated.
 485           */
 486          return apply_filters( 'bp_get_the_message_thread_mark_read_url', $url );
 487      }
 488  
 489  /**
 490   * Output the CSS class for the current thread.
 491   */
 492  function bp_message_css_class() {
 493      echo esc_attr( bp_get_message_css_class() );
 494  }
 495      /**
 496       * Generate the CSS class for the current thread.
 497       *
 498       * @return string
 499       */
 500  	function bp_get_message_css_class() {
 501          global $messages_template;
 502  
 503          $class = false;
 504  
 505          if ( $messages_template->current_thread % 2 == 1 ) {
 506              $class .= 'alt';
 507          }
 508  
 509          /**
 510           * Filters the CSS class for the current thread.
 511           *
 512           * @since 1.2.10
 513           *
 514           * @param string $class Class string to be added to the list of classes.
 515           */
 516          return apply_filters( 'bp_get_message_css_class', trim( $class ) );
 517      }
 518  
 519  /**
 520   * Check whether the current thread has unread items.
 521   *
 522   * @return bool True if there are unread items, otherwise false.
 523   */
 524  function bp_message_thread_has_unread() {
 525      global $messages_template;
 526  
 527      $retval = ! empty( $messages_template->thread->unread_count )
 528          ? true
 529          : false;
 530  
 531      /**
 532       * Filters whether or not a message thread has unread items.
 533       *
 534       * @since 2.1.0
 535       *
 536       * @param bool $retval Whether or not a message thread has unread items.
 537       */
 538      return apply_filters( 'bp_message_thread_has_unread', $retval );
 539  }
 540  
 541  /**
 542   * Output the current thread's unread count.
 543   */
 544  function bp_message_thread_unread_count() {
 545      echo esc_html( bp_get_message_thread_unread_count() );
 546  }
 547      /**
 548       * Get the current thread's unread count.
 549       *
 550       * @return int
 551       */
 552  	function bp_get_message_thread_unread_count() {
 553          global $messages_template;
 554  
 555          $count = ! empty( $messages_template->thread->unread_count )
 556              ? (int) $messages_template->thread->unread_count
 557              : false;
 558  
 559          /**
 560           * Filters the current thread's unread count.
 561           *
 562           * @since 1.0.0
 563           *
 564           * @param int $count Current thread unread count.
 565           */
 566          return apply_filters( 'bp_get_message_thread_unread_count', $count );
 567      }
 568  
 569  /**
 570   * Output a thread's total message count.
 571   *
 572   * @since 2.2.0
 573   *
 574   * @param int|bool $thread_id Optional. ID of the thread. Defaults to current thread ID.
 575   */
 576  function bp_message_thread_total_count( $thread_id = false ) {
 577      echo bp_get_message_thread_total_count( $thread_id );
 578  }
 579      /**
 580       * Get the current thread's total message count.
 581       *
 582       * @since 2.2.0
 583       *
 584       * @param int|bool $thread_id Optional. ID of the thread.
 585       *                            Defaults to current thread ID.
 586       * @return int
 587       */
 588  	function bp_get_message_thread_total_count( $thread_id = false ) {
 589          if ( false === $thread_id ) {
 590              $thread_id = bp_get_message_thread_id();
 591          }
 592  
 593          $thread_template = new BP_Messages_Thread_Template( $thread_id, 'ASC', array(
 594              'update_meta_cache' => false
 595          ) );
 596  
 597          $count = 0;
 598          if ( ! empty( $thread_template->message_count ) ) {
 599              $count = intval( $thread_template->message_count );
 600          }
 601  
 602          /**
 603           * Filters the current thread's total message count.
 604           *
 605           * @since 2.2.0
 606           * @since 2.6.0 Added the `$thread_id` parameter.
 607           *
 608           * @param int $count     Current thread total message count.
 609           * @param int $thread_id ID of the queried thread.
 610           */
 611          return apply_filters( 'bp_get_message_thread_total_count', $count, $thread_id );
 612      }
 613  
 614  /**
 615   * Output markup for the current thread's total and unread count.
 616   *
 617   * @since 2.2.0
 618   *
 619   * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID.
 620   */
 621  function bp_message_thread_total_and_unread_count( $thread_id = false ) {
 622      echo bp_get_message_thread_total_and_unread_count( $thread_id );
 623  }
 624      /**
 625       * Get markup for the current thread's total and unread count.
 626       *
 627       * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID.
 628       * @return string Markup displaying the total and unread count for the thread.
 629       */
 630  	function bp_get_message_thread_total_and_unread_count( $thread_id = false ) {
 631          if ( false === $thread_id ) {
 632              $thread_id = bp_get_message_thread_id();
 633          }
 634  
 635          $total  = bp_get_message_thread_total_count( $thread_id );
 636          $unread = bp_get_message_thread_unread_count( $thread_id );
 637  
 638          return sprintf(
 639              /* translators: 1: total number, 2: accessibility text: number of unread messages */
 640              '<span class="thread-count">(%1$s)</span> <span class="bp-screen-reader-text">%2$s</span>',
 641              number_format_i18n( $total ),
 642              sprintf( _n( '%d unread', '%d unread', $unread, 'buddypress' ), number_format_i18n( $unread ) )
 643          );
 644      }
 645  
 646  /**
 647   * Output the unformatted date of the last post in the current thread.
 648   */
 649  function bp_message_thread_last_post_date_raw() {
 650      echo bp_get_message_thread_last_post_date_raw();
 651  }
 652      /**
 653       * Get the unformatted date of the last post in the current thread.
 654       *
 655       * @return string
 656       */
 657  	function bp_get_message_thread_last_post_date_raw() {
 658          global $messages_template;
 659  
 660          /**
 661           * Filters the unformatted date of the last post in the current thread.
 662           *
 663           * @since 2.1.0
 664           *
 665           * @param string $last_message_date Unformatted date of the last post in the current thread.
 666           */
 667          return apply_filters( 'bp_get_message_thread_last_message_date', $messages_template->thread->last_message_date );
 668      }
 669  
 670  /**
 671   * Output the nicely formatted date of the last post in the current thread.
 672   */
 673  function bp_message_thread_last_post_date() {
 674      echo bp_get_message_thread_last_post_date();
 675  }
 676      /**
 677       * Get the nicely formatted date of the last post in the current thread.
 678       *
 679       * @return string
 680       */
 681  	function bp_get_message_thread_last_post_date() {
 682  
 683          /**
 684           * Filters the nicely formatted date of the last post in the current thread.
 685           *
 686           * @since 2.1.0
 687           *
 688           * @param string $value Formatted date of the last post in the current thread.
 689           */
 690          return apply_filters( 'bp_get_message_thread_last_post_date', bp_format_time( strtotime( bp_get_message_thread_last_post_date_raw() ) ) );
 691      }
 692  
 693  /**
 694   * Output the avatar for the last sender in the current message thread.
 695   *
 696   * @see bp_get_message_thread_avatar() for a description of arguments.
 697   *
 698   * @param array|string $args See {@link bp_get_message_thread_avatar()}.
 699   */
 700  function bp_message_thread_avatar( $args = '' ) {
 701      echo bp_get_message_thread_avatar( $args );
 702  }
 703      /**
 704       * Return the avatar for the last sender in the current message thread.
 705       *
 706       * @see bp_core_fetch_avatar() For a description of arguments and
 707       *      return values.
 708       *
 709       * @param array|string $args {
 710       *     Arguments are listed here with an explanation of their defaults.
 711       *     For more information about the arguments, see
 712       *     {@link bp_core_fetch_avatar()}.
 713       *     @type string      $type   Default: 'thumb'.
 714       *     @type int|bool    $width  Default: false.
 715       *     @type int|bool    $height Default: false.
 716       *     @type string      $class  Default: 'avatar'.
 717       *     @type string|bool $id     Default: false.
 718       *     @type string      $alt    Default: 'Profile picture of [display name]'.
 719       * }
 720       * @return string User avatar string.
 721       */
 722  	function bp_get_message_thread_avatar( $args = '' ) {
 723          global $messages_template;
 724  
 725          $fullname = bp_core_get_user_displayname( $messages_template->thread->last_sender_id );
 726          $alt      = sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname );
 727  
 728          $r = bp_parse_args( $args, array(
 729              'type'   => 'thumb',
 730              'width'  => false,
 731              'height' => false,
 732              'class'  => 'avatar',
 733              'id'     => false,
 734              'alt'    => $alt
 735          ) );
 736  
 737          /**
 738           * Filters the avatar for the last sender in the current message thread.
 739           *
 740           * @since 1.0.0
 741           * @since 2.6.0 Added the `$r` parameter.
 742           *
 743           * @param string $value User avatar string.
 744           * @param array  $r     Array of parsed arguments.
 745           */
 746          return apply_filters( 'bp_get_message_thread_avatar', bp_core_fetch_avatar( array(
 747              'item_id' => $messages_template->thread->last_sender_id,
 748              'type'    => $r['type'],
 749              'alt'     => $r['alt'],
 750              'css_id'  => $r['id'],
 751              'class'   => $r['class'],
 752              'width'   => $r['width'],
 753              'height'  => $r['height'],
 754          ) ), $r );
 755      }
 756  
 757  /**
 758   * Output the unread messages count for the current inbox.
 759   *
 760   * @since 2.6.x Added $user_id argument.
 761   *
 762   * @param int $user_id The user ID.
 763   *
 764   * @return int $unread_count Total inbox unread count for user.
 765   */
 766  function bp_total_unread_messages_count( $user_id = 0 ) {
 767      echo bp_get_total_unread_messages_count( $user_id );
 768  }
 769      /**
 770       * Get the unread messages count for the current inbox.
 771       *
 772       * @since 2.6.x Added $user_id argument.
 773       *
 774       * @param int $user_id The user ID.
 775       *
 776       * @return int $unread_count Total inbox unread count for user.
 777       */
 778  	function bp_get_total_unread_messages_count( $user_id = 0 ) {
 779  
 780          /**
 781           * Filters the unread messages count for the current inbox.
 782           *
 783           * @since 1.0.0
 784           *
 785           * @param int $value Unread messages count for the current inbox.
 786           */
 787          return apply_filters( 'bp_get_total_unread_messages_count', BP_Messages_Thread::get_inbox_count( $user_id ) );
 788      }
 789  
 790  /**
 791   * Output the pagination HTML for the current thread loop.
 792   */
 793  function bp_messages_pagination() {
 794      echo bp_get_messages_pagination();
 795  }
 796      /**
 797       * Get the pagination HTML for the current thread loop.
 798       *
 799       * @return string
 800       */
 801  	function bp_get_messages_pagination() {
 802          global $messages_template;
 803  
 804          /**
 805           * Filters the pagination HTML for the current thread loop.
 806           *
 807           * @since 1.0.0
 808           *
 809           * @param int $pag_links Pagination HTML for the current thread loop.
 810           */
 811          return apply_filters( 'bp_get_messages_pagination', $messages_template->pag_links );
 812      }
 813  
 814  /**
 815   * Generate the "Viewing message x to y (of z messages)" string for a loop.
 816   */
 817  function bp_messages_pagination_count() {
 818      global $messages_template;
 819  
 820      $start_num = intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1;
 821      $from_num  = bp_core_number_format( $start_num );
 822      $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 ) );
 823      $total     = bp_core_number_format( $messages_template->total_thread_count );
 824  
 825      if ( 1 == $messages_template->total_thread_count ) {
 826          $message = __( 'Viewing 1 message', 'buddypress' );
 827      } else {
 828          $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s message', 'Viewing %1$s - %2$s of %3$s messages', $messages_template->total_thread_count, 'buddypress' ), $from_num, $to_num, $total );
 829      }
 830  
 831      echo esc_html( $message );
 832  }
 833  
 834  /**
 835   * Output the Private Message search form.
 836   *
 837   * @todo  Move markup to template part in: /members/single/messages/search.php
 838   * @since 1.6.0
 839   */
 840  function bp_message_search_form() {
 841  
 842      // Get the default search text.
 843      $default_search_value = bp_get_search_default_text( 'messages' );
 844  
 845      // Setup a few values based on what's being searched for.
 846      $search_submitted     = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value;
 847      $search_placeholder   = ( $search_submitted === $default_search_value ) ? ' placeholder="' .  esc_attr( $search_submitted ) . '"' : '';
 848      $search_value         = ( $search_submitted !== $default_search_value ) ? ' value="'       .  esc_attr( $search_submitted ) . '"' : '';
 849  
 850      // Start the output buffer, so form can be filtered.
 851      ob_start(); ?>
 852  
 853      <form action="" method="get" id="search-message-form">
 854          <label for="messages_search" class="bp-screen-reader-text"><?php
 855              /* translators: accessibility text */
 856              esc_html_e( 'Search Messages', 'buddypress' );
 857          ?></label>
 858          <input type="text" name="s" id="messages_search"<?php echo $search_placeholder . $search_value; ?> />
 859          <input type="submit" class="button" id="messages_search_submit" name="messages_search_submit" value="<?php esc_html_e( 'Search', 'buddypress' ); ?>" />
 860      </form>
 861  
 862      <?php
 863  
 864      // Get the search form from the above output buffer.
 865      $search_form_html = ob_get_clean();
 866  
 867      /**
 868       * Filters the private message component search form.
 869       *
 870       * @since 2.2.0
 871       *
 872       * @param string $search_form_html HTML markup for the message search form.
 873       */
 874      echo apply_filters( 'bp_message_search_form', $search_form_html );
 875  }
 876  
 877  /**
 878   * Echo the form action for Messages HTML forms.
 879   */
 880  function bp_messages_form_action() {
 881      echo esc_url( bp_get_messages_form_action() );
 882  }
 883      /**
 884       * Return the form action for Messages HTML forms.
 885       *
 886       * @return string The form action.
 887       */
 888  	function bp_get_messages_form_action() {
 889  
 890          /**
 891           * Filters the form action for Messages HTML forms.
 892           *
 893           * @since 1.0.0
 894           *
 895           * @param string $value The form action.
 896           */
 897          return apply_filters( 'bp_get_messages_form_action', trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' . bp_action_variable( 0 ) ) );
 898      }
 899  
 900  /**
 901   * Output the default username for the recipient box.
 902   */
 903  function bp_messages_username_value() {
 904      echo esc_attr( bp_get_messages_username_value() );
 905  }
 906      /**
 907       * Get the default username for the recipient box.
 908       *
 909       * @return string
 910       */
 911  	function bp_get_messages_username_value() {
 912          if ( isset( $_COOKIE['bp_messages_send_to'] ) ) {
 913  
 914              /**
 915               * Filters the default username for the recipient box.
 916               *
 917               * Value passed into filter is dependent on if the 'bp_messages_send_to'
 918               * cookie or 'r' $_GET parameter is set.
 919               *
 920               * @since 1.0.0
 921               *
 922               * @param string $value Default user name.
 923               */
 924              return apply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] );
 925          } elseif ( isset( $_GET['r'] ) && !isset( $_COOKIE['bp_messages_send_to'] ) ) {
 926              /** This filter is documented in bp-messages-template.php */
 927              return apply_filters( 'bp_get_messages_username_value', $_GET['r'] );
 928          }
 929      }
 930  
 931  /**
 932   * Output the default value for the Subject field.
 933   */
 934  function bp_messages_subject_value() {
 935      echo esc_attr( bp_get_messages_subject_value() );
 936  }
 937      /**
 938       * Get the default value for the Subject field.
 939       *
 940       * Will get a value out of $_POST['subject'] if available (ie after a
 941       * failed submission).
 942       *
 943       * @return string
 944       */
 945  	function bp_get_messages_subject_value() {
 946  
 947          // Sanitized in bp-messages-filters.php.
 948          $subject = ! empty( $_POST['subject'] )
 949              ? $_POST['subject']
 950              : '';
 951  
 952          /**
 953           * Filters the default value for the subject field.
 954           *
 955           * @since 1.0.0
 956           *
 957           * @param string $subject The default value for the subject field.
 958           */
 959          return apply_filters( 'bp_get_messages_subject_value', $subject );
 960      }
 961  
 962  /**
 963   * Output the default value for the Compose content field.
 964   */
 965  function bp_messages_content_value() {
 966      echo esc_textarea( bp_get_messages_content_value() );
 967  }
 968      /**
 969       * Get the default value fo the Compose content field.
 970       *
 971       * Will get a value out of $_POST['content'] if available (ie after a
 972       * failed submission).
 973       *
 974       * @return string
 975       */
 976  	function bp_get_messages_content_value() {
 977  
 978          // Sanitized in bp-messages-filters.php.
 979          $content = ! empty( $_POST['content'] )
 980              ? $_POST['content']
 981              : '';
 982  
 983          /**
 984           * Filters the default value for the content field.
 985           *
 986           * @since 1.0.0
 987           *
 988           * @param string $content The default value for the content field.
 989           */
 990          return apply_filters( 'bp_get_messages_content_value', $content );
 991      }
 992  
 993  /**
 994   * Output the markup for the message type dropdown.
 995   */
 996  function bp_messages_options() {
 997  ?>
 998  
 999      <label for="message-type-select" class="bp-screen-reader-text"><?php
1000          /* translators: accessibility text */
1001          _e( 'Select:', 'buddypress' );
1002      ?></label>
1003      <select name="message-type-select" id="message-type-select">
1004          <option value=""><?php _e( 'Select', 'buddypress' ); ?></option>
1005          <option value="read"><?php _ex('Read', 'Message dropdown filter', 'buddypress') ?></option>
1006          <option value="unread"><?php _ex('Unread', 'Message dropdown filter', 'buddypress') ?></option>
1007          <option value="all"><?php _ex('All', 'Message dropdown filter', 'buddypress') ?></option>
1008      </select> &nbsp;
1009  
1010      <?php if ( ! bp_is_current_action( 'sentbox' ) && ! bp_is_current_action( 'notices' ) ) : ?>
1011  
1012          <a href="#" id="mark_as_read"><?php _ex('Mark as Read', 'Message management markup', 'buddypress') ?></a> &nbsp;
1013          <a href="#" id="mark_as_unread"><?php _ex('Mark as Unread', 'Message management markup', 'buddypress') ?></a> &nbsp;
1014  
1015          <?php wp_nonce_field( 'bp_messages_mark_messages_read', 'mark-messages-read-nonce', false ); ?>
1016          <?php wp_nonce_field( 'bp_messages_mark_messages_unread', 'mark-messages-unread-nonce', false ); ?>
1017  
1018      <?php endif; ?>
1019  
1020      <a href="#" id="delete_<?php echo bp_current_action(); ?>_messages"><?php _e( 'Delete Selected', 'buddypress' ); ?></a> &nbsp;
1021      <?php wp_nonce_field( 'bp_messages_delete_selected', 'delete-selected-nonce', false ); ?>
1022  <?php
1023  }
1024  
1025  /**
1026   * Output the dropdown for bulk management of messages.
1027   *
1028   * @since 2.2.0
1029   */
1030  function bp_messages_bulk_management_dropdown() {
1031      ?>
1032      <label class="bp-screen-reader-text" for="messages-select"><?php
1033          _e( 'Select Bulk Action', 'buddypress' );
1034      ?></label>
1035      <select name="messages_bulk_action" id="messages-select">
1036          <option value="" selected="selected"><?php _e( 'Bulk Actions', 'buddypress' ); ?></option>
1037          <option value="read"><?php _e( 'Mark read', 'buddypress' ); ?></option>
1038          <option value="unread"><?php _e( 'Mark unread', 'buddypress' ); ?></option>
1039          <option value="delete"><?php _e( 'Delete', 'buddypress' ); ?></option>
1040          <?php
1041              /**
1042               * Action to add additional options to the messages bulk management dropdown.
1043               *
1044               * @since 2.3.0
1045               */
1046              do_action( 'bp_messages_bulk_management_dropdown' );
1047          ?>
1048      </select>
1049      <input type="submit" id="messages-bulk-manage" class="button action" value="<?php esc_attr_e( 'Apply', 'buddypress' ); ?>">
1050      <?php
1051  }
1052  
1053  /**
1054   * Return whether or not the notice is currently active.
1055   *
1056   * @since 1.6.0
1057   *
1058   * @return bool
1059   */
1060  function bp_messages_is_active_notice() {
1061      global $messages_template;
1062  
1063      $retval = ! empty( $messages_template->thread->is_active )
1064          ? true
1065          : false;
1066  
1067      /**
1068       * Filters whether or not the notice is currently active.
1069       *
1070       * @since 2.1.0
1071       *
1072       * @param bool $retval Whether or not the notice is currently active.
1073       */
1074      return apply_filters( 'bp_messages_is_active_notice', $retval );
1075  }
1076  
1077  /**
1078   * Output a string for the active notice.
1079   *
1080   * Since 1.6 this function has been deprecated in favor of text in the theme.
1081   *
1082   * @since 1.0.0
1083   * @deprecated 1.6.0
1084   * @return bool
1085   */
1086  function bp_message_is_active_notice() {
1087      echo bp_get_message_is_active_notice();
1088  }
1089      /**
1090       * Returns a string for the active notice.
1091       *
1092       * Since 1.6 this function has been deprecated in favor of text in the
1093       * theme.
1094       *
1095       * @since 1.0.0
1096       * @deprecated 1.6.0
1097       * @return string
1098       */
1099  	function bp_get_message_is_active_notice() {
1100  
1101          $string = bp_messages_is_active_notice()
1102              ? __( 'Currently Active', 'buddypress' )
1103              : '';
1104  
1105          return apply_filters( 'bp_get_message_is_active_notice', $string );
1106      }
1107  
1108  /**
1109   * Output the ID of the current notice in the loop.
1110   */
1111  function bp_message_notice_id() {
1112      echo (int) bp_get_message_notice_id();
1113  }
1114      /**
1115       * Get the ID of the current notice in the loop.
1116       *
1117       * @return int
1118       */
1119  	function bp_get_message_notice_id() {
1120          global $messages_template;
1121  
1122          /**
1123           * Filters the ID of the current notice in the loop.
1124           *
1125           * @since 1.5.0
1126           *
1127           * @param int $id ID of the current notice in the loop.
1128           */
1129          return apply_filters( 'bp_get_message_notice_id', $messages_template->thread->id );
1130      }
1131  
1132  /**
1133   * Output the post date of the current notice in the loop.
1134   */
1135  function bp_message_notice_post_date() {
1136      echo bp_get_message_notice_post_date();
1137  }
1138      /**
1139       * Get the post date of the current notice in the loop.
1140       *
1141       * @return string
1142       */
1143  	function bp_get_message_notice_post_date() {
1144          global $messages_template;
1145  
1146          /**
1147           * Filters the post date of the current notice in the loop.
1148           *
1149           * @since 1.0.0
1150           *
1151           * @param string $value Formatted post date of the current notice in the loop.
1152           */
1153          return apply_filters( 'bp_get_message_notice_post_date', bp_format_time( strtotime( $messages_template->thread->date_sent ) ) );
1154      }
1155  
1156  /**
1157   * Output the subject of the current notice in the loop.
1158   */
1159  function bp_message_notice_subject() {
1160      echo bp_get_message_notice_subject();
1161  }
1162      /**
1163       * Get the subject of the current notice in the loop.
1164       *
1165       * @return string
1166       */
1167  	function bp_get_message_notice_subject() {
1168          global $messages_template;
1169  
1170          /**
1171           * Filters the subject of the current notice in the loop.
1172           *
1173           * @since 1.0.0
1174           *
1175           * @param string $subject Subject of the current notice in the loop.
1176           */
1177          return apply_filters( 'bp_get_message_notice_subject', $messages_template->thread->subject );
1178      }
1179  
1180  /**
1181   * Output the text of the current notice in the loop.
1182   */
1183  function bp_message_notice_text() {
1184      echo bp_get_message_notice_text();
1185  }
1186      /**
1187       * Get the text of the current notice in the loop.
1188       *
1189       * @return string
1190       */
1191  	function bp_get_message_notice_text() {
1192          global $messages_template;
1193  
1194          /**
1195           * Filters the text of the current notice in the loop.
1196           *
1197           * @since 1.0.0
1198           *
1199           * @param string $message Text for the current notice in the loop.
1200           */
1201          return apply_filters( 'bp_get_message_notice_text', $messages_template->thread->message );
1202      }
1203  
1204  /**
1205   * Output the URL for deleting the current notice.
1206   */
1207  function bp_message_notice_delete_link() {
1208      echo esc_url( bp_get_message_notice_delete_link() );
1209  }
1210      /**
1211       * Get the URL for deleting the current notice.
1212       *
1213       * @return string Delete URL.
1214       */
1215  	function bp_get_message_notice_delete_link() {
1216          global $messages_template;
1217  
1218          /**
1219           * Filters the URL for deleting the current notice.
1220           *
1221           * @since 1.0.0
1222           *
1223           * @param string $value URL for deleting the current notice.
1224           * @param string $value Text indicating action being executed.
1225           */
1226          return apply_filters( 'bp_get_message_notice_delete_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/delete/' . $messages_template->thread->id ), 'messages_delete_notice' ) );
1227      }
1228  
1229  /**
1230   * Output the URL for deactivating the current notice.
1231   */
1232  function bp_message_activate_deactivate_link() {
1233      echo esc_url( bp_get_message_activate_deactivate_link() );
1234  }
1235      /**
1236       * Get the URL for deactivating the current notice.
1237       *
1238       * @return string
1239       */
1240  	function bp_get_message_activate_deactivate_link() {
1241          global $messages_template;
1242  
1243          if ( 1 === (int) $messages_template->thread->is_active ) {
1244              $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
1245          } else {
1246              $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
1247          }
1248  
1249          /**
1250           * Filters the URL for deactivating the current notice.
1251           *
1252           * @since 1.0.0
1253           *
1254           * @param string $link URL for deactivating the current notice.
1255           */
1256          return apply_filters( 'bp_get_message_activate_deactivate_link', $link );
1257      }
1258  
1259  /**
1260   * Output the Deactivate/Activate text for the notice action link.
1261   */
1262  function bp_message_activate_deactivate_text() {
1263      echo esc_html( bp_get_message_activate_deactivate_text() );
1264  }
1265      /**
1266       * Generate the text ('Deactivate' or 'Activate') for the notice action link.
1267       *
1268       * @return string
1269       */
1270  	function bp_get_message_activate_deactivate_text() {
1271          global $messages_template;
1272  
1273          if ( 1 === (int) $messages_template->thread->is_active  ) {
1274              $text = __('Deactivate', 'buddypress');
1275          } else {
1276              $text = __('Activate', 'buddypress');
1277          }
1278  
1279          /**
1280           * Filters the "Deactivate" or "Activate" text for notice action links.
1281           *
1282           * @since 1.0.0
1283           *
1284           * @param string $text Text used for notice action links.
1285           */
1286          return apply_filters( 'bp_message_activate_deactivate_text', $text );
1287      }
1288  
1289  /**
1290   * Output the messages component slug.
1291   *
1292   * @since 1.5.0
1293   *
1294   */
1295  function bp_messages_slug() {
1296      echo bp_get_messages_slug();
1297  }
1298      /**
1299       * Return the messages component slug.
1300       *
1301       * @since 1.5.0
1302       *
1303       * @return string
1304       */
1305  	function bp_get_messages_slug() {
1306  
1307          /**
1308           * Filters the messages component slug.
1309           *
1310           * @since 1.5.0
1311           *
1312           * @param string $slug Messages component slug.
1313           */
1314          return apply_filters( 'bp_get_messages_slug', buddypress()->messages->slug );
1315      }
1316  
1317  /**
1318   * Generate markup for currently active notices.
1319   */
1320  function bp_message_get_notices() {
1321      $notice = BP_Messages_Notice::get_active();
1322  
1323      if ( empty( $notice ) ) {
1324          return false;
1325      }
1326  
1327      $closed_notices = bp_get_user_meta( bp_loggedin_user_id(), 'closed_notices', true );
1328  
1329      if ( empty( $closed_notices ) ) {
1330          $closed_notices = array();
1331      }
1332  
1333      if ( is_array( $closed_notices ) ) {
1334          if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) {
1335              ?>
1336              <div id="message" class="info notice" rel="n-<?php echo esc_attr( $notice->id ); ?>">
1337                  <p>
1338                      <strong><?php echo stripslashes( wp_filter_kses( $notice->subject ) ) ?></strong><br />
1339                      <?php echo stripslashes( wp_filter_kses( $notice->message) ) ?>
1340                      <button type="button" id="close-notice" class="bp-tooltip" data-bp-tooltip="<?php esc_attr_e( 'Dismiss this notice', 'buddypress' ) ?>"><span class="bp-screen-reader-text"><?php _e( 'Dismiss this notice', 'buddypress' ) ?></span> <span aria-hidden="true">&Chi;</span></button>
1341                      <?php wp_nonce_field( 'bp_messages_close_notice', 'close-notice-nonce' ); ?>
1342                  </p>
1343              </div>
1344              <?php
1345          }
1346      }
1347  }
1348  
1349  /**
1350   * Output the URL for the Private Message link in member profile headers.
1351   */
1352  function bp_send_private_message_link() {
1353      echo esc_url( bp_get_send_private_message_link() );
1354  }
1355      /**
1356       * Generate the URL for the Private Message link in member profile headers.
1357       *
1358       * @return bool|string False on failure, otherwise the URL.
1359       */
1360  	function bp_get_send_private_message_link() {
1361  
1362          if ( bp_is_my_profile() || ! is_user_logged_in() ) {
1363              return false;
1364          }
1365  
1366          /**
1367           * Filters the URL for the Private Message link in member profile headers.
1368           *
1369           * @since 1.2.10
1370           *
1371           * @param string $value URL for the Private Message link in member profile headers.
1372           */
1373          return apply_filters( 'bp_get_send_private_message_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( bp_displayed_user_id() ) ) );
1374      }
1375  
1376  /**
1377   * Output the 'Private Message' button for member profile headers.
1378   *
1379   * Explicitly named function to avoid confusion with public messages.
1380   *
1381   * @since 1.2.6
1382   *
1383   */
1384  function bp_send_private_message_button() {
1385      echo bp_get_send_message_button();
1386  }
1387  
1388  /**
1389   * Output the 'Private Message' button for member profile headers.
1390   *
1391   * @since 1.2.0
1392   * @since 3.0.0 Added `$args` parameter.
1393   *
1394   * @param array|string $args See {@link bp_get_send_message_button()}.
1395   */
1396  function bp_send_message_button( $args = '' ) {
1397      echo bp_get_send_message_button( $args );
1398  }
1399      /**
1400       * Generate the 'Private Message' button for member profile headers.
1401       *
1402       * @since 1.2.0
1403       * @since 3.0.0 Added `$args` parameter.
1404       *
1405       * @param array|string $args {
1406       *     All arguments are optional. See {@link BP_Button} for complete
1407       *     descriptions.
1408       *     @type string $id                Default: 'private_message'.
1409       *     @type string $component         Default: 'messages'.
1410       *     @type bool   $must_be_logged_in Default: true.
1411       *     @type bool   $block_self        Default: true.
1412       *     @type string $wrapper_id        Default: 'send-private-message'.
1413       *     @type string $link_href         Default: the private message link for
1414       *                                     the current member in the loop.
1415       *     @type string $link_text         Default: 'Private Message'.
1416       *     @type string $link_class        Default: 'send-message'.
1417       * }
1418       * @return string
1419       */
1420  	function bp_get_send_message_button( $args = '' ) {
1421  
1422          $r = bp_parse_args( $args, array(
1423              'id'                => 'private_message',
1424              'component'         => 'messages',
1425              'must_be_logged_in' => true,
1426              'block_self'        => true,
1427              'wrapper_id'        => 'send-private-message',
1428              'link_href'         => bp_get_send_private_message_link(),
1429              'link_text'         => __( 'Private Message', 'buddypress' ),
1430              'link_class'        => 'send-message',
1431          ) );
1432  
1433  
1434          // Note: 'bp_get_send_message_button' is a legacy filter. Use
1435          // 'bp_get_send_message_button_args' instead. See #4536.
1436          return apply_filters( 'bp_get_send_message_button',
1437  
1438              /**
1439               * Filters the "Private Message" button for member profile headers.
1440               *
1441               * @since 1.8.0
1442               *
1443               * @param array $value See {@link BP_Button}.
1444               */
1445              bp_get_button( apply_filters( 'bp_get_send_message_button_args', $r ) )
1446          );
1447      }
1448  
1449  /**
1450   * Output the URL of the Messages AJAX loader gif.
1451   */
1452  function bp_message_loading_image_src() {
1453      echo esc_url( bp_get_message_loading_image_src() );
1454  }
1455      /**
1456       * Get the URL of the Messages AJAX loader gif.
1457       *
1458       * @return string
1459       */
1460  	function bp_get_message_loading_image_src() {
1461  
1462          /**
1463           * Filters the URL of the Messages AJAX loader gif.
1464           *
1465           * @since 1.0.0
1466           *
1467           * @param string $value URL of the Messages AJAX loader gif.
1468           */
1469          return apply_filters( 'bp_get_message_loading_image_src', buddypress()->messages->image_base . '/ajax-loader.gif' );
1470      }
1471  
1472  /**
1473   * Output the markup for the message recipient tabs.
1474   */
1475  function bp_message_get_recipient_tabs() {
1476      $recipients = explode( ' ', bp_get_message_get_recipient_usernames() );
1477  
1478      foreach ( $recipients as $recipient ) {
1479  
1480          $user_id = bp_is_username_compatibility_mode()
1481              ? bp_core_get_userid( $recipient )
1482              : bp_core_get_userid_from_nicename( $recipient );
1483  
1484          if ( ! empty( $user_id ) ) : ?>
1485  
1486              <li id="un-<?php echo esc_attr( $recipient ); ?>" class="friend-tab">
1487                  <span><?php
1488                      echo bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15 ) );
1489                      echo bp_core_get_userlink( $user_id );
1490                  ?></span>
1491              </li>
1492  
1493          <?php endif;
1494      }
1495  }
1496  
1497  /**
1498   * Output recipient usernames for prefilling the 'To' field on the Compose screen.
1499   */
1500  function bp_message_get_recipient_usernames() {
1501      echo esc_attr( bp_get_message_get_recipient_usernames() );
1502  }
1503      /**
1504       * Get the recipient usernames for prefilling the 'To' field on the Compose screen.
1505       *
1506       * @return string
1507       */
1508  	function bp_get_message_get_recipient_usernames() {
1509  
1510          // Sanitized in bp-messages-filters.php.
1511          $recipients = isset( $_GET['r'] )
1512              ? $_GET['r']
1513              : '';
1514  
1515          /**
1516           * Filters the recipients usernames for prefilling the 'To' field on the Compose screen.
1517           *
1518           * @since 1.0.0
1519           *
1520           * @param string $recipients Recipients usernames for 'To' field prefilling.
1521           */
1522          return apply_filters( 'bp_get_message_get_recipient_usernames', $recipients );
1523      }
1524  
1525  /**
1526   * Initialize the messages template loop for a specific thread.
1527   *
1528   * @param array|string $args {
1529   *     Array of arguments. All are optional.
1530   *     @type int    $thread_id         ID of the thread whose messages you are displaying.
1531   *                                     Default: if viewing a thread, the thread ID will be parsed from
1532   *                                     the URL (bp_action_variable( 0 )).
1533   *     @type string $order             'ASC' or 'DESC'. Default: 'ASC'.
1534   *     @type bool   $update_meta_cache Whether to pre-fetch metadata for
1535   *                                     queried message items. Default: true.
1536   * }
1537   * @return bool True if there are messages to display, otherwise false.
1538   */
1539  function bp_thread_has_messages( $args = '' ) {
1540      global $thread_template;
1541  
1542      $r = bp_parse_args( $args, array(
1543          'thread_id'         => false,
1544          'order'             => 'ASC',
1545          'update_meta_cache' => true,
1546      ), 'thread_has_messages' );
1547  
1548      if ( empty( $r['thread_id'] ) && bp_is_messages_component() && bp_is_current_action( 'view' ) ) {
1549          $r['thread_id'] = (int) bp_action_variable( 0 );
1550      }
1551  
1552      // Set up extra args.
1553      $extra_args = $r;
1554      unset( $extra_args['thread_id'], $extra_args['order'] );
1555  
1556      $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'], $extra_args );
1557  
1558      return $thread_template->has_messages();
1559  }
1560  
1561  /**
1562   * Output the 'ASC' or 'DESC' messages order string for this loop.
1563   */
1564  function bp_thread_messages_order() {
1565      echo esc_attr( bp_get_thread_messages_order() );
1566  }
1567      /**
1568       * Get the 'ASC' or 'DESC' messages order string for this loop.
1569       *
1570       * @return string
1571       */
1572  	function bp_get_thread_messages_order() {
1573          global $thread_template;
1574          return $thread_template->thread->messages_order;
1575      }
1576  
1577  /**
1578   * Check whether there are more messages to iterate over.
1579   *
1580   * @return bool
1581   */
1582  function bp_thread_messages() {
1583      global $thread_template;
1584  
1585      return $thread_template->messages();
1586  }
1587  
1588  /**
1589   * Set up the current thread inside the loop.
1590   *
1591   * @return object
1592   */
1593  function bp_thread_the_message() {
1594      global $thread_template;
1595  
1596      return $thread_template->the_message();
1597  }
1598  
1599  /**
1600   * Output the ID of the thread that the current loop belongs to.
1601   */
1602  function bp_the_thread_id() {
1603      echo (int) bp_get_the_thread_id();
1604  }
1605      /**
1606       * Get the ID of the thread that the current loop belongs to.
1607       *
1608       * @return int
1609       */
1610  	function bp_get_the_thread_id() {
1611          global $thread_template;
1612  
1613          /**
1614           * Filters the ID of the thread that the current loop belongs to.
1615           *
1616           * @since 1.1.0
1617           *
1618           * @param int $thread_id ID of the thread.
1619           */
1620          return apply_filters( 'bp_get_the_thread_id', $thread_template->thread->thread_id );
1621      }
1622  
1623  /**
1624   * Output the subject of the thread currently being iterated over.
1625   */
1626  function bp_the_thread_subject() {
1627      echo bp_get_the_thread_subject();
1628  }
1629      /**
1630       * Get the subject of the thread currently being iterated over.
1631       *
1632       * @return string
1633       */
1634  	function bp_get_the_thread_subject() {
1635          global $thread_template;
1636  
1637          /**
1638           * Filters the subject of the thread currently being iterated over.
1639           *
1640           * @since 1.1.0
1641           *
1642           * @return string $last_message_subject Subject of the thread currently being iterated over.
1643           */
1644          return apply_filters( 'bp_get_the_thread_subject', $thread_template->thread->last_message_subject );
1645      }
1646  
1647  /**
1648   * Get a list of thread recipients or a "x recipients" string.
1649   *
1650   * In BuddyPress 2.2.0, this parts of this functionality were moved into the
1651   * members/single/messages/single.php template. This function is no longer used
1652   * by BuddyPress.
1653   *
1654   * @return string
1655   */
1656  function bp_get_the_thread_recipients() {
1657      if ( 5 <= bp_get_thread_recipients_count() ) {
1658          $recipients = sprintf( __( '%s recipients', 'buddypress' ), number_format_i18n( bp_get_thread_recipients_count() ) );
1659      } else {
1660          $recipients = bp_get_thread_recipients_list();
1661      }
1662  
1663      return apply_filters( 'bp_get_the_thread_recipients', $recipients );
1664  }
1665  
1666  /**
1667   * Get the number of recipients in the current thread.
1668   *
1669   * @since 2.2.0
1670   *
1671   * @return int
1672   */
1673  function bp_get_thread_recipients_count() {
1674      global $thread_template;
1675      /**
1676       * Filters the total number of recipients in a thread.
1677       *
1678       * @since 2.8.0
1679       *
1680       * @param int $count Total recipients number.
1681       */
1682      return (int) apply_filters( 'bp_get_thread_recipients_count', count( $thread_template->thread->recipients ) );
1683  }
1684  
1685  /**
1686   * Get the max number of recipients to list in the 'Conversation between...' gloss.
1687   *
1688   * @since 2.3.0
1689   *
1690   * @return int
1691   */
1692  function bp_get_max_thread_recipients_to_list() {
1693      /**
1694       * Filters the max number of recipients to list in the 'Conversation between...' gloss.
1695       *
1696       * @since 2.3.0
1697       *
1698       * @param int $count Recipient count. Default: 5.
1699       */
1700      return (int) apply_filters( 'bp_get_max_thread_recipients_to_list', 5 );
1701  }
1702  
1703  /**
1704   * Output HTML links to recipients in the current thread.
1705   *
1706   * @since 2.2.0
1707   */
1708  function bp_the_thread_recipients_list() {
1709      echo bp_get_thread_recipients_list();
1710  }
1711      /**
1712       * Generate HTML links to the profiles of recipients in the current thread.
1713       *
1714       * @since 2.2.0
1715       *
1716       * @return string
1717       */
1718  	function bp_get_thread_recipients_list() {
1719          global $thread_template;
1720  
1721          $recipient_links = array();
1722  
1723          foreach( (array) $thread_template->thread->recipients as $recipient ) {
1724              if ( (int) $recipient->user_id !== bp_loggedin_user_id() ) {
1725                  $recipient_link = bp_core_get_userlink( $recipient->user_id );
1726  
1727                  if ( empty( $recipient_link ) ) {
1728                      $recipient_link = __( 'Deleted User', 'buddypress' );
1729                  }
1730  
1731                  $recipient_links[] = $recipient_link;
1732              } else {
1733                  $recipient_links[] = __( 'you', 'buddypress' );
1734              }
1735          }
1736  
1737          // Concatenate to natural language string.
1738          $recipient_links = wp_sprintf_l( '%l', $recipient_links );
1739  
1740          /**
1741           * Filters the HTML links to the profiles of recipients in the current thread.
1742           *
1743           * @since 2.2.0
1744           *
1745           * @param string $value Comma-separated list of recipient HTML links for current thread.
1746           */
1747          return apply_filters( 'bp_get_the_thread_recipients_list', $recipient_links );
1748      }
1749  
1750  /**
1751   * Echo the ID of the current message in the thread.
1752   *
1753   * @since 1.9.0
1754   */
1755  function bp_the_thread_message_id() {
1756      echo (int) bp_get_the_thread_message_id();
1757  }
1758      /**
1759       * Get the ID of the current message in the thread.
1760       *
1761       * @since 1.9.0
1762       *
1763       * @return int
1764       */
1765  	function bp_get_the_thread_message_id() {
1766          global $thread_template;
1767  
1768          $thread_message_id = isset( $thread_template->message->id )
1769              ? (int) $thread_template->message->id
1770              : null;
1771  
1772          /**
1773           * Filters the ID of the current message in the thread.
1774           *
1775           * @since 1.9.0
1776           *
1777           * @param int $thread_message_id ID of the current message in the thread.
1778           */
1779          return apply_filters( 'bp_get_the_thread_message_id', $thread_message_id );
1780      }
1781  
1782  /**
1783   * Output the CSS classes for messages within a single thread.
1784   *
1785   * @since 2.1.0
1786   */
1787  function bp_the_thread_message_css_class() {
1788      echo esc_attr( bp_get_the_thread_message_css_class() );
1789  }
1790      /**
1791       * Generate the CSS classes for messages within a single thread.
1792       *
1793       * @since 2.1.0
1794       *
1795       * @return string
1796       */
1797  	function bp_get_the_thread_message_css_class() {
1798          global $thread_template;
1799  
1800          $classes = array();
1801  
1802          // Zebra-striping.
1803          $classes[] = bp_get_the_thread_message_alt_class();
1804  
1805          // ID of the sender.
1806          $classes[] = 'sent-by-' . intval( $thread_template->message->sender_id );
1807  
1808          // Whether the sender is the same as the logged-in user.
1809          if ( bp_loggedin_user_id() == $thread_template->message->sender_id ) {
1810              $classes[] = 'sent-by-me';
1811          }
1812  
1813          /**
1814           * Filters the CSS classes for messages within a single thread.
1815           *
1816           * @since 2.1.0
1817           *
1818           * @param array $classes Array of classes to add to the HTML class attribute.
1819           */
1820          $classes = apply_filters( 'bp_get_the_thread_message_css_class', $classes );
1821  
1822          return implode( ' ', $classes );
1823      }
1824  
1825  /**
1826   * Output the CSS class used for message zebra striping.
1827   */
1828  function bp_the_thread_message_alt_class() {
1829      echo esc_attr( bp_get_the_thread_message_alt_class() );
1830  }
1831      /**
1832       * Get the CSS class used for message zebra striping.
1833       *
1834       * @return string
1835       */
1836  	function bp_get_the_thread_message_alt_class() {
1837          global $thread_template;
1838  
1839          if ( $thread_template->current_message % 2 == 1 ) {
1840              $class = 'even alt';
1841          } else {
1842              $class = 'odd';
1843          }
1844  
1845          /**
1846           * Filters the CSS class used for message zebra striping.
1847           *
1848           * @since 1.1.0
1849           *
1850           * @param string $class Class determined to be next for zebra striping effect.
1851           */
1852          return apply_filters( 'bp_get_the_thread_message_alt_class', $class );
1853      }
1854  
1855  /**
1856   * Output the ID for message sender within a single thread.
1857   *
1858   * @since 2.1.0
1859   */
1860  function bp_the_thread_message_sender_id() {
1861      echo (int) bp_get_the_thread_message_sender_id();
1862  }
1863      /**
1864       * Return the ID for message sender within a single thread.
1865       *
1866       * @since 2.1.0
1867       *
1868       * @return int
1869       */
1870  	function bp_get_the_thread_message_sender_id() {
1871          global $thread_template;
1872  
1873          $user_id = ! empty( $thread_template->message->sender_id )
1874              ? $thread_template->message->sender_id
1875              : 0;
1876  
1877          /**
1878           * Filters the ID for message sender within a single thread.
1879           *
1880           * @since 2.1.0
1881           *
1882           * @param int $user_id ID of the message sender.
1883           */
1884          return (int) apply_filters( 'bp_get_the_thread_message_sender_id', (int) $user_id );
1885      }
1886  
1887  /**
1888   * Output the avatar for the current message sender.
1889   *
1890   * @param array|string $args See {@link bp_get_the_thread_message_sender_avatar_thumb()}
1891   *                           for a description.
1892   */
1893  function bp_the_thread_message_sender_avatar( $args = '' ) {
1894      echo bp_get_the_thread_message_sender_avatar_thumb( $args );
1895  }
1896      /**
1897       * Get the avatar for the current message sender.
1898       *
1899       * @param array|string $args {
1900       *     Array of arguments. See {@link bp_core_fetch_avatar()} for more
1901       *     complete details. All arguments are optional.
1902       *     @type string $type   Avatar type. Default: 'thumb'.
1903       *     @type int    $width  Avatar width. Default: default for your $type.
1904       *     @type int    $height Avatar height. Default: default for your $type.
1905       * }
1906       * @return string <img> tag containing the avatar.
1907       */
1908  	function bp_get_the_thread_message_sender_avatar_thumb( $args = '' ) {
1909          global $thread_template;
1910  
1911          $r = bp_parse_args( $args, array(
1912              'type'   => 'thumb',
1913              'width'  => false,
1914              'height' => false,
1915          ) );
1916  
1917          /**
1918           * Filters the avatar for the current message sender.
1919           *
1920           * @since 1.1.0
1921           * @since 2.6.0 Added the `$r` parameter.
1922           *
1923           * @param string $value <img> tag containing the avatar value.
1924           * @param array  $r     Array of parsed arguments.
1925           */
1926          return apply_filters( 'bp_get_the_thread_message_sender_avatar_thumb', bp_core_fetch_avatar( array(
1927              'item_id' => $thread_template->message->sender_id,
1928              'type'    => $r['type'],
1929              'width'   => $r['width'],
1930              'height'  => $r['height'],
1931              'alt'     => bp_core_get_user_displayname( $thread_template->message->sender_id )
1932          ) ), $r );
1933      }
1934  
1935  /**
1936   * Output a link to the sender of the current message.
1937   *
1938   * @since 1.1.0
1939   */
1940  function bp_the_thread_message_sender_link() {
1941      echo esc_url( bp_get_the_thread_message_sender_link() );
1942  }
1943      /**
1944       * Get a link to the sender of the current message.
1945       *
1946       * @since 1.1.0
1947       *
1948       * @return string
1949       */
1950  	function bp_get_the_thread_message_sender_link() {
1951          global $thread_template;
1952  
1953          /**
1954           * Filters the link to the sender of the current message.
1955           *
1956           * @since 1.1.0
1957           *
1958           * @param string $value Link to the sender of the current message.
1959           */
1960          return apply_filters( 'bp_get_the_thread_message_sender_link', bp_core_get_userlink( $thread_template->message->sender_id, false, true ) );
1961      }
1962  
1963  /**
1964   * Output the display name of the sender of the current message.
1965   *
1966   * @since 1.1.0
1967   */
1968  function bp_the_thread_message_sender_name() {
1969      echo esc_html( bp_get_the_thread_message_sender_name() );
1970  }
1971      /**
1972       * Get the display name of the sender of the current message.
1973       *
1974       * @since 1.1.0
1975       *
1976       * @return string
1977       */
1978  	function bp_get_the_thread_message_sender_name() {
1979          global $thread_template;
1980  
1981          $display_name = bp_core_get_user_displayname( $thread_template->message->sender_id );
1982  
1983          if ( empty( $display_name ) ) {
1984              $display_name = __( 'Deleted User', 'buddypress' );
1985          }
1986  
1987          /**
1988           * Filters the display name of the sender of the current message.
1989           *
1990           * @since 1.1.0
1991           *
1992           * @param string $display_name Display name of the sender of the current message.
1993           */
1994          return apply_filters( 'bp_get_the_thread_message_sender_name', $display_name );
1995      }
1996  
1997  /**
1998   * Output the URL for deleting the current thread.
1999   *
2000   * @since 1.5.0
2001   */
2002  function bp_the_thread_delete_link() {
2003      echo esc_url( bp_get_the_thread_delete_link() );
2004  }
2005      /**
2006       * Get the URL for deleting the current thread.
2007       *
2008       * @since 1.5.0
2009       *
2010       * @return string URL
2011       */
2012  	function bp_get_the_thread_delete_link() {
2013  
2014          /**
2015           * Filters the URL for deleting the current thread.
2016           *
2017           * @since 1.0.0
2018           *
2019           * @param string $value URL for deleting the current thread.
2020           * @param string $value Text indicating action being executed.
2021           */
2022          return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_messages_slug() . '/inbox/delete/' . bp_get_the_thread_id(), 'messages_delete_thread' ) );
2023      }
2024  
2025  /**
2026   * Output the 'Sent x hours ago' string for the current message.
2027   *
2028   * @since 1.1.0
2029   */
2030  function bp_the_thread_message_time_since() {
2031      echo bp_get_the_thread_message_time_since();
2032  }
2033      /**
2034       * Generate the 'Sent x hours ago' string for the current message.
2035       *
2036       * @since 1.1.0
2037       *
2038       * @return string
2039       */
2040  	function bp_get_the_thread_message_time_since() {
2041  
2042          /**
2043           * Filters the 'Sent x hours ago' string for the current message.
2044           *
2045           * @since 1.1.0
2046           *
2047           * @param string $value Default text of 'Sent x hours ago'.
2048           */
2049          return apply_filters( 'bp_get_the_thread_message_time_since', sprintf( __( 'Sent %s', 'buddypress' ), bp_core_time_since( bp_get_the_thread_message_date_sent() ) ) );
2050      }
2051  
2052  /**
2053   * Output the timestamp for the current message.
2054   *
2055   * @since 2.1.0
2056   */
2057  function bp_the_thread_message_date_sent() {
2058      echo bp_get_the_thread_message_date_sent();
2059  }
2060      /**
2061       * Generate the 'Sent x hours ago' string for the current message.
2062       *
2063       * @since 2.1.0
2064       *
2065       *
2066       * @return int
2067       */
2068  	function bp_get_the_thread_message_date_sent() {
2069          global $thread_template;
2070  
2071          /**
2072           * Filters the date sent value for the current message as a timestamp.
2073           *
2074           * @since 2.1.0
2075           *
2076           * @param string $value Timestamp of the date sent value for the current message.
2077           */
2078          return apply_filters( 'bp_get_the_thread_message_date_sent', strtotime( $thread_template->message->date_sent ) );
2079      }
2080  
2081  /**
2082   * Output the content of the current message in the loop.
2083   *
2084   * @since 1.1.0
2085   */
2086  function bp_the_thread_message_content() {
2087      echo bp_get_the_thread_message_content();
2088  }
2089      /**
2090       * Get the content of the current message in the loop.
2091       *
2092       * @since 1.1.0
2093       *
2094       * @return string
2095       */
2096  	function bp_get_the_thread_message_content() {
2097          global $thread_template;
2098  
2099          $content = $thread_template->message->message;
2100  
2101          // If user was deleted, mark content as deleted.
2102          if ( false === bp_core_get_core_userdata( bp_get_the_thread_message_sender_id() ) ) {
2103              $content = esc_html__( '[deleted]', 'buddypress' );
2104          }
2105  
2106          /**
2107           * Filters the content of the current message in the loop.
2108           *
2109           * @since 1.1.0
2110           *
2111           * @param string $message The content of the current message in the loop.
2112           */
2113          return apply_filters( 'bp_get_the_thread_message_content', $content );
2114      }
2115  
2116  /** Embeds *******************************************************************/
2117  
2118  /**
2119   * Enable oEmbed support for Messages.
2120   *
2121   * @since 1.5.0
2122   *
2123   * @see BP_Embed
2124   */
2125  function bp_messages_embed() {
2126      add_filter( 'embed_post_id',         'bp_get_the_thread_message_id' );
2127      add_filter( 'bp_embed_get_cache',    'bp_embed_message_cache',      10, 3 );
2128      add_action( 'bp_embed_update_cache', 'bp_embed_message_save_cache', 10, 3 );
2129  }
2130  add_action( 'thread_loop_start', 'bp_messages_embed' );
2131  
2132  /**
2133   * Fetch a private message item's cached embeds.
2134   *
2135   * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}.
2136   *
2137   * @since 2.2.0
2138   *
2139   * @param string $cache    An empty string passed by BP_Embed::parse_oembed() for
2140   *                         functions like this one to filter.
2141   * @param int    $id       The ID of the message item.
2142   * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
2143   * @return mixed The cached embeds for this message item.
2144   */
2145  function bp_embed_message_cache( $cache, $id, $cachekey ) {
2146      return bp_messages_get_meta( $id, $cachekey );
2147  }
2148  
2149  /**
2150   * Set a private message item's embed cache.
2151   *
2152   * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}.
2153   *
2154   * @since 2.2.0
2155   *
2156   * @param string $cache    An empty string passed by BP_Embed::parse_oembed() for
2157   *                         functions like this one to filter.
2158   * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
2159   * @param int    $id       The ID of the message item.
2160   */
2161  function bp_embed_message_save_cache( $cache, $cachekey, $id ) {
2162      bp_messages_update_meta( $id, $cachekey, $cache );
2163  }


Generated: Tue Jul 16 01:01:43 2019 Cross-referenced by PHPXref 0.7.1