Changeset 6285 for trunk/bp-loader.php
- Timestamp:
- 09/03/2012 12:33:13 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/bp-loader.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-loader.php
r6275 r6285 35 35 class BuddyPress { 36 36 37 /** 38 * Note to Plugin and Theme authors: 39 * 40 * Do not directly reference the variables below in your code. Their names 41 * and locations in the BuddyPress class are subject to change at any time. 42 * 43 * Most of them have reference functions located in bp-core-functions.php. 44 * The ones that don't can be accessed via their respective WordPress API's. 45 * 46 * Components are encouraged to store their data in the $bp global rather 47 * than new globals to keep all BuddyPress data in one place. 48 */ 49 50 /** Version ***************************************************************/ 51 52 /** 53 * @var string BuddyPress version 54 */ 55 public $version = '1.7-bleeding-6275'; 56 57 /** 58 * @var int Database version of current BuddyPress files 59 */ 60 public $db_version = 6066; 61 62 /** 63 * @var int Database version raw from database connection 64 */ 65 public $db_version_raw = 0; 66 67 /** 68 * @var string State of BuddyPress installation 69 */ 70 public $maintenance_mode = ''; 71 72 /** 73 * @var bool Include deprecated BuddyPress files or not 74 */ 75 public $load_deprecated = true; 76 77 /** Root ******************************************************************/ 78 79 /** 80 * @var int The root blog ID 81 */ 82 public $root_blog_id = 1; 83 84 /** Paths *****************************************************************/ 85 86 /** 87 * The absolute path and filename of this file. 88 * 89 * @since BuddyPress (1.6) 90 * @var string 91 */ 92 public $file; 93 94 /** 95 * @var string Basename of the BuddyPress plugin directory 96 */ 97 public $basename = ''; 98 99 /** 100 * @var string Absolute path to the BuddyPress plugin directory 101 */ 102 public $plugin_dir = ''; 103 104 /** 105 * @var string Absolute path to the BuddyPress themes directory 106 */ 107 public $themes_dir = ''; 108 109 /** 110 * @var string Absolute path to the BuddyPress language directory 111 */ 112 public $lang_dir = ''; 113 114 /** URLs ******************************************************************/ 115 116 /** 117 * @var string URL to the BuddyPress plugin directory 118 */ 119 public $plugin_url = ''; 120 121 /** 122 * @var string URL to the BuddyPress themes directory 123 */ 124 public $themes_url = ''; 125 126 /** Users *****************************************************************/ 127 128 /** 129 * @var object Current user 130 */ 131 public $current_user = null; 132 133 /** 134 * @var object Displayed user 135 */ 136 public $displayed_user = null; 137 138 /** Navigation ************************************************************/ 37 /** Magic *****************************************************************/ 38 39 /** 40 * BuddyPress uses many variables, most of which can be filtered to customize 41 * the way that it works. To prevent unauthorized access, these variables 42 * are stored in a private array that is magically updated using PHP 5.2+ 43 * methods. This is to prevent third party plugins from tampering with 44 * essential information indirectly, which would cause issues later. 45 * 46 * @see BuddyPress::setup_globals() 47 * @var array 48 */ 49 private $data; 50 51 /** Not Magic *************************************************************/ 139 52 140 53 /** … … 147 60 */ 148 61 public $bp_options_nav = array(); 149 150 /** Toolbar ***************************************************************/151 152 /**153 * @var string The primary toolbar ID154 */155 public $my_account_menu_id = '';156 157 /** URI's *****************************************************************/158 62 159 63 /** … … 162 66 */ 163 67 public $unfiltered_uri = array(); 164 165 /**166 * @var int The current offset of the URI167 * @see bp_core_set_uri_globals()168 */169 public $unfiltered_uri_offset = 0;170 171 /**172 * @var bool Are status headers already sent?173 */174 public $no_status_set = false;175 68 176 69 /** … … 181 74 public $canonical_stack = array(); 182 75 183 /** Components ************************************************************/184 185 /**186 * @var string Name of the current BuddyPress component (primary)187 */188 public $current_component = '';189 190 /**191 * @var string Name of the current BuddyPress item (secondary)192 */193 public $current_item = '';194 195 /**196 * @var string Name of the current BuddyPress action (tertiary)197 */198 public $current_action = '';199 200 76 /** 201 77 * @var array Additional navigation elements (supplemental) … … 204 80 205 81 /** 206 * @var bool Displaying custom 2nd level navigation menu (I.E a group) 207 */ 208 public $is_single_item = false; 82 * @var array Required components (core, members) 83 */ 84 public $required_components = array(); 85 86 /** 87 * @var array Additional active components 88 */ 89 public $loaded_components = array(); 209 90 210 91 /** Option Overload *******************************************************/ … … 215 96 public $options = array(); 216 97 217 /** Functions *************************************************************/ 218 219 /** 220 * The main BuddyPress loader 221 * 222 * @since BuddyPress (1.6) 223 * 224 * @uses BuddyPress::constants() Setup legacy constants 225 * @uses BuddyPress::setup_globals() Setup globals needed 226 * @uses BuddyPress::includes() Includ required files 227 * @uses BuddyPress::setup_actions() Setup hooks and actions 228 */ 229 public function __construct() { 230 $this->constants(); 231 $this->setup_globals(); 232 $this->includes(); 233 $this->setup_actions(); 234 } 98 /** Singleton *************************************************************/ 99 100 /** 101 * @var BuddyPress The one true BuddyPress 102 */ 103 private static $instance; 104 105 /** 106 * Main BuddyPress Instance 107 * 108 * BuddyPress is great 109 * Please load it only one time 110 * For this, we thank you 111 * 112 * Insures that only one instance of BuddyPress exists in memory at any one 113 * time. Also prevents needing to define globals all over the place. 114 * 115 * @since BuddyPress (1.7) 116 * 117 * @staticvar array $instance 118 * @uses BuddyPress::constants() Setup the constants (mostly deprecated) 119 * @uses BuddyPress::setup_globals() Setup the globals needed 120 * @uses BuddyPress::includes() Include the required files 121 * @uses BuddyPress::setup_actions() Setup the hooks and actions 122 * @see buddypress() 123 * 124 * @return The one true BuddyPress 125 */ 126 public static function instance() { 127 if ( ! isset( self::$instance ) ) { 128 self::$instance = new BuddyPress; 129 self::$instance->constants(); 130 self::$instance->setup_globals(); 131 self::$instance->includes(); 132 self::$instance->setup_actions(); 133 } 134 return self::$instance; 135 } 136 137 /** Magic Methods *********************************************************/ 138 139 /** 140 * A dummy constructor to prevent BuddyPress from being loaded more than once. 141 * 142 * @since BuddyPress (1.7) 143 * @see BuddyPress::instance() 144 * @see buddypress() 145 */ 146 private function __construct() { /* Do nothing here */ } 147 148 /** 149 * A dummy magic method to prevent BuddyPress from being cloned 150 * 151 * @since BuddyPress (1.7) 152 */ 153 public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'buddypress' ), '1.7' ); } 154 155 /** 156 * A dummy magic method to prevent BuddyPress from being unserialized 157 * 158 * @since BuddyPress (1.7) 159 */ 160 public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'buddypress' ), '1.7' ); } 161 162 /** 163 * Magic method for checking the existence of a certain custom field 164 * 165 * @since BuddyPress (1.7) 166 */ 167 public function __isset( $key ) { return isset( $this->data[$key] ); } 168 169 /** 170 * Magic method for getting BuddyPress varibles 171 * 172 * @since BuddyPress (1.7) 173 */ 174 public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; } 175 176 /** 177 * Magic method for setting BuddyPress varibles 178 * 179 * @since BuddyPress (1.7) 180 */ 181 public function __set( $key, $value ) { $this->data[$key] = $value; } 182 183 /** Private Methods *******************************************************/ 235 184 236 185 /** … … 316 265 private function setup_globals() { 317 266 267 /** Versions **********************************************************/ 268 269 $this->version = '1.7-bleeding-6275'; 270 $this->db_version = 6066; 271 272 /** Loading ***********************************************************/ 273 274 $this->maintenance_mode = ''; 275 $this->load_deprecated = true; 276 277 /** Toolbar ***********************************************************/ 278 279 /** 280 * @var string The primary toolbar ID 281 */ 282 $this->my_account_menu_id = ''; 283 284 /** URI's *************************************************************/ 285 286 /** 287 * @var int The current offset of the URI 288 * @see bp_core_set_uri_globals() 289 */ 290 $this->unfiltered_uri_offset = 0; 291 292 /** 293 * @var bool Are status headers already sent? 294 */ 295 $this->no_status_set = false; 296 297 /** Components ********************************************************/ 298 299 /** 300 * @var string Name of the current BuddyPress component (primary) 301 */ 302 $this->current_component = ''; 303 304 /** 305 * @var string Name of the current BuddyPress item (secondary) 306 */ 307 $this->current_item = ''; 308 309 /** 310 * @var string Name of the current BuddyPress action (tertiary) 311 */ 312 $this->current_action = ''; 313 314 /** 315 * @var bool Displaying custom 2nd level navigation menu (I.E a group) 316 */ 317 $this->is_single_item = false; 318 318 319 /** Root **************************************************************/ 319 320 … … 336 337 $this->lang_dir = $this->plugin_dir . 'bp-languages'; 337 338 339 /** Theme Compat ******************************************************/ 340 341 $this->theme_compat = new stdClass(); // Base theme compatibility class 342 $this->filters = new stdClass(); // Used when adding/removing filters 343 338 344 /** Users *************************************************************/ 339 345 … … 368 374 $versions['1.5-multi'] = get_site_option( 'bp-db-version' ); 369 375 $versions['1.6-multi'] = get_site_option( '_bp_db_version' ); 370 $versions['1.5-single'] = get_blog_option( $this->root_blog_id, 'bp-db-version');376 $versions['1.5-single'] = get_blog_option( $this->root_blog_id, 'bp-db-version' ); 371 377 372 378 // Remove empty array items … … 412 418 if ( empty( $this->maintenance_mode ) ) { 413 419 420 // Theme compatability 421 require( $this->plugin_dir . 'bp-core/bp-core-template-loader.php' ); 422 require( $this->plugin_dir . 'bp-core/bp-core-theme-compatibility.php' ); 423 414 424 // Require all of the BuddyPress core libraries 425 require( $this->plugin_dir . 'bp-core/bp-core-dependency.php' ); 415 426 require( $this->plugin_dir . 'bp-core/bp-core-actions.php' ); 416 427 require( $this->plugin_dir . 'bp-core/bp-core-caps.php' ); … … 462 473 // Array of BuddyPress core actions 463 474 $actions = array( 475 'setup_theme', // Setup the default theme compat 464 476 'setup_current_user', // Setup currently logged in user 465 477 'register_post_types', // Register post types … … 468 480 'register_views', // Register the views 469 481 'register_theme_directory', // Register the theme directory 482 'register_theme_packages', // Register bundled theme packages (bp-themes) 470 483 'load_textdomain', // Load textdomain 471 484 'add_rewrite_tags', // Add rewrite tags … … 480 493 register_theme_directory( $this->themes_dir ); 481 494 } 495 496 /** Public Methods ********************************************************/ 497 498 /** 499 * Register bundled theme packages 500 * 501 * Note that since we currently have complete control over bp-themes and 502 * the bp-legacy folders, it's fine to hardcode these here. If at a 503 * later date we need to automate this, an API will need to be built. 504 * 505 * @since BuddyPress (1.7) 506 */ 507 public function register_theme_packages() { 508 bp_register_theme_package( array( 509 'id' => 'legacy', 510 'name' => __( 'BuddyPress Default', 'buddypress' ), 511 'version' => bp_get_version(), 512 'dir' => trailingslashit( $this->themes_dir . '/bp-legacy' ), 513 'url' => trailingslashit( $this->themes_url . '/bp-legacy' ) 514 ) ); 515 } 516 517 /** 518 * Setup the default BuddyPress theme compatability location. 519 * 520 * @since BuddyPress (1.7) 521 */ 522 public function setup_theme() { 523 524 // Bail if something already has this under control 525 if ( ! empty( $this->theme_compat->theme ) ) 526 return; 527 528 // Setup the theme package to use for compatibility 529 bp_setup_theme_compat( bp_get_theme_package_id() ); 530 } 482 531 } 483 532 484 // "And now for something completely different" 485 $GLOBALS['bp'] = new BuddyPress; 533 /** 534 * The main function responsible for returning the one true BuddyPress Instance 535 * to functions everywhere. 536 * 537 * Use this function like you would a global variable, except without needing 538 * to declare the global. 539 * 540 * Example: <?php $bp = buddypress(); ?> 541 * 542 * @return The one true BuddyPress Instance 543 */ 544 function buddypress() { 545 return buddypress::instance(); 546 } 547 548 /** 549 * Hook BuddyPress early onto the 'plugins_loaded' action. 550 * 551 * This gives all other plugins the chance to load before BuddyPress, to get 552 * their actions, filters, and overrides setup without BuddyPress being in the 553 * way. 554 */ 555 if ( defined( 'BUDDYPRESS_LATE_LOAD' ) ) { 556 add_action( 'plugins_loaded', 'buddypress', (int) BUDDYPRESS_LATE_LOAD ); 557 558 // "And now here's something we hope you'll really like!" 559 } else { 560 $GLOBALS['bp'] = &buddypress(); 561 } 486 562 487 563 endif; 488 489 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)