Skip to:
Content

BuddyPress.org

Changeset 9161


Ignore:
Timestamp:
11/21/2014 09:07:47 PM (6 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.

Location:
trunk/src
Files:
5 edited

Legend:

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

    r8621 r9161  
    9393
    9494/**
     95 * Handle marking a single message thread as read.
     96 *
     97 * @since BuddyPress (2.2.0)
     98 *
     99 * @return bool|null Returns false on failure. Otherwise redirects back to the
     100 *         message box URL.
     101 */
     102function bp_messages_action_mark_read() {
     103
     104    if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'read', 0 ) ) {
     105        return false;
     106    }
     107
     108    $action = ! empty( $_GET['action'] ) ? $_GET['action'] : '';
     109    $nonce  = ! empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : '';
     110    $id     = ! empty( $_GET['message_id'] ) ? intval( $_GET['message_id'] ) : '';
     111
     112    // Bail if no action or no ID.
     113    if ( 'read' !== $action || empty( $id ) || empty( $nonce ) ) {
     114        return false;
     115    }
     116
     117    // Check the nonce.
     118    if ( ! bp_verify_nonce_request( 'bp_message_thread_mark_read_' . $id ) ) {
     119        return false;
     120    }
     121
     122    // Check access to the message and mark as read.
     123    if ( messages_check_thread_access( $id ) ) {
     124        messages_mark_thread_read( $id );
     125        bp_core_add_message( __( 'Message marked as read.', 'buddypress' ) );
     126    } else {
     127        bp_core_add_message( __( 'There was a problem marking that message.', 'buddypress' ), 'error' );
     128    }
     129
     130    // Redirect back to the message box.
     131    bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() );
     132}
     133add_action( 'bp_actions', 'bp_messages_action_mark_read' );
     134
     135/**
     136 * Handle marking a single message thread as unread.
     137 *
     138 * @since BuddyPress (2.2.0)
     139 *
     140 * @return bool|null Returns false on failure. Otherwise redirects back to the
     141 *         message box URL.
     142 */
     143function bp_messages_action_mark_unread() {
     144
     145    if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'unread', 0 ) ) {
     146        return false;
     147    }
     148
     149    $action = ! empty( $_GET['action'] ) ? $_GET['action'] : '';
     150    $nonce  = ! empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : '';
     151    $id     = ! empty( $_GET['message_id'] ) ? intval( $_GET['message_id'] ) : '';
     152
     153    // Bail if no action or no ID.
     154    if ( 'unread' !== $action || empty( $id ) || empty( $nonce ) ) {
     155        return false;
     156    }
     157
     158    // Check the nonce.
     159    if ( ! bp_verify_nonce_request( 'bp_message_thread_mark_unread_' . $id ) ) {
     160        return false;
     161    }
     162
     163    // Check access to the message and mark unread.
     164    if ( messages_check_thread_access( $id ) ) {
     165        messages_mark_thread_unread( $id );
     166        bp_core_add_message( __( 'Message marked unread.', 'buddypress' ) );
     167    } else {
     168        bp_core_add_message( __( 'There was a problem marking that message.', 'buddypress' ), 'error' );
     169    }
     170
     171    // Redirect back to the message box URL.
     172    bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() );
     173}
     174add_action( 'bp_actions', 'bp_messages_action_mark_unread' );
     175
     176/**
     177 * Handle bulk management (mark as read/unread, delete) of message threads.
     178 *
     179 * @since BuddyPress (2.2.0)
     180 *
     181 * @return bool Returns false on failure. Otherwise redirects back to the
     182 *         message box URL.
     183 */
     184function bp_messages_action_bulk_manage() {
     185
     186    if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'bulk-manage', 0 ) ) {
     187        return false;
     188    }
     189
     190    $action   = ! empty( $_POST['messages_bulk_action'] ) ? $_POST['messages_bulk_action'] : '';
     191    $nonce    = ! empty( $_POST['messages_bulk_nonce'] ) ? $_POST['messages_bulk_nonce'] : '';
     192    $messages = ! empty( $_POST['message_ids'] ) ? $_POST['message_ids'] : '';
     193
     194    $messages = wp_parse_id_list( $messages );
     195
     196    // Bail if no action or no IDs.
     197    if ( ( ! in_array( $action, array( 'delete', 'read', 'unread' ) ) ) || empty( $messages ) || empty( $nonce ) ) {
     198        bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
     199    }
     200
     201    // Check the nonce.
     202    if ( ! wp_verify_nonce( $nonce, 'messages_bulk_nonce' ) ) {
     203        return false;
     204    }
     205
     206    // Make sure the user has access to all notifications before managing them.
     207    foreach ( $messages as $message ) {
     208        if ( ! messages_check_thread_access( $message ) ) {
     209            bp_core_add_message( __( 'There was a problem managing your messages.', 'buddypress' ), 'error' );
     210            bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
     211        }
     212    }
     213
     214    // Delete, mark as read or unread depending on the user 'action'.
     215    switch ( $action ) {
     216        case 'delete' :
     217            foreach ( $messages as $message ) {
     218                messages_delete_thread( $message );
     219            }
     220            bp_core_add_message( __( 'Messages deleted.', 'buddypress' ) );
     221        break;
     222
     223        case 'read' :
     224            foreach ( $messages as $message ) {
     225                messages_mark_thread_read( $message );
     226            }
     227            bp_core_add_message( __( 'Messages marked as read', 'buddypress' ) );
     228        break;
     229
     230        case 'unread' :
     231            foreach ( $messages as $message ) {
     232                messages_mark_thread_unread( $message );
     233            }
     234            bp_core_add_message( __( 'Messages marked as unread.', 'buddypress' ) );
     235        break;
     236    }
     237
     238    // Redirect back to message box.
     239    bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
     240}
     241add_action( 'bp_actions', 'bp_messages_action_bulk_manage' );
     242
     243/**
    95244 * Process a request to bulk delete messages.
    96245 *
  • 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
  • trunk/src/bp-templates/bp-legacy/buddypress/members/single/messages/messages-loop.php

    r9089 r9161  
    1717    <?php do_action( 'bp_after_member_messages_pagination' ); ?>
    1818
    19     <?php do_action( 'bp_before_member_messages_threads'   ); ?>
     19    <?php do_action( 'bp_before_member_messages_threads' ); ?>
    2020
    21     <table id="message-threads" class="messages-notices">
    22         <?php while ( bp_message_threads() ) : bp_message_thread(); ?>
     21    <form action="<?php echo bp_loggedin_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() ?>/bulk-manage/" method="post" id="messages-bulk-management">
    2322
    24             <tr id="m-<?php bp_message_thread_id(); ?>" class="<?php bp_message_css_class(); ?><?php if ( bp_message_thread_has_unread() ) : ?> unread<?php else: ?> read<?php endif; ?>">
    25                 <td width="1%" class="thread-count">
    26                     <span class="unread-count"><?php bp_message_thread_unread_count(); ?></span>
    27                 </td>
    28                 <td width="1%" class="thread-avatar"><?php bp_message_thread_avatar(); ?></td>
     23        <table id="message-threads" class="messages-notices">
    2924
    30                 <?php if ( 'sentbox' != bp_current_action() ) : ?>
    31                     <td width="30%" class="thread-from">
    32                         <?php _e( 'From:', 'buddypress' ); ?> <?php bp_message_thread_from(); ?><br />
    33                         <span class="activity"><?php bp_message_thread_last_post_date(); ?></span>
    34                     </td>
    35                 <?php else: ?>
    36                     <td width="30%" class="thread-from">
    37                         <?php _e( 'To:', 'buddypress' ); ?> <?php bp_message_thread_to(); ?><br />
    38                         <span class="activity"><?php bp_message_thread_last_post_date(); ?></span>
    39                     </td>
    40                 <?php endif; ?>
     25            <thead>
     26                <tr>
     27                    <th scope="col" class="thread-checkbox"><label class="bp-screen-reader-text" for="select-all-messages"><?php _e( 'Select all', 'buddypress' ); ?></label><input id="select-all-messages" type="checkbox"></th>
     28                    <th scope="col" class="thread-from"><?php _e( 'From', 'buddypress' ); ?></th>
     29                    <th scope="col" class="thread-info"><?php _e( 'Subject', 'buddypress' ); ?></th>
     30                    <th scope="col" class="thread-options"><?php _e( 'Actions', 'buddypress' ); ?></th>
     31                </tr>
     32            </thead>
    4133
    42                 <td width="50%" class="thread-info">
    43                     <p><a href="<?php bp_message_thread_view_link(); ?>" title="<?php esc_attr_e( "View Message", "buddypress" ); ?>"><?php bp_message_thread_subject(); ?></a></p>
    44                     <p class="thread-excerpt"><?php bp_message_thread_excerpt(); ?></p>
    45                 </td>
     34            <tbody>
    4635
    47                 <?php do_action( 'bp_messages_inbox_list_item' ); ?>
     36                <?php while ( bp_message_threads() ) : bp_message_thread(); ?>
    4837
    49                 <td width="13%" class="thread-options">
    50                     <input type="checkbox" name="message_ids[]" value="<?php bp_message_thread_id(); ?>" />
    51                     <a class="button confirm" href="<?php bp_message_thread_delete_link(); ?>" title="<?php esc_attr_e( "Delete Conversation", "buddypress" ); ?>"><?php _e( 'Delete', 'buddypress' ); ?></a> &nbsp;
    52                 </td>
    53             </tr>
     38                    <tr id="m-<?php bp_message_thread_id(); ?>" class="<?php bp_message_css_class(); ?><?php if ( bp_message_thread_has_unread() ) : ?> unread<?php else: ?> read<?php endif; ?>">
     39                        <td>
     40                            <input type="checkbox" name="message_ids[]" class="message-check" value="<?php bp_message_thread_id(); ?>" />
     41                        </td>
    5442
    55         <?php endwhile; ?>
    56     </table><!-- #message-threads -->
     43                        <?php if ( 'sentbox' != bp_current_action() ) : ?>
     44                            <td class="thread-from">
     45                                <?php bp_message_thread_avatar( array( 'width' => 25, 'height' => 25 ) ); ?>
     46                                <span class="from"><?php _e( 'From:', 'buddypress' ); ?></span> <?php bp_message_thread_from(); ?>
     47                                <?php bp_message_thread_total_and_unread_count(); ?>
     48                                <span class="activity"><?php bp_message_thread_last_post_date(); ?></span>
     49                            </td>
     50                        <?php else: ?>
     51                            <td class="thread-from">
     52                                <?php bp_message_thread_avatar( array( 'width' => 25, 'height' => 25 ) ); ?>
     53                                <span class="to"><?php _e( 'To:', 'buddypress' ); ?></span> <?php bp_message_thread_to(); ?>
     54                                <?php bp_message_thread_total_and_unread_count(); ?>
     55                                <span class="activity"><?php bp_message_thread_last_post_date(); ?></span>
     56                            </td>
     57                        <?php endif; ?>
    5758
    58     <div class="messages-options-nav">
    59         <?php bp_messages_options(); ?>
    60     </div><!-- .messages-options-nav -->
     59                        <td class="thread-info">
     60                            <p><a href="<?php bp_message_thread_view_link(); ?>" title="<?php esc_attr_e( "View Message", "buddypress" ); ?>"><?php bp_message_thread_subject(); ?></a></p>
     61                            <p class="thread-excerpt"><?php bp_message_thread_excerpt(); ?></p>
     62                        </td>
     63
     64                        <?php do_action( 'bp_messages_inbox_list_item' ); ?>
     65
     66                        <td class="thread-options">
     67                            <?php if ( bp_message_thread_has_unread() ) : ?>
     68                                <a class="read" href="<?php bp_the_message_thread_mark_read_url();?>"><?php _e( 'Read', 'buddypress' ); ?></a>
     69                            <?php else : ?>
     70                                <a class="unread" href="<?php bp_the_message_thread_mark_unread_url();?>"><?php _e( 'Unread', 'buddypress' ); ?></a>
     71                            <?php endif; ?>
     72                             |
     73                            <a class="delete" href="<?php bp_message_thread_delete_link(); ?>"><?php _e( 'Delete', 'buddypress' ); ?></a>
     74                        </td>
     75                    </tr>
     76
     77                <?php endwhile; ?>
     78
     79            </tbody>
     80
     81        </table><!-- #message-threads -->
     82
     83        <div class="messages-options-nav">
     84            <?php bp_messages_bulk_management_dropdown(); ?>
     85        </div><!-- .messages-options-nav -->
     86
     87        <?php wp_nonce_field( 'messages_bulk_nonce', 'messages_bulk_nonce' ); ?>
     88    </form>
    6189
    6290    <?php do_action( 'bp_after_member_messages_threads' ); ?>
  • trunk/src/bp-templates/bp-legacy/css/buddypress.css

    r9159 r9161  
    739739body.no-js #buddypress #delete_inbox_messages,
    740740body.no-js #buddypress #delete_sentbox_messages,
    741 body.no-js #buddypress #notifications-bulk-management #select-all-notifications {
     741body.no-js #buddypress #messages-bulk-management #select-all-messages {
    742742    display: none;
    743743}
     
    975975#buddypress table#message-threads {
    976976    clear: both;
    977     margin: 0;
    978     width: auto;
    979977}
    980978#buddypress table.profile-fields {
     
    10161014    width: 25%;
    10171015}
     1016#buddypress #message-threads .thread-info {
     1017    min-width: 40%;
     1018}
    10181019#buddypress table tr td.thread-info p {
    10191020    margin: 0;
     
    13851386    font-weight: bold;
    13861387}
     1388#buddypress table#message-threads tr.unread td .thread-excerpt,
     1389#buddypress table#message-threads tr.unread td .activity,
     1390#buddypress table#message-threads tr.unread td.thread-options {
     1391    font-weight: normal;
     1392}
    13871393#buddypress li span.unread-count,
    13881394#buddypress tr.unread span.unread-count {
     
    13951401    padding: 1px 6px;
    13961402    color: #fff;
    1397 }
    1398 #buddypress div.messages-options-nav {
    1399     background: #eee;
    1400     font-size: 80%;
    1401     margin: 0;
    1402     padding: 5px 15px;
    1403     text-align: right;
    14041403}
    14051404#buddypress div#message-thread div.message-box {
  • trunk/src/bp-templates/bp-legacy/js/buddypress.js

    r9143 r9161  
    15241524
    15251525        return false;
     1526    });
     1527
     1528    /* Selecting/Deselecting all messages */
     1529    jq('#select-all-messages').click(function(event) {
     1530        if( this.checked ) {
     1531            jq('.message-check').each(function() {
     1532                this.checked = true;
     1533            });
     1534        } else {
     1535            jq('.message-check').each(function() {
     1536                this.checked = false;
     1537            });
     1538        }
     1539    });
     1540
     1541    /* Make sure a 'Bulk Action' is selected before submiting the messages bulk action form */
     1542    jq('#messages-bulk-manage').attr('disabled', 'disabled');
     1543
     1544    /* Remove the disabled attribute from the messages form submit button when bulk action has a value */
     1545    jq('#messages-select').on('change', function(){
     1546        jq('#messages-bulk-manage').attr('disabled', jq(this).val().length <= 0);
    15261547    });
    15271548
Note: See TracChangeset for help on using the changeset viewer.