BP_Activity_Component

Main Activity Class.

Defined (1)

The class is defined in the following location(s).

/bp-activity/classes/class-bp-activity-component.php  
  1. class BP_Activity_Component extends BP_Component { 
  2.  
  3. /** 
  4. * Start the activity component setup process. 
  5. * @since 1.5.0 
  6. */ 
  7. public function __construct() { 
  8. parent::start( 
  9. 'activity',  
  10. __( 'Activity Streams', 'buddypress' ),  
  11. buddypress()->plugin_dir,  
  12. array( 
  13. 'adminbar_myaccount_order' => 10,  
  14. 'search_query_arg' => 'activity_search',  
  15. 'features' => array( 'embeds' ) 
  16. ); 
  17.  
  18. /** 
  19. * Include component files. 
  20. * @since 1.5.0 
  21. * @see BP_Component::includes() for a description of arguments. 
  22. * @param array $includes See BP_Component::includes() for a description. 
  23. */ 
  24. public function includes( $includes = array() ) { 
  25.  
  26. // Files to include. 
  27. $includes = array( 
  28. 'cssjs',  
  29. 'actions',  
  30. 'screens',  
  31. 'filters',  
  32. 'adminbar',  
  33. 'template',  
  34. 'functions',  
  35. 'cache' 
  36. ); 
  37.  
  38. // Notifications support. 
  39. if ( bp_is_active( 'notifications' ) ) { 
  40. $includes[] = 'notifications'; 
  41.  
  42. // Load Akismet support if Akismet is configured. 
  43. $akismet_key = bp_get_option( 'wordpress_api_key' ); 
  44.  
  45. /** This filter is documented in bp-activity/bp-activity-akismet.php */ 
  46. if ( defined( 'AKISMET_VERSION' ) && class_exists( 'Akismet' ) && ( ! empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) && apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) { 
  47. $includes[] = 'akismet'; 
  48.  
  49. // Embeds - only applicable for WP 4.5+ 
  50. if ( version_compare( $GLOBALS['wp_version'], '4.5', '>=' ) && bp_is_active( $this->id, 'embeds' ) ) { 
  51. $includes[] = 'embeds'; 
  52.  
  53. if ( is_admin() ) { 
  54. $includes[] = 'admin'; 
  55.  
  56. parent::includes( $includes ); 
  57.  
  58. /** 
  59. * Set up component global variables. 
  60. * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for 
  61. * backwards compatibility. 
  62. * @since 1.5.0 
  63. * @see BP_Component::setup_globals() for a description of arguments. 
  64. * @param array $args See BP_Component::setup_globals() for a description. 
  65. */ 
  66. public function setup_globals( $args = array() ) { 
  67. $bp = buddypress(); 
  68.  
  69. // Define a slug, if necessary. 
  70. if ( ! defined( 'BP_ACTIVITY_SLUG' ) ) { 
  71. define( 'BP_ACTIVITY_SLUG', $this->id ); 
  72.  
  73. // Global tables for activity component. 
  74. $global_tables = array( 
  75. 'table_name' => $bp->table_prefix . 'bp_activity',  
  76. 'table_name_meta' => $bp->table_prefix . 'bp_activity_meta',  
  77. ); 
  78.  
  79. // Metadata tables for groups component. 
  80. $meta_tables = array( 
  81. 'activity' => $bp->table_prefix . 'bp_activity_meta',  
  82. ); 
  83.  
  84. // Fetch the default directory title. 
  85. $default_directory_titles = bp_core_get_directory_page_default_titles(); 
  86. $default_directory_title = $default_directory_titles[$this->id]; 
  87.  
  88. // All globals for activity component. 
  89. // Note that global_tables is included in this array. 
  90. $args = array( 
  91. 'slug' => BP_ACTIVITY_SLUG,  
  92. 'root_slug' => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,  
  93. 'has_directory' => true,  
  94. 'directory_title' => isset( $bp->pages->activity->title ) ? $bp->pages->activity->title : $default_directory_title,  
  95. 'notification_callback' => 'bp_activity_format_notifications',  
  96. 'search_string' => __( 'Search Activity...', 'buddypress' ),  
  97. 'global_tables' => $global_tables,  
  98. 'meta_tables' => $meta_tables,  
  99. ); 
  100.  
  101. parent::setup_globals( $args ); 
  102.  
  103. /** 
  104. * Set up component navigation. 
  105. * @since 1.5.0 
  106. * @see BP_Component::setup_nav() for a description of arguments. 
  107. * @param array $main_nav Optional. See BP_Component::setup_nav() for description. 
  108. * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. 
  109. */ 
  110. public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 
  111.  
  112. // Stop if there is no user displayed or logged in. 
  113. if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 
  114. return; 
  115.  
  116. // Determine user to use. 
  117. if ( bp_displayed_user_domain() ) { 
  118. $user_domain = bp_displayed_user_domain(); 
  119. } elseif ( bp_loggedin_user_domain() ) { 
  120. $user_domain = bp_loggedin_user_domain(); 
  121. } else { 
  122. return; 
  123.  
  124. $slug = bp_get_activity_slug(); 
  125. $activity_link = trailingslashit( $user_domain . $slug ); 
  126.  
  127. // Add 'Activity' to the main navigation. 
  128. $main_nav = array( 
  129. 'name' => _x( 'Activity', 'Profile activity screen nav', 'buddypress' ),  
  130. 'slug' => $slug,  
  131. 'position' => 10,  
  132. 'screen_function' => 'bp_activity_screen_my_activity',  
  133. 'default_subnav_slug' => 'just-me',  
  134. 'item_css_id' => $this->id 
  135. ); 
  136.  
  137. // Add the subnav items to the activity nav item if we are using a theme that supports this. 
  138. $sub_nav[] = array( 
  139. 'name' => _x( 'Personal', 'Profile activity screen sub nav', 'buddypress' ),  
  140. 'slug' => 'just-me',  
  141. 'parent_url' => $activity_link,  
  142. 'parent_slug' => $slug,  
  143. 'screen_function' => 'bp_activity_screen_my_activity',  
  144. 'position' => 10 
  145. ); 
  146.  
  147. // Check @mentions. 
  148. if ( bp_activity_do_mentions() ) { 
  149. $sub_nav[] = array( 
  150. 'name' => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ),  
  151. 'slug' => 'mentions',  
  152. 'parent_url' => $activity_link,  
  153. 'parent_slug' => $slug,  
  154. 'screen_function' => 'bp_activity_screen_mentions',  
  155. 'position' => 20,  
  156. 'item_css_id' => 'activity-mentions' 
  157. ); 
  158.  
  159. // Favorite activity items. 
  160. if ( bp_activity_can_favorite() ) { 
  161. $sub_nav[] = array( 
  162. 'name' => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ),  
  163. 'slug' => 'favorites',  
  164. 'parent_url' => $activity_link,  
  165. 'parent_slug' => $slug,  
  166. 'screen_function' => 'bp_activity_screen_favorites',  
  167. 'position' => 30,  
  168. 'item_css_id' => 'activity-favs' 
  169. ); 
  170.  
  171. // Additional menu if friends is active. 
  172. if ( bp_is_active( 'friends' ) ) { 
  173. $sub_nav[] = array( 
  174. 'name' => _x( 'Friends', 'Profile activity screen sub nav', 'buddypress' ),  
  175. 'slug' => bp_get_friends_slug(),  
  176. 'parent_url' => $activity_link,  
  177. 'parent_slug' => $slug,  
  178. 'screen_function' => 'bp_activity_screen_friends',  
  179. 'position' => 40,  
  180. 'item_css_id' => 'activity-friends' 
  181. ) ; 
  182.  
  183. // Additional menu if groups is active. 
  184. if ( bp_is_active( 'groups' ) ) { 
  185. $sub_nav[] = array( 
  186. 'name' => _x( 'Groups', 'Profile activity screen sub nav', 'buddypress' ),  
  187. 'slug' => bp_get_groups_slug(),  
  188. 'parent_url' => $activity_link,  
  189. 'parent_slug' => $slug,  
  190. 'screen_function' => 'bp_activity_screen_groups',  
  191. 'position' => 50,  
  192. 'item_css_id' => 'activity-groups' 
  193. ); 
  194.  
  195. parent::setup_nav( $main_nav, $sub_nav ); 
  196.  
  197. /** 
  198. * Set up the component entries in the WordPress Admin Bar. 
  199. * @since 1.5.0 
  200. * @see BP_Component::setup_nav() for a description of the $wp_admin_nav 
  201. * parameter array. 
  202. * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a 
  203. * description. 
  204. */ 
  205. public function setup_admin_bar( $wp_admin_nav = array() ) { 
  206.  
  207. // Menus for logged in user. 
  208. if ( is_user_logged_in() ) { 
  209.  
  210. // Setup the logged in user variables. 
  211. $activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() ); 
  212.  
  213. // Unread message count. 
  214. if ( bp_activity_do_mentions() ) { 
  215. $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() ); 
  216. if ( !empty( $count ) ) { 
  217. $title = sprintf( 
  218. /** translators: %s: Unread mention count for the current user */ 
  219. _x( 'Mentions %s', 'Toolbar Mention logged in user', 'buddypress' ),  
  220. '<span class="count">' . bp_core_number_format( $count ) . '</span>' 
  221. ); 
  222. } else { 
  223. $title = _x( 'Mentions', 'Toolbar Mention logged in user', 'buddypress' ); 
  224.  
  225. // Add the "Activity" sub menu. 
  226. $wp_admin_nav[] = array( 
  227. 'parent' => buddypress()->my_account_menu_id,  
  228. 'id' => 'my-account-' . $this->id,  
  229. 'title' => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ),  
  230. 'href' => $activity_link 
  231. ); 
  232.  
  233. // Personal. 
  234. $wp_admin_nav[] = array( 
  235. 'parent' => 'my-account-' . $this->id,  
  236. 'id' => 'my-account-' . $this->id . '-personal',  
  237. 'title' => _x( 'Personal', 'My Account Activity sub nav', 'buddypress' ),  
  238. 'href' => $activity_link,  
  239. 'position' => 10 
  240. ); 
  241.  
  242. // Mentions. 
  243. if ( bp_activity_do_mentions() ) { 
  244. $wp_admin_nav[] = array( 
  245. 'parent' => 'my-account-' . $this->id,  
  246. 'id' => 'my-account-' . $this->id . '-mentions',  
  247. 'title' => $title,  
  248. 'href' => trailingslashit( $activity_link . 'mentions' ),  
  249. 'position' => 20 
  250. ); 
  251.  
  252. // Favorite activity items. 
  253. if ( bp_activity_can_favorite() ) { 
  254. $wp_admin_nav[] = array( 
  255. 'parent' => 'my-account-' . $this->id,  
  256. 'id' => 'my-account-' . $this->id . '-favorites',  
  257. 'title' => _x( 'Favorites', 'My Account Activity sub nav', 'buddypress' ),  
  258. 'href' => trailingslashit( $activity_link . 'favorites' ),  
  259. 'position' => 30 
  260. ); 
  261.  
  262. // Friends? 
  263. if ( bp_is_active( 'friends' ) ) { 
  264. $wp_admin_nav[] = array( 
  265. 'parent' => 'my-account-' . $this->id,  
  266. 'id' => 'my-account-' . $this->id . '-friends',  
  267. 'title' => _x( 'Friends', 'My Account Activity sub nav', 'buddypress' ),  
  268. 'href' => trailingslashit( $activity_link . bp_get_friends_slug() ),  
  269. 'position' => 40 
  270. ); 
  271.  
  272. // Groups? 
  273. if ( bp_is_active( 'groups' ) ) { 
  274. $wp_admin_nav[] = array( 
  275. 'parent' => 'my-account-' . $this->id,  
  276. 'id' => 'my-account-' . $this->id . '-groups',  
  277. 'title' => _x( 'Groups', 'My Account Activity sub nav', 'buddypress' ),  
  278. 'href' => trailingslashit( $activity_link . bp_get_groups_slug() ),  
  279. 'position' => 50 
  280. ); 
  281.  
  282. parent::setup_admin_bar( $wp_admin_nav ); 
  283.  
  284. /** 
  285. * Set up the title for pages and <title>. 
  286. * @since 1.5.0 
  287. */ 
  288. public function setup_title() { 
  289.  
  290. // Adjust title based on view. 
  291. if ( bp_is_activity_component() ) { 
  292. $bp = buddypress(); 
  293.  
  294. if ( bp_is_my_profile() ) { 
  295. $bp->bp_options_title = _x( 'My Activity', 'Page and <title>', 'buddypress' ); 
  296. } else { 
  297. $bp->bp_options_avatar = bp_core_fetch_avatar( array( 
  298. 'item_id' => bp_displayed_user_id(),  
  299. 'type' => 'thumb',  
  300. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 
  301. ) ); 
  302. $bp->bp_options_title = bp_get_displayed_user_fullname(); 
  303.  
  304. parent::setup_title(); 
  305.  
  306. /** 
  307. * Setup cache groups. 
  308. * @since 2.2.0 
  309. */ 
  310. public function setup_cache_groups() { 
  311.  
  312. // Global groups. 
  313. wp_cache_add_global_groups( array( 
  314. 'bp_activity',  
  315. 'bp_activity_comments',  
  316. 'activity_meta' 
  317. ) ); 
  318.  
  319. parent::setup_cache_groups();