From: Roland Häder Date: Wed, 29 Jun 2011 02:05:52 +0000 (+0000) Subject: Fixed handling of nicknames as 'refid': X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=commitdiff_plain;h=815ca2471c4e145975873d2b754b91f78bd7b5d7 Fixed handling of nicknames as 'refid': - 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 --- diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index fb162595b7..3594f60b0d 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -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); diff --git a/inc/functions.php b/inc/functions.php index be1223d7b4..1d535c60b6 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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 4eb1fe139f..780de8e94b 100644 --- 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&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&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 diff --git a/sponsor_ref.php b/sponsor_ref.php index d6cbd1f0de..dd2bb617c6 100644 --- a/sponsor_ref.php +++ b/sponsor_ref.php @@ -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 .= '&what=sponsor_reg&refid=' . $GLOBALS['refid']; + $url .= '&what=sponsor_reg&refid=' . determineReferalId(); } // END - if // Load the URL