PluginProbe
bbPress / 2.0-beta-3
bbPress v2.0-beta-3
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-3, at bbp-includes/bbp-reply-functions.php

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