[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Forums Screen Functions. 4 * 5 * @package BuddyPress 6 * @subpackage ForumsScreens 7 * @since 1.5.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Load the Forums directory. 15 * 16 * @since 1.1.0 17 */ 18 function bp_forums_directory_forums_setup() { 19 20 // Get BuddyPress once. 21 $bp = buddypress(); 22 23 if ( bp_is_forums_component() && ( !bp_current_action() || ( 'tag' == bp_current_action() && bp_action_variables() ) ) && !bp_current_item() ) { 24 if ( !bp_forums_has_directory() ) 25 return false; 26 27 if ( !bp_forums_is_installed_correctly() ) { 28 bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' ); 29 bp_core_redirect( bp_get_root_domain() ); 30 } 31 32 bp_update_is_directory( true, 'forums' ); 33 34 /** 35 * Fires early in the initialization of bbPress-based areas of BuddyPress. 36 * 37 * @since 1.1.0 38 */ 39 do_action( 'bbpress_init' ); 40 41 // Check to see if the user has posted a new topic from the forums page. 42 if ( isset( $_POST['submit_topic'] ) && bp_is_active( 'forums' ) ) { 43 check_admin_referer( 'bp_forums_new_topic' ); 44 45 $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ); 46 if ( !empty( $bp->groups->current_group->id ) ) { 47 // Auto join this user if they are not yet a member of this group. 48 if ( !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 ) ) 49 groups_join_group( $bp->groups->current_group->id ); 50 51 $error_message = ''; 52 53 $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ); 54 if ( !empty( $forum_id ) ) { 55 if ( empty( $_POST['topic_title'] ) ) 56 $error_message = __( 'Please provide a title for your forum topic.', 'buddypress' ); 57 else if ( empty( $_POST['topic_text'] ) ) 58 $error_message = __( 'Forum posts cannot be empty. Please enter some text.', 'buddypress' ); 59 60 if ( $error_message ) { 61 bp_core_add_message( $error_message, 'error' ); 62 $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum'; 63 } else { 64 if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) ) { 65 bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' ); 66 $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum'; 67 } else { 68 bp_core_add_message( __( 'The topic was created successfully', 'buddypress') ); 69 $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/'; 70 } 71 } 72 73 bp_core_redirect( $redirect ); 74 75 } else { 76 bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' ); 77 bp_core_redirect( add_query_arg( 'new', '', bp_get_forums_directory_permalink() ) ); 78 } 79 80 } else { 81 bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' ); 82 bp_core_redirect( add_query_arg( 'new', '', bp_get_forums_directory_permalink() ) ); 83 } 84 } 85 86 /** 87 * Fires right before the loading of the forums directory screen template file. 88 * 89 * @since 1.1.0 90 */ 91 do_action( 'bp_forums_directory_forums_setup' ); 92 93 /** 94 * Filters the template to load for the forums directory screen. 95 * 96 * @since 1.1.0 97 * 98 * @param string $template Path to the forums template to load. 99 */ 100 bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) ); 101 } 102 } 103 add_action( 'bp_screens', 'bp_forums_directory_forums_setup', 2 ); 104 105 /** 106 * Load the Topics Started screen. 107 * 108 * @since 1.5.0 109 */ 110 function bp_member_forums_screen_topics() { 111 112 /** 113 * Fires right before the loading of the forums topics started screen template file. 114 * 115 * @since 1.5.0 116 */ 117 do_action( 'bp_member_forums_screen_topics' ); 118 119 /** 120 * Filters the template to load for the forums topics started screen. 121 * 122 * @since 1.5.0 123 * 124 * @param string $template Path to the forums topics started template to load. 125 */ 126 bp_core_load_template( apply_filters( 'bp_member_forums_screen_topics', 'members/single/home' ) ); 127 } 128 129 /** 130 * Load the Replied To screen. 131 * 132 * @since 1.5.0 133 */ 134 function bp_member_forums_screen_replies() { 135 136 /** 137 * Fires right before the loading of the forums replied to screen template file. 138 * 139 * @since 1.5.0 140 */ 141 do_action( 'bp_member_forums_screen_replies' ); 142 143 /** 144 * Filters the template to load for the forums replied to screen. 145 * 146 * @since 1.5.0 147 * 148 * @param string $template Path to the forums replied to template to load. 149 */ 150 bp_core_load_template( apply_filters( 'bp_member_forums_screen_replies', 'members/single/home' ) ); 151 } 152 153 /** 154 * Load the template content for a user's Favorites forum tab. 155 * 156 * Note that this feature is not fully implemented at the moment. 157 * 158 * @since 1.5.0 159 */ 160 function bp_member_forums_screen_favorites() { 161 162 /** 163 * Fires right before the loading of the forums favorites screen template file. 164 * 165 * @since 1.5.0 166 */ 167 do_action( 'bp_member_forums_screen_favorites' ); 168 169 /** 170 * Filters the template to load for the forums favorites screen. 171 * 172 * @since 1.5.0 173 * 174 * @param string $template Path to the forums favorites template to load. 175 */ 176 bp_core_load_template( apply_filters( 'bp_member_forums_screen_favorites', 'members/single/home' ) ); 177 } 178 179 /** 180 * Load a single forum page. 181 * 182 * @since 1.5.0 183 */ 184 function bp_forums_screen_single_forum() { 185 186 if ( !bp_is_forums_component() || !bp_is_current_action( 'forum' ) || !bp_action_variable( 0 ) ) 187 return false; 188 189 /** 190 * Fires right before the loading of the forums single forum screen template file. 191 * 192 * @since 1.5.0 193 */ 194 do_action( 'bp_forums_screen_single_forum' ); 195 196 /** 197 * Filters the template to load for the forums single forum screen. 198 * 199 * @since 1.5.0 200 * 201 * @param string $template Path to the forums single forum template to load. 202 */ 203 bp_core_load_template( apply_filters( 'bp_forums_screen_single_forum', 'forums/single/forum' ) ); 204 } 205 add_action( 'bp_screens', 'bp_forums_screen_single_forum' ); 206 207 /** 208 * Load a single forum topic page. 209 * 210 * @since 1.5.0 211 */ 212 function bp_forums_screen_single_topic() { 213 214 if ( !bp_is_forums_component() || !bp_is_current_action( 'topic' ) || !bp_action_variable( 0 ) ) 215 return false; 216 217 /** 218 * Fires right before the loading of the forums single topic screen template file. 219 * 220 * @since 1.5.0 221 */ 222 do_action( 'bp_forums_screen_single_topic' ); 223 224 /** 225 * Filters the template to load for the forums single topic screen. 226 * 227 * @since 1.5.0 228 * 229 * @param string $template Path to the forums single topic template to load. 230 */ 231 bp_core_load_template( apply_filters( 'bp_forums_screen_single_topic', 'forums/single/topic' ) ); 232 } 233 add_action( 'bp_screens', 'bp_forums_screen_single_topic' ); 234 235 236 /** Theme Compatibility *******************************************************/ 237 238 /** 239 * The main theme compat class for legacy BuddyPress forums. 240 * 241 * This class sets up the necessary theme compatibility actions to safely output 242 * old forum template parts to the_title and the_content areas of a theme. 243 * 244 * @since 1.7.0 245 */ 246 class BP_Forum_Legacy_Theme_Compat { 247 248 /** 249 * Set up theme compatibility for the legacy forums component. 250 * 251 * @since 1.7.0 252 */ 253 public function __construct() { 254 add_action( 'bp_setup_theme_compat', array( $this, 'is_legacy_forum' ) ); 255 } 256 257 /** 258 * Are we looking at something that needs old forum theme compatibility? 259 * 260 * @since 1.7.0 261 */ 262 public function is_legacy_forum() { 263 264 // Bail if not looking at a group. 265 if ( ! bp_is_forums_component() ) 266 return; 267 268 // Forum Directory. 269 if ( ( ! bp_current_action() || ( 'tag' == bp_current_action() && bp_action_variables() ) ) && ! bp_current_item() ) { 270 271 if ( ! bp_forums_has_directory() ) 272 return false; 273 274 if ( ! bp_forums_is_installed_correctly() ) { 275 bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' ); 276 bp_core_redirect( bp_get_root_domain() ); 277 } 278 279 bp_update_is_directory( true, 'forums' ); 280 281 do_action( 'bp_forums_directory_forums_setup' ); 282 283 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) ); 284 add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) ); 285 286 } 287 288 } 289 290 /** Directory *************************************************************/ 291 292 /** 293 * Update the global $post with directory data. 294 * 295 * @since 1.7.0 296 */ 297 public function directory_dummy_post() { 298 299 // Title based on ability to create groups. 300 if ( is_user_logged_in() ) { 301 $title = __( 'Forums', 'buddypress' ) . ' <a class="button show-hide-new bp-title-button" href="#new-topic" id="new-topic-button">' . __( 'New Topic', 'buddypress' ) . '</a>'; 302 } else { 303 $title = __( 'Forums', 'buddypress' ); 304 } 305 306 bp_theme_compat_reset_post( array( 307 'ID' => 0, 308 'post_title' => $title, 309 'post_author' => 0, 310 'post_date' => 0, 311 'post_content' => '', 312 'post_type' => 'page', 313 'post_status' => 'publish', 314 'is_page' => true, 315 'comment_status' => 'closed' 316 ) ); 317 } 318 319 /** 320 * Filter the_content with the old forum index template part. 321 * 322 * @since 1.7.0 323 */ 324 public function directory_content() { 325 return bp_buffer_template_part( 'forums/index', null, false ); 326 } 327 } 328 new BP_Forum_Legacy_Theme_Compat();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Dec 7 01:01:35 2017 | Cross-referenced by PHPXref 0.7.1 |