Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 04:37:45 AM (8 years ago)
Author:
boonebgorges
Message:

Move bp-friends classes to their own files.

See #6870.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/bp-friends-loader.php

    r10417 r10519  
    1313defined( 'ABSPATH' ) || exit;
    1414
    15 /**
    16  * Defines the BuddyPress Friends Component.
    17  */
    18 class BP_Friends_Component extends BP_Component {
    19 
    20     /**
    21      * Start the friends component creation process.
    22      *
    23      * @since 1.5.0
    24      */
    25     public function __construct() {
    26         parent::start(
    27             'friends',
    28             _x( 'Friend Connections', 'Friends screen page <title>', 'buddypress' ),
    29             buddypress()->plugin_dir,
    30             array(
    31                 'adminbar_myaccount_order' => 60
    32             )
    33         );
    34     }
    35 
    36     /**
    37      * Include bp-friends files.
    38      *
    39      * @see BP_Component::includes() for description of parameters.
    40      *
    41      * @param array $includes See {@link BP_Component::includes()}.
    42      */
    43     public function includes( $includes = array() ) {
    44         $includes = array(
    45             'cache',
    46             'actions',
    47             'screens',
    48             'filters',
    49             'classes',
    50             'activity',
    51             'template',
    52             'functions',
    53             'notifications',
    54             'widgets',
    55         );
    56 
    57         parent::includes( $includes );
    58     }
    59 
    60     /**
    61      * Set up bp-friends global settings.
    62      *
    63      * The BP_FRIENDS_SLUG constant is deprecated, and only used here for
    64      * backwards compatibility.
    65      *
    66      * @since 1.5.0
    67      *
    68      * @see BP_Component::setup_globals() for description of parameters.
    69      *
    70      * @param array $args See {@link BP_Component::setup_globals()}.
    71      */
    72     public function setup_globals( $args = array() ) {
    73         $bp = buddypress();
    74 
    75         // Deprecated. Do not use.
    76         // Defined conditionally to support unit tests.
    77         if ( ! defined( 'BP_FRIENDS_DB_VERSION' ) ) {
    78             define( 'BP_FRIENDS_DB_VERSION', '1800' );
    79         }
    80 
    81         // Define a slug, if necessary.
    82         if ( ! defined( 'BP_FRIENDS_SLUG' ) ) {
    83             define( 'BP_FRIENDS_SLUG', $this->id );
    84         }
    85 
    86         // Global tables for the friends component.
    87         $global_tables = array(
    88             'table_name'      => $bp->table_prefix . 'bp_friends',
    89             'table_name_meta' => $bp->table_prefix . 'bp_friends_meta',
    90         );
    91 
    92         // All globals for the friends component.
    93         // Note that global_tables is included in this array.
    94         $args = array(
    95             'slug'                  => BP_FRIENDS_SLUG,
    96             'has_directory'         => false,
    97             'search_string'         => __( 'Search Friends...', 'buddypress' ),
    98             'notification_callback' => 'friends_format_notifications',
    99             'global_tables'         => $global_tables
    100         );
    101 
    102         parent::setup_globals( $args );
    103     }
    104 
    105     /**
    106      * Set up component navigation.
    107      *
    108      * @since 1.5.0
    109      *
    110      * @see BP_Component::setup_nav() for a description of arguments.
    111      *
    112      * @param array $main_nav Optional. See BP_Component::setup_nav() for
    113      *                        description.
    114      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
    115      *                        description.
    116      */
    117     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    118 
    119         // Determine user to use.
    120         if ( bp_displayed_user_domain() ) {
    121             $user_domain = bp_displayed_user_domain();
    122         } elseif ( bp_loggedin_user_domain() ) {
    123             $user_domain = bp_loggedin_user_domain();
    124         } else {
    125             return;
    126         }
    127 
    128         $access       = bp_core_can_edit_settings();
    129         $slug         = bp_get_friends_slug();
    130         $friends_link = trailingslashit( $user_domain . $slug );
    131 
    132         // Add 'Friends' to the main navigation.
    133         $count    = friends_get_total_friend_count();
    134         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    135         $main_nav = array(
    136             'name'                => sprintf( __( 'Friends <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) ),
    137             'slug'                => $slug,
    138             'position'            => 60,
    139             'screen_function'     => 'friends_screen_my_friends',
    140             'default_subnav_slug' => 'my-friends',
    141             'item_css_id'         => $this->id
    142         );
    143 
    144         // Add the subnav items to the friends nav item.
    145         $sub_nav[] = array(
    146             'name'            => _x( 'Friendships', 'Friends screen sub nav', 'buddypress' ),
    147             'slug'            => 'my-friends',
    148             'parent_url'      => $friends_link,
    149             'parent_slug'     => $slug,
    150             'screen_function' => 'friends_screen_my_friends',
    151             'position'        => 10,
    152             'item_css_id'     => 'friends-my-friends'
    153         );
    154 
    155         $sub_nav[] = array(
    156             'name'            => _x( 'Requests', 'Friends screen sub nav', 'buddypress' ),
    157             'slug'            => 'requests',
    158             'parent_url'      => $friends_link,
    159             'parent_slug'     => $slug,
    160             'screen_function' => 'friends_screen_requests',
    161             'position'        => 20,
    162             'user_has_access' => $access
    163         );
    164 
    165         parent::setup_nav( $main_nav, $sub_nav );
    166     }
    167 
    168     /**
    169      * Set up bp-friends integration with the WordPress admin bar.
    170      *
    171      * @since 1.5.0
    172      *
    173      * @see BP_Component::setup_admin_bar() for a description of arguments.
    174      *
    175      * @param array $wp_admin_nav See BP_Component::setup_admin_bar()
    176      *                            for description.
    177      */
    178     public function setup_admin_bar( $wp_admin_nav = array() ) {
    179 
    180         // Menus for logged in user.
    181         if ( is_user_logged_in() ) {
    182 
    183             // Setup the logged in user variables.
    184             $friends_link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() );
    185 
    186             // Pending friend requests.
    187             $count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) );
    188             if ( !empty( $count ) ) {
    189                 $title   = sprintf( _x( 'Friends <span class="count">%s</span>',          'My Account Friends menu',         'buddypress' ), bp_core_number_format( $count ) );
    190                 $pending = sprintf( _x( 'Pending Requests <span class="count">%s</span>', 'My Account Friends menu sub nav', 'buddypress' ), bp_core_number_format( $count ) );
    191             } else {
    192                 $title   = _x( 'Friends',            'My Account Friends menu',         'buddypress' );
    193                 $pending = _x( 'No Pending Requests','My Account Friends menu sub nav', 'buddypress' );
    194             }
    195 
    196             // Add the "My Account" sub menus.
    197             $wp_admin_nav[] = array(
    198                 'parent' => buddypress()->my_account_menu_id,
    199                 'id'     => 'my-account-' . $this->id,
    200                 'title'  => $title,
    201                 'href'   => $friends_link
    202             );
    203 
    204             // My Friends.
    205             $wp_admin_nav[] = array(
    206                 'parent' => 'my-account-' . $this->id,
    207                 'id'     => 'my-account-' . $this->id . '-friendships',
    208                 'title'  => _x( 'Friendships', 'My Account Friends menu sub nav', 'buddypress' ),
    209                 'href'   => $friends_link
    210             );
    211 
    212             // Requests.
    213             $wp_admin_nav[] = array(
    214                 'parent' => 'my-account-' . $this->id,
    215                 'id'     => 'my-account-' . $this->id . '-requests',
    216                 'title'  => $pending,
    217                 'href'   => trailingslashit( $friends_link . 'requests' )
    218             );
    219         }
    220 
    221         parent::setup_admin_bar( $wp_admin_nav );
    222     }
    223 
    224     /**
    225      * Set up the title for pages and <title>.
    226      */
    227     public function setup_title() {
    228 
    229         // Adjust title.
    230         if ( bp_is_friends_component() ) {
    231             $bp = buddypress();
    232 
    233             if ( bp_is_my_profile() ) {
    234                 $bp->bp_options_title = __( 'Friendships', 'buddypress' );
    235             } else {
    236                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    237                     'item_id' => bp_displayed_user_id(),
    238                     'type'    => 'thumb',
    239                     'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
    240                 ) );
    241                 $bp->bp_options_title = bp_get_displayed_user_fullname();
    242             }
    243         }
    244 
    245         parent::setup_title();
    246     }
    247 
    248     /**
    249      * Setup cache groups.
    250      *
    251      * @since 2.2.0
    252      */
    253     public function setup_cache_groups() {
    254 
    255         // Global groups.
    256         wp_cache_add_global_groups( array(
    257             'bp_friends_requests'
    258         ) );
    259 
    260         parent::setup_cache_groups();
    261     }
    262 }
     15require dirname( __FILE__ ) . '/classes/class-bp-friends-component.php';
    26316
    26417/**
Note: See TracChangeset for help on using the changeset viewer.