/**
  * Save the current group to the database.
  *
  * @return bool True on success, false on failure.
  */
 public function save()
 {
     global $wpdb;
     $bp = buddypress();
     $this->creator_id = apply_filters('groups_group_creator_id_before_save', $this->creator_id, $this->id);
     $this->name = apply_filters('groups_group_name_before_save', $this->name, $this->id);
     $this->slug = apply_filters('groups_group_slug_before_save', $this->slug, $this->id);
     $this->description = apply_filters('groups_group_description_before_save', $this->description, $this->id);
     $this->status = apply_filters('groups_group_status_before_save', $this->status, $this->id);
     $this->enable_forum = apply_filters('groups_group_enable_forum_before_save', $this->enable_forum, $this->id);
     $this->date_created = apply_filters('groups_group_date_created_before_save', $this->date_created, $this->id);
     /**
      * Fires before the current group item gets saved.
      *
      * Please use this hook to filter the properties above. Each part will be passed in.
      *
      * @since 1.0.0
      *
      * @param BP_Groups_Group $this Current instance of the group item being saved. Passed by reference.
      */
     do_action_ref_array('groups_group_before_save', array(&$this));
     // Groups need at least a name.
     if (empty($this->name)) {
         return false;
     }
     // Set slug with group title if not passed.
     if (empty($this->slug)) {
         $this->slug = sanitize_title($this->name);
     }
     // Sanity check.
     if (empty($this->slug)) {
         return false;
     }
     // Check for slug conflicts if creating new group.
     if (empty($this->id)) {
         $this->slug = groups_check_slug($this->slug);
     }
     if (!empty($this->id)) {
         $sql = $wpdb->prepare("UPDATE {$bp->groups->table_name} SET\n\t\t\t\t\tcreator_id = %d,\n\t\t\t\t\tname = %s,\n\t\t\t\t\tslug = %s,\n\t\t\t\t\tdescription = %s,\n\t\t\t\t\tstatus = %s,\n\t\t\t\t\tenable_forum = %d,\n\t\t\t\t\tdate_created = %s\n\t\t\t\tWHERE\n\t\t\t\t\tid = %d\n\t\t\t\t", $this->creator_id, $this->name, $this->slug, $this->description, $this->status, $this->enable_forum, $this->date_created, $this->id);
     } else {
         $sql = $wpdb->prepare("INSERT INTO {$bp->groups->table_name} (\n\t\t\t\t\tcreator_id,\n\t\t\t\t\tname,\n\t\t\t\t\tslug,\n\t\t\t\t\tdescription,\n\t\t\t\t\tstatus,\n\t\t\t\t\tenable_forum,\n\t\t\t\t\tdate_created\n\t\t\t\t) VALUES (\n\t\t\t\t\t%d, %s, %s, %s, %s, %d, %s\n\t\t\t\t)", $this->creator_id, $this->name, $this->slug, $this->description, $this->status, $this->enable_forum, $this->date_created);
     }
     if (false === $wpdb->query($sql)) {
         return false;
     }
     if (empty($this->id)) {
         $this->id = $wpdb->insert_id;
     }
     /**
      * Fires after the current group item has been saved.
      *
      * @since 1.0.0
      *
      * @param BP_Groups_Group $this Current instance of the group item that was saved. Passed by reference.
      */
     do_action_ref_array('groups_group_after_save', array(&$this));
     wp_cache_delete($this->id, 'bp_groups');
     return true;
 }
Ejemplo n.º 2
0
/**
 * Catch and process group creation form submissions.
 */
function groups_action_create_group()
{
    global $bp;
    // If we're not at domain.org/groups/create/ then return false
    if (!bp_is_groups_component() || !bp_is_current_action('create')) {
        return false;
    }
    if (!is_user_logged_in()) {
        return false;
    }
    if (!bp_user_can_create_groups()) {
        bp_core_add_message(__('Sorry, you are not allowed to create groups.', 'buddypress'), 'error');
        bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug()));
    }
    // Make sure creation steps are in the right order
    groups_action_sort_creation_steps();
    // If no current step is set, reset everything so we can start a fresh group creation
    $bp->groups->current_create_step = bp_action_variable(1);
    if (!bp_get_groups_current_create_step()) {
        unset($bp->groups->current_create_step);
        unset($bp->groups->completed_create_steps);
        setcookie('bp_new_group_id', false, time() - 1000, COOKIEPATH);
        setcookie('bp_completed_create_steps', false, time() - 1000, COOKIEPATH);
        $reset_steps = true;
        $keys = array_keys($bp->groups->group_creation_steps);
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . array_shift($keys) . '/');
    }
    // If this is a creation step that is not recognized, just redirect them back to the first screen
    if (bp_get_groups_current_create_step() && empty($bp->groups->group_creation_steps[bp_get_groups_current_create_step()])) {
        bp_core_add_message(__('There was an error saving group details. Please try again.', 'buddypress'), 'error');
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/');
    }
    // Fetch the currently completed steps variable
    if (isset($_COOKIE['bp_completed_create_steps']) && !isset($reset_steps)) {
        $bp->groups->completed_create_steps = json_decode(base64_decode(stripslashes($_COOKIE['bp_completed_create_steps'])));
    }
    // Set the ID of the new group, if it has already been created in a previous step
    if (isset($_COOKIE['bp_new_group_id'])) {
        $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id'];
        $bp->groups->current_group = groups_get_group(array('group_id' => $bp->groups->new_group_id));
        // Only allow the group creator to continue to edit the new group
        if (!bp_is_group_creator($bp->groups->current_group, bp_loggedin_user_id())) {
            bp_core_add_message(__('Only the group creator may continue editing this group.', 'buddypress'), 'error');
            bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/');
        }
    }
    // If the save, upload or skip button is hit, lets calculate what we need to save
    if (isset($_POST['save'])) {
        // Check the nonce
        check_admin_referer('groups_create_save_' . bp_get_groups_current_create_step());
        if ('group-details' == bp_get_groups_current_create_step()) {
            if (empty($_POST['group-name']) || empty($_POST['group-desc']) || !strlen(trim($_POST['group-name'])) || !strlen(trim($_POST['group-desc']))) {
                bp_core_add_message(__('Please fill in all of the required fields', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
            $new_group_id = isset($bp->groups->new_group_id) ? $bp->groups->new_group_id : 0;
            if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug(sanitize_title(esc_attr($_POST['group-name']))), 'date_created' => bp_core_current_time(), 'status' => 'public')))) {
                bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
        }
        if ('group-settings' == bp_get_groups_current_create_step()) {
            $group_status = 'public';
            $group_enable_forum = 1;
            if (!isset($_POST['group-show-forum'])) {
                $group_enable_forum = 0;
            } else {
                // Create the forum if enable_forum = 1
                if (bp_is_active('forums') && !groups_get_groupmeta($bp->groups->new_group_id, 'forum_id')) {
                    groups_new_group_forum();
                }
            }
            if ('private' == $_POST['group-status']) {
                $group_status = 'private';
            } else {
                if ('hidden' == $_POST['group-status']) {
                    $group_status = 'hidden';
                }
            }
            if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum)))) {
                bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
            // Set the invite status
            // Checked against a whitelist for security
            $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
            $invite_status = !empty($_POST['group-invite-status']) && in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
            groups_update_groupmeta($bp->groups->new_group_id, 'invite_status', $invite_status);
        }
        if ('group-invites' === bp_get_groups_current_create_step()) {
            if (!empty($_POST['friends'])) {
                foreach ((array) $_POST['friends'] as $friend) {
                    groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->new_group_id));
                }
            }
            groups_send_invites(bp_loggedin_user_id(), $bp->groups->new_group_id);
        }
        do_action('groups_create_group_step_save_' . bp_get_groups_current_create_step());
        do_action('groups_create_group_step_complete');
        // Mostly for clearing cache on a generic action name
        /**
         * Once we have successfully saved the details for this step of the creation process
         * we need to add the current step to the array of completed steps, then update the cookies
         * holding the information
         */
        $completed_create_steps = isset($bp->groups->completed_create_steps) ? $bp->groups->completed_create_steps : array();
        if (!in_array(bp_get_groups_current_create_step(), $completed_create_steps)) {
            $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step();
        }
        // Reset cookie info
        setcookie('bp_new_group_id', $bp->groups->new_group_id, time() + 60 * 60 * 24, COOKIEPATH);
        setcookie('bp_completed_create_steps', base64_encode(json_encode($bp->groups->completed_create_steps)), time() + 60 * 60 * 24, COOKIEPATH);
        // If we have completed all steps and hit done on the final step we
        // can redirect to the completed group
        $keys = array_keys($bp->groups->group_creation_steps);
        if (count($bp->groups->completed_create_steps) == count($keys) && bp_get_groups_current_create_step() == array_pop($keys)) {
            unset($bp->groups->current_create_step);
            unset($bp->groups->completed_create_steps);
            // Once we compelete all steps, record the group creation in the activity stream.
            groups_record_activity(array('type' => 'created_group', 'item_id' => $bp->groups->new_group_id));
            do_action('groups_group_create_complete', $bp->groups->new_group_id);
            bp_core_redirect(bp_get_group_permalink($bp->groups->current_group));
        } else {
            /**
             * Since we don't know what the next step is going to be (any plugin can insert steps)
             * we need to loop the step array and fetch the next step that way.
             */
            foreach ($keys as $key) {
                if ($key == bp_get_groups_current_create_step()) {
                    $next = 1;
                    continue;
                }
                if (isset($next)) {
                    $next_step = $key;
                    break;
                }
            }
            bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $next_step . '/');
        }
    }
    // Remove invitations
    if ('group-invites' === bp_get_groups_current_create_step() && !empty($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id'])) {
        if (!check_admin_referer('groups_invite_uninvite_user')) {
            return false;
        }
        $message = __('Invite successfully removed', 'buddypress');
        $error = false;
        if (!groups_uninvite_user((int) $_REQUEST['user_id'], $bp->groups->new_group_id)) {
            $message = __('There was an error removing the invite', 'buddypress');
            $error = 'error';
        }
        bp_core_add_message($message, $error);
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/');
    }
    // Group avatar is handled separately
    if ('group-avatar' == bp_get_groups_current_create_step() && isset($_POST['upload'])) {
        if (!isset($bp->avatar_admin)) {
            $bp->avatar_admin = new stdClass();
        }
        if (!empty($_FILES) && isset($_POST['upload'])) {
            // Normally we would check a nonce here, but the group save nonce is used instead
            // Pass the file to the avatar upload handler
            if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) {
                $bp->avatar_admin->step = 'crop-image';
                // Make sure we include the jQuery jCrop file for image cropping
                add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
            }
        }
        // If the image cropping is done, crop the image and save a full/thumb version
        if (isset($_POST['avatar-crop-submit']) && isset($_POST['upload'])) {
            // Normally we would check a nonce here, but the group save nonce is used instead
            if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
                bp_core_add_message(__('There was an error saving the group profile photo, please try uploading again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The group profile photo was uploaded successfully!', 'buddypress'));
            }
        }
    }
    bp_core_load_template(apply_filters('groups_template_create_group', 'groups/create'));
}
function groups_create_group($args = '')
{
    extract($args);
    /**
     * Possible parameters (pass as assoc array):
     *	'group_id'
     *	'creator_id'
     *	'name'
     *	'description'
     *	'slug'
     *	'status'
     *	'enable_forum'
     *	'date_created'
     */
    if (!empty($group_id)) {
        $group = groups_get_group(array('group_id' => $group_id));
    } else {
        $group = new BP_Groups_Group();
    }
    if (!empty($creator_id)) {
        $group->creator_id = $creator_id;
    } else {
        $group->creator_id = bp_loggedin_user_id();
    }
    if (isset($name)) {
        $group->name = $name;
    }
    if (isset($description)) {
        $group->description = $description;
    }
    if (isset($slug) && groups_check_slug($slug)) {
        $group->slug = $slug;
    }
    if (isset($status)) {
        if (groups_is_valid_status($status)) {
            $group->status = $status;
        }
    }
    if (isset($enable_forum)) {
        $group->enable_forum = $enable_forum;
    } else {
        if (empty($group_id) && !isset($enable_forum)) {
            $group->enable_forum = 1;
        }
    }
    if (isset($date_created)) {
        $group->date_created = $date_created;
    }
    if (!$group->save()) {
        return false;
    }
    // If this is a new group, set up the creator as the first member and admin
    if (empty($group_id)) {
        $member = new BP_Groups_Member();
        $member->group_id = $group->id;
        $member->user_id = $group->creator_id;
        $member->is_admin = 1;
        $member->user_title = __('Group Admin', 'buddypress');
        $member->is_confirmed = 1;
        $member->date_modified = bp_core_current_time();
        $member->save();
        groups_update_groupmeta($group->id, 'last_activity', bp_core_current_time());
        do_action('groups_create_group', $group->id, $member, $group);
    } else {
        do_action('groups_update_group', $group->id, $group);
    }
    do_action('groups_created_group', $group->id, $group);
    return $group->id;
}
function bp_group_organizer_import_group($group, $args = array())
{
    if (empty($group['name'])) {
        return false;
    }
    if (isset($group['path'])) {
        if (bpgo_is_hierarchy_available()) {
            // Try to place the group in the requested spot, but if the spot doesn't exist (e.g. because of slug conflicts)
            // then place it as far down the tree as possible
            $parent_path = $group['path'];
            do {
                $parent_path = dirname($parent_path);
                $parent_id = BP_Groups_Hierarchy::get_id_from_slug($parent_path);
            } while ($parent_path != '.' && $parent_id == 0);
            $group['parent_id'] = $parent_id ? $parent_id : 0;
        }
        $group['slug'] = basename($group['path']);
        unset($group['path']);
    }
    $group['slug'] = groups_check_slug($group['slug']);
    $group_id = groups_create_group($group);
    if (!$group_id) {
        return false;
    }
    groups_update_groupmeta($group_id, 'total_member_count', 1);
    if (bpgo_is_hierarchy_available()) {
        $obj_group = new BP_Groups_Hierarchy($group_id);
        $obj_group->parent_id = (int) $group['parent_id'];
        $obj_group->save();
    }
    // Create the forum if enable_forum is checked
    if ($group['enable_forum']) {
        // Ensure group forums are activated, and group does not already have a forum
        if (bp_is_active('forums')) {
            // Check for BuddyPress group forums
            if (!groups_get_groupmeta($group_id, 'forum_id')) {
                groups_new_group_forum($group_id, $group['name'], $group['description']);
            }
        } else {
            if (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) {
                // Check for bbPress group forums
                if (count(bbp_get_group_forum_ids($group_id)) == 0) {
                    // Create the group forum - implementation from BBP_Forums_Group_Extension:create_screen_save
                    // Set the default forum status
                    switch ($group['status']) {
                        case 'hidden':
                            $status = bbp_get_hidden_status_id();
                            break;
                        case 'private':
                            $status = bbp_get_private_status_id();
                            break;
                        case 'public':
                        default:
                            $status = bbp_get_public_status_id();
                            break;
                    }
                    // Create the initial forum
                    $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group['name'], 'post_content' => $group['description'], 'post_status' => $status));
                    bbp_add_forum_id_to_group($group_id, $forum_id);
                    bbp_add_group_id_to_forum($forum_id, $group_id);
                }
            }
        }
    }
    do_action('bp_group_organizer_import_group', $group_id);
    return $group_id;
}
Ejemplo n.º 5
0
function bpdd_import_groups($users = false)
{
    $groups = array();
    $group_ids = array();
    if (empty($users)) {
        $users = get_users();
    }
    require dirname(__FILE__) . '/data/groups.php';
    foreach ($groups as $group) {
        $cur = groups_create_group(array('creator_id' => $users[array_rand($users)]->ID, 'name' => $group['name'], 'description' => $group['description'], 'slug' => groups_check_slug(sanitize_title(esc_attr($group['name']))), 'status' => $group['status'], 'date_created' => bpdd_get_random_date(30, 5), 'enable_forum' => $group['enable_forum']));
        groups_update_groupmeta($cur, 'total_member_count', 1);
        groups_update_groupmeta($cur, 'last_activity', bpdd_get_random_date(10));
        // create forums if Forum Component is active
        if (bp_is_active('forums') && bp_forums_is_installed_correctly()) {
            groups_new_group_forum($cur, $group['name'], $group['description']);
        }
        $group_ids[] = $cur;
    }
    return $group_ids;
}
 /**
  * Save the current group to the database.
  *
  * @return bool True on success, false on failure.
  */
 public function save()
 {
     global $wpdb, $bp;
     $this->creator_id = apply_filters('groups_group_creator_id_before_save', $this->creator_id, $this->id);
     $this->name = apply_filters('groups_group_name_before_save', $this->name, $this->id);
     $this->slug = apply_filters('groups_group_slug_before_save', $this->slug, $this->id);
     $this->description = apply_filters('groups_group_description_before_save', $this->description, $this->id);
     $this->status = apply_filters('groups_group_status_before_save', $this->status, $this->id);
     $this->enable_forum = apply_filters('groups_group_enable_forum_before_save', $this->enable_forum, $this->id);
     $this->date_created = apply_filters('groups_group_date_created_before_save', $this->date_created, $this->id);
     do_action_ref_array('groups_group_before_save', array(&$this));
     // Groups need at least a name
     if (empty($this->name)) {
         return false;
     }
     // Set slug with group title if not passed
     if (empty($this->slug)) {
         $this->slug = sanitize_title($this->name);
     }
     // Sanity check
     if (empty($this->slug)) {
         return false;
     }
     // Check for slug conflicts if creating new group
     if (empty($this->id)) {
         $this->slug = groups_check_slug($this->slug);
     }
     if (!empty($this->id)) {
         $sql = $wpdb->prepare("UPDATE {$bp->groups->table_name} SET\n\t\t\t\t\tcreator_id = %d,\n\t\t\t\t\tname = %s,\n\t\t\t\t\tslug = %s,\n\t\t\t\t\tdescription = %s,\n\t\t\t\t\tstatus = %s,\n\t\t\t\t\tenable_forum = %d,\n\t\t\t\t\tdate_created = %s\n\t\t\t\tWHERE\n\t\t\t\t\tid = %d\n\t\t\t\t", $this->creator_id, $this->name, $this->slug, $this->description, $this->status, $this->enable_forum, $this->date_created, $this->id);
     } else {
         $sql = $wpdb->prepare("INSERT INTO {$bp->groups->table_name} (\n\t\t\t\t\tcreator_id,\n\t\t\t\t\tname,\n\t\t\t\t\tslug,\n\t\t\t\t\tdescription,\n\t\t\t\t\tstatus,\n\t\t\t\t\tenable_forum,\n\t\t\t\t\tdate_created\n\t\t\t\t) VALUES (\n\t\t\t\t\t%d, %s, %s, %s, %s, %d, %s\n\t\t\t\t)", $this->creator_id, $this->name, $this->slug, $this->description, $this->status, $this->enable_forum, $this->date_created);
     }
     if (false === $wpdb->query($sql)) {
         return false;
     }
     if (empty($this->id)) {
         $this->id = $wpdb->insert_id;
     }
     do_action_ref_array('groups_group_after_save', array(&$this));
     wp_cache_delete($this->id, 'bp_groups');
     return true;
 }
Ejemplo n.º 7
0
function groups_create_group( $args = '' ) {
	global $bp;

	extract( $args );

	/**
	 * Possible parameters (pass as assoc array):
	 *	'group_id'
	 *	'creator_id'
	 *	'name'
	 *	'description'
	 *	'slug'
	 *	'status'
	 *	'enable_forum'
	 *	'date_created'
	 */

	if ( $group_id )
		$group = new BP_Groups_Group( $group_id );
	else
		$group = new BP_Groups_Group;

	if ( $creator_id )
		$group->creator_id = $creator_id;
	else
		$group->creator_id = $bp->loggedin_user->id;

	if ( isset( $name ) )
		$group->name = $name;

	if ( isset( $description ) )
		$group->description = $description;

	if ( isset( $slug ) && groups_check_slug( $slug ) )
		$group->slug = $slug;

	if ( isset( $status ) ) {
		if ( groups_is_valid_status( $status ) )
			$group->status = $status;
	}

	if ( isset( $enable_forum ) )
		$group->enable_forum = $enable_forum;
	else if ( !$group_id && !isset( $enable_forum ) )
		$group->enable_forum = 1;

	if ( isset( $date_created ) )
		$group->date_created = $date_created;

	if ( !$group->save() )
		return false;

	if ( !$group_id ) {
		// If this is a new group, set up the creator as the first member and admin
		$member = new BP_Groups_Member;
		$member->group_id = $group->id;
		$member->user_id = $group->creator_id;
		$member->is_admin = 1;
		$member->user_title = __( 'Group Admin', 'buddypress' );
		$member->is_confirmed = 1;
		$member->date_modified = gmdate( "Y-m-d H:i:s" );

		$member->save();
		do_action( 'groups_create_group', $group->id, $member, $group );

	} else {
		do_action( 'groups_update_group', $group->id, $group );
	}

	do_action( 'groups_created_group', $group->id );

	return $group->id;
}
Ejemplo n.º 8
0
function bp_group_organizer_admin_page()
{
    global $wpdb;
    // Permissions Check
    if (!current_user_can('manage_options')) {
        wp_die(__('Cheatin’ uh?'));
    }
    // Load all the nav menu interface functions
    require_once 'includes/group-meta-boxes.php';
    require_once 'includes/group-organizer-template.php';
    require_once 'includes/group-organizer.php';
    // Container for any messages displayed to the user
    $messages = array();
    // Container that stores the name of the active menu
    $nav_menu_selected_title = '';
    // Allowed actions: add, update, delete
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'edit';
    $errored = false;
    switch ($action) {
        case 'add-group':
            check_admin_referer('add-group', 'group-settings-column-nonce');
            $group['name'] = stripslashes($_POST['group_name']);
            $group['description'] = stripslashes($_POST['group_desc']);
            $group['slug'] = groups_check_slug($_POST['group_slug']);
            $group['status'] = $_POST['group_status'];
            $group['enable_forum'] = isset($_POST['group_forum']) ? true : false;
            $group['date_created'] = date('Y-m-d H:i:s');
            if ($group['slug'] != $_POST['group_slug']) {
                $messages[] = '<div class="updated warning"><p>' . sprintf(__('The group slug you specified was unavailable or invalid. This group was created with the slug: <code>%s</code>.', 'bp-group-organizer'), $group['slug']) . '</p></div>';
            }
            if (empty($group['name'])) {
                $messages[] = '<div class="error"><p>' . __('Group could not be created because one or more required fields were not filled in', 'bp-group-organizer') . '</p></div>';
                $errored = true;
            }
            if (!$errored) {
                $group_id = groups_create_group($group);
                if (!$group_id) {
                    $wpdb->show_errors();
                    $wpdb->print_error();
                    $messages[] = '<div class="error"><p>' . __('Group was not successfully created.', 'bp-group-organizer') . '</p></div>';
                } else {
                    $messages[] = '<div class="updated"><p>' . __('Group was created successfully.', 'bp-group-organizer') . '</p></div>';
                }
            }
            if (!empty($group_id)) {
                groups_update_groupmeta($group_id, 'total_member_count', 1);
                if (bpgo_is_hierarchy_available()) {
                    $obj_group = new BP_Groups_Hierarchy($group_id);
                    $obj_group->parent_id = (int) $_POST['group_parent'];
                    $obj_group->save();
                }
                // Create the forum if enable_forum is checked
                if ($group['enable_forum']) {
                    // Ensure group forums are activated, and group does not already have a forum
                    if (bp_is_active('forums')) {
                        // Check for BuddyPress group forums
                        if (!groups_get_groupmeta($group_id, 'forum_id')) {
                            groups_new_group_forum($group_id, $group['name'], $group['description']);
                        }
                    } else {
                        if (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) {
                            // Check for bbPress group forums
                            if (count(bbp_get_group_forum_ids($group_id)) == 0) {
                                // Create the group forum - implementation from BBP_Forums_Group_Extension:create_screen_save
                                // Set the default forum status
                                switch ($group['status']) {
                                    case 'hidden':
                                        $status = bbp_get_hidden_status_id();
                                        break;
                                    case 'private':
                                        $status = bbp_get_private_status_id();
                                        break;
                                    case 'public':
                                    default:
                                        $status = bbp_get_public_status_id();
                                        break;
                                }
                                // Create the initial forum
                                $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group['name'], 'post_content' => $group['description'], 'post_status' => $status));
                                bbp_add_forum_id_to_group($group_id, $forum_id);
                                bbp_add_group_id_to_forum($forum_id, $group_id);
                            }
                        }
                    }
                }
                do_action('bp_group_organizer_save_new_group_options', $group_id);
            }
            break;
        case 'delete-group':
            $group_id = (int) $_REQUEST['group_id'];
            check_admin_referer('delete-group_' . $group_id);
            break;
        case 'update':
            check_admin_referer('update-groups', 'update-groups-nonce');
            $groups_order = $_POST['group'];
            $parent_ids = $_POST['menu-item-parent-id'];
            $db_ids = $_POST['menu-item-db-id'];
            foreach ($groups_order as $id => $group) {
                $group_reference = new BP_Groups_Group($id);
                if (defined('BP_GROUP_HIERARCHY_IS_INSTALLED') && method_exists('BP_Groups_Hierarchy', 'get_tree')) {
                    // if group hierarchy is installed and available, check for tree changes
                    $group_hierarchy = new BP_Groups_Hierarchy($id);
                    if ($parent_ids[$id] !== null && $group_hierarchy->parent_id != $parent_ids[$id]) {
                        $group_hierarchy->parent_id = $parent_ids[$id];
                        $group_hierarchy->save();
                    } else {
                        if ($group_hierarchy->parent_id != $group['parent_id']) {
                            $group_hierarchy->parent_id = $group['parent_id'];
                            $group_hierarchy->save();
                        }
                    }
                    unset($group_hierarchy);
                }
                // check for group attribute changes
                $attrs_changed = array();
                if ($group['name'] != $group_reference->name) {
                    $group_reference->name = stripslashes($group['name']);
                    $attrs_changed[] = 'name';
                }
                if ($group['slug'] != $group_reference->slug) {
                    $slug = groups_check_slug($group['slug']);
                    if ($slug == $group['slug']) {
                        $group_reference->slug = $group['slug'];
                        $attrs_changed[] = 'slug';
                    }
                }
                if ($group['description'] != $group_reference->description) {
                    $group_reference->description = stripslashes($group['description']);
                    $attrs_changed[] = 'description';
                }
                if ($group['status'] != $group_reference->status && groups_is_valid_status($group['status'])) {
                    $group_reference->status = $group['status'];
                    $attrs_changed[] = 'status';
                }
                if (!isset($group['forum_enabled']) || $group['forum_enabled'] != $group_reference->enable_forum) {
                    $group_reference->enable_forum = isset($group['forum_enabled']) ? true : false;
                    $attrs_changed[] = 'enable_forum';
                }
                if (count($attrs_changed) > 0) {
                    $group_reference->save();
                }
                // finally, let plugins run any other changes
                do_action('group_details_updated', $group_reference->id);
                do_action('bp_group_organizer_save_group_options', $group, $group_reference);
            }
            break;
        case 'import':
            if (!isset($_FILES['import_groups'])) {
                // No files was uploaded
            }
            if (!is_uploaded_file($_FILES['import_groups']['tmp_name'])) {
                // Not an uploaded file
                $errors = array(UPLOAD_ERR_OK => sprintf(__('File uploaded successfully, but there is a problem. (%d)', 'bp-group-organizer'), UPLOAD_ERR_OK), UPLOAD_ERR_INI_SIZE => sprintf(__('File exceeded PHP\'s maximum upload size. (%d)', 'bp-group-organizer'), UPLOAD_ERR_INI_SIZE), UPLOAD_ERR_FORM_SIZE => sprintf(__('File exceeded the form\'s maximum upload size. (%d)', 'bp-group-organizer'), UPLOAD_ERR_FORM_SIZE), UPLOAD_ERR_PARTIAL => sprintf(__('File was only partially uploaded. (%d)', 'bp-group-organizer'), UPLOAD_ERR_PARTIAL), UPLOAD_ERR_NO_FILE => sprintf(__('No uploaded file was found. (%d)', 'bp-group-organizer'), UPLOAD_ERR_NO_FILE), 6 => sprintf(__('No temporary folder could be found for the uploaded file. (%d)', 'bp-group-organizer'), 6), 7 => sprintf(__('Could not write uploaded file to disk. (%d)', 'bp-group-organizer'), 7), 8 => sprintf(__('Upload was stopped by a PHP extension. (%d)', 'bp-group-organizer'), 8));
                $messages[] = '<div class="error"><p>' . sprintf(__('', 'bp-group-organizer'), $errors[$_FILES['import_groups']['error']]) . '</p></div>';
                break;
            }
            require_once dirname(__FILE__) . '/includes/group-organizer-import.php';
            if ($result = bp_group_organizer_import_csv_file($_FILES['import_groups']['tmp_name'], $_POST['import'])) {
                $messages[] = '<div class="updated"><p>' . implode('<br />', $result) . '</p></div>';
            } else {
                $messages[] = '<div class="error"><p>' . 'ERROR - IMPORT FAILED COMPLETELY' . '</p></div>';
            }
            break;
    }
    // Ensure the user will be able to scroll horizontally
    // by adding a class for the max menu depth.
    global $_wp_nav_menu_max_depth;
    $_wp_nav_menu_max_depth = 0;
    if (isset($_REQUEST['screen']) && $_REQUEST['screen'] == 'import') {
        $action = 'import';
    } else {
        $action = 'organize';
    }
    if ($action == 'import') {
        $edit_markup = bp_group_organizer_import_export_page();
    } else {
        $edit_markup = bp_get_groups_to_edit();
    }
    ?>
<div class="wrap">
	<h2><?php 
    esc_html_e('Group Organizer');
    ?>
</h2>
	<?php 
    foreach ($messages as $message) {
        echo $message . "\n";
    }
    ?>
	<div <?php 
    if ($action == 'organize') {
        echo 'id="nav-menus-frame"';
    }
    ?>
>
	<div id="menu-settings-column" class="metabox-holder nav-menus-php">
		<form id="group-organizer-meta" action="" class="group-organizer-meta" method="post" enctype="multipart/form-data">
			<input type="hidden" name="action" value="add-group" />
			<?php 
    wp_nonce_field('add-group', 'group-settings-column-nonce');
    ?>
			<?php 
    if ($action == 'organize') {
        do_meta_boxes('group-organizer', 'side', null);
    }
    ?>
		</form>
	</div><!-- /#menu-settings-column -->
	<div id="menu-management-liquid">
		<div id="menu-management" class="nav-menus-php">

			<div class="nav-tabs-wrapper">
			<div class="nav-tabs">
				<a href="<?php 
    echo esc_url(remove_query_arg(array('screen')));
    ?>
" class="nav-tab <?php 
    if ($action == 'organize') {
        echo 'nav-tab-active';
    }
    ?>
">
					<?php 
    printf('<abbr title="%s">%s</abbr>', esc_html__('Drag and drop your groups', 'bp-group-hierarchy'), __('Organize', 'bp-group-organizer'));
    ?>
				</a>
				<a href="<?php 
    echo esc_url(add_query_arg(array('screen' => 'import')));
    ?>
" class="nav-tab <?php 
    if ($action == 'import') {
        echo 'nav-tab-active';
    }
    ?>
">
					<?php 
    printf('<abbr title="%s">%s</abbr>', esc_html__('Import or export groups in bulk', 'bp-group-organizer'), __('Import / Export', 'bp-group-organizer'));
    ?>
				</a>
			</div>
			</div>


			<div class="menu-edit">
				<?php 
    if ($action == 'organize') {
        ?>
				<form id="update-nav-menu" action="" method="post" enctype="multipart/form-data">
				<?php 
    }
    ?>
					<div id="nav-menu-header">
						<div id="submitpost" class="submitbox">
							<div class="major-publishing-actions">
								<label class="menu-name-label howto open-label" for="menu-name">
									<span><?php 
    _e('Group Organizer', 'bp-group-organizer');
    ?>
</span>
								</label>
								<div class="publishing-action">
									<?php 
    if ($action == 'organize') {
        submit_button(__('Save Groups', 'bp-group-organizer'), 'button-primary menu-save', 'save_menu', false, array('id' => 'save_menu_header'));
    }
    ?>
								</div><!-- END .publishing-action -->
							</div><!-- END .major-publishing-actions -->
						</div><!-- END #submitpost .submitbox -->
						<?php 
    wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
    wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
    wp_nonce_field('update-groups', 'update-groups-nonce');
    ?>
						<input type="hidden" name="action" value="update" />
					</div><!-- END #nav-menu-header -->
					<div id="post-body">
						<div id="post-body-content">
							<?php 
    if (isset($edit_markup)) {
        if (!is_wp_error($edit_markup)) {
            echo $edit_markup;
        }
    } else {
        echo '<div class="post-body-plain">';
        echo '<p>' . __('You don\'t yet have any groups.', 'bp-group-organizer') . '</p>';
        echo '</div>';
    }
    ?>
						</div><!-- /#post-body-content -->
					</div><!-- /#post-body -->
					<div id="nav-menu-footer">
						<div class="major-publishing-actions">
						<div class="publishing-action">
							<?php 
    if ($action == 'organize') {
        submit_button(__('Save Groups', 'bp-group-organizer'), 'button-primary menu-save', 'save_menu', false, array('id' => 'save_menu_header'));
    }
    ?>
						</div>
						</div>
					</div><!-- /#nav-menu-footer -->
				<?php 
    if ($action == 'organize') {
        ?>
				</form><!-- /#update-nav-menu -->
				<?php 
    }
    ?>
			</div><!-- /.menu-edit -->
		</div><!-- /#menu-management -->
	</div><!-- /#menu-management-liquid -->
	</div><!-- /#nav-menus-frame -->
</div><!-- /.wrap-->

<?php 
}
Ejemplo n.º 9
0
function groups_create_group($step, $group_id)
{
    global $bp, $create_group_step, $group_obj, $bbpress_live;
    if (is_numeric($step) && (1 == (int) $step || 2 == (int) $step || 3 == (int) $step || 4 == (int) $step)) {
        if (!$group_obj) {
            $group_obj = new BP_Groups_Group($group_id);
        }
        switch ($step) {
            case '1':
                if (!check_admin_referer('groups_step1_save')) {
                    return false;
                }
                if ($_POST['group-name'] != '' && $_POST['group-desc'] != '') {
                    $group_obj->creator_id = $bp->loggedin_user->id;
                    $group_obj->name = stripslashes($_POST['group-name']);
                    $group_obj->description = stripslashes($_POST['group-desc']);
                    $group_obj->news = stripslashes($_POST['group-news']);
                    $slug = groups_check_slug(sanitize_title($_POST['group-name']));
                    $group_obj->slug = $slug;
                    $group_obj->status = 'public';
                    $group_obj->is_invitation_only = 0;
                    $group_obj->enable_wire = 1;
                    $group_obj->enable_forum = 1;
                    $group_obj->enable_photos = 1;
                    $group_obj->photos_admin_only = 0;
                    $group_obj->date_created = time();
                    if (!$group_obj->save()) {
                        return false;
                    }
                    // Save the creator as the group administrator
                    $admin = new BP_Groups_Member($bp->loggedin_user->id, $group_obj->id);
                    $admin->is_admin = 1;
                    $admin->user_title = __('Group Admin', 'buddypress');
                    $admin->date_modified = time();
                    $admin->inviter_id = 0;
                    $admin->is_confirmed = 1;
                    if (!$admin->save()) {
                        return false;
                    }
                    do_action('groups_create_group_step1_save');
                    /* Set groupmeta */
                    groups_update_groupmeta($group_obj->id, 'total_member_count', 1);
                    groups_update_groupmeta($group_obj->id, 'last_activity', time());
                    groups_update_groupmeta($group_obj->id, 'theme', 'buddypress');
                    groups_update_groupmeta($group_obj->id, 'stylesheet', 'buddypress');
                    return $group_obj->id;
                }
                return false;
                break;
            case '2':
                if (!check_admin_referer('groups_step2_save')) {
                    return false;
                }
                $group_obj->status = 'public';
                $group_obj->is_invitation_only = 0;
                $group_obj->enable_wire = 1;
                $group_obj->enable_forum = 1;
                $group_obj->enable_photos = 1;
                $group_obj->photos_admin_only = 0;
                if (!isset($_POST['group-show-wire'])) {
                    $group_obj->enable_wire = 0;
                }
                if (!isset($_POST['group-show-forum'])) {
                    $group_obj->enable_forum = 0;
                } else {
                    /* Create the forum if enable_forum = 1 */
                    if (function_exists('bp_forums_setup') && '' == groups_get_groupmeta($group_obj->id, 'forum_id')) {
                        groups_new_group_forum();
                    }
                }
                if (!isset($_POST['group-show-photos'])) {
                    $group_obj->enable_photos = 0;
                }
                if ($_POST['group-photos-status'] != 'all') {
                    $group_obj->photos_admin_only = 1;
                }
                if ('private' == $_POST['group-status']) {
                    $group_obj->status = 'private';
                } else {
                    if ('hidden' == $_POST['group-status']) {
                        $group_obj->status = 'hidden';
                    }
                }
                if (!$group_obj->save()) {
                    return false;
                }
                /* Record in activity streams */
                groups_record_activity(array('item_id' => $group_obj->id, 'component_name' => $bp->groups->slug, 'component_action' => 'created_group', 'is_private' => 0));
                do_action('groups_create_group_step2_save');
                return $group_obj->id;
                break;
            case '3':
                if (!check_admin_referer('groups_step3_save')) {
                    return false;
                }
                if (isset($_POST['skip'])) {
                    return $group_obj->id;
                }
                // Image already cropped and uploaded, lets store a reference in the DB.
                if (!wp_verify_nonce($_POST['nonce'], 'slick_avatars') || !($result = bp_core_avatar_cropstore($_POST['orig'], $_POST['canvas'], $_POST['v1_x1'], $_POST['v1_y1'], $_POST['v1_w'], $_POST['v1_h'], $_POST['v2_x1'], $_POST['v2_y1'], $_POST['v2_w'], $_POST['v2_h'], false, 'groupavatar', $group_obj->id))) {
                    return false;
                }
                // Success on group avatar cropping, now save the results.
                $avatar_hrefs = groups_get_avatar_hrefs($result);
                $group_obj->avatar_thumb = stripslashes($avatar_hrefs['thumb_href']);
                $group_obj->avatar_full = stripslashes($avatar_hrefs['full_href']);
                if (!$group_obj->save()) {
                    return false;
                }
                do_action('groups_create_group_step3_save');
                return $group_obj->id;
                break;
            case '4':
                if (!check_admin_referer('groups_step4_save')) {
                    return false;
                }
                groups_send_invites($group_obj, true);
                do_action('groups_created_group', $group_obj->id);
                return $group_obj->id;
                break;
        }
    }
    return false;
}
Ejemplo n.º 10
0
function bp_ning_import_get_discussions()
{
    global $wpdb;
    $ning_id_array = get_option('bp_ning_user_array');
    // Get list of Ning groups for cross reference
    $groups = bp_ning_import_prepare_json('groups');
    $ning_group_id_array = get_option('bp_ning_group_array', array());
    $discussions = bp_ning_import_prepare_json('discussions');
    //delete_option('bp_ning_discussions_imported');
    $imported = get_option('bp_ning_discussions_imported', array());
    $counter = 0;
    foreach ((array) $discussions as $discussion_key => $discussion) {
        unset($topic_id);
        if (isset($imported[$discussion->id])) {
            continue;
        }
        if ($counter >= 10) {
            update_option('bp_ning_discussions_imported', $imported);
            printf(__('%d out of %d discussions done.'), count($imported), count($discussions));
            return false;
        }
        $slug = sanitize_title(esc_attr($discussion->category));
        $ning_group_creator_id = $discussion->contributorName;
        $creator_id = $ning_id_array[$ning_group_creator_id];
        if (!$creator_id) {
            $what++;
            continue;
        }
        $ndate = strtotime($discussion->createdDate);
        $date_created = date("Y-m-d H:i:s", $ndate);
        if (isset($discussion->category)) {
            $ning_group_id = $discussion->category;
            $group_id = $ning_group_id_array[$ning_group_id];
        } else {
            if (isset($discussion->groupId)) {
                $ngroup_id = $discussion->groupId;
                $group_id = $ning_group_id_array[$ngroup_id];
            } else {
                continue;
                // todo fix me!
            }
        }
        $group = new BP_Groups_Group($group_id);
        $args = array('topic_title' => $discussion->title, 'topic_slug' => groups_check_slug(sanitize_title(esc_attr($discussion->title))), 'topic_text' => $discussion->description, 'topic_poster' => $creator_id, 'topic_poster_name' => bp_core_get_user_displayname($creator_id), 'topic_last_poster' => $creator_id, 'topic_last_poster_name' => bp_core_get_user_displayname($creator_id), 'topic_start_time' => $date_created, 'topic_time' => $date_created, 'forum_id' => groups_get_groupmeta($group_id, 'forum_id'));
        $query = "SELECT `topic_id` FROM wp_bb_topics WHERE topic_title = '%s' AND topic_start_time = '%s' LIMIT 1";
        $q = $wpdb->prepare($query, $args['topic_title'], $args['topic_start_time']);
        $topic_exists = $wpdb->get_results($q);
        if (isset($topic_exists[0])) {
            echo "<em>- Topic {$discussion->title} already exists</em><br />";
            $imported[$discussion->id] = true;
            continue;
        }
        if (!$args['forum_id']) {
            echo "No forum id - skipping";
            continue;
        }
        if (!($topic_id = bp_forums_new_topic($args))) {
            // TODO: WTF?
            return false;
            echo "<h2>Refresh to import more discussions</h2>";
            die;
        } else {
            bp_ning_import_process_inline_images_new('discussions', $topic_id, 'topic');
            echo "<strong>- Created topic: {$discussion->title}</strong><br />";
        }
        $activity_content = bp_create_excerpt($discussion->description);
        $skip_activity = get_option('bp_ning_skip_forum_activity');
        if (!$skip_activity) {
            $topic = bp_forums_get_topic_details($topic_id);
            // Activity item
            $activity_action = sprintf(__('%s started the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink($creator_id), '<a href="' . bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_html($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_html($group->name) . '</a>');
            groups_record_activity(array('user_id' => $creator_id, 'action' => apply_filters('groups_activity_new_forum_topic_action', $activity_action, $discussion->description, $topic), 'content' => apply_filters('groups_activity_new_forum_topic_content', $activity_content, $discussion->description, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_topic_primary_link', bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/'), 'type' => 'new_forum_topic', 'item_id' => $group_id, 'secondary_item_id' => $topic->topic_id, 'recorded_time' => $date_created, 'hide_sitewide' => 0));
            do_action('groups_new_forum_topic', $group_id, $topic);
        }
        // Now check for comments
        if (isset($discussion->comments)) {
            foreach ($discussion->comments as $reply) {
                $ning_group_creator_id = $reply->contributorName;
                $creator_id = $ning_id_array[$ning_group_creator_id];
                $ndate = strtotime($reply->createdDate);
                $date_created = date("Y-m-d H:i:s", $ndate);
                $args = array('topic_id' => $topic_id, 'post_text' => $reply->description, 'post_time' => $date_created, 'poster_id' => $creator_id, 'poster_ip' => '192.168.1.1');
                $query = "SELECT * FROM wp_bb_posts WHERE topic_id = '%s' AND post_text = '%s'";
                $q = $wpdb->prepare($query, $args['topic_id'], $args['post_text']);
                $post_exists = $wpdb->get_results($q);
                if ($post_exists) {
                    continue;
                }
                $post_id = bp_forums_insert_post($args);
                if ($post_id) {
                    bp_ning_import_process_inline_images_new('discussions', $post_id, 'topic_reply');
                    $import_summary = esc_html(bp_create_excerpt($reply->description, 100, array('html' => false)));
                    echo "<em>- Imported forum post: {$import_summary}</em><br />";
                }
                if (!groups_is_user_member($creator_id, $group_id)) {
                    if (!$bp->groups->current_group) {
                        $bp->groups->current_group = new BP_Groups_Group($group_id);
                    }
                    $new_member = new BP_Groups_Member();
                    $new_member->group_id = $group_id;
                    $new_member->user_id = $creator_id;
                    $new_member->inviter_id = 0;
                    $new_member->is_admin = 0;
                    $new_member->user_title = '';
                    $new_member->date_modified = $date_created;
                    $new_member->is_confirmed = 1;
                    $new_member->save();
                    groups_update_groupmeta($group_id, 'total_member_count', (int) groups_get_groupmeta($group_id, 'total_member_count') + 1);
                    groups_update_groupmeta($group_id, 'last_activity', $date_created);
                    do_action('groups_join_group', $group_id, $creator_id);
                }
                if ($skip_activity) {
                    continue;
                }
                // Activity item
                $topic = bp_forums_get_topic_details($topic_id);
                $activity_action = sprintf(__('%s posted on the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink($creator_id), '<a href="' . bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>');
                $activity_content = bp_create_excerpt($reply->description);
                $primary_link = bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/';
                //if ( $page )
                //	$primary_link .= "?topic_page=" . $page;
                //echo $primary_link; die();
                groups_record_activity(array('user_id' => $creator_id, 'action' => apply_filters('groups_activity_new_forum_post_action', $activity_action, $post_id, $reply->description, $topic), 'content' => apply_filters('groups_activity_new_forum_post_content', $activity_content, $post_id, $reply->description, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}"), 'type' => 'new_forum_post', 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'recorded_time' => $date_created, 'hide_sitewide' => 0));
                do_action('groups_new_forum_topic_post', $group_id, $post_id);
            }
        }
        $imported[$discussion->id] = true;
        $counter++;
    }
    update_option('bp_ning_discussions_imported', $imported);
    return true;
}