PluginProbe
bbPress / 2.1-beta-1
bbPress v2.1-beta-1
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-beta-1, at bbp-includes/bbp-reply-template.php

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