Skip to:
Content

bbPress.org

Changeset 1562


Ignore:
Timestamp:
06/21/2008 05:10:20 AM (17 years ago)
Author:
sambauers
Message:
  • Some re-organisation of bb-settings.
  • More sane treatment of BB_INSTALLING constant.
  • Add additional $_SERVER stabilisation code from WordPress
  • Start of PHPdoc for bb-settings
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/functions.php

    r1561 r1562  
    17231723
    17241724    if ( false === $r = wp_cache_get( $option, 'bb_option' ) ) {
    1725         //if ( defined( 'BB_INSTALLING' ) ) $bbdb->return_errors();
     1725        //if ( BB_INSTALLING ) $bbdb->return_errors();
    17261726        $row = $bbdb->get_row( $bbdb->prepare( "SELECT meta_value FROM $bbdb->meta WHERE object_type = 'bb_option' AND meta_key = %s", $option ) );
    1727         //if ( defined( 'BB_INSTALLING' ) ) $bbdb->show_errors();
     1727        //if ( BB_INSTALLING ) $bbdb->show_errors();
    17281728
    17291729        if ( is_object($row) ) {
     
    25282528       
    25292529        $uri = false;
    2530         if ( function_exists('bb_get_option') && ( !defined('BB_INSTALLING') || !BB_INSTALLING ) )
     2530        if ( function_exists('bb_get_option') && !BB_INSTALLING )
    25312531            $uri = bb_get_option('uri');
    25322532       
  • trunk/bb-includes/pluggable.php

    r1504 r1562  
    5050//This is only used at initialization.  Use bb_get_current_user_info() (or $bb_current_user global if really needed) to grab user info.
    5151function bb_current_user() {
    52     if ( defined( 'BB_INSTALLING' ) )
     52    if (BB_INSTALLING)
    5353        return false;
    5454
     
    243243        $salt = BB_SECRET_SALT;
    244244    } else {
    245         if (!defined('BB_INSTALLING')) {
     245        if (!BB_INSTALLING) {
    246246            $salt = bb_get_option('secret');
    247247            if ( empty($salt) ) {
     
    382382        return false;
    383383
    384     if ( defined( 'BB_INSTALLING' ) ) {
     384    if (BB_INSTALLING) {
    385385        bb_update_usermeta( $user['ID'], $bbdb->prefix . 'capabilities', array('keymaster' => true) );
    386386    } else {       
  • trunk/bb-settings.php

    r1561 r1562  
    11<?php
     2/**
     3 * Used to setup and fix common variables and include
     4 * the bbPress and BackPress procedural and class libraries.
     5 *
     6 * You should not have to change this file, some configuration
     7 * is possible in bb-config.php
     8 *
     9 * @package bbPress
     10 */
     11
     12
     13
     14/**
     15 * Low level reasons to die
     16 */
     17
     18// Die if PHP is not new enough
    219if ( version_compare(PHP_VERSION, '4.3', '<') )
    320    die(sprintf('Your server is running PHP version %s but bbPress requires at least 4.3', PHP_VERSION) );
    421
     22// Die if called directly
     23if ( !defined('BB_PATH') )
     24    die('This file cannot be called directly.');
     25
     26// Die if there is no database table prefix
    527if ( !$bb_table_prefix )
    628    die('You must specify a table prefix in your <code>bb-config.php</code> file.');
    729
    8 if ( !defined('BB_PATH') )
    9     die('This file cannot be called directly.');
    10 
    11 // Turn register globals off
     30
     31
     32// Modify error reporting levels to exclude PHP notices
     33error_reporting(E_ALL ^ E_NOTICE);
     34
     35/**
     36 * bb_unregister_GLOBALS() - Turn register globals off
     37 *
     38 * @access private
     39 * @return null Will return null if register_globals PHP directive was disabled
     40 */
    1241function bb_unregister_GLOBALS() {
    1342    if ( !ini_get('register_globals') )
     
    2756        }
    2857}
    29 
    3058bb_unregister_GLOBALS();
    3159
     60
     61
     62/**
     63 * bb_timer_start() - PHP 4 standard microtime start capture
     64 *
     65 * @access private
     66 * @global int $bb_timestart Seconds and Microseconds added together from when function is called
     67 * @return bool Always returns true
     68 */
    3269function bb_timer_start() {
    3370    global $bb_timestart;
     
    3875bb_timer_start();
    3976
     77
     78
     79/**
     80 * Whether the server software is IIS or something else
     81 * @global bool $is_IIS
     82 */
    4083$is_IIS = strstr($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') ? 1 : 0;
     84
     85
     86
     87/**
     88 * Stabilise $_SERVER variables in various PHP environments
     89 */
     90
    4191// Fix for IIS, which doesn't set REQUEST_URI
    4292if ( empty( $_SERVER['REQUEST_URI'] ) ) {
    43     $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; // Does this work under CGI?
    44 
    45     // Append the query string if it exists and isn't null
    46     if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
    47         $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    48 }
    49 
    50 // Modify error reporting levels
    51 error_reporting(E_ALL ^ E_NOTICE);
    52 
     93
     94    // IIS Mod-Rewrite
     95    if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
     96        $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
     97    }
     98    // IIS Isapi_Rewrite
     99    else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
     100        $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
     101    }
     102    else
     103    {
     104        // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
     105        if ( isset($_SERVER['PATH_INFO']) ) {
     106            if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
     107                $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
     108            else
     109                $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
     110        }
     111
     112        // Append the query string if it exists and isn't null
     113        if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
     114            $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
     115        }
     116    }
     117}
     118
     119// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
     120if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
     121    $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
     122
     123// Fix for Dreamhost and other PHP as CGI hosts
     124if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
     125    unset($_SERVER['PATH_INFO']);
     126
     127// Fix empty PHP_SELF
     128$PHP_SELF = $_SERVER['PHP_SELF'];
     129if ( empty($PHP_SELF) )
     130    $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
     131
     132
     133
     134/**
     135 * Let bbPress know where we are, or aren't
     136 */
     137
     138/**
     139 * Whether the current script is in the admin area or not
     140 */
    53141if ( !defined( 'BB_IS_ADMIN' ) )
    54142    define( 'BB_IS_ADMIN', false );
     143
     144/**
     145 * Whether the current script is part of the installation process or not
     146 * @since 1.0-beta
     147 */
     148if ( !defined( 'BB_INSTALLING' ) )
     149    define( 'BB_INSTALLING', false );
     150
     151
    55152
    56153// Define the include path
     
    71168    define( 'BB_DATABASE_CLASS', 'BPDB_Multi' );
    72169
    73 function bb_init_bbdb() {
    74     global $bbdb;
    75    
    76     $bbdb_class = BB_DATABASE_CLASS;
    77     $bbdb =& new $bbdb_class( array(
    78         'name' => BBDB_NAME,
    79         'user' => BBDB_USER,
    80         'password' => BBDB_PASSWORD,
    81         'host' => BBDB_HOST,
    82         'charset' => defined( 'BBDB_CHARSET' ) ? BBDB_CHARSET : false,
    83         'collate' => defined( 'BBDB_COLLATE' ) ? BBDB_COLLATE : false
    84     ) );
    85     unset($bbdb_class);
    86    
    87     $bbdb->tables = array(
    88         'forums'             => false,
    89         'meta'               => false,
    90         'posts'              => false,
    91         'tagged'             => false, // Deprecated
    92         'tags'               => false, // Deprecated
    93         'terms'              => false,
    94         'term_relationships' => false,
    95         'term_taxonomy'      => false,
    96         'topics'             => false,
    97         'topicmeta'          => false, // Deprecated
    98         'users'              => false,
    99         'usermeta'           => false
    100     );
    101 }
    102 
    103 bb_init_bbdb();
    104 
     170$bbdb_class = BB_DATABASE_CLASS;
     171$bbdb =& new $bbdb_class( array(
     172    'name' => BBDB_NAME,
     173    'user' => BBDB_USER,
     174    'password' => BBDB_PASSWORD,
     175    'host' => BBDB_HOST,
     176    'charset' => defined( 'BBDB_CHARSET' ) ? BBDB_CHARSET : false,
     177    'collate' => defined( 'BBDB_COLLATE' ) ? BBDB_COLLATE : false
     178) );
     179unset($bbdb_class);
     180
     181$bbdb->tables = array(
     182    'forums'             => false,
     183    'meta'               => false,
     184    'posts'              => false,
     185    'tagged'             => false, // Deprecated
     186    'tags'               => false, // Deprecated
     187    'terms'              => false,
     188    'term_relationships' => false,
     189    'term_taxonomy'      => false,
     190    'topics'             => false,
     191    'topicmeta'          => false, // Deprecated
     192    'users'              => false,
     193    'usermeta'           => false
     194);
    105195
    106196// Define BackPress Database errors if not already done - no internationalisation at this stage
     
    172262    require( BB_COMMUNITIES_INCLUDE );
    173263
    174 if ( !bb_is_installed() && ( !defined('BB_INSTALLING') || !BB_INSTALLING ) ) {
     264if ( !BB_INSTALLING && !bb_is_installed() ) {
    175265    $link = preg_replace('|(/bb-admin)?/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'bb-admin/install.php';
    176266    require( BB_PATH . BB_INC . 'pluggable.php');
     
    182272// TODO: consider seperating into external upgrade script for 1.0
    183273$bbdb->suppress_errors();
    184 if ( ( !defined('BB_INSTALLING') || !BB_INSTALLING ) && !bb_get_option_from_db( 'bb_db_version' ) ) {
     274if ( !BB_INSTALLING && !bb_get_option_from_db( 'bb_db_version' ) ) {
    185275    $meta_exists = $bbdb->query("SELECT * FROM $bbdb->meta LIMIT 1");
    186276    if (!$meta_exists) {
     
    208298unset($o, $oo);
    209299
    210 if ( defined('BB_INSTALLING') && BB_INSTALLING )
    211 foreach ( array('active_plugins') as $i )
    212     $bb->$i = false;
    213 unset($i);
     300if ( BB_INSTALLING ) {
     301    foreach ( array('active_plugins') as $i )
     302        $bb->$i = false;
     303    unset($i);
     304}
    214305
    215306require( BB_PATH . BB_INC . 'formatting-functions.php');
     
    262353}
    263354// Die if no URI
    264 if ( ( !defined('BB_INSTALLING') || !BB_INSTALLING ) && !$bb->uri ) {
     355if ( !BB_INSTALLING && !$bb->uri ) {
    265356    bb_die( __('Could not determine site URI') );
    266357}
Note: See TracChangeset for help on using the changeset viewer.