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-admin / bbp-replies.php

bbp-replies.php in bbPress 2.0-beta-1, at bbp-admin/bbp-replies.php

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