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-topics.php

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

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