From a2ca374f65976d21651fffb64a78d3a9678bb3b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 30 Oct 2009 08:47:22 +0000 Subject: [PATCH] Rewrites not to init config in config-functions.php (some still remain, many untested) --- doubler.php | 3 ++- inc/config-functions.php | 35 +++++++++++--------------------- inc/databases.php | 6 ------ inc/db/lib-mysql3.php | 2 +- inc/extensions/ext-other.php | 11 ++++++++-- inc/filters.php | 21 ++++++++++++++++--- inc/functions.php | 36 +++++++++++++++++++++++++++++---- inc/header.php | 2 +- inc/language-functions.php | 5 ++++- inc/language/de.php | 1 + inc/modules/admin.php | 2 +- inc/modules/admin/admin-inc.php | 14 +++++++++++-- inc/mysql-connect.php | 10 ++++----- inc/mysql-manager.php | 16 ++++++++++----- inc/session.php | 14 ++++++++----- inc/wrapper-functions.php | 14 +++++++++---- install/tables.sql | 1 - mailid_top.php | 5 ++++- 18 files changed, 132 insertions(+), 66 deletions(-) diff --git a/doubler.php b/doubler.php index 5fd52022b5..791dc3e025 100644 --- a/doubler.php +++ b/doubler.php @@ -84,7 +84,8 @@ $userid = 0; // If no account was found set default refid and status to CONFIRMED if (empty($GLOBALS['refid'])) { - $GLOBALS['refid'] = getConfig('def_refid'); + // Determine referal id again + $GLOBALS['refid'] = determineReferalId(); $status = 'CONFIRMED'; } // END - if diff --git a/inc/config-functions.php b/inc/config-functions.php index 48e6d0a63a..5cbb77db72 100644 --- a/inc/config-functions.php +++ b/inc/config-functions.php @@ -51,32 +51,21 @@ function initConfig () { // Set a minimum of configuration, required to by-pass some error triggers in getConfig() $GLOBALS['config'] = array( - 'code_length' => 0, - 'patch_level' => 0, - 'last_update' => time(), - 'activate_xchange' => 100, - 'enable_mod_title' => 'Y', - 'update_filter_usage' => 'N', - 'ADMIN_REGISTERED' => 'N', - 'MXCHANGE_INSTALLED' => 'N', - 'DEFAULT_LANG' => 'de', - 'DEFAULT_SALT_LENGTH' => 40, - 'DEBUG_MODE' => 'N', - 'DEBUG_RESET' => 'N', - 'DEBUG_MONTHLY' => 'N', - 'DEBUG_WEEKLY' => 'N', - 'DEBUG_REGEX' => 'N', - 'ADMIN_REGISTERED' => 'N', - 'sql_count' => 0, 'sql_time' => 0, + 'sql_count' => 0, 'num_templates' => 0, - 'default_theme' => 'default', - 'verbose_sql' => 'Y', - 'def_refid' => 0, - 'ENABLE_BACKLINK' => 'Y', - 'display_debug_sqls' => 'N', + // 'DEFAULT_SALT_LENGTH' => 40, + // 'DEBUG_MODE' => 'N', + // 'DEBUG_RESET' => 'N', + // 'DEBUG_MONTHLY' => 'N', + // 'DEBUG_WEEKLY' => 'N', + // 'DEBUG_REGEX' => 'N', + // 'ADMIN_REGISTERED' => 'N', + // 'verbose_sql' => 'Y', + // 'ENABLE_BACKLINK' => 'Y', + // 'display_debug_sqls' => 'N', // Keep session_save_path to fall-back to php.ini setting - 'session_save_path' => '', + // 'session_save_path' => '', // For installation phase: 'SMTP_HOSTNAME' => '', 'SMTP_USER' => '', diff --git a/inc/databases.php b/inc/databases.php index 15c81b861f..9eb216ce8f 100644 --- a/inc/databases.php +++ b/inc/databases.php @@ -99,12 +99,6 @@ setConfigEntry('CURRENT_DATE', generateDateTime(time(), 3)); setConfigEntry('START_YDAY', makeTime(0, 0, 0, time() - getConfig('ONE_DAY'))); setConfigEntry('START_TDAY', makeTime(0, 0, 0, time())); -// Take a prime number which is long (if you know a longer one please try it out!) -setConfigEntry('_PRIME', 591623); - -// Calculate "entropy" with the prime number (for code generation) -setConfigEntry('_ADD', (getConfig('_PRIME') * getConfig('_PRIME') / (pi() * getConfig('code_length') + 1))); - // HTTP-EOL setConfigEntry('HTTP_EOL', "\r\n"); diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index e11f335446..465e0d5b2c 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -104,7 +104,7 @@ Query string:
incrementConfigEntry('sql_count'); // Debug output - if ((getOutputMode() != 1) && (isDebugModeEnabled()) && (getConfig('DEBUG_SQL') == 'Y')) { + if ((getOutputMode() != 1) && (isDebugModeEnabled()) && (isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y')) { // // Debugging stuff... // diff --git a/inc/extensions/ext-other.php b/inc/extensions/ext-other.php index 5d0472bdad..4f3b30d031 100644 --- a/inc/extensions/ext-other.php +++ b/inc/extensions/ext-other.php @@ -42,10 +42,10 @@ if (!defined('__SECURITY')) { } // END - if // Version number -setThisExtensionVersion('0.2.4'); +setThisExtensionVersion('0.2.5'); // Version history array (add more with , '0.1.0' and so on) -setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4')); +setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5')); // Keep this extension always active! setExtensionAlwaysActive('Y'); @@ -221,6 +221,13 @@ switch (getExtensionMode()) { // Update notes (these will be set as task text!) setExtensionUpdateNotes("Filter zum Anzeigen (Debug) von ausgeführten SQL-Anweisungen hinzugefügt."); break; + + case '0.2.5': // SQL queries for v0.2.5 + addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `code_length` TINYINT(3) UNSIGNED NOT NULL DEFAULT 5"); + + // Update notes (these will be set as task text!) + setExtensionUpdateNotes("Codelänge aus tables.sql rausgeholt."); + break; } break; diff --git a/inc/filters.php b/inc/filters.php index f100892efe..f64b28f064 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -327,6 +327,15 @@ function FILTER_UPDATE_LOGIN_DATA () { // Filter for initializing randomizer function FILTER_INIT_RANDOMIZER () { + // Only execute this filter if installed + if ((!isInstalled()) || (!isExtensionInstalledAndNewer('other', '0.2.5'))) return; + + // Take a prime number which is long (if you know a longer one please try it out!) + setConfigEntry('_PRIME', 591623); + + // Calculate "entropy" with the prime number (for code generation) + setConfigEntry('_ADD', (getConfig('_PRIME') * getConfig('_PRIME') / (pi() * getConfig('code_length') + 1))); + // Simply init the randomizer with seed and _ADD value mt_srand(generateSeed() + getConfig('_ADD')); } @@ -488,7 +497,7 @@ function FILTER_RUN_RESET_INCLUDES () { setIncludePool('reset', getArrayFromDirectory('inc/reset/', 'reset_')); // Update database - if (getConfig('DEBUG_RESET') != 'Y') updateConfiguration('last_update', time()); + if ((!isConfigEntrySet('DEBUG_RESET')) || (getConfig('DEBUG_RESET') != 'Y')) updateConfiguration('last_update', time()); // Is the config entry set? if (isExtensionInstalledAndNewer('sql_patches', '0.4.2')) { @@ -623,6 +632,9 @@ function FILTER_TRIGGER_SENDING_POOL () { // Filter for checking and updating SVN revision function FILTER_CHECK_SVN_REVISION () { + // Only execute this filter if installed and all config entries are there + if ((!isInstalled()) || (!isConfigEntrySet('patch_level'))) return; + // Check for patch level differences between databases and current hard-coded if ((getConfig('CURR_SVN_REVISION') > getConfig('patch_level')) || (getConfig('patch_level') == 'CURR_SVN_REVISION') || (getConfig('patch_ctime') == 'UNIX_TIMES')) { // Update database and CONFIG array @@ -634,9 +646,12 @@ function FILTER_CHECK_SVN_REVISION () { // Filter for running daily reset function FILTER_RUN_DAILY_RESET () { + // Only execute this filter if installed + if ((!isInstalled()) || (!isAdminRegistered())) return; + // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D // 012 3 4 43 3 4432 2 3 3 21 1 221 1 221 1 2 21 1 22 10 - if (((date('d', getConfig('last_update')) != date('d', time())) || (getConfig('DEBUG_RESET') == 'Y')) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('register')) && (getOutputMode() != 1)) { + if (((date('d', getConfig('last_update')) != date('d', time())) || ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'))) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestElementSet('register')) && (getOutputMode() != 1)) { // Tell every module we are in reset-mode! doReset(); } // END - if @@ -793,7 +808,7 @@ function FILTER_DISPLAY_COPYRIGHT () { // Shall we display the copyright notice? if ((!isGetRequestElementSet('frame')) && (basename($_SERVER['PHP_SELF']) != 'mailid_top.php') && ((getConfig('WRITE_FOOTER') == 'Y') || (isInstalling())) && ($GLOBALS['header_sent'] == 2)) { // Backlink enabled? - if ((getConfig('ENABLE_BACKLINK') == 'Y') || (isInstalling())) { + if (((isConfigEntrySet('ENABLE_BACKLINK')) && (getConfig('ENABLE_BACKLINK') == 'Y')) || (isInstalling())) { // Copyright with backlink, thanks! :-) loadTemplate('copyright_backlink'); } else { diff --git a/inc/functions.php b/inc/functions.php index 2d4fcf45df..620a4bbce0 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2310,7 +2310,7 @@ function getCurrentTheme () { $ret = 'default'; // Load default theme if not empty from configuration - if (getConfig('default_theme') != '') $ret = getConfig('default_theme'); + if ((isConfigEntrySet('default_theme')) && (getConfig('default_theme') != '')) $ret = getConfig('default_theme'); if (!isSessionVariableSet('mxchange_theme')) { // Set default theme @@ -2619,6 +2619,17 @@ function debug_get_printable_backtrace () { // Output a debug backtrace to the user function debug_report_bug ($message = '') { + // Is this already called? + if (isset($GLOBALS[__FUNCTION__])) { + // Other backtrace + print 'Message:'.$message.'
Backtrace:
';
+		debug_print_backtrace();
+		die('
'); + } // END - if + + // Set this function as called + $GLOBALS[__FUNCTION__] = true; + // Init message $debug = ''; @@ -3203,7 +3214,7 @@ function determineReferalId () { } // Set cookie when default refid > 0 - if (!isSessionVariableSet('refid') || (!empty($GLOBALS['refid'])) || ((getSession('refid') == 0) && (getConfig('def_refid') > 0))) { + if (!isSessionVariableSet('refid') || (!empty($GLOBALS['refid'])) || ((getSession('refid') == 0) && (isConfigEntrySet('def_refid')) && (getConfig('def_refid') > 0))) { // Set cookie setSession('refid', $GLOBALS['refid']); } // END - if @@ -3491,8 +3502,25 @@ function mapModuleToTable ($moduleName) { // Add SQL debug data to array for later output function addSqlToDebug ($result, $sqlString, $timing, $F, $L) { - // Don't execute anything here if we don't need - if (getConfig('display_debug_sqls') != 'Y') return; + // Already executed? + if (isset($GLOBALS['debug_sqls'][$F][$L][$sqlString])) { + // Then abort here, we don't need to profile a query twice + return; + } // END - if + + // Remeber this as profiled (or not, but we don't care here) + $GLOBALS['debug_sqls'][$F][$L][$sqlString] = true; + + // Do we have cache? + if (!isset($GLOBALS['debug_sql_available'])) { + // Check it and cache it in $GLOBALS + $GLOBALS['debug_sql_available'] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y')); + } // END - if + + // Don't execute anything here if we don't need or ext-other is missing + if ($GLOBALS['debug_sql_available'] === false) { + return; + } // END - if // Generate record $record = array( diff --git a/inc/header.php b/inc/header.php index ce68e54388..34feadb23c 100644 --- a/inc/header.php +++ b/inc/header.php @@ -48,7 +48,7 @@ if (($GLOBALS['header_sent'] != 1) && ($GLOBALS['header_sent'] != 2)) { // If not in CSS mode generate the header if (getOutputMode() != 1) { // Config and database connection valid? - if ((isConfigLocalLoaded()) && (isConfigLoaded()) && (SQL_IS_LINK_UP()) && (isExtensionActive('sql_patches'))) { + if ((isConfigLocalLoaded()) && (isConfigLoaded()) && (SQL_IS_LINK_UP()) && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) { // Init title $TITLE = ''; diff --git a/inc/language-functions.php b/inc/language-functions.php index 1936842e75..f2fe7a9536 100644 --- a/inc/language-functions.php +++ b/inc/language-functions.php @@ -83,8 +83,11 @@ function getCurrentLanguage () { // "Getter" for language function getLanguage () { + // Default is 'de'. DO NOT CHANGE THIS!!! + $ret = 'de'; + // Set default return value to default language from config - $ret = getConfig('DEFAULT_LANG'); + if (isConfigEntrySet('DEFAULT_LANG')) $ret = getConfig('DEFAULT_LANG'); // Init variable $lang = ''; diff --git a/inc/language/de.php b/inc/language/de.php index 559cc0dcda..dc9271d5c8 100644 --- a/inc/language/de.php +++ b/inc/language/de.php @@ -1132,6 +1132,7 @@ addMessages(array( 'ADMIN_EXT_TEXT_FILE_MISSING' => "Die Erweiterung %s hat keinen Beschreibungstext. Bitte melden Sie dies uns im Bug-Tracker.", 'GUEST_STATS_NO_CLICKS' => "Keine Klicks in Ihrem {?mt_word?} verzeichnet.", 'ADMIN_EXTENSIONS_REMOVED' => "Es wurden %s Erweiterungen aus Ihrem {?mt_word?} entfernt.", + 'ADMIN_WARNING_SQL_PATCHES_MISSING' => "Ein essentielle Erweiterung sql_patches ist noch nicht installiert. Bitte erledigen Sie dies bald, da Ihr {?mt_word?} sonst nicht funktioniert.", 'MEMBER_MAIL_BONUS_CONFIRMED_ON' => "Sie haben diese Bonusmail %s bestätigt.", 'MEMBER_MAIL_NORMAL_CONFIRMED_ON' => "Sie haben diese Klickmail %s bestätigt.", diff --git a/inc/modules/admin.php b/inc/modules/admin.php index eda91788cf..0a26a6ff36 100644 --- a/inc/modules/admin.php +++ b/inc/modules/admin.php @@ -363,7 +363,7 @@ if (!isAdminRegistered()) { } else { // This little call constructs the whole default old and lacky menu system // on left side. It also renders the content on right side - doAdminAction(getWhat()); + doAdminAction(); } break; diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index 4cce611c95..37af59ab4c 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -238,7 +238,10 @@ function ifAdminCookiesAreValid ($admin, $password) { } // Do an admin action -function doAdminAction ($what) { +function doAdminAction () { + // Get default what + $what = getWhat(); + //* DEBUG: */ outputHtml(__LINE__."*".$what.'/'.getModule().'/'.getAction().'/'.getWhat()."*
"); // Remove any spaces from variable @@ -269,6 +272,12 @@ function doAdminAction ($what) { // Tableset header loadTemplate('admin_main_header', false, $content); + // Is sql_patches not yet installed? + if (!isExtensionInstalled('sql_patches')) { + // Output warning + loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WARNING_SQL_PATCHES_MISSING')); + } // END - if + // Check if action/what pair is valid $result_action = SQL_QUERY_ESC("SELECT `id` @@ -287,7 +296,8 @@ WHERE ) ) ) -LIMIT 1", array($action, $what, $what), __FUNCTION__, __LINE__); +LIMIT 1", + array($action, $what, $what), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result_action) == 1) { // Is valid but does the inlcude file exists? $inc = sprintf("inc/modules/admin/action-%s.php", $action); diff --git a/inc/mysql-connect.php b/inc/mysql-connect.php index d29d479a65..42b6a887dc 100644 --- a/inc/mysql-connect.php +++ b/inc/mysql-connect.php @@ -69,10 +69,7 @@ initFatalMessages(); initMessages(); // Check if this file is writeable or read-only and warn the user -if ((!isInstalling()) && (!isInstallationPhase())) { - // Load "databases" aka static arrays - loadIncludeOnce('inc/databases.php'); - +if (!isInstalling()) { // Load database layer here loadIncludeOnce('inc/db/lib.php'); @@ -112,6 +109,9 @@ if ((!isInstalling()) && (!isInstallationPhase())) { // Run the init filter chain runFilterChain('init'); + // Load "databases" aka static arrays + loadIncludeOnce('inc/databases.php'); + // Check module for permissions $checkModule = checkModulePermissions(); @@ -155,7 +155,7 @@ if ((!isInstalling()) && (!isInstallationPhase())) { if (!isOutputModeSet()) setOutputMode(0); // Include more - foreach (array('inc/databases.php','inc/db/lib.php','inc/session.php','inc/versions.php','inc/install-functions.php','inc/load_config.php') as $inc) { + foreach (array('inc/databases.php','inc/versions.php','inc/db/lib.php','inc/session.php','inc/install-functions.php','inc/load_config.php') as $inc) { // Load the include loadIncludeOnce($inc); } // END - foreach diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 2b88cfbc83..7c8d7b4947 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -1641,11 +1641,17 @@ function FILTER_ACTIVATE_EXCHANGE () { // Deletes a user account with given reason function deleteUserAccount ($userid, $reason) { $points = 0; - $result = SQL_QUERY_ESC("SELECT (SUM(p.points) - d.used_points) AS points -FROM `{?_MYSQL_PREFIX?}_user_points` AS p -LEFT JOIN `{?_MYSQL_PREFIX?}_user_data` AS d -ON p.userid=d.userid -WHERE p.userid=%s", array(bigintval($userid)), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT + (SUM(p.points) - d.used_points) AS points +FROM + `{?_MYSQL_PREFIX?}_user_points` AS p +LEFT JOIN + `{?_MYSQL_PREFIX?}_user_data` AS d +ON + p.userid=d.userid +WHERE + p.userid=%s", + array(bigintval($userid)), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Save his points to add them to the jackpot list($points) = SQL_FETCHROW($result); diff --git a/inc/session.php b/inc/session.php index 591cb1c4ee..71e6eca53d 100644 --- a/inc/session.php +++ b/inc/session.php @@ -39,14 +39,18 @@ // Some security stuff... if (!defined('__SECURITY')) { die(); -} +} // END - if -// Set session save path if set -if (getConfig('session_save_path') != '') { - // Please make sure this valid! - session_save_path(getConfig('session_save_path')); +// Is ext-sql_patches there and newer? +if (isExtensionInstalledAndNewer('sql_patches', '0.5.3')) { + // Set session save path if set + if (getConfig('session_save_path') != '') { + // Please make sure this valid! + session_save_path(getConfig('session_save_path')); + } // END - if } // END - if +// Is a session id there? if (session_id() == '') { // Start the session session_start(); diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 2363003720..882cd3aa9b 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -286,7 +286,13 @@ function isInstalled () { $GLOBALS['is_installed'] = ( ( // First is config - getConfig('MXCHANGE_INSTALLED') == 'Y' + ( + ( + isConfigEntrySet('MXCHANGE_INSTALLED') + ) && ( + getConfig('MXCHANGE_INSTALLED') == 'Y' + ) + ) ) || ( // New config file found and loaded isIncludeReadable(getConfig('CACHE_PATH') . 'config-local.php') @@ -312,7 +318,7 @@ function isInstalled () { // Check wether an admin is registered function isAdminRegistered () { - return (getConfig('ADMIN_REGISTERED') == 'Y'); + return ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y')); } // Checks wether the reset mode is active @@ -324,13 +330,13 @@ function isResetModeEnabled () { // Checks wether the debug mode is enabled function isDebugModeEnabled () { // Simply check it - return (getConfig('DEBUG_MODE') == 'Y'); + return ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y')); } // Checks wether we shall debug regular expressions function isDebugRegExpressionEnabled () { // Simply check it - return (getConfig('DEBUG_REGEX') == 'Y'); + return ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y')); } // Checks wether the cache instance is valid diff --git a/install/tables.sql b/install/tables.sql index 4169ca5415..b8e4d02a93 100644 --- a/install/tables.sql +++ b/install/tables.sql @@ -58,7 +58,6 @@ CREATE TABLE `{?_MYSQL_PREFIX?}_config` ( `resend_profile_update` BIGINT(20) UNSIGNED NOT NULL DEFAULT '172800', `patch_level` VARCHAR(100) NOT NULL DEFAULT '78', `patch_ctime` VARCHAR(10) NOT NULL DEFAULT 0, - `code_length` TINYINT(3) UNSIGNED NOT NULL DEFAULT 5, `guest_stats` ENUM('MEMBERS','MODULES','INACTIVE') NOT NULL DEFAULT 'MEMBERS', `ref_payout` TINYINT(3) UNSIGNED NOT NULL DEFAULT 5, `activate_xchange` BIGINT(20) UNSIGNED NOT NULL DEFAULT 100, diff --git a/mailid_top.php b/mailid_top.php index c5fab11c92..b63c937417 100644 --- a/mailid_top.php +++ b/mailid_top.php @@ -52,9 +52,12 @@ require('inc/config-global.php'); // Set content type setContentType('text/html'); -// Is the extension active +// Is the extension mailid active? redirectOnUninstalledExtension('mailid'); +// Is the extension other active? +redirectOnUninstalledExtension('other'); + // Init variables $url_userid = 0; $url_bid = 0; -- 2.30.2