Skip to:
Content

BuddyPress.org

Changeset 3300 for trunk/bp-messages.php


Ignore:
Timestamp:
10/24/2010 09:22:29 PM (16 years ago)
Author:
djpaul
Message:

Fixed #2676

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages.php

    r2941 r3300  
    66
    77function messages_setup_globals() {
    8         global $bp, $wpdb;
     8        global $bp;
    99
    1010        if ( !defined( 'BP_MESSAGES_SLUG' ) )
     
    1414        $bp->messages->id = 'messages';
    1515
    16         $bp->messages->table_name_messages = $wpdb->base_prefix . 'bp_messages_messages';
    17         $bp->messages->table_name_recipients = $wpdb->base_prefix . 'bp_messages_recipients';
    18         $bp->messages->table_name_notices = $wpdb->base_prefix . 'bp_messages_notices';
     16        $bp->messages->slug = BP_MESSAGES_SLUG;
     17        $bp->messages->table_name_notices               = $bp->table_prefix . 'bp_messages_notices';
     18        $bp->messages->table_name_messages              = $bp->table_prefix . 'bp_messages_messages';
     19        $bp->messages->table_name_recipients    = $bp->table_prefix . 'bp_messages_recipients';
    1920        $bp->messages->format_notification_function = 'messages_format_notifications';
    20         $bp->messages->slug = BP_MESSAGES_SLUG;
    2121
    2222        /* Register this in the active components array */
     
    4545        bp_core_new_subnav_item( array( 'name' => __( 'Compose', 'buddypress' ), 'slug' => 'compose', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_compose', 'position' => 30, 'user_has_access' => bp_is_my_profile() ) );
    4646
    47         if ( is_site_admin() )
    48                 bp_core_new_subnav_item( array( 'name' => __( 'Notices', 'buddypress' ), 'slug' => 'notices', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_notices', 'position' => 90, 'user_has_access' => is_site_admin() ) );
     47        if ( is_super_admin() )
     48                bp_core_new_subnav_item( array( 'name' => __( 'Notices', 'buddypress' ), 'slug' => 'notices', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_notices', 'position' => 90, 'user_has_access' => is_super_admin() ) );
    4949
    5050        if ( $bp->current_component == $bp->messages->slug ) {
     
    8585        messages_remove_callback_values();
    8686
    87         /* Check if the message form has been submitted */
     87        // Check if the message form has been submitted
    8888        if ( isset( $_POST['send'] ) ) {
    8989
    90                 /* Check the nonce */
     90                // Check the nonce
    9191                check_admin_referer( 'messages_send_message' );
    9292
    93                 /* Check we have what we need */
     93                // Check we have what we need
    9494                if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) {
    9595                        bp_core_add_message( __( 'There was an error sending that message, please try again', 'buddypress' ), 'error' );
    9696                } else {
    97                         /* If this is a notice, send it */
     97                        // If this is a notice, send it
    9898                        if ( isset( $_POST['send-notice'] ) ) {
    9999                                if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) {
     
    104104                                }
    105105                        } else {
    106                                 /* Filter recipients into the format we need - array( 'username/userid', 'username/userid' ) */
     106                                // Filter recipients into the format we need - array( 'username/userid', 'username/userid' )
    107107                                $autocomplete_recipients = explode( ',', $_POST['send-to-input'] );
    108                                 $typed_recipients = explode( ' ', $_POST['send_to_usernames'] );
    109                                 $recipients = array_merge( (array) $autocomplete_recipients, (array) $typed_recipients );
    110 
    111                                 /* Send the message */
     108                                $typed_recipients        = explode( ' ', $_POST['send_to_usernames'] );
     109                                $recipients              = array_merge( (array) $autocomplete_recipients, (array) $typed_recipients );
     110                                $recipients              = apply_filters( 'bp_messages_recipients', $recipients );
     111
     112                                // Send the message
    112113                                if ( $thread_id = messages_new_message( array( 'recipients' => $recipients, 'subject' => $_POST['subject'], 'content' => $_POST['content'] ) ) ) {
    113114                                        bp_core_add_message( __( 'Message sent successfully!', 'buddypress' ) );
     
    118119                        }
    119120                }
    120 
    121121        }
    122122
     
    129129        global $bp, $notice_id;
    130130
    131         if ( !is_site_admin() )
     131        if ( !is_super_admin() )
    132132                return false;
    133133
     
    166166function messages_screen_notification_settings() {
    167167        global $current_user; ?>
    168         <table class="notification-settings" id="messages-notification-settings">
    169                 <tr>
    170                         <th class="icon"></th>
    171                         <th class="title"><?php _e( 'Messages', 'buddypress' ) ?></th>
    172                         <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
    173                         <th class="no"><?php _e( 'No', 'buddypress' )?></th>
    174                 </tr>
    175                 <tr>
    176                         <td></td>
    177                         <td><?php _e( 'A member sends you a new message', 'buddypress' ) ?></td>
    178                         <td class="yes"><input type="radio" name="notifications[notification_messages_new_message]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_messages_new_message' ) || 'yes' == get_usermeta( $current_user->id, 'notification_messages_new_message' ) ) { ?>checked="checked" <?php } ?>/></td>
    179                         <td class="no"><input type="radio" name="notifications[notification_messages_new_message]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_messages_new_message' ) ) { ?>checked="checked" <?php } ?>/></td>
    180                 </tr>
    181                 <tr>
    182                         <td></td>
    183                         <td><?php _e( 'A new site notice is posted', 'buddypress' ) ?></td>
    184                         <td class="yes"><input type="radio" name="notifications[notification_messages_new_notice]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_messages_new_notice' ) || 'yes' == get_usermeta( $current_user->id, 'notification_messages_new_notice' ) ) { ?>checked="checked" <?php } ?>/></td>
    185                         <td class="no"><input type="radio" name="notifications[notification_messages_new_notice]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_messages_new_notice' ) ) { ?>checked="checked" <?php } ?>/></td>
    186                 </tr>
    187 
    188                 <?php do_action( 'messages_screen_notification_settings' ) ?>
     168        <table class="notification-settings zebra" id="messages-notification-settings">
     169                <thead>
     170                        <tr>
     171                                <th class="icon"></th>
     172                                <th class="title"><?php _e( 'Messages', 'buddypress' ) ?></th>
     173                                <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
     174                                <th class="no"><?php _e( 'No', 'buddypress' )?></th>
     175                        </tr>
     176                </thead>
     177
     178                <tbody>
     179                        <tr>
     180                                <td></td>
     181                                <td><?php _e( 'A member sends you a new message', 'buddypress' ) ?></td>
     182                                <td class="yes"><input type="radio" name="notifications[notification_messages_new_message]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_messages_new_message', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_messages_new_message', true ) ) { ?>checked="checked" <?php } ?>/></td>
     183                                <td class="no"><input type="radio" name="notifications[notification_messages_new_message]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_messages_new_message', true ) ) { ?>checked="checked" <?php } ?>/></td>
     184                        </tr>
     185                        <tr>
     186                                <td></td>
     187                                <td><?php _e( 'A new site notice is posted', 'buddypress' ) ?></td>
     188                                <td class="yes"><input type="radio" name="notifications[notification_messages_new_notice]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_messages_new_notice', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_messages_new_notice', true ) ) { ?>checked="checked" <?php } ?>/></td>
     189                                <td class="no"><input type="radio" name="notifications[notification_messages_new_notice]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_messages_new_notice', true ) ) { ?>checked="checked" <?php } ?>/></td>
     190                        </tr>
     191
     192                        <?php do_action( 'messages_screen_notification_settings' ) ?>
     193                </tbody>
    189194        </table>
    190195<?php
     
    209214        $thread_id = $bp->action_variables[0];
    210215
    211         if ( !$thread_id || !messages_is_valid_thread( $thread_id ) || ( !messages_check_thread_access($thread_id) && !is_site_admin() ) )
     216        if ( !$thread_id || !messages_is_valid_thread( $thread_id ) || ( !messages_check_thread_access($thread_id) && !is_super_admin() ) )
    212217                bp_core_redirect( $bp->displayed_user->domain . $bp->current_component );
    213218
     
    328333                'subject' => false,
    329334                'content' => false,
    330                 'date_sent' => time()
     335                'date_sent' => bp_core_current_time()
    331336        );
    332337
     
    345350        $message->date_sent = $date_sent;
    346351
    347         /* If we have a thread ID, use the existing recipients, otherwise use the recipients passed */
     352        // If we have a thread ID, use the existing recipients, otherwise use the recipients passed
    348353        if ( $thread_id ) {
    349354                $thread = new BP_Messages_Thread( $thread_id );
    350355                $message->recipients = $thread->get_recipients();
    351356
     357                // Strip the sender from the recipient list if they exist
     358                if ( isset( $message->recipients[$sender_id] ) )
     359                        unset( $message->recipients[$sender_id] );
     360
    352361                if ( empty( $message->subject ) )
    353362                        $message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject );
    354363
     364        // No thread ID, so make some adjustments
    355365        } else {
    356366                if ( empty( $recipients ) )
     
    406416
    407417function messages_send_notice( $subject, $message ) {
    408         if ( !is_site_admin() || empty( $subject ) || empty( $message ) ) {
     418        if ( !is_super_admin() || empty( $subject ) || empty( $message ) ) {
    409419                return false;
    410420        } else {
     
    413423                $notice->subject = $subject;
    414424                $notice->message = $message;
    415                 $notice->date_sent = time();
     425                $notice->date_sent = bp_core_current_time();
    416426                $notice->is_active = 1;
    417427                $notice->save(); // send it.
Note: See TracChangeset for help on using the changeset viewer.