PluginProbe
bbPress / 2.1
bbPress v2.1
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 2.2.2 All 71 releases
bbpress / bbp-includes / bbp-reply-template.php

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

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