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

bbp-topic-template.php in bbPress 2.0-beta-3, at bbp-includes/bbp-topic-template.php

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