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

bbp-reply-functions.php in bbPress 2.0-beta-2b, at bbp-includes/bbp-reply-functions.php

1,259 lines 44.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Reply Functions
5 *
6 * @package bbPress
7 * @subpackage Functions
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * Update the reply with its forum id it is in
15 *
16 * @since bbPress (r2855)
17 *
18 * @param int $reply_id Optional. Reply id to update
19 * @param int $forum_id Optional. Forum id
20 * @uses bbp_get_reply_id() To get the reply id
21 * @uses bbp_get_forum_id() To get the forum id
22 * @uses get_post_ancestors() To get the reply's forum
23 * @uses get_post_field() To get the post type of the post
24 * @uses update_post_meta() To update the reply forum id meta
25 * @uses apply_filters() Calls 'bbp_update_reply_forum_id' with the forum id
26 * and reply id
27 * @return bool Reply's forum id
28 */
29 function bbp_update_reply_forum_id( $reply_id = 0, $forum_id = 0 ) {
30
31 // Validation
32 $reply_id = bbp_get_reply_id( $reply_id );
33 $forum_id = bbp_get_forum_id( $forum_id );
34
35 // If no forum_id was passed, walk up ancestors and look for forum type
36 if ( empty( $forum_id ) ) {
37
38 // Get ancestors
39 $ancestors = get_post_ancestors( $reply_id );
40
41 // Loop through ancestors
42 foreach ( $ancestors as $ancestor ) {
43
44 // Get first parent that is a forum
45 if ( get_post_field( 'post_type', $ancestor ) == bbp_get_forum_post_type() ) {
46 $forum_id = $ancestor;
47
48 // Found a forum, so exit the loop and continue
49 continue;
50 }
51 }
52 }
53
54 // Update the forum ID
55 bbp_update_forum_id( $reply_id, $forum_id );
56
57 return apply_filters( 'bbp_update_reply_forum_id', (int) $forum_id, $reply_id );
58 }
59
60 /**
61 * Update the reply with its topic id it is in
62 *
63 * @since bbPress (r2855)
64 *
65 * @param int $reply_id Optional. Reply id to update
66 * @param int $topic_id Optional. Topic id
67 * @uses bbp_get_reply_id() To get the reply id
68 * @uses bbp_get_topic_id() To get the topic id
69 * @uses get_post_ancestors() To get the reply's topic
70 * @uses get_post_field() To get the post type of the post
71 * @uses update_post_meta() To update the reply topic id meta
72 * @uses apply_filters() Calls 'bbp_update_reply_topic_id' with the topic id
73 * and reply id
74 * @return bool Reply's topic id
75 */
76 function bbp_update_reply_topic_id( $reply_id = 0, $topic_id = 0 ) {
77
78 // Validation
79 $reply_id = bbp_get_reply_id( $reply_id );
80 $topic_id = bbp_get_topic_id( $topic_id );
81
82 // If no topic_id was passed, walk up ancestors and look for topic type
83 if ( empty( $topic_id ) ) {
84
85 // Get ancestors
86 $ancestors = get_post_ancestors( $reply_id );
87
88 // Loop through ancestors
89 foreach ( $ancestors as $ancestor ) {
90
91 // Get first parent that is a forum
92 if ( get_post_field( 'post_type', $ancestor ) == bbp_get_topic_post_type() ) {
93 $topic_id = $ancestor;
94
95 // Found a forum, so exit the loop and continue
96 continue;
97 }
98 }
99 }
100
101 // Update the topic ID
102 bbp_update_topic_id( $reply_id, $topic_id );
103
104 return apply_filters( 'bbp_update_reply_topic_id', (int) $topic_id, $reply_id );
105 }
106
107 /** Post Form Handlers ********************************************************/
108
109 /**
110 * Handles the front end reply submission
111 *
112 * @since bbPress (r2574)
113 *
114 * @uses bbPress:errors::add() To log various error messages
115 * @uses check_admin_referer() To verify the nonce and check the referer
116 * @uses bbp_is_anonymous() To check if an anonymous post is being made
117 * @uses current_user_can() To check if the current user can publish replies
118 * @uses bbp_get_current_user_id() To get the current user id
119 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
120 * @uses bbp_set_current_anonymous_user_data() To set the anonymous user
121 * cookies
122 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
123 * @uses remove_filter() To remove 'wp_filter_kses' filters if needed
124 * @uses esc_attr() For sanitization
125 * @uses bbp_check_for_flood() To check for flooding
126 * @uses bbp_check_for_duplicate() To check for duplicates
127 * @uses apply_filters() Calls 'bbp_new_reply_pre_title' with the title
128 * @uses apply_filters() Calls 'bbp_new_reply_pre_content' with the content
129 * @uses bbp_get_reply_post_type() To get the reply post type
130 * @uses wp_set_post_terms() To set the topic tags
131 * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors
132 * @uses wp_insert_post() To insert the reply
133 * @uses do_action() Calls 'bbp_new_reply' with the reply id, topic id, forum
134 * id, anonymous data and reply author
135 * @uses bbp_get_reply_url() To get the paginated url to the reply
136 * @uses wp_redirect() To redirect to the reply url
137 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
138 * message
139 */
140 function bbp_new_reply_handler() {
141
142 // Only proceed if POST is a new reply
143 if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && !empty( $_POST['action'] ) && ( 'bbp-new-reply' === $_POST['action'] ) ) {
144 global $bbp;
145
146 // Nonce check
147 check_admin_referer( 'bbp-new-reply' );
148
149 // Set defaults to prevent debug notices
150 $topic_id = $forum_id = $topic_author = $anonymous_data = 0;
151 $reply_title = $reply_content = $terms = '';
152
153 /** Reply Author ******************************************************/
154
155 // User is anonymous
156 if ( bbp_is_anonymous() ) {
157
158 // Filter anonymous data
159 $anonymous_data = bbp_filter_anonymous_post_data();
160
161 // Anonymous data checks out, so set cookies, etc...
162 if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) {
163 bbp_set_current_anonymous_user_data( $anonymous_data );
164 }
165
166 // User is logged in
167 } else {
168
169 // User cannot create replies
170 if ( !current_user_can( 'publish_replies' ) ) {
171 $bbp->errors->add( 'bbp_reply_permissions', __( '<strong>ERROR</strong>: You do not have permission to reply.', 'bbpress' ) );
172 }
173
174 // Reply author is current user
175 $reply_author = bbp_get_current_user_id();
176
177 }
178
179 /** Topic ID **********************************************************/
180
181 // Handle Topic ID to append reply to
182 if ( isset( $_POST['bbp_topic_id'] ) && ( !$topic_id = (int) $_POST['bbp_topic_id'] ) )
183 $bbp->errors->add( 'bbp_reply_topic_id', __( '<strong>ERROR</strong>: Topic ID is missing.', 'bbpress' ) );
184
185 /** Forum ID **********************************************************/
186
187 // Handle Forum ID to adjust counts of
188 if ( isset( $_POST['bbp_forum_id'] ) && ( !$forum_id = (int) $_POST['bbp_forum_id'] ) )
189 $bbp->errors->add( 'bbp_reply_forum_id', __( '<strong>ERROR</strong>: Forum ID is missing.', 'bbpress' ) );
190
191 /** Unfiltered HTML ***************************************************/
192
193 // Remove wp_filter_kses filters from title and content for capable users and if the nonce is verified
194 if ( current_user_can( 'unfiltered_html' ) && !empty( $_POST['_bbp_unfiltered_html_reply'] ) && wp_create_nonce( 'bbp-unfiltered-html-reply_' . $topic_id ) == $_POST['_bbp_unfiltered_html_reply'] ) {
195 remove_filter( 'bbp_new_reply_pre_title', 'wp_filter_kses' );
196 remove_filter( 'bbp_new_reply_pre_content', 'wp_filter_kses' );
197 }
198
199 /** Reply Title *******************************************************/
200
201 if ( !empty( $_POST['bbp_reply_title'] ) )
202 $reply_title = esc_attr( strip_tags( $_POST['bbp_reply_title'] ) );
203
204 // Filter and sanitize
205 $reply_title = apply_filters( 'bbp_new_reply_pre_title', $reply_title );
206
207 // No reply title
208 if ( empty( $reply_title ) )
209 $bbp->errors->add( 'bbp_reply_title', __( '<strong>ERROR</strong>: Your reply needs a title.', 'bbpress' ) );
210
211 /** Reply Content *****************************************************/
212
213 if ( !empty( $_POST['bbp_reply_content'] ) )
214 $reply_content = $_POST['bbp_reply_content'];
215
216 // Filter and sanitize
217 $reply_content = apply_filters( 'bbp_new_reply_pre_content', $reply_content );
218
219 // No reply content
220 if ( empty( $reply_content ) )
221 $bbp->errors->add( 'bbp_reply_content', __( '<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress' ) );
222
223 /** Reply Flooding ****************************************************/
224
225 if ( !bbp_check_for_flood( $anonymous_data, $reply_author ) )
226 $bbp->errors->add( 'bbp_reply_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) );
227
228 /** Reply Duplicate ***************************************************/
229
230 if ( !bbp_check_for_duplicate( array( 'post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data ) ) )
231 $bbp->errors->add( 'bbp_reply_duplicate', __( '<strong>ERROR</strong>: Duplicate reply detected; it looks as though you&#8217;ve already said that!', 'bbpress' ) );
232
233 /** Topic Tags ********************************************************/
234
235 if ( !empty( $_POST['bbp_topic_tags'] ) )
236 $terms = esc_attr( strip_tags( $_POST['bbp_topic_tags'] ) );
237
238 /** Additional Actions (Before Save) **********************************/
239
240 do_action( 'bbp_new_reply_pre_extras' );
241
242 /** No Errors *********************************************************/
243
244 // Handle insertion into posts table
245 if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) {
246
247 /** Create new reply **********************************************/
248
249 // Add the content of the form to $post as an array
250 $reply_data = array(
251 'post_author' => $reply_author,
252 'post_title' => $reply_title,
253 'post_content' => $reply_content,
254 'post_parent' => $topic_id,
255 'post_status' => 'publish',
256 'post_type' => bbp_get_reply_post_type()
257 );
258
259 // Just in time manipulation of reply data before being created
260 $reply_data = apply_filters( 'bbp_new_reply_pre_insert', $reply_data );
261
262 // Insert reply
263 $reply_id = wp_insert_post( $reply_data );
264
265 /** No Errors *****************************************************/
266
267 // Check for missing reply_id or error
268 if ( !empty( $reply_id ) && !is_wp_error( $reply_id ) ) {
269
270 /** Topic Tags ************************************************/
271
272 // Insert terms
273 $terms = wp_set_post_terms( $topic_id, $terms, $bbp->topic_tag_id, false );
274
275 // Term error
276 if ( is_wp_error( $terms ) )
277 $bbp->errors->add( 'bbp_reply_tags', __( '<strong>ERROR</strong>: There was some problem adding the tags to the topic.', 'bbpress' ) );
278
279 /** Trash Check ***********************************************/
280
281 // If this reply starts as trash, add it to pre_trashed_replies
282 // for the topic, so it is properly restored.
283 if ( bbp_is_topic_trash( $topic_id ) || ( $reply_data['post_status'] == $bbp->trash_status_id ) ) {
284
285 // Trash the reply
286 wp_trash_post( $reply_id );
287
288 // Get pre_trashed_replies for topic
289 $pre_trashed_replies = get_post_meta( $topic_id, '_bbp_pre_trashed_replies', true );
290
291 // Add this reply to the end of the existing replies
292 $pre_trashed_replies[] = $reply_id;
293
294 // Update the pre_trashed_reply post meta
295 update_post_meta( $topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies );
296 }
297
298 // Update counts, etc...
299 do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author );
300
301 /** Redirect **************************************************/
302
303 $reply_url = bbp_get_reply_url( $reply_id );
304
305 if ( ( !empty( $_GET['view'] ) && ( 'all' === $_GET['view'] ) ) || ( $reply_data['post_status'] == $bbp->trash_status_id ) )
306 $reply_url = add_query_arg( array( 'view' => 'all' ), $reply_url );
307
308 $reply_url = apply_filters( 'bbp_new_reply_redirect_to', $reply_url );
309
310 /** Successful Save *******************************************/
311
312 // Redirect back to new reply
313 wp_redirect( $reply_url );
314
315 // For good measure
316 exit();
317
318 /** Errors ********************************************************/
319
320 } else {
321 $append_error = ( is_wp_error( $reply_id ) && $reply_id->get_error_message() ) ? $reply_id->get_error_message() . ' ' : '';
322 $bbp->errors->add( 'bbp_reply_error', __( '<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress' ) );
323 }
324 }
325 }
326 }
327
328 /**
329 * Handles the front end edit reply submission
330 *
331 * @uses bbPress:errors::add() To log various error messages
332 * @uses bbp_get_reply() To get the reply
333 * @uses check_admin_referer() To verify the nonce and check the referer
334 * @uses bbp_is_reply_anonymous() To check if the reply was by an anonymous user
335 * @uses current_user_can() To check if the current user can edit that reply
336 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
337 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
338 * @uses remove_filter() To remove 'wp_filter_kses' filters if needed
339 * @uses esc_attr() For sanitization
340 * @uses apply_filters() Calls 'bbp_edit_reply_pre_title' with the title and
341 * reply id
342 * @uses apply_filters() Calls 'bbp_edit_reply_pre_content' with the content
343 * reply id
344 * @uses wp_set_post_terms() To set the topic tags
345 * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors
346 * @uses wp_save_post_revision() To save a reply revision
347 * @uses bbp_update_topic_revision_log() To update the reply revision log
348 * @uses wp_update_post() To update the reply
349 * @uses bbp_get_reply_topic_id() To get the reply topic id
350 * @uses bbp_get_topic_forum_id() To get the topic forum id
351 * @uses do_action() Calls 'bbp_edit_reply' with the reply id, topic id, forum
352 * id, anonymous data, reply author and bool true (for edit)
353 * @uses bbp_get_reply_url() To get the paginated url to the reply
354 * @uses wp_redirect() To redirect to the reply url
355 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
356 * message
357 */
358 function bbp_edit_reply_handler() {
359
360 // Only proceed if POST is an reply request
361 if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && !empty( $_POST['action'] ) && ( 'bbp-edit-reply' === $_POST['action'] ) ) {
362 global $bbp;
363
364 // Set defaults to prevent debug notices
365 $reply = $reply_id = $topic_id = $forum_id = $anonymous_data = 0;
366 $reply_title = $reply_content = $reply_edit_reason = $terms = '';
367
368 /** Reply *************************************************************/
369
370 // Reply id was not passed
371 if ( empty( $_POST['bbp_reply_id'] ) )
372 $bbp->errors->add( 'bbp_edit_reply_id', __( '<strong>ERROR</strong>: Reply ID not found.', 'bbpress' ) );
373
374 // Reply id was passed
375 elseif ( is_numeric( $_POST['bbp_reply_id'] ) )
376 $reply_id = (int) $_POST['bbp_reply_id'];
377
378 // Reply does not exist
379 if ( !$reply = bbp_get_reply( $reply_id ) ) {
380 $bbp->errors->add( 'bbp_edit_reply_not_found', __( '<strong>ERROR</strong>: The reply you want to edit was not found.', 'bbpress' ) );
381
382 // Reply exists
383 } else {
384
385 // Nonce check
386 check_admin_referer( 'bbp-edit-reply_' . $reply_id );
387
388 // Check users ability to create new reply
389 if ( !bbp_is_reply_anonymous( $reply_id ) ) {
390
391 // User cannot edit this reply
392 if ( !current_user_can( 'edit_reply', $reply_id ) ) {
393 $bbp->errors->add( 'bbp_edit_reply_permissions', __( '<strong>ERROR</strong>: You do not have permission to edit that reply.', 'bbpress' ) );
394 }
395
396 // It is an anonymous post
397 } else {
398
399 // Filter anonymous data
400 $anonymous_data = bbp_filter_anonymous_post_data( array(), true );
401 }
402 }
403
404 // Remove wp_filter_kses filters from title and content for capable users and if the nonce is verified
405 if ( current_user_can( 'unfiltered_html' ) && !empty( $_POST['_bbp_unfiltered_html_reply'] ) && wp_create_nonce( 'bbp-unfiltered-html-reply_' . $reply_id ) == $_POST['_bbp_unfiltered_html_reply'] ) {
406 remove_filter( 'bbp_edit_reply_pre_title', 'wp_filter_kses' );
407 remove_filter( 'bbp_edit_reply_pre_content', 'wp_filter_kses' );
408 }
409
410 /** Reply Topic *******************************************************/
411
412 $topic_id = bbp_get_reply_topic_id( $reply_id );
413
414 /** Reply Forum *******************************************************/
415
416 $forum_id = bbp_get_topic_forum_id( $topic_id );
417
418 // Forum exists
419 if ( !empty( $forum_id ) && ( $forum_id != $reply->post_parent ) ) {
420
421 // Forum is a category
422 if ( bbp_is_forum_category( $forum_id ) )
423 $bbp->errors->add( 'bbp_edit_reply_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics or replies can be created in it.', 'bbpress' ) );
424
425 // Forum is closed and user cannot access
426 if ( bbp_is_forum_closed( $forum_id ) && !current_user_can( 'edit_forum', $forum_id ) )
427 $bbp->errors->add( 'bbp_edit_reply_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics and replies.', 'bbpress' ) );
428
429 // Forum is private and user cannot access
430 if ( bbp_is_forum_private( $forum_id ) && !current_user_can( 'read_private_forums' ) )
431 $bbp->errors->add( 'bbp_edit_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
432
433 // Forum is hidden and user cannot access
434 if ( bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) )
435 $bbp->errors->add( 'bbp_edit_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
436 }
437
438 /** Reply Title *******************************************************/
439
440 if ( !empty( $_POST['bbp_reply_title'] ) )
441 $reply_title = esc_attr( strip_tags( $_POST['bbp_reply_title'] ) );
442
443 // Filter and sanitize
444 $reply_title = apply_filters( 'bbp_edit_reply_pre_title', $reply_title, $reply_id );
445
446 /** Reply Content *****************************************************/
447
448 if ( !empty( $_POST['bbp_reply_content'] ) )
449 $reply_content = $_POST['bbp_reply_content'];
450
451 // Filter and sanitize
452 $reply_content = apply_filters( 'bbp_edit_reply_pre_content', $reply_content, $reply_id );
453
454 // No reply content
455 if ( empty( $reply_content ) )
456 $bbp->errors->add( 'bbp_edit_reply_content', __( '<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress' ) );
457
458 /** Topic Tags ********************************************************/
459
460 if ( !empty( $_POST['bbp_topic_tags'] ) )
461 $terms = esc_attr( strip_tags( $_POST['bbp_topic_tags'] ) );
462
463 /** Additional Actions (Before Save) **********************************/
464
465 do_action( 'bbp_edit_reply_pre_extras', $reply_id );
466
467 /** No Errors *********************************************************/
468
469 // Handle insertion into posts table
470 if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) {
471
472 // Add the content of the form to $post as an array
473 $reply_data = array(
474 'ID' => $reply_id,
475 'post_title' => $reply_title,
476 'post_content' => $reply_content
477 );
478
479 // Just in time manipulation of reply data before being edited
480 $reply_data = apply_filters( 'bbp_edit_reply_pre_insert', $reply_data );
481
482 // Insert reply
483 $reply_id = wp_update_post( $reply_data );
484
485 /** Topic Tags ************************************************/
486
487 // Insert terms
488 $terms = wp_set_post_terms( $topic_id, $terms, $bbp->topic_tag_id, false );
489
490 // Term error
491 if ( is_wp_error( $terms ) )
492 $bbp->errors->add( 'bbp_reply_tags', __( '<strong>ERROR</strong>: There was some problem adding the tags to the topic.', 'bbpress' ) );
493
494 /** Revisions *****************************************************/
495
496 // Revision Reason
497 if ( !empty( $_POST['bbp_reply_edit_reason'] ) )
498 $reply_edit_reason = esc_attr( strip_tags( $_POST['bbp_reply_edit_reason'] ) );
499
500 // Update revision log
501 if ( !empty( $_POST['bbp_log_reply_edit'] ) && ( 1 == $_POST['bbp_log_reply_edit'] ) && ( $revision_id = wp_save_post_revision( $reply_id ) ) ) {
502 bbp_update_reply_revision_log( array(
503 'reply_id' => $reply_id,
504 'revision_id' => $revision_id,
505 'author_id' => bbp_get_current_user_id(),
506 'reason' => $reply_edit_reason
507 ) );
508 }
509
510 /** No Errors *****************************************************/
511
512 if ( !empty( $reply_id ) && !is_wp_error( $reply_id ) ) {
513
514 // Update counts, etc...
515 do_action( 'bbp_edit_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply->post_author , true /* Is edit */ );
516
517 /** Additional Actions (After Save) ***************************/
518
519 do_action( 'bbp_edit_reply_post_extras', $reply_id );
520
521 /** Successful Edit *******************************************/
522
523 // Redirect back to new reply
524 wp_redirect( bbp_get_reply_url( $reply_id ) );
525
526 // For good measure
527 exit();
528
529 /** Errors ********************************************************/
530
531 } else {
532 $append_error = ( is_wp_error( $reply_id ) && $reply_id->get_error_message() ) ? $reply_id->get_error_message() . ' ' : '';
533 $bbp->errors->add( 'bbp_reply_error', __( '<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress' ) );
534 }
535 }
536 }
537 }
538
539 /**
540 * Handles new reply submission from within wp-admin
541 *
542 * @param int $reply_id Reply id
543 * @param obj $reply Reply
544 * @uses bbp_get_reply_post_type() To get the reply post type
545 * @uses bbp_update_reply() To update the reply
546 */
547 function bbp_new_reply_admin_handler( $reply_id, $reply ) {
548 global $bbp;
549
550 if ( // Check if POST action
551 'POST' === $_SERVER['REQUEST_METHOD'] &&
552
553 // Check Actions exist in POST
554 !empty( $_POST['action'] ) &&
555 !empty( $_POST['post_type'] ) &&
556
557 // Check that actions match what we need
558 'editpost' === $_POST['action'] &&
559 'publish' === $_POST['post_status'] &&
560 bbp_get_reply_post_type() === $_POST['post_type']
561
562 ) {
563
564 // Update the reply meta bidness
565 $parent_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
566 bbp_update_topic( $reply_id, $parent_id );
567 }
568 }
569
570 /**
571 * Handle all the extra meta stuff from posting a new reply or editing a reply
572 *
573 * @param int $reply_id Optional. Reply id
574 * @param int $topic_id Optional. Topic id
575 * @param int $forum_id Optional. Forum id
576 * @param bool|array $anonymous_data Optional. If it is an array, it is
577 * extracted and anonymous user info is saved
578 * @param int $author_id Author id
579 * @param bool $is_edit Optional. Is the post being edited? Defaults to false.
580 * @uses bbp_get_reply_id() To get the reply id
581 * @uses bbp_get_topic_id() To get the topic id
582 * @uses bbp_get_forum_id() To get the forum id
583 * @uses bbp_get_current_user_id() To get the current user id
584 * @uses bbp_get_reply_topic_id() To get the reply topic id
585 * @uses bbp_get_topic_forum_id() To get the topic forum id
586 * @uses update_post_meta() To update the reply metas
587 * @uses set_transient() To update the flood check transient for the ip
588 * @uses update_user_meta() To update the last posted meta for the user
589 * @uses bbp_is_subscriptions_active() To check if the subscriptions feature is
590 * activated or not
591 * @uses bbp_is_user_subscribed() To check if the user is subscribed
592 * @uses bbp_remove_user_subscription() To remove the user's subscription
593 * @uses bbp_add_user_subscription() To add the user's subscription
594 * @uses bbp_update_reply_forum_id() To update the reply forum id
595 * @uses bbp_update_reply_topic_id() To update the reply topic id
596 * @uses bbp_update_reply_walker() To update the reply's ancestors' counts
597 */
598 function bbp_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) {
599
600 // Validate the ID's passed from 'bbp_new_reply' action
601 $reply_id = bbp_get_reply_id( $reply_id );
602 $topic_id = bbp_get_topic_id( $topic_id );
603 $forum_id = bbp_get_forum_id( $forum_id );
604
605 // Check author_id
606 if ( empty( $author_id ) )
607 $author_id = bbp_get_current_user_id();
608
609 // Check topic_id
610 if ( empty( $topic_id ) )
611 $topic_id = bbp_get_reply_topic_id( $reply_id );
612
613 // Check forum_id
614 if ( !empty( $topic_id ) && empty( $forum_id ) )
615 $forum_id = bbp_get_topic_forum_id( $topic_id );
616
617 // If anonymous post, store name, email, website and ip in post_meta.
618 // It expects anonymous_data to be sanitized.
619 // Check bbp_filter_anonymous_post_data() for sanitization.
620 if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) {
621 extract( $anonymous_data );
622
623 update_post_meta( $reply_id, '_bbp_anonymous_name', $bbp_anonymous_name, false );
624 update_post_meta( $reply_id, '_bbp_anonymous_email', $bbp_anonymous_email, false );
625
626 // Set transient for throttle check (only on new, not edit)
627 if ( empty( $is_edit ) )
628 set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time() );
629
630 // Website is optional
631 if ( !empty( $bbp_anonymous_website ) )
632 update_post_meta( $reply_id, '_bbp_anonymous_website', $bbp_anonymous_website, false );
633
634 } else {
635 if ( empty( $is_edit ) && !current_user_can( 'throttle' ) )
636 update_user_meta( $author_id, '_bbp_last_posted', time() );
637 }
638
639 // Handle Subscription Checkbox
640 if ( bbp_is_subscriptions_active() && !empty( $author_id ) ) {
641 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
642 $subscheck = ( !empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' == $_POST['bbp_topic_subscription'] ) ) ? true : false;
643
644 // Subscribed and unsubscribing
645 if ( true == $subscribed && false == $subscheck )
646 bbp_remove_user_subscription( $author_id, $topic_id );
647
648 // Subscribing
649 elseif ( false == $subscribed && true == $subscheck )
650 bbp_add_user_subscription( $author_id, $topic_id );
651 }
652
653 // Reply meta relating to reply position in tree
654 bbp_update_reply_forum_id( $reply_id, $forum_id );
655 bbp_update_reply_topic_id( $reply_id, $topic_id );
656
657 // Update associated topic values if this is a new reply
658 if ( empty( $is_edit ) ) {
659
660 // Update poster IP if not editing
661 update_post_meta( $reply_id, '_bbp_author_ip', bbp_current_author_ip(), false );
662
663 // Last active time
664 $last_active_time = current_time( 'mysql' );
665
666 // Walk up ancestors and do the dirty work
667 bbp_update_reply_walker( $reply_id, $last_active_time, $forum_id, $topic_id, false );
668 }
669 }
670
671 /**
672 * Walk up the ancestor tree from the current reply, and update all the counts
673 *
674 * @since bbPress (r2884)
675 *
676 * @param int $reply_id Optional. Reply id
677 * @param string $last_active_time Optional. Last active time
678 * @param int $forum_id Optional. Forum id
679 * @param int $topic_id Optional. Topic id
680 * @param bool $refresh If set to true, unsets all the previous parameters.
681 * Defaults to true
682 * @uses bbp_get_reply_id() To get the reply id
683 * @uses bbp_get_reply_topic_id() To get the reply topic id
684 * @uses bbp_get_reply_forum_id() To get the reply forum id
685 * @uses get_post_ancestors() To get the ancestors of the reply
686 * @uses bbp_is_reply() To check if the ancestor is a reply
687 * @uses bbp_is_topic() To check if the ancestor is a topic
688 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
689 * @uses bbp_update_topic_last_active_id() To update the topic last active id
690 * @uses bbp_get_topic_last_active_id() To get the topic last active id
691 * @uses get_post_field() To get the post date of the last active id
692 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
693 * @uses bbp_update_topic_voice_count() To update the topic voice count
694 * @uses bbp_update_topic_reply_count() To update the topic reply count
695 * @uses bbp_update_topic_hidden_reply_count() To update the topic hidden reply
696 * count
697 * @uses bbp_is_forum() To check if the ancestor is a forum
698 * @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
699 * @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
700 * @uses bbp_update_forum_last_active_id() To update the forum last active id
701 * @uses bbp_get_forum_last_active_id() To get the forum last active id
702 * @uses bbp_update_forum_last_active_time() To update the forum last active time
703 * @uses bbp_update_forum_reply_count() To update the forum reply count
704 */
705 function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true ) {
706 global $bbp;
707
708 // Verify the reply ID
709 if ( $reply_id = bbp_get_reply_id( $reply_id ) ) {
710
711 // Get the topic ID if none was passed
712 if ( empty( $topic_id ) )
713 $topic_id = bbp_get_reply_topic_id( $reply_id );
714
715 // Get the forum ID if none was passed
716 if ( empty( $forum_id ) )
717 $forum_id = bbp_get_reply_forum_id( $reply_id );
718 }
719
720 // Set the active_id based on topic_id/reply_id
721 $active_id = empty( $reply_id ) ? $topic_id : $reply_id;
722
723 // Setup ancestors array to walk up
724 $ancestors = array_values( array_unique( array_merge( array( $topic_id, $forum_id ), get_post_ancestors( $topic_id ) ) ) );
725
726 // If we want a full refresh, unset any of the possibly passed variables
727 if ( true == $refresh )
728 $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
729
730 // Walk up ancestors
731 foreach ( $ancestors as $ancestor ) {
732
733 // Reply meta relating to most recent reply
734 if ( bbp_is_reply( $ancestor ) ) {
735 // @todo - hierarchical replies
736
737 // Topic meta relating to most recent reply
738 } elseif ( bbp_is_topic( $ancestor ) ) {
739
740 // Last reply and active ID's
741 bbp_update_topic_last_reply_id ( $ancestor, $reply_id );
742 bbp_update_topic_last_active_id ( $ancestor, $active_id );
743
744 // Get the last active time if none was passed
745 if ( empty( $last_active_time ) )
746 $topic_last_active_time = get_post_field( 'post_date', bbp_get_topic_last_active_id( $ancestor ) );
747 else
748 $topic_last_active_time = $last_active_time;
749
750 bbp_update_topic_last_active_time ( $ancestor, $topic_last_active_time );
751
752 // Counts
753 bbp_update_topic_voice_count ( $ancestor );
754 bbp_update_topic_reply_count ( $ancestor );
755 bbp_update_topic_hidden_reply_count( $ancestor );
756
757 // Forum meta relating to most recent topic
758 } elseif ( bbp_is_forum( $ancestor ) ) {
759
760 // Last topic and reply ID's
761 bbp_update_forum_last_topic_id( $ancestor, $topic_id );
762 bbp_update_forum_last_reply_id( $ancestor, $reply_id );
763
764 // Last Active
765 bbp_update_forum_last_active_id( $ancestor, $active_id );
766
767 if ( empty( $last_active_time ) )
768 $forum_last_active_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $ancestor ) );
769 else
770 $forum_last_active_time = $last_active_time;
771
772 bbp_update_forum_last_active_time( $ancestor, $forum_last_active_time );
773
774 // Counts
775 bbp_update_forum_reply_count( $ancestor );
776 }
777 }
778 }
779
780 /**
781 * Update the revision log of the reply
782 *
783 * @since bbPress (r2782)
784 *
785 * @param mixed $args Supports these args:
786 * - reply_id: reply id
787 * - author_id: Author id
788 * - reason: Reason for editing
789 * - revision_id: Revision id
790 * @uses bbp_get_reply_id() To get the reply id
791 * @uses bbp_get_user_id() To get the user id
792 * @uses bbp_format_revision_reason() To format the reason
793 * @uses bbp_get_reply_raw_revision_log() To get the raw reply revision log
794 * @uses update_post_meta() To update the reply revision log meta
795 * @return mixed False on failure, true on success
796 */
797 function bbp_update_reply_revision_log( $args = '' ) {
798 $defaults = array (
799 'reason' => '',
800 'reply_id' => 0,
801 'author_id' => 0,
802 'revision_id' => 0
803 );
804
805 $r = wp_parse_args( $args, $defaults );
806 extract( $r );
807
808 // Populate the variables
809 $reason = bbp_format_revision_reason( $reason );
810 $reply_id = bbp_get_reply_id( $reply_id );
811 $author_id = bbp_get_user_id ( $author_id, false, true );
812 $revision_id = (int) $revision_id;
813
814 // Get the logs and append the new one to those
815 $revision_log = bbp_get_reply_raw_revision_log( $reply_id );
816 $revision_log[$revision_id] = array( 'author' => $author_id, 'reason' => $reason );
817
818 // Finally, update
819 update_post_meta( $reply_id, '_bbp_revision_log', $revision_log );
820
821 return apply_filters( 'bbp_update_reply_revision_log', $revision_log, $reply_id );
822 }
823
824 /** Reply Actions *************************************************************/
825
826 /**
827 * Handles the front end spamming/unspamming and trashing/untrashing/deleting of
828 * replies
829 *
830 * @since bbPress (r2740)
831 *
832 * @uses bbp_get_reply() To get the reply
833 * @uses current_user_can() To check if the user is capable of editing or
834 * deleting the reply
835 * @uses check_ajax_referer() To verify the nonce and check the referer
836 * @uses bbp_get_reply_post_type() To get the reply post type
837 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
838 * @uses bbp_spam_reply() To make the reply as spam
839 * @uses bbp_unspam_reply() To unmark the reply as spam
840 * @uses wp_trash_post() To trash the reply
841 * @uses wp_untrash_post() To untrash the reply
842 * @uses wp_delete_post() To delete the reply
843 * @uses do_action() Calls 'bbp_toggle_reply_handler' with success, post data
844 * and action
845 * @uses bbp_get_reply_url() To get the reply url
846 * @uses add_query_arg() To add custom args to the reply url
847 * @uses wp_redirect() To redirect to the reply
848 * @uses bbPress::errors:add() To log the error messages
849 */
850 function bbp_toggle_reply_handler() {
851
852 // Only proceed if GET is a reply toggle action
853 if ( 'GET' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && !empty( $_GET['reply_id'] ) && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_reply_spam', 'bbp_toggle_reply_trash' ) ) ) {
854 global $bbp;
855
856 $action = $_GET['action']; // What action is taking place?
857 $reply_id = (int) $_GET['reply_id']; // What's the reply id?
858 $success = false; // Flag
859 $post_data = array( 'ID' => $reply_id ); // Prelim array
860
861 // Make sure reply exists
862 if ( !$reply = bbp_get_reply( $reply_id ) )
863 return;
864
865 // What is the user doing here?
866 if ( !current_user_can( 'edit_reply', $reply->ID ) || ( 'bbp_toggle_reply_trash' == $action && !current_user_can( 'delete_reply', $reply->ID ) ) ) {
867 $bbp->errors->add( 'bbp_toggle_reply_permission', __( '<strong>ERROR:</strong> You do not have the permission to do that!', 'bbpress' ) );
868 return;
869 }
870
871 // What action are we trying to perform?
872 switch ( $action ) {
873
874 // Toggle spam
875 case 'bbp_toggle_reply_spam' :
876 check_ajax_referer( 'spam-reply_' . $reply_id );
877
878 $is_spam = bbp_is_reply_spam( $reply_id );
879 $success = $is_spam ? bbp_unspam_reply( $reply_id ) : bbp_spam_reply( $reply_id );
880 $failure = $is_spam ? __( '<strong>ERROR</strong>: There was a problem unmarking the reply as spam!', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem marking the reply as spam!', 'bbpress' );
881
882 break;
883
884 // Toggle trash
885 case 'bbp_toggle_reply_trash' :
886
887 $sub_action = in_array( $_GET['sub_action'], array( 'trash', 'untrash', 'delete' ) ) ? $_GET['sub_action'] : false;
888
889 if ( empty( $sub_action ) )
890 break;
891
892 switch ( $sub_action ) {
893 case 'trash':
894 check_ajax_referer( 'trash-' . bbp_get_reply_post_type() . '_' . $reply_id );
895
896 $success = wp_trash_post( $reply_id );
897 $failure = __( '<strong>ERROR</strong>: There was a problem trashing the reply!', 'bbpress' );
898
899 break;
900
901 case 'untrash':
902 check_ajax_referer( 'untrash-' . bbp_get_reply_post_type() . '_' . $reply_id );
903
904 $success = wp_untrash_post( $reply_id );
905 $failure = __( '<strong>ERROR</strong>: There was a problem untrashing the reply!', 'bbpress' );
906
907 break;
908
909 case 'delete':
910 check_ajax_referer( 'delete-' . bbp_get_reply_post_type() . '_' . $reply_id );
911
912 $success = wp_delete_post( $reply_id );
913 $failure = __( '<strong>ERROR</strong>: There was a problem deleting the reply!', 'bbpress' );
914
915 break;
916 }
917
918 break;
919 }
920
921 // Do additional reply toggle actions
922 do_action( 'bbp_toggle_reply_handler', $success, $post_data, $action );
923
924 // No errors
925 if ( ( false != $success ) && !is_wp_error( $success ) ) {
926
927 // Redirect back to the reply
928 $redirect = add_query_arg( array( 'view' => 'all' ), bbp_get_reply_url( $reply_id, true ) );
929 wp_redirect( $redirect );
930
931 // For good measure
932 exit();
933
934 // Handle errors
935 } else {
936 $bbp->errors->add( 'bbp_toggle_reply', $failure );
937 }
938 }
939 }
940
941 /** Reply Actions *************************************************************/
942
943 /**
944 * Marks a reply as spam
945 *
946 * @since bbPress (r2740)
947 *
948 * @param int $reply_id Reply id
949 * @uses wp_get_single_post() To get the reply
950 * @uses do_action() Calls 'bbp_spam_reply' with the reply ID
951 * @uses add_post_meta() To add the previous status to a meta
952 * @uses wp_insert_post() To insert the updated post
953 * @uses do_action() Calls 'bbp_spammed_reply' with the reply ID
954 * @return mixed False or {@link WP_Error} on failure, reply id on success
955 */
956 function bbp_spam_reply( $reply_id = 0 ) {
957 global $bbp;
958
959 if ( !$reply = wp_get_single_post( $reply_id, ARRAY_A ) )
960 return $reply;
961
962 if ( $reply['post_status'] == $bbp->spam_status_id )
963 return false;
964
965 do_action( 'bbp_spam_reply', $reply_id );
966
967 add_post_meta( $reply_id, '_bbp_spam_meta_status', $reply['post_status'] );
968
969 $reply['post_status'] = $bbp->spam_status_id;
970
971 $reply_id = wp_insert_post( $reply );
972
973 do_action( 'bbp_spammed_reply', $reply_id );
974
975 return $reply_id;
976 }
977
978 /**
979 * Unspams a reply
980 *
981 * @since bbPress (r2740)
982 *
983 * @param int $reply_id Reply id
984 * @uses wp_get_single_post() To get the reply
985 * @uses do_action() Calls 'bbp_unspam_reply' with the reply ID
986 * @uses get_post_meta() To get the previous status meta
987 * @uses delete_post_meta() To delete the previous status meta
988 * @uses wp_insert_post() To insert the updated post
989 * @uses do_action() Calls 'bbp_unspammed_reply' with the reply ID
990 * @return mixed False or {@link WP_Error} on failure, reply id on success
991 */
992 function bbp_unspam_reply( $reply_id = 0 ) {
993 global $bbp;
994
995 if ( !$reply = wp_get_single_post( $reply_id, ARRAY_A ) )
996 return $reply;
997
998 if ( $reply['post_status'] != $bbp->spam_status_id )
999 return false;
1000
1001 do_action( 'bbp_unspam_reply', $reply_id );
1002
1003 $reply_status = get_post_meta( $reply_id, '_bbp_spam_meta_status', true );
1004 $reply['post_status'] = $reply_status;
1005
1006 delete_post_meta( $reply_id, '_bbp_spam_meta_status' );
1007
1008 $reply_id = wp_insert_post( $reply );
1009
1010 do_action( 'bbp_unspammed_reply', $reply_id );
1011
1012 return $reply_id;
1013 }
1014
1015 /** Before Delete/Trash/Untrash ***********************************************/
1016
1017 /**
1018 * Called before deleting a reply
1019 *
1020 * @uses bbp_get_reply_id() To get the reply id
1021 * @uses bbp_is_reply() To check if the passed id is a reply
1022 * @uses do_action() Calls 'bbp_delete_reply' with the reply id
1023 */
1024 function bbp_delete_reply( $reply_id = 0 ) {
1025 $reply_id = bbp_get_reply_id( $reply_id );
1026
1027 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1028 return false;
1029
1030 do_action( 'bbp_delete_reply', $reply_id );
1031 }
1032
1033 /**
1034 * Called before trashing a reply
1035 *
1036 * @uses bbp_get_reply_id() To get the reply id
1037 * @uses bbp_is_reply() To check if the passed id is a reply
1038 * @uses do_action() Calls 'bbp_trash_reply' with the reply id
1039 */
1040 function bbp_trash_reply( $reply_id = 0 ) {
1041 $reply_id = bbp_get_reply_id( $reply_id );
1042
1043 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1044 return false;
1045
1046 do_action( 'bbp_trash_reply', $reply_id );
1047 }
1048
1049 /**
1050 * Called before untrashing (restoring) a reply
1051 *
1052 * @uses bbp_get_reply_id() To get the reply id
1053 * @uses bbp_is_reply() To check if the passed id is a reply
1054 * @uses do_action() Calls 'bbp_unstrash_reply' with the reply id
1055 */
1056 function bbp_untrash_reply( $reply_id = 0 ) {
1057 $reply_id = bbp_get_reply_id( $reply_id );
1058
1059 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1060 return false;
1061
1062 do_action( 'bbp_untrash_reply', $reply_id );
1063 }
1064
1065 /** After Delete/Trash/Untrash ************************************************/
1066
1067 /**
1068 * Called after deleting a reply
1069 *
1070 * @uses bbp_get_reply_id() To get the reply id
1071 * @uses bbp_is_reply() To check if the passed id is a reply
1072 * @uses do_action() Calls 'bbp_deleted_reply' with the reply id
1073 */
1074 function bbp_deleted_reply( $reply_id = 0 ) {
1075 $reply_id = bbp_get_reply_id( $reply_id );
1076
1077 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1078 return false;
1079
1080 do_action( 'bbp_deleted_reply', $reply_id );
1081 }
1082
1083 /**
1084 * Called after trashing a reply
1085 *
1086 * @uses bbp_get_reply_id() To get the reply id
1087 * @uses bbp_is_reply() To check if the passed id is a reply
1088 * @uses do_action() Calls 'bbp_trashed_reply' with the reply id
1089 */
1090 function bbp_trashed_reply( $reply_id = 0 ) {
1091 $reply_id = bbp_get_reply_id( $reply_id );
1092
1093 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1094 return false;
1095
1096 do_action( 'bbp_trashed_reply', $reply_id );
1097 }
1098
1099 /**
1100 * Called after untrashing (restoring) a reply
1101 *
1102 * @uses bbp_get_reply_id() To get the reply id
1103 * @uses bbp_is_reply() To check if the passed id is a reply
1104 * @uses do_action() Calls 'bbp_untrashed_reply' with the reply id
1105 */
1106 function bbp_untrashed_reply( $reply_id = 0 ) {
1107 $reply_id = bbp_get_reply_id( $reply_id );
1108
1109 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1110 return false;
1111
1112 do_action( 'bbp_untrashed_reply', $reply_id );
1113 }
1114
1115 /** Feeds *********************************************************************/
1116
1117 /**
1118 * Output an RSS2 feed of replies, based on the query passed.
1119 *
1120 * @since bbPress (r3171)
1121 *
1122 * @global bbPress $bbp
1123 *
1124 * @uses bbp_exclude_forum_ids()
1125 * @uses bbp_is_topic()
1126 * @uses bbp_user_can_view_forum()
1127 * @uses bbp_get_topic_forum_id()
1128 * @uses bbp_show_load_topic()
1129 * @uses bbp_topic_permalink()
1130 * @uses bbp_topic_title()
1131 * @uses bbp_get_topic_reply_count()
1132 * @uses bbp_topic_content()
1133 * @uses bbp_has_replies()
1134 * @uses bbp_replies()
1135 * @uses bbp_the_reply()
1136 * @uses bbp_reply_url()
1137 * @uses bbp_reply_title()
1138 * @uses bbp_reply_content()
1139 * @uses get_wp_title_rss()
1140 * @uses get_option()
1141 * @uses bloginfo_rss
1142 * @uses self_link()
1143 * @uses the_author()
1144 * @uses get_post_time()
1145 * @uses rss_enclosure()
1146 * @uses do_action()
1147 * @uses apply_filters()
1148 *
1149 * @param array $replies_query
1150 */
1151 function bbp_display_replies_feed_rss2( $replies_query = array() ) {
1152 global $bbp;
1153
1154 // User cannot access forum this topic is in
1155 if ( bbp_is_topic() && !bbp_user_can_view_forum( array( 'forum_id' => bbp_get_topic_forum_id() ) ) )
1156 return;
1157
1158 // Remove any replies from hidden forums
1159 $replies_query = bbp_exclude_forum_ids( $replies_query );
1160
1161 // Adjust the title based on context
1162 if ( bbp_is_topic() && bbp_user_can_view_forum( array( 'forum_id' => bbp_get_topic_forum_id() ) ) )
1163 $title = apply_filters( 'wp_title_rss', get_wp_title_rss( ' &#187; ' ) );
1164 elseif ( !bbp_show_lead_topic() )
1165 $title = ' &#187; ' . __( 'All Posts', 'bbpress' );
1166 else
1167 $title = ' &#187; ' . __( 'All Replies', 'bbpress' );
1168
1169 // Display the feed
1170 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
1171 header( 'Status: 200 OK' );
1172 echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>'; ?>
1173
1174 <rss version="2.0"
1175 xmlns:content="http://purl.org/rss/1.0/modules/content/"
1176 xmlns:wfw="http://wellformedweb.org/CommentAPI/"
1177 xmlns:dc="http://purl.org/dc/elements/1.1/"
1178 xmlns:atom="http://www.w3.org/2005/Atom"
1179
1180 <?php do_action( 'bbp_feed' ); ?>
1181 >
1182
1183 <channel>
1184 <title><?php bloginfo_rss('name'); echo $title; ?></title>
1185 <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
1186 <link><?php self_link(); ?></link>
1187 <description><?php //?></description>
1188 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s O', '', false ); ?></pubDate>
1189 <generator>http://bbpress.org/?v=<?php echo BBP_VERSION; ?></generator>
1190 <language><?php echo get_option( 'rss_language' ); ?></language>
1191
1192 <?php do_action( 'bbp_feed_head' ); ?>
1193
1194 <?php if ( bbp_is_topic() ) : ?>
1195 <?php if ( bbp_user_can_view_forum( array( 'forum_id' => bbp_get_topic_forum_id() ) ) ) : ?>
1196 <?php if ( bbp_show_lead_topic() ) : ?>
1197
1198 <item>
1199 <guid><?php bbp_topic_permalink(); ?></guid>
1200 <title><![CDATA[<?php bbp_topic_title(); ?>]]></title>
1201 <link><?php bbp_topic_permalink(); ?></link>
1202 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
1203 <dc:creator><?php the_author(); ?></dc:creator>
1204
1205 <description>
1206 <![CDATA[
1207 <p><?php printf( __( 'Replies: %s', 'bbpress' ), bbp_get_topic_reply_count() ); ?></p>
1208 <?php bbp_topic_content(); ?>
1209 ]]>
1210 </description>
1211
1212 <?php rss_enclosure(); ?>
1213
1214 <?php do_action( 'bbp_feed_item' ); ?>
1215
1216 </item>
1217
1218 <?php endif; ?>
1219 <?php endif; ?>
1220 <?php endif; ?>
1221
1222 <?php if ( bbp_has_replies( $replies_query ) ) : ?>
1223 <?php while ( bbp_replies() ) : bbp_the_reply(); ?>
1224
1225 <item>
1226 <guid><?php bbp_reply_url(); ?></guid>
1227 <title><![CDATA[<?php bbp_reply_title(); ?>]]></title>
1228 <link><?php bbp_reply_url(); ?></link>
1229 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
1230 <dc:creator><?php the_author() ?></dc:creator>
1231
1232 <description>
1233 <![CDATA[
1234 <?php bbp_reply_content(); ?>
1235 ]]>
1236 </description>
1237
1238 <?php rss_enclosure(); ?>
1239
1240 <?php do_action( 'bbp_feed_item' ); ?>
1241
1242 </item>
1243
1244 <?php endwhile; ?>
1245 <?php endif; ?>
1246
1247 <?php do_action( 'bbp_feed_footer' ); ?>
1248
1249 </channel>
1250 </rss>
1251
1252 <?php
1253
1254 // We're done here
1255 exit();
1256 }
1257
1258 ?>
1259