PluginProbe
bbPress / 2.1-rc4
bbPress v2.1-rc4
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / bbp-includes / bbp-reply-template.php

bbp-reply-template.php in bbPress 2.1-rc4, at bbp-includes/bbp-reply-template.php

1,976 lines 64.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Reply Template Tags
5 *
6 * @package bbPress
7 * @subpackage TemplateTags
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Post Type *****************************************************************/
14
15 /**
16 * Return the unique id of the custom post type for replies
17 *
18 * @since bbPress (r2857)
19 *
20 * @uses bbp_get_reply_post_type() To get the reply post type
21 */
22 function bbp_reply_post_type() {
23 echo bbp_get_reply_post_type();
24 }
25 /**
26 * Return the unique id of the custom post type for replies
27 *
28 * @since bbPress (r2857)
29 *
30 * @uses apply_filters() Calls 'bbp_get_forum_post_type' with the forum
31 * post type id
32 * @return string The unique reply post type id
33 */
34 function bbp_get_reply_post_type() {
35 return apply_filters( 'bbp_get_reply_post_type', bbpress()->reply_post_type );
36 }
37
38 /** Reply Loop Functions ******************************************************/
39
40 /**
41 * The main reply loop. WordPress makes this easy for us
42 *
43 * @since bbPress (r2553)
44 *
45 * @param mixed $args All the arguments supported by {@link WP_Query}
46 * @uses bbp_show_lead_topic() Are we showing the topic as a lead?
47 * @uses bbp_get_topic_id() To get the topic id
48 * @uses bbp_get_reply_post_type() To get the reply post type
49 * @uses bbp_get_topic_post_type() To get the topic post type
50 * @uses bbp_is_query_name() To check if we are getting replies for a widget
51 * @uses get_option() To get the replies per page option
52 * @uses bbp_get_paged() To get the current page value
53 * @uses current_user_can() To check if the current user is capable of editing
54 * others' replies
55 * @uses WP_Query To make query and get the replies
56 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
57 * @uses get_permalink() To get the permalink
58 * @uses add_query_arg() To add custom args to the url
59 * @uses apply_filters() Calls 'bbp_replies_pagination' with the pagination args
60 * @uses paginate_links() To paginate the links
61 * @uses apply_filters() Calls 'bbp_has_replies' with
62 * bbPres::reply_query::have_posts()
63 * and bbPres::reply_query
64 * @return object Multidimensional array of reply information
65 */
66 function bbp_has_replies( $args = '' ) {
67 global $wp_rewrite;
68
69 // Default status
70 $default_status = join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) );
71
72 // Skip topic_id if in the replies widget query
73 $parent_args['meta_query'] = array( array(
74 'key' => '_bbp_topic_id',
75 'value' => bbp_get_topic_id(),
76 'compare' => '='
77 ) );
78
79 // What are the default allowed statuses (based on user caps)
80 if ( bbp_get_view_all( 'edit_others_replies' ) )
81 $default_status = join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id() ) );
82
83 // Default query args
84 $default = array(
85 'post_type' => bbp_show_lead_topic() ? bbp_get_reply_post_type() : array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ),
86 'orderby' => 'date', // 'author', 'date', 'title', 'modified', 'parent', rand',
87 'order' => 'ASC', // 'ASC', 'DESC'
88 'posts_per_page' => bbp_get_replies_per_page(), // Max number
89 'paged' => bbp_get_paged(), // Page Number
90 's' => !empty( $_REQUEST['rs'] ) ? $_REQUEST['rs'] : '', // Reply Search
91 'post_status' => $default_status // Post Status
92 );
93
94 // Merge the default args and parent args together
95 if ( !empty( $parent_args ) )
96 $default = array_merge( $parent_args, $default );
97
98 // Set up topic variables
99 $bbp_r = bbp_parse_args( $args, $default, 'has_replies' );
100
101 // Extract the query variables
102 extract( $bbp_r );
103
104 // Get bbPress
105 $bbp = bbpress();
106
107 // Call the query
108 $bbp->reply_query = new WP_Query( $bbp_r );
109
110 // Add pagination values to query object
111 $bbp->reply_query->posts_per_page = $posts_per_page;
112 $bbp->reply_query->paged = $paged;
113
114 // Only add pagination if query returned results
115 if ( (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) {
116
117 // If pretty permalinks are enabled, make our pagination pretty
118 if ( $wp_rewrite->using_permalinks() ) {
119
120 // Page or single
121 if ( is_page() || is_single() ) {
122 $base = get_permalink();
123
124 // Topic
125 } else {
126 $base = get_permalink( bbp_get_topic_id() );
127 }
128
129 $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
130
131 // Unpretty permalinks
132 } else {
133 $base = add_query_arg( 'paged', '%#%' );
134 }
135
136 // Pagination settings with filter
137 $bbp_replies_pagination = apply_filters( 'bbp_replies_pagination', array(
138 'base' => $base,
139 'format' => '',
140 'total' => ceil( (int) $bbp->reply_query->found_posts / (int) $posts_per_page ),
141 'current' => (int) $bbp->reply_query->paged,
142 'prev_text' => '&larr;',
143 'next_text' => '&rarr;',
144 'mid_size' => 1,
145 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false
146 ) );
147
148 // Add pagination to query object
149 $bbp->reply_query->pagination_links = paginate_links( $bbp_replies_pagination );
150
151 // Remove first page from pagination
152 if ( $wp_rewrite->using_permalinks() )
153 $bbp->reply_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links );
154 else
155 $bbp->reply_query->pagination_links = str_replace( '&#038;paged=1', '', $bbp->reply_query->pagination_links );
156 }
157
158 // Return object
159 return apply_filters( 'bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query );
160 }
161
162 /**
163 * Whether there are more replies available in the loop
164 *
165 * @since bbPress (r2553)
166 *
167 * @uses WP_Query bbPress::reply_query::have_posts() To check if there are more
168 * replies available
169 * @return object Replies information
170 */
171 function bbp_replies() {
172
173 // Put into variable to check against next
174 $have_posts = bbpress()->reply_query->have_posts();
175
176 // Reset the post data when finished
177 if ( empty( $have_posts ) )
178 wp_reset_postdata();
179
180 return $have_posts;
181 }
182
183 /**
184 * Loads up the current reply in the loop
185 *
186 * @since bbPress (r2553)
187 *
188 * @uses WP_Query bbPress::reply_query::the_post() To get the current reply
189 * @return object Reply information
190 */
191 function bbp_the_reply() {
192 return bbpress()->reply_query->the_post();
193 }
194
195 /**
196 * Output reply id
197 *
198 * @since bbPress (r2553)
199 *
200 * @param $reply_id Optional. Used to check emptiness
201 * @uses bbp_get_reply_id() To get the reply id
202 */
203 function bbp_reply_id( $reply_id = 0 ) {
204 echo bbp_get_reply_id( $reply_id );
205 }
206 /**
207 * Return the id of the reply in a replies loop
208 *
209 * @since bbPress (r2553)
210 *
211 * @param $reply_id Optional. Used to check emptiness
212 * @uses bbPress::reply_query::post::ID To get the reply id
213 * @uses bbp_is_reply() To check if it's a reply page
214 * @uses bbp_is_reply_edit() To check if it's a reply edit page
215 * @uses get_post_field() To get the post's post type
216 * @uses WP_Query::post::ID To get the reply id
217 * @uses bbp_get_reply_post_type() To get the reply post type
218 * @uses apply_filters() Calls 'bbp_get_reply_id' with the reply id and
219 * supplied reply id
220 * @return int The reply id
221 */
222 function bbp_get_reply_id( $reply_id = 0 ) {
223 global $wp_query;
224
225 $bbp = bbpress();
226
227 // Easy empty checking
228 if ( !empty( $reply_id ) && is_numeric( $reply_id ) )
229 $bbp_reply_id = $reply_id;
230
231 // Currently inside a replies loop
232 elseif ( !empty( $bbp->reply_query->in_the_loop ) && isset( $bbp->reply_query->post->ID ) )
233 $bbp_reply_id = $bbp->reply_query->post->ID;
234
235 // Currently viewing a forum
236 elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && !empty( $bbp->current_reply_id ) )
237 $bbp_reply_id = $bbp->current_reply_id;
238
239 // Currently viewing a reply
240 elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) )
241 $bbp_reply_id = $wp_query->post->ID;
242
243 // Fallback
244 else
245 $bbp_reply_id = 0;
246
247 return (int) apply_filters( 'bbp_get_reply_id', (int) $bbp_reply_id, $reply_id );
248 }
249
250 /**
251 * Gets a reply
252 *
253 * @since bbPress (r2787)
254 *
255 * @param int|object $reply reply id or reply object
256 * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
257 * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
258 * @uses get_post() To get the reply
259 * @uses bbp_get_reply_post_type() To get the reply post type
260 * @uses apply_filters() Calls 'bbp_get_reply' with the reply, output type and
261 * sanitation filter
262 * @return mixed Null if error or reply (in specified form) if success
263 */
264 function bbp_get_reply( $reply, $output = OBJECT, $filter = 'raw' ) {
265 if ( empty( $reply ) || is_numeric( $reply ) )
266 $reply = bbp_get_reply_id( $reply );
267
268 $reply = get_post( $reply, OBJECT, $filter );
269 if ( empty( $reply ) )
270 return $reply;
271
272 if ( $reply->post_type !== bbp_get_reply_post_type() )
273 return null;
274
275 if ( $output == OBJECT ) {
276 return $reply;
277
278 } elseif ( $output == ARRAY_A ) {
279 $_reply = get_object_vars( $reply );
280 return $_reply;
281
282 } elseif ( $output == ARRAY_N ) {
283 $_reply = array_values( get_object_vars( $reply ) );
284 return $_reply;
285
286 }
287
288 return apply_filters( 'bbp_get_reply', $reply, $output, $filter );
289 }
290
291 /**
292 * Output the link to the reply in the reply loop
293 *
294 * @since bbPress (r2553)
295 *
296 * @param int $reply_id Optional. Reply id
297 * @uses bbp_get_reply_permalink() To get the reply permalink
298 */
299 function bbp_reply_permalink( $reply_id = 0 ) {
300 echo bbp_get_reply_permalink( $reply_id );
301 }
302 /**
303 * Return the link to the reply
304 *
305 * @since bbPress (r2553)
306 *
307 * @param int $reply_id Optional. Reply id
308 * @uses bbp_get_reply_id() To get the reply id
309 * @uses get_permalink() To get the permalink of the reply
310 * @uses apply_filters() Calls 'bbp_get_reply_permalink' with the link
311 * and reply id
312 * @return string Permanent link to reply
313 */
314 function bbp_get_reply_permalink( $reply_id = 0 ) {
315 $reply_id = bbp_get_reply_id( $reply_id );
316
317 return apply_filters( 'bbp_get_reply_permalink', get_permalink( $reply_id ), $reply_id );
318 }
319 /**
320 * Output the paginated url to the reply in the reply loop
321 *
322 * @since bbPress (r2679)
323 *
324 * @param int $reply_id Optional. Reply id
325 * @uses bbp_get_reply_url() To get the reply url
326 */
327 function bbp_reply_url( $reply_id = 0 ) {
328 echo bbp_get_reply_url( $reply_id );
329 }
330 /**
331 * Return the paginated url to the reply in the reply loop
332 *
333 * @since bbPress (r2679)
334 *
335 * @param int $reply_id Optional. Reply id
336 * @param $string $redirect_to Optional. Pass a redirect value for use with
337 * shortcodes and other fun things.
338 * @uses bbp_get_reply_id() To get the reply id
339 * @uses bbp_get_reply_topic_id() To get the reply topic id
340 * @uses bbp_get_topic_permalink() To get the topic permalink
341 * @uses bbp_get_reply_position() To get the reply position
342 * @uses get_option() To get the replies per page option
343 * @uses WP_Rewrite::using_permalinks() To check if the blog uses
344 * permalinks
345 * @uses add_query_arg() To add custom args to the url
346 * @uses apply_filters() Calls 'bbp_get_reply_url' with the reply url,
347 * reply id and bool count hidden
348 * @return string Link to reply relative to paginated topic
349 */
350 function bbp_get_reply_url( $reply_id = 0, $redirect_to = '' ) {
351
352 // Set needed variables
353 $reply_id = bbp_get_reply_id ( $reply_id );
354 $topic_id = bbp_get_reply_topic_id( $reply_id );
355 $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() );
356 $reply_hash = '#post-' . $reply_id;
357 $topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to );
358 $topic_url = remove_query_arg( 'view', $topic_link );
359
360 // Don't include pagination if on first page
361 if ( 1 >= $reply_page ) {
362 $url = trailingslashit( $topic_url ) . $reply_hash;
363
364 // Include pagination
365 } else {
366 global $wp_rewrite;
367
368 // Pretty permalinks
369 if ( $wp_rewrite->using_permalinks() ) {
370 $url = trailingslashit( $topic_url ) . trailingslashit( $wp_rewrite->pagination_base ) . trailingslashit( $reply_page ) . $reply_hash;
371
372 // Yucky links
373 } else {
374 $url = add_query_arg( 'paged', $reply_page, $topic_url ) . $reply_hash;
375 }
376 }
377
378 // Add topic view query arg back to end if it is set
379 if ( bbp_get_view_all() )
380 $url = bbp_add_view_all( $url );
381
382 return apply_filters( 'bbp_get_reply_url', $url, $reply_id, $redirect_to );
383 }
384
385 /**
386 * Output the title of the reply
387 *
388 * @since bbPress (r2553)
389 *
390 * @param int $reply_id Optional. Reply id
391 * @uses bbp_get_reply_title() To get the reply title
392 */
393 function bbp_reply_title( $reply_id = 0 ) {
394 echo bbp_get_reply_title( $reply_id );
395 }
396
397 /**
398 * Return the title of the reply
399 *
400 * @since bbPress (r2553)
401 *
402 * @param int $reply_id Optional. Reply id
403 * @uses bbp_get_reply_id() To get the reply id
404 * @uses get_the_title() To get the reply title
405 * @uses apply_filters() Calls 'bbp_get_reply_title' with the title and
406 * reply id
407 * @return string Title of reply
408 */
409 function bbp_get_reply_title( $reply_id = 0 ) {
410 $reply_id = bbp_get_reply_id( $reply_id );
411
412 return apply_filters( 'bbp_get_reply_title', get_the_title( $reply_id ), $reply_id );
413 }
414
415 /**
416 * Output the content of the reply
417 *
418 * @since bbPress (r2553)
419 *
420 * @param int $reply_id Optional. reply id
421 * @uses bbp_get_reply_content() To get the reply content
422 */
423 function bbp_reply_content( $reply_id = 0 ) {
424 echo bbp_get_reply_content( $reply_id );
425 }
426 /**
427 * Return the content of the reply
428 *
429 * @since bbPress (r2780)
430 *
431 * @param int $reply_id Optional. reply id
432 * @uses bbp_get_reply_id() To get the reply id
433 * @uses post_password_required() To check if the reply requires pass
434 * @uses get_the_password_form() To get the password form
435 * @uses get_post_field() To get the content post field
436 * @uses apply_filters() Calls 'bbp_get_reply_content' with the content
437 * and reply id
438 * @return string Content of the reply
439 */
440 function bbp_get_reply_content( $reply_id = 0 ) {
441 $reply_id = bbp_get_reply_id( $reply_id );
442
443 // Check if password is required
444 if ( post_password_required( $reply_id ) )
445 return get_the_password_form();
446
447 $content = get_post_field( 'post_content', $reply_id );
448
449 return apply_filters( 'bbp_get_reply_content', $content, $reply_id );
450 }
451
452 /**
453 * Output the excerpt of the reply
454 *
455 * @since bbPress (r2751)
456 *
457 * @param int $reply_id Optional. Reply id
458 * @param int $length Optional. Length of the excerpt. Defaults to 100 letters
459 * @uses bbp_get_reply_excerpt() To get the reply excerpt
460 */
461 function bbp_reply_excerpt( $reply_id = 0, $length = 100 ) {
462 echo bbp_get_reply_excerpt( $reply_id, $length );
463 }
464 /**
465 * Return the excerpt of the reply
466 *
467 * @since bbPress (r2751)
468 *
469 * @param int $reply_id Optional. Reply id
470 * @param int $length Optional. Length of the excerpt. Defaults to 100
471 * letters
472 * @uses bbp_get_reply_id() To get the reply id
473 * @uses get_post_field() To get the excerpt
474 * @uses bbp_get_reply_content() To get the reply content
475 * @uses apply_filters() Calls 'bbp_get_reply_excerpt' with the excerpt,
476 * reply id and length
477 * @return string Reply Excerpt
478 */
479 function bbp_get_reply_excerpt( $reply_id = 0, $length = 100 ) {
480 $reply_id = bbp_get_reply_id( $reply_id );
481 $length = (int) $length;
482 $excerpt = get_post_field( $reply_id, 'post_excerpt' );
483
484 if ( empty( $excerpt ) )
485 $excerpt = bbp_get_reply_content( $reply_id );
486
487 $excerpt = trim ( strip_tags( $excerpt ) );
488
489 if ( !empty( $length ) && strlen( $excerpt ) > $length ) {
490 $excerpt = substr( $excerpt, 0, $length - 1 );
491 $excerpt .= '&hellip;';
492 }
493
494 return apply_filters( 'bbp_get_reply_excerpt', $excerpt, $reply_id, $length );
495 }
496
497 /**
498 * Append revisions to the reply content
499 *
500 * @since bbPress (r2782)
501 *
502 * @param string $content Optional. Content to which we need to append the revisions to
503 * @param int $reply_id Optional. Reply id
504 * @uses bbp_get_reply_revision_log() To get the reply revision log
505 * @uses apply_filters() Calls 'bbp_reply_append_revisions' with the processed
506 * content, original content and reply id
507 * @return string Content with the revisions appended
508 */
509 function bbp_reply_content_append_revisions( $content = '', $reply_id = 0 ) {
510
511 // Bail if in admin or feed
512 if ( is_admin() || is_feed() )
513 return $content;
514
515 // Validate the ID
516 $reply_id = bbp_get_reply_id( $reply_id );
517
518 return apply_filters( 'bbp_reply_append_revisions', $content . bbp_get_reply_revision_log( $reply_id ), $content, $reply_id );
519 }
520
521 /**
522 * Output the revision log of the reply
523 *
524 * @since bbPress (r2782)
525 *
526 * @param int $reply_id Optional. Reply id
527 * @uses bbp_get_reply_revision_log() To get the reply revision log
528 */
529 function bbp_reply_revision_log( $reply_id = 0 ) {
530 echo bbp_get_reply_revision_log( $reply_id );
531 }
532 /**
533 * Return the formatted revision log of the reply
534 *
535 * @since bbPress (r2782)
536 *
537 * @param int $reply_id Optional. Reply id
538 * @uses bbp_get_reply_id() To get the reply id
539 * @uses bbp_get_reply_revisions() To get the reply revisions
540 * @uses bbp_get_reply_raw_revision_log() To get the raw revision log
541 * @uses bbp_get_reply_author_display_name() To get the reply author
542 * @uses bbp_get_reply_author_link() To get the reply author link
543 * @uses bbp_convert_date() To convert the date
544 * @uses bbp_get_time_since() To get the time in since format
545 * @uses apply_filters() Calls 'bbp_get_reply_revision_log' with the
546 * log and reply id
547 * @return string Revision log of the reply
548 */
549 function bbp_get_reply_revision_log( $reply_id = 0 ) {
550
551 // Create necessary variables
552 $reply_id = bbp_get_reply_id( $reply_id );
553 $revision_log = bbp_get_reply_raw_revision_log( $reply_id );
554
555 // Check reply and revision log exist
556 if ( empty( $reply_id ) || empty( $revision_log ) || !is_array( $revision_log ) )
557 return false;
558
559 // Get the actual revisions
560 $revisions = bbp_get_reply_revisions( $reply_id );
561 if ( empty( $revisions ) )
562 return false;
563
564 $r = "\n\n" . '<ul id="bbp-reply-revision-log-' . $reply_id . '" class="bbp-reply-revision-log">' . "\n\n";
565
566 // Loop through revisions
567 foreach ( (array) $revisions as $revision ) {
568
569 if ( empty( $revision_log[$revision->ID] ) ) {
570 $author_id = $revision->post_author;
571 $reason = '';
572 } else {
573 $author_id = $revision_log[$revision->ID]['author'];
574 $reason = $revision_log[$revision->ID]['reason'];
575 }
576
577 $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_reply_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) );
578 $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) );
579
580 $r .= "\t" . '<li id="bbp-reply-revision-log-' . $reply_id . '-item-' . $revision->ID . '" class="bbp-reply-revision-log-item">' . "\n";
581 if ( !empty( $reason ) ) {
582 $r .= "\t\t" . sprintf( __( 'This reply was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), $since, $author, $reason ) . "\n";
583 } else {
584 $r .= "\t\t" . sprintf( __( 'This reply was modified %1$s by %2$s.', 'bbpress' ), $since, $author ) . "\n";
585 }
586 $r .= "\t" . '</li>' . "\n";
587
588 }
589
590 $r .= "\n" . '</ul>' . "\n\n";
591
592 return apply_filters( 'bbp_get_reply_revision_log', $r, $reply_id );
593 }
594 /**
595 * Return the raw revision log of the reply
596 *
597 * @since bbPress (r2782)
598 *
599 * @param int $reply_id Optional. Reply id
600 * @uses bbp_get_reply_id() To get the reply id
601 * @uses get_post_meta() To get the revision log meta
602 * @uses apply_filters() Calls 'bbp_get_reply_raw_revision_log'
603 * with the log and reply id
604 * @return string Raw revision log of the reply
605 */
606 function bbp_get_reply_raw_revision_log( $reply_id = 0 ) {
607 $reply_id = bbp_get_reply_id( $reply_id );
608 $revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true );
609 $revision_log = empty( $revision_log ) ? array() : $revision_log;
610
611 return apply_filters( 'bbp_get_reply_raw_revision_log', $revision_log, $reply_id );
612 }
613
614 /**
615 * Return the revisions of the reply
616 *
617 * @since bbPress (r2782)
618 *
619 * @param int $reply_id Optional. Reply id
620 * @uses bbp_get_reply_id() To get the reply id
621 * @uses wp_get_post_revisions() To get the reply revisions
622 * @uses apply_filters() Calls 'bbp_get_reply_revisions'
623 * with the revisions and reply id
624 * @return string reply revisions
625 */
626 function bbp_get_reply_revisions( $reply_id = 0 ) {
627 $reply_id = bbp_get_reply_id( $reply_id );
628 $revisions = wp_get_post_revisions( $reply_id, array( 'order' => 'ASC' ) );
629
630 return apply_filters( 'bbp_get_reply_revisions', $revisions, $reply_id );
631 }
632
633 /**
634 * Return the revision count of the reply
635 *
636 * @since bbPress (r2782)
637 *
638 * @param int $reply_id Optional. Reply id
639 * @uses bbp_get_reply_revisions() To get the reply revisions
640 * @uses apply_filters() Calls 'bbp_get_reply_revision_count'
641 * with the revision count and reply id
642 * @return string reply revision count
643 */
644 function bbp_get_reply_revision_count( $reply_id = 0 ) {
645 return apply_filters( 'bbp_get_reply_revisions', count( bbp_get_reply_revisions( $reply_id ) ), $reply_id );
646 }
647
648 /**
649 * Output the status of the reply
650 *
651 * @since bbPress (r2667)
652 *
653 * @param int $reply_id Optional. Reply id
654 * @uses bbp_get_reply_status() To get the reply status
655 */
656 function bbp_reply_status( $reply_id = 0 ) {
657 echo bbp_get_reply_status( $reply_id );
658 }
659 /**
660 * Return the status of the reply
661 *
662 * @since bbPress (r2667)
663 *
664 * @param int $reply_id Optional. Reply id
665 * @uses bbp_get_reply_id() To get the reply id
666 * @uses get_post_status() To get the reply status
667 * @uses apply_filters() Calls 'bbp_get_reply_status' with the reply id
668 * @return string Status of reply
669 */
670 function bbp_get_reply_status( $reply_id = 0 ) {
671 $reply_id = bbp_get_reply_id( $reply_id );
672 return apply_filters( 'bbp_get_reply_status', get_post_status( $reply_id ), $reply_id );
673 }
674
675 /**
676 * Is the reply not spam or deleted?
677 *
678 * @since bbPress (r3496)
679 *
680 * @param int $reply_id Optional. Topic id
681 * @uses bbp_get_reply_id() To get the reply id
682 * @uses bbp_get_reply_status() To get the reply status
683 * @return bool True if published, false if not.
684 */
685 function bbp_is_reply_published( $reply_id = 0 ) {
686 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) == bbp_get_public_status_id();
687 return (bool) apply_filters( 'bbp_is_reply_published', (bool) $reply_status, $reply_id );
688 }
689
690 /**
691 * Is the reply marked as spam?
692 *
693 * @since bbPress (r2740)
694 *
695 * @param int $reply_id Optional. Reply id
696 * @uses bbp_get_reply_id() To get the reply id
697 * @uses bbp_get_reply_status() To get the reply status
698 * @return bool True if spam, false if not.
699 */
700 function bbp_is_reply_spam( $reply_id = 0 ) {
701 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) == bbp_get_spam_status_id();
702 return (bool) apply_filters( 'bbp_is_reply_spam', (bool) $reply_status, $reply_id );
703 }
704
705 /**
706 * Is the reply trashed?
707 *
708 * @since bbPress (r2884)
709 *
710 * @param int $reply_id Optional. Topic id
711 * @uses bbp_get_reply_id() To get the reply id
712 * @uses bbp_get_reply_status() To get the reply status
713 * @return bool True if spam, false if not.
714 */
715 function bbp_is_reply_trash( $reply_id = 0 ) {
716 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) == bbp_get_trash_status_id();
717 return (bool) apply_filters( 'bbp_is_reply_trash', (bool) $reply_status, $reply_id );
718 }
719
720 /**
721 * Is the reply by an anonymous user?
722 *
723 * @since bbPress (r2753)
724 *
725 * @param int $reply_id Optional. Reply id
726 * @uses bbp_get_reply_id() To get the reply id
727 * @uses bbp_get_reply_author_id() To get the reply author id
728 * @uses get_post_meta() To get the anonymous name and email metas
729 * @return bool True if the post is by an anonymous user, false if not.
730 */
731 function bbp_is_reply_anonymous( $reply_id = 0 ) {
732 $reply_id = bbp_get_reply_id( $reply_id );
733 $retval = false;
734
735 if ( !bbp_get_reply_author_id( $reply_id ) )
736 $retval = true;
737
738 elseif ( get_post_meta( $reply_id, '_bbp_anonymous_name', true ) )
739 $retval = true;
740
741 elseif ( get_post_meta( $reply_id, '_bbp_anonymous_email', true ) )
742 $retval = true;
743
744 return (bool) apply_filters( 'bbp_is_reply_anonymous', $retval, $reply_id );
745 }
746
747 /**
748 * Output the author of the reply
749 *
750 * @since bbPress (r2667)
751 *
752 * @param int $reply_id Optional. Reply id
753 * @uses bbp_get_reply_author() To get the reply author
754 */
755 function bbp_reply_author( $reply_id = 0 ) {
756 echo bbp_get_reply_author( $reply_id );
757 }
758 /**
759 * Return the author of the reply
760 *
761 * @since bbPress (r2667)
762 *
763 * @param int $reply_id Optional. Reply id
764 * @uses bbp_get_reply_id() To get the reply id
765 * @uses bbp_is_reply_anonymous() To check if the reply is by an
766 * anonymous user
767 * @uses get_the_author_meta() To get the reply author display name
768 * @uses get_post_meta() To get the anonymous poster name
769 * @uses apply_filters() Calls 'bbp_get_reply_author' with the reply
770 * author and reply id
771 * @return string Author of reply
772 */
773 function bbp_get_reply_author( $reply_id = 0 ) {
774 $reply_id = bbp_get_reply_id( $reply_id );
775
776 if ( !bbp_is_reply_anonymous( $reply_id ) )
777 $author = get_the_author_meta( 'display_name', bbp_get_reply_author_id( $reply_id ) );
778 else
779 $author = get_post_meta( $reply_id, '_bbp_anonymous_name', true );
780
781 return apply_filters( 'bbp_get_reply_author', $author, $reply_id );
782 }
783
784 /**
785 * Output the author ID of the reply
786 *
787 * @since bbPress (r2667)
788 *
789 * @param int $reply_id Optional. Reply id
790 * @uses bbp_get_reply_author_id() To get the reply author id
791 */
792 function bbp_reply_author_id( $reply_id = 0 ) {
793 echo bbp_get_reply_author_id( $reply_id );
794 }
795 /**
796 * Return the author ID of the reply
797 *
798 * @since bbPress (r2667)
799 *
800 * @param int $reply_id Optional. Reply id
801 * @uses bbp_get_reply_id() To get the reply id
802 * @uses get_post_field() To get the reply author id
803 * @uses apply_filters() Calls 'bbp_get_reply_author_id' with the author
804 * id and reply id
805 * @return string Author id of reply
806 */
807 function bbp_get_reply_author_id( $reply_id = 0 ) {
808 $reply_id = bbp_get_reply_id( $reply_id );
809 $author_id = get_post_field( 'post_author', $reply_id );
810
811 return (int) apply_filters( 'bbp_get_reply_author_id', (int) $author_id, $reply_id );
812 }
813
814 /**
815 * Output the author display_name of the reply
816 *
817 * @since bbPress (r2667)
818 *
819 * @param int $reply_id Optional. Reply id
820 * @uses bbp_get_reply_author_display_name()
821 */
822 function bbp_reply_author_display_name( $reply_id = 0 ) {
823 echo bbp_get_reply_author_display_name( $reply_id );
824 }
825 /**
826 * Return the author display_name of the reply
827 *
828 * @since bbPress (r2667)
829 *
830 * @param int $reply_id Optional. Reply id
831 * @uses bbp_get_reply_id() To get the reply id
832 * @uses bbp_is_reply_anonymous() To check if the reply is by an
833 * anonymous user
834 * @uses bbp_get_reply_author_id() To get the reply author id
835 * @uses get_the_author_meta() To get the reply author's display name
836 * @uses get_post_meta() To get the anonymous poster's name
837 * @uses apply_filters() Calls 'bbp_get_reply_author_display_name' with
838 * the author display name and reply id
839 * @return string Reply's author's display name
840 */
841 function bbp_get_reply_author_display_name( $reply_id = 0 ) {
842 $reply_id = bbp_get_reply_id( $reply_id );
843
844 // User is not a guest
845 if ( !bbp_is_reply_anonymous( $reply_id ) ) {
846
847 // Get the author ID
848 $author_id = bbp_get_reply_author_id( $reply_id );
849
850 // Try to get a display name
851 $author_name = get_the_author_meta( 'display_name', $author_id );
852
853 // Fall back to user login
854 if ( empty( $author_name ) ) {
855 $author_name = get_the_author_meta( 'user_login', $author_id );
856 }
857
858 // User does not have an account
859 } else {
860 $author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true );
861 }
862
863 // If nothing could be found anywhere, use Anonymous
864 if ( empty( $author_name ) )
865 $author_name = __( 'Anonymous', 'bbpress' );
866
867 return apply_filters( 'bbp_get_reply_author_display_name', esc_attr( $author_name ), $reply_id );
868 }
869
870 /**
871 * Output the author avatar of the reply
872 *
873 * @since bbPress (r2667)
874 *
875 * @param int $reply_id Optional. Reply id
876 * @param int $size Optional. Size of the avatar. Defaults to 40
877 * @uses bbp_get_reply_author_avatar() To get the reply author id
878 */
879 function bbp_reply_author_avatar( $reply_id = 0, $size = 40 ) {
880 echo bbp_get_reply_author_avatar( $reply_id, $size );
881 }
882 /**
883 * Return the author avatar of the reply
884 *
885 * @since bbPress (r2667)
886 *
887 * @param int $reply_id Optional. Reply id
888 * @param int $size Optional. Size of the avatar. Defaults to 40
889 * @uses bbp_get_reply_id() To get the reply id
890 * @uses bbp_is_reply_anonymous() To check if the reply is by an
891 * anonymous user
892 * @uses bbp_get_reply_author_id() To get the reply author id
893 * @uses get_post_meta() To get the anonymous poster's email id
894 * @uses get_avatar() To get the avatar
895 * @uses apply_filters() Calls 'bbp_get_reply_author_avatar' with the
896 * author avatar, reply id and size
897 * @return string Avatar of author of the reply
898 */
899 function bbp_get_reply_author_avatar( $reply_id = 0, $size = 40 ) {
900 $reply_id = bbp_get_reply_id( $reply_id );
901 if ( !empty( $reply_id ) ) {
902 // Check for anonymous user
903 if ( !bbp_is_reply_anonymous( $reply_id ) ) {
904 $author_avatar = get_avatar( bbp_get_reply_author_id( $reply_id ), $size );
905 } else {
906 $author_avatar = get_avatar( get_post_meta( $reply_id, '_bbp_anonymous_email', true ), $size );
907 }
908 } else {
909 $author_avatar = '';
910 }
911
912 return apply_filters( 'bbp_get_reply_author_avatar', $author_avatar, $reply_id, $size );
913 }
914
915 /**
916 * Output the author link of the reply
917 *
918 * @since bbPress (r2717)
919 *
920 * @param mixed $args Optional. If it is an integer, it is used as reply id.
921 * @uses bbp_get_reply_author_link() To get the reply author link
922 */
923 function bbp_reply_author_link( $args = '' ) {
924 echo bbp_get_reply_author_link( $args );
925 }
926 /**
927 * Return the author link of the reply
928 *
929 * @since bbPress (r2717)
930 *
931 * @param mixed $args Optional. If an integer, it is used as reply id.
932 * @uses bbp_get_reply_id() To get the reply id
933 * @uses bbp_is_reply_anonymous() To check if the reply is by an
934 * anonymous user
935 * @uses bbp_get_reply_author() To get the reply author name
936 * @uses bbp_get_reply_author_url() To get the reply author url
937 * @uses bbp_get_reply_author_avatar() To get the reply author avatar
938 * @uses bbp_get_reply_author_display_name() To get the reply author display
939 * name
940 * @uses bbp_get_user_display_role() To get the reply author display role
941 * @uses bbp_get_reply_author_id() To get the reply author id
942 * @uses apply_filters() Calls 'bbp_get_reply_author_link' with the
943 * author link and args
944 * @return string Author link of reply
945 */
946 function bbp_get_reply_author_link( $args = '' ) {
947 $defaults = array (
948 'post_id' => 0,
949 'link_title' => '',
950 'type' => 'both',
951 'size' => 80,
952 'sep' => '&nbsp;',
953 'show_role' => false
954 );
955 $r = bbp_parse_args( $args, $defaults, 'get_reply_author_link' );
956 extract( $r );
957
958 // Used as reply_id
959 if ( is_numeric( $args ) )
960 $reply_id = bbp_get_reply_id( $args );
961 else
962 $reply_id = bbp_get_reply_id( $post_id );
963
964 if ( !empty( $reply_id ) ) {
965 if ( empty( $link_title ) ) {
966 $link_title = sprintf( !bbp_is_reply_anonymous( $reply_id ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_reply_author_display_name( $reply_id ) );
967 }
968
969 $link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : '';
970 $author_url = bbp_get_reply_author_url( $reply_id );
971 $anonymous = bbp_is_reply_anonymous( $reply_id );
972
973 // Get avatar
974 if ( 'avatar' == $type || 'both' == $type ) {
975 $author_links['avatar'] = bbp_get_reply_author_avatar( $reply_id, $size );
976 }
977
978 // Get display name
979 if ( 'name' == $type || 'both' == $type ) {
980 $author_links['name'] = bbp_get_reply_author_display_name( $reply_id );
981 }
982
983 // Add links if not anonymous
984 if ( empty( $anonymous ) ) {
985 foreach ( $author_links as $link => $link_text ) {
986 $link_class = ' class="bbp-author-' . $link . '"';
987 $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', $author_url, $link_title, $link_class, $link_text );
988 }
989
990 if ( true === $show_role ) {
991 $author_link[] = bbp_get_reply_author_role( array( 'reply_id' => $reply_id ) );
992 }
993
994 $author_link = join( $sep, $author_link );
995
996 // No links if anonymous
997 } else {
998 $author_link = join( $sep, $author_links );
999 }
1000
1001 // No replies so link is empty
1002 } else {
1003 $author_link = '';
1004 }
1005
1006 return apply_filters( 'bbp_get_reply_author_link', $author_link, $args );
1007 }
1008
1009 /**
1010 * Output the author url of the reply
1011 *
1012 * @since bbPress (r2667)
1013 *
1014 * @param int $reply_id Optional. Reply id
1015 * @uses bbp_get_reply_author_url() To get the reply author url
1016 */
1017 function bbp_reply_author_url( $reply_id = 0 ) {
1018 echo bbp_get_reply_author_url( $reply_id );
1019 }
1020 /**
1021 * Return the author url of the reply
1022 *
1023 * @since bbPress (r2667)
1024 *
1025 * @param int $reply_id Optional. Reply id
1026 * @uses bbp_get_reply_id() To get the reply id
1027 * @uses bbp_is_reply_anonymous() To check if the reply is by an anonymous
1028 * user
1029 * @uses bbp_get_reply_author_id() To get the reply author id
1030 * @uses bbp_get_user_profile_url() To get the user profile url
1031 * @uses get_post_meta() To get the anonymous poster's website url
1032 * @uses apply_filters() Calls bbp_get_reply_author_url with the author
1033 * url & reply id
1034 * @return string Author URL of the reply
1035 */
1036 function bbp_get_reply_author_url( $reply_id = 0 ) {
1037 $reply_id = bbp_get_reply_id( $reply_id );
1038
1039 // Check for anonymous user
1040 if ( !bbp_is_reply_anonymous( $reply_id ) ) {
1041 $author_url = bbp_get_user_profile_url( bbp_get_reply_author_id( $reply_id ) );
1042 } else {
1043 $author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true );
1044 if ( empty( $author_url ) ) {
1045 $author_url = '';
1046 }
1047 }
1048
1049 return apply_filters( 'bbp_get_reply_author_url', $author_url, $reply_id );
1050 }
1051
1052 /**
1053 * Output the reply author email address
1054 *
1055 * @since bbPress (r3445)
1056 *
1057 * @param int $reply_id Optional. Reply id
1058 * @uses bbp_get_reply_author_email() To get the reply author email
1059 */
1060 function bbp_reply_author_email( $reply_id = 0 ) {
1061 echo bbp_get_reply_author_email( $reply_id );
1062 }
1063 /**
1064 * Return the reply author email address
1065 *
1066 * @since bbPress (r3445)
1067 *
1068 * @param int $reply_id Optional. Reply id
1069 * @uses bbp_get_reply_id() To get the reply id
1070 * @uses bbp_is_reply_anonymous() To check if the reply is by an anonymous
1071 * user
1072 * @uses bbp_get_reply_author_id() To get the reply author id
1073 * @uses get_userdata() To get the user data
1074 * @uses get_post_meta() To get the anonymous poster's website email
1075 * @uses apply_filters() Calls bbp_get_reply_author_email with the author
1076 * email & reply id
1077 * @return string Reply author email address
1078 */
1079 function bbp_get_reply_author_email( $reply_id = 0 ) {
1080 $reply_id = bbp_get_reply_id( $reply_id );
1081
1082 // Not anonymous
1083 if ( !bbp_is_reply_anonymous( $reply_id ) ) {
1084
1085 // Use reply author email address
1086 $user_id = bbp_get_reply_author_id( $reply_id );
1087 $user = get_userdata( $user_id );
1088 $author_email = !empty( $user->user_email ) ? $user->user_email : '';
1089
1090 // Anonymous
1091 } else {
1092
1093 // Get email from post meta
1094 $author_email = get_post_meta( $reply_id, '_bbp_anonymous_email', true );
1095
1096 // Sanity check for missing email address
1097 if ( empty( $author_email ) ) {
1098 $author_email = '';
1099 }
1100 }
1101
1102 return apply_filters( 'bbp_get_reply_author_email', $author_email, $reply_id );
1103 }
1104
1105 /**
1106 * Output the reply author role
1107 *
1108 * @since bbPress (r3860)
1109 *
1110 * @param array $args Optional.
1111 * @uses bbp_get_reply_author_role() To get the reply author role
1112 */
1113 function bbp_reply_author_role( $args = array() ) {
1114 echo bbp_get_reply_author_role( $args );
1115 }
1116 /**
1117 * Return the reply author role
1118 *
1119 * @since bbPress (r3860)
1120 *
1121 * @param array $args Optional.
1122 * @uses bbp_get_reply_id() To get the reply id
1123 * @uses bbp_get_user_display_role() To get the user display role
1124 * @uses bbp_get_reply_author_id() To get the reply author id
1125 * @uses apply_filters() Calls bbp_get_reply_author_role with the author
1126 * role & args
1127 * @return string Reply author role
1128 */
1129 function bbp_get_reply_author_role( $args = array() ) {
1130 $defaults = array(
1131 'reply_id' => 0,
1132 'class' => 'bbp-author-role',
1133 'before' => '',
1134 'after' => ''
1135 );
1136 $args = bbp_parse_args( $args, $defaults, 'get_reply_author_role' );
1137 extract( $args, EXTR_SKIP );
1138
1139 $reply_id = bbp_get_reply_id( $reply_id );
1140 $role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );
1141 $author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $before, $class, $role, $after );
1142
1143 return apply_filters( 'bbp_get_reply_author_role', $author_role, $args );
1144 }
1145
1146 /**
1147 * Output the topic title a reply belongs to
1148 *
1149 * @since bbPress (r2553)
1150 *
1151 * @param int $reply_id Optional. Reply id
1152 * @uses bbp_get_reply_topic_title() To get the reply topic title
1153 */
1154 function bbp_reply_topic_title( $reply_id = 0 ) {
1155 echo bbp_get_reply_topic_title( $reply_id );
1156 }
1157 /**
1158 * Return the topic title a reply belongs to
1159 *
1160 * @since bbPress (r2553)
1161 *
1162 * @param int $reply_id Optional. Reply id
1163 * @uses bbp_get_reply_id() To get the reply id
1164 * @uses bbp_get_reply_topic_id() To get the reply topic id
1165 * @uses bbp_get_topic_title() To get the reply topic title
1166 * @uses apply_filters() Calls 'bbp_get_reply_topic_title' with the
1167 * topic title and reply id
1168 * @return string Reply's topic's title
1169 */
1170 function bbp_get_reply_topic_title( $reply_id = 0 ) {
1171 $reply_id = bbp_get_reply_id( $reply_id );
1172 $topic_id = bbp_get_reply_topic_id( $reply_id );
1173
1174 return apply_filters( 'bbp_get_reply_topic_title', bbp_get_topic_title( $topic_id ), $reply_id );
1175 }
1176
1177 /**
1178 * Output the topic id a reply belongs to
1179 *
1180 * @since bbPress (r2553)
1181 *
1182 * @param int $reply_id Optional. Reply id
1183 * @uses bbp_get_reply_topic_id() To get the reply topic id
1184 */
1185 function bbp_reply_topic_id( $reply_id = 0 ) {
1186 echo bbp_get_reply_topic_id( $reply_id );
1187 }
1188 /**
1189 * Return the topic id a reply belongs to
1190 *
1191 * @since bbPress (r2553)
1192 *
1193 * @param int $reply_id Optional. Reply id
1194 * @uses bbp_get_reply_id() To get the reply id
1195 * @uses get_post_meta() To get the reply topic id from meta
1196 * @uses bbp_get_topic_id() To get the topic id
1197 * @uses apply_filters() Calls 'bbp_get_reply_topic_id' with the topic
1198 * id and reply id
1199 * @return int Reply's topic id
1200 */
1201 function bbp_get_reply_topic_id( $reply_id = 0 ) {
1202
1203 // Assume there is no topic id
1204 $topic_id = 0;
1205
1206 // Check that reply_id is valid
1207 if ( $reply_id = bbp_get_reply_id( $reply_id ) )
1208
1209 // Get topic_id from reply
1210 if ( $topic_id = get_post_meta( $reply_id, '_bbp_topic_id', true ) )
1211
1212 // Validate the topic_id
1213 $topic_id = bbp_get_topic_id( $topic_id );
1214
1215 return apply_filters( 'bbp_get_reply_topic_id', (int) $topic_id, $reply_id );
1216 }
1217
1218 /**
1219 * Output the forum id a reply belongs to
1220 *
1221 * @since bbPress (r2679)
1222 *
1223 * @param int $reply_id Optional. Reply id
1224 * @uses bbp_get_reply_forum_id() To get the reply forum id
1225 */
1226 function bbp_reply_forum_id( $reply_id = 0 ) {
1227 echo bbp_get_reply_forum_id( $reply_id );
1228 }
1229 /**
1230 * Return the forum id a reply belongs to
1231 *
1232 * @since bbPress (r2679)
1233 *
1234 * @param int $reply_id Optional. Reply id
1235 * @uses bbp_get_reply_id() To get the reply id
1236 * @uses get_post_meta() To get the reply forum id
1237 * @uses apply_filters() Calls 'bbp_get_reply_forum_id' with the forum
1238 * id and reply id
1239 * @return int Reply's forum id
1240 */
1241 function bbp_get_reply_forum_id( $reply_id = 0 ) {
1242
1243 // Assume there is no forum
1244 $forum_id = 0;
1245
1246 // Check that reply_id is valid
1247 if ( $reply_id = bbp_get_reply_id( $reply_id ) )
1248
1249 // Get forum_id from reply
1250 if ( $forum_id = get_post_meta( $reply_id, '_bbp_forum_id', true ) )
1251
1252 // Validate the forum_id
1253 $forum_id = bbp_get_forum_id( $forum_id );
1254
1255 return apply_filters( 'bbp_get_reply_forum_id', (int) $forum_id, $reply_id );
1256 }
1257
1258 /**
1259 * Output the numeric position of a reply within a topic
1260 *
1261 * @since bbPress (r2984)
1262 *
1263 * @param int $reply_id Optional. Reply id
1264 * @param int $topic_id Optional. Topic id
1265 * @uses bbp_get_reply_position() To get the reply position
1266 */
1267 function bbp_reply_position( $reply_id = 0, $topic_id = 0 ) {
1268 echo bbp_get_reply_position( $reply_id, $topic_id );
1269 }
1270 /**
1271 * Return the numeric position of a reply within a topic
1272 *
1273 * @since bbPress (r2984)
1274 *
1275 * @param int $reply_id Optional. Reply id
1276 * @param int $topic_id Optional. Topic id
1277 * @uses bbp_get_reply_id() To get the reply id
1278 * @uses bbp_get_reply_topic_id() Get the topic id of the reply id
1279 * @uses bbp_get_topic_reply_count() To get the topic reply count
1280 * @uses bbp_get_reply_post_type() To get the reply post type
1281 * @uses bbp_get_reply_position_raw() To get calculate the reply position
1282 * @uses bbp_update_reply_position() To update the reply position
1283 * @uses bbp_show_lead_topic() Bump the count if lead topic is included
1284 * @uses apply_filters() Calls 'bbp_get_reply_position' with the reply
1285 * position, reply id and topic id
1286 * @return int Reply position
1287 */
1288 function bbp_get_reply_position( $reply_id = 0, $topic_id = 0 ) {
1289
1290 // Get required data
1291 $reply_id = bbp_get_reply_id( $reply_id );
1292 $reply_position = get_post_field( 'menu_order', $reply_id );
1293
1294 // Reply doesn't have a position so get the raw value
1295 if ( empty( $reply_position ) ) {
1296 $topic_id = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id );
1297
1298 // Post is not the topic
1299 if ( $reply_id != $topic_id ) {
1300 $reply_position = bbp_get_reply_position_raw( $reply_id, $topic_id );
1301
1302 // Update the reply position in the posts table so we'll never have
1303 // to hit the DB again.
1304 if ( !empty( $reply_position ) ) {
1305 bbp_update_reply_position( $reply_id, $reply_position );
1306 }
1307
1308 // Topic's position is always 0
1309 } else {
1310 $reply_position = 0;
1311 }
1312 }
1313
1314 // Bump the position by one if the lead topic is in the replies loop
1315 if ( ! bbp_show_lead_topic() )
1316 $reply_position++;
1317
1318 return (int) apply_filters( 'bbp_get_reply_position', (int) $reply_position, $reply_id, $topic_id );
1319 }
1320
1321 /** Reply Admin Links *********************************************************/
1322
1323 /**
1324 * Output admin links for reply
1325 *
1326 * @since bbPress (r2667)
1327 *
1328 * @param mixed $args See {@link bbp_get_reply_admin_links()}
1329 * @uses bbp_get_reply_admin_links() To get the reply admin links
1330 */
1331 function bbp_reply_admin_links( $args = '' ) {
1332 echo bbp_get_reply_admin_links( $args );
1333 }
1334 /**
1335 * Return admin links for reply
1336 *
1337 * @since bbPress (r2667)
1338 *
1339 * @param mixed $args This function supports these arguments:
1340 * - id: Optional. Reply id
1341 * - before: HTML before the links. Defaults to
1342 * '<span class="bbp-admin-links">'
1343 * - after: HTML after the links. Defaults to '</span>'
1344 * - sep: Separator. Defaults to ' | '
1345 * - links: Array of the links to display. By default, edit, trash,
1346 * spam and topic split links are displayed
1347 * @uses bbp_is_topic() To check if it's the topic page
1348 * @uses bbp_is_reply() To check if it's the reply page
1349 * @uses bbp_get_reply_id() To get the reply id
1350 * @uses bbp_get_reply_edit_link() To get the reply edit link
1351 * @uses bbp_get_reply_trash_link() To get the reply trash link
1352 * @uses bbp_get_reply_spam_link() To get the reply spam link
1353 * @uses bbp_get_topic_split_link() To get the topic split link
1354 * @uses current_user_can() To check if the current user can edit or
1355 * delete the reply
1356 * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
1357 * reply admin links and args
1358 * @return string Reply admin links
1359 */
1360 function bbp_get_reply_admin_links( $args = '' ) {
1361
1362 $defaults = array (
1363 'id' => 0,
1364 'before' => '<span class="bbp-admin-links">',
1365 'after' => '</span>',
1366 'sep' => ' | ',
1367 'links' => array()
1368 );
1369 $r = bbp_parse_args( $args, $defaults, 'get_reply_admin_links' );
1370
1371 $r['id'] = bbp_get_reply_id( (int) $r['id'] );
1372
1373 // If post is a topic, return the topic admin links instead
1374 if ( bbp_is_topic( $r['id'] ) )
1375 return bbp_get_topic_admin_links( $args );
1376
1377 // If post is not a reply, return
1378 if ( !bbp_is_reply( $r['id'] ) )
1379 return;
1380
1381 // Make sure user can edit this reply
1382 if ( !current_user_can( 'edit_reply', $r['id'] ) )
1383 return;
1384
1385 // If topic is trashed, do not show admin links
1386 if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) )
1387 return;
1388
1389 // If no links were passed, default to the standard
1390 if ( empty( $r['links'] ) ) {
1391 $r['links'] = array (
1392 'edit' => bbp_get_reply_edit_link ( $r ),
1393 'split' => bbp_get_topic_split_link( $r ),
1394 'trash' => bbp_get_reply_trash_link( $r ),
1395 'spam' => bbp_get_reply_spam_link ( $r ),
1396 );
1397 }
1398
1399 // Check caps for trashing the topic
1400 if ( !current_user_can( 'delete_reply', $r['id'] ) && !empty( $r['links']['trash'] ) )
1401 unset( $r['links']['trash'] );
1402
1403 // See if links need to be unset
1404 $reply_status = bbp_get_reply_status( $r['id'] );
1405 if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) {
1406
1407 // Spam link shouldn't be visible on trashed topics
1408 if ( $reply_status == bbp_get_trash_status_id() ) {
1409 unset( $r['links']['spam'] );
1410
1411 // Trash link shouldn't be visible on spam topics
1412 } elseif ( isset( $r['links']['trash'] ) && ( bbp_get_spam_status_id() == $reply_status ) ) {
1413 unset( $r['links']['trash'] );
1414 }
1415 }
1416
1417 // Process the admin links
1418 $links = implode( $r['sep'], array_filter( $r['links'] ) );
1419 $retval = $r['before'] . $links . $r['after'];
1420
1421 return apply_filters( 'bbp_get_reply_admin_links', $retval, $args );
1422 }
1423
1424 /**
1425 * Output the edit link of the reply
1426 *
1427 * @since bbPress (r2740)
1428 *
1429 * @param mixed $args See {@link bbp_get_reply_edit_link()}
1430 * @uses bbp_get_reply_edit_link() To get the reply edit link
1431 */
1432 function bbp_reply_edit_link( $args = '' ) {
1433 echo bbp_get_reply_edit_link( $args );
1434 }
1435
1436 /**
1437 * Return the edit link of the reply
1438 *
1439 * @since bbPress (r2740)
1440 *
1441 * @param mixed $args This function supports these arguments:
1442 * - id: Reply id
1443 * - link_before: HTML before the link
1444 * - link_after: HTML after the link
1445 * - edit_text: Edit text. Defaults to 'Edit'
1446 * @uses bbp_get_reply_id() To get the reply id
1447 * @uses bbp_get_reply() To get the reply
1448 * @uses current_user_can() To check if the current user can edit the
1449 * reply
1450 * @uses bbp_get_reply_edit_url() To get the reply edit url
1451 * @uses apply_filters() Calls 'bbp_get_reply_edit_link' with the reply
1452 * edit link and args
1453 * @return string Reply edit link
1454 */
1455 function bbp_get_reply_edit_link( $args = '' ) {
1456 $defaults = array (
1457 'id' => 0,
1458 'link_before' => '',
1459 'link_after' => '',
1460 'edit_text' => __( 'Edit', 'bbpress' )
1461 );
1462 $r = bbp_parse_args( $args, $defaults, 'get_reply_edit_link' );
1463 extract( $r );
1464
1465 $reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) );
1466
1467 // Bypass check if user has caps
1468 if ( !current_user_can( 'edit_others_replies' ) ) {
1469
1470 // User cannot edit or it is past the lock time
1471 if ( empty( $reply ) || !current_user_can( 'edit_reply', $reply->ID ) || bbp_past_edit_lock( $reply->post_date_gmt ) )
1472 return;
1473 }
1474
1475 // Get uri
1476 $uri = bbp_get_reply_edit_url( $id );
1477
1478 // Bail if no uri
1479 if ( empty( $uri ) )
1480 return;
1481
1482 $retval = $link_before . '<a href="' . $uri . '">' . $edit_text . '</a>' . $link_after;
1483
1484 return apply_filters( 'bbp_get_reply_edit_link', $retval, $args );
1485 }
1486
1487 /**
1488 * Output URL to the reply edit page
1489 *
1490 * @since bbPress (r2753)
1491 *
1492 * @param int $reply_id Optional. Reply id
1493 * @uses bbp_get_reply_edit_url() To get the reply edit url
1494 */
1495 function bbp_reply_edit_url( $reply_id = 0 ) {
1496 echo bbp_get_reply_edit_url( $reply_id );
1497 }
1498 /**
1499 * Return URL to the reply edit page
1500 *
1501 * @since bbPress (r2753)
1502 *
1503 * @param int $reply_id Optional. Reply id
1504 * @uses bbp_get_reply_id() To get the reply id
1505 * @uses bbp_get_reply() To get the reply
1506 * @uses bbp_get_reply_post_type() To get the reply post type
1507 * @uses add_query_arg() To add custom args to the url
1508 * @uses apply_filters() Calls 'bbp_get_reply_edit_url' with the edit
1509 * url and reply id
1510 * @return string Reply edit url
1511 */
1512 function bbp_get_reply_edit_url( $reply_id = 0 ) {
1513 global $wp_rewrite;
1514
1515 $bbp = bbpress();
1516 $reply = bbp_get_reply( bbp_get_reply_id( $reply_id ) );
1517 if ( empty( $reply ) )
1518 return;
1519
1520 $reply_link = bbp_get_reply_permalink( $reply_id );
1521
1522 // Pretty permalinks
1523 if ( $wp_rewrite->using_permalinks() ) {
1524 $url = trailingslashit( $reply_link ) . $bbp->edit_id;
1525 $url = trailingslashit( $url );
1526
1527 // Unpretty permalinks
1528 } else {
1529 $url = add_query_arg( array( bbp_get_reply_post_type() => $reply->post_name, $bbp->edit_id => '1' ), $reply_link );
1530 }
1531
1532 return apply_filters( 'bbp_get_reply_edit_url', $url, $reply_id );
1533 }
1534
1535 /**
1536 * Output the trash link of the reply
1537 *
1538 * @since bbPress (r2740)
1539 *
1540 * @param mixed $args See {@link bbp_get_reply_trash_link()}
1541 * @uses bbp_get_reply_trash_link() To get the reply trash link
1542 */
1543 function bbp_reply_trash_link( $args = '' ) {
1544 echo bbp_get_reply_trash_link( $args );
1545 }
1546
1547 /**
1548 * Return the trash link of the reply
1549 *
1550 * @since bbPress (r2740)
1551 *
1552 * @param mixed $args This function supports these arguments:
1553 * - id: Reply id
1554 * - link_before: HTML before the link
1555 * - link_after: HTML after the link
1556 * - sep: Separator
1557 * - trash_text: Trash text
1558 * - restore_text: Restore text
1559 * - delete_text: Delete text
1560 * @uses bbp_get_reply_id() To get the reply id
1561 * @uses bbp_get_reply() To get the reply
1562 * @uses current_user_can() To check if the current user can delete the
1563 * reply
1564 * @uses bbp_is_reply_trash() To check if the reply is trashed
1565 * @uses bbp_get_reply_status() To get the reply status
1566 * @uses add_query_arg() To add custom args to the url
1567 * @uses wp_nonce_url() To nonce the url
1568 * @uses esc_url() To escape the url
1569 * @uses bbp_get_reply_edit_url() To get the reply edit url
1570 * @uses apply_filters() Calls 'bbp_get_reply_trash_link' with the reply
1571 * trash link and args
1572 * @return string Reply trash link
1573 */
1574 function bbp_get_reply_trash_link( $args = '' ) {
1575 $defaults = array (
1576 'id' => 0,
1577 'link_before' => '',
1578 'link_after' => '',
1579 'sep' => ' | ',
1580 'trash_text' => __( 'Trash', 'bbpress' ),
1581 'restore_text' => __( 'Restore', 'bbpress' ),
1582 'delete_text' => __( 'Delete', 'bbpress' )
1583 );
1584 $r = bbp_parse_args( $args, $defaults, 'get_reply_trash_link' );
1585 extract( $r );
1586
1587 $actions = array();
1588 $reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) );
1589
1590 if ( empty( $reply ) || !current_user_can( 'delete_reply', $reply->ID ) ) {
1591 return;
1592 }
1593
1594 if ( bbp_is_reply_trash( $reply->ID ) ) {
1595 $actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'untrash', 'reply_id' => $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . '">' . esc_html( $restore_text ) . '</a>';
1596 } elseif ( EMPTY_TRASH_DAYS ) {
1597 $actions['trash'] = '<a title="' . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'trash', 'reply_id' => $reply->ID ) ), 'trash-' . $reply->post_type . '_' . $reply->ID ) ) . '">' . esc_html( $trash_text ) . '</a>';
1598 }
1599
1600 if ( bbp_is_reply_trash( $reply->ID ) || !EMPTY_TRASH_DAYS ) {
1601 $actions['delete'] = '<a title="' . esc_attr__( 'Delete this item permanently', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'delete', 'reply_id' => $reply->ID ) ), 'delete-' . $reply->post_type . '_' . $reply->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );">' . esc_html( $delete_text ) . '</a>';
1602 }
1603
1604 // Process the admin links
1605 $retval = $link_before . implode( $sep, $actions ) . $link_after;
1606
1607 return apply_filters( 'bbp_get_reply_trash_link', $retval, $args );
1608 }
1609
1610 /**
1611 * Output the spam link of the reply
1612 *
1613 * @since bbPress (r2740)
1614 *
1615 * @param mixed $args See {@link bbp_get_reply_spam_link()}
1616 * @uses bbp_get_reply_spam_link() To get the reply spam link
1617 */
1618 function bbp_reply_spam_link( $args = '' ) {
1619 echo bbp_get_reply_spam_link( $args );
1620 }
1621
1622 /**
1623 * Return the spam link of the reply
1624 *
1625 * @since bbPress (r2740)
1626 *
1627 * @param mixed $args This function supports these arguments:
1628 * - id: Reply id
1629 * - link_before: HTML before the link
1630 * - link_after: HTML after the link
1631 * - spam_text: Spam text
1632 * - unspam_text: Unspam text
1633 * @uses bbp_get_reply_id() To get the reply id
1634 * @uses bbp_get_reply() To get the reply
1635 * @uses current_user_can() To check if the current user can edit the
1636 * reply
1637 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
1638 * @uses add_query_arg() To add custom args to the url
1639 * @uses wp_nonce_url() To nonce the url
1640 * @uses esc_url() To escape the url
1641 * @uses bbp_get_reply_edit_url() To get the reply edit url
1642 * @uses apply_filters() Calls 'bbp_get_reply_spam_link' with the reply
1643 * spam link and args
1644 * @return string Reply spam link
1645 */
1646 function bbp_get_reply_spam_link( $args = '' ) {
1647 $defaults = array (
1648 'id' => 0,
1649 'link_before' => '',
1650 'link_after' => '',
1651 'spam_text' => __( 'Spam', 'bbpress' ),
1652 'unspam_text' => __( 'Unspam', 'bbpress' )
1653 );
1654 $r = bbp_parse_args( $args, $defaults, 'get_reply_spam_link' );
1655 extract( $r );
1656
1657 $reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) );
1658
1659 if ( empty( $reply ) || !current_user_can( 'moderate', $reply->ID ) )
1660 return;
1661
1662 $display = bbp_is_reply_spam( $reply->ID ) ? $unspam_text : $spam_text;
1663 $uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_spam', 'reply_id' => $reply->ID ) );
1664 $uri = esc_url( wp_nonce_url( $uri, 'spam-reply_' . $reply->ID ) );
1665 $retval = $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after;
1666
1667 return apply_filters( 'bbp_get_reply_spam_link', $retval, $args );
1668 }
1669
1670 /**
1671 * Split topic link
1672 *
1673 * Output the split link of the topic (but is bundled with each topic)
1674 *
1675 * @since bbPress (r2756)
1676 *
1677 * @param mixed $args See {@link bbp_get_topic_split_link()}
1678 * @uses bbp_get_topic_split_link() To get the topic split link
1679 */
1680 function bbp_topic_split_link( $args = '' ) {
1681 echo bbp_get_topic_split_link( $args );
1682 }
1683
1684 /**
1685 * Get split topic link
1686 *
1687 * Return the split link of the topic (but is bundled with each reply)
1688 *
1689 * @since bbPress (r2756)
1690 *
1691 * @param mixed $args This function supports these arguments:
1692 * - id: Reply id
1693 * - link_before: HTML before the link
1694 * - link_after: HTML after the link
1695 * - split_text: Split text
1696 * - split_title: Split title attribute
1697 * @uses bbp_get_reply_id() To get the reply id
1698 * @uses bbp_get_reply() To get the reply
1699 * @uses current_user_can() To check if the current user can edit the
1700 * topic
1701 * @uses bbp_get_reply_topic_id() To get the reply topic id
1702 * @uses bbp_get_topic_edit_url() To get the topic edit url
1703 * @uses add_query_arg() To add custom args to the url
1704 * @uses wp_nonce_url() To nonce the url
1705 * @uses esc_url() To escape the url
1706 * @uses apply_filters() Calls 'bbp_get_topic_split_link' with the topic
1707 * split link and args
1708 * @return string Reply spam link
1709 */
1710 function bbp_get_topic_split_link( $args = '' ) {
1711 $defaults = array (
1712 'id' => 0,
1713 'link_before' => '',
1714 'link_after' => '',
1715 'split_text' => __( 'Split', 'bbpress' ),
1716 'split_title' => __( 'Split the topic from this reply', 'bbpress' )
1717 );
1718 $r = bbp_parse_args( $args, $defaults, 'get_topic_split_link' );
1719 extract( $r );
1720
1721 $reply_id = bbp_get_reply_id( $id );
1722 $topic_id = bbp_get_reply_topic_id( $reply_id );
1723
1724 if ( empty( $reply_id ) || !current_user_can( 'moderate', $topic_id ) )
1725 return;
1726
1727 $uri = esc_url(
1728 add_query_arg(
1729 array(
1730 'action' => 'split',
1731 'reply_id' => $reply_id
1732 ),
1733 bbp_get_topic_edit_url( $topic_id )
1734 ) );
1735
1736 $retval = $link_before . '<a href="' . $uri . '" title="' . esc_attr( $split_title ) . '">' . $split_text . '</a>' . $link_after;
1737
1738 return apply_filters( 'bbp_get_topic_split_link', $retval, $args );
1739 }
1740
1741 /**
1742 * Output the row class of a reply
1743 *
1744 * @since bbPress (r2678)
1745 *
1746 * @param int $reply_id Optional. Reply ID
1747 * @uses bbp_get_reply_class() To get the reply class
1748 */
1749 function bbp_reply_class( $reply_id = 0 ) {
1750 echo bbp_get_reply_class( $reply_id );
1751 }
1752 /**
1753 * Return the row class of a reply
1754 *
1755 * @since bbPress (r2678)
1756 *
1757 * @param int $reply_id Optional. Reply ID
1758 * @uses bbp_get_reply_id() To validate the reply id
1759 * @uses bbp_get_reply_forum_id() To get the reply's forum id
1760 * @uses bbp_get_reply_topic_id() To get the reply's topic id
1761 * @uses get_post_class() To get all the classes including ours
1762 * @uses apply_filters() Calls 'bbp_get_reply_class' with the classes
1763 * @return string Row class of the reply
1764 */
1765 function bbp_get_reply_class( $reply_id = 0 ) {
1766 $bbp = bbpress();
1767 $reply_id = bbp_get_reply_id( $reply_id );
1768 $count = isset( $bbp->reply_query->current_post ) ? $bbp->reply_query->current_post : 1;
1769 $classes = array();
1770 $classes[] = ( (int) $count % 2 ) ? 'even' : 'odd';
1771 $classes[] = 'bbp-parent-forum-' . bbp_get_reply_forum_id( $reply_id );
1772 $classes[] = 'bbp-parent-topic-' . bbp_get_reply_topic_id( $reply_id );
1773 $classes[] = 'bbp-reply-position-' . bbp_get_reply_position( $reply_id );
1774 $classes[] = 'user-id-' . bbp_get_reply_author_id( $reply_id );
1775 $classes[] = ( bbp_get_reply_author_id( $reply_id ) == bbp_get_topic_author_id( bbp_get_reply_topic_id( $reply_id ) ) ? 'topic-author' : '' );
1776 $classes = array_filter( $classes );
1777 $classes = get_post_class( $classes, $reply_id );
1778 $classes = apply_filters( 'bbp_get_reply_class', $classes, $reply_id );
1779 $retval = 'class="' . join( ' ', $classes ) . '"';
1780
1781 return $retval;
1782 }
1783
1784 /**
1785 * Output the topic pagination count
1786 *
1787 * @since bbPress (r2519)
1788 *
1789 * @uses bbp_get_topic_pagination_count() To get the topic pagination count
1790 */
1791 function bbp_topic_pagination_count() {
1792 echo bbp_get_topic_pagination_count();
1793 }
1794 /**
1795 * Return the topic pagination count
1796 *
1797 * @since bbPress (r2519)
1798 *
1799 * @uses bbp_number_format() To format the number value
1800 * @uses bbp_show_lead_topic() Are we showing the topic as a lead?
1801 * @uses apply_filters() Calls 'bbp_get_topic_pagination_count' with the
1802 * pagination count
1803 * @return string Topic pagination count
1804 */
1805 function bbp_get_topic_pagination_count() {
1806 $bbp = bbpress();
1807
1808 // Define local variable(s)
1809 $retstr = '';
1810
1811 // Set pagination values
1812 $start_num = intval( ( $bbp->reply_query->paged - 1 ) * $bbp->reply_query->posts_per_page ) + 1;
1813 $from_num = bbp_number_format( $start_num );
1814 $to_num = bbp_number_format( ( $start_num + ( $bbp->reply_query->posts_per_page - 1 ) > $bbp->reply_query->found_posts ) ? $bbp->reply_query->found_posts : $start_num + ( $bbp->reply_query->posts_per_page - 1 ) );
1815 $total_int = (int) $bbp->reply_query->found_posts;
1816 $total = bbp_number_format( $total_int );
1817
1818 // We are not including the lead topic
1819 if ( bbp_show_lead_topic() ) {
1820
1821 // Several replies in a topic with a single page
1822 if ( empty( $to_num ) ) {
1823 $retstr = sprintf( _n( 'Viewing %1$s reply', 'Viewing %1$s replies', $total_int, 'bbpress' ), $total );
1824
1825 // Several replies in a topic with several pages
1826 } else {
1827 $retstr = sprintf( _n( 'Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress' ), $bbp->reply_query->post_count, $from_num, $to_num, $total );
1828 }
1829
1830 // We are including the lead topic
1831 } else {
1832
1833 // Several posts in a topic with a single page
1834 if ( empty( $to_num ) ) {
1835 $retstr = sprintf( _n( 'Viewing %1$s post', 'Viewing %1$s posts', $total_int, 'bbpress' ), $total );
1836
1837 // Several posts in a topic with several pages
1838 } else {
1839 $retstr = sprintf( _n( 'Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress' ), $bbp->reply_query->post_count, $from_num, $to_num, $total );
1840 }
1841 }
1842
1843 // Filter and return
1844 return apply_filters( 'bbp_get_topic_pagination_count', $retstr );
1845 }
1846
1847 /**
1848 * Output topic pagination links
1849 *
1850 * @since bbPress (r2519)
1851 *
1852 * @uses bbp_get_topic_pagination_links() To get the topic pagination links
1853 */
1854 function bbp_topic_pagination_links() {
1855 echo bbp_get_topic_pagination_links();
1856 }
1857 /**
1858 * Return topic pagination links
1859 *
1860 * @since bbPress (r2519)
1861 *
1862 * @uses apply_filters() Calls 'bbp_get_topic_pagination_links' with the
1863 * pagination links
1864 * @return string Topic pagination links
1865 */
1866 function bbp_get_topic_pagination_links() {
1867 $bbp = bbpress();
1868
1869 if ( !isset( $bbp->reply_query->pagination_links ) || empty( $bbp->reply_query->pagination_links ) )
1870 return false;
1871
1872 return apply_filters( 'bbp_get_topic_pagination_links', $bbp->reply_query->pagination_links );
1873 }
1874
1875 /** Forms *********************************************************************/
1876
1877 /**
1878 * Output the value of reply content field
1879 *
1880 * @since bbPress (r31301)
1881 *
1882 * @uses bbp_get_form_reply_content() To get value of reply content field
1883 */
1884 function bbp_form_reply_content() {
1885 echo bbp_get_form_reply_content();
1886 }
1887 /**
1888 * Return the value of reply content field
1889 *
1890 * @since bbPress (r31301)
1891 *
1892 * @uses bbp_is_reply_edit() To check if it's the reply edit page
1893 * @uses apply_filters() Calls 'bbp_get_form_reply_content' with the content
1894 * @return string Value of reply content field
1895 */
1896 function bbp_get_form_reply_content() {
1897
1898 // Get _POST data
1899 if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_reply_content'] ) )
1900 $reply_content = $_POST['bbp_reply_content'];
1901
1902 // Get edit data
1903 elseif ( bbp_is_reply_edit() )
1904 $reply_content = bbp_get_global_post_field( 'post_content', 'raw' );
1905
1906 // No data
1907 else
1908 $reply_content = '';
1909
1910 return apply_filters( 'bbp_get_form_reply_content', esc_textarea( $reply_content ) );
1911 }
1912
1913 /**
1914 * Output checked value of reply log edit field
1915 *
1916 * @since bbPress (r31301)
1917 *
1918 * @uses bbp_get_form_reply_log_edit() To get the reply log edit value
1919 */
1920 function bbp_form_reply_log_edit() {
1921 echo bbp_get_form_reply_log_edit();
1922 }
1923 /**
1924 * Return checked value of reply log edit field
1925 *
1926 * @since bbPress (r31301)
1927 *
1928 * @uses apply_filters() Calls 'bbp_get_form_reply_log_edit' with the
1929 * log edit value
1930 * @return string Reply log edit checked value
1931 */
1932 function bbp_get_form_reply_log_edit() {
1933
1934 // Get _POST data
1935 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_log_reply_edit'] ) )
1936 $reply_revision = $_POST['bbp_log_reply_edit'];
1937
1938 // No data
1939 else
1940 $reply_revision = 1;
1941
1942 return apply_filters( 'bbp_get_form_reply_log_edit', checked( $reply_revision, true, false ) );
1943 }
1944
1945 /**
1946 * Output the value of the reply edit reason
1947 *
1948 * @since bbPress (r31301)
1949 *
1950 * @uses bbp_get_form_reply_edit_reason() To get the reply edit reason value
1951 */
1952 function bbp_form_reply_edit_reason() {
1953 echo bbp_get_form_reply_edit_reason();
1954 }
1955 /**
1956 * Return the value of the reply edit reason
1957 *
1958 * @since bbPress (r31301)
1959 *
1960 * @uses apply_filters() Calls 'bbp_get_form_reply_edit_reason' with the
1961 * reply edit reason value
1962 * @return string Reply edit reason value
1963 */
1964 function bbp_get_form_reply_edit_reason() {
1965
1966 // Get _POST data
1967 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_reply_edit_reason'] ) )
1968 $reply_edit_reason = $_POST['bbp_reply_edit_reason'];
1969
1970 // No data
1971 else
1972 $reply_edit_reason = '';
1973
1974 return apply_filters( 'bbp_get_form_reply_edit_reason', esc_attr( $reply_edit_reason ) );
1975 }
1976