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

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