PluginProbe
bbPress / 2.0-beta-2b
bbPress v2.0-beta-2b
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.0-beta-2b, at bbp-admin/bbp-topics.php

953 lines 39.5 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 (PHP4 compat)
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 */
40 function BBP_Topics_Admin() {
41 $this->__construct();
42 }
43
44 /**
45 * The main bbPress topics admin loader
46 *
47 * @since bbPress (r2515)
48 *
49 * @uses BBP_Topics_Admin::_setup_globals() Setup the globals needed
50 * @uses BBP_Topics_Admin::_setup_actions() Setup the hooks and actions
51 */
52 function __construct() {
53 $this->_setup_globals();
54 $this->_setup_actions();
55 $this->_setup_help();
56 }
57
58 /**
59 * Setup the admin hooks, actions and filters
60 *
61 * @since bbPress (r2646)
62 * @access private
63 *
64 * @uses add_action() To add various actions
65 * @uses add_filter() To add various filters
66 * @uses bbp_get_forum_post_type() To get the forum post type
67 * @uses bbp_get_topic_post_type() To get the topic post type
68 * @uses bbp_get_reply_post_type() To get the reply post type
69 */
70 function _setup_actions() {
71
72 // Add some general styling to the admin area
73 add_action( 'admin_head', array( $this, 'admin_head' ) );
74
75 // Messages
76 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
77
78 // Topic column headers.
79 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'topics_column_headers' ) );
80
81 // Topic columns (in post row)
82 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'topics_column_data' ), 10, 2 );
83 add_filter( 'post_row_actions', array( $this, 'topics_row_actions' ), 10, 2 );
84
85 // Topic metabox actions
86 add_action( 'add_meta_boxes', array( $this, 'topic_attributes_metabox' ) );
87 add_action( 'save_post', array( $this, 'topic_attributes_metabox_save' ) );
88
89 // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed
90 add_action( 'bbp_admin_init', array( $this, 'toggle_topic' ) );
91 add_action( 'admin_notices', array( $this, 'toggle_topic_notice' ) );
92
93 // Anonymous metabox actions
94 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) );
95 add_action( 'save_post', array( $this, 'author_metabox_save' ) );
96
97 // Add ability to filter topics and replies per forum
98 add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) );
99 add_filter( 'request', array( $this, 'filter_post_rows' ) );
100 }
101
102 /**
103 * Admin globals
104 *
105 * @since bbPress (r2646)
106 * @access private
107 */
108 function _setup_globals() {
109
110 // Setup the post type for this admin component
111 $this->post_type = bbp_get_topic_post_type();
112 }
113
114 /**
115 * Contextual help for topics
116 *
117 * @since bbPress (r3119)
118 * @access private
119 */
120 function _setup_help() {
121
122 // Prevent debug notices
123 $contextual_help = '';
124
125 /** New/Edit **********************************************************/
126
127 $bbp_contextual_help[] = __( 'The topic 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 the box. Use the Screen Options tab to unhide more boxes (Topic Tags, Topic Attributes, or Slug) or to choose a 1- or 2-column layout for this screen.', 'bbpress' );
128 $bbp_contextual_help[] = __( '<strong>Title</strong> - Enter a title for your topic. After you enter a title, you will see the permalink below, which you can edit.', 'bbpress' );
129 $bbp_contextual_help[] = __( '<strong>Post 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 screen icon just before that allows you to expand the edit box to full screen. The HTML mode allows you to enter raw HTML along with your forum text. You can insert media files by clicking the icons above the post editor and following the directions.', 'bbpress' );
130 $bbp_contextual_help[] = __( '<strong>Topic Attributes</strong> - Select the attributes that your topic should have. The Forum 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' );
131 $bbp_contextual_help[] = __( '<strong>Publish</strong> - The Publish box will allow you to save your topic as Draft or Pending Review. You may Preview your topic before it is published as well. The Visibility will determine whether the topic is Public, Password protected (requiring a password on the site to view) or Private (only the author will have access to it). Topics may be published immediately by clicking the dropdown, or at a specific date and time by clicking the Edit link.', 'bbpress' );
132 $bbp_contextual_help[] = __( '<strong>Topic Tags</strong> - You can assign keywords to your topics using Topic Tags. Unlike categories, tags have no hierarchy, meaning there is no relationship from one tag to another. Topics can be added and modified further from the Topic Tags screen.', 'bbpress' );
133 $bbp_contextual_help[] = __( '<strong>Revisions</strong> - Revisions show past versions of the saved topic. Each revision can be compared to the current version, or another revision. Revisions can also be restored to the current version.', 'bbpress' );
134 $bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' );
135 $bbp_contextual_help[] =
136 '<ul>' .
137 '<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' .
138 '<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>', 'bbpress' ) . '</li>' .
139 '</ul>';
140
141 // Wrap each help item in paragraph tags
142 foreach( $bbp_contextual_help as $paragraph )
143 $contextual_help .= '<p>' . $paragraph . '</p>';
144
145 // Add help
146 add_contextual_help( bbp_get_topic_post_type(), $contextual_help );
147
148 // Reset
149 $contextual_help = $bbp_contextual_help = '';
150
151 /** Post Rows *********************************************************/
152
153 $bbp_contextual_help[] = __( 'This screen displays the topics created on your site.', 'bbpress' );
154 $bbp_contextual_help[] = __( 'You can customize the display of this screen in a number of ways:', 'bbpress' );
155 $bbp_contextual_help[] =
156 '<ul>' .
157 '<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>' .
158 '<li>' . __( 'You can filter the list of topics by topics status using the text links in the upper left to show All, Published, Pending Review, Draft, or Trashed topics. The default view is to show all topics.', 'bbpress' ) . '</li>' .
159 '<li>' . __( 'You can view topics 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>' .
160 '<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.', 'bbpress' ) . '</li>' .
161 '<li>' . __( 'You can also show only topics from a specific parent forum by using the parent forum dropdown above the topics list and selecting the parent forum. Click the Filter button after making your selection.', 'bbpress' ) . '</li>' .
162 '<li>' . __( 'You can refine the list by clicking on the topic creator in the topics list.', 'bbpress' ) . '</li>' .
163 '</ul>' .
164
165 $bbp_contextual_help[] = __( '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' );
166 $bbp_contextual_help[] =
167 '<ul>' .
168 '<li>' . __( 'Edit takes you to the editing screen for that topic. You can also reach that screen by clicking on the topic title.', 'bbpress' ) . '</li>' .
169 '<li>' . __( 'Trash removes your topic from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
170 '<li>' . __( 'View will take you to your live topic to view the topic.', 'bbpress' ) . '</li>' .
171 '<li>' . __( 'Close will close your topic, disabling new replies within it. It will remain viewable to users, but replies will not be allowed.', 'bbpress' ) . '</li>' .
172 '<li>' . __( 'Stick (to front) will pin the topic to the front page of the forum that it&rsquo;s in. New topics will begin beneath the list of "stuck" topics, which will always sit at the top of the list.', 'bbpress' ) . '</li>' .
173 '<li>' . __( 'Spam will mark the topic as spam, closing the post to new replies and removing it from the public view.', 'bbpress' ) . '</li>' .
174 '</ul>' .
175
176 $bbp_contextual_help[] = __( 'You can also edit multiple topics at once. Select the topics you want to edit using the checkboxes, select Edit from the Bulk Actions menu and click Apply. You will be able to change the metadata 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' );
177 $bbp_contextual_help[] = __( 'The Bulk Actions menu may also be used to delete multiple topics at once. Select Delete from the dropdown after making your selection.', 'bbpress' );
178 $bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' );
179 $bbp_contextual_help[] =
180 '<ul>' .
181 '<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' .
182 '<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>' , 'bbpress' ) . '</li>' .
183 '</ul>';
184
185 // Wrap each help item in paragraph tags
186 foreach( $bbp_contextual_help as $paragraph )
187 $contextual_help .= '<p>' . $paragraph . '</p>';
188
189 // Add help
190 add_contextual_help( bbp_get_topic_post_type(), $contextual_help );
191
192 // Reset
193 $contextual_help = $bbp_contextual_help = '';
194
195 /** Topic Tags **********************************************************/
196
197 $bbp_contextual_help[] = __( 'You can change the display of this screen using the Screen Options tab to set how many items are displayed per screen (20 by default) and to display/hide columns in the table (Description, Slug, and Topics).', 'bbpress' );
198 $bbp_contextual_help[] = __( 'You can assign keywords to your topics using Topic Tags. Unlike categories, tags have no hierarchy, meaning there is no relationship from one tag to another.', 'bbpress' );
199 $bbp_contextual_help[] = __( 'Normally, tags are ad-hoc keywords that identify important information in your topic (names, subjects, etc) that may or may not recur in other topics. If you think of your forum like a book, the tags are like the terms in the index.', 'bbpress' );
200 $bbp_contextual_help[] = __( 'When editing a topic tag on this screen, you will fill in the following fields:', 'bbpress' );
201 $bbp_contextual_help[] =
202 '<ul>' .
203 '<li>' . __( '<strong>Name</strong> - The name is how it appears on your site.', 'bbpress' ) . '</li>' .
204 '<li>' . __( '<strong>Slug</strong> - The Slug is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'bbpress' ) . '</li>' .
205 '<li>' . __( '<strong>Description</strong> - The description is not prominent by default; however, some forum themes may display it.', 'bbpress' ) . '</li>' .
206 '</ul>' ;
207
208 // Wrap each help item in paragraph tags
209 foreach( $bbp_contextual_help as $paragraph )
210 $contextual_help .= '<p>' . $paragraph . '</p>';
211
212 // Add help
213 global $bbp;
214 add_contextual_help( 'edit-' . $bbp->topic_tag_id, $contextual_help );
215 }
216
217 /**
218 * Add the topic attributes metabox
219 *
220 * @since bbPress (r2744)
221 *
222 * @uses bbp_get_topic_post_type() To get the topic post type
223 * @uses add_meta_box() To add the metabox
224 * @uses do_action() Calls 'bbp_topic_attributes_metabox'
225 */
226 function topic_attributes_metabox() {
227 add_meta_box (
228 'bbp_topic_attributes',
229 __( 'Topic Attributes', 'bbpress' ),
230 'bbp_topic_metabox',
231 $this->post_type,
232 'side',
233 'high'
234 );
235
236 do_action( 'bbp_topic_attributes_metabox' );
237 }
238
239 /**
240 * Pass the topic attributes for processing
241 *
242 * @since bbPress (r2746)
243 *
244 * @param int $topic_id Topic id
245 * @uses current_user_can() To check if the current user is capable of
246 * editing the topic
247 * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the
248 * topic id and parent id
249 * @return int Parent id
250 */
251 function topic_attributes_metabox_save( $topic_id ) {
252
253 // Bail if doing an autosave
254 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
255 return $topic_id;
256
257 // Bail if current user cannot edit this topic
258 if ( !current_user_can( 'edit_topic', $topic_id ) )
259 return $topic_id;
260
261 // Load the topic
262 if ( !$topic = bbp_get_topic( $topic_id ) )
263 return $topic_id;
264
265 // OK, we're authenticated: we need to find and save the data
266 $parent_id = isset( $topic->parent_id ) ? $topic->parent_id : 0;
267
268 do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $parent_id );
269
270 return $parent_id;
271 }
272
273 /**
274 * Add the author info metabox
275 *
276 * @since bbPress (r2828)
277 *
278 * @uses bbp_get_topic() To get the topic
279 * @uses bbp_get_reply() To get the reply
280 * @uses bbp_get_topic_post_type() To get the topic post type
281 * @uses bbp_get_reply_post_type() To get the reply post type
282 * @uses add_meta_box() To add the metabox
283 * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply
284 * id
285 */
286 function author_metabox() {
287 global $current_screen;
288
289 // Bail if post_type is not a topic
290 if ( ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) ) || ( get_post_type() != $this->post_type ) )
291 return;
292
293 // Add the metabox
294 add_meta_box(
295 'bbp_author_metabox',
296 __( 'Author Information', 'bbpress' ),
297 'bbp_author_metabox',
298 $this->post_type,
299 'side',
300 'high'
301 );
302
303 do_action( 'bbp_author_metabox', get_the_ID() );
304 }
305
306 /**
307 * Save the author information for the topic
308 *
309 * @since bbPress (r2828)
310 *
311 * @param int $post_id Topic or reply id
312 * @uses bbp_get_topic() To get the topic
313 * @uses bbp_get_reply() To get the reply
314 * @uses current_user_can() To check if the current user can edit the
315 * topic or reply
316 * @uses bbp_filter_author_post_data() To filter the author data
317 * @uses update_post_meta() To update the anonymous user data
318 * @uses do_action() Calls 'bbp_author_metabox_save' with the topic id and
319 * anonymous data
320 * @return int Topic or reply id
321 */
322 function author_metabox_save( $post_id ) {
323
324 // Bail if no post_id
325 if ( empty( $post_id ) )
326 return $post_id;
327
328 // Bail if doing an autosave
329 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
330 return $post_id;
331
332 // Bail if post_type is not a topic or reply
333 if ( get_post_type( $post_id ) != $this->post_type )
334 return;
335
336 // Bail if user cannot edit replies
337 if ( !current_user_can( 'edit_topic', $post_id ) )
338 return $post_id;
339
340 $anonymous_data = bbp_filter_anonymous_post_data();
341
342 update_post_meta( $post_id, '_bbp_anonymous_name', $anonymous_data['bbp_anonymous_name'] );
343 update_post_meta( $post_id, '_bbp_anonymous_email', $anonymous_data['bbp_anonymous_email'] );
344 update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] );
345
346 do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data );
347
348 return $post_id;
349 }
350
351 /**
352 * Add some general styling to the admin area
353 *
354 * @since bbPress (r2464)
355 *
356 * @uses bbp_get_forum_post_type() To get the forum post type
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 sanitize_html_class() To sanitize the classes
360 * @uses bbp_is_forum() To check if it is a forum page
361 * @uses bbp_is_topic() To check if it is a topic page
362 * @uses bbp_is_reply() To check if it is a reply page
363 * @uses do_action() Calls 'bbp_admin_head'
364 */
365 function admin_head() {
366
367 if ( bbp_is_topic() ) : ?>
368
369 <style type="text/css" media="screen">
370 /*<![CDATA[*/
371
372 .column-bbp_forum_topic_count,
373 .column-bbp_forum_reply_count,
374 .column-bbp_topic_reply_count,
375 .column-bbp_topic_voice_count {
376 width: 8% !important;
377 }
378
379 .column-author,
380 .column-bbp_reply_author,
381 .column-bbp_topic_author {
382 width: 10% !important;
383 }
384
385 .column-bbp_topic_forum,
386 .column-bbp_reply_forum,
387 .column-bbp_reply_topic {
388 width: 10% !important;
389 }
390
391 .column-bbp_forum_freshness,
392 .column-bbp_topic_freshness {
393 width: 10% !important;
394 }
395
396 .column-bbp_forum_created,
397 .column-bbp_topic_created,
398 .column-bbp_reply_created {
399 width: 15% !important;
400 }
401
402 .status-closed {
403 background-color: #eaeaea;
404 }
405
406 .status-spam {
407 background-color: #faeaea;
408 }
409
410 /*]]>*/
411 </style>
412
413 <?php endif;
414
415 }
416
417 /**
418 * Toggle topic
419 *
420 * Handles the admin-side opening/closing, sticking/unsticking and
421 * spamming/unspamming of topics
422 *
423 * @since bbPress (r2727)
424 *
425 * @uses bbp_get_topic() To get the topic
426 * @uses current_user_can() To check if the user is capable of editing
427 * the topic
428 * @uses wp_die() To die if the user isn't capable or the post wasn't
429 * found
430 * @uses check_admin_referer() To verify the nonce and check referer
431 * @uses bbp_is_topic_open() To check if the topic is open
432 * @uses bbp_close_topic() To close the topic
433 * @uses bbp_open_topic() To open the topic
434 * @uses bbp_is_topic_sticky() To check if the topic is a sticky or
435 * super sticky
436 * @uses bbp_unstick_topic() To unstick the topic
437 * @uses bbp_stick_topic() To stick the topic
438 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
439 * @uses bbp_unspam_topic() To unmark the topic as spam
440 * @uses bbp_spam_topic() To mark the topic as spam
441 * @uses do_action() Calls 'bbp_toggle_topic_admin' with success, post
442 * data, action and message
443 * @uses add_query_arg() To add custom args to the url
444 * @uses wp_redirect() Redirect the page to custom url
445 */
446 function toggle_topic() {
447
448 // Only proceed if GET is a topic toggle action
449 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'] ) ) {
450 $action = $_GET['action']; // What action is taking place?
451 $topic_id = (int) $_GET['topic_id']; // What's the topic id?
452 $success = false; // Flag
453 $post_data = array( 'ID' => $topic_id ); // Prelim array
454
455 if ( !$topic = bbp_get_topic( $topic_id ) ) // Which topic?
456 wp_die( __( 'The topic was not found!', 'bbpress' ) );
457
458 if ( !current_user_can( 'moderate', $topic->ID ) ) // What is the user doing here?
459 wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) );
460
461 switch ( $action ) {
462 case 'bbp_toggle_topic_close' :
463 check_admin_referer( 'close-topic_' . $topic_id );
464
465 $is_open = bbp_is_topic_open( $topic_id );
466 $message = true == $is_open ? 'closed' : 'opened';
467 $success = true == $is_open ? bbp_close_topic( $topic_id ) : bbp_open_topic( $topic_id );
468
469 break;
470
471 case 'bbp_toggle_topic_stick' :
472 check_admin_referer( 'stick-topic_' . $topic_id );
473
474 $is_sticky = bbp_is_topic_sticky( $topic_id );
475 $is_super = ( empty( $is_sticky ) && !empty( $_GET['super'] ) && 1 == (int) $_GET['super'] ) ? true : false;
476 $message = true == $is_sticky ? 'unsticked' : 'sticked';
477 $message = true == $is_super ? 'super_sticked' : $message;
478 $success = true == $is_sticky ? bbp_unstick_topic( $topic_id ) : bbp_stick_topic( $topic_id, $is_super );
479
480 break;
481
482 case 'bbp_toggle_topic_spam' :
483 check_admin_referer( 'spam-topic_' . $topic_id );
484
485 $is_spam = bbp_is_topic_spam( $topic_id );
486 $message = true == $is_spam ? 'unspammed' : 'spammed';
487 $success = true == $is_spam ? bbp_unspam_topic( $topic_id ) : bbp_spam_topic( $topic_id );
488
489 break;
490 }
491
492 $message = array( 'bbp_topic_toggle_notice' => $message, 'topic_id' => $topic->ID );
493
494 if ( false == $success || is_wp_error( $success ) )
495 $message['failed'] = '1';
496
497 // Do additional topic toggle actions (admin side)
498 do_action( 'bbp_toggle_topic_admin', $success, $post_data, $action, $message );
499
500 // Redirect back to the topic
501 $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'topic_id' ) ) );
502 wp_redirect( $redirect );
503
504 // For good measure
505 exit();
506 }
507 }
508
509 /**
510 * Toggle topic notices
511 *
512 * Display the success/error notices from
513 * {@link BBP_Admin::toggle_topic()}
514 *
515 * @since bbPress (r2727)
516 *
517 * @uses bbp_get_topic() To get the topic
518 * @uses bbp_get_topic_title() To get the topic title of the topic
519 * @uses esc_html() To sanitize the topic title
520 * @uses apply_filters() Calls 'bbp_toggle_topic_notice_admin' with
521 * message, topic id, notice and is it a failure
522 */
523 function toggle_topic_notice() {
524
525 // Only proceed if GET is a topic toggle action
526 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'] ) ) {
527 $notice = $_GET['bbp_topic_toggle_notice']; // Which notice?
528 $topic_id = (int) $_GET['topic_id']; // What's the topic id?
529 $is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure?
530
531 // Empty? No topic?
532 if ( empty( $notice ) || empty( $topic_id ) || !$topic = bbp_get_topic( $topic_id ) )
533 return;
534
535 $topic_title = esc_html( bbp_get_topic_title( $topic->ID ) );
536
537 switch ( $notice ) {
538 case 'opened' :
539 $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 );
540 break;
541
542 case 'closed' :
543 $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 );
544 break;
545
546 case 'super_sticked' :
547 $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 );
548 break;
549
550 case 'sticked' :
551 $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 );
552 break;
553
554 case 'unsticked' :
555 $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 );
556 break;
557
558 case 'spammed' :
559 $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 );
560 break;
561
562 case 'unspammed' :
563 $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 );
564 break;
565 }
566
567 // Do additional topic toggle notice filters (admin side)
568 $message = apply_filters( 'bbp_toggle_topic_notice_admin', $message, $topic->ID, $notice, $is_failure );
569
570 ?>
571
572 <div id="message" class="<?php echo $is_failure == true ? 'error' : 'updated'; ?> fade">
573 <p style="line-height: 150%"><?php echo $message; ?></p>
574 </div>
575
576 <?php
577 }
578 }
579
580 /**
581 * Manage the column headers for the topics page
582 *
583 * @since bbPress (r2485)
584 *
585 * @param array $columns The columns
586 * @uses apply_filters() Calls 'bbp_admin_topics_column_headers' with
587 * the columns
588 * @return array $columns bbPress topic columns
589 */
590 function topics_column_headers( $columns ) {
591 $columns = array(
592 'cb' => '<input type="checkbox" />',
593 'title' => __( 'Topics', 'bbpress' ),
594 'bbp_topic_forum' => __( 'Forum', 'bbpress' ),
595 'bbp_topic_reply_count' => __( 'Replies', 'bbpress' ),
596 'bbp_topic_voice_count' => __( 'Voices', 'bbpress' ),
597 'bbp_topic_author' => __( 'Author', 'bbpress' ),
598 'bbp_topic_created' => __( 'Created', 'bbpress' ),
599 'bbp_topic_freshness' => __( 'Freshness', 'bbpress' )
600 );
601
602 return apply_filters( 'bbp_admin_topics_column_headers', $columns );
603 }
604
605 /**
606 * Print extra columns for the topics page
607 *
608 * @since bbPress (r2485)
609 *
610 * @param string $column Column
611 * @param int $topic_id Topic id
612 * @uses bbp_get_topic_forum_id() To get the forum id of the topic
613 * @uses bbp_forum_title() To output the topic's forum title
614 * @uses apply_filters() Calls 'topic_forum_row_actions' with an array
615 * of topic forum actions
616 * @uses bbp_get_forum_permalink() To get the forum permalink
617 * @uses admin_url() To get the admin url of post.php
618 * @uses add_query_arg() To add custom args to the url
619 * @uses bbp_topic_reply_count() To output the topic reply count
620 * @uses bbp_topic_voice_count() To output the topic voice count
621 * @uses bbp_topic_author_display_name() To output the topic author name
622 * @uses get_the_date() Get the topic creation date
623 * @uses get_the_time() Get the topic creation time
624 * @uses esc_attr() To sanitize the topic creation time
625 * @uses bbp_get_topic_last_active_time() To get the time when the topic was
626 * last active
627 * @uses do_action() Calls 'bbp_admin_topics_column_data' with the
628 * column and topic id
629 */
630 function topics_column_data( $column, $topic_id ) {
631
632 // Get topic forum ID
633 $forum_id = bbp_get_topic_forum_id( $topic_id );
634
635 // Populate column data
636 switch ( $column ) {
637
638 // Forum
639 case 'bbp_topic_forum' :
640
641 // Output forum name
642 if ( !empty( $forum_id ) ) {
643 bbp_forum_title( $forum_id );
644
645 // Link information
646 $actions = apply_filters( 'topic_forum_row_actions', array (
647 'edit' => '<a href="' . add_query_arg( array( 'post' => $forum_id, 'action' => 'edit' ), admin_url( '/post.php' ) ) . '">' . __( 'Edit', 'bbpress' ) . '</a>',
648 'view' => '<a href="' . bbp_get_forum_permalink( $forum_id ) . '">' . __( 'View', 'bbpress' ) . '</a>'
649 ) );
650
651 // Output forum post row links
652 foreach ( $actions as $action => $link )
653 $formatted_actions[] = '<span class="' . $action . '">' . $link . '</span>';
654
655 echo '<div class="row-actions">' . implode( ' | ', $formatted_actions ) . '</div>';
656 } else {
657 _e( '(No Forum)', 'bbpress' );
658 }
659
660 break;
661
662 // Reply Count
663 case 'bbp_topic_reply_count' :
664 bbp_topic_reply_count( $topic_id );
665 break;
666
667 // Reply Count
668 case 'bbp_topic_voice_count' :
669 bbp_topic_voice_count( $topic_id );
670 break;
671
672 // Author
673 case 'bbp_topic_author' :
674 bbp_topic_author_display_name( $topic_id );
675 break;
676
677 // Freshness
678 case 'bbp_topic_created':
679 printf( __( '%1$s <br /> %2$s', 'bbpress' ),
680 get_the_date(),
681 esc_attr( get_the_time() )
682 );
683
684 break;
685
686 // Freshness
687 case 'bbp_topic_freshness' :
688 if ( $last_active = bbp_get_topic_last_active_time( $topic_id, false ) )
689 printf( __( '%s ago', 'bbpress' ), $last_active );
690 else
691 _e( 'No Replies', 'bbpress' ); // This should never happen
692
693 break;
694
695 // Do an action for anything else
696 default :
697 do_action( 'bbp_admin_topics_column_data', $column, $topic_id );
698 break;
699 }
700 }
701
702 /**
703 * Topic Row actions
704 *
705 * Remove the quick-edit action link under the topic title and add the
706 * content and close/stick/spam links
707 *
708 * @since bbPress (r2485)
709 *
710 * @param array $actions Actions
711 * @param array $topic Topic object
712 * @uses bbp_get_topic_post_type() To get the topic post type
713 * @uses bbp_topic_content() To output topic content
714 * @uses bbp_get_topic_permalink() To get the topic link
715 * @uses bbp_get_topic_title() To get the topic title
716 * @uses current_user_can() To check if the current user can edit or
717 * delete the topic
718 * @uses bbp_is_topic_open() To check if the topic is open
719 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
720 * @uses bbp_is_topic_sticky() To check if the topic is a sticky or a
721 * super sticky
722 * @uses get_post_type_object() To get the topic post type object
723 * @uses add_query_arg() To add custom args to the url
724 * @uses remove_query_arg() To remove custom args from the url
725 * @uses wp_nonce_url() To nonce the url
726 * @uses get_delete_post_link() To get the delete post link of the topic
727 * @return array $actions Actions
728 */
729 function topics_row_actions( $actions, $topic ) {
730 global $bbp;
731
732 if ( $topic->post_type == $this->post_type ) {
733 unset( $actions['inline hide-if-no-js'] );
734
735 bbp_topic_content( $topic->ID );
736
737 // Show view link if it's not set, the topic is trashed and the user can view trashed topics
738 if ( empty( $actions['view'] ) && 'trash' == $topic->post_status && current_user_can( 'view_trash' ) )
739 $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>';
740
741 // Only show the actions if the user is capable of viewing them :)
742 if ( current_user_can( 'moderate', $topic->ID ) ) {
743
744 // Close
745 // Show the 'close' and 'open' link on published and closed posts only
746 if ( in_array( $topic->post_status, array( 'publish', $bbp->closed_status_id ) ) ) {
747 $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 ) );
748 if ( bbp_is_topic_open( $topic->ID ) )
749 $actions['closed'] = '<a href="' . $close_uri . '" title="' . esc_attr__( 'Close this topic', 'bbpress' ) . '">' . __( 'Close', 'bbpress' ) . '</a>';
750 else
751 $actions['closed'] = '<a href="' . $close_uri . '" title="' . esc_attr__( 'Open this topic', 'bbpress' ) . '">' . __( 'Open', 'bbpress' ) . '</a>';
752 }
753
754 // Sticky
755 $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 ) );
756 if ( bbp_is_topic_sticky( $topic->ID ) ) {
757 $actions['stick'] = '<a href="' . $stick_uri . '" title="' . esc_attr__( 'Unstick this topic', 'bbpress' ) . '">' . __( 'Unstick', 'bbpress' ) . '</a>';
758 } else {
759 $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 ) );
760 $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>)';
761 }
762
763 // Spam
764 $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 ) );
765 if ( bbp_is_topic_spam( $topic->ID ) )
766 $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the topic as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>';
767 else
768 $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this topic as spam', 'bbpress' ) . '">' . __( 'Spam', 'bbpress' ) . '</a>';
769
770 }
771
772 // Do not show trash links for spam topics, or spam links for trashed topics
773 if ( current_user_can( 'delete_topic', $topic->ID ) ) {
774 if ( $bbp->trash_status_id == $topic->post_status ) {
775 $post_type_object = get_post_type_object( bbp_get_topic_post_type() );
776 $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>";
777 } elseif ( EMPTY_TRASH_DAYS ) {
778 $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>";
779 }
780
781 if ( $bbp->trash_status_id == $topic->post_status || !EMPTY_TRASH_DAYS ) {
782 $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>";
783 } elseif ( $bbp->spam_status_id == $topic->post_status ) {
784 unset( $actions['trash'] );
785 }
786 }
787 }
788
789 return $actions;
790 }
791
792 /**
793 * Add forum dropdown to topic and reply list table filters
794 *
795 * @since bbPress (r2991)
796 *
797 * @uses bbp_get_reply_post_type() To get the reply post type
798 * @uses bbp_get_topic_post_type() To get the topic post type
799 * @uses bbp_dropdown() To generate a forum dropdown
800 * @return bool False. If post type is not topic or reply
801 */
802 function filter_dropdown() {
803
804 // Bail if not viewing the topics list
805 if (
806 // post_type exists in _GET
807 empty( $_GET['post_type'] ) ||
808
809 // post_type is not topic type
810 ( $_GET['post_type'] != $this->post_type )
811 )
812 return;
813
814 // Get which forum is selected
815 $selected = !empty( $_GET['bbp_forum_id'] ) ? $_GET['bbp_forum_id'] : '';
816
817 // Show the forums dropdown
818 bbp_dropdown( array(
819 'selected' => $selected,
820 'show_none' => __( 'In all forums', 'bbpress' )
821 ) );
822 }
823
824 /**
825 * Adjust the request query and include the forum id
826 *
827 * @since bbPress (r2991)
828 *
829 * @param array $query_vars Query variables from {@link WP_Query}
830 * @uses is_admin() To check if it's the admin section
831 * @uses bbp_get_topic_post_type() To get the topic post type
832 * @uses bbp_get_reply_post_type() To get the reply post type
833 * @return array Processed Query Vars
834 */
835 function filter_post_rows( $query_vars ) {
836 global $pagenow;
837
838 // Avoid poisoning other requests
839 if (
840 // Only look in admin
841 !is_admin() ||
842
843 // Make sure the current page is for post rows
844 ( 'edit.php' != $pagenow ) ||
845
846 // Make sure we're looking for a post_type
847 empty( $_GET['post_type'] ) ||
848
849 // Make sure we're looking at bbPress topics
850 ( $_GET['post_type'] != $this->post_type )
851 )
852
853 // We're in no shape to filter anything, so return
854 return $query_vars;
855
856 // Add post_parent query_var if one is present
857 if ( !empty( $_GET['bbp_forum_id'] ) ) {
858 $query_vars['meta_key'] = '_bbp_forum_id';
859 $query_vars['meta_value'] = $_GET['bbp_forum_id'];
860 }
861
862 // Return manipulated query_vars
863 return $query_vars;
864 }
865
866 /**
867 * Custom user feedback messages for topic post type
868 *
869 * @since bbPress (r3080)
870 *
871 * @global WP_Query $post
872 * @global int $post_ID
873 * @uses get_post_type()
874 * @uses bbp_get_topic_permalink()
875 * @uses wp_post_revision_title()
876 * @uses esc_url()
877 * @uses add_query_arg()
878 *
879 * @param array $messages
880 *
881 * @return array
882 */
883 function updated_messages( $messages ) {
884 global $post, $post_ID;
885
886 if ( get_post_type( $post_ID ) != $this->post_type )
887 return $messages;
888
889 // URL for the current topic
890 $topic_url = bbp_get_topic_permalink( $post_ID );
891
892 // Messages array
893 $messages[$this->post_type] = array(
894 0 => '', // Left empty on purpose
895
896 // Updated
897 1 => sprintf( __( 'Topic updated. <a href="%s">View topic</a>' ), $topic_url ),
898
899 // Custom field updated
900 2 => __( 'Custom field updated.', 'bbpress' ),
901
902 // Custom field deleted
903 3 => __( 'Custom field deleted.', 'bbpress' ),
904
905 // Topic updated
906 4 => __( 'Topic updated.', 'bbpress' ),
907
908 // Restored from revision
909 // translators: %s: date and time of the revision
910 5 => isset( $_GET['revision'] )
911 ? sprintf( __( 'Topic restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
912 : false,
913
914 // Topic created
915 6 => sprintf( __( 'Topic created. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
916
917 // Topic saved
918 7 => __( 'Topic saved.', 'bbpress' ),
919
920 // Topic submitted
921 8 => sprintf( __( 'Topic submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
922
923 // Topic scheduled
924 9 => sprintf( __( 'Topic scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress' ),
925 // translators: Publish box date format, see http://php.net/date
926 date_i18n( __( 'M j, Y @ G:i' ),
927 strtotime( $post->post_date ) ),
928 $topic_url ),
929
930 // Topic draft updated
931 10 => sprintf( __( 'Topic draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
932 );
933
934 return $messages;
935 }
936 }
937 endif; // class_exists check
938
939 /**
940 * Setup bbPress Topics Admin
941 *
942 * @since bbPress (r2596)
943 *
944 * @uses BBP_Forums_Admin
945 */
946 function bbp_topics_admin() {
947 global $bbp;
948
949 $bbp->admin->topics = new BBP_Topics_Admin();
950 }
951
952 ?>
953