PluginProbe
bbPress / 2.0-rc-2
bbPress v2.0-rc-2
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-2, at bbp-includes/bbp-topic-template.php

3,234 lines 99.2 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', '%#%' );
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 return apply_filters( 'bbp_get_topic_author_url', $author_url, $topic_id );
1292 }
1293
1294 /**
1295 * Output the title of the forum a topic belongs to
1296 *
1297 * @since bbPress (r2485)
1298 *
1299 * @param int $topic_id Optional. Topic id
1300 * @uses bbp_get_topic_forum_title() To get the topic's forum title
1301 */
1302 function bbp_topic_forum_title( $topic_id = 0 ) {
1303 echo bbp_get_topic_forum_title( $topic_id );
1304 }
1305 /**
1306 * Return the title of the forum a topic belongs to
1307 *
1308 * @since bbPress (r2485)
1309 *
1310 * @param int $topic_id Optional. Topic id
1311 * @uses bbp_get_topic_id() To get topic id
1312 * @uses bbp_get_topic_forum_id() To get topic's forum id
1313 * @uses apply_filters() Calls 'bbp_get_topic_forum' with the forum
1314 * title and topic id
1315 * @return string Topic forum title
1316 */
1317 function bbp_get_topic_forum_title( $topic_id = 0 ) {
1318 $topic_id = bbp_get_topic_id( $topic_id );
1319 $forum_id = bbp_get_topic_forum_id( $topic_id );
1320
1321 return apply_filters( 'bbp_get_topic_forum', bbp_get_forum_title( $forum_id ), $topic_id );
1322 }
1323
1324 /**
1325 * Output the forum id a topic belongs to
1326 *
1327 * @since bbPress (r2491)
1328 *
1329 * @param int $topic_id Optional. Topic id
1330 * @uses bbp_get_topic_forum_id()
1331 */
1332 function bbp_topic_forum_id( $topic_id = 0 ) {
1333 echo bbp_get_topic_forum_id( $topic_id );
1334 }
1335 /**
1336 * Return the forum id a topic belongs to
1337 *
1338 * @since bbPress (r2491)
1339 *
1340 * @param int $topic_id Optional. Topic id
1341 * @uses bbp_get_topic_id() To get topic id
1342 * @uses get_post_meta() To retrieve get topic's forum id meta
1343 * @uses apply_filters() Calls 'bbp_get_topic_forum_id' with the forum
1344 * id and topic id
1345 * @return int Topic forum id
1346 */
1347 function bbp_get_topic_forum_id( $topic_id = 0 ) {
1348 $topic_id = bbp_get_topic_id( $topic_id );
1349 $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true );
1350
1351 return apply_filters( 'bbp_get_topic_forum_id', (int) $forum_id, $topic_id );
1352 }
1353
1354 /**
1355 * Output the topics last active ID
1356 *
1357 * @since bbPress (r2860)
1358 *
1359 * @param int $topic_id Optional. Forum id
1360 * @uses bbp_get_topic_last_active_id() To get the topic's last active id
1361 */
1362 function bbp_topic_last_active_id( $topic_id = 0 ) {
1363 echo bbp_get_topic_last_active_id( $topic_id );
1364 }
1365 /**
1366 * Return the topics last active ID
1367 *
1368 * @since bbPress (r2860)
1369 *
1370 * @param int $topic_id Optional. Forum id
1371 * @uses bbp_get_topic_id() To get the topic id
1372 * @uses get_post_meta() To get the topic's last active id
1373 * @uses apply_filters() Calls 'bbp_get_topic_last_active_id' with
1374 * the last active id and topic id
1375 * @return int Forum's last active id
1376 */
1377 function bbp_get_topic_last_active_id( $topic_id = 0 ) {
1378 $topic_id = bbp_get_topic_id( $topic_id );
1379 $active_id = get_post_meta( $topic_id, '_bbp_last_active_id', true );
1380
1381 return apply_filters( 'bbp_get_topic_last_active_id', (int) $active_id, $topic_id );
1382 }
1383
1384 /**
1385 * Output the topics last update date/time (aka freshness)
1386 *
1387 * @since bbPress (r2625)
1388 *
1389 * @param int $topic_id Optional. Topic id
1390 * @uses bbp_get_topic_last_active_time() To get topic freshness
1391 */
1392 function bbp_topic_last_active_time( $topic_id = 0 ) {
1393 echo bbp_get_topic_last_active_time( $topic_id );
1394 }
1395 /**
1396 * Return the topics last update date/time (aka freshness)
1397 *
1398 * @since bbPress (r2625)
1399 *
1400 * @param int $topic_id Optional. Topic id
1401 * @uses bbp_get_topic_id() To get topic id
1402 * @uses get_post_meta() To get the topic lst active meta
1403 * @uses bbp_get_topic_last_reply_id() To get topic last reply id
1404 * @uses get_post_field() To get the post date of topic/reply
1405 * @uses bbp_convert_date() To convert date
1406 * @uses bbp_get_time_since() To get time in since format
1407 * @uses apply_filters() Calls 'bbp_get_topic_last_active' with topic
1408 * freshness and topic id
1409 * @return string Topic freshness
1410 */
1411 function bbp_get_topic_last_active_time( $topic_id = 0 ) {
1412 $topic_id = bbp_get_topic_id( $topic_id );
1413
1414 // Try to get the most accurate freshness time possible
1415 if ( !$last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true ) ) {
1416 if ( $reply_id = bbp_get_topic_last_reply_id( $topic_id ) ) {
1417 $last_active = get_post_field( 'post_date', $reply_id );
1418 } else {
1419 $last_active = get_post_field( 'post_date', $topic_id );
1420 }
1421 }
1422
1423 $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
1424
1425 // Return the time since
1426 return apply_filters( 'bbp_get_topic_last_active', $last_active, $topic_id );
1427 }
1428
1429 /** Topic Last Reply **********************************************************/
1430
1431 /**
1432 * Output the id of the topics last reply
1433 *
1434 * @since bbPress (r2625)
1435 *
1436 * @param int $topic_id Optional. Topic id
1437 * @uses bbp_get_topic_last_reply_id() To get the topic last reply id
1438 */
1439 function bbp_topic_last_reply_id( $topic_id = 0 ) {
1440 echo bbp_get_topic_last_reply_id( $topic_id );
1441 }
1442 /**
1443 * Return the topics last update date/time (aka freshness)
1444 *
1445 * @since bbPress (r2625)
1446 *
1447 * @param int $topic_id Optional. Topic id
1448 * @uses bbp_get_topic_id() To get the topic id
1449 * @uses get_post_meta() To get the last reply id meta
1450 * @uses apply_filters() Calls 'bbp_get_topic_last_reply_id' with the
1451 * last reply id and topic id
1452 * @return int Topic last reply id
1453 */
1454 function bbp_get_topic_last_reply_id( $topic_id = 0 ) {
1455 $topic_id = bbp_get_topic_id( $topic_id );
1456 $reply_id = get_post_meta( $topic_id, '_bbp_last_reply_id', true );
1457
1458 if ( empty( $reply_id ) )
1459 $reply_id = $topic_id;
1460
1461 return apply_filters( 'bbp_get_topic_last_reply_id', (int) $reply_id, $topic_id );
1462 }
1463
1464 /**
1465 * Output the title of the last reply inside a topic
1466 *
1467 * @param int $topic_id Optional. Topic id
1468 * @uses bbp_get_topic_last_reply_title() To get the topic last reply title
1469 */
1470 function bbp_topic_last_reply_title( $topic_id = 0 ) {
1471 echo bbp_get_topic_last_reply_title( $topic_id );
1472 }
1473 /**
1474 * Return the title of the last reply inside a topic
1475 *
1476 * @param int $topic_id Optional. Topic id
1477 * @uses bbp_get_topic_id() To get the topic id
1478 * @uses bbp_get_topic_last_reply_id() To get the topic last reply id
1479 * @uses bbp_get_reply_title() To get the reply title
1480 * @uses apply_filters() Calls 'bbp_get_topic_last_topic_title' with
1481 * the reply title and topic id
1482 * @return string Topic last reply title
1483 */
1484 function bbp_get_topic_last_reply_title( $topic_id = 0 ) {
1485 $topic_id = bbp_get_topic_id( $topic_id );
1486 return apply_filters( 'bbp_get_topic_last_topic_title', bbp_get_reply_title( bbp_get_topic_last_reply_id( $topic_id ) ), $topic_id );
1487 }
1488
1489 /**
1490 * Output the link to the last reply in a topic
1491 *
1492 * @since bbPress (r2464)
1493 *
1494 * @param int $topic_id Optional. Topic id
1495 * @uses bbp_get_topic_last_reply_permalink() To get the topic's last reply link
1496 */
1497 function bbp_topic_last_reply_permalink( $topic_id = 0 ) {
1498 echo bbp_get_topic_last_reply_permalink( $topic_id );
1499 }
1500 /**
1501 * Return the link to the last reply in a topic
1502 *
1503 * @since bbPress (r2464)
1504 *
1505 * @param int $topic_id Optional. Topic id
1506 * @uses bbp_get_topic_id() To get the topic id
1507 * @uses bbp_get_topic_last_reply_id() To get the topic last reply id
1508 * @uses bbp_get_reply_permalink() To get the reply permalink
1509 * @uses apply_filters() Calls 'bbp_get_topic_last_topic_permalink' with
1510 * the reply permalink and topic id
1511 * @return string Permanent link to the reply
1512 */
1513 function bbp_get_topic_last_reply_permalink( $topic_id = 0 ) {
1514 $topic_id = bbp_get_topic_id( $topic_id );
1515 return apply_filters( 'bbp_get_topic_last_reply_permalink', bbp_get_reply_permalink( bbp_get_topic_last_reply_id( $topic_id ) ) );
1516 }
1517
1518 /**
1519 * Output the link to the last reply in a topic
1520 *
1521 * @since bbPress (r2683)
1522 *
1523 * @param int $topic_id Optional. Topic id
1524 * @uses bbp_get_topic_last_reply_url() To get the topic last reply url
1525 */
1526 function bbp_topic_last_reply_url( $topic_id = 0 ) {
1527 echo bbp_get_topic_last_reply_url( $topic_id );
1528 }
1529 /**
1530 * Return the link to the last reply in a topic
1531 *
1532 * @since bbPress (r2683)
1533 *
1534 * @param int $topic_id Optional. Topic id
1535 * @uses bbp_get_topic_id() To get the topic id
1536 * @uses bbp_get_topic_last_reply_id() To get the topic last reply id
1537 * @uses bbp_get_reply_url() To get the reply url
1538 * @uses bbp_get_reply_permalink() To get the reply permalink
1539 * @uses apply_filters() Calls 'bbp_get_topic_last_topic_url' with
1540 * the reply url and topic id
1541 * @return string Topic last reply url
1542 */
1543 function bbp_get_topic_last_reply_url( $topic_id = 0 ) {
1544 $topic_id = bbp_get_topic_id( $topic_id );
1545 $reply_id = bbp_get_topic_last_reply_id( $topic_id );
1546
1547 if ( !empty( $reply_id ) && ( $reply_id != $topic_id ) )
1548 $reply_url = bbp_get_reply_url( $reply_id );
1549 else
1550 $reply_url = bbp_get_topic_permalink( $topic_id );
1551
1552 return apply_filters( 'bbp_get_topic_last_reply_url', $reply_url );
1553 }
1554
1555 /**
1556 * Output link to the most recent activity inside a topic, complete with link
1557 * attributes and content.
1558 *
1559 * @since bbPress (r2625)
1560 *
1561 * @param int $topic_id Optional. Topic id
1562 * @uses bbp_get_topic_freshness_link() To get the topic freshness link
1563 */
1564 function bbp_topic_freshness_link( $topic_id = 0) {
1565 echo bbp_get_topic_freshness_link( $topic_id );
1566 }
1567 /**
1568 * Returns link to the most recent activity inside a topic, complete
1569 * with link attributes and content.
1570 *
1571 * @since bbPress (r2625)
1572 *
1573 * @param int $topic_id Optional. Topic id
1574 * @uses bbp_get_topic_id() To get the topic id
1575 * @uses bbp_get_topic_last_reply_url() To get the topic last reply url
1576 * @uses bbp_get_topic_last_reply_title() To get the reply title
1577 * @uses bbp_get_topic_last_active_time() To get the topic freshness
1578 * @uses apply_filters() Calls 'bbp_get_topic_freshness_link' with the
1579 * link and topic id
1580 * @return string Topic freshness link
1581 */
1582 function bbp_get_topic_freshness_link( $topic_id = 0 ) {
1583 $topic_id = bbp_get_topic_id( $topic_id );
1584 $link_url = bbp_get_topic_last_reply_url( $topic_id );
1585 $title = bbp_get_topic_last_reply_title( $topic_id );
1586 $time_since = bbp_get_topic_last_active_time( $topic_id );
1587
1588 if ( !empty( $time_since ) )
1589 $anchor = '<a href="' . $link_url . '" title="' . esc_attr( $title ) . '">' . $time_since . '</a>';
1590 else
1591 $anchor = __( 'No Replies', 'bbpress' );
1592
1593 return apply_filters( 'bbp_get_topic_freshness_link', $anchor, $topic_id );
1594 }
1595
1596 /**
1597 * Output the replies link of the topic
1598 *
1599 * @since bbPress (r2740)
1600 *
1601 * @param int $topic_id Optional. Topic id
1602 * @uses bbp_get_topic_replies_link() To get the topic replies link
1603 */
1604 function bbp_topic_replies_link( $topic_id = 0 ) {
1605 echo bbp_get_topic_replies_link( $topic_id );
1606 }
1607
1608 /**
1609 * Return the replies link of the topic
1610 *
1611 * @since bbPress (r2740)
1612 *
1613 * @param int $topic_id Optional. Topic id
1614 * @uses bbp_get_topic_id() To get the topic id
1615 * @uses bbp_get_topic() To get the topic
1616 * @uses bbp_get_topic_reply_count() To get the topic reply count
1617 * @uses bbp_get_topic_permalink() To get the topic permalink
1618 * @uses remove_query_arg() To remove args from the url
1619 * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden
1620 * reply count
1621 * @uses current_user_can() To check if the current user can edit others
1622 * replies
1623 * @uses add_query_arg() To add custom args to the url
1624 * @uses apply_filters() Calls 'bbp_get_topic_replies_link' with the
1625 * replies link and topic id
1626 */
1627 function bbp_get_topic_replies_link( $topic_id = 0 ) {
1628 global $bbp;
1629
1630 $topic = bbp_get_topic( bbp_get_topic_id( (int) $topic_id ) );
1631 $topic_id = $topic->ID;
1632 $replies = bbp_get_topic_reply_count( $topic_id );
1633 $replies = sprintf( _n( '%s reply', '%s replies', $replies, 'bbpress' ), $replies );
1634 $retval = '';
1635
1636 // First link never has view=all
1637 if ( bbp_get_view_all( 'edit_others_replies' ) )
1638 $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_topic_permalink( $topic_id ) ) ) . "'>$replies</a>";
1639 else
1640 $retval .= $replies;
1641
1642 // This forum has hidden topics
1643 if ( current_user_can( 'edit_others_replies' ) && ( $deleted = bbp_get_topic_reply_count_hidden( $topic_id ) ) ) {
1644
1645 // Extra text
1646 $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted );
1647
1648 // No link
1649 if ( bbp_get_view_all() )
1650 $retval .= " $extra";
1651
1652 // Link
1653 else
1654 $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_topic_permalink( $topic_id ), true ) ) . "'>$extra</a>";
1655 }
1656
1657 return apply_filters( 'bbp_get_topic_replies_link', $retval, $topic_id );
1658 }
1659
1660 /**
1661 * Output total reply count of a topic
1662 *
1663 * @since bbPress (r2485)
1664 *
1665 * @param int $topic_id Optional. Topic id
1666 * @uses bbp_get_topic_reply_count() To get the topic reply count
1667 */
1668 function bbp_topic_reply_count( $topic_id = 0 ) {
1669 echo bbp_get_topic_reply_count( $topic_id );
1670 }
1671 /**
1672 * Return total reply count of a topic
1673 *
1674 * @since bbPress (r2485)
1675 *
1676 * @param int $topic_id Optional. Topic id
1677 * @uses bbp_get_topic_id() To get the topic id
1678 * @uses get_post_meta() To get the topic reply count meta
1679 * @uses apply_filters() Calls 'bbp_get_topic_reply_count' with the
1680 * reply count and topic id
1681 * @return int Reply count
1682 */
1683 function bbp_get_topic_reply_count( $topic_id = 0 ) {
1684 $topic_id = bbp_get_topic_id( $topic_id );
1685 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true );
1686
1687 return apply_filters( 'bbp_get_topic_reply_count', (int) $replies, $topic_id );
1688 }
1689
1690 /**
1691 * Output total post count of a topic
1692 *
1693 * @since bbPress (r2954)
1694 *
1695 * @param int $topic_id Optional. Topic id
1696 * @uses bbp_get_topic_post_count() To get the topic post count
1697 */
1698 function bbp_topic_post_count( $topic_id = 0 ) {
1699 echo bbp_get_topic_post_count( $topic_id );
1700 }
1701 /**
1702 * Return total post count of a topic
1703 *
1704 * @since bbPress (r2954)
1705 *
1706 * @param int $topic_id Optional. Topic id
1707 * @uses bbp_get_topic_id() To get the topic id
1708 * @uses get_post_meta() To get the topic post count meta
1709 * @uses apply_filters() Calls 'bbp_get_topic_post_count' with the
1710 * post count and topic id
1711 * @return int Post count
1712 */
1713 function bbp_get_topic_post_count( $topic_id = 0 ) {
1714 $topic_id = bbp_get_topic_id( $topic_id );
1715 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true );
1716
1717 return apply_filters( 'bbp_get_topic_post_count', (int) $replies + 1, $topic_id );
1718 }
1719
1720 /**
1721 * Output total hidden reply count of a topic (hidden includes trashed and
1722 * spammed replies)
1723 *
1724 * @since bbPress (r2740)
1725 *
1726 * @param int $topic_id Optional. Topic id
1727 * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count
1728 */
1729 function bbp_topic_reply_count_hidden( $topic_id = 0 ) {
1730 echo bbp_get_topic_reply_count_hidden( $topic_id );
1731 }
1732 /**
1733 * Return total hidden reply count of a topic (hidden includes trashed
1734 * and spammed replies)
1735 *
1736 * @since bbPress (r2740)
1737 *
1738 * @param int $topic_id Optional. Topic id
1739 * @uses bbp_get_topic_id() To get the topic id
1740 * @uses get_post_meta() To get the hidden reply count
1741 * @uses apply_filters() Calls 'bbp_get_topic_reply_count_hidden' with
1742 * the hidden reply count and topic id
1743 * @return int Topic hidden reply count
1744 */
1745 function bbp_get_topic_reply_count_hidden( $topic_id = 0 ) {
1746 $topic_id = bbp_get_topic_id( $topic_id );
1747 $replies = get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );
1748
1749 return apply_filters( 'bbp_get_topic_reply_count_hidden', (int) $replies, $topic_id );
1750 }
1751
1752 /**
1753 * Output total voice count of a topic
1754 *
1755 * @since bbPress (r2567)
1756 *
1757 * @param int $topic_id Optional. Topic id
1758 * @uses bbp_get_topic_voice_count() To get the topic voice count
1759 */
1760 function bbp_topic_voice_count( $topic_id = 0 ) {
1761 echo bbp_get_topic_voice_count( $topic_id );
1762 }
1763 /**
1764 * Return total voice count of a topic
1765 *
1766 * @since bbPress (r2567)
1767 *
1768 * @param int $topic_id Optional. Topic id
1769 * @uses bbp_get_topic_id() To get the topic id
1770 * @uses get_post_meta() To get the voice count meta
1771 * @uses apply_filters() Calls 'bbp_get_topic_voice_count' with the
1772 * voice count and topic id
1773 * @return int Voice count of the topic
1774 */
1775 function bbp_get_topic_voice_count( $topic_id = 0 ) {
1776 $topic_id = bbp_get_topic_id( $topic_id );
1777 $voices = get_post_meta( $topic_id, '_bbp_voice_count', true );
1778
1779 return apply_filters( 'bbp_get_topic_voice_count', (int) $voices, $topic_id );
1780 }
1781
1782 /**
1783 * Output a the tags of a topic
1784 *
1785 * @param int $topic_id Optional. Topic id
1786 * @param mixed $args See {@link bbp_get_topic_tag_list()}
1787 * @uses bbp_get_topic_tag_list() To get the topic tag list
1788 */
1789 function bbp_topic_tag_list( $topic_id = 0, $args = '' ) {
1790 echo bbp_get_topic_tag_list( $topic_id, $args );
1791 }
1792 /**
1793 * Return the tags of a topic
1794 *
1795 * @param int $topic_id Optional. Topic id
1796 * @param array $args This function supports these arguments:
1797 * - before: Before the tag list
1798 * - sep: Tag separator
1799 * - after: After the tag list
1800 * @uses bbp_get_topic_id() To get the topic id
1801 * @uses get_the_term_list() To get the tags list
1802 * @return string Tag list of the topic
1803 */
1804 function bbp_get_topic_tag_list( $topic_id = 0, $args = '' ) {
1805
1806 $defaults = array(
1807 'before' => '<div class="bbp-topic-tags"><p>' . __( 'Tagged:', 'bbpress' ) . '&nbsp;',
1808 'sep' => ', ',
1809 'after' => '</p></div>'
1810 );
1811
1812 $r = wp_parse_args( $args, $defaults );
1813 extract( $r );
1814
1815 $topic_id = bbp_get_topic_id( $topic_id );
1816
1817 return get_the_term_list( $topic_id, bbp_get_topic_tag_tax_id(), $before, $sep, $after );
1818 }
1819
1820 /**
1821 * Output the row class of a topic
1822 *
1823 * @since bbPress (r2667)
1824 *
1825 * @param int $topic_id Optional. Topic id
1826 * @uses bbp_get_topic_class() To get the topic class
1827 */
1828 function bbp_topic_class( $topic_id = 0 ) {
1829 echo bbp_get_topic_class( $topic_id );
1830 }
1831 /**
1832 * Return the row class of a topic
1833 *
1834 * @since bbPress (r2667)
1835 *
1836 * @param int $topic_id Optional. Topic id
1837 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
1838 * @uses bbp_is_topic_super_sticky() To check if the topic is a super
1839 * sticky
1840 * @uses post_class() To get the topic classes
1841 * @uses apply_filters() Calls 'bbp_get_topic_class' with the classes
1842 * and topic id
1843 * @return string Row class of a topic
1844 */
1845 function bbp_get_topic_class( $topic_id = 0 ) {
1846 global $bbp;
1847
1848 $classes = array();
1849 $classes[] = $bbp->topic_query->current_post % 2 ? 'even' : 'odd';
1850 $classes[] = bbp_is_topic_sticky( $topic_id, false ) ? 'sticky' : '';
1851 $classes[] = bbp_is_topic_super_sticky( $topic_id ) ? 'super-sticky' : '';
1852 $classes = array_filter( $classes );
1853 $post = post_class( $classes, $topic_id );
1854
1855 return apply_filters( 'bbp_get_topic_class', $post, $topic_id );
1856 }
1857
1858 /** Topic Admin Links *********************************************************/
1859
1860 /**
1861 * Output admin links for topic
1862 *
1863 * @param mixed $args See {@link bbp_get_topic_admin_links()}
1864 * @uses bbp_get_topic_admin_links() To get the topic admin links
1865 */
1866 function bbp_topic_admin_links( $args = '' ) {
1867 echo bbp_get_topic_admin_links( $args );
1868 }
1869 /**
1870 * Return admin links for topic.
1871 *
1872 * Move topic functionality is handled by the edit topic page.
1873 *
1874 * @param mixed $args This function supports these arguments:
1875 * - id: Optional. Topic id
1876 * - before: Before the links
1877 * - after: After the links
1878 * - sep: Links separator
1879 * - links: Topic admin links array
1880 * @uses current_user_can() To check if the current user can edit/delete
1881 * the topic
1882 * @uses bbp_get_topic_edit_link() To get the topic edit link
1883 * @uses bbp_get_topic_trash_link() To get the topic trash link
1884 * @uses bbp_get_topic_close_link() To get the topic close link
1885 * @uses bbp_get_topic_spam_link() To get the topic spam link
1886 * @uses bbp_get_topic_stick_link() To get the topic stick link
1887 * @uses bbp_get_topic_merge_link() To get the topic merge link
1888 * @uses bbp_get_topic_status() To get the topic status
1889 * @uses apply_filters() Calls 'bbp_get_topic_admin_links' with the
1890 * topic admin links and args
1891 * @return string Topic admin links
1892 */
1893 function bbp_get_topic_admin_links( $args = '' ) {
1894 global $bbp;
1895
1896 if ( !bbp_is_single_topic() )
1897 return;
1898
1899 $defaults = array (
1900 'id' => bbp_get_topic_id(),
1901 'before' => '<span class="bbp-admin-links">',
1902 'after' => '</span>',
1903 'sep' => ' | ',
1904 'links' => array()
1905 );
1906
1907 $r = wp_parse_args( $args, $defaults );
1908
1909 if ( !current_user_can( 'edit_topic', $r['id'] ) )
1910 return;
1911
1912 if ( empty( $r['links'] ) ) {
1913 $r['links'] = array(
1914 'edit' => bbp_get_topic_edit_link ( $r ),
1915 'close' => bbp_get_topic_close_link( $r ),
1916 'stick' => bbp_get_topic_stick_link( $r ),
1917 'merge' => bbp_get_topic_merge_link( $r ),
1918 'trash' => bbp_get_topic_trash_link( $r ),
1919 'spam' => bbp_get_topic_spam_link ( $r ),
1920 );
1921 }
1922
1923 // Check caps for trashing the topic
1924 if ( !current_user_can( 'delete_topic', $r['id'] ) && !empty( $r['links']['trash'] ) )
1925 unset( $r['links']['trash'] );
1926
1927 // See if links need to be unset
1928 $topic_status = bbp_get_topic_status( $r['id'] );
1929 if ( in_array( $topic_status, array( $bbp->spam_status_id, $bbp->trash_status_id ) ) ) {
1930
1931 // Close link shouldn't be visible on trashed/spammed topics
1932 unset( $r['links']['close'] );
1933
1934 // Spam link shouldn't be visible on trashed topics
1935 if ( $topic_status == $bbp->trash_status_id )
1936 unset( $r['links']['spam'] );
1937
1938 // Trash link shouldn't be visible on spam topics
1939 elseif ( $topic_status == $bbp->spam_status_id )
1940 unset( $r['links']['trash'] );
1941 }
1942
1943 // Process the admin links
1944 $links = implode( $r['sep'], array_filter( $r['links'] ) );
1945
1946 return apply_filters( 'bbp_get_topic_admin_links', $r['before'] . $links . $r['after'], $args );
1947 }
1948
1949 /**
1950 * Output the edit link of the topic
1951 *
1952 * @since bbPress (r2727)
1953 *
1954 * @param mixed $args See {@link bbp_get_topic_edit_link()}
1955 * @uses bbp_get_topic_edit_link() To get the topic edit link
1956 */
1957 function bbp_topic_edit_link( $args = '' ) {
1958 echo bbp_get_topic_edit_link( $args );
1959 }
1960
1961 /**
1962 * Return the edit link of the topic
1963 *
1964 * @since bbPress (r2727)
1965 *
1966 * @param mixed $args This function supports these args:
1967 * - id: Optional. Topic id
1968 * - link_before: Before the link
1969 * - link_after: After the link
1970 * - edit_text: Edit text
1971 * @uses bbp_get_topic_id() To get the topic id
1972 * @uses bbp_get_topic() To get the topic
1973 * @uses current_user_can() To check if the current user can edit the
1974 * topic
1975 * @uses bbp_get_topic_edit_url() To get the topic edit url
1976 * @uses apply_filters() Calls 'bbp_get_topic_edit_link' with the link
1977 * and args
1978 * @return string Topic edit link
1979 */
1980 function bbp_get_topic_edit_link( $args = '' ) {
1981 $defaults = array (
1982 'id' => 0,
1983 'link_before' => '',
1984 'link_after' => '',
1985 'edit_text' => __( 'Edit', 'bbpress' )
1986 );
1987
1988 $r = wp_parse_args( $args, $defaults );
1989 extract( $r );
1990
1991 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
1992
1993 // Bypass check if user has caps
1994 if ( !current_user_can( 'edit_others_topics' ) ) {
1995
1996 // User cannot edit or it is past the lock time
1997 if ( empty( $topic ) || !current_user_can( 'edit_topic', $topic->ID ) || bbp_past_edit_lock( $topic->post_date_gmt ) )
1998 return;
1999 }
2000
2001 // No uri to edit topic
2002 if ( !$uri = bbp_get_topic_edit_url( $id ) )
2003 return;
2004
2005 return apply_filters( 'bbp_get_topic_edit_link', $link_before . '<a href="' . $uri . '">' . $edit_text . '</a>' . $link_after, $args );
2006 }
2007
2008 /**
2009 * Output URL to the topic edit page
2010 *
2011 * @since bbPress (r2753)
2012 *
2013 * @param int $topic_id Optional. Topic id
2014 * @uses bbp_get_topic_edit_url() To get the topic edit url
2015 */
2016 function bbp_topic_edit_url( $topic_id = 0 ) {
2017 echo bbp_get_topic_edit_url( $topic_id );
2018 }
2019 /**
2020 * Return URL to the topic edit page
2021 *
2022 * @since bbPress (r2753)
2023 *
2024 * @param int $topic_id Optional. Topic id
2025 * @uses bbp_get_topic_id() To get the topic id
2026 * @uses bbp_get_topic() To get the topic
2027 * @uses add_query_arg() To add custom args to the url
2028 * @uses home_url() To get the home url
2029 * @uses apply_filters() Calls 'bbp_get_topic_edit_url' with the edit
2030 * url and topic id
2031 * @return string Topic edit url
2032 */
2033 function bbp_get_topic_edit_url( $topic_id = 0 ) {
2034 global $wp_rewrite, $bbp;
2035
2036 if ( !$topic = bbp_get_topic( bbp_get_topic_id( $topic_id ) ) )
2037 return;
2038
2039 // Pretty permalinks
2040 if ( $wp_rewrite->using_permalinks() ) {
2041 $url = $wp_rewrite->root . $bbp->topic_slug . '/' . $topic->post_name . '/edit';
2042 $url = home_url( user_trailingslashit( $url ) );
2043
2044 // Unpretty permalinks
2045 } else {
2046 $url = add_query_arg( array( bbp_get_topic_post_type() => $topic->post_name, 'edit' => '1' ), home_url( '/' ) );
2047 }
2048
2049 return apply_filters( 'bbp_get_topic_edit_url', $url, $topic_id );
2050 }
2051
2052 /**
2053 * Output the trash link of the topic
2054 *
2055 * @since bbPress (r2727)
2056 *
2057 * @param mixed $args See {@link bbp_get_topic_trash_link()}
2058 * @uses bbp_get_topic_trash_link() To get the topic trash link
2059 */
2060 function bbp_topic_trash_link( $args = '' ) {
2061 echo bbp_get_topic_trash_link( $args );
2062 }
2063
2064 /**
2065 * Return the trash link of the topic
2066 *
2067 * @since bbPress (r2727)
2068 *
2069 * @param mixed $args This function supports these args:
2070 * - id: Optional. Topic id
2071 * - link_before: Before the link
2072 * - link_after: After the link
2073 * - sep: Links separator
2074 * - trash_text: Trash text
2075 * - restore_text: Restore text
2076 * - delete_text: Delete text
2077 * @uses bbp_get_topic_id() To get the topic id
2078 * @uses bbp_get_topic() To get the topic
2079 * @uses current_user_can() To check if the current user can delete the
2080 * topic
2081 * @uses bbp_is_topic_trash() To check if the topic is trashed
2082 * @uses bbp_get_topic_status() To get the topic status
2083 * @uses add_query_arg() To add custom args to the url
2084 * @uses wp_nonce_url() To nonce the url
2085 * @uses esc_url() To escape the url
2086 * @uses apply_filters() Calls 'bbp_get_topic_trash_link' with the link
2087 * and args
2088 * @return string Topic trash link
2089 */
2090 function bbp_get_topic_trash_link( $args = '' ) {
2091 global $bbp;
2092
2093 $defaults = array (
2094 'id' => 0,
2095 'link_before' => '',
2096 'link_after' => '',
2097 'sep' => ' | ',
2098 'trash_text' => __( 'Trash', 'bbpress' ),
2099 'restore_text' => __( 'Restore', 'bbpress' ),
2100 'delete_text' => __( 'Delete', 'bbpress' )
2101 );
2102 $r = wp_parse_args( $args, $defaults );
2103 extract( $r );
2104
2105 $actions = array();
2106 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2107
2108 if ( empty( $topic ) || !current_user_can( 'delete_topic', $topic->ID ) ) {
2109 return;
2110 }
2111
2112 if ( bbp_is_topic_trash( $topic->ID ) ) {
2113 $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>';
2114 } elseif ( EMPTY_TRASH_DAYS ) {
2115 $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>';
2116 }
2117
2118 if ( bbp_is_topic_trash( $topic->ID ) || !EMPTY_TRASH_DAYS ) {
2119 $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>';
2120 }
2121
2122 // Process the admin links
2123 $actions = implode( $sep, $actions );
2124
2125 return apply_filters( 'bbp_get_topic_trash_link', $link_before . $actions . $link_after, $args );
2126 }
2127
2128 /**
2129 * Output the close link of the topic
2130 *
2131 * @since bbPress (r2727)
2132 *
2133 * @param mixed $args See {@link bbp_get_topic_close_link()}
2134 * @uses bbp_get_topic_close_link() To get the topic close link
2135 */
2136 function bbp_topic_close_link( $args = '' ) {
2137 echo bbp_get_topic_close_link( $args );
2138 }
2139
2140 /**
2141 * Return the close 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 * - close_text: Close text
2150 * - open_text: Open text
2151 * @uses bbp_get_topic_id() To get the topic id
2152 * @uses bbp_get_topic() To get the topic
2153 * @uses current_user_can() To check if the current user can edit the
2154 * topic
2155 * @uses bbp_is_topic_open() To check if the topic is open
2156 * @uses add_query_arg() To add custom args to the url
2157 * @uses wp_nonce_url() To nonce the url
2158 * @uses esc_url() To escape the url
2159 * @uses apply_filters() Calls 'bbp_get_topic_close_link' with the link
2160 * and args
2161 * @return string Topic close link
2162 */
2163 function bbp_get_topic_close_link( $args = '' ) {
2164 $defaults = array (
2165 'id' => 0,
2166 'link_before' => '',
2167 'link_after' => '',
2168 'sep' => ' | ',
2169 'close_text' => __( 'Close', 'bbpress' ),
2170 'open_text' => __( 'Open', 'bbpress' )
2171 );
2172
2173 $r = wp_parse_args( $args, $defaults );
2174 extract( $r );
2175
2176 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2177
2178 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2179 return;
2180
2181 $display = bbp_is_topic_open( $topic->ID ) ? $close_text : $open_text;
2182
2183 $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_close', 'topic_id' => $topic->ID ) );
2184 $uri = esc_url( wp_nonce_url( $uri, 'close-topic_' . $topic->ID ) );
2185
2186 return apply_filters( 'bbp_get_topic_close_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args );
2187 }
2188
2189 /**
2190 * Output the stick link of the topic
2191 *
2192 * @since bbPress (r2754)
2193 *
2194 * @param mixed $args See {@link bbp_get_topic_stick_link()}
2195 * @uses bbp_get_topic_stick_link() To get the topic stick link
2196 */
2197 function bbp_topic_stick_link( $args = '' ) {
2198 echo bbp_get_topic_stick_link( $args );
2199 }
2200
2201 /**
2202 * Return the stick link of the topic
2203 *
2204 * @since bbPress (r2754)
2205 *
2206 * @param mixed $args This function supports these args:
2207 * - id: Optional. Topic id
2208 * - link_before: Before the link
2209 * - link_after: After the link
2210 * - stick_text: Stick text
2211 * - unstick_text: Unstick text
2212 * - super_text: Stick to front text
2213 * @uses bbp_get_topic_id() To get the topic id
2214 * @uses bbp_get_topic() To get the topic
2215 * @uses current_user_can() To check if the current user can edit the
2216 * topic
2217 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
2218 * @uses add_query_arg() To add custom args to the url
2219 * @uses wp_nonce_url() To nonce the url
2220 * @uses esc_url() To escape the url
2221 * @uses apply_filters() Calls 'bbp_get_topic_stick_link' with the link
2222 * and args
2223 * @return string Topic stick link
2224 */
2225 function bbp_get_topic_stick_link( $args = '' ) {
2226 $defaults = array (
2227 'id' => 0,
2228 'link_before' => '',
2229 'link_after' => '',
2230 'stick_text' => __( 'Stick', 'bbpress' ),
2231 'unstick_text' => __( 'Unstick', 'bbpress' ),
2232 'super_text' => __( 'to front', 'bbpress' ),
2233 );
2234
2235 $r = wp_parse_args( $args, $defaults );
2236 extract( $r );
2237
2238 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2239
2240 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2241 return;
2242
2243 $is_sticky = bbp_is_topic_sticky( $topic->ID );
2244
2245 $stick_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID ) );
2246 $stick_uri = esc_url( wp_nonce_url( $stick_uri, 'stick-topic_' . $topic->ID ) );
2247
2248 $stick_display = true == $is_sticky ? $unstick_text : $stick_text;
2249 $stick_display = '<a href="' . $stick_uri . '">' . $stick_display . '</a>';
2250
2251 if ( empty( $is_sticky ) ) {
2252 $super_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID, 'super' => 1 ) );
2253 $super_uri = esc_url( wp_nonce_url( $super_uri, 'stick-topic_' . $topic->ID ) );
2254
2255 $super_display = ' (<a href="' . $super_uri . '">' . $super_text . '</a>)';
2256 } else {
2257 $super_display = '';
2258 }
2259
2260 return apply_filters( 'bbp_get_topic_stick_link', $link_before . $stick_display . $super_display . $link_after, $args );
2261 }
2262
2263 /**
2264 * Output the merge link of the topic
2265 *
2266 * @since bbPress (r2756)
2267 *
2268 * @param mixed $args
2269 * @uses bbp_get_topic_merge_link() To get the topic merge link
2270 */
2271 function bbp_topic_merge_link( $args = '' ) {
2272 echo bbp_get_topic_merge_link( $args );
2273 }
2274
2275 /**
2276 * Return the merge link of the topic
2277 *
2278 * @since bbPress (r2756)
2279 *
2280 * @param mixed $args This function supports these args:
2281 * - id: Optional. Topic id
2282 * - link_before: Before the link
2283 * - link_after: After the link
2284 * - merge_text: Merge text
2285 * @uses bbp_get_topic_id() To get the topic id
2286 * @uses bbp_get_topic() To get the topic
2287 * @uses bbp_get_topic_edit_url() To get the topic edit url
2288 * @uses add_query_arg() To add custom args to the url
2289 * @uses esc_url() To escape the url
2290 * @uses apply_filters() Calls 'bbp_get_topic_merge_link' with the link
2291 * and args
2292 * @return string Topic merge link
2293 */
2294 function bbp_get_topic_merge_link( $args = '' ) {
2295 $defaults = array (
2296 'id' => 0,
2297 'link_before' => '',
2298 'link_after' => '',
2299 'merge_text' => __( 'Merge', 'bbpress' ),
2300 );
2301
2302 $r = wp_parse_args( $args, $defaults );
2303 extract( $r );
2304
2305 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2306
2307 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2308 return;
2309
2310 $uri = esc_url( add_query_arg( array( 'action' => 'merge' ), bbp_get_topic_edit_url( $topic->ID ) ) );
2311
2312 return apply_filters( 'bbp_get_topic_merge_link', $link_before . '<a href="' . $uri . '">' . $merge_text . '</a>' . $link_after, $args );
2313 }
2314
2315 /**
2316 * Output the spam link of the topic
2317 *
2318 * @since bbPress (r2727)
2319 *
2320 * @param mixed $args See {@link bbp_get_topic_spam_link()}
2321 * @uses bbp_get_topic_spam_link() Topic spam link
2322 */
2323 function bbp_topic_spam_link( $args = '' ) {
2324 echo bbp_get_topic_spam_link( $args );
2325 }
2326
2327 /**
2328 * Return the spam link of the topic
2329 *
2330 * @since bbPress (r2727)
2331 *
2332 * @param mixed $args This function supports these args:
2333 * - id: Optional. Topic id
2334 * - link_before: Before the link
2335 * - link_after: After the link
2336 * - spam_text: Spam text
2337 * - unspam_text: Unspam text
2338 * @uses bbp_get_topic_id() To get the topic id
2339 * @uses bbp_get_topic() To get the topic
2340 * @uses current_user_can() To check if the current user can edit the
2341 * topic
2342 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
2343 * @uses add_query_arg() To add custom args to the url
2344 * @uses wp_nonce_url() To nonce the url
2345 * @uses esc_url() To escape the url
2346 * @uses apply_filters() Calls 'bbp_get_topic_spam_link' with the link
2347 * and args
2348 * @return string Topic spam link
2349 */
2350 function bbp_get_topic_spam_link( $args = '' ) {
2351 $defaults = array (
2352 'id' => 0,
2353 'link_before' => '',
2354 'link_after' => '',
2355 'sep' => ' | ',
2356 'spam_text' => __( 'Spam', 'bbpress' ),
2357 'unspam_text' => __( 'Unspam', 'bbpress' )
2358 );
2359
2360 $r = wp_parse_args( $args, $defaults );
2361 extract( $r );
2362
2363 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2364
2365 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2366 return;
2367
2368 $display = bbp_is_topic_spam( $topic->ID ) ? $unspam_text : $spam_text;
2369
2370 $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_spam', 'topic_id' => $topic->ID ) );
2371 $uri = esc_url( wp_nonce_url( $uri, 'spam-topic_' . $topic->ID ) );
2372
2373 return apply_filters( 'bbp_get_topic_spam_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args );
2374 }
2375
2376 /** Topic Pagination **********************************************************/
2377
2378 /**
2379 * Output the pagination count
2380 *
2381 * @since bbPress (r2519)
2382 *
2383 * @uses bbp_get_forum_pagination_count() To get the forum pagination count
2384 */
2385 function bbp_forum_pagination_count() {
2386 echo bbp_get_forum_pagination_count();
2387 }
2388 /**
2389 * Return the pagination count
2390 *
2391 * @since bbPress (r2519)
2392 *
2393 * @uses bbp_number_format() To format the number value
2394 * @uses apply_filters() Calls 'bbp_get_forum_pagination_count' with the
2395 * pagination count
2396 * @return string Forum Pagintion count
2397 */
2398 function bbp_get_forum_pagination_count() {
2399 global $bbp;
2400
2401 if ( empty( $bbp->topic_query ) )
2402 return false;
2403
2404 // Set pagination values
2405 $start_num = intval( ( $bbp->topic_query->paged - 1 ) * $bbp->topic_query->posts_per_page ) + 1;
2406 $from_num = bbp_number_format( $start_num );
2407 $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 ) );
2408 $total = bbp_number_format( !empty( $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $bbp->topic_query->post_count );
2409
2410 // Set return string
2411 if ( $total > 1 && (int) $from_num == (int) $to_num )
2412 $retstr = sprintf( __( 'Viewing topic %1$s (of %2$s total)', 'bbpress' ), $from_num, $total );
2413 elseif ( $total > 1 && empty( $to_num ) )
2414 $retstr = sprintf( __( 'Viewing %1$s topics', 'bbpress' ), $total );
2415 elseif ( $total > 1 && (int) $from_num != (int) $to_num )
2416 $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 );
2417 else
2418 $retstr = sprintf( __( 'Viewing %1$s topic', 'bbpress' ), $total );
2419
2420 // Filter and return
2421 return apply_filters( 'bbp_get_topic_pagination_count', $retstr );
2422 }
2423
2424 /**
2425 * Output pagination links
2426 *
2427 * @since bbPress (r2519)
2428 *
2429 * @uses bbp_get_forum_pagination_links() To get the pagination links
2430 */
2431 function bbp_forum_pagination_links() {
2432 echo bbp_get_forum_pagination_links();
2433 }
2434 /**
2435 * Return pagination links
2436 *
2437 * @since bbPress (r2519)
2438 *
2439 * @uses bbPress::topic_query::pagination_links To get the links
2440 * @return string Pagination links
2441 */
2442 function bbp_get_forum_pagination_links() {
2443 global $bbp;
2444
2445 if ( empty( $bbp->topic_query ) )
2446 return false;
2447
2448 return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links );
2449 }
2450
2451 /**
2452 * Displays topic notices
2453 *
2454 * @since bbPress (r2744)
2455 *
2456 * @uses bbp_is_single_topic() To check if it's a topic page
2457 * @uses bbp_get_topic_status() To get the topic status
2458 * @uses bbp_get_topic_id() To get the topic id
2459 * @uses apply_filters() Calls 'bbp_topic_notices' with the notice text, topic
2460 * status and topic id
2461 * @uses bbPress::errors::add() To add the notices to the error handler
2462 */
2463 function bbp_topic_notices() {
2464 global $bbp;
2465
2466 // Bail if not viewing a topic
2467 if ( !bbp_is_single_topic() )
2468 return;
2469
2470 // Get the topic_status
2471 $topic_status = bbp_get_topic_status();
2472
2473 // Get the topic status
2474 switch ( $topic_status ) {
2475
2476 // Spam notice
2477 case $bbp->spam_status_id :
2478 $notice_text = __( 'This topic is marked as spam.', 'bbpress' );
2479 break;
2480
2481 // Trashed notice
2482 case $bbp->trash_status_id :
2483 $notice_text = __( 'This topic is in the trash.', 'bbpress' );
2484 break;
2485
2486 // Standard status
2487 default :
2488 $notice_text = '';
2489 break;
2490 }
2491
2492 // Filter notice text and bail if empty
2493 if ( !$notice_text = apply_filters( 'bbp_topic_notices', $notice_text, $topic_status, bbp_get_topic_id() ) )
2494 return;
2495
2496 bbp_add_error( 'topic_notice', $notice_text, 'message' );
2497 }
2498
2499 /**
2500 * Displays topic type select box (normal/sticky/super sticky)
2501 *
2502 * @since bbPress (r2784)
2503 *
2504 * @param $args This function supports these arguments:
2505 * - stick_text: Sticky text
2506 * - super_text: Super Sticky text
2507 * - unstick_text: Unstick (normal) text
2508 * - select_id: Select id. Defaults to bbp_stick_topic
2509 * - tab: Tabindex
2510 * - topic_id: Topic id
2511 * @uses bbp_get_topic_id() To get the topic id
2512 * @uses bbp_is_topic_edit() To check if it is the topic edit page
2513 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
2514 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
2515 */
2516 function bbp_topic_type_select( $args = '' ) {
2517
2518 $defaults = array (
2519 'unstick_text' => __( 'Normal', 'bbpress' ),
2520 'stick_text' => __( 'Sticky', 'bbpress' ),
2521 'super_text' => __( 'Super Sticky', 'bbpress' ),
2522 'select_id' => 'bbp_stick_topic',
2523 'tab' => bbp_get_tab_index(),
2524 'topic_id' => 0
2525 );
2526
2527 $r = wp_parse_args( $args, $defaults );
2528 extract( $r );
2529
2530 // Get current topic id
2531 $topic_id = bbp_get_topic_id( $topic_id );
2532
2533 // Edit topic
2534 if ( bbp_is_topic_edit() ) {
2535
2536 // Post value is passed
2537 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$select_id] ) ) {
2538 $sticky_current = $_POST[$select_id];
2539
2540 // Topic is super sticky
2541 } elseif ( bbp_is_topic_super_sticky( $topic_id ) ) {
2542 $sticky_current = 'super';
2543
2544 // Topic is sticky or normal
2545 } else {
2546 $sticky_current = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick';
2547 }
2548
2549 // New topic
2550 } else {
2551
2552 // Post value is passed
2553 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$select_id] ) ) {
2554 $sticky_current = $_POST[$select_id];
2555
2556 // Default to unstick
2557 } else {
2558 $sticky_current = 'unstick';
2559 }
2560 }
2561
2562 // Used variables
2563 $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
2564 $select_id = esc_attr( $select_id );
2565 $sticky_statuses = array (
2566 'unstick' => $unstick_text,
2567 'stick' => $stick_text,
2568 'super' => $super_text,
2569 ); ?>
2570
2571 <select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>"<?php echo $tab; ?>>
2572
2573 <?php foreach ( $sticky_statuses as $sticky_status => $label ) : ?>
2574
2575 <option value="<?php echo $sticky_status; ?>"<?php selected( $sticky_current, $sticky_status ); ?>><?php echo $label; ?></option>
2576
2577 <?php endforeach; ?>
2578
2579 </select>
2580
2581 <?php
2582 }
2583
2584 /** Single Topic **************************************************************/
2585
2586 /**
2587 * Output a fancy description of the current topic, including total topics,
2588 * total replies, and last activity.
2589 *
2590 * @since bbPress (r2860)
2591 *
2592 * @param array $args See {@link bbp_get_single_topic_description()}
2593 * @uses bbp_get_single_topic_description() Return the eventual output
2594 */
2595 function bbp_single_topic_description( $args = '' ) {
2596 echo bbp_get_single_topic_description( $args );
2597 }
2598 /**
2599 * Return a fancy description of the current topic, including total topics,
2600 * total replies, and last activity.
2601 *
2602 * @since bbPress (r2860)
2603 *
2604 * @param mixed $args This function supports these arguments:
2605 * - topic_id: Topic id
2606 * - before: Before the text
2607 * - after: After the text
2608 * - size: Size of the avatar
2609 * @uses bbp_get_topic_id() To get the topic id
2610 * @uses bbp_get_topic_voice_count() To get the topic voice count
2611 * @uses bbp_get_topic_reply_count() To get the topic reply count
2612 * @uses bbp_get_topic_freshness_link() To get the topic freshness link
2613 * @uses bbp_get_topic_last_active_id() To get the topic last active id
2614 * @uses bbp_get_reply_author_link() To get the reply author link
2615 * @uses apply_filters() Calls 'bbp_get_single_topic_description' with
2616 * the description and args
2617 * @return string Filtered topic description
2618 */
2619 function bbp_get_single_topic_description( $args = '' ) {
2620 // Default arguments
2621 $defaults = array (
2622 'topic_id' => 0,
2623 'before' => '<div class="bbp-template-notice info"><p class="post-meta description">',
2624 'after' => '</p></div>',
2625 'size' => 14
2626 );
2627 $r = wp_parse_args( $args, $defaults );
2628 extract( $r );
2629
2630 // Validate topic_id
2631 $topic_id = bbp_get_topic_id( $topic_id );
2632
2633 // Unhook the 'view all' query var adder
2634 remove_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
2635
2636 // Build the topic description
2637 $forum_id = bbp_get_topic_forum_id ( $topic_id );
2638 $voice_count = bbp_get_topic_voice_count ( $topic_id );
2639 $reply_count = bbp_get_topic_replies_link ( $topic_id );
2640 $time_since = bbp_get_topic_freshness_link( $topic_id );
2641
2642 // Singular/Plural
2643 $voice_count = sprintf( _n( '%s voice', '%s voices', $voice_count, 'bbpress' ), $voice_count );
2644
2645 // Topic has replies
2646 if ( $last_reply = bbp_get_topic_last_active_id( $topic_id ) ) {
2647 $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $size ) );
2648 $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 );
2649
2650 // Topic has no replies
2651 } else {
2652 $retstr = sprintf( __( 'This topic has %1$s, contains %2$s.', 'bbpress' ), $voice_count, $reply_count );
2653 }
2654
2655 // Add the 'view all' filter back
2656 add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
2657
2658 // Combine the elements together
2659 $retstr = $before . $retstr . $after;
2660
2661 // Return filtered result
2662 return apply_filters( 'bbp_get_single_topic_description', $retstr, $args );
2663 }
2664
2665 /** Topic Tags ****************************************************************/
2666
2667 /**
2668 * Output the unique id of the topic tag taxonomy
2669 *
2670 * @since bbPress (r3348)
2671 *
2672 * @uses bbp_get_topic_post_type() To get the topic post type
2673 */
2674 function bbp_topic_tag_tax_id() {
2675 echo bbp_get_topic_tag_tax_id();
2676 }
2677 /**
2678 * Return the unique id of the topic tag taxonomy
2679 *
2680 * @since bbPress (r3348)
2681 *
2682 * @uses apply_filters() Calls 'bbp_get_topic_tag_tax_id' with the topic tax id
2683 * @return string The unique topic tag taxonomy
2684 */
2685 function bbp_get_topic_tag_tax_id() {
2686 global $bbp;
2687
2688 return apply_filters( 'bbp_get_topic_tag_tax_id', $bbp->topic_tag_tax_id );
2689 }
2690
2691 /**
2692 * Output the id of the current tag
2693 *
2694 * @since bbPress (r3109)
2695 *
2696 * @uses bbp_get_topic_tag_id()
2697 */
2698 function bbp_topic_tag_id( $tag = '' ) {
2699 echo bbp_get_topic_tag_id( $tag );
2700 }
2701 /**
2702 * Return the id of the current tag
2703 *
2704 * @since bbPress (r3109)
2705 *
2706 * @uses get_term_by()
2707 * @uses get_query_var()
2708 * @uses apply_filters()
2709 *
2710 * @return string Term Name
2711 */
2712 function bbp_get_topic_tag_id( $tag = '' ) {
2713
2714 // Get the term
2715 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2716 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2717
2718 // Add before and after if description exists
2719 if ( !empty( $term->term_id ) )
2720 $retval = $term->term_id;
2721
2722 // No id
2723 else
2724 $retval = '';
2725
2726 return apply_filters( 'bbp_get_topic_tag_id', (int) $retval );
2727 }
2728
2729 /**
2730 * Output the name of the current tag
2731 *
2732 * @since bbPress (r3109)
2733 *
2734 * @uses bbp_get_topic_tag_name()
2735 */
2736 function bbp_topic_tag_name( $tag = '' ) {
2737 echo bbp_get_topic_tag_name( $tag );
2738 }
2739 /**
2740 * Return the name of the current tag
2741 *
2742 * @since bbPress (r3109)
2743 *
2744 * @uses get_term_by()
2745 * @uses get_query_var()
2746 * @uses apply_filters()
2747 *
2748 * @return string Term Name
2749 */
2750 function bbp_get_topic_tag_name( $tag = '' ) {
2751
2752 // Get the term
2753 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2754 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2755
2756 // Add before and after if description exists
2757 if ( !empty( $term->name ) )
2758 $retval = $term->name;
2759
2760 // No name
2761 else
2762 $retval = '';
2763
2764 return apply_filters( 'bbp_get_topic_tag_name', $retval );
2765 }
2766
2767 /**
2768 * Output the slug of the current tag
2769 *
2770 * @since bbPress (r3109)
2771 *
2772 * @uses bbp_get_topic_tag_slug()
2773 */
2774 function bbp_topic_tag_slug( $tag = '' ) {
2775 echo bbp_get_topic_tag_slug( $tag );
2776 }
2777 /**
2778 * Return the slug of the current tag
2779 *
2780 * @since bbPress (r3109)
2781 *
2782 * @uses get_term_by()
2783 * @uses get_query_var()
2784 * @uses apply_filters()
2785 *
2786 * @return string Term Name
2787 */
2788 function bbp_get_topic_tag_slug( $tag = '' ) {
2789
2790 // Get the term
2791 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2792 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2793
2794 // Add before and after if description exists
2795 if ( !empty( $term->slug ) )
2796 $retval = $term->slug;
2797
2798 // No slug
2799 else
2800 $retval = '';
2801
2802 return apply_filters( 'bbp_get_topic_tag_slug', $retval );
2803 }
2804
2805 /**
2806 * Output the link of the current tag
2807 *
2808 * @since bbPress (r3348)
2809 *
2810 * @uses bbp_get_topic_tag_link()
2811 */
2812 function bbp_topic_tag_link( $tag = '' ) {
2813 echo bbp_get_topic_tag_link( $tag );
2814 }
2815 /**
2816 * Return the link of the current tag
2817 *
2818 * @since bbPress (r3348)
2819 *
2820 * @uses get_term_by()
2821 * @uses get_query_var()
2822 * @uses apply_filters()
2823 *
2824 * @return string Term Name
2825 */
2826 function bbp_get_topic_tag_link( $tag = '' ) {
2827
2828 // Get the term
2829 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2830 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2831
2832 // Add before and after if description exists
2833 if ( !empty( $term->term_id ) )
2834 $retval = get_term_link( $term, bbp_get_topic_tag_tax_id() );
2835
2836 // No link
2837 else
2838 $retval = '';
2839
2840 return apply_filters( 'bbp_get_topic_tag_link', $retval );
2841 }
2842
2843 /**
2844 * Output the link of the current tag
2845 *
2846 * @since bbPress (r3348)
2847 *
2848 * @uses bbp_get_topic_tag_edit_link()
2849 */
2850 function bbp_topic_tag_edit_link( $tag = '' ) {
2851 echo bbp_get_topic_tag_edit_link( $tag );
2852 }
2853 /**
2854 * Return the link of the current tag
2855 *
2856 * @since bbPress (r3348)
2857 *
2858 * @uses get_term_by()
2859 * @uses get_query_var()
2860 * @uses apply_filters()
2861 *
2862 * @return string Term Name
2863 */
2864 function bbp_get_topic_tag_edit_link( $tag = '' ) {
2865 global $wp_query;
2866
2867 // Get the term
2868 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2869 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2870
2871 // Add before and after if description exists
2872 if ( !empty( $term->term_id ) ) {
2873
2874 // Pretty
2875 if ( $wp_rewrite->using_permalinks() ) {
2876 $retval = user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . 'edit' );
2877
2878 // Ugly
2879 } else {
2880 $retval = add_query_arg( array( 'paged' => '%#%' ), bbp_get_topic_tag_link() );
2881 }
2882
2883 // No link
2884 } else {
2885 $retval = '';
2886 }
2887
2888 return apply_filters( 'bbp_get_topic_tag_edit_link', $retval );
2889 }
2890
2891 /**
2892 * Output the description of the current tag
2893 *
2894 * @since bbPress (r3109)
2895 *
2896 * @uses bbp_get_topic_tag_description()
2897 */
2898 function bbp_topic_tag_description( $args = array() ) {
2899 echo bbp_get_topic_tag_description( $args );
2900 }
2901 /**
2902 * Return the description of the current tag
2903 *
2904 * @since bbPress (r3109)
2905 *
2906 * @uses get_term_by()
2907 * @uses get_query_var()
2908 * @uses apply_filters()
2909 *
2910 * @return string Term Name
2911 */
2912 function bbp_get_topic_tag_description( $args = array() ) {
2913 global $bbp;
2914
2915 $defaults = array(
2916 'before' => '<div class="bbp-topic-tag-description"><p>',
2917 'after' => '</p></div>',
2918 'tag' => ''
2919 );
2920 $r = wp_parse_args( $args, $defaults );
2921 extract( $r );
2922
2923 // Get the term
2924 $tag = !empty( $tag ) ? $tag : get_query_var( 'term' );
2925 $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
2926
2927 // Add before and after if description exists
2928 if ( !empty( $term->description ) )
2929 $retval = $before . $term->description . $after;
2930
2931 // No description, no HTML
2932 else
2933 $retval = '';
2934
2935 return apply_filters( 'bbp_get_topic_tag_description', $retval, $args );
2936 }
2937
2938 /** Forms *********************************************************************/
2939
2940 /**
2941 * Output the value of topic title field
2942 *
2943 * @since bbPress (r2976)
2944 *
2945 * @uses bbp_get_form_topic_title() To get the value of topic title field
2946 */
2947 function bbp_form_topic_title() {
2948 echo bbp_get_form_topic_title();
2949 }
2950 /**
2951 * Return the value of topic title field
2952 *
2953 * @since bbPress (r2976)
2954 *
2955 * @uses bbp_is_topic_edit() To check if it's topic edit page
2956 * @uses apply_filters() Calls 'bbp_get_form_topic_title' with the title
2957 * @return string Value of topic title field
2958 */
2959 function bbp_get_form_topic_title() {
2960 global $post;
2961
2962 // Get _POST data
2963 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_title'] ) )
2964 $topic_title = $_POST['bbp_topic_title'];
2965
2966 // Get edit data
2967 elseif ( !empty( $post->post_title ) && bbp_is_topic_edit() )
2968 $topic_title = $post->post_title;
2969
2970 // No data
2971 else
2972 $topic_title = '';
2973
2974 return apply_filters( 'bbp_get_form_topic_title', esc_attr( $topic_title ) );
2975 }
2976
2977 /**
2978 * Output the value of topic content field
2979 *
2980 * @since bbPress (r2976)
2981 *
2982 * @uses bbp_get_form_topic_content() To get value of topic content field
2983 */
2984 function bbp_form_topic_content() {
2985 echo bbp_get_form_topic_content();
2986 }
2987 /**
2988 * Return the value of topic content field
2989 *
2990 * @since bbPress (r2976)
2991 *
2992 * @uses bbp_is_topic_edit() To check if it's the topic edit page
2993 * @uses apply_filters() Calls 'bbp_get_form_topic_content' with the content
2994 * @return string Value of topic content field
2995 */
2996 function bbp_get_form_topic_content() {
2997 global $post;
2998
2999 // Get _POST data
3000 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_content'] ) )
3001 $topic_content = $_POST['bbp_topic_content'];
3002
3003 // Get edit data
3004 elseif ( !empty( $post->post_title ) && bbp_is_topic_edit() )
3005 $topic_content = $post->post_content;
3006
3007 // No data
3008 else
3009 $topic_content = '';
3010
3011 return apply_filters( 'bbp_get_form_topic_content', esc_textarea( $topic_content ) );
3012 }
3013
3014 /**
3015 * Output value of topic tags field
3016 *
3017 * @since bbPress (r2976)
3018 * @uses bbp_get_form_topic_tags() To get the value of topic tags field
3019 */
3020 function bbp_form_topic_tags() {
3021 echo bbp_get_form_topic_tags();
3022 }
3023 /**
3024 * Return value of topic tags field
3025 *
3026 * @since bbPress (r2976)
3027 *
3028 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3029 * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags
3030 * @return string Value of topic tags field
3031 */
3032 function bbp_get_form_topic_tags() {
3033 global $post, $bbp;
3034
3035 // Get _POST data
3036 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_tags'] ) ) {
3037 $topic_tags = $_POST['bbp_topic_tags'];
3038
3039 // Get edit data
3040 } elseif ( !empty( $post ) ) {
3041
3042 // Post is a topic
3043 if ( bbp_get_topic_post_type() == $post->post_type )
3044 $topic_id = $post->ID;
3045
3046 // Post is a reply
3047 elseif ( bbp_get_reply_post_type() == $post->post_type )
3048 $topic_id = bbp_get_reply_topic_id( $post->ID );
3049
3050 // Topic exists and has tags
3051 if ( !empty( $topic_id ) && ( $terms = get_the_terms( $topic_id, bbp_get_topic_tag_tax_id() ) ) ) {
3052
3053 // Loop through them
3054 foreach( $terms as $term ) {
3055 $new_terms[] = $term->name;
3056 }
3057
3058 // Define local variable(s)
3059 } else {
3060 $new_terms = '';
3061 }
3062
3063 // Set the return value
3064 $topic_tags = ( !empty( $new_terms ) ) ? implode( ', ', $new_terms ) : '';
3065
3066 // No data
3067 } else {
3068 $topic_tags = '';
3069 }
3070
3071 return apply_filters( 'bbp_get_form_topic_tags', esc_attr( $topic_tags ) );
3072 }
3073
3074 /**
3075 * Output value of topic forum
3076 *
3077 * @since bbPress (r2976)
3078 *
3079 * @uses bbp_get_form_topic_forum() To get the topic's forum id
3080 */
3081 function bbp_form_topic_forum() {
3082 echo bbp_get_form_topic_forum();
3083 }
3084 /**
3085 * Return value of topic forum
3086 *
3087 * @since bbPress (r2976)
3088 *
3089 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3090 * @uses bbp_get_topic_forum_id() To get the topic forum id
3091 * @uses apply_filters() Calls 'bbp_get_form_topic_forum' with the forum
3092 * @return string Value of topic content field
3093 */
3094 function bbp_get_form_topic_forum() {
3095
3096 // Get _POST data
3097 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_id'] ) )
3098 $topic_forum = $_POST['bbp_forum_id'];
3099
3100 // Get edit data
3101 elseif ( bbp_is_topic_edit() )
3102 $topic_forum = bbp_get_topic_forum_id();
3103
3104 // No data
3105 else
3106 $topic_forum = 0;
3107
3108 return apply_filters( 'bbp_get_form_topic_forum', esc_attr( $topic_forum ) );
3109 }
3110
3111 /**
3112 * Output checked value of topic subscription
3113 *
3114 * @since bbPress (r2976)
3115 *
3116 * @uses bbp_get_form_topic_subscribed() To get the subscribed checkbox value
3117 */
3118 function bbp_form_topic_subscribed() {
3119 echo bbp_get_form_topic_subscribed();
3120 }
3121 /**
3122 * Return checked value of topic subscription
3123 *
3124 * @since bbPress (r2976)
3125 *
3126 * @uses bbp_is_topic_edit() To check if it's the topic edit page
3127 * @uses bbp_is_user_subscribed() To check if the user is subscribed to
3128 * the topic
3129 * @uses apply_filters() Calls 'bbp_get_form_topic_subscribed' with the
3130 * option
3131 * @return string Checked value of topic subscription
3132 */
3133 function bbp_get_form_topic_subscribed() {
3134 global $post;
3135
3136 // Get _POST data
3137 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_subscription'] ) ) {
3138 $topic_subscribed = $_POST['bbp_topic_subscription'];
3139
3140 // Get edit data
3141 } elseif ( bbp_is_topic_edit() || bbp_is_reply_edit() ) {
3142
3143 // Post author is not the current user
3144 if ( $post->post_author != bbp_get_current_user_id() ) {
3145 $topic_subscribed = bbp_is_user_subscribed( $post->post_author );
3146
3147 // Post author is the current user
3148 } else {
3149 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() );
3150 }
3151
3152 // Get current status
3153 } elseif ( bbp_is_single_topic() ) {
3154 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() );
3155
3156 // No data
3157 } else {
3158 $topic_subscribed = 0;
3159 }
3160
3161 // Get checked output
3162 $checked = checked( $topic_subscribed, true, false );
3163
3164 return apply_filters( 'bbp_get_form_topic_subscribed', $checked, $topic_subscribed );
3165 }
3166
3167 /**
3168 * Output checked value of topic log edit field
3169 *
3170 * @since bbPress (r2976)
3171 *
3172 * @uses bbp_get_form_topic_log_edit() To get the topic log edit value
3173 */
3174 function bbp_form_topic_log_edit() {
3175 echo bbp_get_form_topic_log_edit();
3176 }
3177 /**
3178 * Return checked value of topic log edit field
3179 *
3180 * @since bbPress (r2976)
3181 *
3182 * @uses apply_filters() Calls 'bbp_get_form_topic_log_edit' with the
3183 * log edit value
3184 * @return string Topic log edit checked value
3185 */
3186 function bbp_get_form_topic_log_edit() {
3187 global $post;
3188
3189 // Get _POST data
3190 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_log_topic_edit'] ) )
3191 $topic_revision = $_POST['bbp_log_topic_edit'];
3192
3193 // No data
3194 else
3195 $topic_revision = 1;
3196
3197 return apply_filters( 'bbp_get_form_topic_log_edit', checked( $topic_revision, true, false ) );
3198 }
3199
3200 /**
3201 * Output the value of the topic edit reason
3202 *
3203 * @since bbPress (r2976)
3204 *
3205 * @uses bbp_get_form_topic_edit_reason() To get the topic edit reason value
3206 */
3207 function bbp_form_topic_edit_reason() {
3208 echo bbp_get_form_topic_edit_reason();
3209 }
3210 /**
3211 * Return the value of the topic edit reason
3212 *
3213 * @since bbPress (r2976)
3214 *
3215 * @uses apply_filters() Calls 'bbp_get_form_topic_edit_reason' with the
3216 * topic edit reason value
3217 * @return string Topic edit reason value
3218 */
3219 function bbp_get_form_topic_edit_reason() {
3220 global $post;
3221
3222 // Get _POST data
3223 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_edit_reason'] ) )
3224 $topic_edit_reason = $_POST['bbp_topic_edit_reason'];
3225
3226 // No data
3227 else
3228 $topic_edit_reason = '';
3229
3230 return apply_filters( 'bbp_get_form_topic_edit_reason', esc_attr( $topic_edit_reason ) );
3231 }
3232
3233 ?>
3234