PluginProbe
bbPress / 2.1
bbPress v2.1
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.1, at bbp-admin/bbp-replies.php

951 lines 36.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 private $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 public function __construct() {
42 $this->setup_globals();
43 $this->setup_actions();
44 }
45
46 /**
47 * Setup the admin hooks, actions and filters
48 *
49 * @since bbPress (r2646)
50 * @access private
51 *
52 * @uses add_action() To add various actions
53 * @uses add_filter() To add various filters
54 * @uses bbp_get_forum_post_type() To get the forum post type
55 * @uses bbp_get_topic_post_type() To get the topic post type
56 * @uses bbp_get_reply_post_type() To get the reply post type
57 */
58 private function setup_actions() {
59
60 // Add some general styling to the admin area
61 add_action( 'bbp_admin_head', array( $this, 'admin_head' ) );
62
63 // Messages
64 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
65
66 // Reply column headers.
67 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'replies_column_headers' ) );
68
69 // Reply columns (in post row)
70 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'replies_column_data' ), 10, 2 );
71 add_filter( 'post_row_actions', array( $this, 'replies_row_actions' ), 10, 2 );
72
73 // Reply metabox actions
74 add_action( 'add_meta_boxes', array( $this, 'reply_attributes_metabox' ) );
75 add_action( 'save_post', array( $this, 'reply_attributes_metabox_save' ) );
76
77 // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed
78 add_action( 'load-edit.php', array( $this, 'toggle_reply' ) );
79 add_action( 'admin_notices', array( $this, 'toggle_reply_notice' ) );
80
81 // Anonymous metabox actions
82 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) );
83 add_action( 'save_post', array( $this, 'author_metabox_save' ) );
84
85 // Add ability to filter topics and replies per forum
86 add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) );
87 add_filter( 'bbp_request', array( $this, 'filter_post_rows' ) );
88
89 // Contextual Help
90 add_action( 'load-edit.php', array( $this, 'edit_help' ) );
91 add_action( 'load-post-new.php', array( $this, 'new_help' ) );
92 }
93
94 /**
95 * Should we bail out of this method?
96 *
97 * @since bbPress (r4067)
98 * @return boolean
99 */
100 private function bail() {
101 if ( $this->post_type != get_current_screen()->post_type )
102 return true;
103
104 return false;
105 }
106
107 /**
108 * Admin globals
109 *
110 * @since bbPress (r2646)
111 * @access private
112 */
113 private function setup_globals() {
114 $this->post_type = bbp_get_reply_post_type();
115 }
116
117 /** Contextual Help *******************************************************/
118
119 /**
120 * Contextual help for bbPress reply edit page
121 *
122 * @since bbPress (r3119)
123 * @uses get_current_screen()
124 */
125 public function edit_help() {
126
127 if ( $this->bail() ) return;
128
129 // Overview
130 get_current_screen()->add_help_tab( array(
131 'id' => 'overview',
132 'title' => __( 'Overview', 'bbpress' ),
133 'content' =>
134 '<p>' . __( 'This screen provides access to all of your replies. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
135 ) );
136
137 // Screen Content
138 get_current_screen()->add_help_tab( array(
139 'id' => 'screen-content',
140 'title' => __( 'Screen Content', 'bbpress' ),
141 'content' =>
142 '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
143 '<ul>' .
144 '<li>' . __( 'You can hide/display columns based on your needs and decide how many replies to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' .
145 '<li>' . __( 'You can filter the list of replies by reply status using the text links in the upper left to show All, Published, Draft, or Trashed replies. The default view is to show all replies.', 'bbpress' ) . '</li>' .
146 '<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>' .
147 '<li>' . __( 'You can refine the list to show only replies in a specific category or from a specific month by using the dropdown menus above the replies list. Click the Filter button after making your selection. You also can refine the list by clicking on the reply author, category or tag in the replies list.', 'bbpress' ) . '</li>' .
148 '</ul>'
149 ) );
150
151 // Available Actions
152 get_current_screen()->add_help_tab( array(
153 'id' => 'action-links',
154 'title' => __( 'Available Actions', 'bbpress' ),
155 'content' =>
156 '<p>' . __( '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' ) . '</p>' .
157 '<ul>' .
158 '<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that reply. You can also reach that screen by clicking on the reply title.', 'bbpress' ) . '</li>' .
159 //'<li>' . __( '<strong>Quick Edit</strong> provides inline access to the metadata of your reply, allowing you to update reply details without leaving this screen.', 'bbpress' ) . '</li>' .
160 '<li>' . __( '<strong>Trash</strong> removes your reply from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
161 '<li>' . __( '<strong>Spam</strong> removes your reply from this list and places it in the spam queue, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
162 '<li>' . __( '<strong>Preview</strong> will show you what your draft reply will look like if you publish it. View will take you to your live site to view the reply. Which link is available depends on your reply&#8217;s status.', 'bbpress' ) . '</li>' .
163 '</ul>'
164 ) );
165
166 // Bulk Actions
167 get_current_screen()->add_help_tab( array(
168 'id' => 'bulk-actions',
169 'title' => __( 'Bulk Actions', 'bbpress' ),
170 'content' =>
171 '<p>' . __( 'You can also edit or move multiple replies to the trash at once. Select the replies you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.', 'bbpress' ) . '</p>' .
172 '<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) 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' ) . '</p>'
173 ) );
174
175 // Help Sidebar
176 get_current_screen()->set_help_sidebar(
177 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
178 '<p>' . __( '<a href="http://bbpress.org/documentation/" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
179 '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
180 );
181 }
182
183 /**
184 * Contextual help for bbPress reply edit page
185 *
186 * @since bbPress (r3119)
187 * @uses get_current_screen()
188 */
189 public function new_help() {
190
191 if ( $this->bail() ) return;
192
193 $customize_display = '<p>' . __( 'The 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 each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>';
194
195 get_current_screen()->add_help_tab( array(
196 'id' => 'customize-display',
197 'title' => __( 'Customizing This Display', 'bbpress' ),
198 'content' => $customize_display,
199 ) );
200
201 get_current_screen()->add_help_tab( array(
202 'id' => 'title-reply-editor',
203 'title' => __( 'Title and Reply Editor', 'bbpress' ),
204 'content' =>
205 '<p>' . __( '<strong>Title</strong> - Enter a title for your reply. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
206 '<p>' . __( '<strong>Reply 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 HTML mode allows you to enter raw HTML along with your reply text. You can insert media files by clicking the icons above the reply editor and following the directions. You can go to the distraction-free writing screen via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular reply editor.', 'bbpress' ) . '</p>'
207 ) );
208
209 $publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your reply in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a reply or making it stay at the top of your blog indefinitely (sticky). Publish (immediately) allows you to set a future or past date and time, so you can schedule a reply to be published in the future or backdate a reply.', 'bbpress' ) . '</p>';
210
211 if ( current_theme_supports( 'reply-formats' ) && reply_type_supports( 'reply', 'reply-formats' ) ) {
212 $publish_box .= '<p>' . __( '<strong>reply Format</strong> - This designates how your theme will display a specific reply. For example, you could have a <em>standard</em> blog reply with a title and paragraphs, or a short <em>aside</em> that omits the title and contains a short text blurb. Please refer to the Codex for <a href="http://codex.wordpress.org/Post_Formats#Supported_Formats">descriptions of each reply format</a>. Your theme could enable all or some of 10 possible formats.', 'bbpress' ) . '</p>';
213 }
214
215 if ( current_theme_supports( 'reply-thumbnails' ) && reply_type_supports( 'reply', 'thumbnail' ) ) {
216 $publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your reply without inserting it. This is usually useful only if your theme makes use of the featured image as a reply thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>';
217 }
218
219 get_current_screen()->add_help_tab( array(
220 'id' => 'reply-attributes',
221 'title' => __( 'Reply Attributes', 'bbpress' ),
222 'content' =>
223 '<p>' . __( 'Select the attributes that your reply should have:', 'bbpress' ) . '</p>' .
224 '<ul>' .
225 '<li>' . __( '<strong>Forum</strong> dropdown determines the parent forum that the reply belongs to. Select the forum, or leave the default (Use Forum of Topic) to post the reply in forum of the topic.', 'bbpress' ) . '</li>' .
226 '<li>' . __( '<strong>Topic</strong> determines the parent topic that the reply belongs to.', 'bbpress' ) . '</li>' .
227 '</ul>'
228 ) );
229
230 get_current_screen()->add_help_tab( array(
231 'id' => 'publish-box',
232 'title' => __( 'Publish Box', 'bbpress' ),
233 'content' => $publish_box,
234 ) );
235
236 get_current_screen()->add_help_tab( array(
237 'id' => 'discussion-settings',
238 'title' => __( 'Discussion Settings', 'bbpress' ),
239 'content' =>
240 '<p>' . __( '<strong>Send Trackbacks</strong> - Trackbacks are a way to notify legacy blog systems that you&#8217;ve linked to them. Enter the URL(s) you want to send trackbacks. If you link to other WordPress sites they&#8217;ll be notified automatically using pingbacks, and this field is unnecessary.', 'bbpress' ) . '</p>' .
241 '<p>' . __( '<strong>Discussion</strong> - You can turn comments and pings on or off, and if there are comments on the reply, you can see them here and moderate them.', 'bbpress' ) . '</p>'
242 ) );
243
244 get_current_screen()->set_help_sidebar(
245 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
246 '<p>' . __( '<a href="http://bbpress.org/documentation/" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
247 '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
248 );
249 }
250
251 /**
252 * Add the reply attributes metabox
253 *
254 * @since bbPress (r2746)
255 *
256 * @uses bbp_get_reply_post_type() To get the reply post type
257 * @uses add_meta_box() To add the metabox
258 * @uses do_action() Calls 'bbp_reply_attributes_metabox'
259 */
260 public function reply_attributes_metabox() {
261
262 if ( $this->bail() ) return;
263
264 add_meta_box (
265 'bbp_reply_attributes',
266 __( 'Reply Attributes', 'bbpress' ),
267 'bbp_reply_metabox',
268 $this->post_type,
269 'side',
270 'high'
271 );
272
273 do_action( 'bbp_reply_attributes_metabox' );
274 }
275
276 /**
277 * Pass the reply attributes for processing
278 *
279 * @since bbPress (r2746)
280 *
281 * @param int $reply_id Reply id
282 * @uses current_user_can() To check if the current user is capable of
283 * editing the reply
284 * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the
285 * reply id and parent id
286 * @return int Parent id
287 */
288 public function reply_attributes_metabox_save( $reply_id ) {
289
290 if ( $this->bail() ) return $reply_id;
291
292 // Bail if doing an autosave
293 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
294 return $reply_id;
295
296 // Bail if not a post request
297 if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
298 return $reply_id;
299
300 // Check action exists
301 if ( empty( $_POST['action'] ) )
302 return $reply_id;
303
304 // Nonce check
305 if ( empty( $_POST['bbp_reply_metabox'] ) || !wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) )
306 return $reply_id;
307
308 // Current user cannot edit this reply
309 if ( !current_user_can( 'edit_reply', $reply_id ) )
310 return $reply_id;
311
312 // Get the reply meta post values
313 $topic_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
314 $forum_id = !empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id );
315
316 // Formally update the reply
317 bbp_update_reply( $reply_id, $topic_id, $forum_id );
318
319 // Allow other fun things to happen
320 do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id );
321
322 return $reply_id;
323 }
324
325 /**
326 * Add the author info metabox
327 *
328 * Allows editing of information about an author
329 *
330 * @since bbPress (r2828)
331 *
332 * @uses bbp_get_topic() To get the topic
333 * @uses bbp_get_reply() To get the reply
334 * @uses bbp_get_topic_post_type() To get the topic post type
335 * @uses bbp_get_reply_post_type() To get the reply post type
336 * @uses add_meta_box() To add the metabox
337 * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply
338 * id
339 */
340 public function author_metabox() {
341
342 if ( $this->bail() ) return;
343
344 // Bail if post_type is not a reply
345 if ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) )
346 return;
347
348 // Add the metabox
349 add_meta_box(
350 'bbp_author_metabox',
351 __( 'Author Information', 'bbpress' ),
352 'bbp_author_metabox',
353 $this->post_type,
354 'side',
355 'high'
356 );
357
358 do_action( 'bbp_author_metabox', get_the_ID() );
359 }
360
361 /**
362 * Save the author information for the topic/reply
363 *
364 * @since bbPress (r2828)
365 *
366 * @param int $post_id Topic or reply id
367 * @uses bbp_get_topic() To get the topic
368 * @uses bbp_get_reply() To get the reply
369 * @uses current_user_can() To check if the current user can edit the
370 * topic or reply
371 * @uses bbp_filter_anonymous_post_data() To filter the anonymous user data
372 * @uses update_post_meta() To update the anonymous user data
373 * @uses do_action() Calls 'bbp_author_metabox_save' with the reply id and
374 * anonymous data
375 * @return int Topic or reply id
376 */
377 public function author_metabox_save( $post_id ) {
378
379 if ( $this->bail() ) return $post_id;
380
381 // Bail if no post_id
382 if ( empty( $post_id ) )
383 return $post_id;
384
385 // Bail if not a post request
386 if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
387 return $post_id;
388
389 // Bail if doing an autosave
390 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
391 return $post_id;
392
393 // Bail if user cannot edit replies or reply is not anonymous
394 if ( !current_user_can( 'edit_reply', $post_id ) )
395 return $post_id;
396
397 $anonymous_data = bbp_filter_anonymous_post_data();
398
399 update_post_meta( $post_id, '_bbp_anonymous_name', $anonymous_data['bbp_anonymous_name'] );
400 update_post_meta( $post_id, '_bbp_anonymous_email', $anonymous_data['bbp_anonymous_email'] );
401 update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] );
402
403 do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data );
404
405 return $post_id;
406 }
407
408 /**
409 * Add some general styling to the admin area
410 *
411 * @since bbPress (r2464)
412 *
413 * @uses bbp_get_forum_post_type() To get the forum post type
414 * @uses bbp_get_topic_post_type() To get the topic post type
415 * @uses bbp_get_reply_post_type() To get the reply post type
416 * @uses sanitize_html_class() To sanitize the classes
417 * @uses do_action() Calls 'bbp_admin_head'
418 */
419 public function admin_head() {
420
421 if ( $this->bail() ) return;
422
423 ?>
424
425 <style type="text/css" media="screen">
426 /*<![CDATA[*/
427
428 .column-bbp_forum_topic_count,
429 .column-bbp_forum_reply_count,
430 .column-bbp_topic_reply_count,
431 .column-bbp_topic_voice_count {
432 width: 8% !important;
433 }
434
435 .column-author,
436 .column-bbp_reply_author,
437 .column-bbp_topic_author {
438 width: 10% !important;
439 }
440
441 .column-bbp_topic_forum,
442 .column-bbp_reply_forum,
443 .column-bbp_reply_topic {
444 width: 10% !important;
445 }
446
447 .column-bbp_forum_freshness,
448 .column-bbp_topic_freshness {
449 width: 10% !important;
450 }
451
452 .column-bbp_forum_created,
453 .column-bbp_topic_created,
454 .column-bbp_reply_created {
455 width: 15% !important;
456 }
457
458 .status-closed {
459 background-color: #eaeaea;
460 }
461
462 .status-spam {
463 background-color: #faeaea;
464 }
465
466 /*]]>*/
467 </style>
468
469 <?php
470 }
471
472 /**
473 * Toggle reply
474 *
475 * Handles the admin-side spamming/unspamming of replies
476 *
477 * @since bbPress (r2740)
478 *
479 * @uses bbp_get_reply() To get the reply
480 * @uses current_user_can() To check if the user is capable of editing
481 * the reply
482 * @uses wp_die() To die if the user isn't capable or the post wasn't
483 * found
484 * @uses check_admin_referer() To verify the nonce and check referer
485 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
486 * @uses bbp_unspam_reply() To unmark the reply as spam
487 * @uses bbp_spam_reply() To mark the reply as spam
488 * @uses do_action() Calls 'bbp_toggle_reply_admin' with success, post
489 * data, action and message
490 * @uses add_query_arg() To add custom args to the url
491 * @uses wp_safe_redirect() Redirect the page to custom url
492 */
493 public function toggle_reply() {
494
495 if ( $this->bail() ) return;
496
497 // Only proceed if GET is a reply toggle action
498 if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_reply_spam' ) ) && !empty( $_GET['reply_id'] ) ) {
499 $action = $_GET['action']; // What action is taking place?
500 $reply_id = (int) $_GET['reply_id']; // What's the reply id?
501 $success = false; // Flag
502 $post_data = array( 'ID' => $reply_id ); // Prelim array
503
504 // Get reply and die if empty
505 $reply = bbp_get_reply( $reply_id );
506 if ( empty( $reply ) ) // Which reply?
507 wp_die( __( 'The reply was not found!', 'bbpress' ) );
508
509 if ( !current_user_can( 'moderate', $reply->ID ) ) // What is the user doing here?
510 wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) );
511
512 switch ( $action ) {
513 case 'bbp_toggle_reply_spam' :
514 check_admin_referer( 'spam-reply_' . $reply_id );
515
516 $is_spam = bbp_is_reply_spam( $reply_id );
517 $message = $is_spam ? 'unspammed' : 'spammed';
518 $success = $is_spam ? bbp_unspam_reply( $reply_id ) : bbp_spam_reply( $reply_id );
519
520 break;
521 }
522
523 $success = wp_update_post( $post_data );
524 $message = array( 'bbp_reply_toggle_notice' => $message, 'reply_id' => $reply->ID );
525
526 if ( false == $success || is_wp_error( $success ) )
527 $message['failed'] = '1';
528
529 // Do additional reply toggle actions (admin side)
530 do_action( 'bbp_toggle_reply_admin', $success, $post_data, $action, $message );
531
532 // Redirect back to the reply
533 $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'reply_id' ) ) );
534 wp_safe_redirect( $redirect );
535
536 // For good measure
537 exit();
538 }
539 }
540
541 /**
542 * Toggle reply notices
543 *
544 * Display the success/error notices from
545 * {@link BBP_Admin::toggle_reply()}
546 *
547 * @since bbPress (r2740)
548 *
549 * @uses bbp_get_reply() To get the reply
550 * @uses bbp_get_reply_title() To get the reply title of the reply
551 * @uses esc_html() To sanitize the reply title
552 * @uses apply_filters() Calls 'bbp_toggle_reply_notice_admin' with
553 * message, reply id, notice and is it a failure
554 */
555 public function toggle_reply_notice() {
556
557 if ( $this->bail() ) return;
558
559 // Only proceed if GET is a reply toggle action
560 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'] ) ) {
561 $notice = $_GET['bbp_reply_toggle_notice']; // Which notice?
562 $reply_id = (int) $_GET['reply_id']; // What's the reply id?
563 $is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure?
564
565 // Empty? No reply?
566 if ( empty( $notice ) || empty( $reply_id ) )
567 return;
568
569 // Get reply and bail if empty
570 $reply = bbp_get_reply( $reply_id );
571 if ( empty( $reply ) )
572 return;
573
574 $reply_title = esc_html( bbp_get_reply_title( $reply->ID ) );
575
576 switch ( $notice ) {
577 case 'spammed' :
578 $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 );
579 break;
580
581 case 'unspammed' :
582 $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 );
583 break;
584 }
585
586 // Do additional reply toggle notice filters (admin side)
587 $message = apply_filters( 'bbp_toggle_reply_notice_admin', $message, $reply->ID, $notice, $is_failure );
588
589 ?>
590
591 <div id="message" class="<?php echo $is_failure == true ? 'error' : 'updated'; ?> fade">
592 <p style="line-height: 150%"><?php echo $message; ?></p>
593 </div>
594
595 <?php
596 }
597 }
598
599 /**
600 * Manage the column headers for the replies page
601 *
602 * @since bbPress (r2577)
603 *
604 * @param array $columns The columns
605 * @uses apply_filters() Calls 'bbp_admin_replies_column_headers' with
606 * the columns
607 * @return array $columns bbPress reply columns
608 */
609 public function replies_column_headers( $columns ) {
610
611 if ( $this->bail() ) return $columns;
612
613 $columns = array(
614 'cb' => '<input type="checkbox" />',
615 'title' => __( 'Title', 'bbpress' ),
616 'bbp_reply_forum' => __( 'Forum', 'bbpress' ),
617 'bbp_reply_topic' => __( 'Topic', 'bbpress' ),
618 'bbp_reply_author' => __( 'Author', 'bbpress' ),
619 'bbp_reply_created' => __( 'Created', 'bbpress' ),
620 );
621
622 return apply_filters( 'bbp_admin_replies_column_headers', $columns );
623 }
624
625 /**
626 * Print extra columns for the replies page
627 *
628 * @since bbPress (r2577)
629 *
630 * @param string $column Column
631 * @param int $reply_id reply id
632 * @uses bbp_get_reply_topic_id() To get the topic id of the reply
633 * @uses bbp_topic_title() To output the reply's topic title
634 * @uses apply_filters() Calls 'reply_topic_row_actions' with an array
635 * of reply topic actions
636 * @uses bbp_get_topic_permalink() To get the topic permalink
637 * @uses bbp_get_topic_forum_id() To get the forum id of the topic of
638 * the reply
639 * @uses bbp_get_forum_permalink() To get the forum permalink
640 * @uses admin_url() To get the admin url of post.php
641 * @uses add_query_arg() To add custom args to the url
642 * @uses apply_filters() Calls 'reply_topic_forum_row_actions' with an
643 * array of reply topic forum actions
644 * @uses bbp_reply_author_display_name() To output the reply author name
645 * @uses get_the_date() Get the reply creation date
646 * @uses get_the_time() Get the reply creation time
647 * @uses esc_attr() To sanitize the reply creation time
648 * @uses bbp_get_reply_last_active_time() To get the time when the reply was
649 * last active
650 * @uses do_action() Calls 'bbp_admin_replies_column_data' with the
651 * column and reply id
652 */
653 public function replies_column_data( $column, $reply_id ) {
654
655 if ( $this->bail() ) return;
656
657 // Get topic ID
658 $topic_id = bbp_get_reply_topic_id( $reply_id );
659
660 // Populate Column Data
661 switch ( $column ) {
662
663 // Topic
664 case 'bbp_reply_topic' :
665
666 // Output forum name
667 if ( !empty( $topic_id ) ) {
668
669 // Topic Title
670 $topic_title = bbp_get_topic_title( $topic_id );
671 if ( empty( $topic_title ) ) {
672 $topic_title = __( 'No Topic', 'bbpress' );
673 }
674
675 // Output the title
676 echo $topic_title;
677
678 // Reply has no topic
679 } else {
680 _e( 'No Topic', 'bbpress' );
681 }
682
683 break;
684
685 // Forum
686 case 'bbp_reply_forum' :
687
688 // Get Forum ID's
689 $reply_forum_id = bbp_get_reply_forum_id( $reply_id );
690 $topic_forum_id = bbp_get_topic_forum_id( $topic_id );
691
692 // Output forum name
693 if ( !empty( $reply_forum_id ) ) {
694
695 // Forum Title
696 $forum_title = bbp_get_forum_title( $reply_forum_id );
697 if ( empty( $forum_title ) ) {
698 $forum_title = __( 'No Forum', 'bbpress' );
699 }
700
701 // Alert capable users of reply forum mismatch
702 if ( $reply_forum_id != $topic_forum_id ) {
703 if ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate' ) ) {
704 $forum_title .= '<div class="attention">' . __( '(Mismatch)', 'bbpress' ) . '</div>';
705 }
706 }
707
708 // Output the title
709 echo $forum_title;
710
711 // Reply has no forum
712 } else {
713 _e( 'No Forum', 'bbpress' );
714 }
715
716 break;
717
718 // Author
719 case 'bbp_reply_author' :
720 bbp_reply_author_display_name ( $reply_id );
721 break;
722
723 // Freshness
724 case 'bbp_reply_created':
725
726 // Output last activity time and date
727 printf( __( '%1$s <br /> %2$s', 'bbpress' ),
728 get_the_date(),
729 esc_attr( get_the_time() )
730 );
731
732 break;
733
734 // Do action for anything else
735 default :
736 do_action( 'bbp_admin_replies_column_data', $column, $reply_id );
737 break;
738 }
739 }
740
741 /**
742 * Reply Row actions
743 *
744 * Remove the quick-edit action link under the reply title and add the
745 * content and spam link
746 *
747 * @since bbPress (r2577)
748 *
749 * @param array $actions Actions
750 * @param array $reply Reply object
751 * @uses bbp_get_reply_post_type() To get the reply post type
752 * @uses bbp_reply_content() To output reply content
753 * @uses bbp_get_reply_permalink() To get the reply link
754 * @uses bbp_get_reply_title() To get the reply title
755 * @uses current_user_can() To check if the current user can edit or
756 * delete the reply
757 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
758 * @uses get_post_type_object() To get the reply post type object
759 * @uses add_query_arg() To add custom args to the url
760 * @uses remove_query_arg() To remove custom args from the url
761 * @uses wp_nonce_url() To nonce the url
762 * @uses get_delete_post_link() To get the delete post link of the reply
763 * @return array $actions Actions
764 */
765 public function replies_row_actions( $actions, $reply ) {
766
767 if ( $this->bail() ) return $actions;
768
769 unset( $actions['inline hide-if-no-js'] );
770
771 // Reply view links to topic
772 $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>';
773
774 // User cannot view replies in trash
775 if ( ( bbp_get_trash_status_id() == $reply->post_status ) && !current_user_can( 'view_trash' ) )
776 unset( $actions['view'] );
777
778 // Only show the actions if the user is capable of viewing them
779 if ( current_user_can( 'moderate', $reply->ID ) ) {
780 if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_spam_status_id() ) ) ) {
781 $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 ) );
782 if ( bbp_is_reply_spam( $reply->ID ) ) {
783 $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the reply as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>';
784 } else {
785 $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this reply as spam', 'bbpress' ) . '">' . __( 'Spam', 'bbpress' ) . '</a>';
786 }
787 }
788 }
789
790 // Trash
791 if ( current_user_can( 'delete_reply', $reply->ID ) ) {
792 if ( bbp_get_trash_status_id() == $reply->post_status ) {
793 $post_type_object = get_post_type_object( bbp_get_reply_post_type() );
794 $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>";
795 } elseif ( EMPTY_TRASH_DAYS ) {
796 $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>";
797 }
798
799 if ( bbp_get_trash_status_id() == $reply->post_status || !EMPTY_TRASH_DAYS ) {
800 $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>";
801 } elseif ( bbp_get_spam_status_id() == $reply->post_status ) {
802 unset( $actions['trash'] );
803 }
804 }
805
806 return $actions;
807 }
808
809 /**
810 * Add forum dropdown to topic and reply list table filters
811 *
812 * @since bbPress (r2991)
813 *
814 * @uses bbp_get_reply_post_type() To get the reply post type
815 * @uses bbp_get_topic_post_type() To get the topic post type
816 * @uses bbp_dropdown() To generate a forum dropdown
817 * @return bool False. If post type is not topic or reply
818 */
819 public function filter_dropdown() {
820
821 if ( $this->bail() ) return;
822
823 // Add Empty Spam button
824 if ( !empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() == $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
825 wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
826 $title = esc_attr__( 'Empty Spam', 'bbpress' );
827 submit_button( $title, 'button-secondary apply', 'delete_all', false );
828 }
829
830 // Get which forum is selected
831 $selected = !empty( $_GET['bbp_forum_id'] ) ? $_GET['bbp_forum_id'] : '';
832
833 // Show the forums dropdown
834 bbp_dropdown( array(
835 'selected' => $selected,
836 'show_none' => __( 'In all forums', 'bbpress' )
837 ) );
838 }
839
840 /**
841 * Adjust the request query and include the forum id
842 *
843 * @since bbPress (r2991)
844 *
845 * @param array $query_vars Query variables from {@link WP_Query}
846 * @uses is_admin() To check if it's the admin section
847 * @uses bbp_get_topic_post_type() To get the topic post type
848 * @uses bbp_get_reply_post_type() To get the reply post type
849 * @return array Processed Query Vars
850 */
851 public function filter_post_rows( $query_vars ) {
852
853 if ( $this->bail() ) return $query_vars;
854
855 // Add post_parent query_var if one is present
856 if ( !empty( $_GET['bbp_forum_id'] ) ) {
857 $query_vars['meta_key'] = '_bbp_forum_id';
858 $query_vars['meta_value'] = $_GET['bbp_forum_id'];
859 }
860
861 // Return manipulated query_vars
862 return $query_vars;
863 }
864
865 /**
866 * Custom user feedback messages for reply post type
867 *
868 * @since bbPress (r3080)
869 *
870 * @global int $post_ID
871 * @uses bbp_get_topic_permalink()
872 * @uses wp_post_revision_title()
873 * @uses esc_url()
874 * @uses add_query_arg()
875 *
876 * @param array $messages
877 *
878 * @return array
879 */
880 public function updated_messages( $messages ) {
881 global $post_ID;
882
883 if ( $this->bail() ) return $messages;
884
885 // URL for the current topic
886 $topic_url = bbp_get_topic_permalink( bbp_get_reply_topic_id( $post_ID ) );
887
888 // Current reply's post_date
889 $post_date = bbp_get_global_post_field( 'post_date', 'raw' );
890
891 // Messages array
892 $messages[$this->post_type] = array(
893 0 => '', // Left empty on purpose
894
895 // Updated
896 1 => sprintf( __( 'Reply updated. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
897
898 // Custom field updated
899 2 => __( 'Custom field updated.', 'bbpress' ),
900
901 // Custom field deleted
902 3 => __( 'Custom field deleted.', 'bbpress' ),
903
904 // Reply updated
905 4 => __( 'Reply updated.', 'bbpress' ),
906
907 // Restored from revision
908 // translators: %s: date and time of the revision
909 5 => isset( $_GET['revision'] )
910 ? sprintf( __( 'Reply restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
911 : false,
912
913 // Reply created
914 6 => sprintf( __( 'Reply created. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
915
916 // Reply saved
917 7 => __( 'Reply saved.', 'bbpress' ),
918
919 // Reply submitted
920 8 => sprintf( __( 'Reply submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
921
922 // Reply scheduled
923 9 => sprintf( __( 'Reply scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress' ),
924 // translators: Publish box date format, see http://php.net/date
925 date_i18n( __( 'M j, Y @ G:i', 'bbpress' ),
926 strtotime( $post_date ) ),
927 $topic_url ),
928
929 // Reply draft updated
930 10 => sprintf( __( 'Reply draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
931 );
932
933 return $messages;
934 }
935 }
936 endif; // class_exists check
937
938 /**
939 * Setup bbPress Replies Admin
940 *
941 * This is currently here to make hooking and unhooking of the admin UI easy.
942 * It could use dependency injection in the future, but for now this is easier.
943 *
944 * @since bbPress (r2596)
945 *
946 * @uses BBP_Replies_Admin
947 */
948 function bbp_admin_replies() {
949 bbpress()->admin->replies = new BBP_Replies_Admin();
950 }
951