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

bbp-common-functions.php in bbPress 2.0-beta-3b, at bbp-includes/bbp-common-functions.php

1,337 lines 44.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 Common Functions
5 *
6 * @package bbPress
7 * @subpackage Functions
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Post Meta *****************************************************************/
14
15 /**
16 * Update a posts forum meta ID
17 *
18 * @since bbPress (r3181)
19 *
20 * @param int $post_id The post to update
21 * @param int $forum_id The forum
22 */
23 function bbp_update_forum_id( $post_id, $forum_id ) {
24
25 // Allow the forum ID to be updated 'just in time' before save
26 $forum_id = apply_filters( 'bbp_update_forum_id', $forum_id, $post_id );
27
28 // Update the post meta forum ID
29 update_post_meta( $post_id, '_bbp_forum_id', (int) $forum_id );
30 }
31
32 /**
33 * Update a posts topic meta ID
34 *
35 * @since bbPress (r3181)
36 *
37 * @param int $post_id The post to update
38 * @param int $forum_id The forum
39 */
40 function bbp_update_topic_id( $post_id, $topic_id ) {
41
42 // Allow the topic ID to be updated 'just in time' before save
43 $topic_id = apply_filters( 'bbp_update_topic_id', $topic_id, $post_id );
44
45 // Update the post meta topic ID
46 update_post_meta( $post_id, '_bbp_topic_id', (int) $topic_id );
47 }
48
49 /**
50 * Update a posts reply meta ID
51 *
52 * @since bbPress (r3181)
53 *
54 * @param int $post_id The post to update
55 * @param int $forum_id The forum
56 */
57 function bbp_update_reply_id( $post_id, $reply_id ) {
58
59 // Allow the reply ID to be updated 'just in time' before save
60 $reply_id = apply_filters( 'bbp_update_reply_id', $reply_id, $post_id );
61
62 // Update the post meta reply ID
63 update_post_meta( $post_id, '_bbp_reply_id',(int) $reply_id );
64 }
65
66 /** Formatting ****************************************************************/
67
68 /**
69 * A bbPress specific method of formatting numeric values
70 *
71 * @since bbPress (r2486)
72 *
73 * @param string $number Number to format
74 * @param string $decimals Optional. Display decimals
75 * @uses apply_filters() Calls 'bbp_number_format' with the formatted values,
76 * number and display decimals bool
77 * @return string Formatted string
78 */
79 function bbp_number_format( $number, $decimals = false ) {
80
81 // If empty, set $number to '0'
82 if ( empty( $number ) || !is_numeric( $number ) )
83 $number = '0';
84
85 return apply_filters( 'bbp_number_format', number_format( $number, $decimals ), $number, $decimals );
86 }
87
88 /**
89 * Convert time supplied from database query into specified date format.
90 *
91 * @since bbPress (r2455)
92 *
93 * @param int|object $post Optional. Default is global post object. A post_id or
94 * post object
95 * @param string $d Optional. Default is 'U'. Either 'G', 'U', or php date
96 * format
97 * @param bool $translate Optional. Default is false. Whether to translate the
98 * result
99 * @uses mysql2date() To convert the format
100 * @uses apply_filters() Calls 'bbp_convert_date' with the time, date format
101 * and translate bool
102 * @return string Returns timestamp
103 */
104 function bbp_convert_date( $time, $d = 'U', $translate = false ) {
105 $time = mysql2date( $d, $time, $translate );
106
107 return apply_filters( 'bbp_convert_date', $time, $d, $translate );
108 }
109
110 /**
111 * Output formatted time to display human readable time difference.
112 *
113 * @since bbPress (r2544)
114 *
115 * @param $time Unix timestamp from which the difference begins.
116 * @uses bbp_get_time_since() To get the formatted time
117 */
118 function bbp_time_since( $time ) {
119 echo bbp_get_time_since( $time );
120 }
121 /**
122 * Return formatted time to display human readable time difference.
123 *
124 * @since bbPress (r2544)
125 *
126 * @param $time Unix timestamp from which the difference begins.
127 * @uses current_time() To get the current time in mysql format
128 * @uses human_time_diff() To get the time differene in since format
129 * @uses apply_filters() Calls 'bbp_get_time_since' with the time
130 * difference and time
131 * @return string Formatted time
132 */
133 function bbp_get_time_since( $time ) {
134 return apply_filters( 'bbp_get_time_since', human_time_diff( $time, current_time( 'timestamp' ) ), $time );
135 }
136
137 /**
138 * Formats the reason for editing the topic/reply.
139 *
140 * Does these things:
141 * - Trimming
142 * - Removing periods from the end of the string
143 * - Trimming again
144 *
145 * @since bbPress (r2782)
146 *
147 * @param int $topic_id Optional. Topic id
148 * @return string Status of topic
149 */
150 function bbp_format_revision_reason( $reason = '' ) {
151 $reason = (string) $reason;
152
153 // Format reason for proper display
154 if ( empty( $reason ) )
155 return $reason;
156
157 // Trimming
158 $reason = trim( $reason );
159
160 // We add our own full stop.
161 while ( substr( $reason, -1 ) == '.' )
162 $reason = substr( $reason, 0, -1 );
163
164 // Trim again
165 $reason = trim( $reason );
166
167 return $reason;
168 }
169
170 /** Misc **********************************************************************/
171
172 /**
173 * The plugin version of bbPress comes with two topic display options:
174 * - Traditional: Topics are included in the reply loop (default)
175 * - New Style: Topics appear as "lead" posts, ahead of replies
176 *
177 * @since bbPress (r2954)
178 *
179 * @param $show_lead Optional. Default false
180 * @return bool Yes if the topic appears as a lead, otherwise false
181 */
182 function bbp_show_lead_topic( $show_lead = false ) {
183 return apply_filters( 'bbp_show_lead_topic', (bool) $show_lead );
184 }
185
186 /**
187 * Append 'view=all' to query string if it's already there from referer
188 *
189 * @since bbPress (r3325)
190 *
191 * @param string $original_link Original Link to be modified
192 * @param bool $force Override bbp_get_view_all() check
193 * @uses current_user_can() To check if the current user can moderate
194 * @uses add_query_arg() To add args to the url
195 * @uses apply_filters() Calls 'bbp_add_view_all' with the link and original link
196 * @return string The link with 'view=all' appended if necessary
197 */
198 function bbp_add_view_all( $original_link = '', $force = false ) {
199
200 // Are we appending the view=all vars?
201 if ( bbp_get_view_all() || !empty( $force ) )
202 $link = add_query_arg( array( 'view' => 'all' ), $original_link );
203 else
204 $link = $original_link;
205
206 return apply_filters( 'bbp_add_view_all', $link, $original_link );
207 }
208
209 /**
210 * Remove 'view=all' from query string
211 *
212 * @since bbPress (r3325)
213 *
214 * @param string $original_link Original Link to be modified
215 * @uses current_user_can() To check if the current user can moderate
216 * @uses add_query_arg() To add args to the url
217 * @uses apply_filters() Calls 'bbp_add_view_all' with the link and original link
218 * @return string The link with 'view=all' appended if necessary
219 */
220 function bbp_remove_view_all( $original_link = '' ) {
221
222 // Are we appending the view=all vars?
223 $link = remove_query_arg( 'view', $original_link );
224
225 return apply_filters( 'bbp_add_view_all', $link, $original_link );
226 }
227
228 /**
229 * If current user can and is vewing all topics/replies
230 *
231 * @since bbPress (r3325)
232 *
233 * @uses current_user_can() To check if the current user can moderate
234 * @uses apply_filters() Calls 'bbp_get_view_all' with the link and original link
235 * @return bool Whether current user can and is viewing all
236 */
237 function bbp_get_view_all( $cap = 'moderate' ) {
238
239 $retval = ( ( !empty( $_GET['view'] ) && ( 'all' == $_GET['view'] ) && current_user_can( $cap ) ) );
240
241 return apply_filters( 'bbp_get_view_all', (bool) $retval );
242 }
243
244 /**
245 * Assist pagination by returning correct page number
246 *
247 * @since bbPress (r2628)
248 *
249 * @uses get_query_var() To get the 'paged' value
250 * @return int Current page number
251 */
252 function bbp_get_paged() {
253
254 // Make sure to not paginate widget queries
255 if ( !bbp_is_query_name( 'bbp_widget' ) && ( $paged = get_query_var( 'paged' ) ) )
256 return (int) $paged;
257
258 // Default to first page
259 return 1;
260 }
261
262 /**
263 * Fix post author id on post save
264 *
265 * When a logged in user changes the status of an anonymous reply or topic, or
266 * edits it, the post_author field is set to the logged in user's id. This
267 * function fixes that.
268 *
269 * @since bbPress (r2734)
270 *
271 * @param array $data Post data
272 * @param array $postarr Original post array (includes post id)
273 * @uses bbp_get_topic_post_type() To get the topic post type
274 * @uses bbp_get_reply_post_type() To get the reply post type
275 * @uses bbp_is_topic_anonymous() To check if the topic is by an anonymous user
276 * @uses bbp_is_reply_anonymous() To check if the reply is by an anonymous user
277 * @return array Data
278 */
279 function bbp_fix_post_author( $data = array(), $postarr = array() ) {
280 global $bbp;
281
282 // Post is not being updated or the post_author is already 0, return
283 if ( empty( $postarr['ID'] ) || empty( $data['post_author'] ) )
284 return $data;
285
286 // Post is not a topic or reply, return
287 if ( !in_array( $data['post_type'], array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) )
288 return $data;
289
290 // Is the post by an anonymous user?
291 if ( ( bbp_get_topic_post_type() == $data['post_type'] && !bbp_is_topic_anonymous( $postarr['ID'] ) ) ||
292 ( bbp_get_reply_post_type() == $data['post_type'] && !bbp_is_reply_anonymous( $postarr['ID'] ) ) )
293 return $data;
294
295 // The post is being updated. It is a topic or a reply and is written by an anonymous user.
296 // Set the post_author back to 0
297 $data['post_author'] = 0;
298
299 return $data;
300 }
301
302 /**
303 * Check the date against the _bbp_edit_lock setting.
304 *
305 * @since bbPress (r3133)
306 *
307 * @param string $post_date_gmt
308 *
309 * @uses get_option() Get the edit lock time
310 * @uses current_time() Get the current time
311 * @uses strtotime() Convert strings to time
312 * @uses apply_filters() Allow output to be manipulated
313 *
314 * @return bool
315 */
316 function bbp_past_edit_lock( $post_date_gmt ) {
317
318 // Assume editing is allowed
319 $retval = false;
320
321 // Bail if empty date
322 if ( ! empty( $post_date_gmt ) ) {
323
324 // Period of time
325 $lockable = '+' . get_option( '_bbp_edit_lock', '5' ) . ' minutes';
326
327 // Now
328 $cur_time = current_time( 'timestamp', true );
329
330 // Add lockable time to post time
331 $lock_time = strtotime( $lockable, strtotime( $post_date_gmt ) );
332
333 // Compare
334 if ( $cur_time >= $lock_time ) {
335 $retval = true;
336 }
337 }
338
339 return apply_filters( 'bbp_past_edit_lock', (bool) $retval, $cur_time, $lock_time, $post_date_gmt );
340 }
341
342 /** Statistics ****************************************************************/
343
344 /**
345 * Get the forum statistics
346 *
347 * @since bbPress (r2769)
348 *
349 * @param mixed $args Optional. The function supports these arguments (all
350 * default to true):
351 * - count_users: Count users?
352 * - count_forums: Count forums?
353 * - count_topics: Count topics? If set to false, private, spammed and trashed
354 * topics are also not counted.
355 * - count_private_topics: Count private topics? (only counted if the current
356 * user has read_private_topics cap)
357 * - count_spammed_topics: Count spammed topics? (only counted if the current
358 * user has edit_others_topics cap)
359 * - count_trashed_topics: Count trashed topics? (only counted if the current
360 * user has view_trash cap)
361 * - count_replies: Count replies? If set to false, private, spammed and
362 * trashed replies are also not counted.
363 * - count_private_replies: Count private replies? (only counted if the current
364 * user has read_private_replies cap)
365 * - count_spammed_replies: Count spammed replies? (only counted if the current
366 * user has edit_others_replies cap)
367 * - count_trashed_replies: Count trashed replies? (only counted if the current
368 * user has view_trash cap)
369 * - count_tags: Count tags? If set to false, empty tags are also not counted
370 * - count_empty_tags: Count empty tags?
371 * @uses bbp_count_users() To count the number of registered users
372 * @uses bbp_get_forum_post_type() To get the forum post type
373 * @uses bbp_get_topic_post_type() To get the topic post type
374 * @uses bbp_get_reply_post_type() To get the reply post type
375 * @uses wp_count_posts() To count the number of forums, topics and replies
376 * @uses wp_count_terms() To count the number of topic tags
377 * @uses current_user_can() To check if the user is capable of doing things
378 * @uses number_format_i18n() To format the number
379 * @uses apply_filters() Calls 'bbp_get_statistics' with the statistics and args
380 * @return object Walked forum tree
381 */
382 function bbp_get_statistics( $args = '' ) {
383 global $bbp;
384
385 $defaults = array (
386 'count_users' => true,
387 'count_forums' => true,
388 'count_topics' => true,
389 'count_private_topics' => true,
390 'count_spammed_topics' => true,
391 'count_trashed_topics' => true,
392 'count_replies' => true,
393 'count_private_replies' => true,
394 'count_spammed_replies' => true,
395 'count_trashed_replies' => true,
396 'count_tags' => true,
397 'count_empty_tags' => true
398 );
399
400 $r = wp_parse_args( $args, $defaults );
401 extract( $r );
402
403 // Users
404 if ( !empty( $count_users ) )
405 $user_count = bbp_get_total_users();
406
407 // Forums
408 if ( !empty( $count_forums ) ) {
409 $forum_count = wp_count_posts( bbp_get_forum_post_type() );
410 $forum_count = $forum_count->publish;
411 }
412
413 // Topics
414 if ( !empty( $count_topics ) ) {
415
416 $all_topics = wp_count_posts( bbp_get_topic_post_type() );
417
418 // Published (publish + closed)
419 $topic_count = $all_topics->publish + $all_topics->{$bbp->closed_status_id};
420
421 if ( current_user_can( 'read_private_topics' ) || current_user_can( 'edit_others_topics' ) || current_user_can( 'view_trash' ) ) {
422
423 // Private
424 $topics['private'] = ( !empty( $count_private_topics ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->private : 0;
425
426 // Spam
427 $topics['spammed'] = ( !empty( $count_spammed_topics ) && current_user_can( 'edit_others_topics' ) ) ? (int) $all_topics->{$bbp->spam_status_id} : 0;
428
429 // Trash
430 $topics['trashed'] = ( !empty( $count_trashed_topics ) && current_user_can( 'view_trash' ) ) ? (int) $all_topics->{$bbp->trash_status_id} : 0;
431
432 // Total hidden (private + spam + trash)
433 $hidden_topic_count = $topics['private'] + $topics['spammed'] + $topics['trashed'];
434
435 // Generate the hidden topic count's title attribute
436 $topic_titles[] = !empty( $topics['private'] ) ? sprintf( __( 'Private: %s', 'bbpress' ), number_format_i18n( $topics['private'] ) ) : '';
437 $topic_titles[] = !empty( $topics['spammed'] ) ? sprintf( __( 'Spammed: %s', 'bbpress' ), number_format_i18n( $topics['spammed'] ) ) : '';
438 $topic_titles[] = !empty( $topics['trashed'] ) ? sprintf( __( 'Trashed: %s', 'bbpress' ), number_format_i18n( $topics['trashed'] ) ) : '';
439
440 // Compile the hidden topic title
441 $hidden_topic_title = implode( ' | ', array_filter( $topic_titles ) );
442 }
443 }
444
445 // Replies
446 if ( !empty( $count_replies ) ) {
447
448 $all_replies = wp_count_posts( bbp_get_reply_post_type() );
449
450 // Published
451 $reply_count = $all_replies->publish;
452
453 if ( current_user_can( 'read_private_replies' ) || current_user_can( 'edit_others_replies' ) || current_user_can( 'view_trash' ) ) {
454
455 // Private
456 $replies['private'] = ( !empty( $count_private_replies ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->private : 0;
457
458 // Spam
459 $replies['spammed'] = ( !empty( $count_spammed_replies ) && current_user_can( 'edit_others_replies' ) ) ? (int) $all_replies->{$bbp->spam_status_id} : 0;
460
461 // Trash
462 $replies['trashed'] = ( !empty( $count_trashed_replies ) && current_user_can( 'view_trash' ) ) ? (int) $all_replies->{$bbp->trash_status_id} : 0;
463
464 // Total hidden (private + spam + trash)
465 $hidden_reply_count = $replies['private'] + $replies['spammed'] + $replies['trashed'];
466
467 // Generate the hidden topic count's title attribute
468 $reply_titles[] = !empty( $replies['private'] ) ? sprintf( __( 'Private: %s', 'bbpress' ), number_format_i18n( $replies['private'] ) ) : '';
469 $reply_titles[] = !empty( $replies['spammed'] ) ? sprintf( __( 'Spammed: %s', 'bbpress' ), number_format_i18n( $replies['spammed'] ) ) : '';
470 $reply_titles[] = !empty( $replies['trashed'] ) ? sprintf( __( 'Trashed: %s', 'bbpress' ), number_format_i18n( $replies['trashed'] ) ) : '';
471
472 // Compile the hidden replies title
473 $hidden_reply_title = implode( ' | ', array_filter( $reply_titles ) );
474
475 }
476 }
477
478 // Topic Tags
479 if ( !empty( $count_tags ) ) {
480
481 // Get the count
482 $topic_tag_count = wp_count_terms( $bbp->topic_tag_id, array( 'hide_empty' => true ) );
483
484 // Empty tags
485 if ( !empty( $count_empty_tags ) && current_user_can( 'edit_topic_tags' ) ) {
486 $empty_topic_tag_count = wp_count_terms( $bbp->topic_tag_id ) - $topic_tag_count;
487 }
488 }
489
490 // Tally the tallies
491 $statistics = compact( 'user_count', 'forum_count', 'topic_count', 'hidden_topic_count', 'reply_count', 'hidden_reply_count', 'topic_tag_count', 'empty_topic_tag_count' );
492 $statistics = array_map( 'absint', $statistics );
493 $statistics = array_map( 'number_format_i18n', $statistics );
494
495 // Add the hidden (topic/reply) count title attribute strings because we don't need to run the math functions on these (see above)
496 if ( isset( $hidden_topic_title ) )
497 $statistics['hidden_topic_title'] = $hidden_topic_title;
498
499 if ( isset( $hidden_reply_title ) )
500 $statistics['hidden_reply_title'] = $hidden_reply_title;
501
502 return apply_filters( 'bbp_get_statistics', $statistics, $args );
503 }
504
505 /** Views *********************************************************************/
506
507 /**
508 * Get the registered views
509 *
510 * Does nothing much other than return the {@link $bbp->views} variable
511 *
512 * @since bbPress (r2789)
513 *
514 * @return array Views
515 */
516 function bbp_get_views() {
517 global $bbp;
518
519 return $bbp->views;
520 }
521
522 /**
523 * Register a bbPress view
524 *
525 * @todo Implement feeds - See {@link http://trac.bbpress.org/ticket/1422}
526 *
527 * @since bbPress (r2789)
528 *
529 * @param string $view View name
530 * @param string $title View title
531 * @param mixed $query_args {@link bbp_has_topics()} arguments.
532 * @param bool $feed Have a feed for the view? Defaults to true. NOT IMPLEMENTED
533 * @uses sanitize_title() To sanitize the view name
534 * @uses esc_html() To sanitize the view title
535 * @return array The just registered (but processed) view
536 */
537 function bbp_register_view( $view, $title, $query_args = '', $feed = true ) {
538 global $bbp;
539
540 $view = sanitize_title( $view );
541 $title = esc_html( $title );
542
543 if ( empty( $view ) || empty( $title ) )
544 return false;
545
546 $query_args = wp_parse_args( $query_args );
547
548 // Set exclude_stickies to true if it wasn't supplied
549 if ( !isset( $query_args['show_stickies'] ) )
550 $query_args['show_stickies'] = false;
551
552 $bbp->views[$view]['title'] = $title;
553 $bbp->views[$view]['query'] = $query_args;
554 $bbp->views[$view]['feed'] = $feed;
555
556 return $bbp->views[$view];
557 }
558
559 /**
560 * Deregister a bbPress view
561 *
562 * @since bbPress (r2789)
563 *
564 * @param string $view View name
565 * @uses sanitize_title() To sanitize the view name
566 * @return bool False if the view doesn't exist, true on success
567 */
568 function bbp_deregister_view( $view ) {
569 global $bbp;
570
571 $view = sanitize_title( $view );
572
573 if ( !isset( $bbp->views[$view] ) )
574 return false;
575
576 unset( $bbp->views[$view] );
577
578 return true;
579 }
580
581 /**
582 * Run the view's query
583 *
584 * @since bbPress (r2789)
585 *
586 * @param string $view Optional. View id
587 * @param mixed $new_args New arguments. See {@link bbp_has_topics()}
588 * @uses bbp_get_view_id() To get the view id
589 * @uses bbp_get_view_query_args() To get the view query args
590 * @uses sanitize_title() To sanitize the view name
591 * @uses bbp_has_topics() To make the topics query
592 * @return bool False if the view doesn't exist, otherwise if topics are there
593 */
594 function bbp_view_query( $view = '', $new_args = '' ) {
595 global $bbp;
596
597 if ( !$view = bbp_get_view_id( $view ) )
598 return false;
599
600 $query_args = bbp_get_view_query_args( $view );
601
602 if ( !empty( $new_args ) ) {
603 $new_args = wp_parse_args( $new_args );
604 $query_args = array_merge( $query_args, $new_args );
605 }
606
607 return bbp_has_topics( $query_args );
608 }
609
610 /**
611 * Run the view's query's arguments
612 *
613 * @since bbPress (r2789)
614 *
615 * @param string $view View name
616 * @uses bbp_get_view_id() To get the view id
617 * @uses sanitize_title() To sanitize the view name
618 * @return array Query arguments
619 */
620 function bbp_get_view_query_args( $view ) {
621 global $bbp;
622
623 if ( !$views = bbp_get_view_id( $view ) )
624 return false;
625
626 return $bbp->views[$view]['query'];
627 }
628
629 /** New/edit topic/reply helpers **********************************************/
630
631 /**
632 * Filter anonymous post data
633 *
634 * We use REMOTE_ADDR here directly. If you are behind a proxy, you should
635 * ensure that it is properly set, such as in wp-config.php, for your
636 * environment. See {@link http://core.trac.wordpress.org/ticket/9235}
637 *
638 * If there are any errors, those are directly added to {@link bbPress:errors}
639 *
640 * @since bbPress (r2734)
641 *
642 * @param mixed $args Optional. If no args are there, then $_POST values are
643 * used.
644 * @param bool $is_edit Optional. Is the topic/reply being edited? There are no
645 * IP checks then.
646 * @uses apply_filters() Calls 'bbp_pre_anonymous_post_author_name' with the
647 * anonymous user name
648 * @uses apply_filters() Calls 'bbp_pre_anonymous_post_author_email' with the
649 * anonymous user email
650 * @uses apply_filters() Calls 'bbp_pre_anonymous_post_author_ip' with the
651 * anonymous user's ip address
652 * @uses apply_filters() Calls 'bbp_pre_anonymous_post_author_website' with the
653 * anonymous user website
654 * @return bool|array False on errors, values in an array on success
655 */
656 function bbp_filter_anonymous_post_data( $args = '', $is_edit = false ) {
657 global $bbp;
658
659 // Assign variables
660 $defaults = array (
661 'bbp_anonymous_name' => !empty( $_POST['bbp_anonymous_name'] ) ? $_POST['bbp_anonymous_name'] : false,
662 'bbp_anonymous_email' => !empty( $_POST['bbp_anonymous_email'] ) ? $_POST['bbp_anonymous_email'] : false,
663 'bbp_anonymous_website' => !empty( $_POST['bbp_anonymous_website'] ) ? $_POST['bbp_anonymous_website'] : false,
664 );
665
666 $r = wp_parse_args( $args, $defaults );
667 extract( $r );
668
669 // Filter variables and add errors if necessary
670 if ( !$bbp_anonymous_name = apply_filters( 'bbp_pre_anonymous_post_author_name', $bbp_anonymous_name ) )
671 $bbp->errors->add( 'bbp_anonymous_name', __( '<strong>ERROR</strong>: Invalid author name submitted!', 'bbpress' ) );
672
673 if ( !$bbp_anonymous_email = apply_filters( 'bbp_pre_anonymous_post_author_email', $bbp_anonymous_email ) )
674 $bbp->errors->add( 'bbp_anonymous_email', __( '<strong>ERROR</strong>: Invalid email address submitted!', 'bbpress' ) );
675
676 // Website is optional
677 $bbp_anonymous_website = apply_filters( 'bbp_pre_anonymous_post_author_website', $bbp_anonymous_website );
678
679 if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() )
680 $retval = compact( 'bbp_anonymous_name', 'bbp_anonymous_email', 'bbp_anonymous_website' );
681 else
682 $retval = false;
683
684 // Finally, return sanitized data or false
685 return apply_filters( 'bbp_filter_anonymous_post_data', $retval, $args );
686 }
687
688 /**
689 * Check for duplicate topics/replies
690 *
691 * Check to make sure that a user is not making a duplicate post
692 *
693 * @since bbPress (r2763)
694 *
695 * @param array $post_data Contains information about the comment
696 * @uses current_user_can() To check if the current user can throttle
697 * @uses get_meta_sql() To generate the meta sql for checking anonymous email
698 * @uses apply_filters() Calls 'bbp_check_for_duplicate_query' with the
699 * duplicate check query and post data
700 * @uses wpdb::get_var() To execute our query and get the var back
701 * @uses get_post_meta() To get the anonymous user email post meta
702 * @uses do_action() Calls 'bbp_post_duplicate_trigger' with the post data when
703 * it is found that it is a duplicate
704 * @return bool True if it is not a duplicate, false if it is
705 */
706 function bbp_check_for_duplicate( $post_data ) {
707
708 // No duplicate checks for those who can throttle
709 if ( current_user_can( 'throttle' ) )
710 return true;
711
712 global $bbp, $wpdb;
713
714 extract( $post_data, EXTR_SKIP );
715
716 // Check for anonymous post
717 if ( empty( $post_author ) && !empty( $anonymous_data['bbp_anonymous_email'] ) ) {
718
719 // WP 3.2
720 if ( function_exists( 'get_meta_sql' ) )
721 $clauses = get_meta_sql( array( array( 'key' => '_bbp_anonymous_email', 'value' => $anonymous_data['bbp_anonymous_email'] ) ), 'post', $wpdb->posts, 'ID' );
722
723 // WP 3.1
724 elseif ( function_exists( '_get_meta_sql' ) )
725 $clauses = _get_meta_sql( array( array( 'key' => '_bbp_anonymous_email', 'value' => $anonymous_data['bbp_anonymous_email'] ) ), 'post', $wpdb->posts, 'ID' );
726
727 $join = $clauses['join'];
728 $where = $clauses['where'];
729 } else{
730 $join = $where = '';
731 }
732
733 // Simple duplicate check
734 // Expected slashed ($post_type, $post_parent, $post_author, $post_content, $anonymous_data)
735 $dupe = "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = '{$post_type}' AND post_status != '{$bbp->trash_status_id}' AND post_author = {$post_author} AND post_content = '{$post_content}' {$where}";
736 $dupe .= !empty( $post_parent ) ? " AND post_parent = '{$post_parent}'" : '';
737 $dupe .= " LIMIT 1";
738 $dupe = apply_filters( 'bbp_check_for_duplicate_query', $dupe, $post_data );
739
740 if ( $wpdb->get_var( $dupe ) ) {
741 do_action( 'bbp_check_for_duplicate_trigger', $post_data );
742 return false;
743 }
744
745 return true;
746 }
747
748 /**
749 * Check for flooding
750 *
751 * Check to make sure that a user is not making too many posts in a short amount
752 * of time.
753 *
754 * @since bbPress (r2734)
755 *
756 * @param false|array $anonymous_data Optional - if it's an anonymous post. Do
757 * not supply if supplying $author_id.
758 * Should have key 'bbp_author_ip'.
759 * Should be sanitized (see
760 * {@link bbp_filter_anonymous_post_data()}
761 * for sanitization)
762 * @param int $author_id Optional. Supply if it's a post by a logged in user.
763 * Do not supply if supplying $anonymous_data.
764 * @uses get_option() To get the throttle time
765 * @uses get_transient() To get the last posted transient of the ip
766 * @uses get_user_meta() To get the last posted meta of the user
767 * @uses current_user_can() To check if the current user can throttle
768 * @return bool True if there is no flooding, true if there is
769 */
770 function bbp_check_for_flood( $anonymous_data = false, $author_id = 0 ) {
771
772 // Option disabled. No flood checks.
773 if ( !$throttle_time = get_option( '_bbp_throttle_time' ) )
774 return true;
775
776 if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) {
777 $last_posted = get_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted' );
778 if ( !empty( $last_posted ) && time() < $last_posted + $throttle_time )
779 return false;
780 } elseif ( !empty( $author_id ) ) {
781 $author_id = (int) $author_id;
782 $last_posted = get_user_meta( $author_id, '_bbp_last_posted', true );
783
784 if ( isset( $last_posted ) && time() < $last_posted + $throttle_time && !current_user_can( 'throttle' ) )
785 return false;
786 } else {
787 return false;
788 }
789
790 return true;
791 }
792
793 /** Subscriptions *************************************************************/
794
795 /**
796 * Sends notification emails for new posts
797 *
798 * Gets new post's ID and check if there are subscribed users to that topic, and
799 * if there are, send notifications
800 *
801 * @since bbPress (r2668)
802 *
803 * @todo When Akismet is made to work with bbPress posts, add a check if the
804 * post is spam or not, to avoid sending out mails for spam posts
805 *
806 * @param int $reply_id ID of the newly made reply
807 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
808 * @uses bbp_get_reply() To get the reply
809 * @uses bbp_get_topic() To get the reply's topic
810 * @uses get_the_author_meta() To get the author's display name
811 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id and
812 * topic id
813 * @uses bbp_get_topic_subscribers() To get the topic subscribers
814 * @uses apply_filters() Calls 'bbp_subscription_mail_message' with the
815 * message, reply id, topic id and user id
816 * @uses get_userdata() To get the user data
817 * @uses wp_mail() To send the mail
818 * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id
819 * and topic id
820 * @return bool True on success, false on failure
821 */
822 function bbp_notify_subscribers( $reply_id = 0 ) {
823 global $bbp, $wpdb;
824
825 if ( !bbp_is_subscriptions_active() )
826 return false;
827
828 if ( empty( $reply_id ) )
829 return false;
830
831 if ( !$reply = bbp_get_reply( $reply_id ) )
832 return false;
833
834 if ( empty( $reply->post_parent ) )
835 return false;
836
837 if ( !$topic = bbp_get_topic( $reply->post_parent ) )
838 return false;
839
840 if ( !$poster_name = get_the_author_meta( 'display_name', $reply->post_author ) )
841 return false;
842
843 do_action( 'bbp_pre_notify_subscribers', $reply->ID, $topic->ID );
844
845 // Get the users who have favorited the topic and have subscriptions on
846 if ( !$user_ids = bbp_get_topic_subscribers( $topic->ID, true ) )
847 return false;
848
849 // Loop through users
850 foreach ( (array) $user_ids as $user_id ) {
851
852 // Don't send notifications to the person who made the post
853 if ( $user_id == $reply->post_author )
854 continue;
855
856 // For plugins
857 if ( !$message = apply_filters( 'bbp_subscription_mail_message', __( "%1\$s wrote:\n\n%2\$s\n\nPost Link: %3\$s\n\nYou're getting this mail because you subscribed to the topic, visit the topic and login to unsubscribe." ), $reply->ID, $topic->ID, $user_id ) )
858 continue;
859
860 // Get user data of this user
861 $user = get_userdata( $user_id );
862
863 // Send notification email
864 wp_mail(
865 $user->user_email,
866 apply_filters( 'bbp_subscription_mail_title', '[' . get_option( 'blogname' ) . '] ' . $topic->post_title, $reply->ID, $topic->ID ),
867 sprintf( $message, $poster_name, strip_tags( $reply->post_content ), bbp_get_reply_url( $reply->ID ) )
868 );
869 }
870
871 do_action( 'bbp_post_notify_subscribers', $reply->ID, $topic->ID );
872
873 return true;
874 }
875
876 /** Login *********************************************************************/
877
878 /**
879 * Return a clean and reliable logout URL
880 *
881 * @param string $url URL
882 * @param string $redirect_to Where to redirect to?
883 * @uses add_query_arg() To add args to the url
884 * @uses apply_filters() Calls 'bbp_logout_url' with the url and redirect to
885 * @return string The url
886 */
887 function bbp_logout_url( $url = '', $redirect_to = '' ) {
888
889 // Rejig the $redirect_to
890 if ( !isset( $_SERVER['REDIRECT_URL'] ) || ( !$redirect_to = home_url( $_SERVER['REDIRECT_URL'] ) ) )
891 $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '';
892
893 // Make sure we are directing somewhere
894 if ( empty( $redirect_to ) )
895 $redirect_to = home_url( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' );
896
897 // Sanitize $redirect_to and add it to full $url
898 $redirect_to = esc_url( add_query_arg( array( 'loggedout' => 'true' ), $redirect_to ) );
899 $url = add_query_arg( array( 'redirect_to' => $redirect_to ), $url );
900
901 // Filter and return
902 return apply_filters( 'bbp_logout_url', $url, $redirect_to );
903 }
904
905 /** Queries *******************************************************************/
906
907 /**
908 * Adjusts topic and reply queries to exclude items that might be contained
909 * inside hidden or private forums that the user does not have the capability
910 * to view.
911 *
912 * @since bbPress (r3291)
913 *
914 * @param WP_Query $posts_query
915 *
916 * @uses apply_filters()
917 * @uses bbp_exclude_forum_ids()
918 * @uses bbp_get_topic_post_type()
919 * @uses bbp_get_reply_post_type()
920
921 * @return WP_Query
922 */
923 function bbp_pre_get_posts_exclude_forums( $posts_query ) {
924
925 // Bail if all forums are explicitly allowed
926 if ( true === apply_filters( 'bbp_include_all_forums', $posts_query ) )
927 return $posts_query;
928
929 // Bail if $posts_query is not an object or of incorrect class
930 if ( !is_object( $posts_query ) || ( 'WP_Query' != get_class( $posts_query ) ) )
931 return $posts_query;
932
933 // Bail if filters are suppressed on this query
934 if ( true == $posts_query->get( 'suppress_filters' ) )
935 return $posts_query;
936
937 // There are forums that need to be excluded
938 if ( $forum_ids = bbp_exclude_forum_ids( 'meta_query' ) ) {
939
940 // Only exclude forums on bbPress queries
941 switch ( $posts_query->get( 'post_type' ) ) {
942
943 // Topics
944 case bbp_get_topic_post_type() :
945
946 // Replies
947 case bbp_get_reply_post_type() :
948
949 // Topics and replies
950 case array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) :
951
952 // Get any existing meta queries
953 $meta_query = $posts_query->get( 'meta_query' );
954
955 // Add our meta query to existing
956 $meta_query[] = $forum_ids;
957
958 // Set the meta_query var
959 $posts_query->set( 'meta_query', $meta_query );
960
961 break;
962 }
963 }
964
965 // Return possibly adjusted query
966 return $posts_query;
967 }
968
969 /**
970 * Adds ability to include or exclude specific post_parent ID's
971 *
972 * @since bbPress (r2996)
973 *
974 * @global DB $wpdb
975 * @global WP $wp
976 * @param string $where
977 * @param WP_Query $object
978 * @return string
979 */
980 function bbp_query_post_parent__in( $where, $object = '' ) {
981 global $wpdb, $wp;
982
983 // Noop if WP core supports this already
984 if ( in_array( 'post_parent__in', $wp->private_query_vars ) )
985 return $where;
986
987 // Bail if no object passed
988 if ( empty( $object ) )
989 return $where;
990
991 // Only 1 post_parent so return $where
992 if ( is_numeric( $object->query_vars['post_parent'] ) )
993 return $where;
994
995 // Including specific post_parent's
996 if ( ! empty( $object->query_vars['post_parent__in'] ) ) {
997 $ids = implode( ',', array_map( 'absint', $object->query_vars['post_parent__in'][0] ) );
998 $where .= " AND $wpdb->posts.post_parent IN ($ids)";
999
1000 // Excluding specific post_parent's
1001 } elseif ( ! empty( $object->query_vars['post_parent__not_in'] ) ) {
1002 $ids = implode( ',', array_map( 'absint', $object->query_vars['post_parent__not_in'][0] ) );
1003 $where .= " AND $wpdb->posts.post_parent NOT IN ($ids)";
1004 }
1005
1006 // Return possibly modified $where
1007 return $where;
1008 }
1009 //add_filter( 'posts_where', 'bbp_query_post_parent__in', 10, 2 );
1010
1011 /**
1012 * Query the DB and get the last public post_id that has parent_id as post_parent
1013 *
1014 * @param int $parent_id Parent id
1015 * @param string $post_type Post type. Defaults to 'post'
1016 * @uses bbp_get_topic_post_type() To get the topic post type
1017 * @uses wp_cache_get() To check if there is a cache of the last child id
1018 * @uses wpdb::prepare() To prepare the query
1019 * @uses wpdb::get_var() To get the result of the query in a variable
1020 * @uses wp_cache_set() To set the cache for future use
1021 * @uses apply_filters() Calls 'bbp_get_public_child_last_id' with the child
1022 * id, parent id and post type
1023 * @return int The last active post_id
1024 */
1025 function bbp_get_public_child_last_id( $parent_id = 0, $post_type = 'post' ) {
1026 global $wpdb;
1027
1028 // Bail if nothing passed
1029 if ( empty( $parent_id ) )
1030 return false;
1031
1032 // The ID of the cached query
1033 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_last_id';
1034 $post_status = array( 'publish' );
1035
1036 // Add closed status if topic post type
1037 if ( $post_type == bbp_get_topic_post_type() )
1038 $post_status[] = $bbp->closed_status_id;
1039
1040 // Join post statuses together
1041 $post_status = "'" . join( "', '", $post_status ) . "'";
1042
1043 // Check for cache and set if needed
1044 if ( !$child_id = wp_cache_get( $cache_id, 'bbpress' ) ) {
1045 $child_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) );
1046 wp_cache_set( $cache_id, $child_id, 'bbpress' );
1047 }
1048
1049 // Filter and return
1050 return apply_filters( 'bbp_get_public_child_last_id', (int) $child_id, (int) $parent_id, $post_type );
1051 }
1052
1053 /**
1054 * Query the DB and get a count of public children
1055 *
1056 * @param int $parent_id Parent id
1057 * @param string $post_type Post type. Defaults to 'post'
1058 * @uses bbp_get_topic_post_type() To get the topic post type
1059 * @uses wp_cache_get() To check if there is a cache of the children count
1060 * @uses wpdb::prepare() To prepare the query
1061 * @uses wpdb::get_var() To get the result of the query in a variable
1062 * @uses wp_cache_set() To set the cache for future use
1063 * @uses apply_filters() Calls 'bbp_get_public_child_count' with the child
1064 * count, parent id and post type
1065 * @return int The number of children
1066 */
1067 function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) {
1068 global $wpdb, $bbp;
1069
1070 // Bail if nothing passed
1071 if ( empty( $parent_id ) )
1072 return false;
1073
1074 // The ID of the cached query
1075 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_count';
1076 $post_status = array( 'publish' );
1077
1078 // Add closed status if topic post type
1079 if ( $post_type == bbp_get_topic_post_type() )
1080 $post_status[] = $bbp->closed_status_id;
1081
1082 // Join post statuses together
1083 $post_status = "'" . join( "', '", $post_status ) . "'";
1084
1085 // Check for cache and set if needed
1086 if ( !$child_count = wp_cache_get( $cache_id, 'bbpress' ) ) {
1087 $child_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ) );
1088 wp_cache_set( $cache_id, $child_count, 'bbpress' );
1089 }
1090
1091 // Filter and return
1092 return apply_filters( 'bbp_get_public_child_count', (int) $child_count, (int) $parent_id, $post_type );
1093 }
1094
1095 /**
1096 * Query the DB and get a the child id's of public children
1097 *
1098 * @param int $parent_id Parent id
1099 * @param string $post_type Post type. Defaults to 'post'
1100 * @uses bbp_get_topic_post_type() To get the topic post type
1101 * @uses wp_cache_get() To check if there is a cache of the children
1102 * @uses wpdb::prepare() To prepare the query
1103 * @uses wpdb::get_col() To get the result of the query in an array
1104 * @uses wp_cache_set() To set the cache for future use
1105 * @uses apply_filters() Calls 'bbp_get_public_child_ids' with the child ids,
1106 * parent id and post type
1107 * @return array The array of children
1108 */
1109 function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) {
1110 global $wpdb, $bbp;
1111
1112 // Bail if nothing passed
1113 if ( empty( $parent_id ) )
1114 return false;
1115
1116 // The ID of the cached query
1117 $cache_id = 'bbp_parent_public_' . $parent_id . '_type_' . $post_type . '_child_ids';
1118 $post_status = array( 'publish' );
1119
1120 // Add closed status if topic post type
1121 if ( $post_type == bbp_get_topic_post_type() )
1122 $post_status[] = $bbp->closed_status_id;
1123
1124 // Join post statuses together
1125 $post_status = "'" . join( "', '", $post_status ) . "'";
1126
1127 // Check for cache and set if needed
1128 if ( !$child_ids = wp_cache_get( $cache_id, 'bbpress' ) ) {
1129 $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
1130 wp_cache_set( $cache_id, $child_ids, 'bbpress' );
1131 }
1132
1133 // Filter and return
1134 return apply_filters( 'bbp_get_public_child_ids', $child_ids, (int) $parent_id, $post_type );
1135 }
1136 /**
1137 * Query the DB and get a the child id's of all children
1138 *
1139 * @param int $parent_id Parent id
1140 * @param string $post_type Post type. Defaults to 'post'
1141 * @uses bbp_get_topic_post_type() To get the topic post type
1142 * @uses wp_cache_get() To check if there is a cache of the children
1143 * @uses wpdb::prepare() To prepare the query
1144 * @uses wpdb::get_col() To get the result of the query in an array
1145 * @uses wp_cache_set() To set the cache for future use
1146 * @uses apply_filters() Calls 'bbp_get_public_child_ids' with the child ids,
1147 * parent id and post type
1148 * @return array The array of children
1149 */
1150 function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) {
1151 global $wpdb, $bbp;
1152
1153 // Bail if nothing passed
1154 if ( empty( $parent_id ) )
1155 return false;
1156
1157 // The ID of the cached query
1158 $cache_id = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids';
1159 $post_status = array( 'publish' );
1160
1161 // Extra post statuses based on post type
1162 switch ( $post_type ) {
1163
1164 // Forum
1165 case bbp_get_forum_post_type() :
1166 $post_status[] = 'private';
1167 $post_status[] = $bbp->hidden_status_id;
1168 break;
1169
1170 // Topic
1171 case bbp_get_topic_post_type() :
1172 $post_status[] = $bbp->closed_status_id;
1173 $post_status[] = $bbp->trash_status_id;
1174 $post_status[] = $bbp->spam_status_id;
1175 break;
1176
1177 // Reply
1178 case bbp_get_reply_post_type() :
1179 $post_status[] = $bbp->trash_status_id;
1180 $post_status[] = $bbp->spam_status_id;
1181 break;
1182 }
1183
1184 // Join post statuses together
1185 $post_status = "'" . join( "', '", $post_status ) . "'";
1186
1187 // Check for cache and set if needed
1188 if ( !$child_ids = wp_cache_get( $cache_id, 'bbpress' ) ) {
1189 $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
1190 wp_cache_set( $cache_id, $child_ids, 'bbpress' );
1191 }
1192
1193 // Filter and return
1194 return apply_filters( 'bbp_get_all_child_ids', $child_ids, (int) $parent_id, $post_type );
1195 }
1196
1197 /** Feeds *********************************************************************/
1198
1199 /**
1200 * This function is hooked into the WordPress 'request' action and is
1201 * responsible for sniffing out the query vars and serving up RSS2 feeds if
1202 * the stars align and the user has requested a feed of any bbPress type.
1203 *
1204 * @since bbPress (r3171)
1205 *
1206 * @global WP_Query $wp_query
1207 * @global bbPress $bbp
1208 * @param array $query_vars
1209 * @return array
1210 */
1211 function bbp_request_feed_trap( $query_vars ) {
1212 global $wp_query, $bbp;
1213
1214 // Looking at a feed
1215 if ( isset( $query_vars['feed'] ) ) {
1216
1217 // Forum Feed
1218 if ( isset( $query_vars['post_type'] ) ) {
1219
1220 // What bbPress post type are we looking for feeds on?
1221 switch ( $query_vars['post_type'] ) {
1222
1223 // Forum
1224 case bbp_get_forum_post_type() :
1225
1226 // Single forum
1227 if ( isset( $query_vars[bbp_get_forum_post_type()] ) ) {
1228
1229 // Load up our own query
1230 $wp_query = new WP_Query( array(
1231 'post_type' => bbp_get_forum_post_type(),
1232 'name' => $query_vars[bbp_get_forum_post_type()]
1233 ) );
1234
1235 // Forum replies
1236 if ( !empty( $_GET['type'] ) && ( bbp_get_reply_post_type() == $_GET['type'] ) ) {
1237
1238 // The query
1239 $the_query = array(
1240 'author' => 0,
1241 'post_type' => bbp_get_reply_post_type(),
1242 'post_parent' => 'any',
1243 'post_status' => join( ',', array( 'publish', $bbp->closed_status_id ) ),
1244 'posts_per_page' => get_option( '_bbp_replies_per_rss_page', 25 ),
1245 'order' => 'DESC',
1246 'meta_query' => array( array(
1247 'key' => '_bbp_forum_id',
1248 'value' => bbp_get_forum_id(),
1249 'compare' => '='
1250 ) )
1251 );
1252
1253 // Output the feed
1254 bbp_display_replies_feed_rss2( $the_query );
1255
1256 // Forum topics
1257 } else {
1258
1259 // The query
1260 $the_query = array(
1261 'author' => 0,
1262 'post_type' => bbp_get_topic_post_type(),
1263 'post_parent' => bbp_get_forum_id(),
1264 'post_status' => join( ',', array( 'publish', $bbp->closed_status_id ) ),
1265 'posts_per_page' => get_option( '_bbp_topics_per_rss_page', 25 ),
1266 'order' => 'DESC',
1267 'meta_query' => array( array(
1268 'key' => '_bbp_forum_id',
1269 'value' => bbp_get_forum_id(),
1270 'compare' => '='
1271 ) )
1272 );
1273
1274 // Output the feed
1275 bbp_display_topics_feed_rss2( $the_query );
1276 }
1277 }
1278
1279 break;
1280
1281 // Topic - Show replies
1282 case bbp_get_topic_post_type() :
1283
1284 // Single topic
1285 if ( isset( $query_vars[bbp_get_topic_post_type()] ) ) {
1286
1287 // Load up our own query
1288 $wp_query = new WP_Query( array(
1289 'post_type' => bbp_get_topic_post_type(),
1290 'name' => $query_vars[bbp_get_topic_post_type()]
1291 ) );
1292
1293 // Output the feed
1294 bbp_display_replies_feed_rss2();
1295
1296 // All topics
1297 } else {
1298
1299 // The query
1300 $the_query = array(
1301 'author' => 0,
1302 'post_parent' => 'any',
1303 'posts_per_page' => get_option( '_bbp_topics_per_rss_page', 25 ),
1304 'show_stickies' => false,
1305 );
1306
1307 // Output the feed
1308 bbp_display_topics_feed_rss2( $the_query );
1309 }
1310
1311 break;
1312
1313 // Replies
1314 case bbp_get_reply_post_type() :
1315
1316 // The query
1317 $the_query = array(
1318 'posts_per_page' => get_option( '_bbp_replies_per_rss_page', 25 ),
1319 'meta_query' => array( array( ) )
1320 );
1321
1322 // All replies
1323 if ( !isset( $query_vars[bbp_get_reply_post_type()] ) ) {
1324 bbp_display_replies_feed_rss2( $the_query );
1325 }
1326
1327 break;
1328 }
1329 }
1330 }
1331
1332 // No feed so continue on
1333 return $query_vars;
1334 }
1335
1336 ?>
1337