From a38de258ffd36319f8b8338fa057957c205d89e3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 4 Oct 2009 22:35:49 +0000 Subject: [PATCH] Determination of username moved to filter FILTER_DETERMINE_USERNAME() (internal TODO) --- inc/filters.php | 42 ++++++++++++++++++++++++++++++++++++++++++ modules.php | 36 ------------------------------------ 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/inc/filters.php b/inc/filters.php index 5f9fa665c4..cf7d0dd08f 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -123,6 +123,7 @@ ORDER BY `filter_id` ASC", __FUNCTION__, __LINE__); // Init filters registerFilter('init', 'UPDATE_LOGIN_DATA'); registerFilter('init', 'INIT_RANDOMIZER'); + registerFilter('init', 'DETERMINE_USERNAME'); // Login failures handler registerFilter('post_youhere_line', 'CALL_HANDLER_LOGIN_FAILTURES'); @@ -575,5 +576,46 @@ function FILTER_REMOVE_UPDATES () { } // END - if } +// Determines username for current user state +function FILTER_DETERMINE_USERNAME () { + global $username; + + // Check if logged in + if (IS_MEMBER()) { + // Is still logged in so we welcome him with his name + $result = SQL_QUERY_ESC("SELECT `surname`, `family` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1", + array(getUserId()), __FILE__, __LINE__); + if (SQL_NUMROWS($result) == 1) { + // Load surname and family's name and build the username + list($s, $f) = SQL_FETCHROW($result); + $username = $s . ' ' . $f; + + // Additionally admin? + if (IS_ADMIN()) { + // Add it + $username .= ' ({--_ADMIN_SHORT--})'; + } // END - if + } else { + // Hmmm, logged in and no valid userid? + $username = '{--_UNKNOWN--}'; + + // Destroy session + destroyUserSession(); + + // Kill userid + setUserId(0); + } + + // Free memory + SQL_FREERESULT($result); + } elseif (IS_ADMIN()) { + // Admin is there + $username = getMessage('_ADMIN'); + } else { + // He's a guest, hello there... ;-) + $username = getMessage('_GUEST'); + } +} + // ?> diff --git a/modules.php b/modules.php index dcc22657d4..0d26db9cf0 100644 --- a/modules.php +++ b/modules.php @@ -55,42 +55,6 @@ require('inc/config-global.php'); // Fix missing module to 'index' if (!REQUEST_ISSET_GET('module')) REQUEST_SET_GET('module', 'index'); -// Check if logged in -if (IS_MEMBER()) { - // Is still logged in so we welcome him with his name - $result = SQL_QUERY_ESC("SELECT `surname`, `family` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1", - array(getUserId()), __FILE__, __LINE__); - if (SQL_NUMROWS($result) == 1) { - // Load surname and family's name and build the username - list($s, $f) = SQL_FETCHROW($result); - $username = $s . ' ' . $f; - - // Additionally admin? - if (IS_ADMIN()) { - // Add it - $username .= ' ({--_ADMIN_SHORT--})'; - } // END - if - } else { - // Hmmm, logged in and no valid userid? - $username = '{--_UNKNOWN--}'; - - // Destroy session - destroyUserSession(); - - // Kill userid - setUserId(0); - } - - // Free memory - SQL_FREERESULT($result); -} elseif (IS_ADMIN()) { - // Admin is there - $username = getMessage('_ADMIN'); -} else { - // He's a guest, hello there... ;-) - $username = getMessage('_GUEST'); -} - // The header file loadIncludeOnce('inc/header.php'); -- 2.39.5