Ejemplo n.º 1
0
 /**
  * Constructor method.
  *
  * @param int $topic_id ID of the topic whose posts are being requested.
  * @param int $per_page Number of items to return per page.
  * @param int $max Max records to return.
  * @param string $order Direction to order results.
  */
 function __construct($topic_id, $per_page, $max, $order)
 {
     global $bp, $current_user, $forum_template;
     if (!isset($forum_template)) {
         $forum_template = new stdClass();
     }
     $this->pag_page = isset($_REQUEST['topic_page']) ? intval($_REQUEST['topic_page']) : 1;
     $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page;
     $this->order = $order;
     $this->topic_id = $topic_id;
     $forum_template->topic = (object) bp_forums_get_topic_details($this->topic_id);
     $this->forum_id = $forum_template->topic->forum_id;
     $this->posts = bp_forums_get_topic_posts(array('topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order));
     if (!$this->posts) {
         $this->post_count = 0;
         $this->total_post_count = 0;
     } else {
         if (!$max || $max >= (int) $forum_template->topic->topic_posts) {
             $this->total_post_count = (int) $forum_template->topic->topic_posts;
         } else {
             $this->total_post_count = (int) $max;
         }
         if ($max) {
             if ($max >= count($this->posts)) {
                 $this->post_count = count($this->posts);
             } else {
                 $this->post_count = (int) $max;
             }
         } else {
             $this->post_count = count($this->posts);
         }
     }
     // Load topic tags
     $this->topic_tags = bb_get_topic_tags($this->topic_id);
     $this->pag = new stdClass();
     if ((int) $this->total_post_count && (int) $this->pag_num) {
         $this->pag_links = paginate_links(array('base' => add_query_arg(array('topic_page' => '%#%', 'num' => (int) $this->pag_num)), 'format' => '', 'total' => ceil((int) $this->total_post_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Forum thread pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Forum thread pagination next text', 'buddypress'), 'mid_size' => 1));
         $this->pag->total_pages = ceil((int) $this->total_post_count / (int) $this->pag_num);
     } else {
         $this->pag->total_pages = 1;
     }
 }
Ejemplo n.º 2
0
/**
 * Update a topic's details.
 *
 * @param array $args {
 *     Array of arguments.
 *     @type int $topic_id ID of the topic being updated.
 *     @type string $topic_title Updated title of the topic.
 *     @type string $topic_title Updated text of the topic.
 *     @type array|string|bool $topic_tags Array or comma-separated list of
 *           topic tags. False to leave empty. Default: false.
 * }
 * @return object Details about the new topic, as returned by
 *         {@link bp_forums_get_topic_details()}.
 */
function bp_forums_update_topic($args = '')
{
    /** This action is documented in bp-forums/bp-forums-screens */
    do_action('bbpress_init');
    $r = wp_parse_args($args, array('topic_id' => false, 'topic_title' => '', 'topic_text' => '', 'topic_tags' => false));
    extract($r, EXTR_SKIP);
    // Check if the user is a spammer
    if (bp_is_user_inactive(bp_loggedin_user_id())) {
        return false;
    }
    // bb_insert_topic() will append tags, but not remove them. So we remove all existing tags.
    bb_remove_topic_tags($topic_id);
    if (!($topic_id = bb_insert_topic(array('topic_id' => $topic_id, 'topic_title' => stripslashes($topic_title), 'tags' => $topic_tags)))) {
        return false;
    }
    if (!($post = bb_get_first_post($topic_id))) {
        return false;
    }
    // Update the first post
    if (!($post = bp_forums_insert_post(array('post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position)))) {
        return false;
    }
    return bp_forums_get_topic_details($topic_id);
}
Ejemplo n.º 3
0
/**
 * 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'));
    }
}
Ejemplo n.º 4
0
	function BP_Forums_Template_Topic( $topic_id, $per_page, $max, $order ) {
		global $bp, $current_user, $forum_template;

		$this->pag_page        = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1;
		$this->pag_num         = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;

		$this->order           = $order;
		$this->topic_id        = $topic_id;
		$forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id );
		$this->forum_id        = $forum_template->topic->forum_id;

		$this->posts           = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order ) );

		if ( !$this->posts ) {
			$this->post_count       = 0;
			$this->total_post_count = 0;
		} else {
			if ( !$max || $max >= (int)$forum_template->topic->topic_posts ) {
				$this->total_post_count = (int)$forum_template->topic->topic_posts;
			} else {
				$this->total_post_count = (int)$max;
			}

			if ( $max ) {
				if ( $max >= count( $this->posts ) ) {
					$this->post_count = count( $this->posts );
				} else {
					$this->post_count = (int)$max;
				}
			} else {
				$this->post_count = count( $this->posts );
			}
		}

		if ( (int)$this->total_post_count && (int)$this->pag_num ) {
			$this->pag_links = paginate_links( array(
				'base'      => add_query_arg( array( 'topic_page' => '%#%', 'num' => (int)$this->pag_num ) ),
				'format'    => '',
				'total'     => ceil( (int)$this->total_post_count / (int)$this->pag_num ),
				'current'   => $this->pag_page,
				'prev_text' => '←',
				'next_text' => '→',
				'mid_size'  => 1
			) );

			$this->pag->total_pages = ceil( (int)$this->total_post_count / (int)$this->pag_num );
		} else {
			$this->pag->total_pages = 1;
		}
	}
Ejemplo n.º 5
0
/**
 * 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;
}
Ejemplo n.º 6
0
/**
 * 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'));
        }
    }
}
Ejemplo n.º 7
0
function bp_forums_update_topic($args = '')
{
    global $bp;
    do_action('bbpress_init');
    $defaults = array('topic_id' => false, 'topic_title' => '', 'topic_text' => '', 'topic_tags' => false);
    $r = nxt_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Check if the user is a spammer
    if (bp_core_is_user_spammer($bp->loggedin_user->id) || bp_core_is_user_deleted($bp->loggedin_user->id)) {
        return false;
    }
    // bb_insert_topic() will append tags, but not remove them. So we remove all existing tags.
    bb_remove_topic_tags($topic_id);
    if (!($topic_id = bb_insert_topic(array('topic_id' => $topic_id, 'topic_title' => stripslashes($topic_title), 'tags' => $topic_tags)))) {
        return false;
    }
    if (!($post = bb_get_first_post($topic_id))) {
        return false;
    }
    // Update the first post
    if (!($post = bp_forums_insert_post(array('post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position)))) {
        return false;
    }
    return bp_forums_get_topic_details($topic_id);
}
 function forum_post_edit($id, $id2)
 {
     if (!($post = bp_forums_get_post($id2))) {
         return false;
     }
     $topic = bp_forums_get_topic_details($post->topic_id);
     $url = bp_core_get_root_domain() . '/' . BP_GROUPS_SLUG . '/' . $topic->object_slug . '/forum/topic/' . $topic->topic_slug . '/edit/post/' . $post->post_id . '/';
     return wp_nonce_url($url, 'bp_forums_edit_post');
 }
Ejemplo n.º 9
0
/**
 * 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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
/**
 * Catches requests to our extra RSS feeds and sets up the parameters needed
 * to display the RSS feed.
 *
 * @since 1.0
 */
function bplf_catcher()
{
    global $bp, $wp_query, $this_bp_feed;
    // Individual member activity feeds
    if (bp_is_activity_component() && bp_displayed_user_id() && bp_action_variable(0) && bp_action_variable(0) == 'feed') {
        switch (bp_current_action()) {
            // Individual member comment feed
            // /members/username/activity/comments/feed
            case 'comments':
                if (!defined('BPLF_DISABLE_MEMBER_COMMENTS_FEED')) {
                    $this_bp_feed = 'member_comments';
                }
                break;
                // Individual member blog post feed
                // /members/username/activity/blogposts/feed
            // Individual member blog post feed
            // /members/username/activity/blogposts/feed
            case 'blogposts':
                if (!defined('BPLF_DISABLE_MEMBER_BLOG_POSTS_FEED')) {
                    $this_bp_feed = 'member_blog_posts';
                }
                break;
                // Individual member activity update feed
                // /members/username/activity/updates/feed
            // Individual member activity update feed
            // /members/username/activity/updates/feed
            case 'updates':
                if (!defined('BPLF_DISABLE_MEMBER_UPDATES_FEED')) {
                    $this_bp_feed = 'member_updates';
                }
                break;
                // Individual member friendship conection feed
                // /members/username/activity/friendships/feed
            // Individual member friendship conection feed
            // /members/username/activity/friendships/feed
            case 'friendships':
                if (!defined('BPLF_DISABLE_MEMBER_FRIENDSHIPS_FEED')) {
                    $this_bp_feed = 'friendships';
                }
                break;
                // Individual member new forum topic feed
                // /members/username/activity/forumtopics/feed
            // Individual member new forum topic feed
            // /members/username/activity/forumtopics/feed
            case 'forumtopics':
                if (!defined('BPLF_DISABLE_MEMBER_TOPICS_FEED')) {
                    $this_bp_feed = 'member_topics';
                }
                break;
                // Individual member forum reply feed
                // /members/username/activity/forumreplies/feed
            // Individual member forum reply feed
            // /members/username/activity/forumreplies/feed
            case 'forumreplies':
                if (!defined('BPLF_DISABLE_MEMBER_REPLIES_FEED')) {
                    $this_bp_feed = 'member_replies';
                }
                break;
                // Individual member forum activity feed
                // /members/username/activity/forums/feed
            // Individual member forum activity feed
            // /members/username/activity/forums/feed
            case 'forums':
                if (!defined('BPLF_DISABLE_MEMBER_FORUMS_FEED')) {
                    $this_bp_feed = 'member_forums';
                }
                break;
        }
    }
    // Group activity feeds
    if (bp_is_groups_component() && isset($bp->groups->current_group->id) && bp_action_variable(0) == 'feed') {
        switch (bp_current_action()) {
            // Group activity updates
            // /groups/groupname/updates/feed
            case 'updates':
                if (!defined('BPLF_DISABLE_GROUP_UPDATES_FEED')) {
                    $this_bp_feed = 'group_updates';
                }
                break;
                // New group forum topics
                // /groups/groupname/forumtopics/feed
            // New group forum topics
            // /groups/groupname/forumtopics/feed
            case 'forumtopics':
                if (!defined('BPLF_DISABLE_GROUP_TOPICS_FEED')) {
                    $this_bp_feed = 'group_topics';
                }
                break;
                // New group forum replies
                // /groups/groupname/forumreplies/feed
            // New group forum replies
            // /groups/groupname/forumreplies/feed
            case 'forumreplies':
                if (!defined('BPLF_DISABLE_GROUP_REPLIES_FEED')) {
                    $this_bp_feed = 'group_replies';
                }
                break;
                // Group forum activity
                // /groups/groupname/forums/feed
            // Group forum activity
            // /groups/groupname/forums/feed
            case 'forums':
                if (!defined('BPLF_DISABLE_GROUP_FORUMS_FEED')) {
                    $this_bp_feed = 'group_forums';
                }
                break;
                // Group membership activity
                // /groups/groupname/membership/feed
            // Group membership activity
            // /groups/groupname/membership/feed
            case 'membership':
                if (!defined('BPLF_DISABLE_GROUP_MEMBERSHIP_FEED')) {
                    $this_bp_feed = 'group_membership';
                }
                break;
        }
    }
    // Individual forum topic feeds
    // /groups/groupname/forum/topic/topicslug/feed
    if (bp_is_groups_component() && bp_current_action() == 'forum' && bp_action_variable(0) == 'topic' && bp_action_variable(1) && bp_action_variable(2) == 'feed') {
        global $bplf_topic, $bplf_topic_posts;
        if (!defined('BPLF_DISABLE_INDIVIDUAL_TOPIC_FEED')) {
            $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(1));
            $bplf_topic = bp_forums_get_topic_details($topic_id);
            $topic_args = array('per_page' => 50, 'max' => 50, 'order' => 'ASC');
            $topic_args = apply_filters('bp_lotsa_feeds_topic_feed_args', $topic_args);
            extract($topic_args);
            $bplf_topic_posts = new BP_Forums_Template_Topic($topic_id, $per_page, $max, $order);
            $this_bp_feed = 'forum_topic';
        }
    }
    $this_bp_feed = apply_filters('bplf_which_feed', $this_bp_feed);
    if (!$this_bp_feed) {
        return false;
    }
    $wp_query->is_404 = false;
    status_header(200);
    include_once apply_filters('bplf_feed_template', dirname(__FILE__) . '/feed-template.php');
    die;
}
Ejemplo n.º 13
0
function bp_forums_update_topic( $args = '' ) {
	global $bp;

	do_action( 'bbpress_init' );

	$defaults = array(
		'topic_id' => false,
		'topic_title' => '',
		'topic_text' => ''
	);

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

	if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
		return false;

	if ( !$post = bb_get_first_post( $topic_id ) )
		return false;

	/* Update the first post */
	if ( !$post = bp_forums_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) )
		return false;

	return bp_forums_get_topic_details( $topic_id );
}
Ejemplo n.º 14
0
function bp_ning_import_get_discussions()
{
    global $wpdb;
    $ning_id_array = get_option('bp_ning_user_array');
    // Get list of Ning groups for cross reference
    $groups = bp_ning_import_prepare_json('groups');
    $ning_group_id_array = get_option('bp_ning_group_array', array());
    $discussions = bp_ning_import_prepare_json('discussions');
    //delete_option('bp_ning_discussions_imported');
    $imported = get_option('bp_ning_discussions_imported', array());
    $counter = 0;
    foreach ((array) $discussions as $discussion_key => $discussion) {
        unset($topic_id);
        if (isset($imported[$discussion->id])) {
            continue;
        }
        if ($counter >= 10) {
            update_option('bp_ning_discussions_imported', $imported);
            printf(__('%d out of %d discussions done.'), count($imported), count($discussions));
            return false;
        }
        $slug = sanitize_title(esc_attr($discussion->category));
        $ning_group_creator_id = $discussion->contributorName;
        $creator_id = $ning_id_array[$ning_group_creator_id];
        if (!$creator_id) {
            $what++;
            continue;
        }
        $ndate = strtotime($discussion->createdDate);
        $date_created = date("Y-m-d H:i:s", $ndate);
        if (isset($discussion->category)) {
            $ning_group_id = $discussion->category;
            $group_id = $ning_group_id_array[$ning_group_id];
        } else {
            if (isset($discussion->groupId)) {
                $ngroup_id = $discussion->groupId;
                $group_id = $ning_group_id_array[$ngroup_id];
            } else {
                continue;
                // todo fix me!
            }
        }
        $group = new BP_Groups_Group($group_id);
        $args = array('topic_title' => $discussion->title, 'topic_slug' => groups_check_slug(sanitize_title(esc_attr($discussion->title))), 'topic_text' => $discussion->description, 'topic_poster' => $creator_id, 'topic_poster_name' => bp_core_get_user_displayname($creator_id), 'topic_last_poster' => $creator_id, 'topic_last_poster_name' => bp_core_get_user_displayname($creator_id), 'topic_start_time' => $date_created, 'topic_time' => $date_created, 'forum_id' => groups_get_groupmeta($group_id, 'forum_id'));
        $query = "SELECT `topic_id` FROM wp_bb_topics WHERE topic_title = '%s' AND topic_start_time = '%s' LIMIT 1";
        $q = $wpdb->prepare($query, $args['topic_title'], $args['topic_start_time']);
        $topic_exists = $wpdb->get_results($q);
        if (isset($topic_exists[0])) {
            echo "<em>- Topic {$discussion->title} already exists</em><br />";
            $imported[$discussion->id] = true;
            continue;
        }
        if (!$args['forum_id']) {
            echo "No forum id - skipping";
            continue;
        }
        if (!($topic_id = bp_forums_new_topic($args))) {
            // TODO: WTF?
            return false;
            echo "<h2>Refresh to import more discussions</h2>";
            die;
        } else {
            bp_ning_import_process_inline_images_new('discussions', $topic_id, 'topic');
            echo "<strong>- Created topic: {$discussion->title}</strong><br />";
        }
        $activity_content = bp_create_excerpt($discussion->description);
        $skip_activity = get_option('bp_ning_skip_forum_activity');
        if (!$skip_activity) {
            $topic = bp_forums_get_topic_details($topic_id);
            // Activity item
            $activity_action = sprintf(__('%s started the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink($creator_id), '<a href="' . bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_html($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_html($group->name) . '</a>');
            groups_record_activity(array('user_id' => $creator_id, 'action' => apply_filters('groups_activity_new_forum_topic_action', $activity_action, $discussion->description, $topic), 'content' => apply_filters('groups_activity_new_forum_topic_content', $activity_content, $discussion->description, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_topic_primary_link', bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/'), 'type' => 'new_forum_topic', 'item_id' => $group_id, 'secondary_item_id' => $topic->topic_id, 'recorded_time' => $date_created, 'hide_sitewide' => 0));
            do_action('groups_new_forum_topic', $group_id, $topic);
        }
        // Now check for comments
        if (isset($discussion->comments)) {
            foreach ($discussion->comments as $reply) {
                $ning_group_creator_id = $reply->contributorName;
                $creator_id = $ning_id_array[$ning_group_creator_id];
                $ndate = strtotime($reply->createdDate);
                $date_created = date("Y-m-d H:i:s", $ndate);
                $args = array('topic_id' => $topic_id, 'post_text' => $reply->description, 'post_time' => $date_created, 'poster_id' => $creator_id, 'poster_ip' => '192.168.1.1');
                $query = "SELECT * FROM wp_bb_posts WHERE topic_id = '%s' AND post_text = '%s'";
                $q = $wpdb->prepare($query, $args['topic_id'], $args['post_text']);
                $post_exists = $wpdb->get_results($q);
                if ($post_exists) {
                    continue;
                }
                $post_id = bp_forums_insert_post($args);
                if ($post_id) {
                    bp_ning_import_process_inline_images_new('discussions', $post_id, 'topic_reply');
                    $import_summary = esc_html(bp_create_excerpt($reply->description, 100, array('html' => false)));
                    echo "<em>- Imported forum post: {$import_summary}</em><br />";
                }
                if (!groups_is_user_member($creator_id, $group_id)) {
                    if (!$bp->groups->current_group) {
                        $bp->groups->current_group = new BP_Groups_Group($group_id);
                    }
                    $new_member = new BP_Groups_Member();
                    $new_member->group_id = $group_id;
                    $new_member->user_id = $creator_id;
                    $new_member->inviter_id = 0;
                    $new_member->is_admin = 0;
                    $new_member->user_title = '';
                    $new_member->date_modified = $date_created;
                    $new_member->is_confirmed = 1;
                    $new_member->save();
                    groups_update_groupmeta($group_id, 'total_member_count', (int) groups_get_groupmeta($group_id, 'total_member_count') + 1);
                    groups_update_groupmeta($group_id, 'last_activity', $date_created);
                    do_action('groups_join_group', $group_id, $creator_id);
                }
                if ($skip_activity) {
                    continue;
                }
                // Activity item
                $topic = bp_forums_get_topic_details($topic_id);
                $activity_action = sprintf(__('%s posted on the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink($creator_id), '<a href="' . bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>');
                $activity_content = bp_create_excerpt($reply->description);
                $primary_link = bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/';
                //if ( $page )
                //	$primary_link .= "?topic_page=" . $page;
                //echo $primary_link; die();
                groups_record_activity(array('user_id' => $creator_id, 'action' => apply_filters('groups_activity_new_forum_post_action', $activity_action, $post_id, $reply->description, $topic), 'content' => apply_filters('groups_activity_new_forum_post_content', $activity_content, $post_id, $reply->description, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}"), 'type' => 'new_forum_post', 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'recorded_time' => $date_created, 'hide_sitewide' => 0));
                do_action('groups_new_forum_topic_post', $group_id, $post_id);
            }
        }
        $imported[$discussion->id] = true;
        $counter++;
    }
    update_option('bp_ning_discussions_imported', $imported);
    return true;
}