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

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