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-reply-functions.php

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

1,274 lines 45.1 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_safe_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 // Define local variable(s)
150 $topic_id = $forum_id = $reply_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 // Just in time manipulation of reply terms before being edited
273 $terms = apply_filters( 'bbp_new_reply_pre_set_terms', $terms, $topic_id, $reply_id );
274
275 // Insert terms
276 $terms = wp_set_post_terms( $topic_id, $terms, $bbp->topic_tag_id, false );
277
278 // Term error
279 if ( is_wp_error( $terms ) )
280 $bbp->errors->add( 'bbp_reply_tags', __( '<strong>ERROR</strong>: There was some problem adding the tags to the topic.', 'bbpress' ) );
281
282 /** Trash Check ***********************************************/
283
284 // If this reply starts as trash, add it to pre_trashed_replies
285 // for the topic, so it is properly restored.
286 if ( bbp_is_topic_trash( $topic_id ) || ( $reply_data['post_status'] == $bbp->trash_status_id ) ) {
287
288 // Trash the reply
289 wp_trash_post( $reply_id );
290
291 // Get pre_trashed_replies for topic
292 $pre_trashed_replies = get_post_meta( $topic_id, '_bbp_pre_trashed_replies', true );
293
294 // Add this reply to the end of the existing replies
295 $pre_trashed_replies[] = $reply_id;
296
297 // Update the pre_trashed_reply post meta
298 update_post_meta( $topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies );
299 }
300
301 /** Spam Check ************************************************/
302
303 // If reply or topic are spam, officially spam this reply
304 if ( bbp_is_topic_spam( $topic_id ) || ( $reply_data['post_status'] == $bbp->spam_status_id ) )
305 add_post_meta( $reply_id, '_bbp_spam_meta_status', 'publish' );
306
307 /** Update counts, etc... *************************************/
308
309 do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author );
310
311 /** Redirect **************************************************/
312
313 // Redirect to
314 $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
315
316 // Get the reply URL
317 $reply_url = bbp_get_reply_url( $reply_id, $redirect_to );
318
319 // Allow to be filtered
320 $reply_url = apply_filters( 'bbp_new_reply_redirect_to', $reply_url, $redirect_to );
321
322 /** Successful Save *******************************************/
323
324 // Redirect back to new reply
325 wp_safe_redirect( $reply_url );
326
327 // For good measure
328 exit();
329
330 /** Errors ********************************************************/
331
332 } else {
333 $append_error = ( is_wp_error( $reply_id ) && $reply_id->get_error_message() ) ? $reply_id->get_error_message() . ' ' : '';
334 $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' ) );
335 }
336 }
337 }
338 }
339
340 /**
341 * Handles the front end edit reply submission
342 *
343 * @uses bbPress:errors::add() To log various error messages
344 * @uses bbp_get_reply() To get the reply
345 * @uses check_admin_referer() To verify the nonce and check the referer
346 * @uses bbp_is_reply_anonymous() To check if the reply was by an anonymous user
347 * @uses current_user_can() To check if the current user can edit that reply
348 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
349 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
350 * @uses remove_filter() To remove 'wp_filter_kses' filters if needed
351 * @uses esc_attr() For sanitization
352 * @uses apply_filters() Calls 'bbp_edit_reply_pre_title' with the title and
353 * reply id
354 * @uses apply_filters() Calls 'bbp_edit_reply_pre_content' with the content
355 * reply id
356 * @uses wp_set_post_terms() To set the topic tags
357 * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors
358 * @uses wp_save_post_revision() To save a reply revision
359 * @uses bbp_update_topic_revision_log() To update the reply revision log
360 * @uses wp_update_post() To update the reply
361 * @uses bbp_get_reply_topic_id() To get the reply topic id
362 * @uses bbp_get_topic_forum_id() To get the topic forum id
363 * @uses do_action() Calls 'bbp_edit_reply' with the reply id, topic id, forum
364 * id, anonymous data, reply author and bool true (for edit)
365 * @uses bbp_get_reply_url() To get the paginated url to the reply
366 * @uses wp_safe_redirect() To redirect to the reply url
367 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
368 * message
369 */
370 function bbp_edit_reply_handler() {
371
372 // Only proceed if POST is an reply request
373 if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && !empty( $_POST['action'] ) && ( 'bbp-edit-reply' === $_POST['action'] ) ) {
374 global $bbp;
375
376 // Define local variable(s)
377 $reply = $reply_id = $topic_id = $forum_id = $anonymous_data = 0;
378 $reply_title = $reply_content = $reply_edit_reason = $terms = '';
379
380 /** Reply *************************************************************/
381
382 // Reply id was not passed
383 if ( empty( $_POST['bbp_reply_id'] ) )
384 $bbp->errors->add( 'bbp_edit_reply_id', __( '<strong>ERROR</strong>: Reply ID not found.', 'bbpress' ) );
385
386 // Reply id was passed
387 elseif ( is_numeric( $_POST['bbp_reply_id'] ) )
388 $reply_id = (int) $_POST['bbp_reply_id'];
389
390 // Reply does not exist
391 if ( !$reply = bbp_get_reply( $reply_id ) ) {
392 $bbp->errors->add( 'bbp_edit_reply_not_found', __( '<strong>ERROR</strong>: The reply you want to edit was not found.', 'bbpress' ) );
393
394 // Reply exists
395 } else {
396
397 // Nonce check
398 check_admin_referer( 'bbp-edit-reply_' . $reply_id );
399
400 // Check users ability to create new reply
401 if ( !bbp_is_reply_anonymous( $reply_id ) ) {
402
403 // User cannot edit this reply
404 if ( !current_user_can( 'edit_reply', $reply_id ) ) {
405 $bbp->errors->add( 'bbp_edit_reply_permissions', __( '<strong>ERROR</strong>: You do not have permission to edit that reply.', 'bbpress' ) );
406 }
407
408 // It is an anonymous post
409 } else {
410
411 // Filter anonymous data
412 $anonymous_data = bbp_filter_anonymous_post_data( array(), true );
413 }
414 }
415
416 // Remove wp_filter_kses filters from title and content for capable users and if the nonce is verified
417 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'] ) {
418 remove_filter( 'bbp_edit_reply_pre_title', 'wp_filter_kses' );
419 remove_filter( 'bbp_edit_reply_pre_content', 'wp_filter_kses' );
420 }
421
422 /** Reply Topic *******************************************************/
423
424 $topic_id = bbp_get_reply_topic_id( $reply_id );
425
426 /** Reply Forum *******************************************************/
427
428 $forum_id = bbp_get_topic_forum_id( $topic_id );
429
430 // Forum exists
431 if ( !empty( $forum_id ) && ( $forum_id != $reply->post_parent ) ) {
432
433 // Forum is a category
434 if ( bbp_is_forum_category( $forum_id ) )
435 $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' ) );
436
437 // Forum is closed and user cannot access
438 if ( bbp_is_forum_closed( $forum_id ) && !current_user_can( 'edit_forum', $forum_id ) )
439 $bbp->errors->add( 'bbp_edit_reply_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics and replies.', 'bbpress' ) );
440
441 // Forum is private and user cannot access
442 if ( bbp_is_forum_private( $forum_id ) && !current_user_can( 'read_private_forums' ) )
443 $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' ) );
444
445 // Forum is hidden and user cannot access
446 if ( bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) )
447 $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' ) );
448 }
449
450 /** Reply Title *******************************************************/
451
452 if ( !empty( $_POST['bbp_reply_title'] ) )
453 $reply_title = esc_attr( strip_tags( $_POST['bbp_reply_title'] ) );
454
455 // Filter and sanitize
456 $reply_title = apply_filters( 'bbp_edit_reply_pre_title', $reply_title, $reply_id );
457
458 /** Reply Content *****************************************************/
459
460 if ( !empty( $_POST['bbp_reply_content'] ) )
461 $reply_content = $_POST['bbp_reply_content'];
462
463 // Filter and sanitize
464 $reply_content = apply_filters( 'bbp_edit_reply_pre_content', $reply_content, $reply_id );
465
466 // No reply content
467 if ( empty( $reply_content ) )
468 $bbp->errors->add( 'bbp_edit_reply_content', __( '<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress' ) );
469
470 /** Topic Tags ********************************************************/
471
472 if ( !empty( $_POST['bbp_topic_tags'] ) )
473 $terms = esc_attr( strip_tags( $_POST['bbp_topic_tags'] ) );
474
475 /** Additional Actions (Before Save) **********************************/
476
477 do_action( 'bbp_edit_reply_pre_extras', $reply_id );
478
479 /** No Errors *********************************************************/
480
481 // Handle insertion into posts table
482 if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) {
483
484 // Add the content of the form to $post as an array
485 $reply_data = array(
486 'ID' => $reply_id,
487 'post_title' => $reply_title,
488 'post_content' => $reply_content
489 );
490
491 // Just in time manipulation of reply data before being edited
492 $reply_data = apply_filters( 'bbp_edit_reply_pre_insert', $reply_data );
493
494 // Insert reply
495 $reply_id = wp_update_post( $reply_data );
496
497 /** Topic Tags ************************************************/
498
499 // Just in time manipulation of reply terms before being edited
500 $terms = apply_filters( 'bbp_edit_reply_pre_set_terms', $terms, $topic_id, $reply_id );
501
502 // Insert terms
503 $terms = wp_set_post_terms( $topic_id, $terms, $bbp->topic_tag_id, false );
504
505 // Term error
506 if ( is_wp_error( $terms ) )
507 $bbp->errors->add( 'bbp_reply_tags', __( '<strong>ERROR</strong>: There was some problem adding the tags to the topic.', 'bbpress' ) );
508
509 /** Revisions *****************************************************/
510
511 // Revision Reason
512 if ( !empty( $_POST['bbp_reply_edit_reason'] ) )
513 $reply_edit_reason = esc_attr( strip_tags( $_POST['bbp_reply_edit_reason'] ) );
514
515 // Update revision log
516 if ( !empty( $_POST['bbp_log_reply_edit'] ) && ( 1 == $_POST['bbp_log_reply_edit'] ) && ( $revision_id = wp_save_post_revision( $reply_id ) ) ) {
517 bbp_update_reply_revision_log( array(
518 'reply_id' => $reply_id,
519 'revision_id' => $revision_id,
520 'author_id' => bbp_get_current_user_id(),
521 'reason' => $reply_edit_reason
522 ) );
523 }
524
525 /** No Errors *****************************************************/
526
527 if ( !empty( $reply_id ) && !is_wp_error( $reply_id ) ) {
528
529 // Update counts, etc...
530 do_action( 'bbp_edit_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply->post_author , true /* Is edit */ );
531
532 /** Additional Actions (After Save) ***************************/
533
534 do_action( 'bbp_edit_reply_post_extras', $reply_id );
535
536 /** Redirect **************************************************/
537
538 // Redirect to
539 $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
540
541 // Get the reply URL
542 $reply_url = bbp_get_reply_url( $reply_id, $redirect_to );
543
544 // Allow to be filtered
545 $reply_url = apply_filters( 'bbp_edit_reply_redirect_to', $reply_url, $redirect_to );
546
547 /** Successful Edit *******************************************/
548
549 // Redirect back to new reply
550 wp_safe_redirect( $reply_url );
551
552 // For good measure
553 exit();
554
555 /** Errors ********************************************************/
556
557 } else {
558 $append_error = ( is_wp_error( $reply_id ) && $reply_id->get_error_message() ) ? $reply_id->get_error_message() . ' ' : '';
559 $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' ) );
560 }
561 }
562 }
563 }
564
565 /**
566 * Handle all the extra meta stuff from posting a new reply or editing a reply
567 *
568 * @param int $reply_id Optional. Reply id
569 * @param int $topic_id Optional. Topic id
570 * @param int $forum_id Optional. Forum id
571 * @param bool|array $anonymous_data Optional. If it is an array, it is
572 * extracted and anonymous user info is saved
573 * @param int $author_id Author id
574 * @param bool $is_edit Optional. Is the post being edited? Defaults to false.
575 * @uses bbp_get_reply_id() To get the reply id
576 * @uses bbp_get_topic_id() To get the topic id
577 * @uses bbp_get_forum_id() To get the forum id
578 * @uses bbp_get_current_user_id() To get the current user id
579 * @uses bbp_get_reply_topic_id() To get the reply topic id
580 * @uses bbp_get_topic_forum_id() To get the topic forum id
581 * @uses update_post_meta() To update the reply metas
582 * @uses set_transient() To update the flood check transient for the ip
583 * @uses update_user_meta() To update the last posted meta for the user
584 * @uses bbp_is_subscriptions_active() To check if the subscriptions feature is
585 * activated or not
586 * @uses bbp_is_user_subscribed() To check if the user is subscribed
587 * @uses bbp_remove_user_subscription() To remove the user's subscription
588 * @uses bbp_add_user_subscription() To add the user's subscription
589 * @uses bbp_update_reply_forum_id() To update the reply forum id
590 * @uses bbp_update_reply_topic_id() To update the reply topic id
591 * @uses bbp_update_reply_walker() To update the reply's ancestors' counts
592 */
593 function bbp_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) {
594
595 // Validate the ID's passed from 'bbp_new_reply' action
596 $reply_id = bbp_get_reply_id( $reply_id );
597 $topic_id = bbp_get_topic_id( $topic_id );
598 $forum_id = bbp_get_forum_id( $forum_id );
599
600 // Check author_id
601 if ( empty( $author_id ) )
602 $author_id = bbp_get_current_user_id();
603
604 // Check topic_id
605 if ( empty( $topic_id ) )
606 $topic_id = bbp_get_reply_topic_id( $reply_id );
607
608 // Check forum_id
609 if ( !empty( $topic_id ) && empty( $forum_id ) )
610 $forum_id = bbp_get_topic_forum_id( $topic_id );
611
612 // If anonymous post, store name, email, website and ip in post_meta.
613 // It expects anonymous_data to be sanitized.
614 // Check bbp_filter_anonymous_post_data() for sanitization.
615 if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) {
616 extract( $anonymous_data );
617
618 update_post_meta( $reply_id, '_bbp_anonymous_name', $bbp_anonymous_name, false );
619 update_post_meta( $reply_id, '_bbp_anonymous_email', $bbp_anonymous_email, false );
620
621 // Set transient for throttle check (only on new, not edit)
622 if ( empty( $is_edit ) )
623 set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time() );
624
625 // Website is optional
626 if ( !empty( $bbp_anonymous_website ) )
627 update_post_meta( $reply_id, '_bbp_anonymous_website', $bbp_anonymous_website, false );
628
629 } else {
630 if ( empty( $is_edit ) && !current_user_can( 'throttle' ) )
631 update_user_meta( $author_id, '_bbp_last_posted', time() );
632 }
633
634 // Handle Subscription Checkbox
635 if ( bbp_is_subscriptions_active() && !empty( $author_id ) ) {
636 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
637 $subscheck = ( !empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' == $_POST['bbp_topic_subscription'] ) ) ? true : false;
638
639 // Subscribed and unsubscribing
640 if ( true == $subscribed && false == $subscheck )
641 bbp_remove_user_subscription( $author_id, $topic_id );
642
643 // Subscribing
644 elseif ( false == $subscribed && true == $subscheck )
645 bbp_add_user_subscription( $author_id, $topic_id );
646 }
647
648 // Reply meta relating to reply position in tree
649 bbp_update_reply_forum_id( $reply_id, $forum_id );
650 bbp_update_reply_topic_id( $reply_id, $topic_id );
651
652 // Update associated topic values if this is a new reply
653 if ( empty( $is_edit ) ) {
654
655 // Update poster IP if not editing
656 update_post_meta( $reply_id, '_bbp_author_ip', bbp_current_author_ip(), false );
657
658 // Last active time
659 $last_active_time = current_time( 'mysql' );
660
661 // Walk up ancestors and do the dirty work
662 bbp_update_reply_walker( $reply_id, $last_active_time, $forum_id, $topic_id, false );
663 }
664 }
665
666 /**
667 * Walk up the ancestor tree from the current reply, and update all the counts
668 *
669 * @since bbPress (r2884)
670 *
671 * @param int $reply_id Optional. Reply id
672 * @param string $last_active_time Optional. Last active time
673 * @param int $forum_id Optional. Forum id
674 * @param int $topic_id Optional. Topic id
675 * @param bool $refresh If set to true, unsets all the previous parameters.
676 * Defaults to true
677 * @uses bbp_get_reply_id() To get the reply id
678 * @uses bbp_get_reply_topic_id() To get the reply topic id
679 * @uses bbp_get_reply_forum_id() To get the reply forum id
680 * @uses get_post_ancestors() To get the ancestors of the reply
681 * @uses bbp_is_reply() To check if the ancestor is a reply
682 * @uses bbp_is_topic() To check if the ancestor is a topic
683 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
684 * @uses bbp_update_topic_last_active_id() To update the topic last active id
685 * @uses bbp_get_topic_last_active_id() To get the topic last active id
686 * @uses get_post_field() To get the post date of the last active id
687 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
688 * @uses bbp_update_topic_voice_count() To update the topic voice count
689 * @uses bbp_update_topic_reply_count() To update the topic reply count
690 * @uses bbp_update_topic_hidden_reply_count() To update the topic hidden reply
691 * count
692 * @uses bbp_is_forum() To check if the ancestor is a forum
693 * @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
694 * @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
695 * @uses bbp_update_forum_last_active_id() To update the forum last active id
696 * @uses bbp_get_forum_last_active_id() To get the forum last active id
697 * @uses bbp_update_forum_last_active_time() To update the forum last active time
698 * @uses bbp_update_forum_reply_count() To update the forum reply count
699 */
700 function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true ) {
701 global $bbp;
702
703 // Verify the reply ID
704 if ( $reply_id = bbp_get_reply_id( $reply_id ) ) {
705
706 // Get the topic ID if none was passed
707 if ( empty( $topic_id ) )
708 $topic_id = bbp_get_reply_topic_id( $reply_id );
709
710 // Get the forum ID if none was passed
711 if ( empty( $forum_id ) )
712 $forum_id = bbp_get_reply_forum_id( $reply_id );
713 }
714
715 // Set the active_id based on topic_id/reply_id
716 $active_id = empty( $reply_id ) ? $topic_id : $reply_id;
717
718 // Setup ancestors array to walk up
719 $ancestors = array_values( array_unique( array_merge( array( $topic_id, $forum_id ), get_post_ancestors( $topic_id ) ) ) );
720
721 // If we want a full refresh, unset any of the possibly passed variables
722 if ( true == $refresh )
723 $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
724
725 // Walk up ancestors
726 foreach ( $ancestors as $ancestor ) {
727
728 // Reply meta relating to most recent reply
729 if ( bbp_is_reply( $ancestor ) ) {
730 // @todo - hierarchical replies
731
732 // Topic meta relating to most recent reply
733 } elseif ( bbp_is_topic( $ancestor ) ) {
734
735 // Last reply and active ID's
736 bbp_update_topic_last_reply_id ( $ancestor, $reply_id );
737 bbp_update_topic_last_active_id ( $ancestor, $active_id );
738
739 // Get the last active time if none was passed
740 if ( empty( $last_active_time ) )
741 $topic_last_active_time = get_post_field( 'post_date', bbp_get_topic_last_active_id( $ancestor ) );
742 else
743 $topic_last_active_time = $last_active_time;
744
745 bbp_update_topic_last_active_time ( $ancestor, $topic_last_active_time );
746
747 // Counts
748 bbp_update_topic_voice_count ( $ancestor );
749 bbp_update_topic_reply_count ( $ancestor );
750 bbp_update_topic_hidden_reply_count( $ancestor );
751
752 // Forum meta relating to most recent topic
753 } elseif ( bbp_is_forum( $ancestor ) ) {
754
755 // Last topic and reply ID's
756 bbp_update_forum_last_topic_id( $ancestor, $topic_id );
757 bbp_update_forum_last_reply_id( $ancestor, $reply_id );
758
759 // Last Active
760 bbp_update_forum_last_active_id( $ancestor, $active_id );
761
762 if ( empty( $last_active_time ) )
763 $forum_last_active_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $ancestor ) );
764 else
765 $forum_last_active_time = $last_active_time;
766
767 bbp_update_forum_last_active_time( $ancestor, $forum_last_active_time );
768
769 // Counts
770 bbp_update_forum_reply_count( $ancestor );
771 }
772 }
773 }
774
775 /**
776 * Update the revision log of the reply
777 *
778 * @since bbPress (r2782)
779 *
780 * @param mixed $args Supports these args:
781 * - reply_id: reply id
782 * - author_id: Author id
783 * - reason: Reason for editing
784 * - revision_id: Revision id
785 * @uses bbp_get_reply_id() To get the reply id
786 * @uses bbp_get_user_id() To get the user id
787 * @uses bbp_format_revision_reason() To format the reason
788 * @uses bbp_get_reply_raw_revision_log() To get the raw reply revision log
789 * @uses update_post_meta() To update the reply revision log meta
790 * @return mixed False on failure, true on success
791 */
792 function bbp_update_reply_revision_log( $args = '' ) {
793 $defaults = array (
794 'reason' => '',
795 'reply_id' => 0,
796 'author_id' => 0,
797 'revision_id' => 0
798 );
799
800 $r = wp_parse_args( $args, $defaults );
801 extract( $r );
802
803 // Populate the variables
804 $reason = bbp_format_revision_reason( $reason );
805 $reply_id = bbp_get_reply_id( $reply_id );
806 $author_id = bbp_get_user_id ( $author_id, false, true );
807 $revision_id = (int) $revision_id;
808
809 // Get the logs and append the new one to those
810 $revision_log = bbp_get_reply_raw_revision_log( $reply_id );
811 $revision_log[$revision_id] = array( 'author' => $author_id, 'reason' => $reason );
812
813 // Finally, update
814 update_post_meta( $reply_id, '_bbp_revision_log', $revision_log );
815
816 return apply_filters( 'bbp_update_reply_revision_log', $revision_log, $reply_id );
817 }
818
819 /** Reply Actions *************************************************************/
820
821 /**
822 * Handles the front end spamming/unspamming and trashing/untrashing/deleting of
823 * replies
824 *
825 * @since bbPress (r2740)
826 *
827 * @uses bbp_get_reply() To get the reply
828 * @uses current_user_can() To check if the user is capable of editing or
829 * deleting the reply
830 * @uses check_ajax_referer() To verify the nonce and check the referer
831 * @uses bbp_get_reply_post_type() To get the reply post type
832 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
833 * @uses bbp_spam_reply() To make the reply as spam
834 * @uses bbp_unspam_reply() To unmark the reply as spam
835 * @uses wp_trash_post() To trash the reply
836 * @uses wp_untrash_post() To untrash the reply
837 * @uses wp_delete_post() To delete the reply
838 * @uses do_action() Calls 'bbp_toggle_reply_handler' with success, post data
839 * and action
840 * @uses bbp_get_reply_url() To get the reply url
841 * @uses add_query_arg() To add custom args to the reply url
842 * @uses wp_redirect() To redirect to the reply
843 * @uses bbPress::errors:add() To log the error messages
844 */
845 function bbp_toggle_reply_handler() {
846
847 // Only proceed if GET is a reply toggle action
848 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' ) ) ) {
849 global $bbp;
850
851 $action = $_GET['action']; // What action is taking place?
852 $reply_id = (int) $_GET['reply_id']; // What's the reply id?
853 $success = false; // Flag
854 $post_data = array( 'ID' => $reply_id ); // Prelim array
855
856 // Make sure reply exists
857 if ( !$reply = bbp_get_reply( $reply_id ) )
858 return;
859
860 // What is the user doing here?
861 if ( !current_user_can( 'edit_reply', $reply->ID ) || ( 'bbp_toggle_reply_trash' == $action && !current_user_can( 'delete_reply', $reply->ID ) ) ) {
862 $bbp->errors->add( 'bbp_toggle_reply_permission', __( '<strong>ERROR:</strong> You do not have the permission to do that!', 'bbpress' ) );
863 return;
864 }
865
866 // What action are we trying to perform?
867 switch ( $action ) {
868
869 // Toggle spam
870 case 'bbp_toggle_reply_spam' :
871 check_ajax_referer( 'spam-reply_' . $reply_id );
872
873 $is_spam = bbp_is_reply_spam( $reply_id );
874 $success = $is_spam ? bbp_unspam_reply( $reply_id ) : bbp_spam_reply( $reply_id );
875 $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' );
876
877 break;
878
879 // Toggle trash
880 case 'bbp_toggle_reply_trash' :
881
882 $sub_action = in_array( $_GET['sub_action'], array( 'trash', 'untrash', 'delete' ) ) ? $_GET['sub_action'] : false;
883
884 if ( empty( $sub_action ) )
885 break;
886
887 switch ( $sub_action ) {
888 case 'trash':
889 check_ajax_referer( 'trash-' . bbp_get_reply_post_type() . '_' . $reply_id );
890
891 $success = wp_trash_post( $reply_id );
892 $failure = __( '<strong>ERROR</strong>: There was a problem trashing the reply!', 'bbpress' );
893
894 break;
895
896 case 'untrash':
897 check_ajax_referer( 'untrash-' . bbp_get_reply_post_type() . '_' . $reply_id );
898
899 $success = wp_untrash_post( $reply_id );
900 $failure = __( '<strong>ERROR</strong>: There was a problem untrashing the reply!', 'bbpress' );
901
902 break;
903
904 case 'delete':
905 check_ajax_referer( 'delete-' . bbp_get_reply_post_type() . '_' . $reply_id );
906
907 $success = wp_delete_post( $reply_id );
908 $failure = __( '<strong>ERROR</strong>: There was a problem deleting the reply!', 'bbpress' );
909
910 break;
911 }
912
913 break;
914 }
915
916 // Do additional reply toggle actions
917 do_action( 'bbp_toggle_reply_handler', $success, $post_data, $action );
918
919 // No errors
920 if ( ( false != $success ) && !is_wp_error( $success ) ) {
921
922 // Redirect back to the reply
923 $redirect = bbp_get_reply_url( $reply_id );
924 wp_redirect( $redirect );
925
926 // For good measure
927 exit();
928
929 // Handle errors
930 } else {
931 $bbp->errors->add( 'bbp_toggle_reply', $failure );
932 }
933 }
934 }
935
936 /** Reply Actions *************************************************************/
937
938 /**
939 * Marks a reply as spam
940 *
941 * @since bbPress (r2740)
942 *
943 * @param int $reply_id Reply id
944 * @uses wp_get_single_post() To get the reply
945 * @uses do_action() Calls 'bbp_spam_reply' with the reply ID
946 * @uses add_post_meta() To add the previous status to a meta
947 * @uses wp_insert_post() To insert the updated post
948 * @uses do_action() Calls 'bbp_spammed_reply' with the reply ID
949 * @return mixed False or {@link WP_Error} on failure, reply id on success
950 */
951 function bbp_spam_reply( $reply_id = 0 ) {
952 global $bbp;
953
954 // Get reply
955 if ( !$reply = wp_get_single_post( $reply_id, ARRAY_A ) )
956 return $reply;
957
958 // Bail if already spam
959 if ( $reply['post_status'] == $bbp->spam_status_id )
960 return false;
961
962 // Execute pre spam code
963 do_action( 'bbp_spam_reply', $reply_id );
964
965 // Add the original post status as post meta for future restoration
966 add_post_meta( $reply_id, '_bbp_spam_meta_status', $reply['post_status'] );
967
968 // Set post status to spam
969 $reply['post_status'] = $bbp->spam_status_id;
970
971 // No revisions
972 remove_action( 'pre_post_update', 'wp_save_post_revision' );
973
974 // Update the reply
975 $reply_id = wp_insert_post( $reply );
976
977 // Execute post spam code
978 do_action( 'bbp_spammed_reply', $reply_id );
979
980 // Return reply_id
981 return $reply_id;
982 }
983
984 /**
985 * Unspams a reply
986 *
987 * @since bbPress (r2740)
988 *
989 * @param int $reply_id Reply id
990 * @uses wp_get_single_post() To get the reply
991 * @uses do_action() Calls 'bbp_unspam_reply' with the reply ID
992 * @uses get_post_meta() To get the previous status meta
993 * @uses delete_post_meta() To delete the previous status meta
994 * @uses wp_insert_post() To insert the updated post
995 * @uses do_action() Calls 'bbp_unspammed_reply' with the reply ID
996 * @return mixed False or {@link WP_Error} on failure, reply id on success
997 */
998 function bbp_unspam_reply( $reply_id = 0 ) {
999 global $bbp;
1000
1001 // Get reply
1002 if ( !$reply = wp_get_single_post( $reply_id, ARRAY_A ) )
1003 return $reply;
1004
1005 // Bail if already not spam
1006 if ( $reply['post_status'] != $bbp->spam_status_id )
1007 return false;
1008
1009 // Execute pre unspam code
1010 do_action( 'bbp_unspam_reply', $reply_id );
1011
1012 // Get pre spam status
1013 $reply_status = get_post_meta( $reply_id, '_bbp_spam_meta_status', true );
1014
1015 // Set post status to pre spam
1016 $reply['post_status'] = $reply_status;
1017
1018 // Delete pre spam meta
1019 delete_post_meta( $reply_id, '_bbp_spam_meta_status' );
1020
1021 // No revisions
1022 remove_action( 'pre_post_update', 'wp_save_post_revision' );
1023
1024 // Update the reply
1025 $reply_id = wp_insert_post( $reply );
1026
1027 // Execute post unspam code
1028 do_action( 'bbp_unspammed_reply', $reply_id );
1029
1030 // Return reply_id
1031 return $reply_id;
1032 }
1033
1034 /** Before Delete/Trash/Untrash ***********************************************/
1035
1036 /**
1037 * Called before deleting a reply
1038 *
1039 * @uses bbp_get_reply_id() To get the reply id
1040 * @uses bbp_is_reply() To check if the passed id is a reply
1041 * @uses do_action() Calls 'bbp_delete_reply' with the reply id
1042 */
1043 function bbp_delete_reply( $reply_id = 0 ) {
1044 $reply_id = bbp_get_reply_id( $reply_id );
1045
1046 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1047 return false;
1048
1049 do_action( 'bbp_delete_reply', $reply_id );
1050 }
1051
1052 /**
1053 * Called before trashing a reply
1054 *
1055 * @uses bbp_get_reply_id() To get the reply id
1056 * @uses bbp_is_reply() To check if the passed id is a reply
1057 * @uses do_action() Calls 'bbp_trash_reply' with the reply id
1058 */
1059 function bbp_trash_reply( $reply_id = 0 ) {
1060 $reply_id = bbp_get_reply_id( $reply_id );
1061
1062 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1063 return false;
1064
1065 do_action( 'bbp_trash_reply', $reply_id );
1066 }
1067
1068 /**
1069 * Called before untrashing (restoring) a reply
1070 *
1071 * @uses bbp_get_reply_id() To get the reply id
1072 * @uses bbp_is_reply() To check if the passed id is a reply
1073 * @uses do_action() Calls 'bbp_unstrash_reply' with the reply id
1074 */
1075 function bbp_untrash_reply( $reply_id = 0 ) {
1076 $reply_id = bbp_get_reply_id( $reply_id );
1077
1078 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1079 return false;
1080
1081 do_action( 'bbp_untrash_reply', $reply_id );
1082 }
1083
1084 /** After Delete/Trash/Untrash ************************************************/
1085
1086 /**
1087 * Called after deleting a reply
1088 *
1089 * @uses bbp_get_reply_id() To get the reply id
1090 * @uses bbp_is_reply() To check if the passed id is a reply
1091 * @uses do_action() Calls 'bbp_deleted_reply' with the reply id
1092 */
1093 function bbp_deleted_reply( $reply_id = 0 ) {
1094 $reply_id = bbp_get_reply_id( $reply_id );
1095
1096 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1097 return false;
1098
1099 do_action( 'bbp_deleted_reply', $reply_id );
1100 }
1101
1102 /**
1103 * Called after trashing a reply
1104 *
1105 * @uses bbp_get_reply_id() To get the reply id
1106 * @uses bbp_is_reply() To check if the passed id is a reply
1107 * @uses do_action() Calls 'bbp_trashed_reply' with the reply id
1108 */
1109 function bbp_trashed_reply( $reply_id = 0 ) {
1110 $reply_id = bbp_get_reply_id( $reply_id );
1111
1112 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1113 return false;
1114
1115 do_action( 'bbp_trashed_reply', $reply_id );
1116 }
1117
1118 /**
1119 * Called after untrashing (restoring) a reply
1120 *
1121 * @uses bbp_get_reply_id() To get the reply id
1122 * @uses bbp_is_reply() To check if the passed id is a reply
1123 * @uses do_action() Calls 'bbp_untrashed_reply' with the reply id
1124 */
1125 function bbp_untrashed_reply( $reply_id = 0 ) {
1126 $reply_id = bbp_get_reply_id( $reply_id );
1127
1128 if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) )
1129 return false;
1130
1131 do_action( 'bbp_untrashed_reply', $reply_id );
1132 }
1133
1134 /** Feeds *********************************************************************/
1135
1136 /**
1137 * Output an RSS2 feed of replies, based on the query passed.
1138 *
1139 * @since bbPress (r3171)
1140 *
1141 * @global bbPress $bbp
1142 *
1143 * @uses bbp_is_topic()
1144 * @uses bbp_user_can_view_forum()
1145 * @uses bbp_get_topic_forum_id()
1146 * @uses bbp_show_load_topic()
1147 * @uses bbp_topic_permalink()
1148 * @uses bbp_topic_title()
1149 * @uses bbp_get_topic_reply_count()
1150 * @uses bbp_topic_content()
1151 * @uses bbp_has_replies()
1152 * @uses bbp_replies()
1153 * @uses bbp_the_reply()
1154 * @uses bbp_reply_url()
1155 * @uses bbp_reply_title()
1156 * @uses bbp_reply_content()
1157 * @uses get_wp_title_rss()
1158 * @uses get_option()
1159 * @uses bloginfo_rss
1160 * @uses self_link()
1161 * @uses the_author()
1162 * @uses get_post_time()
1163 * @uses rss_enclosure()
1164 * @uses do_action()
1165 * @uses apply_filters()
1166 *
1167 * @param array $replies_query
1168 */
1169 function bbp_display_replies_feed_rss2( $replies_query = array() ) {
1170 global $bbp;
1171
1172 // User cannot access forum this topic is in
1173 if ( bbp_is_topic() && !bbp_user_can_view_forum( array( 'forum_id' => bbp_get_topic_forum_id() ) ) )
1174 return;
1175
1176 // Adjust the title based on context
1177 if ( bbp_is_topic() && bbp_user_can_view_forum( array( 'forum_id' => bbp_get_topic_forum_id() ) ) )
1178 $title = apply_filters( 'wp_title_rss', get_wp_title_rss( ' &#187; ' ) );
1179 elseif ( !bbp_show_lead_topic() )
1180 $title = ' &#187; ' . __( 'All Posts', 'bbpress' );
1181 else
1182 $title = ' &#187; ' . __( 'All Replies', 'bbpress' );
1183
1184 // Display the feed
1185 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
1186 header( 'Status: 200 OK' );
1187 echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>'; ?>
1188
1189 <rss version="2.0"
1190 xmlns:content="http://purl.org/rss/1.0/modules/content/"
1191 xmlns:wfw="http://wellformedweb.org/CommentAPI/"
1192 xmlns:dc="http://purl.org/dc/elements/1.1/"
1193 xmlns:atom="http://www.w3.org/2005/Atom"
1194
1195 <?php do_action( 'bbp_feed' ); ?>
1196 >
1197
1198 <channel>
1199 <title><?php bloginfo_rss('name'); echo $title; ?></title>
1200 <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
1201 <link><?php self_link(); ?></link>
1202 <description><?php //?></description>
1203 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s O', '', false ); ?></pubDate>
1204 <generator>http://bbpress.org/?v=<?php echo BBP_VERSION; ?></generator>
1205 <language><?php echo get_option( 'rss_language' ); ?></language>
1206
1207 <?php do_action( 'bbp_feed_head' ); ?>
1208
1209 <?php if ( bbp_is_topic() ) : ?>
1210 <?php if ( bbp_user_can_view_forum( array( 'forum_id' => bbp_get_topic_forum_id() ) ) ) : ?>
1211 <?php if ( bbp_show_lead_topic() ) : ?>
1212
1213 <item>
1214 <guid><?php bbp_topic_permalink(); ?></guid>
1215 <title><![CDATA[<?php bbp_topic_title(); ?>]]></title>
1216 <link><?php bbp_topic_permalink(); ?></link>
1217 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
1218 <dc:creator><?php the_author(); ?></dc:creator>
1219
1220 <description>
1221 <![CDATA[
1222 <p><?php printf( __( 'Replies: %s', 'bbpress' ), bbp_get_topic_reply_count() ); ?></p>
1223 <?php bbp_topic_content(); ?>
1224 ]]>
1225 </description>
1226
1227 <?php rss_enclosure(); ?>
1228
1229 <?php do_action( 'bbp_feed_item' ); ?>
1230
1231 </item>
1232
1233 <?php endif; ?>
1234 <?php endif; ?>
1235 <?php endif; ?>
1236
1237 <?php if ( bbp_has_replies( $replies_query ) ) : ?>
1238 <?php while ( bbp_replies() ) : bbp_the_reply(); ?>
1239
1240 <item>
1241 <guid><?php bbp_reply_url(); ?></guid>
1242 <title><![CDATA[<?php bbp_reply_title(); ?>]]></title>
1243 <link><?php bbp_reply_url(); ?></link>
1244 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
1245 <dc:creator><?php the_author() ?></dc:creator>
1246
1247 <description>
1248 <![CDATA[
1249 <?php bbp_reply_content(); ?>
1250 ]]>
1251 </description>
1252
1253 <?php rss_enclosure(); ?>
1254
1255 <?php do_action( 'bbp_feed_item' ); ?>
1256
1257 </item>
1258
1259 <?php endwhile; ?>
1260 <?php endif; ?>
1261
1262 <?php do_action( 'bbp_feed_footer' ); ?>
1263
1264 </channel>
1265 </rss>
1266
1267 <?php
1268
1269 // We're done here
1270 exit();
1271 }
1272
1273 ?>
1274