PluginProbe
bbPress / 2.0-rc-5
bbPress v2.0-rc-5
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-topic-template.php

bbp-topic-template.php in bbPress 2.0-rc-5, at bbp-includes/bbp-topic-template.php

3,349 lines 102.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Topic 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 * Output the unique id of the custom post type for topics
17 *
18 * @since bbPress (r2857)
19 *
20 * @uses bbp_get_topic_post_type() To get the topic post type
21 */
22 function bbp_topic_post_type() {
23 echo bbp_get_topic_post_type();
24 }
25 /**
26 * Return the unique id of the custom post type for topics
27 *
28 * @since bbPress (r2857)
29 *
30 * @uses apply_filters() Calls 'bbp_get_topic_post_type' with the topic
31 * post type id
32 * @return string The unique topic post type id
33 */
34 function bbp_get_topic_post_type() {
35 global $bbp;
36
37 return apply_filters( 'bbp_get_topic_post_type', $bbp->topic_post_type );
38 }
39
40 /** Topic Loop ****************************************************************/
41
42 /**
43 * The main topic loop. WordPress makes this easy for us
44 *
45 * @since bbPress (r2485)
46 *
47 * @param mixed $args All the arguments supported by {@link WP_Query}
48 * @uses current_user_can() To check if the current user can edit other's topics
49 * @uses bbp_get_topic_post_type() To get the topic post type
50 * @uses WP_Query To make query and get the topics
51 * @uses is_page() To check if it's a page
52 * @uses bbp_is_single_forum() To check if it's a forum
53 * @uses bbp_get_forum_id() To get the forum id
54 * @uses bbp_get_paged() To get the current page value
55 * @uses bbp_get_super_stickies() To get the super stickies
56 * @uses bbp_get_stickies() To get the forum stickies
57 * @uses wpdb::get_results() To execute our query and get the results
58 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
59 * @uses get_permalink() To get the permalink
60 * @uses add_query_arg() To add custom args to the url
61 * @uses apply_filters() Calls 'bbp_topics_pagination' with the pagination args
62 * @uses paginate_links() To paginate the links
63 * @uses apply_filters() Calls 'bbp_has_topics' with
64 * bbPres::topic_query::have_posts()
65 * and bbPres::topic_query
66 * @return object Multidimensional array of topic information
67 */
68 function bbp_has_topics( $args = '' ) {
69 global $wp_rewrite, $wp_query, $bbp, $wpdb;
70
71 // What are the default allowed statuses (based on user caps)
72 if ( !bbp_is_query_name( 'bbp_widget' ) && bbp_get_view_all() )
73 $default_status = join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id() ) );
74 else
75 $default_status = join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) );
76
77 // Default arguments
78 $default = array (
79
80 // Narrow query down to bbPress topics
81 'post_type' => bbp_get_topic_post_type(),
82
83 // Forum ID
84 'post_parent' => bbp_is_single_forum() ? bbp_get_forum_id() : 'any',
85
86 // Make sure topic has some last activity time
87 'meta_key' => '_bbp_last_active_time',
88
89 // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
90 'orderby' => 'meta_value',
91
92 // 'ASC', 'DESC'
93 'order' => 'DESC',
94
95 // Topics per page
96 'posts_per_page' => get_option( '_bbp_topics_per_page', 15 ),
97
98 // Page Number
99 'paged' => bbp_get_paged(),
100
101 // Topic Search
102 's' => !empty( $_REQUEST['ts'] ) ? $_REQUEST['ts'] : '',
103
104 // Ignore sticky topics?
105 'show_stickies' => bbp_is_single_forum(),
106
107 // Maximum number of pages to show
108 'max_num_pages' => false,
109
110 // Post Status
111 'post_status' => $default_status,
112 );
113
114 // Set up topic variables
115 $bbp_t = wp_parse_args( $args, $default );
116
117 // Filter the topics query to allow just-in-time modifications
118 $bbp_t = apply_filters( 'bbp_has_topics_query', $bbp_t );
119
120 // Extract the query variables
121 extract( $bbp_t );
122
123 // Call the query
124 $bbp->topic_query = new WP_Query( $bbp_t );
125
126 // Set post_parent back to 0 if originally set to 'any'
127 if ( 'any' == $bbp_t['post_parent'] )
128 $bbp_t['post_parent'] = $post_parent = 0;
129
130 // Limited the number of pages shown
131 if ( !empty( $max_num_pages ) )
132 $bbp->topic_query->max_num_pages = $max_num_pages;
133
134 // Put sticky posts at the top of the posts array
135 if ( !empty( $show_stickies ) && $paged <= 1 ) {
136
137 // Get super stickies and stickies in this forum
138 $stickies = bbp_get_super_stickies();
139 $stickies = !empty( $post_parent ) ? array_merge( $stickies, bbp_get_stickies( $post_parent ) ) : $stickies;
140 $stickies = array_unique( $stickies );
141
142 // We have stickies
143 if ( is_array( $stickies ) && !empty( $stickies ) ) {
144
145 // Setup the number of stickies and reset offset to 0
146 $num_topics = count( $bbp->topic_query->posts );
147 $sticky_offset = 0;
148
149 // Loop over topics and relocate stickies to the front.
150 for ( $i = 0; $i < $num_topics; $i++ ) {
151 if ( in_array( $bbp->topic_query->posts[$i]->ID, $stickies ) ) {
152 $sticky = $bbp->topic_query->posts[$i];
153
154 // Remove sticky from current position
155 array_splice( $bbp->topic_query->posts, $i, 1 );
156
157 // Move to front, after other stickies
158 array_splice( $bbp->topic_query->posts, $sticky_offset, 0, array( $sticky ) );
159
160 // Increment the sticky offset. The next sticky will be placed at this offset.
161 $sticky_offset++;
162
163 // Remove post from sticky posts array
164 $offset = array_search( $sticky->ID, $stickies );
165
166 // Cleanup
167 unset( $stickies[$offset] );
168 unset( $sticky );
169 }
170 }
171
172 // If any posts have been excluded specifically, Ignore those that are sticky.
173 if ( !empty( $stickies ) && !empty( $post__not_in ) )
174 $stickies = array_diff( $stickies, $post__not_in );
175
176 // Fetch sticky posts that weren't in the query results
177 if ( !empty( $stickies ) ) {
178
179 // Query to use in get_posts to get sticky posts
180 $sticky_query = array(
181 'post_type' => bbp_get_topic_post_type(),
182 'post_parent' => 'any',
183 'include' => $stickies
184 );
185
186 // Get all stickies
187 if ( $sticky_posts = get_posts( $sticky_query ) ) {
188
189 // Get a count of the visible stickies
190 $sticky_count = count( $sticky_posts );
191
192 // Loop through stickies and add them to beginning of array
193 foreach ( $sticky_posts as $sticky )
194 $topics[] = $sticky;
195
196 // Loop through topics and add them to end of array
197 foreach ( $bbp->topic_query->posts as $topic )
198 $topics[] = $topic;
199
200 // Adjust loop and counts for new sticky positions
201 $bbp->topic_query->posts = $topics;
202 $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count;
203 $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count;
204
205 // Cleanup
206 unset( $topics );
207 unset( $stickies );
208 unset( $sticky_posts );
209 }
210 }
211 }
212 }
213
214 // If no limit to posts per page, set it to the current post_count
215 if ( -1 == $posts_per_page )
216 $posts_per_page = $bbp->topic_query->post_count;
217
218 // Add pagination values to query object
219 $bbp->topic_query->posts_per_page = $posts_per_page;
220 $bbp->topic_query->paged = $paged;
221
222 // Only add pagination if query returned results
223 if ( !bbp_is_query_name( 'bbp_widget' ) && ( (int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts ) && (int) $bbp->topic_query->posts_per_page ) {
224
225 // Limit the number of topics shown based on maximum allowed pages
226 if ( ( !empty( $max_num_pages ) ) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count )
227 $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count;
228
229 // If pretty permalinks are enabled, make our pagination pretty
230 if ( $wp_rewrite->using_permalinks() ) {
231
232 // Profile page
233 if ( bbp_is_single_user() )
234 $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() );
235
236 // View
237 elseif ( bbp_is_single_view() )
238 $base = bbp_get_view_url();
239
240 // Topic tag
241 elseif ( bbp_is_topic_tag() )
242 $base = bbp_get_topic_tag_link();
243
244 // Page or single post
245 elseif ( is_page() || is_single() )
246 $base = get_permalink();
247
248 // Topic archive
249 elseif ( bbp_is_topic_archive() )
250 $base = home_url( $bbp->topic_archive_slug );
251
252 // Default
253 else
254 $base = get_permalink( $post_parent );
255
256 // Use pagination base
257 $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
258
259 // Unpretty pagination
260 } else {
261 $base = add_query_arg( 'paged', '%#%' );
262 }
263
264 // Pagination settings with filter
265 $bbp_topic_pagination = apply_filters( 'bbp_topic_pagination', array (
266 'base' => $base,
267 'format' => '',
268 'total' => $posts_per_page == $bbp->topic_query->found_posts ? 1 : ceil( (int) $bbp->topic_query->found_posts / (int) $posts_per_page ),
269 'current' => (int) $bbp->topic_query->paged,
270 'prev_text' => '&larr;',
271 'next_text' => '&rarr;',
272 'mid_size' => 1
273 ) );
274
275 // Add pagination to query object
276 $bbp->topic_query->pagination_links = paginate_links ( $bbp_topic_pagination );
277
278 // Remove first page from pagination
279 $bbp->topic_query->pagination_links = str_replace( $wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links );
280 }
281
282 // Return object
283 return apply_filters( 'bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query );
284 }
285
286 /**
287 * Whether there are more topics available in the loop
288 *
289 * @since bbPress (r2485)
290 *
291 * @uses WP_Query bbPress::topic_query::have_posts()
292 * @return object Topic information
293 */
294 function bbp_topics() {
295 global $bbp;
296
297 // Put into variable to check against next
298 $have_posts = $bbp->topic_query->have_posts();
299
300 // Reset the post data when finished
301 if ( empty( $have_posts ) )
302 wp_reset_postdata();
303
304 return $have_posts;
305 }
306
307 /**
308 * Loads up the current topic in the loop
309 *
310 * @since bbPress (r2485)
311 *
312 * @uses WP_Query bbPress::topic_query::the_post()
313 * @return object Topic information
314 */
315 function bbp_the_topic() {
316 global $bbp;
317 return $bbp->topic_query->the_post();
318 }
319
320 /**
321 * Output the topic id
322 *
323 * @since bbPress (r2485)
324 *
325 * @uses bbp_get_topic_id() To get the topic id
326 */
327 function bbp_topic_id( $topic_id = 0) {
328 echo bbp_get_topic_id( $topic_id );
329 }
330 /**
331 * Return the topic id
332 *
333 * @since bbPress (r2485)
334 *
335 * @param $topic_id Optional. Used to check emptiness
336 * @uses bbPress::topic_query::post::ID To get the topic id
337 * @uses bbp_is_single_topic() To check if it's a topic page
338 * @uses bbp_is_topic_edit() To check if it's a topic edit page
339 * @uses bbp_is_single_reply() To check if it it's a reply page
340 * @uses bbp_is_reply_edit() To check if it's a reply edit page
341 * @uses bbp_get_reply_topic_edit() To get the reply topic id
342 * @uses get_post_field() To get the post's post type
343 * @uses WP_Query::post::ID To get the topic id
344 * @uses bbp_get_topic_post_type() To get the topic post type
345 * @uses apply_filters() Calls 'bbp_get_topic_id' with the topic id and
346 * supplied topic id
347 * @return int The topic id
348 */
349 function bbp_get_topic_id( $topic_id = 0 ) {
350 global $bbp, $wp_query;
351
352 // Easy empty checking
353 if ( !empty( $topic_id ) && is_numeric( $topic_id ) )
354 $bbp_topic_id = $topic_id;
355
356 // Currently inside a topic loop
357 elseif ( !empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) )
358 $bbp_topic_id = $bbp->topic_query->post->ID;
359
360 // Currently viewing a topic
361 elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) )
362 $bbp_topic_id = $bbp->current_topic_id = $wp_query->post->ID;
363
364 // Currently viewing a topic
365 elseif ( bbp_is_single_reply() )
366 $bbp_topic_id = $bbp->current_topic_id = bbp_get_reply_topic_id();
367
368 // Fallback
369 else
370 $bbp_topic_id = 0;
371
372 // Check if current_reply_id is set, and check post_type if so
373 if ( !empty( $bbp->current_topic_id ) && ( bbp_get_topic_post_type() != get_post_field( 'post_type', $bbp_topic_id ) ) )
374 $bbp->current_topic_id = null;
375
376 return apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id );
377 }
378
379 /**
380 * Gets a topic
381 *
382 * @since bbPress (r2787)
383 *
384 * @param int|object $topic Topic id or topic object
385 * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
386 * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
387 * @uses get_post() To get the topic
388 * @uses apply_filters() Calls 'bbp_get_topic' with the topic, output type and
389 * sanitation filter
390 * @return mixed Null if error or topic (in specified form) if success
391 */
392 function bbp_get_topic( $topic, $output = OBJECT, $filter = 'raw' ) {
393
394 if ( empty( $topic ) || is_numeric( $topic ) )
395 $topic = bbp_get_topic_id( $topic );
396
397 if ( !$topic = get_post( $topic, OBJECT, $filter ) )
398 return $topic;
399
400 if ( $topic->post_type !== bbp_get_topic_post_type() )
401 return null;
402
403 if ( $output == OBJECT ) {
404 return $topic;
405
406 } elseif ( $output == ARRAY_A ) {
407 $_topic = get_object_vars( $topic );
408 return $_topic;
409
410 } elseif ( $output == ARRAY_N ) {
411 $_topic = array_values( get_object_vars( $topic ) );
412 return $_topic;
413
414 }
415
416 return apply_filters( 'bbp_get_topic', $topic, $output, $filter );
417 }
418
419 /**
420 * Output the link to the topic in the topic loop
421 *
422 * @since bbPress (r2485)
423 *
424 * @param int $topic_id Optional. Topic id
425 * @uses bbp_get_topic_permalink() To get the topic permalink
426 */
427 function bbp_topic_permalink( $topic_id = 0 ) {
428 echo bbp_get_topic_permalink( $topic_id );
429 }
430 /**
431 * Return the link to the topic
432 *
433 * @since bbPress (r2485)
434 *
435 * @param int $topic_id Optional. Topic id
436 * @param $string $redirect_to Optional. Pass a redirect value for use with
437 * shortcodes and other fun things.
438 * @uses bbp_get_topic_id() To get the topic id
439 * @uses get_permalink() To get the topic permalink
440 * @uses esc_url_raw() To clean the redirect_to url
441 * @uses apply_filters() Calls 'bbp_get_topic_permalink' with the link
442 * and topic id
443 * @return string Permanent link to topic
444 */
445 function bbp_get_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
446 $topic_id = bbp_get_topic_id( $topic_id );
447
448 // Use the redirect address
449 if ( !empty( $redirect_to ) )
450 $topic_permalink = esc_url_raw( $redirect_to );
451
452 // Use the topic permalink
453 else
454 $topic_permalink = get_permalink( $topic_id );
455
456 return apply_filters( 'bbp_get_topic_permalink', $topic_permalink, $topic_id );
457 }
458
459 /**
460 * Output the title of the topic
461 *
462 * @since bbPress (r2485)
463 *
464 * @param int $topic_id Optional. Topic id
465 * @uses bbp_get_topic_title() To get the topic title
466 */
467 function bbp_topic_title( $topic_id = 0 ) {
468 echo bbp_get_topic_title( $topic_id );
469 }
470 /**
471 * Return the title of the topic
472 *
473 * @since bbPress (r2485)
474 *
475 * @param int $topic_id Optional. Topic id
476 * @uses bbp_get_topic_id() To get the topic id
477 * @uses get_the_title() To get the title
478 * @uses apply_filters() Calls 'bbp_get_topic_title' with the title and
479 * topic id
480 * @return string Title of topic
481 */
482 function bbp_get_topic_title( $topic_id = 0 ) {
483 $topic_id = bbp_get_topic_id( $topic_id );
484
485 return apply_filters( 'bbp_get_topic_title', get_the_title( $topic_id ), $topic_id );
486 }
487
488 /**
489 * Output the topic archive title
490 *
491 * @since bbPress (r3249)
492 *
493 * @param string $title Default text to use as title
494 */
495 function bbp_topic_archive_title( $title = '' ) {
496 echo bbp_get_topic_archive_title( $title );
497 }
498 /**
499 * Return the topic archive title
500 *
501 * @since bbPress (r3249)
502 *
503 * @global bbPress $bbp The main bbPress class
504 * @param string $title Default text to use as title
505 *
506 * @uses bbp_get_page_by_path() Check if page exists at root path
507 * @uses get_the_title() Use the page title at the root path
508 * @uses get_post_type_object() Load the post type object
509 * @uses bbp_get_topic_post_type() Get the topic post type ID
510 * @uses get_post_type_labels() Get labels for topic post type
511 * @uses apply_filters() Allow output to be manipulated
512 *
513 * @return string The topic archive title
514 */
515 function bbp_get_topic_archive_title( $title = '' ) {
516 global $bbp;
517
518 // If no title was passed
519 if ( empty( $title ) ) {
520
521 // Set root text to page title
522 if ( $page = bbp_get_page_by_path( $bbp->topic_archive_slug ) ) {
523 $title = get_the_title( $page->ID );
524
525 // Default to topic post type name label
526 } else {
527 $tto = get_post_type_object( bbp_get_topic_post_type() );
528 $title = $tto->labels->name;
529 }
530 }
531
532 return apply_filters( 'bbp_get_topic_archive_title', $title );
533 }
534
535 /**
536 * Output the content of the topic
537 *
538 * @since bbPress (r2780)
539 *
540 * @param int $topic_id Optional. Topic id
541 * @uses bbp_get_topic_content() To get the topic content
542 */
543 function bbp_topic_content( $topic_id = 0 ) {
544 echo bbp_get_topic_content( $topic_id );
545 }
546 /**
547 * Return the content of the topic
548 *
549 * @since bbPress (r2780)
550 *
551 * @param int $topic_id Optional. Topic id
552 * @uses bbp_get_topic_id() To get the topic id
553 * @uses post_password_required() To check if the topic requires pass
554 * @uses get_the_password_form() To get the password form
555 * @uses get_post_field() To get the content post field
556 * @uses apply_filters() Calls 'bbp_get_topic_content' with the content
557 * and topic id
558 * @return string Content of the topic
559 */
560 function bbp_get_topic_content( $topic_id = 0 ) {
561 $topic_id = bbp_get_topic_id( $topic_id );
562
563 // Check if password is required
564 if ( post_password_required( $topic_id ) )
565 return get_the_password_form();
566
567 $content = get_post_field( 'post_content', $topic_id );
568
569 return apply_filters( 'bbp_get_topic_content', $content, $topic_id );
570 }
571
572 /**
573 * Output the excerpt of the topic
574 *
575 * @since bbPress (r2780)
576 *
577 * @param int $topic_id Optional. Topic id
578 * @param int $length Optional. Length of the excerpt. Defaults to 100 letters
579 * @uses bbp_get_topic_excerpt() To get the topic excerpt
580 */
581 function bbp_topic_excerpt( $topic_id = 0, $length = 100 ) {
582 echo bbp_get_topic_excerpt( $topic_id, $length );
583 }
584 /**
585 * Return the excerpt of the topic
586 *
587 * @since bbPress (r2780)
588 *
589 * @param int $topic_id Optional. topic id
590 * @param int $length Optional. Length of the excerpt. Defaults to 100
591 * letters
592 * @uses bbp_get_topic_id() To get the topic id
593 * @uses get_post_field() To get the excerpt
594 * @uses bbp_get_topic_content() To get the topic content
595 * @uses apply_filters() Calls 'bbp_get_topic_excerpt' with the excerpt,
596 * topic id and length
597 * @return string topic Excerpt
598 */
599 function bbp_get_topic_excerpt( $topic_id = 0, $length = 100 ) {
600 $topic_id = bbp_get_topic_id( $topic_id );
601 $length = (int) $length;
602 $excerpt = get_post_field( $topic_id, 'post_excerpt' );
603
604 if ( empty( $excerpt ) )
605 $excerpt = bbp_get_topic_content( $topic_id );
606
607 $excerpt = trim( strip_tags( $excerpt ) );
608
609 if ( !empty( $length ) && strlen( $excerpt ) > $length ) {
610 $excerpt = substr( $excerpt, 0, $length - 1 );
611 $excerpt .= '&hellip;';
612 }
613
614 return apply_filters( 'bbp_get_topic_excerpt', $excerpt, $topic_id, $length );
615 }
616
617 /**
618 * Output pagination links of a topic within the topic loop
619 *
620 * @since bbPress (r2966)
621 *
622 * @param mixed $args See {@link bbp_get_topic_pagination()}
623 * @uses bbp_get_topic_pagination() To get the topic pagination links
624 */
625 function bbp_topic_pagination( $args = '' ) {
626 echo bbp_get_topic_pagination( $args );
627 }
628 /**
629 * Returns pagination links of a topic within the topic loop
630 *
631 * @since bbPress (r2966)
632 *
633 * @param mixed $args This function supports these arguments:
634 * - topic_id: Topic id
635 * - before: Before the links
636 * - after: After the links
637 * @uses bbp_get_topic_id() To get the topic id
638 * @uses WP_Rewrite::using_permalinks() To check if the blog is using
639 * permalinks
640 * @uses user_trailingslashit() To add a trailing slash
641 * @uses trailingslashit() To add a trailing slash
642 * @uses get_permalink() To get the permalink of the topic
643 * @uses add_query_arg() To add query args
644 * @uses bbp_get_topic_reply_count() To get topic reply count
645 * @uses bbp_show_topic_lead() Are we showing the topic as a lead?
646 * @uses get_option() To get replies per page option
647 * @uses paginate_links() To paginate the links
648 * @uses apply_filters() Calls 'bbp_get_topic_pagination' with the links
649 * and arguments
650 * @return string Pagination links
651 */
652 function bbp_get_topic_pagination( $args = '' ) {
653 global $wp_rewrite;
654
655 $defaults = array(
656 'topic_id' => bbp_get_topic_id(),
657 'before' => '<span class="bbp-topic-pagination">',
658 'after' => '</span>',
659 );
660
661 $r = wp_parse_args( $args, $defaults );
662 extract( $r );
663
664 // If pretty permalinks are enabled, make our pagination pretty
665 if ( $wp_rewrite->using_permalinks() )
666 $base = trailingslashit( get_permalink( $topic_id ) ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
667 else
668 $base = add_query_arg( 'paged', '%#%', get_permalink( $topic_id ) );
669
670 // Get total and add 1 if topic is included in the reply loop
671 $total = bbp_get_topic_reply_count( $topic_id );
672
673 // Bump if topic is in loop
674 if ( !bbp_show_lead_topic() )
675 $total++;
676
677 // Pagination settings
678 $pagination = array(
679 'base' => $base,
680 'format' => '',
681 'total' => ceil( (int) $total / (int) get_option( '_bbp_replies_per_page', 15 ) ),
682 'current' => 0,
683 'prev_next' => false,
684 'mid_size' => 2,
685 'end_size' => 3,
686 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false
687 );
688
689 // Add pagination to query object
690 if ( $pagination_links = paginate_links( $pagination ) ) {
691
692 // Remove first page from pagination
693 if ( $wp_rewrite->using_permalinks() )
694 $pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $pagination_links );
695 else
696 $pagination_links = str_replace( '&#038;paged=1', '', $pagination_links );
697
698 // Add before and after to pagination links
699 $pagination_links = $before . $pagination_links . $after;
700 }
701
702 return apply_filters( 'bbp_get_topic_pagination', $pagination_links, $args );
703 }
704
705 /**
706 * Append revisions to the topic content
707 *
708 * @since bbPress (r2782)
709 *
710 * @param string $content Optional. Content to which we need to append the revisions to
711 * @param int $topic_id Optional. Topic id
712 * @uses bbp_get_topic_revision_log() To get the topic revision log
713 * @uses apply_filters() Calls 'bbp_topic_append_revisions' with the processed
714 * content, original content and topic id
715 * @return string Content with the revisions appended
716 */
717 function bbp_topic_content_append_revisions( $content = '', $topic_id = 0 ) {
718
719 // Bail if in admin
720 if ( is_admin() )
721 return;
722
723 // Validate the ID
724 $topic_id = bbp_get_topic_id( $topic_id );
725
726 return apply_filters( 'bbp_topic_append_revisions', $content . bbp_get_topic_revision_log( $topic_id ), $content, $topic_id );
727 }
728
729 /**
730 * Output the revision log of the topic
731 *
732 * @since bbPress (r2782)
733 *
734 * @param int $topic_id Optional. Topic id
735 * @uses bbp_get_topic_revision_log() To get the topic revision log
736 */
737 function bbp_topic_revision_log( $topic_id = 0 ) {
738 echo bbp_get_topic_revision_log( $topic_id );
739 }
740 /**
741 * Return the formatted revision log of the topic
742 *
743 * @since bbPress (r2782)
744 *
745 * @param int $topic_id Optional. Topic id
746 * @uses bbp_get_topic_id() To get the topic id
747 * @uses bbp_get_topic_revisions() To get the topic revisions
748 * @uses bbp_get_topic_raw_revision_log() To get the raw revision log
749 * @uses bbp_get_topic_author_display_name() To get the topic author
750 * @uses bbp_get_author_link() To get the topic author link
751 * @uses bbp_convert_date() To convert the date
752 * @uses bbp_get_time_since() To get the time in since format
753 * @uses apply_filters() Calls 'bbp_get_topic_revision_log' with the
754 * log and topic id
755 * @return string Revision log of the topic
756 */
757 function bbp_get_topic_revision_log( $topic_id = 0 ) {
758 // Create necessary variables
759 $topic_id = bbp_get_topic_id( $topic_id );
760 $revision_log = bbp_get_topic_raw_revision_log( $topic_id );
761
762 if ( empty( $topic_id ) || empty( $revision_log ) || !is_array( $revision_log ) )
763 return false;
764
765 if ( !$revisions = bbp_get_topic_revisions( $topic_id ) )
766 return false;
767
768 $r = "\n\n" . '<ul id="bbp-topic-revision-log-' . $topic_id . '" class="bbp-topic-revision-log">' . "\n\n";
769
770 // Loop through revisions
771 foreach ( (array) $revisions as $revision ) {
772
773 if ( empty( $revision_log[$revision->ID] ) ) {
774 $author_id = $revision->post_author;
775 $reason = '';
776 } else {
777 $author_id = $revision_log[$revision->ID]['author'];
778 $reason = $revision_log[$revision->ID]['reason'];
779 }
780
781 $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_topic_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) );
782 $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) );
783
784 $r .= "\t" . '<li id="bbp-topic-revision-log-' . $topic_id . '-item-' . $revision->ID . '" class="bbp-topic-revision-log-item">' . "\n";
785 $r .= "\t\t" . sprintf( __( empty( $reason ) ? 'This topic was modified %1$s ago by %2$s.' : 'This topic was modified %1$s ago by %2$s. Reason: %3$s', 'bbpress' ), $since, $author, $reason ) . "\n";
786 $r .= "\t" . '</li>' . "\n";
787
788 }
789
790 $r .= "\n" . '</ul>' . "\n\n";
791
792 return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id );
793 }
794 /**
795 * Return the raw revision log of the topic
796 *
797 * @since bbPress (r2782)
798 *
799 * @param int $topic_id Optional. Topic id
800 * @uses bbp_get_topic_id() To get the topic id
801 * @uses get_post_meta() To get the revision log meta
802 * @uses apply_filters() Calls 'bbp_get_topic_raw_revision_log'
803 * with the log and topic id
804 * @return string Raw revision log of the topic
805 */
806 function bbp_get_topic_raw_revision_log( $topic_id = 0 ) {
807 $topic_id = bbp_get_topic_id( $topic_id );
808
809 $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true );
810 $revision_log = empty( $revision_log ) ? array() : $revision_log;
811
812 return apply_filters( 'bbp_get_topic_raw_revision_log', $revision_log, $topic_id );
813 }
814
815 /**
816 * Return the revisions of the topic
817 *
818 * @since bbPress (r2782)
819 *
820 * @param int $topic_id Optional. Topic id
821 * @uses bbp_get_topic_id() To get the topic id
822 * @uses wp_get_post_revisions() To get the topic revisions
823 * @uses apply_filters() Calls 'bbp_get_topic_revisions'
824 * with the revisions and topic id
825 * @return string Topic revisions
826 */
827 function bbp_get_topic_revisions( $topic_id = 0 ) {
828 $topic_id = bbp_get_topic_id( $topic_id );
829 $revisions = wp_get_post_revisions( $topic_id, array( 'order' => 'ASC' ) );
830
831 return apply_filters( 'bbp_get_topic_revisions', $revisions, $topic_id );
832 }
833
834 /**
835 * Return the revision count of the topic
836 *
837 * @since bbPress (r2782)
838 *
839 * @param int $topic_id Optional. Topic id
840 * @uses bbp_get_topic_revisions() To get the topic revisions
841 * @uses apply_filters() Calls 'bbp_get_topic_revision_count'
842 * with the revision count and topic id
843 * @return string Topic revision count
844 */
845 function bbp_get_topic_revision_count( $topic_id = 0 ) {
846 return apply_filters( 'bbp_get_topic_revisions', count( bbp_get_topic_revisions( $topic_id ) ), $topic_id );
847 }
848
849 /**
850 * Output the status of the topic
851 *
852 * @since bbPress (r2667)
853 *
854 * @param int $topic_id Optional. Topic id
855 * @uses bbp_get_topic_status() To get the topic status
856 */
857 function bbp_topic_status( $topic_id = 0 ) {
858 echo bbp_get_topic_status( $topic_id );
859 }
860 /**
861 * Return the status of the topic
862 *
863 * @since bbPress (r2667)
864 *
865 * @param int $topic_id Optional. Topic id
866 * @uses bbp_get_topic_id() To get the topic id
867 * @uses get_post_status() To get the topic status
868 * @uses apply_filters() Calls 'bbp_get_topic_status' with the status
869 * and topic id
870 * @return string Status of topic
871 */
872 function bbp_get_topic_status( $topic_id = 0 ) {
873 $topic_id = bbp_get_topic_id( $topic_id );
874
875 return apply_filters( 'bbp_get_topic_status', get_post_status( $topic_id ), $topic_id );
876 }
877
878 /**
879 * Is the topic open to new replies?
880 *
881 * @since bbPress (r2727)
882 *
883 * @uses bbp_get_topic_status()
884 *
885 * @param int $topic_id Optional. Topic id
886 * @uses bbp_is_topic_closed() To check if the topic is closed
887 * @return bool True if open, false if closed.
888 */
889 function bbp_is_topic_open( $topic_id = 0 ) {
890 return !bbp_is_topic_closed( $topic_id );
891 }
892
893 /**
894 * Is the topic closed to new replies?
895 *
896 * @since bbPress (r2746)
897 *
898 * @param int $topic_id Optional. Topic id
899 * @uses bbp_get_topic_status() To get the topic status
900 * @return bool True if closed, false if not.
901 */
902 function bbp_is_topic_closed( $topic_id = 0 ) {
903 if ( bbp_get_closed_status_id() == bbp_get_topic_status( $topic_id ) )
904 return true;
905
906 return false;
907 }
908
909 /**
910 * Is the topic a sticky or super sticky?
911 *
912 * @since bbPress (r2754)
913 *
914 * @param int $topic_id Optional. Topic id
915 * @param int $check_super Optional. If set to true and if the topic is not a
916 * normal sticky, it is checked if it is a super
917 * sticky or not. Defaults to true.
918 * @uses bbp_get_topic_id() To get the topic id
919 * @uses bbp_get_topic_forum_id() To get the topic forum id
920 * @uses bbp_get_stickies() To get the stickies
921 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
922 * @return bool True if sticky or super sticky, false if not.
923 */
924 function bbp_is_topic_sticky( $topic_id = 0, $check_super = true ) {
925 $topic_id = bbp_get_topic_id( $topic_id );
926 $forum_id = bbp_get_topic_forum_id( $topic_id );
927 $stickies = bbp_get_stickies( $forum_id );
928
929 if ( in_array( $topic_id, $stickies ) || ( !empty( $check_super ) && bbp_is_topic_super_sticky( $topic_id ) ) )
930 return true;
931
932 return false;
933 }
934
935 /**
936 * Is the topic a super sticky?
937 *
938 * @since bbPress (r2754)
939 *
940 * @param int $topic_id Optional. Topic id
941 * @uses bbp_get_topic_id() To get the topic id
942 * @uses bbp_get_super_stickies() To get the super stickies
943 * @return bool True if super sticky, false if not.
944 */
945 function bbp_is_topic_super_sticky( $topic_id = 0 ) {
946 $topic_id = bbp_get_topic_id( $topic_id );
947 $stickies = bbp_get_super_stickies( $topic_id );
948
949 return in_array( $topic_id, $stickies );
950 }
951
952 /**
953 * Is the topic not spam or deleted?
954 *
955 * @since bbPress (r3496)
956 *
957 * @param int $topic_id Optional. Topic id
958 * @uses bbp_get_topic_id() To get the topic id
959 * @uses bbp_get_topic_status() To get the topic status
960 * @return bool True if published, false if not.
961 */
962 function bbp_is_topic_published( $topic_id = 0 ) {
963 $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) );
964 return bbp_get_public_status_id() == $topic_status;
965 }
966
967 /**
968 * Is the topic marked as spam?
969 *
970 * @since bbPress (r2727)
971 *
972 * @param int $topic_id Optional. Topic id
973 * @uses bbp_get_topic_id() To get the topic id
974 * @uses bbp_get_topic_status() To get the topic status
975 * @return bool True if spam, false if not.
976 */
977 function bbp_is_topic_spam( $topic_id = 0 ) {
978 $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) );
979 return bbp_get_spam_status_id() == $topic_status;
980 }
981
982 /**
983 * Is the topic trashed?
984 *
985 * @since bbPress (r2888)
986 *
987 * @param int $topic_id Optional. Topic id
988 * @uses bbp_get_topic_id() To get the topic id
989 * @uses bbp_get_topic_status() To get the topic status
990 * @return bool True if trashed, false if not.
991 */
992 function bbp_is_topic_trash( $topic_id = 0 ) {
993 $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) );
994 return bbp_get_trash_status_id() == $topic_status;
995 }
996
997 /**
998 * Is the posted by an anonymous user?
999 *
1000 * @since bbPress (r2753)
1001 *
1002 * @param int $topic_id Optional. Topic id
1003 * @uses bbp_get_topic_id() To get the topic id
1004 * @uses bbp_get_topic_author_id() To get the topic author id
1005 * @uses get_post_meta() To get the anonymous user name and email meta
1006 * @return bool True if the post is by an anonymous user, false if not.
1007 */
1008 function bbp_is_topic_anonymous( $topic_id = 0 ) {
1009 $topic_id = bbp_get_topic_id( $topic_id );
1010
1011 if ( 0 != bbp_get_topic_author_id( $topic_id ) )
1012 return false;
1013
1014 if ( false == get_post_meta( $topic_id, '_bbp_anonymous_name', true ) )
1015 return false;
1016
1017 if ( false == get_post_meta( $topic_id, '_bbp_anonymous_email', true ) )
1018 return false;
1019
1020 // The topic is by an anonymous user
1021 return true;
1022 }
1023
1024 /**
1025 * Output the author of the topic
1026 *
1027 * @since bbPress (r2590)
1028 *
1029 * @param int $topic_id Optional. Topic id
1030 * @uses bbp_get_topic_author() To get the topic author
1031 */
1032 function bbp_topic_author( $topic_id = 0 ) {
1033 echo bbp_get_topic_author( $topic_id );
1034 }
1035 /**
1036 * Return the author of the topic
1037 *
1038 * @since bbPress (r2590)
1039 *
1040 * @param int $topic_id Optional. Topic id
1041 * @uses bbp_get_topic_id() To get the topic id
1042 * @uses bbp_is_topic_anonymous() To check if the topic is by an
1043 * anonymous user
1044 * @uses bbp_get_topic_author_id() To get the topic author id
1045 * @uses get_the_author_meta() To get the display name of the author
1046 * @uses get_post_meta() To get the name of the anonymous poster
1047 * @uses apply_filters() Calls 'bbp_get_topic_author' with the author
1048 * and topic id
1049 * @return string Author of topic
1050 */
1051 function bbp_get_topic_author( $topic_id = 0 ) {
1052 $topic_id = bbp_get_topic_id( $topic_id );
1053
1054 if ( !bbp_is_topic_anonymous( $topic_id ) )
1055 $author = get_the_author_meta( 'display_name', bbp_get_topic_author_id( $topic_id ) );
1056 else
1057 $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
1058
1059 return apply_filters( 'bbp_get_topic_author', $author, $topic_id );
1060 }
1061
1062 /**
1063 * Output the author ID of the topic
1064 *
1065 * @since bbPress (r2590)
1066 *
1067 * @param int $topic_id Optional. Topic id
1068 * @uses bbp_get_topic_author_id() To get the topic author id
1069 */
1070 function bbp_topic_author_id( $topic_id = 0 ) {
1071 echo bbp_get_topic_author_id( $topic_id );
1072 }
1073 /**
1074 * Return the author ID of the topic
1075 *
1076 * @since bbPress (r2590)
1077 *
1078 * @param int $topic_id Optional. Topic id
1079 * @uses bbp_get_topic_id() To get the topic id
1080 * @uses get_post_field() To get the topic author id
1081 * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the author
1082 * id and topic id
1083 * @return string Author of topic
1084 */
1085 function bbp_get_topic_author_id( $topic_id = 0 ) {
1086 $topic_id = bbp_get_topic_id( $topic_id );
1087 $author_id = get_post_field( 'post_author', $topic_id );
1088
1089 return apply_filters( 'bbp_get_topic_author_id', (int) $author_id, $topic_id );
1090 }
1091
1092 /**
1093 * Output the author display_name of the topic
1094 *
1095 * @since bbPress (r2590)
1096 *
1097 * @param int $topic_id Optional. Topic id
1098 * @uses bbp_get_topic_author_display_name() To get the topic author's display
1099 * name
1100 */
1101 function bbp_topic_author_display_name( $topic_id = 0 ) {
1102 echo bbp_get_topic_author_display_name( $topic_id );
1103 }
1104 /**
1105 * Return the author display_name of the topic
1106 *
1107 * @since bbPress (r2485)
1108 *
1109 * @param int $topic_id Optional. Topic id
1110 * @uses bbp_get_topic_id() To get the topic id
1111 * @uses bbp_is_topic_anonymous() To check if the topic is by an
1112 * anonymous user
1113 * @uses bbp_get_topic_author_id() To get the topic author id
1114 * @uses get_the_author_meta() To get the author meta
1115 * @uses get_post_meta() To get the anonymous user name
1116 * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the
1117 * display name and topic id
1118 * @return string Topic's author's display name
1119 */
1120 function bbp_get_topic_author_display_name( $topic_id = 0 ) {
1121 $topic_id = bbp_get_topic_id( $topic_id );
1122
1123 // Check for anonymous user
1124 if ( !bbp_is_topic_anonymous( $topic_id ) )
1125 $author_name = get_the_author_meta( 'display_name', bbp_get_topic_author_id( $topic_id ) );
1126 else
1127 $author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
1128
1129 return apply_filters( 'bbp_get_topic_author_id', esc_attr( $author_name ), $topic_id );
1130 }
1131
1132 /**
1133 * Output the author avatar of the topic
1134 *
1135 * @since bbPress (r2590)
1136 *
1137 * @param int $topic_id Optional. Topic id
1138 * @param int $size Optional. Avatar size. Defaults to 40
1139 * @uses bbp_get_topic_author_avatar() To get the topic author avatar
1140 */
1141 function bbp_topic_author_avatar( $topic_id = 0, $size = 40 ) {
1142 echo bbp_get_topic_author_avatar( $topic_id, $size );
1143 }
1144 /**
1145 * Return the author avatar of the topic
1146 *
1147 * @since bbPress (r2590)
1148 *
1149 * @param int $topic_id Optional. Topic id
1150 * @param int $size Optional. Avatar size. Defaults to 40
1151 * @uses bbp_get_topic_id() To get the topic id
1152 * @uses bbp_is_topic_anonymous() To check if the topic is by an
1153 * anonymous user
1154 * @uses bbp_get_topic_author_id() To get the topic author id
1155 * @uses get_post_meta() To get the anonymous user's email
1156 * @uses get_avatar() To get the avatar
1157 * @uses apply_filters() Calls 'bbp_get_topic_author_avatar' with the
1158 * avatar, topic id and size
1159 * @return string Avatar of the author of the topic
1160 */
1161 function bbp_get_topic_author_avatar( $topic_id = 0, $size = 40 ) {
1162 $author_avatar = '';
1163
1164 if ( $topic_id = bbp_get_topic_id( $topic_id ) ) {
1165
1166 // Check for anonymous user
1167 if ( !bbp_is_topic_anonymous( $topic_id ) )
1168 $author_avatar = get_avatar( bbp_get_topic_author_id( $topic_id ), $size );
1169 else
1170 $author_avatar = get_avatar( get_post_meta( $topic_id, '_bbp_anonymous_email', true ), $size );
1171 }
1172
1173 return apply_filters( 'bbp_get_topic_author_avatar', $author_avatar, $topic_id, $size );
1174 }
1175
1176 /**
1177 * Output the author link of the topic
1178 *
1179 * @since bbPress (r2717)
1180 *
1181 * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
1182 * @uses bbp_get_topic_author_link() To get the topic author link
1183 */
1184 function bbp_topic_author_link( $args = '' ) {
1185 echo bbp_get_topic_author_link( $args );
1186 }
1187 /**
1188 * Return the author link of the topic
1189 *
1190 * @since bbPress (r2717)
1191 *
1192 * @param mixed|int $args If it is an integer, it is used as topic id.
1193 * Optional.
1194 * @uses bbp_get_topic_id() To get the topic id
1195 * @uses bbp_get_topic_author_display_name() To get the topic author
1196 * @uses bbp_is_topic_anonymous() To check if the topic is by an
1197 * anonymous user
1198 * @uses bbp_get_topic_author_avatar() To get the topic author avatar
1199 * @uses bbp_get_topic_author_url() To get the topic author url
1200 * @uses apply_filters() Calls 'bbp_get_topic_author_link' with the link
1201 * and args
1202 * @return string Author link of topic
1203 */
1204 function bbp_get_topic_author_link( $args = '' ) {
1205 $defaults = array (
1206 'post_id' => 0,
1207 'link_title' => '',
1208 'type' => 'both',
1209 'size' => 80,
1210 'sep' => '&nbsp;'
1211 );
1212
1213 $r = wp_parse_args( $args, $defaults );
1214 extract( $r );
1215
1216 // Used as topic_id
1217 if ( is_numeric( $args ) )
1218 $topic_id = bbp_get_topic_id( $args );
1219 else
1220 $topic_id = bbp_get_topic_id( $post_id );
1221
1222 if ( !empty( $topic_id ) ) {
1223 if ( empty( $link_title ) )
1224 $link_title = sprintf( !bbp_is_topic_anonymous( $topic_id ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_topic_author_display_name( $topic_id ) );
1225
1226 $link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : '';
1227 $author_url = bbp_get_topic_author_url( $topic_id );
1228 $anonymous = bbp_is_topic_anonymous( $topic_id );
1229
1230 // Get avatar
1231 if ( 'avatar' == $type || 'both' == $type )
1232 $author_links['avatar'] = bbp_get_topic_author_avatar( $topic_id, $size );
1233
1234 // Get display name
1235 if ( 'name' == $type || 'both' == $type )
1236 $author_links['name'] = bbp_get_topic_author_display_name( $topic_id );
1237
1238 // Link class
1239 $link_class = ' class="bbp-author-' . $type . '"';
1240
1241 // Add links if not anonymous
1242 if ( empty( $anonymous ) ) {
1243 foreach ( $author_links as $link => $link_text ) {
1244 $link_class = ' class="bbp-author-' . $link . '"';
1245 $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', $author_url, $link_title, $link_class, $link_text );
1246 }
1247 $author_link = join( $sep, $author_link );
1248
1249 // No links if anonymous
1250 } else {
1251 $author_link = join( $sep, $author_links );
1252 }
1253
1254 } else {
1255 $author_link = '';
1256 }
1257
1258 return apply_filters( 'bbp_get_topic_author_link', $author_link, $args );
1259 }
1260
1261 /**
1262 * Output the author url of the topic
1263 *
1264 * @since bbPress (r2590)
1265 *
1266 * @param int $topic_id Optional. Topic id
1267 * @uses bbp_get_topic_author_url() To get the topic author url
1268 */
1269 function bbp_topic_author_url( $topic_id = 0 ) {
1270 echo bbp_get_topic_author_url( $topic_id );
1271 }
1272
1273 /**
1274 * Return the author url of the topic
1275 *
1276 * @since bbPress (r2590)
1277 *
1278 * @param int $topic_id Optional. Topic id
1279 * @uses bbp_get_topic_id() To get the topic id
1280 * @uses bbp_is_topic_anonymous() To check if the topic
1281 * is by an anonymous
1282 * user or not
1283 * @uses bbp_get_topic_author_id() To get topic author
1284 * id
1285 * @uses bbp_get_user_profile_url() To get profile url
1286 * @uses get_post_meta() To get anonmous user's website
1287 * @uses apply_filters() Calls
1288 * 'bbp_get_topic_author_url'
1289 * with the link & topic id
1290 * @return string Author URL of topic
1291 */
1292 function bbp_get_topic_author_url( $topic_id = 0 ) {
1293 $topic_id = bbp_get_topic_id( $topic_id );
1294
1295 // Check for anonymous user
1296 if ( !bbp_is_topic_anonymous( $topic_id ) ) {
1297 $author_url = bbp_get_user_profile_url( bbp_get_topic_author_id( $topic_id ) );
1298 } else {
1299 if ( !$author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true ) ) {
1300 $author_url = '';
1301 }
1302 }
1303
1304 return apply_filters( 'bbp_get_topic_author_url', $author_url, $topic_id );
1305 }
1306
1307 /**
1308 * Output the topic author email address
1309 *
1310 * @since bbPress (r3445)
1311 *
1312 * @param int $topic_id Optional. Reply id
1313 * @uses bbp_get_topic_author_email() To get the topic author email
1314 */
1315 function bbp_topic_author_email( $topic_id = 0 ) {
1316 echo bbp_get_topic_author_email( $topic_id );
1317 }
1318 /**
1319 * Return the topic author email address
1320 *
1321 * @since bbPress (r3445)
1322 *
1323 * @param int $topic_id Optional. Reply id
1324 * @uses bbp_get_topic_id() To get the topic id
1325 * @uses bbp_is_topic_anonymous() To check if the topic is by an anonymous
1326 * user
1327 * @uses bbp_get_topic_author_id() To get the topic author id
1328 * @uses get_userdata() To get the user data
1329 * @uses get_post_meta() To get the anonymous poster's email
1330 * @uses apply_filters() Calls bbp_get_topic_author_email with the author
1331 * email & topic id
1332 * @return string Topic author email address
1333 */
1334 function bbp_get_topic_author_email( $topic_id = 0 ) {
1335 $topic_id = bbp_get_topic_id( $topic_id );
1336
1337 // Not anonymous user
1338 if ( !bbp_is_topic_anonymous( $topic_id ) ) {
1339
1340 // Use topic author email address
1341 $user_id = bbp_get_topic_author_id( $topic_id );
1342 $user = get_userdata( $user_id );
1343 $author_email = !empty( $user->user_email ) ? $user->user_email : '';
1344
1345 // Anonymous
1346 } else {
1347
1348 // Get email from post meta
1349 $author_email = get_post_meta( $topic_id, '_bbp_anonymous_email', true );
1350
1351 // Sanity check for missing email address
1352 if ( empty( $author_email ) ) {
1353 $author_email = '';
1354 }
1355 }
1356
1357 return apply_filters( 'bbp_get_topic_author_email', $author_email, $topic_id );
1358 }
1359
1360 /**
1361 * Output the title of the forum a topic belongs to
1362 *
1363 * @since bbPress (r2485)
1364 *
1365 * @param int $topic_id Optional. Topic id
1366 * @uses bbp_get_topic_forum_title() To get the topic's forum title
1367 */
1368 function bbp_topic_forum_title( $topic_id = 0 ) {
1369 echo bbp_get_topic_forum_title( $topic_id );
1370 }
1371 /**
1372 * Return the title of the forum a topic belongs to
1373 *
1374 * @since bbPress (r2485)
1375 *
1376 * @param int $topic_id Optional. Topic id
1377 * @uses bbp_get_topic_id() To get topic id
1378 * @uses bbp_get_topic_forum_id() To get topic's forum id
1379 * @uses apply_filters() Calls 'bbp_get_topic_forum' with the forum
1380 * title and topic id
1381 * @return string Topic forum title
1382 */
1383 function bbp_get_topic_forum_title( $topic_id = 0 ) {
1384 $topic_id = bbp_get_topic_id( $topic_id );
1385 $forum_id = bbp_get_topic_forum_id( $topic_id );
1386
1387 return apply_filters( 'bbp_get_topic_forum', bbp_get_forum_title( $forum_id ), $topic_id );
1388 }
1389
1390 /**
1391 * Output the forum id a topic belongs to
1392 *
1393 * @since bbPress (r2491)
1394 *
1395 * @param int $topic_id Optional. Topic id
1396 * @uses bbp_get_topic_forum_id()
1397 */
1398 function bbp_topic_forum_id( $topic_id = 0 ) {
1399 echo bbp_get_topic_forum_id( $topic_id );
1400 }
1401 /**
1402 * Return the forum id a topic belongs to
1403 *
1404 * @since bbPress (r2491)
1405 *
1406 * @param int $topic_id Optional. Topic id
1407 * @uses bbp_get_topic_id() To get topic id
1408 * @uses get_post_meta() To retrieve get topic's forum id meta
1409 * @uses apply_filters() Calls 'bbp_get_topic_forum_id' with the forum
1410 * id and topic id
1411 * @return int Topic forum id
1412 */
1413 function bbp_get_topic_forum_id( $topic_id = 0 ) {
1414 $topic_id = bbp_get_topic_id( $topic_id );
1415 $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true );
1416
1417 return apply_filters( 'bbp_get_topic_forum_id', (int) $forum_id, $topic_id );
1418 }
1419
1420 /**
1421 * Output the topics last active ID
1422 *
1423 * @since bbPress (r2860)
1424 *
1425 * @param int $topic_id Optional. Forum id
1426 * @uses bbp_get_topic_last_active_id() To get the topic's last active id
1427 */
1428 function bbp_topic_last_active_id( $topic_id = 0 ) {
1429 echo bbp_get_topic_last_active_id( $topic_id );
1430 }
1431 /**
1432 * Return the topics last active ID
1433 *
1434 * @since bbPress (r2860)
1435 *
1436 * @param int $topic_id Optional. Forum id
1437 * @uses bbp_get_topic_id() To get the topic id
1438 * @uses get_post_meta() To get the topic's last active id
1439 * @uses apply_filters() Calls 'bbp_get_topic_last_active_id' with
1440 * the last active id and topic id
1441 * @return int Forum's last active id
1442 */
1443 function bbp_get_topic_last_active_id( $topic_id = 0 ) {
1444 $topic_id = bbp_get_topic_id( $topic_id );
1445 $active_id = get_post_meta( $topic_id, '_bbp_last_active_id', true );
1446
1447 return apply_filters( 'bbp_get_topic_last_active_id', (int) $active_id, $topic_id );
1448 }
1449
1450 /**
1451 * Output the topics last update date/time (aka freshness)
1452 *
1453 * @since bbPress (r2625)
1454 *
1455 * @param int $topic_id Optional. Topic id
1456 * @uses bbp_get_topic_last_active_time() To get topic freshness
1457 */
1458 function bbp_topic_last_active_time( $topic_id = 0 ) {
1459 echo bbp_get_topic_last_active_time( $topic_id );
1460 }
1461 /**
1462 * Return the topics last update date/time (aka freshness)
1463 *
1464 * @since bbPress (r2625)
1465 *
1466 * @param int $topic_id Optional. Topic id
1467 * @uses bbp_get_topic_id() To get topic id
1468 * @uses get_post_meta() To get the topic lst active meta
1469 * @uses bbp_get_topic_last_reply_id() To get topic last reply id
1470 * @uses get_post_field() To get the post date of topic/reply
1471 * @uses bbp_convert_date() To convert date
1472 * @uses bbp_get_time_since() To get time in since format
1473 * @uses apply_filters() Calls 'bbp_get_topic_last_active' with topic
1474 * freshness and topic id
1475 * @return string Topic freshness
1476 */
1477 function bbp_get_topic_last_active_time( $topic_id = 0 ) {
1478 $topic_id = bbp_get_topic_id( $topic_id );
1479
1480 // Try to get the most accurate freshness time possible
1481 if ( !$last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true ) ) {
1482 if ( $reply_id = bbp_get_topic_last_reply_id( $topic_id ) ) {
1483 $last_active = get_post_field( 'post_date', $reply_id );
1484 } else {
1485 $last_active = get_post_field( 'post_date', $topic_id );
1486 }
1487 }
1488
1489 $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
1490
1491 // Return the time since
1492 return apply_filters( 'bbp_get_topic_last_active', $last_active, $topic_id );
1493 }
1494
1495 /** Topic Last Reply **********************************************************/
1496
1497 /**
1498 * Output the id of the topics last reply
1499 *
1500 * @since bbPress (r2625)
1501 *
1502 * @param int $topic_id Optional. Topic id
1503 * @uses bbp_get_topic_last_reply_id() To get the topic last reply id
1504 */
1505 function bbp_topic_last_reply_id( $topic_id = 0 ) {
1506 echo bbp_get_topic_last_reply_id( $topic_id );
1507 }
1508 /**
1509 * Return the topics last update date/time (aka freshness)
1510 *
1511 * @since bbPress (r2625)
1512 *
1513 * @param int $topic_id Optional. Topic id
1514 * @uses bbp_get_topic_id() To get the topic id
1515 * @uses get_post_meta() To get the last reply id meta
1516 * @uses apply_filters() Calls 'bbp_get_topic_last_reply_id' with the
1517 * last reply id and topic id
1518 * @return int Topic last reply id
1519 */
1520 function bbp_get_topic_last_reply_id( $topic_id = 0 ) {
1521 $topic_id = bbp_get_topic_id( $topic_id );
1522 $reply_id = get_post_meta( $topic_id, '_bbp_last_reply_id', true );
1523
1524 if ( empty( $reply_id ) )
1525 $reply_id = $topic_id;
1526
1527 return apply_filters( 'bbp_get_topic_last_reply_id', (int) $reply_id, $topic_id );
1528 }
1529
1530 /**
1531 * Output the title of the last reply inside a topic
1532 *
1533 * @param int $topic_id Optional. Topic id
1534 * @uses bbp_get_topic_last_reply_title() To get the topic last reply title
1535 */
1536 function bbp_topic_last_reply_title( $topic_id = 0 ) {
1537 echo bbp_get_topic_last_reply_title( $topic_id );
1538 }
1539 /**
1540 * Return the title of the last reply inside a topic
1541 *
1542 * @param int $topic_id Optional. Topic id
1543 * @uses bbp_get_topic_id() To get the topic id
1544 * @uses bbp_get_topic_last_reply_id() To get the topic last reply id
1545 * @uses bbp_get_reply_title() To get the reply title
1546 * @uses apply_filters() Calls 'bbp_get_topic_last_topic_title' with
1547 * the reply title and topic id
1548 * @return string Topic last reply title
1549 */
1550 function bbp_get_topic_last_reply_title( $topic_id = 0 ) {
1551 $topic_id = bbp_get_topic_id( $topic_id );
1552 return apply_filters( 'bbp_get_topic_last_topic_title', bbp_get_reply_title( bbp_get_topic_last_reply_id( $topic_id ) ), $topic_id );
1553 }
1554
1555 /**
1556 * Output the link to the last reply in a topic
1557 *
1558 * @since bbPress (r2464)
1559 *
1560 * @param int $topic_id Optional. Topic id
1561 * @uses bbp_get_topic_last_reply_permalink() To get the topic's last reply link
1562 */
1563 function bbp_topic_last_reply_permalink( $topic_id = 0 ) {
1564 echo bbp_get_topic_last_reply_permalink( $topic_id );
1565 }
1566 /**
1567 * Return the link to the last reply in a topic
1568 *
1569 * @since bbPress (r2464)
1570 *
1571 * @param int $topic_id Optional. Topic id
1572 * @uses bbp_get_topic_id() To get the topic id
1573 * @uses bbp_get_topic_last_reply_id() To get the topic last reply id
1574 * @uses bbp_get_reply_permalink() To get the reply permalink
1575 * @uses apply_filters() Calls 'bbp_get_topic_last_topic_permalink' with
1576 * the reply permalink and topic id
1577 * @return string Permanent link to the reply
1578 */
1579 function bbp_get_topic_last_reply_permalink( $topic_id = 0 ) {
1580 $topic_id = bbp_get_topic_id( $topic_id );
1581 return apply_filters( 'bbp_get_topic_last_reply_permalink', bbp_get_reply_permalink( bbp_get_topic_last_reply_id( $topic_id ) ) );
1582 }
1583
1584 /**
1585 * Output the link to the last reply in a topic
1586 *
1587 * @since bbPress (r2683)
1588 *
1589 * @param int $topic_id Optional. Topic id
1590 * @uses bbp_get_topic_last_reply_url() To get the topic last reply url
1591 */
1592 function bbp_topic_last_reply_url( $topic_id = 0 ) {
1593 echo bbp_get_topic_last_reply_url( $topic_id );
1594 }
1595 /**
1596 * Return the link to the last reply in a topic
1597 *
1598 * @since bbPress (r2683)
1599 *
1600 * @param int $topic_id Optional. Topic id
1601 * @uses bbp_get_topic_id() To get the topic id
1602 * @uses bbp_get_topic_last_reply_id() To get the topic last reply id
1603 * @uses bbp_get_reply_url() To get the reply url
1604 * @uses bbp_get_reply_permalink() To get the reply permalink
1605 * @uses apply_filters() Calls 'bbp_get_topic_last_topic_url' with
1606 * the reply url and topic id
1607 * @return string Topic last reply url
1608 */
1609 function bbp_get_topic_last_reply_url( $topic_id = 0 ) {
1610 $topic_id = bbp_get_topic_id( $topic_id );
1611 $reply_id = bbp_get_topic_last_reply_id( $topic_id );
1612
1613 if ( !empty( $reply_id ) && ( $reply_id != $topic_id ) )
1614 $reply_url = bbp_get_reply_url( $reply_id );
1615 else
1616 $reply_url = bbp_get_topic_permalink( $topic_id );
1617
1618 return apply_filters( 'bbp_get_topic_last_reply_url', $reply_url );
1619 }
1620
1621 /**
1622 * Output link to the most recent activity inside a topic, complete with link
1623 * attributes and content.
1624 *
1625 * @since bbPress (r2625)
1626 *
1627 * @param int $topic_id Optional. Topic id
1628 * @uses bbp_get_topic_freshness_link() To get the topic freshness link
1629 */
1630 function bbp_topic_freshness_link( $topic_id = 0 ) {
1631 echo bbp_get_topic_freshness_link( $topic_id );
1632 }
1633 /**
1634 * Returns link to the most recent activity inside a topic, complete
1635 * with link attributes and content.
1636 *
1637 * @since bbPress (r2625)
1638 *
1639 * @param int $topic_id Optional. Topic id
1640 * @uses bbp_get_topic_id() To get the topic id
1641 * @uses bbp_get_topic_last_reply_url() To get the topic last reply url
1642 * @uses bbp_get_topic_last_reply_title() To get the reply title
1643 * @uses bbp_get_topic_last_active_time() To get the topic freshness
1644 * @uses apply_filters() Calls 'bbp_get_topic_freshness_link' with the
1645 * link and topic id
1646 * @return string Topic freshness link
1647 */
1648 function bbp_get_topic_freshness_link( $topic_id = 0 ) {
1649 $topic_id = bbp_get_topic_id( $topic_id );
1650 $link_url = bbp_get_topic_last_reply_url( $topic_id );
1651 $title = bbp_get_topic_last_reply_title( $topic_id );
1652 $time_since = bbp_get_topic_last_active_time( $topic_id );
1653
1654 if ( !empty( $time_since ) )
1655 $anchor = '<a href="' . $link_url . '" title="' . esc_attr( $title ) . '">' . $time_since . '</a>';
1656 else
1657 $anchor = __( 'No Replies', 'bbpress' );
1658
1659 return apply_filters( 'bbp_get_topic_freshness_link', $anchor, $topic_id );
1660 }
1661
1662 /**
1663 * Output the replies link of the topic
1664 *
1665 * @since bbPress (r2740)
1666 *
1667 * @param int $topic_id Optional. Topic id
1668 * @uses bbp_get_topic_replies_link() To get the topic replies link
1669 */
1670 function bbp_topic_replies_link( $topic_id = 0 ) {
1671 echo bbp_get_topic_replies_link( $topic_id );
1672 }
1673
1674 /**
1675 * Return the replies link of the topic
1676 *
1677 * @since bbPress (r2740)
1678 *
1679 * @param int $topic_id Optional. Topic id
1680 * @uses bbp_get_topic_id() To get the topic id
1681 * @uses bbp_get_topic() To get the topic
1682 * @uses bbp_get_topic_reply_count() To get the topic reply count
1683 * @uses bbp_get_topic_permalink() To get the topic permalink
1684 * @uses remove_query_arg() To remove args from the url
1685 * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden
1686 * reply count
1687 * @uses current_user_can() To check if the current user can edit others
1688 * replies
1689 * @uses add_query_arg() To add custom args to the url
1690 * @uses apply_filters() Calls 'bbp_get_topic_replies_link' with the
1691 * replies link and topic id
1692 */
1693 function bbp_get_topic_replies_link( $topic_id = 0 ) {
1694
1695 $topic = bbp_get_topic( bbp_get_topic_id( (int) $topic_id ) );
1696 $topic_id = $topic->ID;
1697 $replies = bbp_get_topic_reply_count( $topic_id );
1698 $replies = sprintf( _n( '%s reply', '%s replies', $replies, 'bbpress' ), $replies );
1699 $retval = '';
1700
1701 // First link never has view=all
1702 if ( bbp_get_view_all( 'edit_others_replies' ) )
1703 $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_topic_permalink( $topic_id ) ) ) . "'>$replies</a>";
1704 else
1705 $retval .= $replies;
1706
1707 // This forum has hidden topics
1708 if ( current_user_can( 'edit_others_replies' ) && ( $deleted = bbp_get_topic_reply_count_hidden( $topic_id ) ) ) {
1709
1710 // Extra text
1711 $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted );
1712
1713 // No link
1714 if ( bbp_get_view_all() )
1715 $retval .= " $extra";
1716
1717 // Link
1718 else
1719 $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_topic_permalink( $topic_id ), true ) ) . "'>$extra</a>";
1720 }
1721
1722 return apply_filters( 'bbp_get_topic_replies_link', $retval, $topic_id );
1723 }
1724
1725 /**
1726 * Output total reply count of a topic
1727 *
1728 * @since bbPress (r2485)
1729 *
1730 * @param int $topic_id Optional. Topic id
1731 * @uses bbp_get_topic_reply_count() To get the topic reply count
1732 */
1733 function bbp_topic_reply_count( $topic_id = 0 ) {
1734 echo bbp_get_topic_reply_count( $topic_id );
1735 }
1736 /**
1737 * Return total reply count of a topic
1738 *
1739 * @since bbPress (r2485)
1740 *
1741 * @param int $topic_id Optional. Topic id
1742 * @uses bbp_get_topic_id() To get the topic id
1743 * @uses get_post_meta() To get the topic reply count meta
1744 * @uses apply_filters() Calls 'bbp_get_topic_reply_count' with the
1745 * reply count and topic id
1746 * @return int Reply count
1747 */
1748 function bbp_get_topic_reply_count( $topic_id = 0 ) {
1749 $topic_id = bbp_get_topic_id( $topic_id );
1750 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true );
1751
1752 return apply_filters( 'bbp_get_topic_reply_count', (int) $replies, $topic_id );
1753 }
1754
1755 /**
1756 * Output total post count of a topic
1757 *
1758 * @since bbPress (r2954)
1759 *
1760 * @param int $topic_id Optional. Topic id
1761 * @uses bbp_get_topic_post_count() To get the topic post count
1762 */
1763 function bbp_topic_post_count( $topic_id = 0 ) {
1764 echo bbp_get_topic_post_count( $topic_id );
1765 }
1766 /**
1767 * Return total post count of a topic
1768 *
1769 * @since bbPress (r2954)
1770 *
1771 * @param int $topic_id Optional. Topic id
1772 * @uses bbp_get_topic_id() To get the topic id
1773 * @uses get_post_meta() To get the topic post count meta
1774 * @uses apply_filters() Calls 'bbp_get_topic_post_count' with the
1775 * post count and topic id
1776 * @return int Post count
1777 */
1778 function bbp_get_topic_post_count( $topic_id = 0 ) {
1779 $topic_id = bbp_get_topic_id( $topic_id );
1780 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true );
1781
1782 return apply_filters( 'bbp_get_topic_post_count', (int) $replies + 1, $topic_id );
1783 }
1784
1785 /**
1786 * Output total hidden reply count of a topic (hidden includes trashed and
1787 * spammed replies)
1788 *
1789 * @since bbPress (r2740)
1790 *
1791 * @param int $topic_id Optional. Topic id
1792 * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count
1793 */
1794 function bbp_topic_reply_count_hidden( $topic_id = 0 ) {
1795 echo bbp_get_topic_reply_count_hidden( $topic_id );
1796 }
1797 /**
1798 * Return total hidden reply count of a topic (hidden includes trashed
1799 * and spammed replies)
1800 *
1801 * @since bbPress (r2740)
1802 *
1803 * @param int $topic_id Optional. Topic id
1804 * @uses bbp_get_topic_id() To get the topic id
1805 * @uses get_post_meta() To get the hidden reply count
1806 * @uses apply_filters() Calls 'bbp_get_topic_reply_count_hidden' with
1807 * the hidden reply count and topic id
1808 * @return int Topic hidden reply count
1809 */
1810 function bbp_get_topic_reply_count_hidden( $topic_id = 0 ) {
1811 $topic_id = bbp_get_topic_id( $topic_id );
1812 $replies = get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );
1813
1814 return apply_filters( 'bbp_get_topic_reply_count_hidden', (int) $replies, $topic_id );
1815 }
1816
1817 /**
1818 * Output total voice count of a topic
1819 *
1820 * @since bbPress (r2567)
1821 *
1822 * @param int $topic_id Optional. Topic id
1823 * @uses bbp_get_topic_voice_count() To get the topic voice count
1824 */
1825 function bbp_topic_voice_count( $topic_id = 0 ) {
1826 echo bbp_get_topic_voice_count( $topic_id );
1827 }
1828 /**
1829 * Return total voice count of a topic
1830 *
1831 * @since bbPress (r2567)
1832 *
1833 * @param int $topic_id Optional. Topic id
1834 * @uses bbp_get_topic_id() To get the topic id
1835 * @uses get_post_meta() To get the voice count meta
1836 * @uses apply_filters() Calls 'bbp_get_topic_voice_count' with the
1837 * voice count and topic id
1838 * @return int Voice count of the topic
1839 */
1840 function bbp_get_topic_voice_count( $topic_id = 0 ) {
1841 $topic_id = bbp_get_topic_id( $topic_id );
1842 $voices = get_post_meta( $topic_id, '_bbp_voice_count', true );
1843
1844 return apply_filters( 'bbp_get_topic_voice_count', (int) $voices, $topic_id );
1845 }
1846
1847 /**
1848 * Output a the tags of a topic
1849 *
1850 * @param int $topic_id Optional. Topic id
1851 * @param mixed $args See {@link bbp_get_topic_tag_list()}
1852 * @uses bbp_get_topic_tag_list() To get the topic tag list
1853 */
1854 function bbp_topic_tag_list( $topic_id = 0, $args = '' ) {
1855 echo bbp_get_topic_tag_list( $topic_id, $args );
1856 }
1857 /**
1858 * Return the tags of a topic
1859 *
1860 * @param int $topic_id Optional. Topic id
1861 * @param array $args This function supports these arguments:
1862 * - before: Before the tag list
1863 * - sep: Tag separator
1864 * - after: After the tag list
1865 * @uses bbp_get_topic_id() To get the topic id
1866 * @uses get_the_term_list() To get the tags list
1867 * @return string Tag list of the topic
1868 */
1869 function bbp_get_topic_tag_list( $topic_id = 0, $args = '' ) {
1870
1871 $defaults = array(
1872 'before' => '<div class="bbp-topic-tags"><p>' . __( 'Tagged:', 'bbpress' ) . '&nbsp;',
1873 'sep' => ', ',
1874 'after' => '</p></div>'
1875 );
1876
1877 $r = wp_parse_args( $args, $defaults );
1878 extract( $r );
1879
1880 $topic_id = bbp_get_topic_id( $topic_id );
1881
1882 // Topic is spammed, so display pre-spam terms
1883 if ( bbp_is_topic_spam( $topic_id ) ) {
1884
1885 // Get pre-spam terms
1886 $terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );
1887
1888 // If terms exist, explode them and compile the return value
1889 if ( !empty( $terms ) ) {
1890 $terms = implode( $sep, $terms );
1891 $retval = $before . $terms . $after;
1892
1893 // No terms so return emty string
1894 } else {
1895 $retval = '';
1896 }
1897
1898 // Topic is not spam so display a clickable term list
1899 } else {
1900 $retval = get_the_term_list( $topic_id, bbp_get_topic_tag_tax_id(), $before, $sep, $after );
1901 }
1902
1903 return $retval;
1904 }
1905
1906 /**
1907 * Output the row class of a topic
1908 *
1909 * @since bbPress (r2667)
1910 *
1911 * @param int $topic_id Optional. Topic id
1912 * @uses bbp_get_topic_class() To get the topic class
1913 */
1914 function bbp_topic_class( $topic_id = 0 ) {
1915 echo bbp_get_topic_class( $topic_id );
1916 }
1917 /**
1918 * Return the row class of a topic
1919 *
1920 * @since bbPress (r2667)
1921 *
1922 * @param int $topic_id Optional. Topic id
1923 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
1924 * @uses bbp_is_topic_super_sticky() To check if the topic is a super
1925 * sticky
1926 * @uses post_class() To get the topic classes
1927 * @uses apply_filters() Calls 'bbp_get_topic_class' with the classes
1928 * and topic id
1929 * @return string Row class of a topic
1930 */
1931 function bbp_get_topic_class( $topic_id = 0 ) {
1932 global $bbp;
1933
1934 $classes = array();
1935 $classes[] = $bbp->topic_query->current_post % 2 ? 'even' : 'odd';
1936 $classes[] = bbp_is_topic_sticky( $topic_id, false ) ? 'sticky' : '';
1937 $classes[] = bbp_is_topic_super_sticky( $topic_id ) ? 'super-sticky' : '';
1938 $classes = array_filter( $classes );
1939 $post = post_class( $classes, $topic_id );
1940
1941 return apply_filters( 'bbp_get_topic_class', $post, $topic_id );
1942 }
1943
1944 /** Topic Admin Links *********************************************************/
1945
1946 /**
1947 * Output admin links for topic
1948 *
1949 * @param mixed $args See {@link bbp_get_topic_admin_links()}
1950 * @uses bbp_get_topic_admin_links() To get the topic admin links
1951 */
1952 function bbp_topic_admin_links( $args = '' ) {
1953 echo bbp_get_topic_admin_links( $args );
1954 }
1955 /**
1956 * Return admin links for topic.
1957 *
1958 * Move topic functionality is handled by the edit topic page.
1959 *
1960 * @param mixed $args This function supports these arguments:
1961 * - id: Optional. Topic id
1962 * - before: Before the links
1963 * - after: After the links
1964 * - sep: Links separator
1965 * - links: Topic admin links array
1966 * @uses current_user_can() To check if the current user can edit/delete
1967 * the topic
1968 * @uses bbp_get_topic_edit_link() To get the topic edit link
1969 * @uses bbp_get_topic_trash_link() To get the topic trash link
1970 * @uses bbp_get_topic_close_link() To get the topic close link
1971 * @uses bbp_get_topic_spam_link() To get the topic spam link
1972 * @uses bbp_get_topic_stick_link() To get the topic stick link
1973 * @uses bbp_get_topic_merge_link() To get the topic merge link
1974 * @uses bbp_get_topic_status() To get the topic status
1975 * @uses apply_filters() Calls 'bbp_get_topic_admin_links' with the
1976 * topic admin links and args
1977 * @return string Topic admin links
1978 */
1979 function bbp_get_topic_admin_links( $args = '' ) {
1980
1981 if ( !bbp_is_single_topic() )
1982 return;
1983
1984 $defaults = array (
1985 'id' => bbp_get_topic_id(),
1986 'before' => '<span class="bbp-admin-links">',
1987 'after' => '</span>',
1988 'sep' => ' | ',
1989 'links' => array()
1990 );
1991
1992 $r = wp_parse_args( $args, $defaults );
1993
1994 if ( !current_user_can( 'edit_topic', $r['id'] ) )
1995 return;
1996
1997 if ( empty( $r['links'] ) ) {
1998 $r['links'] = array(
1999 'edit' => bbp_get_topic_edit_link ( $r ),
2000 'close' => bbp_get_topic_close_link( $r ),
2001 'stick' => bbp_get_topic_stick_link( $r ),
2002 'merge' => bbp_get_topic_merge_link( $r ),
2003 'trash' => bbp_get_topic_trash_link( $r ),
2004 'spam' => bbp_get_topic_spam_link ( $r ),
2005 );
2006 }
2007
2008 // Check caps for trashing the topic
2009 if ( !current_user_can( 'delete_topic', $r['id'] ) && !empty( $r['links']['trash'] ) )
2010 unset( $r['links']['trash'] );
2011
2012 // See if links need to be unset
2013 $topic_status = bbp_get_topic_status( $r['id'] );
2014 if ( in_array( $topic_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) {
2015
2016 // Close link shouldn't be visible on trashed/spammed topics
2017 unset( $r['links']['close'] );
2018
2019 // Spam link shouldn't be visible on trashed topics
2020 if ( $topic_status == bbp_get_trash_status_id() )
2021 unset( $r['links']['spam'] );
2022
2023 // Trash link shouldn't be visible on spam topics
2024 elseif ( $topic_status == bbp_get_spam_status_id() )
2025 unset( $r['links']['trash'] );
2026 }
2027
2028 // Process the admin links
2029 $links = implode( $r['sep'], array_filter( $r['links'] ) );
2030
2031 return apply_filters( 'bbp_get_topic_admin_links', $r['before'] . $links . $r['after'], $args );
2032 }
2033
2034 /**
2035 * Output the edit link of the topic
2036 *
2037 * @since bbPress (r2727)
2038 *
2039 * @param mixed $args See {@link bbp_get_topic_edit_link()}
2040 * @uses bbp_get_topic_edit_link() To get the topic edit link
2041 */
2042 function bbp_topic_edit_link( $args = '' ) {
2043 echo bbp_get_topic_edit_link( $args );
2044 }
2045
2046 /**
2047 * Return the edit link of the topic
2048 *
2049 * @since bbPress (r2727)
2050 *
2051 * @param mixed $args This function supports these args:
2052 * - id: Optional. Topic id
2053 * - link_before: Before the link
2054 * - link_after: After the link
2055 * - edit_text: Edit text
2056 * @uses bbp_get_topic_id() To get the topic id
2057 * @uses bbp_get_topic() To get the topic
2058 * @uses current_user_can() To check if the current user can edit the
2059 * topic
2060 * @uses bbp_get_topic_edit_url() To get the topic edit url
2061 * @uses apply_filters() Calls 'bbp_get_topic_edit_link' with the link
2062 * and args
2063 * @return string Topic edit link
2064 */
2065 function bbp_get_topic_edit_link( $args = '' ) {
2066 $defaults = array (
2067 'id' => 0,
2068 'link_before' => '',
2069 'link_after' => '',
2070 'edit_text' => __( 'Edit', 'bbpress' )
2071 );
2072
2073 $r = wp_parse_args( $args, $defaults );
2074 extract( $r );
2075
2076 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2077
2078 // Bypass check if user has caps
2079 if ( !current_user_can( 'edit_others_topics' ) ) {
2080
2081 // User cannot edit or it is past the lock time
2082 if ( empty( $topic ) || !current_user_can( 'edit_topic', $topic->ID ) || bbp_past_edit_lock( $topic->post_date_gmt ) )
2083 return;
2084 }
2085
2086 // No uri to edit topic
2087 if ( !$uri = bbp_get_topic_edit_url( $id ) )
2088 return;
2089
2090 return apply_filters( 'bbp_get_topic_edit_link', $link_before . '<a href="' . $uri . '">' . $edit_text . '</a>' . $link_after, $args );
2091 }
2092
2093 /**
2094 * Output URL to the topic edit page
2095 *
2096 * @since bbPress (r2753)
2097 *
2098 * @param int $topic_id Optional. Topic id
2099 * @uses bbp_get_topic_edit_url() To get the topic edit url
2100 */
2101 function bbp_topic_edit_url( $topic_id = 0 ) {
2102 echo bbp_get_topic_edit_url( $topic_id );
2103 }
2104 /**
2105 * Return URL to the topic edit page
2106 *
2107 * @since bbPress (r2753)
2108 *
2109 * @param int $topic_id Optional. Topic id
2110 * @uses bbp_get_topic_id() To get the topic id
2111 * @uses bbp_get_topic() To get the topic
2112 * @uses add_query_arg() To add custom args to the url
2113 * @uses home_url() To get the home url
2114 * @uses apply_filters() Calls 'bbp_get_topic_edit_url' with the edit
2115 * url and topic id
2116 * @return string Topic edit url
2117 */
2118 function bbp_get_topic_edit_url( $topic_id = 0 ) {
2119 global $wp_rewrite, $bbp;
2120
2121 if ( !$topic = bbp_get_topic( bbp_get_topic_id( $topic_id ) ) )
2122 return;
2123
2124 // Pretty permalinks
2125 if ( $wp_rewrite->using_permalinks() ) {
2126 $url = $wp_rewrite->root . $bbp->topic_slug . '/' . $topic->post_name . '/edit';
2127 $url = home_url( user_trailingslashit( $url ) );
2128
2129 // Unpretty permalinks
2130 } else {
2131 $url = add_query_arg( array( bbp_get_topic_post_type() => $topic->post_name, 'edit' => '1' ), home_url( '/' ) );
2132 }
2133
2134 return apply_filters( 'bbp_get_topic_edit_url', $url, $topic_id );
2135 }
2136
2137 /**
2138 * Output the trash link of the topic
2139 *
2140 * @since bbPress (r2727)
2141 *
2142 * @param mixed $args See {@link bbp_get_topic_trash_link()}
2143 * @uses bbp_get_topic_trash_link() To get the topic trash link
2144 */
2145 function bbp_topic_trash_link( $args = '' ) {
2146 echo bbp_get_topic_trash_link( $args );
2147 }
2148
2149 /**
2150 * Return the trash link of the topic
2151 *
2152 * @since bbPress (r2727)
2153 *
2154 * @param mixed $args This function supports these args:
2155 * - id: Optional. Topic id
2156 * - link_before: Before the link
2157 * - link_after: After the link
2158 * - sep: Links separator
2159 * - trash_text: Trash text
2160 * - restore_text: Restore text
2161 * - delete_text: Delete text
2162 * @uses bbp_get_topic_id() To get the topic id
2163 * @uses bbp_get_topic() To get the topic
2164 * @uses current_user_can() To check if the current user can delete the
2165 * topic
2166 * @uses bbp_is_topic_trash() To check if the topic is trashed
2167 * @uses bbp_get_topic_status() To get the topic status
2168 * @uses add_query_arg() To add custom args to the url
2169 * @uses wp_nonce_url() To nonce the url
2170 * @uses esc_url() To escape the url
2171 * @uses apply_filters() Calls 'bbp_get_topic_trash_link' with the link
2172 * and args
2173 * @return string Topic trash link
2174 */
2175 function bbp_get_topic_trash_link( $args = '' ) {
2176
2177 $defaults = array (
2178 'id' => 0,
2179 'link_before' => '',
2180 'link_after' => '',
2181 'sep' => ' | ',
2182 'trash_text' => __( 'Trash', 'bbpress' ),
2183 'restore_text' => __( 'Restore', 'bbpress' ),
2184 'delete_text' => __( 'Delete', 'bbpress' )
2185 );
2186 $r = wp_parse_args( $args, $defaults );
2187 extract( $r );
2188
2189 $actions = array();
2190 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2191
2192 if ( empty( $topic ) || !current_user_can( 'delete_topic', $topic->ID ) ) {
2193 return;
2194 }
2195
2196 if ( bbp_is_topic_trash( $topic->ID ) ) {
2197 $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_topic_trash', 'sub_action' => 'untrash', 'topic_id' => $topic->ID ) ), 'untrash-' . $topic->post_type . '_' . $topic->ID ) ) . '">' . esc_html( $restore_text ) . '</a>';
2198 } elseif ( EMPTY_TRASH_DAYS ) {
2199 $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_topic_trash', 'sub_action' => 'trash', 'topic_id' => $topic->ID ) ), 'trash-' . $topic->post_type . '_' . $topic->ID ) ) . '">' . esc_html( $trash_text ) . '</a>';
2200 }
2201
2202 if ( bbp_is_topic_trash( $topic->ID ) || !EMPTY_TRASH_DAYS ) {
2203 $actions['delete'] = '<a title="' . esc_attr( __( 'Delete this item permanently', 'bbpress' ) ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'delete', 'topic_id' => $topic->ID ) ), 'delete-' . $topic->post_type . '_' . $topic->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );">' . esc_html( $delete_text ) . '</a>';
2204 }
2205
2206 // Process the admin links
2207 $actions = implode( $sep, $actions );
2208
2209 return apply_filters( 'bbp_get_topic_trash_link', $link_before . $actions . $link_after, $args );
2210 }
2211
2212 /**
2213 * Output the close link of the topic
2214 *
2215 * @since bbPress (r2727)
2216 *
2217 * @param mixed $args See {@link bbp_get_topic_close_link()}
2218 * @uses bbp_get_topic_close_link() To get the topic close link
2219 */
2220 function bbp_topic_close_link( $args = '' ) {
2221 echo bbp_get_topic_close_link( $args );
2222 }
2223
2224 /**
2225 * Return the close link of the topic
2226 *
2227 * @since bbPress (r2727)
2228 *
2229 * @param mixed $args This function supports these args:
2230 * - id: Optional. Topic id
2231 * - link_before: Before the link
2232 * - link_after: After the link
2233 * - close_text: Close text
2234 * - open_text: Open text
2235 * @uses bbp_get_topic_id() To get the topic id
2236 * @uses bbp_get_topic() To get the topic
2237 * @uses current_user_can() To check if the current user can edit the
2238 * topic
2239 * @uses bbp_is_topic_open() To check if the topic is open
2240 * @uses add_query_arg() To add custom args to the url
2241 * @uses wp_nonce_url() To nonce the url
2242 * @uses esc_url() To escape the url
2243 * @uses apply_filters() Calls 'bbp_get_topic_close_link' with the link
2244 * and args
2245 * @return string Topic close link
2246 */
2247 function bbp_get_topic_close_link( $args = '' ) {
2248 $defaults = array (
2249 'id' => 0,
2250 'link_before' => '',
2251 'link_after' => '',
2252 'sep' => ' | ',
2253 'close_text' => __( 'Close', 'bbpress' ),
2254 'open_text' => __( 'Open', 'bbpress' )
2255 );
2256
2257 $r = wp_parse_args( $args, $defaults );
2258 extract( $r );
2259
2260 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2261
2262 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2263 return;
2264
2265 $display = bbp_is_topic_open( $topic->ID ) ? $close_text : $open_text;
2266
2267 $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_close', 'topic_id' => $topic->ID ) );
2268 $uri = esc_url( wp_nonce_url( $uri, 'close-topic_' . $topic->ID ) );
2269
2270 return apply_filters( 'bbp_get_topic_close_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args );
2271 }
2272
2273 /**
2274 * Output the stick link of the topic
2275 *
2276 * @since bbPress (r2754)
2277 *
2278 * @param mixed $args See {@link bbp_get_topic_stick_link()}
2279 * @uses bbp_get_topic_stick_link() To get the topic stick link
2280 */
2281 function bbp_topic_stick_link( $args = '' ) {
2282 echo bbp_get_topic_stick_link( $args );
2283 }
2284
2285 /**
2286 * Return the stick link of the topic
2287 *
2288 * @since bbPress (r2754)
2289 *
2290 * @param mixed $args This function supports these args:
2291 * - id: Optional. Topic id
2292 * - link_before: Before the link
2293 * - link_after: After the link
2294 * - stick_text: Stick text
2295 * - unstick_text: Unstick text
2296 * - super_text: Stick to front text
2297 * @uses bbp_get_topic_id() To get the topic id
2298 * @uses bbp_get_topic() To get the topic
2299 * @uses current_user_can() To check if the current user can edit the
2300 * topic
2301 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
2302 * @uses add_query_arg() To add custom args to the url
2303 * @uses wp_nonce_url() To nonce the url
2304 * @uses esc_url() To escape the url
2305 * @uses apply_filters() Calls 'bbp_get_topic_stick_link' with the link
2306 * and args
2307 * @return string Topic stick link
2308 */
2309 function bbp_get_topic_stick_link( $args = '' ) {
2310 $defaults = array (
2311 'id' => 0,
2312 'link_before' => '',
2313 'link_after' => '',
2314 'stick_text' => __( 'Stick', 'bbpress' ),
2315 'unstick_text' => __( 'Unstick', 'bbpress' ),
2316 'super_text' => __( 'to front', 'bbpress' ),
2317 );
2318
2319 $r = wp_parse_args( $args, $defaults );
2320 extract( $r );
2321
2322 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2323
2324 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2325 return;
2326
2327 $is_sticky = bbp_is_topic_sticky( $topic->ID );
2328
2329 $stick_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID ) );
2330 $stick_uri = esc_url( wp_nonce_url( $stick_uri, 'stick-topic_' . $topic->ID ) );
2331
2332 $stick_display = true == $is_sticky ? $unstick_text : $stick_text;
2333 $stick_display = '<a href="' . $stick_uri . '">' . $stick_display . '</a>';
2334
2335 if ( empty( $is_sticky ) ) {
2336 $super_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID, 'super' => 1 ) );
2337 $super_uri = esc_url( wp_nonce_url( $super_uri, 'stick-topic_' . $topic->ID ) );
2338
2339 $super_display = ' (<a href="' . $super_uri . '">' . $super_text . '</a>)';
2340 } else {
2341 $super_display = '';
2342 }
2343
2344 return apply_filters( 'bbp_get_topic_stick_link', $link_before . $stick_display . $super_display . $link_after, $args );
2345 }
2346
2347 /**
2348 * Output the merge link of the topic
2349 *
2350 * @since bbPress (r2756)
2351 *
2352 * @param mixed $args
2353 * @uses bbp_get_topic_merge_link() To get the topic merge link
2354 */
2355 function bbp_topic_merge_link( $args = '' ) {
2356 echo bbp_get_topic_merge_link( $args );
2357 }
2358
2359 /**
2360 * Return the merge link of the topic
2361 *
2362 * @since bbPress (r2756)
2363 *
2364 * @param mixed $args This function supports these args:
2365 * - id: Optional. Topic id
2366 * - link_before: Before the link
2367 * - link_after: After the link
2368 * - merge_text: Merge text
2369 * @uses bbp_get_topic_id() To get the topic id
2370 * @uses bbp_get_topic() To get the topic
2371 * @uses bbp_get_topic_edit_url() To get the topic edit url
2372 * @uses add_query_arg() To add custom args to the url
2373 * @uses esc_url() To escape the url
2374 * @uses apply_filters() Calls 'bbp_get_topic_merge_link' with the link
2375 * and args
2376 * @return string Topic merge link
2377 */
2378 function bbp_get_topic_merge_link( $args = '' ) {
2379 $defaults = array (
2380 'id' => 0,
2381 'link_before' => '',
2382 'link_after' => '',
2383 'merge_text' => __( 'Merge', 'bbpress' ),
2384 );
2385
2386 $r = wp_parse_args( $args, $defaults );
2387 extract( $r );
2388
2389 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2390
2391 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2392 return;
2393
2394 $uri = esc_url( add_query_arg( array( 'action' => 'merge' ), bbp_get_topic_edit_url( $topic->ID ) ) );
2395
2396 return apply_filters( 'bbp_get_topic_merge_link', $link_before . '<a href="' . $uri . '">' . $merge_text . '</a>' . $link_after, $args );
2397 }
2398
2399 /**
2400 * Output the spam link of the topic
2401 *
2402 * @since bbPress (r2727)
2403 *
2404 * @param mixed $args See {@link bbp_get_topic_spam_link()}
2405 * @uses bbp_get_topic_spam_link() Topic spam link
2406 */
2407 function bbp_topic_spam_link( $args = '' ) {
2408 echo bbp_get_topic_spam_link( $args );
2409 }
2410
2411 /**
2412 * Return the spam link of the topic
2413 *
2414 * @since bbPress (r2727)
2415 *
2416 * @param mixed $args This function supports these args:
2417 * - id: Optional. Topic id
2418 * - link_before: Before the link
2419 * - link_after: After the link
2420 * - spam_text: Spam text
2421 * - unspam_text: Unspam text
2422 * @uses bbp_get_topic_id() To get the topic id
2423 * @uses bbp_get_topic() To get the topic
2424 * @uses current_user_can() To check if the current user can edit the
2425 * topic
2426 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
2427 * @uses add_query_arg() To add custom args to the url
2428 * @uses wp_nonce_url() To nonce the url
2429 * @uses esc_url() To escape the url
2430 * @uses apply_filters() Calls 'bbp_get_topic_spam_link' with the link
2431 * and args
2432 * @return string Topic spam link
2433 */
2434 function bbp_get_topic_spam_link( $args = '' ) {
2435 $defaults = array (
2436 'id' => 0,
2437 'link_before' => '',
2438 'link_after' => '',
2439 'sep' => ' | ',
2440 'spam_text' => __( 'Spam', 'bbpress' ),
2441 'unspam_text' => __( 'Unspam', 'bbpress' )
2442 );
2443
2444 $r = wp_parse_args( $args, $defaults );
2445 extract( $r );
2446
2447 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2448
2449 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2450 return;
2451
2452 $display = bbp_is_topic_spam( $topic->ID ) ? $unspam_text : $spam_text;
2453
2454 $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_spam', 'topic_id' => $topic->ID ) );
2455 $uri = esc_url( wp_nonce_url( $uri, 'spam-topic_' . $topic->ID ) );
2456
2457 return apply_filters( 'bbp_get_topic_spam_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args );
2458 }
2459
2460 /** Topic Pagination **********************************************************/
2461
2462 /**
2463 * Output the pagination count
2464 *
2465 * @since bbPress (r2519)
2466 *
2467 * @uses bbp_get_forum_pagination_count() To get the forum pagination count
2468 */
2469 function bbp_forum_pagination_count() {
2470 echo bbp_get_forum_pagination_count();
2471 }
2472 /**
2473 * Return the pagination count
2474 *
2475 * @since bbPress (r2519)
2476 *
2477 * @uses bbp_number_format() To format the number value
2478 * @uses apply_filters() Calls 'bbp_get_forum_pagination_count' with the
2479 * pagination count
2480 * @return string Forum Pagintion count
2481 */
2482 function bbp_get_forum_pagination_count() {
2483 global $bbp;
2484
2485 if ( empty( $bbp->topic_query ) )
2486 return false;
2487
2488 // Set pagination values
2489 $start_num = intval( ( $bbp->topic_query->paged - 1 ) * $bbp->topic_query->posts_per_page ) + 1;
2490 $from_num = bbp_number_format( $start_num );
2491 $to_num = bbp_number_format( ( $start_num + ( $bbp->topic_query->posts_per_page - 1 ) > $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $start_num + ( $bbp->topic_query->posts_per_page - 1 ) );
2492 $total = bbp_number_format( !empty( $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $bbp->topic_query->post_count );
2493
2494 /**
2495 * Translators - _n() should not be needed, as singular/plural strings
2496 * are already separated into unique strings for you
2497 */
2498
2499 // More than one topic
2500 if ( $total > 1 ) {
2501
2502 // Single topic in a forum with several pages
2503 if ( (int) $from_num == (int) $to_num ) {
2504 $retstr = sprintf( __( 'Viewing topic %1$s (of %2$s total)', 'bbpress' ), $from_num, $total );
2505
2506 // Several topics in a forum with a single page
2507 } elseif ( empty( $to_num ) ) {
2508 $retstr = sprintf( __( 'Viewing %1$s topics', 'bbpress' ), $total );
2509
2510 // Several topics in a forum with several pages
2511 } elseif ( (int) $from_num != (int) $to_num ) {
2512 $retstr = sprintf( __( 'Viewing %1$s topics - %2$s through %3$s (of %4$s total)', 'bbpress' ), $bbp->topic_query->post_count, $from_num, $to_num, $total );
2513 }
2514
2515 // Only 1 topic
2516 } else {
2517 $retstr = sprintf( __( 'Viewing %1$s topic', 'bbpress' ), $total );
2518 }
2519
2520 // Filter and return
2521 return apply_filters( 'bbp_get_topic_pagination_count', $retstr );
2522 }
2523
2524 /**
2525 * Output pagination links
2526 *
2527 * @since bbPress (r2519)
2528 *
2529 * @uses bbp_get_forum_pagination_links() To get the pagination links
2530 */
2531 function bbp_forum_pagination_links() {
2532 echo bbp_get_forum_pagination_links();
2533 }
2534 /**
2535 * Return pagination links
2536 *
2537 * @since bbPress (r2519)
2538 *
2539 * @uses bbPress::topic_query::pagination_links To get the links
2540 * @return string Pagination links
2541 */
2542 function bbp_get_forum_pagination_links() {
2543 global $bbp;
2544
2545 if ( empty( $bbp->topic_query ) )
2546 return false;
2547
2548 return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links );
2549 }
2550
2551 /**
2552 * Displays topic notices
2553 *
2554 * @since bbPress (r2744)
2555 *
2556 * @uses bbp_is_single_topic() To check if it's a topic page
2557 * @uses bbp_get_topic_status() To get the topic status
2558 * @uses bbp_get_topic_id() To get the topic id
2559 * @uses apply_filters() Calls 'bbp_topic_notices' with the notice text, topic
2560 * status and topic id
2561 * @uses bbPress::errors::add() To add the notices to the error handler
2562 */
2563 function bbp_topic_notices() {
2564
2565 // Bail if not viewing a topic
2566 if ( !bbp_is_single_topic() )
2567 return;
2568
2569 // Get the topic_status
2570 $topic_status = bbp_get_topic_status();
2571
2572 // Get the topic status
2573 switch ( $topic_status ) {
2574
2575 // Spam notice
2576 case bbp_get_spam_status_id() :
2577 $notice_text = __( 'This topic is marked as spam.', 'bbpress' );
2578 break;
2579
2580 // Trashed notice
2581 case bbp_get_trash_status_id() :
2582 $notice_text = __( 'This topic is in the trash.', 'bbpress' );
2583 break;
2584
2585 // Standard status
2586 default :
2587 $notice_text = '';
2588 break;
2589 }
2590
2591 // Filter notice text and bail if empty
2592 if ( !$notice_text = apply_filters( 'bbp_topic_notices', $notice_text, $topic_status, bbp_get_topic_id() ) )
2593 return;
2594
2595 bbp_add_error( 'topic_notice', $notice_text, 'message' );
2596 }
2597
2598 /**
2599 * Displays topic type select box (normal/sticky/super sticky)
2600 *
2601 * @since bbPress (r2784)
2602 *
2603 * @param $args This function supports these arguments:
2604 * - stick_text: Sticky text
2605 * - super_text: Super Sticky text
2606 * - unstick_text: Unstick (normal) text
2607 * - select_id: Select id. Defaults to bbp_stick_topic
2608 * - tab: Tabindex
2609 * - topic_id: Topic id
2610 * @uses bbp_get_topic_id() To get the topic id
2611 * @uses bbp_is_topic_edit() To check if it is the topic edit page
2612 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
2613 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
2614 */
2615 function bbp_topic_type_select( $args = '' ) {
2616
2617 $defaults = array (
2618 'unstick_text' => __( 'Normal', 'bbpress' ),
2619 'stick_text' => __( 'Sticky', 'bbpress' ),
2620 'super_text' => __( 'Super Sticky', 'bbpress' ),
2621 'select_id' => 'bbp_stick_topic',
2622 'tab' => bbp_get_tab_index(),
2623 'topic_id' => 0
2624 );
2625
2626 $r = wp_parse_args( $args, $defaults );
2627 extract( $r );
2628
2629 // Get current topic id
2630 $topic_id = bbp_get_topic_id( $topic_id );
2631
2632 // Edit topic
2633 if ( bbp_is_topic_edit() ) {
2634
2635 // Post value is passed
2636 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$select_id] ) ) {
2637 $sticky_current = $_POST[$select_id];
2638
2639 // Topic is super sticky
2640 } elseif ( bbp_is_topic_super_sticky( $topic_id ) ) {
2641 $sticky_current = 'super';
2642
2643 // Topic is sticky or normal
2644 } else {
2645 $sticky_current = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick';
2646 }
2647
2648 // New topic
2649 } else {
2650
2651 // Post value is passed
2652 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$select_id] ) ) {
2653 $sticky_current = $_POST[$select_id];
2654
2655 // Default to unstick
2656 } else {
2657 $sticky_current = 'unstick';
2658 }
2659 }
2660
2661 // Used variables
2662 $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
2663 $select_id = esc_attr( $select_id );
2664 $sticky_statuses = array (
2665 'unstick' => $unstick_text,
2666 'stick' => $stick_text,
2667 'super' => $super_text,
2668 ); ?>
2669
2670 <select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>"<?php echo $tab; ?>>
2671
2672 <?php foreach ( $sticky_statuses as $sticky_status => $label ) : ?>
2673
2674 <option value="<?php echo $sticky_status; ?>"<?php selected( $sticky_current, $sticky_status ); ?>><?php echo $label; ?></option>
2675
2676 <?php endforeach; ?>
2677
2678 </select>
2679
2680 <?php
2681 }
2682
2683 /** Single Topic **************************************************************/
2684
2685 /**
2686 * Output a fancy description of the current topic, including total topics,
2687 * total replies, and last activity.
2688 *
2689 * @since bbPress (r2860)
2690 *
2691 * @param array $args See {@link bbp_get_single_topic_description()}
2692 * @uses bbp_get_single_topic_description() Return the eventual output
2693 */
2694 function bbp_single_topic_description( $args = '' ) {
2695 echo bbp_get_single_topic_description( $args );
2696 }
2697 /**
2698 * Return a fancy description of the current topic, including total topics,
2699 * total replies, and last activity.
2700 *
2701 * @since bbPress (r2860)
2702 *
2703 * @param mixed $args This function supports these arguments:
2704 * - topic_id: Topic id
2705 * - before: Before the text
2706 * - after: After the text
2707 * - size: Size of the avatar
2708 * @uses bbp_get_topic_id() To get the topic id
2709 * @uses bbp_get_topic_voice_count() To get the topic voice count
2710 * @uses bbp_get_topic_reply_count() To get the topic reply count
2711 * @uses bbp_get_topic_freshness_link() To get the topic freshness link
2712 * @uses bbp_get_topic_last_active_id() To get the topic last active id
2713 * @uses bbp_get_reply_author_link() To get the reply author link
2714 * @uses apply_filters() Calls 'bbp_get_single_topic_description' with
2715 * the description and args
2716 * @return string Filtered topic description
2717 */
2718 function bbp_get_single_topic_description( $args = '' ) {
2719 // Default arguments
2720 $defaults = array (
2721 'topic_id' => 0,
2722 'before' => '<div class="bbp-template-notice info"><p class="bbp-topic-description">',
2723 'after' => '</p></div>',
2724 'size' => 14
2725 );
2726 $r = wp_parse_args( $args, $defaults );
2727 extract( $r );
2728
2729 // Validate topic_id
2730 $topic_id = bbp_get_topic_id( $topic_id );
2731
2732 // Unhook the 'view all' query var adder
2733 remove_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
2734
2735 // Build the topic description
2736 $forum_id = bbp_get_topic_forum_id ( $topic_id );
2737 $voice_count = bbp_get_topic_voice_count ( $topic_id );
2738 $reply_count = bbp_get_topic_replies_link ( $topic_id );
2739 $time_since = bbp_get_topic_freshness_link( $topic_id );
2740
2741 // Singular/Plural
2742 $voice_count = sprintf( _n( '%s voice', '%s voices', $voice_count, 'bbpress' ), $voice_count );
2743
2744 // Topic has replies
2745 if ( $last_reply = bbp_get_topic_last_active_id( $topic_id ) ) {
2746 $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $size ) );
2747 $retstr = sprintf( __( 'This topic has %1$s, contains %2$s, and was last updated by %3$s %4$s ago.', 'bbpress' ), $voice_count, $reply_count, $last_updated_by, $time_since );
2748
2749 // Topic has no replies
2750 } else {
2751 $retstr = sprintf( __( 'This topic has %1$s, contains %2$s.', 'bbpress' ), $voice_count, $reply_count );
2752 }
2753
2754 // Add the 'view all' filter back
2755 add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
2756
2757 // Combine the elements together
2758 $retstr = $before . $retstr . $after;
2759
2760 // Return filtered result
2761 return apply_filters( 'bbp_get_single_topic_description', $retstr, $args );
2762 }
2763
2764 /** Topic Tags ****************************************************************/
2765
2766 /**
2767 * Output the unique id of the topic tag taxonomy
2768 *
2769 * @since bbPress (r3348)
2770 *
2771 * @uses bbp_get_topic_post_type() To get the topic post type
2772 */
2773 function bbp_topic_tag_tax_id() {
2774 echo bbp_get_topic_tag_tax_id();
2775 }
2776 /**
2777 * Return the unique id of the topic tag taxonomy
2778 *
2779 * @since bbPress (r3348)
2780 *
2781 * @uses apply_filters() Calls 'bbp_get_topic_tag_tax_id' with the topic tax id
2782 * @return string The unique topic tag taxonomy
2783 */
2784 function bbp_get_topic_tag_tax_id() {
2785 global $bbp;
2786
2787 return apply_filters( 'bbp_get_topic_tag_tax_id', $bbp->topic_tag_tax_id );
2788 }
2789
2790 /**
2791 * Output the id of the current tag
2792 *
2793 * @since bbPress (r3109)
2794 *
2795 * @uses bbp_get_topic_tag_id()
2796 */
2797 function bbp_topic_tag_id( $tag = '' ) {
2798 echo bbp_get_topic_tag_id( $tag );
2799 }
2800 /**
2801 * Return the id of the current tag
2802 *
2803 * @since bbPress (r3109)
2804 *
2805 * @uses get_term_by()
2806 * @uses get_query_var()
2807 * @uses apply_filters()
2808 *
2809 * @return string Term Name
2810 */
2811 function bbp_get_topic_tag_id( $tag = '' ) {
2812
2813 // Get the term
2814 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2815 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2816
2817 // Add before and after if description exists
2818 if ( !empty( $term->term_id ) )
2819 $retval = $term->term_id;
2820
2821 // No id
2822 else
2823 $retval = '';
2824
2825 return apply_filters( 'bbp_get_topic_tag_id', (int) $retval );
2826 }
2827
2828 /**
2829 * Output the name of the current tag
2830 *
2831 * @since bbPress (r3109)
2832 *
2833 * @uses bbp_get_topic_tag_name()
2834 */
2835 function bbp_topic_tag_name( $tag = '' ) {
2836 echo bbp_get_topic_tag_name( $tag );
2837 }
2838 /**
2839 * Return the name of the current tag
2840 *
2841 * @since bbPress (r3109)
2842 *
2843 * @uses get_term_by()
2844 * @uses get_query_var()
2845 * @uses apply_filters()
2846 *
2847 * @return string Term Name
2848 */
2849 function bbp_get_topic_tag_name( $tag = '' ) {
2850
2851 // Get the term
2852 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2853 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2854
2855 // Add before and after if description exists
2856 if ( !empty( $term->name ) )
2857 $retval = $term->name;
2858
2859 // No name
2860 else
2861 $retval = '';
2862
2863 return apply_filters( 'bbp_get_topic_tag_name', $retval );
2864 }
2865
2866 /**
2867 * Output the slug of the current tag
2868 *
2869 * @since bbPress (r3109)
2870 *
2871 * @uses bbp_get_topic_tag_slug()
2872 */
2873 function bbp_topic_tag_slug( $tag = '' ) {
2874 echo bbp_get_topic_tag_slug( $tag );
2875 }
2876 /**
2877 * Return the slug of the current tag
2878 *
2879 * @since bbPress (r3109)
2880 *
2881 * @uses get_term_by()
2882 * @uses get_query_var()
2883 * @uses apply_filters()
2884 *
2885 * @return string Term Name
2886 */
2887 function bbp_get_topic_tag_slug( $tag = '' ) {
2888
2889 // Get the term
2890 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2891 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2892
2893 // Add before and after if description exists
2894 if ( !empty( $term->slug ) )
2895 $retval = $term->slug;
2896
2897 // No slug
2898 else
2899 $retval = '';
2900
2901 return apply_filters( 'bbp_get_topic_tag_slug', $retval );
2902 }
2903
2904 /**
2905 * Output the link of the current tag
2906 *
2907 * @since bbPress (r3348)
2908 *
2909 * @uses bbp_get_topic_tag_link()
2910 */
2911 function bbp_topic_tag_link( $tag = '' ) {
2912 echo bbp_get_topic_tag_link( $tag );
2913 }
2914 /**
2915 * Return the link of the current tag
2916 *
2917 * @since bbPress (r3348)
2918 *
2919 * @uses get_term_by()
2920 * @uses get_query_var()
2921 * @uses apply_filters()
2922 *
2923 * @return string Term Name
2924 */
2925 function bbp_get_topic_tag_link( $tag = '' ) {
2926
2927 // Get the term
2928 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2929 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2930
2931 // Add before and after if description exists
2932 if ( !empty( $term->term_id ) )
2933 $retval = get_term_link( $term, bbp_get_topic_tag_tax_id() );
2934
2935 // No link
2936 else
2937 $retval = '';
2938
2939 return apply_filters( 'bbp_get_topic_tag_link', $retval );
2940 }
2941
2942 /**
2943 * Output the link of the current tag
2944 *
2945 * @since bbPress (r3348)
2946 *
2947 * @uses bbp_get_topic_tag_edit_link()
2948 */
2949 function bbp_topic_tag_edit_link( $tag = '' ) {
2950 echo bbp_get_topic_tag_edit_link( $tag );
2951 }
2952 /**
2953 * Return the link of the current tag
2954 *
2955 * @since bbPress (r3348)
2956 *
2957 * @uses get_term_by()
2958 * @uses get_query_var()
2959 * @uses apply_filters()
2960 *
2961 * @return string Term Name
2962 */
2963 function bbp_get_topic_tag_edit_link( $tag = '' ) {
2964 global $wp_query, $wp_rewrite;
2965
2966 // Get the term
2967 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2968 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2969
2970 // Add before and after if description exists
2971 if ( !empty( $term->term_id ) ) {
2972
2973 // Pretty
2974 if ( $wp_rewrite->using_permalinks() ) {
2975 $retval = user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . 'edit' );
2976
2977 // Ugly
2978 } else {
2979 $retval = add_query_arg( array( 'edit' => '1' ), bbp_get_topic_tag_link() );
2980 }
2981
2982 // No link
2983 } else {
2984 $retval = '';
2985 }
2986
2987 return apply_filters( 'bbp_get_topic_tag_edit_link', $retval );
2988 }
2989
2990 /**
2991 * Output the description of the current tag
2992 *
2993 * @since bbPress (r3109)
2994 *
2995 * @uses bbp_get_topic_tag_description()
2996 */
2997 function bbp_topic_tag_description( $args = array() ) {
2998 echo bbp_get_topic_tag_description( $args );
2999 }
3000 /**
3001 * Return the description of the current tag
3002 *
3003 * @since bbPress (r3109)
3004 *
3005 * @uses get_term_by()
3006 * @uses get_query_var()
3007 * @uses apply_filters()
3008 *
3009 * @return string Term Name
3010 */
3011 function bbp_get_topic_tag_description( $args = array() ) {
3012
3013 $defaults = array(
3014 'before' => '<div class="bbp-topic-tag-description"><p>',
3015 'after' => '</p></div>',
3016 'tag' => ''
3017 );
3018 $r = wp_parse_args( $args, $defaults );
3019 extract( $r );
3020
3021 // Get the term
3022 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
3023 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3024
3025 // Add before and after if description exists
3026 if ( !empty( $term->description ) )
3027 $retval = $before . $term->description . $after;
3028
3029 // No description, no HTML
3030 else
3031 $retval = '';
3032
3033 return apply_filters( 'bbp_get_topic_tag_description', $retval, $args );
3034 }
3035
3036 /** Forms *********************************************************************/
3037
3038 /**
3039 * Output the value of topic title field
3040 *
3041 * @since bbPress (r2976)
3042 *
3043 * @uses bbp_get_form_topic_title() To get the value of topic title field
3044 */
3045 function bbp_form_topic_title() {
3046 echo bbp_get_form_topic_title();
3047 }
3048 /**
3049 * Return the value of topic title field
3050 *
3051 * @since bbPress (r2976)
3052 *
3053 * @uses bbp_is_topic_edit() To check if it's topic edit page
3054 * @uses apply_filters() Calls 'bbp_get_form_topic_title' with the title
3055 * @return string Value of topic title field
3056 */
3057 function bbp_get_form_topic_title() {
3058 global $post;
3059
3060 // Get _POST data
3061 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_title'] ) )
3062 $topic_title = $_POST['bbp_topic_title'];
3063
3064 // Get edit data
3065 elseif ( !empty( $post->post_title ) && bbp_is_topic_edit() )
3066 $topic_title = $post->post_title;
3067
3068 // No data
3069 else
3070 $topic_title = '';
3071
3072 return apply_filters( 'bbp_get_form_topic_title', esc_attr( $topic_title ) );
3073 }
3074
3075 /**
3076 * Output the value of topic content field
3077 *
3078 * @since bbPress (r2976)
3079 *
3080 * @uses bbp_get_form_topic_content() To get value of topic content field
3081 */
3082 function bbp_form_topic_content() {
3083 echo bbp_get_form_topic_content();
3084 }
3085 /**
3086 * Return the value of topic content field
3087 *
3088 * @since bbPress (r2976)
3089 *
3090 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3091 * @uses apply_filters() Calls 'bbp_get_form_topic_content' with the content
3092 * @return string Value of topic content field
3093 */
3094 function bbp_get_form_topic_content() {
3095 global $post;
3096
3097 // Get _POST data
3098 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_content'] ) )
3099 $topic_content = $_POST['bbp_topic_content'];
3100
3101 // Get edit data
3102 elseif ( !empty( $post->post_title ) && bbp_is_topic_edit() )
3103 $topic_content = $post->post_content;
3104
3105 // No data
3106 else
3107 $topic_content = '';
3108
3109 return apply_filters( 'bbp_get_form_topic_content', esc_textarea( $topic_content ) );
3110 }
3111
3112 /**
3113 * Output value of topic tags field
3114 *
3115 * @since bbPress (r2976)
3116 * @uses bbp_get_form_topic_tags() To get the value of topic tags field
3117 */
3118 function bbp_form_topic_tags() {
3119 echo bbp_get_form_topic_tags();
3120 }
3121 /**
3122 * Return value of topic tags field
3123 *
3124 * @since bbPress (r2976)
3125 *
3126 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3127 * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags
3128 * @return string Value of topic tags field
3129 */
3130 function bbp_get_form_topic_tags() {
3131 global $post;
3132
3133 // Get _POST data
3134 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_tags'] ) ) {
3135 $topic_tags = $_POST['bbp_topic_tags'];
3136
3137 // Get edit data
3138 } elseif ( !empty( $post ) ) {
3139
3140 // Post is a topic
3141 if ( bbp_get_topic_post_type() == $post->post_type ) {
3142 $topic_id = $post->ID;
3143
3144 // Post is a reply
3145 } elseif ( bbp_get_reply_post_type() == $post->post_type ) {
3146 $topic_id = bbp_get_reply_topic_id( $post->ID );
3147 }
3148
3149 // Topic exists
3150 if ( !empty( $topic_id ) ) {
3151
3152 // Topic is spammed so display pre-spam terms
3153 if ( bbp_is_topic_spam( $topic_id ) ) {
3154
3155 // Get pre-spam terms
3156 $new_terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );
3157
3158 // If terms exist, explode them and compile the return value
3159 if ( empty( $new_terms ) ) {
3160 $new_terms = '';
3161 }
3162
3163 // Topic is not spam so get real terms
3164 } else {
3165 $terms = array_filter( (array) get_the_terms( $topic_id, bbp_get_topic_tag_tax_id() ) );
3166
3167 // Loop through them
3168 foreach( $terms as $term ) {
3169 $new_terms[] = $term->name;
3170 }
3171 }
3172
3173 // Define local variable(s)
3174 } else {
3175 $new_terms = '';
3176 }
3177
3178 // Set the return value
3179 $topic_tags = ( !empty( $new_terms ) ) ? implode( ', ', $new_terms ) : '';
3180
3181 // No data
3182 } else {
3183 $topic_tags = '';
3184 }
3185
3186 return apply_filters( 'bbp_get_form_topic_tags', esc_attr( $topic_tags ) );
3187 }
3188
3189 /**
3190 * Output value of topic forum
3191 *
3192 * @since bbPress (r2976)
3193 *
3194 * @uses bbp_get_form_topic_forum() To get the topic's forum id
3195 */
3196 function bbp_form_topic_forum() {
3197 echo bbp_get_form_topic_forum();
3198 }
3199 /**
3200 * Return value of topic forum
3201 *
3202 * @since bbPress (r2976)
3203 *
3204 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3205 * @uses bbp_get_topic_forum_id() To get the topic forum id
3206 * @uses apply_filters() Calls 'bbp_get_form_topic_forum' with the forum
3207 * @return string Value of topic content field
3208 */
3209 function bbp_get_form_topic_forum() {
3210
3211 // Get _POST data
3212 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_id'] ) )
3213 $topic_forum = $_POST['bbp_forum_id'];
3214
3215 // Get edit data
3216 elseif ( bbp_is_topic_edit() )
3217 $topic_forum = bbp_get_topic_forum_id();
3218
3219 // No data
3220 else
3221 $topic_forum = 0;
3222
3223 return apply_filters( 'bbp_get_form_topic_forum', esc_attr( $topic_forum ) );
3224 }
3225
3226 /**
3227 * Output checked value of topic subscription
3228 *
3229 * @since bbPress (r2976)
3230 *
3231 * @uses bbp_get_form_topic_subscribed() To get the subscribed checkbox value
3232 */
3233 function bbp_form_topic_subscribed() {
3234 echo bbp_get_form_topic_subscribed();
3235 }
3236 /**
3237 * Return checked value of topic subscription
3238 *
3239 * @since bbPress (r2976)
3240 *
3241 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3242 * @uses bbp_is_user_subscribed() To check if the user is subscribed to
3243 * the topic
3244 * @uses apply_filters() Calls 'bbp_get_form_topic_subscribed' with the
3245 * option
3246 * @return string Checked value of topic subscription
3247 */
3248 function bbp_get_form_topic_subscribed() {
3249 global $post;
3250
3251 // Get _POST data
3252 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_subscription'] ) ) {
3253 $topic_subscribed = $_POST['bbp_topic_subscription'];
3254
3255 // Get edit data
3256 } elseif ( bbp_is_topic_edit() || bbp_is_reply_edit() ) {
3257
3258 // Post author is not the current user
3259 if ( $post->post_author != bbp_get_current_user_id() ) {
3260 $topic_subscribed = bbp_is_user_subscribed( $post->post_author );
3261
3262 // Post author is the current user
3263 } else {
3264 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() );
3265 }
3266
3267 // Get current status
3268 } elseif ( bbp_is_single_topic() ) {
3269 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() );
3270
3271 // No data
3272 } else {
3273 $topic_subscribed = 0;
3274 }
3275
3276 // Get checked output
3277 $checked = checked( $topic_subscribed, true, false );
3278
3279 return apply_filters( 'bbp_get_form_topic_subscribed', $checked, $topic_subscribed );
3280 }
3281
3282 /**
3283 * Output checked value of topic log edit field
3284 *
3285 * @since bbPress (r2976)
3286 *
3287 * @uses bbp_get_form_topic_log_edit() To get the topic log edit value
3288 */
3289 function bbp_form_topic_log_edit() {
3290 echo bbp_get_form_topic_log_edit();
3291 }
3292 /**
3293 * Return checked value of topic log edit field
3294 *
3295 * @since bbPress (r2976)
3296 *
3297 * @uses apply_filters() Calls 'bbp_get_form_topic_log_edit' with the
3298 * log edit value
3299 * @return string Topic log edit checked value
3300 */
3301 function bbp_get_form_topic_log_edit() {
3302 global $post;
3303
3304 // Get _POST data
3305 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_log_topic_edit'] ) )
3306 $topic_revision = $_POST['bbp_log_topic_edit'];
3307
3308 // No data
3309 else
3310 $topic_revision = 1;
3311
3312 return apply_filters( 'bbp_get_form_topic_log_edit', checked( $topic_revision, true, false ) );
3313 }
3314
3315 /**
3316 * Output the value of the topic edit reason
3317 *
3318 * @since bbPress (r2976)
3319 *
3320 * @uses bbp_get_form_topic_edit_reason() To get the topic edit reason value
3321 */
3322 function bbp_form_topic_edit_reason() {
3323 echo bbp_get_form_topic_edit_reason();
3324 }
3325 /**
3326 * Return the value of the topic edit reason
3327 *
3328 * @since bbPress (r2976)
3329 *
3330 * @uses apply_filters() Calls 'bbp_get_form_topic_edit_reason' with the
3331 * topic edit reason value
3332 * @return string Topic edit reason value
3333 */
3334 function bbp_get_form_topic_edit_reason() {
3335 global $post;
3336
3337 // Get _POST data
3338 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_edit_reason'] ) )
3339 $topic_edit_reason = $_POST['bbp_topic_edit_reason'];
3340
3341 // No data
3342 else
3343 $topic_edit_reason = '';
3344
3345 return apply_filters( 'bbp_get_form_topic_edit_reason', esc_attr( $topic_edit_reason ) );
3346 }
3347
3348 ?>
3349