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

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