From f225b2a600dba0c79fe2499d6360630a9d556bb3 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Thu, 8 Jul 2010 22:17:38 +0000
Subject: [PATCH] Rewrites to handle non-existent modules: - Getting module'
 title is now done while compilation phase (and not when the   filter runs).
 This allows us to modify it even after the page header has been   loaded. -
 TODOs.txt updated

---
 DOCS/TODOs.txt             | 12 ++++++------
 inc/language/de.php        |  1 +
 inc/module-functions.php   | 20 +++++++++++++-------
 inc/template-functions.php |  2 +-
 modules.php                |  3 +++
 5 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt
index 5bc1084cf4..095875b9fb 100644
--- a/DOCS/TODOs.txt
+++ b/DOCS/TODOs.txt
@@ -49,10 +49,10 @@
 ./inc/functions.php:2245:	// @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:63:	// @TODO DEACTIVATED: changeDataInFile(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0);
-./inc/language/de.php:1135:// @TODO Rewrite these two constants
-./inc/language/de.php:1150:// @TODO Rewrite these three constants
-./inc/language/de.php:301:	// @TODO Following two are unused?
-./inc/language/de.php:828:// @TODO Are these constants longer used?
+./inc/language/de.php:1136:// @TODO Rewrite these two constants
+./inc/language/de.php:1151:// @TODO Rewrite these three constants
+./inc/language/de.php:302:	// @TODO Following two are unused?
+./inc/language/de.php:829:// @TODO Are these constants longer used?
 ./inc/language-functions.php:234:	// @TODO These are all valid languages, again hard-coded
 ./inc/language-functions.php:46:// @TODO Rewrite all language constants to this function.
 ./inc/language/rallye_de.php:13: * @TODO Naming convention not applied for language strings             *
@@ -87,8 +87,8 @@
 ./inc/libs/yoomedia_functions.php:116:	$response = YOOMEDIA_QUERY_API('out_textmail.php', true); // @TODO Ask Yoo!Media for test script
 ./inc/load_config.php:77:	// @TODO Rewrite them to avoid this else block
 ./inc/loader/load_cache-extension.php:13: * @TODO Rewrite this whole file to load_cache-extensions.php           *
-./inc/module-functions.php:197:			// @TODO Nothing helped???
-./inc/module-functions.php:232:			// @TODO Rewrite this to a filter
+./inc/module-functions.php:203:			// @TODO Nothing helped???
+./inc/module-functions.php:238:			// @TODO Rewrite this to a filter
 ./inc/modules/admin/admin-inc.php:261:		// @TODO Rewrite this to $content = SQL_FETCHARRAY()
 ./inc/modules/admin/admin-inc.php:266:				// @TODO ACL is 'allow'... hmmm
 ./inc/modules/admin/admin-inc.php:332:					// @TODO Rewrite this to $content = SQL_FETCHARRAY()
diff --git a/inc/language/de.php b/inc/language/de.php
index 2284942c83..f77017472a 100644
--- a/inc/language/de.php
+++ b/inc/language/de.php
@@ -58,6 +58,7 @@ addMessages(array(
 	'_OKOPT' => "Optimiert.",
 	'MAILER_DOWN_FOR_MAINTENANCE' => "System wegen Wartungsarbeiten geschlossen.",
 	'MODULE_REGISTRY_404' => "Modul <span class=\"data\">%s</span> existiert nicht.",
+	'MODULE_ERROR_404' => "Fehler: Modul nicht gefunden",
 	'UNKNOWN_MODULE_DETECTED' => "Unbekanntes Modul %s",
 	'MAILER_WARNING' => "Warnung",
 	'DIE_CONFIG_CHANGED_YOU' => "Sie haben Ihre Config-Datei editiert! Auf Wiedersehen...",
diff --git a/inc/module-functions.php b/inc/module-functions.php
index 7918a233e8..beb8929522 100644
--- a/inc/module-functions.php
+++ b/inc/module-functions.php
@@ -49,7 +49,7 @@ function getModuleTitle ($module) {
 	$result = false;
 
 	// Is the script installed?
-	if (isInstalled()) {
+	if ((isInstalled()) && ($module != 'error')) {
 		// Check if cache is valid
 		if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isset($GLOBALS['cache_array']['modules']['module'])) && (in_array($module, $GLOBALS['cache_array']['modules']['module']))) {
 			// Load from cache
@@ -78,12 +78,18 @@ function getModuleTitle ($module) {
 
 	// Still no luck or empty title?
 	if (empty($data['title'])) {
-		// No name found
-		$data['title'] = getMaskedMessage('UNKNOWN_MODULE_DETECTED', $module);
-		if ((is_resource($result)) && (SQL_HASZERONUMS($result))) {
-			// Add module to database
-			$dummy = checkModulePermissions($module);
-		} // END - if
+		// Is it 'error'?
+		if ($module == 'error') {
+			// Error (real module was not found)
+			$data['title'] = getMessage('MODULE_ERROR_404');
+		}  else {
+			// No name found
+			$data['title'] = getMaskedMessage('UNKNOWN_MODULE_DETECTED', $module);
+			if ((is_resource($result)) && (SQL_HASZERONUMS($result))) {
+				// Add module to database
+				$dummy = checkModulePermissions($module);
+			} // END - if
+		}
 	} // END - if
 
 	// Return name
diff --git a/inc/template-functions.php b/inc/template-functions.php
index cec52e7ccb..81c6d2f5e1 100644
--- a/inc/template-functions.php
+++ b/inc/template-functions.php
@@ -1360,7 +1360,7 @@ function determinePageTitle () {
 
 		// Add title of module? (middle decoration will also be added!)
 		if ((isModuleTitleEnabled()) || ((!isWhatSet()) && (!isActionSet())) || (getModule() == 'admin')) {
-			$TITLE .= ' ' . trim(getConfig('title_middle')) . ' ' . getModuleTitle(getModule());
+			$TITLE .= ' ' . trim(getConfig('title_middle')) . ' {DQUOTE} . getModuleTitle(getModule()) . {DQUOTE}';
 		} // END - if
 
 		// Add title from what file
diff --git a/modules.php b/modules.php
index 5dcf9f06cf..446ffe9cd3 100644
--- a/modules.php
+++ b/modules.php
@@ -98,6 +98,9 @@ if ((isExtensionActive('maintenance')) && (getConfig('maintenance') == 'Y') && (
 
 				// Module not found!
 				addFatalMessage(__FILE__, __LINE__, getMaskedMessage('MODULE_REGISTRY_404', getModule()));
+
+				// Set module to error module (non-existent!)
+				setModule('error');
 			}
 			break;
 
-- 
2.39.5