PluginProbe
bbPress / 2.1.2
bbPress v2.1.2
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-topics.php

bbp-topics.php in bbPress 2.1.2, at bbp-admin/bbp-topics.php

1,020 lines 40.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 Topics 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_Topics_Admin' ) ) :
14 /**
15 * Loads bbPress topics admin area
16 *
17 * @package bbPress
18 * @subpackage Administration
19 * @since bbPress (r2464)
20 */
21 class BBP_Topics_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 topics admin loader
34 *
35 * @since bbPress (r2515)
36 *
37 * @uses BBP_Topics_Admin::setup_globals() Setup the globals needed
38 * @uses BBP_Topics_Admin::setup_actions() Setup the hooks and actions
39 * @uses BBP_Topics_Admin::setup_help() 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 // Topic column headers.
67 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'topics_column_headers' ) );
68
69 // Topic columns (in post row)
70 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'topics_column_data' ), 10, 2 );
71 add_filter( 'post_row_actions', array( $this, 'topics_row_actions' ), 10, 2 );
72
73 // Topic metabox actions
74 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) );
75 add_action( 'save_post', array( $this, 'attributes_metabox_save' ) );
76
77 // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed
78 add_action( 'load-edit.php', array( $this, 'toggle_topic' ) );
79 add_action( 'admin_notices', array( $this, 'toggle_topic_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 ( !isset( get_current_screen()->post_type ) || ( $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_topic_post_type();
115 }
116
117 /** Contextual Help *******************************************************/
118
119 /**
120 * Contextual help for bbPress topic 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 displays the individual topics on your site. 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 topics to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' .
145 '<li>' . __( 'You can filter the list of topics by forum status using the text links in the upper left to show All, Published, or Trashed topics. The default view is to show all topics.', 'bbpress' ) . '</li>' .
146 '<li>' . __( 'You can refine the list to show only topics from a specific month by using the dropdown menus above the topics list. Click the Filter button after making your selection. You also can refine the list by clicking on the forum creator in the topics list.', 'bbpress' ) . '</li>' .
147 '</ul>'
148 ) );
149
150 // Available Actions
151 get_current_screen()->add_help_tab( array(
152 'id' => 'action-links',
153 'title' => __( 'Available Actions', 'bbpress' ),
154 'content' =>
155 '<p>' . __( 'Hovering over a row in the topics list will display action links that allow you to manage your topic. You can perform the following actions:', 'bbpress' ) . '</p>' .
156 '<ul>' .
157 '<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that forum. You can also reach that screen by clicking on the forum title.', 'bbpress' ) . '</li>' .
158 '<li>' . __( '<strong>Trash</strong> removes your forum 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 topic 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 topic will look like if you publish it. View will take you to your live site to view the topic. Which link is available depends on your topic&#8217;s status.', 'bbpress' ) . '</li>' .
161 '</ul>'
162 ) );
163
164 // Bulk Actions
165 get_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 topics to the trash at once. Select the topics 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 topics at once. To remove a topic 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 get_current_screen()->set_help_sidebar(
175 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
176 '<p>' . __( '<a href="http://codex.bbpress.org" 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 topic edit page
183 *
184 * @since bbPress (r3119)
185 * @uses get_current_screen()
186 */
187 public function new_help() {
188
189 if ( $this->bail() ) return;
190
191 $customize_display = '<p>' . __( 'The title field and the big topic 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>';
192
193 get_current_screen()->add_help_tab( array(
194 'id' => 'customize-display',
195 'title' => __( 'Customizing This Display', 'bbpress' ),
196 'content' => $customize_display,
197 ) );
198
199 get_current_screen()->add_help_tab( array(
200 'id' => 'title-topic-editor',
201 'title' => __( 'Title and Topic Editor', 'bbpress' ),
202 'content' =>
203 '<p>' . __( '<strong>Title</strong> - Enter a title for your topic. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
204 '<p>' . __( '<strong>Topic Editor</strong> - Enter the text for your topic. 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 topic text. You can insert media files by clicking the icons above the topic 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 topic editor.', 'bbpress' ) . '</p>'
205 ) );
206
207 $publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your topic 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 topic 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 topic to be published in the future or backdate a topic.', 'bbpress' ) . '</p>';
208
209 if ( current_theme_supports( 'topic-formats' ) && topic_type_supports( 'topic', 'topic-formats' ) ) {
210 $publish_box .= '<p>' . __( '<strong>topic Format</strong> - This designates how your theme will display a specific topic. For example, you could have a <em>standard</em> blog topic 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 topic format</a>. Your theme could enable all or some of 10 possible formats.', 'bbpress' ) . '</p>';
211 }
212
213 if ( current_theme_supports( 'topic-thumbnails' ) && topic_type_supports( 'topic', 'thumbnail' ) ) {
214 $publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your topic without inserting it. This is usually useful only if your theme makes use of the featured image as a topic thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>';
215 }
216
217 get_current_screen()->add_help_tab( array(
218 'id' => 'topic-attributes',
219 'title' => __( 'Topic Attributes', 'bbpress' ),
220 'content' =>
221 '<p>' . __( 'Select the attributes that your topic should have:', 'bbpress' ) . '</p>' .
222 '<ul>' .
223 '<li>' . __( '<strong>Forum</strong> dropdown determines the parent forum that the topic belongs to. Select the forum or category from the dropdown, or leave the default (No Forum) to post the topic without an assigned forum.', 'bbpress' ) . '</li>' .
224 '<li>' . __( '<strong>Topic Type</strong> dropdown indicates the sticky status of the topic. Selecting the super sticky option would stick the topic to the front of your forums, i.e. the topic index, sticky option would stick the topic to its respective forum. Selecting normal would not stick the topic anywhere.', 'bbpress' ) . '</li>' .
225 '</ul>'
226 ) );
227
228 get_current_screen()->add_help_tab( array(
229 'id' => 'publish-box',
230 'title' => __( 'Publish Box', 'bbpress' ),
231 'content' => $publish_box,
232 ) );
233
234 get_current_screen()->add_help_tab( array(
235 'id' => 'discussion-settings',
236 'title' => __( 'Discussion Settings', 'bbpress' ),
237 'content' =>
238 '<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>' .
239 '<p>' . __( '<strong>Discussion</strong> - You can turn comments and pings on or off, and if there are comments on the topic, you can see them here and moderate them.', 'bbpress' ) . '</p>'
240 ) );
241
242 get_current_screen()->set_help_sidebar(
243 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
244 '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
245 '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
246 );
247 }
248
249 /**
250 * Add the topic attributes metabox
251 *
252 * @since bbPress (r2744)
253 *
254 * @uses bbp_get_topic_post_type() To get the topic post type
255 * @uses add_meta_box() To add the metabox
256 * @uses do_action() Calls 'bbp_topic_attributes_metabox'
257 */
258 public function attributes_metabox() {
259
260 if ( $this->bail() ) return;
261
262 add_meta_box (
263 'bbp_topic_attributes',
264 __( 'Topic Attributes', 'bbpress' ),
265 'bbp_topic_metabox',
266 $this->post_type,
267 'side',
268 'high'
269 );
270
271 do_action( 'bbp_topic_attributes_metabox' );
272 }
273
274 /**
275 * Pass the topic attributes for processing
276 *
277 * @since bbPress (r2746)
278 *
279 * @param int $topic_id Topic id
280 * @uses current_user_can() To check if the current user is capable of
281 * editing the topic
282 * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the
283 * topic id and parent id
284 * @return int Parent id
285 */
286 public function attributes_metabox_save( $topic_id ) {
287
288 if ( $this->bail() ) return $topic_id;
289
290 // Bail if doing an autosave
291 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
292 return $topic_id;
293
294 // Bail if not a post request
295 if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
296 return $topic_id;
297
298 // Nonce check
299 if ( empty( $_POST['bbp_topic_metabox'] ) || !wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) )
300 return $topic_id;
301
302 // Bail if current user cannot edit this topic
303 if ( !current_user_can( 'edit_topic', $topic_id ) )
304 return $topic_id;
305
306 // Get the forum ID
307 $forum_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
308
309 // Formally update the topic
310 bbp_update_topic( $topic_id, $forum_id );
311
312 // Stickies
313 if ( !empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array( 'stick', 'super', 'unstick' ) ) ) {
314
315 // What's the haps?
316 switch ( $_POST['bbp_stick_topic'] ) {
317
318 // Sticky in this forum
319 case 'stick' :
320 bbp_stick_topic( $topic_id );
321 break;
322
323 // Super sticky in all forums
324 case 'super' :
325 bbp_stick_topic( $topic_id, true );
326 break;
327
328 // Normal
329 case 'unstick' :
330 default :
331 bbp_unstick_topic( $topic_id );
332 break;
333 }
334 }
335
336 // Allow other fun things to happen
337 do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id );
338
339 return $topic_id;
340 }
341
342 /**
343 * Add the author info metabox
344 *
345 * @since bbPress (r2828)
346 *
347 * @uses bbp_get_topic() To get the topic
348 * @uses bbp_get_reply() To get the reply
349 * @uses bbp_get_topic_post_type() To get the topic post type
350 * @uses bbp_get_reply_post_type() To get the reply post type
351 * @uses add_meta_box() To add the metabox
352 * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply
353 * id
354 */
355 public function author_metabox() {
356
357 if ( $this->bail() ) return;
358
359 // Bail if post_type is not a topic
360 if ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) )
361 return;
362
363 // Add the metabox
364 add_meta_box(
365 'bbp_author_metabox',
366 __( 'Author Information', 'bbpress' ),
367 'bbp_author_metabox',
368 $this->post_type,
369 'side',
370 'high'
371 );
372
373 do_action( 'bbp_author_metabox', get_the_ID() );
374 }
375
376 /**
377 * Save the author information for the topic
378 *
379 * @since bbPress (r2828)
380 *
381 * @param int $post_id Topic or reply id
382 * @uses bbp_get_topic() To get the topic
383 * @uses bbp_get_reply() To get the reply
384 * @uses current_user_can() To check if the current user can edit the
385 * topic or reply
386 * @uses bbp_filter_author_post_data() To filter the author data
387 * @uses update_post_meta() To update the anonymous user data
388 * @uses do_action() Calls 'bbp_author_metabox_save' with the topic id and
389 * anonymous data
390 * @return int Topic or reply id
391 */
392 public function author_metabox_save( $post_id ) {
393
394 if ( $this->bail() ) return $post_id;
395
396 // Bail if no post_id
397 if ( empty( $post_id ) )
398 return $post_id;
399
400 // Bail if doing an autosave
401 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
402 return $post_id;
403
404 // Bail if not a post request
405 if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
406 return $post_id;
407
408 // Bail if user cannot edit topics
409 if ( !current_user_can( 'edit_topic', $post_id ) )
410 return $post_id;
411
412 $anonymous_data = bbp_filter_anonymous_post_data();
413
414 update_post_meta( $post_id, '_bbp_anonymous_name', $anonymous_data['bbp_anonymous_name'] );
415 update_post_meta( $post_id, '_bbp_anonymous_email', $anonymous_data['bbp_anonymous_email'] );
416 update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] );
417
418 do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data );
419
420 return $post_id;
421 }
422
423 /**
424 * Add some general styling to the admin area
425 *
426 * @since bbPress (r2464)
427 *
428 * @uses bbp_get_forum_post_type() To get the forum post type
429 * @uses bbp_get_topic_post_type() To get the topic post type
430 * @uses bbp_get_reply_post_type() To get the reply post type
431 * @uses sanitize_html_class() To sanitize the classes
432 * @uses do_action() Calls 'bbp_admin_head'
433 */
434 public function admin_head() {
435
436 if ( $this->bail() ) return;
437
438 ?>
439
440 <style type="text/css" media="screen">
441 /*<![CDATA[*/
442
443 .column-bbp_forum_topic_count,
444 .column-bbp_forum_reply_count,
445 .column-bbp_topic_reply_count,
446 .column-bbp_topic_voice_count {
447 width: 8% !important;
448 }
449
450 .column-author,
451 .column-bbp_reply_author,
452 .column-bbp_topic_author {
453 width: 10% !important;
454 }
455
456 .column-bbp_topic_forum,
457 .column-bbp_reply_forum,
458 .column-bbp_reply_topic {
459 width: 10% !important;
460 }
461
462 .column-bbp_forum_freshness,
463 .column-bbp_topic_freshness {
464 width: 10% !important;
465 }
466
467 .column-bbp_forum_created,
468 .column-bbp_topic_created,
469 .column-bbp_reply_created {
470 width: 15% !important;
471 }
472
473 .status-closed {
474 background-color: #eaeaea;
475 }
476
477 .status-spam {
478 background-color: #faeaea;
479 }
480
481 /*]]>*/
482 </style>
483
484 <?php
485 }
486
487 /**
488 * Toggle topic
489 *
490 * Handles the admin-side opening/closing, sticking/unsticking and
491 * spamming/unspamming of topics
492 *
493 * @since bbPress (r2727)
494 *
495 * @uses bbp_get_topic() To get the topic
496 * @uses current_user_can() To check if the user is capable of editing
497 * the topic
498 * @uses wp_die() To die if the user isn't capable or the post wasn't
499 * found
500 * @uses check_admin_referer() To verify the nonce and check referer
501 * @uses bbp_is_topic_open() To check if the topic is open
502 * @uses bbp_close_topic() To close the topic
503 * @uses bbp_open_topic() To open the topic
504 * @uses bbp_is_topic_sticky() To check if the topic is a sticky or
505 * super sticky
506 * @uses bbp_unstick_topic() To unstick the topic
507 * @uses bbp_stick_topic() To stick the topic
508 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
509 * @uses bbp_unspam_topic() To unmark the topic as spam
510 * @uses bbp_spam_topic() To mark the topic as spam
511 * @uses do_action() Calls 'bbp_toggle_topic_admin' with success, post
512 * data, action and message
513 * @uses add_query_arg() To add custom args to the url
514 * @uses wp_safe_redirect() Redirect the page to custom url
515 */
516 public function toggle_topic() {
517
518 if ( $this->bail() ) return;
519
520 // Only proceed if GET is a topic toggle action
521 if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam' ) ) && !empty( $_GET['topic_id'] ) ) {
522 $action = $_GET['action']; // What action is taking place?
523 $topic_id = (int) $_GET['topic_id']; // What's the topic id?
524 $success = false; // Flag
525 $post_data = array( 'ID' => $topic_id ); // Prelim array
526 $topic = bbp_get_topic( $topic_id );
527
528 // Bail if topic is missing
529 if ( empty( $topic ) )
530 wp_die( __( 'The topic was not found!', 'bbpress' ) );
531
532 if ( !current_user_can( 'moderate', $topic->ID ) ) // What is the user doing here?
533 wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) );
534
535 switch ( $action ) {
536 case 'bbp_toggle_topic_close' :
537 check_admin_referer( 'close-topic_' . $topic_id );
538
539 $is_open = bbp_is_topic_open( $topic_id );
540 $message = true == $is_open ? 'closed' : 'opened';
541 $success = true == $is_open ? bbp_close_topic( $topic_id ) : bbp_open_topic( $topic_id );
542
543 break;
544
545 case 'bbp_toggle_topic_stick' :
546 check_admin_referer( 'stick-topic_' . $topic_id );
547
548 $is_sticky = bbp_is_topic_sticky( $topic_id );
549 $is_super = ( empty( $is_sticky ) && !empty( $_GET['super'] ) && 1 == (int) $_GET['super'] ) ? true : false;
550 $message = true == $is_sticky ? 'unsticked' : 'sticked';
551 $message = true == $is_super ? 'super_sticked' : $message;
552 $success = true == $is_sticky ? bbp_unstick_topic( $topic_id ) : bbp_stick_topic( $topic_id, $is_super );
553
554 break;
555
556 case 'bbp_toggle_topic_spam' :
557 check_admin_referer( 'spam-topic_' . $topic_id );
558
559 $is_spam = bbp_is_topic_spam( $topic_id );
560 $message = true == $is_spam ? 'unspammed' : 'spammed';
561 $success = true == $is_spam ? bbp_unspam_topic( $topic_id ) : bbp_spam_topic( $topic_id );
562
563 break;
564 }
565
566 $message = array( 'bbp_topic_toggle_notice' => $message, 'topic_id' => $topic->ID );
567
568 if ( false == $success || is_wp_error( $success ) )
569 $message['failed'] = '1';
570
571 // Do additional topic toggle actions (admin side)
572 do_action( 'bbp_toggle_topic_admin', $success, $post_data, $action, $message );
573
574 // Redirect back to the topic
575 $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'topic_id' ) ) );
576 wp_safe_redirect( $redirect );
577
578 // For good measure
579 exit();
580 }
581 }
582
583 /**
584 * Toggle topic notices
585 *
586 * Display the success/error notices from
587 * {@link BBP_Admin::toggle_topic()}
588 *
589 * @since bbPress (r2727)
590 *
591 * @uses bbp_get_topic() To get the topic
592 * @uses bbp_get_topic_title() To get the topic title of the topic
593 * @uses esc_html() To sanitize the topic title
594 * @uses apply_filters() Calls 'bbp_toggle_topic_notice_admin' with
595 * message, topic id, notice and is it a failure
596 */
597 public function toggle_topic_notice() {
598
599 if ( $this->bail() ) return;
600
601 // Only proceed if GET is a topic toggle action
602 if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['bbp_topic_toggle_notice'] ) && in_array( $_GET['bbp_topic_toggle_notice'], array( 'opened', 'closed', 'super_sticked', 'sticked', 'unsticked', 'spammed', 'unspammed' ) ) && !empty( $_GET['topic_id'] ) ) {
603 $notice = $_GET['bbp_topic_toggle_notice']; // Which notice?
604 $topic_id = (int) $_GET['topic_id']; // What's the topic id?
605 $is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure?
606
607 // Bais if no topic_id or notice
608 if ( empty( $notice ) || empty( $topic_id ) )
609 return;
610
611 // Bail if topic is missing
612 $topic = bbp_get_topic( $topic_id );
613 if ( empty( $topic ) )
614 return;
615
616 $topic_title = esc_html( bbp_get_topic_title( $topic->ID ) );
617
618 switch ( $notice ) {
619 case 'opened' :
620 $message = $is_failure == true ? sprintf( __( 'There was a problem opening the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully opened.', 'bbpress' ), $topic_title );
621 break;
622
623 case 'closed' :
624 $message = $is_failure == true ? sprintf( __( 'There was a problem closing the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully closed.', 'bbpress' ), $topic_title );
625 break;
626
627 case 'super_sticked' :
628 $message = $is_failure == true ? sprintf( __( 'There was a problem sticking the topic "%1$s" to front.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked to front.', 'bbpress' ), $topic_title );
629 break;
630
631 case 'sticked' :
632 $message = $is_failure == true ? sprintf( __( 'There was a problem sticking the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked.', 'bbpress' ), $topic_title );
633 break;
634
635 case 'unsticked' :
636 $message = $is_failure == true ? sprintf( __( 'There was a problem unsticking the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unsticked.', 'bbpress' ), $topic_title );
637 break;
638
639 case 'spammed' :
640 $message = $is_failure == true ? sprintf( __( 'There was a problem marking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully marked as spam.', 'bbpress' ), $topic_title );
641 break;
642
643 case 'unspammed' :
644 $message = $is_failure == true ? sprintf( __( 'There was a problem unmarking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unmarked as spam.', 'bbpress' ), $topic_title );
645 break;
646 }
647
648 // Do additional topic toggle notice filters (admin side)
649 $message = apply_filters( 'bbp_toggle_topic_notice_admin', $message, $topic->ID, $notice, $is_failure );
650
651 ?>
652
653 <div id="message" class="<?php echo $is_failure == true ? 'error' : 'updated'; ?> fade">
654 <p style="line-height: 150%"><?php echo $message; ?></p>
655 </div>
656
657 <?php
658 }
659 }
660
661 /**
662 * Manage the column headers for the topics page
663 *
664 * @since bbPress (r2485)
665 *
666 * @param array $columns The columns
667 * @uses apply_filters() Calls 'bbp_admin_topics_column_headers' with
668 * the columns
669 * @return array $columns bbPress topic columns
670 */
671 public function topics_column_headers( $columns ) {
672
673 if ( $this->bail() ) return $columns;
674
675 $columns = array(
676 'cb' => '<input type="checkbox" />',
677 'title' => __( 'Topics', 'bbpress' ),
678 'bbp_topic_forum' => __( 'Forum', 'bbpress' ),
679 'bbp_topic_reply_count' => __( 'Replies', 'bbpress' ),
680 'bbp_topic_voice_count' => __( 'Voices', 'bbpress' ),
681 'bbp_topic_author' => __( 'Author', 'bbpress' ),
682 'bbp_topic_created' => __( 'Created', 'bbpress' ),
683 'bbp_topic_freshness' => __( 'Freshness', 'bbpress' )
684 );
685
686 return apply_filters( 'bbp_admin_topics_column_headers', $columns );
687 }
688
689 /**
690 * Print extra columns for the topics page
691 *
692 * @since bbPress (r2485)
693 *
694 * @param string $column Column
695 * @param int $topic_id Topic id
696 * @uses bbp_get_topic_forum_id() To get the forum id of the topic
697 * @uses bbp_forum_title() To output the topic's forum title
698 * @uses apply_filters() Calls 'topic_forum_row_actions' with an array
699 * of topic forum actions
700 * @uses bbp_get_forum_permalink() To get the forum permalink
701 * @uses admin_url() To get the admin url of post.php
702 * @uses add_query_arg() To add custom args to the url
703 * @uses bbp_topic_reply_count() To output the topic reply count
704 * @uses bbp_topic_voice_count() To output the topic voice count
705 * @uses bbp_topic_author_display_name() To output the topic author name
706 * @uses get_the_date() Get the topic creation date
707 * @uses get_the_time() Get the topic creation time
708 * @uses esc_attr() To sanitize the topic creation time
709 * @uses bbp_get_topic_last_active_time() To get the time when the topic was
710 * last active
711 * @uses do_action() Calls 'bbp_admin_topics_column_data' with the
712 * column and topic id
713 */
714 function topics_column_data( $column, $topic_id ) {
715
716 if ( $this->bail() ) return;
717
718 // Get topic forum ID
719 $forum_id = bbp_get_topic_forum_id( $topic_id );
720
721 // Populate column data
722 switch ( $column ) {
723
724 // Forum
725 case 'bbp_topic_forum' :
726
727 // Output forum name
728 if ( !empty( $forum_id ) ) {
729
730 // Forum Title
731 $forum_title = bbp_get_forum_title( $forum_id );
732 if ( empty( $forum_title ) ) {
733 $forum_title = __( 'No Forum', 'bbpress' );
734 }
735
736 // Output the title
737 echo $forum_title;
738
739 } else {
740 _e( '(No Forum)', 'bbpress' );
741 }
742
743 break;
744
745 // Reply Count
746 case 'bbp_topic_reply_count' :
747 bbp_topic_reply_count( $topic_id );
748 break;
749
750 // Reply Count
751 case 'bbp_topic_voice_count' :
752 bbp_topic_voice_count( $topic_id );
753 break;
754
755 // Author
756 case 'bbp_topic_author' :
757 bbp_topic_author_display_name( $topic_id );
758 break;
759
760 // Freshness
761 case 'bbp_topic_created':
762 printf( __( '%1$s <br /> %2$s', 'bbpress' ),
763 get_the_date(),
764 esc_attr( get_the_time() )
765 );
766
767 break;
768
769 // Freshness
770 case 'bbp_topic_freshness' :
771 $last_active = bbp_get_topic_last_active_time( $topic_id, false );
772 if ( !empty( $last_active ) ) {
773 echo $last_active;
774 } else {
775 _e( 'No Replies', 'bbpress' ); // This should never happen
776 }
777
778 break;
779
780 // Do an action for anything else
781 default :
782 do_action( 'bbp_admin_topics_column_data', $column, $topic_id );
783 break;
784 }
785 }
786
787 /**
788 * Topic Row actions
789 *
790 * Remove the quick-edit action link under the topic title and add the
791 * content and close/stick/spam links
792 *
793 * @since bbPress (r2485)
794 *
795 * @param array $actions Actions
796 * @param array $topic Topic object
797 * @uses bbp_get_topic_post_type() To get the topic post type
798 * @uses bbp_topic_content() To output topic content
799 * @uses bbp_get_topic_permalink() To get the topic link
800 * @uses bbp_get_topic_title() To get the topic title
801 * @uses current_user_can() To check if the current user can edit or
802 * delete the topic
803 * @uses bbp_is_topic_open() To check if the topic is open
804 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
805 * @uses bbp_is_topic_sticky() To check if the topic is a sticky or a
806 * super sticky
807 * @uses get_post_type_object() To get the topic post type object
808 * @uses add_query_arg() To add custom args to the url
809 * @uses remove_query_arg() To remove custom args from the url
810 * @uses wp_nonce_url() To nonce the url
811 * @uses get_delete_post_link() To get the delete post link of the topic
812 * @return array $actions Actions
813 */
814 public function topics_row_actions( $actions, $topic ) {
815
816 if ( $this->bail() ) return $actions;
817
818 unset( $actions['inline hide-if-no-js'] );
819
820 // Show view link if it's not set, the topic is trashed and the user can view trashed topics
821 if ( empty( $actions['view'] ) && ( bbp_get_trash_status_id() == $topic->post_status ) && current_user_can( 'view_trash' ) )
822 $actions['view'] = '<a href="' . bbp_get_topic_permalink( $topic->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . __( 'View', 'bbpress' ) . '</a>';
823
824 // Only show the actions if the user is capable of viewing them :)
825 if ( current_user_can( 'moderate', $topic->ID ) ) {
826
827 // Close
828 // Show the 'close' and 'open' link on published and closed posts only
829 if ( in_array( $topic->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ) ) {
830 $close_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_close' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'close-topic_' . $topic->ID ) );
831 if ( bbp_is_topic_open( $topic->ID ) )
832 $actions['closed'] = '<a href="' . $close_uri . '" title="' . esc_attr__( 'Close this topic', 'bbpress' ) . '">' . _x( 'Close', 'Close a Topic', 'bbpress' ) . '</a>';
833 else
834 $actions['closed'] = '<a href="' . $close_uri . '" title="' . esc_attr__( 'Open this topic', 'bbpress' ) . '">' . _x( 'Open', 'Open a Topic', 'bbpress' ) . '</a>';
835 }
836
837 // Dont show sticky if topic links is spam or trash
838 if ( !bbp_is_topic_spam( $topic->ID ) && !bbp_is_topic_trash( $topic->ID ) ) {
839
840 // Sticky
841 $stick_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_' . $topic->ID ) );
842 if ( bbp_is_topic_sticky( $topic->ID ) ) {
843 $actions['stick'] = '<a href="' . $stick_uri . '" title="' . esc_attr__( 'Unstick this topic', 'bbpress' ) . '">' . __( 'Unstick', 'bbpress' ) . '</a>';
844 } else {
845 $super_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick', 'super' => '1' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_' . $topic->ID ) );
846 $actions['stick'] = '<a href="' . $stick_uri . '" title="' . esc_attr__( 'Stick this topic to its forum', 'bbpress' ) . '">' . __( 'Stick', 'bbpress' ) . '</a> (<a href="' . $super_uri . '" title="' . esc_attr__( 'Stick this topic to front', 'bbpress' ) . '">' . __( 'to front', 'bbpress' ) . '</a>)';
847 }
848 }
849
850 // Spam
851 $spam_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_spam' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'spam-topic_' . $topic->ID ) );
852 if ( bbp_is_topic_spam( $topic->ID ) )
853 $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the topic as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>';
854 else
855 $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this topic as spam', 'bbpress' ) . '">' . __( 'Spam', 'bbpress' ) . '</a>';
856
857 }
858
859 // Do not show trash links for spam topics, or spam links for trashed topics
860 if ( current_user_can( 'delete_topic', $topic->ID ) ) {
861 if ( bbp_get_trash_status_id() == $topic->post_status ) {
862 $post_type_object = get_post_type_object( bbp_get_topic_post_type() );
863 $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . wp_nonce_url( add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit.php' ) ) ), admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $topic->ID ) ) ), 'untrash-' . $topic->post_type . '_' . $topic->ID ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>";
864 } elseif ( EMPTY_TRASH_DAYS ) {
865 $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_topic_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $topic->ID ) ) . "'>" . __( 'Trash', 'bbpress' ) . "</a>";
866 }
867
868 if ( bbp_get_trash_status_id() == $topic->post_status || !EMPTY_TRASH_DAYS ) {
869 $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_topic_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $topic->ID, '', true ) ) . "'>" . __( 'Delete Permanently', 'bbpress' ) . "</a>";
870 } elseif ( bbp_get_spam_status_id() == $topic->post_status ) {
871 unset( $actions['trash'] );
872 }
873 }
874
875 return $actions;
876 }
877
878 /**
879 * Add forum dropdown to topic and reply list table filters
880 *
881 * @since bbPress (r2991)
882 *
883 * @uses bbp_get_reply_post_type() To get the reply post type
884 * @uses bbp_get_topic_post_type() To get the topic post type
885 * @uses bbp_dropdown() To generate a forum dropdown
886 * @return bool False. If post type is not topic or reply
887 */
888 public function filter_dropdown() {
889
890 if ( $this->bail() ) return;
891
892 // Add Empty Spam button
893 if ( !empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() == $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
894 wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
895 $title = esc_attr__( 'Empty Spam', 'bbpress' );
896 submit_button( $title, 'button-secondary apply', 'delete_all', false );
897 }
898
899 // Get which forum is selected
900 $selected = !empty( $_GET['bbp_forum_id'] ) ? $_GET['bbp_forum_id'] : '';
901
902 // Show the forums dropdown
903 bbp_dropdown( array(
904 'selected' => $selected,
905 'show_none' => __( 'In all forums', 'bbpress' )
906 ) );
907 }
908
909 /**
910 * Adjust the request query and include the forum id
911 *
912 * @since bbPress (r2991)
913 *
914 * @param array $query_vars Query variables from {@link WP_Query}
915 * @uses is_admin() To check if it's the admin section
916 * @uses bbp_get_topic_post_type() To get the topic post type
917 * @uses bbp_get_reply_post_type() To get the reply post type
918 * @return array Processed Query Vars
919 */
920 function filter_post_rows( $query_vars ) {
921
922 if ( $this->bail() ) return $query_vars;
923
924 // Add post_parent query_var if one is present
925 if ( !empty( $_GET['bbp_forum_id'] ) ) {
926 $query_vars['meta_key'] = '_bbp_forum_id';
927 $query_vars['meta_value'] = $_GET['bbp_forum_id'];
928 }
929
930 // Return manipulated query_vars
931 return $query_vars;
932 }
933
934 /**
935 * Custom user feedback messages for topic post type
936 *
937 * @since bbPress (r3080)
938 *
939 * @global int $post_ID
940 * @uses bbp_get_topic_permalink()
941 * @uses wp_post_revision_title()
942 * @uses esc_url()
943 * @uses add_query_arg()
944 *
945 * @param array $messages
946 *
947 * @return array
948 */
949 public function updated_messages( $messages ) {
950 global $post_ID;
951
952 if ( $this->bail() ) return $messages;
953
954 // URL for the current topic
955 $topic_url = bbp_get_topic_permalink( $post_ID );
956
957 // Current topic's post_date
958 $post_date = bbp_get_global_post_field( 'post_date', 'raw' );
959
960 // Messages array
961 $messages[$this->post_type] = array(
962 0 => '', // Left empty on purpose
963
964 // Updated
965 1 => sprintf( __( 'Topic updated. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
966
967 // Custom field updated
968 2 => __( 'Custom field updated.', 'bbpress' ),
969
970 // Custom field deleted
971 3 => __( 'Custom field deleted.', 'bbpress' ),
972
973 // Topic updated
974 4 => __( 'Topic updated.', 'bbpress' ),
975
976 // Restored from revision
977 // translators: %s: date and time of the revision
978 5 => isset( $_GET['revision'] )
979 ? sprintf( __( 'Topic restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
980 : false,
981
982 // Topic created
983 6 => sprintf( __( 'Topic created. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
984
985 // Topic saved
986 7 => __( 'Topic saved.', 'bbpress' ),
987
988 // Topic submitted
989 8 => sprintf( __( 'Topic submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
990
991 // Topic scheduled
992 9 => sprintf( __( 'Topic scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress' ),
993 // translators: Publish box date format, see http://php.net/date
994 date_i18n( __( 'M j, Y @ G:i', 'bbpress' ),
995 strtotime( $post_date ) ),
996 $topic_url ),
997
998 // Topic draft updated
999 10 => sprintf( __( 'Topic draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
1000 );
1001
1002 return $messages;
1003 }
1004 }
1005 endif; // class_exists check
1006
1007 /**
1008 * Setup bbPress Topics Admin
1009 *
1010 * This is currently here to make hooking and unhooking of the admin UI easy.
1011 * It could use dependency injection in the future, but for now this is easier.
1012 *
1013 * @since bbPress (r2596)
1014 *
1015 * @uses BBP_Forums_Admin
1016 */
1017 function bbp_admin_topics() {
1018 bbpress()->admin->topics = new BBP_Topics_Admin();
1019 }
1020