Changeset 10516 for trunk/src/bp-activity/bp-activity-loader.php
- Timestamp:
- 02/05/2016 03:54:56 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-activity/bp-activity-loader.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-loader.php
r10455 r10516 13 13 defined( 'ABSPATH' ) || exit; 14 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 ) 36 ); 37 } 38 39 /** 40 * Include component files. 41 * 42 * @since 1.5.0 43 * 44 * @see BP_Component::includes() for a description of arguments. 45 * 46 * @param array $includes See BP_Component::includes() for a description. 47 */ 48 public function includes( $includes = array() ) { 49 50 // Files to include. 51 $includes = array( 52 'cssjs', 53 'actions', 54 'screens', 55 'filters', 56 'classes', 57 'template', 58 'functions', 59 'notifications', 60 'cache' 61 ); 62 63 // Load Akismet support if Akismet is configured. 64 $akismet_key = bp_get_option( 'wordpress_api_key' ); 65 66 /** This filter is documented in bp-activity/bp-activity-actions.php */ 67 if ( defined( 'AKISMET_VERSION' ) && class_exists( 'Akismet' ) && ( ! empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) && apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) { 68 $includes[] = 'akismet'; 69 } 70 71 if ( is_admin() ) { 72 $includes[] = 'admin'; 73 } 74 75 parent::includes( $includes ); 76 } 77 78 /** 79 * Set up component global variables. 80 * 81 * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for 82 * backwards compatibility. 83 * 84 * @since 1.5.0 85 * 86 * @see BP_Component::setup_globals() for a description of arguments. 87 * 88 * @param array $args See BP_Component::setup_globals() for a description. 89 */ 90 public function setup_globals( $args = array() ) { 91 $bp = buddypress(); 92 93 // Define a slug, if necessary. 94 if ( ! defined( 'BP_ACTIVITY_SLUG' ) ) { 95 define( 'BP_ACTIVITY_SLUG', $this->id ); 96 } 97 98 // Global tables for activity component. 99 $global_tables = array( 100 'table_name' => $bp->table_prefix . 'bp_activity', 101 'table_name_meta' => $bp->table_prefix . 'bp_activity_meta', 102 ); 103 104 // Metadata tables for groups component. 105 $meta_tables = array( 106 'activity' => $bp->table_prefix . 'bp_activity_meta', 107 ); 108 109 // All globals for activity component. 110 // Note that global_tables is included in this array. 111 $args = array( 112 'slug' => BP_ACTIVITY_SLUG, 113 'root_slug' => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG, 114 'has_directory' => true, 115 'directory_title' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ), 116 'notification_callback' => 'bp_activity_format_notifications', 117 'search_string' => __( 'Search Activity...', 'buddypress' ), 118 'global_tables' => $global_tables, 119 'meta_tables' => $meta_tables, 120 ); 121 122 parent::setup_globals( $args ); 123 } 124 125 /** 126 * Set up component navigation. 127 * 128 * @since 1.5.0 129 * 130 * @see BP_Component::setup_nav() for a description of arguments. 131 * @uses bp_is_active() 132 * @uses is_user_logged_in() 133 * @uses bp_get_friends_slug() 134 * @uses bp_get_groups_slug() 135 * 136 * @param array $main_nav Optional. See BP_Component::setup_nav() for description. 137 * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. 138 */ 139 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 140 141 // Stop if there is no user displayed or logged in. 142 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 143 return; 144 } 145 146 // Determine user to use. 147 if ( bp_displayed_user_domain() ) { 148 $user_domain = bp_displayed_user_domain(); 149 } elseif ( bp_loggedin_user_domain() ) { 150 $user_domain = bp_loggedin_user_domain(); 151 } else { 152 return; 153 } 154 155 $slug = bp_get_activity_slug(); 156 $activity_link = trailingslashit( $user_domain . $slug ); 157 158 // Add 'Activity' to the main navigation. 159 $main_nav = array( 160 'name' => _x( 'Activity', 'Profile activity screen nav', 'buddypress' ), 161 'slug' => $slug, 162 'position' => 10, 163 'screen_function' => 'bp_activity_screen_my_activity', 164 'default_subnav_slug' => 'just-me', 165 'item_css_id' => $this->id 166 ); 167 168 // Add the subnav items to the activity nav item if we are using a theme that supports this. 169 $sub_nav[] = array( 170 'name' => _x( 'Personal', 'Profile activity screen sub nav', 'buddypress' ), 171 'slug' => 'just-me', 172 'parent_url' => $activity_link, 173 'parent_slug' => $slug, 174 'screen_function' => 'bp_activity_screen_my_activity', 175 'position' => 10 176 ); 177 178 // Check @mentions. 179 if ( bp_activity_do_mentions() ) { 180 $sub_nav[] = array( 181 'name' => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ), 182 'slug' => 'mentions', 183 'parent_url' => $activity_link, 184 'parent_slug' => $slug, 185 'screen_function' => 'bp_activity_screen_mentions', 186 'position' => 20, 187 'item_css_id' => 'activity-mentions' 188 ); 189 } 190 191 // Favorite activity items. 192 if ( bp_activity_can_favorite() ) { 193 $sub_nav[] = array( 194 'name' => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ), 195 'slug' => 'favorites', 196 'parent_url' => $activity_link, 197 'parent_slug' => $slug, 198 'screen_function' => 'bp_activity_screen_favorites', 199 'position' => 30, 200 'item_css_id' => 'activity-favs' 201 ); 202 } 203 204 // Additional menu if friends is active. 205 if ( bp_is_active( 'friends' ) ) { 206 $sub_nav[] = array( 207 'name' => _x( 'Friends', 'Profile activity screen sub nav', 'buddypress' ), 208 'slug' => bp_get_friends_slug(), 209 'parent_url' => $activity_link, 210 'parent_slug' => $slug, 211 'screen_function' => 'bp_activity_screen_friends', 212 'position' => 40, 213 'item_css_id' => 'activity-friends' 214 ) ; 215 } 216 217 // Additional menu if groups is active. 218 if ( bp_is_active( 'groups' ) ) { 219 $sub_nav[] = array( 220 'name' => _x( 'Groups', 'Profile activity screen sub nav', 'buddypress' ), 221 'slug' => bp_get_groups_slug(), 222 'parent_url' => $activity_link, 223 'parent_slug' => $slug, 224 'screen_function' => 'bp_activity_screen_groups', 225 'position' => 50, 226 'item_css_id' => 'activity-groups' 227 ); 228 } 229 230 parent::setup_nav( $main_nav, $sub_nav ); 231 } 232 233 /** 234 * Set up the component entries in the WordPress Admin Bar. 235 * 236 * @since 1.5.0 237 * 238 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav 239 * parameter array. 240 * @uses is_user_logged_in() 241 * @uses trailingslashit() 242 * @uses bp_get_total_mention_count_for_user() 243 * @uses bp_loggedin_user_id() 244 * @uses bp_is_active() 245 * @uses bp_get_friends_slug() 246 * @uses bp_get_groups_slug() 247 * 248 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a 249 * description. 250 */ 251 public function setup_admin_bar( $wp_admin_nav = array() ) { 252 253 // Menus for logged in user. 254 if ( is_user_logged_in() ) { 255 256 // Setup the logged in user variables. 257 $activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() ); 258 259 // Unread message count. 260 if ( bp_activity_do_mentions() ) { 261 $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() ); 262 if ( !empty( $count ) ) { 263 $title = sprintf( _x( 'Mentions <span class="count">%s</span>', 'Toolbar Mention logged in user', 'buddypress' ), bp_core_number_format( $count ) ); 264 } else { 265 $title = _x( 'Mentions', 'Toolbar Mention logged in user', 'buddypress' ); 266 } 267 } 268 269 // Add the "Activity" sub menu. 270 $wp_admin_nav[] = array( 271 'parent' => buddypress()->my_account_menu_id, 272 'id' => 'my-account-' . $this->id, 273 'title' => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ), 274 'href' => $activity_link 275 ); 276 277 // Personal. 278 $wp_admin_nav[] = array( 279 'parent' => 'my-account-' . $this->id, 280 'id' => 'my-account-' . $this->id . '-personal', 281 'title' => _x( 'Personal', 'My Account Activity sub nav', 'buddypress' ), 282 'href' => $activity_link 283 ); 284 285 // Mentions. 286 if ( bp_activity_do_mentions() ) { 287 $wp_admin_nav[] = array( 288 'parent' => 'my-account-' . $this->id, 289 'id' => 'my-account-' . $this->id . '-mentions', 290 'title' => $title, 291 'href' => trailingslashit( $activity_link . 'mentions' ) 292 ); 293 } 294 295 // Favorite activity items. 296 if ( bp_activity_can_favorite() ) { 297 $wp_admin_nav[] = array( 298 'parent' => 'my-account-' . $this->id, 299 'id' => 'my-account-' . $this->id . '-favorites', 300 'title' => _x( 'Favorites', 'My Account Activity sub nav', 'buddypress' ), 301 'href' => trailingslashit( $activity_link . 'favorites' ) 302 ); 303 } 304 305 // Friends? 306 if ( bp_is_active( 'friends' ) ) { 307 $wp_admin_nav[] = array( 308 'parent' => 'my-account-' . $this->id, 309 'id' => 'my-account-' . $this->id . '-friends', 310 'title' => _x( 'Friends', 'My Account Activity sub nav', 'buddypress' ), 311 'href' => trailingslashit( $activity_link . bp_get_friends_slug() ) 312 ); 313 } 314 315 // Groups? 316 if ( bp_is_active( 'groups' ) ) { 317 $wp_admin_nav[] = array( 318 'parent' => 'my-account-' . $this->id, 319 'id' => 'my-account-' . $this->id . '-groups', 320 'title' => _x( 'Groups', 'My Account Activity sub nav', 'buddypress' ), 321 'href' => trailingslashit( $activity_link . bp_get_groups_slug() ) 322 ); 323 } 324 } 325 326 parent::setup_admin_bar( $wp_admin_nav ); 327 } 328 329 /** 330 * Set up the title for pages and <title>. 331 * 332 * @since 1.5.0 333 * 334 * @uses bp_is_activity_component() 335 * @uses bp_is_my_profile() 336 * @uses bp_core_fetch_avatar() 337 */ 338 public function setup_title() { 339 340 // Adjust title based on view. 341 if ( bp_is_activity_component() ) { 342 $bp = buddypress(); 343 344 if ( bp_is_my_profile() ) { 345 $bp->bp_options_title = _x( 'My Activity', 'Page and <title>', 'buddypress' ); 346 } else { 347 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 348 'item_id' => bp_displayed_user_id(), 349 'type' => 'thumb', 350 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 351 ) ); 352 $bp->bp_options_title = bp_get_displayed_user_fullname(); 353 } 354 } 355 356 parent::setup_title(); 357 } 358 359 /** 360 * Set up actions necessary for the component. 361 * 362 * @since 1.6.0 363 */ 364 public function setup_actions() { 365 366 // Spam prevention. 367 add_action( 'bp_include', 'bp_activity_setup_akismet' ); 368 369 parent::setup_actions(); 370 } 371 372 /** 373 * Setup cache groups. 374 * 375 * @since 2.2.0 376 */ 377 public function setup_cache_groups() { 378 379 // Global groups. 380 wp_cache_add_global_groups( array( 381 'bp_activity', 382 'bp_activity_comments', 383 'activity_meta' 384 ) ); 385 386 parent::setup_cache_groups(); 387 } 388 } 15 require dirname( __FILE__ ) . '/classes/class-bp-activity-component.php'; 389 16 390 17 /**
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)