Changeset 3135
- Timestamp:
- 05/11/2011 04:13:41 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-topic-functions.php
r3129 r3135 46 46 */ 47 47 function bbp_new_topic_handler() { 48 48 49 // Only proceed if POST is a new topic 49 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && 'bbp-new-topic' === $_POST['action']) {50 if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && !empty( $_POST['action'] ) && ( 'bbp-new-topic' === $_POST['action'] ) ) { 50 51 global $bbp; 51 52 … … 53 54 check_admin_referer( 'bbp-new-topic' ); 54 55 55 // Prevent debug notices 56 $forum_id = $topic_title = $topic_content = ''; 57 58 // Check users ability to create new topic 59 if ( !bbp_is_anonymous() ) { 60 if ( !current_user_can( 'publish_topics' ) ) 56 // Set defaults to prevent debug notices 57 $forum_id = $topic_author = $anonymous_data = 0; 58 $topic_title = $topic_content = ''; 59 $terms = array( $bbp->topic_tag_id => array() ); 60 61 /** Topic Author ******************************************************/ 62 63 // User is anonymous 64 if ( bbp_is_anonymous() ) { 65 66 // Filter anonymous data 67 $anonymous_data = bbp_filter_anonymous_post_data(); 68 69 // Anonymous data checks out, so set cookies, etc... 70 if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) { 71 bbp_set_current_anonymous_user_data( $anonymous_data ); 72 } 73 74 // User is logged in 75 } else { 76 77 // User cannot create topics 78 if ( !current_user_can( 'publish_topics' ) ) { 61 79 $bbp->errors->add( 'bbp_topic_permissions', __( '<strong>ERROR</strong>: You do not have permission to create new topics.', 'bbpress' ) ); 62 63 $anonymous_data = false; 64 $topic_author = bbp_get_current_user_id(); 65 66 // It is an anonymous post 67 } else { 68 $anonymous_data = bbp_filter_anonymous_post_data(); // Filter anonymous data 69 $topic_author = 0; 70 71 if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) 72 bbp_set_current_anonymous_user_data( $anonymous_data ); 80 } 81 82 // Topic author is current user 83 $topic_author = bbp_get_current_user_id(); 84 73 85 } 74 86 … … 79 91 } 80 92 81 // Handle Title 82 if ( isset( $_POST['bbp_topic_title'] ) && ( !$topic_title = esc_attr( strip_tags( $_POST['bbp_topic_title'] ) ) ) ) 93 /** Topic Title *******************************************************/ 94 95 // Topic title 96 if ( !empty( $_POST['bbp_topic_title'] ) ) { 97 98 // Sanitize and strip HTML tags 99 $topic_title = esc_attr( strip_tags( $_POST['bbp_topic_title'] ) ); 100 101 // Filter and sanitize 102 $topic_title = apply_filters( 'bbp_new_topic_pre_title', $topic_title ); 103 } 104 105 // No topic title 106 if ( empty( $topic_title ) ) 83 107 $bbp->errors->add( 'bbp_topic_title', __( '<strong>ERROR</strong>: Your topic needs a title.', 'bbpress' ) ); 84 108 85 $topic_title = apply_filters( 'bbp_new_topic_pre_title', $topic_title ); 86 87 // Handle Content 88 if ( isset( $_POST['bbp_topic_content'] ) && ( !$topic_content = $_POST['bbp_topic_content'] ) ) 109 /** Topic Content *****************************************************/ 110 111 // Topic content 112 if ( !empty( $_POST['bbp_topic_content'] ) ) { 113 114 // Set topic content 115 $topic_content = $_POST['bbp_topic_content']; 116 117 // Filter and sanitize 118 $topic_content = apply_filters( 'bbp_new_topic_pre_content', $topic_content ); 119 } 120 121 // No topic content 122 if ( empty( $topic_content ) ) 89 123 $bbp->errors->add( 'bbp_topic_content', __( '<strong>ERROR</strong>: Your topic needs some content.', 'bbpress' ) ); 90 124 91 $topic_content = apply_filters( 'bbp_new_topic_pre_content', $topic_content );92 93 // Handle Forum id to append topic to94 if ( isset( $_POST['bbp_forum_id'] ) && ( !$forum_id = $_POST['bbp_forum_id'] ) ) {125 /** Topic Forum *******************************************************/ 126 127 // Forum id was not passed 128 if ( empty( $_POST['bbp_forum_id'] ) ) 95 129 $bbp->errors->add( 'bbp_topic_forum_id', __( '<strong>ERROR</strong>: Forum ID is missing.', 'bbpress' ) ); 96 } else { 130 131 // Forum id was passed 132 elseif ( is_numeric( $_POST['bbp_forum_id'] ) ) 133 $forum_id = (int) $_POST['bbp_forum_id']; 134 135 // Forum exists 136 if ( !empty( $forum_id ) ) { 137 138 // Forum is a category 97 139 if ( bbp_is_forum_category( $forum_id ) ) 98 $bbp->errors->add( 'bbp_topic_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics can be created in this forum!', 'bbpress' ) ); 99 140 $bbp->errors->add( 'bbp_edit_topic_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics can be created in this forum.', 'bbpress' ) ); 141 142 // Forum is closed and user cannot access 100 143 if ( bbp_is_forum_closed( $forum_id ) && !current_user_can( 'edit_forum', $forum_id ) ) 101 $bbp->errors->add( 'bbp_topic_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics!', 'bbpress' ) ); 102 144 $bbp->errors->add( 'bbp_edit_topic_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress' ) ); 145 146 // Forum is private and user cannot access 103 147 if ( bbp_is_forum_private( $forum_id ) && !current_user_can( 'read_private_forums' ) ) 104 $bbp->errors->add( 'bbp_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in this forum!', 'bbpress' ) ); 105 } 106 107 // Check for flood 148 $bbp->errors->add( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 149 150 // Forum is hidden and user cannot access 151 if ( bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) ) 152 $bbp->errors->add( 'bbp_edit_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 153 } 154 155 /** Topic Flooding ****************************************************/ 156 108 157 if ( !bbp_check_for_flood( $anonymous_data, $topic_author ) ) 109 158 $bbp->errors->add( 'bbp_topic_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) ); 110 159 111 // Check for duplicate 160 /** Topic Duplicate ***************************************************/ 161 112 162 if ( !bbp_check_for_duplicate( array( 'post_type' => bbp_get_topic_post_type(), 'post_author' => $topic_author, 'post_content' => $topic_content, 'anonymous_data' => $anonymous_data ) ) ) 113 163 $bbp->errors->add( 'bbp_topic_duplicate', __( '<strong>ERROR</strong>: Duplicate topic detected; it looks as though you’ve already said that!', 'bbpress' ) ); 114 164 115 // Handle Tags 165 /** Topic Tags ********************************************************/ 166 116 167 if ( !empty( $_POST['bbp_topic_tags'] ) ) { 117 168 … … 120 171 121 172 // Explode by comma 122 if ( strstr( $terms, ',' ) ) 173 if ( strstr( $terms, ',' ) ) { 123 174 $terms = explode( ',', $terms ); 175 } 124 176 125 177 // Add topic tag ID as main key 126 178 $terms = array( $bbp->topic_tag_id => $terms ); 127 128 // No tags 129 } else { 130 $terms = ''; 131 } 132 133 // Handle insertion into posts table 179 } 180 181 /** Additional Actions (Before Save) **********************************/ 182 183 do_action( 'bbp_new_topic_pre_extras' ); 184 185 /** No Errors *********************************************************/ 186 134 187 if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) { 188 189 /** Create new topic **********************************************/ 135 190 136 191 // Add the content of the form to $post as an array … … 145 200 ); 146 201 147 // Insert reply202 // Insert topic 148 203 $topic_id = wp_insert_post( $topic_data ); 149 204 150 // Check for missing topic_id or error 205 /** No Errors *****************************************************/ 206 151 207 if ( !empty( $topic_id ) && !is_wp_error( $topic_id ) ) { 152 208 153 // Stick status 209 /** Stickies **************************************************/ 210 154 211 if ( !empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array( 'stick', 'super', 'unstick' ) ) ) { 155 212 213 // What's the haps? 156 214 switch ( $_POST['bbp_stick_topic'] ) { 157 215 216 // Sticky in this forum 158 217 case 'stick' : 159 218 bbp_stick_topic( $topic_id ); 160 161 219 break; 162 220 221 // Super sticky in all forums 163 222 case 'super' : 164 223 bbp_stick_topic( $topic_id, true ); 165 166 224 break; 167 225 226 // We can avoid this as it is a new topic 168 227 case 'unstick' : 169 228 default : 170 171 // We can avoid this as it is a new topic172 // bbp_unstick_topic( $topic_id );173 174 229 break; 175 230 } … … 180 235 do_action( 'bbp_new_topic', $topic_id, $forum_id, $anonymous_data, $topic_author ); 181 236 237 /** Successful Save *******************************************/ 238 182 239 // Redirect back to new reply 183 240 wp_redirect( bbp_get_topic_permalink( $topic_id ) . '#post-' . $topic_id ); … … 186 243 exit(); 187 244 188 // Errors to report245 // Errors 189 246 } else { 190 247 $append_error = ( is_wp_error( $topic_id ) && $topic_id->get_error_message() ) ? $topic_id->get_error_message() . ' ' : ''; … … 230 287 */ 231 288 function bbp_edit_topic_handler() { 289 232 290 // Only proceed if POST is an edit topic request 233 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && 'bbp-edit-topic' === $_POST['action']) {291 if ( ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ) && ( !empty( $_POST['action'] ) && ( 'bbp-edit-topic' === $_POST['action'] ) ) ) { 234 292 global $bbp; 235 293 236 if ( !$topic_id = (int) $_POST['bbp_topic_id'] ) { 237 $bbp->errors->add( 'bbp_edit_topic_id', __( '<strong>ERROR</strong>: Topic ID not found!', 'bbpress' ) ); 238 } elseif ( !$topic = bbp_get_topic( $topic_id ) ) { 239 $bbp->errors->add( 'bbp_edit_topic_not_found', __( '<strong>ERROR</strong>: The topic you want to edit was not found!', 'bbpress' ) ); 294 // Set defaults to prevent debug notices 295 $topic_id = $forum_id = $anonymous_data = 0; 296 $topic_title = $topic_content = $topic_edit_reason = ''; 297 $terms = array( $bbp->topic_tag_id => array() ); 298 299 /** Topic *************************************************************/ 300 301 // Topic id was not passed 302 if ( empty( $_POST['bbp_topic_id'] ) ) 303 $bbp->errors->add( 'bbp_edit_topic_id', __( '<strong>ERROR</strong>: Topic ID not found.', 'bbpress' ) ); 304 305 // Topic id was passed 306 elseif ( is_numeric( $_POST['bbp_topic_id'] ) ) 307 $topic_id = (int) $_POST['bbp_topic_id']; 308 309 // Topic does not exist 310 if ( !$topic = bbp_get_topic( $topic_id ) ) { 311 $bbp->errors->add( 'bbp_edit_topic_not_found', __( '<strong>ERROR</strong>: The topic you want to edit was not found.', 'bbpress' ) ); 312 313 // Topic exists 240 314 } else { 315 241 316 // Nonce check 242 317 check_admin_referer( 'bbp-edit-topic_' . $topic_id ); … … 244 319 // Check users ability to create new topic 245 320 if ( !bbp_is_topic_anonymous( $topic_id ) ) { 246 if ( !current_user_can( 'edit_topic', $topic_id ) ) 247 $bbp->errors->add( 'bbp_edit_topic_permissions', __( '<strong>ERROR</strong>: You do not have permission to edit that topic!', 'bbpress' ) ); 248 249 $anonymous_data = false; 321 322 // User cannot edit this topic 323 if ( !current_user_can( 'edit_topic', $topic_id ) ) { 324 $bbp->errors->add( 'bbp_edit_topic_permissions', __( '<strong>ERROR</strong>: You do not have permission to edit that topic.', 'bbpress' ) ); 325 } 250 326 251 327 // It is an anonymous post 252 328 } else { 253 $anonymous_data = bbp_filter_anonymous_post_data( array(), true ); // Filter anonymous data 329 330 // Filter anonymous data 331 $anonymous_data = bbp_filter_anonymous_post_data( array(), true ); 254 332 } 255 333 } 256 334 257 335 // Remove wp_filter_kses filters from title and content for capable users and if the nonce is verified 258 if ( current_user_can( 'unfiltered_html' ) && !empty( $_POST['_bbp_unfiltered_html_topic'] ) && wp_create_nonce( 'bbp-unfiltered-html-topic_' . $topic_id ) == $_POST['_bbp_unfiltered_html_topic']) {336 if ( current_user_can( 'unfiltered_html' ) && !empty( $_POST['_bbp_unfiltered_html_topic'] ) && ( wp_create_nonce( 'bbp-unfiltered-html-topic_' . $topic_id ) == $_POST['_bbp_unfiltered_html_topic'] ) ) { 259 337 remove_filter( 'bbp_edit_topic_pre_title', 'wp_filter_kses' ); 260 338 remove_filter( 'bbp_edit_topic_pre_content', 'wp_filter_kses' ); 261 339 } 262 340 263 // Handle Forum id to append topic to 264 if ( isset( $_POST['bbp_forum_id'] ) && ( !$forum_id = $_POST['bbp_forum_id'] ) ) { 341 /** Topic Forum *******************************************************/ 342 343 // Forum id was not passed 344 if ( empty( $_POST['bbp_forum_id'] ) ) 265 345 $bbp->errors->add( 'bbp_topic_forum_id', __( '<strong>ERROR</strong>: Forum ID is missing.', 'bbpress' ) ); 266 } elseif ( $forum_id != $topic->post_parent ) { 346 347 // Forum id was passed 348 elseif ( is_numeric( $_POST['bbp_forum_id'] ) ) 349 $forum_id = (int) $_POST['bbp_forum_id']; 350 351 // Forum exists 352 if ( !empty( $forum_id ) && ( $forum_id != $topic->post_parent ) ) { 353 354 // Forum is a category 267 355 if ( bbp_is_forum_category( $forum_id ) ) 268 $bbp->errors->add( 'bbp_edit_topic_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics can be created in this forum!', 'bbpress' ) ); 269 356 $bbp->errors->add( 'bbp_edit_topic_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics can be created in this forum.', 'bbpress' ) ); 357 358 // Forum is closed and user cannot access 270 359 if ( bbp_is_forum_closed( $forum_id ) && !current_user_can( 'edit_forum', $forum_id ) ) 271 $bbp->errors->add( 'bbp_edit_topic_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics!', 'bbpress' ) ); 272 360 $bbp->errors->add( 'bbp_edit_topic_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress' ) ); 361 362 // Forum is private and user cannot access 273 363 if ( bbp_is_forum_private( $forum_id ) && !current_user_can( 'read_private_forums' ) ) 274 $bbp->errors->add( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in this forum!', 'bbpress' ) ); 275 } 276 277 // Handle Title 278 if ( isset( $_POST['bbp_topic_title'] ) && ( !$topic_title = esc_attr( strip_tags( $_POST['bbp_topic_title'] ) ) ) ) 364 $bbp->errors->add( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 365 366 // Forum is hidden and user cannot access 367 if ( bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) ) 368 $bbp->errors->add( 'bbp_edit_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 369 } 370 371 /** Topic Title *******************************************************/ 372 373 // Topic title 374 if ( !empty( $_POST['bbp_topic_title'] ) ) { 375 376 // Sanitize and strip HTML tags 377 $topic_title = esc_attr( strip_tags( $_POST['bbp_topic_title'] ) ); 378 379 // Filter and sanitize 380 $topic_title = apply_filters( 'bbp_edit_topic_pre_title', $topic_title, $topic_id ); 381 } 382 383 // No topic title 384 if ( empty( $topic_title ) ) 279 385 $bbp->errors->add( 'bbp_edit_topic_title', __( '<strong>ERROR</strong>: Your topic needs a title.', 'bbpress' ) ); 280 386 281 $topic_title = apply_filters( 'bbp_edit_topic_pre_title', $topic_title, $topic_id ); 282 283 // Handle Content 284 if ( isset( $_POST['bbp_topic_content'] ) && ( !$topic_content = $_POST['bbp_topic_content'] ) ) 387 /** Topic Content *****************************************************/ 388 389 // Topic content 390 if ( !empty( $_POST['bbp_topic_content'] ) ) { 391 392 // Set topic content 393 $topic_content = $_POST['bbp_topic_content']; 394 395 // Filter and sanitize 396 $topic_content = apply_filters( 'bbp_edit_topic_pre_content', $topic_content, $topic_id ); 397 } 398 399 // No topic content 400 if ( empty( $topic_content ) ) 285 401 $bbp->errors->add( 'bbp_edit_topic_content', __( '<strong>ERROR</strong>: Your topic cannot be empty.', 'bbpress' ) ); 286 402 287 $topic_content = apply_filters( 'bbp_edit_topic_pre_content', $topic_content, $topic_id );288 289 // HandleTags403 /** Topic Tags ********************************************************/ 404 405 // Tags 290 406 if ( !empty( $_POST['bbp_topic_tags'] ) ) { 291 407 … … 294 410 295 411 // Explode by comma 296 if ( strstr( $terms, ',' ) ) 412 if ( strstr( $terms, ',' ) ) { 297 413 $terms = explode( ',', $terms ); 414 } 298 415 299 416 // Add topic tag ID as main key 300 417 $terms = array( $bbp->topic_tag_id => $terms ); 301 302 // No tags 303 } else { 304 $terms = array( $bbp->topic_tag_id => array() ); 305 } 306 307 // Handle insertion into posts table 418 } 419 420 /** Additional Actions (Before Save) **********************************/ 421 422 do_action( 'bbp_edit_topic_pre_extras', $topic_id ); 423 424 /** No Errors *********************************************************/ 425 308 426 if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) { 309 427 310 // Stick status 428 /** Stickies ******************************************************/ 429 311 430 if ( !empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array( 'stick', 'super', 'unstick' ) ) ) { 431 432 // What's the dilly? 312 433 switch ( $_POST['bbp_stick_topic'] ) { 313 434 435 // Sticky in forum 314 436 case 'stick' : 315 437 bbp_stick_topic( $topic_id ); 316 438 break; 317 439 440 // Sticky in all forums 318 441 case 'super' : 319 442 bbp_stick_topic( $topic_id, true ); 320 443 break; 321 444 445 // Normal 322 446 case 'unstick' : 323 447 default : … … 326 450 } 327 451 } 452 453 /** Update the topic **********************************************/ 328 454 329 455 // Add the content of the form to $post as an array … … 339 465 $topic_id = wp_update_post( $topic_data ); 340 466 341 // Revisions 342 $topic_edit_reason = !empty( $_POST['bbp_topic_edit_reason'] ) ? esc_attr( strip_tags( $_POST['bbp_topic_edit_reason'] ) ) : ''; 343 344 if ( !empty( $_POST['bbp_log_topic_edit'] ) && 1 == $_POST['bbp_log_topic_edit'] && $revision_id = wp_save_post_revision( $topic_id ) ) 345 bbp_update_topic_revision_log( array( 'topic_id' => $topic_id, 'revision_id' => $revision_id, 'author_id' => bbp_get_current_user_id(), 'reason' => $topic_edit_reason ) ); 346 347 // Check for missing topic_id or error 467 /** Revisions *****************************************************/ 468 469 // Revision Reason 470 if ( !empty( $_POST['bbp_topic_edit_reason'] ) ) { 471 $topic_edit_reason = esc_attr( strip_tags( $_POST['bbp_topic_edit_reason'] ) ); 472 } 473 474 // Update revision log 475 if ( !empty( $_POST['bbp_log_topic_edit'] ) && ( 1 == $_POST['bbp_log_topic_edit'] ) && ( $revision_id = wp_save_post_revision( $topic_id ) ) ) { 476 bbp_update_topic_revision_log( array( 477 'topic_id' => $topic_id, 478 'revision_id' => $revision_id, 479 'author_id' => bbp_get_current_user_id(), 480 'reason' => $topic_edit_reason 481 ) ); 482 } 483 484 /** No Errors *****************************************************/ 485 348 486 if ( !empty( $topic_id ) && !is_wp_error( $topic_id ) ) { 349 487 … … 357 495 bbp_move_topic_handler( $topic_id, $topic->post_parent, $forum_id ); 358 496 497 /** Additional Actions (After Save) ***************************/ 498 499 do_action( 'bbp_edit_topic_post_extras', $topic_id ); 500 501 /** Successful Edit *******************************************/ 502 359 503 // Redirect back to new topic 360 504 wp_redirect( bbp_get_topic_permalink( $topic_id ) ); … … 363 507 exit(); 364 508 365 / / Errors to report509 /** Errors ********************************************************/ 366 510 } else { 367 511 $append_error = ( is_wp_error( $topic_id ) && $topic_id->get_error_message() ) ? $topic_id->get_error_message() . ' ' : ''; … … 384 528 385 529 if ( // Check if POST action 386 'POST' === $_SERVER['REQUEST_METHOD']&&530 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) && 387 531 388 532 // Check Actions exist in POST 389 !empty( $_POST['action'] ) 390 !empty( $_POST['post_type'] ) 533 !empty( $_POST['action'] ) && 534 !empty( $_POST['post_type'] ) && 391 535 392 536 // Check that actions match what we need 393 'editpost' === $_POST['action']&&394 'publish' === $_POST['post_status']&&395 bbp_get_topic_post_type() 537 'editpost' === $_POST['action'] && 538 'publish' === $_POST['post_status'] && 539 bbp_get_topic_post_type() === $_POST['post_type'] 396 540 ) { 397 541 398 542 // Update the topic meta bidness 399 bbp_update_topic( $topic_id, (int) $_POST['parent_id'] ); 543 $parent_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; 544 bbp_update_topic( $topic_id, $parent_id ); 400 545 } 401 546 } … … 470 615 if ( bbp_is_subscriptions_active() && !empty( $author_id ) ) { 471 616 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id ); 472 $subscheck = ( !empty( $_POST['bbp_topic_subscription'] ) && 'bbp_subscribe' == $_POST['bbp_topic_subscription']) ? true : false;617 $subscheck = ( !empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' == $_POST['bbp_topic_subscription'] ) ) ? true : false; 473 618 474 619 // Subscribed and unsubscribing … … 673 818 */ 674 819 function bbp_merge_topic_handler() { 820 675 821 // Only proceed if POST is an merge topic request 676 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && 'bbp-merge-topic' === $_POST['action']) {822 if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && !empty( $_POST['action'] ) && ( 'bbp-merge-topic' === $_POST['action'] ) ) { 677 823 global $bbp; 678 824 679 if ( !$source_topic_id = (int) $_POST['bbp_topic_id'] ) 680 $bbp->errors->add( 'bbp_merge_topic_source_id', __( '<strong>ERROR</strong>: Topic ID not found!', 'bbpress' ) ); 825 // Prevent debug notices 826 $source_topic_id = $destination_topic_id = 0; 827 $source_topic = $destination_topic = 0; 828 $subscribers = $favoriters = $replies = array(); 829 830 /** Source Topic ******************************************************/ 831 832 // Topic id 833 if ( empty( $_POST['bbp_topic_id'] ) ) 834 $bbp->errors->add( 'bbp_merge_topic_source_id', __( '<strong>ERROR</strong>: Topic ID not found.', 'bbpress' ) ); 835 else 836 $source_topic_id = (int) $_POST['bbp_topic_id']; 681 837 682 838 // Nonce check 683 839 check_admin_referer( 'bbp-merge-topic_' . $source_topic_id ); 684 840 841 // Source topic not found 685 842 if ( !$source_topic = bbp_get_topic( $source_topic_id ) ) 686 $bbp->errors->add( 'bbp_merge_topic_source_not_found', __( '<strong>ERROR</strong>: The topic you want to merge was not found!', 'bbpress' ) ); 687 843 $bbp->errors->add( 'bbp_merge_topic_source_not_found', __( '<strong>ERROR</strong>: The topic you want to merge was not found.', 'bbpress' ) ); 844 845 // Cannot edit source topic 688 846 if ( !current_user_can( 'edit_topic', $source_topic->ID ) ) 689 $bbp->errors->add( 'bbp_merge_topic_source_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the source topic!', 'bbpress' ) ); 690 691 if ( !$destination_topic_id = (int) $_POST['bbp_destination_topic'] ) 692 $bbp->errors->add( 'bbp_merge_topic_destination_id', __( '<strong>ERROR</strong>: Destination topic ID not found!', 'bbpress' ) ); 693 847 $bbp->errors->add( 'bbp_merge_topic_source_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the source topic.', 'bbpress' ) ); 848 849 /** Destination Topic *************************************************/ 850 851 // Topic id 852 if ( empty( $_POST['bbp_destination_topic'] ) ) 853 $bbp->errors->add( 'bbp_merge_topic_destination_id', __( '<strong>ERROR</strong>: Destination topic ID not found.', 'bbpress' ) ); 854 else 855 $destination_topic_id = (int) $_POST['bbp_destination_topic']; 856 857 // Destination topic not found 694 858 if ( !$destination_topic = bbp_get_topic( $destination_topic_id ) ) 695 $bbp->errors->add( 'bbp_merge_topic_destination_not_found', __( '<strong>ERROR</strong>: The topic you want to merge to was not found!', 'bbpress' ) ); 696 859 $bbp->errors->add( 'bbp_merge_topic_destination_not_found', __( '<strong>ERROR</strong>: The topic you want to merge to was not found.', 'bbpress' ) ); 860 861 // Cannot edit destination topic 697 862 if ( !current_user_can( 'edit_topic', $destination_topic->ID ) ) 698 $bbp->errors->add( 'bbp_merge_topic_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the destination topic!', 'bbpress' ) ); 699 700 // Handle the merge 863 $bbp->errors->add( 'bbp_merge_topic_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the destination topic.', 'bbpress' ) ); 864 865 /** No Errors *********************************************************/ 866 701 867 if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) { 702 868 703 869 // Update counts, etc... 704 870 do_action( 'bbp_merge_topic', $destination_topic->ID, $source_topic->ID ); 871 872 /** Date Check ****************************************************/ 705 873 706 874 // Check if the destination topic is older than the source topic … … 720 888 } 721 889 890 /** Subscriptions *************************************************/ 891 722 892 // Remove the topic from everybody's subscriptions 723 $subscribers = bbp_get_topic_subscribers( $source_topic->ID ); 724 foreach ( (array) $subscribers as $subscriber ) { 725 726 // Shift the subscriber if told to 727 if ( !empty( $_POST['bbp_topic_subscribers'] ) && 1 == $_POST['bbp_topic_subscribers'] && bbp_is_subscriptions_active() ) 728 bbp_add_user_subscription( $subscriber, $destination_topic->ID ); 729 730 bbp_remove_user_subscription( $subscriber, $source_topic->ID ); 893 if ( $subscribers = bbp_get_topic_subscribers( $source_topic->ID ) ) { 894 895 // Loop through each user 896 foreach ( (array) $subscribers as $subscriber ) { 897 898 // Shift the subscriber if told to 899 if ( !empty( $_POST['bbp_topic_subscribers'] ) && ( 1 == $_POST['bbp_topic_subscribers'] ) && bbp_is_subscriptions_active() ) 900 bbp_add_user_subscription( $subscriber, $destination_topic->ID ); 901 902 // Remove old subscription 903 bbp_remove_user_subscription( $subscriber, $source_topic->ID ); 904 } 731 905 } 732 906 907 /** Favorites *****************************************************/ 908 733 909 // Remove the topic from everybody's favorites 734 $favoriters = bbp_get_topic_favoriters( $source_topic->ID ); 735 foreach ( (array) $favoriters as $favoriter ) { 736 737 // Shift the favoriter if told to 738 if ( !empty( $_POST['bbp_topic_favoriters'] ) && 1 == $_POST['bbp_topic_favoriters'] ) 739 bbp_add_user_favorite( $favoriter, $destination_topic->ID ); 740 741 bbp_remove_user_favorite( $favoriter, $source_topic->ID ); 910 if ( $favoriters = bbp_get_topic_favoriters( $source_topic->ID ) ) { 911 912 // Loop through each user 913 foreach ( (array) $favoriters as $favoriter ) { 914 915 // Shift the favoriter if told to 916 if ( !empty( $_POST['bbp_topic_favoriters'] ) && 1 == $_POST['bbp_topic_favoriters'] ) 917 bbp_add_user_favorite( $favoriter, $destination_topic->ID ); 918 919 // Remove old favorite 920 bbp_remove_user_favorite( $favoriter, $source_topic->ID ); 921 } 742 922 } 923 924 /** Tags **********************************************************/ 743 925 744 926 // Get the source topic tags 745 927 $source_topic_tags = wp_get_post_terms( $source_topic->ID, $bbp->topic_tag_id, array( 'fields' => 'names' ) ); 928 929 // Tags to possibly merge 746 930 if ( !empty( $source_topic_tags ) && !is_wp_error( $source_topic_tags ) ) { 747 931 748 932 // Shift the tags if told to 749 if ( !empty( $_POST['bbp_topic_tags'] ) && 1 == $_POST['bbp_topic_tags'])933 if ( !empty( $_POST['bbp_topic_tags'] ) && ( 1 == $_POST['bbp_topic_tags'] ) ) 750 934 wp_set_post_terms( $destination_topic->ID, $source_topic_tags, $bbp->topic_tag_id, true ); 751 935 … … 754 938 } 755 939 756 // Attempt to revert the closed/sticky status 757 bbp_open_topic ( $source_topic->ID ); 940 /** Source Topic **************************************************/ 941 942 // Status 943 bbp_open_topic( $source_topic->ID ); 944 945 // Sticky 758 946 bbp_unstick_topic( $source_topic->ID ); 759 947 … … 769 957 array_unshift( $replies, $source_topic ); 770 958 771 // Change the post_parent of each reply to the destination topic id 772 foreach ( $replies as $reply ) { 773 $postarr = array( 774 'ID' => $reply->ID, 775 'post_title' => sprintf( __( 'Reply To: %s', 'bbpress' ), $destination_topic->post_title ), 776 'post_name' => false, 777 'post_type' => bbp_get_reply_post_type(), 778 'post_parent' => $destination_topic->ID, 779 'guid' => '' 780 ); 781 782 wp_update_post( $postarr ); 783 784 // Adjust reply meta values 785 bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID ); 786 bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) ); 787 788 // Do additional actions per merged reply 789 do_action( 'bbp_merged_topic_reply', $reply->ID, $destination_topic->ID ); 959 if ( !empty( $replies ) ) { 960 961 /** Merge Replies *************************************************/ 962 963 // Change the post_parent of each reply to the destination topic id 964 foreach ( $replies as $reply ) { 965 $postarr = array( 966 'ID' => $reply->ID, 967 'post_title' => sprintf( __( 'Reply To: %s', 'bbpress' ), $destination_topic->post_title ), 968 'post_name' => false, 969 'post_type' => bbp_get_reply_post_type(), 970 'post_parent' => $destination_topic->ID, 971 'guid' => '' 972 ); 973 974 wp_update_post( $postarr ); 975 976 // Adjust reply meta values 977 bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID ); 978 bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) ); 979 980 // Do additional actions per merged reply 981 do_action( 'bbp_merged_topic_reply', $reply->ID, $destination_topic->ID ); 982 } 790 983 } 984 985 /** Successful Merge *******************************************/ 791 986 792 987 // Send the post parent of the source topic as it has been shifted … … 826 1021 function bbp_merge_topic_count( $destination_topic_id, $source_topic_id, $source_topic_forum_id ) { 827 1022 1023 /** Source Topic **********************************************************/ 1024 828 1025 // Forum Topic Counts 829 1026 bbp_update_forum_topic_count( $source_topic_forum_id ); 830 // bbp_update_forum_topic_count( $destination_topic_id );831 1027 832 1028 // Forum Reply Counts 833 1029 bbp_update_forum_reply_count( $source_topic_forum_id ); 1030 1031 /** Destination Topic *****************************************************/ 834 1032 835 1033 // Topic Reply Counts … … 884 1082 */ 885 1083 function bbp_split_topic_handler() { 1084 886 1085 // Only proceed if POST is an split topic request 887 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && 'bbp-split-topic' === $_POST['action']) {1086 if ( ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) ) && !empty( $_POST['action'] ) && ( 'bbp-split-topic' === $_POST['action'] ) ) { 888 1087 global $wpdb, $bbp; 889 1088 … … 1094 1293 1095 1294 // Are we managing a tag? 1096 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && in_array( $_POST['action'], array( 'bbp-update-topic-tag', 'bbp-merge-topic-tag', 'bbp-delete-topic-tag' ) ) && !empty( $_POST['tag-id']) ) {1295 if ( ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) ) && !empty( $_POST['tag-id'] ) && !empty( $_POST['action'] ) && in_array( $_POST['action'], array( 'bbp-update-topic-tag', 'bbp-merge-topic-tag', 'bbp-delete-topic-tag' ) ) ) { 1097 1296 1098 1297 global $bbp; … … 1309 1508 1310 1509 // Only proceed if GET is a topic toggle action 1311 if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam', 'bbp_toggle_topic_trash' ) ) && !empty( $_GET['topic_id']) ) {1510 if ( ( 'GET' == strtoupper( $_SERVER['REQUEST_METHOD'] ) ) && !empty( $_GET['topic_id'] ) && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam', 'bbp_toggle_topic_trash' ) ) ) { 1312 1511 global $bbp; 1313 1512
Note: See TracChangeset
for help on using the changeset viewer.