Skip to:
Content

BuddyPress.org

Changeset 11763


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

Location:
trunk
Files:
7 deleted
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/.jshintignore

    r11009 r11763  
    1 // Deprecated
    2 src/bp-forums/bbpress/**/*
    3 
    41// 3rd party libraries
    52src/bp-core/js/vendor/**/*
  • trunk/Gruntfile.js

    r11690 r11763  
    1919
    2020        BP_EXCLUDED_MISC = [
    21             '!bp-forums/bbpress/**/*'
    2221        ],
    2322
     
    257256        },
    258257        exec: {
    259             bbpress: {
    260                 command: 'svn export --force https://bbpress.svn.wordpress.org/tags/1.2 bbpress',
    261                 cwd: BUILD_DIR + 'bp-forums',
    262                 stdout: false
    263             },
    264258            bpdefault: {
    265259                command: 'svn export --force https://github.com/buddypress/BP-Default.git/trunk bp-themes/bp-default',
     
    304298    grunt.registerTask( 'commit',  ['src', 'checktextdomain', 'imagemin'] );
    305299    grunt.registerTask( 'build',   ['commit', 'clean:all', 'copy:files', 'uglify', 'jsvalidate:build', 'cssmin', 'makepot', 'exec:bpdefault'] );
    306     grunt.registerTask( 'release', ['build', 'exec:bbpress'] );
     300    grunt.registerTask( 'release', ['build'] );
    307301
    308302    // Testing tasks.
  • trunk/composer.json

    r11615 r11763  
    66    "activity",
    77    "community",
    8     "forum",
    98    "friends",
    109    "groups",
  • trunk/package.json

    r11679 r11763  
    3535    "activity",
    3636    "community",
    37     "forum",
    3837    "friends",
    3938    "groups",
  • trunk/src/bp-activity/bp-activity-filters.php

    r11592 r11763  
    9797
    9898add_filter( 'pre_comment_content',                   'bp_activity_at_name_filter' );
    99 add_filter( 'group_forum_topic_text_before_save',    'bp_activity_at_name_filter' );
    100 add_filter( 'group_forum_post_text_before_save',     'bp_activity_at_name_filter' );
    10199add_filter( 'the_content',                           'bp_activity_at_name_filter' );
    102100add_filter( 'bp_activity_get_embed_excerpt',         'bp_activity_at_name_filter' );
  • trunk/src/bp-core/admin/bp-core-admin-components.php

    r10934 r11763  
    8181    $required_components = bp_core_admin_get_components( 'required' );
    8282    $retired_components  = bp_core_admin_get_components( 'retired'  );
    83 
    84     // Don't show Forums component in optional components if it's disabled.
    85     if ( ! bp_is_active( 'forums' ) ) {
    86         unset( $optional_components['forums'] );
    87     }
    8883
    8984    // Merge optional and required together.
  • trunk/src/bp-core/admin/bp-core-admin-functions.php

    r11513 r11763  
    287287            $orphaned_components[] = $component['name'];
    288288        }
    289     }
    290 
    291     // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is
    292     // not correctly set up, don't show a nag. (In these cases, it's probably the case that the
    293     // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292.
    294     if ( isset( $bp->forums->name ) && in_array( $bp->forums->name, $orphaned_components ) && !bp_forums_is_installed_correctly() ) {
    295         $forum_key = array_search( $bp->forums->name, $orphaned_components );
    296         unset( $orphaned_components[$forum_key] );
    297         $orphaned_components = array_values( $orphaned_components );
    298289    }
    299290
     
    440431        ),
    441432    );
    442 
    443     // If forums component is active, add additional tab.
    444     if ( bp_is_active( 'forums' ) && class_exists( 'BP_Forums_Component' ) ) {
    445 
    446         // Enqueue thickbox.
    447         wp_enqueue_script( 'thickbox' );
    448         wp_enqueue_style( 'thickbox' );
    449 
    450         $tabs['3'] = array(
    451             'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bb-forums-setup'  ), 'admin.php' ) ),
    452             'name' => __( 'Forums', 'buddypress' )
    453         );
    454     }
    455433
    456434    /**
  • trunk/src/bp-core/admin/bp-core-admin-settings.php

    r11606 r11763  
    248248}
    249249
    250 /** Forums Section ************************************************************/
    251 
    252 /**
    253  * Forums settings section description for the settings page.
    254  *
    255  * @since 1.6.0
    256  */
    257 function bp_admin_setting_callback_bbpress_section() { }
    258 
    259 /**
    260  * The bb-config.php location field.
    261  *
    262  * @since 1.6.0
    263  *
    264  */
    265 function bp_admin_setting_callback_bbpress_configuration() {
    266 
    267     $config_location = bp_get_option( 'bb-config-location' );
    268     $file_exists     = (bool) ( file_exists( $config_location ) || is_file( $config_location ) ); ?>
    269 
    270     <input name="bb-config-location" type="text" id="bb-config-location" value="<?php bp_form_option( 'bb-config-location', '' ); ?>" class="medium-text" style="width: 300px;" />
    271 
    272     <?php if ( false === $file_exists ) : ?>
    273 
    274         <a class="button" href="<?php bp_admin_url( 'admin.php?page=bb-forums-setup&repair=1' ); ?>"><?php _e( 'Repair', 'buddypress' ) ?></a>
    275         <span class="attention"><?php _e( 'File does not exist', 'buddypress' ); ?></span>
    276 
    277     <?php endif; ?>
    278 
    279     <p class="description"><?php _e( 'Absolute path to your bbPress configuration file.', 'buddypress' ); ?></p>
    280 
    281 <?php
    282 }
    283 
    284250/** Settings Page *************************************************************/
    285251
  • trunk/src/bp-core/admin/css/common-rtl.css

    r11711 r11763  
    524524}
    525525
    526 .settings_page_bp-components tr.forums td.plugin-title span:before {
    527     content: "\f452";
    528 }
    529 
    530526.settings_page_bp-components tr.blogs td.plugin-title span:before {
    531527    content: "\f120";
  • trunk/src/bp-core/admin/css/common.css

    r11711 r11763  
    524524}
    525525
    526 .settings_page_bp-components tr.forums td.plugin-title span:before {
    527     content: "\f452";
    528 }
    529 
    530526.settings_page_bp-components tr.blogs td.plugin-title span:before {
    531527    content: "\f120";
  • trunk/src/bp-core/bp-core-filters.php

    r11698 r11763  
    101101    if ( !empty( $bp->pages->register ) )
    102102        $pages[] = $bp->pages->register->id;
    103 
    104     if ( !empty( $bp->pages->forums ) && ( !bp_is_active( 'forums' ) || ( bp_is_active( 'forums' ) && bp_forums_has_directory() && !bp_forums_is_installed_correctly() ) ) )
    105         $pages[] = $bp->pages->forums->id;
    106103
    107104    /**
  • trunk/src/bp-core/bp-core-functions.php

    r11698 r11763  
    446446}
    447447
     448
     449/**
     450 * Return the parent forum ID for the Legacy Forums abstraction layer.
     451 *
     452 * @since 1.5.0
     453 * @since 3.0.0 Supported for compatibility with bbPress 2.
     454 *
     455 * @return int Forum ID.
     456 */
     457function bp_forums_parent_forum_id() {
     458
     459    /**
     460     * Filters the parent forum ID for the bbPress abstraction layer.
     461     *
     462     * @since 1.5.0
     463     *
     464     * @param int BP_FORUMS_PARENT_FORUM_ID The Parent forum ID constant.
     465     */
     466    return apply_filters( 'bp_forums_parent_forum_id', BP_FORUMS_PARENT_FORUM_ID );
     467}
     468
    448469/** Directory *****************************************************************/
    449470
     
    467488        'notifications',
    468489    );
    469 
    470     // Only add legacy forums if it is enabled
    471     // prevents conflicts with bbPress, which also uses the same 'forums' id.
    472     if ( class_exists( 'BP_Forums_Component' ) ) {
    473         $components[] = 'forums';
    474     }
    475490
    476491    return $components;
     
    17311746
    17321747/**
    1733  * Are oembeds allowed in forum posts?
    1734  *
    1735  * @since 1.5.0
    1736  *
    1737  * @return bool False when forum post embed support is disabled; true when
    1738  *              enabled. Default: true.
    1739  */
    1740 function bp_use_embed_in_forum_posts() {
    1741 
    1742     /**
    1743      * Filters whether or not oEmbeds are allowed in forum posts.
    1744      *
    1745      * @since 1.5.0
    1746      *
    1747      * @param bool $value Whether or not oEmbeds are allowed.
    1748      */
    1749     return apply_filters( 'bp_use_embed_in_forum_posts', !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) || !BP_EMBED_DISABLE_FORUM_POSTS );
    1750 }
    1751 
    1752 /**
    17531748 * Are oembeds allowed in private messages?
    17541749 *
     
    23562351                break;
    23572352
    2358             case 'forums':
    2359                 $slug = bp_is_active( 'forums' ) ? bp_get_forums_root_slug() : '';
    2360                 $query_string = '/?fs=';
    2361                 break;
    2362 
    23632353            case 'groups':
    23642354                $slug = bp_is_active( 'groups' ) ? bp_get_groups_root_slug() : '';
     
    24642454
    24652455    $retired_components = array(
    2466         'forums' => array(
    2467             'title'       => __( 'Group Forums', 'buddypress' ),
    2468             'description' => sprintf( __( 'BuddyPress Forums are retired. Use %s.', 'buddypress' ), '<a href="https://bbpress.org/">bbPress</a>' )
    2469         ),
    24702456    );
    24712457
     
    24982484            'title'       => __( 'User Groups', 'buddypress' ),
    24992485            'description' => __( 'Groups allow your users to organize themselves into specific public, private or hidden sections with separate activity streams and member listings.', 'buddypress' )
    2500         ),
    2501         'forums'   => array(
    2502             'title'       => __( 'Group Forums (Legacy)', 'buddypress' ),
    2503             'description' => __( 'Group forums allow for focused, bulletin-board style conversations.', 'buddypress' )
    25042486        ),
    25052487        'blogs'    => array(
  • trunk/src/bp-core/bp-core-options.php

    r11695 r11763  
    2929
    3030        'bp-deactivated-components'            => array(),
    31 
    32         /* bbPress ***********************************************************/
    33 
    34         // Legacy bbPress config location.
    35         'bb-config-location'                   => ABSPATH . 'bb-config.php',
    3631
    3732        /* XProfile **********************************************************/
     
    695690
    696691/**
    697  * Output the group forums root parent forum id.
    698  *
    699  * @since 1.6.0
    700  *
    701  * @param bool|string $default Optional. Default: '0'.
    702  */
    703 function bp_group_forums_root_id( $default = '0' ) {
    704     echo bp_get_group_forums_root_id( $default );
    705 }
    706     /**
    707      * Return the group forums root parent forum id.
    708      *
    709      * @since 1.6.0
    710      *
    711      * @param bool|string $default Optional. Default: '0'.
    712      * @return int The ID of the group forums root forum.
    713      */
    714     function bp_get_group_forums_root_id( $default = '0' ) {
    715 
    716         /**
    717          * Filters the group forums root parent forum id.
    718          *
    719          * @since 1.6.0
    720          *
    721          * @param int $value The group forums root parent forum id.
    722          */
    723         return (int) apply_filters( 'bp_get_group_forums_root_id', (int) bp_get_option( '_bp_group_forums_root_id', $default ) );
    724     }
    725 
    726 /**
    727  * Check whether BuddyPress Group Forums are enabled.
    728  *
    729  * @since 1.6.0
    730  *
    731  * @param bool $default Optional. Fallback value if not found in the database.
    732  *                      Default: true.
    733  * @return bool True if group forums are active, otherwise false.
    734  */
    735 function bp_is_group_forums_active( $default = true ) {
    736 
    737     /**
    738      * Filters whether or not BuddyPress Group Forums are enabled.
    739      *
    740      * @since 1.6.0
    741      *
    742      * @param bool $value Whether or not BuddyPress Group Forums are enabled.
    743      */
    744     return (bool) apply_filters( 'bp_is_group_forums_active', (bool) bp_get_option( '_bp_enable_group_forums', $default ) );
    745 }
    746 
    747 /**
    748692 * Check whether Akismet is enabled.
    749693 *
  • trunk/src/bp-core/bp-core-template.php

    r11605 r11763  
    549549    if ( bp_is_active( 'blogs' ) && is_multisite() ) {
    550550        $options['blogs']   = _x( 'Blogs', 'search form', 'buddypress' );
    551     }
    552 
    553     if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() && bp_forums_has_directory() ) {
    554         $options['forums']  = _x( 'Forums', 'search form', 'buddypress' );
    555551    }
    556552
     
    22002196 *
    22012197 * @since 1.5.0
     2198 * @since 3.0.0 Required for bbPress 2 integration.
    22022199 *
    22032200 * @return bool True if the current page is part of the Forums component.
     
    24742471
    24752472/**
    2476  * Is this a user's forums page?
    2477  *
    2478  * Eg http://example.com/members/joe/forums/ (or a subpage thereof).
    2479  *
    2480  * @since 1.5.0
    2481  *
    2482  * @return bool True if the current page is a user's forums page.
    2483  */
    2484 function bp_is_user_forums() {
    2485 
    2486     if ( ! bp_is_active( 'forums' ) ) {
    2487         return false;
    2488     }
    2489 
    2490     if ( bp_is_user() && bp_is_forums_component() ) {
    2491         return true;
    2492     }
    2493 
    2494     return false;
    2495 }
    2496 
    2497 /**
    2498  * Is this a user's "Topics Started" page?
    2499  *
    2500  * Eg http://example.com/members/joe/forums/topics/.
    2501  *
    2502  * @since 1.5.0
    2503  *
    2504  * @return bool True if the current page is a user's Topics Started page.
    2505  */
    2506 function bp_is_user_forums_started() {
    2507     return (bool) ( bp_is_user_forums() && bp_is_current_action( 'topics' ) );
    2508 }
    2509 
    2510 /**
    2511  * Is this a user's "Replied To" page?
    2512  *
    2513  * Eg http://example.com/members/joe/forums/replies/.
    2514  *
    2515  * @since 1.5.0
    2516  *
    2517  * @return bool True if the current page is a user's Replied To forums page.
    2518  */
    2519 function bp_is_user_forums_replied_to() {
    2520     return (bool) ( bp_is_user_forums() && bp_is_current_action( 'replies' ) );
    2521 }
    2522 
    2523 /**
    25242473 * Is the current page part of a user's Groups page?
    25252474 *
     
    27562705
    27572706/**
    2758  * Is the current page a group's forum page?
    2759  *
    2760  * Only applies to legacy bbPress forums.
    2761  *
    2762  * @since 1.1.0
    2763  *
    2764  * @return bool True if the current page is a group forum page.
    2765  */
    2766 function bp_is_group_forum() {
    2767     $retval = false;
    2768 
    2769     // At a forum URL.
    2770     if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) ) {
    2771         $retval = true;
    2772 
    2773         // If at a forum URL, set back to false if forums are inactive, or not
    2774         // installed correctly.
    2775         if ( ! bp_is_active( 'forums' ) || ! bp_forums_is_installed_correctly() ) {
    2776             $retval = false;
    2777         }
    2778     }
    2779 
    2780     return $retval;
    2781 }
    2782 
    2783 /**
    27842707 * Is the current page a group's activity page?
    27852708 *
     
    28052728 * Is the current page a group forum topic?
    28062729 *
    2807  * Only applies to legacy bbPress (1.x) forums.
    2808  *
    28092730 * @since 1.1.0
     2731 * @since 3.0.0 Required for bbPress 2 integration.
    28102732 *
    28112733 * @return bool True if the current page is part of a group forum topic.
     
    28182740 * Is the current page a group forum topic edit page?
    28192741 *
    2820  * Only applies to legacy bbPress (1.x) forums.
    2821  *
    28222742 * @since 1.2.0
     2743 * @since 3.0.0 Required for bbPress 2 integration.
    28232744 *
    28242745 * @return bool True if the current page is part of a group forum topic edit page.
     
    34153336        if ( bp_is_group_members() ) {
    34163337            $bp_classes[] = 'group-members';
    3417         }
    3418 
    3419         if ( bp_is_group_forum_topic() ) {
    3420             $bp_classes[] = 'group-forum-topic';
    3421         }
    3422 
    3423         if ( bp_is_group_forum_topic_edit() ) {
    3424             $bp_classes[] = 'group-forum-topic-edit';
    3425         }
    3426 
    3427         if ( bp_is_group_forum() ) {
    3428             $bp_classes[] = 'group-forum';
    34293338        }
    34303339
     
    35263435    } elseif ( bp_is_activation_page() ) {
    35273436        $bp_classes[] = 'bp_activate';
    3528 
    3529     } elseif ( bp_is_forums_component() && bp_is_directory() ) {
    3530         $bp_classes[] = 'bp_forum';
    35313437    }
    35323438
  • trunk/src/bp-core/classes/class-bp-admin.php

    r11648 r11763  
    442442                register_setting( 'buddypress', 'bp-disable-group-cover-image-uploads', 'intval' );
    443443            }
    444         }
    445 
    446         /* Forums ************************************************************/
    447 
    448         if ( bp_is_active( 'forums' ) ) {
    449 
    450             // Add the main section.
    451             add_settings_section( 'bp_forums', __( 'Legacy Group Forums', 'buddypress' ), 'bp_admin_setting_callback_bbpress_section', 'buddypress' );
    452 
    453             // Allow subscriptions setting.
    454             add_settings_field( 'bb-config-location', __( 'bbPress Configuration', 'buddypress' ), 'bp_admin_setting_callback_bbpress_configuration', 'buddypress', 'bp_forums' );
    455             register_setting( 'buddypress', 'bb-config-location', '' );
    456444        }
    457445
  • trunk/src/bp-core/classes/class-bp-core.php

    r11361 r11763  
    6666         * @param array $value Array of included and optional components.
    6767         */
    68         $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'forums', 'friends', 'groups', 'messages', 'notifications', 'settings', 'xprofile' ) );
     68        $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'friends', 'groups', 'messages', 'notifications', 'settings', 'xprofile' ) );
    6969
    7070        /**
  • trunk/src/bp-core/classes/class-bp-embed.php

    r10825 r11763  
    4444            add_filter( 'bp_get_activity_content', array( &$this, 'autoembed' ), 8 );
    4545            add_filter( 'bp_get_activity_content', array( &$this, 'run_shortcode' ), 7 );
    46         }
    47 
    48         if ( bp_use_embed_in_forum_posts() ) {
    49             add_filter( 'bp_get_the_topic_post_content', array( &$this, 'autoembed' ), 8 );
    50             add_filter( 'bp_get_the_topic_post_content', array( &$this, 'run_shortcode' ), 7 );
    5146        }
    5247
  • trunk/src/bp-core/deprecated/1.5.php

    r11447 r11763  
    398398    return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );
    399399}
    400 
    401 /**
    402  * In BP 1.5, these functions were renamed for greater consistency
    403  * @deprecated 1.5.0
    404  */
    405 function bp_forum_directory_permalink() {
    406     _deprecated_function( __FUNCTION__, '1.5', 'bp_forums_directory_permalink()' );
    407     bp_forums_directory_permalink();
    408 }
    409     function bp_get_forum_directory_permalink() {
    410         _deprecated_function( __FUNCTION__, '1.5', 'bp_get_forums_directory_permalink()' );
    411         return bp_get_forums_directory_permalink();
    412     }
    413400
    414401/**
  • trunk/src/bp-groups/bp-groups-actions.php

    r11761 r11763  
    195195            if ( !isset($_POST['group-show-forum']) ) {
    196196                $group_enable_forum = 0;
    197             } else {
    198                 // Create the forum if enable_forum = 1.
    199                 if ( bp_is_active( 'forums' ) && !groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
    200                     groups_new_group_forum();
    201                 }
    202197            }
    203198
  • trunk/src/bp-groups/bp-groups-activity.php

    r11557 r11763  
    5454        array( 'activity', 'group', 'member', 'member_groups' )
    5555    );
    56 
    57     // These actions are for the legacy forums
    58     // Since the bbPress plugin also shares the same 'forums' identifier, we also
    59     // check for the legacy forums loader class to be extra cautious.
    60     if ( bp_is_active( 'forums' ) && class_exists( 'BP_Forums_Component' ) ) {
    61         bp_activity_set_action(
    62             $bp->groups->id,
    63             'new_forum_topic',
    64             __( 'New group forum topic', 'buddypress' ),
    65             false,
    66             __( 'Forum Topics', 'buddypress' ),
    67             array( 'activity', 'group', 'member', 'member_groups' )
    68         );
    69 
    70         bp_activity_set_action(
    71             $bp->groups->id,
    72             'new_forum_post',
    73             __( 'New group forum post',  'buddypress' ),
    74             false,
    75             __( 'Forum Replies', 'buddypress' ),
    76             array( 'activity', 'group', 'member', 'member_groups' )
    77         );
    78     }
    7956
    8057    /**
     
    405382add_action( 'groups_leave_group',          'groups_update_last_activity' );
    406383add_action( 'groups_created_group',        'groups_update_last_activity' );
    407 add_action( 'groups_new_forum_topic',      'groups_update_last_activity' );
    408 add_action( 'groups_new_forum_topic_post', 'groups_update_last_activity' );
    409384
    410385/**
  • trunk/src/bp-groups/bp-groups-filters.php

    r11703 r11763  
    4545add_filter( 'bp_get_group_member_name',         'stripslashes' );
    4646add_filter( 'bp_get_group_member_link',         'stripslashes' );
    47 
    48 add_filter( 'groups_new_group_forum_desc', 'bp_create_excerpt' );
    4947
    5048add_filter( 'groups_group_name_before_save',        'force_balance_tags' );
     
    121119}
    122120
    123 /** Legacy group forums (bbPress 1.x) *****************************************/
    124 
    125 /**
    126  * Filter bbPress query SQL when on group pages or on forums directory.
    127  *
    128  * @since 1.1.0
    129  */
    130 function groups_add_forum_privacy_sql() {
    131     add_filter( 'get_topics_fields', 'groups_add_forum_fields_sql' );
    132     add_filter( 'get_topics_join',   'groups_add_forum_tables_sql' );
    133     add_filter( 'get_topics_where',  'groups_add_forum_where_sql'  );
    134 }
    135 add_filter( 'bbpress_init', 'groups_add_forum_privacy_sql' );
    136 
    137 /**
    138  * Add fields to bbPress query for group-specific data.
    139  *
    140  * @since 1.1.0
    141  *
    142  * @param string $sql SQL statement to amend.
    143  * @return string
    144  */
    145 function groups_add_forum_fields_sql( $sql = '' ) {
    146     $sql = 't.*, g.id as object_id, g.name as object_name, g.slug as object_slug';
    147     return $sql;
    148 }
    149 
    150 /**
    151  * Add JOINed tables to bbPress query for group-specific data.
    152  *
    153  * @since 1.1.0
    154  *
    155  * @param string $sql SQL statement to amend.
    156  * @return string
    157  */
    158 function groups_add_forum_tables_sql( $sql = '' ) {
    159     $bp = buddypress();
    160 
    161     $sql .= 'JOIN ' . $bp->groups->table_name . ' AS g LEFT JOIN ' . $bp->groups->table_name_groupmeta . ' AS gm ON g.id = gm.group_id ';
    162 
    163     return $sql;
    164 }
    165 
    166 /**
    167  * Add WHERE clauses to bbPress query for group-specific data and access protection.
    168  *
    169  * @since 1.1.0
    170  *
    171  * @param string $sql SQL Statement to amend.
    172  * @return string
    173  */
    174 function groups_add_forum_where_sql( $sql = '' ) {
    175 
    176     // Define locale variable.
    177     $parts = array();
    178 
    179     // Set this for groups.
    180     $parts['groups'] = "(gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id)";
    181 
    182     // Restrict to public...
    183     $parts['private'] = "g.status = 'public'";
    184 
    185     /**
    186      * ...but do some checks to possibly remove public restriction.
    187      *
    188      * Decide if private are visible
    189      */
    190 
    191     // Are we in our own profile?
    192     if ( bp_is_my_profile() )
    193         unset( $parts['private'] );
    194 
    195     // Are we a super admin?
    196     elseif ( bp_current_user_can( 'bp_moderate' ) )
    197         unset( $parts['private'] );
    198 
    199     // No need to filter on a single item.
    200     elseif ( bp_is_single_item() )
    201         unset( $parts['private'] );
    202 
    203     // Check the SQL filter that was passed.
    204     if ( !empty( $sql ) )
    205         $parts['passed'] = $sql;
    206 
    207     // Assemble Voltron.
    208     $parts_string = implode( ' AND ', $parts );
    209 
    210     $bp = buddypress();
    211 
    212     // Set it to the global filter.
    213     $bp->groups->filter_sql = $parts_string;
    214 
    215     // Return the global filter.
    216     return $bp->groups->filter_sql;
    217 }
    218 
    219 /**
    220  * Modify bbPress caps for bp-forums.
    221  *
    222  * @since 1.1.0
    223  *
    224  * @param bool   $value Original value for current_user_can check.
    225  * @param string $cap   Capability checked.
    226  * @param array  $args  Arguments for the caps.
    227  * @return bool
    228  */
    229 function groups_filter_bbpress_caps( $value, $cap, $args ) {
    230 
    231     if ( bp_current_user_can( 'bp_moderate' ) )
    232         return true;
    233 
    234     if ( 'add_tag_to' === $cap ) {
    235         $bp = buddypress();
    236 
    237         if ( $bp->groups->current_group->user_has_access ) {
    238             return true;
    239         }
    240     }
    241 
    242     if ( 'manage_forums' == $cap && is_user_logged_in() )
    243         return true;
    244 
    245     return $value;
    246 }
    247 add_filter( 'bb_current_user_can', 'groups_filter_bbpress_caps', 10, 3 );
    248 
    249 /**
    250  * Amends the forum directory's "last active" bbPress SQL query to stop it fetching information we aren't going to use.
    251  *
    252  * This speeds up the query.
    253  *
    254  * @since 1.5.0
    255  *
    256  * @see BB_Query::_filter_sql()
    257  *
    258  * @param string $sql SQL statement.
    259  * @return string
    260  */
    261 function groups_filter_forums_root_page_sql( $sql ) {
    262 
    263     /**
    264      * Filters the forum directory's "last active" bbPress SQL query.
    265      *
    266      * This filter is used to prevent fetching information that is not used.
    267      *
    268      * @since 1.5.0
    269      *
    270      * @param string $value SQL string to specify fetching just topic_id.
    271      */
    272     return apply_filters( 'groups_filter_bbpress_root_page_sql', 't.topic_id' );
    273 }
    274 add_filter( 'get_latest_topics_fields', 'groups_filter_forums_root_page_sql' );
    275 
    276121/**
    277122 * Should BuddyPress load the mentions scripts and related assets, including results to prime the
  • trunk/src/bp-groups/bp-groups-functions.php

    r11762 r11763  
    355355    if ( !$group->save() )
    356356        return false;
    357 
    358     // If forums have been enabled, and a forum does not yet exist, we need to create one.
    359     if ( $group->enable_forum ) {
    360         if ( bp_is_active( 'forums' ) && !groups_get_groupmeta( $group->id, 'forum_id' ) ) {
    361             groups_new_group_forum( $group->id, $group->name, $group->description );
    362         }
    363     }
    364357
    365358    // Set the invite status.
  • 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
  • trunk/src/bp-groups/bp-groups-template.php

    r11761 r11763  
    20252025
    20262026/**
    2027  * Output the URL of the Forum page of the current group in the loop.
    2028  *
    2029  * @since 1.0.0
    2030  */
    2031 function bp_group_forum_permalink() {
    2032     echo bp_get_group_forum_permalink();
    2033 }
    2034     /**
    2035      * Generate the URL of the Forum page of a group.
    2036      *
    2037      * @since 1.0.0
    2038      *
    2039      * @param object|bool $group Optional. Group object.
    2040      *                           Default: current group in loop.
    2041      * @return string
    2042      */
    2043     function bp_get_group_forum_permalink( $group = false ) {
    2044         global $groups_template;
    2045 
    2046         if ( empty( $group ) ) {
    2047             $group =& $groups_template->group;
    2048         }
    2049 
    2050         /**
    2051          * Filters the URL of the Forum page of a group.
    2052          *
    2053          * @since 1.0.0
    2054          * @since 2.5.0 Added the `$group` parameter.
    2055          *
    2056          * @param string $value URL permalink for the Forum Page.
    2057          * @param object $group Group object.
    2058          */
    2059         return apply_filters( 'bp_get_group_forum_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'forum' ), $group );
    2060     }
    2061 
    2062 /**
    2063  * Output the topic count for a group forum.
    2064  *
    2065  * @since 1.2.0
    2066  *
    2067  * @param array|string $args See {@link bp_get_group_forum_topic_count()}.
    2068  */
    2069 function bp_group_forum_topic_count( $args = '' ) {
    2070     echo bp_get_group_forum_topic_count( $args );
    2071 }
    2072     /**
    2073      * Generate the topic count string for a group forum.
    2074      *
    2075      * @since 1.2.0
    2076      *
    2077      * @param array|string $args {
    2078      *     Array of arguments.
    2079      *     @type bool $showtext Optional. If true, result will be formatted as "x topics".
    2080      *                          If false, just a number will be returned.
    2081      *                          Default: false.
    2082      * }
    2083      * @return string|int
    2084      */
    2085     function bp_get_group_forum_topic_count( $args = '' ) {
    2086         global $groups_template;
    2087 
    2088         $defaults = array(
    2089             'showtext' => false
    2090         );
    2091 
    2092         $r = wp_parse_args( $args, $defaults );
    2093         extract( $r, EXTR_SKIP );
    2094 
    2095         if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) ) {
    2096             return false;
    2097         }
    2098 
    2099         if ( !bp_is_active( 'forums' ) ) {
    2100             return false;
    2101         }
    2102 
    2103         if ( !$groups_template->group->forum_counts ) {
    2104             $groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id );
    2105         }
    2106 
    2107         if ( (bool) $showtext ) {
    2108             if ( 1 == (int) $groups_template->group->forum_counts[0]->topics ) {
    2109                 $total_topics = sprintf( __( '%d topic', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics );
    2110             } else {
    2111                 $total_topics = sprintf( __( '%d topics', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics );
    2112             }
    2113         } else {
    2114             $total_topics = (int) $groups_template->group->forum_counts[0]->topics;
    2115         }
    2116 
    2117         /**
    2118          * Filters the topic count string for a group forum.
    2119          *
    2120          * @since 1.2.0
    2121          *
    2122          * @param string $total_topics Total topic count string.
    2123          * @param bool   $showtext     Whether or not to return as formatted string.
    2124          */
    2125         return apply_filters( 'bp_get_group_forum_topic_count', $total_topics, (bool)$showtext );
    2126     }
    2127 
    2128 /**
    2129  * Output the post count for a group forum.
    2130  *
    2131  * @since 1.2.0
    2132  *
    2133  * @param array|string $args See {@link bp_get_group_forum_post_count()}.
    2134  */
    2135 function bp_group_forum_post_count( $args = '' ) {
    2136     echo bp_get_group_forum_post_count( $args );
    2137 }
    2138     /**
    2139      * Generate the post count string for a group forum.
    2140      *
    2141      * @since 1.2.0
    2142      *
    2143      * @param array|string $args {
    2144      *     Array of arguments.
    2145      *     @type bool $showtext Optional. If true, result will be formatted as "x posts".
    2146      *                          If false, just a number will be returned.
    2147      *                          Default: false.
    2148      * }
    2149      * @return string|int
    2150      */
    2151     function bp_get_group_forum_post_count( $args = '' ) {
    2152         global $groups_template;
    2153 
    2154         $defaults = array(
    2155             'showtext' => false
    2156         );
    2157 
    2158         $r = wp_parse_args( $args, $defaults );
    2159         extract( $r, EXTR_SKIP );
    2160 
    2161         if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) ) {
    2162             return false;
    2163         }
    2164 
    2165         if ( !bp_is_active( 'forums' ) ) {
    2166             return false;
    2167         }
    2168 
    2169         if ( !$groups_template->group->forum_counts ) {
    2170             $groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id );
    2171         }
    2172 
    2173         if ( (bool) $showtext ) {
    2174             if ( 1 == (int) $groups_template->group->forum_counts[0]->posts ) {
    2175                 $total_posts = sprintf( __( '%d post', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts );
    2176             } else {
    2177                 $total_posts = sprintf( __( '%d posts', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts );
    2178             }
    2179         } else {
    2180             $total_posts = (int) $groups_template->group->forum_counts[0]->posts;
    2181         }
    2182 
    2183         /**
    2184          * Filters the post count string for a group forum.
    2185          *
    2186          * @since 1.2.0
    2187          *
    2188          * @param string $total_posts Total post count string.
    2189          * @param bool   $showtext    Whether or not to return as formatted string.
    2190          */
    2191         return apply_filters( 'bp_get_group_forum_post_count', $total_posts, (bool)$showtext );
    2192     }
    2193 
    2194 /**
    21952027 * Determine whether forums are enabled for a group.
    21962028 *
     
    33813213    return true;
    33823214}
    3383 
    3384 /**
    3385  * Output a 'New Topic' button for a group.
    3386  *
    3387  * @since 1.2.7
    3388  *
    3389  * @param BP_Groups_Group|bool $group The BP Groups_Group object if passed,
    3390  *                                    boolean false if not passed.
    3391  */
    3392 function bp_group_new_topic_button( $group = false ) {
    3393     echo bp_get_group_new_topic_button( $group );
    3394 }
    3395 
    3396     /**
    3397      * Returns a 'New Topic' button for a group.
    3398      *
    3399      * @since 1.2.7
    3400      *
    3401      * @param BP_Groups_Group|bool $group The BP Groups_Group object if
    3402      *                                    passed, boolean false if not passed.
    3403      * @return false|string HTML code for the button.
    3404      */
    3405     function bp_get_group_new_topic_button( $group = false ) {
    3406         global $groups_template;
    3407 
    3408         if ( empty( $group ) ) {
    3409             $group =& $groups_template->group;
    3410         }
    3411 
    3412         if ( !is_user_logged_in() || bp_group_is_user_banned() || !bp_is_group_forum() || bp_is_group_forum_topic() ) {
    3413             return false;
    3414         }
    3415 
    3416         $button = array(
    3417             'id'                => 'new_topic',
    3418             'component'         => 'groups',
    3419             'must_be_logged_in' => true,
    3420             'block_self'        => true,
    3421             'wrapper_class'     => 'group-button',
    3422             'link_href'         => '#post-new',
    3423             'link_class'        => 'group-button show-hide-new',
    3424             'link_id'           => 'new-topic-button',
    3425             'link_text'         => __( 'New Topic', 'buddypress' ),
    3426         );
    3427 
    3428         /**
    3429          * Filters the HTML button for creating a new topic in a group.
    3430          *
    3431          * @since 1.5.0
    3432          * @since 2.5.0 Added the `$group` parameter.
    3433          *
    3434          * @param string $button HTML button for a new topic.
    3435          * @param object $group  Group object.
    3436          */
    3437         return bp_get_button( apply_filters( 'bp_get_group_new_topic_button', $button, $group ) );
    3438     }
    34393215
    34403216/**
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r11559 r11763  
    124124        $includes = array(
    125125            'cache',
    126             'forums',
    127126            'actions',
    128127            'filters',
  • trunk/src/bp-groups/classes/class-bp-groups-group.php

    r11762 r11763  
    7979
    8080    /**
    81      * Should (legacy) bbPress forums be enabled for this group?
    82      *
    83      * @since 1.6.0
     81     * Controls whether the group has a forum enabled.
     82     *
     83     * @since 1.6.0
     84     * @since 3.0.0 Previously, this referred to Legacy Forums. It's still used by bbPress 2 for integration.
     85     *
    8486     * @var int
    8587     */
     
    14571459
    14581460    /**
    1459      * Get a list of groups, sorted by those that have the most legacy forum topics.
     1461     * Convert the 'orderby' param into a proper SQL term/column.
     1462     *
     1463     * @since 1.8.0
     1464     *
     1465     * @param string $orderby Orderby term as passed to get().
     1466     * @return string $order_by_term SQL-friendly orderby term.
     1467     */
     1468    protected static function convert_orderby_to_order_by_term( $orderby ) {
     1469        $order_by_term = '';
     1470
     1471        switch ( $orderby ) {
     1472            case 'date_created' :
     1473            default :
     1474                $order_by_term = 'g.date_created';
     1475                break;
     1476
     1477            case 'last_activity' :
     1478                $order_by_term = 'gm_last_activity.meta_value';
     1479                break;
     1480
     1481            case 'total_member_count' :
     1482                $order_by_term = 'CONVERT(gm_total_member_count.meta_value, SIGNED)';
     1483                break;
     1484
     1485            case 'name' :
     1486                $order_by_term = 'g.name';
     1487                break;
     1488
     1489            case 'random' :
     1490                $order_by_term = 'rand()';
     1491                break;
     1492
     1493            case 'meta_id' :
     1494                $order_by_term = buddypress()->groups->table_name_groupmeta . '.id';
     1495                break;
     1496        }
     1497
     1498        return $order_by_term;
     1499    }
     1500
     1501    /**
     1502     * Get a list of groups whose names start with a given letter.
     1503     *
     1504     * @since 1.6.0
     1505     *
     1506     * @param string            $letter          The letter.
     1507     * @param int|null          $limit           Optional. The max number of results to return.
     1508     *                                           Default: null (no limit).
     1509     * @param int|null          $page            Optional. The page offset of results to return.
     1510     *                                           Default: null (no limit).
     1511     * @param bool              $populate_extras Deprecated.
     1512     * @param string|array|bool $exclude         Optional. Array or comma-separated list of group
     1513     *                                           IDs to exclude from results.
     1514     * @return false|array {
     1515     *     @type array $groups Array of group objects returned by the
     1516     *                         paginated query.
     1517     *     @type int   $total  Total count of all groups matching non-
     1518     *                         paginated query params.
     1519     * }
     1520     */
     1521    public static function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true, $exclude = false ) {
     1522        global $wpdb;
     1523
     1524        $pag_sql = $hidden_sql = $exclude_sql = '';
     1525
     1526        // Multibyte compliance.
     1527        if ( function_exists( 'mb_strlen' ) ) {
     1528            if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) {
     1529                return false;
     1530            }
     1531        } else {
     1532            if ( strlen( $letter ) > 1 || is_numeric( $letter ) || !$letter ) {
     1533                return false;
     1534            }
     1535        }
     1536
     1537        $args = array(
     1538            'per_page'       => $limit,
     1539            'page'           => $page,
     1540            'search_terms'   => $letter . '*',
     1541            'search_columns' => array( 'name' ),
     1542            'exclude'        => $exclude,
     1543        );
     1544
     1545        return BP_Groups_Group::get( $args );
     1546    }
     1547
     1548    /**
     1549     * Get a list of random groups.
     1550     *
     1551     * Use BP_Groups_Group::get() with 'type' = 'random' instead.
    14601552     *
    14611553     * @since 1.6.0
     
    14801572     * }
    14811573     */
    1482     public static function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
    1483         global $wpdb, $bbdb;
    1484 
    1485         if ( empty( $bbdb ) ) {
    1486 
    1487             /** This action is documented in bp-forums/bp-forums-screens */
    1488             do_action( 'bbpress_init' );
    1489         }
    1490 
    1491         if ( !empty( $limit ) && !empty( $page ) ) {
    1492             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    1493         }
    1494 
    1495         if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
    1496             $hidden_sql = " AND g.status != 'hidden'";
    1497 
    1498         if ( !empty( $search_terms ) ) {
    1499             $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%';
    1500             $search_sql        = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s ) ', $search_terms_like, $search_terms_like );
    1501         }
    1502 
    1503         if ( !empty( $exclude ) ) {
    1504             $exclude     = implode( ',', wp_parse_id_list( $exclude ) );
    1505             $exclude_sql = " AND g.id NOT IN ({$exclude})";
    1506         }
    1507 
    1508         $bp = buddypress();
    1509 
    1510         if ( !empty( $user_id ) ) {
    1511             $user_id      = absint( esc_sql( $user_id ) );
    1512             $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
    1513             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}" );
    1514         } else {
    1515             $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
    1516             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} {$exclude_sql}" );
    1517         }
    1518 
    1519         if ( !empty( $populate_extras ) ) {
    1520             foreach ( (array) $paged_groups as $group ) {
    1521                 $group_ids[] = $group->id;
    1522             }
    1523             $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
    1524         }
    1525 
    1526         return array( 'groups' => $paged_groups, 'total' => $total_groups );
    1527     }
    1528 
    1529     /**
    1530      * Convert the 'orderby' param into a proper SQL term/column.
    1531      *
    1532      * @since 1.8.0
    1533      *
    1534      * @param string $orderby Orderby term as passed to get().
    1535      * @return string $order_by_term SQL-friendly orderby term.
    1536      */
    1537     protected static function convert_orderby_to_order_by_term( $orderby ) {
    1538         $order_by_term = '';
    1539 
    1540         switch ( $orderby ) {
    1541             case 'date_created' :
    1542             default :
    1543                 $order_by_term = 'g.date_created';
    1544                 break;
    1545 
    1546             case 'last_activity' :
    1547                 $order_by_term = 'gm_last_activity.meta_value';
    1548                 break;
    1549 
    1550             case 'total_member_count' :
    1551                 $order_by_term = 'CONVERT(gm_total_member_count.meta_value, SIGNED)';
    1552                 break;
    1553 
    1554             case 'name' :
    1555                 $order_by_term = 'g.name';
    1556                 break;
    1557 
    1558             case 'random' :
    1559                 $order_by_term = 'rand()';
    1560                 break;
    1561 
    1562             case 'meta_id' :
    1563                 $order_by_term = buddypress()->groups->table_name_groupmeta . '.id';
    1564                 break;
    1565         }
    1566 
    1567         return $order_by_term;
    1568     }
    1569 
    1570     /**
    1571      * Get a list of groups, sorted by those that have the most legacy forum posts.
    1572      *
    1573      * @since 1.6.0
    1574      *
    1575      * @param int|null          $limit           Optional. The max number of results to return.
    1576      *                                           Default: null (no limit).
    1577      * @param int|null          $page            Optional. The page offset of results to return.
    1578      *                                           Default: null (no limit).
    1579      * @param string|bool       $search_terms    Optional. Limit groups to those whose name
    1580      *                                           or description field contain the search string.
    1581      * @param bool              $populate_extras Optional. Whether to fetch extra
    1582      *                                           information about the groups. Default: true.
    1583      * @param string|array|bool $exclude         Optional. Array or comma-separated list of group
    1584      *                                           IDs to exclude from results.
    1585      * @return array {
    1586      *     @type array $groups Array of group objects returned by the
    1587      *                         paginated query.
    1588      *     @type int   $total  Total count of all groups matching non-
    1589      *                         paginated query params.
    1590      * }
    1591      */
    1592     public static function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) {
    1593         global $wpdb, $bbdb;
    1594 
    1595         if ( empty( $bbdb ) ) {
    1596 
    1597             /** This action is documented in bp-forums/bp-forums-screens */
    1598             do_action( 'bbpress_init' );
    1599         }
    1600 
    1601         if ( !empty( $limit ) && !empty( $page ) ) {
    1602             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    1603         }
    1604 
    1605         if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
    1606             $hidden_sql = " AND g.status != 'hidden'";
    1607 
    1608         if ( !empty( $search_terms ) ) {
    1609             $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%';
    1610             $search_sql        = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s ) ', $search_terms_like, $search_terms_like );
    1611         }
    1612 
    1613         if ( !empty( $exclude ) ) {
    1614             $exclude     = implode( ',', wp_parse_id_list( $exclude ) );
    1615             $exclude_sql = " AND g.id NOT IN ({$exclude})";
    1616         }
    1617 
    1618         $bp = buddypress();
    1619 
    1620         if ( !empty( $user_id ) ) {
    1621             $user_id = esc_sql( $user_id );
    1622             $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
    1623             $total_groups = $wpdb->get_results( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.posts > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} " );
    1624         } else {
    1625             $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.posts > 0 {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
    1626             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql} {$exclude_sql}" );
    1627         }
    1628 
    1629         if ( !empty( $populate_extras ) ) {
    1630             foreach ( (array) $paged_groups as $group ) {
    1631                 $group_ids[] = $group->id;
    1632             }
    1633             $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
    1634         }
    1635 
    1636         return array( 'groups' => $paged_groups, 'total' => $total_groups );
    1637     }
    1638 
    1639     /**
    1640      * Get a list of groups whose names start with a given letter.
    1641      *
    1642      * @since 1.6.0
    1643      *
    1644      * @param string            $letter          The letter.
    1645      * @param int|null          $limit           Optional. The max number of results to return.
    1646      *                                           Default: null (no limit).
    1647      * @param int|null          $page            Optional. The page offset of results to return.
    1648      *                                           Default: null (no limit).
    1649      * @param bool              $populate_extras Deprecated.
    1650      * @param string|array|bool $exclude         Optional. Array or comma-separated list of group
    1651      *                                           IDs to exclude from results.
    1652      * @return false|array {
    1653      *     @type array $groups Array of group objects returned by the
    1654      *                         paginated query.
    1655      *     @type int   $total  Total count of all groups matching non-
    1656      *                         paginated query params.
    1657      * }
    1658      */
    1659     public static function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true, $exclude = false ) {
    1660         global $wpdb;
    1661 
    1662         $pag_sql = $hidden_sql = $exclude_sql = '';
    1663 
    1664         // Multibyte compliance.
    1665         if ( function_exists( 'mb_strlen' ) ) {
    1666             if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) {
    1667                 return false;
    1668             }
    1669         } else {
    1670             if ( strlen( $letter ) > 1 || is_numeric( $letter ) || !$letter ) {
    1671                 return false;
    1672             }
    1673         }
    1674 
    1675         $args = array(
    1676             'per_page'       => $limit,
    1677             'page'           => $page,
    1678             'search_terms'   => $letter . '*',
    1679             'search_columns' => array( 'name' ),
    1680             'exclude'        => $exclude,
    1681         );
    1682 
    1683         return BP_Groups_Group::get( $args );
    1684     }
    1685 
    1686     /**
    1687      * Get a list of random groups.
    1688      *
    1689      * Use BP_Groups_Group::get() with 'type' = 'random' instead.
    1690      *
    1691      * @since 1.6.0
    1692      *
    1693      * @param int|null          $limit           Optional. The max number of results to return.
    1694      *                                           Default: null (no limit).
    1695      * @param int|null          $page            Optional. The page offset of results to return.
    1696      *                                           Default: null (no limit).
    1697      * @param int               $user_id         Optional. If present, groups will be limited to
    1698      *                                           those of which the specified user is a member.
    1699      * @param string|bool       $search_terms    Optional. Limit groups to those whose name
    1700      *                                           or description field contain the search string.
    1701      * @param bool              $populate_extras Optional. Whether to fetch extra
    1702      *                                           information about the groups. Default: true.
    1703      * @param string|array|bool $exclude         Optional. Array or comma-separated list of group
    1704      *                                           IDs to exclude from results.
    1705      * @return array {
    1706      *     @type array $groups Array of group objects returned by the
    1707      *                         paginated query.
    1708      *     @type int   $total  Total count of all groups matching non-
    1709      *                         paginated query params.
    1710      * }
    1711      */
    17121574    public static function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
    17131575        $args = array(
     
    17941656
    17951657    /**
    1796      * Get global count of forum topics in public groups (legacy forums).
    1797      *
    1798      * @since 1.6.0
    1799      *
    1800      * @param string $type Optional. If 'unreplied', count will be limited to
    1801      *                     those topics that have received no replies.
    1802      * @return int Forum topic count.
    1803      */
    1804     public static function get_global_forum_topic_count( $type ) {
    1805         global $bbdb, $wpdb;
    1806 
    1807         $bp = buddypress();
    1808 
    1809         if ( 'unreplied' == $type )
    1810             $bp->groups->filter_sql = ' AND t.topic_posts = 1';
    1811 
    1812         /**
    1813          * Filters the portion of the SQL related to global count of forum topics in public groups.
    1814          *
    1815          * See https://buddypress.trac.wordpress.org/ticket/4306.
    1816          *
    1817          * @since 1.6.0
    1818          *
    1819          * @param string $filter_sql SQL portion for the query.
    1820          * @param string $type       Type of forum topics to query for.
    1821          */
    1822         $extra_sql = apply_filters( 'get_global_forum_topic_count_extra_sql', $bp->groups->filter_sql, $type );
    1823 
    1824         // Make sure the $extra_sql begins with an AND.
    1825         if ( 'AND' != substr( trim( strtoupper( $extra_sql ) ), 0, 3 ) )
    1826             $extra_sql = ' AND ' . $extra_sql;
    1827 
    1828         return $wpdb->get_var( "SELECT COUNT(t.topic_id) FROM {$bbdb->topics} AS t, {$bp->groups->table_name} AS g LEFT JOIN {$bp->groups->table_name_groupmeta} AS gm ON g.id = gm.group_id WHERE (gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id) AND g.status = 'public' AND t.topic_status = '0' AND t.topic_sticky != '2' {$extra_sql} " );
    1829     }
    1830 
    1831     /**
    18321658     * Get the member count for a group.
    18331659     *
     
    18431669
    18441670        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
    1845     }
    1846 
    1847     /**
    1848      * Get a total count of all topics of a given status, across groups/forums.
    1849      *
    1850      * @since 1.5.0
    1851      *
    1852      * @param string      $status       Which group type to count. 'public', 'private',
    1853      *                                  'hidden', or 'all'. Default: 'public'.
    1854      * @param string|bool $search_terms Provided search terms.
    1855      * @return int The topic count
    1856      */
    1857     public static function get_global_topic_count( $status = 'public', $search_terms = false ) {
    1858         global $bbdb, $wpdb;
    1859 
    1860         switch ( $status ) {
    1861             case 'all' :
    1862                 $status_sql = '';
    1863                 break;
    1864 
    1865             case 'hidden' :
    1866                 $status_sql = "AND g.status = 'hidden'";
    1867                 break;
    1868 
    1869             case 'private' :
    1870                 $status_sql = "AND g.status = 'private'";
    1871                 break;
    1872 
    1873             case 'public' :
    1874             default :
    1875                 $status_sql = "AND g.status = 'public'";
    1876                 break;
    1877         }
    1878 
    1879         $bp = buddypress();
    1880 
    1881         $sql = array();
    1882 
    1883         $sql['select'] = "SELECT COUNT(t.topic_id)";
    1884         $sql['from']   = "FROM {$bbdb->topics} AS t INNER JOIN {$bp->groups->table_name_groupmeta} AS gm ON t.forum_id = gm.meta_value INNER JOIN {$bp->groups->table_name} AS g ON gm.group_id = g.id";
    1885         $sql['where']  = "WHERE gm.meta_key = 'forum_id' {$status_sql} AND t.topic_status = '0' AND t.topic_sticky != '2'";
    1886 
    1887         if ( !empty( $search_terms ) ) {
    1888             $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%';
    1889             $sql['where'] .= $wpdb->prepare( " AND ( t.topic_title LIKE %s )", $search_terms_like );
    1890         }
    1891 
    1892         return $wpdb->get_var( implode( ' ', $sql ) );
    18931671    }
    18941672
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/create.php

    r11591 r11763  
    194194                    <h4><?php _e( 'Group Forums', 'buddypress' ); ?></h4>
    195195
    196                     <?php if ( bp_forums_is_installed_correctly() ) : ?>
    197 
    198                         <p><?php _e( 'Should this group have a forum?', 'buddypress' ); ?></p>
    199 
    200                         <div class="checkbox">
    201                             <label for="group-show-forum"><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php checked( bp_get_new_group_enable_forum(), true, true ); ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?></label>
    202                         </div>
    203                     <?php elseif ( is_super_admin() ) : ?>
    204 
    205                         <p><?php printf( __( '<strong>Attention Site Admin:</strong> Group forums require the <a href="%s">correct setup and configuration</a> of a bbPress installation.', 'buddypress' ), bp_core_do_network_admin() ? network_admin_url( 'settings.php?page=bb-forums-setup' ) :  admin_url( 'admin.php?page=bb-forums-setup' ) ); ?></p>
    206 
    207                     <?php endif; ?>
     196                    <p><?php _e( 'Should this group have a forum?', 'buddypress' ); ?></p>
     197
     198                    <div class="checkbox">
     199                        <label for="group-show-forum"><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php checked( bp_get_new_group_enable_forum(), true, true ); ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?></label>
     200                    </div>
    208201
    209202                <?php endif; ?>
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/single/admin/group-settings.php

    r11591 r11763  
    2222<?php if ( bp_is_active( 'forums' ) ) : ?>
    2323
    24     <?php if ( bp_forums_is_installed_correctly() ) : ?>
     24    <div class="checkbox">
     25        <label for="group-show-forum"><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php bp_group_show_forum_setting(); ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?></label>
     26    </div>
    2527
    26         <div class="checkbox">
    27             <label for="group-show-forum"><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php bp_group_show_forum_setting(); ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?></label>
    28         </div>
    29 
    30         <hr />
    31 
    32     <?php endif; ?>
     28    <hr />
    3329
    3430<?php endif; ?>
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/single/home.php

    r11128 r11763  
    120120                elseif ( bp_is_group_invites()    ) : bp_get_template_part( 'groups/single/send-invites' );
    121121
    122                 // Old group forums
    123                 elseif ( bp_is_group_forum()      ) : bp_get_template_part( 'groups/single/forum'        );
    124 
    125122                // Membership request
    126123                elseif ( bp_is_group_membership_request() ) : bp_get_template_part( 'groups/single/request-membership' );
  • trunk/src/bp-templates/bp-legacy/buddypress/members/single/home.php

    r11128 r11763  
    8686            bp_get_template_part( 'members/single/profile'  );
    8787
    88         elseif ( bp_is_user_forums() ) :
    89             bp_get_template_part( 'members/single/forums'   );
    90 
    9188        elseif ( bp_is_user_notifications() ) :
    9289            bp_get_template_part( 'members/single/notifications' );
  • trunk/src/bp-templates/bp-legacy/js/buddypress.js

    r11619 r11763  
    1313    /**** Page Load Actions *******************************************************/
    1414
    15     /* Hide Forums Post Form */
    16     if ( '-1' === window.location.search.indexOf('new') && jq('div.forums').length ) {
    17         jq('#new-topic-post').hide();
    18     } else {
    19         jq('#new-topic-post').show();
    20     }
    21 
    2215    /* Activity filter and scope set */
    2316    bp_init_activity();
    2417
    25     var objects  = [ 'members', 'groups', 'blogs', 'forums', 'group_members' ],
     18    var objects  = [ 'members', 'groups', 'blogs', 'group_members' ],
    2619        $whats_new = jq('#whats-new');
    2720
     
    10451038        }
    10461039
    1047     });
    1048 
    1049     /**** New Forum Directory Post **************************************/
    1050 
    1051     /* Hit the "New Topic" button on the forums directory page */
    1052     jq('a.show-hide-new').on( 'click', function() {
    1053         if ( !jq('#new-topic-post').length ) {
    1054             return false;
    1055         }
    1056 
    1057         if ( jq('#new-topic-post').is(':visible') ) {
    1058             jq('#new-topic-post').slideUp(200);
    1059         } else {
    1060             jq('#new-topic-post').slideDown(200, function() {
    1061                 jq('#topic_title').focus();
    1062             } );
    1063         }
    1064 
    1065         return false;
    1066     });
    1067 
    1068     /* Cancel the posting of a new forum topic */
    1069     jq('#submit_topic_cancel').on( 'click', function() {
    1070         if ( !jq('#new-topic-post').length ) {
    1071             return false;
    1072         }
    1073 
    1074         jq('#new-topic-post').slideUp(200);
    1075         return false;
    1076     });
    1077 
    1078     /* Clicking a forum tag */
    1079     jq('#forum-directory-tags a').on( 'click', function() {
    1080         bp_filter_request( 'forums', 'tags', jq.cookie('bp-forums-scope'), 'div.forums', jq(this).html().replace( /&nbsp;/g, '-' ), 1, jq.cookie('bp-forums-extras') );
    1081         return false;
    10821040    });
    10831041
  • trunk/src/class-buddypress.php

    r11717 r11763  
    234234        if ( ! defined( 'BP_PLUGIN_URL' ) ) {
    235235            define( 'BP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
     236        }
     237
     238        // Legacy forum constant - supported for compatibility with bbPress 2.
     239        if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
     240            define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
     241        }
     242
     243        // Legacy forum constant - supported for compatibility with bbPress 2.
     244        if ( ! defined( 'BP_FORUMS_SLUG' ) ) {
     245            define( 'BP_FORUMS_SLUG', 'forums' );
    236246        }
    237247
  • trunk/src/readme.txt

    r11745 r11763  
    11=== BuddyPress ===
    22Contributors: johnjamesjacoby, DJPaul, boonebgorges, r-a-y, imath, mercime, tw2113, dcavins, hnla
    3 Tags: social networking, activity, profiles, messaging, friends, groups, forums, notifications, settings, social, community, networks, networking
     3Tags: social networking, activity, profiles, messaging, friends, groups, notifications, settings, social, community, networks, networking
    44Requires at least: 4.5
    55Tested up to: 4.9
  • trunk/tests/phpunit/testcases/admin/functions.php

    r11737 r11763  
    8484        $this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted2 ), array( 'activity' => 1, 'groups' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) );
    8585
    86         // Activating from the Retired screen
    87         $_GET['action'] = 'retired';
    88         buddypress()->active_components = array(
    89             'activity' => 1,
    90             'members' => 1,
    91             'messages' => 1,
    92             'settings' => 1,
    93             'xprofile' => 1,
    94         );
    95 
    96         $submitted3 = array(
    97             'forums' => 1,
    98         );
    99 
    100         $this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted3 ), array( 'activity' => 1, 'forums' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) );
    101 
    10286        // Deactivating from the Retired screen
    10387        $_GET['action'] = 'retired';
    10488        buddypress()->active_components = array(
    10589            'activity' => 1,
    106             'forums' => 1,
    10790            'members' => 1,
    10891            'messages' => 1,
Note: See TracChangeset for help on using the changeset viewer.