29 * Setup bbPress group extension variables |
29 * Setup bbPress group extension variables |
30 * |
30 * |
31 * @since bbPress (r3552) |
31 * @since bbPress (r3552) |
32 */ |
32 */ |
33 public function __construct() { |
33 public function __construct() { |
|
34 $this->setup_variables(); |
|
35 $this->setup_actions(); |
|
36 $this->setup_filters(); |
|
37 $this->maybe_unset_forum_menu(); |
|
38 } |
|
39 |
|
40 /** |
|
41 * Setup the group forums class variables |
|
42 * |
|
43 * @since bbPress () |
|
44 */ |
|
45 private function setup_variables() { |
34 |
46 |
35 // Name and slug |
47 // Name and slug |
36 $this->name = __( 'Forum', 'bbpress' ); |
48 $this->name = __( 'Forum', 'bbpress' ); |
37 $this->nav_item_name = __( 'Forum', 'bbpress' ); |
49 $this->nav_item_name = __( 'Forum', 'bbpress' ); |
38 $this->slug = 'forum'; |
50 $this->slug = 'forum'; |
52 $this->enable_edit_item = true; |
64 $this->enable_edit_item = true; |
53 |
65 |
54 // Template file to load, and action to hook display on to |
66 // Template file to load, and action to hook display on to |
55 $this->template_file = 'groups/single/plugins'; |
67 $this->template_file = 'groups/single/plugins'; |
56 $this->display_hook = 'bp_template_content'; |
68 $this->display_hook = 'bp_template_content'; |
57 |
69 } |
58 // Add handlers to bp_actions |
70 |
59 add_action( 'bp_actions', 'bbp_new_forum_handler' ); |
71 /** |
60 add_action( 'bp_actions', 'bbp_new_topic_handler' ); |
72 * Setup the group forums class actions |
61 add_action( 'bp_actions', 'bbp_new_reply_handler' ); |
73 * |
62 add_action( 'bp_actions', 'bbp_edit_forum_handler' ); |
74 * @since bbPress (r4552) |
63 add_action( 'bp_actions', 'bbp_edit_topic_handler' ); |
75 */ |
64 add_action( 'bp_actions', 'bbp_edit_reply_handler' ); |
76 private function setup_actions() { |
65 |
77 |
66 // Possibly redirect |
78 // Possibly redirect |
67 add_action( 'bbp_template_redirect', array( $this, 'redirect_canonical' ) ); |
79 add_action( 'bbp_template_redirect', array( $this, 'redirect_canonical' ) ); |
|
80 |
|
81 // Remove topic cap map when view is done |
|
82 add_action( 'bbp_after_group_forum_display', array( $this, 'remove_topic_meta_cap_map' ) ); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Setup the group forums class filters |
|
87 * |
|
88 * @since bbPress (r4552) |
|
89 */ |
|
90 private function setup_filters() { |
68 |
91 |
69 // Group forum pagination |
92 // Group forum pagination |
70 add_filter( 'bbp_topic_pagination', array( $this, 'topic_pagination' ) ); |
93 add_filter( 'bbp_topic_pagination', array( $this, 'topic_pagination' ) ); |
71 add_filter( 'bbp_replies_pagination', array( $this, 'replies_pagination' ) ); |
94 add_filter( 'bbp_replies_pagination', array( $this, 'replies_pagination' ) ); |
72 |
95 |
89 |
112 |
90 // Allow group member to view private/hidden forums |
113 // Allow group member to view private/hidden forums |
91 add_filter( 'bbp_map_topic_meta_caps', array( $this, 'map_topic_meta_caps' ), 10, 4 ); |
114 add_filter( 'bbp_map_topic_meta_caps', array( $this, 'map_topic_meta_caps' ), 10, 4 ); |
92 add_filter( 'bbp_map_reply_meta_caps', array( $this, 'map_topic_meta_caps' ), 10, 4 ); |
115 add_filter( 'bbp_map_reply_meta_caps', array( $this, 'map_topic_meta_caps' ), 10, 4 ); |
93 |
116 |
94 // Remove topic cap map when view is done |
|
95 add_action( 'bbp_after_group_forum_display', array( $this, 'remove_topic_meta_cap_map' ) ); |
|
96 |
|
97 // Map group forum activity items to groups |
117 // Map group forum activity items to groups |
98 add_filter( 'bbp_before_record_activity_parse_args', array( $this, 'map_activity_to_group' ) ); |
118 add_filter( 'bbp_before_record_activity_parse_args', array( $this, 'map_activity_to_group' ) ); |
99 |
119 |
100 // No subforums yet, so suppress them for now |
120 // No subforums yet, so suppress them for now |
101 add_filter( 'bbp_get_forum_subforum_count_int', array( $this, 'no_subforums_yet' ) ); |
121 add_filter( 'bbp_get_forum_subforum_count_int', array( $this, 'no_subforums_yet' ) ); |
118 |
138 |
119 // Hide breadcrumb |
139 // Hide breadcrumb |
120 add_filter( 'bbp_no_breadcrumb', '__return_true' ); |
140 add_filter( 'bbp_no_breadcrumb', '__return_true' ); |
121 |
141 |
122 $this->display_forums( 0 ); |
142 $this->display_forums( 0 ); |
|
143 } |
|
144 |
|
145 /** |
|
146 * Maybe unset the group forum nav item if group does not have a forum |
|
147 * |
|
148 * @since bbPress (r4552) |
|
149 * |
|
150 * @return If not viewing a single group |
|
151 */ |
|
152 public function maybe_unset_forum_menu() { |
|
153 |
|
154 // Bail if not viewing a single group |
|
155 if ( ! bp_is_group() ) |
|
156 return; |
|
157 |
|
158 // Are forums enabled for this group? |
|
159 $checked = (bool) ( bp_get_new_group_enable_forum() ); |
|
160 |
|
161 // Tweak the nav item variable based on if group has forum or not |
|
162 $this->enable_nav_item = $checked; |
123 } |
163 } |
124 |
164 |
125 /** |
165 /** |
126 * Allow group members to have advanced priviledges in group forum topics. |
166 * Allow group members to have advanced priviledges in group forum topics. |
127 * |
167 * |
145 case 'read_forum' : |
185 case 'read_forum' : |
146 case 'publish_replies' : |
186 case 'publish_replies' : |
147 case 'publish_topics' : |
187 case 'publish_topics' : |
148 case 'read_hidden_forums' : |
188 case 'read_hidden_forums' : |
149 case 'read_private_forums' : |
189 case 'read_private_forums' : |
150 if ( bp_group_is_member() ) { |
190 if ( bp_group_is_member() || bp_group_is_mod() || bp_group_is_admin() ) { |
151 $caps = array( 'participate' ); |
191 $caps = array( 'participate' ); |
152 } |
192 } |
153 break; |
193 break; |
154 |
194 |
155 // If user is a group mod ar admin, map to participate cap. |
195 // If user is a group mod ar admin, map to participate cap. |
232 check_admin_referer( 'groups_edit_save_' . $this->slug ); |
272 check_admin_referer( 'groups_edit_save_' . $this->slug ); |
233 |
273 |
234 $edit_forum = !empty( $_POST['bbp-edit-group-forum'] ) ? true : false; |
274 $edit_forum = !empty( $_POST['bbp-edit-group-forum'] ) ? true : false; |
235 $forum_id = 0; |
275 $forum_id = 0; |
236 $group_id = bp_get_current_group_id(); |
276 $group_id = bp_get_current_group_id(); |
237 $forum_ids = bbp_get_group_forum_ids( $group_id ); |
277 $forum_ids = array_values( bbp_get_group_forum_ids( $group_id ) ); |
238 if ( !empty( $forum_ids ) ) |
278 |
239 $forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids; |
279 // Normalize group forum relationships now |
|
280 if ( !empty( $forum_ids ) ) { |
|
281 |
|
282 // Loop through forums, and make sure they exist |
|
283 foreach ( $forum_ids as $forum_id ) { |
|
284 |
|
285 // Look for forum |
|
286 $forum = bbp_get_forum( $forum_id ); |
|
287 |
|
288 // No forum exists, so break the relationship |
|
289 if ( empty( $forum ) ) { |
|
290 $this->remove_forum( array( 'forum_id' => $forum_id ) ); |
|
291 unset( $forum_ids[$forum_id] ); |
|
292 } |
|
293 } |
|
294 |
|
295 // No support for multiple forums yet |
|
296 $forum_id = (int) ( is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids ); |
|
297 } |
240 |
298 |
241 // Update the group forum setting |
299 // Update the group forum setting |
242 $group = new BP_Groups_Group( $group_id ); |
300 $group = new BP_Groups_Group( $group_id ); |
243 $group->enable_forum = $edit_forum; |
301 $group->enable_forum = $edit_forum; |
244 $group->save(); |
302 $group->save(); |
|
303 |
|
304 // Create a new forum |
|
305 if ( empty( $forum_id ) && ( true === $edit_forum ) ) { |
|
306 |
|
307 // Set the default forum status |
|
308 switch ( $group->status ) { |
|
309 case 'hidden' : |
|
310 $status = bbp_get_hidden_status_id(); |
|
311 break; |
|
312 case 'private' : |
|
313 $status = bbp_get_private_status_id(); |
|
314 break; |
|
315 case 'public' : |
|
316 default : |
|
317 $status = bbp_get_public_status_id(); |
|
318 break; |
|
319 } |
|
320 |
|
321 // Create the initial forum |
|
322 $forum_id = bbp_insert_forum( array( |
|
323 'post_parent' => bbp_get_group_forums_root_id(), |
|
324 'post_title' => $group->name, |
|
325 'post_content' => $group->description, |
|
326 'post_status' => $status |
|
327 ) ); |
|
328 |
|
329 // Run the BP-specific functions for new groups |
|
330 $this->new_forum( array( 'forum_id' => $forum_id ) ); |
|
331 } |
245 |
332 |
246 // Redirect after save |
333 // Redirect after save |
247 bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) ); |
334 bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) ); |
248 } |
335 } |
249 |
336 |
423 |
510 |
424 // Load up bbPress once |
511 // Load up bbPress once |
425 $bbp = bbpress(); |
512 $bbp = bbpress(); |
426 |
513 |
427 // Forum data |
514 // Forum data |
|
515 $forum_slug = bp_action_variable( $offset ); |
428 $forum_ids = bbp_get_group_forum_ids( bp_get_current_group_id() ); |
516 $forum_ids = bbp_get_group_forum_ids( bp_get_current_group_id() ); |
429 $forum_args = array( 'post__in' => $forum_ids, 'post_parent' => null ); |
517 $forum_args = array( 'post__in' => $forum_ids, 'post_parent' => null ); |
430 |
518 |
431 // Unset global queries |
519 // Unset global queries |
432 $bbp->forum_query = new stdClass; |
520 $bbp->forum_query = new stdClass; |
450 <div id="bbpress-forums"> |
538 <div id="bbpress-forums"> |
451 |
539 |
452 <?php |
540 <?php |
453 |
541 |
454 // Looking at the group forum root |
542 // Looking at the group forum root |
455 if ( !bp_action_variable( $offset ) ) : |
543 if ( empty( $forum_slug ) || ( 'page' == $forum_slug ) ) : |
456 |
544 |
457 // Query forums and show them if they exist |
545 // Query forums and show them if they exist |
458 if ( !empty( $forum_ids ) && bbp_has_forums( $forum_args ) ) : |
546 if ( !empty( $forum_ids ) && bbp_has_forums( $forum_args ) ) : |
459 |
547 |
460 // Only one forum found |
548 // Only one forum found |
461 if ( 1 == $bbp->forum_query->post_count ) : |
549 if ( 1 == $bbp->forum_query->post_count ) : |
462 |
550 |
463 // Get forum data |
551 // Remove 'name' check for paginated requests |
464 $forum_slug = bp_action_variable( $offset ); |
552 if ( 'page' == $forum_slug ) { |
465 $forum_args = array( 'name' => $forum_slug, 'post_type' => bbp_get_forum_post_type() ); |
553 $forum_args = array( 'post_type' => bbp_get_forum_post_type() ); |
466 $forums = get_posts( $forum_args ); |
554 } else { |
|
555 $forum_args = array( 'name' => $forum_slug, 'post_type' => bbp_get_forum_post_type() ); |
|
556 } |
|
557 |
|
558 // Get the forums |
|
559 $forums = get_posts( $forum_args ); |
467 |
560 |
468 bbp_the_forum(); |
561 bbp_the_forum(); |
469 |
562 |
470 // Forum exists |
563 // Forum exists |
471 if ( !empty( $forums ) ) : |
564 if ( !empty( $forums ) ) : |
473 |
566 |
474 // Suppress subforums for now |
567 // Suppress subforums for now |
475 add_filter( 'bbp_get_forum_subforum_count', '__return_false' ); |
568 add_filter( 'bbp_get_forum_subforum_count', '__return_false' ); |
476 |
569 |
477 // Set up forum data |
570 // Set up forum data |
478 $forum_id = bbpress()->current_forum_id = $forum->ID; |
571 bbpress()->current_forum_id = $forum->ID; |
479 bbp_set_query_name( 'bbp_single_forum' ); ?> |
572 bbp_set_query_name( 'bbp_single_forum' ); ?> |
480 |
573 |
481 <h3><?php bbp_forum_title(); ?></h3> |
574 <h3><?php bbp_forum_title(); ?></h3> |
482 |
575 |
483 <?php bbp_get_template_part( 'content', 'single-forum' ); ?> |
576 <?php bbp_get_template_part( 'content', 'single-forum' ); ?> |
484 |
577 |
485 <?php |
578 <?php |
486 |
579 |
487 // Remove the subforum suppression filter |
580 // Remove the subforum suppression filter |
488 remove_filter( 'bbp_get_forum_subforum_count', '__return_false' ); |
581 remove_filter( 'bbp_get_forum_subforum_count', '__return_false' ); |
489 |
582 |
490 ?> |
583 ?> |
491 |
584 |
492 <?php else : ?> |
585 <?php else : ?> |
493 |
586 |
494 <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> |
587 <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> |
569 $wp_query->bbp_is_edit = true; |
662 $wp_query->bbp_is_edit = true; |
570 $wp_query->bbp_is_forum_edit = true; |
663 $wp_query->bbp_is_forum_edit = true; |
571 $post = $forum; |
664 $post = $forum; |
572 |
665 |
573 bbp_set_query_name( 'bbp_forum_form' ); |
666 bbp_set_query_name( 'bbp_forum_form' ); |
574 |
|
575 bbp_get_template_part( 'form', 'forum' ); |
667 bbp_get_template_part( 'form', 'forum' ); |
576 |
668 |
577 else : |
669 else : |
578 bbp_set_query_name( 'bbp_single_forum' ); ?> |
670 bbp_set_query_name( 'bbp_single_forum' ); ?> |
579 |
671 |
623 $post = $topic; |
715 $post = $topic; |
624 |
716 |
625 // Merge |
717 // Merge |
626 if ( !empty( $_GET['action'] ) && 'merge' == $_GET['action'] ) : |
718 if ( !empty( $_GET['action'] ) && 'merge' == $_GET['action'] ) : |
627 bbp_set_query_name( 'bbp_topic_merge' ); |
719 bbp_set_query_name( 'bbp_topic_merge' ); |
628 |
|
629 bbp_get_template_part( 'form', 'topic-merge' ); |
720 bbp_get_template_part( 'form', 'topic-merge' ); |
630 |
721 |
631 // Split |
722 // Split |
632 elseif ( !empty( $_GET['action'] ) && 'split' == $_GET['action'] ) : |
723 elseif ( !empty( $_GET['action'] ) && 'split' == $_GET['action'] ) : |
633 bbp_set_query_name( 'bbp_topic_split' ); |
724 bbp_set_query_name( 'bbp_topic_split' ); |
634 |
|
635 bbp_get_template_part( 'form', 'topic-split' ); |
725 bbp_get_template_part( 'form', 'topic-split' ); |
636 |
726 |
637 // Edit |
727 // Edit |
638 else : |
728 else : |
639 bbp_set_query_name( 'bbp_topic_form' ); |
729 bbp_set_query_name( 'bbp_topic_form' ); |