Beispiel #1
0
function groups_new_group_forum_topic($topic_title, $topic_text, $topic_tags, $forum_id)
{
    global $bp;
    if (empty($topic_title) || empty($topic_text)) {
        return false;
    }
    $topic_title = apply_filters('group_forum_topic_title_before_save', $topic_title);
    $topic_text = apply_filters('group_forum_topic_text_before_save', $topic_text);
    $topic_tags = apply_filters('group_forum_topic_tags_before_save', $topic_tags);
    $forum_id = apply_filters('group_forum_topic_forum_id_before_save', $forum_id);
    if ($topic_id = bp_forums_new_topic(array('topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id))) {
        $topic = bp_forums_get_topic_details($topic_id);
        $activity_action = sprintf(__('%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>');
        $activity_content = bp_create_excerpt($topic_text);
        // Record this in activity streams
        groups_record_activity(array('action' => apply_filters_ref_array('groups_activity_new_forum_topic_action', array($activity_action, $topic_text, &$topic)), 'content' => apply_filters_ref_array('groups_activity_new_forum_topic_content', array($activity_content, $topic_text, &$topic)), 'primary_link' => apply_filters('groups_activity_new_forum_topic_primary_link', bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/'), 'type' => 'new_forum_topic', 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic->topic_id));
        do_action_ref_array('groups_new_forum_topic', array($bp->groups->current_group->id, &$topic));
        return $topic;
    }
    return false;
}
/**
 * Create a new group forum topic.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.0.0)
 *
 * @param string $topic_title The title for the forum topic.
 * @param string $topic_text  The text for the forum topic.
 * @param string $topic_tags  A comma-delimited string of topic tags.
 * @param int    $forum_id    The forum ID this forum topic resides in.
 *
 * @return mixed The new topic object on success. Boolean false on failure.
 */
function groups_new_group_forum_topic($topic_title, $topic_text, $topic_tags, $forum_id)
{
    if (empty($topic_title) || empty($topic_text)) {
        return false;
    }
    /**
     * Filters the new groups forum topic title before saving.
     *
     * @since BuddyPress (1.2.0)
     *
     * @param string $topic_title The title for the forum topic.
     */
    $topic_title = apply_filters('group_forum_topic_title_before_save', $topic_title);
    /**
     * Filters the new groups forum topic text before saving.
     *
     * @since BuddyPress (1.2.0)
     *
     * @param string $topic_text The text for the forum topic.
     */
    $topic_text = apply_filters('group_forum_topic_text_before_save', $topic_text);
    /**
     * Filters the new groups forum topic tags before saving.
     *
     * @since BuddyPress (1.2.0)
     *
     * @param string $topic_tags A comma-delimited string of topic tags.
     */
    $topic_tags = apply_filters('group_forum_topic_tags_before_save', $topic_tags);
    /**
     * Filters the forum ID this forum topic resides in.
     *
     * @since BuddyPress (1.2.0)
     *
     * @param string $forum_id The forum ID this forum topic resides in.
     */
    $forum_id = apply_filters('group_forum_topic_forum_id_before_save', $forum_id);
    $topic_id = bp_forums_new_topic(array('topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id));
    if (empty($topic_id)) {
        return false;
    }
    $topic = bp_forums_get_topic_details($topic_id);
    $activity_action = sprintf(__('%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink(bp_loggedin_user_id()), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>');
    $activity_content = bp_create_excerpt($topic_text);
    /**
     * Filters the new groups activity forum topic action.
     *
     * @since BuddyPress (1.2.0)
     *
     * @param string $activity_action Formatted action related to forum topic.
     * @param string $topic_text      New topic text.
     * @param object $topic           Object holding current topic details. Passed by reference.
     */
    $action = apply_filters_ref_array('groups_activity_new_forum_topic_action', array($activity_action, $topic_text, &$topic));
    /**
     * Filters the new groups activity forum topic content.
     *
     * @since BuddyPress (1.2.0)
     *
     * @param string $activity_content Excerpt-length activity content to be posted.
     * @param string $topic_text       New topic text.
     * @param object $topic            Object holding current topic details. Passed by reference.
     */
    $content = apply_filters_ref_array('groups_activity_new_forum_topic_content', array($activity_content, $topic_text, &$topic));
    /**
     * Filters the new groups activity forum topic primary link.
     *
     * @since BuddyPress (1.1.0)
     *
     * @param string $value Concatenated primary link.
     */
    $primary_link = apply_filters('groups_activity_new_forum_topic_primary_link', bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/');
    groups_record_activity(array('action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'type' => 'new_forum_topic', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $topic->topic_id));
    /**
     * Fires after the creation of a new group forum topic.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param int    $value ID of the current group.
     * @param object $topic Object holding current topic details. Passed by reference.
     */
    do_action_ref_array('groups_new_forum_topic', array(bp_get_current_group_id(), &$topic));
    return $topic;
}
/**
 * Modified version of {@link groups_new_group_forum_topic()}.
 *
 * Duplicated because:
 * 	- groups_new_group_forum_topic() hardcodes the $user_id.
 * 	- $bp->groups->current_group doesn't exist outside the BP groups component.
 * 	- {@link groups_record_activity()} restricts a bunch of parameters - use full {@link bp_activity_add()} instead.
 *
 * @param mixed $args Arguments can be passed as an associative array or as a URL argument string
 * @return mixed If forum topic is successful, returns the forum topic ID; false on failure
 * @since 1.0-beta
 */
function bp_rbe_groups_new_group_forum_topic($args = '')
{
    global $bp;
    $defaults = array('topic_title' => false, 'topic_text' => false, 'topic_tags' => false, 'forum_id' => false, 'user_id' => false, 'group_id' => false);
    $r = apply_filters('bp_rbe_groups_new_group_forum_topic_args', wp_parse_args($args, $defaults));
    extract($r);
    if (empty($topic_title) || empty($topic_text)) {
        return false;
    }
    if (empty($forum_id)) {
        $forum_id = groups_get_groupmeta($group_id, 'forum_id');
    }
    // apply BP's filters
    $topic_title = apply_filters('group_forum_topic_title_before_save', $topic_title);
    $topic_text = apply_filters('group_forum_topic_text_before_save', $topic_text);
    $topic_tags = apply_filters('group_forum_topic_tags_before_save', $topic_tags);
    $forum_id = apply_filters('group_forum_topic_forum_id_before_save', $forum_id);
    if ($topic_id = bp_forums_new_topic(array('topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id, 'topic_poster' => $user_id, 'topic_last_poster' => $user_id, 'topic_poster_name' => bp_core_get_user_displayname($user_id), 'topic_last_poster_name' => bp_core_get_user_displayname($user_id)))) {
        // initialize bundled bbPress
        do_action('bbpress_init');
        global $bbdb;
        // do a direct bbPress DB call
        if (isset($bbdb)) {
            $topic = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->topics} WHERE topic_id = {$topic_id}"));
        }
        $group = groups_get_group('group_id=' . $group_id);
        $activity_action = sprintf(__('%s started the forum topic %s in the group %s via email:', 'bp-rbe'), bp_core_get_userlink($user_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($topic_text);
        /* Record this in activity streams */
        $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('groups_activity_new_forum_topic_action', $activity_action, $topic_text, $topic), 'content' => apply_filters('groups_activity_new_forum_topic_content', $activity_content, $topic_text, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_topic_primary_link', bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/'), 'component' => $bp->groups->id, 'type' => 'new_forum_topic', 'item_id' => $group_id, 'secondary_item_id' => $topic_id, 'hide_sitewide' => $group->status == 'public' ? false : true));
        // special hook for RBE activity items
        do_action('bp_rbe_new_activity', array('activity_id' => $activity_id, 'type' => 'new_forum_topic', 'user_id' => $user_id, 'item_id' => $group_id, 'secondary_item_id' => $topic_id, 'content' => $activity_content));
        // apply BP's group forum topic hook
        do_action('groups_new_forum_topic', $group_id, $topic);
        return $topic;
    }
    return false;
}
Beispiel #4
0
function groups_new_group_forum_topic($topic_title, $topic_text, $topic_tags, $forum_id)
{
    global $group_obj;
    /* Check the nonce */
    if (!check_admin_referer('bp_forums_new_topic')) {
        return false;
    }
    if ($topic = bp_forums_new_topic($topic_title, $topic_text, $topic_tags, $forum_id)) {
        bp_core_add_message(__('Topic posted successfully!', 'buddypress'));
        /* Record in activity streams */
        groups_record_activity(array('item_id' => $group_obj->id, 'component_name' => $bp->groups->slug, 'component_action' => 'new_forum_topic', 'is_private' => 0, 'secondary_item_id' => $topic['topic_id']));
        do_action('groups_new_forum_topic', $group_obj->id, $topic);
        return $topic;
    }
    bp_core_add_message(__('There was an error posting that topic.', 'buddypress'), 'error');
    return false;
}
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;
}