From 1e1188491367caefea828ed0dca143c7115c02c5 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Sun, 15 Nov 2009 20:20:35 +0000
Subject: [PATCH] Function renamed and dublicate code removed

---
 inc/functions.php                   |  4 +-
 inc/modules/member/what-welcome.php |  2 +-
 inc/mysql-manager.php               | 66 +++++++++++++----------------
 3 files changed, 33 insertions(+), 39 deletions(-)

diff --git a/inc/functions.php b/inc/functions.php
index 521a3fa7ba..4127ee62a1 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -3617,10 +3617,10 @@ function determinePageTitle () {
 		$mode = '';
 		if (getModule() == 'login') $mode = 'member';
 		elseif (getModule() == 'index') $mode = 'guest';
-		if ((!empty($mode)) && (getConfig('enable_what_title') == 'Y')) $TITLE .= " ".trim(getConfig('title_middle'))." ".getModuleDescription($mode, getWhat());
+		if ((!empty($mode)) && (getConfig('enable_what_title') == 'Y')) $TITLE .= ' ' . trim(getConfig('title_middle')) . ' ' . getTitleFromMenu($mode, getWhat());
 
 		// Add title decorations? (right)
-		if ((getConfig('enable_title_deco') == 'Y') && (getConfig('title_right') != '')) $TITLE .= " ".trim(getConfig('title_right'));
+		if ((getConfig('enable_title_deco') == 'Y') && (getConfig('title_right') != '')) $TITLE .= ' ' . trim(getConfig('title_right'));
 
 		// Remember title in constant for the template
 		$pageTitle = $TITLE;
diff --git a/inc/modules/member/what-welcome.php b/inc/modules/member/what-welcome.php
index 1737ea753f..3ccbb927aa 100644
--- a/inc/modules/member/what-welcome.php
+++ b/inc/modules/member/what-welcome.php
@@ -49,7 +49,7 @@ addMenuDescription('member', basename(__FILE__));
 // Export data for template
 $content = array(
 	'last_online' => generateDateTime($GLOBALS['last_online']['online']),
-	'last_module' => getModuleDescription('member', $GLOBALS['last_online']['module'])
+	'last_module' => getTitleFromMenu('member', $GLOBALS['last_online']['module'])
 );
 
 // Load header template
diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php
index e691d6cf7c..c9c73e5718 100644
--- a/inc/mysql-manager.php
+++ b/inc/mysql-manager.php
@@ -91,7 +91,7 @@ function getModuleTitle ($mod) {
 
 // "Getter" for module description
 // @TODO Can we cache this?
-function getModuleDescription ($mode, $what, $column = 'what') {
+function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') {
 	// Fix empty 'what'
 	if (empty($what)) {
 		$what = getConfig('index_home');
@@ -101,8 +101,12 @@ function getModuleDescription ($mode, $what, $column = 'what') {
 	$ret = '??? (' . $what . ')';
 
 	// Look for title
-	$result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE %s='%s' LIMIT 1",
-		array($mode, $column, $what), __FUNCTION__, __LINE__);
+	$result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `%s`='%s'" . $ADD . " LIMIT 1",
+		array(
+			$mode,
+			$column,
+			$what
+		), __FUNCTION__, __LINE__);
 
 	// Is there an entry?
 	if (SQL_NUMROWS($result) == 1) {
@@ -351,42 +355,32 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru
 	} // END - i
 
 	// Get the title from menu
-	$result = SQL_QUERY_ESC("SELECT title FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE %s='%s' ".$AND." LIMIT 1",
-	array($accessLevel, $type, $search), __FUNCTION__, __LINE__);
-
-	// Menu found?
-	if (SQL_NUMROWS($result) == 1) {
-		// Load title
-		list($ret) = SQL_FETCHROW($result);
-
-		// Shall we return it?
-		if ($return === true) {
-			// Return title
-			return $ret;
-		} elseif (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
-			// Output HTML code
-			$OUT = $prefix . "<strong><a class=\"you_are_here\" href=\"{?URL?}/modules.php?module=" . $modCheck . '&amp;' . $type . '=' . $search.$LINK_ADD . "\">" . $ret . "</a></strong>\n";
-
-			// Can we close the you-are-here navigation?
-			//* DEBUG: */ print(__LINE__."*".$type.'/'.getWhat()."*<br />");
-			if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
-				//* DEBUG: */ print(__LINE__.'+'.$type."+<br />");
-				// Add closing div and br-tag
-				$OUT .= "</div><br />\n";
-				$GLOBALS['nav_depth'] = '0';
-
-				// Run the filter chain
-				$ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => ""));
-				$OUT .= $ret['content'];
-			} // END - if
-		}
-	} // END - if
+	$ret = getTitleFromMenu($accessLevel, $search, $type, $AND);
 
-	// Free result
-	SQL_FREERESULT($result);
+	// Shall we return it?
+	if ($return === true) {
+		// Return title
+		return $ret;
+	} elseif (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
+		// Output HTML code
+		$OUT = $prefix . "<strong><a class=\"you_are_here\" href=\"{?URL?}/modules.php?module=" . $modCheck . '&amp;' . $type . '=' . $search.$LINK_ADD . "\">" . $ret . "</a></strong>\n";
+
+		// Can we close the you-are-here navigation?
+		//* DEBUG: */ print(__LINE__."*".$type.'/'.getWhat()."*<br />");
+		if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
+			//* DEBUG: */ print(__LINE__.'+'.$type."+<br />");
+			// Add closing div and br-tag
+			$OUT .= "</div><br />\n";
+			$GLOBALS['nav_depth'] = '0';
+
+			// Run the filter chain
+			$ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => ""));
+			$OUT .= $ret['content'];
+		} // END - if
+	}
 
 	// Return or output HTML code?
-	if ($output) {
+	if ($output === true) {
 		// Output HTML code here
 		outputHtml($OUT);
 	} else {
-- 
2.39.5