diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index a6a6dcb563..c66935d84a 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -171,26 +171,25 @@ function adm_page_footer($copyright_html = true) global $starttime; // Output page creation time - if (defined('DEBUG')) + if (phpbb::$base_config['debug']) { $mtime = explode(' ', microtime()); $totaltime = $mtime[0] + $mtime[1] - $starttime; - if (phpbb_request::variable('explain', false) && phpbb::$acl->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists(phpbb::$db, 'sql_report')) + if (phpbb_request::variable('explain', false) && phpbb::$acl->acl_get('a_') && phpbb::$base_config['debug_extra'] && method_exists(phpbb::$db, 'sql_report')) { phpbb::$db->sql_report('display'); } $debug_output = sprintf('Time : %.3fs | ' . phpbb::$db->sql_num_queries() . ' Queries | GZIP : ' . ((phpbb::$config['gzip_compress']) ? 'On' : 'Off') . ((phpbb::$user->system['load']) ? ' | Load : ' . phpbb::$user->system['load'] : ''), $totaltime); - if (phpbb::$acl->acl_get('a_') && defined('DEBUG_EXTRA')) + if (phpbb::$acl->acl_get('a_') && phpbb::$base_config['debug_extra']) { if (function_exists('memory_get_usage')) { if ($memory_usage = memory_get_usage()) { - global $base_memory_usage; - $memory_usage -= $base_memory_usage; + $memory_usage -= phpbb::$base_config['memory_usage']; $memory_usage = get_formatted_filesize($memory_usage); $debug_output .= ' | Memory Usage: ' . $memory_usage; @@ -202,7 +201,7 @@ function adm_page_footer($copyright_html = true) } phpbb::$template->assign_vars(array( - 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '', + 'DEBUG_OUTPUT' => (phpbb::$base_config['debug']) ? $debug_output : '', 'TRANSLATION_INFO' => (!empty(phpbb::$user->lang['TRANSLATION_INFO'])) ? phpbb::$user->lang['TRANSLATION_INFO'] : '', 'S_COPYRIGHT_HTML' => $copyright_html, 'VERSION' => phpbb::$config['version']) diff --git a/phpBB/adm/swatch.php b/phpBB/adm/swatch.php index 7ee6d7d0c0..a7ece7e30d 100644 --- a/phpBB/adm/swatch.php +++ b/phpBB/adm/swatch.php @@ -23,7 +23,7 @@ $auth->acl($user->data); $user->setup(); // Set custom template for admin area -$template->set_custom_template(PHPBB_ROOT_PATH . CONFIG_ADM_FOLDER . '/style', 'admin'); +$template->set_custom_template(PHPBB_ROOT_PATH . phpbb::$base_config['admin_folder'] . '/style', 'admin'); $template->set_filenames(array( 'body' => 'colour_swatch.html') diff --git a/phpBB/common.php b/phpBB/common.php index b0db9ad5b2..aa72b83612 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) require PHPBB_ROOT_PATH . 'includes/core/bootstrap.' . PHP_EXT; // Run through remaining Framework states -if (defined('PHPBB_CONFIG_MISSING') || !defined('PHPBB_INSTALLED')) +if (!phpbb::$base_config['config_set'] || !phpbb::$base_config['installed']) { // Redirect the user to the installer // We have to generate a full HTTP/1.1 header here since we can't guarantee to have any of the information @@ -66,16 +66,16 @@ phpbb_request::disable_super_globals(); // @todo Syndicate config variables somehow and check them here. It would be also nice to not have so many global vars from the config file (means: re-think layout of config file, maybe require phpbb:: to be set) -if (!empty($dbms)) +if (!empty(phpbb::$base_config['dbms'])) { // Register DB object. - phpbb::assign('db', phpbb_db_dbal::connect($dbms, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false)); + phpbb::assign('db', phpbb_db_dbal::connect(phpbb::$base_config['dbms'], phpbb::$base_config['dbhost'], phpbb::$base_config['dbuser'], phpbb::$base_config['dbpasswd'], phpbb::$base_config['dbname'], phpbb::$base_config['dbport'], false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false)); } // We do not need the db password any longer, unset for safety purposes -if (!empty($dbpasswd)) +if (!empty(phpbb::$base_config['dbpasswd'])) { - unset($dbpasswd); + unset(phpbb::$base_config['dbpasswd']); } // Register Cache Manager diff --git a/phpBB/includes/acm/bootstrap.php b/phpBB/includes/acm/bootstrap.php index 849f3e3863..ea671706e5 100644 --- a/phpBB/includes/acm/bootstrap.php +++ b/phpBB/includes/acm/bootstrap.php @@ -16,15 +16,6 @@ if (!defined('IN_PHPBB')) exit; } -/** -* Define missing ACM config variable... if not initialized yet -* @ignore -*/ -if (!defined('CONFIG_ACM_TYPE')) -{ - define('CONFIG_ACM_TYPE', 'file'); -} - /** * Base cache class. * @@ -63,6 +54,9 @@ class phpbb_acm /** * Magic method for calling type-specific functions. * Functions directly supported are: get(), put(), exists(), destroy() + * + * The type is added to the methods name, for getting sql data just use get_sql() for example. + * * see {@link phpbb_acm_abstract phpbb_acm_abstract} for more information * * @access public @@ -176,8 +170,10 @@ class phpbb_acm * @return bool Returns true on success, else false. * @access public */ - public function register($cache_type, $cache_append = false, $cache_object = CONFIG_ACM_TYPE) + public function register($cache_type, $cache_append = false, $cache_object = false) { + $cache_object = ($cache_object === false) ? basename(phpbb::$base_config['acm_type']) : basename($cache_object); + // We need to init every cache type... if (!isset($this->cache_types[$cache_type])) { diff --git a/phpBB/includes/classes/session.php b/phpBB/includes/classes/session.php index 616f85b349..e5f4bd8e0c 100644 --- a/phpBB/includes/classes/session.php +++ b/phpBB/includes/classes/session.php @@ -1265,7 +1265,7 @@ abstract class phpbb_session if ($user_ip !== $session_ip || $user_browser !== $session_browser || $user_forwarded_for !== $session_forwarded_for || !$referer_valid) { // Added logging temporarly to help debug bugs... - if (defined('DEBUG_EXTRA') && $this->data['user_id'] != ANONYMOUS && $log_failure) + if (phpbb::$base_config['debug_extra'] && $this->data['user_id'] != ANONYMOUS && $log_failure) { if ($referer_valid) { diff --git a/phpBB/includes/classes/template.php b/phpBB/includes/classes/template.php index f574f4d9fb..a3277475cf 100644 --- a/phpBB/includes/classes/template.php +++ b/phpBB/includes/classes/template.php @@ -236,7 +236,7 @@ class phpbb_template $recompile = (!file_exists($filename) || @filesize($filename) === 0 || (phpbb::$config['load_tplcompile'] && @filemtime($filename) < filemtime($this->files[$handle]))) ? true : false; - if (defined('DEBUG_EXTRA')) + if (phpbb::$base_config['debug_extra']) { $recompile = true; } diff --git a/phpBB/includes/classes/user.php b/phpBB/includes/classes/user.php index a050c43fbb..d4d083916c 100644 --- a/phpBB/includes/classes/user.php +++ b/phpBB/includes/classes/user.php @@ -457,7 +457,7 @@ class phpbb_user extends phpbb_session // Disable board if the install/ directory is still present // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally - if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists(PHPBB_ROOT_PATH . 'install')) + if (!phpbb::$base_config['debug_extra'] && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists(PHPBB_ROOT_PATH . 'install')) { // Adjust the message slightly according to the permissions if (phpbb::$acl->acl_gets('a_', 'm_') || phpbb::$acl->acl_getf_global('m_')) diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index c62e50d481..f4863bd24f 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -173,69 +173,68 @@ define('REFERER_VALIDATE_PATH', 2); define('VOTE_CONVERTED', 127); // Table names -define('ACL_GROUPS_TABLE', $table_prefix . 'acl_groups'); -define('ACL_OPTIONS_TABLE', $table_prefix . 'acl_options'); -define('ACL_ROLES_DATA_TABLE', $table_prefix . 'acl_roles_data'); -define('ACL_ROLES_TABLE', $table_prefix . 'acl_roles'); -define('ACL_USERS_TABLE', $table_prefix . 'acl_users'); -define('ATTACHMENTS_TABLE', $table_prefix . 'attachments'); -define('BANLIST_TABLE', $table_prefix . 'banlist'); -define('BBCODES_TABLE', $table_prefix . 'bbcodes'); -define('BOOKMARKS_TABLE', $table_prefix . 'bookmarks'); -define('BOTS_TABLE', $table_prefix . 'bots'); -define('CONFIG_TABLE', $table_prefix . 'config'); -define('CONFIRM_TABLE', $table_prefix . 'confirm'); -define('DISALLOW_TABLE', $table_prefix . 'disallow'); -define('DRAFTS_TABLE', $table_prefix . 'drafts'); -define('EXTENSIONS_TABLE', $table_prefix . 'extensions'); -define('EXTENSION_GROUPS_TABLE', $table_prefix . 'extension_groups'); -define('FORUMS_TABLE', $table_prefix . 'forums'); -define('FORUMS_ACCESS_TABLE', $table_prefix . 'forums_access'); -define('FORUMS_TRACK_TABLE', $table_prefix . 'forums_track'); -define('FORUMS_WATCH_TABLE', $table_prefix . 'forums_watch'); -define('GROUPS_TABLE', $table_prefix . 'groups'); -define('ICONS_TABLE', $table_prefix . 'icons'); -define('LANG_TABLE', $table_prefix . 'lang'); -define('LOG_TABLE', $table_prefix . 'log'); -define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); -define('MODULES_TABLE', $table_prefix . 'modules'); -define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); -define('POLL_VOTES_TABLE', $table_prefix . 'poll_votes'); -define('POSTS_TABLE', $table_prefix . 'posts'); -define('PRIVMSGS_TABLE', $table_prefix . 'privmsgs'); -define('PRIVMSGS_FOLDER_TABLE', $table_prefix . 'privmsgs_folder'); -define('PRIVMSGS_RULES_TABLE', $table_prefix . 'privmsgs_rules'); -define('PRIVMSGS_TO_TABLE', $table_prefix . 'privmsgs_to'); -define('PROFILE_FIELDS_TABLE', $table_prefix . 'profile_fields'); -define('PROFILE_FIELDS_DATA_TABLE', $table_prefix . 'profile_fields_data'); -define('PROFILE_FIELDS_LANG_TABLE', $table_prefix . 'profile_fields_lang'); -define('PROFILE_LANG_TABLE', $table_prefix . 'profile_lang'); -define('RANKS_TABLE', $table_prefix . 'ranks'); -define('REPORTS_TABLE', $table_prefix . 'reports'); -define('REPORTS_REASONS_TABLE', $table_prefix . 'reports_reasons'); -define('SEARCH_RESULTS_TABLE', $table_prefix . 'search_results'); -define('SEARCH_WORDLIST_TABLE', $table_prefix . 'search_wordlist'); -define('SEARCH_WORDMATCH_TABLE', $table_prefix . 'search_wordmatch'); -define('SESSIONS_TABLE', $table_prefix . 'sessions'); -define('SESSIONS_KEYS_TABLE', $table_prefix . 'sessions_keys'); -define('SITELIST_TABLE', $table_prefix . 'sitelist'); -define('SMILIES_TABLE', $table_prefix . 'smilies'); -define('STYLES_TABLE', $table_prefix . 'styles'); -define('STYLES_TEMPLATE_TABLE', $table_prefix . 'styles_template'); -define('STYLES_THEME_TABLE', $table_prefix . 'styles_theme'); -define('STYLES_IMAGESET_TABLE', $table_prefix . 'styles_imageset'); -define('STYLES_IMAGESET_DATA_TABLE',$table_prefix . 'styles_imageset_data'); -define('TOPICS_TABLE', $table_prefix . 'topics'); -define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted'); -define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track'); -define('TOPICS_WATCH_TABLE', $table_prefix . 'topics_watch'); -define('USER_GROUP_TABLE', $table_prefix . 'user_group'); -define('USERS_TABLE', $table_prefix . 'users'); -define('WARNINGS_TABLE', $table_prefix . 'warnings'); -define('WORDS_TABLE', $table_prefix . 'words'); -define('ZEBRA_TABLE', $table_prefix . 'zebra'); +define('ACL_GROUPS_TABLE', phpbb::$base_config['table_prefix'] . 'acl_groups'); +define('ACL_OPTIONS_TABLE', phpbb::$base_config['table_prefix'] . 'acl_options'); +define('ACL_ROLES_DATA_TABLE', phpbb::$base_config['table_prefix'] . 'acl_roles_data'); +define('ACL_ROLES_TABLE', phpbb::$base_config['table_prefix'] . 'acl_roles'); +define('ACL_USERS_TABLE', phpbb::$base_config['table_prefix'] . 'acl_users'); +define('ATTACHMENTS_TABLE', phpbb::$base_config['table_prefix'] . 'attachments'); +define('BANLIST_TABLE', phpbb::$base_config['table_prefix'] . 'banlist'); +define('BBCODES_TABLE', phpbb::$base_config['table_prefix'] . 'bbcodes'); +define('BOOKMARKS_TABLE', phpbb::$base_config['table_prefix'] . 'bookmarks'); +define('BOTS_TABLE', phpbb::$base_config['table_prefix'] . 'bots'); +define('CONFIG_TABLE', phpbb::$base_config['table_prefix'] . 'config'); +define('CONFIRM_TABLE', phpbb::$base_config['table_prefix'] . 'confirm'); +define('DISALLOW_TABLE', phpbb::$base_config['table_prefix'] . 'disallow'); +define('DRAFTS_TABLE', phpbb::$base_config['table_prefix'] . 'drafts'); +define('EXTENSIONS_TABLE', phpbb::$base_config['table_prefix'] . 'extensions'); +define('EXTENSION_GROUPS_TABLE', phpbb::$base_config['table_prefix'] . 'extension_groups'); +define('FORUMS_TABLE', phpbb::$base_config['table_prefix'] . 'forums'); +define('FORUMS_ACCESS_TABLE', phpbb::$base_config['table_prefix'] . 'forums_access'); +define('FORUMS_TRACK_TABLE', phpbb::$base_config['table_prefix'] . 'forums_track'); +define('FORUMS_WATCH_TABLE', phpbb::$base_config['table_prefix'] . 'forums_watch'); +define('GROUPS_TABLE', phpbb::$base_config['table_prefix'] . 'groups'); +define('ICONS_TABLE', phpbb::$base_config['table_prefix'] . 'icons'); +define('LANG_TABLE', phpbb::$base_config['table_prefix'] . 'lang'); +define('LOG_TABLE', phpbb::$base_config['table_prefix'] . 'log'); +define('MODERATOR_CACHE_TABLE', phpbb::$base_config['table_prefix'] . 'moderator_cache'); +define('MODULES_TABLE', phpbb::$base_config['table_prefix'] . 'modules'); +define('POLL_OPTIONS_TABLE', phpbb::$base_config['table_prefix'] . 'poll_options'); +define('POLL_VOTES_TABLE', phpbb::$base_config['table_prefix'] . 'poll_votes'); +define('POSTS_TABLE', phpbb::$base_config['table_prefix'] . 'posts'); +define('PRIVMSGS_TABLE', phpbb::$base_config['table_prefix'] . 'privmsgs'); +define('PRIVMSGS_FOLDER_TABLE', phpbb::$base_config['table_prefix'] . 'privmsgs_folder'); +define('PRIVMSGS_RULES_TABLE', phpbb::$base_config['table_prefix'] . 'privmsgs_rules'); +define('PRIVMSGS_TO_TABLE', phpbb::$base_config['table_prefix'] . 'privmsgs_to'); +define('PROFILE_FIELDS_TABLE', phpbb::$base_config['table_prefix'] . 'profile_fields'); +define('PROFILE_FIELDS_DATA_TABLE', phpbb::$base_config['table_prefix'] . 'profile_fields_data'); +define('PROFILE_FIELDS_LANG_TABLE', phpbb::$base_config['table_prefix'] . 'profile_fields_lang'); +define('PROFILE_LANG_TABLE', phpbb::$base_config['table_prefix'] . 'profile_lang'); +define('RANKS_TABLE', phpbb::$base_config['table_prefix'] . 'ranks'); +define('REPORTS_TABLE', phpbb::$base_config['table_prefix'] . 'reports'); +define('REPORTS_REASONS_TABLE', phpbb::$base_config['table_prefix'] . 'reports_reasons'); +define('SEARCH_RESULTS_TABLE', phpbb::$base_config['table_prefix'] . 'search_results'); +define('SEARCH_WORDLIST_TABLE', phpbb::$base_config['table_prefix'] . 'search_wordlist'); +define('SEARCH_WORDMATCH_TABLE', phpbb::$base_config['table_prefix'] . 'search_wordmatch'); +define('SESSIONS_TABLE', phpbb::$base_config['table_prefix'] . 'sessions'); +define('SESSIONS_KEYS_TABLE', phpbb::$base_config['table_prefix'] . 'sessions_keys'); +define('SITELIST_TABLE', phpbb::$base_config['table_prefix'] . 'sitelist'); +define('SMILIES_TABLE', phpbb::$base_config['table_prefix'] . 'smilies'); +define('STYLES_TABLE', phpbb::$base_config['table_prefix'] . 'styles'); +define('STYLES_TEMPLATE_TABLE', phpbb::$base_config['table_prefix'] . 'styles_template'); +define('STYLES_THEME_TABLE', phpbb::$base_config['table_prefix'] . 'styles_theme'); +define('STYLES_IMAGESET_TABLE', phpbb::$base_config['table_prefix'] . 'styles_imageset'); +define('STYLES_IMAGESET_DATA_TABLE',phpbb::$base_config['table_prefix'] . 'styles_imageset_data'); +define('TOPICS_TABLE', phpbb::$base_config['table_prefix'] . 'topics'); +define('TOPICS_POSTED_TABLE', phpbb::$base_config['table_prefix'] . 'topics_posted'); +define('TOPICS_TRACK_TABLE', phpbb::$base_config['table_prefix'] . 'topics_track'); +define('TOPICS_WATCH_TABLE', phpbb::$base_config['table_prefix'] . 'topics_watch'); +define('USER_GROUP_TABLE', phpbb::$base_config['table_prefix'] . 'user_group'); +define('USERS_TABLE', phpbb::$base_config['table_prefix'] . 'users'); +define('WARNINGS_TABLE', phpbb::$base_config['table_prefix'] . 'warnings'); +define('WORDS_TABLE', phpbb::$base_config['table_prefix'] . 'words'); +define('ZEBRA_TABLE', phpbb::$base_config['table_prefix'] . 'zebra'); // Additional tables - ?> \ No newline at end of file diff --git a/phpBB/includes/core/bootstrap.php b/phpBB/includes/core/bootstrap.php index 4d604dadcc..0a4910b052 100644 --- a/phpBB/includes/core/bootstrap.php +++ b/phpBB/includes/core/bootstrap.php @@ -61,44 +61,14 @@ if (defined('IN_CRON')) // Set some default configuration parameter if the config file does not exist if (!file_exists(PHPBB_ROOT_PATH . 'config.' . PHP_EXT)) { - define('CONFIG_ADM_FOLDER', 'adm'); - define('CONFIG_ACM_TYPE', 'file'); - + // phpbb::$base_config['config_set'] = false // This allows common.php or an installation script to do specific actions if the configuration is missing - define('PHPBB_CONFIG_MISSING', true); } else { require PHPBB_ROOT_PATH . 'config.' . PHP_EXT; } -// Set default configuration variables if phpBB is not installed -if (!defined('PHPBB_INSTALLED')) -{ - $dbms = $dbhost = $dbport = $dbname = $dbuser = $dbpasswd = ''; - $table_prefix = 'phpbb_'; -} - -if (defined('DEBUG_EXTRA')) -{ - $base_memory_usage = 0; - if (function_exists('memory_get_usage')) - { - $base_memory_usage = memory_get_usage(); - } -} - -// Load Extensions -if (!empty($load_extensions)) -{ - $load_extensions = explode(',', $load_extensions); - - foreach ($load_extensions as $extension) - { - @dl(trim($extension)); - } -} - // Register autoload function spl_autoload_register('__phpbb_autoload'); diff --git a/phpBB/includes/core/core.php b/phpBB/includes/core/core.php index 717ff0d4a2..09b6365da2 100644 --- a/phpBB/includes/core/core.php +++ b/phpBB/includes/core/core.php @@ -81,7 +81,24 @@ abstract class phpbb * @var array The phpBB configuration array */ public static $config = array(); - /**#@-*/ + + /** + * @var array The base configuration array + */ + public static $base_config = array( + 'table_prefix' => 'phpbb_', + 'admin_folder' => 'adm', + 'acm_type' => 'file', + + 'config_set' => false, + 'extensions_set' => false, + + 'memory_usage' => 0, + + 'debug' => false, + 'debug_extra' => false, + 'installed' => false, + ); /**#@+ * Permission constant @@ -144,6 +161,33 @@ abstract class phpbb throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } + /** + * Set base configuration - called from config.php file + */ + public static function set_config($config) + { + phpbb::$base_config = array_merge(phpbb::$base_config, $config); + phpbb::$base_config['config_set'] = true; + + if (phpbb::$base_config['debug_extra'] && function_exists('memory_get_usage')) + { + phpbb::$base_config['memory_usage'] = memory_get_usage(); + } + + // Load Extensions + if (!empty(phpbb::$base_config['extensions']) && !phpbb::$base_config['extensions_set']) + { + $load_extensions = explode(',', phpbb::$base_config['extensions']); + + foreach ($load_extensions as $extension) + { + @dl(trim($extension)); + } + + phpbb::$base_config['extensions_set'] = true; + } + } + /** * Get instance of static property * diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b5be112e5c..1f6e7bcae7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2026,7 +2026,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) // Check the error reporting level and return if the error level does not match // If DEBUG is defined the default level is E_ALL - if (($errno & ((defined('DEBUG')) ? E_ALL | E_STRICT : error_reporting())) == 0) + if (($errno & ((phpbb::$base_config['debug']) ? E_ALL | E_STRICT : error_reporting())) == 0) { return; } @@ -2122,7 +2122,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) echo '