PluginProbe
bbPress / 2.1-rc2
bbPress v2.1-rc2
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-topics.php

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

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