PluginProbe
bbPress / 2.0.1
bbPress v2.0.1
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / bbp-admin / bbp-forums.php

bbp-forums.php in bbPress 2.0.1, at bbp-admin/bbp-forums.php

563 lines 19.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Forum 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_Forums_Admin' ) ) :
14 /**
15 * Loads bbPress forums admin area
16 *
17 * @package bbPress
18 * @subpackage Administration
19 * @since bbPress (r2464)
20 */
21 class BBP_Forums_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 forums admin loader
34 *
35 * @since bbPress (r2515)
36 *
37 * @uses BBP_Forums_Admin::setup_globals() Setup the globals needed
38 * @uses BBP_Forums_Admin::setup_actions() Setup the hooks and actions
39 * @uses BBP_Forums_Admin::setup_help() Setup the help text
40 */
41 function __construct() {
42 $this->setup_globals();
43 $this->setup_actions();
44 $this->setup_help();
45 }
46
47 /**
48 * Setup the admin hooks, actions and filters
49 *
50 * @since bbPress (r2646)
51 * @access private
52 *
53 * @uses add_action() To add various actions
54 * @uses add_filter() To add various filters
55 * @uses bbp_get_forum_post_type() To get the forum post type
56 * @uses bbp_get_topic_post_type() To get the topic post type
57 * @uses bbp_get_reply_post_type() To get the reply post type
58 */
59 function setup_actions() {
60
61 // Add some general styling to the admin area
62 add_action( 'admin_head', array( $this, 'admin_head' ) );
63
64 // Messages
65 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
66
67 // Metabox actions
68 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) );
69 add_action( 'save_post', array( $this, 'attributes_metabox_save' ) );
70
71 // Column headers.
72 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) );
73
74 // Columns (in page row)
75 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 );
76 add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
77 }
78
79 /**
80 * Admin globals
81 *
82 * @since bbPress (r2646)
83 * @access private
84 */
85 function setup_globals() {
86
87 // Setup the post type for this admin component
88 $this->post_type = bbp_get_forum_post_type();
89 }
90
91 /**
92 * Contextual help for forums
93 *
94 * @since bbPress (r3119)
95 * @access private
96 */
97 function setup_help() {
98
99 // Define local variable(s)
100 $contextual_help = array();
101
102 /** New/Edit **********************************************************/
103
104 $bbp_contextual_help[] = __( 'The forum title field and the big forum 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 (like Slug) or to choose a 1- or 2-column layout for this screen.', 'bbpress' );
105 $bbp_contextual_help[] = __( '<strong>Title</strong> - Enter a title for your forum. After you enter a title, you will see the permalink appear below it, which is fully editable.', 'bbpress' );
106 $bbp_contextual_help[] = __( '<strong>Post editor</strong> - Enter the description for your forum. 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' );
107 $bbp_contextual_help[] = __( '<strong>Forum Attributes</strong> - Select the various attributes that your forum should have:', 'bbpress' );
108 $bbp_contextual_help[] =
109 '<ul>' .
110 '<li>' . __( 'Forum Type determines whether it is a Forum (by default) or a Category, which means no new topics (only other forums) can be created within it.', 'bbpress' ) . '</li>' .
111 '<li>' . __( 'Forum Status controls whether it is open (and thus can be posted to) or closed (thus not able to be posted to).', 'bbpress' ) . '</li>' .
112 '<li>' . __( 'Visibility can be set to either Public (by default, seen by everyone), Private (seen only by chosen users), and Hidden (hidden from all users).', 'bbpress' ) . '</li>' .
113 '<li>' . __( 'Parent turns the forum into a child forum of the selected forum/category in the dropdown.', 'bbpress' ) . '</li>' .
114 '<li>' . __( 'Order determines the order that forums in the given hierarchy are displayed (lower numbers first, higher numbers last).', 'bbpress' ) . '</li>' .
115 '</ul>';
116
117 $bbp_contextual_help[] = __( '<strong>Publish</strong> - The Publish box will allow you to Preview your forum before it is published, Publish your forum to your site, or Move to Trash will move your forum to the trash.', 'bbpress' );
118 $bbp_contextual_help[] = __( '<strong>Revisions</strong> - Revisions show past versions of the saved forum. Each revision can be compared to the current version, or another revision. Revisions can also be restored to the current version.', 'bbpress' );
119 $bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' );
120 $bbp_contextual_help[] =
121 '<ul>' .
122 '<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' .
123 '<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>', 'bbpress' ) . '</li>' .
124 '</ul>';
125
126 // Wrap each help item in paragraph tags
127 foreach( $bbp_contextual_help as $paragraph )
128 $contextual_help .= '<p>' . $paragraph . '</p>';
129
130 // Add help
131 add_contextual_help( bbp_get_forum_post_type(), $contextual_help );
132
133 // Reset
134 $contextual_help = $bbp_contextual_help = '';
135
136 /** Post Rows *********************************************************/
137
138 $bbp_contextual_help[] = __( 'This screen displays the forums available on your site.', 'bbpress' );
139 $bbp_contextual_help[] = __( 'You can customize the display of this screen in a number of ways:', 'bbpress' );
140 $bbp_contextual_help[] =
141 '<ul>' .
142 '<li>' . __( 'You can hide/display columns based on your needs and decide how many forums to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' .
143 '<li>' . __( 'You can filter the list of forums by forum status using the text links in the upper left to show All, Published, or Trashed forums. The default view is to show all forums.', 'bbpress' ) . '</li>' .
144 '<li>' . __( 'You can refine the list to show only forums from a specific month by using the dropdown menus above the forums list. Click the Filter button after making your selection. You also can refine the list by clicking on the forum creator in the forums list.', 'bbpress' ) . '</li>' .
145 '</ul>';
146
147 $bbp_contextual_help[] = __( 'Hovering over a row in the forums list will display action links that allow you to manage your forum. You can perform the following actions:', 'bbpress' );
148 $bbp_contextual_help[] =
149 '<ul>' .
150 '<li>' . __( 'Edit takes you to the editing screen for that forum. You can also reach that screen by clicking on the forum title.', 'bbpress' ) . '</li>' .
151 '<li>' . __( 'Trash removes your forum from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
152 '<li>' . __( 'View will take you to your live forum to view the forum.', 'bbpress' ) . '</li>' .
153 '</ul>';
154
155 $bbp_contextual_help[] = __( 'You can also edit multiple forums at once. Select the forums 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 forums at once. To remove a forum from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' );
156 $bbp_contextual_help[] = __( 'The Bulk Actions menu may also be used to delete multiple forums at once. Select Delete from the dropdown after making your selection.', 'bbpress' );
157 $bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' );
158 $bbp_contextual_help[] =
159 '<ul>' .
160 '<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' .
161 '<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>', 'bbpress' ) . '</li>' .
162 '</ul>';
163
164 // Wrap each help item in paragraph tags
165 foreach( $bbp_contextual_help as $paragraph )
166 $contextual_help .= '<p>' . $paragraph . '</p>';
167
168 // Add help
169 add_contextual_help( 'edit-' . bbp_get_forum_post_type(), $contextual_help );
170 }
171
172 /**
173 * Add the forum attributes metabox
174 *
175 * @since bbPress (r2746)
176 *
177 * @uses bbp_get_forum_post_type() To get the forum post type
178 * @uses add_meta_box() To add the metabox
179 * @uses do_action() Calls 'bbp_forum_attributes_metabox'
180 */
181 function attributes_metabox() {
182 add_meta_box (
183 'bbp_forum_attributes',
184 __( 'Forum Attributes', 'bbpress' ),
185 'bbp_forum_metabox',
186 $this->post_type,
187 'side',
188 'high'
189 );
190
191 do_action( 'bbp_forum_attributes_metabox' );
192 }
193
194 /**
195 * Pass the forum attributes for processing
196 *
197 * @since bbPress (r2746)
198 *
199 * @param int $forum_id Forum id
200 * @uses current_user_can() To check if the current user is capable of
201 * editing the forum
202 * @uses bbp_get_forum() To get the forum
203 * @uses bbp_is_forum_closed() To check if the forum is closed
204 * @uses bbp_is_forum_category() To check if the forum is a category
205 * @uses bbp_is_forum_private() To check if the forum is private
206 * @uses bbp_close_forum() To close the forum
207 * @uses bbp_open_forum() To open the forum
208 * @uses bbp_categorize_forum() To make the forum a category
209 * @uses bbp_normalize_forum() To make the forum normal (not category)
210 * @uses bbp_privatize_forum() To mark the forum as private
211 * @uses bbp_publicize_forum() To mark the forum as public
212 * @uses do_action() Calls 'bbp_forum_attributes_metabox_save' with the
213 * forum id
214 * @return int Forum id
215 */
216 function attributes_metabox_save( $forum_id ) {
217
218 // Bail if doing an autosave
219 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
220 return $forum_id;
221
222 // Bail if not a post request
223 if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
224 return $forum_id;
225
226 // Bail if current user cannot edit this forum
227 if ( !current_user_can( 'edit_forum', $forum_id ) )
228 return $forum_id;
229
230 // Load the forum
231 if ( !$forum = bbp_get_forum( $forum_id ) )
232 return $forum_id;
233
234 // Closed?
235 if ( !empty( $_POST['bbp_forum_status'] ) && in_array( $_POST['bbp_forum_status'], array( 'open', 'closed' ) ) ) {
236 if ( 'closed' == $_POST['bbp_forum_status'] && !bbp_is_forum_closed( $forum_id, false ) )
237 bbp_close_forum( $forum_id );
238 elseif ( 'open' == $_POST['bbp_forum_status'] && bbp_is_forum_closed( $forum_id, false ) )
239 bbp_open_forum( $forum_id );
240 }
241
242 // Category?
243 if ( !empty( $_POST['bbp_forum_type'] ) && in_array( $_POST['bbp_forum_type'], array( 'forum', 'category' ) ) ) {
244 if ( 'category' == $_POST['bbp_forum_type'] && !bbp_is_forum_category( $forum_id ) ) {
245 bbp_categorize_forum( $forum_id );
246 } elseif ( 'forum' == $_POST['bbp_forum_type'] && bbp_is_forum_category( $forum_id ) ) {
247 bbp_normalize_forum( $forum_id );
248 }
249 }
250
251 // Visibility
252 if ( !empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() ) ) ) {
253
254 // Get forums current visibility
255 $visibility = bbp_get_forum_visibility( $forum_id );
256
257 // If new visibility is different, change it
258 if ( $visibility != $_POST['bbp_forum_visibility'] ) {
259
260 // What is the new forum visibility setting?
261 switch ( $_POST['bbp_forum_visibility'] ) {
262
263 // Hidden
264 case bbp_get_hidden_status_id() :
265 bbp_hide_forum( $forum_id, $visibility );
266 break;
267
268 // Private
269 case bbp_get_private_status_id() :
270 bbp_privatize_forum( $forum_id, $visibility );
271 break;
272
273 // Publish (default)
274 case bbp_get_public_status_id() :
275 default :
276 bbp_publicize_forum( $forum_id, $visibility );
277 break;
278 }
279 }
280 }
281
282 // Parent ID
283 $parent_id = ( !empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) ? $_POST['parent_id'] : 0;
284
285 // Update the forum meta bidness
286 bbp_update_forum( array(
287 'forum_id' => $forum_id,
288 'post_parent' => (int) $parent_id
289 ) );
290
291 do_action( 'bbp_forum_attributes_metabox_save', $forum_id );
292
293 return $forum_id;
294 }
295
296 /**
297 * Add some general styling to the admin area
298 *
299 * @since bbPress (r2464)
300 *
301 * @uses bbp_get_forum_post_type() To get the forum post type
302 * @uses bbp_get_topic_post_type() To get the topic post type
303 * @uses bbp_get_reply_post_type() To get the reply post type
304 * @uses sanitize_html_class() To sanitize the classes
305 * @uses do_action() Calls 'bbp_admin_head'
306 */
307 function admin_head() {
308
309 if ( get_post_type() == $this->post_type ) : ?>
310
311 <style type="text/css" media="screen">
312 /*<![CDATA[*/
313
314 #misc-publishing-actions,
315 #save-post {
316 display: none;
317 }
318
319 strong.label {
320 display: inline-block;
321 width: 60px;
322 }
323
324 #bbp_forum_attributes hr {
325 border-style: solid;
326 border-width: 1px;
327 border-color: #ccc #fff #fff #ccc;
328 }
329
330 .column-bbp_forum_topic_count,
331 .column-bbp_forum_reply_count,
332 .column-bbp_topic_reply_count,
333 .column-bbp_topic_voice_count {
334 width: 8% !important;
335 }
336
337 .column-author,
338 .column-bbp_reply_author,
339 .column-bbp_topic_author {
340 width: 10% !important;
341 }
342
343 .column-bbp_topic_forum,
344 .column-bbp_reply_forum,
345 .column-bbp_reply_topic {
346 width: 10% !important;
347 }
348
349 .column-bbp_forum_freshness,
350 .column-bbp_topic_freshness {
351 width: 10% !important;
352 }
353
354 .column-bbp_forum_created,
355 .column-bbp_topic_created,
356 .column-bbp_reply_created {
357 width: 15% !important;
358 }
359
360 .status-closed {
361 background-color: #eaeaea;
362 }
363
364 .status-spam {
365 background-color: #faeaea;
366 }
367
368 /*]]>*/
369 </style>
370
371 <?php endif; ?>
372
373 <?php
374 }
375
376 /**
377 * Manage the column headers for the forums page
378 *
379 * @since bbPress (r2485)
380 *
381 * @param array $columns The columns
382 * @uses apply_filters() Calls 'bbp_admin_forums_column_headers' with
383 * the columns
384 * @return array $columns bbPress forum columns
385 */
386 function column_headers( $columns ) {
387 $columns = array (
388 'cb' => '<input type="checkbox" />',
389 'title' => __( 'Forum', 'bbpress' ),
390 'bbp_forum_topic_count' => __( 'Topics', 'bbpress' ),
391 'bbp_forum_reply_count' => __( 'Replies', 'bbpress' ),
392 'author' => __( 'Creator', 'bbpress' ),
393 'bbp_forum_created' => __( 'Created' , 'bbpress' ),
394 'bbp_forum_freshness' => __( 'Freshness', 'bbpress' )
395 );
396
397 return apply_filters( 'bbp_admin_forums_column_headers', $columns );
398 }
399
400 /**
401 * Print extra columns for the forums page
402 *
403 * @since bbPress (r2485)
404 *
405 * @param string $column Column
406 * @param int $forum_id Forum id
407 * @uses bbp_forum_topic_count() To output the forum topic count
408 * @uses bbp_forum_reply_count() To output the forum reply count
409 * @uses get_the_date() Get the forum creation date
410 * @uses get_the_time() Get the forum creation time
411 * @uses esc_attr() To sanitize the forum creation time
412 * @uses bbp_get_forum_last_active_time() To get the time when the forum was
413 * last active
414 * @uses do_action() Calls 'bbp_admin_forums_column_data' with the
415 * column and forum id
416 */
417 function column_data( $column, $forum_id ) {
418 switch ( $column ) {
419 case 'bbp_forum_topic_count' :
420 bbp_forum_topic_count( $forum_id );
421 break;
422
423 case 'bbp_forum_reply_count' :
424 bbp_forum_reply_count( $forum_id );
425 break;
426
427 case 'bbp_forum_created':
428 printf( __( '%1$s <br /> %2$s', 'bbpress' ),
429 get_the_date(),
430 esc_attr( get_the_time() )
431 );
432
433 break;
434
435 case 'bbp_forum_freshness' :
436 if ( $last_active = bbp_get_forum_last_active_time( $forum_id, false ) )
437 printf( __( '%s ago', 'bbpress' ), $last_active );
438 else
439 _e( 'No Topics', 'bbpress' );
440
441 break;
442
443 default:
444 do_action( 'bbp_admin_forums_column_data', $column, $forum_id );
445 break;
446 }
447 }
448
449 /**
450 * Forum Row actions
451 *
452 * Remove the quick-edit action link and display the description under
453 * the forum title
454 *
455 * @since bbPress (r2577)
456 *
457 * @param array $actions Actions
458 * @param array $forum Forum object
459 * @uses the_content() To output forum description
460 * @return array $actions Actions
461 */
462 function row_actions( $actions, $forum ) {
463 if ( $forum->post_type == $this->post_type ) {
464 unset( $actions['inline hide-if-no-js'] );
465
466 // simple hack to show the forum description under the title
467 bbp_forum_content( $forum->ID );
468 }
469
470 return $actions;
471 }
472
473 /**
474 * Custom user feedback messages for forum post type
475 *
476 * @since bbPress (r3080)
477 *
478 * @global WP_Query $post
479 * @global int $post_ID
480 * @uses get_post_type()
481 * @uses bbp_get_forum_permalink()
482 * @uses wp_post_revision_title()
483 * @uses esc_url()
484 * @uses add_query_arg()
485 *
486 * @param array $messages
487 *
488 * @return array
489 */
490 function updated_messages( $messages ) {
491 global $post, $post_ID;
492
493 if ( get_post_type( $post_ID ) != $this->post_type )
494 return $messages;
495
496 // URL for the current forum
497 $forum_url = bbp_get_forum_permalink( $post_ID );
498
499 // Messages array
500 $messages[$this->post_type] = array(
501 0 => '', // Left empty on purpose
502
503 // Updated
504 1 => sprintf( __( 'Forum updated. <a href="%s">View forum</a>' ), $forum_url ),
505
506 // Custom field updated
507 2 => __( 'Custom field updated.', 'bbpress' ),
508
509 // Custom field deleted
510 3 => __( 'Custom field deleted.', 'bbpress' ),
511
512 // Forum updated
513 4 => __( 'Forum updated.', 'bbpress' ),
514
515 // Restored from revision
516 // translators: %s: date and time of the revision
517 5 => isset( $_GET['revision'] )
518 ? sprintf( __( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
519 : false,
520
521 // Forum created
522 6 => sprintf( __( 'Forum created. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ),
523
524 // Forum saved
525 7 => __( 'Forum saved.', 'bbpress' ),
526
527 // Forum submitted
528 8 => sprintf( __( 'Forum submitted. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ),
529
530 // Forum scheduled
531 9 => sprintf( __( 'Forum scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview forum</a>', 'bbpress' ),
532 // translators: Publish box date format, see http://php.net/date
533 date_i18n( __( 'M j, Y @ G:i' ),
534 strtotime( $post->post_date ) ),
535 $forum_url ),
536
537 // Forum draft updated
538 10 => sprintf( __( 'Forum draft updated. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ),
539 );
540
541 return $messages;
542 }
543 }
544 endif; // class_exists check
545
546 /**
547 * Setup bbPress Forums Admin
548 *
549 * @since bbPress (r2596)
550 *
551 * @uses BBP_Forums_Admin
552 */
553 function bbp_admin_forums() {
554 global $bbp;
555
556 // Bail if bbPress is not loaded
557 if ( 'bbPress' !== get_class( $bbp ) ) return;
558
559 $bbp->admin->forums = new BBP_Forums_Admin();
560 }
561
562 ?>
563