A lot code refactured to newly introduces wrapper function isNicknameUsed()
authorRoland Häder <roland@mxchange.org>
Mon, 27 Jul 2009 20:33:32 +0000 (20:33 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 27 Jul 2009 20:33:32 +0000 (20:33 +0000)
doubler.php
inc/libs/user_functions.php
inc/modules/guest/what-login.php
inc/modules/guest/what-register.php
inc/wrapper-functions.php

index a521ad470903a35cc3c474e34223036fdf5d376f..3a3cb93ba46aaf228ace04231e7d1b766a6a667f 100644 (file)
@@ -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 {
index 27ec67fe21b9e88cb28609e43539ab0c542c0da3..1d39e644e8c7137b035c846dcff87f4d6b57f83d 100644 (file)
@@ -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&amp;what=login&amp;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",
index 04c9285dfad43228f548c61039868a1d7121f89b..f48373d62f062d148c5d60365ded7a6bb2a5f79c 100644 (file)
@@ -53,7 +53,6 @@ global $DATA;
 
 // Initialize variables
 $errorCode = 0;
-$probe_nickname = false;
 $uid = false;
 $hash = '';
 $URL = '';
index 44b47978d9b3219859bafc82492e5bdb620105ad..24000305668717e8bd7caa906f473c97045eb63e 100644 (file)
@@ -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()."'";
index 7068fdc8bb5baee5a5d0b658101fd58d621ccfe5..bbe9c0c87932b3b860a92bd60da0199b6946970c 100644 (file)
@@ -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]
 ?>