Changeset 3728 for trunk/bp-forums.php
- Timestamp:
- 01/18/2011 12:53:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-forums.php
r3713 r3728 1 1 <?php 2 2 3 / * Define the parent forum ID */3 // Define the parent forum ID 4 4 if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) 5 5 define( 'BP_FORUMS_PARENT_FORUM_ID', 1 ); … … 19 19 function bp_forums_setup() { 20 20 global $bp; 21 22 23 define ( 'BP_FORUMS_SLUG', $bp->pages->forums->slug);21 22 if ( !defined( 'BP_FORUMS_SLUG' ) ) 23 define ( 'BP_FORUMS_SLUG', bp_core_component_slug_from_root_slug( $bp->pages->forums->slug ) ); 24 24 25 25 // For internal identification 26 26 $bp->forums->id = 'forums'; 27 27 28 // Slugs 29 $bp->forums->slug = BP_FORUMS_SLUG; 30 $bp->forums->root_slug = $bp->pages->forums->slug; 31 32 // Images 28 33 $bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images'; 29 $bp->forums->slug = BP_FORUMS_SLUG;30 34 31 35 if ( isset( $bp->site_options['bb-config-location'] ) ) … … 81 85 do_action( 'bbpress_init' ); 82 86 83 / * Check to see if the user has posted a new topic from the forums page. */87 // Check to see if the user has posted a new topic from the forums page. 84 88 if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) { 85 /* Check the nonce */86 89 check_admin_referer( 'bp_forums_new_topic' ); 87 90 88 91 if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) { 89 / * Auto join this user if they are not yet a member of this group */92 // Auto join this user if they are not yet a member of this group 90 93 if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) 91 94 groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id ); … … 134 137 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' ); 135 138 136 / * Add the administration tab under the "Site Admin" tab for site administrators */139 // Add the administration tab under the "Site Admin" tab for site administrators 137 140 add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" ); 138 141 } 139 142 add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_forums_add_admin_menu' ); 140 143 141 /* Forum Functions*/144 /** Forum Functions ***********************************************************/ 142 145 143 146 function bp_forums_get_forum( $forum_id ) { … … 150 153 151 154 $defaults = array( 152 'forum_name' => '',153 'forum_desc' => '',154 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,155 'forum_order' => false,155 'forum_name' => '', 156 'forum_desc' => '', 157 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID, 158 'forum_order' => false, 156 159 'forum_is_category' => 0 157 160 ); … … 182 185 } 183 186 184 /* Topic Functions*/187 /** Topic Functions ***********************************************************/ 185 188 186 189 function bp_forums_get_forum_topics( $args = '' ) { … … 207 210 $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_latest_topics' ); 208 211 $topics =& $query->results; 209 break;212 break; 210 213 211 214 case 'popular': 212 215 $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies ) ); 213 216 $topics =& $query->results; 214 break;217 break; 215 218 216 219 case 'unreplied': 217 220 $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies ) ); 218 221 $topics =& $query->results; 219 break;222 break; 220 223 221 224 case 'tags': 222 225 $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies ) ); 223 226 $topics =& $query->results; 224 break;227 break; 225 228 } 226 229 … … 247 250 248 251 $defaults = array( 249 'topic_title' => '',250 'topic_slug' => '',251 'topic_text' => '',252 'topic_poster' => $bp->loggedin_user->id, // accepts ids253 'topic_poster_name' => $bp->loggedin_user->fullname, // accept names254 'topic_last_poster' => $bp->loggedin_user->id, // accepts ids252 'topic_title' => '', 253 'topic_slug' => '', 254 'topic_text' => '', 255 'topic_poster' => $bp->loggedin_user->id, // accepts ids 256 'topic_poster_name' => $bp->loggedin_user->fullname, // accept names 257 'topic_last_poster' => $bp->loggedin_user->id, // accepts ids 255 258 'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names 256 'topic_start_time' => bp_core_current_time(),257 'topic_time' => bp_core_current_time(),258 'topic_open' => 1,259 'topic_tags' => false, // accepts array or comma delim260 'forum_id' => 0 // accepts ids or slugs259 'topic_start_time' => bp_core_current_time(), 260 'topic_time' => bp_core_current_time(), 261 'topic_open' => 1, 262 'topic_tags' => false, // accepts array or comma delim 263 'forum_id' => 0 // accepts ids or slugs 261 264 ); 262 265 … … 275 278 return false; 276 279 277 / * Now insert the first post. */280 // Now insert the first post. 278 281 if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) ) 279 282 return false; … … 290 293 291 294 $defaults = array( 295 'topic_id' => false, 296 'topic_title' => '', 297 'topic_text' => '' 298 ); 299 300 $r = wp_parse_args( $args, $defaults ); 301 extract( $r, EXTR_SKIP ); 302 303 if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) ) 304 return false; 305 306 if ( !$post = bb_get_first_post( $topic_id ) ) 307 return false; 308 309 // Update the first post 310 if ( !$post = bp_forums_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) ) 311 return false; 312 313 return bp_forums_get_topic_details( $topic_id ); 314 } 315 316 function bp_forums_sticky_topic( $args = '' ) { 317 global $bp; 318 319 do_action( 'bbpress_init' ); 320 321 $defaults = array( 292 322 'topic_id' => false, 293 'topic_title' => '', 294 'topic_text' => '' 295 ); 296 297 $r = wp_parse_args( $args, $defaults ); 298 extract( $r, EXTR_SKIP ); 299 300 if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) ) 301 return false; 302 303 if ( !$post = bb_get_first_post( $topic_id ) ) 304 return false; 305 306 /* Update the first post */ 307 if ( !$post = bp_forums_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) ) 308 return false; 309 310 return bp_forums_get_topic_details( $topic_id ); 311 } 312 313 function bp_forums_sticky_topic( $args = '' ) { 314 global $bp; 315 316 do_action( 'bbpress_init' ); 317 318 $defaults = array( 319 'topic_id' => false, 320 'mode' => 'stick' // stick/unstick 323 'mode' => 'stick' // stick/unstick 321 324 ); 322 325 … … 339 342 $defaults = array( 340 343 'topic_id' => false, 341 'mode' => 'close' // stick/unstick344 'mode' => 'close' // stick/unstick 342 345 ); 343 346 … … 398 401 return $topics; 399 402 400 / * Get the topic ids */403 // Get the topic ids 401 404 foreach ( (array)$topics as $topic ) $topic_ids[] = $topic->topic_id; 402 405 $topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) ); 403 406 404 / * Fetch the topic's last poster details */407 // Fetch the topic's last poster details 405 408 $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, t.topic_last_poster, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u, {$bbdb->topics} t WHERE u.ID = t.topic_last_poster AND t.topic_id IN ( {$topic_ids} )" ) ); 406 409 for ( $i = 0; $i < count( $topics ); $i++ ) { 407 410 foreach ( (array)$poster_details as $poster ) { 408 411 if ( $poster->topic_id == $topics[$i]->topic_id ) { 409 $topics[$i]->topic_last_poster_email = $poster->user_email;410 $topics[$i]->topic_last_poster_nicename = $poster->user_nicename;411 $topics[$i]->topic_last_poster_login = $poster->user_login;412 $topics[$i]->topic_last_poster_email = $poster->user_email; 413 $topics[$i]->topic_last_poster_nicename = $poster->user_nicename; 414 $topics[$i]->topic_last_poster_login = $poster->user_login; 412 415 $topics[$i]->topic_last_poster_displayname = $poster->display_name; 413 416 } … … 415 418 } 416 419 417 / * Fetch fullname for the topic's last poster */420 // Fetch fullname for the topic's last poster 418 421 if ( bp_is_active( 'xprofile' ) ) { 419 422 $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) ); … … 429 432 } 430 433 431 /* Post Functions*/434 /** Post Functions ************************************************************/ 432 435 433 436 function bp_forums_get_topic_posts( $args = '' ) { … … 436 439 $defaults = array( 437 440 'topic_id' => false, 438 'page' => 1,441 'page' => 1, 439 442 'per_page' => 15, 440 'order' => 'ASC' 441 ); 442 443 $args = wp_parse_args( $args, $defaults ); 444 443 'order' => 'ASC' 444 ); 445 446 $args = wp_parse_args( $args, $defaults ); 445 447 $query = new BB_Query( 'post', $args, 'get_thread' ); 448 446 449 return bp_forums_get_post_extras( $query->results ); 447 450 } … … 473 476 474 477 $defaults = array( 475 'post_id' => false,476 'topic_id' => false,477 'post_text' => '',478 'post_time' => bp_core_current_time(),479 'poster_id' => $bp->loggedin_user->id, // accepts ids or names480 'poster_ip' => $_SERVER['REMOTE_ADDR'],481 'post_status' => 0, // use bb_delete_post() instead478 'post_id' => false, 479 'topic_id' => false, 480 'post_text' => '', 481 'post_time' => bp_core_current_time(), 482 'poster_id' => $bp->loggedin_user->id, // accepts ids or names 483 'poster_ip' => $_SERVER['REMOTE_ADDR'], 484 'post_status' => 0, // use bb_delete_post() instead 482 485 'post_position' => false 483 486 ); … … 503 506 $post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) ); 504 507 505 if ( $post_id)508 if ( !empty( $post_id ) ) 506 509 do_action( 'bp_forums_new_post', $post_id ); 507 510 … … 515 518 return $posts; 516 519 517 / * Get the user ids */520 // Get the user ids 518 521 foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id; 519 522 $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) ); 520 523 521 / * Fetch the poster's user_email, user_nicename and user_login */524 // Fetch the poster's user_email, user_nicename and user_login 522 525 $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ) ); 523 526 … … 525 528 foreach ( (array)$poster_details as $poster ) { 526 529 if ( $poster->user_id == $posts[$i]->poster_id ) { 527 $posts[$i]->poster_email = $poster->user_email;528 $posts[$i]->poster_login = $poster->user_nicename;530 $posts[$i]->poster_email = $poster->user_email; 531 $posts[$i]->poster_login = $poster->user_nicename; 529 532 $posts[$i]->poster_nicename = $poster->user_login; 530 $posts[$i]->poster_name = $poster->display_name;533 $posts[$i]->poster_name = $poster->display_name; 531 534 } 532 535 } 533 536 } 534 537 535 / * Fetch fullname for each poster. */538 // Fetch fullname for each poster. 536 539 if ( bp_is_active( 'xprofile' ) ) { 537 540 $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) ); … … 552 555 do_action( 'bbpress_init' ); 553 556 554 / * Need to find a bbPress function that does this */557 // Need to find a bbPress function that does this 555 558 return $wpdb->get_results( $wpdb->prepare( "SELECT topics, posts from {$bbdb->forums} WHERE forum_id = %d", $forum_id ) ); 556 559 } … … 586 589 add_action( 'bp_forums_new_forum', 'bp_core_clear_cache' ); 587 590 add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' ); 588 add_action( 'bp_forums_new_post', 'bp_core_clear_cache' ); 591 add_action( 'bp_forums_new_post', 'bp_core_clear_cache' ); 592 589 593 ?>
Note: See TracChangeset
for help on using the changeset viewer.