]> git.mxchange.org Git - mailer.git/commitdiff
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 fb162595b751d5b7d5f411f074838d8edc06f5d6..3594f60b0d7ea4161fc96305bc0c9aed2b91a905 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: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);
 ./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 be1223d7b40a3a7ca61983734dae43382adf51bc..1d535c60b6212029582cab863dfe7d3bc728a1d8 100644 (file)
@@ -1658,60 +1658,69 @@ function determineReferalId () {
        } // END - if
 
        // Check if refid is set
        } // 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
                // 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
        } 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)
        } 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
        } 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
        } 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
        } 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
        } 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
        } else {
                // No default id when sql_patches is not installed or none set
-               $GLOBALS['refid'] = null;
+               setReferalId(null);
        }
 
        // Set cookie when default refid > 0
        }
 
        // 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?
                // 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
                        // 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
                        // 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
                }
 
                // 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
                } // END - if
 
                // Set cookie
-               setSession('refid', $GLOBALS['refid']);
-       } // END - if
+               setSession('refid', getReferalId());
+       } elseif (!isReferalIdValid()) {
+               // Not valid!
+               setSession('refid', 0);
+       }
 
        // Return determined refid
 
        // Return determined refid
-       return $GLOBALS['refid'];
+       return getReferalId();
 }
 
 // Enables the reset mode and runs it
 }
 
 // Enables the reset mode and runs it
@@ -2343,6 +2352,21 @@ function determinePointsColumnFromSubjectLocked ($subject, $locked) {
        return $pointsColumn;
 }
 
        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
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // Automatically re-created functions, all taken from user comments on www.php.net
 //-----------------------------------------------------------------------------
diff --git a/ref.php b/ref.php
index 4eb1fe139f7e9fb5bd3e0dd4b5390293f216c180..780de8e94b2b14e0bd9409fd5a75a333c9f4ceb2 100644 (file)
--- a/ref.php
+++ b/ref.php
@@ -51,48 +51,22 @@ setContentType('text/html');
 // No refid by default
 $url = 'modules.php?module=index';
 
 // 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
 } // END - if
 
 // Load the URL
index d6cbd1f0de10c076b9a16990154897b71790d003..dd2bb617c612b06c02caeefbb3ea6fcd40932de4 100644 (file)
@@ -53,9 +53,9 @@ setContentType('text/html');
 $url = 'modules.php?module=index';
 
 // Do we have a referal id?
 $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
        // 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
 } // END - if
 
 // Load the URL