web/wp-content/plugins/bbpress/includes/extend/buddypress/group.php
changeset 196 5e8dcbe22c24
child 204 09a1c134465b
equal deleted inserted replaced
195:c7c0fbc09788 196:5e8dcbe22c24
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * bbPress BuddyPress Group Extension Class
       
     5  *
       
     6  * @package bbPress
       
     7  * @subpackage BuddyPress
       
     8  * @todo maybe move to BuddyPress Forums once bbPress 1.1 can be removed
       
     9  */
       
    10 
       
    11 // Exit if accessed directly
       
    12 if ( !defined( 'ABSPATH' ) ) exit;
       
    13 
       
    14 if ( !class_exists( 'BBP_Forums_Group_Extension' ) && class_exists( 'BP_Group_Extension' ) ) :
       
    15 /**
       
    16  * Loads Group Extension for Forums Component
       
    17  *
       
    18  * @since bbPress (r3552)
       
    19  *
       
    20  * @package bbPress
       
    21  * @subpackage BuddyPress
       
    22  * @todo Everything
       
    23  */
       
    24 class BBP_Forums_Group_Extension extends BP_Group_Extension {
       
    25 
       
    26 	/** Methods ***************************************************************/
       
    27 
       
    28 	/**
       
    29 	 * Setup bbPress group extension variables
       
    30 	 *
       
    31 	 * @since bbPress (r3552)
       
    32 	 */
       
    33 	public function __construct() {
       
    34 
       
    35 		// Name and slug
       
    36 		$this->name          = __( 'Forum', 'bbpress' );
       
    37 		$this->nav_item_name = __( 'Forum', 'bbpress' );
       
    38 		$this->slug          = 'forum';
       
    39 		$this->topic_slug    = 'topic';
       
    40 		$this->reply_slug    = 'reply';
       
    41 
       
    42 		// Forum component is visible
       
    43 		$this->visibility = 'public';
       
    44 
       
    45 		// Set positions towards end
       
    46 		$this->create_step_position = 15;
       
    47 		$this->nav_item_position    = 10;
       
    48 
       
    49 		// Allow create step and show in nav
       
    50 		$this->enable_create_step   = true;
       
    51 		$this->enable_nav_item      = true;
       
    52 		$this->enable_edit_item     = true;
       
    53 
       
    54 		// Template file to load, and action to hook display on to
       
    55 		$this->template_file        = 'groups/single/plugins';
       
    56 		$this->display_hook         = 'bp_template_content';
       
    57 
       
    58 		// Add handlers to bp_actions
       
    59 		add_action( 'bp_actions', 'bbp_new_forum_handler'  );
       
    60 		add_action( 'bp_actions', 'bbp_new_topic_handler'  );
       
    61 		add_action( 'bp_actions', 'bbp_new_reply_handler'  );
       
    62 		add_action( 'bp_actions', 'bbp_edit_forum_handler' );
       
    63 		add_action( 'bp_actions', 'bbp_edit_topic_handler' );
       
    64 		add_action( 'bp_actions', 'bbp_edit_reply_handler' );
       
    65 
       
    66 		// Possibly redirect
       
    67 		add_action( 'bbp_template_redirect',     array( $this, 'redirect_canonical' ) );
       
    68 
       
    69 		// Group forum pagination
       
    70 		add_filter( 'bbp_topic_pagination',      array( $this, 'topic_pagination'   ) );
       
    71 		add_filter( 'bbp_replies_pagination',    array( $this, 'replies_pagination' ) );
       
    72 
       
    73 		// Tweak the redirect field
       
    74 		add_filter( 'bbp_new_topic_redirect_to', array( $this, 'new_topic_redirect_to'        ), 10, 3 );
       
    75 		add_filter( 'bbp_new_reply_redirect_to', array( $this, 'new_reply_redirect_to'        ), 10, 3 );
       
    76 
       
    77 		// Map forum/topic/replys permalinks to their groups
       
    78 		add_filter( 'bbp_get_forum_permalink',   array( $this, 'map_forum_permalink_to_group' ), 10, 2 );
       
    79 		add_filter( 'bbp_get_topic_permalink',   array( $this, 'map_topic_permalink_to_group' ), 10, 2 );
       
    80 		add_filter( 'bbp_get_reply_permalink',   array( $this, 'map_reply_permalink_to_group' ), 10, 2 );
       
    81 
       
    82 		// Map reply edit links to their groups
       
    83 		add_filter( 'bbp_get_reply_edit_url',    array( $this, 'map_reply_edit_url_to_group'  ), 10, 2 );
       
    84 
       
    85 		// Map assorted template function permalinks
       
    86 		add_filter( 'post_link',                 array( $this, 'post_link'                    ), 10, 2 );
       
    87 		add_filter( 'page_link',                 array( $this, 'page_link'                    ), 10, 2 );
       
    88 		add_filter( 'post_type_link',            array( $this, 'post_type_link'               ), 10, 2 );
       
    89 
       
    90 		// Allow group member to view private/hidden forums
       
    91 		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 );
       
    93 
       
    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
       
    98 		add_filter( 'bbp_before_record_activity_parse_args', array( $this, 'map_activity_to_group' ) );
       
    99 
       
   100 		// No subforums yet, so suppress them for now
       
   101 		add_filter( 'bbp_get_forum_subforum_count_int', array( $this, 'no_subforums_yet' ) );
       
   102 	}
       
   103 
       
   104 	/**
       
   105 	 * The primary display function for group forums
       
   106 	 */
       
   107 	public function display() {
       
   108 
       
   109 		// Prevent Topic Parent from appearing
       
   110 		add_action( 'bbp_theme_before_topic_form_forum', array( $this, 'ob_start'     ) );
       
   111 		add_action( 'bbp_theme_after_topic_form_forum',  array( $this, 'ob_end_clean' ) );
       
   112 		add_action( 'bbp_theme_after_topic_form_forum',  array( $this, 'topic_parent' ) );
       
   113 
       
   114 		// Prevent Forum Parent from appearing
       
   115 		add_action( 'bbp_theme_before_forum_form_parent', array( $this, 'ob_start'     ) );
       
   116 		add_action( 'bbp_theme_after_forum_form_parent',  array( $this, 'ob_end_clean' ) );
       
   117 		add_action( 'bbp_theme_after_forum_form_parent',  array( $this, 'forum_parent' ) );
       
   118 
       
   119 		// Hide breadcrumb
       
   120 		add_filter( 'bbp_no_breadcrumb', '__return_true' );
       
   121 
       
   122 		$this->display_forums( 0 );
       
   123 	}
       
   124 
       
   125 	/**
       
   126 	 * Allow group members to have advanced priviledges in group forum topics.
       
   127 	 *
       
   128 	 * @since bbPress (r4434)
       
   129 	 *
       
   130 	 * @param array $caps
       
   131 	 * @param string $cap
       
   132 	 * @param int $user_id
       
   133 	 * @param array $args
       
   134 	 * @return array
       
   135 	 */
       
   136 	public function map_topic_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
       
   137 
       
   138 		// Bail if not viewing a single topic
       
   139 		if ( ! bp_is_single_item() || ! bp_is_groups_component() || ! bp_is_current_action( 'forum' ) || ! bp_is_action_variable( 0, 'topic' ) )
       
   140 			return $caps;
       
   141 
       
   142 		switch ( $cap ) {
       
   143 
       
   144 			// If user is a group mmember, allow them to create content.
       
   145 			case 'read_forum'          :
       
   146 			case 'publish_replies'     :
       
   147 			case 'publish_topics'      :
       
   148 			case 'read_hidden_forums'  :
       
   149 			case 'read_private_forums' :
       
   150 				if ( bp_group_is_member() ) {
       
   151 					$caps = array( 'participate' );
       
   152 				}
       
   153 				break;
       
   154 
       
   155 			// If user is a group mod ar admin, map to participate cap.
       
   156 			case 'moderate'     :
       
   157 			case 'edit_topic'   :
       
   158 			case 'edit_reply'   :
       
   159 			case 'view_trash'   :
       
   160 			case 'edit_others_replies' :
       
   161 			case 'edit_others_topics'  :
       
   162 				if ( bp_group_is_mod() || bp_group_is_admin() ) {
       
   163 					$caps = array( 'participate' );
       
   164 				}
       
   165 				break;
       
   166 
       
   167 			// If user is a group admin, allow them to delete topics and replies.
       
   168 			case 'delete_topic' :
       
   169 			case 'delete_reply' :
       
   170 				if ( bp_group_is_admin() ) {
       
   171 					$caps = array( 'participate' );
       
   172 				}
       
   173 				break;
       
   174 		}
       
   175 
       
   176 		return apply_filters( 'bbp_map_group_forum_topic_meta_caps', $caps, $cap, $user_id, $args );
       
   177 	}
       
   178 
       
   179 	/**
       
   180 	 * Remove the topic meta cap map, so it doesn't interfere with sidebars.
       
   181 	 *
       
   182 	 * @since bbPress (r4434)
       
   183 	 */
       
   184 	public function remove_topic_meta_cap_map() {
       
   185 		remove_filter( 'bbp_map_topic_meta_caps', array( $this, 'map_topic_meta_caps' ), 10, 4 );
       
   186 		remove_filter( 'bbp_map_reply_meta_caps', array( $this, 'map_topic_meta_caps' ), 10, 4 );
       
   187 	}
       
   188 
       
   189 	/** Edit ******************************************************************/
       
   190 
       
   191 	/**
       
   192 	 * Show forums and new forum form when editing a group
       
   193 	 *
       
   194 	 * @since bbPress (r3563)
       
   195 	 * @uses bbp_get_template_part()
       
   196 	 */
       
   197 	public function edit_screen() {
       
   198 
       
   199 		$checked = bp_get_new_group_enable_forum() || bp_group_is_forum_enabled( bp_get_group_id() ); ?>
       
   200 
       
   201 		<h4><?php _e( 'Enable Group Forum', 'bbpress' ); ?></h4>
       
   202 
       
   203 		<p><?php _e( 'Create a discussion forum to allow members of this group to communicate in a structured, bulletin-board style fashion.', 'bbpress' ); ?></p>
       
   204 
       
   205 		<div class="checkbox">
       
   206 			<label><input type="checkbox" name="bbp-edit-group-forum" id="bbp-edit-group-forum" value="1"<?php checked( $checked ); ?> /> <?php _e( 'Yes. I want this group to have a forum.', 'bbpress' ); ?></label>
       
   207 		</div>
       
   208 
       
   209 		<p class="description"><?php _e( 'Saying no will not delete existing forum content.', 'bbpress' ); ?></p>
       
   210 
       
   211 		<input type="submit" value="<?php esc_attr_e( 'Save Settings', 'bbpress' ); ?>" />
       
   212 
       
   213 		<?php
       
   214 
       
   215 		// Verify intent
       
   216 		wp_nonce_field( 'groups_edit_save_' . $this->slug );
       
   217 	}
       
   218 
       
   219 	/**
       
   220 	 * Save the Group Forum data on edit
       
   221 	 *
       
   222 	 * @since bbPress (r3465)
       
   223 	 * @uses bbp_new_forum_handler() To check for forum creation
       
   224 	 * @uses bbp_edit_forum_handler() To check for forum edit
       
   225 	 */
       
   226 	public function edit_screen_save() {
       
   227 
       
   228 		// Bail if not a POST action
       
   229 		if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
       
   230 			return;
       
   231 
       
   232 		check_admin_referer( 'groups_edit_save_' . $this->slug );
       
   233 
       
   234 		$edit_forum   = !empty( $_POST['bbp-edit-group-forum'] ) ? true : false;
       
   235 		$forum_id     = 0;
       
   236 		$group_id     = bp_get_current_group_id();
       
   237 		$forum_ids    = bbp_get_group_forum_ids( $group_id );
       
   238 		if ( !empty( $forum_ids ) )
       
   239 			$forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids;
       
   240 
       
   241 		// Update the group forum setting
       
   242 		$group               = new BP_Groups_Group( $group_id );
       
   243 		$group->enable_forum = $edit_forum;
       
   244 		$group->save();
       
   245 
       
   246 		// Redirect after save
       
   247 		bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) );
       
   248 	}
       
   249 
       
   250 	/** Create ****************************************************************/
       
   251 
       
   252 	/**
       
   253 	 * Show forums and new forum form when creating a group
       
   254 	 *
       
   255 	 * @since bbPress (r3465)
       
   256 	 */
       
   257 	public function create_screen() {
       
   258 
       
   259 		// Bail if not looking at this screen
       
   260 		if ( !bp_is_group_creation_step( $this->slug ) )
       
   261 			return false;
       
   262 
       
   263 		$checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( bp_get_new_group_id(), 'forum_id' ); ?>
       
   264 
       
   265 		<h4><?php _e( 'Group Forum', 'bbpress' ); ?></h4>
       
   266 
       
   267 		<p><?php _e( 'Create a discussion forum to allow members of this group to communicate in a structured, bulletin-board style fashion.', 'bbpress' ); ?></p>
       
   268 
       
   269 		<div class="checkbox">
       
   270 			<label><input type="checkbox" name="bbp-create-group-forum" id="bbp-create-group-forum" value="1"<?php checked( $checked ); ?> /> <?php _e( 'Yes. I want this group to have a forum.', 'bbpress' ); ?></label>
       
   271 		</div>
       
   272 
       
   273 		<?php
       
   274 
       
   275 		// Verify intent
       
   276 		wp_nonce_field( 'groups_create_save_' . $this->slug );
       
   277 	}
       
   278 
       
   279 	/**
       
   280 	 * Save the Group Forum data on create
       
   281 	 *
       
   282 	 * @since bbPress (r3465)
       
   283 	 */
       
   284 	public function create_screen_save() {
       
   285 
       
   286 		check_admin_referer( 'groups_create_save_' . $this->slug );
       
   287 
       
   288 		$create_forum = !empty( $_POST['bbp-create-group-forum'] ) ? true : false;
       
   289 		$forum_id     = 0;
       
   290 		$forum_ids    = bbp_get_group_forum_ids( bp_get_new_group_id() );
       
   291 		if ( !empty( $forum_ids ) )
       
   292 			$forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids;
       
   293 
       
   294 		// Create a forum, or not
       
   295 		switch ( $create_forum ) {
       
   296 			case true  :
       
   297 
       
   298 				// Bail if initial content was already created
       
   299 				if ( !empty( $forum_id ) )
       
   300 					return;
       
   301 
       
   302 				// Set the default forum status
       
   303 				switch ( bp_get_new_group_status() ) {
       
   304 					case 'hidden'  :
       
   305 						$status = bbp_get_hidden_status_id();
       
   306 						break;
       
   307 					case 'private' :
       
   308 						$status = bbp_get_private_status_id();
       
   309 						break;
       
   310 					case 'public'  :
       
   311 					default        :
       
   312 						$status = bbp_get_public_status_id();
       
   313 						break;
       
   314 				}
       
   315 
       
   316 				// Create the initial forum
       
   317 				$forum_id = bbp_insert_forum( array(
       
   318 					'post_parent'  => bbp_get_group_forums_root_id(),
       
   319 					'post_title'   => bp_get_new_group_name(),
       
   320 					'post_content' => bp_get_new_group_description(),
       
   321 					'post_status'  => $status
       
   322 				) );
       
   323 
       
   324 				// Run the BP-specific functions for new groups
       
   325 				$this->new_forum( array( 'forum_id' => $forum_id ) );
       
   326 
       
   327 				// Update forum active
       
   328 				groups_update_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true );
       
   329 
       
   330 				break;
       
   331 			case false :
       
   332 
       
   333 				// Forum was created but is now being undone
       
   334 				if ( !empty( $forum_id ) ) {
       
   335 					wp_delete_post( $forum_id, true );
       
   336 					groups_delete_groupmeta( bp_get_new_group_id(), 'forum_id' );
       
   337 					groups_delete_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id );
       
   338 				}
       
   339 
       
   340 				break;
       
   341 		}
       
   342 	}
       
   343 
       
   344 	/**
       
   345 	 * Used to start an output buffer
       
   346 	 */
       
   347 	public function ob_start() {
       
   348 		ob_start();
       
   349 	}
       
   350 
       
   351 	/**
       
   352 	 * Used to end an output buffer
       
   353 	 */
       
   354 	public function ob_end_clean() {
       
   355 		ob_end_clean();
       
   356 	}
       
   357 
       
   358 	/**
       
   359 	 * Creating a group forum or category (including root for group)
       
   360 	 *
       
   361 	 * @since bbPress (r3653)
       
   362 	 * @param type $forum_args
       
   363 	 * @uses bbp_get_forum_id()
       
   364 	 * @uses bp_get_current_group_id()
       
   365 	 * @uses bbp_add_forum_id_to_group()
       
   366 	 * @uses bbp_add_group_id_to_forum()
       
   367 	 * @return if no forum_id is available
       
   368 	 */
       
   369 	public function new_forum( $forum_args = array() ) {
       
   370 
       
   371 		// Bail if no forum_id was passed
       
   372 		if ( empty( $forum_args['forum_id'] ) )
       
   373 			return;
       
   374 
       
   375 		// Validate forum_id
       
   376 		$forum_id = bbp_get_forum_id( $forum_args['forum_id'] );
       
   377 		$group_id = bp_get_current_group_id();
       
   378 
       
   379 		bbp_add_forum_id_to_group( $group_id, $forum_id );
       
   380 		bbp_add_group_id_to_forum( $forum_id, $group_id );
       
   381 	}
       
   382 
       
   383 	/**
       
   384 	 * Removing a group forum or category (including root for group)
       
   385 	 *
       
   386 	 * @since bbPress (r3653)
       
   387 	 * @param type $forum_args
       
   388 	 * @uses bbp_get_forum_id()
       
   389 	 * @uses bp_get_current_group_id()
       
   390 	 * @uses bbp_add_forum_id_to_group()
       
   391 	 * @uses bbp_add_group_id_to_forum()
       
   392 	 * @return if no forum_id is available
       
   393 	 */
       
   394 	public function remove_forum( $forum_args = array() ) {
       
   395 
       
   396 		// Bail if no forum_id was passed
       
   397 		if ( empty( $forum_args['forum_id'] ) )
       
   398 			return;
       
   399 
       
   400 		// Validate forum_id
       
   401 		$forum_id = bbp_get_forum_id( $forum_args['forum_id'] );
       
   402 		$group_id = bp_get_current_group_id();
       
   403 
       
   404 		bbp_remove_forum_id_from_group( $group_id, $forum_id );
       
   405 		bbp_remove_group_id_from_forum( $forum_id, $group_id );
       
   406 	}
       
   407 
       
   408 	/** Display Methods *******************************************************/
       
   409 
       
   410 	/**
       
   411 	 * Output the forums for a group in the edit screens
       
   412 	 *
       
   413 	 * @since bbPress (r3653)
       
   414 	 * @uses bp_get_current_group_id()
       
   415 	 * @uses bbp_get_group_forum_ids()
       
   416 	 * @uses bbp_has_forums()
       
   417 	 * @uses bbp_get_template_part()
       
   418 	 */
       
   419 	public function display_forums( $offset = 0 ) {
       
   420 
       
   421 		// Allow actions immediately before group forum output
       
   422 		do_action( 'bbp_before_group_forum_display' );
       
   423 
       
   424 		// Load up bbPress once
       
   425 		$bbp = bbpress();
       
   426 
       
   427 		// Forum data
       
   428 		$forum_ids  = bbp_get_group_forum_ids( bp_get_current_group_id() );
       
   429 		$forum_args = array( 'post__in' => $forum_ids, 'post_parent' => null );
       
   430 
       
   431 		// Unset global queries
       
   432 		$bbp->forum_query = new stdClass;
       
   433 		$bbp->topic_query = new stdClass;
       
   434 		$bbp->reply_query = new stdClass;
       
   435 
       
   436 		// Unset global ID's
       
   437 		$bbp->current_forum_id     = 0;
       
   438 		$bbp->current_topic_id     = 0;
       
   439 		$bbp->current_reply_id     = 0;
       
   440 		$bbp->current_topic_tag_id = 0;
       
   441 
       
   442 		// Reset the post data
       
   443 		wp_reset_postdata();
       
   444 
       
   445 		// Allow admins special views
       
   446 		$post_status = array( bbp_get_closed_status_id(), bbp_get_public_status_id() );
       
   447 		if ( is_super_admin() || current_user_can( 'moderate' ) || bp_is_item_admin() || bp_is_item_mod() )
       
   448 			$post_status = array_merge( $post_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ); ?>
       
   449 
       
   450 		<div id="bbpress-forums">
       
   451 
       
   452 			<?php
       
   453 
       
   454 			// Looking at the group forum root
       
   455 			if ( !bp_action_variable( $offset ) ) :
       
   456 
       
   457 				// Query forums and show them if they exist
       
   458 				if ( !empty( $forum_ids ) && bbp_has_forums( $forum_args ) ) :
       
   459 
       
   460 					// Only one forum found
       
   461 					if ( 1 == $bbp->forum_query->post_count ) :
       
   462 
       
   463 						// Get forum data
       
   464 						$forum_slug = bp_action_variable( $offset );
       
   465 						$forum_args = array( 'name' => $forum_slug, 'post_type' => bbp_get_forum_post_type() );
       
   466 						$forums     = get_posts( $forum_args );
       
   467 
       
   468 						bbp_the_forum();
       
   469 
       
   470 						// Forum exists
       
   471 						if ( !empty( $forums ) ) :
       
   472 							$forum = $forums[0];
       
   473 
       
   474 							// Suppress subforums for now
       
   475 							add_filter( 'bbp_get_forum_subforum_count', '__return_false' );
       
   476 
       
   477 							// Set up forum data
       
   478 							$forum_id = bbpress()->current_forum_id = $forum->ID;
       
   479 							bbp_set_query_name( 'bbp_single_forum' ); ?>
       
   480 
       
   481 							<h3><?php bbp_forum_title(); ?></h3>
       
   482 
       
   483 							<?php bbp_get_template_part( 'content', 'single-forum' ); ?>
       
   484 
       
   485 							<?php 
       
   486 
       
   487 							// Remove the subforum suppression filter
       
   488 							remove_filter( 'bbp_get_forum_subforum_count', '__return_false' );
       
   489 							
       
   490 							?>
       
   491 
       
   492 						<?php else : ?>
       
   493 
       
   494 							<?php bbp_get_template_part( 'feedback',   'no-topics' ); ?>
       
   495 
       
   496 							<?php bbp_get_template_part( 'form',       'topic'     ); ?>
       
   497 
       
   498 						<?php endif;
       
   499 
       
   500 					// More than 1 forum found or group forum admin screen
       
   501 					elseif ( 1 < $bbp->forum_query->post_count ) : ?>
       
   502 
       
   503 						<h3><?php _e( 'Forums', 'bbpress' ); ?></h3>
       
   504 
       
   505 						<?php bbp_get_template_part( 'loop', 'forums' ); ?>
       
   506 
       
   507 						<h3><?php _e( 'Topics', 'bbpress' ); ?></h3>
       
   508 
       
   509 						<?php if ( bbp_has_topics( array( 'post_parent__in' => $forum_ids ) ) ) : ?>
       
   510 
       
   511 							<?php bbp_get_template_part( 'pagination', 'topics'    ); ?>
       
   512 
       
   513 							<?php bbp_get_template_part( 'loop',       'topics'    ); ?>
       
   514 
       
   515 							<?php bbp_get_template_part( 'pagination', 'topics'    ); ?>
       
   516 
       
   517 							<?php bbp_get_template_part( 'form',       'topic'     ); ?>
       
   518 
       
   519 						<?php else : ?>
       
   520 
       
   521 							<?php bbp_get_template_part( 'feedback',   'no-topics' ); ?>
       
   522 
       
   523 							<?php bbp_get_template_part( 'form',       'topic'     ); ?>
       
   524 
       
   525 						<?php endif;
       
   526 
       
   527 					// No forums found
       
   528 					else : ?>
       
   529 
       
   530 						<div id="message" class="info">
       
   531 							<p><?php _e( 'This group does not currently have any forums.', 'bbpress' ); ?></p>
       
   532 						</div>
       
   533 
       
   534 					<?php endif;
       
   535 
       
   536 				// No forums found
       
   537 				else : ?>
       
   538 
       
   539 					<div id="message" class="info">
       
   540 						<p><?php _e( 'This group does not currently have any forums.', 'bbpress' ); ?></p>
       
   541 					</div>
       
   542 
       
   543 				<?php endif;
       
   544 
       
   545 			// Single forum
       
   546 			elseif ( ( bp_action_variable( $offset ) != $this->slug ) && ( bp_action_variable( $offset ) != $this->topic_slug ) && ( bp_action_variable( $offset ) != $this->reply_slug ) ) :
       
   547 
       
   548 				// Get forum data
       
   549 				$forum_slug = bp_action_variable( $offset );
       
   550 				$forum_args = array( 'name' => $forum_slug, 'post_type' => bbp_get_forum_post_type() );
       
   551 				$forums     = get_posts( $forum_args );
       
   552 
       
   553 				// Forum exists
       
   554 				if ( !empty( $forums ) ) :
       
   555 					$forum = $forums[0];
       
   556 
       
   557 					// Set up forum data
       
   558 					$forum_id = bbpress()->current_forum_id = $forum->ID;
       
   559 
       
   560 					// Reset necessary forum_query attributes for forums loop to function
       
   561 					$bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
       
   562 					$bbp->forum_query->in_the_loop             = true;
       
   563 					$bbp->forum_query->post                    = get_post( $forum_id );
       
   564 
       
   565 					// Forum edit
       
   566 					if ( bp_action_variable( $offset + 1 ) == $bbp->edit_id ) :
       
   567 						global $wp_query, $post;
       
   568 
       
   569 						$wp_query->bbp_is_edit       = true;
       
   570 						$wp_query->bbp_is_forum_edit = true;
       
   571 						$post                        = $forum;
       
   572 
       
   573 						bbp_set_query_name( 'bbp_forum_form' );
       
   574 
       
   575 						bbp_get_template_part( 'form', 'forum' );
       
   576 
       
   577 					else :
       
   578 						bbp_set_query_name( 'bbp_single_forum' ); ?>
       
   579 
       
   580 						<h3><?php bbp_forum_title(); ?></h3>
       
   581 
       
   582 						<?php bbp_get_template_part( 'content', 'single-forum' );
       
   583 
       
   584 					endif;
       
   585 
       
   586 				else :
       
   587 					bbp_get_template_part( 'feedback', 'no-topics' );
       
   588 					bbp_get_template_part( 'form',     'topic'     );
       
   589 
       
   590 				endif;
       
   591 
       
   592 			// Single topic
       
   593 			elseif ( bp_action_variable( $offset ) == $this->topic_slug ) :
       
   594 
       
   595 				// Get topic data
       
   596 				$topic_slug = bp_action_variable( $offset + 1 );
       
   597 				$topic_args = array( 'name' => $topic_slug, 'post_type' => bbp_get_topic_post_type(), 'post_status' => $post_status );
       
   598 				$topics     = get_posts( $topic_args );
       
   599 
       
   600 				// Topic exists
       
   601 				if ( !empty( $topics ) ) :
       
   602 					$topic = $topics[0];
       
   603 
       
   604 					// Set up topic data
       
   605 					$topic_id = bbpress()->current_topic_id = $topic->ID;
       
   606 					$forum_id = bbp_get_topic_forum_id( $topic_id );
       
   607 
       
   608 					// Reset necessary forum_query attributes for topics loop to function
       
   609 					$bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
       
   610 					$bbp->forum_query->in_the_loop             = true;
       
   611 					$bbp->forum_query->post                    = get_post( $forum_id );
       
   612 
       
   613 					// Reset necessary topic_query attributes for topics loop to function
       
   614 					$bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
       
   615 					$bbp->topic_query->in_the_loop             = true;
       
   616 					$bbp->topic_query->post                    = $topic;
       
   617 
       
   618 					// Topic edit
       
   619 					if ( bp_action_variable( $offset + 2 ) == $bbp->edit_id ) :
       
   620 						global $wp_query, $post;
       
   621 						$wp_query->bbp_is_edit       = true;
       
   622 						$wp_query->bbp_is_topic_edit = true;
       
   623 						$post                        = $topic;
       
   624 
       
   625 						// Merge
       
   626 						if ( !empty( $_GET['action'] ) && 'merge' == $_GET['action'] ) :
       
   627 							bbp_set_query_name( 'bbp_topic_merge' );
       
   628 
       
   629 							bbp_get_template_part( 'form', 'topic-merge' );
       
   630 
       
   631 						// Split
       
   632 						elseif ( !empty( $_GET['action'] ) && 'split' == $_GET['action'] ) :
       
   633 							bbp_set_query_name( 'bbp_topic_split' );
       
   634 
       
   635 							bbp_get_template_part( 'form', 'topic-split' );
       
   636 
       
   637 						// Edit
       
   638 						else :
       
   639 							bbp_set_query_name( 'bbp_topic_form' );
       
   640 							bbp_get_template_part( 'form', 'topic' );
       
   641 
       
   642 						endif;
       
   643 
       
   644 					// Single Topic
       
   645 					else:
       
   646 
       
   647 						bbp_set_query_name( 'bbp_single_topic' ); ?>
       
   648 
       
   649 						<h3><?php bbp_topic_title(); ?></h3>
       
   650 
       
   651 						<?php bbp_get_template_part( 'content', 'single-topic' );
       
   652 
       
   653 					endif;
       
   654 
       
   655 				// No Topics
       
   656 				else :
       
   657 					bbp_get_template_part( 'feedback', 'no-topics'   );
       
   658 					bbp_get_template_part( 'form',     'topic'       );
       
   659 
       
   660 				endif;
       
   661 
       
   662 			// Single reply
       
   663 			elseif ( bp_action_variable( $offset ) == $this->reply_slug ) :
       
   664 
       
   665 				// Get reply data
       
   666 				$reply_slug = bp_action_variable( $offset + 1 );
       
   667 				$reply_args = array( 'name' => $reply_slug, 'post_type' => bbp_get_reply_post_type() );
       
   668 				$replies    = get_posts( $reply_args );
       
   669 
       
   670 				if ( empty( $replies ) )
       
   671 					return;
       
   672 
       
   673 				// Get the first reply
       
   674 				$reply = $replies[0];
       
   675 
       
   676 				// Set up reply data
       
   677 				$reply_id = bbpress()->current_reply_id = $reply->ID;
       
   678 				$topic_id = bbp_get_reply_topic_id( $reply_id );
       
   679 				$forum_id = bbp_get_reply_forum_id( $reply_id );
       
   680 
       
   681 				// Reset necessary forum_query attributes for reply to function
       
   682 				$bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
       
   683 				$bbp->forum_query->in_the_loop             = true;
       
   684 				$bbp->forum_query->post                    = get_post( $forum_id );
       
   685 
       
   686 				// Reset necessary topic_query attributes for reply to function
       
   687 				$bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
       
   688 				$bbp->topic_query->in_the_loop             = true;
       
   689 				$bbp->topic_query->post                    = get_post( $topic_id );
       
   690 
       
   691 				// Reset necessary reply_query attributes for reply to function
       
   692 				$bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
       
   693 				$bbp->reply_query->in_the_loop             = true;
       
   694 				$bbp->reply_query->post                    = $reply;
       
   695 
       
   696 				if ( bp_action_variable( $offset + 2 ) == $bbp->edit_id ) :
       
   697 					global $wp_query, $post;
       
   698 
       
   699 					$wp_query->bbp_is_edit       = true;
       
   700 					$wp_query->bbp_is_reply_edit = true;
       
   701 					$post                        = $reply;
       
   702 
       
   703 					bbp_set_query_name( 'bbp_reply_form' );
       
   704 					bbp_get_template_part( 'form', 'reply' );
       
   705 
       
   706 				endif;
       
   707 
       
   708 			endif; ?>
       
   709 
       
   710 		</div>
       
   711 
       
   712 		<?php
       
   713 
       
   714 		// Allow actions immediately after group forum output
       
   715 		do_action( 'bbp_after_group_forum_display' );
       
   716 	}
       
   717 
       
   718 	/** Redirect Helpers ******************************************************/
       
   719 
       
   720 	/**
       
   721 	 * Redirect to the group forum screen
       
   722 	 *
       
   723 	 * @since bbPress (r3653)
       
   724 	 * @param str $redirect_url
       
   725 	 * @param str $redirect_to
       
   726 	 */
       
   727 	public function new_topic_redirect_to( $redirect_url = '', $redirect_to = '', $topic_id = 0 ) {
       
   728 		if ( bp_is_group() ) {
       
   729 			$topic        = bbp_get_topic( $topic_id );
       
   730 			$topic_hash   = '#post-' . $topic_id;
       
   731 			$redirect_url = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name ) . $topic_hash;
       
   732 		}
       
   733 
       
   734 		return $redirect_url;
       
   735 	}
       
   736 
       
   737 	/**
       
   738 	 * Redirect to the group forum screen
       
   739 	 *
       
   740 	 * @since bbPress (r3653)
       
   741 	 */
       
   742 	public function new_reply_redirect_to( $redirect_url = '', $redirect_to = '', $reply_id = 0 ) {
       
   743 		global $wp_rewrite;
       
   744 
       
   745 		if ( bp_is_group() ) {
       
   746 			$topic_id       = bbp_get_reply_topic_id( $reply_id );
       
   747 			$topic          = bbp_get_topic( $topic_id );
       
   748 			$reply_position = bbp_get_reply_position( $reply_id, $topic_id );
       
   749 			$reply_page     = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() );
       
   750 			$reply_hash     = '#post-' . $reply_id;
       
   751 			$topic_url      = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name );
       
   752 
       
   753 			// Don't include pagination if on first page
       
   754 			if ( 1 >= $reply_page ) {
       
   755 				$redirect_url = trailingslashit( $topic_url ) . $reply_hash;
       
   756 
       
   757 			// Include pagination
       
   758 			} else {
       
   759 				$redirect_url = trailingslashit( $topic_url ) . trailingslashit( $wp_rewrite->pagination_base ) . trailingslashit( $reply_page ) . $reply_hash;
       
   760 			}
       
   761 
       
   762 			// Add topic view query arg back to end if it is set
       
   763 			if ( bbp_get_view_all() ) {
       
   764 				$redirect_url = bbp_add_view_all( $redirect_url );
       
   765 			}
       
   766 		}
       
   767 
       
   768 		return $redirect_url;
       
   769 	}
       
   770 
       
   771 	/**
       
   772 	 * Redirect to the group admin forum edit screen
       
   773 	 *
       
   774 	 * @since bbPress (r3653)
       
   775 	 * @uses groups_get_current_group()
       
   776 	 * @uses bp_is_group_admin_screen()
       
   777 	 * @uses trailingslashit()
       
   778 	 * @uses bp_get_root_domain()
       
   779 	 * @uses bp_get_groups_root_slug()
       
   780 	 */
       
   781 	public function edit_redirect_to( $redirect_url = '' ) {
       
   782 
       
   783 		// Get the current group, if there is one
       
   784 		$group = groups_get_current_group();
       
   785 
       
   786 		// If this is a group of any kind, empty out the redirect URL
       
   787 		if ( bp_is_group_admin_screen( $this->slug ) )
       
   788 			$redirect_url = trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $group->slug . '/admin/' . $this->slug );
       
   789 
       
   790 		return $redirect_url;
       
   791 	}
       
   792 
       
   793 	/** Form Helpers **********************************************************/
       
   794 
       
   795 	public function forum_parent() {
       
   796 	?>
       
   797 
       
   798 		<input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_group_forums_root_id(); ?>" />
       
   799 
       
   800 	<?php
       
   801 	}
       
   802 
       
   803 	public function topic_parent() {
       
   804 
       
   805 		$forum_ids = bbp_get_group_forum_ids( bp_get_current_group_id() ); ?>
       
   806 
       
   807 		<p>
       
   808 			<label for="bbp_forum_id"><?php _e( 'Forum:', 'bbpress' ); ?></label><br />
       
   809 			<?php bbp_dropdown( array( 'include' => $forum_ids, 'selected' => bbp_get_form_topic_forum() ) ); ?>
       
   810 		</p>
       
   811 
       
   812 	<?php
       
   813 	}
       
   814 
       
   815 	/** Permalink Mappers *****************************************************/
       
   816 
       
   817 	/**
       
   818 	 * Maybe map a bbPress forum/topic/reply permalink to the corresponding group
       
   819 	 *
       
   820 	 * @param int $post_id
       
   821 	 * @uses get_post()
       
   822 	 * @uses bbp_is_reply()
       
   823 	 * @uses bbp_get_reply_topic_id()
       
   824 	 * @uses bbp_get_reply_forum_id()
       
   825 	 * @uses bbp_is_topic()
       
   826 	 * @uses bbp_get_topic_forum_id()
       
   827 	 * @uses bbp_is_forum()
       
   828 	 * @uses get_post_field()
       
   829 	 * @uses bbp_get_forum_group_ids()
       
   830 	 * @uses groups_get_group()
       
   831 	 * @uses bp_get_group_admin_permalink()
       
   832 	 * @uses bp_get_group_permalink()
       
   833 	 * @return Bail early if not a group forum post
       
   834 	 * @return string
       
   835 	 */
       
   836 	private function maybe_map_permalink_to_group( $post_id = 0, $url = false ) {
       
   837 
       
   838 		switch ( get_post_type( $post_id ) ) {
       
   839 
       
   840 			// Reply
       
   841 			case bbp_get_reply_post_type() :
       
   842 				$topic_id = bbp_get_reply_topic_id( $post_id );
       
   843 				$forum_id = bbp_get_reply_forum_id( $post_id );
       
   844 				$url_end  = trailingslashit( $this->reply_slug ) . get_post_field( 'post_name', $post_id );
       
   845 				break;
       
   846 
       
   847 			// Topic
       
   848 			case bbp_get_topic_post_type() :
       
   849 				$topic_id = $post_id;
       
   850 				$forum_id = bbp_get_topic_forum_id( $post_id );
       
   851 				$url_end  = trailingslashit( $this->topic_slug ) . get_post_field( 'post_name', $post_id );
       
   852 				break;
       
   853 
       
   854 			// Forum
       
   855 			case bbp_get_forum_post_type() :
       
   856 				$forum_id = $post_id;
       
   857 				$url_end  = ''; //get_post_field( 'post_name', $post_id );
       
   858 				break;
       
   859 
       
   860 			// Unknown
       
   861 			default :
       
   862 				return $url;
       
   863 				break;
       
   864 		}
       
   865 		
       
   866 		// Get group ID's for this forum
       
   867 		$group_ids = bbp_get_forum_group_ids( $forum_id );
       
   868 
       
   869 		// Bail if the post isn't associated with a group
       
   870 		if ( empty( $group_ids ) )
       
   871 			return $url;
       
   872 
       
   873 		// @todo Multiple group forums/forum groups
       
   874 		$group_id = $group_ids[0];
       
   875 		$group    = groups_get_group( array( 'group_id' => $group_id ) );
       
   876 
       
   877 		if ( bp_is_group_admin_screen( $this->slug ) ) {
       
   878 			$group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) );
       
   879 		} else {
       
   880 			$group_permalink = trailingslashit( bp_get_group_permalink( $group ) );
       
   881 		}
       
   882 
       
   883 		return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end );
       
   884 	}
       
   885 
       
   886 	/**
       
   887 	 * Map a forum permalink to its corresponding group
       
   888 	 *
       
   889 	 * @since bbPress (r3802)
       
   890 	 * @param string $url
       
   891 	 * @param int $forum_id
       
   892 	 * @uses maybe_map_permalink_to_group()
       
   893 	 * @return string
       
   894 	 */
       
   895 	public function map_forum_permalink_to_group( $url, $forum_id ) {
       
   896 		return $this->maybe_map_permalink_to_group( $forum_id, $url );
       
   897 	}
       
   898 
       
   899 	/**
       
   900 	 * Map a topic permalink to its group forum
       
   901 	 *
       
   902 	 * @since bbPress (r3802)
       
   903 	 * @param string $url
       
   904 	 * @param int $topic_id
       
   905 	 * @uses maybe_map_permalink_to_group()
       
   906 	 * @return string
       
   907 	 */
       
   908 	public function map_topic_permalink_to_group( $url, $topic_id ) {
       
   909 		return $this->maybe_map_permalink_to_group( $topic_id, $url );
       
   910 	}
       
   911 
       
   912 	/**
       
   913 	 * Map a reply permalink to its group forum
       
   914 	 *
       
   915 	 * @since bbPress (r3802)
       
   916 	 * @param string $url
       
   917 	 * @param int $reply_id
       
   918 	 * @uses maybe_map_permalink_to_group()
       
   919 	 * @return string
       
   920 	 */
       
   921 	public function map_reply_permalink_to_group( $url, $reply_id ) {
       
   922 		return $this->maybe_map_permalink_to_group( bbp_get_reply_topic_id( $reply_id ), $url );
       
   923 	}
       
   924 
       
   925 	/**
       
   926 	 * Map a reply edit link to its group forum
       
   927 	 *
       
   928 	 * @param string $url
       
   929 	 * @param int $reply_id
       
   930 	 * @uses maybe_map_permalink_to_group()
       
   931 	 * @return string
       
   932 	 */
       
   933 	public function map_reply_edit_url_to_group( $url, $reply_id ) {
       
   934 		$new = $this->maybe_map_permalink_to_group( $reply_id );
       
   935 
       
   936 		if ( empty( $new ) )
       
   937 			return $url;
       
   938 
       
   939 		return trailingslashit( $new ) . bbpress()->edit_id  . '/';
       
   940 	}
       
   941 
       
   942 	/**
       
   943 	 * Map a post link to its group forum
       
   944 	 *
       
   945 	 * @param string $url
       
   946 	 * @param obj $post
       
   947 	 * @param boolean $leavename
       
   948 	 * @uses maybe_map_permalink_to_group()
       
   949 	 * @return string
       
   950 	 */
       
   951 	public function post_link( $url, $post ) {
       
   952 		return $this->maybe_map_permalink_to_group( $post->ID, $url );
       
   953 	}
       
   954 
       
   955 	/**
       
   956 	 * Map a page link to its group forum
       
   957 	 *
       
   958 	 * @param string $url
       
   959 	 * @param int $post_id
       
   960 	 * @param $sample
       
   961 	 * @uses maybe_map_permalink_to_group()
       
   962 	 * @return string
       
   963 	 */
       
   964 	public function page_link( $url, $post_id ) {
       
   965 		return $this->maybe_map_permalink_to_group( $post_id, $url );
       
   966 	}
       
   967 
       
   968 	/**
       
   969 	 * Map a custom post type link to its group forum
       
   970 	 *
       
   971 	 * @param string $url
       
   972 	 * @param obj $post
       
   973 	 * @param $leavename
       
   974 	 * @param $sample
       
   975 	 * @uses maybe_map_permalink_to_group()
       
   976 	 * @return string
       
   977 	 */
       
   978 	public function post_type_link( $url, $post ) {
       
   979 		return $this->maybe_map_permalink_to_group( $post->ID, $url );
       
   980 	}
       
   981 
       
   982 	/**
       
   983 	 * Fix pagination of topics on forum view
       
   984 	 *
       
   985 	 * @param array $args
       
   986 	 * @global $wp_rewrite
       
   987 	 * @uses bbp_get_forum_id()
       
   988 	 * @uses maybe_map_permalink_to_group
       
   989 	 * @return array
       
   990  	 */
       
   991 	public function topic_pagination( $args ) {
       
   992 		$new = $this->maybe_map_permalink_to_group( bbp_get_forum_id() );
       
   993 
       
   994 		if ( empty( $new ) )
       
   995 			return $args;
       
   996 
       
   997 		global $wp_rewrite;
       
   998 
       
   999 		$args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/';
       
  1000 
       
  1001 		return $args;
       
  1002 	}
       
  1003 
       
  1004 	/**
       
  1005 	 * Fix pagination of replies on topic view
       
  1006 	 *
       
  1007 	 * @param array $args
       
  1008 	 * @global $wp_rewrite
       
  1009 	 * @uses bbp_get_topic_id()
       
  1010 	 * @uses maybe_map_permalink_to_group
       
  1011 	 * @return array
       
  1012 	 */
       
  1013 	public function replies_pagination( $args ) {
       
  1014 		$new = $this->maybe_map_permalink_to_group( bbp_get_topic_id() );
       
  1015 		if ( empty( $new ) )
       
  1016 			return $args;
       
  1017 
       
  1018 		global $wp_rewrite;
       
  1019 
       
  1020 		$args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/';
       
  1021 
       
  1022 		return $args;
       
  1023 	}
       
  1024 	
       
  1025 	/**
       
  1026 	 * Ensure that forum content associated with a BuddyPress group can only be
       
  1027 	 * viewed via the group URL.
       
  1028 	 *
       
  1029 	 * @since bbPress (r3802)
       
  1030 	 */
       
  1031 	public function redirect_canonical() {
       
  1032 
       
  1033 		// Viewing a single forum
       
  1034 		if ( bbp_is_single_forum() ) {
       
  1035 			$forum_id  = get_the_ID();
       
  1036 			$group_ids = bbp_get_forum_group_ids( $forum_id );
       
  1037 
       
  1038 		// Viewing a single topic
       
  1039 		} elseif ( bbp_is_single_topic() ) {
       
  1040 			$topic_id  = get_the_ID();
       
  1041 			$slug      = get_post_field( 'post_name', $topic_id );
       
  1042 			$forum_id  = bbp_get_topic_forum_id( $topic_id );
       
  1043 			$group_ids = bbp_get_forum_group_ids( $forum_id );
       
  1044 
       
  1045 		// Not a forum or topic
       
  1046 		} else {
       
  1047 			return;
       
  1048 		}
       
  1049 
       
  1050 		// Bail if not a group forum
       
  1051 		if ( empty( $group_ids ) )
       
  1052 			return;
       
  1053 
       
  1054 		// Use the first group ID
       
  1055 		$group_id 	 = $group_ids[0];
       
  1056 		$group    	 = groups_get_group( array( 'group_id' => $group_id ) );
       
  1057 		$group_link  = trailingslashit( bp_get_group_permalink( $group ) );
       
  1058 		$redirect_to = trailingslashit( $group_link . $this->slug );
       
  1059 
       
  1060 		// Add topic slug to URL
       
  1061 		if ( bbp_is_single_topic() ) {
       
  1062 			$redirect_to  = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug );
       
  1063 		}
       
  1064 
       
  1065 		bp_core_redirect( $redirect_to );
       
  1066 	}
       
  1067 
       
  1068 	/** Activity ***************************************************************/
       
  1069 
       
  1070 	/**
       
  1071 	 * Map a forum post to its corresponding group in the group activity stream.
       
  1072 	 *
       
  1073 	 * @since bbPress (r4396)
       
  1074 	 *
       
  1075 	 * @param array $args Arguments from BBP_BuddyPress_Activity::record_activity()
       
  1076 	 * @uses groups_get_current_group() To see if we're posting from a BP group
       
  1077 	 *
       
  1078 	 * @return array
       
  1079 	 */
       
  1080 	public function map_activity_to_group( $args = array() ) {
       
  1081 
       
  1082 		// Get current BP group
       
  1083 		$group = groups_get_current_group();
       
  1084 
       
  1085 		// Not posting from a BuddyPress group? stop now!
       
  1086 		if ( empty( $group ) )
       
  1087 			return $args;
       
  1088 
       
  1089 		// Set the component to 'groups' so the activity item shows up in the group
       
  1090 		$args['component']         = buddypress()->groups->id;
       
  1091 
       
  1092 		// Move the forum post ID to the secondary item ID
       
  1093 		$args['secondary_item_id'] = $args['item_id'];
       
  1094 
       
  1095 		// Set the item ID to the group ID so the activity item shows up in the group
       
  1096 		$args['item_id']           = $group->id;
       
  1097 
       
  1098 		return $args;
       
  1099 	}	
       
  1100 }
       
  1101 endif;