From f0c86248d1ca0d6d0859d98796cb1da28884201e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 27 Sep 2010 13:16:45 +0000 Subject: [PATCH] Wrapper function introduced, description for random refid rewritten: - New wrapper function getDefRefid() introduced - Description in admin area for random referal id rewritten, it now matches with the actual code logic and is now easier to understand - TODOs.txt updated --- DOCS/TODOs.txt | 12 ++--- inc/autopurge/purge-inact.php | 2 +- inc/functions.php | 44 +++++++++++-------- inc/language/de.php | 7 +-- inc/libs/task_functions.php | 2 +- inc/libs/user_functions.php | 4 +- inc/modules/admin/what-config_refid.php | 2 +- inc/modules/admin/what-list_autopurge.php | 16 +++---- inc/wrapper-functions.php | 14 +++++- mailid_top.php | 2 +- ref.php | 2 +- .../de/html/admin/admin_config_order.tpl | 4 +- .../de/html/admin/admin_config_refid.tpl | 22 ++++++---- templates/de/html/admin/admin_edit_user.tpl | 6 +-- .../html/admin/admin_list_autopurge_row.tpl | 2 +- 15 files changed, 84 insertions(+), 57 deletions(-) diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index ef407804c6..caff153be7 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -42,15 +42,15 @@ ./inc/extensions-functions.php:434:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) ) ./inc/extensions-functions.php:564: // @TODO Extension is loaded, what next? ./inc/functions.php:110: // @TODO Extension 'msg' does not exist -./inc/functions.php:1501: // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ? -./inc/functions.php:1589: // @TODO Are these convertions still required? -./inc/functions.php:1607:// @TODO Rewrite this function to use readFromFile() and writeToFile() +./inc/functions.php:1509: // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ? +./inc/functions.php:1597: // @TODO Are these convertions still required? +./inc/functions.php:1615:// @TODO Rewrite this function to use readFromFile() and writeToFile() ./inc/functions.php:179:// @TODO Rewrite this to an extension 'smtp' -./inc/functions.php:2265: // @TODO This is still very static, rewrite it somehow +./inc/functions.php:2273: // @TODO This is still very static, rewrite it somehow ./inc/gen_sql_patches.php:94:// @TODO Rewrite this to a filter ./inc/install-functions.php:57: // @TODO DEACTIVATED: changeDataInFile(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0); -./inc/language/de.php:1089:// @TODO Rewrite these two constants -./inc/language/de.php:1104:// @TODO Rewrite these three constants +./inc/language/de.php:1090:// @TODO Rewrite these two constants +./inc/language/de.php:1105:// @TODO Rewrite these three constants ./inc/language/de.php:286: // @TODO Following two are unused? ./inc/language/de.php:789:// @TODO Are these constants longer used? ./inc/language-functions.php:241: // @TODO These are all valid languages, again hard-coded diff --git a/inc/autopurge/purge-inact.php b/inc/autopurge/purge-inact.php index faa424f51e..3301af8d19 100644 --- a/inc/autopurge/purge-inact.php +++ b/inc/autopurge/purge-inact.php @@ -54,7 +54,7 @@ if (getConfig('autopurge_inactive') == 'Y') { // Init exclusion list // @TODO Rewrite these if() blocks to a filter $EXCLUDE_LIST = ''; - if (isValidUserId(getConfig('def_refid'))) $EXCLUDE_LIST .= ' AND `userid` != {?def_refid?}'; + if (isValidUserId(getDefRefid())) $EXCLUDE_LIST .= ' AND `userid` != {?def_refid?}'; // Check for more extensions if (isExtensionActive('beg')) $EXCLUDE_LIST .= ' AND `userid` != {?beg_userid?}'; if (isExtensionActive('bonus')) $EXCLUDE_LIST .= ' AND `userid` != {?bonus_userid?}'; diff --git a/inc/functions.php b/inc/functions.php index 29151e81e0..7c3470844c 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -661,16 +661,24 @@ function generateRandomCode ($length, $code, $userid, $DATA = '') { // Build key string $keys = getConfig('SITE_KEY') . getEncryptSeperator() . getConfig('DATE_KEY'); - if (isConfigEntrySet('secret_key')) $keys .= getEncryptSeperator().getSecretKey(); - if (isConfigEntrySet('file_hash')) $keys .= getEncryptSeperator().getFileHash(); + if (isConfigEntrySet('secret_key')) { + $keys .= getEncryptSeperator().getSecretKey(); + } // END - if + if (isConfigEntrySet('file_hash')) { + $keys .= getEncryptSeperator().getFileHash(); + } // END - if $keys .= getEncryptSeperator() . getDateFromPatchTime(); - if (isConfigEntrySet('master_salt')) $keys .= getEncryptSeperator().getMasterSalt(); + if (isConfigEntrySet('master_salt')) { + $keys .= getEncryptSeperator().getMasterSalt(); + } // END - if // Build string from misc data $data = $code . getEncryptSeperator() . $userid . getEncryptSeperator() . $DATA; // Add more additional data - if (isSessionVariableSet('u_hash')) $data .= getEncryptSeperator() . getSession('u_hash'); + if (isSessionVariableSet('u_hash')) { + $data .= getEncryptSeperator() . getSession('u_hash'); + } // END - if // Add referal id, language, theme and userid $data .= getEncryptSeperator() . determineReferalId(); @@ -1278,11 +1286,11 @@ function genScrambleString ($len) { // First we need to setup randomized numbers from 0 to 31 for ($idx = 0; $idx < $len; $idx++) { // Generate number - $rand = mt_rand(0, ($len -1)); + $rand = mt_rand(0, ($len - 1)); // Check for it by creating more numbers while (array_key_exists($rand, $scrambleNumbers)) { - $rand = mt_rand(0, ($len -1)); + $rand = mt_rand(0, ($len - 1)); } // END - while // Add number @@ -1926,34 +1934,34 @@ function determineReferalId () { // Check if refid is set if ((isset($GLOBALS['refid'])) && ($GLOBALS['refid'] > 0)) { // This is fine... - } elseif ((isGetRequestParameterSet('user')) && (basename($_SERVER['PHP_SELF']) == 'click.php')) { - // The variable user comes from the click-counter script click.php and we only accept this here - $GLOBALS['refid'] = bigintval(getRequestParameter('user')); } elseif (isPostRequestParameterSet('refid')) { - // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts) + // Get referal id from POST element refid $GLOBALS['refid'] = secureString(postRequestParameter('refid')); } elseif (isGetRequestParameterSet('refid')) { - // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts) + // Get referal id from GET parameter refid $GLOBALS['refid'] = secureString(getRequestParameter('refid')); } elseif (isGetRequestParameterSet('ref')) { // Set refid=ref (the referal link uses such variable) $GLOBALS['refid'] = secureString(getRequestParameter('ref')); + } elseif ((isGetRequestParameterSet('user')) && (basename($_SERVER['PHP_SELF']) == 'click.php')) { + // The variable user comes from click.php + $GLOBALS['refid'] = bigintval(getRequestParameter('user')); } elseif ((isSessionVariableSet('refid')) && (isValidUserId(getSession('refid')))) { // Set session refid als global $GLOBALS['refid'] = bigintval(getSession('refid')); - } elseif ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isRandomReferalIdEnabled())) { + } elseif (isRandomReferalIdEnabled()) { // Select a random user which has confirmed enougth mails $GLOBALS['refid'] = determineRandomReferalId(); - } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getConfig('def_refid')))) { + } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid()))) { // Set default refid as refid in URL - $GLOBALS['refid'] = getConfig('def_refid'); + $GLOBALS['refid'] = getDefRefid(); } else { // No default id when sql_patches is not installed or none set $GLOBALS['refid'] = null; } // Set cookie when default refid > 0 - if (!isSessionVariableSet('refid') || (isValidUserId($GLOBALS['refid'])) || ((!isValidUserId(getSession('refid'))) && (isConfigEntrySet('def_refid')) && (isValidUserId(getConfig('def_refid'))))) { + if (!isSessionVariableSet('refid') || (isValidUserId($GLOBALS['refid'])) || ((!isValidUserId(getSession('refid'))) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid())))) { // Default is not found $found = false; @@ -1961,15 +1969,15 @@ function determineReferalId () { if ((isExtensionActive('nickname')) && (isNicknameUsed($GLOBALS['refid']))) { // Nickname in URL, so load the id $found = fetchUserData($GLOBALS['refid'], 'nickname'); - } elseif ($GLOBALS['refid'] > 0) { + } elseif (isValidUserId($GLOBALS['refid'])) { // Direct userid entered $found = fetchUserData($GLOBALS['refid']); } // Is the record valid? - if ((($found === false) || (!isUserDataValid())) && (isConfigEntrySet('def_refid'))) { + if ((($found === false) || (!isUserDataValid())) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2'))) { // No, then reset referal id - $GLOBALS['refid'] = getConfig('def_refid'); + $GLOBALS['refid'] = getDefRefid(); } // END - if // Set cookie diff --git a/inc/language/de.php b/inc/language/de.php index 6c32c02272..98cf72d544 100644 --- a/inc/language/de.php +++ b/inc/language/de.php @@ -1051,9 +1051,10 @@ addMessages(array( 'EMAIL_DETAILS' => "Email-Details", 'EMAIL_DETAILS_LINK' => "Details anzeigen", 'ADMIN_CONFIG_REFID_TITLE' => "Einstellungen zum Referal-Link", - 'ADMIN_RANDOM_ZERO_REFID' => "Soll per Zufall ein Mitglied nach folgenden Kriterien ausgewählt werden, wenn keine Standart-Refid eingestellt ist?", - 'ADMIN_RAND_REFID_ENABLED' => "Mitglieder per Zufall wählen", - 'ADMIN_RAND_REFID_DISABLED' => "Referal-Id 0 verwenden", + 'ADMIN_RANDOM_ZERO_REFID' => "Soll per Zufall ein Mitglied werden oder soll die oben eingestellte Standart-Refid verwendet werden?", + 'ADMIN_RANDOM_REFID_ENABLED' => "Mitglieder per Zufall wählen", + 'ADMIN_RANDOM_REFID_DISABLED' => "Voreingestellte Referal-Id setzen", + 'ADMIN_CONFIG_RANDOM_REFID_TITLE' => "Kriterien wonach ein Mitglied als Zufallsreferal ausgewählt wird:", 'ADMIN_RANDOM_MIN_CONFIRMED' => "Wie viele bestätigte Mails muss ein Mitglied mindestens haben, um per Zufall ausgewählt zu werden?", 'EMAILS_RECEIVED' => "Emails empfangen", 'MAILS_CONFIRMED' => "Emails bestätigt", diff --git a/inc/libs/task_functions.php b/inc/libs/task_functions.php index b1a98ecc8a..f067f2e4eb 100644 --- a/inc/libs/task_functions.php +++ b/inc/libs/task_functions.php @@ -237,7 +237,7 @@ function outputAdvancedOverview (&$result_main) { // Check for more extensions // @TODO These can be rewritten to filter - if (getConfig('def_refid') > 0) $EXCLUDE_LIST .= ' AND d.`userid` != {?def_refid?}'; + if (isValidUserId(getDefRefid())) $EXCLUDE_LIST .= ' AND d.`userid` != {?def_refid?}'; if (isExtensionActive('beg')) $EXCLUDE_LIST .= ' AND d.`userid` != {?beg_userid?}'; if (isExtensionActive('bonus')) $EXCLUDE_LIST .= ' AND d.`userid` != {?bonus_userid?}'; if (isExtensionActive('doubler')) $EXCLUDE_LIST .= ' AND d.`userid` != {?doubler_userid?}'; diff --git a/inc/libs/user_functions.php b/inc/libs/user_functions.php index fc9e433269..1c7ae8a45b 100644 --- a/inc/libs/user_functions.php +++ b/inc/libs/user_functions.php @@ -253,8 +253,8 @@ function determineRandomReferalId () { // Use that userid as new referal id list($refid) = SQL_FETCHROW($result); - // Reset this user's counter - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0 WHERE `userid`=%s LIMIT 1", + // Reset all users, this makes this random referal id more challenging + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0", array($refid), __FUNCTION__, __LINE__); } // END - if diff --git a/inc/modules/admin/what-config_refid.php b/inc/modules/admin/what-config_refid.php index 9b4a3d57a7..7aad038823 100644 --- a/inc/modules/admin/what-config_refid.php +++ b/inc/modules/admin/what-config_refid.php @@ -48,7 +48,7 @@ if (isFormSent()) { adminSaveSettingsFromPostData(); } else { // Prepare member selection - $content['form_selection'] = addMemberSelectionBox(getConfig('def_refid'), false, true, true, 'def_refid'); + $content['form_selection'] = addMemberSelectionBox(getDefRefid(), false, true, true, 'def_refid'); // Prepare contants for the template foreach (array('refid_target_index','refid_target_register','select_user_zero_refid_y','select_user_zero_refid_n') as $entry) { diff --git a/inc/modules/admin/what-list_autopurge.php b/inc/modules/admin/what-list_autopurge.php index 69404cd437..2835465e1b 100644 --- a/inc/modules/admin/what-list_autopurge.php +++ b/inc/modules/admin/what-list_autopurge.php @@ -46,25 +46,25 @@ addMenuDescription('admin', __FILE__); // Exclude default referal id if set // @TODO Rewrite those lines to filter $EXCLUDE_LIST = ''; -if (getConfig('def_refid') > 0) $EXCLUDE_LIST .= ' AND d.userid != {?def_refid?}'; +if (isValidUserId(getDefRefid())) $EXCLUDE_LIST .= ' AND d.userid != {?def_refid?}'; if (isExtensionActive('beg')) $EXCLUDE_LIST .= ' AND d.userid != {?beg_userid?}'; if (isExtensionActive('bonus')) $EXCLUDE_LIST .= ' AND d.userid != {?bonus_userid?}'; if (isExtensionActive('doubler')) $EXCLUDE_LIST .= ' AND d.userid != {?doubler_userid?}'; -if (isExtensionInstalledAndNewer('holiday', '0.1.3')) $EXCLUDE_LIST .= " AND d.holiday_active='N'"; +if (isExtensionInstalledAndNewer('holiday', '0.1.3')) $EXCLUDE_LIST .= " AND d.`holiday_active`='N'"; // Check for all accounts $result = SQL_QUERY("SELECT - d.userid, d.gender, d.surname, d.family, d.email, d.joined, d.last_online, d.ap_notified + d.`userid`, d.`gender`, d.`surname`, d.`family`, d.`email`, d.`joined`, d.`last_online`, d.`ap_notified` FROM `{?_MYSQL_PREFIX?}_user_data` AS d WHERE d.`status`='CONFIRMED' AND - d.joined < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND - d.last_online < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND - d.ap_notified < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) + d.`joined` < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND + d.`last_online` < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND + d.`ap_notified` < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) ".$EXCLUDE_LIST." ORDER BY - d.userid ASC", __FILE__, __LINE__); + d.`userid` ASC", __FILE__, __LINE__); if (!SQL_HASZERONUMS($result)) { // Ok, we have found some inactive accounts @@ -79,7 +79,7 @@ if (!SQL_HASZERONUMS($result)) { 'email' => '' . $content['email'] . '', 'joined' => generateDateTime($content['joined'], 2), 'last_online' => generateDateTime($content['last_online'], 2), - 'notified' => generateDateTime($content['ap_notified'], 2), + 'ap_notified' => generateDateTime($content['ap_notified'], 2), ); // Load row template diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index b42874ee8a..76ef4a034e 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -1317,7 +1317,7 @@ function isRandomReferalIdEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('select_user_zero_refid') == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y')); } // END - if // Return cache @@ -1336,6 +1336,18 @@ function getDefaultLanguage () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for default referal id +function getDefRefid () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('def_refid'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for path function getPath () { // Do we have cache? diff --git a/mailid_top.php b/mailid_top.php index d77d5eba4c..5fa5fb3e1b 100644 --- a/mailid_top.php +++ b/mailid_top.php @@ -260,7 +260,7 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr // Is an active-rallye running and this is not a notification mail? if ((isBonusRallyeActive()) && ($notify != 'Y')) { // Shall I exclude the webmaster's own userid from the active-rallye? - if ((((getBonusUserId() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserId() != $userId)) && (getConfig('def_refid') != $userId)) { + if ((((getBonusUserId() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserId() != $userId)) && (getDefRefid() != $userId)) { // Add points and remember ranking are done in this function.... addTurboBonus($urlId, $userId, $type); diff --git a/ref.php b/ref.php index 59fe143ffc..3b5fd80085 100644 --- a/ref.php +++ b/ref.php @@ -68,7 +68,7 @@ if (isValidUserId(determineReferalId())) { // Do we have an entry? if (!isUserDataValid()) { // No entry, so no referal id - $GLOBALS['refid'] = getConfig('def_refid'); + $GLOBALS['refid'] = getDefRefid(); } // END - if } } // END - if diff --git a/templates/de/html/admin/admin_config_order.tpl b/templates/de/html/admin/admin_config_order.tpl index ed24684ebe..3d6c42476b 100644 --- a/templates/de/html/admin/admin_config_order.tpl +++ b/templates/de/html/admin/admin_config_order.tpl @@ -104,8 +104,8 @@ {--ADMIN_ORDER_SELECTION_MODE--}: diff --git a/templates/de/html/admin/admin_config_refid.tpl b/templates/de/html/admin/admin_config_refid.tpl index 7378838dbc..ba95377356 100644 --- a/templates/de/html/admin/admin_config_refid.tpl +++ b/templates/de/html/admin/admin_config_refid.tpl @@ -15,25 +15,31 @@ - {--ADMIN_SELECT_REFID_TARGRT--}: - + {--ADMIN_SELECT_REFID_TARGRT--}: + - {--ADMIN_RANDOM_ZERO_REFID--} - + {--ADMIN_RANDOM_ZERO_REFID--} + + + + {--ADMIN_CONFIG_RANDOM_REFID_TITLE--} + + + {--ADMIN_RANDOM_MIN_CONFIRMED--} diff --git a/templates/de/html/admin/admin_edit_user.tpl b/templates/de/html/admin/admin_edit_user.tpl index 07e30cd6f5..78fc892b48 100644 --- a/templates/de/html/admin/admin_edit_user.tpl +++ b/templates/de/html/admin/admin_edit_user.tpl @@ -10,9 +10,9 @@ {--GENDER--}: diff --git a/templates/de/html/admin/admin_list_autopurge_row.tpl b/templates/de/html/admin/admin_list_autopurge_row.tpl index cf02eb6a08..58164702a8 100644 --- a/templates/de/html/admin/admin_list_autopurge_row.tpl +++ b/templates/de/html/admin/admin_list_autopurge_row.tpl @@ -6,5 +6,5 @@ $content[email] $content[joined] $content[last_online] - $content[notified] + $content[ap_notified] -- 2.39.2