Skip to:
Content

BuddyPress.org

Changeset 3728 for trunk/bp-messages.php


Ignore:
Timestamp:
01/18/2011 12:53:31 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Code normalization and whitespace clean-up. Introduce bp-core-deprecated.php. Introduce root_slug globals into components with directories, to help with WP page slugs. Fixes #2600. Optimus Props boonebgorges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages.php

    r3633 r3728  
    11<?php
    2 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-classes.php' );
    3 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-cssjs.php' );
     2
     3// Required Files
     4require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-classes.php'      );
     5require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-cssjs.php'        );
    46require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-templatetags.php' );
    5 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-filters.php' );
     7require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-filters.php'      );
    68
    79function messages_setup_globals() {
     
    1416    $bp->messages->id = 'messages';
    1517
     18    // Slug
    1619    $bp->messages->slug = BP_MESSAGES_SLUG;
     20
     21    // Tables
    1722    $bp->messages->table_name_notices       = $bp->table_prefix . 'bp_messages_notices';
    1823    $bp->messages->table_name_messages      = $bp->table_prefix . 'bp_messages_messages';
    1924    $bp->messages->table_name_recipients    = $bp->table_prefix . 'bp_messages_recipients';
     25
     26    // Notifications
    2027    $bp->messages->format_notification_function = 'messages_format_notifications';
    2128
     
    3845        $name = __('Messages <strong></strong>', 'buddypress');
    3946
    40     /* Add 'Messages' to the main navigation */
     47    // Add 'Messages' to the main navigation
    4148    bp_core_new_nav_item( array( 'name' => $name, 'slug' => $bp->messages->slug, 'position' => 50, 'show_for_displayed_user' => false, 'screen_function' => 'messages_screen_inbox', 'default_subnav_slug' => 'inbox', 'item_css_id' => $bp->messages->id ) );
    4249
    4350    $messages_link = $bp->loggedin_user->domain . $bp->messages->slug . '/';
    4451
    45     /* Add the subnav items to the profile */
     52    // Add the subnav items to the profile
    4653    bp_core_new_subnav_item( array( 'name' => __( 'Inbox', 'buddypress' ), 'slug' => 'inbox', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_inbox', 'position' => 10, 'user_has_access' => bp_is_my_profile() ) );
    4754    bp_core_new_subnav_item( array( 'name' => __( 'Sent Messages', 'buddypress' ), 'slug' => 'sentbox', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'messages_screen_sentbox', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) );
     
    170177    global $bp;
    171178
    172     $new_messages = get_user_meta( $bp->displayed_user->id, 'notification_messages_new_message', true );
    173     if ( !$new_messages )
     179    if ( !$new_messages = get_user_meta( $bp->displayed_user->id, 'notification_messages_new_message', true ) )
    174180        $new_messages = 'yes';
    175181
    176     $new_notices = get_user_meta( $bp->displayed_user->id, 'notification_messages_new_notice', true );
    177     if ( !$new_notices )
    178         $new_notices = 'yes';
     182    if ( !$new_notices = get_user_meta( $bp->displayed_user->id, 'notification_messages_new_notice', true ) )
     183        $new_notices  = 'yes';
    179184?>
     185
    180186    <table class="notification-settings zebra" id="messages-notification-settings">
    181187        <thead>
     
    205211        </tbody>
    206212    </table>
     213
    207214<?php
    208215}
     
    229236        bp_core_redirect( $bp->displayed_user->domain . $bp->current_component );
    230237
    231     /* Check if a new reply has been submitted */
     238    // Check if a new reply has been submitted
    232239    if ( isset( $_POST['send'] ) ) {
    233240
    234         /* Check the nonce */
     241        // Check the nonce
    235242        check_admin_referer( 'messages_send_message', 'send_message_nonce' );
    236243
    237         /* Send the reply */
     244        // Send the reply
    238245        if ( messages_new_message( array( 'thread_id' => $thread_id, 'subject' => $_POST['subject'], 'content' => $_POST['content'] ) ) )
    239246            bp_core_add_message( __( 'Your reply was sent successfully', 'buddypress' ) );
     
    244251    }
    245252
    246     /* Mark message read */
     253    // Mark message read
    247254    messages_mark_thread_read( $thread_id );
    248255
     
    268275            return false;
    269276
    270         // delete message
     277        // Delete message
    271278        if ( !messages_delete_thread($thread_id) ) {
    272279            bp_core_add_message( __('There was an error deleting that message.', 'buddypress'), 'error' );
     
    293300            return false;
    294301
    295         if ( !messages_delete_thread( $thread_ids ) ) {
     302        if ( !messages_delete_thread( $thread_ids ) )
    296303            bp_core_add_message( __('There was an error deleting messages.', 'buddypress'), 'error' );
    297         } else {
     304        else
    298305            bp_core_add_message( __('Messages deleted.', 'buddypress') );
    299         }
     306
    300307        bp_core_redirect( $bp->loggedin_user->domain . $bp->current_component . '/' . $bp->current_action );
    301308    }
     
    339346    global $bp;
    340347
    341     $defaults = array(
    342         'thread_id' => false, // false for a new message, thread id for a reply to a thread.
    343         'sender_id' => $bp->loggedin_user->id,
     348    $defaults = array (
     349        'sender_id'  => $bp->loggedin_user->id,
     350        'thread_id'  => false, // false for a new message, thread id for a reply to a thread.
    344351        'recipients' => false, // Can be an array of usernames, user_ids or mixed.
    345         'subject' => false,
    346         'content' => false,
    347         'date_sent' => bp_core_current_time()
     352        'subject'    => false,
     353        'content'    => false,
     354        'date_sent'  => bp_core_current_time()
    348355    );
    349356
     
    354361        return false;
    355362
    356     /* Create a new message object */
    357     $message = new BP_Messages_Message;
     363    // Create a new message object
     364    $message            = new BP_Messages_Message;
    358365    $message->thread_id = $thread_id;
    359366    $message->sender_id = $sender_id;
    360     $message->subject = $subject;
    361     $message->message = $content;
     367    $message->subject   = $subject;
     368    $message->message   = $content;
    362369    $message->date_sent = $date_sent;
    363370
     
    382389            $message->subject = __( 'No Subject', 'buddypress' );
    383390
    384         /* Loop the recipients and convert all usernames to user_ids where needed */
     391        // Loop the recipients and convert all usernames to user_ids where needed
    385392        foreach( (array) $recipients as $recipient ) {
    386393            if ( is_numeric( trim( $recipient ) ) )
     
    391398        }
    392399
    393         /* Strip the sender from the recipient list if they exist */
     400        // Strip the sender from the recipient list if they exist
    394401        if ( $key = array_search( $sender_id, (array)$recipient_ids ) )
    395402            unset( $recipient_ids[$key] );
    396403
    397         /* Remove duplicates */
     404        // Remove duplicates
    398405        $recipient_ids = array_unique( (array)$recipient_ids );
    399406
     
    401408            return false;
    402409
    403         /* Format this to match existing recipients */
     410        // Format this to match existing recipients
    404411        foreach( (array)$recipient_ids as $i => $recipient_id ) {
    405412            $message->recipients[$i] = new stdClass;
     
    430437    if ( !is_super_admin() || empty( $subject ) || empty( $message ) ) {
    431438        return false;
     439
     440    // Has access to send notices, lets do it.
    432441    } else {
    433         // Has access to send notices, lets do it.
    434         $notice = new BP_Messages_Notice;
    435         $notice->subject = $subject;
    436         $notice->message = $message;
     442        $notice            = new BP_Messages_Notice;
     443        $notice->subject   = $subject;
     444        $notice->message   = $message;
    437445        $notice->date_sent = bp_core_current_time();
    438446        $notice->is_active = 1;
     
    470478}
    471479
    472 function messages_check_thread_access( $thread_id, $user_id = false ) {
     480function messages_check_thread_access( $thread_id, $user_id = 0 ) {
    473481    global $bp;
    474482
     
    499507}
    500508
    501 function messages_get_unread_count( $user_id = false ) {
     509function messages_get_unread_count( $user_id = 0 ) {
    502510    global $bp;
    503511
     
    529537
    530538// List actions to clear super cached pages on, if super cache is installed
    531 add_action( 'messages_delete_thread', 'bp_core_clear_cache' );
    532 add_action( 'messages_send_notice', 'bp_core_clear_cache' );
    533 add_action( 'messages_message_sent', 'bp_core_clear_cache' );
     539add_action( 'messages_delete_thread',  'bp_core_clear_cache' );
     540add_action( 'messages_send_notice',    'bp_core_clear_cache' );
     541add_action( 'messages_message_sent',   'bp_core_clear_cache' );
    534542
    535543// Don't cache message inbox/sentbox/compose as it's too problematic
    536544add_action( 'messages_screen_compose', 'bp_core_clear_cache' );
    537545add_action( 'messages_screen_sentbox', 'bp_core_clear_cache' );
    538 add_action( 'messages_screen_inbox', 'bp_core_clear_cache' );
     546add_action( 'messages_screen_inbox',   'bp_core_clear_cache' );
    539547
    540548?>
Note: See TracChangeset for help on using the changeset viewer.