Rewritten to use NICKNAME_IS_ACTIVE()
[mailer.git] / inc / libs / nickname_functions.php
index cb013cf8ab6416b49399106aa6aec796831f92fe..c776c5fb50092588a4790f3368546f66883a7bb4 100644 (file)
@@ -42,7 +42,7 @@ if (!defined('__SECURITY')) {
        require($INC);
 }
 
-//
+// Checks wether the nickname is active
 function NICKNAME_IS_ACTIVE ($uidNick) {
        // By default nothing is found...
        $ret = false;
@@ -55,16 +55,11 @@ function NICKNAME_IS_ACTIVE ($uidNick) {
                // Increment cache counter
                incrementConfigEntry('cache_hits');
        } else {
-               // Search in database
-               // @TODO Can we replace this with GET_TOTAL_DATA() ?
-               $result = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s OR nickname='%s' LIMIT 1",
-               array(bigintval($uidNick), $uidNick), __FUNCTION__, __LINE__);
-
-               // Check existence of nickname
-               $ret = (SQL_NUMROWS($result) == 1);
+               // Nickname or userid used?
+               $nick = NICKNAME_GET_NICK($uidNick);
 
                // Put it in cache
-               $GLOBALS['cache_array']['nick_active'][$uidNick] = $ret;
+               $GLOBALS['cache_array']['nick_active'][$uidNick] = (!empty($nick));
 
                // Free result
                SQL_FREERESULT($result);
@@ -74,7 +69,7 @@ function NICKNAME_IS_ACTIVE ($uidNick) {
        return $ret;
 }
 
-//
+// "Getter" for nickname for specfied userid
 function NICKNAME_GET_NICK ($userid) {
        // If not found...
        $ret = '';
@@ -86,10 +81,20 @@ function NICKNAME_GET_NICK ($userid) {
 
                // Increment cache counter
                incrementConfigEntry('cache_hits');
-       } elseif (NICKNAME_IS_ACTIVE($userid)) {
-               // Search for non-empty nickname
-               $result = SQL_QUERY_ESC("SELECT nickname FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s AND nickname != '' LIMIT 1",
-               array(bigintval($userid)), __FUNCTION__, __LINE__);
+       } else {
+               // Init result
+               $result = false;
+
+               // Nickname or userid used?
+               if (''.round($uidNick).'' === ''.$uidNick.'') {
+                       // Userid given
+                       $result = SQL_QUERY_ESC("SELECT `userid`  FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid` =%s LIMIT 1",
+                               array(bigintval($uidNick)), __FUNCTION__, __LINE__);
+               } else {
+                       // Nickname given
+                       $result = SQL_QUERY_ESC("SELECT `userid`  FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `nickname`='%s' LIMIT 1",
+                               array($uidNick), __FUNCTION__, __LINE__);
+               }
 
                // Found?
                if (SQL_NUMROWS($result) == 1) {
@@ -108,10 +113,5 @@ function NICKNAME_GET_NICK ($userid) {
        return $ret;
 }
 
-// Simple wrapper function
-function NICKNAME_PROBE_ON_USERID ($uid) {
-       return (NICKNAME_GET_NICK($uid) != '');
-}
-
 //
 ?>