From 2242e96edcd22361e94ed18d72f5667ab286f791 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Mon, 23 Aug 2010 12:32:54 +0000
Subject: [PATCH] Rewrites/fixes for CURRENT_DATE, better encapsulation of
 redirect, coding convention: - loadExtension()'s parameter $ext_ver is now
 '0.0' by default, this saves a   manual fix. Still all these errors needs to
 be fixed - Setting CURRENT_DATE in inc/databases.php causes an error on some
 servers,   thanks to km4l (www.funcoins.de) for helping me - Redirect
 re-introduced, it should now no longer endless redirect and is   required to
 redirect from any script to the base script - Move setting of HTTP status
 '302 MOVED' into sendRawRedirect() - if() braces added (coding convention
 applied) - TODOs.txt updated

---
 DOCS/TODOs.txt               | 11 +++++------
 inc/databases.php            |  3 ---
 inc/extensions-functions.php | 10 ++++++----
 inc/filter-functions.php     |  1 +
 inc/filters.php              |  6 ++++++
 inc/functions.php            |  7 +++----
 inc/mysql-connect.php        |  6 ++++++
 inc/wrapper-functions.php    |  3 +++
 8 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt
index 21a0837eb8..50b59eec88 100644
--- a/DOCS/TODOs.txt
+++ b/DOCS/TODOs.txt
@@ -4,7 +4,6 @@
 ./beg.php:165:			// @TODO Opps, what is missing here???
 ./birthday_confirm.php:95:		// @TODO Try to rewrite the following unset()
 ./inc/autopurge/purge-inact.php:57:	// @TODO Rewrite these if() blocks to a filter
-./inc/cache/config-local.php:126:// @TODO Rewrite the following three constants, somehow...
 ./inc/classes/cachesystem.class.php:474:	// @TODO Add support for more types which break in last else-block
 ./inc/config-functions.php:141:	// @TODO Make this all better... :-/
 ./inc/expression-functions.php:166:// @TODO FILTER_COMPILE_CONFIG does not handle call-back functions so we handle it here again
@@ -40,12 +39,12 @@
 ./inc/extensions-functions.php:434:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
 ./inc/extensions-functions.php:564:		// @TODO Extension is loaded, what next?
 ./inc/functions.php:112:		// @TODO Extension 'msg' does not exist
-./inc/functions.php:1499:			// @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ?
-./inc/functions.php:1522:			// @TODO Rewrite this old lost code to a template
-./inc/functions.php:1590:			// @TODO Are these convertions still required?
-./inc/functions.php:1608:// @TODO Rewrite this function to use readFromFile() and writeToFile()
+./inc/functions.php:1496:			// @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ?
+./inc/functions.php:1519:			// @TODO Rewrite this old lost code to a template
+./inc/functions.php:1587:			// @TODO Are these convertions still required?
+./inc/functions.php:1605:// @TODO Rewrite this function to use readFromFile() and writeToFile()
 ./inc/functions.php:181:// @TODO Rewrite this to an extension 'smtp'
-./inc/functions.php:2264:	// @TODO This is still very static, rewrite it somehow
+./inc/functions.php:2263:	// @TODO This is still very static, rewrite it somehow
 ./inc/gen_sql_patches.php:96:// @TODO Rewrite this to a filter
 ./inc/install-functions.php:59:	// @TODO DEACTIVATED: changeDataInFile(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0);
 ./inc/language/de.php:1116:// @TODO Rewrite these two constants
diff --git a/inc/databases.php b/inc/databases.php
index 8dd31b8864..7b61176b96 100644
--- a/inc/databases.php
+++ b/inc/databases.php
@@ -96,9 +96,6 @@ $GLOBALS['replacer'] = array(
 // One day
 setConfigEntry('ONE_DAY', (60*60*24));
 
-// Current date
-setConfigEntry('CURRENT_DATE', generateDateTime(time(), 3));
-
 // Timestamp for yesterday, today ... all at 00:00 am
 setConfigEntry('START_YDAY', makeTime(0, 0, 0, time() - getConfig('ONE_DAY')));
 setConfigEntry('START_TDAY', makeTime(0, 0, 0, time()));
diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php
index 56b1313923..5ceb349621 100644
--- a/inc/extensions-functions.php
+++ b/inc/extensions-functions.php
@@ -43,9 +43,11 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Load the extension and maybe found language and function files.
-function loadExtension ($ext_name, $ext_mode, $ext_ver = '', $dry_run = false) {
-	// If this happens twice, we need the bug report from you, except for updates/tests
+function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0', $dry_run = false) {
+	// Loading an extension in same mode, but not test/update, twice is not
+	// good, so is the extension $ext_name already loaded in mode $ext_mode?
 	if ((isset($GLOBALS['loaded_extension'][$ext_name][$ext_mode])) && (!in_array($ext_mode, array('update', 'test')))) {
+		// If this happens twice, we need the bug report from you, except for updates/tests
 		debug_report_bug(__FUNCTION__, __LINE__, '() is called twice: ext_name=' . $ext_name . ', ext_mode='. $ext_mode . ',ext_sqls=' . print_r(getExtensionSqls(), true) . ', ext_register_running=' . print_r($GLOBALS['ext_register_running'], true) . ', ext_running_updates=' . print_r($GLOBALS['ext_running_updates'], true));
 	} // END - if
 
@@ -76,8 +78,8 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '', $dry_run = false) {
 
 		// In all but test-mode we need these messages to debug! Please report all (together, e.g.)
 		if (($ext_mode != 'test') && (getCurrentExtensionVersion() == '0.0')) {
-			// Log empty versions not in test-mode, but maybe it is fine...
-			logDebugMessage(__FUNCTION__, __LINE__, 'Extension version is empty, setting to 0.0. ext_name=' . $ext_name . ', ext_mode=' . $ext_mode . ', dry_run=' . intval($dry_run));
+			// Abort here, this must now always be set!
+			debug_report_bug(__FUNCTION__, __LINE__, 'Extension version is empty, setting to 0.0. ext_name=' . $ext_name . ', ext_mode=' . $ext_mode . ', dry_run=' . intval($dry_run));
 		} // END - if
 	}
 
diff --git a/inc/filter-functions.php b/inc/filter-functions.php
index dac79b3107..e5421fd4ba 100644
--- a/inc/filter-functions.php
+++ b/inc/filter-functions.php
@@ -104,6 +104,7 @@ ORDER BY
 	registerFilter('init', 'INIT_RANDOMIZER');
 	registerFilter('init', 'LOAD_RUNTIME_INCLUDES');
 	registerFilter('init', 'INIT_EXTENSIONS');
+	registerFilter('init', 'SET_CURRENT_DATE');
 	registerFilter('init', 'INIT_RANDOM_NUMBER');
 	registerFilter('init', 'CHECK_SVN_REVISION');
 	registerFilter('init', 'RUN_DAILY_RESET');
diff --git a/inc/filters.php b/inc/filters.php
index fe1a36c009..b68274ccb2 100644
--- a/inc/filters.php
+++ b/inc/filters.php
@@ -1016,5 +1016,11 @@ function FILTER_CLEANUP_DNS_CACHE () {
 	} // END - if
 }
 
+// Filter for setting CURRENT_DATE, this is required after initialization of extensions
+function FILTER_SET_CURRENT_DATE () {
+	// Set current date
+	setConfigEntry('CURRENT_DATE', generateDateTime(time(), '3'));
+}
+
 // [EOF]
 ?>
diff --git a/inc/functions.php b/inc/functions.php
index ff31b7dcbb..ff063d75f7 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -585,9 +585,6 @@ function redirectToUrl ($URL, $allowSpider = true) {
 		// Clear own output buffer
 		$GLOBALS['output'] = '';
 
-		// Set header
-		setHttpStatus('302 Found');
-
 		// Load URL when headers are not sent
 		sendRawRedirect(doFinalCompilation(str_replace('&amp;', '&', $URL), false));
 	} else {
@@ -2016,7 +2013,9 @@ function initMemberId () {
 // Setter for member id
 function setMemberId ($memberid) {
 	// We should not set member id to zero
-	if ($memberid == '0') debug_report_bug(__FUNCTION__, __LINE__, 'Userid should not be set zero.');
+	if ($memberid == '0') {
+		debug_report_bug(__FUNCTION__, __LINE__, 'Userid should not be set zero.');
+	} // END - if
 
 	// Set it secured
 	$GLOBALS['member_id'] = bigintval($memberid);
diff --git a/inc/mysql-connect.php b/inc/mysql-connect.php
index 70a3ef45b9..40a86ef8f9 100644
--- a/inc/mysql-connect.php
+++ b/inc/mysql-connect.php
@@ -149,6 +149,12 @@ if ((!isInstalling()) && (!isInstallationPhase())) {
 		// Load the include
 		loadIncludeOnce('inc/' . $inc . '.php');
 	} // END - foreach
+
+	// Check wether we are in installation routine
+	if ((!isInstalling()) && (!isCssOutputMode()) && (!isRawOutputMode())) {
+		// Redirect to the URL
+		redirectToUrl('install.php');
+	} // END - if
 }
 
 // Handle fatal errors
diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php
index de57eb8b26..918ad0a93a 100644
--- a/inc/wrapper-functions.php
+++ b/inc/wrapper-functions.php
@@ -965,6 +965,9 @@ function getHttpStatus () {
  * @access  private
  */
 function sendRawRedirect ($url) {
+	// Send helping header
+	setHttpStatus('302 Found');
+
 	// always close the session
 	session_write_close();
 
-- 
2.39.5