From 0437f06b273f885db05736449a952c6eb72086ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 7 Apr 2009 21:08:15 +0000 Subject: [PATCH] Migration of stelzi's commit 1022 with some changes so we have a nicer code. See bug #119 for details --- birthday_confirm.php | 4 ++-- css.php | 4 ++-- doubler.php | 4 ++-- inc/fatal_errors.php | 15 +++++++++------ inc/functions.php | 30 +++++++++++++++++++----------- inc/header.php | 2 +- inc/load_config.php | 25 +++++++++++++++++++++++++ inc/mysql-connect.php | 22 +++------------------- inc/wrapper-functions.php | 13 +++++++++---- index.php | 4 ++-- install.php | 27 +++++++++++++++------------ lead-confirm.php | 4 ++-- show_bonus.php | 4 ++-- 13 files changed, 93 insertions(+), 65 deletions(-) diff --git a/birthday_confirm.php b/birthday_confirm.php index 24c46fcc56..efbb4a55cb 100644 --- a/birthday_confirm.php +++ b/birthday_confirm.php @@ -120,7 +120,7 @@ WHERE b.userid=%s AND b.chk_value='%s' LIMIT 1", $GLOBALS['module'] = 'birthday_confirm'; // Include header - loadInclude('inc/header.php'); + loadIncludeOnce('inc/header.php'); // Load birthday header template (for your banners, e.g.?) $content['header'] = LOAD_TEMPLATE('birthday_header', true); @@ -132,7 +132,7 @@ WHERE b.userid=%s AND b.chk_value='%s' LIMIT 1", LOAD_TEMPLATE('birthday_confirm', false, $content); // Include footer - loadInclude('inc/footer.php'); + loadIncludeOnce('inc/footer.php'); } else { // You have to install first! redirectToUrl('install.php'); diff --git a/css.php b/css.php index 714848650a..45ad87d954 100644 --- a/css.php +++ b/css.php @@ -57,13 +57,13 @@ require('inc/config-global.php'); sendHeader('Content-type: text/css'); // Load header -loadInclude('inc/header.php'); +loadIncludeOnce('inc/header.php'); // Load CSS code loadInclude('inc/stylesheet.php'); // Load footer -loadInclude('inc/footer.php'); +loadIncludeOnce('inc/footer.php'); // ?> diff --git a/doubler.php b/doubler.php index 9a63547831..6920cd1553 100644 --- a/doubler.php +++ b/doubler.php @@ -211,7 +211,7 @@ if (isInstalled()) { if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/doubler_send.php'); // Output header - loadInclude('inc/header.php'); + loadIncludeOnce('inc/header.php'); // Banner in text define('__DOUBLER_BANNER', LOAD_TEMPLATE('doubler_banner', true)); @@ -272,7 +272,7 @@ if (isInstalled()) { LOAD_TEMPLATE('doubler_index'); // Output footer - loadInclude('inc/footer.php'); + loadIncludeOnce('inc/footer.php'); } else { // You have to install first! redirectToUrl('install.php'); diff --git a/inc/fatal_errors.php b/inc/fatal_errors.php index 3d4a97a7fc..3ff6ec562e 100644 --- a/inc/fatal_errors.php +++ b/inc/fatal_errors.php @@ -43,8 +43,11 @@ if (!defined('__SECURITY')) { } if (getTotalFatalErrors() > 0) { + // Load config here + loadIncludeOnce('inc/load_config.php'); + // Main div container - LOAD_TEMPLATE("fatal_header"); + LOAD_TEMPLATE('fatal_header'); // Set unset variable if (empty($check)) $check = ''; @@ -59,11 +62,11 @@ if (getTotalFatalErrors() > 0) { ); // Load row template - $OUT .= LOAD_TEMPLATE("install_fatal_row", true, $content); + $OUT .= LOAD_TEMPLATE('install_fatal_row', true, $content); } // Load main template - LOAD_TEMPLATE("install_fatal_table", false, $OUT); + LOAD_TEMPLATE('install_fatal_table', false, $OUT); } elseif (isInstalled()) { // Display all runtime fatal errors $OUT = ''; @@ -75,11 +78,11 @@ if (getTotalFatalErrors() > 0) { ); // Load row template - $OUT .= LOAD_TEMPLATE("runtime_fatal_row", true, $content); + $OUT .= LOAD_TEMPLATE('runtime_fatal_row', true, $content); } // Load main template - LOAD_TEMPLATE("runtime_fatal_table", false, $OUT); + LOAD_TEMPLATE('runtime_fatal_table', false, $OUT); // Abort here shutdown(); @@ -94,7 +97,7 @@ if (getTotalFatalErrors() > 0) { } // END - if // Load footer template - LOAD_TEMPLATE("fatal_footer", false, $CORR); + LOAD_TEMPLATE('fatal_footer', false, $CORR); } // diff --git a/inc/functions.php b/inc/functions.php index 64e185bdec..b9decbaac6 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -79,7 +79,6 @@ function OUTPUT_HTML ($HTML, $newLine = true) { default: // Huh, something goes wrong or maybe you have edited config.php ??? - DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid renderer %s detected.", getConfig('OUTPUT_MODE'))); app_die(__FUNCTION__, __LINE__, "{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}"); break; } @@ -2248,20 +2247,29 @@ function fixDeletedCookies ($cookies) { // Output error messages in a fasioned way and die... function app_die ($F, $L, $msg) { - // Load header - loadIncludeOnce('inc/header.php'); + // Check if Script is already dieing and not let it kill itself another 1000 times + if (!isset($GLOBALS['app_died'])) { + // Make sure, that the script realy realy diese here and now + $GLOBALS['app_died'] = true; - // Prepare message for output - $msg = sprintf(getMessage('MXCHANGE_HAS_DIED'), basename($F), $L, $msg); + // Load header + loadIncludeOnce('inc/header.php'); - // Load the message template - LOAD_TEMPLATE('admin_settings_saved', false, $msg); + // Prepare message for output + $msg = sprintf(getMessage('MXCHANGE_HAS_DIED'), basename($F), $L, $msg); - // Load footer - loadIncludeOnce('inc/footer.php'); + // Load the message template + LOAD_TEMPLATE('admin_settings_saved', false, $msg); - // Exit explicitly - shutdown(); + // Load footer + loadIncludeOnce('inc/footer.php'); + + // Exit explicitly + shutdown(); + } else { + // Script tried to kill itself twice + debug_report_bug('Script wanted to kill itself more than once! Raw message=' . $msg . ', file/function=' . $F . ', line=' . $L); + } } // Display parsing time and number of SQL queries in footer diff --git a/inc/header.php b/inc/header.php index 9afbe993d2..bd4c3e3075 100644 --- a/inc/header.php +++ b/inc/header.php @@ -54,7 +54,7 @@ if (($GLOBALS['header_sent'] != '1') && ($GLOBALS['header_sent'] != '2')) { // Add title decorations? (left) if (!defined('__PAGE_TITLE')) { // Config and database connection valid? - if ((isConfigLoaded()) && (SQL_IS_LINK_UP())) { + if ((isConfigLocalLoaded()) && (isConfigLoaded()) && (SQL_IS_LINK_UP())) { // Title decoration enabled? if ((getConfig('enable_title_deco') == 'Y') && (getConfig('title_left') != '')) $TITLE .= trim(getConfig('title_left'))." "; diff --git a/inc/load_config.php b/inc/load_config.php index 26d35e68c8..f0b36d146a 100644 --- a/inc/load_config.php +++ b/inc/load_config.php @@ -47,20 +47,45 @@ setConfigEntry('OUTPUT_MODE' , 'render'); setConfigEntry('WRITE_FOOTER', 'Y'); setConfigEntry('_DB_TYPE' , 'mysql3'); +// Mark configuration as NOT loaded which is the default +$GLOBALS['config_local_loaded'] = false; + // Is the local configuration there? if (isIncludeReadable('inc/cache/config-local.php')) { // Then load it loadIncludeOnce('inc/cache/config-local.php'); + + // Mark configuration as loaded + $GLOBALS['config_local_loaded'] = true; } elseif (isInstalling()) { // Set some essential constants // @TODO Rewrite them to avoid this else block define('MAIN_TITLE', 'Your mail-exchanger title'); define('SLOGAN' , 'Your cool slogan here'); define('WEBMASTER' , 'you@some-hoster.tld.invalid'); + + // Set output mode here + setConfigEntry('OUTPUT_MODE', 'render'); } else { // Problem in application detected debug_report_bug('Wether we are not installing nor config-local.php is created!'); } +// Check if the user setups his MySQL stuff... +if ((empty($GLOBALS['mysql']['login'])) && (!isInstalling()) && (!REQUEST_ISSET_GET('installing')) && (isInstalled())) { + // No login entered and outside installation mode + OUTPUT_HTML('{--LANG_WARNING--}: '); + if (isInstalled()) { + // You have changed my configuration file! + app_die(__FILE__, __LINE__, '{--DIE_CONFIG_CHANGED_YOU--}'); + } else { + // Please run the installation script (maybe again) + app_die(__FILE__, __LINE__, '{--DIE_RUN_INSTALL_MYSQL--}'); + } +} elseif ((!isInstalling()) && (empty($GLOBALS['mysql']['password'])) && (getConfig('WARN_NO_PASS') == 'Y')) { + // No database password entered!!! + OUTPUT_HTML('
{--LANG_WARNING--}:
{--WARN_NULL_PASSWORD--}'); +} + // ?> diff --git a/inc/mysql-connect.php b/inc/mysql-connect.php index 8693a51c6b..f4e1d42d3a 100644 --- a/inc/mysql-connect.php +++ b/inc/mysql-connect.php @@ -57,33 +57,17 @@ foreach (array('request-functions', 'session-functions', 'config-functions', 'co // Set error handler set_error_handler('__errorHandler'); -// Load configuration file(s) here -loadIncludeOnce('inc/load_config.php'); - // Set important header_sent $GLOBALS['header_sent'] = 0; -// Check if the user setups his MySQL stuff... -if ((empty($GLOBALS['mysql']['login'])) && (!isInstalling()) && (!REQUEST_ISSET_GET('installing')) && (isInstalled())) { - // No login entered and outside installation mode - OUTPUT_HTML('{--LANG_WARNING--}: '); - if (isInstalled()) { - // You have changed my configuration file! - app_die(__FILE__, __LINE__, '{--DIE_CONFIG_CHANGED_YOU--}'); - } else { - // Please run the installation script (maybe again) - app_die(__FILE__, __LINE__, '{--DIE_RUN_INSTALL_MYSQL--}'); - } -} elseif ((!isInstalling()) && (empty($GLOBALS['mysql']['password'])) && (getConfig('WARN_NO_PASS') == 'Y')) { - // No database password entered!!! - OUTPUT_HTML('
{--LANG_WARNING--}:
{--WARN_NULL_PASSWORD--}'); -} - // Init fatal messages initFatalMessages(); // Check if this file is writeable or read-only and warn the user if ((!isInstalling()) && (isInstalled())) { + // Load configuration file(s) here + loadIncludeOnce('inc/load_config.php'); + // Check for write-permission for config.php and inc directory if (empty($GLOBALS['module'])) $GLOBALS['module'] = REQUEST_GET('module'); if (empty($GLOBALS['module'])) $GLOBALS['module'] = 'index'; diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 6803dfc378..b3c3c13590 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -125,11 +125,11 @@ function loadInclude ($INC) { function loadIncludeOnce ($INC) { // Is it not loaded? if (!isset($GLOBALS['load_once'][$INC])) { + // Mark it as loaded + $GLOBALS['load_once'][$INC] = "loaded"; + // Then try to load it loadInclude($INC); - - // And mark it as loaded - $GLOBALS['load_once'][$INC] = "loaded"; } // END - if } @@ -278,7 +278,7 @@ function isInstalling () { // Check wether this script is installed function isInstalled () { - return (getConfig('MXCHANGE_INSTALLED') == 'Y'); + return ((getConfig('MXCHANGE_INSTALLED') == 'Y') || (isIncludeReadable('inc/cache/config-local.php'))); } // Check wether an admin is registered @@ -372,5 +372,10 @@ function countPostSelection () { return countSelection(REQUEST_POST('sel')); } +// Checks wether the config-local.php is loaded +function isConfigLocalLoaded () { + return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true)); +} + // [EOF] ?> diff --git a/index.php b/index.php index 04c3926242..8b38b1e2e3 100644 --- a/index.php +++ b/index.php @@ -56,7 +56,7 @@ require('inc/config-global.php'); // Is the script installed? if (isInstalled()) { // Header - loadInclude('inc/header.php'); + loadIncludeOnce('inc/header.php'); // Fix missing array elements here if (!isConfigEntrySet('index_delay')) setConfigEntry('index_delay' , 0); @@ -89,7 +89,7 @@ if (isInstalled()) { } // Footer - loadInclude('inc/footer.php'); + loadIncludeOnce('inc/footer.php'); } else { // You have to install first! redirectToUrl('install.php'); diff --git a/install.php b/install.php index d632be4e43..b1ad8f1736 100644 --- a/install.php +++ b/install.php @@ -65,22 +65,22 @@ $GLOBALS['module'] = 'install'; // Load config file require('inc/config-global.php'); -// Header -loadInclude('inc/header.php'); - -// Reload page to page=welcome when it is not specified -if (!REQUEST_ISSET_GET('page')) { - redirectToUrl('install.php?page=welcome'); -} // END - if - // Already installed? -if ((isInstalled()) && (isAdminRegistered())) { +if (isInstalled()) { // Add fatal message addFatalMessage(__FILE__, __LINE__, getMessage('ALREADY_INSTALLED')); } // END - if // Does something goes wrong? if (getTotalFatalErrors() == 0) { + // Reload page to page=welcome when it is not specified + if (!REQUEST_ISSET_GET('page')) { + redirectToUrl('install.php?page=welcome'); + } // END - if + + // Load header here + loadIncludeOnce('inc/header.php'); + // Add main installation table LOAD_TEMPLATE('install_header'); @@ -89,10 +89,13 @@ if (getTotalFatalErrors() == 0) { // Close main installation table LOAD_TEMPLATE('install_footer'); -} -// Footer -loadInclude('inc/footer.php'); + // Footer + loadIncludeOnce('inc/footer.php'); +} else { + // Output fatal messages + loadInclude('inc/fatal_errors.php'); +} // ?> diff --git a/lead-confirm.php b/lead-confirm.php index 3078aa5b47..e21f4f6070 100644 --- a/lead-confirm.php +++ b/lead-confirm.php @@ -56,7 +56,7 @@ require('inc/config-global.php'); // Is the script installed? if (isInstalled()) { // Header - loadInclude('inc/header.php'); + loadIncludeOnce('inc/header.php'); // Initialize the array for the template $content = array( @@ -91,7 +91,7 @@ if (isInstalled()) { LOAD_TEMPLATE('lead_code', false, $content); // Footer - loadInclude('inc/footer.php'); + loadIncludeOnce('inc/footer.php'); } else { // You have to install first! redirectToUrl('install.php'); diff --git a/show_bonus.php b/show_bonus.php index d8dc4bf7d0..6f2e4bffb6 100644 --- a/show_bonus.php +++ b/show_bonus.php @@ -57,7 +57,7 @@ redirectOnUninstalledExtension('bonus'); // List only rankings when script is installed if (isInstalled()) { // Include header - loadInclude('inc/header.php'); + loadIncludeOnce('inc/header.php'); if ((REQUEST_GET('uid') > 0) && (REQUEST_GET('d') > 0) && (REQUEST_ISSET_GET(('t')))) { // Set row name @@ -132,7 +132,7 @@ LIMIT 1", LOAD_TEMPLATE('show_bonus', false, $content); // Include footer - loadInclude('inc/footer.php'); + loadIncludeOnce('inc/footer.php'); } else { // You have to install first! redirectToUrl('install.php'); -- 2.39.5