[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Activity Streams Loader. 4 * 5 * An activity stream component, for users, groups, and site tracking. 6 * 7 * @package BuddyPress 8 * @subpackage ActivityCore 9 * @since 1.5.0 10 */ 11 12 // Exit if accessed directly. 13 defined( 'ABSPATH' ) || exit; 14 15 /** 16 * Main Activity Class. 17 * 18 * @since 1.5.0 19 */ 20 class BP_Activity_Component extends BP_Component { 21 22 /** 23 * Start the activity component setup process. 24 * 25 * @since 1.5.0 26 */ 27 public function __construct() { 28 parent::start( 29 'activity', 30 __( 'Activity Streams', 'buddypress' ), 31 buddypress()->plugin_dir, 32 array( 33 'adminbar_myaccount_order' => 10, 34 'search_query_arg' => 'activity_search', 35 'features' => array( 'embeds' ) 36 ) 37 ); 38 } 39 40 /** 41 * Include component files. 42 * 43 * @since 1.5.0 44 * 45 * @see BP_Component::includes() for a description of arguments. 46 * 47 * @param array $includes See BP_Component::includes() for a description. 48 */ 49 public function includes( $includes = array() ) { 50 51 // Files to include. 52 $includes = array( 53 'cssjs', 54 'filters', 55 'adminbar', 56 'template', 57 'functions', 58 'cache', 59 'blocks', 60 ); 61 62 // Notifications support. 63 if ( bp_is_active( 'notifications' ) ) { 64 $includes[] = 'notifications'; 65 } 66 67 // Load Akismet support if Akismet is configured. 68 $akismet_key = bp_get_option( 'wordpress_api_key' ); 69 70 /** This filter is documented in bp-activity/bp-activity-akismet.php */ 71 if ( defined( 'AKISMET_VERSION' ) && class_exists( 'Akismet' ) && ( ! empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) && apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) { 72 $includes[] = 'akismet'; 73 } 74 75 // Embeds. 76 if ( bp_is_active( $this->id, 'embeds' ) ) { 77 $includes[] = 'embeds'; 78 } 79 80 if ( is_admin() ) { 81 $includes[] = 'admin'; 82 } 83 84 parent::includes( $includes ); 85 } 86 87 /** 88 * Late includes method. 89 * 90 * Only load up certain code when on specific pages. 91 * 92 * @since 3.0.0 93 */ 94 public function late_includes() { 95 // Bail if PHPUnit is running. 96 if ( defined( 'BP_TESTS_DIR' ) ) { 97 return; 98 } 99 100 /* 101 * Load activity action and screen code if PHPUnit isn't running. 102 * 103 * For PHPUnit, we load these files in tests/phpunit/includes/install.php. 104 */ 105 if ( bp_is_current_component( 'activity' ) ) { 106 // Authenticated actions - Only fires when JS is disabled. 107 if ( is_user_logged_in() && 108 in_array( bp_current_action(), array( 'delete', 'spam', 'post', 'reply', 'favorite', 'unfavorite' ), true ) 109 ) { 110 require $this->path . 'bp-activity/actions/' . bp_current_action() . '.php'; 111 } 112 113 // RSS feeds. 114 if ( bp_is_current_action( 'feed' ) || bp_is_action_variable( 'feed', 0 ) ) { 115 require $this->path . 'bp-activity/actions/feeds.php'; 116 } 117 118 // Screens - Directory. 119 if ( bp_is_activity_directory() ) { 120 require $this->path . 'bp-activity/screens/directory.php'; 121 } 122 123 // Screens - User main nav. 124 if ( bp_is_user() ) { 125 require $this->path . 'bp-activity/screens/just-me.php'; 126 } 127 128 /** 129 * Screens - User secondary nav. 130 * 131 * For these specific actions, slugs can be customized using `BP_{COMPONENT}_SLUGS`. 132 * As a result, we need to map filenames with slugs. 133 */ 134 $filenames = array( 135 'favorites' => 'favorites', 136 'mentions' => 'mentions', 137 ); 138 139 if ( bp_is_active( 'friends' ) ) { 140 $filenames[bp_get_friends_slug()] = 'friends'; 141 } 142 143 if ( bp_is_active( 'groups' ) ) { 144 $filenames[bp_get_groups_slug()] = 'groups'; 145 } 146 147 // The slug is the current action requested. 148 $slug = bp_current_action(); 149 150 if ( bp_is_user() && isset( $filenames[ $slug ] ) ) { 151 require $this->path . 'bp-activity/screens/' . $filenames[ $slug ] . '.php'; 152 } 153 154 // Screens - Single permalink. 155 if ( bp_is_current_action( 'p' ) || is_numeric( bp_current_action() ) ) { 156 require $this->path . 'bp-activity/screens/permalink.php'; 157 } 158 159 // Theme compatibility. 160 new BP_Activity_Theme_Compat(); 161 } 162 } 163 164 /** 165 * Set up component global variables. 166 * 167 * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for 168 * backwards compatibility. 169 * 170 * @since 1.5.0 171 * 172 * @see BP_Component::setup_globals() for a description of arguments. 173 * 174 * @param array $args See BP_Component::setup_globals() for a description. 175 */ 176 public function setup_globals( $args = array() ) { 177 $bp = buddypress(); 178 179 // Define a slug, if necessary. 180 if ( ! defined( 'BP_ACTIVITY_SLUG' ) ) { 181 define( 'BP_ACTIVITY_SLUG', $this->id ); 182 } 183 184 // Global tables for activity component. 185 $global_tables = array( 186 'table_name' => $bp->table_prefix . 'bp_activity', 187 'table_name_meta' => $bp->table_prefix . 'bp_activity_meta', 188 ); 189 190 // Metadata tables for groups component. 191 $meta_tables = array( 192 'activity' => $bp->table_prefix . 'bp_activity_meta', 193 ); 194 195 // Fetch the default directory title. 196 $default_directory_titles = bp_core_get_directory_page_default_titles(); 197 $default_directory_title = $default_directory_titles[$this->id]; 198 199 // All globals for activity component. 200 // Note that global_tables is included in this array. 201 $args = array( 202 'slug' => BP_ACTIVITY_SLUG, 203 'root_slug' => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG, 204 'has_directory' => true, 205 'directory_title' => isset( $bp->pages->activity->title ) ? $bp->pages->activity->title : $default_directory_title, 206 'notification_callback' => 'bp_activity_format_notifications', 207 'search_string' => __( 'Search Activity...', 'buddypress' ), 208 'global_tables' => $global_tables, 209 'meta_tables' => $meta_tables, 210 ); 211 212 parent::setup_globals( $args ); 213 } 214 215 /** 216 * Set up component navigation. 217 * 218 * @since 1.5.0 219 * 220 * @see BP_Component::setup_nav() for a description of arguments. 221 * 222 * @param array $main_nav Optional. See BP_Component::setup_nav() for description. 223 * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. 224 */ 225 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 226 227 // Stop if there is no user displayed or logged in. 228 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 229 return; 230 } 231 232 // Determine user to use. 233 if ( bp_displayed_user_domain() ) { 234 $user_domain = bp_displayed_user_domain(); 235 } elseif ( bp_loggedin_user_domain() ) { 236 $user_domain = bp_loggedin_user_domain(); 237 } else { 238 return; 239 } 240 241 $slug = bp_get_activity_slug(); 242 $activity_link = trailingslashit( $user_domain . $slug ); 243 244 // Add 'Activity' to the main navigation. 245 $main_nav = array( 246 'name' => _x( 'Activity', 'Profile activity screen nav', 'buddypress' ), 247 'slug' => $slug, 248 'position' => 10, 249 'screen_function' => 'bp_activity_screen_my_activity', 250 'default_subnav_slug' => 'just-me', 251 'item_css_id' => $this->id 252 ); 253 254 // Add the subnav items to the activity nav item if we are using a theme that supports this. 255 $sub_nav[] = array( 256 'name' => _x( 'Personal', 'Profile activity screen sub nav', 'buddypress' ), 257 'slug' => 'just-me', 258 'parent_url' => $activity_link, 259 'parent_slug' => $slug, 260 'screen_function' => 'bp_activity_screen_my_activity', 261 'position' => 10 262 ); 263 264 // Check @mentions. 265 if ( bp_activity_do_mentions() ) { 266 $sub_nav[] = array( 267 'name' => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ), 268 'slug' => 'mentions', 269 'parent_url' => $activity_link, 270 'parent_slug' => $slug, 271 'screen_function' => 'bp_activity_screen_mentions', 272 'position' => 20, 273 'item_css_id' => 'activity-mentions' 274 ); 275 } 276 277 // Favorite activity items. 278 if ( bp_activity_can_favorite() ) { 279 $sub_nav[] = array( 280 'name' => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ), 281 'slug' => 'favorites', 282 'parent_url' => $activity_link, 283 'parent_slug' => $slug, 284 'screen_function' => 'bp_activity_screen_favorites', 285 'position' => 30, 286 'item_css_id' => 'activity-favs' 287 ); 288 } 289 290 // Additional menu if friends is active. 291 if ( bp_is_active( 'friends' ) ) { 292 $sub_nav[] = array( 293 'name' => _x( 'Friends', 'Profile activity screen sub nav', 'buddypress' ), 294 'slug' => bp_get_friends_slug(), 295 'parent_url' => $activity_link, 296 'parent_slug' => $slug, 297 'screen_function' => 'bp_activity_screen_friends', 298 'position' => 40, 299 'item_css_id' => 'activity-friends' 300 ) ; 301 } 302 303 // Additional menu if groups is active. 304 if ( bp_is_active( 'groups' ) ) { 305 $sub_nav[] = array( 306 'name' => _x( 'Groups', 'Profile activity screen sub nav', 'buddypress' ), 307 'slug' => bp_get_groups_slug(), 308 'parent_url' => $activity_link, 309 'parent_slug' => $slug, 310 'screen_function' => 'bp_activity_screen_groups', 311 'position' => 50, 312 'item_css_id' => 'activity-groups' 313 ); 314 } 315 316 parent::setup_nav( $main_nav, $sub_nav ); 317 } 318 319 /** 320 * Set up the component entries in the WordPress Admin Bar. 321 * 322 * @since 1.5.0 323 * 324 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav 325 * parameter array. 326 * 327 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a 328 * description. 329 */ 330 public function setup_admin_bar( $wp_admin_nav = array() ) { 331 332 // Menus for logged in user. 333 if ( is_user_logged_in() ) { 334 335 // Setup the logged in user variables. 336 $activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() ); 337 338 // Unread message count. 339 if ( bp_activity_do_mentions() ) { 340 $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() ); 341 if ( !empty( $count ) ) { 342 $title = sprintf( 343 /* translators: %s: Unread mention count for the current user */ 344 _x( 'Mentions %s', 'Toolbar Mention logged in user', 'buddypress' ), 345 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 346 ); 347 } else { 348 $title = _x( 'Mentions', 'Toolbar Mention logged in user', 'buddypress' ); 349 } 350 } 351 352 // Add the "Activity" sub menu. 353 $wp_admin_nav[] = array( 354 'parent' => buddypress()->my_account_menu_id, 355 'id' => 'my-account-' . $this->id, 356 'title' => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ), 357 'href' => $activity_link 358 ); 359 360 // Personal. 361 $wp_admin_nav[] = array( 362 'parent' => 'my-account-' . $this->id, 363 'id' => 'my-account-' . $this->id . '-personal', 364 'title' => _x( 'Personal', 'My Account Activity sub nav', 'buddypress' ), 365 'href' => $activity_link, 366 'position' => 10 367 ); 368 369 // Mentions. 370 if ( bp_activity_do_mentions() ) { 371 $wp_admin_nav[] = array( 372 'parent' => 'my-account-' . $this->id, 373 'id' => 'my-account-' . $this->id . '-mentions', 374 'title' => $title, 375 'href' => trailingslashit( $activity_link . 'mentions' ), 376 'position' => 20 377 ); 378 } 379 380 // Favorite activity items. 381 if ( bp_activity_can_favorite() ) { 382 $wp_admin_nav[] = array( 383 'parent' => 'my-account-' . $this->id, 384 'id' => 'my-account-' . $this->id . '-favorites', 385 'title' => _x( 'Favorites', 'My Account Activity sub nav', 'buddypress' ), 386 'href' => trailingslashit( $activity_link . 'favorites' ), 387 'position' => 30 388 ); 389 } 390 391 // Friends? 392 if ( bp_is_active( 'friends' ) ) { 393 $wp_admin_nav[] = array( 394 'parent' => 'my-account-' . $this->id, 395 'id' => 'my-account-' . $this->id . '-friends', 396 'title' => _x( 'Friends', 'My Account Activity sub nav', 'buddypress' ), 397 'href' => trailingslashit( $activity_link . bp_get_friends_slug() ), 398 'position' => 40 399 ); 400 } 401 402 // Groups? 403 if ( bp_is_active( 'groups' ) ) { 404 $wp_admin_nav[] = array( 405 'parent' => 'my-account-' . $this->id, 406 'id' => 'my-account-' . $this->id . '-groups', 407 'title' => _x( 'Groups', 'My Account Activity sub nav', 'buddypress' ), 408 'href' => trailingslashit( $activity_link . bp_get_groups_slug() ), 409 'position' => 50 410 ); 411 } 412 } 413 414 parent::setup_admin_bar( $wp_admin_nav ); 415 } 416 417 /** 418 * Set up the title for pages and <title>. 419 * 420 * @since 1.5.0 421 * 422 */ 423 public function setup_title() { 424 425 // Adjust title based on view. 426 if ( bp_is_activity_component() ) { 427 $bp = buddypress(); 428 429 if ( bp_is_my_profile() ) { 430 $bp->bp_options_title = _x( 'My Activity', 'Page and <title>', 'buddypress' ); 431 } else { 432 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 433 'item_id' => bp_displayed_user_id(), 434 'type' => 'thumb', 435 'alt' => sprintf( 436 /* translators: %s: member name */ 437 __( 'Profile picture of %s', 'buddypress' ), 438 bp_get_displayed_user_fullname() 439 ), 440 ) ); 441 $bp->bp_options_title = bp_get_displayed_user_fullname(); 442 } 443 } 444 445 parent::setup_title(); 446 } 447 448 /** 449 * Setup cache groups. 450 * 451 * @since 2.2.0 452 */ 453 public function setup_cache_groups() { 454 455 // Global groups. 456 wp_cache_add_global_groups( array( 457 'bp_activity', 458 'bp_activity_comments', 459 'activity_meta' 460 ) ); 461 462 parent::setup_cache_groups(); 463 } 464 465 /** 466 * Init the BP REST API. 467 * 468 * @since 5.0.0 469 * 470 * @param array $controllers Optional. See BP_Component::rest_api_init() for 471 * description. 472 */ 473 public function rest_api_init( $controllers = array() ) { 474 parent::rest_api_init( array( 'BP_REST_Activity_Endpoint' ) ); 475 } 476 477 /** 478 * Register the BP Activity Blocks. 479 * 480 * @since 7.0.0 481 * 482 * @param array $blocks Optional. See BP_Component::blocks_init() for 483 * description. 484 */ 485 public function blocks_init( $blocks = array() ) { 486 parent::blocks_init( 487 array( 488 'bp/embed-activity' => array( 489 'name' => 'bp/embed-activity', 490 'editor_script' => 'bp-embed-activity-block', 491 'editor_script_url' => plugins_url( 'js/blocks/embed-activity.js', dirname( __FILE__ ) ), 492 'editor_script_deps' => array( 493 'wp-blocks', 494 'wp-element', 495 'wp-i18n', 496 'wp-components', 497 'wp-block-editor', 498 'wp-data', 499 'wp-compose', 500 ), 501 ), 502 ) 503 ); 504 } 505 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Jan 18 01:01:36 2021 | Cross-referenced by PHPXref 0.7.1 |