Skip to:
Content

BuddyPress.org

Changeset 439 for trunk/bp-messages.php


Ignore:
Timestamp:
10/28/2008 02:49:35 PM (18 years ago)
Author:
apeatling
Message:

Added global notification system for BuddyPress components and added a "Notifications" menu to the logged in admin bar.

Cleaned up the design of the admin bar menus.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages.php

    r398 r439  
    1717 **************************************************************************/
    1818
    19 function messages_install( $version ) {
     19function messages_install() {
    2020    global $wpdb, $bp;
    2121   
     
    7979    dbDelta($sql);
    8080   
    81     add_site_option( 'bp-messages-version', $version );
     81    add_site_option( 'bp-messages-version', BP_MESSAGES_VERSION );
    8282}
    8383
     
    115115 **************************************************************************/
    116116
    117 function messages_add_admin_menu() {   
     117function messages_check_installed() {   
    118118    global $wpdb, $bp, $userdata;
    119119
    120     if ( $wpdb->blogid == $bp['current_homebase_id'] ) {   
    121         //Add the administration tab under the "Site Admin" tab for site administrators
    122         //add_submenu_page ( 'wpmu-admin.php', __('Messages'), __('Messages'), 1, basename(__FILE__), "messages_settings" );
    123     }
    124    
    125     /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    126     if ( ( $wpdb->get_var( "show tables like '%" . $bp['messages']['table_name'] . "%'" ) == false ) || ( get_site_option('bp-messages-version') < BP_MESSAGES_VERSION ) )
    127         messages_install(BP_MESSAGES_VERSION);
    128 }
    129 add_action( 'admin_menu', 'messages_add_admin_menu' );
     120    if ( is_site_admin() ) {
     121        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     122        if ( ( $wpdb->get_var( "show tables like '%" . $bp['messages']['table_name'] . "%'" ) == false ) || ( get_site_option('bp-messages-version') < BP_MESSAGES_VERSION ) )
     123            messages_install();
     124    }
     125}
     126add_action( 'admin_menu', 'messages_check_installed' );
    130127
    131128/**************************************************************************
     
    340337}
    341338
     339function messages_format_notifications( $action, $item_id, $total_items ) {
     340    global $bp;
     341   
     342    if ( $action == 'new_message') {
     343        if ( (int)$total_items > 1 )
     344            return '<a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/inbox" title="Inbox">' . sprintf( __('You have %d new messages'), (int)$total_items ) . '</a>';       
     345        else
     346            return '<a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/inbox" title="Inbox">' . sprintf( __('You have %d new message'), (int)$total_items ) . '</a>';
     347    }
     348}
     349
     350
    342351/**************************************************************************
    343352 messages_write_new()
     
    349358    <?php
    350359    global $messages_write_new_action;
    351    
    352     if ( $messages_write_new_action == '' )
    353         $messages_write_new_action = 'admin.php?page=bp-messages.php&amp;mode=send';
    354360    ?>
    355361   
     
    409415}
    410416
    411 function messages_inbox() {
    412     messages_box( 'inbox', __('Inbox', 'buddypress') );
    413 }
    414 
    415 function messages_sentbox() {
    416     messages_box( 'sentbox', __('Sent Messages', 'buddypress') );
    417 }
    418 
    419 
    420 /**************************************************************************
    421  messages_box()
    422  
    423  Handles and displays the messages in a particular box for the current user.
    424  **************************************************************************/
    425 
    426 function messages_box( $box = 'inbox', $display_name = 'Inbox', $message = '', $type = '' ) {
    427     global $bp, $userdata;
    428    
    429     if ( isset($_GET['mode']) && isset($_GET['thread_id']) && $_GET['mode'] == 'view' ) {
    430         messages_view_thread( $_GET['thread_id'], 'inbox' );
    431     } else if ( isset($_GET['mode']) && isset($_GET['thread_id']) && $_GET['mode'] == 'delete' ) {
    432         messages_delete_thread( $_GET['thread_id'], $box, $display_name );
    433     } else if ( isset($_GET['mode']) && isset($_POST['thread_ids']) && $_GET['mode'] == 'delete_bulk' ) {
    434         messages_delete_thread( $_POST['thread_ids'], $box, $display_name );
    435     } else if ( isset($_GET['mode']) && $_GET['mode'] == 'send' ) {
    436         messages_send_message( $_POST['send_to'], $_POST['subject'], $_POST['content'], $_POST['thread_id'] );
    437     } else {
    438     ?>
    439    
    440         <div class="wrap">
    441             <h2><?php echo $display_name ?></h2>
    442             <form action="admin.php?page=bp-messages.php&amp;mode=delete_bulk" method="post">
    443 
    444             <?php
    445                 if ( $message != '' ) {
    446                     $type = ( $type == 'error' ) ? 'error' : 'updated';
    447             ?>
    448                 <div id="message" class="<?php echo $type; ?> fade">
    449                     <p><?php echo $message; ?></p>
    450                 </div>
    451             <?php } ?>
    452            
    453             <?php if ( $box == 'inbox' ) { ?>
    454                 <div class="messages-options"> 
    455                     <?php bp_messages_options() ?>
    456                 </div>
    457                
    458                 <?php bp_message_get_notices(); ?>
    459             <?php } ?>
    460    
    461             <table class="widefat" id="message-threads" style="margin-top: 10px;">
    462                 <tbody id="the-list">
    463         <?php
    464         $threads = BP_Messages_Thread::get_current_threads_for_user( $userdata->ID, $box );
    465        
    466         if ( $threads ) {
    467             $counter = 0;
    468             foreach ( $threads as $thread ) {
    469                 if ( $thread->unread_count ) {
    470                     $is_read = '<img src="' . $bp['messages']['image_base'] .'/email.gif" alt="New Message" /><a href="admin.php?page=bp-messages.php&amp;mode=view&amp;thread_id=' . $thread->thread_id . '"><span id="awaiting-mod" class="count-1"><span class="message-count">' . $thread->unread_count . '</span></span></a>';
    471                     $new = " unread";
    472                 } else {
    473                     $is_read = '<img src="' . $bp['messages']['image_base'] .'/email_open.gif" alt="Older Message" />';
    474                     $new = " read";
    475                 }
    476                
    477                 if ( $counter % 2 == 0 )
    478                     $class = "alternate";
    479                 ?>
    480                     <tr class="<?php echo $class . $new ?>" id="m-<?php echo $message->id ?>">
    481                         <td class="is-read" width="1%"><?php echo $is_read ?></td>
    482                         <td class="avatar" width="1%">
    483                             <?php if ( function_exists('bp_core_get_avatar') )
    484                                     echo bp_core_get_avatar($thread->last_sender_id, 1);
    485                             ?>
    486                         </td>
    487                         <td class="sender-details" width="20%">
    488                             <?php if ( $box == 'sentbox') { ?>
    489                                 <h3>To: <?php echo BP_Messages_Thread::get_recipient_links($thread->recipients); ?></h3>
    490                             <?php } else { ?>
    491                                 <h3>From: <?php echo bp_core_get_userlink($thread->last_sender_id) ?></h3>
    492                             <?php } ?>
    493                             <?php echo bp_format_time(strtotime($thread->last_post_date)) ?>
    494                         </td>
    495                         <td class="message-details" width="40%">
    496                             <h4><a href="admin.php?page=bp-messages.php&amp;mode=view&amp;thread_id=<?php echo $thread->thread_id ?>"><?php echo stripslashes($thread->last_message_subject) ?></a></h4>
    497                             <?php echo bp_create_excerpt($thread->last_message_message, 20); ?>
    498                         </td>
    499                         <td width="10%"><a href="admin.php?page=bp-messages.php&amp;mode=delete&amp;thread_id=<?php echo $thread->thread_id ?>">Delete</a> <input type="checkbox" name="message_ids[]" value="<?php echo $thread->thread_id ?>" /></td>
    500                     </tr>
    501                 <?php
    502    
    503                 $counter++;
    504                 unset($class);
    505                 unset($new);
    506                 unset($is_read);
    507             }
    508            
    509             echo '
    510                 </tbody>
    511                 </table>
    512                 <p class="submit">
    513                     <input id="deletebookmarks" class="button" type="submit" onclick="return confirm(\'You are about to delete these messages permanently.\n[Cancel] to stop, [OK] to delete.\')" value="Delete Checked Messages &raquo;" name="deletebookmarks"/>
    514                 </p>
    515                 </form>
    516             </div>';
    517            
    518         } else {
    519             ?>
    520                 <tr class="alternate">
    521                 <td colspan="7" style="text-align: center; padding: 15px 0;">
    522                     <?php _e('You have no messages in your', 'buddypress'); echo ' ' . $display_name . '.'; ?>
    523                 </td>
    524                 </tr>
    525             <?php
    526         }
    527         ?>
    528             </tbody>
    529             </table>
    530             </form>
    531         </div>
    532         <?php
    533     }
    534 }
    535 
    536417/**************************************************************************
    537418 messages_send_message()
     
    603484                    $type = 'success';
    604485                   
    605                     do_action( 'bp_messages_message_sent', array( 'item_id' => $pmessage->id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1 ) );
     486                    // Send notices to the recipients
     487                    for ( $i = 0; $i < count($pmessage->recipients); $i++ ) {
     488                        if ( $pmessage->recipients[$i] != $bp['loggedin_userid'] )
     489                            bp_core_add_notification( $pmessage->id, $pmessage->recipients[$i], 'messages', 'new_message' );   
     490                    }
     491                   
     492                    do_action( 'bp_messages_message_sent', array( 'item_id' => $pmessage->id, 'recipient_ids' => $pmessage->recipients, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1 ) );
    606493           
    607494                    if ( $from_ajax ) {
Note: See TracChangeset for help on using the changeset viewer.