Beispiel #1
0
/**
 * Calculates the bible references for an activity before it is saved
 *
 * @param $activity
 */
function bfox_bp_activity_before_save($activity)
{
    global $bp;
    // For blog posts, index the full post content and tags
    if ($activity->component == $bp->blogs->id && $activity->type == 'new_blog_post') {
        switch_to_blog($activity->item_id);
        $ref = bfox_blog_post_get_ref($activity->secondary_item_id);
        restore_current_blog();
    } elseif ($activity->component == $bp->groups->id && ($activity->type == 'new_forum_post' || $activity->type == 'new_forum_topic')) {
        // Get the forum post
        if ($activity->type == 'new_forum_topic') {
            list($post) = bp_forums_get_topic_posts(array('topic_id' => $activity->secondary_item_id, 'per_page' => 1));
        } else {
            $post = bp_forums_get_post($activity->secondary_item_id);
        }
        // Index the post text
        $ref = bfox_ref_from_content($post->post_text);
        // Only index the tags for the first post in a topic
        if ($activity->type == 'new_forum_topic') {
            $tags = bb_get_topic_tags($post->topic_id, array('fields' => 'names'));
            foreach ($tags as $tag) {
                $ref->add_ref(bfox_ref_from_tag($tag));
            }
        }
    } else {
        $ref = bfox_ref_from_content($activity->content);
    }
    // Add any 'Bible Tag' read passage strings
    if ('activity_update' == $activity->type && isset($_REQUEST['bfox_read_ref_str'])) {
        $tag_ref = new BfoxRef($_REQUEST['bfox_read_ref_str']);
        if ($tag_ref->is_valid()) {
            $activity->bfox_read_ref_str = $tag_ref->get_string();
            $activity->action = str_replace('posted an update', __('posted an update about ', 'bfox') . $activity->bfox_read_ref_str, $activity->action);
            $ref->add_ref($tag_ref);
        }
    }
    if ($ref->is_valid()) {
        $activity->bfox_ref = $ref;
    }
}
/**
 * Create a new post.
 *
 * @param array $args {
 *     @type int $post_id Optional. ID of an existing post, if you want to
 *           update rather than create. Default: false.
 *     @type int $topic_id ID of the topic to which the post belongs.
 *     @type string $post_text Contents of the post.
 *     @type string $post_time Optional. Time when the post was recorded.
 *           Default: current time, as reported by {@link bp_core_current_time()}.
 *     @type int $poster_id Optional. ID of the user creating the post.
 *           Default: ID of the logged-in user.
 *     @type string $poster_ip Optional. IP address of the user creating the
 *           post. Default: the IP address found in $_SERVER['REMOTE_ADDR'].
 *     @type int $post_status Post status. Default: 0.
 *     @type int $post_position Optional. Default: false (auto).
 * }
 * @return int|bool ID of the new post on success, false on failure.
 */
function bp_forums_insert_post($args = '')
{
    /** This action is documented in bp-forums/bp-forums-screens */
    do_action('bbpress_init');
    $defaults = array('post_id' => false, 'topic_id' => false, 'post_text' => '', 'post_time' => bp_core_current_time(), 'poster_id' => bp_loggedin_user_id(), 'poster_ip' => $_SERVER['REMOTE_ADDR'], 'post_status' => 0, 'post_position' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if (!($post = bp_forums_get_post($post_id))) {
        $post_id = false;
    }
    if (!isset($topic_id)) {
        $topic_id = $post->topic_id;
    }
    if (empty($post_text)) {
        $post_text = $post->post_text;
    }
    if (!isset($post_time)) {
        $post_time = $post->post_time;
    }
    if (!isset($post_position)) {
        $post_position = $post->post_position;
    }
    if (empty($poster_id)) {
        return false;
    }
    if (bp_is_user_inactive(bp_loggedin_user_id())) {
        return false;
    }
    $post_id = bb_insert_post(array('post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes(trim($post_text)), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position));
    if (!empty($post_id)) {
        /**
         * Fires if there was a new post created.
         *
         * @since BuddyPress (1.0.0)
         *
         * @param int $post_id ID of the newly created forum post.
         */
        do_action('bp_forums_new_post', $post_id);
    }
    return $post_id;
}
/**
 * Update an existing group forum post.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int    $post_id   The post ID of the existing forum post.
 * @param string $post_text The text for the forum post.
 * @param int    $topic_id  The topic ID of the existing forum topic.
 * @param mixed  $page      The page number where the new forum post should reside. Optional.
 *
 * @return mixed The forum post ID on success. Boolean false on failure.
 */
function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false)
{
    $bp = buddypress();
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $post_text = apply_filters('group_forum_post_text_before_save', $post_text);
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id);
    $post = bp_forums_get_post($post_id);
    $post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id));
    if (empty($post_id)) {
        return false;
    }
    $topic = bp_forums_get_topic_details($topic_id);
    $activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_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($post_text);
    $primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/';
    if (!empty($page)) {
        $primary_link .= "?topic_page=" . $page;
    }
    // Get the corresponding activity item
    if (bp_is_active('activity')) {
        $id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id));
    }
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $action = apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic));
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $content = apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic));
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $filtered_primary_link = apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id);
    groups_record_activity(array('id' => $id, 'action' => $action, 'content' => $content, 'primary_link' => $filtered_primary_link, 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time));
    /**
     * Fires after the update of a group forum post.
     *
     * @since BuddyPress (1.1.0)
     *
     * @param object $post  Object holding current post being updated.
     * @param object $topic Object holding current topic details. Passed by reference.
     */
    do_action_ref_array('groups_update_group_forum_post', array($post, &$topic));
    return $post_id;
}
	function bp_get_the_topic_post_edit_text() {
		global $bp;

		$post = bp_forums_get_post( $bp->action_variables[4] );
		return apply_filters( 'bp_get_the_topic_post_edit_text', esc_attr( $post->post_text ) );
	}
	/**
	 * Return the text to edit when editing a post.
	 *
	 * @return string Editable text.
	 */
	function bp_get_the_topic_post_edit_text() {
		$post = bp_forums_get_post( bp_action_variable( 4 ) );

		/**
		 * Filters the text to edit when editing a post.
		 *
		 * @since BuddyPress (1.2.4)
		 *
		 * @param string $value The text to edit when editing a post.
		 */
		return apply_filters( 'bp_get_the_topic_post_edit_text', esc_attr( $post->post_text ) );
	}
        function widget($args, $instance)
        {
            if (RWLogger::IsOn()) {
                $params = func_get_args();
                RWLogger::LogEnterence("RatingWidgetPlugin_TopRatedWidget.widget", $params, true);
            }
            if (!defined("WP_RW__SITE_PUBLIC_KEY") || false === WP_RW__SITE_PUBLIC_KEY) {
                return;
            }
            if (RatingWidgetPlugin::$WP_RW__HIDE_RATINGS) {
                return;
            }
            extract($args, EXTR_SKIP);
            $bpInstalled = ratingwidget()->IsBuddyPressInstalled();
            $bbInstalled = ratingwidget()->IsBBPressInstalled();
            $types = $this->GetTypesInfo();
            $show_any = false;
            foreach ($types as $type => $data) {
                if (false !== $instance["show_{$type}"]) {
                    $show_any = true;
                    break;
                }
            }
            if (RWLogger::IsOn()) {
                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget', 'show_any = ' . ($show_any ? 'TRUE' : 'FALSE'));
            }
            if (false === $show_any) {
                // Nothing to show.
                return;
            }
            $details = array("uid" => WP_RW__SITE_PUBLIC_KEY);
            $queries = array();
            foreach ($types as $type => $type_data) {
                if (isset($instance["show_{$type}"]) && $instance["show_{$type}"] && $instance["{$type}_count"] > 0) {
                    $options = ratingwidget()->GetOption($type_data["options"]);
                    $queries[$type] = array("rclasses" => $type_data["classes"], "votes" => max(1, (int) $instance["{$type}_min_votes"]), "orderby" => $instance["{$type}_orderby"], "order" => $instance["{$type}_order"], "limit" => (int) $instance["{$type}_count"], "types" => isset($options->type) ? $options->type : "star");
                    $since_created = isset($instance["{$type}_since_created"]) ? (int) $instance["{$type}_since_created"] : WP_RW__TIME_ALL_TIME;
                    // since_created should be at least 24 hours (86400 seconds), skip otherwise.
                    if ($since_created >= WP_RW__TIME_24_HOURS_IN_SEC) {
                        $time = current_time('timestamp', true) - $since_created;
                        // c: ISO 8601 full date/time, e.g.: 2004-02-12T15:19:21+00:00
                        $queries[$type]['since_created'] = date('c', $time);
                    }
                }
            }
            $details["queries"] = urlencode(json_encode($queries));
            $rw_ret_obj = ratingwidget()->RemoteCall("action/query/ratings.php", $details, WP_RW__CACHE_TIMEOUT_TOP_RATED);
            if (false === $rw_ret_obj) {
                return;
            }
            $rw_ret_obj = json_decode($rw_ret_obj);
            if (null === $rw_ret_obj || true !== $rw_ret_obj->success) {
                return;
            }
            $title = empty($instance['title']) ? __('Top Rated', WP_RW__ID) : apply_filters('widget_title', $instance['title']);
            $titleMaxLength = isset($instance['title_max_length']) && is_numeric($instance['title_max_length']) ? (int) $instance['title_max_length'] : 30;
            $empty = true;
            $toprated_data = new stdClass();
            $toprated_data->id = rand(1, 100);
            $toprated_data->title = array('label' => $title, 'show' => true, 'before' => $this->EncodeHtml($before_title), 'after' => $this->EncodeHtml($after_title));
            $toprated_data->options = array('align' => 'vertical', 'direction' => 'ltr', 'html' => array('before' => $this->EncodeHtml($before_widget), 'after' => $this->EncodeHtml($after_widget)));
            $toprated_data->site = array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST'], 'type' => 'WordPress');
            $toprated_data->itemGroups = array();
            if (count($rw_ret_obj->data) > 0) {
                foreach ($rw_ret_obj->data as $type => $ratings) {
                    if (is_array($ratings) && count($ratings) > 0) {
                        $item_group = new stdClass();
                        $item_group->type = $type;
                        $item_group->title = $instance["{$type}_title"];
                        $item_group->showTitle = 1 === $instance["show_{$type}_title"] && '' !== trim($item_group->title);
                        if (is_numeric($instance["{$type}_style"])) {
                            switch ($instance["{$type}_style"]) {
                                case 0:
                                    $instance["{$type}_style"] = 'legacy';
                                    break;
                                case 1:
                                default:
                                    $instance["{$type}_style"] = 'thumbs';
                                    break;
                            }
                        }
                        $item_group->style = $instance["{$type}_style"];
                        $item_group->options = array('title' => array('maxLen' => $titleMaxLength));
                        $item_group->items = array();
                        $has_thumb = strtolower($instance["{$type}_style"]) !== 'legacy';
                        $thumb_width = 160;
                        $thumb_height = 100;
                        if ($has_thumb) {
                            switch ($instance["{$type}_style"]) {
                                case '2':
                                case 'compact_thumbs':
                                    $thumb_width = 50;
                                    $thumb_height = 40;
                                    break;
                                case '1':
                                case 'thumbs':
                                default:
                                    $thumb_width = 160;
                                    $thumb_height = 100;
                                    break;
                            }
                            $item_group->options['thumb'] = array('width' => $thumb_width, 'height' => $thumb_height);
                        }
                        $cell = 0;
                        foreach ($ratings as $rating) {
                            $urid = $rating->urid;
                            $rclass = $types[$type]["rclass"];
                            $rclasses[$rclass] = true;
                            $extension_type = false;
                            if (RWLogger::IsOn()) {
                                RWLogger::Log('HANDLED_ITEM', 'Urid = ' . $urid . '; Class = ' . $rclass . ';');
                            }
                            if ('posts' === $type || 'pages' === $type) {
                                $post = null;
                                $id = RatingWidgetPlugin::Urid2PostId($urid);
                                $status = @get_post_status($id);
                                if (false === $status) {
                                    if (RWLogger::IsOn()) {
                                        RWLogger::Log('POST_NOT_EXIST', $id);
                                    }
                                    // Post not exist.
                                    continue;
                                } else {
                                    if ('publish' !== $status && 'private' !== $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('POST_NOT_VISIBLE', 'status = ' . $status);
                                        }
                                        // Post not yet published.
                                        continue;
                                    } else {
                                        if ('private' === $status && !is_user_logged_in()) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget::widget', 'POST_PRIVATE && USER_LOGGED_OUT');
                                            }
                                            // Private post but user is not logged in.
                                            continue;
                                        }
                                    }
                                }
                                $post = @get_post($id);
                                $title = trim(strip_tags($post->post_title));
                                $permalink = get_permalink($post->ID);
                            } else {
                                if ('comments' === $type) {
                                    $comment = null;
                                    $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                    $status = @wp_get_comment_status($id);
                                    if (false === $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('COMMENT_NOT_EXIST', $id);
                                        }
                                        // Comment not exist.
                                        continue;
                                    } else {
                                        if ('approved' !== $status) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('COMMENT_NOT_VISIBLE', 'status = ' . $status);
                                            }
                                            // Comment not approved.
                                            continue;
                                        }
                                    }
                                    $comment = @get_comment($id);
                                    $title = trim(strip_tags($comment->comment_content));
                                    $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                } else {
                                    if ('activity_updates' === $type || 'activity_comments' === $type) {
                                        $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                        $activity = new bp_activity_activity($id);
                                        if (!is_object($activity)) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('BP_ACTIVITY_NOT_EXIST', $id);
                                            }
                                            // Activity not exist.
                                            continue;
                                        } else {
                                            if (!empty($activity->is_spam)) {
                                                if (RWLogger::IsOn()) {
                                                    RWLogger::Log('BP_ACTIVITY_NOT_VISIBLE (SPAM or TRASH)');
                                                }
                                                // Activity marked as SPAM or TRASH.
                                                continue;
                                            } else {
                                                if (!empty($activity->hide_sitewide)) {
                                                    if (RWLogger::IsOn()) {
                                                        RWLogger::Log('BP_ACTIVITY_HIDE_SITEWIDE');
                                                    }
                                                    // Activity marked as hidden in site.
                                                    continue;
                                                }
                                            }
                                        }
                                        $title = trim(strip_tags($activity->content));
                                        $permalink = bp_activity_get_permalink($id);
                                    } else {
                                        if ('users' === $type) {
                                            $id = RatingWidgetPlugin::Urid2UserId($urid);
                                            if ($bpInstalled) {
                                                $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                                $permalink = bp_core_get_user_domain($id);
                                            } else {
                                                if ($bbInstalled) {
                                                    $title = trim(strip_tags(bbp_get_user_display_name($id)));
                                                    $permalink = bbp_get_user_profile_url($id);
                                                } else {
                                                    continue;
                                                }
                                            }
                                        } else {
                                            if ('forum_posts' === $type || 'forum_replies' === $type) {
                                                $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                                if (function_exists('bp_forums_get_post')) {
                                                    $forum_post = @bp_forums_get_post($id);
                                                    if (!is_object($forum_post)) {
                                                        continue;
                                                    }
                                                    $title = trim(strip_tags($forum_post->post_text));
                                                    $page = bb_get_page_number($forum_post->post_position);
                                                    $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                                } else {
                                                    if (function_exists('bbp_get_reply_id')) {
                                                        $forum_item = bbp_get_topic();
                                                        if (is_object($forum_item)) {
                                                            $is_topic = true;
                                                        } else {
                                                            $is_topic = false;
                                                            $forum_item = bbp_get_reply($id);
                                                            if (!is_object($forum_item)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_FORUM_ITEM_NOT_EXIST', $id);
                                                                }
                                                                // Invalid id (no topic nor reply).
                                                                continue;
                                                            }
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_IS_TOPIC_REPLY', $is_topic ? 'FALSE' : 'TRUE');
                                                            }
                                                        }
                                                        // Visible statueses: Public or Closed.
                                                        $visible_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id());
                                                        if (!in_array($forum_item->post_status, $visible_statuses)) {
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_FORUM_ITEM_HIDDEN', $forum_item->post_status);
                                                            }
                                                            // Item is not public nor closed.
                                                            continue;
                                                        }
                                                        $is_reply = !$is_topic;
                                                        if ($is_reply) {
                                                            // Get parent topic.
                                                            $forum_topic = bbp_get_topic($forum_post->post_parent);
                                                            if (!in_array($forum_topic->post_status, $visible_statuses)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_PARENT_FORUM_TOPIC_IS_HIDDEN', 'TRUE');
                                                                }
                                                                // Parent topic is not public nor closed.
                                                                continue;
                                                            }
                                                        }
                                                        $title = trim(strip_tags($forum_post->post_title));
                                                        $permalink = get_permalink($forum_post->ID);
                                                    } else {
                                                        continue;
                                                    }
                                                }
                                                $types[$type]['handler']->GetElementInfoByRating();
                                            } else {
                                                $found_handler = false;
                                                $extensions = ratingwidget()->GetExtensions();
                                                foreach ($extensions as $ext) {
                                                    $result = $ext->GetElementInfoByRating($type, $rating);
                                                    if (false !== $result) {
                                                        $found_handler = true;
                                                        break;
                                                    }
                                                }
                                                if ($found_handler) {
                                                    $id = $result['id'];
                                                    $title = $result['title'];
                                                    $permalink = $result['permalink'];
                                                    $img = rw_get_thumb_url($result['img'], $thumb_width, $thumb_height, $result['permalink']);
                                                    $extension_type = true;
                                                } else {
                                                    continue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            $queued = ratingwidget()->QueueRatingData($urid, "", "", $rclass);
                            // Override rating class in case the same rating has already been queued with a different rclass.
                            $rclass = $queued['rclass'];
                            $short = mb_strlen($title) > $titleMaxLength ? trim(mb_substr($title, 0, $titleMaxLength)) . "..." : $title;
                            $item = array('site' => array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST']), 'page' => array('externalID' => $id, 'url' => $permalink, 'title' => $short), 'rating' => array('localID' => $urid, 'options' => array('rclass' => $rclass)));
                            // Add thumb url.
                            if ($extension_type && is_string($img)) {
                                $item['page']['img'] = $img;
                            } else {
                                if ($has_thumb && in_array($type, array('posts', 'pages'))) {
                                    $item['page']['img'] = rw_get_post_thumb_url($post, $thumb_width, $thumb_height);
                                }
                            }
                            $item_group->items[] = $item;
                            $cell++;
                            $empty = false;
                        }
                        $toprated_data->itemGroups[] = $item_group;
                    }
                }
            }
            if (true === $empty) {
                //            echo '<p style="margin: 0;">There are no rated items for this period.</p>';
                //        echo $before_widget;
                //        echo $after_widget;
            } else {
                // Set a flag that the widget is loaded.
                ratingwidget()->TopRatedWidgetLoaded();
                ?>
					<b class="rw-ui-recommendations" data-id="<?php 
                echo $toprated_data->id;
                ?>
"></b>
					<script type="text/javascript">
						var _rwq = _rwq || [];
						_rwq.push(['_setRecommendations', <?php 
                echo json_encode($toprated_data);
                ?>
]);
					</script>
				<?php 
            }
        }
Beispiel #7
0
function bp_forums_insert_post($args = '')
{
    global $bp;
    do_action('bbpress_init');
    $defaults = array('post_id' => false, 'topic_id' => false, 'post_text' => '', 'post_time' => bp_core_current_time(), 'poster_id' => bp_loggedin_user_id(), 'poster_ip' => $_SERVER['REMOTE_ADDR'], 'post_status' => 0, 'post_position' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if (!($post = bp_forums_get_post($post_id))) {
        $post_id = false;
    }
    if (!isset($topic_id)) {
        $topic_id = $post->topic_id;
    }
    if (empty($post_text)) {
        $post_text = $post->post_text;
    }
    if (!isset($post_time)) {
        $post_time = $post->post_time;
    }
    if (!isset($post_position)) {
        $post_position = $post->post_position;
    }
    if (empty($poster_id)) {
        return false;
    }
    if (bp_is_user_inactive(bp_loggedin_user_id())) {
        return false;
    }
    $post_id = bb_insert_post(array('post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes(trim($post_text)), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position));
    if (!empty($post_id)) {
        do_action('bp_forums_new_post', $post_id);
    }
    return $post_id;
}
        function widget($args, $instance)
        {
            if (RWLogger::IsOn()) {
                $params = func_get_args();
                RWLogger::LogEnterence("RWTopRated.widget", $params, true);
            }
            if (!defined("WP_RW__USER_KEY") || false === WP_RW__USER_KEY) {
                return;
            }
            if (RatingWidgetPlugin::$WP_RW__HIDE_RATINGS) {
                return;
            }
            extract($args, EXTR_SKIP);
            $types = array("posts" => array("rclass" => "blog-post", "classes" => "front-post,blog-post,new-blog-post,user-post", "options" => WP_RW__BLOG_POSTS_OPTIONS), "pages" => array("rclass" => "page", "classes" => "page,user-page", "options" => WP_RW__PAGES_OPTIONS), "comments" => array("rclass" => "comment", "classes" => "comment,new-blog-comment,user-comment", "options" => WP_RW__COMMENTS_OPTIONS), "activity_updates" => array("rclass" => "activity-update", "classes" => "activity-update,user-activity-update", "options" => WP_RW__ACTIVITY_UPDATES_OPTIONS), "activity_comments" => array("rclass" => "activity-comment", "classes" => "activity-comment,user-activity-comment", "options" => WP_RW__ACTIVITY_COMMENTS_OPTIONS), "forum_posts" => array("rclass" => "forum-post", "classes" => "forum-post,new-forum-post,user-forum-post", "options" => WP_RW__FORUM_POSTS_OPTIONS), "users" => array("rclass" => "user", "classes" => "user", "options" => WP_RW__FORUM_POSTS_OPTIONS));
            $show_any = false;
            foreach ($types as $type => $data) {
                if (false !== $instance["show_{$type}"]) {
                    $show_any = true;
                    break;
                }
            }
            if (false === $show_any) {
                // Nothing to show.
                return;
            }
            $details = array("uid" => WP_RW__USER_KEY);
            $queries = array();
            foreach ($types as $type => $type_data) {
                if ($instance["show_{$type}"] && $instance["{$type}_count"] > 0) {
                    $options = json_decode(RatingWidgetPlugin::_getOption($type_data["options"]));
                    $queries[$type] = array("rclasses" => $type_data["classes"], "votes" => max(1, (int) $instance["{$type}_min_votes"]), "orderby" => $instance["{$type}_orderby"], "order" => $instance["{$type}_order"], "limit" => (int) $instance["{$type}_count"], "types" => isset($options->type) ? $options->type : "star");
                }
            }
            $details["queries"] = urlencode(json_encode($queries));
            $rw_ret_obj = RatingWidgetPlugin::RemoteCall("action/query/ratings.php", $details);
            if (false === $rw_ret_obj) {
                return;
            }
            $rw_ret_obj = json_decode($rw_ret_obj);
            if (null === $rw_ret_obj || true !== $rw_ret_obj->success) {
                return;
            }
            echo $before_widget;
            $title = empty($instance['title']) ? __('Top Rated', WP_RW__ID) : apply_filters('widget_title', $instance['title']);
            echo $before_title . $title . $after_title;
            $empty = true;
            if (count($rw_ret_obj->data) > 0) {
                foreach ($rw_ret_obj->data as $type => $ratings) {
                    if (is_array($ratings) && count($ratings) > 0) {
                        echo '<div id="rw_top_rated_' . $type . '">';
                        if ($instance["show_{$type}_title"]) {
                            /* (1.3.3) - Conditional title display */
                            $instance["{$type}_title"] = empty($instance["{$type}_title"]) ? ucwords($type) : $instance["{$type}_title"];
                            echo '<p style="margin: 0;">' . $instance["{$type}_title"] . '</p>';
                        }
                        echo '<ul class="rw-top-rated-list">';
                        foreach ($ratings as $rating) {
                            $urid = $rating->urid;
                            $rclass = $types[$type]["rclass"];
                            RatingWidgetPlugin::QueueRatingData($urid, "", "", $rclass);
                            switch ($type) {
                                case "posts":
                                case "pages":
                                    $id = RatingWidgetPlugin::Urid2PostId($urid);
                                    $post = get_post($id);
                                    $title = trim(strip_tags($post->post_title));
                                    $permalink = get_permalink($post->ID);
                                    break;
                                case "comments":
                                    $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                    $comment = get_comment($id);
                                    $title = trim(strip_tags($comment->comment_content));
                                    $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                    break;
                                case "activity_updates":
                                case "activity_comments":
                                    $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                    $activity = new bp_activity_activity($id);
                                    $title = trim(strip_tags($activity->content));
                                    $permalink = bp_activity_get_permalink($id);
                                    break;
                                case "users":
                                    $id = RatingWidgetPlugin::Urid2UserId($urid);
                                    $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                    $permalink = bp_core_get_user_domain($id);
                                    break;
                                case "forum_posts":
                                    $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                    $forum_post = bp_forums_get_post($id);
                                    $title = trim(strip_tags($forum_post->post_text));
                                    $page = bb_get_page_number($forum_post->post_position);
                                    $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                    break;
                            }
                            $short = mb_strlen($title) > 30 ? trim(mb_substr($title, 0, 30)) . "..." : $title;
                            echo '<li>' . '<a href="' . $permalink . '" title="' . $title . '">' . $short . '</a>' . '<br />' . '<div class="rw-ui-container rw-class-' . $rclass . ' rw-urid-' . $urid . '"></div>' . '</li>';
                        }
                        echo "</ul>";
                        echo "</div>";
                        $empty = false;
                    }
                }
            }
            if (true === $empty) {
                echo '<p style="margin: 0;">There are no rated items for this period.</p>';
            } else {
                // Set a flag that the widget is loaded.
                RatingWidgetPlugin::TopRatedWidgetLoaded();
                ?>
<script type="text/javascript">
    // Hook render widget.
    if (typeof(RW_HOOK_READY) === "undefined"){ RW_HOOK_READY = []; }
    RW_HOOK_READY.push(function(){
        RW._foreach(RW._getByClassName("rw-top-rated-list", "ul"), function(list){
            RW._foreach(RW._getByClassName("rw-ui-container", "div", list), function(rating){
                // Deactivate rating.
                RW._Class.remove(rating, "rw-active");
                var i = (RW._getByClassName("rw-report-link", "a", rating))[0];
                if (RW._is(i)){ i.parentNode.removeChild(i); }
                
                // Update size to small.
                if (!RW._Class.has(rating, "rw-size-small"))
                {
                    RW._Class.add(rating, "rw-size-small");
                    RW._Class.remove(rating, "rw-size-medium");
                    RW._Class.remove(rating, "rw-size-large");
                }
                
                if (RW._Class.has(rating, "rw-ui-star"))
                {
                    RW._foreach(RW._getByTagName("li", rating), function(star){
                        // Clear star event handlers.
                        star.onmouseover =
                        star.onmouseout =
                        star.onclick = "";
                    });
                }
                else
                {
                    RW._foreach(RW._getByTagName("i", rating), function(thumb){
                        // Clear star event handlers.
                        thumb.onmouseover =
                        thumb.onmouseout =
                        thumb.onclick = "";
                    });

                    var like_label = RW._getByClassName("rw-ui-like-label", "span", rating);
                    if (like_label.length == 1)
                    {
                        like_label = like_label[0];
                        like_label.style.fontSize = like_label.style.lineHeight = "";
                    }
                    
                    var dislike_label = RW._getByClassName("rw-ui-dislike-label", "span", rating);
                    if (dislike_label.length == 1)
                    {
                        dislike_label = dislike_label[0];
                        dislike_label.style.fontSize = dislike_label.style.lineHeight = "";
                    }
                }
                
                var label = (RW._getByClassName("rw-ui-info", "span", rating))[0];
                label.style.fontSize = label.style.lineHeight = "";
            });
        });
    });
</script>
<?php 
            }
            echo $after_widget;
        }
/**
 * Update an existing group forum post.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int $post_id The post ID of the existing forum post.
 * @param string $post_text The text for the forum post.
 * @param int $topic_id The topic ID of the existing forum topic.
 * @param mixed $page The page number where the new forum post should reside.
 *	  Optional.
 * @return mixed The forum post ID on success. Boolean false on failure.
 */
function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false)
{
    $bp = buddypress();
    $post_text = apply_filters('group_forum_post_text_before_save', $post_text);
    $topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id);
    $post = bp_forums_get_post($post_id);
    $post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id));
    if (empty($post_id)) {
        return false;
    }
    $topic = bp_forums_get_topic_details($topic_id);
    $activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_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($post_text);
    $primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/';
    if (!empty($page)) {
        $primary_link .= "?topic_page=" . $page;
    }
    // Get the corresponding activity item
    if (bp_is_active('activity')) {
        $id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id));
    }
    // Update the entry in activity streams
    groups_record_activity(array('id' => $id, 'action' => apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic)), 'content' => apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic)), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id), 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time));
    do_action_ref_array('groups_update_group_forum_post', array($post, &$topic));
    return $post_id;
}
 function forum_post_delete($id, $id2)
 {
     if (!($post = bp_forums_get_post($id2))) {
         return true;
     }
     // deleting a post don't remove it from db, it just set its status to 1
     if (1 == (int) $post->post_status) {
         return true;
     }
     if (!groups_delete_group_forum_post($id2, $post->topic_id)) {
         return false;
     }
     //if it was the first post (topic), then the activity doesn't get delete by bp because is new_forum_topic, instead of new_forum_post
     //so we check if it is the first post and then delete the activity
     if (function_exists('bp_activity_delete')) {
         $first_post = bp_forums_get_topic_posts(array('topic_id' => $post->topic_id, 'post_status' => 'all', 'page' => 1, 'per_page' => 1));
         if ($first_post[0]->post_id == $post->post_id) {
             bp_activity_delete(array('item_id' => $id, 'secondary_item_id' => $post->topic_id, 'component' => $GLOBALS['bp']->groups->id, 'type' => 'new_forum_topic'));
         }
     }
     return true;
 }
Beispiel #11
0
function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page = false ) {
	global $bp;

	$post_text = apply_filters( 'group_forum_post_text_before_save', $post_text );
	$topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id );

	$post = bp_forums_get_post( $post_id );

	if ( $post_id = bp_forums_insert_post( array( 'post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id ) ) ) {
		$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( $post->poster_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( $post_text );
		$primary_link = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';

		if ( $page )
			$primary_link .= "?topic_page=" . $page;

		/* Fetch an existing entry and update if one exists. */
		if ( function_exists( 'bp_activity_get_activity_id' ) )
			$id = bp_activity_get_activity_id( array( 'user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id ) );

		/* Update the entry in activity streams */
		groups_record_activity( array(
			'id' => $id,
			'action' => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_text, &$topic, &$forum_post ),
			'content' => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_text, &$topic, &$forum_post ),
			'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ),
			'type' => 'new_forum_post',
			'item_id' => (int)$bp->groups->current_group->id,
			'user_id' => (int)$post->poster_id,
			'secondary_item_id' => $post_id,
			'recorded_time' => $post->post_time
		) );

		do_action( 'groups_update_group_forum_post', &$post, &$topic );

		return $post_id;
	}

	return false;
}
function bp_get_the_topic_latest_post_excerpt()
{
    global $forum_template;
    $post = bp_forums_get_post($forum_template->topic->topic_last_post_id);
    return apply_filters('bp_get_the_topic_latest_post_excerpt', $post['post_text']);
}
Beispiel #13
0
function groups_format_activity($item_id, $user_id, $action, $secondary_item_id = false, $for_secondary_user = false)
{
    global $bp;
    switch ($action) {
        case 'joined_group':
            $group = new BP_Groups_Group($item_id, false, false);
            if (!$group) {
                return false;
            }
            $user_link = bp_core_get_userlink($user_id);
            $group_link = bp_get_group_permalink($group);
            return array('primary_link' => $group_link, 'content' => apply_filters('bp_groups_joined_group_activity', sprintf(__('%s joined the group %s', 'buddypress'), $user_link, '<a href="' . $group_link . '">' . $group->name . '</a>') . ' <span class="time-since">%s</span>', $user_link, $group_link, $group->name));
            break;
        case 'created_group':
            $group = new BP_Groups_Group($item_id, false, false);
            if (!$group) {
                return false;
            }
            $user_link = bp_core_get_userlink($user_id);
            $group_link = bp_get_group_permalink($group);
            return array('primary_link' => $group_link, 'content' => apply_filters('bp_groups_created_group_activity', sprintf(__('%s created the group %s', 'buddypress'), $user_link, '<a href="' . $group_link . '">' . $group->name . '</a>') . ' <span class="time-since">%s</span>', $user_link, $group_link, $group->name));
            break;
        case 'new_wire_post':
            $wire_post = new BP_Wire_Post($bp->groups->table_name_wire, $item_id);
            $group = new BP_Groups_Group($wire_post->item_id, false, false);
            if (!$group || !$wire_post || !$wire_post->content) {
                return false;
            }
            $user_link = bp_core_get_userlink($user_id);
            $group_link = bp_get_group_permalink($group);
            $post_excerpt = bp_create_excerpt($wire_post->content);
            $content = sprintf(__('%s wrote on the wire of the group %s', 'buddypress'), $user_link, '<a href="' . $group_link . '">' . $group->name . '</a>') . ' <span class="time-since">%s</span>';
            $content .= '<blockquote>' . $post_excerpt . '</blockquote>';
            $content = apply_filters('bp_groups_new_wire_post_activity', $content, $user_link, $group_link, $group->name, $post_excerpt);
            return array('primary_link' => $group_link, 'content' => $content);
            break;
        case 'new_forum_post':
            if (function_exists('bp_forums_setup')) {
                $group = new BP_Groups_Group($item_id, false, false);
                $forum_post = bp_forums_get_post($secondary_item_id);
                $forum_topic = bp_forums_get_topic_details($forum_post['topic_id']);
                if (!$group || !$forum_post || !$forum_topic) {
                    return false;
                }
                $user_link = bp_core_get_userlink($user_id);
                $group_link = bp_get_group_permalink($group);
                $post_content = apply_filters('bp_the_topic_post_content', bp_create_excerpt(stripslashes($forum_post['post_text']), 55, false));
                $content = sprintf(__('%s posted on the forum topic %s in the group %s:', 'buddypress'), $user_link, '<a href="' . $group_link . '/forum/topic/' . $forum_topic['topic_id'] . '">' . $forum_topic['topic_title'] . '</a>', '<a href="' . $group_link . '">' . $group->name . '</a>') . ' <span class="time-since">%s</span>';
                $content .= '<blockquote>' . $post_content . '</blockquote>';
                $content = apply_filters('bp_groups_new_forum_post_activity', $content, $user_link, $group_link, $forum_topic['topic_id'], $forum_topic['topic_title'], $group_link, $group->name, $post_content);
                return array('primary_link' => $group_link, 'content' => $content);
            }
            break;
        case 'new_forum_topic':
            if (function_exists('bp_forums_setup')) {
                $group = new BP_Groups_Group($item_id, false, false);
                $forum_topic = bp_forums_get_topic_details($secondary_item_id);
                $forum_post = bp_forums_get_post($forum_topic['topic_last_post_id']);
                if (!$group || !$forum_post || !$forum_topic) {
                    return false;
                }
                $user_link = bp_core_get_userlink($user_id);
                $group_link = bp_get_group_permalink($group);
                $post_content = apply_filters('bp_the_topic_post_content', bp_create_excerpt(stripslashes($forum_post['post_text']), 55, false));
                $content = sprintf(__('%s created the forum topic %s in the group %s:', 'buddypress'), $user_link, '<a href="' . $group_link . '/forum/topic/' . $forum_topic['topic_id'] . '">' . $forum_topic['topic_title'] . '</a>', '<a href="' . $group_link . '">' . $group->name . '</a>') . ' <span class="time-since">%s</span>';
                $content .= '<blockquote>' . $post_content . '</blockquote>';
                $content = apply_filters('bp_groups_new_forum_topic_activity', $content, $user_link, $group_link, $forum_topic['topic_id'], $forum_topic['topic_title'], $group_link, $group->name, $post_content);
                return array('primary_link' => $group_link, 'content' => $content);
            }
            break;
    }
    do_action('groups_format_activity', $action, $item_id, $user_id, $action, $secondary_item_id, $for_secondary_user);
    return false;
}
Beispiel #14
0
        public function GetTopRated()
        {
            $rw_ret_obj = $this->GetTopRatedData(array('posts', 'pages'));
            if (false === $rw_ret_obj || count($rw_ret_obj->data) == 0) {
                return '';
            }
            $html = '<div id="rw_top_rated_page">';
            foreach ($rw_ret_obj->data as $type => $ratings) {
                if (is_array($ratings) && count($ratings) > 0) {
                    $html .= '<div id="rw_top_rated_page_' . $type . '" class="rw-wp-ui-top-rated-list-container">';
                    if ($instance["show_{$type}_title"]) {
                        $instance["{$type}_title"] = empty($instance["{$type}_title"]) ? ucwords($type) : $instance["{$type}_title"];
                        $html .= '<p style="margin: 0;">' . $instance["{$type}_title"] . '</p>';
                    }
                    $html .= '<ul class="rw-wp-ui-top-rated-list">';
                    $count = 1;
                    foreach ($ratings as $rating) {
                        $urid = $rating->urid;
                        $rclass = $types[$type]["rclass"];
                        $thumbnail = '';
                        ratingwidget()->QueueRatingData($urid, "", "", $rclass);
                        switch ($type) {
                            case "posts":
                            case "pages":
                                $id = RatingWidgetPlugin::Urid2PostId($urid);
                                $post = get_post($id);
                                $title = trim(strip_tags($post->post_title));
                                $excerpt = $this->GetPostExcerpt($post, 15);
                                $permalink = get_permalink($post->ID);
                                $thumbnail = $this->GetPostFeaturedImage($post->ID);
                                break;
                            case "comments":
                                $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                $comment = get_comment($id);
                                $title = trim(strip_tags($comment->comment_content));
                                $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                break;
                            case "activity_updates":
                            case "activity_comments":
                                $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                $activity = new bp_activity_activity($id);
                                $title = trim(strip_tags($activity->content));
                                $permalink = bp_activity_get_permalink($id);
                                break;
                            case "users":
                                $id = RatingWidgetPlugin::Urid2UserId($urid);
                                $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                $permalink = bp_core_get_user_domain($id);
                                break;
                            case "forum_posts":
                                $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                $forum_post = bp_forums_get_post($id);
                                $title = trim(strip_tags($forum_post->post_text));
                                $page = bb_get_page_number($forum_post->post_position);
                                $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                break;
                        }
                        $short = mb_strlen($title) > 30 ? trim(mb_substr($title, 0, 30)) . "..." : $title;
                        $html .= '
<li class="rw-wp-ui-top-rated-list-item">
    <div>
        <b class="rw-wp-ui-top-rated-list-count">' . $count . '</b>
        <img class="rw-wp-ui-top-rated-list-item-thumbnail" src="' . $thumbnail . '" alt="" />
        <div class="rw-wp-ui-top-rated-list-item-data">
            <div>
                <a class="rw-wp-ui-top-rated-list-item-title" href="' . $permalink . '" title="' . $title . '">' . $short . '</a>
                <div class="rw-ui-container rw-class-' . $rclass . ' rw-urid-' . $urid . ' rw-size-small rw-prop-readOnly-true"></div>
            </div>
            <p class="rw-wp-ui-top-rated-list-item-excerpt">' . $excerpt . '</p>
        </div>
    </div>
</li>';
                        $count++;
                    }
                    $html .= "</ul>";
                    $html .= "</div>";
                }
            }
            // Set a flag that the widget is loaded.
            RatingWidgetPlugin::TopRatedWidgetLoaded();
            ob_start();
            ?>
<script type="text/javascript">
    // Hook render widget.
    if (typeof(RW_HOOK_READY) === "undefined"){ RW_HOOK_READY = []; }
    RW_HOOK_READY.push(function(){
        RW._foreach(RW._getByClassName("rw-wp-ui-top-rated-list", "ul"), function(list){
            RW._foreach(RW._getByClassName("rw-ui-container", "div", list), function(rating){
                // Deactivate rating.
                RW._Class.remove(rating, "rw-active");
                var i = (RW._getByClassName("rw-report-link", "a", rating))[0];
                if (RW._is(i)){ i.parentNode.removeChild(i); }
            });
        });
    });
</script>
<?php 
            $html .= ob_get_clean();
            $html .= '</div>';
            return $html;
        }
Beispiel #15
0
function bp_forums_insert_post( $args = '' ) {
	global $bp;

	do_action( 'bbpress_init' );

	$defaults = array(
		'post_id' => false,
		'topic_id' => false,
		'post_text' => '',
		'post_time' => date( 'Y-m-d H:i:s' ),
		'poster_id' => $bp->loggedin_user->id, // accepts ids or names
		'poster_ip' => $_SERVER['REMOTE_ADDR'],
		'post_status' => 0, // use bb_delete_post() instead
		'post_position' => false
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	if ( !$post = bp_forums_get_post( $post_id ) )
		$post_id = false;

	if ( !isset( $topic_id ) )
		$topic_id = $post->topic_id;

	if ( empty( $post_text ) )
		$post_text = $post->post_text;

	if ( !isset( $post_time ) )
		$post_time = $post->post_time;

	if ( !isset( $post_position ) )
		$post_position = $post->post_position;

	$post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );

	if ( $post_id )
		do_action( 'bp_forums_new_post', $post_id );

	return $post_id;
}
/**
 * This screen function handles actions related to group forums.
 */
function groups_screen_group_forum()
{
    if (!bp_is_active('forums') || !bp_forums_is_installed_correctly()) {
        return false;
    }
    if (bp_action_variable(0) && !bp_is_action_variable('topic', 0)) {
        bp_do_404();
        return;
    }
    $bp = buddypress();
    if (!$bp->groups->current_group->user_has_access) {
        bp_core_no_access();
        return;
    }
    if (!bp_is_single_item()) {
        return false;
    }
    // Fetch the details we need.
    $topic_slug = (string) bp_action_variable(1);
    $topic_id = bp_forums_get_topic_id_from_slug($topic_slug);
    $forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
    $user_is_banned = false;
    if (!bp_current_user_can('bp_moderate') && groups_is_user_banned(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
        $user_is_banned = true;
    }
    if (!empty($topic_slug) && !empty($topic_id)) {
        // Posting a reply.
        if (!$user_is_banned && !bp_action_variable(2) && isset($_POST['submit_reply'])) {
            // Check the nonce.
            check_admin_referer('bp_forums_new_reply');
            // Auto join this user if they are not yet a member of this group.
            if (bp_groups_auto_join() && !bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                groups_join_group($bp->groups->current_group->id, bp_loggedin_user_id());
            }
            $topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
            // Don't allow reply flooding.
            if (bp_forums_reply_exists($_POST['reply_text'], $topic_id, bp_loggedin_user_id())) {
                bp_core_add_message(__('It looks like you\'ve already said that!', 'buddypress'), 'error');
            } else {
                if (!($post_id = groups_new_group_forum_post($_POST['reply_text'], $topic_id, $topic_page))) {
                    bp_core_add_message(__('There was an error when replying to that topic', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('Your reply was posted successfully', 'buddypress'));
                }
            }
            $query_vars = isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '';
            $redirect = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/' . $query_vars;
            if (!empty($post_id)) {
                $redirect .= '#post-' . $post_id;
            }
            bp_core_redirect($redirect);
        } elseif (bp_is_action_variable('stick', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_stick_topic');
            if (!bp_forums_sticky_topic(array('topic_id' => $topic_id))) {
                bp_core_add_message(__('There was an error when making that topic a sticky', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was made sticky successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been stickied.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being stickied.
             */
            do_action('groups_stick_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (bp_is_action_variable('unstick', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_unstick_topic');
            if (!bp_forums_sticky_topic(array('topic_id' => $topic_id, 'mode' => 'unstick'))) {
                bp_core_add_message(__('There was an error when unsticking that topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was unstuck successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been un-stickied.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being un-stickied.
             */
            do_action('groups_unstick_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (bp_is_action_variable('close', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_close_topic');
            if (!bp_forums_openclose_topic(array('topic_id' => $topic_id))) {
                bp_core_add_message(__('There was an error when closing that topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was closed successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been closed.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being closed.
             */
            do_action('groups_close_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (bp_is_action_variable('open', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_open_topic');
            if (!bp_forums_openclose_topic(array('topic_id' => $topic_id, 'mode' => 'open'))) {
                bp_core_add_message(__('There was an error when opening that topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was opened successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been opened.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being opened.
             */
            do_action('groups_open_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (empty($user_is_banned) && bp_is_action_variable('delete', 2) && !bp_action_variable(3)) {
            // Fetch the topic.
            $topic = bp_forums_get_topic_details($topic_id);
            /* Check the logged in user can delete this topic */
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                bp_core_redirect(wp_get_referer());
            }
            // Check the nonce.
            check_admin_referer('bp_forums_delete_topic');
            /**
             * Fires before a group forum topic is deleted.
             *
             * @since 1.5.0
             *
             * @param int $topic_id ID of the topic being deleted.
             */
            do_action('groups_before_delete_forum_topic', $topic_id);
            if (!groups_delete_group_forum_topic($topic_id)) {
                bp_core_add_message(__('There was an error deleting the topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was deleted successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been deleted.
             *
             * @since 1.5.0
             *
             * @param int $topic_id ID of the topic being deleted.
             */
            do_action('groups_delete_forum_topic', $topic_id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/');
        } elseif (empty($user_is_banned) && bp_is_action_variable('edit', 2) && !bp_action_variable(3)) {
            // Fetch the topic.
            $topic = bp_forums_get_topic_details($topic_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                bp_core_redirect(wp_get_referer());
            }
            if (isset($_POST['save_changes'])) {
                // Check the nonce.
                check_admin_referer('bp_forums_edit_topic');
                $topic_tags = !empty($_POST['topic_tags']) ? $_POST['topic_tags'] : false;
                if (!groups_update_group_forum_topic($topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags)) {
                    bp_core_add_message(__('There was an error when editing that topic', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('The topic was edited successfully', 'buddypress'));
                }
                /**
                 * Fires after a group forum topic has been edited.
                 *
                 * @since 1.1.0
                 *
                 * @param int $topic_id ID of the topic being edited.
                 */
                do_action('groups_edit_forum_topic', $topic_id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/');
            }
            /**
             * Filters the template to load for a topic edit page.
             *
             * @since 1.1.0
             *
             * @param string $value Path to a topic edit template.
             */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
            // Delete a post.
        } elseif (empty($user_is_banned) && bp_is_action_variable('delete', 2) && ($post_id = bp_action_variable(4))) {
            // Fetch the post.
            $post = bp_forums_get_post($post_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                bp_core_redirect(wp_get_referer());
            }
            // Check the nonce.
            check_admin_referer('bp_forums_delete_post');
            /**
             * Fires before the deletion of a group forum post.
             *
             * @since 1.5.0
             *
             * @param int $post_id ID of the forum post being deleted.
             */
            do_action('groups_before_delete_forum_post', $post_id);
            if (!groups_delete_group_forum_post($post_id)) {
                bp_core_add_message(__('There was an error deleting that post', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The post was deleted successfully', 'buddypress'));
            }
            /**
             * Fires after the deletion of a group forum post.
             *
             * @since 1.1.0
             *
             * @param int $post_id ID of the forum post being deleted.
             */
            do_action('groups_delete_forum_post', $post_id);
            bp_core_redirect(wp_get_referer());
            // Editing a post.
        } elseif (empty($user_is_banned) && bp_is_action_variable('edit', 2) && ($post_id = bp_action_variable(4))) {
            // Fetch the post.
            $post = bp_forums_get_post($post_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                bp_core_redirect(wp_get_referer());
            }
            if (isset($_POST['save_changes'])) {
                // Check the nonce.
                check_admin_referer('bp_forums_edit_post');
                $topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
                if (!($post_id = groups_update_group_forum_post($post_id, $_POST['post_text'], $topic_id, $topic_page))) {
                    bp_core_add_message(__('There was an error when editing that post', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('The post was edited successfully', 'buddypress'));
                }
                if ($_SERVER['QUERY_STRING']) {
                    $query_vars = '?' . $_SERVER['QUERY_STRING'];
                }
                /**
                 * Fires after the editing of a group forum post.
                 *
                 * @since 1.1.0
                 *
                 * @param int $post_id ID of the forum post being edited.
                 */
                do_action('groups_edit_forum_post', $post_id);
                bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id);
            }
            /** This filter is documented in bp-groups/bp-groups-screens.php */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
            // Standard topic display.
        } else {
            if (!empty($user_is_banned)) {
                bp_core_add_message(__("You have been banned from this group.", 'buddypress'));
            }
            /**
             * Filters the template to load for a topic page.
             *
             * @since 1.1.0
             *
             * @param string $value Path to a topic template.
             */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic', 'groups/single/home'));
        }
        // Forum topic does not exist.
    } elseif (!empty($topic_slug) && empty($topic_id)) {
        bp_do_404();
        return;
    } else {
        // Posting a topic.
        if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
            // Check the nonce.
            check_admin_referer('bp_forums_new_topic');
            if ($user_is_banned) {
                $error_message = __("You have been banned from this group.", 'buddypress');
            } elseif (bp_groups_auto_join() && !bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                // Auto join this user if they are not yet a member of this group.
                groups_join_group($bp->groups->current_group->id, bp_loggedin_user_id());
            }
            if (empty($_POST['topic_title'])) {
                $error_message = __('Please provide a title for your forum topic.', 'buddypress');
            } elseif (empty($_POST['topic_text'])) {
                $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
            }
            if (empty($forum_id)) {
                $error_message = __('This group does not have a forum setup yet.', 'buddypress');
            }
            if (isset($error_message)) {
                bp_core_add_message($error_message, 'error');
                $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
            } else {
                if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) {
                    bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error');
                    $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                } else {
                    bp_core_add_message(__('The topic was created successfully', 'buddypress'));
                    $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';
                }
            }
            bp_core_redirect($redirect);
        }
        /**
         * Fires at the end of the group forum screen loading process.
         *
         * @since 1.0.0
         *
         * @param int $topic_id ID of the topic being displayed.
         * @param int $forum_id ID of the forum being displayed.
         */
        do_action('groups_screen_group_forum', $topic_id, $forum_id);
        /**
         * Filters the template to load for a group forum page.
         *
         * @since 1.0.0
         *
         * @param string $value Path to a group forum template.
         */
        bp_core_load_template(apply_filters('groups_template_group_forum', 'groups/single/home'));
    }
}
/**
 * Return the text to edit when editing a post.
 *
 * @return string Editable text.
 */
function bp_get_the_topic_post_edit_text()
{
    $post = bp_forums_get_post(bp_action_variable(4));
    return apply_filters('bp_get_the_topic_post_edit_text', esc_attr($post->post_text));
}
/**
 * This screen function handles actions related to group forums
 *
 * @package BuddyPress
 */
function groups_screen_group_forum()
{
    global $bp;
    if (!bp_is_active('forums') || !bp_forums_is_installed_correctly()) {
        return false;
    }
    if (bp_action_variable(0) && !bp_is_action_variable('topic', 0)) {
        bp_do_404();
        return;
    }
    if (!$bp->groups->current_group->user_has_access) {
        bp_core_no_access();
        return;
    }
    if (bp_is_single_item()) {
        // Fetch the details we need
        $topic_slug = (string) bp_action_variable(1);
        $topic_id = bp_forums_get_topic_id_from_slug($topic_slug);
        $forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
        $user_is_banned = false;
        if (!bp_current_user_can('bp_moderate') && groups_is_user_banned(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
            $user_is_banned = true;
        }
        if (!empty($topic_slug) && !empty($topic_id)) {
            // Posting a reply
            if (!$user_is_banned && !bp_action_variable(2) && isset($_POST['submit_reply'])) {
                // Check the nonce
                check_admin_referer('bp_forums_new_reply');
                // Auto join this user if they are not yet a member of this group
                if (bp_groups_auto_join() && !bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                    groups_join_group($bp->groups->current_group->id, bp_loggedin_user_id());
                }
                $topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
                if (!($post_id = groups_new_group_forum_post($_POST['reply_text'], $topic_id, $topic_page))) {
                    bp_core_add_message(__('There was an error when replying to that topic', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('Your reply was posted successfully', 'buddypress'));
                }
                if (isset($_SERVER['QUERY_STRING'])) {
                    $query_vars = '?' . $_SERVER['QUERY_STRING'];
                }
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id);
            } else {
                if (bp_is_action_variable('stick', 2) && (isset($bp->is_item_admin) || isset($bp->is_item_mod))) {
                    // Check the nonce
                    check_admin_referer('bp_forums_stick_topic');
                    if (!bp_forums_sticky_topic(array('topic_id' => $topic_id))) {
                        bp_core_add_message(__('There was an error when making that topic a sticky', 'buddypress'), 'error');
                    } else {
                        bp_core_add_message(__('The topic was made sticky successfully', 'buddypress'));
                    }
                    do_action('groups_stick_forum_topic', $topic_id);
                    bp_core_redirect(wp_get_referer());
                } else {
                    if (bp_is_action_variable('unstick', 2) && (isset($bp->is_item_admin) || isset($bp->is_item_mod))) {
                        // Check the nonce
                        check_admin_referer('bp_forums_unstick_topic');
                        if (!bp_forums_sticky_topic(array('topic_id' => $topic_id, 'mode' => 'unstick'))) {
                            bp_core_add_message(__('There was an error when unsticking that topic', 'buddypress'), 'error');
                        } else {
                            bp_core_add_message(__('The topic was unstuck successfully', 'buddypress'));
                        }
                        do_action('groups_unstick_forum_topic', $topic_id);
                        bp_core_redirect(wp_get_referer());
                    } else {
                        if (bp_is_action_variable('close', 2) && (isset($bp->is_item_admin) || isset($bp->is_item_mod))) {
                            // Check the nonce
                            check_admin_referer('bp_forums_close_topic');
                            if (!bp_forums_openclose_topic(array('topic_id' => $topic_id))) {
                                bp_core_add_message(__('There was an error when closing that topic', 'buddypress'), 'error');
                            } else {
                                bp_core_add_message(__('The topic was closed successfully', 'buddypress'));
                            }
                            do_action('groups_close_forum_topic', $topic_id);
                            bp_core_redirect(wp_get_referer());
                        } else {
                            if (bp_is_action_variable('open', 2) && (isset($bp->is_item_admin) || isset($bp->is_item_mod))) {
                                // Check the nonce
                                check_admin_referer('bp_forums_open_topic');
                                if (!bp_forums_openclose_topic(array('topic_id' => $topic_id, 'mode' => 'open'))) {
                                    bp_core_add_message(__('There was an error when opening that topic', 'buddypress'), 'error');
                                } else {
                                    bp_core_add_message(__('The topic was opened successfully', 'buddypress'));
                                }
                                do_action('groups_open_forum_topic', $topic_id);
                                bp_core_redirect(wp_get_referer());
                            } else {
                                if (empty($user_is_banned) && bp_is_action_variable('delete', 2) && !bp_action_variable(3)) {
                                    // Fetch the topic
                                    $topic = bp_forums_get_topic_details($topic_id);
                                    /* Check the logged in user can delete this topic */
                                    if (!$bp->is_item_admin && !$bp->is_item_mod && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                                        bp_core_redirect(wp_get_referer());
                                    }
                                    // Check the nonce
                                    check_admin_referer('bp_forums_delete_topic');
                                    do_action('groups_before_delete_forum_topic', $topic_id);
                                    if (!groups_delete_group_forum_topic($topic_id)) {
                                        bp_core_add_message(__('There was an error deleting the topic', 'buddypress'), 'error');
                                    } else {
                                        bp_core_add_message(__('The topic was deleted successfully', 'buddypress'));
                                    }
                                    do_action('groups_delete_forum_topic', $topic_id);
                                    bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/');
                                } else {
                                    if (empty($user_is_banned) && bp_is_action_variable('edit', 2) && !bp_action_variable(3)) {
                                        // Fetch the topic
                                        $topic = bp_forums_get_topic_details($topic_id);
                                        // Check the logged in user can edit this topic
                                        if (!$bp->is_item_admin && !$bp->is_item_mod && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                                            bp_core_redirect(wp_get_referer());
                                        }
                                        if (isset($_POST['save_changes'])) {
                                            // Check the nonce
                                            check_admin_referer('bp_forums_edit_topic');
                                            $topic_tags = !empty($_POST['topic_tags']) ? $_POST['topic_tags'] : false;
                                            if (!groups_update_group_forum_topic($topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags)) {
                                                bp_core_add_message(__('There was an error when editing that topic', 'buddypress'), 'error');
                                            } else {
                                                bp_core_add_message(__('The topic was edited successfully', 'buddypress'));
                                            }
                                            do_action('groups_edit_forum_topic', $topic_id);
                                            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/');
                                        }
                                        bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
                                    } else {
                                        if (empty($user_is_banned) && bp_is_action_variable('delete', 2) && ($post_id = bp_action_variable(4))) {
                                            // Fetch the post
                                            $post = bp_forums_get_post($post_id);
                                            // Check the logged in user can edit this topic
                                            if (!$bp->is_item_admin && !$bp->is_item_mod && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                                                bp_core_redirect(wp_get_referer());
                                            }
                                            // Check the nonce
                                            check_admin_referer('bp_forums_delete_post');
                                            do_action('groups_before_delete_forum_post', $post_id);
                                            if (!groups_delete_group_forum_post($post_id)) {
                                                bp_core_add_message(__('There was an error deleting that post', 'buddypress'), 'error');
                                            } else {
                                                bp_core_add_message(__('The post was deleted successfully', 'buddypress'));
                                            }
                                            do_action('groups_delete_forum_post', $post_id);
                                            bp_core_redirect(wp_get_referer());
                                        } else {
                                            if (empty($user_is_banned) && bp_is_action_variable('edit', 2) && ($post_id = bp_action_variable(4))) {
                                                // Fetch the post
                                                $post = bp_forums_get_post($post_id);
                                                // Check the logged in user can edit this topic
                                                if (!$bp->is_item_admin && !$bp->is_item_mod && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                                                    bp_core_redirect(wp_get_referer());
                                                }
                                                if (isset($_POST['save_changes'])) {
                                                    // Check the nonce
                                                    check_admin_referer('bp_forums_edit_post');
                                                    $topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
                                                    if (!($post_id = groups_update_group_forum_post($post_id, $_POST['post_text'], $topic_id, $topic_page))) {
                                                        bp_core_add_message(__('There was an error when editing that post', 'buddypress'), 'error');
                                                    } else {
                                                        bp_core_add_message(__('The post was edited successfully', 'buddypress'));
                                                    }
                                                    if ($_SERVER['QUERY_STRING']) {
                                                        $query_vars = '?' . $_SERVER['QUERY_STRING'];
                                                    }
                                                    do_action('groups_edit_forum_post', $post_id);
                                                    bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id);
                                                }
                                                bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
                                            } else {
                                                if (!empty($user_is_banned)) {
                                                    bp_core_add_message(__("You have been banned from this group.", 'buddypress'));
                                                }
                                                bp_core_load_template(apply_filters('groups_template_group_forum_topic', 'groups/single/home'));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Forum topic does not exist
        } elseif (!empty($topic_slug) && empty($topic_id)) {
            bp_do_404();
            return;
        } else {
            // Posting a topic
            if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
                // Check the nonce
                check_admin_referer('bp_forums_new_topic');
                if ($user_is_banned) {
                    $error_message = __("You have been banned from this group.", 'buddypress');
                } elseif (bp_groups_auto_join() && !bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                    // Auto join this user if they are not yet a member of this group
                    groups_join_group($bp->groups->current_group->id, bp_loggedin_user_id());
                }
                if (empty($_POST['topic_title'])) {
                    $error_message = __('Please provide a title for your forum topic.', 'buddypress');
                } else {
                    if (empty($_POST['topic_text'])) {
                        $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
                    }
                }
                if (empty($forum_id)) {
                    $error_message = __('This group does not have a forum setup yet.', 'buddypress');
                }
                if (isset($error_message)) {
                    bp_core_add_message($error_message, 'error');
                    $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                } else {
                    if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) {
                        bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error');
                        $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                    } else {
                        bp_core_add_message(__('The topic was created successfully', 'buddypress'));
                        $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';
                    }
                }
                bp_core_redirect($redirect);
            }
            do_action('groups_screen_group_forum', $topic_id, $forum_id);
            bp_core_load_template(apply_filters('groups_template_group_forum', 'groups/single/home'));
        }
    }
}