PluginProbe
bbPress / 2.0-rc-3
bbPress v2.0-rc-3
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.0-rc-3, at bbp-includes/bbp-reply-template.php

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