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

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

664 lines 21.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Main bbPress 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_Admin' ) ) :
14 /**
15 * Loads bbPress plugin admin area
16 *
17 * @package bbPress
18 * @subpackage Administration
19 * @since bbPress (r2464)
20 */
21 class BBP_Admin {
22
23 /** URLs ******************************************************************/
24
25 /**
26 * @var string URL to the bbPress images directory
27 */
28 var $images_url = '';
29
30 /**
31 * @var string URL to the bbPress admin styles directory
32 */
33 var $styles_url = '';
34
35 /** URLs ******************************************************************/
36
37 /**
38 * @var bool Enable recounts in Tools area
39 */
40 var $enable_recounts = false;
41
42 /** Functions *************************************************************/
43
44 /**
45 * The main bbPress admin loader (PHP4 compat)
46 *
47 * @since bbPress (r2515)
48 *
49 * @uses BBP_Admin::_setup_globals() Setup the globals needed
50 * @uses BBP_Admin::_includes() Include the required files
51 * @uses BBP_Admin::_setup_actions() Setup the hooks and actions
52 */
53 function BBP_Admin() {
54 $this->__construct();
55 }
56
57 /**
58 * The main bbPress admin loader
59 *
60 * @since bbPress (r2515)
61 *
62 * @uses BBP_Admin::_setup_globals() Setup the globals needed
63 * @uses BBP_Admin::_includes() Include the required files
64 * @uses BBP_Admin::_setup_actions() Setup the hooks and actions
65 */
66 function __construct() {
67 $this->_setup_globals();
68 $this->_includes();
69 $this->_setup_actions();
70 }
71
72 /**
73 * Setup the admin hooks, actions and filters
74 *
75 * @since bbPress (r2646)
76 * @access private
77 *
78 * @uses add_action() To add various actions
79 * @uses add_filter() To add various filters
80 */
81 function _setup_actions() {
82
83 /** General Actions ***************************************************/
84
85 // Attach the bbPress admin init action to the WordPress admin init action.
86 add_action( 'admin_init', array( $this, 'init' ) );
87
88 // Add some general styling to the admin area
89 add_action( 'admin_head', array( $this, 'admin_head' ) );
90
91 // Add menu item to settings menu
92 add_action( 'admin_menu', array( $this, 'admin_menus' ) );
93
94 // Add notice if not using a bbPress theme
95 add_action( 'admin_notices', array( $this, 'activation_notice' ) );
96
97 // Register bbPress admin style
98 // @todo Refresh for 3.2 UI
99 //add_action( 'bbp_admin_init', array( $this, 'register_admin_style' ) );
100
101 // Add the importers
102 add_action( 'bbp_admin_init', array( $this, 'register_importers' ) );
103
104 // Add the settings
105 add_action( 'bbp_admin_init', array( $this, 'register_admin_settings' ) );
106
107 // Forums 'Right now' Dashboard widget
108 add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget_right_now' ) );
109
110 /** Filters ***********************************************************/
111
112 // Add link to settings page
113 add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 10, 2 );
114 }
115
116 /**
117 * Include required files
118 *
119 * @since bbPress (r2646)
120 * @access private
121 */
122 function _includes() {
123 global $bbp;
124
125 // Files to include
126 $files = array( 'tools', 'settings', 'functions', 'metaboxes', 'forums', 'topics', 'replies' );
127
128 // Buzz buzz
129 //if ( get_option( '_bbp_first_run' ) ) $files[] = 'first-run';
130
131 // Include the files
132 foreach ( $files as $file )
133 require( $bbp->plugin_dir . 'bbp-admin/bbp-' . $file . '.php' );
134 }
135
136 /**
137 * Admin globals
138 *
139 * @since bbPress (r2646)
140 * @access private
141 */
142 function _setup_globals() {
143 global $bbp;
144
145 // Admin url
146 $this->admin_url = trailingslashit( $bbp->plugin_url . 'bbp-admin' );
147
148 // Admin images URL
149 $this->images_url = trailingslashit( $this->admin_url . 'images' );
150
151 // Admin images URL
152 $this->styles_url = trailingslashit( $this->admin_url . 'styles' );
153 }
154
155 /**
156 * Add the navigational menu elements
157 *
158 * @since bbPress (r2646)
159 *
160 * @uses add_management_page() To add the Recount page in Tools section
161 * @uses add_options_page() To add the Forums settings page in Settings
162 * section
163 */
164 function admin_menus() {
165
166 // Recounts
167 if ( is_super_admin() || !empty( $this->enable_recounts ) )
168 add_management_page( __( 'Recount', 'bbpress' ), __( 'Recount', 'bbpress' ), 'manage_options', 'bbp-recount', 'bbp_admin_tools' );
169
170 // Forums settings
171 add_options_page ( __( 'Forums', 'bbpress' ), __( 'Forums', 'bbpress' ), 'manage_options', 'bbpress', 'bbp_admin_settings' );
172 }
173
174 /**
175 * Register the settings
176 *
177 * @since bbPress (r2737)
178 *
179 * @uses add_settings_section() To add our own settings section
180 * @uses add_settings_field() To add various settings fields
181 * @uses register_setting() To register various settings
182 * @uses do_action() Calls 'bbp_register_admin_settings'
183 */
184 function register_admin_settings() {
185
186 /** Main Section ******************************************************/
187
188 // Add the main section
189 add_settings_section( 'bbp_main', __( 'Main Settings', 'bbpress' ), 'bbp_admin_setting_callback_main_section', 'bbpress' );
190
191 // Edit lock setting
192 add_settings_field( '_bbp_edit_lock', __( 'Lock post editing after', 'bbpress' ), 'bbp_admin_setting_callback_editlock', 'bbpress', 'bbp_main' );
193 register_setting ( 'bbpress', '_bbp_edit_lock', 'intval' );
194
195 // Throttle setting
196 add_settings_field( '_bbp_throttle_time', __( 'Throttle time', 'bbpress' ), 'bbp_admin_setting_callback_throttle', 'bbpress', 'bbp_main' );
197 register_setting ( 'bbpress', '_bbp_throttle_time', 'intval' );
198
199 // Allow favorites setting
200 add_settings_field( '_bbp_enable_favorites', __( 'Allow Favorites', 'bbpress' ), 'bbp_admin_setting_callback_favorites', 'bbpress', 'bbp_main' );
201 register_setting ( 'bbpress', '_bbp_enable_favorites', 'intval' );
202
203 // Allow subscriptions setting
204 add_settings_field( '_bbp_enable_subscriptions', __( 'Allow Subscriptions', 'bbpress' ), 'bbp_admin_setting_callback_subscriptions', 'bbpress', 'bbp_main' );
205 register_setting ( 'bbpress', '_bbp_enable_subscriptions', 'intval' );
206
207 // Allow anonymous posting setting
208 add_settings_field( '_bbp_allow_anonymous', __( 'Allow Anonymous Posting', 'bbpress' ), 'bbp_admin_setting_callback_anonymous', 'bbpress', 'bbp_main' );
209 register_setting ( 'bbpress', '_bbp_allow_anonymous', 'intval' );
210
211 /** Per Page Section **************************************************/
212
213 // Add the per page section
214 add_settings_section( 'bbp_per_page', __( 'Per Page', 'bbpress' ), 'bbp_admin_setting_callback_per_page_section', 'bbpress' );
215
216 // Topics per page setting
217 add_settings_field( '_bbp_topics_per_page', __( 'Topics Per Page', 'bbpress' ), 'bbp_admin_setting_callback_topics_per_page', 'bbpress', 'bbp_per_page' );
218 register_setting ( 'bbpress', '_bbp_topics_per_page', 'intval' );
219
220 // Replies per page setting
221 add_settings_field( '_bbp_replies_per_page', __( 'Replies Per Page', 'bbpress' ), 'bbp_admin_setting_callback_replies_per_page', 'bbpress', 'bbp_per_page' );
222 register_setting ( 'bbpress', '_bbp_replies_per_page', 'intval' );
223
224 /** Per RSS Page Section **********************************************/
225
226 // Add the per page section
227 add_settings_section( 'bbp_per_rss_page', __( 'Per RSS Page', 'bbpress' ), 'bbp_admin_setting_callback_per_rss_page_section', 'bbpress' );
228
229 // Topics per page setting
230 add_settings_field( '_bbp_topics_per_page', __( 'Topics Per Page', 'bbpress' ), 'bbp_admin_setting_callback_topics_per_rss_page', 'bbpress', 'bbp_per_rss_page' );
231 register_setting ( 'bbpress', '_bbp_topics_per_rss_page', 'intval' );
232
233 // Replies per page setting
234 add_settings_field( '_bbp_replies_per_page', __( 'Replies Per Page', 'bbpress' ), 'bbp_admin_setting_callback_replies_per_rss_page', 'bbpress', 'bbp_per_rss_page' );
235 register_setting ( 'bbpress', '_bbp_replies_per_rss_page', 'intval' );
236
237 /** Front Slugs *******************************************************/
238
239 // Add the per page section
240 add_settings_section( 'bbp_root_slug', __( 'Archive Slugs', 'bbpress' ), 'bbp_admin_setting_callback_root_slug_section', 'bbpress' );
241
242 // Root slug setting
243 add_settings_field ( '_bbp_root_slug', __( 'Forums Base', 'bbpress' ), 'bbp_admin_setting_callback_root_slug', 'bbpress', 'bbp_root_slug' );
244 register_setting ( 'bbpress', '_bbp_root_slug', 'esc_sql' );
245
246 // Topic archive setting
247 add_settings_field ( '_bbp_topic_archive_slug', __( 'Topics Base', 'bbpress' ), 'bbp_admin_setting_callback_topic_archive_slug', 'bbpress', 'bbp_root_slug' );
248 register_setting ( 'bbpress', '_bbp_topic_archive_slug', 'esc_sql' );
249
250 /** Single slugs ******************************************************/
251
252 // Add the per page section
253 add_settings_section( 'bbp_single_slugs', __( 'Single Slugs', 'bbpress' ), 'bbp_admin_setting_callback_single_slug_section', 'bbpress' );
254
255 // Include root setting
256 add_settings_field( '_bbp_include_root', __( 'Forum Prefix', 'bbpress' ), 'bbp_admin_setting_callback_include_root', 'bbpress', 'bbp_single_slugs' );
257 register_setting ( 'bbpress', '_bbp_include_root', 'intval' );
258
259 // Forum slug setting
260 add_settings_field( '_bbp_forum_slug', __( 'Forum slug', 'bbpress' ), 'bbp_admin_setting_callback_forum_slug', 'bbpress', 'bbp_single_slugs' );
261 register_setting ( 'bbpress', '_bbp_forum_slug', 'sanitize_title' );
262
263 // Topic slug setting
264 add_settings_field( '_bbp_topic_slug', __( 'Topic slug', 'bbpress' ), 'bbp_admin_setting_callback_topic_slug', 'bbpress', 'bbp_single_slugs' );
265 register_setting ( 'bbpress', '_bbp_topic_slug', 'sanitize_title' );
266
267 // Topic tag slug setting
268 add_settings_field( '_bbp_topic_tag_slug', __( 'Topic tag slug', 'bbpress' ), 'bbp_admin_setting_callback_topic_tag_slug', 'bbpress', 'bbp_single_slugs' );
269 register_setting ( 'bbpress', '_bbp_topic_tag_slug', 'sanitize_title' );
270
271 // Reply slug setting
272 add_settings_field( '_bbp_reply_slug', __( 'Reply slug', 'bbpress' ), 'bbp_admin_setting_callback_reply_slug', 'bbpress', 'bbp_single_slugs' );
273 register_setting ( 'bbpress', '_bbp_reply_slug', 'sanitize_title' );
274
275 /** Other slugs *******************************************************/
276
277 // User slug setting
278 add_settings_field( '_bbp_user_slug', __( 'User base', 'bbpress' ), 'bbp_admin_setting_callback_user_slug', 'bbpress', 'bbp_single_slugs' );
279 register_setting ( 'bbpress', '_bbp_user_slug', 'sanitize_title' );
280
281 // View slug setting
282 add_settings_field( '_bbp_view_slug', __( 'View base', 'bbpress' ), 'bbp_admin_setting_callback_view_slug', 'bbpress', 'bbp_single_slugs' );
283 register_setting ( 'bbpress', '_bbp_view_slug', 'sanitize_title' );
284
285 do_action( 'bbp_register_admin_settings' );
286 }
287 /**
288 * Register the importers
289 *
290 * @todo Make this better
291 *
292 * @since bbPress (r2737)
293 *
294 * @uses do_action() Calls 'bbp_register_importers'
295 */
296 function register_importers() {
297
298 // Leave if we're not in the import section
299 if ( !defined( 'WP_LOAD_IMPORTERS' ) )
300 return;
301
302 global $bbp;
303
304 // Load Importer API
305 require_once( ABSPATH . 'wp-admin/includes/import.php' );
306
307 // Load our importers
308 // The logic here needs to be improved upon
309 $importers = apply_filters( 'bbp_importers', array( 'bbpress' ) );
310
311 // Loop through included importers
312 foreach ( $importers as $importer ) {
313
314 // Compile the importer path
315 $import_file = $bbp->plugin_dir . 'bbp-admin/importers/' . $importer . '.php';
316
317 // If the file exists, include it
318 if ( file_exists( $import_file ) )
319 require( $import_file );
320 }
321
322 // Don't do anything we wouldn't do
323 do_action( 'bbp_register_importers' );
324 }
325
326 /**
327 * Admin area activation notice
328 *
329 * Shows a nag message in admin area about the theme not supporting bbPress
330 *
331 * @since bbPress (r2743)
332 *
333 * @global bbPress $bbp
334 *
335 * @uses current_user_can() To check notice should be displayed.
336 * @uses current_theme_supports() To check theme for bbPress support
337 */
338 function activation_notice() {
339 global $bbp, $pagenow;
340
341 // Bail if not on admin theme page
342 if ( 'themes.php' != $pagenow )
343 return;
344
345 // Bail if user cannot change the theme
346 if ( !current_user_can( 'switch_themes' ) )
347 return;
348
349 // Set $bbp->theme_compat to true to bypass nag
350 if ( !empty( $bbp->theme_compat->theme ) && !current_theme_supports( 'bbpress' ) ) { ?>
351
352 <div id="message" class="updated fade">
353 <p style="line-height: 150%"><?php printf( __( "<strong>bbPress is in Theme Compatability Mode</strong>. Your forums are using default styling.", 'bbpress' ), admin_url( 'themes.php' ), admin_url( 'theme-install.php?type=tag&s=bbpress&tab=search' ) ) ?></p>
354 </div>
355
356 <?php }
357 }
358
359 /**
360 * Add Settings link to plugins area
361 *
362 * @since bbPress (r2737)
363 *
364 * @param array $links Links array in which we would prepend our link
365 * @param string $file Current plugin basename
366 * @return array Processed links
367 */
368 function add_settings_link( $links, $file ) {
369 global $bbp;
370
371 if ( plugin_basename( $bbp->file ) == $file ) {
372 $settings_link = '<a href="' . add_query_arg( array( 'page' => 'bbpress' ), admin_url( 'options-general.php' ) ) . '">' . __( 'Settings', 'bbpress' ) . '</a>';
373 array_unshift( $links, $settings_link );
374 }
375
376 return $links;
377 }
378
379 /**
380 * bbPress's dedicated admin init action
381 *
382 * @since bbPress (r2464)
383 *
384 * @uses do_action() Calls 'bbp_admin_init'
385 */
386 function init() {
387 do_action( 'bbp_admin_init' );
388 }
389
390 /**
391 * Add the 'Right now in Forums' dashboard widget
392 *
393 * @since bbPress (r2770)
394 *
395 * @uses wp_add_dashboard_widget() To add the dashboard widget
396 */
397 function dashboard_widget_right_now() {
398 wp_add_dashboard_widget( 'bbp-dashboard-right-now', __( 'Right Now in Forums', 'bbpress' ), 'bbp_dashboard_widget_right_now' );
399 }
400
401 /**
402 * Add some general styling to the admin area
403 *
404 * @since bbPress (r2464)
405 *
406 * @uses bbp_get_forum_post_type() To get the forum post type
407 * @uses bbp_get_topic_post_type() To get the topic post type
408 * @uses bbp_get_reply_post_type() To get the reply post type
409 * @uses sanitize_html_class() To sanitize the classes
410 * @uses bbp_is_forum() To check if it is a forum page
411 * @uses bbp_is_topic() To check if it is a topic page
412 * @uses bbp_is_reply() To check if it is a reply page
413 * @uses do_action() Calls 'bbp_admin_head'
414 */
415 function admin_head() {
416
417 // Icons for top level admin menus
418 $menu_icon_url = $this->images_url . 'menu.png';
419 $icon32_url = $this->images_url . 'icons32.png';
420
421 // Top level menu classes
422 $forum_class = sanitize_html_class( bbp_get_forum_post_type() );
423 $topic_class = sanitize_html_class( bbp_get_topic_post_type() );
424 $reply_class = sanitize_html_class( bbp_get_reply_post_type() ); ?>
425
426 <style type="text/css" media="screen">
427 /*<![CDATA[*/
428
429 #bbp-dashboard-right-now p.sub,
430 #bbp-dashboard-right-now .table,
431 #bbp-dashboard-right-now .versions {
432 margin: -12px;
433 }
434
435 #bbp-dashboard-right-now .inside {
436 font-size: 12px;
437 padding-top: 20px;
438 margin-bottom: 0;
439 }
440
441 #bbp-dashboard-right-now p.sub {
442 font-style: italic;
443 font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
444 padding: 5px 10px 15px;
445
446 <?php if ( is_rtl() ) : ?>
447
448 right: 15px;
449
450 <?php else : ?>
451
452 left: 15px;
453
454 <?php endif; ?>
455
456 color: #777;
457 font-size: 13px;
458 position: absolute;
459 top: -17px;
460 }
461
462 #bbp-dashboard-right-now .table {
463 margin: 0 -9px;
464 padding: 0 10px;
465 position: relative;
466 }
467
468 #bbp-dashboard-right-now .table_content {
469
470 <?php if ( is_rtl() ) : ?>
471
472 float: right;
473
474 <?php else : ?>
475
476 float: left;
477
478 <?php endif; ?>
479
480 border-top: #ececec 1px solid;
481 width: 45%;
482 }
483
484 #bbp-dashboard-right-now .table_discussion {
485
486 <?php if ( is_rtl() ) : ?>
487
488 float: left;
489
490 <?php else : ?>
491
492 float: right;
493
494 <?php endif; ?>
495
496 border-top: #ececec 1px solid;
497 width: 45%;
498 }
499
500 #bbp-dashboard-right-now table td {
501 padding: 3px 0;
502 white-space: nowrap;
503 }
504
505 #bbp-dashboard-right-now table tr.first td {
506 border-top: none;
507 }
508
509 #bbp-dashboard-right-now td.b {
510
511 <?php if ( is_rtl() ) : ?>
512
513 padding-left: 6px;
514
515 <?php else : ?>
516
517 padding-right: 6px;
518
519 <?php endif; ?>
520
521 text-align: right;
522 font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
523 font-size: 14px;
524 width: 1%;
525 }
526
527 #bbp-dashboard-right-now td.b a {
528 font-size: 18px;
529 }
530
531 #bbp-dashboard-right-now td.b a:hover {
532 color: #d54e21;
533 }
534
535 #bbp-dashboard-right-now .t {
536 font-size: 12px;
537
538 <?php if ( is_rtl() ) : ?>
539
540 padding-left: 12px;
541
542 <?php else : ?>
543
544 padding-right: 12px;
545
546 <?php endif; ?>
547
548 padding-top: 6px;
549 color: #777;
550 }
551
552 #bbp-dashboard-right-now .t a {
553 white-space: nowrap;
554 }
555
556 #bbp-dashboard-right-now .spam {
557 color: red;
558 }
559
560 #bbp-dashboard-right-now .waiting {
561 color: #e66f00;
562 }
563
564 #bbp-dashboard-right-now .approved {
565 color: green;
566 }
567
568 #bbp-dashboard-right-now .versions {
569 padding: 6px 10px 12px;
570 clear: both;
571 }
572
573 #bbp-dashboard-right-now .versions .b {
574 font-weight: bold;
575 }
576
577 #bbp-dashboard-right-now a.button {
578
579 <?php if ( is_rtl() ) : ?>
580
581 float: left;
582 clear: left;
583
584 <?php else : ?>
585
586 float: right;
587 clear: right;
588
589 <?php endif; ?>
590
591 position: relative;
592 top: -5px;
593 }
594
595 #menu-posts-<?php echo $forum_class; ?> .wp-menu-image {
596 background: url(<?php echo $menu_icon_url; ?>) no-repeat 0px -32px;
597 }
598 #menu-posts-<?php echo $forum_class; ?>:hover .wp-menu-image,
599 #menu-posts-<?php echo $forum_class; ?>.wp-has-current-submenu .wp-menu-image {
600 background: url(<?php echo $menu_icon_url; ?>) no-repeat 0px 0px;
601 }
602 #icon-edit.icon32-posts-<?php echo $forum_class; ?> {
603 background: url(<?php echo $icon32_url; ?>) no-repeat -4px 0px;
604 }
605
606 #menu-posts-<?php echo $topic_class; ?> .wp-menu-image {
607 background: url(<?php echo $menu_icon_url; ?>) no-repeat -70px -32px;
608 }
609 #menu-posts-<?php echo $topic_class; ?>:hover .wp-menu-image,
610 #menu-posts-<?php echo $topic_class; ?>.wp-has-current-submenu .wp-menu-image {
611 background: url(<?php echo $menu_icon_url; ?>) no-repeat -70px 0px;
612 }
613 #icon-edit.icon32-posts-<?php echo $topic_class; ?> {
614 background: url(<?php echo $icon32_url; ?>) no-repeat -4px -90px;
615 }
616
617 #menu-posts-<?php echo $reply_class; ?> .wp-menu-image {
618 background: url(<?php echo $menu_icon_url; ?>) no-repeat -35px -32px;
619 }
620 #menu-posts-<?php echo $reply_class; ?>:hover .wp-menu-image,
621 #menu-posts-<?php echo $reply_class; ?>.wp-has-current-submenu .wp-menu-image {
622 background: url(<?php echo $menu_icon_url; ?>) no-repeat -35px 0px;
623 }
624 #icon-edit.icon32-posts-<?php echo $reply_class; ?> {
625 background: url(<?php echo $icon32_url; ?>) no-repeat -4px -180px;
626 }
627
628 /*]]>*/
629 </style>
630
631 <?php
632
633 // Add extra actions to bbPress admin header area
634 do_action( 'bbp_admin_head' );
635 }
636
637 /**
638 * Registers the bbPress admin color scheme
639 *
640 * @since bbPress (r2521)
641 *
642 * @uses wp_admin_css_color() To register the color scheme
643 */
644 function register_admin_style () {
645 wp_admin_css_color( 'bbpress', __( 'Green', 'bbpress' ), $this->styles_url . 'admin.css', array( '#222222', '#006600', '#deece1', '#6eb469' ) );
646 }
647 }
648 endif; // class_exists check
649
650 /**
651 * Setup bbPress Admin
652 *
653 * @since bbPress (r2596)
654 *
655 * @uses BBP_Admin
656 */
657 function bbp_admin() {
658 global $bbp;
659
660 $bbp->admin = new BBP_Admin();
661 }
662
663 ?>
664