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

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