Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/21/2014 09:07:47 PM (9 years ago)
Author:
boonebgorges
Message:

Improvements to the messages thread interface.

  • Introduce noscript support for bulk actions.
  • Revise structure and markup to better match the Notifications table.
  • Add "Read/Unread" and "Delete" links for each message thread.
  • Remove unnecessary "Select Read/Unread" dropdown.
  • Introduce a number of new template functions in support of the new interface.

Props lakrisgubben.
See #6005.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-template.php

    r9151 r9161  
    562562
    563563/**
     564 * Output the URL used for marking a single message thread as unread.
     565 *
     566 * Since this function directly outputs a URL, it is escaped.
     567 *
     568 * @since BuddyPress (2.2.0)
     569 */
     570function bp_the_message_thread_mark_unread_url() {
     571    echo esc_url( bp_get_the_message_thread_mark_unread_url() );
     572}
     573    /**
     574     * Return the URL used for marking a single message thread as unread.
     575     *
     576     * @since BuddyPress (2.2.0)
     577     *
     578     * @return string
     579     */
     580    function bp_get_the_message_thread_mark_unread_url() {
     581
     582        // Get the message ID.
     583        $id = bp_get_message_thread_id();
     584
     585        // Get the args to add to the URL.
     586        $args = array(
     587            'action'     => 'unread',
     588            'message_id' => $id
     589        );
     590
     591        // Base unread URL.
     592        $url = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
     593
     594        // Add the args to the URL.
     595        $url = add_query_arg( $args, $url );
     596
     597        // Add the nonce.
     598        $url = wp_nonce_url( $url, 'bp_message_thread_mark_unread_' . $id );
     599
     600        // Filter and return.
     601        return apply_filters( 'bp_get_the_message_thread_mark_unread_url', $url );
     602    }
     603
     604/**
     605 * Output the URL used for marking a single message thread as read.
     606 *
     607 * Since this function directly outputs a URL, it is escaped.
     608 *
     609 * @since BuddyPress (2.2.0)
     610 */
     611function bp_the_message_thread_mark_read_url() {
     612    echo esc_url( bp_get_the_message_thread_mark_read_url() );
     613}
     614    /**
     615     * Return the URL used for marking a single message thread as read
     616     *
     617     * @since BuddyPress (2.2.0)
     618     *
     619     * @return string
     620     */
     621    function bp_get_the_message_thread_mark_read_url() {
     622
     623        // Get the message ID.
     624        $id = bp_get_message_thread_id();
     625
     626        // Get the args to add to the URL.
     627        $args = array(
     628            'action'     => 'read',
     629            'message_id' => $id
     630        );
     631
     632        // Base read URL.
     633        $url = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
     634
     635        // Add the args to the URL.
     636        $url = add_query_arg( $args, $url );
     637
     638        // Add the nonce.
     639        $url = wp_nonce_url( $url, 'bp_message_thread_mark_read_' . $id );
     640
     641        // Filter and return.
     642        return apply_filters( 'bp_get_the_message_thread_mark_read_url', $url );
     643    }
     644
     645/**
    564646 * Output the CSS class for the current thread.
    565647 */
     
    618700
    619701        return apply_filters( 'bp_get_message_thread_unread_count', $count );
     702    }
     703
     704/**
     705 * Output a thread's total message count.
     706 *
     707 * @since BuddyPress (2.2.0)
     708 *
     709 * @param int $thread_id Optional. ID of the thread. Defaults to current thread ID.
     710 */
     711function bp_message_thread_total_count( $thread_id = false ) {
     712    echo bp_get_message_thread_total_count( $thread_id );
     713}
     714    /**
     715     * Get the current thread's total message count.
     716     *
     717     * @since BuddyPress (2.2.0)
     718     *
     719     * @param int $thread_id Optional. ID of the thread. Defaults to
     720     *        current thread ID.
     721     * @return int
     722     */
     723    function bp_get_message_thread_total_count( $thread_id = false ) {
     724        if ( false === $thread_id ) {
     725            $thread_id = bp_get_message_thread_id();
     726        }
     727
     728        $thread_template = new BP_Messages_Thread_Template( $thread_id, 'ASC' );
     729
     730        $count = 0;
     731        if ( ! empty( $thread_template->message_count ) ) {
     732            $count = intval( $thread_template->message_count );
     733        }
     734
     735        return apply_filters( 'bp_get_message_thread_total_count', $count );
     736    }
     737
     738/**
     739 * Output markup for the current thread's total and unread count.
     740 *
     741 * @since Buddypress (2.2.0)
     742 *
     743 * @param int $thread_id Optional. ID of the thread. Default: current thread ID.
     744 */
     745function bp_message_thread_total_and_unread_count( $thread_id = false ) {
     746    echo bp_get_message_thread_total_and_unread_count( $thread_id );
     747}
     748    /**
     749     * Get markup for the current thread's total and unread count.
     750     *
     751     * @param int $thread_id Optional. ID of the thread. Default: current thread ID.
     752     * @return string Markup displaying the total and unread count for the thread.
     753     */
     754    function bp_get_message_thread_total_and_unread_count( $thread_id = false ) {
     755        if ( false === $thread_id ) {
     756            $thread_id = bp_get_message_thread_id();
     757        }
     758
     759        $total  = bp_get_message_thread_total_count( $thread_id );
     760        $unread = bp_get_message_thread_unread_count( $thread_id );
     761
     762        return sprintf(
     763            '<span class="thread-count">(%1$s)</span> <span class="bp-screen-reader-text">%2$s</span>',
     764            number_format_i18n( $total ),
     765            sprintf( _n( '%d unread', '%d unread', $unread, 'buddypress' ), number_format_i18n( $unread ) )
     766        );
    620767    }
    621768
     
    8571004?>
    8581005
    859     <?php _e( 'Select:', 'buddypress' ) ?>
     1006    <label for="message-type-select" class="bp-screen-reader-text">
     1007        <?php _e( 'Select:', 'buddypress' ) ?>
     1008     </label>
    8601009
    8611010    <select name="message-type-select" id="message-type-select">
    862         <option value=""></option>
     1011        <option value=""><?php _e( 'Select', 'buddypress' ); ?></option>
    8631012        <option value="read"><?php _ex('Read', 'Message dropdown filter', 'buddypress') ?></option>
    8641013        <option value="unread"><?php _ex('Unread', 'Message dropdown filter', 'buddypress') ?></option>
     
    8761025
    8771026<?php
     1027}
     1028
     1029/**
     1030 * Output the dropdown for bulk management of messages.
     1031 *
     1032 * @since BuddyPress (2.2.0)
     1033 */
     1034function bp_messages_bulk_management_dropdown() {
     1035    ?>
     1036    <label class="bp-screen-reader-text" for="messages-select"><?php _e( 'Select Bulk Action', 'buddypress' ); ?></label>
     1037    <select name="messages_bulk_action" id="messages-select">
     1038        <option value="" selected="selected"><?php _e( 'Bulk Actions', 'buddypress' ); ?></option>
     1039        <option value="read"><?php _e( 'Mark read', 'buddypress' ); ?></option>
     1040        <option value="unread"><?php _e( 'Mark unread', 'buddypress' ); ?></option>
     1041        <option value="delete"><?php _e( 'Delete', 'buddypress' ); ?></option>
     1042    </select>
     1043    <input type="submit" id="messages-bulk-manage" class="button action" value="<?php esc_attr_e( 'Apply', 'buddypress' ); ?>">
     1044    <?php
    8781045}
    8791046
Note: See TracChangeset for help on using the changeset viewer.