Skip to:
Content

BuddyPress.org

Ticket #4239: 4239.02.patch

File 4239.02.patch, 19.5 KB (added by r-a-y, 13 years ago)
  • bp-groups/bp-groups-forums.php

     
    1414// Exit if accessed directly
    1515if ( !defined( 'ABSPATH' ) ) exit;
    1616
     17/**
     18 * Creates a new forum inside a specific BuddyPress group.
     19 *
     20 * Uses the bundled version of bbPress packaged with BuddyPress.
     21 *
     22 * @param int $group_id The group ID that the new forum should be attached to
     23 * @param string $group_name The group name
     24 * @param string $group_description The group description
     25 *
     26 * @since 1.0
     27 */
    1728function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = '' ) {
    1829        global $bp;
    1930
    2031        if ( empty( $group_id ) )
    21                 $group_id = $bp->groups->current_group->id;
     32                $group_id = bp_get_current_group_id();
    2233
    2334        if ( empty( $group_name ) )
    24                 $group_name = $bp->groups->current_group->name;
     35                $group_name = bp_get_current_group_name();
    2536
    2637        if ( empty( $group_desc ) )
    2738                $group_desc = $bp->groups->current_group->description;
    function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = 
    4051 * @subpackage Groups
    4152 *
    4253 * @param int $group_id Group id, passed from groups_details_updated
     54 *
     55 * @since 1.1
    4356 */
    4457function groups_update_group_forum( $group_id ) {
    4558
    function groups_update_group_forum( $group_id ) { 
    6679}
    6780add_action( 'groups_details_updated', 'groups_update_group_forum' );
    6881
     82/**
     83 * Creates a new group forum post.
     84 *
     85 * Uses the bundled version of bbPress packaged with BuddyPress.
     86 *
     87 * @param string $post_text The text for the forum post
     88 * @param int $topic_id The topic ID used so we can identify where the new forum post should reside
     89 * @param mixed $page The page number where the new forum post should reside. Defaults to boolean false.
     90 * @return mixed The new forum post ID on success. Boolean false on failure.
     91 *
     92 * @since 1.0
     93 */
    6994function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) {
    70         global $bp;
    71 
    7295        if ( empty( $post_text ) )
    7396                return false;
    7497
    function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) { 
    78101        if ( $post_id = bp_forums_insert_post( array( 'post_text' => $post_text, 'topic_id' => $topic_id ) ) ) {
    79102                $topic = bp_forums_get_topic_details( $topic_id );
    80103
    81                 $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
     104                $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' );
    82105                $activity_content = bp_create_excerpt( $post_text );
    83                 $primary_link = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
     106                $primary_link = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/';
    84107
    85108                if ( $page )
    86109                        $primary_link .= "?topic_page=" . $page;
    87110
    88111                // Record this in activity streams
    89112                groups_record_activity( array(
    90                         'action'            => apply_filters_ref_array( 'groups_activity_new_forum_post_action',       array( $activity_action,  $post_id, $post_text, &$topic ) ),
    91                         'content'           => apply_filters_ref_array( 'groups_activity_new_forum_post_content',      array( $activity_content, $post_id, $post_text, &$topic ) ),
     113                        'action'            => apply_filters_ref_array( 'groups_activity_new_forum_post_action',  array( $activity_action,  $post_id, $post_text, &$topic ) ),
     114                        'content'           => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_id, $post_text, &$topic ) ),
    92115                        'primary_link'      => apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ),
    93116                        'type'              => 'new_forum_post',
    94                         'item_id'           => $bp->groups->current_group->id,
     117                        'item_id'           => bp_get_current_group_id(),
    95118                        'secondary_item_id' => $post_id
    96119                ) );
    97120
    98                 do_action( 'groups_new_forum_topic_post', $bp->groups->current_group->id, $post_id );
     121                do_action( 'groups_new_forum_topic_post', bp_get_current_group_id(), $post_id );
    99122
    100123                return $post_id;
    101124        }
    function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) { 
    103126        return false;
    104127}
    105128
     129/**
     130 * Creates a new group forum topic.
     131 *
     132 * Uses the bundled version of bbPress packaged with BuddyPress.
     133 *
     134 * @param string $topic_title The title for the forum topic
     135 * @param string $topic_text The text for the forum topic
     136 * @param string $topic_tags A comma-delimited string of topic tags
     137 * @param int $forum_id The forum ID this forum topic resides in
     138 * @return mixed The new topic object on success. Boolean false on failure.
     139 *
     140 * @since 1.0
     141 */
    106142function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $forum_id ) {
    107         global $bp;
    108 
    109143        if ( empty( $topic_title ) || empty( $topic_text ) )
    110144                return false;
    111145
    function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $ 
    117151        if ( $topic_id = bp_forums_new_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id ) ) ) {
    118152                $topic = bp_forums_get_topic_details( $topic_id );
    119153
    120                 $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
     154                $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' );
    121155                $activity_content = bp_create_excerpt( $topic_text );
    122156
    123157                // Record this in activity streams
    124158                groups_record_activity( array(
    125159                        'action'            => apply_filters_ref_array( 'groups_activity_new_forum_topic_action',  array( $activity_action,  $topic_text, &$topic ) ),
    126160                        'content'           => apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ),
    127                         'primary_link'      => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),
     161                        'primary_link'      => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/' ),
    128162                        'type'              => 'new_forum_topic',
    129                         'item_id'           => $bp->groups->current_group->id,
     163                        'item_id'           => bp_get_current_group_id(),
    130164                        'secondary_item_id' => $topic->topic_id
    131165                ) );
    132166
    133           do_action_ref_array( 'groups_new_forum_topic', array( $bp->groups->current_group->id, &$topic ) );
     167                do_action_ref_array( 'groups_new_forum_topic', array( bp_get_current_group_id(), &$topic ) );
    134168
    135169                return $topic;
    136170        }
    function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $ 
    138172        return false;
    139173}
    140174
     175/**
     176 * Updates an existing group forum topic.
     177 *
     178 * Uses the bundled version of bbPress packaged with BuddyPress.
     179 *
     180 * @param int $topic_id The topic ID of the existing forum topic
     181 * @param string $topic_title The title for the forum topic
     182 * @param string $topic_text The text for the forum topic
     183 * @param mixed $topic_tags A comma-delimited string of topic tags. Defaults to boolean false.
     184 * @return mixed The topic object on success. Boolean false on failure.
     185 *
     186 * @since 1.1
     187 */
    141188function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, $topic_tags = false ) {
    142189        global $bp;
    143190
    function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, 
    149196                // Get the corresponding activity item
    150197                if ( bp_is_active( 'activity' ) ) {
    151198                        $id = bp_activity_get_activity_id( array(
    152                                         'item_id'           => $bp->groups->current_group->id,
     199                                        'item_id'           => bp_get_current_group_id(),
    153200                                        'secondary_item_id' => $topic_id,
    154201                                        'component'         => $bp->groups->id,
    155202                                        'type'              => 'new_forum_topic'
    156203                        ) );
    157204                }
    158205
    159                 $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<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>' );
     206                $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<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>' );
    160207                $activity_content = bp_create_excerpt( $topic_text );
    161208
    162209                // Record this in activity streams
    function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, 
    164211                        'id'                => $id,
    165212                        'action'            => apply_filters_ref_array( 'groups_activity_new_forum_topic_action',  array( $activity_action,  $topic_text, &$topic ) ),
    166213                        'content'           => apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ),
    167                         'primary_link'      => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),
     214                        'primary_link'      => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/' ),
    168215                        'type'              => 'new_forum_topic',
    169                         'item_id'           => (int) $bp->groups->current_group->id,
     216                        'item_id'           => (int) bp_get_current_group_id(),
    170217                        'user_id'           => (int) $topic->topic_poster,
    171218                        'secondary_item_id' => $topic->topic_id,
    172219                        'recorded_time '    => $topic->topic_time
    function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, 
    180227        return false;
    181228}
    182229
     230/**
     231 * Updates an existing group forum post.
     232 *
     233 * Uses the bundled version of bbPress packaged with BuddyPress.
     234 *
     235 * @param int $post_id The post ID of the existing forum post
     236 * @param string $post_text The text for the forum post
     237 * @param int $topic_id The topic ID of the existing forum topic
     238 * @param mixed $page The page number where the new forum post should reside. Defaults to boolean false.
     239 * @return mixed The forum post ID on success. Boolean false on failure.
     240 *
     241 * @since 1.1
     242 */
    183243function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page = false ) {
    184244        global $bp;
    185245
    function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page 
    190250        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 ) ) ) {
    191251                $topic = bp_forums_get_topic_details( $topic_id );
    192252
    193                 $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( $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>' );
     253                $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>' );
    194254                $activity_content = bp_create_excerpt( $post_text );
    195                 $primary_link = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
     255                $primary_link = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/';
    196256
    197257                if ( $page )
    198258                        $primary_link .= "?topic_page=" . $page;
    199259
    200                 // Fetch an existing entry and update if one exists.
    201                 if ( bp_is_active( 'activity' ) )
    202                         $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 ) );
     260                // Get the corresponding activity item
     261                if ( bp_is_active( 'activity' ) ) {
     262                        $id = bp_activity_get_activity_id( array(
     263                                'user_id'           => $post->poster_id,
     264                                'component'         => $bp->groups->id,
     265                                'type'              => 'new_forum_post',
     266                                'item_id'           => bp_get_current_group_id(),
     267                                'secondary_item_id' => $post_id
     268                         ) );
     269                }
    203270
    204271                // Update the entry in activity streams
    205272                groups_record_activity( array(
    206273                        'id'                => $id,
    207                         'action'            => apply_filters_ref_array( 'groups_activity_new_forum_post_action',  array( $activity_action,  $post_text, &$topic, &$forum_post ) ),
    208                         'content'           => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_text, &$topic, &$forum_post ) ),
     274                        'action'            => apply_filters_ref_array( 'groups_activity_new_forum_post_action',  array( $activity_action,  $post_text, &$topic, &$topic ) ),
     275                        'content'           => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_text, &$topic, &$topic ) ),
    209276                        'primary_link'      => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ),
    210277                        'type'              => 'new_forum_post',
    211                         'item_id'           => (int) $bp->groups->current_group->id,
     278                        'item_id'           => (int) bp_get_current_group_id(),
    212279                        'user_id'           => (int) $post->poster_id,
    213280                        'secondary_item_id' => $post_id,
    214281                        'recorded_time'     => $post->post_time
    function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page 
    223290}
    224291
    225292/**
    226  * Handles the forum topic deletion routine
     293 * Deletes a group forum topic and also any corresponding activity items.
     294 *
     295 * Uses the bundled version of bbPress packaged with BuddyPress.
    227296 *
    228297 * @package BuddyPress
    229298 *
    function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page 
    232301 * @uses bp_forums_delete_topic() to do the deletion itself
    233302 * @param int $topic_id The id of the topic to be deleted
    234303 * @return bool True if the delete routine went through properly
     304 *
     305 * @since 1.1
    235306 */
    236307function groups_delete_group_forum_topic( $topic_id ) {
    237308        global $bp;
    function groups_delete_group_forum_topic( $topic_id ) { 
    242313        if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
    243314                do_action( 'groups_before_delete_group_forum_topic', $topic_id );
    244315
    245                 // Delete the activity stream items
     316                // Delete the corresponding activity stream items
    246317                if ( bp_is_active( 'activity' ) ) {
    247318                        // The activity item for the initial topic
    248                         bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) );
     319                        bp_activity_delete( array(
     320                                'item_id'           => bp_get_current_group_id(),
     321                                'secondary_item_id' => $topic_id,
     322                                'component'         => $bp->groups->id,
     323                                'type'              => 'new_forum_topic'
     324                        ) );
    249325
    250326                        // The activity item for each post
    251327                        foreach ( (array) $posts as $post ) {
    252                                 bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post->post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post' ) );
     328                                bp_activity_delete( array(
     329                                        'item_id'           => bp_get_current_group_id(),
     330                                        'secondary_item_id' => $post->post_id,
     331                                        'component'         => $bp->groups->id,
     332                                        'type'              => 'new_forum_post'
     333                                ) );
    253334                        }
    254335                }
    255336
    function groups_delete_group_forum_topic( $topic_id ) { 
    262343}
    263344
    264345/**
    265  * Delete a forum post
     346 * Deletes a group forum post and its corresponding activity item.
     347 *
     348 * Uses the bundled version of bbPress packaged with BuddyPress.
    266349 *
    267350 * @package BuddyPress
    268351 *
    function groups_delete_group_forum_topic( $topic_id ) { 
    270353 * @param int $topic_id Optional. The topic to which the post belongs. This value isn't used in the
    271354 *   function but is passed along to do_action() hooks.
    272355 * @return bool True on success.
     356 *
     357 * @since 1.1
    273358 */
    274359function groups_delete_group_forum_post( $post_id, $topic_id = false ) {
    275360        global $bp;
    function groups_delete_group_forum_post( $post_id, $topic_id = false ) { 
    277362        if ( bp_forums_delete_post( array( 'post_id' => $post_id ) ) ) {
    278363                do_action( 'groups_before_delete_group_forum_post', $post_id, $topic_id );
    279364
    280                 // Delete the activity stream item
     365                // Delete the corresponding activity stream item
    281366                if ( bp_is_active( 'activity' ) )
    282                         bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post' ) );
     367                        bp_activity_delete( array(
     368                                'item_id'           => bp_get_current_group_id(),
     369                                'secondary_item_id' => $post_id,
     370                                'component'         => $bp->groups->id,
     371                                'type'              => 'new_forum_post'
     372                        ) );
    283373
    284374                do_action( 'groups_delete_group_forum_post', $post_id, $topic_id );
    285375
    function groups_delete_group_forum_post( $post_id, $topic_id = false ) { 
    289379        return false;
    290380}
    291381
     382/**
     383 * Get a total count of all public topics of a given type, across groups/forums
     384 *
     385 * @package BuddyPress
     386 * @since 1.5
     387 *
     388 * @param string $type Either 'newest', 'popular', 'unreplied', 'tags'.  Defaults to 'newest'.
     389 * @return int The topic count
     390 */
    292391function groups_total_public_forum_topic_count( $type = 'newest' ) {
    293392        return apply_filters( 'groups_total_public_forum_topic_count', BP_Groups_Group::get_global_forum_topic_count( $type ) );
    294393}
    function groups_total_public_forum_topic_count( $type = 'newest' ) { 
    297396 * Get a total count of all topics of a given status, across groups/forums
    298397 *
    299398 * @package BuddyPress
    300  * @since BuddyPress (1.5)
     399 * @since 1.5
    301400 *
    302401 * @param str $status 'public', 'private', 'hidden', 'all' Which group types to count
    303402 * @return int The topic count