Ticket #2617: 2617.patch
File 2617.patch, 16.0 KB (added by , 10 years ago) |
---|
-
includes/common/classes.php
191 191 * 192 192 * @var string 193 193 */ 194 var $tree_type;194 public $tree_type = 'forum'; 195 195 196 196 /** 197 197 * @see Walker::$db_fields … … 200 200 * 201 201 * @var array 202 202 */ 203 var $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); 203 public $db_fields = array( 204 'parent' => 'post_parent', 205 'id' => 'ID' 206 ); 204 207 205 208 /** Methods ***************************************************************/ 206 209 … … 219 222 * @since bbPress (r2746) 220 223 * 221 224 * @param string $output Passed by reference. Used to append additional 222 * content. 223 * @param object $_post Post data object. 224 * @param int $depth Depth of post in reference to parent posts. Used 225 * for padding. 226 * @param array $args Uses 'selected' argument for selected post to set 227 * selected HTML attribute for option element. 228 * @param int $current_object_id 225 * content. 226 * @param object $object Post data object. 227 * @param int $depth Depth of post in reference to parent posts. Used 228 * for padding. 229 * @param array $args Uses 'selected' argument for selected post to set 230 * selected HTML attribute for option element. 231 * @param int $current_object_id 232 * 229 233 * @uses bbp_is_forum_category() To check if the forum is a category 230 234 * @uses current_user_can() To check if the current user can post in 231 235 * closed forums … … 277 281 * 278 282 * @var string 279 283 */ 280 var$tree_type = 'reply';284 public $tree_type = 'reply'; 281 285 282 286 /** 283 287 * @see Walker::$db_fields … … 286 290 * 287 291 * @var array 288 292 */ 289 var$db_fields = array(293 public $db_fields = array( 290 294 'parent' => 'reply_to', 291 295 'id' => 'ID' 292 296 ); 293 297 294 298 /** 299 * Confirm the tree_type 300 * 301 * @since bbPress (rxxxx) 302 */ 303 public function __construct() { 304 $this->tree_type = bbp_get_reply_post_type(); 305 } 306 307 /** 295 308 * @see Walker::start_lvl() 296 309 * 297 310 * @since bbPress (r4944) … … 301 314 * @param array $args Uses 'style' argument for type of HTML list 302 315 */ 303 316 public function start_lvl( &$output = '', $depth = 0, $args = array() ) { 304 bbpress()->reply_query->reply_depth = $depth + 1;317 bbpress()->reply_query->reply_depth = (int) $depth + 1; 305 318 306 319 switch ( $args['style'] ) { 307 320 case 'div': … … 375 388 376 389 // Set up reply 377 390 $depth++; 378 bbpress()->reply_query->reply_depth = $depth;391 bbpress()->reply_query->reply_depth = (int) $depth; 379 392 bbpress()->reply_query->post = $object; 380 393 bbpress()->current_reply_id = $object->ID; 381 394 … … 414 427 } 415 428 } 416 429 } 430 431 /** 432 * Create HTML dropdown list of bbPress replies. 433 * 434 * @package bbPress 435 * @subpackage Classes 436 * 437 * @since bbPress (rxxxx) 438 * @uses Walker 439 */ 440 class BBP_Walker_Reply_Dropdown extends Walker { 441 442 /** 443 * @see Walker::$tree_type 444 * 445 * @since bbPress (rxxxx) 446 * 447 * @var string 448 */ 449 public $tree_type = 'reply'; 450 451 /** 452 * @see Walker::$db_fields 453 * 454 * @since bbPress (rxxxx) 455 * 456 * @var array 457 */ 458 public $db_fields = array( 459 'parent' => 'reply_to', 460 'id' => 'ID' 461 ); 462 463 /** Methods ***************************************************************/ 464 465 /** 466 * Confirm the tree_type 467 * 468 * @since bbPress (rxxxx) 469 */ 470 public function __construct() { 471 $this->tree_type = bbp_get_reply_post_type(); 472 } 473 474 /** 475 * @see Walker::start_el() 476 * 477 * @since bbPress (rxxxx) 478 * 479 * @param string $output Passed by reference. Used to append additional 480 * content. 481 * 482 * @param object $object Post data object. 483 * 484 * @param int $depth Depth of post in reference to parent posts. Used 485 * for padding. 486 * 487 * @param array $args Uses 'selected' argument for selected post to set 488 * selected HTML attribute for option element. 489 * 490 * @param int $current_object_id Not Used 491 * 492 * @uses bbp_is_forum_category() To check if the forum is a category 493 * @uses current_user_can() To check if the current user can post in 494 * closed forums 495 * @uses bbp_is_forum_closed() To check if the forum is closed 496 * @uses apply_filters() Calls 'bbp_walker_dropdown_post_title' with the 497 * title, output, post, depth and args 498 */ 499 public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { 500 501 // Set up reply 502 $depth++; 503 bbpress()->reply_query->reply_depth = (int) $depth; 504 bbpress()->reply_query->post = $object; 505 bbpress()->current_reply_id = $object->ID; 506 507 // Get reply ancestors 508 $to_check = bbp_get_reply_ancestors( $object->ID ); 509 510 // Array of ancestors to check for disabling 511 if ( $args['selected'] !== $object->ID ) { 512 array_unshift( $to_check, $object->ID ); 513 } 514 515 // Determine the indentation 516 $pad = str_repeat( ' ', (int) $depth * 3 ); 517 518 // Determine reply title (either post_title, or excerpt of post_content) 519 $title = ! empty( $object->post_title ) ? $object->post_title : wp_html_excerpt( $object->post_content, 10 ); 520 $title = sprintf( esc_html__( '%1$s - %2$s', 'bbpress' ), (int) $object->ID, $title ); 521 $title = apply_filters( 'bbp_walker_dropdown_post_title', $title, $output, $object, $depth, $args ); 522 523 // Attributes 524 $class = 'level-' . (int) $depth; 525 $value = (int) $object->ID; 526 527 // Start an output buffer to make late escaping easier 528 ob_start(); ?> 529 530 <option class="<?php echo esc_attr( $class ); ?>" value="<?php echo esc_attr( $value ); ?>"<?php selected( $args['selected'], $object->ID ); ?> <?php disabled( in_array( $args['selected'], $to_check ), true ); ?>><?php echo $pad . esc_html( $title ); ?></option> 531 532 <?php 533 534 // Append the output buffer to the $output variable 535 $output .= ob_get_clean(); 536 } 537 } 417 538 endif; // class_exists check -
includes/common/template.php
1280 1280 } 1281 1281 1282 1282 /** 1283 * Outputthe current tab index of a given form1283 * Return the current tab index of a given form 1284 1284 * 1285 1285 * Use this function to handle the tab indexing of user facing forms 1286 1286 * within a template file. Calling this function will automatically … … 1316 1316 echo bbp_get_dropdown( $args ); 1317 1317 } 1318 1318 /** 1319 * Outputa select box allowing to pick which forum/topic a new1319 * Return a select box allowing to pick which forum/topic a new 1320 1320 * topic/reply belongs in. 1321 1321 * 1322 1322 * @since bbPress (r2746) … … 1358 1358 */ 1359 1359 function bbp_get_dropdown( $args = '' ) { 1360 1360 1361 // Setup return value 1362 $retval = ''; 1363 1361 1364 /** Arguments *********************************************************/ 1362 1365 1363 1366 // Parse arguments against default values … … 1396 1399 $r['exclude'] = explode( ',', $r['exclude'] ); 1397 1400 } 1398 1401 1399 /** Setup variables***************************************************/1402 /** Setup Posts *******************************************************/ 1400 1403 1401 $retval = ''; 1402 $posts = get_posts( array( 1403 'post_type' => $r['post_type'], 1404 'post_status' => $r['post_status'], 1405 'exclude' => $r['exclude'], 1406 'post_parent' => $r['post_parent'], 1407 'numberposts' => $r['numberposts'], 1408 'orderby' => $r['orderby'], 1409 'order' => $r['order'], 1410 'walker' => $r['walker'], 1411 'disable_categories' => $r['disable_categories'] 1412 ) ); 1404 /** 1405 * Allow passing of custom posts data 1406 * 1407 * @see bbp_get_reply_to_dropdown() as an example 1408 */ 1409 if ( ! empty( $r['posts'] ) ) { 1410 $posts = $r['posts']; 1411 } else { 1412 $posts = get_posts( array( 1413 'post_type' => $r['post_type'], 1414 'post_status' => $r['post_status'], 1415 'post_parent' => $r['post_parent'], 1416 'exclude' => $r['exclude'], 1417 'numberposts' => $r['numberposts'], 1418 'orderby' => $r['orderby'], 1419 'order' => $r['order'], 1420 ) ); 1421 } 1413 1422 1414 1423 /** Drop Down *********************************************************/ 1415 1424 … … 1590 1599 if ( bbp_is_reply_edit() ) : ?> 1591 1600 1592 1601 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" /> 1593 <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="<?php bbp_form_reply_to(); ?>" />1594 1602 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" /> 1595 1603 1596 1604 <?php if ( current_user_can( 'unfiltered_html' ) ) -
includes/replies/functions.php
1113 1113 1114 1114 // Validation 1115 1115 $reply_id = bbp_get_reply_id( $reply_id ); 1116 $reply_to = bbp_validate_reply_to( $reply_to );1116 $reply_to = bbp_validate_reply_to( $reply_to, $reply_id ); 1117 1117 1118 1118 // Update or delete the `reply_to` postmeta 1119 1119 if ( ! empty( $reply_id ) ) { … … 1132 1132 } 1133 1133 1134 1134 /** 1135 * Get all ancestors to a reply 1136 * 1137 * Because settings can be changed, this function does not care if hierarchical 1138 * replies are active or to what depth. 1139 * 1140 * @since bbPress (r5387) 1141 * 1142 * @param int $reply_id 1143 * @return array 1144 */ 1145 function bbp_get_reply_ancestors( $reply_id = 0 ) { 1146 1147 // Validation 1148 $reply_id = bbp_get_reply_id( $reply_id ); 1149 $ancestors = array(); 1150 1151 // Reply id is valid 1152 if ( ! empty( $reply_id ) ) { 1153 1154 // Try to get reply parent 1155 $reply_to = bbp_get_reply_to( $reply_id ); 1156 1157 // Reply has a hierarchical parent 1158 if ( ! empty( $reply_to ) ) { 1159 1160 // Setup the current ID and current post as an ancestor 1161 $id = $ancestors[] = $reply_to; 1162 1163 // Get parent reply 1164 while ( $ancestor = bbp_get_reply( $id ) ) { 1165 1166 // Does parent have a parent? 1167 $grampy_id = bbp_get_reply_to( $ancestor->ID ); 1168 1169 // Loop detection: If the ancestor has been seen before, break. 1170 if ( empty( $ancestor->post_parent ) || ( $grampy_id === $reply_id ) || in_array( $grampy_id, $ancestors ) ) { 1171 break; 1172 } 1173 1174 $id = $ancestors[] = $grampy_id; 1175 } 1176 } 1177 } 1178 1179 return apply_filters( 'bbp_get_reply_ancestors', $ancestors, $reply_id ); 1180 } 1181 1182 /** 1135 1183 * Update the revision log of the reply 1136 1184 * 1137 1185 * @since bbPress (r2782) -
includes/replies/template.php
2477 2477 } 2478 2478 2479 2479 /** 2480 * Output a select box allowing to pick which reply an existing hierarchical 2481 * reply belongs to. 2482 * 2483 * @since bbPress (rxxxx) 2484 * 2485 * @param int $reply_id 2486 */ 2487 function bbp_reply_to_dropdown( $reply_id = 0 ) { 2488 echo bbp_get_reply_to_dropdown( $reply_id ); 2489 } 2490 /** 2491 * Return a select box allowing to pick which forum/topic a new 2492 * topic/reply belongs in. 2493 * 2494 * @since bbPress (rxxxx) 2495 * 2496 * @param int $reply_id 2497 * 2498 * @uses BBP_Reply_Walker_Dropdown() As the default walker to generate the 2499 * dropdown 2500 * @uses current_user_can() To check if the current user can read 2501 * private forums 2502 * @uses bbp_get_forum_post_type() To get the forum post type 2503 * @uses bbp_get_topic_post_type() To get the topic post type 2504 * 2505 * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown 2506 * and args 2507 * @return string The dropdown 2508 */ 2509 function bbp_get_reply_to_dropdown( $reply_id = 0 ) { 2510 2511 // Validate the reply data 2512 $reply_id = bbp_get_reply_id( $reply_id ); 2513 $reply_to = bbp_get_reply_to( $reply_id ); 2514 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2515 2516 // Setup default dropdown arguments 2517 $r = bbp_parse_args( array( 2518 'show_none' => sprintf( esc_attr__( '%1$s - %2$s', 'bbpress' ), $topic_id, bbp_get_topic_title( $topic_id ) ), 2519 'select_id' => 'bbp_reply_to', 2520 'exclude' => array(), 2521 'selected' => $reply_to, 2522 'post_parent' => $topic_id, 2523 'post_type' => bbp_get_reply_post_type(), 2524 'post_status' => bbp_get_public_status_id(), 2525 'max_depth' => bbp_thread_replies_depth(), 2526 'page' => 1, 2527 'per_page' => -1, 2528 'orderby' => 'menu_order', 2529 'order' => 'ASC', 2530 'walker' => new BBP_Walker_Reply_Dropdown() 2531 ), 'reply_to_drodown' ); 2532 2533 // Get the replies 2534 $posts = get_posts( array( 2535 'post_type' => $r['post_type'], 2536 'post_status' => $r['post_status'], 2537 'post_parent' => $r['post_parent'], 2538 'exclude' => $r['exclude'], 2539 'numberposts' => $r['per_page'], 2540 'orderby' => $r['orderby'], 2541 'order' => $r['order'], 2542 ) ); 2543 2544 // Append `reply_to` for each reply so it can be walked 2545 foreach ( $posts as &$post ) { 2546 2547 // Check for reply post type 2548 $_reply_to = bbp_get_reply_to( $post->ID ); 2549 2550 // Make sure it's a reply to a reply 2551 if ( empty( $_reply_to ) || ( $topic_id === $_reply_to ) ) { 2552 $_reply_to = 0; 2553 } 2554 2555 // Add reply_to to the post object so we can walk it later 2556 $post->reply_to = $_reply_to; 2557 } 2558 2559 // Get the dropdown and return it 2560 $retval = bbp_get_dropdown( array( 2561 'show_none' => $r['show_none'], 2562 'select_id' => $r['select_id'], 2563 'exclude' => $r['exclude'], 2564 'selected' => $r['selected'], 2565 'post_parent' => $r['post_parent'], 2566 'post_type' => $r['post_type'], 2567 'max_depth' => $r['max_depth'], 2568 'page' => $r['page'], 2569 'per_page' => $r['per_page'], 2570 'walker' => $r['walker'], 2571 'posts' => $posts 2572 ) ); 2573 2574 // Filter and return 2575 return apply_filters( 'bbp_get_reply_to_dropdown', $retval, $r, $reply_id, $reply_to, $topic_id ); 2576 } 2577 2578 /** 2480 2579 * Output checked value of reply log edit field 2481 2580 * 2482 2581 * @since bbPress (r31301) -
templates/default/bbpress/form-reply.php
104 104 105 105 <?php endif; ?> 106 106 107 <?php if ( bbp_ allow_revisions() && bbp_is_reply_edit() ) : ?>107 <?php if ( bbp_is_reply_edit() ) : ?> 108 108 109 <?php do_action( 'bbp_theme_before_reply_form_revisions' );?>109 <?php if ( current_user_can( 'moderate' ) ) : ?> 110 110 111 <fieldset class="bbp-form"> 112 <legend> 113 <input name="bbp_log_reply_edit" id="bbp_log_reply_edit" type="checkbox" value="1" <?php bbp_form_reply_log_edit(); ?> tabindex="<?php bbp_tab_index(); ?>" /> 114 <label for="bbp_log_reply_edit"><?php _e( 'Keep a log of this edit:', 'bbpress' ); ?></label><br /> 115 </legend> 111 <?php do_action( 'bbp_theme_before_reply_form_reply_to' ); ?> 116 112 117 <div> 118 <label for="bbp_reply_edit_reason"><?php printf( __( 'Optional reason for editing:', 'bbpress' ), bbp_get_current_user_name() ); ?></label><br /> 119 <input type="text" value="<?php bbp_form_reply_edit_reason(); ?>" tabindex="<?php bbp_tab_index(); ?>" size="40" name="bbp_reply_edit_reason" id="bbp_reply_edit_reason" /> 120 </div> 121 </fieldset> 113 <p class="form-reply-to"> 114 <label for="bbp_reply_to"><?php _e( 'Reply To:', 'bbpress' ); ?></label><br /> 115 <?php bbp_reply_to_dropdown(); ?> 116 </p> 122 117 123 <?php do_action( 'bbp_theme_after_reply_form_revisions' ); ?>118 <?php do_action( 'bbp_theme_after_reply_form_reply_to' ); ?> 124 119 120 <?php endif; ?> 121 122 <?php if ( bbp_allow_revisions() ) : ?> 123 124 <?php do_action( 'bbp_theme_before_reply_form_revisions' ); ?> 125 126 <fieldset class="bbp-form"> 127 <legend> 128 <input name="bbp_log_reply_edit" id="bbp_log_reply_edit" type="checkbox" value="1" <?php bbp_form_reply_log_edit(); ?> tabindex="<?php bbp_tab_index(); ?>" /> 129 <label for="bbp_log_reply_edit"><?php _e( 'Keep a log of this edit:', 'bbpress' ); ?></label><br /> 130 </legend> 131 132 <div> 133 <label for="bbp_reply_edit_reason"><?php printf( __( 'Optional reason for editing:', 'bbpress' ), bbp_get_current_user_name() ); ?></label><br /> 134 <input type="text" value="<?php bbp_form_reply_edit_reason(); ?>" tabindex="<?php bbp_tab_index(); ?>" size="40" name="bbp_reply_edit_reason" id="bbp_reply_edit_reason" /> 135 </div> 136 </fieldset> 137 138 <?php do_action( 'bbp_theme_after_reply_form_revisions' ); ?> 139 140 <?php endif; ?> 141 125 142 <?php endif; ?> 126 143 127 144 <?php do_action( 'bbp_theme_before_reply_form_submit_wrapper' ); ?>