Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/25/2011 08:58:56 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Rename new 'bp-users' component to 'bp-members' for consistency through-out project.
Core, Messages, and Friends Components now use the BP_Component class.
Split Friends and Messages components into smaller files.
Change references to 'profile' to 'xprofile' through-out project for consistency.
Introduce 'bp_actions' and 'bp_screens' standard hooks to replace the usage of 'wp' through-out project.
Move component loader sequence into bp-core-bootstrap.php,
Move old root_component action into 1.3 deprecated file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages/bp-messages-loader.php

    r3757 r3917  
    11<?php
    22
    3 // Required Files
    4 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-cssjs.php'     );
    5 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-actions.php'   );
    6 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-screens.php'   );
    7 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-classes.php'   );
    8 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-filters.php'   );
    9 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-template.php'  );
    10 require ( BP_PLUGIN_DIR . '/bp-messages/bp-messages-functions.php' );
     3/**
     4 * BuddyPress Private Messages Loader
     5 *
     6 * A private messages component, for users to send messages to each other
     7 *
     8 * @package BuddyPress
     9 * @subpackage Messages Core
     10 */
    1111
    12 function messages_setup_globals() {
    13     global $bp;
     12class BP_Messages_Component extends BP_Component {
    1413
    15     if ( !defined( 'BP_MESSAGES_SLUG' ) )
    16         define ( 'BP_MESSAGES_SLUG', 'messages' );
    17 
    18     // For internal identification
    19     $bp->messages->id = 'messages';
    20 
    21     // Slug
    22     $bp->messages->slug = BP_MESSAGES_SLUG;
    23 
    24     // Tables
    25     $bp->messages->table_name_notices       = $bp->table_prefix . 'bp_messages_notices';
    26     $bp->messages->table_name_messages      = $bp->table_prefix . 'bp_messages_messages';
    27     $bp->messages->table_name_recipients    = $bp->table_prefix . 'bp_messages_recipients';
    28 
    29     // Notifications
    30     $bp->messages->notification_callback = 'messages_format_notifications';
    31 
    32     // Register this in the active components array
    33     $bp->active_components[$bp->messages->slug] = $bp->messages->id;
    34 
    35     // Include all members in the To: autocomplete?
    36     $bp->messages->autocomplete_all = defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ) ? true : false;
    37 
    38     do_action( 'messages_setup_globals' );
    39 }
    40 add_action( 'bp_setup_globals', 'messages_setup_globals' );
    41 
    42 function messages_setup_nav() {
    43     global $bp;
    44 
    45     if ( $count = messages_get_unread_count() )
    46         $name = sprintf( __('Messages <strong>(%s)</strong>', 'buddypress'), $count );
    47     else
    48         $name = __('Messages <strong></strong>', 'buddypress');
    49 
    50     // Add 'Messages' to the main navigation
    51     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 ) );
    52 
    53     $messages_link = $bp->loggedin_user->domain . $bp->messages->slug . '/';
    54 
    55     // Add the subnav items to the profile
    56     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() ) );
    57     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() ) );
    58     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() ) );
    59 
    60     if ( is_super_admin() )
    61         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() ) );
    62 
    63     if ( $bp->current_component == $bp->messages->slug ) {
    64         if ( bp_is_my_profile() ) {
    65             $bp->bp_options_title = __( 'My Messages', 'buddypress' );
    66         } else {
    67             $bp_options_avatar =  bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
    68             $bp->bp_options_title = $bp->displayed_user->fullname;
    69         }
     14    /**
     15     * Start the messages component creation process
     16     *
     17     * @since BuddyPress {unknown}
     18     */
     19    function BP_Messages_Component() {
     20        parent::start(
     21            'messages',
     22            __( 'Private Messages', 'buddypress' ),
     23            BP_PLUGIN_DIR
     24        );
    7025    }
    7126
    72     do_action( 'messages_setup_nav' );
    73 }
    74 add_action( 'bp_setup_nav', 'messages_setup_nav' );
     27    /**
     28     * Include files
     29     */
     30    function _includes() {
     31        // Files to include
     32        $includes = array(
     33            'cssjs',
     34            'cache',
     35            'actions',
     36            'screens',
     37            'classes',
     38            'filters',
     39            'template',
     40            'functions',
     41        );
    7542
    76 /*******************************************************************************
    77  * These functions handle the recording, deleting and formatting of activity and
    78  * notifications for the user and for this specific component.
    79  */
    80 
    81 function messages_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
    82     global $bp;
    83 
    84     if ( 'new_message' == $action ) {
    85         if ( (int)$total_items > 1 )
    86             return apply_filters( 'bp_messages_multiple_new_message_notification', '<a href="' . $bp->loggedin_user->domain . $bp->messages->slug . '/inbox" title="' . __( 'Inbox', 'buddypress' ) . '">' . sprintf( __('You have %d new messages', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );
    87         else
    88             return apply_filters( 'bp_messages_single_new_message_notification', '<a href="' . $bp->loggedin_user->domain . $bp->messages->slug . '/inbox" title="' . __( 'Inbox', 'buddypress' ) . '">' . sprintf( __('You have %d new message', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );
     43        parent::_includes( $includes );
    8944    }
    9045
    91     do_action( 'messages_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
     46    /**
     47     * Setup globals
     48     *
     49     * The BP_MESSAGES_SLUG constant is deprecated, and only used here for
     50     * backwards compatibility.
     51     *
     52     * @since BuddyPress {unknown}
     53     * @global obj $bp
     54     */
     55    function _setup_globals() {
     56        global $bp;
    9257
    93     return false;
     58        // Define a slug, if necessary
     59        if ( !defined( 'BP_MESSAGES_SLUG' ) )
     60            define( 'BP_MESSAGES_SLUG', $this->id );
     61
     62        // Global tables for messaging component
     63        $global_tables = array(
     64            'table_name_notices'    => $bp->table_prefix . 'bp_messages_notices',
     65            'table_name_messages'   => $bp->table_prefix . 'bp_messages_messages',
     66            'table_name_recipients' => $bp->table_prefix . 'bp_messages_recipients'
     67        );
     68
     69        // All globals for messaging component.
     70        // Note that global_tables is included in this array.
     71        $globals = array(
     72            'slug'                  => BP_MESSAGES_SLUG,
     73            'root_slug'             => isset( $bp->pages->messages->slug ) ? $bp->pages->messages->slug : BP_MESSAGES_SLUG,
     74            'notification_callback' => 'messages_format_notifications',
     75            'search_string'         => __( 'Search Messages...', 'buddypress' ),
     76            'autocomplete_all'      => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ),
     77            'global_tables'         => $global_tables,
     78        );
     79
     80        parent::_setup_globals( $globals );
     81    }
     82
     83    /**
     84     * Setup BuddyBar navigation
     85     *
     86     * @global obj $bp
     87     */
     88    function _setup_nav() {
     89        global $bp;
     90
     91        if ( $count = messages_get_unread_count() )
     92            $name = sprintf( __( 'Messages <strong>(%s)</strong>', 'buddypress' ), $count );
     93        else
     94            $name = __( 'Messages <strong></strong>', 'buddypress' );
     95
     96        // Add 'Messages' to the main navigation
     97        $main_nav = array(
     98            'name'                    => $name,
     99            'slug'                    => $this->slug,
     100            'root_slug'               => $this->root_slug,
     101            'position'                => 50,
     102            'show_for_displayed_user' => false,
     103            'screen_function'         => 'messages_screen_inbox',
     104            'default_subnav_slug'     => 'inbox',
     105            'item_css_id'             => $this->id
     106        );
     107
     108        // Link to user messages
     109        $messages_link = trailingslashit( $bp->loggedin_user->domain . $this->slug );
     110
     111        // Add the subnav items to the profile
     112        $sub_nav[] = array(
     113            'name'            => __( 'Inbox', 'buddypress' ),
     114            'slug'            => 'inbox',
     115            'parent_url'      => $messages_link,
     116            'parent_slug'     => $this->slug,
     117            'screen_function' => 'messages_screen_inbox',
     118            'position'        => 10,
     119            'user_has_access' => bp_is_my_profile()
     120        );
     121
     122        $sub_nav[] = array(
     123            'name'            => __( 'Sent Messages', 'buddypress' ),
     124            'slug'            => 'sentbox',
     125            'parent_url'      => $messages_link,
     126            'parent_slug'     => $this->slug,
     127            'screen_function' => 'messages_screen_sentbox',
     128            'position'        => 20,
     129            'user_has_access' => bp_is_my_profile()
     130        );
     131
     132        $sub_nav[] = array(
     133            'name'            => __( 'Compose', 'buddypress' ),
     134            'slug'            => 'compose',
     135            'parent_url'      => $messages_link,
     136            'parent_slug'     => $this->slug,
     137            'screen_function' => 'messages_screen_compose',
     138            'position'        => 30,
     139            'user_has_access' => bp_is_my_profile()
     140        );
     141
     142        if ( is_super_admin() ) {
     143            $sub_nav[] = array(
     144                'name'            => __( 'Notices', 'buddypress' ),
     145                'slug'            => 'notices',
     146                'parent_url'      => $messages_link,
     147                'parent_slug'     => $this->slug,
     148                'screen_function' => 'messages_screen_notices',
     149                'position'        => 90,
     150                'user_has_access' => is_super_admin()
     151            );
     152        }
     153
     154        if ( bp_is_messages_component() ) {
     155            if ( bp_is_my_profile() ) {
     156                $bp->bp_options_title = __( 'My Messages', 'buddypress' );
     157            } else {
     158                $bp->bp_options_avatar = bp_core_fetch_avatar( array(
     159                    'item_id' => $bp->displayed_user->id,
     160                    'type'    => 'thumb'
     161                ) );
     162                $bp->bp_options_title = $bp->displayed_user->fullname;
     163            }
     164        }
     165
     166        parent::_setup_nav( $main_nav, $sub_nav );
     167    }
    94168}
    95 
    96 /*******************************************************************************
    97  * Caching functions handle the clearing of cached objects and pages on specific
    98  * actions throughout BuddyPress.
    99  */
    100 
    101 // List actions to clear super cached pages on, if super cache is installed
    102 add_action( 'messages_delete_thread',  'bp_core_clear_cache' );
    103 add_action( 'messages_send_notice',    'bp_core_clear_cache' );
    104 add_action( 'messages_message_sent',   'bp_core_clear_cache' );
    105 
    106 // Don't cache message inbox/sentbox/compose as it's too problematic
    107 add_action( 'messages_screen_compose', 'bp_core_clear_cache' );
    108 add_action( 'messages_screen_sentbox', 'bp_core_clear_cache' );
    109 add_action( 'messages_screen_inbox',   'bp_core_clear_cache' );
     169// Create the messages component
     170$bp->messages = new BP_Messages_Component();
    110171
    111172?>
Note: See TracChangeset for help on using the changeset viewer.