PluginProbe
bbPress / trunk
bbPress vtrunk
2.6.19 2.6.18 2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 All 74 releases
bbpress / includes / extend / buddypress / loader.php

loader.php in bbPress trunk, at includes/extend/buddypress/loader.php

417 lines 11.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress BuddyPress Component Class.
5 *
6 * bbPress and BuddyPress are designed to connect together seamlessly and
7 * invisibly, and this is the hunk of code necessary to make that happen.
8 *
9 * The code in this BuddyPress Extension does some pretty complicated stuff,
10 * far outside the realm of the simplicity bbPress is traditionally known for.
11 *
12 * While the rest of bbPress serves as an example of how to write pretty, simple
13 * code, what's in these files is pure madness. It should not be used as an
14 * example of anything other than successfully juggling chainsaws and puppy-dogs.
15 *
16 * @package bbPress
17 * @subpackage BuddyPress
18 */
19
20 // Exit if accessed directly
21 defined( 'ABSPATH' ) || exit;
22
23 if ( ! class_exists( 'BBP_Forums_Component' ) ) :
24 /**
25 * Loads Forums Component.
26 *
27 * @since 2.1.0 bbPress (r3552)
28 *
29 * @package bbPress
30 * @subpackage BuddyPress
31 */
32 class BBP_Forums_Component extends BP_Component {
33
34 /**
35 * BuddyPress Members component shim.
36 *
37 * @since 2.6.14 bbPress (r7305)
38 *
39 * @var void|BBP_BuddyPress_Members
40 */
41 public $members;
42
43 /**
44 * BuddyPress Activity component shim.
45 *
46 * @since 2.6.14 bbPress (r7305)
47 *
48 * @var void|BBP_BuddyPress_Members
49 */
50 public $activity;
51
52 /**
53 * Start the forums component creation process.
54 *
55 * @since 2.1.0 bbPress (r3552)
56 */
57 public function __construct() {
58 parent::start(
59 'forums',
60 esc_html__( 'Forums', 'bbpress' ),
61 bbpress()->includes_dir . 'extend/buddypress/'
62 );
63 $this->includes();
64 $this->setup_globals();
65 $this->setup_actions();
66 $this->fully_loaded();
67 }
68
69 /**
70 * Include BuddyPress classes and functions.
71 */
72 public function includes( $includes = array() ) {
73
74 // Helper BuddyPress functions
75 $includes[] = 'functions.php';
76
77 // Members modifications
78 $includes[] = 'members.php';
79
80 // BuddyPress Notfications Extension functions
81 if ( bp_is_active( 'notifications' ) ) {
82 $includes[] = 'notifications.php';
83 }
84
85 // BuddyPress Activity Extension class
86 if ( bp_is_active( 'activity' ) ) {
87 $includes[] = 'activity.php';
88 }
89
90 // BuddyPress Group Extension class
91 if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
92 $includes[] = 'groups.php';
93 }
94
95 // Require files if they exist
96 foreach ( $includes as $file ) {
97
98 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
99 if ( @is_file( $this->path . $file ) ) {
100 require $this->path . $file;
101 }
102 }
103
104 /**
105 * Hook for plugins to include files, if necessary.
106 *
107 * @since 2.6.0 bbPress (r3552)
108 */
109 do_action( "bp_{$this->id}_includes" );
110 }
111
112 /**
113 * Setup globals.
114 *
115 * The BP_FORUMS_SLUG constant is deprecated, and only used here for
116 * backwards compatibility.
117 *
118 * @since 2.1.0 bbPress (r3552)
119 */
120 public function setup_globals( $args = array() ) {
121 $bp = buddypress();
122
123 // Define the parent forum ID
124 if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
125 define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
126 }
127
128 // Define a slug, if necessary
129 if ( ! defined( 'BP_FORUMS_SLUG' ) ) {
130 define( 'BP_FORUMS_SLUG', $this->id );
131 }
132
133 // All arguments for forums component
134 $args = array(
135 'path' => BP_PLUGIN_DIR,
136 'slug' => BP_FORUMS_SLUG,
137 'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG,
138 'has_directory' => false,
139 'search_string' => esc_html__( 'Search Forums...', 'bbpress' ),
140 );
141
142 parent::setup_globals( $args );
143 }
144
145 /**
146 * Setup the actions.
147 *
148 * @since 2.2.0 bbPress (r4397)
149 *
150 * @access private
151 * @link https://bbpress.trac.wordpress.org/ticket/2176
152 */
153 public function setup_actions() {
154
155 // Setup the components
156 add_action( 'bp_init', array( $this, 'setup_components' ), 7 );
157
158 /** Dependencies ******************************************************/
159
160 // Allow plugins to modify these actions
161 do_action_ref_array( 'bbp_extend_buddypress_loaded', array( &$this ) );
162
163 parent::setup_actions();
164 }
165
166 /**
167 * Instantiate classes for BuddyPress integration.
168 *
169 * @since 2.6.0 bbPress (r5271)
170 */
171 public function setup_components() {
172
173 // Always load the members component
174 bbpress()->extend->buddypress->members = new BBP_BuddyPress_Members();
175
176 // Create new activity class
177 if ( bp_is_active( 'activity' ) ) {
178 bbpress()->extend->buddypress->activity = new BBP_BuddyPress_Activity();
179 }
180
181 // Register the group extension only if groups are active
182 if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
183 bp_register_group_extension( 'BBP_Forums_Group_Extension' );
184 }
185 }
186
187 /**
188 * Allow the variables, actions, and filters to be modified by third party
189 * plugins and themes.
190 *
191 * @since 2.6.0 bbPress (r5271)
192 */
193 private function fully_loaded() {
194 do_action_ref_array( 'bbp_buddypress_loaded', array( $this ) );
195 }
196
197 /**
198 * Setup BuddyBar navigation.
199 *
200 * @since 2.1.0 bbPress (r3552)
201 */
202 public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
203
204 // Stop if there is no user displayed or logged in
205 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
206 return;
207 }
208
209 // Define local variable(s)
210 $user_domain = '';
211
212 // Add 'Forums' to the main navigation
213 $main_nav = array(
214 'name' => esc_html__( 'Forums', 'bbpress' ),
215 'slug' => $this->slug,
216 'position' => 80,
217 'screen_function' => 'bbp_member_forums_screen_topics',
218 'default_subnav_slug' => bbp_get_topic_archive_slug(),
219 'item_css_id' => $this->id
220 );
221
222 // Determine user to use
223 if ( bp_displayed_user_id() ) {
224 $user_domain = bp_displayed_user_domain();
225 } elseif ( bp_loggedin_user_domain() ) {
226 $user_domain = bp_loggedin_user_domain();
227 } else {
228 return;
229 }
230
231 // User link
232 $forums_link = trailingslashit( $user_domain . $this->slug );
233
234 // Topics started
235 $sub_nav[] = array(
236 'name' => esc_html__( 'Topics Started', 'bbpress' ),
237 'slug' => bbp_get_topic_archive_slug(),
238 'parent_url' => $forums_link,
239 'parent_slug' => $this->slug,
240 'screen_function' => 'bbp_member_forums_screen_topics',
241 'position' => 20,
242 'item_css_id' => 'topics'
243 );
244
245 // Replies to topics
246 $sub_nav[] = array(
247 'name' => esc_html__( 'Replies Created', 'bbpress' ),
248 'slug' => bbp_get_reply_archive_slug(),
249 'parent_url' => $forums_link,
250 'parent_slug' => $this->slug,
251 'screen_function' => 'bbp_member_forums_screen_replies',
252 'position' => 40,
253 'item_css_id' => 'replies'
254 );
255
256 // Engagements
257 if ( bbp_is_engagements_active() ) {
258 $sub_nav[] = array(
259 'name' => esc_html__( 'Engagements', 'bbpress' ),
260 'slug' => bbp_get_user_engagements_slug(),
261 'parent_url' => $forums_link,
262 'parent_slug' => $this->slug,
263 'screen_function' => 'bbp_member_forums_screen_engagements',
264 'position' => 60,
265 'item_css_id' => 'engagements'
266 );
267 }
268
269 // Favorite topics
270 if ( bbp_is_favorites_active() ) {
271 $sub_nav[] = array(
272 'name' => esc_html__( 'Favorites', 'bbpress' ),
273 'slug' => bbp_get_user_favorites_slug(),
274 'parent_url' => $forums_link,
275 'parent_slug' => $this->slug,
276 'screen_function' => 'bbp_member_forums_screen_favorites',
277 'position' => 80,
278 'item_css_id' => 'favorites'
279 );
280 }
281
282 // Subscribed topics (my profile only)
283 if ( bp_is_my_profile() && bbp_is_subscriptions_active() ) {
284 $sub_nav[] = array(
285 'name' => esc_html__( 'Subscriptions', 'bbpress' ),
286 'slug' => bbp_get_user_subscriptions_slug(),
287 'parent_url' => $forums_link,
288 'parent_slug' => $this->slug,
289 'screen_function' => 'bbp_member_forums_screen_subscriptions',
290 'position' => 100,
291 'item_css_id' => 'subscriptions'
292 );
293 }
294
295 parent::setup_nav( $main_nav, $sub_nav );
296 }
297
298 /**
299 * Set up the admin bar.
300 *
301 * @since 2.1.0 bbPress (r3552)
302 */
303 public function setup_admin_bar( $wp_admin_nav = array() ) {
304
305 // Menus for logged in user
306 if ( is_user_logged_in() ) {
307
308 // If BuddyPress is network activated and bbPress is
309 // not activated on a the root blog but on any child one
310 if ( ! bp_is_root_blog() ) {
311 $user_id = bbp_get_current_user_id();
312 $my_account_link = bbp_get_user_profile_url( $user_id );
313 $my_topics_link = bbp_get_user_topics_created_url( $user_id );
314 $my_replies_link = bbp_get_user_replies_created_url( $user_id );
315 $my_engagements_link = bbp_get_user_engagements_url( $user_id );
316 $my_favorites_link = bbp_get_favorites_permalink( $user_id );
317 $my_subscriptions_link = bbp_get_subscriptions_permalink( $user_id );
318 } else {
319
320 // Setup the logged in user variables
321 $user_domain = bp_loggedin_user_domain();
322 $forums_link = trailingslashit( $user_domain . $this->slug );
323
324 $my_account_link = trailingslashit( $forums_link );
325 $my_topics_link = trailingslashit( $forums_link . bbp_get_topic_archive_slug() );
326 $my_replies_link = trailingslashit( $forums_link . bbp_get_reply_archive_slug() );
327 $my_engagements_link = trailingslashit( $forums_link . bbp_get_user_engagements_slug() );
328 $my_favorites_link = trailingslashit( $forums_link . bbp_get_user_favorites_slug() );
329 $my_subscriptions_link = trailingslashit( $forums_link . bbp_get_user_subscriptions_slug() );
330 }
331
332 // Add the "My Account" sub menus
333 $wp_admin_nav[] = array(
334 'parent' => buddypress()->my_account_menu_id,
335 'id' => 'my-account-' . $this->id,
336 'title' => esc_html__( 'Forums', 'bbpress' ),
337 'href' => $my_account_link
338 );
339
340 // Topics
341 $wp_admin_nav[] = array(
342 'parent' => 'my-account-' . $this->id,
343 'id' => 'my-account-' . $this->id . '-topics',
344 'title' => esc_html__( 'Topics Started', 'bbpress' ),
345 'href' => $my_topics_link
346 );
347
348 // Replies
349 $wp_admin_nav[] = array(
350 'parent' => 'my-account-' . $this->id,
351 'id' => 'my-account-' . $this->id . '-replies',
352 'title' => esc_html__( 'Replies Created', 'bbpress' ),
353 'href' => $my_replies_link
354 );
355
356 // Engagements
357 if ( bbp_is_engagements_active() ) {
358 $wp_admin_nav[] = array(
359 'parent' => 'my-account-' . $this->id,
360 'id' => 'my-account-' . $this->id . '-engagements',
361 'title' => esc_html__( 'Engagements', 'bbpress' ),
362 'href' => $my_engagements_link
363 );
364 }
365
366 // Favorites
367 if ( bbp_is_favorites_active() ) {
368 $wp_admin_nav[] = array(
369 'parent' => 'my-account-' . $this->id,
370 'id' => 'my-account-' . $this->id . '-favorites',
371 'title' => esc_html__( 'Favorite Topics', 'bbpress' ),
372 'href' => $my_favorites_link
373 );
374 }
375
376 // Subscriptions
377 if ( bbp_is_subscriptions_active() ) {
378 $wp_admin_nav[] = array(
379 'parent' => 'my-account-' . $this->id,
380 'id' => 'my-account-' . $this->id . '-subscriptions',
381 'title' => esc_html__( 'Subscribed Topics', 'bbpress' ),
382 'href' => $my_subscriptions_link
383 );
384 }
385 }
386
387 parent::setup_admin_bar( $wp_admin_nav );
388 }
389
390 /**
391 * Sets up the title for pages and <title>.
392 *
393 * @since 2.1.0 bbPress (r3552)
394 */
395 public function setup_title() {
396 $bp = buddypress();
397
398 // Adjust title based on view
399 if ( bp_is_forums_component() ) {
400 if ( bp_is_my_profile() ) {
401 $bp->bp_options_title = esc_html__( 'Forums', 'bbpress' );
402 } elseif ( bp_is_user() ) {
403 $bp->bp_options_avatar = bp_core_fetch_avatar(
404 array(
405 'item_id' => bp_displayed_user_id(),
406 'type' => 'thumb'
407 )
408 );
409 $bp->bp_options_title = bp_get_displayed_user_fullname();
410 }
411 }
412
413 parent::setup_title();
414 }
415 }
416 endif;
417