From: Roland Häder Date: Wed, 23 Jan 2013 11:20:08 +0000 (+0000) Subject: Rewrites to use filters instead of mass if() blocks X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=commitdiff_plain;h=6c6f24bd5a3817573d1d49ed114700914ae8c920 Rewrites to use filters instead of mass if() blocks --- diff --git a/inc/daily/daily_birthday.php b/inc/daily/daily_birthday.php index 7085425d84..beae7944a2 100644 --- a/inc/daily/daily_birthday.php +++ b/inc/daily/daily_birthday.php @@ -55,30 +55,38 @@ $day = getDay(); $month = getMonth(); $year = getYear(); -// Init variable +// Init variables $lastOnline = ''; +$excludeSql = ''; // Shall I include only active members? if ((getConfig('birthday_active') == 'Y') && (isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) { - $add = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}'; + $excludeSql = ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}'; +} // END - if + +// Is ext-holiday installed? +// @TODO Rewrite these if() blocks to a filter +if (isExtensionActive('holiday')) { + // Exclude those as well + $excludeSql .= " AND `d`.`holiday_active`='N'"; } // END - if // Only confirmed members shall receive birthday mails... $result_birthday = SQL_QUERY_ESC("SELECT - `userid`, - `email`, - `birth_year` + `d`.`userid`, + `d`.`email`, + `d`.`birth_year` FROM - `{?_MYSQL_PREFIX?}_user_data` + `{?_MYSQL_PREFIX?}_user_data` AS `d` WHERE - `status`='CONFIRMED' - " . runFilterChain('user_exclusion_sql', ' ') . " AND - `birth_day`=%s AND - `birth_month`=%s AND - `birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364)) - ".$lastOnline." + `d`.`status`='CONFIRMED' + " . runFilterChain('user_exclusion_sql', $excludeSql) . " AND + `d`.`birth_day`=%s AND + `d`.`birth_month`=%s AND + `d`.`birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364)) + " . $lastOnline . " ORDER BY - `userid` ASC", + `d`.`userid` ASC", array($day, $month), __FILE__, __LINE__); if (!SQL_HASZERONUMS($result_birthday)) { diff --git a/inc/libs/bonus_functions.php b/inc/libs/bonus_functions.php index 525e0468b8..448accb5f3 100644 --- a/inc/libs/bonus_functions.php +++ b/inc/libs/bonus_functions.php @@ -270,7 +270,7 @@ function handleBonusPoints ($mode, $userid) { } // Purges expired fast-click bonus entries -function purgeExpiredTurboBonus() { +function purgeExpiredTurboBonus () { // Remove entries $result = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE (UNIX_TIMESTAMP() - `timemark`) >= {?bonus_timeout?}', __FUNCTION__, __LINE__); diff --git a/inc/libs/task_functions.php b/inc/libs/task_functions.php index 34462b98a3..254c53af5e 100644 --- a/inc/libs/task_functions.php +++ b/inc/libs/task_functions.php @@ -248,16 +248,14 @@ function outputAdvancedOverview (&$result_main) { if ((isExtensionActive('autopurge')) && (isExtensionActive('user'))) { // Start finding them... $userExclusionSql = ' '; - - // Exclude test accounts - $userExclusionSql = runFilterChain('user_exclusion_sql', ' '); + $excludedUserids = runFilterChain('config_userid_exclusion_sql', array()); + if (count($excludedUserids) > 0) { + // Exclude all + $userExcludeSql = ' AND `d`.`userid` NOT IN (' . implode(', ', $excludedUserids) . ')'; + } // END - if // Check for more extensions - // @TODO These can be rewritten to filter - if (isValidId(getDefRefid())) $userExclusionSql .= ' AND `d`.`userid` != {?def_refid?}'; - if (isExtensionActive('beg')) $userExclusionSql .= ' AND `d`.`userid` != {?beg_userid?}'; - if (isExtensionActive('bonus')) $userExclusionSql .= ' AND `d`.`userid` != {?bonus_userid?}'; - if (isExtensionActive('doubler')) $userExclusionSql .= ' AND `d`.`userid` != {?doubler_userid?}'; + // @TODO This can be rewritten to filter if (isExtensionInstalledAndNewer('holiday', '0.1.3')) { // Recent ext-holiday found $userExclusionSql .= " AND `d`.`holiday_active`='N'"; @@ -275,7 +273,7 @@ WHERE (UNIX_TIMESTAMP() - `d`.`joined`) >= {?ap_inactive_since?} AND (UNIX_TIMESTAMP() - `d`.`last_online`) >= {?ap_inactive_since?} AND (UNIX_TIMESTAMP() - `d`.`ap_notified`) >= {?ap_inactive_since?} -" . $userExclusionSql . " + " . runFilterChain('user_exclusion_sql', $userExcludeSql) . " ORDER BY `d`.`userid` ASC"); $WHATs[] = 'list_autopurge'; diff --git a/inc/mails/beg_mails.php b/inc/mails/beg_mails.php index 7c5217a3d9..ea429a5a36 100644 --- a/inc/mails/beg_mails.php +++ b/inc/mails/beg_mails.php @@ -51,12 +51,12 @@ $mark = mktime(0, 0, 0, getLastMonthly(), getDay(), getYear()); $sql = ''; $mode = ''; // Shall I sent activation or deactivation mail? -$sql = "SELECT `userid`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE (`beg_rallye_enable_notify` "; +$sql = "SELECT `d`.`userid`, `d`.`email` FROM `{?_MYSQL_PREFIX?}_user_data` AS `d` WHERE (`d`.`beg_rallye_enable_notify` "; switch (getBegRallye()) { case 'Y': // Begging rallye is activated if (isBegRallyeEnableNotifyEnabled()) { // Okay, let's check for member accounts - $sql .= '= 0 OR (`beg_rallye_enable_notify` > 0 AND `beg_rallye_enable_notify` < `beg_rallye_disable_notify`)'; + $sql .= '= 0 OR (`d`.`beg_rallye_enable_notify` > 0 AND `d`.`beg_rallye_enable_notify` < `d`.`beg_rallye_disable_notify`)'; $mode = 'enable'; } else { // Do not notify! @@ -67,7 +67,7 @@ switch (getBegRallye()) { case 'N': // Begging rallye is deactivated if (isBegRallyeDisableNotifyEnabled()) { // Okay, let's check for member accounts - $sql .= ' > 0 AND `beg_rallye_disable_notify` < `beg_rallye_enable_notify`'; + $sql .= ' > 0 AND `d`.`beg_rallye_disable_notify` < `d`.`beg_rallye_enable_notify`'; $mode = 'disable'; } else { // Do not notify! @@ -77,8 +77,18 @@ switch (getBegRallye()) { } // END - switch if (!empty($sql)) { + // Init additional WHERE statement + $whereStatement = ''; + + // Is ext-holiday installed? + // @TODO Rewrite these if() blocks to a filter + if (isExtensionActive('holiday')) { + // Exclude those as well + $whereStatement .= " AND `d`.`holiday_active`='N'"; + } // END - if + // The SQL command needs to be finisched here (only confirmed accounts!) - $sql .= ')' . runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'") . ' ORDER BY `last_online` ASC'; + $sql .= ')' . $whereStatement . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC'; // No IP locking setuped by default $content['ip_locker'] = '{--BEG_NO_LIMITATION--}'; diff --git a/inc/mails/bonus_mails.php b/inc/mails/bonus_mails.php index 4cab32d50b..92de0ae6b5 100644 --- a/inc/mails/bonus_mails.php +++ b/inc/mails/bonus_mails.php @@ -51,12 +51,12 @@ $mark = mktime(0, 0, 0, getLastMonthly(), getDay(), getYear()); $sql = ''; $mode = ''; // Shall I sent activation or deactivation mail? -$sql = "SELECT `userid`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE (`bonus_rallye_enable_notify` "; +$sql = "SELECT `d`.`userid`, `d`.`email` FROM `{?_MYSQL_PREFIX?}_user_data` AS `d` WHERE (`d`.`bonus_rallye_enable_notify` "; switch (getBonusActive()) { case 'Y': // Active rallye is activated if (getBonusEnableNotify() == 'Y') { // Okay, let's check for member accounts - $sql .= '= 0 OR (`bonus_rallye_enable_notify` > 0 AND `bonus_rallye_enable_notify` < `bonus_rallye_disable_notify`)'; + $sql .= '= 0 OR (`d`.`bonus_rallye_enable_notify` > 0 AND `d`.`bonus_rallye_enable_notify` < `d`.`bonus_rallye_disable_notify`)'; $mode = 'enable'; } else { // Do not notify! @@ -67,7 +67,7 @@ switch (getBonusActive()) { case 'N': // Active rallye is deactivated if (getBonusDisableNotify() == 'Y') { // Okay, let's check for member accounts - $sql .= ' > 0 AND `bonus_rallye_disable_notify` < `bonus_rallye_enable_notify`'; + $sql .= ' > 0 AND `d`.`bonus_rallye_disable_notify` < `d`.`bonus_rallye_enable_notify`'; $mode = 'disable'; } else { // Do not notify! @@ -77,8 +77,18 @@ switch (getBonusActive()) { } // END - switch if (!empty($sql)) { + // Init additional WHERE statement + $whereStatement = ''; + + // Is ext-holiday installed? + // @TODO Rewrite these if() blocks to a filter + if (isExtensionActive('holiday')) { + // Exclude those as well + $whereStatement .= " AND `d`.`holiday_active`='N'"; + } // END - if + // The SQL command needs to be finisched here (only confirmed accounts!) - $sql .= ')' . runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'") . ' ORDER BY `last_online` ASC'; + $sql .= ')' . $whereStatement . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC'; // Normal notification mails or bonus mails? $sentBonusMails = ((getBonusNotifyPoints() > 0) && ($mode == 'enable') && (isExtensionActive('bonus'))); diff --git a/inc/mails/doubler_mails.php b/inc/mails/doubler_mails.php index f9837feb99..1dc41a242a 100644 --- a/inc/mails/doubler_mails.php +++ b/inc/mails/doubler_mails.php @@ -56,8 +56,8 @@ if (isExtensionActive('jackpot')) { } // END - if // Get total points of the doubler itself -$DOUBLER_POINTS = getDoublerTotalPointsLeft(); -if ($DOUBLER_POINTS == '0') { +$totalPoints = getDoublerTotalPointsLeft(); +if ($totalPoints == '0') { // Exit here to prevent some SQL errors (SQL_QUERY_ESC doen't insert zeros! We need to fix this...) return; } // END - if @@ -68,67 +68,83 @@ unsetPostRequestElement('DOUBLER_USERID'); setSession('DOUBLER_USERID', ''); if (empty($GLOBALS['local_doubler_userid'])) $GLOBALS['local_doubler_userid'] = '0'; +// Init additional WHERE statement +$whereStatement = ' '; + +// Is ext-holiday installed? +// @TODO Rewrite these if() blocks to a filter +if (isExtensionActive('holiday')) { + // Exclude those as well + $whereStatement .= " AND `d`.`holiday_active`='N'"; +} // END - if + // Check for doubles which we can pay out $result_total = SQL_QUERY_ESC("SELECT - d.id, d.userid, d.points, d.remote_ip, d.timemark + COUNT(`do`.`id`) AS `cnt`, FROM - `{?_MYSQL_PREFIX?}_doubler` AS `d` -LEFT JOIN - `{?_MYSQL_PREFIX?}_user_data` AS `u` + `{?_MYSQL_PREFIX?}_doubler` AS `do` +INNER JOIN + `{?_MYSQL_PREFIX?}_user_data` AS `d` ON - `d`.`userid`=`u`.`userid` + `do`.`userid`=`d`.`userid` WHERE - `u`.`status`='CONFIRMED' - " . runFilterChain('user_exclusion_sql', ' ') . " AND - `d`.`points` <= %s AND - `d`.`points` >= ({?doubler_min?} * 2) AND - `d`.`completed`='N' AND - `d`.`is_ref`='N' + `d`.`status`='CONFIRMED' + " . runFilterChain('user_exclusion_sql', $whereStatement) . " AND + `do`.`points` <= %s AND + `do`.`points` >= ({?doubler_min?} * 2) AND + `do`.`completed`='N' AND + `do`.`is_ref`='N' ORDER BY - `d`.`timemark` ASC", + `do`.`timemark` ASC", array( - $DOUBLER_POINTS + $totalPoints ), __FILE__, __LINE__); +// Get total count +list($totalCount) = SQL_FETCHROW($result_total); + +// Free memory +SQL_FREERESULT($result_total); + // Check for accounts with limitation $result_main = SQL_QUERY_ESC("SELECT - `d`.`id`, - `d`.`userid`, - `d`.`points`, - `d`.`remote_ip`, - `d`.`timemark` + `do`.`id`, + `do`.`userid`, + `do`.`points`, + `do`.`remote_ip`, + `do`.`timemark` FROM - `{?_MYSQL_PREFIX?}_doubler` AS `d` -LEFT JOIN - `{?_MYSQL_PREFIX?}_user_data` AS `u` + `{?_MYSQL_PREFIX?}_doubler` AS `do` +INNER JOIN + `{?_MYSQL_PREFIX?}_user_data` AS `d` ON - `d`.`userid`=`u`.`userid` + `do`.`userid`=`d`.`userid` WHERE - `u`.`status`='CONFIRMED' - " . runFilterChain('user_exclusion_sql', ' ') . " AND - `d`.`points` <= %s AND - `d`.`points` >= ({?doubler_min?} * 2) AND - `d`.`completed`='N' AND - `d`.`is_ref`='N' + `d`.`status`='CONFIRMED' + " . runFilterChain('user_exclusion_sql', $whereStatement) . " AND + `do`.`points` <= %s AND + `do`.`points` >= ({?doubler_min?} * 2) AND + `do`.`completed`='N' AND + `do`.`is_ref`='N' ORDER BY - `d`.`timemark` ASC + `do`.`timemark` ASC LIMIT {?doubler_max_sent?}", array( - $DOUBLER_POINTS + $totalPoints ), __FILE__, __LINE__); // Are there entries found? -if (((!SQL_HASZERONUMS($result_total)) && (getConfig('doubler_sent_all') == 'Y')) || ((SQL_NUMROWS($result_main) == getConfig('doubler_group_sent')) && (getConfig('doubler_sent_all') != 'Y'))) { +if ((($totalCount > 0) && (getConfig('doubler_sent_all') == 'Y')) || ((SQL_NUMROWS($result_main) == getConfig('doubler_group_sent')) && (getConfig('doubler_sent_all') != 'Y'))) { // Switch to matching SQL resource $result_load = $result_main; - if ((!SQL_HASZERONUMS($result_total)) && (getConfig('doubler_sent_all') == 'Y')) { + if (($totalCount > 0) && (getConfig('doubler_sent_all') == 'Y')) { $result_load = $result_total; } // END - if // At least one account was found while ($content = SQL_FETCHARRAY($result_load)) { // Only double when points are enougth! - if ($DOUBLER_POINTS >= $content['points']) { + if ($totalPoints >= $content['points']) { // Check for his ref points $refPoints = countSumTotalData($content['userid'], 'doubler', 'points', 'refid', FALSE, " AND `completed`='N' AND `is_ref`='Y'"); @@ -181,7 +197,7 @@ if (((!SQL_HASZERONUMS($result_total)) && (getConfig('doubler_sent_all') == 'Y') // Update variables to prevent errors incrementConfigEntry('doubler_used', $content['points']); - $DOUBLER_POINTS -= $content['points']; + $totalPoints -= $content['points']; // Prepare array $content['timemark'] = generateDateTime($content['timemark'], 2); diff --git a/inc/modules/admin/what-list_autopurge.php b/inc/modules/admin/what-list_autopurge.php index eb76f798e2..769a911165 100644 --- a/inc/modules/admin/what-list_autopurge.php +++ b/inc/modules/admin/what-list_autopurge.php @@ -44,13 +44,17 @@ if ((!defined('__SECURITY')) || (!isAdmin())) { addYouAreHereLink('admin', __FILE__); // Exclude default referral id if set -// @TODO Rewrite those lines to filter -$userExclusionSql = runFilterChain('user_exclusion_sql', ' '); -if (isValidId(getDefRefid())) $userExclusionSql .= ' AND d.userid != {?def_refid?}'; -if (isExtensionActive('beg')) $userExclusionSql .= ' AND d.userid != {?beg_userid?}'; -if (isExtensionActive('bonus')) $userExclusionSql .= ' AND d.userid != {?bonus_userid?}'; -if (isExtensionActive('doubler')) $userExclusionSql .= ' AND d.userid != {?doubler_userid?}'; -if (isExtensionInstalledAndNewer('holiday', '0.1.3')) $userExclusionSql .= " AND `d`.`holiday_active`='N'"; +$userExclusionSql = ' '; +$excludedUserids = runFilterChain('config_userid_exclusion_sql', array()); +if (count($excludedUserids) > 0) { + // Exclude all + $userExcludeSql = ' AND `d`.`userid` NOT IN (' . implode(', ', $excludedUserids) . ')'; +} // END - if + +// @TODO Rewrite this as a filter +if (isExtensionInstalledAndNewer('holiday', '0.1.3')) { + $userExclusionSql .= " AND `d`.`holiday_active`='N'"; +} // END - if // Check for all accounts $result = SQL_QUERY("SELECT @@ -69,7 +73,7 @@ WHERE (UNIX_TIMESTAMP() - `d`.`joined`) >= {?ap_inactive_since?} AND (UNIX_TIMESTAMP() - `d`.`last_online`) >= {?ap_inactive_since?} AND (UNIX_TIMESTAMP() - `d`.`ap_notified`) >= {?ap_inactive_since?} - " . $userExclusionSql . " + " . runFilterChain('user_exclusion_sql', $userExcludeSql) . " ORDER BY `d`.`userid` ASC", __FILE__, __LINE__); diff --git a/inc/monthly/monthly_beg.php b/inc/monthly/monthly_beg.php index 62d017396f..893b2e0609 100644 --- a/inc/monthly/monthly_beg.php +++ b/inc/monthly/monthly_beg.php @@ -55,31 +55,38 @@ if ((getBegRanks() > 0) && (!isCssOutputMode())) { $whereStatement = ''; // Shall we exclude webmaster's own userid? + // @TODO Rewrite these if() blocks to a filter if ((!isBegIncludeOwnEnabled()) && (isValidId(getBegUserid()))) { // Exclude it - $whereStatement .= ' AND `userid` != {?beg_userid?}'; + $whereStatement .= ' AND `d`.`userid` != {?beg_userid?}'; } // END - if // Let's check if there are some points left we can pay... if ((isExtensionActive('autopurge')) && (isBegActiveEnabled()) && ((getApInactiveSince() > 0))) { // Okay, include last online timestamp - $whereStatement .= ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}'; + $whereStatement .= ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}'; + } // END - if + + // Is ext-holiday installed? + if (isExtensionActive('holiday')) { + // Exclude those as well + $whereStatement .= " AND `d`.`holiday_active`='N'"; } // END - if // SQL string to check for accounts $result_main = SQL_QUERY("SELECT - `userid`, - `beg_points` + `d`.`userid`, + `d`.`beg_points` FROM - `{?_MYSQL_PREFIX?}_user_data` + `{?_MYSQL_PREFIX?}_user_data` AS `d` WHERE - `status`='CONFIRMED' + `d`.`status`='CONFIRMED' " . $whereStatement . " " . runFilterChain('user_exclusion_sql', ' ') . " AND - `beg_points` > 0 + `d`.`beg_points` > 0 ORDER BY - `beg_points` DESC, - `userid` ASC + `d`.`beg_points` DESC, + `d`.`userid` ASC LIMIT {?beg_ranks?}", __FILE__, __LINE__); if (!SQL_HASZERONUMS($result_main)) { diff --git a/inc/monthly/monthly_bonus.php b/inc/monthly/monthly_bonus.php index 90ceed68ab..129d4b8d17 100644 --- a/inc/monthly/monthly_bonus.php +++ b/inc/monthly/monthly_bonus.php @@ -50,13 +50,20 @@ if (!defined('__SECURITY')) { //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Monthly reset started.'); if ((getBonusRanks() > 0) && (!isCssOutputMode())) { - // Extension 'autopurge' is inactive or purging of inactive accounts is deactivated + // Extension 'autopurge' is inactive or purging of inactive accounts is deactivated\ $whereStatement = runFilterChain('user_exclusion_sql', "WHERE `status`='CONFIRMED'"); // Shall I keep inactive members away from here? (mostly wanted in an "active-rallye" ...) + // @TODO Rewrite these if() blocks to a filter if ((isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) { // Okay, include last online timestamp - $whereStatement .= ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}'; + $whereStatement .= ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}'; + } // END - if + + // Is ext-holiday installed? + if (isExtensionActive('holiday')) { + // Exclude those as well + $whereStatement .= " AND `d`.`holiday_active`='N'"; } // END - if // Add more bonus points here by running a filter @@ -69,14 +76,14 @@ if ((getBonusRanks() > 0) && (!isCssOutputMode())) { // Run SQL string to check for accounts $result_main = SQL_QUERY('SELECT - `userid`, + `d`.`userid`, (0' . $add . ') AS `points` FROM - `{?_MYSQL_PREFIX?}_user_data` + `{?_MYSQL_PREFIX?}_user_data` AS `d` ' . $whereStatement . ' ORDER BY - `points` DESC, - `userid` ASC + `d`.`points` DESC, + `d`.`userid` ASC LIMIT {?bonus_ranks?}', __FILE__, __LINE__); // Some entries were found? diff --git a/inc/purge/purge-inact.php b/inc/purge/purge-inact.php index 30da0a025b..ee364dedc2 100644 --- a/inc/purge/purge-inact.php +++ b/inc/purge/purge-inact.php @@ -73,12 +73,11 @@ if (isAutopurgeInactiveEnabled()) { FROM `{?_MYSQL_PREFIX?}_user_data` WHERE - `status`='CONFIRMED' - " . runFilterChain('user_exclusion_sql', ' ') . " AND + `status`='CONFIRMED' AND (UNIX_TIMESTAMP() - `joined`) >= {?ap_inactive_since?} AND (UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?} AND (UNIX_TIMESTAMP() - `ap_notified`) >= {?ap_inactive_since?} AND - " . $excludeSql . " + " . runFilterChain('user_exclusion_sql', $excludeSql) . " ORDER BY `userid` ASC", __FILE__, __LINE__); @@ -131,12 +130,11 @@ FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' - " . runFilterChain('user_exclusion_sql', ' ') . " AND + " . runFilterChain('user_exclusion_sql', $excludeSql) . " AND (UNIX_TIMESTAMP() - `joined`) >= {?ap_inactive_since?} AND (UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?} AND (UNIX_TIMESTAMP() - `ap_notified`) >= {?ap_inactive_time?} AND `ap_notified` > 0 - " . $excludeSql . " ORDER BY `userid` ASC", __FILE__, __LINE__);