Skip to:
Content

bbPress.org

Changeset 4266


Ignore:
Timestamp:
10/26/2012 06:19:01 AM (14 years ago)
Author:
johnjamesjacoby
Message:

BuddyPress:

  • Remove advanced group forum admin UI; go with feature parity of existing bbPress 1.1 installations for a v1.
  • Remove support for multiple forums/groups combinations. Assume the first item in the array is the only one.
  • Adds some canonical redirection to group forum content.
  • Maps forum content links to group forums when needed.
  • Add support for editing of topics and replies within group forums.
  • Some more to do here, but closing in on completeness.
  • Huge props jmdodd,
  • Fixes #1906.
  • See #1669.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/extend/buddypress.php

    r4249 r4266  
    174174                        add_action( 'wp_insert_post',                    array( $this, 'topic_update'              ), 10, 2 );
    175175                        add_action( 'wp_insert_post',                    array( $this, 'reply_update'              ), 10, 2 );
    176  
     176
    177177                        // Hook into topic and reply deletion
    178178                        add_action( 'bbp_delete_topic',                  array( $this, 'topic_delete'              ), 10, 1 );
     
    227227                add_filter( 'bbp_get_subscriptions_permalink', array( $this, 'get_subscriptions_permalink' ), 10, 2 );
    228228
     229                /** Links and pagination **********************************************/
     230
    229231                // Map forum/topic/replys permalinks to their groups
    230232                add_filter( 'bbp_get_forum_permalink', array( $this, 'map_forum_permalink_to_group' ), 10, 2 );
     
    232234                add_filter( 'bbp_get_reply_permalink', array( $this, 'map_reply_permalink_to_group' ), 10, 2 );
    233235
     236                // Map reply edit links to their groups
     237                add_filter( 'bbp_get_reply_edit_url',  array( $this, 'map_reply_edit_url_to_group'  ), 10, 2 );
     238
     239                // Map assorted template function permalinks
     240                add_filter( 'post_link',               array( $this, 'post_link'                    ), 10, 2 );
     241                add_filter( 'page_link',               array( $this, 'page_link'                    ), 10, 2 );
     242                add_filter( 'post_type_link',          array( $this, 'post_type_link'               ), 10, 2 );
     243
    234244                // Canonical redirects for normal URLs
    235245                add_action( 'template_redirect', array( $this, 'redirect_canonical' ) );
     246
     247                // Group forum pagination
     248                add_filter( 'bbp_topic_pagination',   array( $this, 'topic_pagination'   ) );
     249                add_filter( 'bbp_replies_pagination', array( $this, 'replies_pagination' ) );
    236250
    237251                /** Mentions **********************************************************/
     
    383397                // Bail if no activity ID is in post meta
    384398                if ( empty( $activity_id ) )
    385                         return false;
     399                        return null;
    386400
    387401                // Get the activity stream item, bail if it doesn't exist
    388402                $existing = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) );
    389403                if ( empty( $existing['total'] ) || ( 1 != $existing['total'] ) )
    390                         return false;
     404                        return null;
    391405
    392406                // Return the activity ID since we've verified the connection
     
    607621                // Compile the activity stream results
    608622                $activity = array(
     623                        'id'                => $this->get_activity_id( $topic_id ),
    609624                        'user_id'           => $user_id,
    610625                        'action'            => $activity_action,
     
    617632                );
    618633
    619                 // Check for existing activity entry ID
    620                 $activity_id = $this->get_activity_id( $topic_id );
    621                 if ( ! empty( $activity_id ) )
    622                         $activity['id'] = $activity_id;
    623 
    624634                // Record the activity
    625635                $activity_id = $this->record_activity( $activity );
     
    640650
    641651                // Get activity ID, bail if it doesn't exist
    642                 $activity_id = $this->get_activity_id( $topic_id );
    643                 if ( empty( $activity_id ) )
    644                         return false;
    645 
    646                 return bp_activity_delete( array( 'id' => $activity_id ) );
     652                if ( $activity_id = $this->get_activity_id( $topic_id ) )
     653                        return bp_activity_delete( array( 'id' => $activity_id ) );
     654
     655                return false;           
    647656        }
    648657
     
    680689
    681690                        // Validate topic data
    682                         $forum_id = bbp_get_topic_forum_id( $topic_id );
     691                        $forum_id        = bbp_get_topic_forum_id( $topic_id );
    683692                        $topic_author_id = bbp_get_topic_author_id( $topic_id );
    684693
     
    765774                // Compile the activity stream results
    766775                $activity = array(
     776                        'id'                => $this->get_activity_id( $reply_id ),
    767777                        'user_id'           => $user_id,
    768778                        'action'            => $activity_action,
     
    772782                        'item_id'           => $reply_id,
    773783                        'secondary_item_id' => $topic_id,
    774                         'recorded_time'     => get_post_time( 'Y-m-d H:i:s', true, $reply_id ),
     784                        'recorded_time'     => get_post_time( 'Y-m-d H:i:s', true, $reply_id ),
    775785                );
    776 
    777                 // Check for existing activity entry ID
    778                 $activity_id = $this->get_activity_id( $reply_id );
    779                 if ( ! empty( $activity_id ) )
    780                         $activity['id'] = $activity_id;
    781786
    782787                // Record the activity
     
    799804
    800805                // Get activity ID, bail if it doesn't exist
    801                 $activity_id = $this->get_activity_id( $reply_id );
    802                 if ( empty( $activity_id ) )
    803                         return false;
    804 
    805                 return bp_activity_delete( array( 'id' => $activity_id ) );
    806         }
    807 
    808         /**
    809          * Update the activity stream entry when a reply status changes
     806                if ( $activity_id = $this->get_activity_id( $reply_id ) )
     807                        return bp_activity_delete( array( 'id' => $activity_id ) );
     808
     809                return false;           
     810        }
     811
     812        /**
     813         * Update the activity stream entry when a reply status changes
    810814         *
    811815         * @param int $post_id
     
    840844
    841845                        // Validate reply data
    842                         $topic_id = bbp_get_reply_topic_id( $reply_id );
    843                         $forum_id = bbp_get_reply_forum_id( $reply_id );
     846                        $topic_id        = bbp_get_reply_topic_id( $reply_id );
     847                        $forum_id        = bbp_get_reply_forum_id( $reply_id );
    844848                        $reply_author_id = bbp_get_reply_author_id( $reply_id );
    845849
     
    850854        }
    851855
    852         /**
    853          * Map a forum permalink to the corresponding group
     856        /** Permalink Mappers *****************************************************/
     857
     858        /**
     859         * Maybe map a bbPress forum/topic/reply permalink to the corresponding group
     860         *
     861         * @param int $post_id
     862         * @uses get_post()
     863         * @uses bbp_is_reply()
     864         * @uses bbp_get_reply_topic_id()
     865         * @uses bbp_get_reply_forum_id()
     866         * @uses bbp_is_topic()
     867         * @uses bbp_get_topic_forum_id()
     868         * @uses bbp_is_forum()
     869         * @uses get_post_field()
     870         * @uses bbp_get_forum_group_ids()
     871         * @uses groups_get_group()
     872         * @uses bp_get_group_admin_permalink()
     873         * @uses bp_get_group_permalink()
     874         * @return Bail early if not a group forum post
     875         * @return string
     876         */
     877        private function maybe_map_permalink_to_group( $post_id = 0, $url = false ) {
     878
     879                switch ( get_post_type( $post_id ) ) {
     880
     881                        // Reply
     882                        case bbp_get_reply_post_type() :
     883                                $topic_id = bbp_get_reply_topic_id( $post_id );
     884                                $forum_id = bbp_get_reply_forum_id( $post_id );
     885                                $url_end  = trailingslashit( $this->reply_slug ) . get_post_field( 'post_name', $post_id );
     886                                break;
     887
     888                        // Topic
     889                        case bbp_get_topic_post_type() :
     890                                $topic_id = $post_id;
     891                                $forum_id = bbp_get_topic_forum_id( $post_id );
     892                                $url_end  = trailingslashit( $this->topic_slug ) . get_post_field( 'post_name', $post_id );
     893                                break;
     894
     895                        // Forum
     896                        case bbp_get_forum_post_type() :
     897                                $forum_id = $post_id;
     898                                $url_end  = get_post_field( 'post_name', $post_id );
     899                                break;
     900
     901                        // Unknown
     902                        default :
     903                                return $url;
     904                                break;
     905                }
     906               
     907                // Get group ID's for this forum
     908                $group_ids = bbp_get_forum_group_ids( $forum_id );
     909
     910                // Bail if the post isn't associated with a group
     911                if ( empty( $group_ids ) )
     912                        return $url;
     913
     914                // @todo Multiple group forums/forum groups
     915                $group_id = $group_ids[0];
     916                $group    = groups_get_group( array( 'group_id' => $group_id ) );
     917
     918                if ( bp_is_group_admin_screen( $this->forums_slug ) ) {
     919                        $group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) );
     920                } else {
     921                        $group_permalink = trailingslashit( bp_get_group_permalink( $group ) );
     922                }
     923
     924                return trailingslashit( trailingslashit( $group_permalink . $this->forums_slug ) . $url_end );
     925        }
     926
     927        /**
     928         * Map a forum permalink to its corresponding group
    854929         *
    855930         * @since bbPress (r3802)
    856931         * @param string $url
    857932         * @param int $forum_id
     933         * @uses maybe_map_permalink_to_group()
    858934         * @return string
    859935         */
    860936        public function map_forum_permalink_to_group( $url, $forum_id ) {
    861                 $slug      = get_post_field( 'post_name', $forum_id );
    862                 $group_ids = bbp_get_forum_group_ids( $forum_id );
    863 
    864                 // If the topic is not associated with a group, don't mess with it
    865                 if ( !empty( $group_ids ) ) {
    866 
    867                         // @todo Multiple group forums/forum groups
    868                         $group_id = $group_ids[0];
    869                         $group    = groups_get_group( array( 'group_id' => $group_id ) );
    870 
    871                         if ( bp_is_group_admin_screen( $this->forums_slug ) ) {
    872                                 $group_permalink = bp_get_group_admin_permalink( $group );
    873                         } else {
    874                                 $group_permalink = bp_get_group_permalink( $group );
    875                         }
    876 
    877                         $url = trailingslashit( $group_permalink . $this->forums_slug . '/' . $slug );
    878                 }
    879 
    880                 return $url;
    881         }
    882 
    883         /**
    884          * Map a topic permalink to the current group forum
     937                return $this->maybe_map_permalink_to_group( $forum_id, $url );
     938        }
     939
     940        /**
     941         * Map a topic permalink to its group forum
    885942         *
    886943         * @since bbPress (r3802)
    887944         * @param string $url
    888945         * @param int $topic_id
     946         * @uses maybe_map_permalink_to_group()
    889947         * @return string
    890948         */
    891949        public function map_topic_permalink_to_group( $url, $topic_id ) {
    892                 $slug      = get_post_field( 'post_name', $topic_id );
    893                 $forum_id  = bbp_get_topic_forum_id( $topic_id );
    894                 $group_ids = bbp_get_forum_group_ids( $forum_id );
    895 
    896                 // If the topic is not associated with a group, don't mess with it
    897                 if ( !empty( $group_ids ) ) {
    898 
    899                         // @todo Multiple group forums/forum groups
    900                         $group_id = $group_ids[0];
    901                         $group    = groups_get_group( array( 'group_id' => $group_id ) );
    902 
    903                         if ( bp_is_group_admin_screen( $this->forums_slug ) ) {
    904                                 $group_permalink = bp_get_group_admin_permalink( $group );
    905                         } else {
    906                                 $group_permalink = bp_get_group_permalink( $group );
    907                         }
    908 
    909                         $url = trailingslashit( $group_permalink . $this->forums_slug . '/' . $this->topic_slug . '/' . $slug );
    910                 }
    911 
    912                 return $url;
    913         }
    914 
    915         /**
    916          * Map a topic permalink to the current group forum
     950                return $this->maybe_map_permalink_to_group( $topic_id, $url );
     951        }
     952
     953        /**
     954         * Map a reply permalink to its group forum
    917955         *
    918956         * @since bbPress (r3802)
    919957         * @param string $url
    920958         * @param int $reply_id
     959         * @uses maybe_map_permalink_to_group()
    921960         * @return string
    922961         */
    923962        public function map_reply_permalink_to_group( $url, $reply_id ) {
    924                 $slug      = get_post_field( 'post_name', $reply_id );
    925                 $forum_id  = bbp_get_reply_forum_id( $reply_id );
    926                 $group_ids = bbp_get_forum_group_ids( $forum_id );
    927 
    928                 // If the topic is not associated with a group, don't mess with it
    929                 if ( !empty( $group_ids ) ) {
    930 
    931                         // @todo Multiple group forums/forum groups
    932                         $group_id = $group_ids[0];
    933                         $group    = groups_get_group( array( 'group_id' => $group_id ) );
    934 
    935                         if ( bp_is_group_admin_screen( $this->forums_slug ) ) {
    936                                 $group_permalink = bp_get_group_admin_permalink( $group );
    937                         } else {
    938                                 $group_permalink = bp_get_group_permalink( $group );
    939                         }
    940 
    941                         $url = trailingslashit( $group_permalink . $this->forums_slug . '/' . $this->topic_slug . '/' . $slug );
    942                 }
    943 
    944                 return $url;
     963                return $this->maybe_map_permalink_to_group( bbp_get_reply_topic_id( $reply_id ), $url );
     964        }
     965
     966        /**
     967         * Map a reply edit link to its group forum
     968         *
     969         * @param string $url
     970         * @param int $reply_id
     971         * @uses maybe_map_permalink_to_group()
     972         * @return string
     973         */
     974        public function map_reply_edit_url_to_group( $url, $reply_id ) {
     975                $new = $this->maybe_map_permalink_to_group( $reply_id );
     976
     977                if ( empty( $new ) )
     978                        return $url;
     979
     980                return trailingslashit( $new ) . bbpress()->edit_id  . '/';
     981        }
     982
     983        /**
     984         * Map a post link to its group forum
     985         *
     986         * @param string $url
     987         * @param obj $post
     988         * @param boolean $leavename
     989         * @uses maybe_map_permalink_to_group()
     990         * @return string
     991         */
     992        public function post_link( $url, $post ) {
     993                return $this->maybe_map_permalink_to_group( $post->ID, $url );
     994        }
     995
     996        /**
     997         * Map a page link to its group forum
     998         *
     999         * @param string $url
     1000         * @param int $post_id
     1001         * @param $sample
     1002         * @uses maybe_map_permalink_to_group()
     1003         * @return string
     1004         */
     1005        public function page_link( $url, $post_id ) {
     1006                return $this->maybe_map_permalink_to_group( $post_id, $url );
     1007        }
     1008
     1009        /**
     1010         * Map a custom post type link to its group forum
     1011         *
     1012         * @param string $url
     1013         * @param obj $post
     1014         * @param $leavename
     1015         * @param $sample
     1016         * @uses maybe_map_permalink_to_group()
     1017         * @return string
     1018         */
     1019        public function post_type_link( $url, $post ) {
     1020                return $this->maybe_map_permalink_to_group( $post->ID, $url );
     1021        }
     1022
     1023        /**
     1024         * Fix pagination of topics on forum view
     1025         *
     1026         * @param array $args
     1027         * @global $wp_rewrite
     1028         * @uses bbp_get_forum_id()
     1029         * @uses maybe_map_permalink_to_group
     1030         * @return array
     1031         */
     1032        public function topic_pagination( $args ) {
     1033                $new = $this->maybe_map_permalink_to_group( bbp_get_forum_id() );
     1034
     1035                if ( empty( $new ) )
     1036                        return $args;
     1037
     1038                global $wp_rewrite;
     1039
     1040                $args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/';
     1041
     1042                return $args;
     1043        }
     1044
     1045        /**
     1046         * Fix pagination of replies on topic view
     1047         *
     1048         * @param array $args
     1049         * @global $wp_rewrite
     1050         * @uses bbp_get_topic_id()
     1051         * @uses maybe_map_permalink_to_group
     1052         * @return array
     1053         */
     1054        public function replies_pagination( $args ) {
     1055                $new = $this->maybe_map_permalink_to_group( bbp_get_topic_id() );
     1056                if ( empty( $new ) )
     1057                        return $args;
     1058
     1059                global $wp_rewrite;
     1060
     1061                $args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/';
     1062
     1063                return $args;
    9451064        }
    9461065
     
    9531072        function redirect_canonical() {
    9541073
     1074                // Viewing a single forum
    9551075                if ( bbp_is_single_forum() ) {
    9561076                        $forum_id  = get_the_ID();
    9571077                        $group_ids = bbp_get_forum_group_ids( $forum_id );
     1078
     1079                // Viewing a single topic
    9581080                } elseif ( bbp_is_single_topic() ) {
    9591081                        $topic_id  = get_the_ID();
     
    9611083                        $forum_id  = bbp_get_topic_forum_id( $topic_id );
    9621084                        $group_ids = bbp_get_forum_group_ids( $forum_id );
     1085
     1086                // Not a forum or topic
     1087                } else {
     1088                        return;
    9631089                }
    9641090
    965                 if ( !empty( $group_ids ) ) {
    966                         // @todo Multiple group forums/forum groups
    967                         $group_id            = $group_ids[0];
    968                         $group               = groups_get_group( array( 'group_id' => $group_id ) );
    969                         $group_permalink = bp_get_group_permalink( $group );
    970                         $redirect_to     = trailingslashit( $group_permalink . $this->forums_slug );
    971 
    972                         if ( !empty( $slug ) ) {
    973                                 $redirect_to  = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug );
    974                         }
    975 
    976                         bp_core_redirect( $redirect_to );
     1091                // Bail if not a group forum
     1092                if ( empty( $group_ids ) )
     1093                        return;
     1094
     1095                // Use the first group ID
     1096                $group_id        = $group_ids[0];
     1097                $group           = groups_get_group( array( 'group_id' => $group_id ) );
     1098                $group_link  = trailingslashit( bp_get_group_permalink( $group ) );
     1099                $redirect_to = trailingslashit( $group_link . $this->forums_slug );
     1100
     1101                // Add topic slug to URL
     1102                if ( bbp_is_single_topic() ) {
     1103                        $redirect_to  = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug );
    9771104                }
     1105
     1106                bp_core_redirect( $redirect_to );
    9781107        }
    9791108}
     
    13021431        public function edit_screen() {
    13031432
    1304                 // Add group admin actions to forum row actions
    1305                 add_action( 'bbp_forum_row_actions', array( $this, 'forum_row_actions' ) );
    1306                 add_action( 'bbp_topic_row_actions', array( $this, 'topic_row_actions' ) );
    1307 
    1308                 // Prevent Topic Parent from appearing
    1309                 add_action( 'bbp_theme_before_topic_form_forum', array( $this, 'ob_start'     ) );
    1310                 add_action( 'bbp_theme_after_topic_form_forum',  array( $this, 'ob_end_clean' ) );
    1311                 add_action( 'bbp_theme_after_topic_form_forum',  array( $this, 'topic_parent' ) );
    1312 
    1313                 // Prevent Forum Parent from appearing
    1314                 add_action( 'bbp_theme_before_forum_form_parent', array( $this, 'ob_start'     ) );
    1315                 add_action( 'bbp_theme_after_forum_form_parent',  array( $this, 'ob_end_clean' ) );
    1316                 add_action( 'bbp_theme_after_forum_form_parent',  array( $this, 'forum_parent' ) );
    1317 
    1318                 // Do not show the new topic form in the moderation area
    1319                 add_filter( 'bbp_current_user_can_access_create_topic_form', '__return_false' );
    1320 
    1321                 // Hide breadcrumb
    1322                 add_filter( 'bbp_no_breadcrumb', '__return_true' );
    1323 
    1324                 $this->display_forums( 1 );
     1433                $checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( bp_get_current_group_id(), 'forum_id' ); ?>
     1434
     1435                <h4><?php _e( 'Enable Group Forum', 'bbpress' ); ?></h4>
     1436
     1437                <p><?php _e( 'Create a discussion forum to allow members of this group to communicate in a structured, bulletin-board style fashion.', 'bbpress' ); ?></p>
     1438
     1439                <div class="checkbox">
     1440                        <label><input type="checkbox" name="bbp-create-group-forum" id="bbp-create-group-forum" value="1"<?php checked( $checked ); ?> /> <?php _e( 'Yes. I want this group to have a forum.', 'bbpress' ); ?></label>
     1441                </div>
     1442
     1443                <p class="description"><?php _e( 'Saying no will not delete existing forum content.', 'bbpress' ); ?></p>
     1444
     1445                <input type="submit" value="<?php _e( 'Save Settings', 'bbpress' ); ?>" />
     1446
     1447                <?php
     1448
     1449                // Verify intent
     1450                wp_nonce_field( 'groups_edit_save_' . $this->slug );
    13251451        }
    13261452
     
    13421468                        return;
    13431469
    1344                 // Handle the different actions that can happen here
    1345                 switch ( $_POST['action'] ) {
    1346 
    1347                         // New forum
    1348                         case 'bbp-new-forum' :
    1349 
    1350                                 // Redirect back here, not to the new forum
    1351                                 add_filter( 'bbp_new_forum_redirect_to',   array( $this, 'edit_redirect_to' )        );
    1352 
    1353                                 // Add actions to bbp_new_forum
    1354                                 add_action( 'bbp_new_forum',               array( $this, 'new_forum'        ), 10, 4 );
    1355 
    1356                                 // Handle the new forum
    1357                                 bbp_new_forum_handler();
    1358 
    1359                                 break;
    1360 
    1361                         // Edit existing forum
    1362                         case 'bbp-edit-forum' :
    1363 
    1364                                 // Redirect back here, not to the new forum
    1365                                 add_filter( 'bbp_edit_forum_redirect_to',  array( $this, 'edit_redirect_to' )        );
    1366 
    1367                                 // Handle the forum edit
    1368                                 bbp_edit_forum_handler();
    1369 
    1370                                 break;
    1371 
    1372                         // Trash a forum
    1373                         case 'bbp-trash-forum' :
    1374                                 //bbp_trash_forum_handler();
    1375                                 break;
    1376 
    1377                         // Permanently delet a forum
    1378                         case 'bbp-delete-forum' :
    1379                                 //bbp_delete_forum_handler();
    1380                                 break;
    1381                 }
     1470                check_admin_referer( 'groups_edit_save_' . $this->slug );
     1471
     1472                $edit_forum   = !empty( $_POST['bbp-edit-group-forum'] ) ? true : false;
     1473                $forum_id     = 0;
     1474                $forum_ids    = bbp_get_group_forum_ids( bp_get_current_group_id() );
     1475                if ( !empty( $forum_ids ) )
     1476                        $forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids;
     1477
     1478                // Update forum active
     1479                groups_update_groupmeta( bp_get_current_group_id(), '_bbp_forum_enabled_' . $forum_id, $edit_forum );
    13821480        }
    13831481
     
    13971495                $checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( bp_get_new_group_id(), 'forum_id' ); ?>
    13981496
    1399                 <h4><?php _e( 'Group Forums', 'bbpress' ); ?></h4>
     1497                <h4><?php _e( 'Group Forum', 'bbpress' ); ?></h4>
    14001498
    14011499                <p><?php _e( 'Create a discussion forum to allow members of this group to communicate in a structured, bulletin-board style fashion.', 'bbpress' ); ?></p>
     
    14591557                                $this->new_forum( array( 'forum_id' => $forum_id ) );
    14601558
     1559                                // Update forum active
     1560                                groups_update_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true );
     1561
    14611562                                break;
    14621563                        case false :
     
    14661567                                        wp_delete_post( $forum_id, true );
    14671568                                        groups_delete_groupmeta( bp_get_new_group_id(), 'forum_id' );
     1569                                        groups_delete_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id );
    14681570                                }
    14691571
     
    15481650         */
    15491651        public function display_forums( $offset = 0 ) {
    1550                 global $wpdb;
    1551 
    15521652                $bbp = bbpress();
    15531653
    15541654                // Forum data
    15551655                $forum_ids  = bbp_get_group_forum_ids( bp_get_current_group_id() );
    1556                 $forum_args = array( 'post__in' => $forum_ids, 'post_parent' => null ); ?>
     1656                $forum_args = array( 'post__in' => $forum_ids, 'post_parent' => null );
     1657
     1658                // Unset global queries
     1659                $bbp->forum_query = new stdClass;
     1660                $bbp->topic_query = new stdClass;
     1661                $bbp->reply_query = new stdClass;
     1662
     1663                // Unset global ID's
     1664                $bbp->current_forum_id     = 0;
     1665                $bbp->current_topic_id     = 0;
     1666                $bbp->current_reply_id     = 0;
     1667                $bbp->current_topic_tag_id = 0;
     1668
     1669                // Reset the post data
     1670                wp_reset_postdata();
     1671
     1672                // Allow admins special views
     1673                $post_status = array( bbp_get_closed_status_id(), bbp_get_public_status_id() );
     1674                if ( is_super_admin() || current_user_can( 'moderate' ) || bp_is_item_admin() || bp_is_item_mod() )
     1675                        $post_status = array_merge( $post_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ); ?>
    15571676
    15581677                <div id="bbpress-forums">
     
    15611680
    15621681                        // Looking at the group forum root
    1563                         if ( ! bp_action_variable( $offset ) ) :
    1564 
    1565                                 // Query forums and show them if
     1682                        if ( !bp_action_variable( $offset ) ) :
     1683
     1684                                // Query forums and show them if they exist
    15661685                                if ( !empty( $forum_ids ) && bbp_has_forums( $forum_args ) ) :
    15671686
    1568                                         bbp_the_forum();
    1569 
    15701687                                        // Only one forum found
    1571                                         if ( $bbp->forum_query->post_count == 1 ) :?>
    1572 
    1573                                                 <h3><?php _e( 'Forum', 'bbpress' ); ?></h3>
    1574 
    1575                                                 <?php bbp_set_query_name( 'bbp_single_forum' ); ?>
    1576 
    1577                                                 <?php if ( bbp_has_topics( array( 'post_parent' => bbp_get_forum_id() ) ) ) : ?>
    1578 
    1579                                                         <?php bbp_get_template_part( 'pagination', 'topics'    ); ?>
    1580 
    1581                                                         <?php bbp_get_template_part( 'loop',       'topics'    ); ?>
    1582 
    1583                                                         <?php bbp_get_template_part( 'pagination', 'topics'    ); ?>
     1688                                        if ( 1 == $bbp->forum_query->post_count ) :
     1689
     1690                                                // Get forum data
     1691                                                $forum_slug = bp_action_variable( $offset );
     1692                                                $forum_args = array( 'name' => $forum_slug, 'post_type' => bbp_get_forum_post_type() );
     1693                                                $forums     = get_posts( $forum_args );
     1694
     1695                                                bbp_the_forum();
     1696
     1697                                                // Forum exists
     1698                                                if ( !empty( $forums ) ) :
     1699                                                        $forum = $forums[0];
     1700
     1701                                                        // Set up forum data
     1702                                                        $forum_id = bbpress()->current_forum_id = $forum->ID;
     1703                                                        bbp_set_query_name( 'bbp_single_forum' ); ?>
     1704
     1705                                                        <h3><?php bbp_forum_title(); ?></h3>
     1706
     1707                                                        <?php bbp_get_template_part( 'content', 'single-forum' ); ?>
     1708
     1709                                                <?php else : ?>
     1710
     1711                                                        <?php bbp_get_template_part( 'feedback',   'no-topics' ); ?>
    15841712
    15851713                                                        <?php bbp_get_template_part( 'form',       'topic'     ); ?>
    15861714
    1587                                                 <?php else : ?>
    1588 
    1589                                                         <?php bbp_get_template_part( 'feedback',   'no-topics' ); ?>
    1590 
    1591                                                         <?php bbp_get_template_part( 'form',       'topic'     ); ?>
    1592 
    15931715                                                <?php endif;
    15941716
    1595                                         // More than 1 forum found
    1596                                         elseif ( $bbp->forum_query->post_count > 1 ) : ?>
     1717                                        // More than 1 forum found or group forum admin screen
     1718                                        elseif ( 1 < $bbp->forum_query->post_count ) : ?>
    15971719
    15981720                                                <h3><?php _e( 'Forums', 'bbpress' ); ?></h3>
     
    16271749                                                </div>
    16281750
    1629                                                 <?php if ( bp_is_group_admin_screen( $this->slug ) ) :
    1630                                                         bbp_get_template_part( 'form', 'forum' );
    1631                                                 endif;
    1632                                         endif;
     1751                                        <?php endif;
    16331752
    16341753                                // No forums found
     
    16391758                                        </div>
    16401759
    1641                                         <?php if ( bp_is_group_admin_screen( $this->slug ) ) :
    1642                                                 bbp_get_template_part( 'form', 'forum' );
    1643                                         endif;
    1644                                 endif;
     1760                                <?php endif;
    16451761
    16461762                        // Single forum
    1647                         elseif ( ( bp_action_variable( $offset ) != $this->slug ) && ( bp_action_variable( $offset ) != $this->topic_slug ) ) :
    1648 
    1649                                 // Get the forum
    1650                                 $forum_post_type = bbp_get_forum_post_type();
    1651                                 $forum_slug      = bp_action_variable( $offset );
    1652                                 $forums          = $wpdb->get_row( "SELECT ID FROM {$wpdb->posts} WHERE post_name = '{$forum_slug}' AND post_type = '{$forum_post_type}'", ARRAY_N );
     1763                        elseif ( ( bp_action_variable( $offset ) != $this->slug ) && ( bp_action_variable( $offset ) != $this->topic_slug ) && ( bp_action_variable( $offset ) != $this->reply_slug ) ) :
     1764
     1765                                // Get forum data
     1766                                $forum_slug = bp_action_variable( $offset );
     1767                                $forum_args = array( 'name' => $forum_slug, 'post_type' => bbp_get_forum_post_type() );
     1768                                $forums     = get_posts( $forum_args );
    16531769
    16541770                                // Forum exists
    16551771                                if ( !empty( $forums ) ) :
    1656                                         $forum_id              = $forums[0];
    1657                                         $bbp->current_forum_id = $forum_id;
    1658                                         bbp_set_query_name( 'bbp_single_forum' ); ?>
    1659 
    1660                                         <h3><?php bbp_forum_title(); ?></h3>
    1661 
    1662                                         <?php bbp_get_template_part( 'content', 'single-forum' ); ?>
    1663 
    1664                                 <?php else : ?>
    1665 
    1666                                         <?php bbp_get_template_part( 'feedback', 'no-topics'   ); ?>
    1667 
    1668                                         <?php bbp_get_template_part( 'form',     'topic'       ); ?>
    1669 
    1670                                 <?php endif;
     1772                                        $forum = $forums[0];
     1773
     1774                                        // Set up forum data
     1775                                        $forum_id = bbpress()->current_forum_id = $forum->ID;
     1776
     1777                                        // Reset necessary forum_query attributes for forums loop to function
     1778                                        $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
     1779                                        $bbp->forum_query->in_the_loop             = true;
     1780                                        $bbp->forum_query->post                    = get_post( $forum_id );
     1781
     1782                                        // Forum edit
     1783                                        if ( bp_action_variable( $offset + 1 ) == $bbp->edit_id ) :
     1784                                                global $wp_query, $post;
     1785
     1786                                                $wp_query->bbp_is_edit       = true;
     1787                                                $wp_query->bbp_is_forum_edit = true;
     1788                                                $post                        = $forum;
     1789
     1790                                                bbp_set_query_name( 'bbp_forum_form' );
     1791
     1792                                                bbp_get_template_part( 'form', 'forum' );
     1793
     1794                                        else :
     1795                                                bbp_set_query_name( 'bbp_single_forum' ); ?>
     1796
     1797                                                <h3><?php bbp_forum_title(); ?></h3>
     1798
     1799                                                <?php bbp_get_template_part( 'content', 'single-forum' );
     1800
     1801                                        endif;
     1802
     1803                                else :
     1804                                        bbp_get_template_part( 'feedback', 'no-topics' );
     1805                                        bbp_get_template_part( 'form',     'topic'     );
     1806
     1807                                endif;
    16711808
    16721809                        // Single topic
    1673                         elseif ( ( bp_action_variable( $offset ) != $this->slug ) && ( bp_action_variable( $offset ) == $this->topic_slug ) ) :
    1674 
    1675                                 // Get the topic
    1676                                 $topic_post_type = bbp_get_topic_post_type();
    1677                                 $topic_slug      = bp_action_variable( $offset + 1 );
    1678                                 $topics          = $wpdb->get_row( "SELECT ID FROM {$wpdb->posts} WHERE post_name = '{$topic_slug}' AND post_type = '{$topic_post_type}'", ARRAY_N );
     1810                        elseif ( bp_action_variable( $offset ) == $this->topic_slug ) :
     1811
     1812                                // Get topic data
     1813                                $topic_slug = bp_action_variable( $offset + 1 );
     1814                                $topic_args = array( 'name' => $topic_slug, 'post_type' => bbp_get_topic_post_type(), 'post_status' => $post_status );
     1815                                $topics     = get_posts( $topic_args );
    16791816
    16801817                                // Topic exists
    16811818                                if ( !empty( $topics ) ) :
    1682                                         $topic_id              = $topics[0];
    1683                                         $bbp->current_topic_id = $topic_id;
    1684                                         bbp_set_query_name( 'bbp_single_topic' ); ?>
    1685 
    1686                                         <h3><?php bbp_topic_title(); ?></h3>
    1687 
    1688                                         <?php bbp_get_template_part( 'content', 'single-topic' ); ?>
    1689 
    1690                                 <?php else : ?>
    1691 
    1692                                         <?php bbp_get_template_part( 'feedback', 'no-topics'   ); ?>
    1693 
    1694                                         <?php bbp_get_template_part( 'form',     'topic'       ); ?>
    1695 
    1696                                 <?php endif;
     1819                                        $topic = $topics[0];
     1820
     1821                                        // Set up topic data
     1822                                        $topic_id = bbpress()->current_topic_id = $topic->ID;
     1823                                        $forum_id = bbp_get_topic_forum_id( $topic_id );
     1824
     1825                                        // Reset necessary forum_query attributes for topics loop to function
     1826                                        $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
     1827                                        $bbp->forum_query->in_the_loop             = true;
     1828                                        $bbp->forum_query->post                    = get_post( $forum_id );
     1829
     1830                                        // Reset necessary topic_query attributes for topics loop to function
     1831                                        $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
     1832                                        $bbp->topic_query->in_the_loop             = true;
     1833                                        $bbp->topic_query->post                    = $topic;
     1834
     1835                                        // Topic edit
     1836                                        if ( bp_action_variable( $offset + 2 ) == $bbp->edit_id ) :
     1837                                                global $wp_query, $post;
     1838                                                $wp_query->bbp_is_edit       = true;
     1839                                                $wp_query->bbp_is_topic_edit = true;
     1840                                                $post                        = $topic;
     1841
     1842                                                // Merge
     1843                                                if ( !empty( $_GET['action'] ) && 'merge' == $_GET['action'] ) :
     1844                                                        bbp_set_query_name( 'bbp_topic_merge' );
     1845
     1846                                                        bbp_get_template_part( 'form', 'topic-merge' );
     1847
     1848                                                // Split
     1849                                                elseif ( !empty( $_GET['action'] ) && 'split' == $_GET['action'] ) :
     1850                                                        bbp_set_query_name( 'bbp_topic_split' );
     1851
     1852                                                        bbp_get_template_part( 'form', 'topic-split' );
     1853
     1854                                                // Edit
     1855                                                else :
     1856                                                        bbp_set_query_name( 'bbp_topic_form' );
     1857                                                        bbp_get_template_part( 'form', 'topic' );
     1858
     1859                                                endif;
     1860
     1861                                        // Single Topic
     1862                                        else:
     1863
     1864                                                bbp_set_query_name( 'bbp_single_topic' ); ?>
     1865
     1866                                                <h3><?php bbp_topic_title(); ?></h3>
     1867
     1868                                                <?php bbp_get_template_part( 'content', 'single-topic' );
     1869
     1870                                        endif;
     1871
     1872                                // No Topics
     1873                                else :
     1874                                        bbp_get_template_part( 'feedback', 'no-topics'   );
     1875                                        bbp_get_template_part( 'form',     'topic'       );
     1876
     1877                                endif;
     1878
     1879                        // Single reply
     1880                        elseif ( bp_action_variable( $offset ) == $this->reply_slug ) :
     1881
     1882                                // Get reply data
     1883                                $reply_slug = bp_action_variable( $offset + 1 );
     1884                                $reply_args = array( 'name' => $reply_slug, 'post_type' => bbp_get_reply_post_type() );
     1885                                $replies    = get_posts( $reply_args );
     1886
     1887                                if ( empty( $replies ) )
     1888                                        return;
     1889
     1890                                // Get the first reply
     1891                                $reply = $replies[0];
     1892
     1893                                // Set up reply data
     1894                                $reply_id = bbpress()->current_reply_id = $reply->ID;
     1895                                $topic_id = bbp_get_reply_topic_id( $reply_id );
     1896                                $forum_id = bbp_get_reply_forum_id( $reply_id );
     1897
     1898                                // Reset necessary forum_query attributes for reply to function
     1899                                $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
     1900                                $bbp->forum_query->in_the_loop             = true;
     1901                                $bbp->forum_query->post                    = get_post( $forum_id );
     1902
     1903                                // Reset necessary topic_query attributes for reply to function
     1904                                $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
     1905                                $bbp->topic_query->in_the_loop             = true;
     1906                                $bbp->topic_query->post                    = get_post( $topic_id );
     1907
     1908                                // Reset necessary reply_query attributes for reply to function
     1909                                $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
     1910                                $bbp->reply_query->in_the_loop             = true;
     1911                                $bbp->reply_query->post                    = $reply;
     1912
     1913                                if ( bp_action_variable( $offset + 2 ) == $bbp->edit_id ) :
     1914                                        global $wp_query, $post;
     1915
     1916                                        $wp_query->bbp_is_edit       = true;
     1917                                        $wp_query->bbp_is_reply_edit = true;
     1918                                        $post                        = $reply;
     1919
     1920                                        bbp_set_query_name( 'bbp_reply_form' );
     1921                                        bbp_get_template_part( 'form', 'reply' );
     1922
     1923                                endif;
    16971924
    16981925                        endif; ?>
Note: See TracChangeset for help on using the changeset viewer.