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

559 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
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 // Visibility
251 if ( !empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array( 'publish', 'private', 'hidden' ) ) ) {
252
253 // Get forums current visibility
254 $visibility = bbp_get_forum_visibility( $forum_id );
255
256 // If new visibility is different, change it
257 if ( $visibility != $_POST['bbp_forum_visibility'] ) {
258
259 // What is the new forum visibility setting?
260 switch ( $_POST['bbp_forum_visibility'] ) {
261
262 // Hidden
263 case 'hidden' :
264 bbp_hide_forum( $forum_id, $visibility );
265 break;
266
267 // Private
268 case 'private' :
269 bbp_privatize_forum( $forum_id, $visibility );
270 break;
271
272 // Publish (default)
273 case 'publish' :
274 default :
275 bbp_publicize_forum( $forum_id, $visibility );
276 break;
277 }
278 }
279 }
280
281 // Parent ID
282 $parent_id = ( !empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) ? $_POST['parent_id'] : 0;
283
284 // Update the forum meta bidness
285 bbp_update_forum( array(
286 'forum_id' => $forum_id,
287 'post_parent' => (int) $parent_id
288 ) );
289
290 do_action( 'bbp_forum_attributes_metabox_save', $forum_id );
291
292 return $forum_id;
293 }
294
295 /**
296 * Add some general styling to the admin area
297 *
298 * @since bbPress (r2464)
299 *
300 * @uses bbp_get_forum_post_type() To get the forum post type
301 * @uses bbp_get_topic_post_type() To get the topic post type
302 * @uses bbp_get_reply_post_type() To get the reply post type
303 * @uses sanitize_html_class() To sanitize the classes
304 * @uses do_action() Calls 'bbp_admin_head'
305 */
306 function admin_head() {
307
308 if ( get_post_type() == $this->post_type ) : ?>
309
310 <style type="text/css" media="screen">
311 /*<![CDATA[*/
312
313 #misc-publishing-actions,
314 #save-post {
315 display: none;
316 }
317
318 strong.label {
319 display: inline-block;
320 width: 60px;
321 }
322
323 #bbp_forum_attributes hr {
324 border-style: solid;
325 border-width: 1px;
326 border-color: #ccc #fff #fff #ccc;
327 }
328
329 .column-bbp_forum_topic_count,
330 .column-bbp_forum_reply_count,
331 .column-bbp_topic_reply_count,
332 .column-bbp_topic_voice_count {
333 width: 8% !important;
334 }
335
336 .column-author,
337 .column-bbp_reply_author,
338 .column-bbp_topic_author {
339 width: 10% !important;
340 }
341
342 .column-bbp_topic_forum,
343 .column-bbp_reply_forum,
344 .column-bbp_reply_topic {
345 width: 10% !important;
346 }
347
348 .column-bbp_forum_freshness,
349 .column-bbp_topic_freshness {
350 width: 10% !important;
351 }
352
353 .column-bbp_forum_created,
354 .column-bbp_topic_created,
355 .column-bbp_reply_created {
356 width: 15% !important;
357 }
358
359 .status-closed {
360 background-color: #eaeaea;
361 }
362
363 .status-spam {
364 background-color: #faeaea;
365 }
366
367 /*]]>*/
368 </style>
369
370 <?php endif; ?>
371
372 <?php
373 }
374
375 /**
376 * Manage the column headers for the forums page
377 *
378 * @since bbPress (r2485)
379 *
380 * @param array $columns The columns
381 * @uses apply_filters() Calls 'bbp_admin_forums_column_headers' with
382 * the columns
383 * @return array $columns bbPress forum columns
384 */
385 function column_headers( $columns ) {
386 $columns = array (
387 'cb' => '<input type="checkbox" />',
388 'title' => __( 'Forum', 'bbpress' ),
389 'bbp_forum_topic_count' => __( 'Topics', 'bbpress' ),
390 'bbp_forum_reply_count' => __( 'Replies', 'bbpress' ),
391 'author' => __( 'Creator', 'bbpress' ),
392 'bbp_forum_created' => __( 'Created' , 'bbpress' ),
393 'bbp_forum_freshness' => __( 'Freshness', 'bbpress' )
394 );
395
396 return apply_filters( 'bbp_admin_forums_column_headers', $columns );
397 }
398
399 /**
400 * Print extra columns for the forums page
401 *
402 * @since bbPress (r2485)
403 *
404 * @param string $column Column
405 * @param int $forum_id Forum id
406 * @uses bbp_forum_topic_count() To output the forum topic count
407 * @uses bbp_forum_reply_count() To output the forum reply count
408 * @uses get_the_date() Get the forum creation date
409 * @uses get_the_time() Get the forum creation time
410 * @uses esc_attr() To sanitize the forum creation time
411 * @uses bbp_get_forum_last_active_time() To get the time when the forum was
412 * last active
413 * @uses do_action() Calls 'bbp_admin_forums_column_data' with the
414 * column and forum id
415 */
416 function column_data( $column, $forum_id ) {
417 switch ( $column ) {
418 case 'bbp_forum_topic_count' :
419 bbp_forum_topic_count( $forum_id );
420 break;
421
422 case 'bbp_forum_reply_count' :
423 bbp_forum_reply_count( $forum_id );
424 break;
425
426 case 'bbp_forum_created':
427 printf( __( '%1$s <br /> %2$s', 'bbpress' ),
428 get_the_date(),
429 esc_attr( get_the_time() )
430 );
431
432 break;
433
434 case 'bbp_forum_freshness' :
435 if ( $last_active = bbp_get_forum_last_active_time( $forum_id, false ) )
436 printf( __( '%s ago', 'bbpress' ), $last_active );
437 else
438 _e( 'No Topics', 'bbpress' );
439
440 break;
441
442 default:
443 do_action( 'bbp_admin_forums_column_data', $column, $forum_id );
444 break;
445 }
446 }
447
448 /**
449 * Forum Row actions
450 *
451 * Remove the quick-edit action link and display the description under
452 * the forum title
453 *
454 * @since bbPress (r2577)
455 *
456 * @param array $actions Actions
457 * @param array $forum Forum object
458 * @uses the_content() To output forum description
459 * @return array $actions Actions
460 */
461 function row_actions( $actions, $forum ) {
462 if ( $forum->post_type == $this->post_type ) {
463 unset( $actions['inline hide-if-no-js'] );
464
465 // simple hack to show the forum description under the title
466 bbp_forum_content( $forum->ID );
467 }
468
469 return $actions;
470 }
471
472 /**
473 * Custom user feedback messages for forum post type
474 *
475 * @since bbPress (r3080)
476 *
477 * @global WP_Query $post
478 * @global int $post_ID
479 * @uses get_post_type()
480 * @uses bbp_get_forum_permalink()
481 * @uses wp_post_revision_title()
482 * @uses esc_url()
483 * @uses add_query_arg()
484 *
485 * @param array $messages
486 *
487 * @return array
488 */
489 function updated_messages( $messages ) {
490 global $post, $post_ID;
491
492 if ( get_post_type( $post_ID ) != $this->post_type )
493 return $messages;
494
495 // URL for the current forum
496 $forum_url = bbp_get_forum_permalink( $post_ID );
497
498 // Messages array
499 $messages[$this->post_type] = array(
500 0 => '', // Left empty on purpose
501
502 // Updated
503 1 => sprintf( __( 'Forum updated. <a href="%s">View forum</a>' ), $forum_url ),
504
505 // Custom field updated
506 2 => __( 'Custom field updated.', 'bbpress' ),
507
508 // Custom field deleted
509 3 => __( 'Custom field deleted.', 'bbpress' ),
510
511 // Forum updated
512 4 => __( 'Forum updated.', 'bbpress' ),
513
514 // Restored from revision
515 // translators: %s: date and time of the revision
516 5 => isset( $_GET['revision'] )
517 ? sprintf( __( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
518 : false,
519
520 // Forum created
521 6 => sprintf( __( 'Forum created. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ),
522
523 // Forum saved
524 7 => __( 'Forum saved.', 'bbpress' ),
525
526 // Forum submitted
527 8 => sprintf( __( 'Forum submitted. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ),
528
529 // Forum scheduled
530 9 => sprintf( __( 'Forum scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview forum</a>', 'bbpress' ),
531 // translators: Publish box date format, see http://php.net/date
532 date_i18n( __( 'M j, Y @ G:i' ),
533 strtotime( $post->post_date ) ),
534 $forum_url ),
535
536 // Forum draft updated
537 10 => sprintf( __( 'Forum draft updated. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ),
538 );
539
540 return $messages;
541 }
542 }
543 endif; // class_exists check
544
545 /**
546 * Setup bbPress Forums Admin
547 *
548 * @since bbPress (r2596)
549 *
550 * @uses BBP_Forums_Admin
551 */
552 function bbp_admin_forums() {
553 global $bbp;
554
555 $bbp->admin->forums = new BBP_Forums_Admin();
556 }
557
558 ?>
559