Ticket #1906: 1906.2.diff
File 1906.2.diff, 24.7 KB (added by , 12 years ago) |
---|
-
includes/extend/buddypress.php
173 173 // Hook into topic and reply status changes 174 174 add_action( 'wp_insert_post', array( $this, 'topic_update' ), 10, 2 ); 175 175 add_action( 'wp_insert_post', array( $this, 'reply_update' ), 10, 2 ); 176 176 177 177 // Hook into topic and reply deletion 178 178 add_action( 'bbp_delete_topic', array( $this, 'topic_delete' ), 10, 1 ); 179 179 add_action( 'bbp_delete_reply', array( $this, 'reply_delete' ), 10, 1 ); … … 226 226 add_filter( 'bbp_get_favorites_permalink', array( $this, 'get_favorites_permalink' ), 10, 2 ); 227 227 add_filter( 'bbp_get_subscriptions_permalink', array( $this, 'get_subscriptions_permalink' ), 10, 2 ); 228 228 229 /** Links and pagination **********************************************/ 230 229 231 // Map forum/topic/replys permalinks to their groups 230 232 add_filter( 'bbp_get_forum_permalink', array( $this, 'map_forum_permalink_to_group' ), 10, 2 ); 231 233 add_filter( 'bbp_get_topic_permalink', array( $this, 'map_topic_permalink_to_group' ), 10, 2 ); 232 234 add_filter( 'bbp_get_reply_permalink', array( $this, 'map_reply_permalink_to_group' ), 10, 2 ); 233 235 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, 3 ); 241 add_filter( 'page_link', array( $this, 'page_link' ), 10, 3 ); 242 add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 4 ); 243 234 244 // Canonical redirects for normal URLs 235 245 add_action( 'template_redirect', array( $this, 'redirect_canonical' ) ); 236 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' ) ); 250 237 251 /** Mentions **********************************************************/ 238 252 239 253 // Only link mentions if activity component is active … … 619 633 // Check for existing activity entry ID 620 634 $activity_id = $this->get_activity_id( $topic_id ); 621 635 if ( ! empty( $activity_id ) ) 622 $activity['id'] = $activity_id; 636 $activity['id'] = $activity_id; 623 637 624 638 // Record the activity 625 639 $activity_id = $this->record_activity( $activity ); … … 639 653 public function topic_delete( $topic_id ) { 640 654 641 655 // Get activity ID, bail if it doesn't exist 642 $activity_id = $this->get_activity_id( $topic_id ); 656 $activity_id = $this->get_activity_id( $topic_id ); 643 657 if ( empty( $activity_id ) ) 644 658 return false; 645 659 … … 679 693 if ( in_array( $post->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ) ) { 680 694 681 695 // Validate topic data 682 $forum_id = bbp_get_topic_forum_id( $topic_id );696 $forum_id = bbp_get_topic_forum_id( $topic_id ); 683 697 $topic_author_id = bbp_get_topic_author_id( $topic_id ); 684 698 685 699 $this->topic_create( $topic_id, $forum_id, $anonymous_data, $topic_author_id ); … … 798 812 public function reply_delete( $reply_id ) { 799 813 800 814 // Get activity ID, bail if it doesn't exist 801 $activity_id = $this->get_activity_id( $reply_id ); 815 $activity_id = $this->get_activity_id( $reply_id ); 802 816 if ( empty( $activity_id ) ) 803 817 return false; 804 818 … … 806 820 } 807 821 808 822 /** 809 * Update the activity stream entry when a reply status changes 823 * Update the activity stream entry when a reply status changes 810 824 * 811 825 * @param int $post_id 812 826 * @param obj $post … … 839 853 if ( $post->post_status == bbp_get_public_status_id() ) { 840 854 841 855 // Validate reply data 842 $topic_id = bbp_get_reply_topic_id( $reply_id );843 $forum_id = bbp_get_reply_forum_id( $reply_id );856 $topic_id = bbp_get_reply_topic_id( $reply_id ); 857 $forum_id = bbp_get_reply_forum_id( $reply_id ); 844 858 $reply_author_id = bbp_get_reply_author_id( $reply_id ); 845 859 846 860 $this->reply_create( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id ); … … 850 864 } 851 865 852 866 /** 853 * Ma p a forumpermalink to the corresponding group867 * Maybe map a bbPress forum/topic/reply permalink to the corresponding group 854 868 * 869 * @param int $post_id 870 * @uses get_post() 871 * @uses bbp_is_reply() 872 * @uses bbp_get_reply_topic_id() 873 * @uses bbp_get_reply_forum_id() 874 * @uses bbp_is_topic() 875 * @uses bbp_get_topic_forum_id() 876 * @uses bbp_is_forum() 877 * @uses get_post_field() 878 * @uses bbp_get_forum_group_ids() 879 * @uses groups_get_group() 880 * @uses bp_get_group_admin_permalink() 881 * @uses bp_get_group_permalink() 882 * @return Bail early if not a group forum post 883 * @return string 884 */ 885 private function maybe_map_permalink_to_group( $post_id = 0 ) { 886 887 // Bail if post does not exist 888 if ( !$_post = get_post( $post_id ) ) 889 return false; 890 891 switch ( get_post_type( $_post ) ) { 892 893 // Reply 894 case bbp_get_reply_post_type() : 895 $topic_id = bbp_get_reply_topic_id( $post_id ); 896 $forum_id = bbp_get_reply_forum_id( $post_id ); 897 $url_end = trailingslashit( $this->reply_slug ) . $_post->post_name; 898 break; 899 900 // Topic 901 case bbp_get_topic_post_type() : 902 $topic_id = $post_id; 903 $forum_id = bbp_get_topic_forum_id( $post_id ); 904 $url_end = trailingslashit( $this->topic_slug ) . $_post->post_name; 905 break; 906 907 // Forum 908 case bbp_get_forum_post_type() : 909 $forum_id = $post_id; 910 $url_end = $_post->post_name; 911 break; 912 913 // Unknown 914 default : 915 return false; 916 break; 917 } 918 919 // Get group ID's for this forum 920 $group_ids = bbp_get_forum_group_ids( $forum_id ); 921 922 // Bail if the post isn't associated with a group 923 if ( empty( $group_ids ) ) 924 return false; 925 926 // @todo Multiple group forums/forum groups 927 $group_id = $group_ids[0]; 928 $group = groups_get_group( array( 'group_id' => $group_id ) ); 929 930 if ( bp_is_group_admin_screen( $this->forums_slug ) ) { 931 $group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) ); 932 } else { 933 $group_permalink = trailingslashit( bp_get_group_permalink( $group ) ); 934 } 935 936 return trailingslashit( trailingslashit( $group_permalink . $this->forums_slug ) . $url_end ); 937 } 938 939 /** 940 * Map a forum permalink to its corresponding group 941 * 855 942 * @since bbPress (r3802) 856 943 * @param string $url 857 944 * @param int $forum_id 945 * @uses maybe_map_permalink_to_group 858 946 * @return string 859 947 */ 860 948 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 949 864 // If the topic is not associated with a group, don't mess with it 865 if ( !empty( $group_ids ) ) { 950 $new = $this->maybe_map_permalink_to_group( $forum_id ); 866 951 867 // @todo Multiple group forums/forum groups 868 $group_id = $group_ids[0]; 869 $group = groups_get_group( array( 'group_id' => $group_id ) ); 952 if ( empty( $new ) ) 953 return $url; 870 954 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; 955 return $new; 881 956 } 882 957 883 958 /** 884 * Map a topic permalink to the currentgroup forum959 * Map a topic permalink to its group forum 885 960 * 886 961 * @since bbPress (r3802) 887 962 * @param string $url 888 963 * @param int $topic_id 964 * @uses maybe_map_permalink_to_group 889 965 * @return string 890 966 */ 891 967 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 ); 968 $new = $this->maybe_map_permalink_to_group( $topic_id ); 969 970 return ( ! empty( $new ) ) ? $new : $url; 971 } 895 972 896 // If the topic is not associated with a group, don't mess with it 897 if ( !empty( $group_ids ) ) { 973 /** 974 * Map a reply permalink to its group forum 975 * 976 * @since bbPress (r3802) 977 * @param string $url 978 * @param int $reply_id 979 * @uses maybe_map_permalink_to_group 980 * @return string 981 */ 982 public function map_reply_permalink_to_group( $url, $reply_id ) { 983 $topic_id = bbp_get_reply_topic_id( $reply_id ); 984 $new = $this->maybe_map_permalink_to_group( $topic_id ); 985 986 return ( ! empty( $new ) ) ? $new : $url; 987 } 898 988 899 // @todo Multiple group forums/forum groups 900 $group_id = $group_ids[0]; 901 $group = groups_get_group( array( 'group_id' => $group_id ) ); 989 /** 990 * Map a reply edit link to its group forum 991 * 992 * @param string $url 993 * @param int $reply_id 994 * @uses maybe_map_permalink_to_group 995 * @return string 996 */ 997 public function map_reply_edit_url_to_group( $url, $reply_id ) { 998 $new = $this->maybe_map_permalink_to_group( $reply_id ); 902 999 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 } 1000 if ( empty( $new ) ) 1001 return $url; 908 1002 909 $url = trailingslashit( $group_permalink . $this->forums_slug . '/' . $this->topic_slug . '/' . $slug );910 1003 return trailingslashit( $new ) . bbpress()->edit_id . '/'; 1004 } 911 1005 912 return $url; 1006 /** 1007 * Map a post link to its group forum 1008 * 1009 * @param string $url 1010 * @param obj $post 1011 * @param boolean $leavename 1012 * @uses maybe_map_permalink_to_group 1013 * @return string 1014 */ 1015 public function post_link( $url, $post, $leavename ) { 1016 $new = $this->maybe_map_permalink_to_group( $post->ID ); 1017 1018 return ( ! empty( $new ) ) ? $new : $url; 913 1019 } 914 1020 915 1021 /** 916 * Map a topic permalink to the currentgroup forum1022 * Map a page link to its group forum 917 1023 * 918 * @since bbPress (r3802)919 1024 * @param string $url 920 * @param int $reply_id 1025 * @param int $post_id 1026 * @param $sample 1027 * @uses maybe_map_permalink_to_group 921 1028 * @return string 922 1029 */ 923 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 ); 1030 public function page_link( $url, $post_id, $sample ) { 1031 $new = $this->maybe_map_permalink_to_group( $post_id ); 927 1032 928 // If the topic is not associated with a group, don't mess with it929 if ( !empty( $group_ids ) ) {1033 return ( ! empty( $new ) ) ? $new : $url; 1034 } 930 1035 931 // @todo Multiple group forums/forum groups 932 $group_id = $group_ids[0]; 933 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1036 /** 1037 * Map a custom post type link to its group forum 1038 * 1039 * @param string $url 1040 * @param obj $post 1041 * @param $leavename 1042 * @param $sample 1043 * @uses maybe_map_permalink_to_group 1044 * @return string 1045 */ 1046 public function post_type_link( $url, $post, $leavename, $sample ) { 1047 $new = $this->maybe_map_permalink_to_group( $post->ID ); 934 1048 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 } 1049 return ( ! empty( $new ) ) ? $new : $url; 1050 } 940 1051 941 $url = trailingslashit( $group_permalink . $this->forums_slug . '/' . $this->topic_slug . '/' . $slug ); 942 } 1052 /** 1053 * Fix pagination of topics on forum view 1054 * 1055 * @param array $args 1056 * @global $wp_rewrite 1057 * @uses bbp_get_forum_id() 1058 * @uses maybe_map_permalink_to_group 1059 * @return array 1060 */ 1061 public function topic_pagination( $args ) { 1062 $new = $this->maybe_map_permalink_to_group( bbp_get_forum_id() ); 943 1063 944 return $url; 1064 if ( empty( $new ) ) 1065 return $args; 1066 1067 global $wp_rewrite; 1068 1069 $args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/'; 1070 1071 return $args; 945 1072 } 946 1073 947 1074 /** 1075 * Fix pagination of replies on topic view 1076 * 1077 * @param array $args 1078 * @global $wp_rewrite 1079 * @uses bbp_get_topic_id() 1080 * @uses maybe_map_permalink_to_group 1081 * @return array 1082 */ 1083 public function replies_pagination( $args ) { 1084 $new = $this->maybe_map_permalink_to_group( bbp_get_topic_id() ); 1085 if ( empty( $new ) ) 1086 return $args; 1087 1088 global $wp_rewrite; 1089 1090 $args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/'; 1091 1092 return $args; 1093 } 1094 1095 /** 948 1096 * Ensure that forum content associated with a BuddyPress group can only be 949 1097 * viewed via the group URL. 950 1098 * … … 962 1110 $group_ids = bbp_get_forum_group_ids( $forum_id ); 963 1111 } 964 1112 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 ); 1113 if ( empty( $group_ids ) ) 1114 return; 971 1115 972 if ( !empty( $slug ) ) { 973 $redirect_to = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug ); 974 } 1116 $group_id = $group_ids[0]; 1117 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1118 $group_link = trailingslashit( bp_get_group_permalink( $group ) ); 1119 $redirect_to = trailingslashit( $group_link . $this->forums_slug ); 975 1120 976 bp_core_redirect( $redirect_to ); 1121 if ( !empty( $slug ) ) { 1122 $redirect_to = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug ); 977 1123 } 1124 1125 bp_core_redirect( $redirect_to ); 978 1126 } 979 1127 } 980 1128 endif; … … 1374 1522 //bbp_trash_forum_handler(); 1375 1523 break; 1376 1524 1377 // Permanently delet a forum1525 // Permanently delete a forum 1378 1526 case 'bbp-delete-forum' : 1379 1527 //bbp_delete_forum_handler(); 1380 1528 break; … … 1547 1695 * @uses bbp_get_template_part() 1548 1696 */ 1549 1697 public function display_forums( $offset = 0 ) { 1550 global $wpdb;1551 1552 1698 $bbp = bbpress(); 1553 1699 1554 1700 // Forum data 1555 1701 $forum_ids = bbp_get_group_forum_ids( bp_get_current_group_id() ); 1556 $forum_args = array( 'post__in' => $forum_ids, 'post_parent' => null ); ?>1702 $forum_args = array( 'post__in' => $forum_ids, 'post_parent' => null ); 1557 1703 1558 <div id="bbpress-forums"> 1704 // Unset global queries 1705 $bbp->forum_query = new stdClass; 1706 $bbp->topic_query = new stdClass; 1707 $bbp->reply_query = new stdClass; 1559 1708 1709 // Unset global ID's 1710 $bbp->current_forum_id = 0; 1711 $bbp->current_topic_id = 0; 1712 $bbp->current_reply_id = 0; 1713 $bbp->current_topic_tag_id = 0; 1714 1715 // Reset the post data 1716 wp_reset_postdata(); 1717 1718 // Allow admins special views 1719 $post_status = array( bbp_get_closed_status_id(), bbp_get_public_status_id() ); 1720 if ( is_super_admin() || current_user_can( 'moderate' ) || bp_is_item_admin() || bp_is_item_mod() ) 1721 $post_status = array_merge( $post_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ); ?> 1722 1723 <div id="bbpress-forums"> 1724 1560 1725 <?php 1561 1726 1562 1727 // Looking at the group forum root 1563 if ( ! 1728 if ( !bp_action_variable( $offset ) ) : 1564 1729 1565 // Query forums and show them if 1730 // Query forums and show them if they exist 1566 1731 if ( !empty( $forum_ids ) && bbp_has_forums( $forum_args ) ) : 1567 1732 1568 bbp_the_forum();1569 1570 1733 // Only one forum found 1571 if ( $bbp->forum_query->post_count == 1 ) :?>1734 if ( 1 == $bbp->forum_query->post_count && !bp_is_group_admin_screen( $this->slug ) ) : 1572 1735 1573 <h3><?php _e( 'Forum', 'bbpress' ); ?></h3> 1736 // Get forum data 1737 $forum_slug = bp_action_variable( $offset ); 1738 $forum_args = array( 'name' => $forum_slug, 'post_type' => bbp_get_forum_post_type() ); 1739 $forums = get_posts( $forum_args ); 1574 1740 1575 <?php bbp_set_query_name( 'bbp_single_forum' ); ?>1741 bbp_the_forum(); 1576 1742 1577 <?php if ( bbp_has_topics( array( 'post_parent' => bbp_get_forum_id() ) ) ) : ?> 1743 // Forum exists 1744 if ( !empty( $forums ) ) : 1745 $forum = $forums[0]; 1578 1746 1579 <?php bbp_get_template_part( 'pagination', 'topics' ); ?> 1747 // Set up forum data 1748 $forum_id = bbpress()->current_forum_id = $forum->ID; 1749 bbp_set_query_name( 'bbp_single_forum' ); ?> 1580 1750 1581 < ?php bbp_get_template_part( 'loop', 'topics' ); ?>1751 <h3><?php bbp_forum_title(); ?></h3> 1582 1752 1583 <?php bbp_get_template_part( ' pagination', 'topics'); ?>1753 <?php bbp_get_template_part( 'content', 'single-forum' ); ?> 1584 1754 1585 <?php bbp_get_template_part( 'form', 'topic' ); ?>1586 1587 1755 <?php else : ?> 1588 1756 1589 1757 <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> … … 1592 1760 1593 1761 <?php endif; 1594 1762 1595 // More than 1 forum found 1596 elseif ( $bbp->forum_query->post_count > 1) : ?>1763 // More than 1 forum found or group forum admin screen 1764 elseif ( 1 < $bbp->forum_query->post_count || bp_is_group_admin_screen( $this->slug ) ) : ?> 1597 1765 1598 1766 <h3><?php _e( 'Forums', 'bbpress' ); ?></h3> 1599 1767 … … 1626 1794 <p><?php _e( 'This group does not currently have any forums.', 'bbpress' ); ?></p> 1627 1795 </div> 1628 1796 1629 <?php if ( bp_is_group_admin_screen( $this->slug ) ) : 1630 bbp_get_template_part( 'form', 'forum' ); 1631 endif; 1797 <?php if ( bp_is_group_admin_screen( $this->slug ) ) : ?> 1798 1799 <?php bbp_get_template_part( 'form', 'forum' ); ?> 1800 1801 <?php endif; 1802 1632 1803 endif; 1633 1804 1634 1805 // No forums found … … 1638 1809 <p><?php _e( 'This group does not currently have any forums.', 'bbpress' ); ?></p> 1639 1810 </div> 1640 1811 1641 <?php if ( bp_is_group_admin_screen( $this->slug ) ) : 1642 bbp_get_template_part( 'form', 'forum' ); 1643 endif; 1812 <?php if ( bp_is_group_admin_screen( $this->slug ) ) : ?> 1813 1814 <?php bbp_get_template_part( 'form', 'forum' ); ?> 1815 1816 <?php endif; 1817 1644 1818 endif; 1645 1819 1646 1820 // Single forum 1647 elseif ( ( bp_action_variable( $offset ) != $this->slug ) && ( bp_action_variable( $offset ) != $this->topic_slug )) :1821 elseif ( bp_action_variable( $offset ) != $this->slug && bp_action_variable( $offset ) != $this->topic_slug && bp_action_variable( $offset ) != $this->reply_slug ) : 1648 1822 1649 // Get the forum1650 $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);1823 // Get forum data 1824 $forum_slug = bp_action_variable( $offset ); 1825 $forum_args = array( 'name' => $forum_slug, 'post_type' => bbp_get_forum_post_type() ); 1826 $forums = get_posts( $forum_args ); 1653 1827 1654 1828 // Forum exists 1655 1829 if ( !empty( $forums ) ) : 1656 $forum_id = $forums[0]; 1657 $bbp->current_forum_id = $forum_id; 1658 bbp_set_query_name( 'bbp_single_forum' ); ?> 1830 $forum = $forums[0]; 1659 1831 1660 <h3><?php bbp_forum_title(); ?></h3> 1832 // Set up forum data 1833 $forum_id = bbpress()->current_forum_id = $forum->ID; 1661 1834 1662 <?php bbp_get_template_part( 'content', 'single-forum' ); ?> 1835 // Reset necessary forum_query attributes for forums loop to function 1836 $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); 1837 $bbp->forum_query->in_the_loop = true; 1838 $bbp->forum_query->post = get_post( $forum_id ); 1663 1839 1840 // Forum edit 1841 if ( bp_action_variable( $offset + 1 ) == $bbp->edit_id ) : 1842 global $wp_query, $post; 1843 1844 $wp_query->bbp_is_edit = true; 1845 $wp_query->bbp_is_forum_edit = true; 1846 $post = $forum; 1847 1848 bbp_set_query_name( 'bbp_forum_form' ); ?> 1849 1850 <?php bbp_get_template_part( 'form', 'forum' ); ?> 1851 1852 <?php else : 1853 bbp_set_query_name( 'bbp_single_forum' ); ?> 1854 1855 <h3><?php bbp_forum_title(); ?></h3> 1856 1857 <?php bbp_get_template_part( 'content', 'single-forum' ); ?> 1858 1859 <?php endif; ?> 1860 1664 1861 <?php else : ?> 1665 1862 1666 <?php bbp_get_template_part( 'feedback', 'no-topics'); ?>1863 <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> 1667 1864 1668 <?php bbp_get_template_part( 'form', 'topic'); ?>1865 <?php bbp_get_template_part( 'form', 'topic' ); ?> 1669 1866 1670 1867 <?php endif; 1671 1868 1672 1869 // Single topic 1673 elseif ( ( bp_action_variable( $offset ) != $this->slug ) && ( bp_action_variable( $offset ) == $this->topic_slug )) :1870 elseif ( bp_action_variable( $offset ) == $this->topic_slug ) : 1674 1871 1675 // Get t he topic1676 $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);1872 // Get topic data 1873 $topic_slug = bp_action_variable( $offset + 1 ); 1874 $topic_args = array( 'name' => $topic_slug, 'post_type' => bbp_get_topic_post_type(), 'post_status' => $post_status ); 1875 $topics = get_posts( $topic_args ); 1679 1876 1680 1877 // Topic exists 1681 1878 if ( !empty( $topics ) ) : 1682 $topic_id = $topics[0]; 1683 $bbp->current_topic_id = $topic_id; 1684 bbp_set_query_name( 'bbp_single_topic' ); ?> 1879 $topic = $topics[0]; 1685 1880 1686 <h3><?php bbp_topic_title(); ?></h3> 1881 // Set up topic data 1882 $topic_id = bbpress()->current_topic_id = $topic->ID; 1883 $forum_id = bbp_get_topic_forum_id( $topic_id ); 1687 1884 1688 <?php bbp_get_template_part( 'content', 'single-topic' ); ?> 1885 // Reset necessary forum_query attributes for topics loop to function 1886 $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); 1887 $bbp->forum_query->in_the_loop = true; 1888 $bbp->forum_query->post = get_post( $forum_id ); 1689 1889 1690 <?php else : ?> 1890 // Reset necessary topic_query attributes for topics loop to function 1891 $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type(); 1892 $bbp->topic_query->in_the_loop = true; 1893 $bbp->topic_query->post = $topic; 1691 1894 1895 // Topic edit 1896 if ( bp_action_variable( $offset + 2 ) == $bbp->edit_id ) : 1897 global $wp_query, $post; 1898 $wp_query->bbp_is_edit = true; 1899 $wp_query->bbp_is_topic_edit = true; 1900 $post = $topic; 1901 1902 // Merge 1903 if ( !empty( $_GET['action'] ) && 'merge' == $_GET['action'] ) : 1904 bbp_set_query_name( 'bbp_topic_merge' ); ?> 1905 1906 <?php bbp_get_template_part( 'form', 'topic-merge' ); ?> 1907 1908 <?php // Split 1909 elseif ( !empty( $_GET['action'] ) && 'split' == $_GET['action'] ) : 1910 bbp_set_query_name( 'bbp_topic_split' ); ?> 1911 1912 <?php bbp_get_template_part( 'form', 'topic-split' ); ?> 1913 1914 <?php // Edit 1915 else : 1916 bbp_set_query_name( 'bbp_topic_form' ); ?> 1917 1918 <?php bbp_get_template_part( 'form', 'topic' ); ?> 1919 1920 <?php endif; 1921 1922 else: 1923 1924 bbp_set_query_name( 'bbp_single_topic' ); ?> 1925 1926 <h3><?php bbp_topic_title(); ?></h3> 1927 1928 <?php bbp_get_template_part( 'content', 'single-topic' ); ?> 1929 1930 <?php endif; 1931 1932 else : ?> 1933 1692 1934 <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> 1693 1935 1694 1936 <?php bbp_get_template_part( 'form', 'topic' ); ?> 1695 1937 1696 1938 <?php endif; 1697 1939 1940 // Single reply 1941 elseif ( bp_action_variable( $offset ) == $this->reply_slug ) : 1942 1943 // Get reply data 1944 $reply_slug = bp_action_variable( $offset + 1 ); 1945 $reply_args = array( 'name' => $reply_slug, 'post_type' => bbp_get_reply_post_type() ); 1946 $replies = get_posts( $reply_args ); 1947 if ( !$replies ) 1948 return; 1949 $reply = $replies[0]; 1950 1951 // Set up reply data 1952 $reply_id = bbpress()->current_reply_id = $reply->ID; 1953 $topic_id = bbp_get_reply_topic_id( $reply_id ); 1954 $forum_id = bbp_get_reply_forum_id( $reply_id ); 1955 1956 // Reset necessary forum_query attributes for reply to function 1957 $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); 1958 $bbp->forum_query->in_the_loop = true; 1959 $bbp->forum_query->post = get_post( $forum_id ); 1960 1961 // Reset necessary topic_query attributes for reply to function 1962 $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type(); 1963 $bbp->topic_query->in_the_loop = true; 1964 $bbp->topic_query->post = get_post( $topic_id ); 1965 1966 // Reset necessary reply_query attributes for reply to function 1967 $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type(); 1968 $bbp->reply_query->in_the_loop = true; 1969 $bbp->reply_query->post = $reply; 1970 1971 if ( bp_action_variable( $offset + 2 ) == $bbp->edit_id ) : 1972 bbp_set_query_name( 'bbp_reply_form' ); 1973 global $wp_query, $post; 1974 $wp_query->bbp_is_edit = true; 1975 $wp_query->bbp_is_reply_edit = true; 1976 $post = $reply; ?> 1977 1978 <?php bbp_get_template_part( 'form', 'reply' ); ?> 1979 1980 <?php endif; 1981 1698 1982 endif; ?> 1699 1983 1700 1984 </div>