PluginProbe
bbPress / 2.0-rc-5
bbPress v2.0-rc-5
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-forum-template.php

bbp-forum-template.php in bbPress 2.0-rc-5, at bbp-includes/bbp-forum-template.php

1,842 lines 59.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Forum 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 forums
17 *
18 * @since bbPress (r2857)
19 * @uses bbp_get_forum_post_type() To get the forum post type
20 */
21 function bbp_forum_post_type() {
22 echo bbp_get_forum_post_type();
23 }
24 /**
25 * Return the unique id of the custom post type for forums
26 *
27 * @since bbPress (r2857)
28 *
29 * @uses apply_filters() Calls 'bbp_get_forum_post_type' with the forum
30 * post type id
31 * @return string The unique forum post type id
32 */
33 function bbp_get_forum_post_type() {
34 global $bbp;
35
36 return apply_filters( 'bbp_get_forum_post_type', $bbp->forum_post_type );
37 }
38
39 /** Forum Loop ****************************************************************/
40
41 /**
42 * The main forum loop.
43 *
44 * WordPress makes this easy for us.
45 *
46 * @since bbPress (r2464)
47 *
48 * @param mixed $args All the arguments supported by {@link WP_Query}
49 * @uses WP_Query To make query and get the forums
50 * @uses bbp_get_forum_post_type() To get the forum post type id
51 * @uses bbp_get_forum_id() To get the forum id
52 * @uses get_option() To get the forums per page option
53 * @uses current_user_can() To check if the current user is capable of editing
54 * others' forums
55 * @uses apply_filters() Calls 'bbp_has_forums' with
56 * bbPres::forum_query::have_posts()
57 * and bbPres::forum_query
58 * @return object Multidimensional array of forum information
59 */
60 function bbp_has_forums( $args = '' ) {
61 global $bbp;
62
63 // Setup possible post__not_in array
64 $post_stati[] = bbp_get_public_status_id();
65
66 // Super admin get whitelisted post statuses
67 if ( is_super_admin() ) {
68 $post_stati = array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() );
69
70 // Not a super admin, so check caps
71 } else {
72
73 // Check if user can read private forums
74 if ( current_user_can( 'read_private_forums' ) )
75 $post_stati[] = bbp_get_private_status_id();
76
77 // Check if user can read hidden forums
78 if ( current_user_can( 'read_hidden_forums' ) )
79 $post_stati[] = bbp_get_hidden_status_id();
80 }
81
82 // The default forum query for most circumstances
83 $default = array (
84 'post_type' => bbp_get_forum_post_type(),
85 'post_parent' => bbp_is_forum_archive() ? 0 : bbp_get_forum_id() ,
86 'post_status' => implode( ',', $post_stati ),
87 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
88 'orderby' => 'menu_order',
89 'order' => 'ASC'
90 );
91
92 // Parse the default against what is requested
93 $bbp_f = wp_parse_args( $args, $default );
94
95 // Filter the forums query to allow just-in-time modifications
96 $bbp_f = apply_filters( 'bbp_has_forums_query', $bbp_f );
97
98 // Run the query
99 $bbp->forum_query = new WP_Query( $bbp_f );
100
101 return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
102 }
103
104 /**
105 * Whether there are more forums available in the loop
106 *
107 * @since bbPress (r2464)
108 *
109 * @uses bbPress:forum_query::have_posts() To check if there are more forums
110 * available
111 * @return object Forum information
112 */
113 function bbp_forums() {
114 global $bbp;
115
116 // Put into variable to check against next
117 $have_posts = $bbp->forum_query->have_posts();
118
119 // Reset the post data when finished
120 if ( empty( $have_posts ) )
121 wp_reset_postdata();
122
123 return $have_posts;
124 }
125
126 /**
127 * Loads up the current forum in the loop
128 *
129 * @since bbPress (r2464)
130 *
131 * @uses bbPress:forum_query::the_post() To get the current forum
132 * @return object Forum information
133 */
134 function bbp_the_forum() {
135 global $bbp;
136 return $bbp->forum_query->the_post();
137 }
138
139 /** Forum *********************************************************************/
140
141 /**
142 * Output forum id
143 *
144 * @since bbPress (r2464)
145 *
146 * @param $forum_id Optional. Used to check emptiness
147 * @uses bbp_get_forum_id() To get the forum id
148 */
149 function bbp_forum_id( $forum_id = 0 ) {
150 echo bbp_get_forum_id( $forum_id );
151 }
152 /**
153 * Return the forum id
154 *
155 * @since bbPress (r2464)
156 *
157 * @param $forum_id Optional. Used to check emptiness
158 * @uses bbPress::forum_query::in_the_loop To check if we're in the loop
159 * @uses bbPress::forum_query::post::ID To get the forum id
160 * @uses WP_Query::post::ID To get the forum id
161 * @uses bbp_is_single_forum() To check if it's a forum page
162 * @uses bbp_is_single_topic() To check if it's a topic page
163 * @uses bbp_get_topic_forum_id() To get the topic forum id
164 * @uses get_post_field() To get the post's post type
165 * @uses apply_filters() Calls 'bbp_get_forum_id' with the forum id and
166 * supplied forum id
167 * @return int The forum id
168 */
169 function bbp_get_forum_id( $forum_id = 0 ) {
170 global $bbp, $wp_query;
171
172 // Easy empty checking
173 if ( !empty( $forum_id ) && is_numeric( $forum_id ) )
174 $bbp_forum_id = $bbp->current_forum_id = $forum_id;
175
176 // Currently inside a forum loop
177 elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) )
178 $bbp_forum_id = $bbp->current_forum_id = $bbp->forum_query->post->ID;
179
180 // Currently viewing a forum
181 elseif ( bbp_is_single_forum() && isset( $wp_query->post->ID ) )
182 $bbp_forum_id = $bbp->current_forum_id = $wp_query->post->ID;
183
184 // Currently viewing a topic
185 elseif ( bbp_is_single_topic() )
186 $bbp_forum_id = $bbp->current_forum_id = bbp_get_topic_forum_id();
187
188 // Fallback
189 else
190 $bbp_forum_id = 0;
191
192 return apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
193 }
194
195 /**
196 * Gets a forum
197 *
198 * @since bbPress (r2787)
199 *
200 * @param int|object $forum forum id or forum object
201 * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
202 * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
203 * @uses get_post() To get the forum
204 * @uses apply_filters() Calls 'bbp_get_forum' with the forum, output type and
205 * sanitation filter
206 * @return mixed Null if error or forum (in specified form) if success
207 */
208 function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) {
209 if ( empty( $forum ) || is_numeric( $forum ) )
210 $forum = bbp_get_forum_id( $forum );
211
212 if ( !$forum = get_post( $forum, OBJECT, $filter ) )
213 return $forum;
214
215 if ( $forum->post_type !== bbp_get_forum_post_type() )
216 return null;
217
218 if ( $output == OBJECT ) {
219 return $forum;
220
221 } elseif ( $output == ARRAY_A ) {
222 $_forum = get_object_vars( $forum );
223 return $_forum;
224
225 } elseif ( $output == ARRAY_N ) {
226 $_forum = array_values( get_object_vars( $forum ) );
227 return $_forum;
228
229 }
230
231 return apply_filters( 'bbp_get_forum', $forum, $output, $filter );
232 }
233
234 /**
235 * Output the link to the forum
236 *
237 * @since bbPress (r2464)
238 *
239 * @param int $forum_id Optional. Forum id
240 * @uses bbp_get_forum_permalink() To get the permalink
241 */
242 function bbp_forum_permalink( $forum_id = 0 ) {
243 echo bbp_get_forum_permalink( $forum_id );
244 }
245 /**
246 * Return the link to the forum
247 *
248 * @since bbPress (r2464)
249 *
250 * @param int $forum_id Optional. Forum id
251 * @uses bbp_get_forum_id() To get the forum id
252 * @uses get_permalink() Get the permalink of the forum
253 * @uses apply_filters() Calls 'bbp_get_forum_permalink' with the forum
254 * link
255 * @return string Permanent link to forum
256 */
257 function bbp_get_forum_permalink( $forum_id = 0 ) {
258 $forum_id = bbp_get_forum_id( $forum_id );
259 return apply_filters( 'bbp_get_forum_permalink', get_permalink( $forum_id ) );
260 }
261
262 /**
263 * Output the title of the forum
264 *
265 * @since bbPress (r2464)
266 *
267 * @param int $forum_id Optional. Forum id
268 * @uses bbp_get_forum_title() To get the forum title
269 */
270 function bbp_forum_title( $forum_id = 0 ) {
271 echo bbp_get_forum_title( $forum_id );
272 }
273 /**
274 * Return the title of the forum
275 *
276 * @since bbPress (r2464)
277 *
278 * @param int $forum_id Optional. Forum id
279 * @uses bbp_get_forum_id() To get the forum id
280 * @uses get_the_title() To get the forum title
281 * @uses apply_filters() Calls 'bbp_get_forum_title' with the title
282 * @return string Title of forum
283 */
284 function bbp_get_forum_title( $forum_id = 0 ) {
285 $forum_id = bbp_get_forum_id( $forum_id );
286
287 return apply_filters( 'bbp_get_forum_title', get_the_title( $forum_id ) );
288 }
289
290 /**
291 * Output the forum archive title
292 *
293 * @since bbPress (r3249)
294 *
295 * @param string $title Default text to use as title
296 */
297 function bbp_forum_archive_title( $title = '' ) {
298 echo bbp_get_forum_archive_title( $title );
299 }
300 /**
301 * Return the forum archive title
302 *
303 * @since bbPress (r3249)
304 *
305 * @global bbPress $bbp The main bbPress class
306 * @param string $title Default text to use as title
307 *
308 * @uses bbp_get_page_by_path() Check if page exists at root path
309 * @uses get_the_title() Use the page title at the root path
310 * @uses get_post_type_object() Load the post type object
311 * @uses bbp_get_forum_post_type() Get the forum post type ID
312 * @uses get_post_type_labels() Get labels for forum post type
313 * @uses apply_filters() Allow output to be manipulated
314 *
315 * @return string The forum archive title
316 */
317 function bbp_get_forum_archive_title( $title = '' ) {
318 global $bbp;
319
320 // If no title was passed
321 if ( empty( $title ) ) {
322
323 // Set root text to page title
324 if ( $page = bbp_get_page_by_path( $bbp->root_slug ) ) {
325 $title = get_the_title( $page->ID );
326
327 // Default to forum post type name label
328 } else {
329 $fto = get_post_type_object( bbp_get_forum_post_type() );
330 $title = $fto->labels->name;
331 }
332 }
333
334 return apply_filters( 'bbp_get_forum_archive_title', $title );
335 }
336
337 /**
338 * Output the content of the forum
339 *
340 * @since bbPress (r2780)
341 *
342 * @param int $forum_id Optional. Topic id
343 * @uses bbp_get_forum_content() To get the forum content
344 */
345 function bbp_forum_content( $forum_id = 0 ) {
346 echo bbp_get_forum_content( $forum_id );
347 }
348 /**
349 * Return the content of the forum
350 *
351 * @since bbPress (r2780)
352 *
353 * @param int $forum_id Optional. Topic id
354 * @uses bbp_get_forum_id() To get the forum id
355 * @uses post_password_required() To check if the forum requires pass
356 * @uses get_the_password_form() To get the password form
357 * @uses get_post_field() To get the content post field
358 * @uses apply_filters() Calls 'bbp_get_forum_content' with the content
359 * and forum id
360 * @return string Content of the forum
361 */
362 function bbp_get_forum_content( $forum_id = 0 ) {
363 $forum_id = bbp_get_forum_id( $forum_id );
364
365 // Check if password is required
366 if ( post_password_required( $forum_id ) )
367 return get_the_password_form();
368
369 $content = get_post_field( 'post_content', $forum_id );
370
371 return apply_filters( 'bbp_get_forum_content', $content, $forum_id );
372 }
373
374 /**
375 * Output the forums last active ID
376 *
377 * @since bbPress (r2860)
378 *
379 * @uses bbp_get_forum_last_active_id() To get the forum's last active id
380 * @param int $forum_id Optional. Forum id
381 */
382 function bbp_forum_last_active_id( $forum_id = 0 ) {
383 echo bbp_get_forum_last_active_id( $forum_id );
384 }
385 /**
386 * Return the forums last active ID
387 *
388 * @since bbPress (r2860)
389 *
390 * @param int $forum_id Optional. Forum id
391 * @uses bbp_get_forum_id() To get the forum id
392 * @uses get_post_meta() To get the forum's last active id
393 * @uses apply_filters() Calls 'bbp_get_forum_last_active_id' with
394 * the last active id and forum id
395 * @return int Forum's last active id
396 */
397 function bbp_get_forum_last_active_id( $forum_id = 0 ) {
398 $forum_id = bbp_get_forum_id( $forum_id );
399 $active_id = get_post_meta( $forum_id, '_bbp_last_active_id', true );
400
401 return apply_filters( 'bbp_get_forum_last_active_id', (int) $active_id, $forum_id );
402 }
403
404 /**
405 * Output the forums last update date/time (aka freshness)
406 *
407 * @since bbPress (r2464)
408 *
409 * @uses bbp_get_forum_last_active_time() To get the forum freshness
410 * @param int $forum_id Optional. Forum id
411 */
412 function bbp_forum_last_active_time( $forum_id = 0 ) {
413 echo bbp_get_forum_last_active_time( $forum_id );
414 }
415 /**
416 * Return the forums last update date/time (aka freshness)
417 *
418 * @since bbPress (r2464)
419 *
420 * @param int $forum_id Optional. Forum id
421 * @uses bbp_get_forum_id() To get the forum id
422 * @uses get_post_meta() To retrieve forum last active meta
423 * @uses bbp_get_forum_last_reply_id() To get forum's last reply id
424 * @uses get_post_field() To get the post date of the reply
425 * @uses bbp_get_forum_last_topic_id() To get forum's last topic id
426 * @uses bbp_get_topic_last_active_time() To get time when the topic was
427 * last active
428 * @uses bbp_convert_date() To convert the date
429 * @uses bbp_get_time_since() To get time in since format
430 * @uses apply_filters() Calls 'bbp_get_forum_last_active' with last
431 * active time and forum id
432 * @return string Forum last update date/time (freshness)
433 */
434 function bbp_get_forum_last_active_time( $forum_id = 0 ) {
435 $forum_id = bbp_get_forum_id( $forum_id );
436
437 if ( !$last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true ) ) {
438 if ( $reply_id = bbp_get_forum_last_reply_id( $forum_id ) ) {
439 $last_active = get_post_field( 'post_date', $reply_id );
440 } else {
441 if ( $topic_id = bbp_get_forum_last_topic_id( $forum_id ) ) {
442 $last_active = bbp_get_topic_last_active_time( $topic_id );
443 }
444 }
445 }
446
447 $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
448
449 return apply_filters( 'bbp_get_forum_last_active', $last_active, $forum_id );
450 }
451
452 /**
453 * Output link to the most recent activity inside a forum.
454 *
455 * Outputs a complete link with attributes and content.
456 *
457 * @since bbPress (r2625)
458 *
459 * @param int $forum_id Optional. Forum id
460 * @uses bbp_get_forum_freshness_link() To get the forum freshness link
461 */
462 function bbp_forum_freshness_link( $forum_id = 0) {
463 echo bbp_get_forum_freshness_link( $forum_id );
464 }
465 /**
466 * Returns link to the most recent activity inside a forum.
467 *
468 * Returns a complete link with attributes and content.
469 *
470 * @since bbPress (r2625)
471 *
472 * @param int $forum_id Optional. Forum id
473 * @uses bbp_get_forum_id() To get the forum id
474 * @uses bbp_get_forum_last_active_id() To get the forum last active id
475 * @uses bbp_get_forum_last_reply_id() To get the forum last reply id
476 * @uses bbp_get_forum_last_topic_id() To get the forum last topic id
477 * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
478 * @uses bbp_get_forum_last_reply_title() To get the forum last reply
479 * title
480 * @uses bbp_get_forum_last_topic_permalink() To get the forum last
481 * topic permalink
482 * @uses bbp_get_forum_last_topic_title() To get the forum last topic
483 * title
484 * @uses bbp_get_forum_last_active_time() To get the time when the forum
485 * was last active
486 * @uses apply_filters() Calls 'bbp_get_forum_freshness_link' with the
487 * link and forum id
488 */
489 function bbp_get_forum_freshness_link( $forum_id = 0 ) {
490 $forum_id = bbp_get_forum_id( $forum_id );
491 $active_id = bbp_get_forum_last_active_id( $forum_id );
492
493 if ( empty( $active_id ) )
494 $active_id = bbp_get_forum_last_reply_id( $forum_id );
495
496 if ( empty( $active_id ) )
497 $active_id = bbp_get_forum_last_topic_id( $forum_id );
498
499 if ( bbp_is_topic( $active_id ) ) {
500 $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
501 $title = bbp_get_forum_last_topic_title( $forum_id );
502 } elseif ( bbp_is_reply( $active_id ) ) {
503 $link_url = bbp_get_forum_last_reply_url( $forum_id );
504 $title = bbp_get_forum_last_reply_title( $forum_id );
505 }
506
507 $time_since = bbp_get_forum_last_active_time( $forum_id );
508
509 if ( !empty( $time_since ) && !empty( $link_url ) )
510 $anchor = '<a href="' . $link_url . '" title="' . esc_attr( $title ) . '">' . $time_since . '</a>';
511 else
512 $anchor = __( 'No Topics', 'bbpress' );
513
514 return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id );
515 }
516
517 /**
518 * Return ID of forum parent, if exists
519 *
520 * @since bbPress (r2625)
521 *
522 * @param int $forum_id Optional. Forum id
523 * @uses bbp_get_forum_id() To get the forum id
524 * @uses get_post_field() To get the forum parent
525 * @uses apply_filters() Calls 'bbp_get_forum_parent' with the parent & forum id
526 * @return int Forum parent
527 */
528 function bbp_get_forum_parent( $forum_id = 0 ) {
529 $forum_id = bbp_get_forum_id( $forum_id );
530 $parent_id = get_post_field( 'post_parent', $forum_id );
531
532 return apply_filters( 'bbp_get_forum_parent', (int) $parent_id, $forum_id );
533 }
534
535 /**
536 * Return array of parent forums
537 *
538 * @since bbPress (r2625)
539 *
540 * @param int $forum_id Optional. Forum id
541 * @uses bbp_get_forum_id() To get the forum id
542 * @uses bbp_get_forum() To get the forum
543 * @uses apply_filters() Calls 'bbp_get_forum_ancestors' with the ancestors
544 * and forum id
545 * @return array Forum ancestors
546 */
547 function bbp_get_forum_ancestors( $forum_id = 0 ) {
548 $forum_id = bbp_get_forum_id( $forum_id );
549 $ancestors = array();
550
551 if ( $forum = bbp_get_forum( $forum_id ) ) {
552 while ( 0 !== $forum->post_parent ) {
553 $ancestors[] = $forum->post_parent;
554 $forum = bbp_get_forum( $forum->post_parent );
555 }
556 }
557
558 return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id );
559 }
560
561 /**
562 * Return subforums of given forum
563 *
564 * @since bbPress (r2747)
565 *
566 * @param mixed $args All the arguments supported by {@link WP_Query}
567 * @uses bbp_get_forum_id() To get the forum id
568 * @uses current_user_can() To check if the current user is capable of
569 * reading private forums
570 * @uses get_posts() To get the subforums
571 * @uses apply_filters() Calls 'bbp_forum_get_subforums' with the subforums
572 * and the args
573 * @return mixed false if none, array of subs if yes
574 */
575 function bbp_forum_get_subforums( $args = '' ) {
576
577 // Use passed integer as post_parent
578 if ( is_numeric( $args ) )
579 $args = array( 'post_parent' => $args );
580
581 // Setup possible post__not_in array
582 $post_stati[] = bbp_get_public_status_id();
583
584 // Super admin get whitelisted post statuses
585 if ( is_super_admin() ) {
586 $post_stati = array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() );
587
588 // Not a super admin, so check caps
589 } else {
590
591 // Check if user can read private forums
592 if ( current_user_can( 'read_private_forums' ) )
593 $post_stati[] = bbp_get_private_status_id();
594
595 // Check if user can read hidden forums
596 if ( current_user_can( 'read_hidden_forums' ) )
597 $post_stati[] = bbp_get_hidden_status_id();
598 }
599
600 $default = array(
601 'post_parent' => 0,
602 'post_type' => bbp_get_forum_post_type(),
603 'post_status' => implode( ',', $post_stati ),
604 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
605 'sort_column' => 'menu_order, post_title',
606 'order' => 'ASC'
607 );
608
609 $r = wp_parse_args( $args, $default );
610 $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
611
612 // No forum passed
613 $sub_forums = !empty( $r['post_parent'] ) ? get_posts( $r ) : '';
614
615 return apply_filters( 'bbp_forum_get_sub_forums', (array) $sub_forums, $args );
616 }
617
618 /**
619 * Output a list of forums (can be used to list subforums)
620 *
621 * @param mixed $args The function supports these args:
622 * - before: To put before the output. Defaults to '<ul class="bbp-forums">'
623 * - after: To put after the output. Defaults to '</ul>'
624 * - link_before: To put before every link. Defaults to '<li class="bbp-forum">'
625 * - link_after: To put after every link. Defaults to '</li>'
626 * - separator: Separator. Defaults to ', '
627 * - forum_id: Forum id. Defaults to ''
628 * - show_topic_count - To show forum topic count or not. Defaults to true
629 * - show_reply_count - To show forum reply count or not. Defaults to true
630 * @uses bbp_forum_get_subforums() To check if the forum has subforums or not
631 * @uses bbp_get_forum_permalink() To get forum permalink
632 * @uses bbp_get_forum_title() To get forum title
633 * @uses bbp_is_forum_category() To check if a forum is a category
634 * @uses bbp_get_forum_topic_count() To get forum topic count
635 * @uses bbp_get_forum_reply_count() To get forum reply count
636 */
637 function bbp_list_forums( $args = '' ) {
638
639 // Define used variables
640 $output = $sub_forums = $topic_count = $reply_count = $counts = '';
641 $i = 0;
642 $count = array();
643
644 // Defaults and arguments
645 $defaults = array (
646 'before' => '<ul class="bbp-forums">',
647 'after' => '</ul>',
648 'link_before' => '<li class="bbp-forum">',
649 'link_after' => '</li>',
650 'count_before' => ' (',
651 'count_after' => ')',
652 'count_sep' => ', ',
653 'separator' => ', ',
654 'forum_id' => '',
655 'show_topic_count' => true,
656 'show_reply_count' => true,
657 );
658 $r = wp_parse_args( $args, $defaults );
659 extract( $r, EXTR_SKIP );
660
661 // Bail if there are no subforums
662 if ( !bbp_get_forum_subforum_count( $forum_id ) )
663 return;
664
665 // Loop through forums and create a list
666 if ( $sub_forums = bbp_forum_get_subforums( $forum_id ) ) {
667
668 // Total count (for separator)
669 $total_subs = count( $sub_forums );
670 foreach ( $sub_forums as $sub_forum ) {
671 $i++; // Separator count
672
673 // Get forum details
674 $count = array();
675 $show_sep = $total_subs > $i ? $separator : '';
676 $permalink = bbp_get_forum_permalink( $sub_forum->ID );
677 $title = bbp_get_forum_title( $sub_forum->ID );
678
679 // Show topic count
680 if ( !empty( $show_topic_count ) && !bbp_is_forum_category( $sub_forum->ID ) )
681 $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
682
683 // Show reply count
684 if ( !empty( $show_reply_count ) && !bbp_is_forum_category( $sub_forum->ID ) )
685 $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
686
687 // Counts to show
688 if ( !empty( $count ) )
689 $counts = $count_before . implode( $count_sep, $count ) . $count_after;
690
691 // Build this sub forums link
692 $output .= $link_before . '<a href="' . $permalink . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $link_after;
693 }
694
695 // Output the list
696 echo $before . $output . $after;
697 }
698 }
699
700 /** Forum Last Topic **********************************************************/
701
702 /**
703 * Output the forum's last topic id
704 *
705 * @since bbPress (r2464)
706 *
707 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
708 * @param int $forum_id Optional. Forum id
709 */
710 function bbp_forum_last_topic_id( $forum_id = 0 ) {
711 echo bbp_get_forum_last_topic_id( $forum_id );
712 }
713 /**
714 * Return the forum's last topic id
715 *
716 * @since bbPress (r2464)
717 *
718 * @param int $forum_id Optional. Forum id
719 * @uses bbp_get_forum_id() To get the forum id
720 * @uses get_post_meta() To get the forum's last topic id
721 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_id' with the
722 * forum and topic id
723 * @return int Forum's last topic id
724 */
725 function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
726 $forum_id = bbp_get_forum_id( $forum_id );
727 $topic_id = get_post_meta( $forum_id, '_bbp_last_topic_id', true );
728
729 return apply_filters( 'bbp_get_forum_last_topic_id', (int) $topic_id, $forum_id );
730 }
731
732 /**
733 * Output the title of the last topic inside a forum
734 *
735 * @since bbPress (r2625)
736 *
737 * @param int $forum_id Optional. Forum id
738 * @uses bbp_get_forum_last_topic_title() To get the forum's last topic's title
739 */
740 function bbp_forum_last_topic_title( $forum_id = 0 ) {
741 echo bbp_get_forum_last_topic_title( $forum_id );
742 }
743 /**
744 * Return the title of the last topic inside a forum
745 *
746 * @since bbPress (r2625)
747 *
748 * @param int $forum_id Optional. Forum id
749 * @uses bbp_get_forum_id() To get the forum id
750 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
751 * @uses bbp_get_topic_title() To get the topic's title
752 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_title' with the
753 * topic title and forum id
754 * @return string Forum's last topic's title
755 */
756 function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
757 $forum_id = bbp_get_forum_id( $forum_id );
758 return apply_filters( 'bbp_get_forum_last_topic_title', bbp_get_topic_title( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
759 }
760
761 /**
762 * Output the link to the last topic in a forum
763 *
764 * @since bbPress (r2464)
765 *
766 * @param int $forum_id Optional. Forum id
767 * @uses bbp_get_forum_last_topic_permalink() To get the forum's last topic's
768 * permanent link
769 */
770 function bbp_forum_last_topic_permalink( $forum_id = 0 ) {
771 echo bbp_get_forum_last_topic_permalink( $forum_id );
772 }
773 /**
774 * Return the link to the last topic in a forum
775 *
776 * @since bbPress (r2464)
777 *
778 * @param int $forum_id Optional. Forum id
779 * @uses bbp_get_forum_id() To get the forum id
780 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
781 * @uses bbp_get_topic_permalink() To get the topic's permalink
782 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_permalink' with
783 * the topic link and forum id
784 * @return string Permanent link to topic
785 */
786 function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
787 $forum_id = bbp_get_forum_id( $forum_id );
788 return apply_filters( 'bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
789 }
790
791 /**
792 * Return the author ID of the last topic of a forum
793 *
794 * @since bbPress (r2625)
795 *
796 * @param int $forum_id Optional. Forum id
797 * @uses bbp_get_forum_id() To get the forum id
798 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
799 * @uses bbp_get_topic_author_id() To get the topic's author id
800 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author' with the author
801 * id and forum id
802 * @return int Forum's last topic's author id
803 */
804 function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
805 $forum_id = bbp_get_forum_id( $forum_id );
806 $author_id = bbp_get_topic_author_id( bbp_get_forum_last_topic_id( $forum_id ) );
807 return apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id );
808 }
809
810 /**
811 * Output link to author of last topic of forum
812 *
813 * @since bbPress (r2625)
814 *
815 * @param int $forum_id Optional. Forum id
816 * @uses bbp_get_forum_last_topic_author_link() To get the forum's last topic's
817 * author link
818 */
819 function bbp_forum_last_topic_author_link( $forum_id = 0 ) {
820 echo bbp_get_forum_last_topic_author_link( $forum_id );
821 }
822 /**
823 * Return link to author of last topic of forum
824 *
825 * @since bbPress (r2625)
826 *
827 * @param int $forum_id Optional. Forum id
828 * @uses bbp_get_forum_id() To get the forum id
829 * @uses bbp_get_forum_last_topic_author_id() To get the forum's last
830 * topic's author id
831 * @uses bbp_get_user_profile_link() To get the author's profile link
832 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author_link'
833 * with the author link and forum id
834 * @return string Forum's last topic's author link
835 */
836 function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
837 $forum_id = bbp_get_forum_id( $forum_id );
838 $author_id = bbp_get_forum_last_topic_author_id( $forum_id );
839 $author_link = bbp_get_user_profile_link( $author_id );
840 return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
841 }
842
843 /** Forum Last Reply **********************************************************/
844
845 /**
846 * Output the forums last reply id
847 *
848 * @since bbPress (r2464)
849 *
850 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
851 * @param int $forum_id Optional. Forum id
852 */
853 function bbp_forum_last_reply_id( $forum_id = 0 ) {
854 echo bbp_get_forum_last_reply_id( $forum_id );
855 }
856 /**
857 * Return the forums last reply id
858 *
859 * @since bbPress (r2464)
860 *
861 * @param int $forum_id Optional. Forum id
862 * @uses bbp_get_forum_id() To get the forum id
863 * @uses get_post_meta() To get the forum's last reply id
864 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
865 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_id' with
866 * the last reply id and forum id
867 * @return int Forum's last reply id
868 */
869 function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
870 $forum_id = bbp_get_forum_id( $forum_id );
871 $reply_id = get_post_meta( $forum_id, '_bbp_last_reply_id', true );
872
873 if ( empty( $reply_id ) )
874 $reply_id = bbp_get_forum_last_topic_id( $forum_id );
875
876 return apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
877 }
878
879 /**
880 * Output the title of the last reply inside a forum
881 *
882 * @param int $forum_id Optional. Forum id
883 * @uses bbp_get_forum_last_reply_title() To get the forum's last reply's title
884 */
885 function bbp_forum_last_reply_title( $forum_id = 0 ) {
886 echo bbp_get_forum_last_reply_title( $forum_id );
887 }
888 /**
889 * Return the title of the last reply inside a forum
890 *
891 * @param int $forum_id Optional. Forum id
892 * @uses bbp_get_forum_id() To get the forum id
893 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
894 * @uses bbp_get_reply_title() To get the reply title
895 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_title' with the
896 * reply title and forum id
897 * @return string
898 */
899 function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
900 $forum_id = bbp_get_forum_id( $forum_id );
901 return apply_filters( 'bbp_get_forum_last_reply_title', bbp_get_reply_title( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
902 }
903
904 /**
905 * Output the link to the last reply in a forum
906 *
907 * @since bbPress (r2464)
908 *
909 * @param int $forum_id Optional. Forum id
910 * @uses bbp_get_forum_last_reply_permalink() To get the forum last reply link
911 */
912 function bbp_forum_last_reply_permalink( $forum_id = 0 ) {
913 echo bbp_get_forum_last_reply_permalink( $forum_id );
914 }
915 /**
916 * Return the link to the last reply in a forum
917 *
918 * @since bbPress (r2464)
919 *
920 * @param int $forum_id Optional. Forum id
921 * @uses bbp_get_forum_id() To get the forum id
922 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
923 * @uses bbp_get_reply_permalink() To get the reply permalink
924 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_permalink' with
925 * the reply link and forum id
926 * @return string Permanent link to the forum's last reply
927 */
928 function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
929 $forum_id = bbp_get_forum_id( $forum_id );
930 return apply_filters( 'bbp_get_forum_last_reply_permalink', bbp_get_reply_permalink( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
931 }
932
933 /**
934 * Output the url to the last reply in a forum
935 *
936 * @since bbPress (r2683)
937 *
938 * @param int $forum_id Optional. Forum id
939 * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
940 */
941 function bbp_forum_last_reply_url( $forum_id = 0 ) {
942 echo bbp_get_forum_last_reply_url( $forum_id );
943 }
944 /**
945 * Return the url to the last reply in a forum
946 *
947 * @since bbPress (r2683)
948 *
949 * @param int $forum_id Optional. Forum id
950 * @uses bbp_get_forum_id() To get the forum id
951 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
952 * @uses bbp_get_reply_url() To get the reply url
953 * @uses bbp_get_forum_last_topic_permalink() To get the forum's last
954 * topic's permalink
955 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_url' with the
956 * reply url and forum id
957 * @return string Paginated URL to latest reply
958 */
959 function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
960 $forum_id = bbp_get_forum_id( $forum_id );
961
962 // If forum has replies, get the last reply and use its url
963 if ( $reply_id = bbp_get_forum_last_reply_id( $forum_id ) ) {
964 $reply_url = bbp_get_reply_url( $reply_id );
965
966 // No replies, so look for topics and use last permalink
967 } else {
968 if ( !$reply_url = bbp_get_forum_last_topic_permalink( $forum_id ) ) {
969 // No topics either, so set $reply_url as empty
970 $reply_url = '';
971 }
972 }
973
974 // Filter and return
975 return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id );
976 }
977
978 /**
979 * Output author ID of last reply of forum
980 *
981 * @since bbPress (r2625)
982 *
983 * @param int $forum_id Optional. Forum id
984 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last reply
985 * author id
986 */
987 function bbp_forum_last_reply_author_id( $forum_id = 0 ) {
988 echo bbp_get_forum_last_reply_author_id( $forum_id );
989 }
990 /**
991 * Return author ID of last reply of forum
992 *
993 * @since bbPress (r2625)
994 *
995 * @param int $forum_id Optional. Forum id
996 * @uses bbp_get_forum_id() To get the forum id
997 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
998 * reply's author id
999 * @uses bbp_get_reply_author_id() To get the reply's author id
1000 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_id' with
1001 * the author id and forum id
1002 * @return int Forum's last reply author id
1003 */
1004 function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
1005 $forum_id = bbp_get_forum_id( $forum_id );
1006 $author_id = bbp_get_reply_author_id( bbp_get_forum_last_reply_id( $forum_id ) );
1007 return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id );
1008 }
1009
1010 /**
1011 * Output link to author of last reply of forum
1012 *
1013 * @since bbPress (r2625)
1014 *
1015 * @param int $forum_id Optional. Forum id
1016 * @uses bbp_get_forum_last_reply_author_link() To get the forum's last reply's
1017 * author link
1018 */
1019 function bbp_forum_last_reply_author_link( $forum_id = 0 ) {
1020 echo bbp_get_forum_last_reply_author_link( $forum_id );
1021 }
1022 /**
1023 * Return link to author of last reply of forum
1024 *
1025 * @since bbPress (r2625)
1026 *
1027 * @param int $forum_id Optional. Forum id
1028 * @uses bbp_get_forum_id() To get the forum id
1029 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
1030 * reply's author id
1031 * @uses bbp_get_user_profile_link() To get the reply's author's profile
1032 * link
1033 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_link'
1034 * with the author link and forum id
1035 * @return string Link to author of last reply of forum
1036 */
1037 function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
1038 $forum_id = bbp_get_forum_id( $forum_id );
1039 $author_id = bbp_get_forum_last_reply_author_id( $forum_id );
1040 $author_link = bbp_get_user_profile_link( $author_id );
1041 return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id );
1042 }
1043
1044 /** Forum Counts **************************************************************/
1045
1046 /**
1047 * Output the topics link of the forum
1048 *
1049 * @since bbPress (r2883)
1050 *
1051 * @param int $forum_id Optional. Topic id
1052 * @uses bbp_get_forum_topics_link() To get the forum topics link
1053 */
1054 function bbp_forum_topics_link( $forum_id = 0 ) {
1055 echo bbp_get_forum_topics_link( $forum_id );
1056 }
1057
1058 /**
1059 * Return the topics link of the forum
1060 *
1061 * @since bbPress (r2883)
1062 *
1063 * @param int $forum_id Optional. Topic id
1064 * @uses bbp_get_forum_id() To get the forum id
1065 * @uses bbp_get_forum() To get the forum
1066 * @uses bbp_get_forum_topic_count() To get the forum topic count
1067 * @uses bbp_get_forum_permalink() To get the forum permalink
1068 * @uses remove_query_arg() To remove args from the url
1069 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden
1070 * topic count
1071 * @uses current_user_can() To check if the current user can edit others
1072 * topics
1073 * @uses add_query_arg() To add custom args to the url
1074 * @uses apply_filters() Calls 'bbp_get_forum_topics_link' with the
1075 * topics link and forum id
1076 */
1077 function bbp_get_forum_topics_link( $forum_id = 0 ) {
1078
1079 $forum = bbp_get_forum( bbp_get_forum_id( (int) $forum_id ) );
1080 $forum_id = $forum->ID;
1081 $topics = bbp_get_forum_topic_count( $forum_id );
1082 $topics = sprintf( _n( '%s topic', '%s topics', $topics, 'bbpress' ), $topics );
1083 $retval = '';
1084
1085 // First link never has view=all
1086 if ( bbp_get_view_all( 'edit_others_topics' ) )
1087 $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_forum_permalink( $forum_id ) ) ) . "'>$topics</a>";
1088 else
1089 $retval .= $topics;
1090
1091 // This forum has hidden topics
1092 if ( current_user_can( 'edit_others_topics' ) && ( $deleted = bbp_get_forum_topic_count_hidden( $forum_id ) ) ) {
1093
1094 // Extra text
1095 $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted );
1096
1097 // No link
1098 if ( bbp_get_view_all() )
1099 $retval .= " $extra";
1100
1101 // Link
1102 else
1103 $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_forum_permalink( $forum_id ), true ) ) . "'>$extra</a>";
1104 }
1105
1106 return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
1107 }
1108
1109 /**
1110 * Output total sub-forum count of a forum
1111 *
1112 * @since bbPress (r2464)
1113 *
1114 * @uses bbp_get_forum_subforum_count() To get the forum's subforum count
1115 * @param int $forum_id Optional. Forum id to check
1116 */
1117 function bbp_forum_subforum_count( $forum_id = 0 ) {
1118 echo bbp_get_forum_subforum_count( $forum_id );
1119 }
1120 /**
1121 * Return total subforum count of a forum
1122 *
1123 * @since bbPress (r2464)
1124 *
1125 * @param int $forum_id Optional. Forum id
1126 * @uses bbp_get_forum_id() To get the forum id
1127 * @uses get_post_meta() To get the subforum count
1128 * @uses apply_filters() Calls 'bbp_get_forum_subforum_count' with the
1129 * subforum count and forum id
1130 * @return int Forum's subforum count
1131 */
1132 function bbp_get_forum_subforum_count( $forum_id = 0 ) {
1133 $forum_id = bbp_get_forum_id( $forum_id );
1134 $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
1135
1136 return apply_filters( 'bbp_get_forum_subforum_count', (int) $forum_count, $forum_id );
1137 }
1138
1139 /**
1140 * Output total topic count of a forum
1141 *
1142 * @since bbPress (r2464)
1143 *
1144 * @param int $forum_id Optional. Forum id
1145 * @param bool $total_count Optional. To get the total count or normal count?
1146 * @uses bbp_get_forum_topic_count() To get the forum topic count
1147 */
1148 function bbp_forum_topic_count( $forum_id = 0, $total_count = true ) {
1149 echo bbp_get_forum_topic_count( $forum_id );
1150 }
1151 /**
1152 * Return total topic count of a forum
1153 *
1154 * @since bbPress (r2464)
1155 *
1156 * @param int $forum_id Optional. Forum id
1157 * @param bool $total_count Optional. To get the total count or normal
1158 * count? Defaults to total.
1159 * @uses bbp_get_forum_id() To get the forum id
1160 * @uses get_post_meta() To get the forum topic count
1161 * @uses apply_filters() Calls 'bbp_get_forum_topic_count' with the
1162 * topic count and forum id
1163 * @return int Forum topic count
1164 */
1165 function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true ) {
1166 $forum_id = bbp_get_forum_id( $forum_id );
1167 $topics = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count', true );
1168
1169 return apply_filters( 'bbp_get_forum_topic_count', (int) $topics, $forum_id );
1170 }
1171
1172 /**
1173 * Output total reply count of a forum
1174 *
1175 * @since bbPress (r2464)
1176 *
1177 * @param int $forum_id Optional. Forum id
1178 * @param bool $total_count Optional. To get the total count or normal count?
1179 * @uses bbp_get_forum_reply_count() To get the forum reply count
1180 */
1181 function bbp_forum_reply_count( $forum_id = 0, $total_count = true ) {
1182 echo bbp_get_forum_reply_count( $forum_id, $total_count );
1183 }
1184 /**
1185 * Return total post count of a forum
1186 *
1187 * @since bbPress (r2464)
1188 *
1189 * @param int $forum_id Optional. Forum id
1190 * @param bool $total_count Optional. To get the total count or normal
1191 * count?
1192 * @uses bbp_get_forum_id() To get the forum id
1193 * @uses get_post_meta() To get the forum reply count
1194 * @uses apply_filters() Calls 'bbp_get_forum_reply_count' with the
1195 * reply count and forum id
1196 * @return int Forum reply count
1197 */
1198 function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true ) {
1199 $forum_id = bbp_get_forum_id( $forum_id );
1200 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true );
1201
1202 return apply_filters( 'bbp_get_forum_reply_count', (int) $replies, $forum_id );
1203 }
1204
1205 /**
1206 * Output total post count of a forum
1207 *
1208 * @since bbPress (r2954)
1209 *
1210 * @param int $forum_id Optional. Forum id
1211 * @param bool $total_count Optional. To get the total count or normal count?
1212 * @uses bbp_get_forum_post_count() To get the forum post count
1213 */
1214 function bbp_forum_post_count( $forum_id = 0, $total_count = true ) {
1215 echo bbp_get_forum_post_count( $forum_id, $total_count );
1216 }
1217 /**
1218 * Return total post count of a forum
1219 *
1220 * @since bbPress (r2954)
1221 *
1222 * @param int $forum_id Optional. Forum id
1223 * @param bool $total_count Optional. To get the total count or normal
1224 * count?
1225 * @uses bbp_get_forum_id() To get the forum id
1226 * @uses get_post_meta() To get the forum post count
1227 * @uses apply_filters() Calls 'bbp_get_forum_post_count' with the
1228 * post count and forum id
1229 * @return int Forum post count
1230 */
1231 function bbp_get_forum_post_count( $forum_id = 0, $total_count = true ) {
1232 $forum_id = bbp_get_forum_id( $forum_id );
1233 $topics = bbp_get_forum_topic_count( $forum_id, $total_count );
1234 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true );
1235
1236 return apply_filters( 'bbp_get_forum_post_count', (int) $replies + (int) $topics, $forum_id );
1237 }
1238
1239 /**
1240 * Output total hidden topic count of a forum (hidden includes trashed and
1241 * spammed topics)
1242 *
1243 * @since bbPress (r2883)
1244 *
1245 * @param int $forum_id Optional. Topic id
1246 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count
1247 */
1248 function bbp_forum_topic_count_hidden( $forum_id = 0 ) {
1249 echo bbp_get_forum_topic_count_hidden( $forum_id );
1250 }
1251 /**
1252 * Return total hidden topic count of a forum (hidden includes trashed
1253 * and spammed topics)
1254 *
1255 * @since bbPress (r2883)
1256 *
1257 * @param int $forum_id Optional. Topic id
1258 * @uses bbp_get_forum_id() To get the forum id
1259 * @uses get_post_meta() To get the hidden topic count
1260 * @uses apply_filters() Calls 'bbp_get_forum_topic_count_hidden' with
1261 * the hidden topic count and forum id
1262 * @return int Topic hidden topic count
1263 */
1264 function bbp_get_forum_topic_count_hidden( $forum_id = 0 ) {
1265 $forum_id = bbp_get_forum_id( $forum_id );
1266 $topics = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true );
1267
1268 return apply_filters( 'bbp_get_forum_topic_count_hidden', (int) $topics, $forum_id );
1269 }
1270
1271 /**
1272 * Output the status of the forum
1273 *
1274 * @since bbPress (r2667)
1275 *
1276 * @param int $forum_id Optional. Forum id
1277 * @uses bbp_get_forum_status() To get the forum status
1278 */
1279 function bbp_forum_status( $forum_id = 0 ) {
1280 echo bbp_get_forum_status( $forum_id );
1281 }
1282 /**
1283 * Return the status of the forum
1284 *
1285 * @since bbPress (r2667)
1286 *
1287 * @param int $forum_id Optional. Forum id
1288 * @uses bbp_get_forum_id() To get the forum id
1289 * @uses get_post_status() To get the forum's status
1290 * @uses apply_filters() Calls 'bbp_get_forum_status' with the status
1291 * and forum id
1292 * @return string Status of forum
1293 */
1294 function bbp_get_forum_status( $forum_id = 0 ) {
1295 $forum_id = bbp_get_forum_id( $forum_id );
1296
1297 return apply_filters( 'bbp_get_forum_status', get_post_meta( $forum_id, '_bbp_status', true ), $forum_id );
1298 }
1299
1300 /**
1301 * Output the visibility of the forum
1302 *
1303 * @since bbPress (r2997)
1304 *
1305 * @param int $forum_id Optional. Forum id
1306 * @uses bbp_get_forum_visibility() To get the forum visibility
1307 */
1308 function bbp_forum_visibility( $forum_id = 0 ) {
1309 echo bbp_get_forum_visibility( $forum_id );
1310 }
1311 /**
1312 * Return the visibility of the forum
1313 *
1314 * @since bbPress (r2997)
1315 *
1316 * @param int $forum_id Optional. Forum id
1317 * @uses bbp_get_forum_id() To get the forum id
1318 * @uses get_post_visibility() To get the forum's visibility
1319 * @uses apply_filters() Calls 'bbp_get_forum_visibility' with the visibility
1320 * and forum id
1321 * @return string Status of forum
1322 */
1323 function bbp_get_forum_visibility( $forum_id = 0 ) {
1324 $forum_id = bbp_get_forum_id( $forum_id );
1325
1326 return apply_filters( 'bbp_get_forum_visibility', get_post_status( $forum_id ), $forum_id );
1327 }
1328
1329 /**
1330 * Is the forum a category?
1331 *
1332 * @since bbPress (r2746)
1333 *
1334 * @param int $forum_id Optional. Forum id
1335 * @uses get_post_meta() To get the forum category meta
1336 * @return bool Whether the forum is a category or not
1337 */
1338 function bbp_is_forum_category( $forum_id = 0 ) {
1339 $forum_id = bbp_get_forum_id( $forum_id );
1340 $type = get_post_meta( $forum_id, '_bbp_forum_type', true );
1341 $retval = ( !empty( $type ) && 'category' == $type );
1342
1343 return apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id );
1344 }
1345
1346 /**
1347 * Is the forum open?
1348 *
1349 * @since bbPress (r2746)
1350 * @param int $forum_id Optional. Forum id
1351 *
1352 * @param int $forum_id Optional. Forum id
1353 * @uses bbp_is_forum_closed() To check if the forum is closed or not
1354 * @return bool Whether the forum is open or not
1355 */
1356 function bbp_is_forum_open( $forum_id = 0 ) {
1357 return !bbp_is_forum_closed( $forum_id );
1358 }
1359
1360 /**
1361 * Is the forum closed?
1362 *
1363 * @since bbPress (r2746)
1364 *
1365 * @param int $forum_id Optional. Forum id
1366 * @param bool $check_ancestors Check if the ancestors are closed (only
1367 * if they're a category)
1368 * @uses bbp_get_forum_status() To get the forum status
1369 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1370 * @uses bbp_is_forum_category() To check if the forum is a category
1371 * @uses bbp_is_forum_closed() To check if the forum is closed
1372 * @return bool True if closed, false if not
1373 */
1374 function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
1375
1376 $forum_id = bbp_get_forum_id( $forum_id );
1377 $retval = ( bbp_get_closed_status_id() == bbp_get_forum_status( $forum_id ) );
1378
1379 if ( !empty( $check_ancestors ) ) {
1380 $ancestors = bbp_get_forum_ancestors( $forum_id );
1381
1382 foreach ( (array) $ancestors as $ancestor ) {
1383 if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) {
1384 $retval = true;
1385 }
1386 }
1387 }
1388
1389 return apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
1390 }
1391
1392 /**
1393 * Is the forum public?
1394 *
1395 * @since bbPress (r2997)
1396 *
1397 * @param int $forum_id Optional. Forum id
1398 * @param bool $check_ancestors Check if the ancestors are public (only if
1399 * they're a category)
1400 * @uses get_post_meta() To get the forum public meta
1401 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1402 * @uses bbp_is_forum_category() To check if the forum is a category
1403 * @uses bbp_is_forum_closed() To check if the forum is closed
1404 * @return bool True if closed, false if not
1405 */
1406 function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
1407
1408 $forum_id = bbp_get_forum_id( $forum_id );
1409 $visibility = bbp_get_forum_visibility( $forum_id );
1410
1411 // If post status is public, return true
1412 $retval = ( bbp_get_public_status_id() == $visibility );
1413
1414 // Check ancestors and inherit their privacy setting for display
1415 if ( !empty( $check_ancestors ) ) {
1416 $ancestors = bbp_get_forum_ancestors( $forum_id );
1417
1418 foreach ( (array) $ancestors as $ancestor ) {
1419 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) {
1420 $retval = true;
1421 }
1422 }
1423 }
1424
1425 return apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors );
1426 }
1427
1428 /**
1429 * Is the forum private?
1430 *
1431 * @since bbPress (r2746)
1432 *
1433 * @param int $forum_id Optional. Forum id
1434 * @param bool $check_ancestors Check if the ancestors are private (only if
1435 * they're a category)
1436 * @uses get_post_meta() To get the forum private meta
1437 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1438 * @uses bbp_is_forum_category() To check if the forum is a category
1439 * @uses bbp_is_forum_closed() To check if the forum is closed
1440 * @return bool True if closed, false if not
1441 */
1442 function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
1443
1444 $forum_id = bbp_get_forum_id( $forum_id );
1445 $visibility = bbp_get_forum_visibility( $forum_id );
1446
1447 // If post status is private, return true
1448 $retval = ( bbp_get_private_status_id() == $visibility );
1449
1450 // Check ancestors and inherit their privacy setting for display
1451 if ( !empty( $check_ancestors ) ) {
1452 $ancestors = bbp_get_forum_ancestors( $forum_id );
1453
1454 foreach ( (array) $ancestors as $ancestor ) {
1455 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) {
1456 $retval = true;
1457 }
1458 }
1459 }
1460
1461 return apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors );
1462 }
1463
1464 /**
1465 * Is the forum hidden?
1466 *
1467 * @since bbPress (r2997)
1468 *
1469 * @param int $forum_id Optional. Forum id
1470 * @param bool $check_ancestors Check if the ancestors are private (only if
1471 * they're a category)
1472 * @uses get_post_meta() To get the forum private meta
1473 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1474 * @uses bbp_is_forum_category() To check if the forum is a category
1475 * @uses bbp_is_forum_closed() To check if the forum is closed
1476 * @return bool True if closed, false if not
1477 */
1478 function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
1479
1480 $forum_id = bbp_get_forum_id( $forum_id );
1481 $visibility = bbp_get_forum_visibility( $forum_id );
1482
1483 // If post status is private, return true
1484 $retval = ( bbp_get_hidden_status_id() == $visibility );
1485
1486 // Check ancestors and inherit their privacy setting for display
1487 if ( !empty( $check_ancestors ) ) {
1488 $ancestors = bbp_get_forum_ancestors( $forum_id );
1489
1490 foreach ( (array) $ancestors as $ancestor ) {
1491 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) {
1492 $retval = true;
1493 }
1494 }
1495 }
1496
1497 return apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
1498 }
1499
1500 /**
1501 * Replace forum meta details for users that cannot view them.
1502 *
1503 * @since bbPress (r3162)
1504 *
1505 * @param string $retval
1506 * @param int $forum_id
1507 *
1508 * @uses bbp_is_forum_private()
1509 * @uses current_user_can()
1510 *
1511 * @return string
1512 */
1513 function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
1514 if ( bbp_is_forum_private( $forum_id, false ) && !current_user_can( 'read_private_forums' ) )
1515 $retval = '-';
1516
1517 return apply_filters( 'bbp_suppress_private_forum_meta', $retval );
1518 }
1519
1520 /**
1521 * Replace forum author details for users that cannot view them.
1522 *
1523 * @since bbPress (r3162)
1524 *
1525 * @param string $retval
1526 * @param int $forum_id
1527 *
1528 * @uses bbp_is_forum_private()
1529 * @uses get_post_field()
1530 * @uses bbp_get_topic_post_type()
1531 * @uses bbp_is_forum_private()
1532 * @uses bbp_get_topic_forum_id()
1533 * @uses bbp_get_reply_post_type()
1534 * @uses bbp_get_reply_forum_id()
1535 *
1536 * @return string
1537 */
1538 function bbp_suppress_private_author_link( $author_link, $args ) {
1539
1540 // Assume the author link is the return value
1541 $retval = $author_link;
1542
1543 // Show the normal author link
1544 if ( !empty( $args['post_id'] ) && !current_user_can( 'read_private_forums' ) ) {
1545
1546 // What post type are we looking at?
1547 $post_type = get_post_field( 'post_type', $args['post_id'] );
1548
1549 switch ( $post_type ) {
1550
1551 // Topic
1552 case bbp_get_topic_post_type() :
1553 if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) )
1554 $retval = '';
1555
1556 break;
1557
1558 // Reply
1559 case bbp_get_reply_post_type() :
1560 if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) )
1561 $retval = '';
1562
1563 break;
1564
1565 // Post
1566 default :
1567 if ( bbp_is_forum_private( $args['post_id'] ) )
1568 $retval = '';
1569
1570 break;
1571 }
1572 }
1573
1574 return apply_filters( 'bbp_suppress_private_author_link', $retval );
1575 }
1576
1577 /**
1578 * Output the row class of a forum
1579 *
1580 * @since bbPress (r2667)
1581 *
1582 * @uses bbp_get_forum_class() To get the row class of the forum
1583 */
1584 function bbp_forum_class() {
1585 echo bbp_get_forum_class();
1586 }
1587 /**
1588 * Return the row class of a forum
1589 *
1590 * @since bbPress (r2667)
1591 *
1592 * @uses post_class() To get all the classes including ours
1593 * @uses apply_filters() Calls 'bbp_get_forum_class' with the classes
1594 * @return string Row class of the forum
1595 */
1596 function bbp_get_forum_class() {
1597 global $bbp;
1598
1599 $classes = array();
1600 $classes[] = $bbp->forum_query->current_post % 2 ? 'even' : 'odd';
1601 $classes[] = bbp_is_forum_category() ? 'status-category' : '';
1602 $classes[] = bbp_is_forum_private() ? 'status-private' : '';
1603 $classes = array_filter( $classes );
1604
1605 $post = post_class( $classes );
1606
1607 return apply_filters( 'bbp_get_forum_class', $post );
1608 }
1609
1610 /** Single Forum **************************************************************/
1611
1612 /**
1613 * Output a fancy description of the current forum, including total topics,
1614 * total replies, and last activity.
1615 *
1616 * @since bbPress (r2860)
1617 *
1618 * @param array $args Arguments passed to alter output
1619 * @uses bbp_get_single_forum_description() Return the eventual output
1620 */
1621 function bbp_single_forum_description( $args = '' ) {
1622 echo bbp_get_single_forum_description( $args );
1623 }
1624 /**
1625 * Return a fancy description of the current forum, including total
1626 * topics, total replies, and last activity.
1627 *
1628 * @since bbPress (r2860)
1629 *
1630 * @param mixed $args This function supports these arguments:
1631 * - topic_id: Topic id
1632 * - before: Before the text
1633 * - after: After the text
1634 * - size: Size of the avatar
1635 * @uses bbp_get_forum_id() To get the forum id
1636 * @uses bbp_get_forum_topic_count() To get the forum topic count
1637 * @uses bbp_get_forum_reply_count() To get the forum reply count
1638 * @uses bbp_get_forum_subforum_count() To get the forum subforum count
1639 * @uses bbp_get_forum_freshness_link() To get the forum freshness link
1640 * @uses bbp_get_forum_last_active_id() To get the forum last active id
1641 * @uses bbp_get_author_link() To get the author link
1642 * @uses add_filter() To add the 'view all' filter back
1643 * @uses apply_filters() Calls 'bbp_get_single_forum_description' with
1644 * the description and args
1645 * @return string Filtered forum description
1646 */
1647 function bbp_get_single_forum_description( $args = '' ) {
1648 // Default arguments
1649 $defaults = array (
1650 'forum_id' => 0,
1651 'before' => '<div class="bbp-template-notice info"><p class="bbp-forum-description">',
1652 'after' => '</p></div>',
1653 'size' => 14,
1654 'feed' => true
1655 );
1656 $r = wp_parse_args( $args, $defaults );
1657 extract( $r );
1658
1659 // Validate forum_id
1660 $forum_id = bbp_get_forum_id( $forum_id );
1661
1662 // Unhook the 'view all' query var adder
1663 remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1664
1665 // Build the forum description
1666 $topic_count = bbp_get_forum_topics_link ( $forum_id );
1667 $reply_count = bbp_get_forum_reply_count ( $forum_id );
1668 $subforum_count = bbp_get_forum_subforum_count( $forum_id );
1669 $time_since = bbp_get_forum_freshness_link( $forum_id );
1670
1671 // Singlular/Plural
1672 $reply_count = sprintf( _n( '%s reply', '%s replies', $reply_count, 'bbpress' ), $reply_count );
1673
1674 // Forum has posts
1675 if ( $last_reply = bbp_get_forum_last_active_id( $forum_id ) ) {
1676
1677 // Freshness author
1678 $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $size ) );
1679
1680 // Category
1681 if ( bbp_is_forum_category( $forum_id ) )
1682 $retstr = sprintf( __( 'This category contains %1$s and %2$s, and was last updated by %3$s %4$s ago.', 'bbpress' ), $topic_count, $reply_count, $last_updated_by, $time_since );
1683
1684 // Forum
1685 else
1686 $retstr = sprintf( __( 'This forum contains %1$s and %2$s, and was last updated by %3$s %4$s ago.', 'bbpress' ), $topic_count, $reply_count, $last_updated_by, $time_since );
1687
1688 // Forum has no last active data
1689 } else {
1690
1691 // Category
1692 if ( bbp_is_forum_category( $forum_id ) )
1693 $retstr = sprintf( __( 'This category contains %1$s and %2$s.', 'bbpress' ), $topic_count, $reply_count );
1694
1695 // Forum
1696 else
1697 $retstr = sprintf( __( 'This forum contains %1$s and %2$s.', 'bbpress' ), $topic_count, $reply_count );
1698 }
1699
1700 // Add feeds
1701 $feed_links = ( !empty( $feed ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : '';
1702
1703 // Add the 'view all' filter back
1704 add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1705
1706 // Combine the elements together
1707 $retstr = $before . $retstr . $after;
1708
1709 // Return filtered result
1710 return apply_filters( 'bbp_get_single_forum_description', $retstr, $args );
1711 }
1712
1713 /** Feeds *********************************************************************/
1714
1715 /**
1716 * Output the link for the forum feed
1717 *
1718 * @since bbPress (r3172)
1719 *
1720 * @param type $forum_id Optional. Forum ID.
1721 *
1722 * @uses bbp_get_forum_topics_feed_link()
1723 */
1724 function bbp_forum_topics_feed_link( $forum_id = 0 ) {
1725 echo bbp_get_forum_topics_feed_link( $forum_id );
1726 }
1727 /**
1728 * Retrieve the link for the forum feed
1729 *
1730 * @since bbPress (r3172)
1731 *
1732 * @param int $forum_id Optional. Forum ID.
1733 *
1734 * @uses bbp_get_forum_id()
1735 * @uses get_option()
1736 * @uses trailingslashit()
1737 * @uses bbp_get_forum_permalink()
1738 * @uses user_trailingslashit()
1739 * @uses bbp_get_forum_post_type()
1740 * @uses get_post_field()
1741 * @uses apply_filters()
1742 *
1743 * @return string
1744 */
1745 function bbp_get_forum_topics_feed_link( $forum_id = 0 ) {
1746
1747 // Validate forum id
1748 $forum_id = bbp_get_forum_id( $forum_id );
1749
1750 // Forum is valid
1751 if ( !empty( $forum_id ) ) {
1752
1753 // Define local variable(s)
1754 $link = '';
1755
1756 // Pretty permalinks
1757 if ( get_option( 'permalink_structure' ) ) {
1758
1759 // Forum link
1760 $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
1761 $url = user_trailingslashit( $url, 'single_feed' );
1762
1763 // Unpretty permalinks
1764 } else {
1765 $url = home_url( add_query_arg( array(
1766 'feed' => 'rss2',
1767 bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
1768 ) ) );
1769 }
1770
1771 $link = '<a href="' . $url . '" class="bbp-forum-rss-link topics"><span>' . __( 'Topics', 'bbpress' ) . '</span></a>';
1772 }
1773
1774 return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id );
1775 }
1776
1777 /**
1778 * Output the link for the forum replies feed
1779 *
1780 * @since bbPress (r3172)
1781 *
1782 * @param type $forum_id Optional. Forum ID.
1783 *
1784 * @uses bbp_get_forum_replies_feed_link()
1785 */
1786 function bbp_forum_replies_feed_link( $forum_id = 0 ) {
1787 echo bbp_get_forum_replies_feed_link( $forum_id );
1788 }
1789 /**
1790 * Retrieve the link for the forum replies feed
1791 *
1792 * @since bbPress (r3172)
1793 *
1794 * @param int $forum_id Optional. Forum ID.
1795 *
1796 * @uses bbp_get_forum_id()
1797 * @uses get_option()
1798 * @uses trailingslashit()
1799 * @uses bbp_get_forum_permalink()
1800 * @uses user_trailingslashit()
1801 * @uses bbp_get_forum_post_type()
1802 * @uses get_post_field()
1803 * @uses apply_filters()
1804 *
1805 * @return string
1806 */
1807 function bbp_get_forum_replies_feed_link( $forum_id = 0 ) {
1808
1809 // Validate forum id
1810 $forum_id = bbp_get_forum_id( $forum_id );
1811
1812 // Forum is valid
1813 if ( !empty( $forum_id ) ) {
1814
1815 // Define local variable(s)
1816 $link = '';
1817
1818 // Pretty permalinks
1819 if ( get_option( 'permalink_structure' ) ) {
1820
1821 // Forum link
1822 $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
1823 $url = user_trailingslashit( $url, 'single_feed' );
1824 $url = add_query_arg( array( 'type' => 'reply' ), $url );
1825
1826 // Unpretty permalinks
1827 } else {
1828 $url = home_url( add_query_arg( array(
1829 'type' => 'reply',
1830 'feed' => 'rss2',
1831 bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
1832 ) ) );
1833 }
1834
1835 $link = '<a href="' . $url . '" class="bbp-forum-rss-link replies"><span>' . __( 'Replies', 'bbpress' ) . '</span></a>';
1836 }
1837
1838 return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id );
1839 }
1840
1841 ?>
1842