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

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