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

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