Fixed handling of nicknames as 'refid':
authorRoland Häder <roland@mxchange.org>
Wed, 29 Jun 2011 02:05:52 +0000 (02:05 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 29 Jun 2011 02:05:52 +0000 (02:05 +0000)
- determineReferalId() does now detect and handle nicknames as referal ids
  correctly by setting the userid as 'refid'
- Removed obsolete code from ref.php (see determineReferalId())
- TODOs.txt updated

DOCS/TODOs.txt
inc/functions.php
ref.php
sponsor_ref.php

index fb16259..3594f60 100644 (file)
@@ -50,9 +50,9 @@
 ./inc/functions.php:1318:                      // @TODO Are these convertions still required?
 ./inc/functions.php:1336:// @TODO Rewrite this function to use readFromFile() and writeToFile()
 ./inc/functions.php:163:// @TODO Rewrite this to an extension 'smtp'
-./inc/functions.php:1918:      // @TODO Find a way to cache this
-./inc/functions.php:2019:      // @TODO This is still very static, rewrite it somehow
-./inc/functions.php:2199:      // @TODO Rename column data_type to e.g. mail_status
+./inc/functions.php:1927:      // @TODO Find a way to cache this
+./inc/functions.php:2028:      // @TODO This is still very static, rewrite it somehow
+./inc/functions.php:2208:      // @TODO Rename column data_type to e.g. mail_status
 ./inc/functions.php:92:                // @TODO Extension 'msg' does not exist
 ./inc/gen_sql_patches.php:95:// @TODO Rewrite this to a filter
 ./inc/install-functions.php:57:        // @TODO DEACTIVATED: changeDataInLocalConfigurationFile('OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0);
index be1223d..1d535c6 100644 (file)
@@ -1658,60 +1658,69 @@ function determineReferalId () {
        } // END - if
 
        // Check if refid is set
-       if ((isset($GLOBALS['refid'])) && ($GLOBALS['refid'] > 0)) {
+       if (isReferalIdValid()) {
                // This is fine...
        } elseif (isPostRequestParameterSet('refid')) {
                // Get referal id from POST element refid
-               $GLOBALS['refid'] = secureString(postRequestParameter('refid'));
+               setReferalId(secureString(postRequestParameter('refid')));
        } elseif (isGetRequestParameterSet('refid')) {
                // Get referal id from GET parameter refid
-               $GLOBALS['refid'] = secureString(getRequestParameter('refid'));
+               setReferalId(secureString(getRequestParameter('refid')));
        } elseif (isGetRequestParameterSet('ref')) {
                // Set refid=ref (the referal link uses such variable)
-               $GLOBALS['refid'] = secureString(getRequestParameter('ref'));
+               setReferalId(secureString(getRequestParameter('ref')));
        } elseif ((isGetRequestParameterSet('user')) && (basename($_SERVER['PHP_SELF']) == 'click.php')) {
                // The variable user comes from  click.php
-               $GLOBALS['refid'] = bigintval(getRequestParameter('user'));
+               setReferalId(bigintval(getRequestParameter('user')));
        } elseif ((isSessionVariableSet('refid')) && (isValidUserId(getSession('refid')))) {
                // Set session refid als global
-               $GLOBALS['refid'] = bigintval(getSession('refid'));
+               setReferalId(bigintval(getSession('refid')));
        } elseif (isRandomReferalIdEnabled()) {
                // Select a random user which has confirmed enougth mails
-               $GLOBALS['refid'] = determineRandomReferalId();
+               setReferalId(determineRandomReferalId());
        } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid()))) {
                // Set default refid as refid in URL
-               $GLOBALS['refid'] = getDefRefid();
+               setReferalId(getDefRefid());
        } else {
                // No default id when sql_patches is not installed or none set
-               $GLOBALS['refid'] = null;
+               setReferalId(null);
        }
 
        // Set cookie when default refid > 0
-       if (!isSessionVariableSet('refid') || (isValidUserId($GLOBALS['refid'])) || ((!isValidUserId(getSession('refid'))) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid())))) {
+       if (!isSessionVariableSet('refid') || (!isValidUserId(getReferalId())) || ((!isValidUserId(getSession('refid'))) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid())))) {
                // Default is not found
                $found = false;
 
                // Do we have nickname or userid set?
-               if ((isExtensionActive('nickname')) && (isNicknameUsed($GLOBALS['refid']))) {
+               if ((isExtensionActive('nickname')) && (isNicknameUsed(getReferalId()))) {
                        // Nickname in URL, so load the id
-                       $found = fetchUserData($GLOBALS['refid'], 'nickname');
-               } elseif (isValidUserId($GLOBALS['refid'])) {
+                       $found = fetchUserData(getReferalId(), 'nickname');
+
+                       // If we found it, use the userid as referal id
+                       if ($found === true) {
+                               // Set the userid as 'refid'
+                               setReferalId(getUserData('userid'));
+                       } // END - if
+               } elseif (isValidUserId(getReferalId())) {
                        // Direct userid entered
-                       $found = fetchUserData($GLOBALS['refid']);
+                       $found = fetchUserData(getReferalId());
                }
 
                // Is the record valid?
                if ((($found === false) || (!isUserDataValid())) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2'))) {
                        // No, then reset referal id
-                       $GLOBALS['refid'] = getDefRefid();
+                       setReferalId(getDefRefid());
                } // END - if
 
                // Set cookie
-               setSession('refid', $GLOBALS['refid']);
-       } // END - if
+               setSession('refid', getReferalId());
+       } elseif (!isReferalIdValid()) {
+               // Not valid!
+               setSession('refid', 0);
+       }
 
        // Return determined refid
-       return $GLOBALS['refid'];
+       return getReferalId();
 }
 
 // Enables the reset mode and runs it
@@ -2343,6 +2352,21 @@ function determinePointsColumnFromSubjectLocked ($subject, $locked) {
        return $pointsColumn;
 }
 
+// Setter for referal id (no bigintval, or nicknames will fail!)
+function setReferalId ($refid) {
+       $GLOBALS['refid'] = $refid;
+}
+
+// Checks if 'refid' is valid
+function isReferalIdValid () {
+       return ((isset($GLOBALS['refid'])) && (getReferalId() !== NULL) && (getReferalId() > 0));
+}
+
+// Getter for referal id
+function getReferalId () {
+       return $GLOBALS['refid'];
+}
+
 //-----------------------------------------------------------------------------
 // Automatically re-created functions, all taken from user comments on www.php.net
 //-----------------------------------------------------------------------------
diff --git a/ref.php b/ref.php
index 4eb1fe1..780de8e 100644 (file)
--- a/ref.php
+++ b/ref.php
@@ -51,48 +51,22 @@ setContentType('text/html');
 // No refid by default
 $url = 'modules.php?module=index';
 
-if (isValidUserId(determineReferalId())) {
-       // Test if nickname or numeric id
-       if (isExtensionActive('nickname')) {
-               // Nickname in URL, so load the id
-               fetchUserData(determineReferalId(), 'nickname');
+// Check for determined referal id
+if ((isReferalIdValid()) && (isValidUserId(determineReferalId()))) {
+       // Update ref counter
+       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_clicks`=`ref_clicks`+1 WHERE `userid`=%s LIMIT 1",
+               array(makeDatabaseUserId(determineReferalId())), __FILE__, __LINE__);
 
-               // Do we have an entry?
-               if (isUserDataValid()) {
-                       // Load userid
-                       $GLOBALS['refid'] = getUserData('userid');
-               } else {
-                       // So do we have a userid?
-                       fetchUserData(determineReferalId());
+       // Base URL for redirection
+       switch (getConfig('refid_target')) {
+               case 'register':
+                       $url = 'modules.php?module=index&amp;what=register';
+                       break;
 
-                       // Do we have an entry?
-                       if (!isUserDataValid()) {
-                               // No entry, so no referal id
-                               $GLOBALS['refid'] = getDefRefid();
-                       } // END - if
-               }
-       } // END - if
-
-       // Update session
-       setSession('refid', determineReferalId());
-
-       // Is the refid valid?
-       if (isValidUserId(determineReferalId())) {
-               // Update ref counter
-               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_clicks`=`ref_clicks`+1 WHERE `userid`=%s LIMIT 1",
-                       array(makeDatabaseUserId(determineReferalId())), __FILE__, __LINE__);
-
-               // Base URL for redirection
-               switch (getConfig('refid_target')) {
-                       case 'register':
-                               $url = 'modules.php?module=index&amp;what=register';
-                               break;
-
-                       case 'index':
-                               $url = 'modules.php?module=index';
-                               break;
-               } // END - switch
-       } // END - if
+               case 'index':
+                       $url = 'modules.php?module=index';
+                       break;
+       } // END - switch
 } // END - if
 
 // Load the URL
index d6cbd1f..dd2bb61 100644 (file)
@@ -53,9 +53,9 @@ setContentType('text/html');
 $url = 'modules.php?module=index';
 
 // Do we have a referal id?
-if (isValidUserId($GLOBALS['refid'])) {
+if (isReferalIdValid()) {
        // We have an refid here. So we simply add it
-       $url .= '&amp;what=sponsor_reg&amp;refid=' . $GLOBALS['refid'];
+       $url .= '&amp;what=sponsor_reg&amp;refid=' . determineReferalId();
 } // END - if
 
 // Load the URL