From 12d1414024e87153a133bb1d0fe0185ca2c700c5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 27 Jul 2009 20:33:32 +0000 Subject: [PATCH] A lot code refactured to newly introduces wrapper function isNicknameUsed() --- doubler.php | 10 +++------- inc/libs/user_functions.php | 8 ++++---- inc/modules/guest/what-login.php | 1 - inc/modules/guest/what-register.php | 2 +- inc/wrapper-functions.php | 21 +++++++++++++++++++++ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/doubler.php b/doubler.php index a521ad4709..3a3cb93ba4 100644 --- a/doubler.php +++ b/doubler.php @@ -64,11 +64,8 @@ if (REQUEST_ISSET_GET(('refid'))) $GLOBALS['refid'] = REQUEST_GET(('refid')); // Only check this if refid is provided! if ($GLOBALS['refid'] > 0) { - // Probe for nickname extension and if a nickname was supplied by URL - $probe_nickname = ((EXT_IS_ACTIVE('nickname')) && ((''.round($GLOBALS['refid']).'') != $GLOBALS['refid'])); - // Do we have nickname or userid set? - if ($probe_nickname === true) { + if (isNicknameUsed($GLOBALS['refid'])) { // Nickname in URL, so load the ID $result = SQL_QUERY_ESC("SELECT userid, status FROM `{!_MYSQL_PREFIX!}_user_data` WHERE nickname='%s' LIMIT 1", array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__); @@ -103,8 +100,7 @@ if (isFormSent()) { // Begin with doubling process if ((REQUEST_ISSET_POST(('userid'))) && (REQUEST_ISSET_POST(('pass'))) && (REQUEST_ISSET_POST(('points')))) { // Probe for nickname extension and if a nickname was entered - $probe_nickname = ((EXT_IS_ACTIVE('nickname')) && ((''.round(REQUEST_POST('userid')).'') != REQUEST_POST('userid'))); - if ($probe_nickname) { + if (isNickNameUsed(REQUEST_POST('userid'))) { // Nickname in URL, so load the ID $result = SQL_QUERY_ESC("SELECT userid, status, password FROM `{!_MYSQL_PREFIX!}_user_data` WHERE nickname='%s' LIMIT 1", array(REQUEST_POST('userid')), __FILE__, __LINE__); @@ -186,7 +182,7 @@ if (isFormSent()) { } elseif (REQUEST_POST('points') > getConfig('doubler_max')) { // Too much points entered define('__ERROR_MSG', getMessage('DOUBLER_FORM_POINTS_MAX')); - } elseif ($probe_nickname) { + } elseif (isNickNameUsed(REQUEST_POST('userid'))) { // Cannot resolv nickname -> userid define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_NICKNAME')); } else { diff --git a/inc/libs/user_functions.php b/inc/libs/user_functions.php index 27ec67fe21..1d39e644e8 100644 --- a/inc/libs/user_functions.php +++ b/inc/libs/user_functions.php @@ -283,11 +283,11 @@ function USER_DO_LOGIN ($uid, $passwd) { if ((EXT_IS_ACTIVE('nickname')) && (NICKNAME_PROBE_ON_USERID($uid))) { // Nickname entered $result = SQL_QUERY_ESC("SELECT userid, password, last_online".$lastOnline." FROM `{!_MYSQL_PREFIX!}_user_data` WHERE nickname='%s' AND `status`='CONFIRMED' LIMIT 1", - array($uid), __FUNCTION__, __LINE__); + array($uid), __FUNCTION__, __LINE__); } else { // Direct userid entered $result = SQL_QUERY_ESC("SELECT userid, password, last_online".$lastOnline." FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s AND `status`='CONFIRMED' LIMIT 1", - array($uid, $content['hash']), __FUNCTION__, __LINE__); + array($uid, $content['hash']), __FUNCTION__, __LINE__); } // Load entry @@ -295,7 +295,7 @@ function USER_DO_LOGIN ($uid, $passwd) { if (!empty($content['userid'])) $uid = bigintval($content['userid']); // Is there an entry? - if ((SQL_NUMROWS($result) == 1) && ((($probe_nickname) && (!empty($content['userid']))) || ($content['userid'] == $uid))) { + if ((SQL_NUMROWS($result) == 1) && ((isNicknameUsed($content['userid'] === true) && (!empty($content['userid']))) || ($content['userid'] == $uid))) { // Free result SQL_FREERESULT($result); @@ -372,7 +372,7 @@ function USER_DO_LOGIN ($uid, $passwd) { // Wrong password! $URL = 'modules.php?module=index&what=login&login='.getCode('WRONG_PASS'); } - } elseif ((($probe_nickname) && (!empty($content['userid']))) || ($content['userid'] == $uid)) { + } elseif (((isNicknameUsed($content['userid'])) && (!empty($content['userid']))) || ($content['userid'] == $uid)) { // Other account status? // @TODO Can this query be merged with above query? $result = SQL_QUERY_ESC("SELECT status FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", diff --git a/inc/modules/guest/what-login.php b/inc/modules/guest/what-login.php index 04c9285dfa..f48373d62f 100644 --- a/inc/modules/guest/what-login.php +++ b/inc/modules/guest/what-login.php @@ -53,7 +53,6 @@ global $DATA; // Initialize variables $errorCode = 0; -$probe_nickname = false; $uid = false; $hash = ''; $URL = ''; diff --git a/inc/modules/guest/what-register.php b/inc/modules/guest/what-register.php index 44b47978d9..2400030566 100644 --- a/inc/modules/guest/what-register.php +++ b/inc/modules/guest/what-register.php @@ -195,7 +195,7 @@ if ((isFormSent()) && (($isFailed === false) || (IS_ADMIN()))) { // Add design when extension sql_patches is v0.2.7 or greater // @TODO Rewrite these all to a single filter $ADD1 = ''; $ADD2 = ''; - if (GET_EXT_VERSION('sql_patches') >= '0.2.7') { + if (GET_EXT_VERSION('theme') >= '0.0.8') { // Okay, add design here $ADD1 = ", `curr_theme`"; $ADD2 = ", '".getCurrentTheme()."'"; diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 7068fdc8bb..bbe9c0c879 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -423,5 +423,26 @@ function isConfigLocalLoaded () { return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true)); } +// Checks wether a nickname or userid was entered and caches the result +function isNicknameUsed ($userid) { + // Default is false + $isUsed = false; + + // Is the cache there + if (isset($GLOBALS['cache_probe_nicknames'][$userid])) { + // Then use it + $isUsed = $GLOBALS['cache_probe_nicknames'][$userid]; + } else { + // Determine it + $isUsed = ((EXT_IS_ACTIVE('nickname')) && ((''.round($userid).'') != $userid)); + + // And write it to the cache + $GLOBALS['cache_probe_nicknames'][$userid] = $isUsed; + } + + // Return the result + return $isUsed; +} + // [EOF] ?> -- 2.39.2