PluginProbe
bbPress / 2.0.3
bbPress v2.0.3
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 2.2.2 All 71 releases
bbpress / bbp-admin / bbp-replies.php

bbp-replies.php in bbPress 2.0.3, at bbp-admin/bbp-replies.php

882 lines 32.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 Replies Admin Class
5 *
6 * @package bbPress
7 * @subpackage Administration
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 if ( !class_exists( 'BBP_Replies_Admin' ) ) :
14 /**
15 * Loads bbPress replies admin area
16 *
17 * @package bbPress
18 * @subpackage Administration
19 * @since bbPress (r2464)
20 */
21 class BBP_Replies_Admin {
22
23 /** Variables *************************************************************/
24
25 /**
26 * @var The post type of this admin component
27 */
28 var $post_type = '';
29
30 /** Functions *************************************************************/
31
32 /**
33 * The main bbPress admin loader
34 *
35 * @since bbPress (r2515)
36 *
37 * @uses BBP_Replies_Admin::setup_globals() Setup the globals needed
38 * @uses BBP_Replies_Admin::setup_actions() Setup the hooks and actions
39 * @uses BBP_Replies_Admin::setup_actions() Setup the help text
40 */
41 function __construct() {
42 $this->setup_globals();
43 $this->setup_actions();
44 $this->setup_help();
45 }
46
47 /**
48 * Setup the admin hooks, actions and filters
49 *
50 * @since bbPress (r2646)
51 * @access private
52 *
53 * @uses add_action() To add various actions
54 * @uses add_filter() To add various filters
55 * @uses bbp_get_forum_post_type() To get the forum post type
56 * @uses bbp_get_topic_post_type() To get the topic post type
57 * @uses bbp_get_reply_post_type() To get the reply post type
58 */
59 function setup_actions() {
60
61 // Add some general styling to the admin area
62 add_action( 'admin_head', array( $this, 'admin_head' ) );
63
64 // Messages
65 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
66
67 // Reply column headers.
68 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'replies_column_headers' ) );
69
70 // Reply columns (in post row)
71 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'replies_column_data' ), 10, 2 );
72 add_filter( 'post_row_actions', array( $this, 'replies_row_actions' ), 10, 2 );
73
74 // Reply metabox actions
75 add_action( 'add_meta_boxes', array( $this, 'reply_attributes_metabox' ) );
76 add_action( 'save_post', array( $this, 'reply_attributes_metabox_save' ) );
77
78 // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed
79 add_action( 'bbp_admin_init', array( $this, 'toggle_reply' ) );
80 add_action( 'admin_notices', array( $this, 'toggle_reply_notice' ) );
81
82 // Anonymous metabox actions
83 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) );
84 add_action( 'save_post', array( $this, 'author_metabox_save' ) );
85
86 // Add ability to filter topics and replies per forum
87 add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) );
88 add_filter( 'request', array( $this, 'filter_post_rows' ) );
89 }
90
91 /**
92 * Admin globals
93 *
94 * @since bbPress (r2646)
95 * @access private
96 */
97 function setup_globals() {
98
99 // Setup the post type for this admin component
100 $this->post_type = bbp_get_reply_post_type();
101 }
102
103 /**
104 * Contextual help for replies
105 *
106 * @since bbPress (r3119)
107 * @access private
108 */
109 function setup_help() {
110
111 // Define local variable(s)
112 $contextual_help = array();
113
114 /** New/Edit **********************************************************/
115
116 $bbp_contextual_help[] = __( 'The reply title field and the big reply editing area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of the box. Use the Screen Options tab to unhide more boxes (Reply Attributes, Slug) or to choose a 1- or 2-column layout for this screen.', 'bbpress' );
117 $bbp_contextual_help[] = __( '<strong>Title</strong> - Enter a title for your reply. After you enter a title, you will see the permalink below, which you can edit.', 'bbpress' );
118 $bbp_contextual_help[] = __( '<strong>Post editor</strong> - Enter the text for your reply. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The screen icon just before that allows you to expand the edit box to full screen. The HTML mode allows you to enter raw HTML along with your forum text. You can insert media files by clicking the icons above the post editor and following the directions.', 'bbpress' );
119 $bbp_contextual_help[] = __( '<strong>Reply Attributes</strong> - Select the attributes that your reply should have. The Parent Topic dropdown determines the parent topic that the reply belongs to.', 'bbpress' );
120 $bbp_contextual_help[] = __( '<strong>Publish</strong> - The Publish box will allow you to save your reply as Draft or Pending Review. You may Preview your reply before it is published as well. The Visibility will determine whether the reply is Public, Password protected (requiring a password on the site to view) or Private (only the author will have access to it). Replies may be published immediately by clicking the dropdown, or at a specific date and time by clicking the Edit link.', 'bbpress' );
121 $bbp_contextual_help[] = __( '<strong>Revisions</strong> - Revisions show past versions of the saved reply. Each revision can be compared to the current version, or another revision. Revisions can also be restored to the current version.', 'bbpress' );
122 $bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' );
123 $bbp_contextual_help[] =
124 '<ul>' .
125 '<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' .
126 '<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>', 'bbpress' ) . '</li>' .
127 '</ul>' ;
128
129 // Wrap each help item in paragraph tags
130 foreach( $bbp_contextual_help as $paragraph )
131 $contextual_help .= '<p>' . $paragraph . '</p>';
132
133 // Add help
134 add_contextual_help( bbp_get_reply_post_type(), $contextual_help );
135
136 // Reset
137 $contextual_help = $bbp_contextual_help = '';
138
139 /** Post Rows *********************************************************/
140
141 $bbp_contextual_help[] = __( 'This screen displays the replies created on your site.', 'bbpress' );
142 $bbp_contextual_help[] = __( 'You can customize the display of this screen in a number of ways:', 'bbpress' );
143 $bbp_contextual_help[] =
144 '<ul>' .
145 '<li>' . __( 'You can hide/display columns based on your needs (Forum, Topic, Author, and Created) and decide how many replies to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' .
146 '<li>' . __( 'You can filter the list of replies by reply status using the text links in the upper left to show All, Published, Pending Review, Draft, or Trashed topics. The default view is to show all replies.', 'bbpress' ) . '</li>' .
147 '<li>' . __( 'You can view replies in a simple title list or with an excerpt. Choose the view you prefer by clicking on the icons at the top of the list on the right.', 'bbpress' ) . '</li>' .
148 '<li>' . __( 'You can refine the list to show only replies from a specific month by using the dropdown menus above the replies list. Click the Filter button after making your selection.', 'bbpress' ) . '</li>' .
149 '<li>' . __( 'You can also show only replies from a specific parent forum by using the parent forum dropdown above the replies list and selecting the parent forum. Click the Filter button after making your selection.', 'bbpress' ) . '</li>' .
150 '</ul>';
151
152 $bbp_contextual_help[] = __( 'Hovering over a row in the replies list will display action links that allow you to manage your reply. You can perform the following actions:', 'bbpress' );
153 $bbp_contextual_help[] =
154 '<ul>' .
155 '<li>' . __( 'Edit takes you to the editing screen for that reply. You can also reach that screen by clicking on the reply title.', 'bbpress' ) . '</li>' .
156 '<li>' . __( 'Trash removes your reply from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
157 '<li>' . __( 'View will take you to your live reply to view the reply.', 'bbpress' ) . '</li>' .
158 '<li>' . __( 'Spam will mark the topic as spam, preventing further replies to it and removing it from the site&rsquo;s public view.', 'bbpress' ) . '</li>' .
159 '</ul>';
160
161 $bbp_contextual_help[] = __( 'You can also edit multiple replies at once. Select the replies you want to edit using the checkboxes, select Edit from the Bulk Actions menu and click Apply. You will be able to change the metadata for all selected replies at once. To remove a reply from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' );
162 $bbp_contextual_help[] = __( 'The Bulk Actions menu may also be used to delete multiple replies at once. Select Delete from the dropdown after making your selection.', 'bbpress' );
163 $bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' );
164 $bbp_contextual_help[] =
165 '<ul>' .
166 '<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' .
167 '<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>', 'bbpress', 'bbpress' ) . '</li>' .
168 '</ul>';
169
170 // Wrap each help item in paragraph tags
171 foreach( $bbp_contextual_help as $paragraph )
172 $contextual_help .= '<p>' . $paragraph . '</p>';
173
174 // Add help
175 add_contextual_help( 'edit-' . bbp_get_reply_post_type(), $contextual_help );
176 }
177
178 /**
179 * Add the reply attributes metabox
180 *
181 * @since bbPress (r2746)
182 *
183 * @uses bbp_get_reply_post_type() To get the reply post type
184 * @uses add_meta_box() To add the metabox
185 * @uses do_action() Calls 'bbp_reply_attributes_metabox'
186 */
187 function reply_attributes_metabox() {
188 add_meta_box (
189 'bbp_reply_attributes',
190 __( 'Reply Attributes', 'bbpress' ),
191 'bbp_reply_metabox',
192 $this->post_type,
193 'side',
194 'high'
195 );
196
197 do_action( 'bbp_reply_attributes_metabox' );
198 }
199
200 /**
201 * Pass the reply attributes for processing
202 *
203 * @since bbPress (r2746)
204 *
205 * @param int $reply_id Reply id
206 * @uses current_user_can() To check if the current user is capable of
207 * editing the reply
208 * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the
209 * reply id and parent id
210 * @return int Parent id
211 */
212 function reply_attributes_metabox_save( $reply_id ) {
213
214 // Bail if doing an autosave
215 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
216 return $reply_id;
217
218 // Bail if not a post request
219 if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
220 return $reply_id;
221
222 // Check action exists
223 if ( empty( $_POST['action'] ) )
224 return $reply_id;
225
226 // Bail if post_type is not a reply
227 if ( get_post_type( $reply_id ) != $this->post_type )
228 return;
229
230 // Current user cannot edit this reply
231 if ( !current_user_can( 'edit_reply', $reply_id ) )
232 return $reply_id;
233
234 // Get the reply meta post values
235 $topic_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
236 $forum_id = !empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id );
237
238 // Formally update the reply
239 bbp_update_reply( $reply_id, $topic_id, $forum_id );
240
241 // Allow other fun things to happen
242 do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id );
243
244 return $reply_id;
245 }
246
247 /**
248 * Add the author info metabox
249 *
250 * Allows editing of information about an author
251 *
252 * @since bbPress (r2828)
253 *
254 * @uses bbp_get_topic() To get the topic
255 * @uses bbp_get_reply() To get the reply
256 * @uses bbp_get_topic_post_type() To get the topic post type
257 * @uses bbp_get_reply_post_type() To get the reply post type
258 * @uses add_meta_box() To add the metabox
259 * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply
260 * id
261 */
262 function author_metabox() {
263 global $current_screen;
264
265 // Bail if post_type is not a reply
266 if ( ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) ) || ( get_post_type() != $this->post_type ) )
267 return;
268
269 // Add the metabox
270 add_meta_box(
271 'bbp_author_metabox',
272 __( 'Author Information', 'bbpress' ),
273 'bbp_author_metabox',
274 $this->post_type,
275 'side',
276 'high'
277 );
278
279 do_action( 'bbp_author_metabox', get_the_ID() );
280 }
281
282 /**
283 * Save the author information for the topic/reply
284 *
285 * @since bbPress (r2828)
286 *
287 * @param int $post_id Topic or reply id
288 * @uses bbp_get_topic() To get the topic
289 * @uses bbp_get_reply() To get the reply
290 * @uses current_user_can() To check if the current user can edit the
291 * topic or reply
292 * @uses bbp_filter_anonymous_post_data() To filter the anonymous user data
293 * @uses update_post_meta() To update the anonymous user data
294 * @uses do_action() Calls 'bbp_author_metabox_save' with the reply id and
295 * anonymous data
296 * @return int Topic or reply id
297 */
298 function author_metabox_save( $post_id ) {
299
300 // Bail if no post_id
301 if ( empty( $post_id ) )
302 return $post_id;
303
304 // Bail if not a post request
305 if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
306 return $post_id;
307
308 // Bail if doing an autosave
309 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
310 return $post_id;
311
312 // Bail if post_type is not a topic or reply
313 if ( get_post_type( $post_id ) != $this->post_type )
314 return;
315
316 // Bail if user cannot edit replies or reply is not anonymous
317 if ( !current_user_can( 'edit_reply', $post_id ) )
318 return $post_id;
319
320 $anonymous_data = bbp_filter_anonymous_post_data();
321
322 update_post_meta( $post_id, '_bbp_anonymous_name', $anonymous_data['bbp_anonymous_name'] );
323 update_post_meta( $post_id, '_bbp_anonymous_email', $anonymous_data['bbp_anonymous_email'] );
324 update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] );
325
326 do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data );
327
328 return $post_id;
329 }
330
331 /**
332 * Add some general styling to the admin area
333 *
334 * @since bbPress (r2464)
335 *
336 * @uses bbp_get_forum_post_type() To get the forum post type
337 * @uses bbp_get_topic_post_type() To get the topic post type
338 * @uses bbp_get_reply_post_type() To get the reply post type
339 * @uses sanitize_html_class() To sanitize the classes
340 * @uses do_action() Calls 'bbp_admin_head'
341 */
342 function admin_head() {
343
344 if ( get_post_type() == $this->post_type ) : ?>
345
346 <style type="text/css" media="screen">
347 /*<![CDATA[*/
348
349 .column-bbp_forum_topic_count,
350 .column-bbp_forum_reply_count,
351 .column-bbp_topic_reply_count,
352 .column-bbp_topic_voice_count {
353 width: 8% !important;
354 }
355
356 .column-author,
357 .column-bbp_reply_author,
358 .column-bbp_topic_author {
359 width: 10% !important;
360 }
361
362 .column-bbp_topic_forum,
363 .column-bbp_reply_forum,
364 .column-bbp_reply_topic {
365 width: 10% !important;
366 }
367
368 .column-bbp_forum_freshness,
369 .column-bbp_topic_freshness {
370 width: 10% !important;
371 }
372
373 .column-bbp_forum_created,
374 .column-bbp_topic_created,
375 .column-bbp_reply_created {
376 width: 15% !important;
377 }
378
379 .status-closed {
380 background-color: #eaeaea;
381 }
382
383 .status-spam {
384 background-color: #faeaea;
385 }
386
387 /*]]>*/
388 </style>
389
390 <?php endif;
391
392 }
393
394 /**
395 * Toggle reply
396 *
397 * Handles the admin-side spamming/unspamming of replies
398 *
399 * @since bbPress (r2740)
400 *
401 * @uses bbp_get_reply() To get the reply
402 * @uses current_user_can() To check if the user is capable of editing
403 * the reply
404 * @uses wp_die() To die if the user isn't capable or the post wasn't
405 * found
406 * @uses check_admin_referer() To verify the nonce and check referer
407 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
408 * @uses bbp_unspam_reply() To unmark the reply as spam
409 * @uses bbp_spam_reply() To mark the reply as spam
410 * @uses do_action() Calls 'bbp_toggle_reply_admin' with success, post
411 * data, action and message
412 * @uses add_query_arg() To add custom args to the url
413 * @uses wp_redirect() Redirect the page to custom url
414 */
415 function toggle_reply() {
416
417 // Only proceed if GET is a reply toggle action
418 if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_reply_spam' ) ) && !empty( $_GET['reply_id'] ) ) {
419 $action = $_GET['action']; // What action is taking place?
420 $reply_id = (int) $_GET['reply_id']; // What's the reply id?
421 $success = false; // Flag
422 $post_data = array( 'ID' => $reply_id ); // Prelim array
423
424 if ( !$reply = bbp_get_reply( $reply_id ) ) // Which reply?
425 wp_die( __( 'The reply was not found!', 'bbpress' ) );
426
427 if ( !current_user_can( 'moderate', $reply->ID ) ) // What is the user doing here?
428 wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) );
429
430 switch ( $action ) {
431 case 'bbp_toggle_reply_spam' :
432 check_admin_referer( 'spam-reply_' . $reply_id );
433
434 $is_spam = bbp_is_reply_spam( $reply_id );
435 $message = $is_spam ? 'unspammed' : 'spammed';
436 $success = $is_spam ? bbp_unspam_reply( $reply_id ) : bbp_spam_reply( $reply_id );
437
438 break;
439 }
440
441 $success = wp_update_post( $post_data );
442 $message = array( 'bbp_reply_toggle_notice' => $message, 'reply_id' => $reply->ID );
443
444 if ( false == $success || is_wp_error( $success ) )
445 $message['failed'] = '1';
446
447 // Do additional reply toggle actions (admin side)
448 do_action( 'bbp_toggle_reply_admin', $success, $post_data, $action, $message );
449
450 // Redirect back to the reply
451 $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'reply_id' ) ) );
452 wp_redirect( $redirect );
453
454 // For good measure
455 exit();
456 }
457 }
458
459 /**
460 * Toggle reply notices
461 *
462 * Display the success/error notices from
463 * {@link BBP_Admin::toggle_reply()}
464 *
465 * @since bbPress (r2740)
466 *
467 * @uses bbp_get_reply() To get the reply
468 * @uses bbp_get_reply_title() To get the reply title of the reply
469 * @uses esc_html() To sanitize the reply title
470 * @uses apply_filters() Calls 'bbp_toggle_reply_notice_admin' with
471 * message, reply id, notice and is it a failure
472 */
473 function toggle_reply_notice() {
474
475 // Only proceed if GET is a reply toggle action
476 if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['bbp_reply_toggle_notice'] ) && in_array( $_GET['bbp_reply_toggle_notice'], array( 'spammed', 'unspammed' ) ) && !empty( $_GET['reply_id'] ) ) {
477 $notice = $_GET['bbp_reply_toggle_notice']; // Which notice?
478 $reply_id = (int) $_GET['reply_id']; // What's the reply id?
479 $is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure?
480
481 // Empty? No reply?
482 if ( empty( $notice ) || empty( $reply_id ) || !$reply = bbp_get_reply( $reply_id ) )
483 return;
484
485 $reply_title = esc_html( bbp_get_reply_title( $reply->ID ) );
486
487 switch ( $notice ) {
488 case 'spammed' :
489 $message = $is_failure == true ? sprintf( __( 'There was a problem marking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) : sprintf( __( 'Reply "%1$s" successfully marked as spam.', 'bbpress' ), $reply_title );
490 break;
491
492 case 'unspammed' :
493 $message = $is_failure == true ? sprintf( __( 'There was a problem unmarking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) : sprintf( __( 'Reply "%1$s" successfully unmarked as spam.', 'bbpress' ), $reply_title );
494 break;
495 }
496
497 // Do additional reply toggle notice filters (admin side)
498 $message = apply_filters( 'bbp_toggle_reply_notice_admin', $message, $reply->ID, $notice, $is_failure );
499
500 ?>
501
502 <div id="message" class="<?php echo $is_failure == true ? 'error' : 'updated'; ?> fade">
503 <p style="line-height: 150%"><?php echo $message; ?></p>
504 </div>
505
506 <?php
507 }
508 }
509
510 /**
511 * Manage the column headers for the replies page
512 *
513 * @since bbPress (r2577)
514 *
515 * @param array $columns The columns
516 * @uses apply_filters() Calls 'bbp_admin_replies_column_headers' with
517 * the columns
518 * @return array $columns bbPress reply columns
519 */
520 function replies_column_headers( $columns ) {
521 $columns = array(
522 'cb' => '<input type="checkbox" />',
523 'title' => __( 'Title', 'bbpress' ),
524 'bbp_reply_forum' => __( 'Forum', 'bbpress' ),
525 'bbp_reply_topic' => __( 'Topic', 'bbpress' ),
526 'bbp_reply_author' => __( 'Author', 'bbpress' ),
527 'bbp_reply_created' => __( 'Created', 'bbpress' ),
528 );
529
530 return apply_filters( 'bbp_admin_replies_column_headers', $columns );
531 }
532
533 /**
534 * Print extra columns for the replies page
535 *
536 * @since bbPress (r2577)
537 *
538 * @param string $column Column
539 * @param int $reply_id reply id
540 * @uses bbp_get_reply_topic_id() To get the topic id of the reply
541 * @uses bbp_topic_title() To output the reply's topic title
542 * @uses apply_filters() Calls 'reply_topic_row_actions' with an array
543 * of reply topic actions
544 * @uses bbp_get_topic_permalink() To get the topic permalink
545 * @uses bbp_get_topic_forum_id() To get the forum id of the topic of
546 * the reply
547 * @uses bbp_get_forum_permalink() To get the forum permalink
548 * @uses admin_url() To get the admin url of post.php
549 * @uses add_query_arg() To add custom args to the url
550 * @uses apply_filters() Calls 'reply_topic_forum_row_actions' with an
551 * array of reply topic forum actions
552 * @uses bbp_reply_author_display_name() To output the reply author name
553 * @uses get_the_date() Get the reply creation date
554 * @uses get_the_time() Get the reply creation time
555 * @uses esc_attr() To sanitize the reply creation time
556 * @uses bbp_get_reply_last_active_time() To get the time when the reply was
557 * last active
558 * @uses do_action() Calls 'bbp_admin_replies_column_data' with the
559 * column and reply id
560 */
561 function replies_column_data( $column, $reply_id ) {
562
563 // Get topic ID
564 $topic_id = bbp_get_reply_topic_id( $reply_id );
565
566 // Populate Column Data
567 switch ( $column ) {
568
569 // Topic
570 case 'bbp_reply_topic' :
571
572 // Output forum name
573 if ( !empty( $topic_id ) ) {
574
575 // Topic Title
576 if ( !$topic_title = bbp_get_topic_title( $topic_id ) )
577 $topic_title = __( 'No Topic', 'bbpress' );
578
579 // Output the title
580 echo $topic_title;
581
582 // Reply has no topic
583 } else {
584 _e( 'No Topic', 'bbpress' );
585 }
586
587 break;
588
589 // Forum
590 case 'bbp_reply_forum' :
591
592 // Get Forum ID's
593 $reply_forum_id = bbp_get_reply_forum_id( $reply_id );
594 $topic_forum_id = bbp_get_topic_forum_id( $topic_id );
595
596 // Output forum name
597 if ( !empty( $reply_forum_id ) ) {
598
599 // Forum Title
600 if ( !$forum_title = bbp_get_forum_title( $reply_forum_id ) )
601 $forum_title = __( 'No Forum', 'bbpress' );
602
603 // Alert capable users of reply forum mismatch
604 if ( $reply_forum_id != $topic_forum_id ) {
605 if ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate' ) ) {
606 $forum_title .= '<div class="attention">' . __( '(Mismatch)', 'bbpress' ) . '</div>';
607 }
608 }
609
610 // Output the title
611 echo $forum_title;
612
613 // Reply has no forum
614 } else {
615 _e( 'No Forum', 'bbpress' );
616 }
617
618 break;
619
620 // Author
621 case 'bbp_reply_author' :
622 bbp_reply_author_display_name ( $reply_id );
623 break;
624
625 // Freshness
626 case 'bbp_reply_created':
627
628 // Output last activity time and date
629 printf( __( '%1$s <br /> %2$s', 'bbpress' ),
630 get_the_date(),
631 esc_attr( get_the_time() )
632 );
633
634 break;
635
636 // Do action for anything else
637 default :
638 do_action( 'bbp_admin_replies_column_data', $column, $reply_id );
639 break;
640 }
641 }
642
643 /**
644 * Reply Row actions
645 *
646 * Remove the quick-edit action link under the reply title and add the
647 * content and spam link
648 *
649 * @since bbPress (r2577)
650 *
651 * @param array $actions Actions
652 * @param array $reply Reply object
653 * @uses bbp_get_reply_post_type() To get the reply post type
654 * @uses bbp_reply_content() To output reply content
655 * @uses bbp_get_reply_permalink() To get the reply link
656 * @uses bbp_get_reply_title() To get the reply title
657 * @uses current_user_can() To check if the current user can edit or
658 * delete the reply
659 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
660 * @uses get_post_type_object() To get the reply post type object
661 * @uses add_query_arg() To add custom args to the url
662 * @uses remove_query_arg() To remove custom args from the url
663 * @uses wp_nonce_url() To nonce the url
664 * @uses get_delete_post_link() To get the delete post link of the reply
665 * @return array $actions Actions
666 */
667 function replies_row_actions( $actions, $reply ) {
668
669 if ( bbp_get_reply_post_type() == $reply->post_type ) {
670 unset( $actions['inline hide-if-no-js'] );
671
672 // Reply view links to topic
673 $actions['view'] = '<a href="' . bbp_get_reply_url( $reply->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_reply_title( $reply->ID ) ) ) . '" rel="permalink">' . __( 'View', 'bbpress' ) . '</a>';
674
675 // User cannot view replies in trash
676 if ( ( bbp_get_trash_status_id() == $reply->post_status ) && !current_user_can( 'view_trash' ) )
677 unset( $actions['view'] );
678
679 // Only show the actions if the user is capable of viewing them
680 if ( current_user_can( 'moderate', $reply->ID ) ) {
681 if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_spam_status_id() ) ) ) {
682 $spam_uri = esc_url( wp_nonce_url( add_query_arg( array( 'reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_spam' ), remove_query_arg( array( 'bbp_reply_toggle_notice', 'reply_id', 'failed', 'super' ) ) ), 'spam-reply_' . $reply->ID ) );
683 if ( bbp_is_reply_spam( $reply->ID ) ) {
684 $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the reply as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>';
685 } else {
686 $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this reply as spam', 'bbpress' ) . '">' . __( 'Spam', 'bbpress' ) . '</a>';
687 }
688 }
689 }
690
691 // Trash
692 if ( current_user_can( 'delete_reply', $reply->ID ) ) {
693 if ( bbp_get_trash_status_id() == $reply->post_status ) {
694 $post_type_object = get_post_type_object( bbp_get_reply_post_type() );
695 $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', 'bbpress' ) ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>";
696 } elseif ( EMPTY_TRASH_DAYS ) {
697 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash', 'bbpress' ) ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $reply->ID ) ) . "'>" . __( 'Trash', 'bbpress' ) . "</a>";
698 }
699
700 if ( bbp_get_trash_status_id() == $reply->post_status || !EMPTY_TRASH_DAYS ) {
701 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently', 'bbpress' ) ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $reply->ID, '', true ) ) . "'>" . __( 'Delete Permanently', 'bbpress' ) . "</a>";
702 } elseif ( bbp_get_spam_status_id() == $reply->post_status ) {
703 unset( $actions['trash'] );
704 }
705 }
706 }
707
708 return $actions;
709 }
710
711 /**
712 * Add forum dropdown to topic and reply list table filters
713 *
714 * @since bbPress (r2991)
715 *
716 * @uses bbp_get_reply_post_type() To get the reply post type
717 * @uses bbp_get_topic_post_type() To get the topic post type
718 * @uses bbp_dropdown() To generate a forum dropdown
719 * @return bool False. If post type is not topic or reply
720 */
721 function filter_dropdown() {
722
723 // Bail if not viewing the topics list
724 if (
725 // post_type exists in _GET
726 empty( $_GET['post_type'] ) ||
727
728 // post_type is reply or topic type
729 ( $_GET['post_type'] != $this->post_type )
730 )
731 return;
732
733 // Add Empty Spam button
734 if ( !empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() == $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
735 wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
736 $title = esc_attr__( 'Empty Spam', 'bbpress' );
737 submit_button( $title, 'button-secondary apply', 'delete_all', false );
738 }
739
740 // Get which forum is selected
741 $selected = !empty( $_GET['bbp_forum_id'] ) ? $_GET['bbp_forum_id'] : '';
742
743 // Show the forums dropdown
744 bbp_dropdown( array(
745 'selected' => $selected,
746 'show_none' => __( 'In all forums', 'bbpress' )
747 ) );
748 }
749
750 /**
751 * Adjust the request query and include the forum id
752 *
753 * @since bbPress (r2991)
754 *
755 * @param array $query_vars Query variables from {@link WP_Query}
756 * @uses is_admin() To check if it's the admin section
757 * @uses bbp_get_topic_post_type() To get the topic post type
758 * @uses bbp_get_reply_post_type() To get the reply post type
759 * @return array Processed Query Vars
760 */
761 function filter_post_rows( $query_vars ) {
762 global $pagenow;
763
764 // Avoid poisoning other requests
765 if (
766 // Only look in admin
767 !is_admin() ||
768
769 // Make sure the current page is for post rows
770 ( 'edit.php' != $pagenow ) ||
771
772 // Make sure we're looking for a post_type
773 empty( $_GET['post_type'] ) ||
774
775 // Make sure we're looking at bbPress topics
776 ( $_GET['post_type'] != $this->post_type )
777 )
778
779 // We're in no shape to filter anything, so return
780 return $query_vars;
781
782 // Add post_parent query_var if one is present
783 if ( !empty( $_GET['bbp_forum_id'] ) ) {
784 $query_vars['meta_key'] = '_bbp_forum_id';
785 $query_vars['meta_value'] = $_GET['bbp_forum_id'];
786 }
787
788 // Return manipulated query_vars
789 return $query_vars;
790 }
791
792 /**
793 * Custom user feedback messages for reply post type
794 *
795 * @since bbPress (r3080)
796 *
797 * @global WP_Query $post
798 * @global int $post_ID
799 * @uses get_post_type()
800 * @uses bbp_get_topic_permalink()
801 * @uses wp_post_revision_title()
802 * @uses esc_url()
803 * @uses add_query_arg()
804 *
805 * @param array $messages
806 *
807 * @return array
808 */
809 function updated_messages( $messages ) {
810 global $post, $post_ID;
811
812 if ( get_post_type( $post_ID ) != $this->post_type )
813 return $messages;
814
815 // URL for the current topic
816 $topic_url = bbp_get_topic_permalink( bbp_get_reply_topic_id( $post_ID ) );
817
818 // Messages array
819 $messages[$this->post_type] = array(
820 0 => '', // Left empty on purpose
821
822 // Updated
823 1 => sprintf( __( 'Reply updated. <a href="%s">View topic</a>' ), $topic_url ),
824
825 // Custom field updated
826 2 => __( 'Custom field updated.', 'bbpress' ),
827
828 // Custom field deleted
829 3 => __( 'Custom field deleted.', 'bbpress' ),
830
831 // Reply updated
832 4 => __( 'Reply updated.', 'bbpress' ),
833
834 // Restored from revision
835 // translators: %s: date and time of the revision
836 5 => isset( $_GET['revision'] )
837 ? sprintf( __( 'Reply restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
838 : false,
839
840 // Reply created
841 6 => sprintf( __( 'Reply created. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
842
843 // Reply saved
844 7 => __( 'Reply saved.', 'bbpress' ),
845
846 // Reply submitted
847 8 => sprintf( __( 'Reply submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
848
849 // Reply scheduled
850 9 => sprintf( __( 'Reply scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress' ),
851 // translators: Publish box date format, see http://php.net/date
852 date_i18n( __( 'M j, Y @ G:i' ),
853 strtotime( $post->post_date ) ),
854 $topic_url ),
855
856 // Reply draft updated
857 10 => sprintf( __( 'Reply draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
858 );
859
860 return $messages;
861 }
862 }
863 endif; // class_exists check
864
865 /**
866 * Setup bbPress Replies Admin
867 *
868 * @since bbPress (r2596)
869 *
870 * @uses BBP_Replies_Admin
871 */
872 function bbp_admin_replies() {
873 global $bbp;
874
875 // Bail if bbPress is not loaded
876 if ( 'bbPress' !== get_class( $bbp ) ) return;
877
878 $bbp->admin->replies = new BBP_Replies_Admin();
879 }
880
881 ?>
882