Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/08/2017 12:22:09 AM (7 years ago)
Author:
djpaul
Message:

Retire Legacy Forums.

"Legacy Forums" is what we now call the bundled version of bbPress 1 that has shipped with BuddyPress for over nine years. The Legacy Forums codebase/features are many years stagnant, and it has been almost completely hidden from the UI for the past five years.

Legacy Forums were replaced by bbPress 2, which is its own plugin, and we've been promoting its integration with BuddyPress for a long time. Most significantly, bbPress 1 only runs on WordPress versions older than 4.7, because of a BackPress conflict (which is nested inside bbPress 1) with WordPress 4.7's WP_Taxonomy class.

If your site is still using Legacy Forums, you will need to migrate to bbPress 2 to run BuddyPress 3.0. See https://bpdevel.wordpress.com/2017/12/07/legacy-forums-support-will-be/ for more information.

Fixes #5351
See #7502

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-screens.php

    r11556 r11763  
    167167     */
    168168    bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    169 }
    170 
    171 /**
    172  * This screen function handles actions related to group forums.
    173  *
    174  * @since 1.0.0
    175  */
    176 function groups_screen_group_forum() {
    177 
    178     if ( !bp_is_active( 'forums' ) || !bp_forums_is_installed_correctly() )
    179         return false;
    180 
    181     if ( bp_action_variable( 0 ) && !bp_is_action_variable( 'topic', 0 ) ) {
    182         bp_do_404();
    183         return;
    184     }
    185 
    186     $bp = buddypress();
    187 
    188     if ( !$bp->groups->current_group->user_has_access ) {
    189         bp_core_no_access();
    190         return;
    191     }
    192 
    193     if ( ! bp_is_single_item() )
    194         return false;
    195 
    196     // Fetch the details we need.
    197     $topic_slug = (string)bp_action_variable( 1 );
    198     $topic_id       = bp_forums_get_topic_id_from_slug( $topic_slug );
    199     $forum_id       = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    200     $user_is_banned = false;
    201 
    202     if ( !bp_current_user_can( 'bp_moderate' ) && groups_is_user_banned( bp_loggedin_user_id(), $bp->groups->current_group->id ) )
    203         $user_is_banned = true;
    204 
    205     if ( !empty( $topic_slug ) && !empty( $topic_id ) ) {
    206 
    207         // Posting a reply.
    208         if ( !$user_is_banned && !bp_action_variable( 2 ) && isset( $_POST['submit_reply'] ) ) {
    209             // Check the nonce.
    210             check_admin_referer( 'bp_forums_new_reply' );
    211 
    212             // Auto join this user if they are not yet a member of this group.
    213             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 ) ) {
    214                 groups_join_group( $bp->groups->current_group->id, bp_loggedin_user_id() );
    215             }
    216 
    217             $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false;
    218 
    219             // Don't allow reply flooding.
    220             if ( bp_forums_reply_exists( $_POST['reply_text'], $topic_id, bp_loggedin_user_id() ) ) {
    221                 bp_core_add_message( __( 'It looks like you\'ve already said that!', 'buddypress' ), 'error' );
    222             } else {
    223                 if ( !$post_id = groups_new_group_forum_post( $_POST['reply_text'], $topic_id, $topic_page ) ) {
    224                     bp_core_add_message( __( 'There was an error when replying to that topic', 'buddypress'), 'error' );
    225                 } else {
    226                     bp_core_add_message( __( 'Your reply was posted successfully', 'buddypress') );
    227                 }
    228             }
    229 
    230             $query_vars = isset( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '';
    231 
    232             $redirect = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic_slug . '/' . $query_vars;
    233 
    234             if ( !empty( $post_id ) ) {
    235                 $redirect .= '#post-' . $post_id;
    236             }
    237 
    238             bp_core_redirect( $redirect );
    239         }
    240 
    241         // Sticky a topic.
    242         elseif ( bp_is_action_variable( 'stick', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    243             // Check the nonce.
    244             check_admin_referer( 'bp_forums_stick_topic' );
    245 
    246             if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id ) ) ) {
    247                 bp_core_add_message( __( 'There was an error when making that topic a sticky', 'buddypress' ), 'error' );
    248             } else {
    249                 bp_core_add_message( __( 'The topic was made sticky successfully', 'buddypress' ) );
    250             }
    251 
    252             /**
    253              * Fires after a group forum topic has been stickied.
    254              *
    255              * @since 1.1.0
    256              *
    257              * @param int $topic_id ID of the topic being stickied.
    258              */
    259             do_action( 'groups_stick_forum_topic', $topic_id );
    260             bp_core_redirect( wp_get_referer() );
    261         }
    262 
    263         // Un-Sticky a topic.
    264         elseif ( bp_is_action_variable( 'unstick', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    265             // Check the nonce.
    266             check_admin_referer( 'bp_forums_unstick_topic' );
    267 
    268             if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id, 'mode' => 'unstick' ) ) ) {
    269                 bp_core_add_message( __( 'There was an error when unsticking that topic', 'buddypress'), 'error' );
    270             } else {
    271                 bp_core_add_message( __( 'The topic was unstuck successfully', 'buddypress') );
    272             }
    273 
    274             /**
    275              * Fires after a group forum topic has been un-stickied.
    276              *
    277              * @since 1.1.0
    278              *
    279              * @param int $topic_id ID of the topic being un-stickied.
    280              */
    281             do_action( 'groups_unstick_forum_topic', $topic_id );
    282             bp_core_redirect( wp_get_referer() );
    283         }
    284 
    285         // Close a topic.
    286         elseif ( bp_is_action_variable( 'close', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    287             // Check the nonce.
    288             check_admin_referer( 'bp_forums_close_topic' );
    289 
    290             if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id ) ) ) {
    291                 bp_core_add_message( __( 'There was an error when closing that topic', 'buddypress'), 'error' );
    292             } else {
    293                 bp_core_add_message( __( 'The topic was closed successfully', 'buddypress') );
    294             }
    295 
    296             /**
    297              * Fires after a group forum topic has been closed.
    298              *
    299              * @since 1.1.0
    300              *
    301              * @param int $topic_id ID of the topic being closed.
    302              */
    303             do_action( 'groups_close_forum_topic', $topic_id );
    304             bp_core_redirect( wp_get_referer() );
    305         }
    306 
    307         // Open a topic.
    308         elseif ( bp_is_action_variable( 'open', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    309             // Check the nonce.
    310             check_admin_referer( 'bp_forums_open_topic' );
    311 
    312             if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id, 'mode' => 'open' ) ) ) {
    313                 bp_core_add_message( __( 'There was an error when opening that topic', 'buddypress'), 'error' );
    314             } else {
    315                 bp_core_add_message( __( 'The topic was opened successfully', 'buddypress') );
    316             }
    317 
    318             /**
    319              * Fires after a group forum topic has been opened.
    320              *
    321              * @since 1.1.0
    322              *
    323              * @param int $topic_id ID of the topic being opened.
    324              */
    325             do_action( 'groups_open_forum_topic', $topic_id );
    326             bp_core_redirect( wp_get_referer() );
    327         }
    328 
    329         // Delete a topic.
    330         elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'delete', 2 ) && !bp_action_variable( 3 ) ) {
    331             // Fetch the topic.
    332             $topic = bp_forums_get_topic_details( $topic_id );
    333 
    334             /* Check the logged in user can delete this topic */
    335             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $topic->topic_poster ) ) {
    336                 bp_core_redirect( wp_get_referer() );
    337             }
    338 
    339             // Check the nonce.
    340             check_admin_referer( 'bp_forums_delete_topic' );
    341 
    342             /**
    343              * Fires before a group forum topic is deleted.
    344              *
    345              * @since 1.5.0
    346              *
    347              * @param int $topic_id ID of the topic being deleted.
    348              */
    349             do_action( 'groups_before_delete_forum_topic', $topic_id );
    350 
    351             if ( !groups_delete_group_forum_topic( $topic_id ) ) {
    352                 bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress' ), 'error' );
    353             } else {
    354                 bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress' ) );
    355             }
    356 
    357             /**
    358              * Fires after a group forum topic has been deleted.
    359              *
    360              * @since 1.5.0
    361              *
    362              * @param int $topic_id ID of the topic being deleted.
    363              */
    364             do_action( 'groups_delete_forum_topic', $topic_id );
    365             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'forum/' );
    366         }
    367 
    368         // Editing a topic.
    369         elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'edit', 2 ) && !bp_action_variable( 3 ) ) {
    370             // Fetch the topic.
    371             $topic = bp_forums_get_topic_details( $topic_id );
    372 
    373             // Check the logged in user can edit this topic.
    374             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $topic->topic_poster ) ) {
    375                 bp_core_redirect( wp_get_referer() );
    376             }
    377 
    378             if ( isset( $_POST['save_changes'] ) ) {
    379                 // Check the nonce.
    380                 check_admin_referer( 'bp_forums_edit_topic' );
    381 
    382                 $topic_tags = !empty( $_POST['topic_tags'] ) ? $_POST['topic_tags'] : false;
    383 
    384                 if ( !groups_update_group_forum_topic( $topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags ) ) {
    385                     bp_core_add_message( __( 'There was an error when editing that topic', 'buddypress'), 'error' );
    386                 } else {
    387                     bp_core_add_message( __( 'The topic was edited successfully', 'buddypress') );
    388                 }
    389 
    390                 /**
    391                  * Fires after a group forum topic has been edited.
    392                  *
    393                  * @since 1.1.0
    394                  *
    395                  * @param int $topic_id ID of the topic being edited.
    396                  */
    397                 do_action( 'groups_edit_forum_topic', $topic_id );
    398                 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic_slug . '/' );
    399             }
    400 
    401             /**
    402              * Filters the template to load for a topic edit page.
    403              *
    404              * @since 1.1.0
    405              *
    406              * @param string $value Path to a topic edit template.
    407              */
    408             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) );
    409 
    410         // Delete a post.
    411         } elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'delete', 2 ) && $post_id = bp_action_variable( 4 ) ) {
    412             // Fetch the post.
    413             $post = bp_forums_get_post( $post_id );
    414 
    415             // Check the logged in user can edit this topic.
    416             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $post->poster_id ) ) {
    417                 bp_core_redirect( wp_get_referer() );
    418             }
    419 
    420             // Check the nonce.
    421             check_admin_referer( 'bp_forums_delete_post' );
    422 
    423             /**
    424              * Fires before the deletion of a group forum post.
    425              *
    426              * @since 1.5.0
    427              *
    428              * @param int $post_id ID of the forum post being deleted.
    429              */
    430             do_action( 'groups_before_delete_forum_post', $post_id );
    431 
    432             if ( !groups_delete_group_forum_post( $post_id ) ) {
    433                 bp_core_add_message( __( 'There was an error deleting that post', 'buddypress'), 'error' );
    434             } else {
    435                 bp_core_add_message( __( 'The post was deleted successfully', 'buddypress') );
    436             }
    437 
    438             /**
    439              * Fires after the deletion of a group forum post.
    440              *
    441              * @since 1.1.0
    442              *
    443              * @param int $post_id ID of the forum post being deleted.
    444              */
    445             do_action( 'groups_delete_forum_post', $post_id );
    446             bp_core_redirect( wp_get_referer() );
    447 
    448         // Editing a post.
    449         } elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'edit', 2 ) && $post_id = bp_action_variable( 4 ) ) {
    450 
    451             // Fetch the post.
    452             $post = bp_forums_get_post( $post_id );
    453 
    454             // Check the logged in user can edit this topic.
    455             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $post->poster_id ) ) {
    456                 bp_core_redirect( wp_get_referer() );
    457             }
    458 
    459             if ( isset( $_POST['save_changes'] ) ) {
    460                 // Check the nonce.
    461                 check_admin_referer( 'bp_forums_edit_post' );
    462 
    463                 $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false;
    464 
    465                 if ( !$post_id = groups_update_group_forum_post( $post_id, $_POST['post_text'], $topic_id, $topic_page ) ) {
    466                     bp_core_add_message( __( 'There was an error when editing that post', 'buddypress'), 'error' );
    467                 } else {
    468                     bp_core_add_message( __( 'The post was edited successfully', 'buddypress') );
    469                 }
    470 
    471                 if ( $_SERVER['QUERY_STRING'] ) {
    472                     $query_vars = '?' . $_SERVER['QUERY_STRING'];
    473                 }
    474 
    475                 /**
    476                  * Fires after the editing of a group forum post.
    477                  *
    478                  * @since 1.1.0
    479                  *
    480                  * @param int $post_id ID of the forum post being edited.
    481                  */
    482                 do_action( 'groups_edit_forum_post', $post_id );
    483                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id );
    484             }
    485 
    486             /** This filter is documented in bp-groups/bp-groups-screens.php */
    487             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) );
    488 
    489         // Standard topic display.
    490         } else {
    491             if ( !empty( $user_is_banned ) ) {
    492                 bp_core_add_message( __( "You have been banned from this group.", 'buddypress' ) );
    493             }
    494 
    495             /**
    496              * Filters the template to load for a topic page.
    497              *
    498              * @since 1.1.0
    499              *
    500              * @param string $value Path to a topic template.
    501              */
    502             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/home' ) );
    503         }
    504 
    505     // Forum topic does not exist.
    506     } elseif ( !empty( $topic_slug ) && empty( $topic_id ) ) {
    507         bp_do_404();
    508         return;
    509 
    510     } else {
    511         // Posting a topic.
    512         if ( isset( $_POST['submit_topic'] ) && bp_is_active( 'forums' ) ) {
    513 
    514             // Check the nonce.
    515             check_admin_referer( 'bp_forums_new_topic' );
    516 
    517             if ( $user_is_banned ) {
    518                 $error_message = __( "You have been banned from this group.", 'buddypress' );
    519 
    520             } 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 ) ) {
    521                 // Auto join this user if they are not yet a member of this group.
    522                 groups_join_group( $bp->groups->current_group->id, bp_loggedin_user_id() );
    523             }
    524 
    525             if ( empty( $_POST['topic_title'] ) ) {
    526                 $error_message = __( 'Please provide a title for your forum topic.', 'buddypress' );
    527             } elseif ( empty( $_POST['topic_text'] ) ) {
    528                 $error_message = __( 'Forum posts cannot be empty. Please enter some text.', 'buddypress' );
    529             }
    530 
    531             if ( empty( $forum_id ) ) {
    532                 $error_message = __( 'This group does not have a forum setup yet.', 'buddypress' );
    533             }
    534 
    535             if ( isset( $error_message ) ) {
    536                 bp_core_add_message( $error_message, 'error' );
    537                 $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
    538             } else {
    539                 if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) ) {
    540                     bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
    541                     $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
    542                 } else {
    543                     bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
    544                     $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
    545                 }
    546             }
    547 
    548             bp_core_redirect( $redirect );
    549         }
    550 
    551         /**
    552          * Fires at the end of the group forum screen loading process.
    553          *
    554          * @since 1.0.0
    555          *
    556          * @param int $topic_id ID of the topic being displayed.
    557          * @param int $forum_id ID of the forum being displayed.
    558          */
    559         do_action( 'groups_screen_group_forum', $topic_id, $forum_id );
    560 
    561         /**
    562          * Filters the template to load for a group forum page.
    563          *
    564          * @since 1.0.0
    565          *
    566          * @param string $value Path to a group forum template.
    567          */
    568         bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/single/home' ) );
    569     }
    570169}
    571170
Note: See TracChangeset for help on using the changeset viewer.