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

1,767 lines 56.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Forum Template Tags
5 *
6 * @package bbPress
7 * @subpackage TemplateTags
8 */
9
10 // Redirect 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' => 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 );
555
556 $r = wp_parse_args( $args, $default );
557 $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
558
559 // No forum passed
560 $sub_forums = !empty( $r['post_parent'] ) ? get_posts( $r ) : '';
561
562 return apply_filters( 'bbp_forum_get_sub_forums', (array) $sub_forums, $args );
563 }
564
565 /**
566 * Output a list of forums (can be used to list subforums)
567 *
568 * @param mixed $args The function supports these args:
569 * - before: To put before the output. Defaults to '<ul class="bbp-forums">'
570 * - after: To put after the output. Defaults to '</ul>'
571 * - link_before: To put before every link. Defaults to '<li class="bbp-forum">'
572 * - link_after: To put after every link. Defaults to '</li>'
573 * - separator: Separator. Defaults to ', '
574 * - forum_id: Forum id. Defaults to ''
575 * - show_topic_count - To show forum topic count or not. Defaults to true
576 * - show_reply_count - To show forum reply count or not. Defaults to true
577 * @uses bbp_forum_get_subforums() To check if the forum has subforums or not
578 * @uses bbp_get_forum_permalink() To get forum permalink
579 * @uses bbp_get_forum_title() To get forum title
580 * @uses bbp_is_forum_category() To check if a forum is a category
581 * @uses bbp_get_forum_topic_count() To get forum topic count
582 * @uses bbp_get_forum_reply_count() To get forum reply count
583 */
584 function bbp_list_forums( $args = '' ) {
585 global $bbp;
586
587 // Define used variables
588 $output = $sub_forums = $topic_count = $reply_count = $counts = '';
589 $i = 0;
590 $count = array();
591
592 // Defaults and arguments
593 $defaults = array (
594 'before' => '<ul class="bbp-forums">',
595 'after' => '</ul>',
596 'link_before' => '<li class="bbp-forum">',
597 'link_after' => '</li>',
598 'count_before' => ' (',
599 'count_after' => ')',
600 'count_sep' => ', ',
601 'separator' => ', ',
602 'forum_id' => '',
603 'show_topic_count' => true,
604 'show_reply_count' => true,
605 );
606 $r = wp_parse_args( $args, $defaults );
607 extract( $r, EXTR_SKIP );
608
609 // Loop through forums and create a list
610 if ( $sub_forums = bbp_forum_get_subforums( $forum_id ) ) {
611
612 // Total count (for separator)
613 $total_subs = count( $sub_forums );
614 foreach ( $sub_forums as $sub_forum ) {
615 $i++; // Separator count
616
617 // Get forum details
618 $count = array();
619 $show_sep = $total_subs > $i ? $separator : '';
620 $permalink = bbp_get_forum_permalink( $sub_forum->ID );
621 $title = bbp_get_forum_title( $sub_forum->ID );
622
623 // Show topic count
624 if ( !empty( $show_topic_count ) && !bbp_is_forum_category( $sub_forum->ID ) )
625 $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
626
627 // Show reply count
628 if ( !empty( $show_reply_count ) && !bbp_is_forum_category( $sub_forum->ID ) )
629 $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
630
631 // Counts to show
632 if ( !empty( $count ) )
633 $counts = $count_before . implode( $count_sep, $count ) . $count_after;
634
635 // Build this sub forums link
636 $output .= $link_before . '<a href="' . $permalink . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $link_after;
637 }
638
639 // Output the list
640 echo $before . $output . $after;
641 }
642 }
643
644 /** Forum Last Topic **********************************************************/
645
646 /**
647 * Output the forum's last topic id
648 *
649 * @since bbPress (r2464)
650 *
651 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
652 * @param int $forum_id Optional. Forum id
653 */
654 function bbp_forum_last_topic_id( $forum_id = 0 ) {
655 echo bbp_get_forum_last_topic_id( $forum_id );
656 }
657 /**
658 * Return the forum's last topic id
659 *
660 * @since bbPress (r2464)
661 *
662 * @param int $forum_id Optional. Forum id
663 * @uses bbp_get_forum_id() To get the forum id
664 * @uses get_post_meta() To get the forum's last topic id
665 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_id' with the
666 * forum and topic id
667 * @return int Forum's last topic id
668 */
669 function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
670 $forum_id = bbp_get_forum_id( $forum_id );
671 $topic_id = get_post_meta( $forum_id, '_bbp_last_topic_id', true );
672
673 return apply_filters( 'bbp_get_forum_last_topic_id', (int) $topic_id, $forum_id );
674 }
675
676 /**
677 * Output the title of the last topic inside a forum
678 *
679 * @since bbPress (r2625)
680 *
681 * @param int $forum_id Optional. Forum id
682 * @uses bbp_get_forum_last_topic_title() To get the forum's last topic's title
683 */
684 function bbp_forum_last_topic_title( $forum_id = 0 ) {
685 echo bbp_get_forum_last_topic_title( $forum_id );
686 }
687 /**
688 * Return the title of the last topic inside a forum
689 *
690 * @since bbPress (r2625)
691 *
692 * @param int $forum_id Optional. Forum id
693 * @uses bbp_get_forum_id() To get the forum id
694 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
695 * @uses bbp_get_topic_title() To get the topic's title
696 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_title' with the
697 * topic title and forum id
698 * @return string Forum's last topic's title
699 */
700 function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
701 $forum_id = bbp_get_forum_id( $forum_id );
702 return apply_filters( 'bbp_get_forum_last_topic_title', bbp_get_topic_title( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
703 }
704
705 /**
706 * Output the link to the last topic in a forum
707 *
708 * @since bbPress (r2464)
709 *
710 * @param int $forum_id Optional. Forum id
711 * @uses bbp_get_forum_last_topic_permalink() To get the forum's last topic's
712 * permanent link
713 */
714 function bbp_forum_last_topic_permalink( $forum_id = 0 ) {
715 echo bbp_get_forum_last_topic_permalink( $forum_id );
716 }
717 /**
718 * Return the link to the last topic in a forum
719 *
720 * @since bbPress (r2464)
721 *
722 * @param int $forum_id Optional. Forum id
723 * @uses bbp_get_forum_id() To get the forum id
724 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
725 * @uses bbp_get_topic_permalink() To get the topic's permalink
726 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_permalink' with
727 * the topic link and forum id
728 * @return string Permanent link to topic
729 */
730 function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
731 $forum_id = bbp_get_forum_id( $forum_id );
732 return apply_filters( 'bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
733 }
734
735 /**
736 * Return the author ID of the last topic of a forum
737 *
738 * @since bbPress (r2625)
739 *
740 * @param int $forum_id Optional. Forum id
741 * @uses bbp_get_forum_id() To get the forum id
742 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
743 * @uses bbp_get_topic_author_id() To get the topic's author id
744 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author' with the author
745 * id and forum id
746 * @return int Forum's last topic's author id
747 */
748 function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
749 $forum_id = bbp_get_forum_id( $forum_id );
750 $author_id = bbp_get_topic_author_id( bbp_get_forum_last_topic_id( $forum_id ) );
751 return apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id );
752 }
753
754 /**
755 * Output link to author of last topic of forum
756 *
757 * @since bbPress (r2625)
758 *
759 * @param int $forum_id Optional. Forum id
760 * @uses bbp_get_forum_last_topic_author_link() To get the forum's last topic's
761 * author link
762 */
763 function bbp_forum_last_topic_author_link( $forum_id = 0 ) {
764 echo bbp_get_forum_last_topic_author_link( $forum_id );
765 }
766 /**
767 * Return link to author of last topic of forum
768 *
769 * @since bbPress (r2625)
770 *
771 * @param int $forum_id Optional. Forum id
772 * @uses bbp_get_forum_id() To get the forum id
773 * @uses bbp_get_forum_last_topic_author_id() To get the forum's last
774 * topic's author id
775 * @uses bbp_get_user_profile_link() To get the author's profile link
776 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author_link'
777 * with the author link and forum id
778 * @return string Forum's last topic's author link
779 */
780 function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
781 $forum_id = bbp_get_forum_id( $forum_id );
782 $author_id = bbp_get_forum_last_topic_author_id( $forum_id );
783 $author_link = bbp_get_user_profile_link( $author_id );
784 return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
785 }
786
787 /** Forum Last Reply **********************************************************/
788
789 /**
790 * Output the forums last reply id
791 *
792 * @since bbPress (r2464)
793 *
794 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
795 * @param int $forum_id Optional. Forum id
796 */
797 function bbp_forum_last_reply_id( $forum_id = 0 ) {
798 echo bbp_get_forum_last_reply_id( $forum_id );
799 }
800 /**
801 * Return the forums last reply id
802 *
803 * @since bbPress (r2464)
804 *
805 * @param int $forum_id Optional. Forum id
806 * @uses bbp_get_forum_id() To get the forum id
807 * @uses get_post_meta() To get the forum's last reply id
808 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
809 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_id' with
810 * the last reply id and forum id
811 * @return int Forum's last reply id
812 */
813 function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
814 $forum_id = bbp_get_forum_id( $forum_id );
815 $reply_id = get_post_meta( $forum_id, '_bbp_last_reply_id', true );
816
817 if ( empty( $reply_id ) )
818 $reply_id = bbp_get_forum_last_topic_id( $forum_id );
819
820 return apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
821 }
822
823 /**
824 * Output the title of the last reply inside a forum
825 *
826 * @param int $forum_id Optional. Forum id
827 * @uses bbp_get_forum_last_reply_title() To get the forum's last reply's title
828 */
829 function bbp_forum_last_reply_title( $forum_id = 0 ) {
830 echo bbp_get_forum_last_reply_title( $forum_id );
831 }
832 /**
833 * Return the title of the last reply inside a forum
834 *
835 * @param int $forum_id Optional. Forum id
836 * @uses bbp_get_forum_id() To get the forum id
837 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
838 * @uses bbp_get_reply_title() To get the reply title
839 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_title' with the
840 * reply title and forum id
841 * @return string
842 */
843 function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
844 $forum_id = bbp_get_forum_id( $forum_id );
845 return apply_filters( 'bbp_get_forum_last_reply_title', bbp_get_reply_title( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
846 }
847
848 /**
849 * Output the link to the last reply in a forum
850 *
851 * @since bbPress (r2464)
852 *
853 * @param int $forum_id Optional. Forum id
854 * @uses bbp_get_forum_last_reply_permalink() To get the forum last reply link
855 */
856 function bbp_forum_last_reply_permalink( $forum_id = 0 ) {
857 echo bbp_get_forum_last_reply_permalink( $forum_id );
858 }
859 /**
860 * Return the link to the last reply in a forum
861 *
862 * @since bbPress (r2464)
863 *
864 * @param int $forum_id Optional. Forum id
865 * @uses bbp_get_forum_id() To get the forum id
866 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
867 * @uses bbp_get_reply_permalink() To get the reply permalink
868 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_permalink' with
869 * the reply link and forum id
870 * @return string Permanent link to the forum's last reply
871 */
872 function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
873 $forum_id = bbp_get_forum_id( $forum_id );
874 return apply_filters( 'bbp_get_forum_last_reply_permalink', bbp_get_reply_permalink( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
875 }
876
877 /**
878 * Output the url to the last reply in a forum
879 *
880 * @since bbPress (r2683)
881 *
882 * @param int $forum_id Optional. Forum id
883 * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
884 */
885 function bbp_forum_last_reply_url( $forum_id = 0 ) {
886 echo bbp_get_forum_last_reply_url( $forum_id );
887 }
888 /**
889 * Return the url to the last reply in a forum
890 *
891 * @since bbPress (r2683)
892 *
893 * @param int $forum_id Optional. Forum id
894 * @uses bbp_get_forum_id() To get the forum id
895 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
896 * @uses bbp_get_reply_url() To get the reply url
897 * @uses bbp_get_forum_last_topic_permalink() To get the forum's last
898 * topic's permalink
899 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_url' with the
900 * reply url and forum id
901 * @return string Paginated URL to latest reply
902 */
903 function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
904 $forum_id = bbp_get_forum_id( $forum_id );
905
906 // If forum has replies, get the last reply and use its url
907 if ( $reply_id = bbp_get_forum_last_reply_id( $forum_id ) ) {
908 $reply_url = bbp_get_reply_url( $reply_id );
909
910 // No replies, so look for topics and use last permalink
911 } else {
912 if ( !$reply_url = bbp_get_forum_last_topic_permalink( $forum_id ) ) {
913 // No topics either, so set $reply_url as empty
914 $reply_url = '';
915 }
916 }
917
918 // Filter and return
919 return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id );
920 }
921
922 /**
923 * Output author ID of last reply of forum
924 *
925 * @since bbPress (r2625)
926 *
927 * @param int $forum_id Optional. Forum id
928 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last reply
929 * author id
930 */
931 function bbp_forum_last_reply_author_id( $forum_id = 0 ) {
932 echo bbp_get_forum_last_reply_author_id( $forum_id );
933 }
934 /**
935 * Return author ID of last reply of forum
936 *
937 * @since bbPress (r2625)
938 *
939 * @param int $forum_id Optional. Forum id
940 * @uses bbp_get_forum_id() To get the forum id
941 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
942 * reply's author id
943 * @uses bbp_get_reply_author_id() To get the reply's author id
944 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_id' with
945 * the author id and forum id
946 * @return int Forum's last reply author id
947 */
948 function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
949 $forum_id = bbp_get_forum_id( $forum_id );
950 $author_id = bbp_get_reply_author_id( bbp_get_forum_last_reply_id( $forum_id ) );
951 return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id );
952 }
953
954 /**
955 * Output link to author of last reply of forum
956 *
957 * @since bbPress (r2625)
958 *
959 * @param int $forum_id Optional. Forum id
960 * @uses bbp_get_forum_last_reply_author_link() To get the forum's last reply's
961 * author link
962 */
963 function bbp_forum_last_reply_author_link( $forum_id = 0 ) {
964 echo bbp_get_forum_last_reply_author_link( $forum_id );
965 }
966 /**
967 * Return link to author of last reply of forum
968 *
969 * @since bbPress (r2625)
970 *
971 * @param int $forum_id Optional. Forum id
972 * @uses bbp_get_forum_id() To get the forum id
973 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
974 * reply's author id
975 * @uses bbp_get_user_profile_link() To get the reply's author's profile
976 * link
977 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_link'
978 * with the author link and forum id
979 * @return string Link to author of last reply of forum
980 */
981 function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
982 $forum_id = bbp_get_forum_id( $forum_id );
983 $author_id = bbp_get_forum_last_reply_author_id( $forum_id );
984 $author_link = bbp_get_user_profile_link( $author_id );
985 return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id );
986 }
987
988 /** Forum Counts **************************************************************/
989
990 /**
991 * Output the topics link of the forum
992 *
993 * @since bbPress (r2883)
994 *
995 * @param int $forum_id Optional. Topic id
996 * @uses bbp_get_forum_topics_link() To get the forum topics link
997 */
998 function bbp_forum_topics_link( $forum_id = 0 ) {
999 echo bbp_get_forum_topics_link( $forum_id );
1000 }
1001
1002 /**
1003 * Return the topics link of the forum
1004 *
1005 * @since bbPress (r2883)
1006 *
1007 * @param int $forum_id Optional. Topic id
1008 * @uses bbp_get_forum_id() To get the forum id
1009 * @uses bbp_get_forum() To get the forum
1010 * @uses bbp_get_forum_topic_count() To get the forum topic count
1011 * @uses bbp_get_forum_permalink() To get the forum permalink
1012 * @uses remove_query_arg() To remove args from the url
1013 * @uses bbp_get_forum_hidden_topic_count() To get the forum hidden
1014 * topic count
1015 * @uses current_user_can() To check if the current user can edit others
1016 * topics
1017 * @uses add_query_arg() To add custom args to the url
1018 * @uses apply_filters() Calls 'bbp_get_forum_topics_link' with the
1019 * topics link and forum id
1020 */
1021 function bbp_get_forum_topics_link( $forum_id = 0 ) {
1022 global $bbp;
1023
1024 $forum = bbp_get_forum( bbp_get_forum_id( (int) $forum_id ) );
1025 $forum_id = $forum->ID;
1026 $topics = bbp_get_forum_topic_count( $forum_id );
1027 $topics = sprintf( _n( '%s topic', '%s topics', $topics, 'bbpress' ), $topics );
1028 $retval = '';
1029
1030 if ( !empty( $_GET['view'] ) && 'all' == $_GET['view'] && current_user_can( 'edit_others_topics' ) )
1031 $retval .= "<a href='" . esc_url( remove_query_arg( array( 'view' => 'all' ), bbp_get_forum_permalink( $forum_id ) ) ) . "'>$topics</a>";
1032 else
1033 $retval .= $topics;
1034
1035 if ( current_user_can( 'edit_others_topics' ) && $deleted = bbp_get_forum_hidden_topic_count( $forum_id ) ) {
1036 $extra = sprintf( __( ' + %d more', 'bbpress' ), $deleted );
1037 if ( !empty( $_GET['view'] ) && 'all' == $_GET['view'] )
1038 $retval .= " $extra";
1039 else
1040 $retval .= " <a href='" . esc_url( add_query_arg( array( 'view' => 'all' ) ) ) . "'>$extra</a>";
1041 }
1042
1043 return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
1044 }
1045
1046 /**
1047 * Output total sub-forum count of a forum
1048 *
1049 * @since bbPress (r2464)
1050 *
1051 * @uses bbp_get_forum_subforum_count() To get the forum's subforum count
1052 * @param int $forum_id Optional. Forum id to check
1053 */
1054 function bbp_forum_subforum_count( $forum_id = 0 ) {
1055 echo bbp_get_forum_subforum_count( $forum_id );
1056 }
1057 /**
1058 * Return total subforum count of a forum
1059 *
1060 * @since bbPress (r2464)
1061 *
1062 * @param int $forum_id Optional. Forum id
1063 * @uses bbp_get_forum_id() To get the forum id
1064 * @uses get_post_meta() To get the subforum count
1065 * @uses apply_filters() Calls 'bbp_get_forum_subforum_count' with the
1066 * subforum count and forum id
1067 * @return int Forum's subforum count
1068 */
1069 function bbp_get_forum_subforum_count( $forum_id = 0 ) {
1070 $forum_id = bbp_get_forum_id( $forum_id );
1071 $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
1072
1073 return apply_filters( 'bbp_get_forum_subforum_count', (int) $forum_count, $forum_id );
1074 }
1075
1076 /**
1077 * Output total topic count of a forum
1078 *
1079 * @since bbPress (r2464)
1080 *
1081 * @param int $forum_id Optional. Forum id
1082 * @param bool $total_count Optional. To get the total count or normal count?
1083 * @uses bbp_get_forum_topic_count() To get the forum topic count
1084 */
1085 function bbp_forum_topic_count( $forum_id = 0, $total_count = true ) {
1086 echo bbp_get_forum_topic_count( $forum_id );
1087 }
1088 /**
1089 * Return total topic count of a forum
1090 *
1091 * @since bbPress (r2464)
1092 *
1093 * @param int $forum_id Optional. Forum id
1094 * @param bool $total_count Optional. To get the total count or normal
1095 * count? Defaults to total.
1096 * @uses bbp_get_forum_id() To get the forum id
1097 * @uses get_post_meta() To get the forum topic count
1098 * @uses apply_filters() Calls 'bbp_get_forum_topic_count' with the
1099 * topic count and forum id
1100 * @return int Forum topic count
1101 */
1102 function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true ) {
1103 $forum_id = bbp_get_forum_id( $forum_id );
1104 $topics = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_forum_topic_count' : '_bbp_total_topic_count', true );
1105
1106 return apply_filters( 'bbp_get_forum_topic_count', (int) $topics, $forum_id );
1107 }
1108
1109 /**
1110 * Output total reply count of a forum
1111 *
1112 * @since bbPress (r2464)
1113 *
1114 * @param int $forum_id Optional. Forum id
1115 * @param bool $total_count Optional. To get the total count or normal count?
1116 * @uses bbp_get_forum_reply_count() To get the forum reply count
1117 */
1118 function bbp_forum_reply_count( $forum_id = 0, $total_count = true ) {
1119 echo bbp_get_forum_reply_count( $forum_id, $total_count );
1120 }
1121 /**
1122 * Return total post count of a forum
1123 *
1124 * @since bbPress (r2464)
1125 *
1126 * @param int $forum_id Optional. Forum id
1127 * @param bool $total_count Optional. To get the total count or normal
1128 * count?
1129 * @uses bbp_get_forum_id() To get the forum id
1130 * @uses get_post_meta() To get the forum reply count
1131 * @uses apply_filters() Calls 'bbp_get_forum_reply_count' with the
1132 * reply count and forum id
1133 * @return int Forum reply count
1134 */
1135 function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true ) {
1136 $forum_id = bbp_get_forum_id( $forum_id );
1137 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true );
1138
1139 return apply_filters( 'bbp_get_forum_reply_count', (int) $replies, $forum_id );
1140 }
1141
1142 /**
1143 * Output total post count of a forum
1144 *
1145 * @since bbPress (r2954)
1146 *
1147 * @param int $forum_id Optional. Forum id
1148 * @param bool $total_count Optional. To get the total count or normal count?
1149 * @uses bbp_get_forum_post_count() To get the forum post count
1150 */
1151 function bbp_forum_post_count( $forum_id = 0, $total_count = true ) {
1152 echo bbp_get_forum_post_count( $forum_id, $total_count );
1153 }
1154 /**
1155 * Return total post count of a forum
1156 *
1157 * @since bbPress (r2954)
1158 *
1159 * @param int $forum_id Optional. Forum id
1160 * @param bool $total_count Optional. To get the total count or normal
1161 * count?
1162 * @uses bbp_get_forum_id() To get the forum id
1163 * @uses get_post_meta() To get the forum post count
1164 * @uses apply_filters() Calls 'bbp_get_forum_post_count' with the
1165 * post count and forum id
1166 * @return int Forum post count
1167 */
1168 function bbp_get_forum_post_count( $forum_id = 0, $total_count = true ) {
1169 $forum_id = bbp_get_forum_id( $forum_id );
1170 $topics = bbp_get_forum_topic_count( $forum_id, $total_count );
1171 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true );
1172
1173 return apply_filters( 'bbp_get_forum_post_count', (int) $replies + (int) $topics, $forum_id );
1174 }
1175
1176 /**
1177 * Output total hidden topic count of a forum (hidden includes trashed and
1178 * spammed topics)
1179 *
1180 * @since bbPress (r2883)
1181 *
1182 * @param int $forum_id Optional. Topic id
1183 * @uses bbp_get_forum_hidden_topic_count() To get the forum hidden topic count
1184 */
1185 function bbp_forum_hidden_topic_count( $forum_id = 0 ) {
1186 echo bbp_get_forum_hidden_topic_count( $forum_id );
1187 }
1188 /**
1189 * Return total hidden topic count of a forum (hidden includes trashed
1190 * and spammed topics)
1191 *
1192 * @since bbPress (r2883)
1193 *
1194 * @param int $forum_id Optional. Topic id
1195 * @uses bbp_get_forum_id() To get the forum id
1196 * @uses get_post_meta() To get the hidden topic count
1197 * @uses apply_filters() Calls 'bbp_get_forum_hidden_topic_count' with
1198 * the hidden topic count and forum id
1199 * @return int Topic hidden topic count
1200 */
1201 function bbp_get_forum_hidden_topic_count( $forum_id = 0 ) {
1202 $forum_id = bbp_get_forum_id( $forum_id );
1203 $topics = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true );
1204
1205 return apply_filters( 'bbp_get_forum_hidden_topic_count', (int) $topics, $forum_id );
1206 }
1207
1208 /**
1209 * Output the status of the forum
1210 *
1211 * @since bbPress (r2667)
1212 *
1213 * @param int $forum_id Optional. Forum id
1214 * @uses bbp_get_forum_status() To get the forum status
1215 */
1216 function bbp_forum_status( $forum_id = 0 ) {
1217 echo bbp_get_forum_status( $forum_id );
1218 }
1219 /**
1220 * Return the status of the forum
1221 *
1222 * @since bbPress (r2667)
1223 *
1224 * @param int $forum_id Optional. Forum id
1225 * @uses bbp_get_forum_id() To get the forum id
1226 * @uses get_post_status() To get the forum's status
1227 * @uses apply_filters() Calls 'bbp_get_forum_status' with the status
1228 * and forum id
1229 * @return string Status of forum
1230 */
1231 function bbp_get_forum_status( $forum_id = 0 ) {
1232 $forum_id = bbp_get_forum_id( $forum_id );
1233
1234 return apply_filters( 'bbp_get_forum_status', get_post_meta( $forum_id, '_bbp_status', true ), $forum_id );
1235 }
1236
1237 /**
1238 * Output the visibility of the forum
1239 *
1240 * @since bbPress (r2997)
1241 *
1242 * @param int $forum_id Optional. Forum id
1243 * @uses bbp_get_forum_visibility() To get the forum visibility
1244 */
1245 function bbp_forum_visibility( $forum_id = 0 ) {
1246 echo bbp_get_forum_visibility( $forum_id );
1247 }
1248 /**
1249 * Return the visibility of the forum
1250 *
1251 * @since bbPress (r2997)
1252 *
1253 * @param int $forum_id Optional. Forum id
1254 * @uses bbp_get_forum_id() To get the forum id
1255 * @uses get_post_visibility() To get the forum's visibility
1256 * @uses apply_filters() Calls 'bbp_get_forum_visibility' with the visibility
1257 * and forum id
1258 * @return string Status of forum
1259 */
1260 function bbp_get_forum_visibility( $forum_id = 0 ) {
1261 $forum_id = bbp_get_forum_id( $forum_id );
1262
1263 return apply_filters( 'bbp_get_forum_visibility', get_post_status( $forum_id ), $forum_id );
1264 }
1265
1266 /**
1267 * Is the forum a category?
1268 *
1269 * @since bbPress (r2746)
1270 *
1271 * @param int $forum_id Optional. Forum id
1272 * @uses get_post_meta() To get the forum category meta
1273 * @return bool Whether the forum is a category or not
1274 */
1275 function bbp_is_forum_category( $forum_id = 0 ) {
1276 $forum_id = bbp_get_forum_id( $forum_id );
1277 $type = get_post_meta( $forum_id, '_bbp_forum_type', true );
1278 $retval = ( !empty( $type ) && 'category' == $type );
1279
1280 return apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id );
1281 }
1282
1283 /**
1284 * Is the forum open?
1285 *
1286 * @since bbPress (r2746)
1287 * @param int $forum_id Optional. Forum id
1288 *
1289 * @param int $forum_id Optional. Forum id
1290 * @uses bbp_is_forum_closed() To check if the forum is closed or not
1291 * @return bool Whether the forum is open or not
1292 */
1293 function bbp_is_forum_open( $forum_id = 0 ) {
1294 return !bbp_is_forum_closed( $forum_id );
1295 }
1296
1297 /**
1298 * Is the forum closed?
1299 *
1300 * @since bbPress (r2746)
1301 *
1302 * @param int $forum_id Optional. Forum id
1303 * @param bool $check_ancestors Check if the ancestors are closed (only
1304 * if they're a category)
1305 * @uses bbp_get_forum_status() To get the forum status
1306 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1307 * @uses bbp_is_forum_category() To check if the forum is a category
1308 * @uses bbp_is_forum_closed() To check if the forum is closed
1309 * @return bool True if closed, false if not
1310 */
1311 function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
1312 global $bbp;
1313
1314 $forum_id = bbp_get_forum_id( $forum_id );
1315 $retval = ( $bbp->closed_status_id == bbp_get_forum_status( $forum_id ) );
1316
1317 if ( !empty( $check_ancestors ) ) {
1318 $ancestors = bbp_get_forum_ancestors( $forum_id );
1319
1320 foreach ( (array) $ancestors as $ancestor ) {
1321 if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) {
1322 $retval = true;
1323 }
1324 }
1325 }
1326
1327 return apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
1328 }
1329
1330 /**
1331 * Is the forum public?
1332 *
1333 * @since bbPress (r2997)
1334 *
1335 * @param int $forum_id Optional. Forum id
1336 * @param bool $check_ancestors Check if the ancestors are public (only if
1337 * they're a category)
1338 * @uses get_post_meta() To get the forum public meta
1339 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1340 * @uses bbp_is_forum_category() To check if the forum is a category
1341 * @uses bbp_is_forum_closed() To check if the forum is closed
1342 * @return bool True if closed, false if not
1343 */
1344 function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
1345 global $bbp;
1346
1347 $forum_id = bbp_get_forum_id( $forum_id );
1348 $visibility = bbp_get_forum_visibility( $forum_id );
1349
1350 // If post status is public, return true
1351 $retval = ( 'publish' == $visibility );
1352
1353 // Check ancestors and inherit their privacy setting for display
1354 if ( !empty( $check_ancestors ) ) {
1355 $ancestors = bbp_get_forum_ancestors( $forum_id );
1356
1357 foreach ( (array) $ancestors as $ancestor ) {
1358 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) {
1359 $retval = true;
1360 }
1361 }
1362 }
1363
1364 return apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors );
1365 }
1366
1367 /**
1368 * Is the forum private?
1369 *
1370 * @since bbPress (r2746)
1371 *
1372 * @param int $forum_id Optional. Forum id
1373 * @param bool $check_ancestors Check if the ancestors are private (only if
1374 * they're a category)
1375 * @uses get_post_meta() To get the forum private meta
1376 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1377 * @uses bbp_is_forum_category() To check if the forum is a category
1378 * @uses bbp_is_forum_closed() To check if the forum is closed
1379 * @return bool True if closed, false if not
1380 */
1381 function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
1382 global $bbp;
1383
1384 $forum_id = bbp_get_forum_id( $forum_id );
1385 $visibility = bbp_get_forum_visibility( $forum_id );
1386
1387 // If post status is private, return true
1388 $retval = ( 'private' == $visibility );
1389
1390 // Check ancestors and inherit their privacy setting for display
1391 if ( !empty( $check_ancestors ) ) {
1392 $ancestors = bbp_get_forum_ancestors( $forum_id );
1393
1394 foreach ( (array) $ancestors as $ancestor ) {
1395 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) {
1396 $retval = true;
1397 }
1398 }
1399 }
1400
1401 return apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors );
1402 }
1403
1404 /**
1405 * Is the forum hidden?
1406 *
1407 * @since bbPress (r2997)
1408 *
1409 * @param int $forum_id Optional. Forum id
1410 * @param bool $check_ancestors Check if the ancestors are private (only if
1411 * they're a category)
1412 * @uses get_post_meta() To get the forum private meta
1413 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1414 * @uses bbp_is_forum_category() To check if the forum is a category
1415 * @uses bbp_is_forum_closed() To check if the forum is closed
1416 * @return bool True if closed, false if not
1417 */
1418 function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
1419 global $bbp;
1420
1421 $forum_id = bbp_get_forum_id( $forum_id );
1422 $visibility = bbp_get_forum_visibility( $forum_id );
1423
1424 // If post status is private, return true
1425 $retval = ( 'hidden' == $visibility );
1426
1427 // Check ancestors and inherit their privacy setting for display
1428 if ( !empty( $check_ancestors ) ) {
1429 $ancestors = bbp_get_forum_ancestors( $forum_id );
1430
1431 foreach ( (array) $ancestors as $ancestor ) {
1432 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) {
1433 $retval = true;
1434 }
1435 }
1436 }
1437
1438 return apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
1439 }
1440
1441 /**
1442 * Replace forum meta details for users that cannot view them.
1443 *
1444 * @since bbPress (r3162)
1445 *
1446 * @param string $retval
1447 * @param int $forum_id
1448 *
1449 * @uses bbp_is_forum_private()
1450 * @uses current_user_can()
1451 *
1452 * @return string
1453 */
1454 function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
1455 if ( bbp_is_forum_private( $forum_id, false ) && !current_user_can( 'read_private_forums' ) )
1456 $retval = '-';
1457
1458 return apply_filters( 'bbp_suppress_private_forum_meta', $retval );
1459 }
1460
1461 /**
1462 * Replace forum author details for users that cannot view them.
1463 *
1464 * @since bbPress (r3162)
1465 *
1466 * @param string $retval
1467 * @param int $forum_id
1468 *
1469 * @uses bbp_is_forum_private()
1470 * @uses get_post_field()
1471 * @uses bbp_get_topic_post_type()
1472 * @uses bbp_is_forum_private()
1473 * @uses bbp_get_topic_forum_id()
1474 * @uses bbp_get_reply_post_type()
1475 * @uses bbp_get_reply_forum_id()
1476 *
1477 * @return string
1478 */
1479 function bbp_suppress_private_author_link( $author_link, $args ) {
1480
1481 // Assume the author link is the return value
1482 $retval = $author_link;
1483
1484 // Show the normal author link
1485 if ( !empty( $args['post_id'] ) && !current_user_can( 'read_private_forums' ) ) {
1486
1487 // What post type are we looking at?
1488 $post_type = get_post_field( 'post_type', $args['post_id'] );
1489
1490 switch ( $post_type ) {
1491
1492 // Topic
1493 case bbp_get_topic_post_type() :
1494 if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) )
1495 $retval = '';
1496
1497 break;
1498
1499 // Reply
1500 case bbp_get_reply_post_type() :
1501 if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) )
1502 $retval = '';
1503
1504 break;
1505
1506 // Post
1507 default :
1508 if ( bbp_is_forum_private( $args['post_id'] ) )
1509 $retval = '';
1510
1511 break;
1512 }
1513 }
1514
1515 return apply_filters( 'bbp_suppress_private_author_link', $retval );
1516 }
1517
1518 /**
1519 * Output the row class of a forum
1520 *
1521 * @since bbPress (r2667)
1522 *
1523 * @uses bbp_get_forum_class() To get the row class of the forum
1524 */
1525 function bbp_forum_class() {
1526 echo bbp_get_forum_class();
1527 }
1528 /**
1529 * Return the row class of a forum
1530 *
1531 * @since bbPress (r2667)
1532 *
1533 * @uses post_class() To get all the classes including ours
1534 * @uses apply_filters() Calls 'bbp_get_forum_class' with the classes
1535 * @return string Row class of the forum
1536 */
1537 function bbp_get_forum_class() {
1538 global $bbp;
1539
1540 $classes = array();
1541 $classes[] = $bbp->forum_query->current_post % 2 ? 'even' : 'odd';
1542 $classes[] = bbp_is_forum_category() ? 'status-category' : '';
1543 $classes[] = bbp_is_forum_private() ? 'status-private' : '';
1544 $classes = array_filter( $classes );
1545
1546 $post = post_class( $classes );
1547
1548 return apply_filters( 'bbp_get_forum_class', $post );
1549 }
1550
1551 /** Single Forum **************************************************************/
1552
1553 /**
1554 * Output a fancy description of the current forum, including total topics,
1555 * total replies, and last activity.
1556 *
1557 * @since bbPress (r2860)
1558 *
1559 * @param array $args Arguments passed to alter output
1560 * @uses bbp_get_single_forum_description() Return the eventual output
1561 */
1562 function bbp_single_forum_description( $args = '' ) {
1563 echo bbp_get_single_forum_description( $args );
1564 }
1565 /**
1566 * Return a fancy description of the current forum, including total
1567 * topics, total replies, and last activity.
1568 *
1569 * @since bbPress (r2860)
1570 *
1571 * @param mixed $args This function supports these arguments:
1572 * - topic_id: Topic id
1573 * - before: Before the text
1574 * - after: After the text
1575 * - size: Size of the avatar
1576 * @uses bbp_get_forum_id() To get the forum id
1577 * @uses bbp_get_forum_topic_count() To get the forum topic count
1578 * @uses bbp_get_forum_reply_count() To get the forum reply count
1579 * @uses bbp_get_forum_subforum_count() To get the forum subforum count
1580 * @uses bbp_get_forum_freshness_link() To get the forum freshness link
1581 * @uses bbp_get_forum_last_active_id() To get the forum last active id
1582 * @uses bbp_get_author_link() To get the author link
1583 * @uses add_filter() To add the 'view all' filter back
1584 * @uses apply_filters() Calls 'bbp_get_single_forum_description' with
1585 * the description and args
1586 * @return string Filtered forum description
1587 */
1588 function bbp_get_single_forum_description( $args = '' ) {
1589 // Default arguments
1590 $defaults = array (
1591 'forum_id' => 0,
1592 'before' => '<div class="bbp-template-notice info"><p class="post-meta description">',
1593 'after' => '</p></div>',
1594 'size' => 14,
1595 'feed' => true
1596 );
1597 $r = wp_parse_args( $args, $defaults );
1598 extract( $r );
1599
1600 // Validate forum_id
1601 $forum_id = bbp_get_forum_id( $forum_id );
1602
1603 // Unhook the 'view all' query var adder
1604 remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1605
1606 // Build the forum description
1607 $topic_count = bbp_get_forum_topics_link ( $forum_id );
1608 $reply_count = bbp_get_forum_reply_count ( $forum_id );
1609 $subforum_count = bbp_get_forum_subforum_count( $forum_id );
1610 $time_since = bbp_get_forum_freshness_link( $forum_id );
1611
1612 // Singlular/Plural
1613 $reply_count = sprintf( _n( '%s reply', '%s replies', $reply_count, 'bbpress' ), $reply_count );
1614
1615 // Forum has posts
1616 if ( $last_reply = bbp_get_forum_last_active_id( $forum_id ) ) {
1617 $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $size ) );
1618 $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 );
1619
1620 // Forum has no last active data
1621 } else {
1622 $retstr = sprintf( __( 'This forum contains %1$s and %2$s replies.', 'bbpress' ), $topic_count, $reply_count );
1623 }
1624
1625 // Add feeds
1626 $feed_links = ( !empty( $feed ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : '';
1627
1628 // Add the 'view all' filter back
1629 add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1630
1631 // Combine the elements together
1632 $retstr = $before . $retstr . $after;
1633
1634 // Return filtered result
1635 return apply_filters( 'bbp_get_single_forum_description', $retstr, $args );
1636 }
1637
1638 /** Feeds *********************************************************************/
1639
1640 /**
1641 * Output the link for the forum feed
1642 *
1643 * @since bbPress (r3172)
1644 *
1645 * @param type $forum_id Optional. Forum ID.
1646 *
1647 * @uses bbp_get_forum_topics_feed_link()
1648 */
1649 function bbp_forum_topics_feed_link( $forum_id = 0 ) {
1650 echo bbp_get_forum_topics_feed_link( $forum_id );
1651 }
1652 /**
1653 * Retrieve the link for the forum feed
1654 *
1655 * @since bbPress (r3172)
1656 *
1657 * @param int $forum_id Optional. Forum ID.
1658 *
1659 * @uses bbp_get_forum_id()
1660 * @uses get_option()
1661 * @uses trailingslashit()
1662 * @uses bbp_get_forum_permalink()
1663 * @uses user_trailingslashit()
1664 * @uses bbp_get_forum_post_type()
1665 * @uses get_post_field()
1666 * @uses apply_filters()
1667 *
1668 * @return string
1669 */
1670 function bbp_get_forum_topics_feed_link( $forum_id = 0 ) {
1671
1672 // Validate forum id
1673 $forum_id = bbp_get_forum_id( $forum_id );
1674
1675 // Forum is valid
1676 if ( !empty( $forum_id ) ) {
1677
1678 // Prevent debug notices
1679 $link = '';
1680
1681 // Pretty permalinks
1682 if ( get_option( 'permalink_structure' ) ) {
1683
1684 // Forum link
1685 $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
1686 $url = user_trailingslashit( $url, 'single_feed' );
1687
1688 // Unpretty permalinks
1689 } else {
1690 $url = home_url( add_query_arg( array(
1691 'feed' => 'rss2',
1692 bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
1693 ) ) );
1694 }
1695
1696 $link = '<a href="' . $url . '" class="bbp-forum-rss-link topics"><span>' . __( 'Topics', 'bbpress' ) . '</span></a>';
1697 }
1698
1699 return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id );
1700 }
1701
1702 /**
1703 * Output the link for the forum replies feed
1704 *
1705 * @since bbPress (r3172)
1706 *
1707 * @param type $forum_id Optional. Forum ID.
1708 *
1709 * @uses bbp_get_forum_replies_feed_link()
1710 */
1711 function bbp_forum_replies_feed_link( $forum_id = 0 ) {
1712 echo bbp_get_forum_replies_feed_link( $forum_id );
1713 }
1714 /**
1715 * Retrieve the link for the forum replies feed
1716 *
1717 * @since bbPress (r3172)
1718 *
1719 * @param int $forum_id Optional. Forum ID.
1720 *
1721 * @uses bbp_get_forum_id()
1722 * @uses get_option()
1723 * @uses trailingslashit()
1724 * @uses bbp_get_forum_permalink()
1725 * @uses user_trailingslashit()
1726 * @uses bbp_get_forum_post_type()
1727 * @uses get_post_field()
1728 * @uses apply_filters()
1729 *
1730 * @return string
1731 */
1732 function bbp_get_forum_replies_feed_link( $forum_id = 0 ) {
1733
1734 // Validate forum id
1735 $forum_id = bbp_get_forum_id( $forum_id );
1736
1737 // Forum is valid
1738 if ( !empty( $forum_id ) ) {
1739
1740 // Prevent debug notices
1741 $link = '';
1742
1743 // Pretty permalinks
1744 if ( get_option( 'permalink_structure' ) ) {
1745
1746 // Forum link
1747 $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
1748 $url = user_trailingslashit( $url, 'single_feed' );
1749 $url = add_query_arg( array( 'type' => 'reply' ), $url );
1750
1751 // Unpretty permalinks
1752 } else {
1753 $url = home_url( add_query_arg( array(
1754 'type' => 'reply',
1755 'feed' => 'rss2',
1756 bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
1757 ) ) );
1758 }
1759
1760 $link = '<a href="' . $url . '" class="bbp-forum-rss-link replies"><span>' . __( 'Replies', 'bbpress' ) . '</span></a>';
1761 }
1762
1763 return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id );
1764 }
1765
1766 ?>
1767