PluginProbe
bbPress / 2.0.2
bbPress v2.0.2
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 2.2.2 All 71 releases
bbpress / bbp-includes / bbp-topic-template.php

bbp-topic-template.php in bbPress 2.0.2, at bbp-includes/bbp-topic-template.php

3,352 lines 102.7 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' => bbp_get_topics_per_page(),
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) bbp_get_replies_per_page() ),
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 get_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 $topic_id = bbp_get_topic_id( $topic_id );
1935 $count = isset( $bbp->topic_query->current_post ) ? $bbp->topic_query->current_post : 1;
1936 $classes = array();
1937 $classes[] = ( (int) $count % 2 ) ? 'even' : 'odd';
1938 $classes[] = bbp_is_topic_sticky( $topic_id, false ) ? 'sticky' : '';
1939 $classes[] = bbp_is_topic_super_sticky( $topic_id ) ? 'super-sticky' : '';
1940 $classes = array_filter( $classes );
1941 $retval = get_post_class( $classes, $topic_id );
1942 $retval = 'class="' . join( ' ', $retval ) . '"';
1943
1944 return apply_filters( 'bbp_get_topic_class', $retval, $topic_id );
1945 }
1946
1947 /** Topic Admin Links *********************************************************/
1948
1949 /**
1950 * Output admin links for topic
1951 *
1952 * @param mixed $args See {@link bbp_get_topic_admin_links()}
1953 * @uses bbp_get_topic_admin_links() To get the topic admin links
1954 */
1955 function bbp_topic_admin_links( $args = '' ) {
1956 echo bbp_get_topic_admin_links( $args );
1957 }
1958 /**
1959 * Return admin links for topic.
1960 *
1961 * Move topic functionality is handled by the edit topic page.
1962 *
1963 * @param mixed $args This function supports these arguments:
1964 * - id: Optional. Topic id
1965 * - before: Before the links
1966 * - after: After the links
1967 * - sep: Links separator
1968 * - links: Topic admin links array
1969 * @uses current_user_can() To check if the current user can edit/delete
1970 * the topic
1971 * @uses bbp_get_topic_edit_link() To get the topic edit link
1972 * @uses bbp_get_topic_trash_link() To get the topic trash link
1973 * @uses bbp_get_topic_close_link() To get the topic close link
1974 * @uses bbp_get_topic_spam_link() To get the topic spam link
1975 * @uses bbp_get_topic_stick_link() To get the topic stick link
1976 * @uses bbp_get_topic_merge_link() To get the topic merge link
1977 * @uses bbp_get_topic_status() To get the topic status
1978 * @uses apply_filters() Calls 'bbp_get_topic_admin_links' with the
1979 * topic admin links and args
1980 * @return string Topic admin links
1981 */
1982 function bbp_get_topic_admin_links( $args = '' ) {
1983
1984 if ( !bbp_is_single_topic() )
1985 return;
1986
1987 $defaults = array (
1988 'id' => bbp_get_topic_id(),
1989 'before' => '<span class="bbp-admin-links">',
1990 'after' => '</span>',
1991 'sep' => ' | ',
1992 'links' => array()
1993 );
1994
1995 $r = wp_parse_args( $args, $defaults );
1996
1997 if ( !current_user_can( 'edit_topic', $r['id'] ) )
1998 return;
1999
2000 if ( empty( $r['links'] ) ) {
2001 $r['links'] = array(
2002 'edit' => bbp_get_topic_edit_link ( $r ),
2003 'close' => bbp_get_topic_close_link( $r ),
2004 'stick' => bbp_get_topic_stick_link( $r ),
2005 'merge' => bbp_get_topic_merge_link( $r ),
2006 'trash' => bbp_get_topic_trash_link( $r ),
2007 'spam' => bbp_get_topic_spam_link ( $r ),
2008 );
2009 }
2010
2011 // Check caps for trashing the topic
2012 if ( !current_user_can( 'delete_topic', $r['id'] ) && !empty( $r['links']['trash'] ) )
2013 unset( $r['links']['trash'] );
2014
2015 // See if links need to be unset
2016 $topic_status = bbp_get_topic_status( $r['id'] );
2017 if ( in_array( $topic_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) {
2018
2019 // Close link shouldn't be visible on trashed/spammed topics
2020 unset( $r['links']['close'] );
2021
2022 // Spam link shouldn't be visible on trashed topics
2023 if ( $topic_status == bbp_get_trash_status_id() )
2024 unset( $r['links']['spam'] );
2025
2026 // Trash link shouldn't be visible on spam topics
2027 elseif ( $topic_status == bbp_get_spam_status_id() )
2028 unset( $r['links']['trash'] );
2029 }
2030
2031 // Process the admin links
2032 $links = implode( $r['sep'], array_filter( $r['links'] ) );
2033
2034 return apply_filters( 'bbp_get_topic_admin_links', $r['before'] . $links . $r['after'], $args );
2035 }
2036
2037 /**
2038 * Output the edit link of the topic
2039 *
2040 * @since bbPress (r2727)
2041 *
2042 * @param mixed $args See {@link bbp_get_topic_edit_link()}
2043 * @uses bbp_get_topic_edit_link() To get the topic edit link
2044 */
2045 function bbp_topic_edit_link( $args = '' ) {
2046 echo bbp_get_topic_edit_link( $args );
2047 }
2048
2049 /**
2050 * Return the edit link of the topic
2051 *
2052 * @since bbPress (r2727)
2053 *
2054 * @param mixed $args This function supports these args:
2055 * - id: Optional. Topic id
2056 * - link_before: Before the link
2057 * - link_after: After the link
2058 * - edit_text: Edit text
2059 * @uses bbp_get_topic_id() To get the topic id
2060 * @uses bbp_get_topic() To get the topic
2061 * @uses current_user_can() To check if the current user can edit the
2062 * topic
2063 * @uses bbp_get_topic_edit_url() To get the topic edit url
2064 * @uses apply_filters() Calls 'bbp_get_topic_edit_link' with the link
2065 * and args
2066 * @return string Topic edit link
2067 */
2068 function bbp_get_topic_edit_link( $args = '' ) {
2069 $defaults = array (
2070 'id' => 0,
2071 'link_before' => '',
2072 'link_after' => '',
2073 'edit_text' => __( 'Edit', 'bbpress' )
2074 );
2075
2076 $r = wp_parse_args( $args, $defaults );
2077 extract( $r );
2078
2079 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2080
2081 // Bypass check if user has caps
2082 if ( !current_user_can( 'edit_others_topics' ) ) {
2083
2084 // User cannot edit or it is past the lock time
2085 if ( empty( $topic ) || !current_user_can( 'edit_topic', $topic->ID ) || bbp_past_edit_lock( $topic->post_date_gmt ) )
2086 return;
2087 }
2088
2089 // No uri to edit topic
2090 if ( !$uri = bbp_get_topic_edit_url( $id ) )
2091 return;
2092
2093 return apply_filters( 'bbp_get_topic_edit_link', $link_before . '<a href="' . $uri . '">' . $edit_text . '</a>' . $link_after, $args );
2094 }
2095
2096 /**
2097 * Output URL to the topic edit page
2098 *
2099 * @since bbPress (r2753)
2100 *
2101 * @param int $topic_id Optional. Topic id
2102 * @uses bbp_get_topic_edit_url() To get the topic edit url
2103 */
2104 function bbp_topic_edit_url( $topic_id = 0 ) {
2105 echo bbp_get_topic_edit_url( $topic_id );
2106 }
2107 /**
2108 * Return URL to the topic edit page
2109 *
2110 * @since bbPress (r2753)
2111 *
2112 * @param int $topic_id Optional. Topic id
2113 * @uses bbp_get_topic_id() To get the topic id
2114 * @uses bbp_get_topic() To get the topic
2115 * @uses add_query_arg() To add custom args to the url
2116 * @uses home_url() To get the home url
2117 * @uses apply_filters() Calls 'bbp_get_topic_edit_url' with the edit
2118 * url and topic id
2119 * @return string Topic edit url
2120 */
2121 function bbp_get_topic_edit_url( $topic_id = 0 ) {
2122 global $wp_rewrite, $bbp;
2123
2124 if ( !$topic = bbp_get_topic( bbp_get_topic_id( $topic_id ) ) )
2125 return;
2126
2127 // Pretty permalinks
2128 if ( $wp_rewrite->using_permalinks() ) {
2129 $url = $wp_rewrite->root . $bbp->topic_slug . '/' . $topic->post_name . '/edit';
2130 $url = home_url( user_trailingslashit( $url ) );
2131
2132 // Unpretty permalinks
2133 } else {
2134 $url = add_query_arg( array( bbp_get_topic_post_type() => $topic->post_name, 'edit' => '1' ), home_url( '/' ) );
2135 }
2136
2137 return apply_filters( 'bbp_get_topic_edit_url', $url, $topic_id );
2138 }
2139
2140 /**
2141 * Output the trash link of the topic
2142 *
2143 * @since bbPress (r2727)
2144 *
2145 * @param mixed $args See {@link bbp_get_topic_trash_link()}
2146 * @uses bbp_get_topic_trash_link() To get the topic trash link
2147 */
2148 function bbp_topic_trash_link( $args = '' ) {
2149 echo bbp_get_topic_trash_link( $args );
2150 }
2151
2152 /**
2153 * Return the trash link of the topic
2154 *
2155 * @since bbPress (r2727)
2156 *
2157 * @param mixed $args This function supports these args:
2158 * - id: Optional. Topic id
2159 * - link_before: Before the link
2160 * - link_after: After the link
2161 * - sep: Links separator
2162 * - trash_text: Trash text
2163 * - restore_text: Restore text
2164 * - delete_text: Delete text
2165 * @uses bbp_get_topic_id() To get the topic id
2166 * @uses bbp_get_topic() To get the topic
2167 * @uses current_user_can() To check if the current user can delete the
2168 * topic
2169 * @uses bbp_is_topic_trash() To check if the topic is trashed
2170 * @uses bbp_get_topic_status() To get the topic status
2171 * @uses add_query_arg() To add custom args to the url
2172 * @uses wp_nonce_url() To nonce the url
2173 * @uses esc_url() To escape the url
2174 * @uses apply_filters() Calls 'bbp_get_topic_trash_link' with the link
2175 * and args
2176 * @return string Topic trash link
2177 */
2178 function bbp_get_topic_trash_link( $args = '' ) {
2179
2180 $defaults = array (
2181 'id' => 0,
2182 'link_before' => '',
2183 'link_after' => '',
2184 'sep' => ' | ',
2185 'trash_text' => __( 'Trash', 'bbpress' ),
2186 'restore_text' => __( 'Restore', 'bbpress' ),
2187 'delete_text' => __( 'Delete', 'bbpress' )
2188 );
2189 $r = wp_parse_args( $args, $defaults );
2190 extract( $r );
2191
2192 $actions = array();
2193 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2194
2195 if ( empty( $topic ) || !current_user_can( 'delete_topic', $topic->ID ) ) {
2196 return;
2197 }
2198
2199 if ( bbp_is_topic_trash( $topic->ID ) ) {
2200 $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>';
2201 } elseif ( EMPTY_TRASH_DAYS ) {
2202 $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>';
2203 }
2204
2205 if ( bbp_is_topic_trash( $topic->ID ) || !EMPTY_TRASH_DAYS ) {
2206 $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>';
2207 }
2208
2209 // Process the admin links
2210 $actions = implode( $sep, $actions );
2211
2212 return apply_filters( 'bbp_get_topic_trash_link', $link_before . $actions . $link_after, $args );
2213 }
2214
2215 /**
2216 * Output the close link of the topic
2217 *
2218 * @since bbPress (r2727)
2219 *
2220 * @param mixed $args See {@link bbp_get_topic_close_link()}
2221 * @uses bbp_get_topic_close_link() To get the topic close link
2222 */
2223 function bbp_topic_close_link( $args = '' ) {
2224 echo bbp_get_topic_close_link( $args );
2225 }
2226
2227 /**
2228 * Return the close link of the topic
2229 *
2230 * @since bbPress (r2727)
2231 *
2232 * @param mixed $args This function supports these args:
2233 * - id: Optional. Topic id
2234 * - link_before: Before the link
2235 * - link_after: After the link
2236 * - close_text: Close text
2237 * - open_text: Open text
2238 * @uses bbp_get_topic_id() To get the topic id
2239 * @uses bbp_get_topic() To get the topic
2240 * @uses current_user_can() To check if the current user can edit the
2241 * topic
2242 * @uses bbp_is_topic_open() To check if the topic is open
2243 * @uses add_query_arg() To add custom args to the url
2244 * @uses wp_nonce_url() To nonce the url
2245 * @uses esc_url() To escape the url
2246 * @uses apply_filters() Calls 'bbp_get_topic_close_link' with the link
2247 * and args
2248 * @return string Topic close link
2249 */
2250 function bbp_get_topic_close_link( $args = '' ) {
2251 $defaults = array (
2252 'id' => 0,
2253 'link_before' => '',
2254 'link_after' => '',
2255 'sep' => ' | ',
2256 'close_text' => __( 'Close', 'bbpress' ),
2257 'open_text' => __( 'Open', 'bbpress' )
2258 );
2259
2260 $r = wp_parse_args( $args, $defaults );
2261 extract( $r );
2262
2263 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2264
2265 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2266 return;
2267
2268 $display = bbp_is_topic_open( $topic->ID ) ? $close_text : $open_text;
2269
2270 $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_close', 'topic_id' => $topic->ID ) );
2271 $uri = esc_url( wp_nonce_url( $uri, 'close-topic_' . $topic->ID ) );
2272
2273 return apply_filters( 'bbp_get_topic_close_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args );
2274 }
2275
2276 /**
2277 * Output the stick link of the topic
2278 *
2279 * @since bbPress (r2754)
2280 *
2281 * @param mixed $args See {@link bbp_get_topic_stick_link()}
2282 * @uses bbp_get_topic_stick_link() To get the topic stick link
2283 */
2284 function bbp_topic_stick_link( $args = '' ) {
2285 echo bbp_get_topic_stick_link( $args );
2286 }
2287
2288 /**
2289 * Return the stick link of the topic
2290 *
2291 * @since bbPress (r2754)
2292 *
2293 * @param mixed $args This function supports these args:
2294 * - id: Optional. Topic id
2295 * - link_before: Before the link
2296 * - link_after: After the link
2297 * - stick_text: Stick text
2298 * - unstick_text: Unstick text
2299 * - super_text: Stick to front text
2300 * @uses bbp_get_topic_id() To get the topic id
2301 * @uses bbp_get_topic() To get the topic
2302 * @uses current_user_can() To check if the current user can edit the
2303 * topic
2304 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
2305 * @uses add_query_arg() To add custom args to the url
2306 * @uses wp_nonce_url() To nonce the url
2307 * @uses esc_url() To escape the url
2308 * @uses apply_filters() Calls 'bbp_get_topic_stick_link' with the link
2309 * and args
2310 * @return string Topic stick link
2311 */
2312 function bbp_get_topic_stick_link( $args = '' ) {
2313 $defaults = array (
2314 'id' => 0,
2315 'link_before' => '',
2316 'link_after' => '',
2317 'stick_text' => __( 'Stick', 'bbpress' ),
2318 'unstick_text' => __( 'Unstick', 'bbpress' ),
2319 'super_text' => __( 'to front', 'bbpress' ),
2320 );
2321
2322 $r = wp_parse_args( $args, $defaults );
2323 extract( $r );
2324
2325 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2326
2327 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2328 return;
2329
2330 $is_sticky = bbp_is_topic_sticky( $topic->ID );
2331
2332 $stick_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID ) );
2333 $stick_uri = esc_url( wp_nonce_url( $stick_uri, 'stick-topic_' . $topic->ID ) );
2334
2335 $stick_display = true == $is_sticky ? $unstick_text : $stick_text;
2336 $stick_display = '<a href="' . $stick_uri . '">' . $stick_display . '</a>';
2337
2338 if ( empty( $is_sticky ) ) {
2339 $super_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID, 'super' => 1 ) );
2340 $super_uri = esc_url( wp_nonce_url( $super_uri, 'stick-topic_' . $topic->ID ) );
2341
2342 $super_display = ' (<a href="' . $super_uri . '">' . $super_text . '</a>)';
2343 } else {
2344 $super_display = '';
2345 }
2346
2347 return apply_filters( 'bbp_get_topic_stick_link', $link_before . $stick_display . $super_display . $link_after, $args );
2348 }
2349
2350 /**
2351 * Output the merge link of the topic
2352 *
2353 * @since bbPress (r2756)
2354 *
2355 * @param mixed $args
2356 * @uses bbp_get_topic_merge_link() To get the topic merge link
2357 */
2358 function bbp_topic_merge_link( $args = '' ) {
2359 echo bbp_get_topic_merge_link( $args );
2360 }
2361
2362 /**
2363 * Return the merge link of the topic
2364 *
2365 * @since bbPress (r2756)
2366 *
2367 * @param mixed $args This function supports these args:
2368 * - id: Optional. Topic id
2369 * - link_before: Before the link
2370 * - link_after: After the link
2371 * - merge_text: Merge text
2372 * @uses bbp_get_topic_id() To get the topic id
2373 * @uses bbp_get_topic() To get the topic
2374 * @uses bbp_get_topic_edit_url() To get the topic edit url
2375 * @uses add_query_arg() To add custom args to the url
2376 * @uses esc_url() To escape the url
2377 * @uses apply_filters() Calls 'bbp_get_topic_merge_link' with the link
2378 * and args
2379 * @return string Topic merge link
2380 */
2381 function bbp_get_topic_merge_link( $args = '' ) {
2382 $defaults = array (
2383 'id' => 0,
2384 'link_before' => '',
2385 'link_after' => '',
2386 'merge_text' => __( 'Merge', 'bbpress' ),
2387 );
2388
2389 $r = wp_parse_args( $args, $defaults );
2390 extract( $r );
2391
2392 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2393
2394 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2395 return;
2396
2397 $uri = esc_url( add_query_arg( array( 'action' => 'merge' ), bbp_get_topic_edit_url( $topic->ID ) ) );
2398
2399 return apply_filters( 'bbp_get_topic_merge_link', $link_before . '<a href="' . $uri . '">' . $merge_text . '</a>' . $link_after, $args );
2400 }
2401
2402 /**
2403 * Output the spam link of the topic
2404 *
2405 * @since bbPress (r2727)
2406 *
2407 * @param mixed $args See {@link bbp_get_topic_spam_link()}
2408 * @uses bbp_get_topic_spam_link() Topic spam link
2409 */
2410 function bbp_topic_spam_link( $args = '' ) {
2411 echo bbp_get_topic_spam_link( $args );
2412 }
2413
2414 /**
2415 * Return the spam link of the topic
2416 *
2417 * @since bbPress (r2727)
2418 *
2419 * @param mixed $args This function supports these args:
2420 * - id: Optional. Topic id
2421 * - link_before: Before the link
2422 * - link_after: After the link
2423 * - spam_text: Spam text
2424 * - unspam_text: Unspam text
2425 * @uses bbp_get_topic_id() To get the topic id
2426 * @uses bbp_get_topic() To get the topic
2427 * @uses current_user_can() To check if the current user can edit the
2428 * topic
2429 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
2430 * @uses add_query_arg() To add custom args to the url
2431 * @uses wp_nonce_url() To nonce the url
2432 * @uses esc_url() To escape the url
2433 * @uses apply_filters() Calls 'bbp_get_topic_spam_link' with the link
2434 * and args
2435 * @return string Topic spam link
2436 */
2437 function bbp_get_topic_spam_link( $args = '' ) {
2438 $defaults = array (
2439 'id' => 0,
2440 'link_before' => '',
2441 'link_after' => '',
2442 'sep' => ' | ',
2443 'spam_text' => __( 'Spam', 'bbpress' ),
2444 'unspam_text' => __( 'Unspam', 'bbpress' )
2445 );
2446
2447 $r = wp_parse_args( $args, $defaults );
2448 extract( $r );
2449
2450 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2451
2452 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2453 return;
2454
2455 $display = bbp_is_topic_spam( $topic->ID ) ? $unspam_text : $spam_text;
2456
2457 $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_spam', 'topic_id' => $topic->ID ) );
2458 $uri = esc_url( wp_nonce_url( $uri, 'spam-topic_' . $topic->ID ) );
2459
2460 return apply_filters( 'bbp_get_topic_spam_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args );
2461 }
2462
2463 /** Topic Pagination **********************************************************/
2464
2465 /**
2466 * Output the pagination count
2467 *
2468 * @since bbPress (r2519)
2469 *
2470 * @uses bbp_get_forum_pagination_count() To get the forum pagination count
2471 */
2472 function bbp_forum_pagination_count() {
2473 echo bbp_get_forum_pagination_count();
2474 }
2475 /**
2476 * Return the pagination count
2477 *
2478 * @since bbPress (r2519)
2479 *
2480 * @uses bbp_number_format() To format the number value
2481 * @uses apply_filters() Calls 'bbp_get_forum_pagination_count' with the
2482 * pagination count
2483 * @return string Forum Pagintion count
2484 */
2485 function bbp_get_forum_pagination_count() {
2486 global $bbp;
2487
2488 if ( empty( $bbp->topic_query ) )
2489 return false;
2490
2491 // Set pagination values
2492 $start_num = intval( ( $bbp->topic_query->paged - 1 ) * $bbp->topic_query->posts_per_page ) + 1;
2493 $from_num = bbp_number_format( $start_num );
2494 $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 ) );
2495 $total = bbp_number_format( !empty( $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $bbp->topic_query->post_count );
2496
2497 /**
2498 * Translators - _n() should not be needed, as singular/plural strings
2499 * are already separated into unique strings for you
2500 */
2501
2502 // More than one topic
2503 if ( $total > 1 ) {
2504
2505 // Single topic in a forum with several pages
2506 if ( (int) $from_num == (int) $to_num ) {
2507 $retstr = sprintf( __( 'Viewing topic %1$s (of %2$s total)', 'bbpress' ), $from_num, $total );
2508
2509 // Several topics in a forum with a single page
2510 } elseif ( empty( $to_num ) ) {
2511 $retstr = sprintf( __( 'Viewing %1$s topics', 'bbpress' ), $total );
2512
2513 // Several topics in a forum with several pages
2514 } elseif ( (int) $from_num != (int) $to_num ) {
2515 $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 );
2516 }
2517
2518 // Only 1 topic
2519 } else {
2520 $retstr = sprintf( __( 'Viewing %1$s topic', 'bbpress' ), $total );
2521 }
2522
2523 // Filter and return
2524 return apply_filters( 'bbp_get_topic_pagination_count', $retstr );
2525 }
2526
2527 /**
2528 * Output pagination links
2529 *
2530 * @since bbPress (r2519)
2531 *
2532 * @uses bbp_get_forum_pagination_links() To get the pagination links
2533 */
2534 function bbp_forum_pagination_links() {
2535 echo bbp_get_forum_pagination_links();
2536 }
2537 /**
2538 * Return pagination links
2539 *
2540 * @since bbPress (r2519)
2541 *
2542 * @uses bbPress::topic_query::pagination_links To get the links
2543 * @return string Pagination links
2544 */
2545 function bbp_get_forum_pagination_links() {
2546 global $bbp;
2547
2548 if ( empty( $bbp->topic_query ) )
2549 return false;
2550
2551 return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links );
2552 }
2553
2554 /**
2555 * Displays topic notices
2556 *
2557 * @since bbPress (r2744)
2558 *
2559 * @uses bbp_is_single_topic() To check if it's a topic page
2560 * @uses bbp_get_topic_status() To get the topic status
2561 * @uses bbp_get_topic_id() To get the topic id
2562 * @uses apply_filters() Calls 'bbp_topic_notices' with the notice text, topic
2563 * status and topic id
2564 * @uses bbPress::errors::add() To add the notices to the error handler
2565 */
2566 function bbp_topic_notices() {
2567
2568 // Bail if not viewing a topic
2569 if ( !bbp_is_single_topic() )
2570 return;
2571
2572 // Get the topic_status
2573 $topic_status = bbp_get_topic_status();
2574
2575 // Get the topic status
2576 switch ( $topic_status ) {
2577
2578 // Spam notice
2579 case bbp_get_spam_status_id() :
2580 $notice_text = __( 'This topic is marked as spam.', 'bbpress' );
2581 break;
2582
2583 // Trashed notice
2584 case bbp_get_trash_status_id() :
2585 $notice_text = __( 'This topic is in the trash.', 'bbpress' );
2586 break;
2587
2588 // Standard status
2589 default :
2590 $notice_text = '';
2591 break;
2592 }
2593
2594 // Filter notice text and bail if empty
2595 if ( !$notice_text = apply_filters( 'bbp_topic_notices', $notice_text, $topic_status, bbp_get_topic_id() ) )
2596 return;
2597
2598 bbp_add_error( 'topic_notice', $notice_text, 'message' );
2599 }
2600
2601 /**
2602 * Displays topic type select box (normal/sticky/super sticky)
2603 *
2604 * @since bbPress (r2784)
2605 *
2606 * @param $args This function supports these arguments:
2607 * - stick_text: Sticky text
2608 * - super_text: Super Sticky text
2609 * - unstick_text: Unstick (normal) text
2610 * - select_id: Select id. Defaults to bbp_stick_topic
2611 * - tab: Tabindex
2612 * - topic_id: Topic id
2613 * @uses bbp_get_topic_id() To get the topic id
2614 * @uses bbp_is_topic_edit() To check if it is the topic edit page
2615 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
2616 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
2617 */
2618 function bbp_topic_type_select( $args = '' ) {
2619
2620 $defaults = array (
2621 'unstick_text' => __( 'Normal', 'bbpress' ),
2622 'stick_text' => __( 'Sticky', 'bbpress' ),
2623 'super_text' => __( 'Super Sticky', 'bbpress' ),
2624 'select_id' => 'bbp_stick_topic',
2625 'tab' => bbp_get_tab_index(),
2626 'topic_id' => 0
2627 );
2628
2629 $r = wp_parse_args( $args, $defaults );
2630 extract( $r );
2631
2632 // Get current topic id
2633 $topic_id = bbp_get_topic_id( $topic_id );
2634
2635 // Edit topic
2636 if ( bbp_is_topic_edit() ) {
2637
2638 // Post value is passed
2639 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$select_id] ) ) {
2640 $sticky_current = $_POST[$select_id];
2641
2642 // Topic is super sticky
2643 } elseif ( bbp_is_topic_super_sticky( $topic_id ) ) {
2644 $sticky_current = 'super';
2645
2646 // Topic is sticky or normal
2647 } else {
2648 $sticky_current = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick';
2649 }
2650
2651 // New topic
2652 } else {
2653
2654 // Post value is passed
2655 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$select_id] ) ) {
2656 $sticky_current = $_POST[$select_id];
2657
2658 // Default to unstick
2659 } else {
2660 $sticky_current = 'unstick';
2661 }
2662 }
2663
2664 // Used variables
2665 $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
2666 $select_id = esc_attr( $select_id );
2667 $sticky_statuses = array (
2668 'unstick' => $unstick_text,
2669 'stick' => $stick_text,
2670 'super' => $super_text,
2671 ); ?>
2672
2673 <select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>"<?php echo $tab; ?>>
2674
2675 <?php foreach ( $sticky_statuses as $sticky_status => $label ) : ?>
2676
2677 <option value="<?php echo $sticky_status; ?>"<?php selected( $sticky_current, $sticky_status ); ?>><?php echo $label; ?></option>
2678
2679 <?php endforeach; ?>
2680
2681 </select>
2682
2683 <?php
2684 }
2685
2686 /** Single Topic **************************************************************/
2687
2688 /**
2689 * Output a fancy description of the current topic, including total topics,
2690 * total replies, and last activity.
2691 *
2692 * @since bbPress (r2860)
2693 *
2694 * @param array $args See {@link bbp_get_single_topic_description()}
2695 * @uses bbp_get_single_topic_description() Return the eventual output
2696 */
2697 function bbp_single_topic_description( $args = '' ) {
2698 echo bbp_get_single_topic_description( $args );
2699 }
2700 /**
2701 * Return a fancy description of the current topic, including total topics,
2702 * total replies, and last activity.
2703 *
2704 * @since bbPress (r2860)
2705 *
2706 * @param mixed $args This function supports these arguments:
2707 * - topic_id: Topic id
2708 * - before: Before the text
2709 * - after: After the text
2710 * - size: Size of the avatar
2711 * @uses bbp_get_topic_id() To get the topic id
2712 * @uses bbp_get_topic_voice_count() To get the topic voice count
2713 * @uses bbp_get_topic_reply_count() To get the topic reply count
2714 * @uses bbp_get_topic_freshness_link() To get the topic freshness link
2715 * @uses bbp_get_topic_last_active_id() To get the topic last active id
2716 * @uses bbp_get_reply_author_link() To get the reply author link
2717 * @uses apply_filters() Calls 'bbp_get_single_topic_description' with
2718 * the description and args
2719 * @return string Filtered topic description
2720 */
2721 function bbp_get_single_topic_description( $args = '' ) {
2722 // Default arguments
2723 $defaults = array (
2724 'topic_id' => 0,
2725 'before' => '<div class="bbp-template-notice info"><p class="bbp-topic-description">',
2726 'after' => '</p></div>',
2727 'size' => 14
2728 );
2729 $r = wp_parse_args( $args, $defaults );
2730 extract( $r );
2731
2732 // Validate topic_id
2733 $topic_id = bbp_get_topic_id( $topic_id );
2734
2735 // Unhook the 'view all' query var adder
2736 remove_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
2737
2738 // Build the topic description
2739 $forum_id = bbp_get_topic_forum_id ( $topic_id );
2740 $voice_count = bbp_get_topic_voice_count ( $topic_id );
2741 $reply_count = bbp_get_topic_replies_link ( $topic_id );
2742 $time_since = bbp_get_topic_freshness_link( $topic_id );
2743
2744 // Singular/Plural
2745 $voice_count = sprintf( _n( '%s voice', '%s voices', $voice_count, 'bbpress' ), $voice_count );
2746
2747 // Topic has replies
2748 if ( $last_reply = bbp_get_topic_last_active_id( $topic_id ) ) {
2749 $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $size ) );
2750 $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 );
2751
2752 // Topic has no replies
2753 } else {
2754 $retstr = sprintf( __( 'This topic has %1$s, contains %2$s.', 'bbpress' ), $voice_count, $reply_count );
2755 }
2756
2757 // Add the 'view all' filter back
2758 add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
2759
2760 // Combine the elements together
2761 $retstr = $before . $retstr . $after;
2762
2763 // Return filtered result
2764 return apply_filters( 'bbp_get_single_topic_description', $retstr, $args );
2765 }
2766
2767 /** Topic Tags ****************************************************************/
2768
2769 /**
2770 * Output the unique id of the topic tag taxonomy
2771 *
2772 * @since bbPress (r3348)
2773 *
2774 * @uses bbp_get_topic_post_type() To get the topic post type
2775 */
2776 function bbp_topic_tag_tax_id() {
2777 echo bbp_get_topic_tag_tax_id();
2778 }
2779 /**
2780 * Return the unique id of the topic tag taxonomy
2781 *
2782 * @since bbPress (r3348)
2783 *
2784 * @uses apply_filters() Calls 'bbp_get_topic_tag_tax_id' with the topic tax id
2785 * @return string The unique topic tag taxonomy
2786 */
2787 function bbp_get_topic_tag_tax_id() {
2788 global $bbp;
2789
2790 return apply_filters( 'bbp_get_topic_tag_tax_id', $bbp->topic_tag_tax_id );
2791 }
2792
2793 /**
2794 * Output the id of the current tag
2795 *
2796 * @since bbPress (r3109)
2797 *
2798 * @uses bbp_get_topic_tag_id()
2799 */
2800 function bbp_topic_tag_id( $tag = '' ) {
2801 echo bbp_get_topic_tag_id( $tag );
2802 }
2803 /**
2804 * Return the id of the current tag
2805 *
2806 * @since bbPress (r3109)
2807 *
2808 * @uses get_term_by()
2809 * @uses get_query_var()
2810 * @uses apply_filters()
2811 *
2812 * @return string Term Name
2813 */
2814 function bbp_get_topic_tag_id( $tag = '' ) {
2815
2816 // Get the term
2817 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2818 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2819
2820 // Add before and after if description exists
2821 if ( !empty( $term->term_id ) )
2822 $retval = $term->term_id;
2823
2824 // No id
2825 else
2826 $retval = '';
2827
2828 return apply_filters( 'bbp_get_topic_tag_id', (int) $retval );
2829 }
2830
2831 /**
2832 * Output the name of the current tag
2833 *
2834 * @since bbPress (r3109)
2835 *
2836 * @uses bbp_get_topic_tag_name()
2837 */
2838 function bbp_topic_tag_name( $tag = '' ) {
2839 echo bbp_get_topic_tag_name( $tag );
2840 }
2841 /**
2842 * Return the name of the current tag
2843 *
2844 * @since bbPress (r3109)
2845 *
2846 * @uses get_term_by()
2847 * @uses get_query_var()
2848 * @uses apply_filters()
2849 *
2850 * @return string Term Name
2851 */
2852 function bbp_get_topic_tag_name( $tag = '' ) {
2853
2854 // Get the term
2855 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2856 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2857
2858 // Add before and after if description exists
2859 if ( !empty( $term->name ) )
2860 $retval = $term->name;
2861
2862 // No name
2863 else
2864 $retval = '';
2865
2866 return apply_filters( 'bbp_get_topic_tag_name', $retval );
2867 }
2868
2869 /**
2870 * Output the slug of the current tag
2871 *
2872 * @since bbPress (r3109)
2873 *
2874 * @uses bbp_get_topic_tag_slug()
2875 */
2876 function bbp_topic_tag_slug( $tag = '' ) {
2877 echo bbp_get_topic_tag_slug( $tag );
2878 }
2879 /**
2880 * Return the slug of the current tag
2881 *
2882 * @since bbPress (r3109)
2883 *
2884 * @uses get_term_by()
2885 * @uses get_query_var()
2886 * @uses apply_filters()
2887 *
2888 * @return string Term Name
2889 */
2890 function bbp_get_topic_tag_slug( $tag = '' ) {
2891
2892 // Get the term
2893 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2894 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2895
2896 // Add before and after if description exists
2897 if ( !empty( $term->slug ) )
2898 $retval = $term->slug;
2899
2900 // No slug
2901 else
2902 $retval = '';
2903
2904 return apply_filters( 'bbp_get_topic_tag_slug', $retval );
2905 }
2906
2907 /**
2908 * Output the link of the current tag
2909 *
2910 * @since bbPress (r3348)
2911 *
2912 * @uses bbp_get_topic_tag_link()
2913 */
2914 function bbp_topic_tag_link( $tag = '' ) {
2915 echo bbp_get_topic_tag_link( $tag );
2916 }
2917 /**
2918 * Return the link of the current tag
2919 *
2920 * @since bbPress (r3348)
2921 *
2922 * @uses get_term_by()
2923 * @uses get_query_var()
2924 * @uses apply_filters()
2925 *
2926 * @return string Term Name
2927 */
2928 function bbp_get_topic_tag_link( $tag = '' ) {
2929
2930 // Get the term
2931 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2932 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2933
2934 // Add before and after if description exists
2935 if ( !empty( $term->term_id ) )
2936 $retval = get_term_link( $term, bbp_get_topic_tag_tax_id() );
2937
2938 // No link
2939 else
2940 $retval = '';
2941
2942 return apply_filters( 'bbp_get_topic_tag_link', $retval );
2943 }
2944
2945 /**
2946 * Output the link of the current tag
2947 *
2948 * @since bbPress (r3348)
2949 *
2950 * @uses bbp_get_topic_tag_edit_link()
2951 */
2952 function bbp_topic_tag_edit_link( $tag = '' ) {
2953 echo bbp_get_topic_tag_edit_link( $tag );
2954 }
2955 /**
2956 * Return the link of the current tag
2957 *
2958 * @since bbPress (r3348)
2959 *
2960 * @uses get_term_by()
2961 * @uses get_query_var()
2962 * @uses apply_filters()
2963 *
2964 * @return string Term Name
2965 */
2966 function bbp_get_topic_tag_edit_link( $tag = '' ) {
2967 global $wp_query, $wp_rewrite;
2968
2969 // Get the term
2970 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2971 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2972
2973 // Add before and after if description exists
2974 if ( !empty( $term->term_id ) ) {
2975
2976 // Pretty
2977 if ( $wp_rewrite->using_permalinks() ) {
2978 $retval = user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . 'edit' );
2979
2980 // Ugly
2981 } else {
2982 $retval = add_query_arg( array( 'edit' => '1' ), bbp_get_topic_tag_link() );
2983 }
2984
2985 // No link
2986 } else {
2987 $retval = '';
2988 }
2989
2990 return apply_filters( 'bbp_get_topic_tag_edit_link', $retval );
2991 }
2992
2993 /**
2994 * Output the description of the current tag
2995 *
2996 * @since bbPress (r3109)
2997 *
2998 * @uses bbp_get_topic_tag_description()
2999 */
3000 function bbp_topic_tag_description( $args = array() ) {
3001 echo bbp_get_topic_tag_description( $args );
3002 }
3003 /**
3004 * Return the description of the current tag
3005 *
3006 * @since bbPress (r3109)
3007 *
3008 * @uses get_term_by()
3009 * @uses get_query_var()
3010 * @uses apply_filters()
3011 *
3012 * @return string Term Name
3013 */
3014 function bbp_get_topic_tag_description( $args = array() ) {
3015
3016 $defaults = array(
3017 'before' => '<div class="bbp-topic-tag-description"><p>',
3018 'after' => '</p></div>',
3019 'tag' => ''
3020 );
3021 $r = wp_parse_args( $args, $defaults );
3022 extract( $r );
3023
3024 // Get the term
3025 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
3026 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3027
3028 // Add before and after if description exists
3029 if ( !empty( $term->description ) )
3030 $retval = $before . $term->description . $after;
3031
3032 // No description, no HTML
3033 else
3034 $retval = '';
3035
3036 return apply_filters( 'bbp_get_topic_tag_description', $retval, $args );
3037 }
3038
3039 /** Forms *********************************************************************/
3040
3041 /**
3042 * Output the value of topic title field
3043 *
3044 * @since bbPress (r2976)
3045 *
3046 * @uses bbp_get_form_topic_title() To get the value of topic title field
3047 */
3048 function bbp_form_topic_title() {
3049 echo bbp_get_form_topic_title();
3050 }
3051 /**
3052 * Return the value of topic title field
3053 *
3054 * @since bbPress (r2976)
3055 *
3056 * @uses bbp_is_topic_edit() To check if it's topic edit page
3057 * @uses apply_filters() Calls 'bbp_get_form_topic_title' with the title
3058 * @return string Value of topic title field
3059 */
3060 function bbp_get_form_topic_title() {
3061 global $post;
3062
3063 // Get _POST data
3064 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_title'] ) )
3065 $topic_title = $_POST['bbp_topic_title'];
3066
3067 // Get edit data
3068 elseif ( !empty( $post->post_title ) && bbp_is_topic_edit() )
3069 $topic_title = $post->post_title;
3070
3071 // No data
3072 else
3073 $topic_title = '';
3074
3075 return apply_filters( 'bbp_get_form_topic_title', esc_attr( $topic_title ) );
3076 }
3077
3078 /**
3079 * Output the value of topic content field
3080 *
3081 * @since bbPress (r2976)
3082 *
3083 * @uses bbp_get_form_topic_content() To get value of topic content field
3084 */
3085 function bbp_form_topic_content() {
3086 echo bbp_get_form_topic_content();
3087 }
3088 /**
3089 * Return the value of topic content field
3090 *
3091 * @since bbPress (r2976)
3092 *
3093 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3094 * @uses apply_filters() Calls 'bbp_get_form_topic_content' with the content
3095 * @return string Value of topic content field
3096 */
3097 function bbp_get_form_topic_content() {
3098 global $post;
3099
3100 // Get _POST data
3101 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_content'] ) )
3102 $topic_content = $_POST['bbp_topic_content'];
3103
3104 // Get edit data
3105 elseif ( !empty( $post->post_title ) && bbp_is_topic_edit() )
3106 $topic_content = $post->post_content;
3107
3108 // No data
3109 else
3110 $topic_content = '';
3111
3112 return apply_filters( 'bbp_get_form_topic_content', esc_textarea( $topic_content ) );
3113 }
3114
3115 /**
3116 * Output value of topic tags field
3117 *
3118 * @since bbPress (r2976)
3119 * @uses bbp_get_form_topic_tags() To get the value of topic tags field
3120 */
3121 function bbp_form_topic_tags() {
3122 echo bbp_get_form_topic_tags();
3123 }
3124 /**
3125 * Return value of topic tags field
3126 *
3127 * @since bbPress (r2976)
3128 *
3129 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3130 * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags
3131 * @return string Value of topic tags field
3132 */
3133 function bbp_get_form_topic_tags() {
3134 global $post;
3135
3136 // Get _POST data
3137 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_tags'] ) ) {
3138 $topic_tags = $_POST['bbp_topic_tags'];
3139
3140 // Get edit data
3141 } elseif ( !empty( $post ) ) {
3142
3143 // Post is a topic
3144 if ( bbp_get_topic_post_type() == $post->post_type ) {
3145 $topic_id = $post->ID;
3146
3147 // Post is a reply
3148 } elseif ( bbp_get_reply_post_type() == $post->post_type ) {
3149 $topic_id = bbp_get_reply_topic_id( $post->ID );
3150 }
3151
3152 // Topic exists
3153 if ( !empty( $topic_id ) ) {
3154
3155 // Topic is spammed so display pre-spam terms
3156 if ( bbp_is_topic_spam( $topic_id ) ) {
3157
3158 // Get pre-spam terms
3159 $new_terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );
3160
3161 // If terms exist, explode them and compile the return value
3162 if ( empty( $new_terms ) ) {
3163 $new_terms = '';
3164 }
3165
3166 // Topic is not spam so get real terms
3167 } else {
3168 $terms = array_filter( (array) get_the_terms( $topic_id, bbp_get_topic_tag_tax_id() ) );
3169
3170 // Loop through them
3171 foreach( $terms as $term ) {
3172 $new_terms[] = $term->name;
3173 }
3174 }
3175
3176 // Define local variable(s)
3177 } else {
3178 $new_terms = '';
3179 }
3180
3181 // Set the return value
3182 $topic_tags = ( !empty( $new_terms ) ) ? implode( ', ', $new_terms ) : '';
3183
3184 // No data
3185 } else {
3186 $topic_tags = '';
3187 }
3188
3189 return apply_filters( 'bbp_get_form_topic_tags', esc_attr( $topic_tags ) );
3190 }
3191
3192 /**
3193 * Output value of topic forum
3194 *
3195 * @since bbPress (r2976)
3196 *
3197 * @uses bbp_get_form_topic_forum() To get the topic's forum id
3198 */
3199 function bbp_form_topic_forum() {
3200 echo bbp_get_form_topic_forum();
3201 }
3202 /**
3203 * Return value of topic forum
3204 *
3205 * @since bbPress (r2976)
3206 *
3207 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3208 * @uses bbp_get_topic_forum_id() To get the topic forum id
3209 * @uses apply_filters() Calls 'bbp_get_form_topic_forum' with the forum
3210 * @return string Value of topic content field
3211 */
3212 function bbp_get_form_topic_forum() {
3213
3214 // Get _POST data
3215 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_id'] ) )
3216 $topic_forum = $_POST['bbp_forum_id'];
3217
3218 // Get edit data
3219 elseif ( bbp_is_topic_edit() )
3220 $topic_forum = bbp_get_topic_forum_id();
3221
3222 // No data
3223 else
3224 $topic_forum = 0;
3225
3226 return apply_filters( 'bbp_get_form_topic_forum', esc_attr( $topic_forum ) );
3227 }
3228
3229 /**
3230 * Output checked value of topic subscription
3231 *
3232 * @since bbPress (r2976)
3233 *
3234 * @uses bbp_get_form_topic_subscribed() To get the subscribed checkbox value
3235 */
3236 function bbp_form_topic_subscribed() {
3237 echo bbp_get_form_topic_subscribed();
3238 }
3239 /**
3240 * Return checked value of topic subscription
3241 *
3242 * @since bbPress (r2976)
3243 *
3244 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3245 * @uses bbp_is_user_subscribed() To check if the user is subscribed to
3246 * the topic
3247 * @uses apply_filters() Calls 'bbp_get_form_topic_subscribed' with the
3248 * option
3249 * @return string Checked value of topic subscription
3250 */
3251 function bbp_get_form_topic_subscribed() {
3252 global $post;
3253
3254 // Get _POST data
3255 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_subscription'] ) ) {
3256 $topic_subscribed = $_POST['bbp_topic_subscription'];
3257
3258 // Get edit data
3259 } elseif ( bbp_is_topic_edit() || bbp_is_reply_edit() ) {
3260
3261 // Post author is not the current user
3262 if ( $post->post_author != bbp_get_current_user_id() ) {
3263 $topic_subscribed = bbp_is_user_subscribed( $post->post_author );
3264
3265 // Post author is the current user
3266 } else {
3267 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() );
3268 }
3269
3270 // Get current status
3271 } elseif ( bbp_is_single_topic() ) {
3272 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() );
3273
3274 // No data
3275 } else {
3276 $topic_subscribed = 0;
3277 }
3278
3279 // Get checked output
3280 $checked = checked( $topic_subscribed, true, false );
3281
3282 return apply_filters( 'bbp_get_form_topic_subscribed', $checked, $topic_subscribed );
3283 }
3284
3285 /**
3286 * Output checked value of topic log edit field
3287 *
3288 * @since bbPress (r2976)
3289 *
3290 * @uses bbp_get_form_topic_log_edit() To get the topic log edit value
3291 */
3292 function bbp_form_topic_log_edit() {
3293 echo bbp_get_form_topic_log_edit();
3294 }
3295 /**
3296 * Return checked value of topic log edit field
3297 *
3298 * @since bbPress (r2976)
3299 *
3300 * @uses apply_filters() Calls 'bbp_get_form_topic_log_edit' with the
3301 * log edit value
3302 * @return string Topic log edit checked value
3303 */
3304 function bbp_get_form_topic_log_edit() {
3305 global $post;
3306
3307 // Get _POST data
3308 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_log_topic_edit'] ) )
3309 $topic_revision = $_POST['bbp_log_topic_edit'];
3310
3311 // No data
3312 else
3313 $topic_revision = 1;
3314
3315 return apply_filters( 'bbp_get_form_topic_log_edit', checked( $topic_revision, true, false ) );
3316 }
3317
3318 /**
3319 * Output the value of the topic edit reason
3320 *
3321 * @since bbPress (r2976)
3322 *
3323 * @uses bbp_get_form_topic_edit_reason() To get the topic edit reason value
3324 */
3325 function bbp_form_topic_edit_reason() {
3326 echo bbp_get_form_topic_edit_reason();
3327 }
3328 /**
3329 * Return the value of the topic edit reason
3330 *
3331 * @since bbPress (r2976)
3332 *
3333 * @uses apply_filters() Calls 'bbp_get_form_topic_edit_reason' with the
3334 * topic edit reason value
3335 * @return string Topic edit reason value
3336 */
3337 function bbp_get_form_topic_edit_reason() {
3338 global $post;
3339
3340 // Get _POST data
3341 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_edit_reason'] ) )
3342 $topic_edit_reason = $_POST['bbp_topic_edit_reason'];
3343
3344 // No data
3345 else
3346 $topic_edit_reason = '';
3347
3348 return apply_filters( 'bbp_get_form_topic_edit_reason', esc_attr( $topic_edit_reason ) );
3349 }
3350
3351 ?>
3352