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

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