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

bbp-forums.php in bbPress 2.0-beta-2b, at bbp-admin/bbp-forums.php

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