/** * 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); }
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); }
/** * 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; }
/** * 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; }
/** * Modified version of {@link groups_new_group_forum_post()}. * * Duplicated because: * - groups_new_group_forum_post() hardcodes the $user_id. * - groups_new_group_forum_post() doesn't check if the corresponding topic is deleted before posting. * - $bp->groups->current_group doesn't exist outside the BP groups component. * - {@link groups_record_activity()} restricts a bunch of parameters - use full {@link bp_activity_add()} instead. * * @param mixed $args Arguments can be passed as an associative array or as a URL argument string * @return mixed If forum reply is successful, returns the forum post ID; false on failure * @since 1.0-beta */ function bp_rbe_groups_new_group_forum_post($args = '') { global $bp; $defaults = array('post_text' => false, 'topic_id' => false, 'user_id' => false, 'group_id' => false, 'page' => false); $r = apply_filters('bp_rbe_groups_new_group_forum_post_args', wp_parse_args($args, $defaults)); extract($r); if (empty($post_text)) { return false; } // apply BP's filters $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); // initialize bundled bbPress // @todo perhaps use $wpdb instead and do away with the 'bbpress_init' hook as it's hella intensive do_action('bbpress_init'); global $bbdb; // do a direct bbPress DB call if (isset($bbdb)) { $topic = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->topics} WHERE topic_id = %d", $topic_id)); } // if the topic was deleted, stop now! if ($topic->topic_status == 1) { return false; } if ($post_id = bp_forums_insert_post(array('post_text' => $post_text, 'topic_id' => $topic_id, 'poster_id' => $user_id))) { $group = groups_get_group('group_id=' . $group_id); // If no page passed, calculate the page where the new post will reside. // I should backport this to BP. if (!$page) { $pag_num = apply_filters('bp_rbe_topic_pag_num', 15); $page = ceil($topic->topic_posts / $pag_num); } $activity_action = sprintf(__('%s replied to the forum topic %s in the group %s via email:', 'bp-rbe'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'); $activity_content = bp_create_excerpt($post_text); $primary_link = bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/?topic_page=' . $page; /* Record this in activity streams */ $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('groups_activity_new_forum_post_action', $activity_action, $post_id, $post_text, $topic), 'content' => apply_filters('groups_activity_new_forum_post_content', $activity_content, $post_id, $post_text, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}"), 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'hide_sitewide' => $group->status == 'public' ? false : true)); // special hook for RBE activity items do_action('bp_rbe_new_activity', array('activity_id' => $activity_id, 'type' => 'new_forum_post', 'user_id' => $user_id, 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'content' => $activity_content)); // apply BP's group forum post hook do_action('groups_new_forum_topic_post', $group_id, $post_id); return $post_id; } return false; }
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_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 ); }
function bp_ning_import_insert_post($args = '') { global $bp; $defaults = array('topic_title' => '', 'topic_slug' => '', 'topic_text' => '', 'topic_poster' => $bp->loggedin_user->id, 'topic_poster_name' => $bp->loggedin_user->fullname, 'topic_last_poster' => $bp->loggedin_user->id, 'topic_last_poster_name' => $bp->loggedin_user->fullname, 'topic_start_time' => date('Y-m-d H:i:s'), 'topic_time' => date('Y-m-d H:i:s'), 'topic_open' => 1, 'topic_tags' => false, 'forum_id' => 0); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $topic_title = strip_tags($topic_title); if (empty($topic_title) || !strlen(trim($topic_title))) { return false; } if (empty($topic_slug)) { $topic_slug = sanitize_title($topic_title); } if (!($topic_id = bb_insert_topic(array('topic_title' => stripslashes($topic_title), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int) $forum_id, 'tags' => $topic_tags)))) { return false; } /* Now insert the first post. */ if (!bp_forums_insert_post(array('topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster))) { return false; } do_action('bp_forums_new_topic', $topic_id); return $topic_id; }