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

3,105 lines 96.8 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 ( !bbp_is_query_name( 'bbp_widget' ) && bbp_get_view_all() )
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' => ( bbp_get_view_all() ) ? 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 // First link never has view=all
1624 if ( bbp_get_view_all( 'edit_others_replies' ) )
1625 $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_topic_permalink( $topic_id ) ) ) . "'>$replies</a>";
1626 else
1627 $retval .= $replies;
1628
1629 // This forum has hidden topics
1630 if ( current_user_can( 'edit_others_replies' ) && ( $deleted = bbp_get_topic_hidden_reply_count( $topic_id ) ) ) {
1631
1632 // Extra text
1633 $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted );
1634
1635 // No link
1636 if ( bbp_get_view_all() )
1637 $retval .= " $extra";
1638
1639 // Link
1640 else
1641 $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_topic_permalink( $topic_id ), true ) ) . "'>$extra</a>";
1642 }
1643
1644 return apply_filters( 'bbp_get_topic_replies_link', $retval, $topic_id );
1645 }
1646
1647 /**
1648 * Output total reply count of a topic
1649 *
1650 * @since bbPress (r2485)
1651 *
1652 * @param int $topic_id Optional. Topic id
1653 * @uses bbp_get_topic_reply_count() To get the topic reply count
1654 */
1655 function bbp_topic_reply_count( $topic_id = 0 ) {
1656 echo bbp_get_topic_reply_count( $topic_id );
1657 }
1658 /**
1659 * Return total reply count of a topic
1660 *
1661 * @since bbPress (r2485)
1662 *
1663 * @param int $topic_id Optional. Topic id
1664 * @uses bbp_get_topic_id() To get the topic id
1665 * @uses get_post_meta() To get the topic reply count meta
1666 * @uses apply_filters() Calls 'bbp_get_topic_reply_count' with the
1667 * reply count and topic id
1668 * @return int Reply count
1669 */
1670 function bbp_get_topic_reply_count( $topic_id = 0 ) {
1671 $topic_id = bbp_get_topic_id( $topic_id );
1672 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true );
1673
1674 return apply_filters( 'bbp_get_topic_reply_count', (int) $replies, $topic_id );
1675 }
1676
1677 /**
1678 * Output total post count of a topic
1679 *
1680 * @since bbPress (r2954)
1681 *
1682 * @param int $topic_id Optional. Topic id
1683 * @uses bbp_get_topic_post_count() To get the topic post count
1684 */
1685 function bbp_topic_post_count( $topic_id = 0 ) {
1686 echo bbp_get_topic_post_count( $topic_id );
1687 }
1688 /**
1689 * Return total post count of a topic
1690 *
1691 * @since bbPress (r2954)
1692 *
1693 * @param int $topic_id Optional. Topic id
1694 * @uses bbp_get_topic_id() To get the topic id
1695 * @uses get_post_meta() To get the topic post count meta
1696 * @uses apply_filters() Calls 'bbp_get_topic_post_count' with the
1697 * post count and topic id
1698 * @return int Post count
1699 */
1700 function bbp_get_topic_post_count( $topic_id = 0 ) {
1701 $topic_id = bbp_get_topic_id( $topic_id );
1702 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true );
1703
1704 return apply_filters( 'bbp_get_topic_post_count', (int) $replies + 1, $topic_id );
1705 }
1706
1707 /**
1708 * Output total hidden reply count of a topic (hidden includes trashed and
1709 * spammed replies)
1710 *
1711 * @since bbPress (r2740)
1712 *
1713 * @param int $topic_id Optional. Topic id
1714 * @uses bbp_get_topic_hidden_reply_count() To get the topic hidden reply count
1715 */
1716 function bbp_topic_hidden_reply_count( $topic_id = 0 ) {
1717 echo bbp_get_topic_hidden_reply_count( $topic_id );
1718 }
1719 /**
1720 * Return total hidden reply count of a topic (hidden includes trashed
1721 * and spammed replies)
1722 *
1723 * @since bbPress (r2740)
1724 *
1725 * @param int $topic_id Optional. Topic id
1726 * @uses bbp_get_topic_id() To get the topic id
1727 * @uses get_post_meta() To get the hidden reply count
1728 * @uses apply_filters() Calls 'bbp_get_topic_hidden_reply_count' with
1729 * the hidden reply count and topic id
1730 * @return int Topic hidden reply count
1731 */
1732 function bbp_get_topic_hidden_reply_count( $topic_id = 0 ) {
1733 $topic_id = bbp_get_topic_id( $topic_id );
1734 $replies = get_post_meta( $topic_id, '_bbp_hidden_reply_count', true );
1735
1736 return apply_filters( 'bbp_get_topic_hidden_reply_count', (int) $replies, $topic_id );
1737 }
1738
1739 /**
1740 * Output total voice count of a topic
1741 *
1742 * @since bbPress (r2567)
1743 *
1744 * @param int $topic_id Optional. Topic id
1745 * @uses bbp_get_topic_voice_count() To get the topic voice count
1746 */
1747 function bbp_topic_voice_count( $topic_id = 0 ) {
1748 echo bbp_get_topic_voice_count( $topic_id );
1749 }
1750 /**
1751 * Return total voice count of a topic
1752 *
1753 * @since bbPress (r2567)
1754 *
1755 * @param int $topic_id Optional. Topic id
1756 * @uses bbp_get_topic_id() To get the topic id
1757 * @uses get_post_meta() To get the voice count meta
1758 * @uses apply_filters() Calls 'bbp_get_topic_voice_count' with the
1759 * voice count and topic id
1760 * @return int Voice count of the topic
1761 */
1762 function bbp_get_topic_voice_count( $topic_id = 0 ) {
1763 $topic_id = bbp_get_topic_id( $topic_id );
1764 $voices = get_post_meta( $topic_id, '_bbp_voice_count', true );
1765
1766 return apply_filters( 'bbp_get_topic_voice_count', (int) $voices, $topic_id );
1767 }
1768
1769 /**
1770 * Output a the tags of a topic
1771 *
1772 * @param int $topic_id Optional. Topic id
1773 * @param mixed $args See {@link bbp_get_topic_tag_list()}
1774 * @uses bbp_get_topic_tag_list() To get the topic tag list
1775 */
1776 function bbp_topic_tag_list( $topic_id = 0, $args = '' ) {
1777 echo bbp_get_topic_tag_list( $topic_id, $args );
1778 }
1779 /**
1780 * Return the tags of a topic
1781 *
1782 * @param int $topic_id Optional. Topic id
1783 * @param array $args This function supports these arguments:
1784 * - before: Before the tag list
1785 * - sep: Tag separator
1786 * - after: After the tag list
1787 * @uses bbp_get_topic_id() To get the topic id
1788 * @uses get_the_term_list() To get the tags list
1789 * @return string Tag list of the topic
1790 */
1791 function bbp_get_topic_tag_list( $topic_id = 0, $args = '' ) {
1792 global $bbp;
1793
1794 $defaults = array(
1795 'before' => '<div class="bbp-topic-tags"><p>' . __( 'Tagged:', 'bbpress' ) . '&nbsp;',
1796 'sep' => ', ',
1797 'after' => '</p></div>'
1798 );
1799
1800 $r = wp_parse_args( $args, $defaults );
1801 extract( $r );
1802
1803 $topic_id = bbp_get_topic_id( $topic_id );
1804
1805 return get_the_term_list( $topic_id, $bbp->topic_tag_id, $before, $sep, $after );
1806 }
1807
1808 /**
1809 * Output the row class of a topic
1810 *
1811 * @since bbPress (r2667)
1812 *
1813 * @param int $topic_id Optional. Topic id
1814 * @uses bbp_get_topic_class() To get the topic class
1815 */
1816 function bbp_topic_class( $topic_id = 0 ) {
1817 echo bbp_get_topic_class( $topic_id );
1818 }
1819 /**
1820 * Return the row class of a topic
1821 *
1822 * @since bbPress (r2667)
1823 *
1824 * @param int $topic_id Optional. Topic id
1825 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
1826 * @uses bbp_is_topic_super_sticky() To check if the topic is a super
1827 * sticky
1828 * @uses post_class() To get the topic classes
1829 * @uses apply_filters() Calls 'bbp_get_topic_class' with the classes
1830 * and topic id
1831 * @return string Row class of a topic
1832 */
1833 function bbp_get_topic_class( $topic_id = 0 ) {
1834 global $bbp;
1835
1836 $classes = array();
1837 $classes[] = $bbp->topic_query->current_post % 2 ? 'even' : 'odd';
1838 $classes[] = bbp_is_topic_sticky( $topic_id, false ) ? 'sticky' : '';
1839 $classes[] = bbp_is_topic_super_sticky( $topic_id ) ? 'super-sticky' : '';
1840 $classes = array_filter( $classes );
1841 $post = post_class( $classes, $topic_id );
1842
1843 return apply_filters( 'bbp_get_topic_class', $post, $topic_id );
1844 }
1845
1846 /** Topic Admin Links *********************************************************/
1847
1848 /**
1849 * Output admin links for topic
1850 *
1851 * @param mixed $args See {@link bbp_get_topic_admin_links()}
1852 * @uses bbp_get_topic_admin_links() To get the topic admin links
1853 */
1854 function bbp_topic_admin_links( $args = '' ) {
1855 echo bbp_get_topic_admin_links( $args );
1856 }
1857 /**
1858 * Return admin links for topic.
1859 *
1860 * Move topic functionality is handled by the edit topic page.
1861 *
1862 * @param mixed $args This function supports these arguments:
1863 * - id: Optional. Topic id
1864 * - before: Before the links
1865 * - after: After the links
1866 * - sep: Links separator
1867 * - links: Topic admin links array
1868 * @uses bbp_is_topic() To check if it is a topic page
1869 * @uses current_user_can() To check if the current user can edit/delete
1870 * the topic
1871 * @uses bbp_get_topic_edit_link() To get the topic edit link
1872 * @uses bbp_get_topic_trash_link() To get the topic trash link
1873 * @uses bbp_get_topic_close_link() To get the topic close link
1874 * @uses bbp_get_topic_spam_link() To get the topic spam link
1875 * @uses bbp_get_topic_stick_link() To get the topic stick link
1876 * @uses bbp_get_topic_merge_link() To get the topic merge link
1877 * @uses bbp_get_topic_status() To get the topic status
1878 * @uses apply_filters() Calls 'bbp_get_topic_admin_links' with the
1879 * topic admin links and args
1880 * @return string Topic admin links
1881 */
1882 function bbp_get_topic_admin_links( $args = '' ) {
1883 global $bbp;
1884
1885 if ( !bbp_is_topic() )
1886 return;
1887
1888 $defaults = array (
1889 'id' => bbp_get_topic_id(),
1890 'before' => '<span class="bbp-admin-links">',
1891 'after' => '</span>',
1892 'sep' => ' | ',
1893 'links' => array()
1894 );
1895
1896 $r = wp_parse_args( $args, $defaults );
1897
1898 if ( !current_user_can( 'edit_topic', $r['id'] ) )
1899 return;
1900
1901 if ( empty( $r['links'] ) ) {
1902 $r['links'] = array(
1903 'edit' => bbp_get_topic_edit_link ( $r ),
1904 'trash' => bbp_get_topic_trash_link( $r ),
1905 'close' => bbp_get_topic_close_link( $r ),
1906 'stick' => bbp_get_topic_stick_link( $r ),
1907 'merge' => bbp_get_topic_merge_link( $r ),
1908 'spam' => bbp_get_topic_spam_link ( $r ),
1909 );
1910 }
1911
1912 // Check caps for trashing the topic
1913 if ( !current_user_can( 'delete_topic', $r['id'] ) && !empty( $r['links']['trash'] ) )
1914 unset( $r['links']['trash'] );
1915
1916 // See if links need to be unset
1917 $topic_status = bbp_get_topic_status( $r['id'] );
1918 if ( in_array( $topic_status, array( $bbp->spam_status_id, $bbp->trash_status_id ) ) ) {
1919
1920 // Close link shouldn't be visible on trashed/spammed topics
1921 unset( $r['links']['close'] );
1922
1923 // Spam link shouldn't be visible on trashed topics
1924 if ( $topic_status == $bbp->trash_status_id )
1925 unset( $r['links']['spam'] );
1926
1927 // Trash link shouldn't be visible on spam topics
1928 elseif ( $topic_status == $bbp->spam_status_id )
1929 unset( $r['links']['trash'] );
1930 }
1931
1932 // Process the admin links
1933 $links = implode( $r['sep'], array_filter( $r['links'] ) );
1934
1935 return apply_filters( 'bbp_get_topic_admin_links', $r['before'] . $links . $r['after'], $args );
1936 }
1937
1938 /**
1939 * Output the edit link of the topic
1940 *
1941 * @since bbPress (r2727)
1942 *
1943 * @param mixed $args See {@link bbp_get_topic_edit_link()}
1944 * @uses bbp_get_topic_edit_link() To get the topic edit link
1945 */
1946 function bbp_topic_edit_link( $args = '' ) {
1947 echo bbp_get_topic_edit_link( $args );
1948 }
1949
1950 /**
1951 * Return the edit link of the topic
1952 *
1953 * @since bbPress (r2727)
1954 *
1955 * @param mixed $args This function supports these args:
1956 * - id: Optional. Topic id
1957 * - link_before: Before the link
1958 * - link_after: After the link
1959 * - edit_text: Edit text
1960 * @uses bbp_get_topic_id() To get the topic id
1961 * @uses bbp_get_topic() To get the topic
1962 * @uses current_user_can() To check if the current user can edit the
1963 * topic
1964 * @uses bbp_get_topic_edit_url() To get the topic edit url
1965 * @uses apply_filters() Calls 'bbp_get_topic_edit_link' with the link
1966 * and args
1967 * @return string Topic edit link
1968 */
1969 function bbp_get_topic_edit_link( $args = '' ) {
1970 $defaults = array (
1971 'id' => 0,
1972 'link_before' => '',
1973 'link_after' => '',
1974 'edit_text' => __( 'Edit', 'bbpress' )
1975 );
1976
1977 $r = wp_parse_args( $args, $defaults );
1978 extract( $r );
1979
1980 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
1981
1982 // Bypass check if user has caps
1983 if ( !is_super_admin() || !current_user_can( 'edit_others_topics' ) ) {
1984
1985 // User cannot edit or it is past the lock time
1986 if ( empty( $topic ) || !current_user_can( 'edit_topic', $topic->ID ) || bbp_past_edit_lock( $topic->post_date_gmt ) )
1987 return;
1988 }
1989
1990 // No uri to edit topic
1991 if ( !$uri = bbp_get_topic_edit_url( $id ) )
1992 return;
1993
1994 return apply_filters( 'bbp_get_topic_edit_link', $link_before . '<a href="' . $uri . '">' . $edit_text . '</a>' . $link_after, $args );
1995 }
1996
1997 /**
1998 * Output URL to the topic edit page
1999 *
2000 * @since bbPress (r2753)
2001 *
2002 * @param int $topic_id Optional. Topic id
2003 * @uses bbp_get_topic_edit_url() To get the topic edit url
2004 */
2005 function bbp_topic_edit_url( $topic_id = 0 ) {
2006 echo bbp_get_topic_edit_url( $topic_id );
2007 }
2008 /**
2009 * Return URL to the topic edit page
2010 *
2011 * @since bbPress (r2753)
2012 *
2013 * @param int $topic_id Optional. Topic id
2014 * @uses bbp_get_topic_id() To get the topic id
2015 * @uses bbp_get_topic() To get the topic
2016 * @uses add_query_arg() To add custom args to the url
2017 * @uses home_url() To get the home url
2018 * @uses apply_filters() Calls 'bbp_get_topic_edit_url' with the edit
2019 * url and topic id
2020 * @return string Topic edit url
2021 */
2022 function bbp_get_topic_edit_url( $topic_id = 0 ) {
2023 global $wp_rewrite, $bbp;
2024
2025 if ( !$topic = bbp_get_topic( bbp_get_topic_id( $topic_id ) ) )
2026 return;
2027
2028 // Pretty permalinks
2029 if ( $wp_rewrite->using_permalinks() ) {
2030 $url = $wp_rewrite->root . $bbp->topic_slug . '/' . $topic->post_name . '/edit';
2031 $url = home_url( user_trailingslashit( $url ) );
2032
2033 // Unpretty permalinks
2034 } else {
2035 $url = add_query_arg( array( bbp_get_topic_post_type() => $topic->post_name, 'edit' => '1' ), home_url( '/' ) );
2036 }
2037
2038 return apply_filters( 'bbp_get_topic_edit_url', $url, $topic_id );
2039 }
2040
2041 /**
2042 * Output the trash link of the topic
2043 *
2044 * @since bbPress (r2727)
2045 *
2046 * @param mixed $args See {@link bbp_get_topic_trash_link()}
2047 * @uses bbp_get_topic_trash_link() To get the topic trash link
2048 */
2049 function bbp_topic_trash_link( $args = '' ) {
2050 echo bbp_get_topic_trash_link( $args );
2051 }
2052
2053 /**
2054 * Return the trash link of the topic
2055 *
2056 * @since bbPress (r2727)
2057 *
2058 * @param mixed $args This function supports these args:
2059 * - id: Optional. Topic id
2060 * - link_before: Before the link
2061 * - link_after: After the link
2062 * - sep: Links separator
2063 * - trash_text: Trash text
2064 * - restore_text: Restore text
2065 * - delete_text: Delete text
2066 * @uses bbp_get_topic_id() To get the topic id
2067 * @uses bbp_get_topic() To get the topic
2068 * @uses current_user_can() To check if the current user can delete the
2069 * topic
2070 * @uses bbp_is_topic_trash() To check if the topic is trashed
2071 * @uses bbp_get_topic_status() To get the topic status
2072 * @uses add_query_arg() To add custom args to the url
2073 * @uses wp_nonce_url() To nonce the url
2074 * @uses esc_url() To escape the url
2075 * @uses apply_filters() Calls 'bbp_get_topic_trash_link' with the link
2076 * and args
2077 * @return string Topic trash link
2078 */
2079 function bbp_get_topic_trash_link( $args = '' ) {
2080 global $bbp;
2081
2082 $defaults = array (
2083 'id' => 0,
2084 'link_before' => '',
2085 'link_after' => '',
2086 'sep' => ' | ',
2087 'trash_text' => __( 'Trash', 'bbpress' ),
2088 'restore_text' => __( 'Restore', 'bbpress' ),
2089 'delete_text' => __( 'Delete', 'bbpress' )
2090 );
2091 $r = wp_parse_args( $args, $defaults );
2092 extract( $r );
2093
2094 $actions = array();
2095 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2096
2097 if ( empty( $topic ) || !current_user_can( 'delete_topic', $topic->ID ) )
2098 return;
2099
2100 if ( bbp_is_topic_trash( $topic->ID ) )
2101 $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>';
2102 elseif ( EMPTY_TRASH_DAYS )
2103 $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>';
2104
2105 if ( bbp_is_topic_trash( $topic->ID ) || !EMPTY_TRASH_DAYS )
2106 $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>';
2107
2108 // Process the admin links
2109 $actions = implode( $sep, $actions );
2110
2111 return apply_filters( 'bbp_get_topic_trash_link', $link_before . $actions . $link_after, $args );
2112 }
2113
2114 /**
2115 * Output the close link of the topic
2116 *
2117 * @since bbPress (r2727)
2118 *
2119 * @param mixed $args See {@link bbp_get_topic_close_link()}
2120 * @uses bbp_get_topic_close_link() To get the topic close link
2121 */
2122 function bbp_topic_close_link( $args = '' ) {
2123 echo bbp_get_topic_close_link( $args );
2124 }
2125
2126 /**
2127 * Return the close link of the topic
2128 *
2129 * @since bbPress (r2727)
2130 *
2131 * @param mixed $args This function supports these args:
2132 * - id: Optional. Topic id
2133 * - link_before: Before the link
2134 * - link_after: After the link
2135 * - close_text: Close text
2136 * - open_text: Open text
2137 * @uses bbp_get_topic_id() To get the topic id
2138 * @uses bbp_get_topic() To get the topic
2139 * @uses current_user_can() To check if the current user can edit the
2140 * topic
2141 * @uses bbp_is_topic_open() To check if the topic is open
2142 * @uses add_query_arg() To add custom args to the url
2143 * @uses wp_nonce_url() To nonce the url
2144 * @uses esc_url() To escape the url
2145 * @uses apply_filters() Calls 'bbp_get_topic_close_link' with the link
2146 * and args
2147 * @return string Topic close link
2148 */
2149 function bbp_get_topic_close_link( $args = '' ) {
2150 $defaults = array (
2151 'id' => 0,
2152 'link_before' => '',
2153 'link_after' => '',
2154 'sep' => ' | ',
2155 'close_text' => __( 'Close', 'bbpress' ),
2156 'open_text' => __( 'Open', 'bbpress' )
2157 );
2158
2159 $r = wp_parse_args( $args, $defaults );
2160 extract( $r );
2161
2162 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2163
2164 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2165 return;
2166
2167 $display = bbp_is_topic_open( $topic->ID ) ? $close_text : $open_text;
2168
2169 $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_close', 'topic_id' => $topic->ID ) );
2170 $uri = esc_url( wp_nonce_url( $uri, 'close-topic_' . $topic->ID ) );
2171
2172 return apply_filters( 'bbp_get_topic_close_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args );
2173 }
2174
2175 /**
2176 * Output the stick link of the topic
2177 *
2178 * @since bbPress (r2754)
2179 *
2180 * @param mixed $args See {@link bbp_get_topic_stick_link()}
2181 * @uses bbp_get_topic_stick_link() To get the topic stick link
2182 */
2183 function bbp_topic_stick_link( $args = '' ) {
2184 echo bbp_get_topic_stick_link( $args );
2185 }
2186
2187 /**
2188 * Return the stick link of the topic
2189 *
2190 * @since bbPress (r2754)
2191 *
2192 * @param mixed $args This function supports these args:
2193 * - id: Optional. Topic id
2194 * - link_before: Before the link
2195 * - link_after: After the link
2196 * - stick_text: Stick text
2197 * - unstick_text: Unstick text
2198 * - super_text: Stick to front text
2199 * @uses bbp_get_topic_id() To get the topic id
2200 * @uses bbp_get_topic() To get the topic
2201 * @uses current_user_can() To check if the current user can edit the
2202 * topic
2203 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
2204 * @uses add_query_arg() To add custom args to the url
2205 * @uses wp_nonce_url() To nonce the url
2206 * @uses esc_url() To escape the url
2207 * @uses apply_filters() Calls 'bbp_get_topic_stick_link' with the link
2208 * and args
2209 * @return string Topic stick link
2210 */
2211 function bbp_get_topic_stick_link( $args = '' ) {
2212 $defaults = array (
2213 'id' => 0,
2214 'link_before' => '',
2215 'link_after' => '',
2216 'stick_text' => __( 'Stick', 'bbpress' ),
2217 'unstick_text' => __( 'Unstick', 'bbpress' ),
2218 'super_text' => __( 'to front', 'bbpress' ),
2219 );
2220
2221 $r = wp_parse_args( $args, $defaults );
2222 extract( $r );
2223
2224 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2225
2226 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2227 return;
2228
2229 $is_sticky = bbp_is_topic_sticky( $topic->ID );
2230
2231 $stick_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID ) );
2232 $stick_uri = esc_url( wp_nonce_url( $stick_uri, 'stick-topic_' . $topic->ID ) );
2233
2234 $stick_display = true == $is_sticky ? $unstick_text : $stick_text;
2235 $stick_display = '<a href="' . $stick_uri . '">' . $stick_display . '</a>';
2236
2237 if ( empty( $is_sticky ) ) {
2238 $super_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID, 'super' => 1 ) );
2239 $super_uri = esc_url( wp_nonce_url( $super_uri, 'stick-topic_' . $topic->ID ) );
2240
2241 $super_display = ' (<a href="' . $super_uri . '">' . $super_text . '</a>)';
2242 } else {
2243 $super_display = '';
2244 }
2245
2246 return apply_filters( 'bbp_get_topic_stick_link', $link_before . $stick_display . $super_display . $link_after, $args );
2247 }
2248
2249 /**
2250 * Output the merge link of the topic
2251 *
2252 * @since bbPress (r2756)
2253 *
2254 * @param mixed $args
2255 * @uses bbp_get_topic_merge_link() To get the topic merge link
2256 */
2257 function bbp_topic_merge_link( $args = '' ) {
2258 echo bbp_get_topic_merge_link( $args );
2259 }
2260
2261 /**
2262 * Return the merge link of the topic
2263 *
2264 * @since bbPress (r2756)
2265 *
2266 * @param mixed $args This function supports these args:
2267 * - id: Optional. Topic id
2268 * - link_before: Before the link
2269 * - link_after: After the link
2270 * - merge_text: Merge text
2271 * @uses bbp_get_topic_id() To get the topic id
2272 * @uses bbp_get_topic() To get the topic
2273 * @uses bbp_get_topic_edit_url() To get the topic edit url
2274 * @uses add_query_arg() To add custom args to the url
2275 * @uses esc_url() To escape the url
2276 * @uses apply_filters() Calls 'bbp_get_topic_merge_link' with the link
2277 * and args
2278 * @return string Topic merge link
2279 */
2280 function bbp_get_topic_merge_link( $args = '' ) {
2281 $defaults = array (
2282 'id' => 0,
2283 'link_before' => '',
2284 'link_after' => '',
2285 'merge_text' => __( 'Merge', 'bbpress' ),
2286 );
2287
2288 $r = wp_parse_args( $args, $defaults );
2289 extract( $r );
2290
2291 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2292
2293 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2294 return;
2295
2296 $uri = esc_url( add_query_arg( array( 'action' => 'merge' ), bbp_get_topic_edit_url( $topic->ID ) ) );
2297
2298 return apply_filters( 'bbp_get_topic_merge_link', $link_before . '<a href="' . $uri . '">' . $merge_text . '</a>' . $link_after, $args );
2299 }
2300
2301 /**
2302 * Output the spam link of the topic
2303 *
2304 * @since bbPress (r2727)
2305 *
2306 * @param mixed $args See {@link bbp_get_topic_spam_link()}
2307 * @uses bbp_get_topic_spam_link() Topic spam link
2308 */
2309 function bbp_topic_spam_link( $args = '' ) {
2310 echo bbp_get_topic_spam_link( $args );
2311 }
2312
2313 /**
2314 * Return the spam link of the topic
2315 *
2316 * @since bbPress (r2727)
2317 *
2318 * @param mixed $args This function supports these args:
2319 * - id: Optional. Topic id
2320 * - link_before: Before the link
2321 * - link_after: After the link
2322 * - spam_text: Spam text
2323 * - unspam_text: Unspam text
2324 * @uses bbp_get_topic_id() To get the topic id
2325 * @uses bbp_get_topic() To get the topic
2326 * @uses current_user_can() To check if the current user can edit the
2327 * topic
2328 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
2329 * @uses add_query_arg() To add custom args to the url
2330 * @uses wp_nonce_url() To nonce the url
2331 * @uses esc_url() To escape the url
2332 * @uses apply_filters() Calls 'bbp_get_topic_spam_link' with the link
2333 * and args
2334 * @return string Topic spam link
2335 */
2336 function bbp_get_topic_spam_link( $args = '' ) {
2337 $defaults = array (
2338 'id' => 0,
2339 'link_before' => '',
2340 'link_after' => '',
2341 'sep' => ' | ',
2342 'spam_text' => __( 'Spam', 'bbpress' ),
2343 'unspam_text' => __( 'Unspam', 'bbpress' )
2344 );
2345
2346 $r = wp_parse_args( $args, $defaults );
2347 extract( $r );
2348
2349 $topic = bbp_get_topic( bbp_get_topic_id( (int) $id ) );
2350
2351 if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
2352 return;
2353
2354 $display = bbp_is_topic_spam( $topic->ID ) ? $unspam_text : $spam_text;
2355
2356 $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_spam', 'topic_id' => $topic->ID ) );
2357 $uri = esc_url( wp_nonce_url( $uri, 'spam-topic_' . $topic->ID ) );
2358
2359 return apply_filters( 'bbp_get_topic_spam_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args );
2360 }
2361
2362 /** Topic Pagination **********************************************************/
2363
2364 /**
2365 * Output the pagination count
2366 *
2367 * @since bbPress (r2519)
2368 *
2369 * @uses bbp_get_forum_pagination_count() To get the forum pagination count
2370 */
2371 function bbp_forum_pagination_count() {
2372 echo bbp_get_forum_pagination_count();
2373 }
2374 /**
2375 * Return the pagination count
2376 *
2377 * @since bbPress (r2519)
2378 *
2379 * @uses bbp_number_format() To format the number value
2380 * @uses apply_filters() Calls 'bbp_get_forum_pagination_count' with the
2381 * pagination count
2382 * @return string Forum Pagintion count
2383 */
2384 function bbp_get_forum_pagination_count() {
2385 global $bbp;
2386
2387 if ( !isset( $bbp->topic_query ) )
2388 return false;
2389
2390 // Set pagination values
2391 $start_num = intval( ( $bbp->topic_query->paged - 1 ) * $bbp->topic_query->posts_per_page ) + 1;
2392 $from_num = bbp_number_format( $start_num );
2393 $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 ) );
2394 $total = bbp_number_format( !empty( $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $bbp->topic_query->post_count );
2395
2396 // Set return string
2397 if ( $total > 1 && (int) $from_num == (int) $to_num )
2398 $retstr = sprintf( __( 'Viewing topic %1$s (of %2$s total)', 'bbpress' ), $from_num, $total );
2399 elseif ( $total > 1 && empty( $to_num ) )
2400 $retstr = sprintf( __( 'Viewing %1$s topics', 'bbpress' ), $total );
2401 elseif ( $total > 1 && (int) $from_num != (int) $to_num )
2402 $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 );
2403 else
2404 $retstr = sprintf( __( 'Viewing %1$s topic', 'bbpress' ), $total );
2405
2406 // Filter and return
2407 return apply_filters( 'bbp_get_topic_pagination_count', $retstr );
2408 }
2409
2410 /**
2411 * Output pagination links
2412 *
2413 * @since bbPress (r2519)
2414 *
2415 * @uses bbp_get_forum_pagination_links() To get the pagination links
2416 */
2417 function bbp_forum_pagination_links() {
2418 echo bbp_get_forum_pagination_links();
2419 }
2420 /**
2421 * Return pagination links
2422 *
2423 * @since bbPress (r2519)
2424 *
2425 * @uses bbPress::topic_query::pagination_links To get the links
2426 * @return string Pagination links
2427 */
2428 function bbp_get_forum_pagination_links() {
2429 global $bbp;
2430
2431 if ( !isset( $bbp->topic_query ) )
2432 return false;
2433
2434 return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links );
2435 }
2436
2437 /**
2438 * Displays topic notices
2439 *
2440 * @since bbPress (r2744)
2441 *
2442 * @uses bbp_is_topic() To check if it's a topic page
2443 * @uses bbp_get_topic_status() To get the topic status
2444 * @uses bbp_get_topic_id() To get the topic id
2445 * @uses apply_filters() Calls 'bbp_topic_notices' with the notice text, topic
2446 * status and topic id
2447 * @uses bbPress::errors::add() To add the notices to the error handler
2448 */
2449 function bbp_topic_notices() {
2450 global $bbp;
2451
2452 // Bail if not viewing a topic
2453 if ( !bbp_is_topic() )
2454 return;
2455
2456 // Get the topic_status
2457 $topic_status = bbp_get_topic_status();
2458
2459 // Get the topic status
2460 switch ( $topic_status ) {
2461
2462 // Spam notice
2463 case $bbp->spam_status_id :
2464 $notice_text = __( 'This topic is marked as spam.', 'bbpress' );
2465 break;
2466
2467 // Trashed notice
2468 case $bbp->trash_status_id :
2469 $notice_text = __( 'This topic is in the trash.', 'bbpress' );
2470 break;
2471
2472 // Standard status
2473 default :
2474 $notice_text = '';
2475 break;
2476 }
2477
2478 // Filter notice text and bail if empty
2479 if ( !$notice_text = apply_filters( 'bbp_topic_notices', $notice_text, $topic_status, bbp_get_topic_id() ) )
2480 return;
2481
2482 $bbp->errors->add( 'topic_notice', $notice_text, 'message' );
2483 }
2484
2485 /**
2486 * Displays topic type select box (normal/sticky/super sticky)
2487 *
2488 * @since bbPress (r2784)
2489 *
2490 * @param $args This function supports these arguments:
2491 * - stick_text: Sticky text
2492 * - super_text: Super Sticky text
2493 * - unstick_text: Unstick (normal) text
2494 * - select_id: Select id. Defaults to bbp_stick_topic
2495 * - tab: Tabindex
2496 * - topic_id: Topic id
2497 * @uses bbp_get_topic_id() To get the topic id
2498 * @uses bbp_is_topic_edit() To check if it is the topic edit page
2499 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
2500 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
2501 */
2502 function bbp_topic_type_select( $args = '' ) {
2503
2504 $defaults = array (
2505 'unstick_text' => __( 'Normal', 'bbpress' ),
2506 'stick_text' => __( 'Sticky', 'bbpress' ),
2507 'super_text' => __( 'Super Sticky', 'bbpress' ),
2508 'select_id' => 'bbp_stick_topic',
2509 'tab' => bbp_get_tab_index(),
2510 'topic_id' => 0
2511 );
2512
2513 $r = wp_parse_args( $args, $defaults );
2514 extract( $r );
2515
2516 // Get current topic id
2517 $topic_id = bbp_get_topic_id( $topic_id );
2518
2519 // Edit topic
2520 if ( bbp_is_topic_edit() ) {
2521
2522 // Post value is passed
2523 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$select_id] ) ) {
2524 $sticky_current = $_POST[$select_id];
2525
2526 // Topic is super sticky
2527 } elseif ( bbp_is_topic_super_sticky( $topic_id ) ) {
2528 $sticky_current = 'super';
2529
2530 // Topic is sticky or normal
2531 } else {
2532 $sticky_current = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick';
2533 }
2534
2535 // New topic
2536 } else {
2537
2538 // Post value is passed
2539 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$select_id] ) ) {
2540 $sticky_current = $_POST[$select_id];
2541
2542 // Default to unstick
2543 } else {
2544 $sticky_current = 'unstick';
2545 }
2546 }
2547
2548 // Used variables
2549 $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
2550 $select_id = esc_attr( $select_id );
2551 $sticky_statuses = array (
2552 'unstick' => $unstick_text,
2553 'stick' => $stick_text,
2554 'super' => $super_text,
2555 ); ?>
2556
2557 <select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>"<?php echo $tab; ?>>
2558
2559 <?php foreach ( $sticky_statuses as $sticky_status => $label ) : ?>
2560
2561 <option value="<?php echo $sticky_status; ?>"<?php selected( $sticky_current, $sticky_status ); ?>><?php echo $label; ?></option>
2562
2563 <?php endforeach; ?>
2564
2565 </select>
2566
2567 <?php
2568 }
2569
2570 /** Single Topic **************************************************************/
2571
2572 /**
2573 * Output a fancy description of the current topic, including total topics,
2574 * total replies, and last activity.
2575 *
2576 * @since bbPress (r2860)
2577 *
2578 * @param array $args See {@link bbp_get_single_topic_description()}
2579 * @uses bbp_get_single_topic_description() Return the eventual output
2580 */
2581 function bbp_single_topic_description( $args = '' ) {
2582 echo bbp_get_single_topic_description( $args );
2583 }
2584 /**
2585 * Return a fancy description of the current topic, including total topics,
2586 * total replies, and last activity.
2587 *
2588 * @since bbPress (r2860)
2589 *
2590 * @param mixed $args This function supports these arguments:
2591 * - topic_id: Topic id
2592 * - before: Before the text
2593 * - after: After the text
2594 * - size: Size of the avatar
2595 * @uses bbp_get_topic_id() To get the topic id
2596 * @uses bbp_get_topic_voice_count() To get the topic voice count
2597 * @uses bbp_get_topic_reply_count() To get the topic reply count
2598 * @uses bbp_get_topic_freshness_link() To get the topic freshness link
2599 * @uses bbp_get_topic_last_active_id() To get the topic last active id
2600 * @uses bbp_get_reply_author_link() To get the reply author link
2601 * @uses apply_filters() Calls 'bbp_get_single_topic_description' with
2602 * the description and args
2603 * @return string Filtered topic description
2604 */
2605 function bbp_get_single_topic_description( $args = '' ) {
2606 // Default arguments
2607 $defaults = array (
2608 'topic_id' => 0,
2609 'before' => '<div class="bbp-template-notice info"><p class="post-meta description">',
2610 'after' => '</p></div>',
2611 'size' => 14
2612 );
2613 $r = wp_parse_args( $args, $defaults );
2614 extract( $r );
2615
2616 // Validate topic_id
2617 $topic_id = bbp_get_topic_id( $topic_id );
2618
2619 // Unhook the 'view all' query var adder
2620 remove_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
2621
2622 // Build the topic description
2623 $forum_id = bbp_get_topic_forum_id ( $topic_id );
2624 $voice_count = bbp_get_topic_voice_count ( $topic_id );
2625 $reply_count = bbp_get_topic_replies_link ( $topic_id );
2626 $time_since = bbp_get_topic_freshness_link( $topic_id );
2627
2628 // Singular/Plural
2629 $voice_count = sprintf( _n( '%s voice', '%s voices', $voice_count, 'bbpress' ), $voice_count );
2630
2631 // Topic has replies
2632 if ( $last_reply = bbp_get_topic_last_active_id( $topic_id ) ) {
2633 $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $size ) );
2634 $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 );
2635
2636 // Topic has no replies
2637 } else {
2638 $retstr = sprintf( __( 'This topic has %1$s, contains %2$s.', 'bbpress' ), $voice_count, $reply_count );
2639 }
2640
2641 // Add the 'view all' filter back
2642 add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
2643
2644 // Combine the elements together
2645 $retstr = $before . $retstr . $after;
2646
2647 // Return filtered result
2648 return apply_filters( 'bbp_get_single_topic_description', $retstr, $args );
2649 }
2650
2651 /** Topic Tags ****************************************************************/
2652
2653 /**
2654 * Output the id of the current tag
2655 *
2656 * @since bbPress (r3109)
2657 *
2658 * @uses bbp_get_topic_tag_id()
2659 */
2660 function bbp_topic_tag_id() {
2661 echo bbp_get_topic_tag_id();
2662 }
2663 /**
2664 * Return the id of the current tag
2665 *
2666 * @since bbPress (r3109)
2667 *
2668 * @uses get_term_by()
2669 * @uses get_query_var()
2670 * @uses apply_filters()
2671 *
2672 * @return string Term Name
2673 */
2674 function bbp_get_topic_tag_id() {
2675
2676 // Get the term
2677 $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
2678
2679 // Add before and after if description exists
2680 if ( !empty( $term->term_id ) )
2681 $retval = $term->term_id;
2682
2683 // No id
2684 else
2685 $retval = '';
2686
2687 return apply_filters( 'bbp_get_topic_tag_id', $retval );
2688 }
2689
2690 /**
2691 * Output the name of the current tag
2692 *
2693 * @since bbPress (r3109)
2694 *
2695 * @uses bbp_get_topic_tag_name()
2696 */
2697 function bbp_topic_tag_name() {
2698 echo bbp_get_topic_tag_name();
2699 }
2700 /**
2701 * Return the name of the current tag
2702 *
2703 * @since bbPress (r3109)
2704 *
2705 * @uses get_term_by()
2706 * @uses get_query_var()
2707 * @uses apply_filters()
2708 *
2709 * @return string Term Name
2710 */
2711 function bbp_get_topic_tag_name() {
2712
2713 // Get the term
2714 $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
2715
2716 // Add before and after if description exists
2717 if ( !empty( $term->name ) )
2718 $retval = $term->name;
2719
2720 // No name
2721 else
2722 $retval = '';
2723
2724 return apply_filters( 'bbp_get_topic_tag_name', $retval );
2725 }
2726
2727 /**
2728 * Output the slug of the current tag
2729 *
2730 * @since bbPress (r3109)
2731 *
2732 * @uses bbp_get_topic_tag_slug()
2733 */
2734 function bbp_topic_tag_slug() {
2735 echo bbp_get_topic_tag_slug();
2736 }
2737 /**
2738 * Return the slug of the current tag
2739 *
2740 * @since bbPress (r3109)
2741 *
2742 * @uses get_term_by()
2743 * @uses get_query_var()
2744 * @uses apply_filters()
2745 *
2746 * @return string Term Name
2747 */
2748 function bbp_get_topic_tag_slug() {
2749
2750 // Get the term
2751 $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
2752
2753 // Add before and after if description exists
2754 if ( !empty( $term->slug ) )
2755 $retval = $term->slug;
2756
2757 // No slug
2758 else
2759 $retval = '';
2760
2761 return apply_filters( 'bbp_get_topic_tag_slug', $retval );
2762 }
2763
2764 /**
2765 * Output the description of the current tag
2766 *
2767 * @since bbPress (r3109)
2768 *
2769 * @uses bbp_get_topic_tag_description()
2770 */
2771 function bbp_topic_tag_description( $args = array() ) {
2772 echo bbp_get_topic_tag_description( $args );
2773 }
2774 /**
2775 * Return the description of the current tag
2776 *
2777 * @since bbPress (r3109)
2778 *
2779 * @uses get_term_by()
2780 * @uses get_query_var()
2781 * @uses apply_filters()
2782 *
2783 * @return string Term Name
2784 */
2785 function bbp_get_topic_tag_description( $args = array() ) {
2786 global $bbp;
2787
2788 $defaults = array(
2789 'before' => '<div class="bbp-topic-tag-description"><p>',
2790 'after' => '</p></div>'
2791 );
2792 $r = wp_parse_args( $args, $defaults );
2793 extract( $r );
2794
2795 // Get the term
2796 $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
2797
2798 // Add before and after if description exists
2799 if ( !empty( $term->description ) )
2800 $retval = $before . $term->description . $after;
2801
2802 // No description, no HTML
2803 else
2804 $retval = '';
2805
2806 return apply_filters( 'bbp_get_topic_tag_description', $retval, $args );
2807 }
2808
2809 /** Forms *********************************************************************/
2810
2811 /**
2812 * Output the value of topic title field
2813 *
2814 * @since bbPress (r2976)
2815 *
2816 * @uses bbp_get_form_topic_title() To get the value of topic title field
2817 */
2818 function bbp_form_topic_title() {
2819 echo bbp_get_form_topic_title();
2820 }
2821 /**
2822 * Return the value of topic title field
2823 *
2824 * @since bbPress (r2976)
2825 *
2826 * @uses bbp_is_topic_edit() To check if it's topic edit page
2827 * @uses apply_filters() Calls 'bbp_get_form_topic_title' with the title
2828 * @return string Value of topic title field
2829 */
2830 function bbp_get_form_topic_title() {
2831 global $post;
2832
2833 // Get _POST data
2834 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_title'] ) )
2835 $topic_title = $_POST['bbp_topic_title'];
2836
2837 // Get edit data
2838 elseif ( !empty( $post->post_title ) && bbp_is_topic_edit() )
2839 $topic_title = $post->post_title;
2840
2841 // No data
2842 else
2843 $topic_title = '';
2844
2845 return apply_filters( 'bbp_get_form_topic_title', esc_attr( $topic_title ) );
2846 }
2847
2848 /**
2849 * Output the value of topic content field
2850 *
2851 * @since bbPress (r2976)
2852 *
2853 * @uses bbp_get_form_topic_content() To get value of topic content field
2854 */
2855 function bbp_form_topic_content() {
2856 echo bbp_get_form_topic_content();
2857 }
2858 /**
2859 * Return the value of topic content field
2860 *
2861 * @since bbPress (r2976)
2862 *
2863 * @uses bbp_is_topic_edit() To check if it's the topic edit page
2864 * @uses apply_filters() Calls 'bbp_get_form_topic_content' with the content
2865 * @return string Value of topic content field
2866 */
2867 function bbp_get_form_topic_content() {
2868 global $post;
2869
2870 // Get _POST data
2871 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_content'] ) )
2872 $topic_content = $_POST['bbp_topic_content'];
2873
2874 // Get edit data
2875 elseif ( !empty( $post->post_title ) && bbp_is_topic_edit() )
2876 $topic_content = $post->post_content;
2877
2878 // No data
2879 else
2880 $topic_content = '';
2881
2882 return apply_filters( 'bbp_get_form_topic_content', esc_textarea( $topic_content ) );
2883 }
2884
2885 /**
2886 * Output value of topic tags field
2887 *
2888 * @since bbPress (r2976)
2889 * @uses bbp_get_form_topic_tags() To get the value of topic tags field
2890 */
2891 function bbp_form_topic_tags() {
2892 echo bbp_get_form_topic_tags();
2893 }
2894 /**
2895 * Return value of topic tags field
2896 *
2897 * @since bbPress (r2976)
2898 *
2899 * @uses bbp_is_topic_edit() To check if it's the topic edit page
2900 * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags
2901 * @return string Value of topic tags field
2902 */
2903 function bbp_get_form_topic_tags() {
2904 global $post, $bbp;
2905
2906 // Get _POST data
2907 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_tags'] ) ) {
2908 $topic_tags = $_POST['bbp_topic_tags'];
2909
2910 // Get edit data
2911 } elseif ( !empty( $post ) ) {
2912
2913 // Post is a topic
2914 if ( bbp_get_topic_post_type() == $post->post_type )
2915 $topic_id = $post->ID;
2916
2917 // Post is a reply
2918 elseif ( bbp_get_reply_post_type() == $post->post_type )
2919 $topic_id = bbp_get_reply_topic_id( $post->ID );
2920
2921 // Topic exists and has tags
2922 if ( !empty( $topic_id ) && ( $terms = get_the_terms( $topic_id, $bbp->topic_tag_id ) ) ) {
2923
2924 // Loop through them
2925 foreach( $terms as $term ) {
2926 $new_terms[] = $term->name;
2927 }
2928
2929 // Define local variable(s)
2930 } else {
2931 $new_terms = '';
2932 }
2933
2934 // Set the return value
2935 $topic_tags = ( !empty( $new_terms ) ) ? implode( ', ', $new_terms ) : '';
2936
2937 // No data
2938 } else {
2939 $topic_tags = '';
2940 }
2941
2942 return apply_filters( 'bbp_get_form_topic_tags', esc_attr( $topic_tags ) );
2943 }
2944
2945 /**
2946 * Output value of topic forum
2947 *
2948 * @since bbPress (r2976)
2949 *
2950 * @uses bbp_get_form_topic_forum() To get the topic's forum id
2951 */
2952 function bbp_form_topic_forum() {
2953 echo bbp_get_form_topic_forum();
2954 }
2955 /**
2956 * Return value of topic forum
2957 *
2958 * @since bbPress (r2976)
2959 *
2960 * @uses bbp_is_topic_edit() To check if it's the topic edit page
2961 * @uses bbp_get_topic_forum_id() To get the topic forum id
2962 * @uses apply_filters() Calls 'bbp_get_form_topic_forum' with the forum
2963 * @return string Value of topic content field
2964 */
2965 function bbp_get_form_topic_forum() {
2966
2967 // Get _POST data
2968 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_id'] ) )
2969 $topic_forum = $_POST['bbp_forum_id'];
2970
2971 // Get edit data
2972 elseif ( bbp_is_topic_edit() )
2973 $topic_forum = bbp_get_topic_forum_id();
2974
2975 // No data
2976 else
2977 $topic_forum = 0;
2978
2979 return apply_filters( 'bbp_get_form_topic_forum', esc_attr( $topic_forum ) );
2980 }
2981
2982 /**
2983 * Output checked value of topic subscription
2984 *
2985 * @since bbPress (r2976)
2986 *
2987 * @uses bbp_get_form_topic_subscribed() To get the subscribed checkbox value
2988 */
2989 function bbp_form_topic_subscribed() {
2990 echo bbp_get_form_topic_subscribed();
2991 }
2992 /**
2993 * Return checked value of topic subscription
2994 *
2995 * @since bbPress (r2976)
2996 *
2997 * @uses bbp_is_topic_edit() To check if it's the topic edit page
2998 * @uses bbp_is_user_subscribed() To check if the user is subscribed to
2999 * the topic
3000 * @uses apply_filters() Calls 'bbp_get_form_topic_subscribed' with the
3001 * option
3002 * @return string Checked value of topic subscription
3003 */
3004 function bbp_get_form_topic_subscribed() {
3005 global $post;
3006
3007 // Get _POST data
3008 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_subscription'] ) ) {
3009 $topic_subscribed = $_POST['bbp_topic_subscription'];
3010
3011 // Get edit data
3012 } elseif ( bbp_is_topic_edit() || bbp_is_reply_edit() ) {
3013
3014 // Post author is not the current user
3015 if ( $post->post_author != bbp_get_current_user_id() ) {
3016 $topic_subscribed = bbp_is_user_subscribed( $post->post_author );
3017
3018 // Post author is the current user
3019 } else {
3020 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() );
3021 }
3022
3023 // Get current status
3024 } elseif ( bbp_is_topic() ) {
3025 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() );
3026
3027 // No data
3028 } else {
3029 $topic_subscribed = 0;
3030 }
3031
3032 // Get checked output
3033 $checked = checked( $topic_subscribed, true, false );
3034
3035 return apply_filters( 'bbp_get_form_topic_subscribed', $checked, $topic_subscribed );
3036 }
3037
3038 /**
3039 * Output checked value of topic log edit field
3040 *
3041 * @since bbPress (r2976)
3042 *
3043 * @uses bbp_get_form_topic_log_edit() To get the topic log edit value
3044 */
3045 function bbp_form_topic_log_edit() {
3046 echo bbp_get_form_topic_log_edit();
3047 }
3048 /**
3049 * Return checked value of topic log edit field
3050 *
3051 * @since bbPress (r2976)
3052 *
3053 * @uses apply_filters() Calls 'bbp_get_form_topic_log_edit' with the
3054 * log edit value
3055 * @return string Topic log edit checked value
3056 */
3057 function bbp_get_form_topic_log_edit() {
3058 global $post;
3059
3060 // Get _POST data
3061 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_log_topic_edit'] ) )
3062 $topic_revision = $_POST['bbp_log_topic_edit'];
3063
3064 // No data
3065 else
3066 $topic_revision = 1;
3067
3068 return apply_filters( 'bbp_get_form_topic_log_edit', checked( $topic_revision, true, false ) );
3069 }
3070
3071 /**
3072 * Output the value of the topic edit reason
3073 *
3074 * @since bbPress (r2976)
3075 *
3076 * @uses bbp_get_form_topic_edit_reason() To get the topic edit reason value
3077 */
3078 function bbp_form_topic_edit_reason() {
3079 echo bbp_get_form_topic_edit_reason();
3080 }
3081 /**
3082 * Return the value of the topic edit reason
3083 *
3084 * @since bbPress (r2976)
3085 *
3086 * @uses apply_filters() Calls 'bbp_get_form_topic_edit_reason' with the
3087 * topic edit reason value
3088 * @return string Topic edit reason value
3089 */
3090 function bbp_get_form_topic_edit_reason() {
3091 global $post;
3092
3093 // Get _POST data
3094 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_topic_edit_reason'] ) )
3095 $topic_edit_reason = $_POST['bbp_topic_edit_reason'];
3096
3097 // No data
3098 else
3099 $topic_edit_reason = '';
3100
3101 return apply_filters( 'bbp_get_form_topic_edit_reason', esc_attr( $topic_edit_reason ) );
3102 }
3103
3104 ?>
3105