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

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

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