PluginProbe
bbPress / 2.0-rc-4
bbPress v2.0-rc-4
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / bbp-includes / bbp-topic-template.php

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

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