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

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