Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 04:08:04 AM (10 years ago)
Author:
boonebgorges
Message:

Move bp-blogs classes to their own files.

See #6870.

File:
1 edited

Legend:

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

    r10417 r10517  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Creates our Blogs component.
    19  */
    20 class BP_Blogs_Component extends BP_Component {
    21 
    22     /**
    23      * Start the blogs component creation process.
    24      *
    25      * @since 1.5.0
    26      */
    27     public function __construct() {
    28         parent::start(
    29             'blogs',
    30             __( 'Site Directory', 'buddypress' ),
    31             buddypress()->plugin_dir,
    32             array(
    33                 'adminbar_myaccount_order' => 30,
    34                 'search_query_arg' => 'sites_search',
    35             )
    36         );
    37     }
    38 
    39     /**
    40      * Set up global settings for the blogs component.
    41      *
    42      * The BP_BLOGS_SLUG constant is deprecated, and only used here for
    43      * backwards compatibility.
    44      *
    45      * @since 1.5.0
    46      *
    47      * @see BP_Component::setup_globals() for description of parameters.
    48      *
    49      * @param array $args See {@link BP_Component::setup_globals()}.
    50      */
    51     public function setup_globals( $args = array() ) {
    52         $bp = buddypress();
    53 
    54         if ( ! defined( 'BP_BLOGS_SLUG' ) ) {
    55             define ( 'BP_BLOGS_SLUG', $this->id );
    56         }
    57 
    58         // Global tables for messaging component.
    59         $global_tables = array(
    60             'table_name'          => $bp->table_prefix . 'bp_user_blogs',
    61             'table_name_blogmeta' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
    62         );
    63 
    64         $meta_tables = array(
    65             'blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
    66         );
    67 
    68         // All globals for blogs component.
    69         $args = array(
    70             'slug'                  => BP_BLOGS_SLUG,
    71             'root_slug'             => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,
    72             'has_directory'         => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site.
    73             'directory_title'       => _x( 'Sites', 'component directory title', 'buddypress' ),
    74             'notification_callback' => 'bp_blogs_format_notifications',
    75             'search_string'         => __( 'Search sites...', 'buddypress' ),
    76             'autocomplete_all'      => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ),
    77             'global_tables'         => $global_tables,
    78             'meta_tables'           => $meta_tables,
    79         );
    80 
    81         // Setup the globals.
    82         parent::setup_globals( $args );
    83 
    84         /**
    85          * Filters if a blog is public.
    86          *
    87          * In case the config is not multisite, the blog_public option is ignored.
    88          *
    89          * @since 2.3.0
    90          *
    91          * @param int $value Whether or not the blog is public.
    92          */
    93         if ( 0 !== apply_filters( 'bp_is_blog_public', (int) get_option( 'blog_public' ) ) || ! is_multisite() ) {
    94 
    95             /**
    96              * Filters the post types to track for the Blogs component.
    97              *
    98              * @since 1.5.0
    99              * @deprecated 2.3.0
    100              *
    101              * @param array $value Array of post types to track.
    102              */
    103             $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
    104 
    105             foreach ( $post_types as $post_type ) {
    106                 add_post_type_support( $post_type, 'buddypress-activity' );
    107             }
    108         }
    109 
    110         // Filter the generic track parameters for the 'post' post type.
    111         add_filter( 'bp_activity_get_post_type_tracking_args', array( $this, 'post_tracking_args' ), 10, 2 );
    112     }
    113 
    114     /**
    115      * Include bp-blogs files.
    116      *
    117      * @see BP_Component::includes() for description of parameters.
    118      *
    119      * @param array $includes See {@link BP_Component::includes()}.
    120      */
    121     public function includes( $includes = array() ) {
    122 
    123         // Files to include.
    124         $includes = array(
    125             'cache',
    126             'actions',
    127             'screens',
    128             'classes',
    129             'template',
    130             'filters',
    131             'activity',
    132             'functions',
    133         );
    134 
    135         if ( is_multisite() ) {
    136             $includes[] = 'widgets';
    137         }
    138 
    139         // Include the files.
    140         parent::includes( $includes );
    141     }
    142 
    143     /**
    144      * Set up component navigation for bp-blogs.
    145      *
    146      * @see BP_Component::setup_nav() for a description of arguments.
    147      *
    148      * @param array $main_nav Optional. See BP_Component::setup_nav() for
    149      *                        description.
    150      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
    151      *                        description.
    152      */
    153     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    154 
    155         /**
    156          * Blog/post/comment menus should not appear on single WordPress setups.
    157          * Although comments and posts made by users will still show on their
    158          * activity stream.
    159          */
    160         if ( ! is_multisite() ) {
    161             return false;
    162         }
    163 
    164         // Determine user to use.
    165         if ( bp_displayed_user_domain() ) {
    166             $user_domain = bp_displayed_user_domain();
    167         } elseif ( bp_loggedin_user_domain() ) {
    168             $user_domain = bp_loggedin_user_domain();
    169         } else {
    170             return;
    171         }
    172 
    173         $slug       = bp_get_blogs_slug();
    174         $parent_url = trailingslashit( $user_domain . $slug );
    175 
    176         // Add 'Sites' to the main navigation.
    177         $count    = (int) bp_get_total_blog_count_for_user();
    178         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    179         $nav_text = sprintf( __( 'Sites <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count )  );
    180         $main_nav = array(
    181             'name'                => $nav_text,
    182             'slug'                => $slug,
    183             'position'            => 30,
    184             'screen_function'     => 'bp_blogs_screen_my_blogs',
    185             'default_subnav_slug' => 'my-sites',
    186             'item_css_id'         => $this->id
    187         );
    188 
    189         $sub_nav[] = array(
    190             'name'            => __( 'My Sites', 'buddypress' ),
    191             'slug'            => 'my-sites',
    192             'parent_url'      => $parent_url,
    193             'parent_slug'     => $slug,
    194             'screen_function' => 'bp_blogs_screen_my_blogs',
    195             'position'        => 10
    196         );
    197 
    198         // Setup navigation.
    199         parent::setup_nav( $main_nav, $sub_nav );
    200     }
    201 
    202     /**
    203      * Set up bp-blogs integration with the WordPress admin bar.
    204      *
    205      * @since 1.5.0
    206      *
    207      * @see BP_Component::setup_admin_bar() for a description of arguments.
    208      *
    209      * @param array $wp_admin_nav See BP_Component::setup_admin_bar()
    210      *                            for description.
    211      * @return bool
    212      */
    213     public function setup_admin_bar( $wp_admin_nav = array() ) {
    214 
    215         /**
    216          * Site/post/comment menus should not appear on single WordPress setups.
    217          *
    218          * Comments and posts made by users will still show in their activity.
    219          */
    220         if ( ! is_multisite() ) {
    221             return false;
    222         }
    223 
    224         // Menus for logged in user.
    225         if ( is_user_logged_in() ) {
    226 
    227             // Setup the logged in user variables.
    228             $blogs_link = trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() );
    229 
    230             // Add the "Sites" sub menu.
    231             $wp_admin_nav[] = array(
    232                 'parent' => buddypress()->my_account_menu_id,
    233                 'id'     => 'my-account-' . $this->id,
    234                 'title'  => __( 'Sites', 'buddypress' ),
    235                 'href'   => $blogs_link
    236             );
    237 
    238             // My Sites.
    239             $wp_admin_nav[] = array(
    240                 'parent' => 'my-account-' . $this->id,
    241                 'id'     => 'my-account-' . $this->id . '-my-sites',
    242                 'title'  => __( 'My Sites', 'buddypress' ),
    243                 'href'   => $blogs_link
    244             );
    245 
    246             // Create a Site.
    247             if ( bp_blog_signup_enabled() ) {
    248                 $wp_admin_nav[] = array(
    249                     'parent' => 'my-account-' . $this->id,
    250                     'id'     => 'my-account-' . $this->id . '-create',
    251                     'title'  => __( 'Create a Site', 'buddypress' ),
    252                     'href'   => trailingslashit( bp_get_blogs_directory_permalink() . 'create' )
    253                 );
    254             }
    255         }
    256 
    257         parent::setup_admin_bar( $wp_admin_nav );
    258     }
    259 
    260     /**
    261      * Set up the title for pages and <title>.
    262      */
    263     public function setup_title() {
    264 
    265         // Set up the component options navigation for Site.
    266         if ( bp_is_blogs_component() ) {
    267             $bp = buddypress();
    268 
    269             if ( bp_is_my_profile() ) {
    270                 if ( bp_is_active( 'xprofile' ) ) {
    271                     $bp->bp_options_title = __( 'My Sites', 'buddypress' );
    272                 }
    273 
    274             // If we are not viewing the logged in user, set up the current
    275             // users avatar and name.
    276             } else {
    277                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    278                     'item_id' => bp_displayed_user_id(),
    279                     'type'    => 'thumb',
    280                     'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
    281                 ) );
    282                 $bp->bp_options_title = bp_get_displayed_user_fullname();
    283             }
    284         }
    285 
    286         parent::setup_title();
    287     }
    288 
    289     /**
    290      * Setup cache groups
    291      *
    292      * @since 2.2.0
    293      */
    294     public function setup_cache_groups() {
    295 
    296         // Global groups.
    297         wp_cache_add_global_groups( array(
    298             'blog_meta'
    299         ) );
    300 
    301         parent::setup_cache_groups();
    302     }
    303 
    304     /**
    305      * Set up the tracking arguments for the 'post' post type.
    306      *
    307      * @since 2.2.0
    308      *
    309      * @see bp_activity_get_post_type_tracking_args() for information on parameters.
    310      *
    311      * @param object|null $params    Tracking arguments.
    312      * @param string|int  $post_type Post type to track.
    313      * @return object
    314      */
    315     public function post_tracking_args( $params = null, $post_type = 0 ) {
    316 
    317         /**
    318          * Filters the post types to track for the Blogs component.
    319          *
    320          * @since 1.5.0
    321          * @deprecated 2.3.0
    322          *
    323          * Make sure plugins still using 'bp_blogs_record_post_post_types'
    324          * to track their post types will generate new_blog_post activities
    325          * See https://buddypress.trac.wordpress.org/ticket/6306
    326          *
    327          * @param array $value Array of post types to track.
    328          */
    329         $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
    330         $post_types_array = array_flip( $post_types );
    331 
    332         if ( ! isset( $post_types_array[ $post_type ] ) ) {
    333             return $params;
    334         }
    335 
    336         // Set specific params for the 'post' post type.
    337         $params->component_id    = $this->id;
    338         $params->action_id       = 'new_blog_post';
    339         $params->admin_filter    = __( 'New post published', 'buddypress' );
    340         $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post';
    341         $params->front_filter    = __( 'Posts', 'buddypress' );
    342         $params->contexts        = array( 'activity', 'member' );
    343         $params->position        = 5;
    344 
    345         return $params;
    346     }
    347 }
     17require dirname( __FILE__ ) . '/classes/class-bp-blogs-component.php';
    34818
    34919/**
Note: See TracChangeset for help on using the changeset viewer.