Skip to:
Content

BuddyPress.org

Changeset 1636 for trunk/bp-core.php


Ignore:
Timestamp:
08/08/2009 05:25:01 PM (17 years ago)
Author:
apeatling
Message:

Re-factored a large amount of code. Moved all deprecated code into a deprecated folder which can be selectively unloaded. Removed all theme specific AJAX, CSS and JS from the plugins (and into the deprecated folder) in anticipation for the new theme setup coming in another big commit next week.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r1621 r1636  
    11<?php
     2
    23/* Define the current version number for checking if DB tables are up to date. */
    3 define( 'BP_CORE_DB_VERSION', '1300' );
     4define( 'BP_CORE_DB_VERSION', '1400' );
    45
    56/* Define the path and url of the BuddyPress plugins directory */
    … …  
    3031require ( BP_PLUGIN_DIR . '/bp-core/bp-core-settings.php' );
    3132require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
    32 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-ajax.php' );
    3333require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
     34require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
    3435
    3536/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar */
    36 if ( !defined( 'BP_DISABLE_ADMIN_BAR') )
     37if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
    3738        require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
     39
     40/* If BP_IGNORE_DEPRECATED is defined, do not load any deprecated functions for backwards support */
     41if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
     42        require ( BP_PLUGIN_DIR . '/bp-core/deprecated/bp-core-deprecated.php' );
    3843
    3944/* Define the slug for member pages and the members directory (e.g. domain.com/[members] ) */
    … …  
    118123        /* Sets up the array container for the component navigation rendered by bp_get_nav() */
    119124        $bp->bp_nav = array();
    120 
    121         /* Sets up the array container for the user navigation rendered by bp_get_user_nav() */
    122         $bp->bp_users_nav = array();
    123125       
    124126        /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */
    … …  
    146148        /* Used to determine if the logged in user is a moderator for the current content. */
    147149        $bp->is_item_mod = false;
    148        
    149         $bp->core->image_base = BP_PLUGIN_URL . '/bp-core/images';
     150
    150151        $bp->core->table_name_notifications = $wpdb->base_prefix . 'bp_notifications';
    151152
    … …  
    219220        bp_core_add_illegal_names();
    220221       
    221         // dbDelta won't change character sets, so we need to do this seperately.
    222         // This will only be in here pre v1.0
    223         $wpdb->query( $wpdb->prepare( "ALTER TABLE {$bp->core->table_name_notifications} DEFAULT CHARACTER SET %s", $wpdb->charset ) );
    224        
    225222        update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION );
    226223}
    … …  
    253250add_action( 'admin_menu', 'bp_core_check_installed' );
    254251
    255 
    256 /**
    257  * bp_core_setup_cookies()
    258  *
    259  * Checks if there is a feedback message in the WP cookie, if so, adds a "template_notices" action
    260  * so that the message can be parsed into the template and displayed to the user.
    261  *
    262  * After the message is displayed, it removes the message vars from the cookie so that the message
    263  * is not shown to the user multiple times.
    264  *
    265  * @package BuddyPress Core
    266  * @global $bp_message The message text
    267  * @global $bp_message_type The type of message (error/success)
    268  * @uses setcookie() Sets a cookie value for the user.
    269  */
    270 function bp_core_setup_cookies() {
    271         global $bp_message, $bp_message_type;
    272        
    273         // Render any error/success feedback on the template
    274         if ( $_COOKIE['bp-message'] == '' || !isset( $_COOKIE['bp-message'] ) )
    275                 return false;
    276 
    277         $bp_message = $_COOKIE['bp-message'];
    278         $bp_message_type = $_COOKIE['bp-message-type'];
    279         add_action( 'template_notices', 'bp_core_render_notice' );
    280 
    281         setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
    282         setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
    283 }
    284 add_action( 'init', 'bp_core_setup_cookies' );
    285 
    286 
    287252/**
    288253 * bp_core_add_admin_menu()
    … …  
    335300 * @uses bp_core_add_subnav_item() Adds a sub navigation item to a nav item
    336301 * @uses bp_is_home() Returns true if the current user being viewed is equal the logged in user
    337  * @uses bp_core_get_avatar() Returns the either the thumb (1) or full (2) avatar URL for the user_id passed
     302 * @uses bp_core_fetch_avatar() Returns the either the thumb or full avatar URL for the user_id passed
    338303 */
    339304function bp_core_setup_nav() {
    … …  
    354319                                $bp->bp_options_title = __('My Profile', 'buddypress');
    355320                        } else {
    356                                 $bp->bp_options_avatar = bp_core_get_avatar( $bp->displayed_user->id, 1 );
     321                                $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
    357322                                $bp->bp_options_title = $bp->displayed_user->fullname;
    358323                        }
    … …  
    381346                $bp->current_component = false;
    382347
    383                 wp_enqueue_script( 'bp-core-directory-members', BP_PLUGIN_URL . '/bp-core/js/directory-members.js', array( 'jquery', 'jquery-livequery-pack' ) );
     348                do_action( 'bp_core_action_directory_members' );
    384349                bp_core_load_template( apply_filters( 'bp_core_template_directory_members', 'directories/members/index' ) );
    385350        }
    … …  
    498463        }
    499464}
    500         /* DEPRECATED - use bp_core_new_nav_item() as it's more friendly and allows ordering */
    501         function bp_core_add_nav_item( $name, $slug, $css_id = false, $show_for_displayed_user = true ) {
    502                 bp_core_new_nav_item( array( 'name' => $name, 'slug' => $slug, 'item_css_id' => $css_id, 'show_for_displayed_user' => $show_for_displayed_user ) );
    503         }
     465
    504466
    505467/**
    … …  
    591553                return false;
    592554       
    593         if ( !$user_has_access )
    594                 return false;
    595        
    596555        /* If this is for site admins only and the user is not one, don't create the subnav item */
    597556        if ( $site_admin_only && !is_site_admin() )
    … …  
    609568        );       
    610569               
    611         if ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) {
     570        if ( $bp->current_action == $slug && $bp->current_component == $parent_slug && $user_has_access ) {
    612571                if ( !is_object($screen_function[0]) )
    613572                        add_action( 'wp', $screen_function, 3 );
    … …  
    616575        }
    617576}
    618         /* DEPRECATED - use bp_core_new_subnav_item() as it's more friendly and allows ordering. */
    619         function bp_core_add_subnav_item( $parent_id, $slug, $name, $link, $function, $css_id = false, $user_has_access = true, $admin_only = false ) {
    620                 bp_core_new_subnav_item( array( 'name' => $name, 'slug' => $slug, 'parent_slug' => $parent_id, 'parent_url' => $link, 'item_css_id' => $css_id, 'user_has_access' => $user_has_access, 'site_admin_only' => $admin_only, 'screen_function' => $function ) );
    621         }
    622577
    623578function bp_core_sort_subnav_items() {
    … …  
    799754                return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
    800755}
    801         function bp_core_get_userid_from_user_login( $deprecated ) {
    802                 return bp_core_get_userid( $deprecated );
    803         }
    804756
    805757/**
    … …  
    965917        return apply_filters( 'bp_core_get_user_displayname', stripslashes( strip_tags( trim( $fullname ) ) ) );
    966918}
    967         /* DEPRECATED Use: bp_core_get_user_displayname */
    968         function bp_core_global_user_fullname( $user_id ) { return bp_core_get_user_displayname( $user_id ); }
    969 
    970919
    971920/**
    … …  
    985934}
    986935
    987 
    988936/**
    989937 * bp_core_get_userlink_by_username()
    … …  
    1034982 */
    1035983function bp_core_add_message( $message, $type = false ) {
     984        global $bp;
     985       
    1036986        if ( !$type )
    1037987                $type = 'success';
    1038 
     988       
     989        /* Send the values to the cookie for page reload display */
    1039990        setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH );
    1040991        setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH );
    1041 }
    1042 
    1043 
    1044 /**
    1045  * bp_core_render_notice()
    1046  *
    1047  * Renders a feedback notice (either error or success message) to the theme template.
     992       
     993        /***
     994         * Send the values to the $bp global so we can still output messages
     995         * without a page reload
     996         */
     997        $bp->template_message = $message;
     998        $bp->template_message_type = $type;
     999}
     1000
     1001/**
     1002 * bp_core_setup_message()
     1003 *
     1004 * Checks if there is a feedback message in the WP cookie, if so, adds a "template_notices" action
     1005 * so that the message can be parsed into the template and displayed to the user.
     1006 *
     1007 * After the message is displayed, it removes the message vars from the cookie so that the message
     1008 * is not shown to the user multiple times.
     1009 *
     1010 * @package BuddyPress Core
     1011 * @global $bp_message The message text
     1012 * @global $bp_message_type The type of message (error/success)
     1013 * @uses setcookie() Sets a cookie value for the user.
     1014 */
     1015function bp_core_setup_message() {
     1016        global $bp;
     1017
     1018        if ( empty( $bp->template_message ) )
     1019                $bp->template_message = $_COOKIE['bp-message'];
     1020       
     1021        if ( empty( $bp->template_message_type ) )
     1022                $bp->template_message_type = $_COOKIE['bp-message-type'];
     1023
     1024        add_action( 'template_notices', 'bp_core_render_message' );
     1025       
     1026        setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
     1027        setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
     1028}
     1029add_action( 'wp', 'bp_core_setup_message' );
     1030
     1031/**
     1032 * bp_core_render_message()
     1033 *
     1034 * Renders a feedback message (either error or success message) to the theme template.
    10481035 * The hook action 'template_notices' is used to call this function, it is not called directly.
    10491036 *
    … …  
    10511038 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    10521039 */
    1053 function bp_core_render_notice() {
    1054         if ( $_COOKIE['bp-message'] ) {
    1055                 $type = ( 'success' == $_COOKIE['bp-message-type'] ) ? 'updated' : 'error';
     1040function bp_core_render_message() {
     1041        global $bp;
     1042       
     1043        if ( $bp->template_message ) {
     1044                $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error';
    10561045        ?>
    10571046                <div id="message" class="<?php echo $type; ?>">
    1058                         <p><?php echo stripslashes( $_COOKIE['bp-message'] ); ?></p>
     1047                        <p><?php echo stripslashes( attribute_escape( $bp->template_message ) ); ?></p>
    10591048                </div>
    10601049        <?php
    1061                 do_action( 'bp_core_render_notice' );
    1062         }
    1063 }
    1064 
     1050                do_action( 'bp_core_render_message' );
     1051        }       
     1052}
    10651053
    10661054/**
    … …  
    12661254
    12671255/**
    1268  * bp_core_get_buddypress_themes()
    1269  *
    1270  * Gets an array of all the BuddyPress themes in the /bp-themes/ directory.
    1271  *
    1272  * @package BuddyPress Core
    1273  * @uses get_themes()
    1274  * @return An array containing all of the themes.
    1275  */
    1276 function bp_core_get_buddypress_themes() {
    1277         global $wp_themes;
    1278        
    1279         /* Remove the cached WP themes first */
    1280         $wp_existing_themes = &$wp_themes;
    1281         $wp_themes = null;
    1282        
    1283         add_filter( 'theme_root', 'bp_core_filter_buddypress_theme_root' );
    1284         $themes = get_themes();
    1285 
    1286         if ( $themes ) {
    1287                 foreach ( $themes as $name => $values ) {
    1288                         if ( $name == 'BuddyPress Default Home Theme' )
    1289                                 continue;
    1290                        
    1291                         $member_themes[] = array(
    1292                                 'name' => $name,
    1293                                 'template' => $values['Template'],
    1294                                 'version' => $values['Version']
    1295                         );
    1296                 }
    1297         }
    1298        
    1299         /* Restore the cached WP themes */
    1300         $wp_themes = $wp_existing_themes;
    1301        
    1302         return $member_themes;
    1303 }
    1304 function bp_core_get_member_themes() { return bp_core_get_buddypress_themes(); } // DEPRECATED
    1305 
    1306 
    1307 /**
    1308  * bp_get_buddypress_theme_uri()
    1309  *
    1310  * Get the url of the selected BuddyPress theme.
    1311  *
    1312  * @package BuddyPress Core
    1313  */
    1314 function bp_get_buddypress_theme_uri() {
    1315         return apply_filters( 'bp_get_buddypress_theme_uri', WP_CONTENT_URL . '/bp-themes/' . get_site_option( 'active-member-theme' ) );
    1316 }
    1317 
    1318 
    1319 /**
    1320  * bp_get_buddypress_theme_path()
    1321  *
    1322  * Get the path of the selected BuddyPress theme.
    1323  *
    1324  * @package BuddyPress Core
    1325  */
    1326 function bp_get_buddypress_theme_path() {
    1327         return apply_filters( 'bp_get_buddypress_theme_path', WP_CONTENT_DIR . '/bp-themes/' . get_site_option( 'active-member-theme' ) );
    1328 }
    1329 
    1330 
    1331 /**
    1332  * bp_core_filter_buddypress_theme_root()
    1333  *
    1334  * Adds a filter that changes the root path of the theme directory to the bp-themes directory.
    1335  *
    1336  * @package BuddyPress Core
    1337  */
    1338 function bp_core_filter_buddypress_theme_root() {
    1339         return apply_filters( 'bp_core_filter_buddypress_theme_root', WP_CONTENT_DIR . "/bp-themes" );
    1340 }
    1341 
    1342 
    1343 /**
    1344  * bp_core_filter_buddypress_theme_root_uri()
    1345  *
    1346  * Adds a filter that changes the root URI of the theme directory to the bp-themes directory.
    1347  *
    1348  * @package BuddyPress Core
    1349  */
    1350 function bp_core_filter_buddypress_theme_root_uri() {
    1351         return apply_filters( 'bp_core_filter_buddypress_theme_root_uri', WP_CONTENT_URL . '/bp-themes' );
    1352 }
    1353 
    1354 
    1355 /**
    13561256 * bp_core_add_illegal_names()
    13571257 *
    … …  
    13831283        update_site_option( 'illegal_names', $new );
    13841284}
    1385 
    13861285
    13871286/**
    … …  
    16291528add_action ( 'plugins_loaded', 'bp_core_load_buddypress_textdomain', 9 );
    16301529
     1530function bp_core_add_ajax_hook() {
     1531        do_action( 'wp_ajax_' . $_REQUEST['action'] );
     1532}
     1533add_action( 'init', 'bp_core_add_ajax_hook' );
    16311534
    16321535/**
Note: See TracChangeset for help on using the changeset viewer.