diff -r c7c0fbc09788 -r 5e8dcbe22c24 web/wp-content/plugins/bbpress/includes/admin/admin.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/bbpress/includes/admin/admin.php Tue Dec 04 18:43:10 2012 -0800 @@ -0,0 +1,1702 @@ +setup_globals(); + $this->includes(); + $this->setup_actions(); + } + + /** + * Admin globals + * + * @since bbPress (r2646) + * @access private + */ + private function setup_globals() { + $bbp = bbpress(); + $this->admin_dir = trailingslashit( $bbp->includes_dir . 'admin' ); // Admin path + $this->admin_url = trailingslashit( $bbp->includes_url . 'admin' ); // Admin url + $this->images_url = trailingslashit( $this->admin_url . 'images' ); // Admin images URL + $this->styles_url = trailingslashit( $this->admin_url . 'styles' ); // Admin styles URL + } + + /** + * Include required files + * + * @since bbPress (r2646) + * @access private + */ + private function includes() { + require( $this->admin_dir . 'tools.php' ); + require( $this->admin_dir . 'converter.php' ); + require( $this->admin_dir . 'settings.php' ); + require( $this->admin_dir . 'functions.php' ); + require( $this->admin_dir . 'metaboxes.php' ); + require( $this->admin_dir . 'forums.php' ); + require( $this->admin_dir . 'topics.php' ); + require( $this->admin_dir . 'replies.php' ); + require( $this->admin_dir . 'users.php' ); + } + + /** + * Setup the admin hooks, actions and filters + * + * @since bbPress (r2646) + * @access private + * + * @uses add_action() To add various actions + * @uses add_filter() To add various filters + */ + private function setup_actions() { + + // Bail to prevent interfering with the deactivation process + if ( bbp_is_deactivation() ) + return; + + /** General Actions ***************************************************/ + + add_action( 'bbp_admin_menu', array( $this, 'admin_menus' ) ); // Add menu item to settings menu + add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); // Add some general styling to the admin area + add_action( 'bbp_admin_notices', array( $this, 'activation_notice' ) ); // Add notice if not using a bbPress theme + add_action( 'bbp_register_admin_style', array( $this, 'register_admin_style' ) ); // Add green admin style + add_action( 'bbp_register_admin_settings', array( $this, 'register_admin_settings' ) ); // Add settings + add_action( 'bbp_activation', array( $this, 'new_install' ) ); // Add menu item to settings menu + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); // Add enqueued JS and CSS + add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget_right_now' ) ); // Forums 'Right now' Dashboard widget + + /** Ajax **************************************************************/ + + add_action( 'wp_ajax_bbp_suggest_topic', array( $this, 'suggest_topic' ) ); + add_action( 'wp_ajax_nopriv_bbp_suggest_topic', array( $this, 'suggest_topic' ) ); + + /** Filters ***********************************************************/ + + // Modify bbPress's admin links + add_filter( 'plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 ); + + // Map settings capabilities + add_filter( 'bbp_map_meta_caps', array( $this, 'map_settings_meta_caps' ), 10, 4 ); + + // Hide the theme compat package selection + add_filter( 'bbp_admin_get_settings_sections', array( $this, 'hide_theme_compat_packages' ) ); + + /** Network Admin *****************************************************/ + + // Add menu item to settings menu + add_action( 'network_admin_menu', array( $this, 'network_admin_menus' ) ); + + /** Dependencies ******************************************************/ + + // Allow plugins to modify these actions + do_action_ref_array( 'bbp_admin_loaded', array( &$this ) ); + } + + /** + * Add the admin menus + * + * @since bbPress (r2646) + * + * @uses add_management_page() To add the Recount page in Tools section + * @uses add_options_page() To add the Forums settings page in Settings + * section + */ + public function admin_menus() { + + $hooks = array(); + + // These are later removed in admin_head + if ( current_user_can( 'bbp_tools_page' ) ) { + if ( current_user_can( 'bbp_tools_repair_page' ) ) { + $hooks[] = add_management_page( + __( 'Repair Forums', 'bbpress' ), + __( 'Forum Repair', 'bbpress' ), + $this->minimum_capability, + 'bbp-repair', + 'bbp_admin_repair' + ); + } + + if ( current_user_can( 'bbp_tools_import_page' ) ) { + $hooks[] = add_management_page( + __( 'Import Forums', 'bbpress' ), + __( 'Forum Import', 'bbpress' ), + $this->minimum_capability, + 'bbp-converter', + 'bbp_converter_settings' + ); + } + + if ( current_user_can( 'bbp_tools_reset_page' ) ) { + $hooks[] = add_management_page( + __( 'Reset Forums', 'bbpress' ), + __( 'Forum Reset', 'bbpress' ), + $this->minimum_capability, + 'bbp-reset', + 'bbp_admin_reset' + ); + } + + // Fudge the highlighted subnav item when on a bbPress admin page + foreach( $hooks as $hook ) { + add_action( "admin_head-$hook", 'bbp_tools_modify_menu_highlight' ); + } + + // Forums Tools Root + add_management_page( + __( 'Forums', 'bbpress' ), + __( 'Forums', 'bbpress' ), + $this->minimum_capability, + 'bbp-repair', + 'bbp_admin_repair' + ); + } + + // Are settings enabled? + if ( current_user_can( 'bbp_settings_page' ) ) { + add_options_page( + __( 'Forums', 'bbpress' ), + __( 'Forums', 'bbpress' ), + $this->minimum_capability, + 'bbpress', + 'bbp_admin_settings' + ); + } + + // These are later removed in admin_head + if ( current_user_can( 'bbp_about_page' ) ) { + + // About + add_dashboard_page( + __( 'Welcome to bbPress', 'bbpress' ), + __( 'Welcome to bbPress', 'bbpress' ), + $this->minimum_capability, + 'bbp-about', + array( $this, 'about_screen' ) + ); + + // Credits + add_dashboard_page( + __( 'Welcome to bbPress', 'bbpress' ), + __( 'Welcome to bbPress', 'bbpress' ), + $this->minimum_capability, + 'bbp-credits', + array( $this, 'credits_screen' ) + ); + } + + // Bail if plugin is not network activated + if ( ! is_plugin_active_for_network( bbpress()->basename ) ) + return; + + add_submenu_page( + 'index.php', + __( 'Update Forums', 'bbpress' ), + __( 'Update Forums', 'bbpress' ), + 'manage_network', + 'bbp-update', + array( $this, 'update_screen' ) + ); + } + + /** + * Add the network admin menus + * + * @since bbPress (r3689) + * @uses add_submenu_page() To add the Update Forums page in Updates + */ + public function network_admin_menus() { + + // Bail if plugin is not network activated + if ( ! is_plugin_active_for_network( bbpress()->basename ) ) + return; + + add_submenu_page( + 'upgrade.php', + __( 'Update Forums', 'bbpress' ), + __( 'Update Forums', 'bbpress' ), + 'manage_network', + 'bbpress-update', + array( $this, 'network_update_screen' ) + ); + } + + /** + * If this is a new installation, create some initial forum content. + * + * @since bbPress (r3767) + * @return type + */ + public static function new_install() { + if ( !bbp_is_install() ) + return; + + bbp_create_initial_content(); + } + + /** + * Register the settings + * + * @since bbPress (r2737) + * + * @uses add_settings_section() To add our own settings section + * @uses add_settings_field() To add various settings fields + * @uses register_setting() To register various settings + * @todo Put fields into multidimensional array + */ + public static function register_admin_settings() { + + // Bail if no sections available + $sections = bbp_admin_get_settings_sections(); + if ( empty( $sections ) ) + return false; + + // Loop through sections + foreach ( (array) $sections as $section_id => $section ) { + + // Only proceed if current user can see this section + if ( ! current_user_can( $section_id ) ) + continue; + + // Only add section and fields if section has fields + $fields = bbp_admin_get_settings_fields_for_section( $section_id ); + if ( empty( $fields ) ) + continue; + + // Add the section + add_settings_section( $section_id, $section['title'], $section['callback'], $section['page'] ); + + // Loop through fields for this section + foreach ( (array) $fields as $field_id => $field ) { + + // Add the field + add_settings_field( $field_id, $field['title'], $field['callback'], $section['page'], $section_id, $field['args'] ); + + // Register the setting + register_setting( $section['page'], $field_id, $field['sanitize_callback'] ); + } + } + } + + /** + * Maps settings capabilities + * + * @since bbPress (r4242) + * + * @param array $caps Capabilities for meta capability + * @param string $cap Capability name + * @param int $user_id User id + * @param mixed $args Arguments + * @uses get_post() To get the post + * @uses get_post_type_object() To get the post type object + * @uses apply_filters() Calls 'bbp_map_meta_caps' with caps, cap, user id and + * args + * @return array Actual capabilities for meta capability + */ + public static function map_settings_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { + + // What capability is being checked? + switch ( $cap ) { + + // BuddyPress + case 'bbp_settings_buddypress' : + if ( ( is_plugin_active( 'buddypress/bp-loader.php' ) && defined( 'BP_VERSION' ) ) && is_super_admin() ) { + $caps = array( bbpress()->admin->minimum_capability ); + } else { + $caps = array( 'do_not_allow' ); + } + + break; + + // Akismet + case 'bbp_settings_akismet' : + if ( ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) && is_super_admin() ) { + $caps = array( bbpress()->admin->minimum_capability ); + } else { + $caps = array( 'do_not_allow' ); + } + + break; + + // bbPress + case 'bbp_about_page' : // About and Credits + case 'bbp_tools_page' : // Tools Page + case 'bbp_tools_repair_page' : // Tools - Repair Page + case 'bbp_tools_import_page' : // Tools - Import Page + case 'bbp_tools_reset_page' : // Tools - Reset Page + case 'bbp_settings_page' : // Settings Page + case 'bbp_settings_main' : // Settings - General + case 'bbp_settings_theme_compat' : // Settings - Theme compat + case 'bbp_settings_root_slugs' : // Settings - Root slugs + case 'bbp_settings_single_slugs' : // Settings - Single slugs + case 'bbp_settings_per_page' : // Settings - Single slugs + case 'bbp_settings_per_page_rss' : // Settings - Single slugs + $caps = array( bbpress()->admin->minimum_capability ); + break; + } + + return apply_filters( 'bbp_map_settings_meta_caps', $caps, $cap, $user_id, $args ); + } + + /** + * Register the importers + * + * @since bbPress (r2737) + * + * @uses apply_filters() Calls 'bbp_importer_path' filter to allow plugins + * to customize the importer script locations. + */ + public function register_importers() { + + // Leave if we're not in the import section + if ( !defined( 'WP_LOAD_IMPORTERS' ) ) + return; + + // Load Importer API + require_once( ABSPATH . 'wp-admin/includes/import.php' ); + + // Load our importers + $importers = apply_filters( 'bbp_importers', array( 'bbpress' ) ); + + // Loop through included importers + foreach ( $importers as $importer ) { + + // Allow custom importer directory + $import_dir = apply_filters( 'bbp_importer_path', $this->admin_dir . 'importers', $importer ); + + // Compile the importer path + $import_file = trailingslashit( $import_dir ) . $importer . '.php'; + + // If the file exists, include it + if ( file_exists( $import_file ) ) { + require( $import_file ); + } + } + } + + /** + * Admin area activation notice + * + * Shows a nag message in admin area about the theme not supporting bbPress + * + * @since bbPress (r2743) + * + * @uses current_user_can() To check notice should be displayed. + */ + public function activation_notice() { + // @todo - something fun + } + + /** + * Add Settings link to plugins area + * + * @since bbPress (r2737) + * + * @param array $links Links array in which we would prepend our link + * @param string $file Current plugin basename + * @return array Processed links + */ + public static function modify_plugin_action_links( $links, $file ) { + + // Return normal links if not bbPress + if ( plugin_basename( bbpress()->file ) != $file ) + return $links; + + // Add a few links to the existing links array + return array_merge( $links, array( + 'settings' => '' . esc_html__( 'Settings', 'bbpress' ) . '', + 'about' => '' . esc_html__( 'About', 'bbpress' ) . '' + ) ); + } + + /** + * Add the 'Right now in Forums' dashboard widget + * + * @since bbPress (r2770) + * + * @uses wp_add_dashboard_widget() To add the dashboard widget + */ + public static function dashboard_widget_right_now() { + wp_add_dashboard_widget( 'bbp-dashboard-right-now', __( 'Right Now in Forums', 'bbpress' ), 'bbp_dashboard_widget_right_now' ); + } + + /** + * Enqueue any admin scripts we might need + * @since bbPress (4260) + */ + public function enqueue_scripts() { + wp_enqueue_script( 'suggest' ); + } + + /** + * Add some general styling to the admin area + * + * @since bbPress (r2464) + * + * @uses bbp_get_forum_post_type() To get the forum post type + * @uses bbp_get_topic_post_type() To get the topic post type + * @uses bbp_get_reply_post_type() To get the reply post type + * @uses sanitize_html_class() To sanitize the classes + */ + public function admin_head() { + + // Remove the individual recount and converter menus. + // They are grouped together by h2 tabs + remove_submenu_page( 'tools.php', 'bbp-repair' ); + remove_submenu_page( 'tools.php', 'bbp-converter' ); + remove_submenu_page( 'tools.php', 'bbp-reset' ); + remove_submenu_page( 'index.php', 'bbp-about' ); + remove_submenu_page( 'index.php', 'bbp-credits' ); + + // The /wp-admin/images/ folder + $wp_admin_url = admin_url( 'images/' ); + + // Icons for top level admin menus + $version = bbp_get_version(); + $menu_icon_url = $this->images_url . 'menu.png?ver=' . $version; + $icon32_url = $this->images_url . 'icons32.png?ver=' . $version; + $menu_icon_url_2x = $this->images_url . 'menu-2x.png?ver=' . $version; + $icon32_url_2x = $this->images_url . 'icons32-2x.png?ver=' . $version; + $badge_url = $this->images_url . 'badge.png?ver=' . $version; + $badge_url_2x = $this->images_url . 'badge-2x.png?ver=' . $version; + + // The image size changed in WordPress 3.5 + if ( function_exists( 'wp_enqueue_media' ) ) { + $icon32_size = '756px 45px'; + } else { + $icon32_size = '708px 45px'; + } + + // Top level menu classes + $forum_class = sanitize_html_class( bbp_get_forum_post_type() ); + $topic_class = sanitize_html_class( bbp_get_topic_post_type() ); + $reply_class = sanitize_html_class( bbp_get_reply_post_type() ); + + if ( ( 'post' == get_current_screen()->base ) && ( bbp_get_reply_post_type() == get_current_screen()->post_type ) ) : ?> + + + + + + + + styles_url . 'green.css'; + + } else { + $green_scheme = $this->styles_url . 'green-34.css'; + } + + // Register the green scheme + wp_admin_css_color( 'bbpress', esc_html_x( 'Green', 'admin color scheme', 'bbpress' ), $green_scheme, array( '#222222', '#006600', '#deece1', '#6eb469' ) ); + } + + /** + * Hide theme compat package selection if only 1 package is registered + * + * @since bbPress (r4315) + * + * @param array $sections Forums settings sections + * @return array + */ + public function hide_theme_compat_packages( $sections = array() ) { + if ( count( bbpress()->theme_compat->packages ) <= 1 ) + unset( $sections['bbp_settings_theme_compat'] ); + + return $sections; + } + + /** Ajax ******************************************************************/ + + /** + * Ajax action for facilitating the forum auto-suggest + * + * @since bbPress (r4261) + * + * @uses get_posts() + * @uses bbp_get_topic_post_type() + * @uses bbp_get_topic_id() + * @uses bbp_get_topic_title() + */ + public function suggest_topic() { + + // TRy to get some topics + $topics = get_posts( array( + 's' => like_escape( $_REQUEST['q'] ), + 'post_type' => bbp_get_topic_post_type() + ) ); + + // If we found some topics, loop through and display them + if ( ! empty( $topics ) ) { + foreach ( (array) $topics as $post ) { + echo sprintf( __( '%s - %s', 'bbpress' ), bbp_get_topic_id( $post->ID ), bbp_get_topic_title( $post->ID ) ) . "\n"; + } + } + die(); + } + + /** About *****************************************************************/ + + /** + * Output the about screen + * + * @since bbPress (r4159) + */ + public function about_screen() { + + list( $display_version ) = explode( '-', bbp_get_version() ); ?> + +
+

+
+
+ + + +
+

+ +
+

+

+ +

+

+
+
+ +
+

+ +
+

+

+
+
+ +
+

+ +
+

+

+ +

+

+
+
+ +
+

+ +
+

+

+ +

+

+
+
+ +
+

+ +
+
+

+

+ +

+

+
+ +
+

+

+ +

+

+
+ +
+

+

+
+
+
+ +
+ +
+ +
+ + + +
+

+
+
+ + + +

+ +

+ + +

+ + +

+ + +

+

+ alexvorn2, + anointed, + boonebgorges, + chexee, + cnorris23, + DanielJuhl, + daveshine, + dimadin, + DJPaul, + duck_, + gawain, + iamzippy, + isaacchapman, + jane, + jkudish, + mamaduka, + mercime, + mesayre, + mordauk, + MZAWeb, + netweb, + nexia, + Omicron7, + otto42, + pavelevap, + plescheff, + scribu, + sorich87, + SteveAtty, + tmoorewp, + tott, + tungdo, + vibol, + wonderboymusic, + westi, + xiosen, +

+ +
+ +
+ +
+ + + +
+

+

+ + + +

+ + + + +

+

+ + + +
+ +
+

+

+ + get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A ); + + // No blogs so all done! + if ( empty( $blogs ) ) : ?> + +

+ + + + + + + + +

+ + +

+ + +

+

+ + + +
admin = new BBP_Admin(); + + bbpress()->admin->converter = new BBP_Converter(); +}