2013-05-31 08:00:59 +00:00
< ? php
2011-03-28 14:21:28 +00:00
set_time_limit ( 50000 );
ob_end_flush ();
gc_enable ();
2013-02-01 08:00:18 +00:00
2013-02-02 08:00:44 +00:00
$PCount = chop ( shell_exec ( " /usr/bin/pgrep -cf schedule.php " ));
if ( $PCount > 3 ) {
// 3 because the cron job starts two processes and pgrep finds itself
die ( " schedule.php is already running. Exiting ( $PCount ) \n " );
2013-02-01 08:00:18 +00:00
}
2013-05-31 08:00:59 +00:00
/* TODO : make it awesome , make it flexible !
INSERT INTO users_geodistribution
( Code , Users )
SELECT g . Code , COUNT ( u . ID ) AS Users
FROM geoip_country AS g
JOIN users_main AS u ON INET_ATON ( u . IP ) BETWEEN g . StartIP AND g . EndIP
WHERE u . Enabled = '1'
GROUP BY g . Code
ORDER BY Users DESC
*/
2011-03-28 14:21:28 +00:00
/************************************************************************* \
//--------------Schedule page -------------------------------------------//
This page is run every 15 minutes , by cron .
\ *************************************************************************/
function next_biweek () {
$Date = date ( 'd' );
2013-05-31 08:00:59 +00:00
if ( $Date < 22 && $Date >= 8 ) {
2011-03-28 14:21:28 +00:00
$Return = 22 ;
} else {
$Return = 8 ;
}
return $Return ;
}
function next_day () {
2013-05-31 08:00:59 +00:00
$Tomorrow = time ( 0 , 0 , 0 , date ( 'm' ), date ( 'd' ) + 1 , date ( 'Y' ));
2011-03-28 14:21:28 +00:00
return date ( 'd' , $Tomorrow );
}
function next_hour () {
2013-05-31 08:00:59 +00:00
$Hour = time ( date ( 'H' ) + 1 , 0 , 0 , date ( 'm' ), date ( 'd' ), date ( 'Y' ));
2011-03-28 14:21:28 +00:00
return date ( 'H' , $Hour );
}
2013-05-31 08:00:59 +00:00
if (( ! isset ( $argv [ 1 ]) || $argv [ 1 ] != SCHEDULE_KEY ) && ! check_perms ( 'admin_schedule' )) { // authorization, Fix to allow people with perms hit this page.
2011-03-28 14:21:28 +00:00
error ( 403 );
}
if ( check_perms ( 'admin_schedule' )) {
authorize ();
2012-10-11 08:00:15 +00:00
View :: show_header ();
2011-03-28 14:21:28 +00:00
echo '<pre>' ;
}
$DB -> query ( " SELECT NextHour, NextDay, NextBiWeekly FROM schedule " );
list ( $Hour , $Day , $BiWeek ) = $DB -> next_record ();
$DB -> query ( " UPDATE schedule SET NextHour = " . next_hour () . " , NextDay = " . next_day () . " , NextBiWeekly = " . next_biweek ());
2012-09-02 08:00:26 +00:00
$NoDaily = isset ( $argv [ 2 ]) && $argv [ 2 ] == 'nodaily' ;
2011-03-28 14:21:28 +00:00
$sqltime = sqltime ();
echo " $sqltime\n " ;
/************************************************************************* \
//--------------Run every time ------------------------------------------//
These functions are run every time the script is executed ( every 15
minutes ) .
\ *************************************************************************/
echo " Ran every-time functions \n " ;
//------------- Freeleech -----------------------------------------------//
2013-02-22 08:00:24 +00:00
//We use this to control 6 hour freeleeches. They're actually 7 hour, but don't tell anyone.
2011-03-28 14:21:28 +00:00
/*
2013-04-17 08:00:58 +00:00
$TimeMinus = time_minus ( 3600 * 7 );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT DISTINCT GroupID
FROM torrents
WHERE FreeTorrent = '1'
AND FreeLeechType = '3'
AND Time < '$TimeMinus' " );
2013-04-17 08:00:58 +00:00
while ( list ( $GroupID ) = $DB -> next_record ()) {
2011-03-28 14:21:28 +00:00
$Cache -> delete_value ( 'torrents_details_' . $GroupID );
$Cache -> delete_value ( 'torrent_group_' . $GroupID );
}
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE torrents
SET FreeTorrent = '0' ,
FreeLeechType = '0' ,
flags = '2'
WHERE FreeTorrent = '1'
AND FreeLeechType = '3'
AND Time < '$TimeMinus' " );
2011-03-28 14:21:28 +00:00
*/
sleep ( 5 );
//------------- Delete unpopular tags -----------------------------------//
$DB -> query ( " DELETE FROM torrents_tags WHERE NegativeVotes>PositiveVotes " );
2011-10-27 08:00:15 +00:00
//------------- Expire old FL Tokens and clear cache where needed ------//
$sqltime = sqltime ();
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT DISTINCT UserID
FROM users_freeleeches
WHERE Expired = FALSE
AND Time < '$sqltime' - INTERVAL 4 DAY " );
2011-10-27 08:00:15 +00:00
while ( list ( $UserID ) = $DB -> next_record ()) {
$Cache -> delete_value ( 'users_tokens_' . $UserID [ 0 ]);
}
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT uf . UserID , t . info_hash
FROM users_freeleeches AS uf
JOIN torrents AS t ON uf . TorrentID = t . ID
WHERE uf . Expired = FALSE
AND uf . Time < '$sqltime' - INTERVAL 4 DAY " );
while ( list ( $UserID , $InfoHash ) = $DB -> next_record ( MYSQLI_NUM , false )) {
2012-10-11 08:00:15 +00:00
Tracker :: update_tracker ( 'remove_token' , array ( 'info_hash' => rawurlencode ( $InfoHash ), 'userid' => $UserID ));
2011-10-27 08:00:15 +00:00
}
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_freeleeches
SET Expired = True
WHERE Time < '$sqltime' - INTERVAL 4 DAY " );
2011-10-27 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
/************************************************************************* \
//--------------Run every hour ------------------------------------------//
These functions are run every hour .
\ *************************************************************************/
2013-04-17 08:00:58 +00:00
if ( $Hour != next_hour () || $_GET [ 'runhour' ] || isset ( $argv [ 2 ])) {
2011-03-28 14:21:28 +00:00
echo " Ran hourly functions \n " ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
//------------- Front page stats ----------------------------------------//
//Love or hate, this makes things a hell of a lot faster
2011-11-07 08:00:19 +00:00
2013-05-31 08:00:59 +00:00
if ( $Hour % 2 == 0 ) {
2011-03-28 14:21:28 +00:00
$DB -> query ( " SELECT COUNT(uid) AS Snatches FROM xbt_snatched " );
list ( $SnatchStats ) = $DB -> next_record ();
2013-05-31 08:00:59 +00:00
$Cache -> cache_value ( 'stats_snatches' , $SnatchStats , 0 );
2011-03-28 14:21:28 +00:00
}
2011-11-07 08:00:19 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT IF ( remaining = 0 , 'Seeding' , 'Leeching' ) AS Type ,
COUNT ( uid )
FROM xbt_files_users
WHERE active = 1
GROUP BY Type " );
2011-11-09 08:00:14 +00:00
$PeerCount = $DB -> to_array ( 0 , MYSQLI_NUM , false );
$SeederCount = isset ( $PeerCount [ 'Seeding' ][ 1 ]) ? $PeerCount [ 'Seeding' ][ 1 ] : 0 ;
$LeecherCount = isset ( $PeerCount [ 'Leeching' ][ 1 ]) ? $PeerCount [ 'Leeching' ][ 1 ] : 0 ;
2013-05-31 08:00:59 +00:00
$Cache -> cache_value ( 'stats_peers' , array ( $LeecherCount , $SeederCount ), 0 );
2011-03-28 14:21:28 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( " SELECT COUNT(ID) FROM users_main WHERE Enabled='1' AND LastAccess>' " . time_minus ( 3600 * 24 ) . " ' " );
2011-03-28 14:21:28 +00:00
list ( $UserStats [ 'Day' ]) = $DB -> next_record ();
2013-05-31 08:00:59 +00:00
$DB -> query ( " SELECT COUNT(ID) FROM users_main WHERE Enabled='1' AND LastAccess>' " . time_minus ( 3600 * 24 * 7 ) . " ' " );
2011-03-28 14:21:28 +00:00
list ( $UserStats [ 'Week' ]) = $DB -> next_record ();
2013-05-31 08:00:59 +00:00
$DB -> query ( " SELECT COUNT(ID) FROM users_main WHERE Enabled='1' AND LastAccess>' " . time_minus ( 3600 * 24 * 30 ) . " ' " );
2011-03-28 14:21:28 +00:00
list ( $UserStats [ 'Month' ]) = $DB -> next_record ();
$Cache -> cache_value ( 'stats_users' , $UserStats , 0 );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
//------------- Record who's seeding how much, used for ratio watch
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$DB -> query ( " TRUNCATE TABLE users_torrent_history_temp " );
2013-06-17 08:01:02 +00:00
// Find seeders that have announced within the last hour
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO users_torrent_history_temp
( UserID , NumTorrents )
SELECT uid ,
COUNT ( DISTINCT fid )
FROM xbt_files_users
2013-06-17 08:01:02 +00:00
WHERE mtime > unix_timestamp ( NOW () - INTERVAL 1 HOUR )
2013-05-31 08:00:59 +00:00
AND Remaining = 0
2013-06-17 08:01:02 +00:00
GROUP BY uid " );
// Mark new records as "checked" and set the current time as the time
// the user started seeding <NumTorrents> seeded.
// Finished = 1 means that the user hasn't been seeding exactly <NumTorrents> earlier today.
// This query will only do something if the next one inserted new rows last hour.
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_torrent_history AS h
2013-06-17 08:01:02 +00:00
JOIN users_torrent_history_temp AS t ON t . UserID = h . UserID
AND t . NumTorrents = h . NumTorrents
2013-05-31 08:00:59 +00:00
SET h . Finished = '0' ,
2013-06-17 08:01:02 +00:00
h . LastTime = UNIX_TIMESTAMP ( NOW ())
2013-05-31 08:00:59 +00:00
WHERE h . Finished = '1'
2013-06-17 08:01:02 +00:00
AND h . Date = UTC_DATE () + 0 " );
// Insert new rows for users who haven't been seeding exactly <NumTorrents> torrents earlier today
// and update the time spent seeding <NumTorrents> torrents for the others.
// Primary table index: (UserID, NumTorrents, Date).
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO users_torrent_history
( UserID , NumTorrents , Date )
SELECT UserID , NumTorrents , UTC_DATE () + 0
FROM users_torrent_history_temp
ON DUPLICATE KEY UPDATE
2013-06-17 08:01:02 +00:00
Time = Time + UNIX_TIMESTAMP ( NOW ()) - LastTime ,
LastTime = UNIX_TIMESTAMP ( NOW ()) " );
2011-03-28 14:21:28 +00:00
//------------- Promote users -------------------------------------------//
sleep ( 5 );
$Criteria = array ();
2013-05-31 08:00:59 +00:00
$Criteria [] = array ( 'From' => USER , 'To' => MEMBER , 'MinUpload' => 10 * 1024 * 1024 * 1024 , 'MinRatio' => 0.7 , 'MinUploads' => 0 , 'MaxTime' => time_minus ( 3600 * 24 * 7 ));
$Criteria [] = array ( 'From' => MEMBER , 'To' => POWER , 'MinUpload' => 25 * 1024 * 1024 * 1024 , 'MinRatio' => 1.05 , 'MinUploads' => 5 , 'MaxTime' => time_minus ( 3600 * 24 * 7 * 2 ));
$Criteria [] = array ( 'From' => POWER , 'To' => ELITE , 'MinUpload' => 100 * 1024 * 1024 * 1024 , 'MinRatio' => 1.05 , 'MinUploads' => 50 , 'MaxTime' => time_minus ( 3600 * 24 * 7 * 4 ));
$Criteria [] = array ( 'From' => ELITE , 'To' => TORRENT_MASTER , 'MinUpload' => 500 * 1024 * 1024 * 1024 , 'MinRatio' => 1.05 , 'MinUploads' => 500 , 'MaxTime' => time_minus ( 3600 * 24 * 7 * 8 ));
$Criteria [] = array (
'From' => TORRENT_MASTER ,
'To' => POWER_TM ,
'MinUpload' => 500 * 1024 * 1024 * 1024 ,
'MinRatio' => 1.05 ,
'MinUploads' => 500 ,
'MaxTime' => time_minus ( 3600 * 24 * 7 * 8 ),
'Extra' => ' ( SELECT COUNT ( DISTINCT GroupID )
FROM torrents
WHERE UserID = users_main . ID
) >= 500 ' );
$Criteria [] = array (
'From' => POWER_TM ,
'To' => ELITE_TM ,
'MinUpload' => 500 * 1024 * 1024 * 1024 ,
'MinRatio' => 1.05 ,
'MinUploads' => 500 ,
'MaxTime' => time_minus ( 3600 * 24 * 7 * 8 ),
'Extra' => " ( SELECT COUNT(ID)
FROM torrents
WHERE (( LogScore = 100 AND Format = 'FLAC' )
OR ( Media = 'Vinyl' AND Format = 'FLAC' )
OR ( Media = 'WEB' AND Format = 'FLAC' )
OR ( Media = 'DVD' AND Format = 'FLAC' )
OR ( Media = 'Soundboard' AND Format = 'FLAC' )
OR ( Media = 'Cassette' AND Format = 'FLAC' )
OR ( Media = 'SACD' AND Format = 'FLAC' )
OR ( Media = 'Blu-ray' AND Format = 'FLAC' )
OR ( Media = 'DAT' AND Format = 'FLAC' )
)
AND UserID = users_main . ID
) >= 500 " );
2011-03-28 14:21:28 +00:00
2013-04-17 08:00:58 +00:00
foreach ( $Criteria as $L ) { // $L = Level
$Query = "
SELECT ID
FROM users_main
JOIN users_info ON users_main . ID = users_info . UserID
WHERE PermissionID = " . $L['From'] . "
AND Warned = '0000-00-00 00:00:00'
AND Uploaded >= '$L[MinUpload]'
AND ( Uploaded / Downloaded >= '$L[MinRatio]' OR ( Uploaded / Downloaded IS NULL ))
AND JoinDate < '$L[MaxTime]'
AND (
SELECT COUNT ( ID )
FROM torrents
WHERE UserID = users_main . ID
) >= '$L[MinUploads]'
AND Enabled = '1' " ;
2011-03-28 14:21:28 +00:00
if ( ! empty ( $L [ 'Extra' ])) {
$Query .= ' AND ' . $L [ 'Extra' ];
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$DB -> query ( $Query );
$UserIDs = $DB -> collect ( 'ID' );
if ( count ( $UserIDs ) > 0 ) {
2013-04-17 08:00:58 +00:00
foreach ( $UserIDs as $UserID ) {
2011-03-28 14:21:28 +00:00
/* $Cache -> begin_transaction ( 'user_info_' . $UserID );
$Cache -> update_row ( false , array ( 'PermissionID' => $L [ 'To' ]));
$Cache -> commit_transaction ( 0 ); */
$Cache -> delete_value ( 'user_info_' . $UserID );
$Cache -> delete_value ( 'user_info_heavy_' . $UserID );
$Cache -> delete_value ( 'user_stats_' . $UserID );
$Cache -> delete_value ( 'enabled_' . $UserID );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_info
SET AdminComment = CONCAT ( '".sqltime()." - Class changed to ".Users::make_class_string($L[' To '])." by System\n\n' , AdminComment )
WHERE UserID = $UserID " );
2013-02-22 08:00:24 +00:00
}
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_main
SET PermissionID = " . $L['To'] . "
WHERE ID IN ( " .implode(',', $UserIDs ).')');
2011-03-28 14:21:28 +00:00
}
// Demote users with less than the required uploads
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
$Query = "
SELECT ID
FROM users_main
JOIN users_info ON users_main . ID = users_info . UserID
2011-03-28 14:21:28 +00:00
WHERE PermissionID = '$L[To]'
2013-04-17 08:00:58 +00:00
AND ( Uploaded < '$L[MinUpload]'
OR (
SELECT COUNT ( ID )
FROM torrents
2013-05-31 08:00:59 +00:00
WHERE UserID = users_main . ID
) < '$L[MinUploads]' " ;
2011-03-28 14:21:28 +00:00
if ( ! empty ( $L [ 'Extra' ])) {
$Query .= " OR NOT " . $L [ 'Extra' ];
}
2013-05-31 08:00:59 +00:00
$Query .= "
)
2013-05-08 08:00:26 +00:00
AND Enabled = '1' " ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$DB -> query ( $Query );
$UserIDs = $DB -> collect ( 'ID' );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
if ( count ( $UserIDs ) > 0 ) {
2013-04-17 08:00:58 +00:00
foreach ( $UserIDs as $UserID ) {
2011-03-28 14:21:28 +00:00
/* $Cache -> begin_transaction ( 'user_info_' . $UserID );
$Cache -> update_row ( false , array ( 'PermissionID' => $L [ 'From' ]));
$Cache -> commit_transaction ( 0 ); */
$Cache -> delete_value ( 'user_info_' . $UserID );
$Cache -> delete_value ( 'user_info_heavy_' . $UserID );
$Cache -> delete_value ( 'user_stats_' . $UserID );
$Cache -> delete_value ( 'enabled_' . $UserID );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_info
SET AdminComment = CONCAT ( '".sqltime()." - Class changed to ".Users::make_class_string($L[' From '])." by System\n\n' , AdminComment )
WHERE UserID = $UserID " );
2011-03-28 14:21:28 +00:00
}
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_main
SET PermissionID = " . $L['From'] . "
WHERE ID IN ( " .implode(',', $UserIDs ).')');
2011-03-28 14:21:28 +00:00
}
}
//------------- Expire invites ------------------------------------------//
sleep ( 3 );
$DB -> query ( " SELECT InviterID FROM invites WHERE Expires<' $sqltime ' " );
$Users = $DB -> to_array ();
foreach ( $Users as $UserID ) {
list ( $UserID ) = $UserID ;
2012-03-18 08:00:22 +00:00
$DB -> query ( " SELECT Invites, PermissionID FROM users_main WHERE ID= $UserID " );
list ( $Invites , $PermID ) = $DB -> next_record ();
if (( $Invites < 2 && $Classes [ $PermID ][ 'Level' ] <= $Classes [ POWER ][ 'Level' ]) || ( $Invites < 4 && $PermID == ELITE )) {
2011-03-28 14:21:28 +00:00
$DB -> query ( " UPDATE users_main SET Invites=Invites+1 WHERE ID= $UserID " );
$Cache -> begin_transaction ( 'user_info_heavy_' . $UserID );
$Cache -> update_row ( false , array ( 'Invites' => '+1' ));
$Cache -> commit_transaction ( 0 );
}
}
$DB -> query ( " DELETE FROM invites WHERE Expires<' $sqltime ' " );
//------------- Hide old requests ---------------------------------------//
sleep ( 3 );
2013-05-27 08:00:58 +00:00
$DB -> query ( "
UPDATE requests
SET Visible = 0
WHERE TimeFilled < ( NOW () - INTERVAL 7 DAY )
AND TimeFilled != '0000-00-00 00:00:00' " );
2011-03-28 14:21:28 +00:00
//------------- Remove dead peers ---------------------------------------//
sleep ( 3 );
$DB -> query ( " DELETE FROM xbt_files_users WHERE mtime<unix_timestamp(now()-interval 6 hour) " );
//------------- Remove dead sessions ---------------------------------------//
sleep ( 3 );
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
$AgoMins = time_minus ( 60 * 30 );
$AgoDays = time_minus ( 3600 * 24 * 30 );
2013-05-16 16:15:57 +00:00
2013-05-27 08:00:58 +00:00
$SessionQuery = $DB -> query ( "
SELECT UserID , SessionID
FROM users_sessions
WHERE ( LastUpdate < '$AgoDays' AND KeepLogged = '1' )
OR ( LastUpdate < '$AgoMins' AND KeepLogged = '0' ) " );
$DB -> query ( "
DELETE FROM users_sessions
WHERE ( LastUpdate < '$AgoDays' AND KeepLogged = '1' )
OR ( LastUpdate < '$AgoMins' AND KeepLogged = '0' ) " );
2011-10-20 08:00:12 +00:00
2012-03-10 08:00:21 +00:00
$DB -> set_query_id ( $SessionQuery );
2013-04-17 08:00:58 +00:00
while ( list ( $UserID , $SessionID ) = $DB -> next_record ()) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'users_sessions_' . $UserID );
$Cache -> delete_row ( $SessionID );
$Cache -> commit_transaction ( 0 );
}
2013-05-16 16:15:57 +00:00
2011-03-28 14:21:28 +00:00
//------------- Lower Login Attempts ------------------------------------//
$DB -> query ( " UPDATE login_attempts SET Attempts=Attempts-1 WHERE Attempts>0 " );
2013-05-16 08:00:10 +00:00
$DB -> query ( " DELETE FROM login_attempts WHERE LastAttempt<' " . time_minus ( 3600 * 24 * 90 ) . " ' " );
2011-03-28 14:21:28 +00:00
2013-04-17 08:00:58 +00:00
//------------- Remove expired warnings ---------------------------------//
$DB -> query ( " SELECT UserID FROM users_info WHERE Warned<' $sqltime ' " );
while ( list ( $UserID ) = $DB -> next_record ()) {
$Cache -> begin_transaction ( 'user_info_' . $UserID );
$Cache -> update_row ( false , array ( 'Warned' => '0000-00-00 00:00:00' ));
$Cache -> commit_transaction ( 2592000 );
}
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
$DB -> query ( " UPDATE users_info SET Warned='0000-00-00 00:00:00' WHERE Warned<' $sqltime ' " );
// If a user has downloaded more than 10 GiBs while on ratio watch, disable leeching privileges and send the user a message
2013-04-21 08:00:52 +00:00
$DB -> query ( "
SELECT ID
FROM users_info AS i
JOIN users_main AS m ON m . ID = i . UserID
WHERE i . RatioWatchEnds != '0000-00-00 00:00:00'
AND i . RatioWatchDownload + 10 * 1024 * 1024 * 1024 < m . Downloaded
AND m . Enabled = '1'
AND m . can_leech = '1' " );
2012-08-19 08:00:19 +00:00
2013-04-17 08:00:58 +00:00
$UserIDs = $DB -> collect ( 'ID' );
if ( count ( $UserIDs ) > 0 ) {
$Subject = 'Leeching Disabled' ;
2013-05-08 08:00:26 +00:00
$Message = 'You have downloaded more then 10 GiB while on Ratio Watch. Your leeching privileges have been disabled. Please reread the rules and refer to this guide on how to improve your ratio https://' . SSL_SITE_URL . '/wiki.php?action=article&id=110' ;
2013-04-17 08:00:58 +00:00
foreach ( $UserIDs as $UserID ) {
Misc :: send_pm ( $UserID , 0 , $Subject , $Message );
send_irc ( 'PRIVMSG #reports :!leechdisabled Downloaded 10 GB+ on Ratio Watch. https://' . SSL_SITE_URL . " /user.php?id= $UserID " );
}
2013-04-21 08:00:52 +00:00
$DB -> query ( "
UPDATE users_info AS i
JOIN users_main AS m ON m . ID = i . UserID
SET m . can_leech = '0' ,
i . AdminComment = CONCAT ( '$sqltime - Leeching privileges disabled by ratio watch system for downloading more than 10 GBs on ratio watch. - required ratio: ' , m . RequiredRatio , '\n\n' , i . AdminComment )
WHERE m . ID IN ( " .implode(',', $UserIDs ).')');
2013-04-17 08:00:58 +00:00
}
2011-03-28 14:21:28 +00:00
}
/************************************************************************* \
//--------------Run every day -------------------------------------------//
These functions are run in the first 15 minutes of every day .
\ *************************************************************************/
2013-04-17 08:00:58 +00:00
if ( ! $NoDaily && $Day != next_day () || $_GET [ 'runday' ]) {
2011-03-28 14:21:28 +00:00
echo " Ran daily functions \n " ;
2013-04-17 08:00:58 +00:00
if ( $Day % 2 == 0 ) { // If we should generate the drive database (at the end)
2011-03-28 14:21:28 +00:00
$GenerateDriveDB = true ;
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
//------------- Ratio requirements
2013-02-22 08:00:24 +00:00
2013-06-17 08:01:02 +00:00
// Clear old seed time history
2013-05-31 08:00:59 +00:00
$DB -> query ( "
DELETE FROM users_torrent_history
2013-06-17 08:01:02 +00:00
WHERE Date < DATE ( '".sqltime()."' - INTERVAL 7 DAY ) + 0 " );
// Store total seeded time for each user in a temp table
$DB -> query ( " TRUNCATE TABLE users_torrent_history_temp " );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO users_torrent_history_temp
( UserID , SumTime )
SELECT UserID , SUM ( Time )
FROM users_torrent_history
2013-06-17 08:01:02 +00:00
GROUP BY UserID " );
// Insert new row with <NumTorrents> = 0 with <Time> being number of seconds short of 72 hours.
// This is where we penalize torrents seeded for less than 72 hours
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO users_torrent_history
( UserID , NumTorrents , Date , Time )
2011-03-28 14:21:28 +00:00
SELECT UserID , 0 , UTC_DATE () + 0 , 259200 - SumTime
FROM users_torrent_history_temp
2013-06-17 08:01:02 +00:00
WHERE SumTime < 259200 " );
// Set <Weight> to the time seeding <NumTorrents> torrents
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_torrent_history
2013-06-17 08:01:02 +00:00
SET Weight = NumTorrents * Time " );
// Calculate average time spent seeding each of the currently active torrents.
// This rounds the results to the nearest integer because SeedingAvg is an int column.
$DB -> query ( " TRUNCATE TABLE users_torrent_history_temp " );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO users_torrent_history_temp
( UserID , SeedingAvg )
SELECT UserID , SUM ( Weight ) / SUM ( Time )
FROM users_torrent_history
2013-06-17 08:01:02 +00:00
GROUP BY UserID " );
// Remove dummy entry for torrents seeded less than 72 hours
2011-03-28 14:21:28 +00:00
$DB -> query ( " DELETE FROM users_torrent_history WHERE NumTorrents='0' " );
2013-06-17 08:01:02 +00:00
// Get each user's amount of snatches of existing torrents
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO users_torrent_history_snatch
( UserID , NumSnatches )
2013-02-22 08:00:24 +00:00
SELECT
2013-05-31 08:00:59 +00:00
xs . uid ,
COUNT ( DISTINCT xs . fid )
FROM xbt_snatched AS xs
JOIN torrents on torrents . ID = xs . fid
2013-06-17 08:01:02 +00:00
GROUP BY xs . uid " );
// Get the fraction of snatched torrents seeded for at least 72 hours this week
// Essentially take the total number of hours seeded this week and divide that by 72 hours*<NumSnatches>
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_main AS um
JOIN users_torrent_history_temp AS t ON t . UserID = um . ID
JOIN users_torrent_history_snatch AS s ON s . UserID = um . ID
SET um . RequiredRatioWork = ( 1 - ( t . SeedingAvg / s . NumSnatches ))
2013-06-17 08:01:02 +00:00
WHERE s . NumSnatches > 0 " );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$RatioRequirements = array (
2013-04-17 08:00:58 +00:00
array ( 80 * 1024 * 1024 * 1024 , 0.60 , 0.50 ),
array ( 60 * 1024 * 1024 * 1024 , 0.60 , 0.40 ),
array ( 50 * 1024 * 1024 * 1024 , 0.60 , 0.30 ),
array ( 40 * 1024 * 1024 * 1024 , 0.50 , 0.20 ),
array ( 30 * 1024 * 1024 * 1024 , 0.40 , 0.10 ),
array ( 20 * 1024 * 1024 * 1024 , 0.30 , 0.05 ),
array ( 10 * 1024 * 1024 * 1024 , 0.20 , 0.0 ),
array ( 5 * 1024 * 1024 * 1024 , 0.15 , 0.0 )
2011-03-28 14:21:28 +00:00
);
2013-02-22 08:00:24 +00:00
2013-06-17 08:01:02 +00:00
$DownloadBarrier = 100 * 1024 * 1024 * 1024 ;
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_main
SET RequiredRatio = 0.60
2013-06-17 08:01:02 +00:00
WHERE Downloaded > $DownloadBarrier " );
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
foreach ( $RatioRequirements as $Requirement ) {
2011-03-28 14:21:28 +00:00
list ( $Download , $Ratio , $MinRatio ) = $Requirement ;
2013-02-22 08:00:24 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_main
SET RequiredRatio = RequiredRatioWork * $Ratio
WHERE Downloaded >= '$Download'
AND Downloaded < '$DownloadBarrier' " );
2013-02-22 08:00:24 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_main
SET RequiredRatio = $MinRatio
WHERE Downloaded >= '$Download'
AND Downloaded < '$DownloadBarrier'
AND RequiredRatio < $MinRatio " );
/* $DB -> query ( "
UPDATE users_main
SET RequiredRatio = $Ratio
WHERE Downloaded >= '$Download'
AND Downloaded < '$DownloadBarrier'
AND can_leech = '0'
AND Enabled = '1' " );
*/
2011-03-28 14:21:28 +00:00
$DownloadBarrier = $Download ;
}
2013-02-22 08:00:24 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_main
SET RequiredRatio = 0.00
WHERE Downloaded < 5 * 1024 * 1024 * 1024 " );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Here is where we manage ratio watch
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$OffRatioWatch = array ();
$OnRatioWatch = array ();
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Take users off ratio watch and enable leeching
2013-04-17 08:00:58 +00:00
$UserQuery = $DB -> query ( "
SELECT
m . ID ,
torrent_pass
FROM users_info AS i
JOIN users_main AS m ON m . ID = i . UserID
WHERE m . Uploaded / m . Downloaded >= m . RequiredRatio
AND i . RatioWatchEnds != '0000-00-00 00:00:00'
AND m . can_leech = '0'
AND m . Enabled = '1' " );
2011-03-28 14:21:28 +00:00
$OffRatioWatch = $DB -> collect ( 'ID' );
2013-04-17 08:00:58 +00:00
if ( count ( $OffRatioWatch ) > 0 ) {
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_info AS ui
JOIN users_main AS um ON um . ID = ui . UserID
SET ui . RatioWatchEnds = '0000-00-00 00:00:00' ,
ui . RatioWatchDownload = '0' ,
um . can_leech = '1' ,
ui . AdminComment = CONCAT ( '$sqltime - Leeching re-enabled by adequate ratio.\n\n' , ui . AdminComment )
WHERE ui . UserID IN ( " .implode(',', $OffRatioWatch ).')');
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
foreach ( $OffRatioWatch as $UserID ) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'user_info_heavy_' . $UserID );
2011-07-10 08:00:06 +00:00
$Cache -> update_row ( false , array ( 'RatioWatchEnds' => '0000-00-00 00:00:00' , 'RatioWatchDownload' => '0' , 'CanLeech' => 1 ));
2011-03-28 14:21:28 +00:00
$Cache -> commit_transaction ( 0 );
2013-04-17 08:00:58 +00:00
Misc :: send_pm ( $UserID , 0 , 'You have been taken off Ratio Watch' , " Congratulations! Feel free to begin downloading again. \n To ensure that you do not get put on ratio watch again, please read the rules located [url=https:// " . SSL_SITE_URL . " /rules.php?p=ratio]here[/url]. \n " );
2011-03-28 14:21:28 +00:00
echo " Ratio watch off: $UserID\n " ;
}
$DB -> set_query_id ( $UserQuery );
$Passkeys = $DB -> collect ( 'torrent_pass' );
2013-04-17 08:00:58 +00:00
foreach ( $Passkeys as $Passkey ) {
2012-10-11 08:00:15 +00:00
Tracker :: update_tracker ( 'update_user' , array ( 'passkey' => $Passkey , 'can_leech' => '1' ));
2011-03-28 14:21:28 +00:00
}
2013-04-17 08:00:58 +00:00
// Take users off ratio watch
$UserQuery = $DB -> query ( "
SELECT
m . ID ,
torrent_pass
FROM users_info AS i
JOIN users_main AS m ON m . ID = i . UserID
WHERE m . Uploaded / m . Downloaded >= m . RequiredRatio
AND i . RatioWatchEnds != '0000-00-00 00:00:00'
AND m . Enabled = '1' " );
$OffRatioWatch = $DB -> collect ( 'ID' );
if ( count ( $OffRatioWatch ) > 0 ) {
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_info AS ui
JOIN users_main AS um ON um . ID = ui . UserID
SET ui . RatioWatchEnds = '0000-00-00 00:00:00' ,
ui . RatioWatchDownload = '0' ,
um . can_leech = '1'
WHERE ui . UserID IN ( " .implode(',', $OffRatioWatch ).')');
2013-04-17 08:00:58 +00:00
}
2011-05-13 08:00:07 +00:00
2013-04-17 08:00:58 +00:00
foreach ( $OffRatioWatch as $UserID ) {
$Cache -> begin_transaction ( 'user_info_heavy_' . $UserID );
$Cache -> update_row ( false , array ( 'RatioWatchEnds' => '0000-00-00 00:00:00' , 'RatioWatchDownload' => '0' , 'CanLeech' => 1 ));
$Cache -> commit_transaction ( 0 );
Misc :: send_pm ( $UserID , 0 , " You have been taken off Ratio Watch " , " Congratulations! Feel free to begin downloading again. \n To ensure that you do not get put on ratio watch again, please read the rules located [url=https:// " . SSL_SITE_URL . " /rules.php?p=ratio]here[/url]. \n " );
echo " Ratio watch off: $UserID\n " ;
}
$DB -> set_query_id ( $UserQuery );
$Passkeys = $DB -> collect ( 'torrent_pass' );
foreach ( $Passkeys as $Passkey ) {
Tracker :: update_tracker ( 'update_user' , array ( 'passkey' => $Passkey , 'can_leech' => '1' ));
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Put user on ratio watch if he doesn't meet the standards
sleep ( 10 );
2013-05-16 08:00:10 +00:00
$DB -> query ( "
SELECT m . ID ,
m . Downloaded
FROM users_info AS i
JOIN users_main AS m ON m . ID = i . UserID
WHERE m . Uploaded / m . Downloaded < m . RequiredRatio
AND i . RatioWatchEnds = '0000-00-00 00:00:00'
AND m . Enabled = '1'
AND m . can_leech = '1' " );
2011-03-28 14:21:28 +00:00
$OnRatioWatch = $DB -> collect ( 'ID' );
2013-02-22 08:00:24 +00:00
2013-05-16 08:00:10 +00:00
if ( count ( $OnRatioWatch ) > 0 ) {
$DB -> query ( "
UPDATE users_info AS i
JOIN users_main AS m ON m . ID = i . UserID
SET i . RatioWatchEnds = '".time_plus(60 * 60 * 24 * 14)."' ,
i . RatioWatchTimes = i . RatioWatchTimes + 1 ,
i . RatioWatchDownload = m . Downloaded
WHERE m . ID IN ( " .implode(',', $OnRatioWatch ).')');
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
foreach ( $OnRatioWatch as $UserID ) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'user_info_heavy_' . $UserID );
2013-04-17 08:00:58 +00:00
$Cache -> update_row ( false , array ( 'RatioWatchEnds' => time_plus ( 60 * 60 * 24 * 14 ), 'RatioWatchDownload' => 0 ));
2011-03-28 14:21:28 +00:00
$Cache -> commit_transaction ( 0 );
2013-04-17 08:00:58 +00:00
Misc :: send_pm ( $UserID , 0 , 'You have been put on Ratio Watch' , " This happens when your ratio falls below the requirements we have outlined in the rules located [url=https:// " . SSL_SITE_URL . " /rules.php?p=ratio]here[/url]. \n For information about ratio watch, click the link above. " );
2011-03-28 14:21:28 +00:00
echo " Ratio watch on: $UserID\n " ;
}
2012-12-31 08:00:20 +00:00
2011-03-28 14:21:28 +00:00
sleep ( 5 );
//------------- Rescore 0.95 logs of disabled users
2013-05-16 08:00:10 +00:00
$LogQuery = $DB -> query ( "
2013-05-31 08:00:59 +00:00
SELECT DISTINCT t . ID
FROM torrents AS t
JOIN users_main AS um ON t . UserID = um . ID
JOIN torrents_logs_new AS tl ON tl . TorrentID = t . ID
WHERE um . Enabled = '2'
AND t . HasLog = '1'
AND LogScore = 100
AND Log LIKE 'EAC extraction logfile from%' " );
2011-03-28 14:21:28 +00:00
$Details = array ();
$Details [] = " Ripped with EAC v0.95, -1 point [1] " ;
$Details = serialize ( $Details );
while ( list ( $TorrentID ) = $DB -> next_record ()) {
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE torrents
SET LogScore = 99
WHERE ID = $TorrentID " );
$DB -> query ( "
UPDATE torrents_logs_new
SET Score = 99 , Details = '$Details'
WHERE TorrentID = $TorrentID " );
2011-03-28 14:21:28 +00:00
}
sleep ( 5 );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
//------------- Disable downloading ability of users on ratio watch
2013-02-22 08:00:24 +00:00
2013-05-16 08:00:10 +00:00
$UserQuery = $DB -> query ( "
SELECT ID , torrent_pass
FROM users_info AS i
JOIN users_main AS m ON m . ID = i . UserID
WHERE i . RatioWatchEnds != '0000-00-00 00:00:00'
AND i . RatioWatchEnds < '$sqltime'
AND m . Enabled = '1'
AND m . can_leech != '0' " );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$UserIDs = $DB -> collect ( 'ID' );
2013-04-17 08:00:58 +00:00
if ( count ( $UserIDs ) > 0 ) {
2013-05-16 08:00:10 +00:00
$DB -> query ( "
UPDATE users_info AS i
JOIN users_main AS m ON m . ID = i . UserID
SET m . can_leech = '0' ,
i . AdminComment = CONCAT ( '$sqltime - Leeching ability disabled by ratio watch system - required ratio: ' , m . RequiredRatio , '' , i . AdminComment )
2013-05-31 08:00:59 +00:00
WHERE m . ID IN ( " .implode(',', $UserIDs ).')');
2012-11-08 08:00:19 +00:00
2013-05-16 16:15:57 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( " DELETE FROM users_torrent_history WHERE UserID IN ( " . implode ( ',' , $UserIDs ) . ')' );
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
foreach ( $UserIDs as $UserID ) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'user_info_heavy_' . $UserID );
2011-07-10 08:00:06 +00:00
$Cache -> update_row ( false , array ( 'RatioWatchDownload' => 0 , 'CanLeech' => 0 ));
2011-03-28 14:21:28 +00:00
$Cache -> commit_transaction ( 0 );
2013-04-17 08:00:58 +00:00
Misc :: send_pm ( $UserID , 0 , 'Your downloading rights have been disabled' , " As you did not raise your ratio in time, your downloading rights have been revoked. You will not be able to download any torrents until your ratio is above your new required ratio. " );
2011-03-28 14:21:28 +00:00
echo " Ratio watch disabled: $UserID\n " ;
}
$DB -> set_query_id ( $UserQuery );
$Passkeys = $DB -> collect ( 'torrent_pass' );
2013-04-17 08:00:58 +00:00
foreach ( $Passkeys as $Passkey ) {
2012-10-11 08:00:15 +00:00
Tracker :: update_tracker ( 'update_user' , array ( 'passkey' => $Passkey , 'can_leech' => '0' ));
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
//------------- Disable inactive user accounts --------------------------//
sleep ( 5 );
// Send email
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT um . Username , um . Email
FROM users_info AS ui
JOIN users_main AS um ON um . ID = ui . UserID
LEFT JOIN users_levels AS ul ON ul . UserID = um . ID AND ul . PermissionID = '".CELEB."'
WHERE um . PermissionID IN ( '".USER."' , '".MEMBER ."' )
AND um . LastAccess < '".time_minus(3600 * 24 * 110, true)."'
AND um . LastAccess > '".time_minus(3600 * 24 * 111, true)."'
AND um . LastAccess != '0000-00-00 00:00:00'
AND ui . Donor = '0'
AND um . Enabled != '2'
AND ul . UserID IS NULL
GROUP BY um . ID " );
2013-04-17 08:00:58 +00:00
while ( list ( $Username , $Email ) = $DB -> next_record ()) {
2013-04-19 08:00:55 +00:00
$Body = " Hi $Username , \n \n It has been almost 4 months since you used your account at https:// " . SSL_SITE_URL . " . This is an automated email to inform you that your account will be disabled in 10 days if you do not sign in. " ;
2012-10-11 08:00:15 +00:00
Misc :: send_email ( $Email , 'Your ' . SITE_NAME . ' account is about to be disabled' , $Body );
2011-03-28 14:21:28 +00:00
}
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT um . ID
FROM users_info AS ui
JOIN users_main AS um ON um . ID = ui . UserID
LEFT JOIN users_levels AS ul ON ul . UserID = um . ID AND ul . PermissionID = '".CELEB."'
WHERE um . PermissionID IN ( '".USER."' , '".MEMBER ."' )
AND um . LastAccess < '".time_minus(3600 * 24 * 30 * 4)."'
AND um . LastAccess != '0000-00-00 00:00:00'
AND ui . Donor = '0'
AND um . Enabled != '2'
AND ul . UserID IS NULL
GROUP BY um . ID " );
2013-04-17 08:00:58 +00:00
if ( $DB -> record_count () > 0 ) {
Tools :: disable_users ( $DB -> collect ( 'ID' ), 'Disabled for inactivity.' , 3 );
2011-03-28 14:21:28 +00:00
}
//------------- Disable unconfirmed users ------------------------------//
sleep ( 10 );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_info AS ui
JOIN users_main AS um ON um . ID = ui . UserID
SET um . Enabled = '2' ,
ui . BanDate = '$sqltime' ,
ui . BanReason = '3' ,
ui . AdminComment = CONCAT ( '$sqltime - Disabled for inactivity (never logged in)' , ui . AdminComment )
WHERE um . LastAccess = '0000-00-00 00:00:00'
AND ui . JoinDate < '".time_minus(60 * 60 * 24 * 7)."'
AND um . Enabled != '2'
2011-03-28 14:21:28 +00:00
" );
$Cache -> decrement ( 'stats_user_count' , $DB -> affected_rows ());
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
echo " disabled unconfirmed \n " ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
//------------- Demote users --------------------------------------------//
sleep ( 10 );
2013-05-31 08:00:59 +00:00
$DB -> query ( '
SELECT um . ID
FROM users_main AS um
WHERE PermissionID IN ( '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
AND Uploaded / Downloaded < 0.95
OR PermissionID IN ( '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
AND Uploaded < 25 * 1024 * 1024 * 1024 ' );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
echo " demoted 1 \n " ;
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
while ( list ( $UserID ) = $DB -> next_record ()) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'user_info_' . $UserID );
$Cache -> update_row ( false , array ( 'PermissionID' => MEMBER ));
$Cache -> commit_transaction ( 2592000 );
}
2013-05-31 08:00:59 +00:00
$DB -> query ( '
UPDATE users_main
SET PermissionID = '.MEMBER.'
WHERE PermissionID IN ( '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
AND Uploaded / Downloaded < 0.95
OR PermissionID IN ( '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
AND Uploaded < 25 * 1024 * 1024 * 1024 ' );
2011-03-28 14:21:28 +00:00
echo " demoted 2 \n " ;
2013-02-22 08:00:24 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( '
SELECT um . ID
FROM users_main AS um
WHERE PermissionID IN ( '.MEMBER.' , '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
AND Uploaded / Downloaded < 0.65 ' );
2011-03-28 14:21:28 +00:00
echo " demoted 3 \n " ;
2013-04-17 08:00:58 +00:00
while ( list ( $UserID ) = $DB -> next_record ()) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'user_info_' . $UserID );
$Cache -> update_row ( false , array ( 'PermissionID' => USER ));
$Cache -> commit_transaction ( 2592000 );
}
2013-05-31 08:00:59 +00:00
$DB -> query ( '
UPDATE users_main
SET PermissionID = '.USER.'
WHERE PermissionID IN ( '.MEMBER.' , '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
AND Uploaded / Downloaded < 0.65 ' );
2011-03-28 14:21:28 +00:00
echo " demoted 4 \n " ;
//------------- Lock old threads ----------------------------------------//
sleep ( 10 );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT t . ID , t . ForumID
FROM forums_topics AS t
JOIN forums AS f ON t . ForumID = f . ID
WHERE t . IsLocked = '0'
AND t . IsSticky = '0'
AND DATEDIFF ( CURDATE (), DATE ( t . LastPostTime )) / 7 > f . AutoLockWeeks
AND f . AutoLock = '1' " );
2011-03-28 14:21:28 +00:00
$IDs = $DB -> collect ( 'ID' );
2013-05-08 08:00:26 +00:00
$ForumIDs = $DB -> collect ( 'ForumID' );
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
if ( count ( $IDs ) > 0 ) {
2011-03-28 14:21:28 +00:00
$LockIDs = implode ( ',' , $IDs );
$DB -> query ( " UPDATE forums_topics SET IsLocked='1' WHERE ID IN( $LockIDs ) " );
sleep ( 2 );
$DB -> query ( " DELETE FROM forums_last_read_topics WHERE TopicID IN( $LockIDs ) " );
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
foreach ( $IDs as $ID ) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'thread_' . $ID . '_info' );
$Cache -> update_row ( false , array ( 'IsLocked' => '1' ));
2013-04-17 08:00:58 +00:00
$Cache -> commit_transaction ( 3600 * 24 * 30 );
2013-05-08 08:00:26 +00:00
$Cache -> expire_value ( 'thread_' . $ID . '_catalogue_0' , 3600 * 24 * 30 );
$Cache -> expire_value ( 'thread_' . $ID . '_info' , 3600 * 24 * 30 );
}
$ForumIDs = array_flip ( array_flip ( $ForumIDs ));
foreach ( $ForumIDs as $ForumID ) {
$Cache -> delete_value ( 'forums_' . $ForumID );
2011-03-28 14:21:28 +00:00
}
}
2012-01-31 08:00:23 +00:00
echo " Old threads locked \n " ;
2011-03-28 14:21:28 +00:00
//------------- Delete dead torrents ------------------------------------//
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
sleep ( 10 );
//remove dead torrents that were never announced to -- XBTT will not delete those with a pid of 0, only those that belong to them (valid pids)
$DB -> query ( " DELETE FROM torrents WHERE flags = 1 AND pid = 0 " );
sleep ( 10 );
$i = 0 ;
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT
t . ID ,
t . GroupID ,
tg . Name ,
ag . Name ,
t . last_action ,
t . Format ,
t . Encoding ,
t . UserID ,
t . Media ,
HEX ( t . info_hash ) AS InfoHash
FROM torrents AS t
JOIN torrents_group AS tg ON tg . ID = t . GroupID
LEFT JOIN artists_group AS ag ON ag . ArtistID = tg . ArtistID
WHERE t . last_action < '".time_minus(3600 * 24 * 28)."'
AND t . last_action != 0
OR t . Time < '".time_minus(3600 * 24 * 2)."'
AND t . last_action = 0 " );
2011-03-28 14:21:28 +00:00
$TorrentIDs = $DB -> to_array ();
2013-04-17 08:00:58 +00:00
echo 'Found ' . count ( $TorrentIDs ) . " inactive torrents to be deleted. \n " ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$LogEntries = array ();
2013-02-22 08:00:24 +00:00
2011-09-01 08:00:07 +00:00
// Exceptions for inactivity deletion
$InactivityExceptionsMade = array ( //UserID => expiry time of exception
2013-05-16 16:15:57 +00:00
2011-09-01 08:00:07 +00:00
);
2011-03-28 14:21:28 +00:00
foreach ( $TorrentIDs as $TorrentID ) {
2013-01-22 08:00:16 +00:00
list ( $ID , $GroupID , $Name , $ArtistName , $LastAction , $Format , $Encoding , $UserID , $Media , $InfoHash ) = $TorrentID ;
2011-09-01 08:00:07 +00:00
if ( array_key_exists ( $UserID , $InactivityExceptionsMade ) && ( time () < $InactivityExceptionsMade [ $UserID ])) {
// don't delete the torrent!
2013-02-22 08:00:24 +00:00
continue ;
2011-09-01 08:00:07 +00:00
}
2013-04-17 08:00:58 +00:00
if ( $ArtistName ) {
2011-03-28 14:21:28 +00:00
$Name = $ArtistName . ' - ' . $Name ;
}
2013-04-17 08:00:58 +00:00
if ( $Format && $Encoding ) {
$Name .= ' [' . ( empty ( $Media ) ? '' : " $Media / " ) . $Format . ' / ' . $Encoding . ']' ;
2011-03-28 14:21:28 +00:00
}
2012-10-11 08:00:15 +00:00
Torrents :: delete_torrent ( $ID , $GroupID );
2013-05-31 08:00:59 +00:00
$LogEntries [] = " Torrent $ID ( $Name ) ( " . strtoupper ( $InfoHash ) . " ) was deleted for inactivity (unseeded) " ;
2013-02-22 08:00:24 +00:00
2011-10-27 08:00:15 +00:00
if ( ! array_key_exists ( $UserID , $DeleteNotes ))
$DeleteNotes [ $UserID ] = array ( 'Count' => 0 , 'Msg' => '' );
2013-02-22 08:00:24 +00:00
2011-10-27 08:00:15 +00:00
$DeleteNotes [ $UserID ][ 'Msg' ] .= " \n $Name " ;
$DeleteNotes [ $UserID ][ 'Count' ] ++ ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
++ $i ;
2012-01-31 08:00:23 +00:00
if ( $i % 500 == 0 ) {
echo " $i inactive torrents removed. \n " ;
}
2011-03-28 14:21:28 +00:00
}
2012-01-31 08:00:23 +00:00
echo " $i torrents deleted for inactivity. \n " ;
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
foreach ( $DeleteNotes as $UserID => $MessageInfo ) {
2013-05-31 08:00:59 +00:00
$Singular = (( $MessageInfo [ 'Count' ] == 1 ) ? true : false );
2013-04-17 08:00:58 +00:00
Misc :: send_pm ( $UserID , 0 , $MessageInfo [ 'Count' ] . ' of your torrents ' . ( $Singular ? 'has' : 'have' ) . ' been deleted for inactivity' , ( $Singular ? 'One' : 'Some' ) . ' of your uploads ' . ( $Singular ? 'has' : 'have' ) . ' been deleted for being unseeded. Since ' . ( $Singular ? 'it' : 'they' ) . ' didn\'t break any rules (we hope), please feel free to re-upload ' . ( $Singular ? 'it' : 'them' ) . " . \n \n The following torrent " . ( $Singular ? ' was' : 's were' ) . ' deleted:' . $MessageInfo [ 'Msg' ]);
2013-02-22 08:00:24 +00:00
}
2011-10-27 08:00:15 +00:00
unset ( $DeleteNotes );
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
if ( count ( $LogEntries ) > 0 ) {
2013-05-31 08:00:59 +00:00
$Values = " (' " . implode ( " ', ' " . $sqltime . " '), (' " , $LogEntries ) . " ', ' $sqltime ') " ;
2011-03-28 14:21:28 +00:00
$DB -> query ( 'INSERT INTO log (Message, Time) VALUES ' . $Values );
echo " \n Deleted $i torrents for inactivity \n " ;
}
$DB -> query ( " SELECT SimilarID FROM artists_similar_scores WHERE Score<=0 " );
$SimilarIDs = implode ( ',' , $DB -> collect ( 'SimilarID' ));
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
if ( $SimilarIDs ) {
2011-03-28 14:21:28 +00:00
$DB -> query ( " DELETE FROM artists_similar WHERE SimilarID IN( $SimilarIDs ) " );
$DB -> query ( " DELETE FROM artists_similar_scores WHERE SimilarID IN( $SimilarIDs ) " );
$DB -> query ( " DELETE FROM artists_similar_votes WHERE SimilarID IN( $SimilarIDs ) " );
}
2013-02-22 08:00:24 +00:00
2013-05-16 16:15:57 +00:00
2011-03-28 14:21:28 +00:00
// Daily top 10 history.
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO top10_history ( Date , Type )
VALUES ( '$sqltime' , 'Daily' ) " );
2011-03-28 14:21:28 +00:00
$HistoryID = $DB -> inserted_id ();
$Top10 = $Cache -> get_value ( 'top10tor_day_10' );
2013-04-17 08:00:58 +00:00
if ( $Top10 === false ) {
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT
2011-03-28 14:21:28 +00:00
t . ID ,
g . ID ,
g . Name ,
g . CategoryID ,
g . TagList ,
t . Format ,
t . Encoding ,
t . Media ,
t . Scene ,
t . HasLog ,
t . HasCue ,
t . LogScore ,
t . RemasterYear ,
g . Year ,
t . RemasterTitle ,
t . Snatched ,
t . Seeders ,
t . Leechers ,
(( t . Size * t . Snatched ) + ( t . Size * 0.5 * t . Leechers )) AS Data
FROM torrents AS t
LEFT JOIN torrents_group AS g ON g . ID = t . GroupID
WHERE t . Seeders > 0
2013-04-17 08:00:58 +00:00
AND t . Time > ( '$sqltime' - INTERVAL 1 DAY )
2011-03-28 14:21:28 +00:00
ORDER BY ( t . Seeders + t . Leechers ) DESC
LIMIT 10 ; " );
$Top10 = $DB -> to_array ();
}
$i = 1 ;
2013-04-17 08:00:58 +00:00
foreach ( $Top10 as $Torrent ) {
2013-05-31 08:00:59 +00:00
list ( $TorrentID , $GroupID , $GroupName , $GroupCategoryID , $TorrentTags ,
$Format , $Encoding , $Media , $Scene , $HasLog , $HasCue , $LogScore , $Year , $GroupYear ,
$RemasterTitle , $Snatched , $Seeders , $Leechers , $Data ) = $Torrent ;
2011-03-28 14:21:28 +00:00
2013-05-31 08:00:59 +00:00
$DisplayName = '' ;
2013-02-22 08:00:24 +00:00
2012-10-11 08:00:15 +00:00
$Artists = Artists :: get_artist ( $GroupID );
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
if ( ! empty ( $Artists )) {
2012-10-11 08:00:15 +00:00
$DisplayName = Artists :: display_artists ( $Artists , false , true );
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$DisplayName .= $GroupName ;
2013-04-17 08:00:58 +00:00
if ( $GroupCategoryID == 1 && $GroupYear > 0 ) {
2011-03-28 14:21:28 +00:00
$DisplayName .= " [ $GroupYear ] " ;
}
// append extra info to torrent title
2013-05-31 08:00:59 +00:00
$ExtraInfo = '' ;
$AddExtra = '' ;
2013-04-17 08:00:58 +00:00
if ( $Format ) { $ExtraInfo .= $Format ; $AddExtra = ' / ' ; }
if ( $Encoding ) { $ExtraInfo .= $AddExtra . $Encoding ; $AddExtra = ' / ' ; }
2012-01-31 08:00:23 +00:00
// "FLAC / Lossless / Log (100%) / Cue / CD";
2013-04-17 08:00:58 +00:00
if ( $HasLog ) { $ExtraInfo .= $AddExtra . " Log ( " . $LogScore . " %) " ; $AddExtra = ' / ' ; }
if ( $HasCue ) { $ExtraInfo .= $AddExtra . " Cue " ; $AddExtra = ' / ' ; }
if ( $Media ) { $ExtraInfo .= $AddExtra . $Media ; $AddExtra = ' / ' ; }
if ( $Scene ) { $ExtraInfo .= $AddExtra . 'Scene' ; $AddExtra = ' / ' ; }
if ( $Year > 0 ) { $ExtraInfo .= $AddExtra . $Year ; $AddExtra = ' ' ; }
if ( $RemasterTitle ) { $ExtraInfo .= $AddExtra . $RemasterTitle ; }
if ( $ExtraInfo != '' ) {
2011-03-28 14:21:28 +00:00
$ExtraInfo = " - [ $ExtraInfo ] " ;
}
$TitleString = $DisplayName . ' ' . $ExtraInfo ;
2013-05-31 08:00:59 +00:00
$TagString = str_replace ( '|' , ' ' , $TorrentTags );
2011-03-28 14:21:28 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO top10_history_torrents
( HistoryID , Rank , TorrentID , TitleString , TagString )
2011-03-28 14:21:28 +00:00
VALUES
2013-05-31 08:00:59 +00:00
( $HistoryID , $i , $TorrentID , '".db_string($TitleString)."' , '".db_string($TagString)."' ) " );
2011-03-28 14:21:28 +00:00
$i ++ ;
}
// Weekly top 10 history.
// We need to haxxor it to work on a Sunday as we don't have a weekly schedule
2013-04-17 08:00:58 +00:00
if ( date ( 'w' ) == 0 ) {
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO top10_history ( Date , Type )
VALUES ( '$sqltime' , 'Weekly' ) " );
2011-03-28 14:21:28 +00:00
$HistoryID = $DB -> inserted_id ();
$Top10 = $Cache -> get_value ( 'top10tor_week_10' );
2013-04-17 08:00:58 +00:00
if ( $Top10 === false ) {
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT
2011-03-28 14:21:28 +00:00
t . ID ,
g . ID ,
g . Name ,
g . CategoryID ,
g . TagList ,
t . Format ,
t . Encoding ,
t . Media ,
t . Scene ,
t . HasLog ,
t . HasCue ,
t . LogScore ,
t . RemasterYear ,
g . Year ,
t . RemasterTitle ,
t . Snatched ,
t . Seeders ,
t . Leechers ,
(( t . Size * t . Snatched ) + ( t . Size * 0.5 * t . Leechers )) AS Data
FROM torrents AS t
LEFT JOIN torrents_group AS g ON g . ID = t . GroupID
WHERE t . Seeders > 0
2013-05-31 08:00:59 +00:00
AND t . Time > ( '$sqltime' - INTERVAL 1 WEEK )
2011-03-28 14:21:28 +00:00
ORDER BY ( t . Seeders + t . Leechers ) DESC
LIMIT 10 ; " );
$Top10 = $DB -> to_array ();
}
$i = 1 ;
2013-04-17 08:00:58 +00:00
foreach ( $Top10 as $Torrent ) :
list ( $TorrentID , $GroupID , $GroupName , $GroupCategoryID , $TorrentTags ,
$Format , $Encoding , $Media , $Scene , $HasLog , $HasCue , $LogScore , $Year , $GroupYear ,
$RemasterTitle , $Snatched , $Seeders , $Leechers , $Data ) = $Torrent ;
2011-03-28 14:21:28 +00:00
2013-05-31 08:00:59 +00:00
$DisplayName = '' ;
2013-02-22 08:00:24 +00:00
2012-10-11 08:00:15 +00:00
$Artists = Artists :: get_artist ( $GroupID );
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
if ( ! empty ( $Artists )) {
2012-10-11 08:00:15 +00:00
$DisplayName = Artists :: display_artists ( $Artists , false , true );
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$DisplayName .= $GroupName ;
2013-04-17 08:00:58 +00:00
if ( $GroupCategoryID == 1 && $GroupYear > 0 ) {
2011-03-28 14:21:28 +00:00
$DisplayName .= " [ $GroupYear ] " ;
}
// append extra info to torrent title
2013-04-17 08:00:58 +00:00
$ExtraInfo = '' ;
$AddExtra = '' ;
if ( $Format ) {
2013-05-31 08:00:59 +00:00
$ExtraInfo .= $Format ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $Encoding ) {
2013-05-31 08:00:59 +00:00
$ExtraInfo .= $AddExtra . $Encoding ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
2012-01-31 08:00:23 +00:00
// "FLAC / Lossless / Log (100%) / Cue / CD";
2013-04-17 08:00:58 +00:00
if ( $HasLog ) {
2013-05-31 08:00:59 +00:00
$ExtraInfo .= $AddExtra . 'Log (' . $LogScore . '%)' ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $HasCue ) {
2013-05-31 08:00:59 +00:00
$ExtraInfo .= $AddExtra . 'Cue' ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $Media ) {
2013-05-31 08:00:59 +00:00
$ExtraInfo .= $AddExtra . $Media ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $Scene ) {
2013-05-31 08:00:59 +00:00
$ExtraInfo .= $AddExtra . 'Scene' ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $Year > 0 ) {
2013-05-31 08:00:59 +00:00
$ExtraInfo .= $AddExtra . $Year ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' ' ;
}
if ( $RemasterTitle ) {
2013-05-31 08:00:59 +00:00
$ExtraInfo .= $AddExtra . $RemasterTitle ;
2013-04-17 08:00:58 +00:00
}
if ( $ExtraInfo != '' ) {
2011-03-28 14:21:28 +00:00
$ExtraInfo = " - [ $ExtraInfo ] " ;
}
$TitleString = $DisplayName . ' ' . $ExtraInfo ;
2013-05-31 08:00:59 +00:00
$TagString = str_replace ( '|' , ' ' , $TorrentTags );
2011-03-28 14:21:28 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO top10_history_torrents
( HistoryID , Rank , TorrentID , TitleString , TagString )
2011-03-28 14:21:28 +00:00
VALUES
2013-05-31 08:00:59 +00:00
( $HistoryID , $i , $TorrentID , " .db_string( $TitleString ). " ', ' " .db_string( $TagString ). " ' ) " );
2011-03-28 14:21:28 +00:00
$i ++ ;
2013-04-17 08:00:58 +00:00
endforeach ;
2013-02-22 08:00:24 +00:00
2011-10-27 08:00:15 +00:00
// Send warnings to uploaders of torrents that will be deleted this week
2013-04-17 08:00:58 +00:00
$DB -> query ( "
SELECT
t . ID ,
t . GroupID ,
tg . Name ,
t . Format ,
t . Encoding ,
t . UserID
2011-10-27 08:00:15 +00:00
FROM torrents AS t
2013-04-17 08:00:58 +00:00
JOIN torrents_group AS tg ON tg . ID = t . GroupID
JOIN users_info AS u ON u . UserID = t . UserID
LEFT JOIN artists_group AS ag ON ag . ArtistID = tg . ArtistID
2011-10-27 08:00:15 +00:00
WHERE t . last_action < NOW () - INTERVAL 20 DAY
2013-04-17 08:00:58 +00:00
AND t . last_action != 0
AND u . UnseededAlerts = '1'
2011-10-27 08:00:15 +00:00
ORDER BY t . last_action ASC " );
$TorrentIDs = $DB -> to_array ();
$TorrentAlerts = array ();
foreach ( $TorrentIDs as $TorrentID ) {
list ( $ID , $GroupID , $Name , $Format , $Encoding , $UserID ) = $TorrentID ;
2013-02-22 08:00:24 +00:00
2011-10-27 08:00:15 +00:00
if ( array_key_exists ( $UserID , $InactivityExceptionsMade ) && ( time () < $InactivityExceptionsMade [ $UserID ])) {
// don't notify exceptions
2013-02-22 08:00:24 +00:00
continue ;
2011-10-27 08:00:15 +00:00
}
2013-02-22 08:00:24 +00:00
2011-10-27 08:00:15 +00:00
if ( ! array_key_exists ( $UserID , $TorrentAlerts ))
$TorrentAlerts [ $UserID ] = array ( 'Count' => 0 , 'Msg' => '' );
2012-10-11 08:00:15 +00:00
$ArtistName = Artists :: display_artists ( Artists :: get_artist ( $GroupID ), false , false , false );
2013-04-17 08:00:58 +00:00
if ( $ArtistName ) {
2011-10-27 08:00:15 +00:00
$Name = $ArtistName . ' - ' . $Name ;
}
2013-04-17 08:00:58 +00:00
if ( $Format && $Encoding ) {
2011-10-27 08:00:15 +00:00
$Name .= ' [' . $Format . ' / ' . $Encoding . ']' ;
}
2013-04-17 08:00:58 +00:00
$TorrentAlerts [ $UserID ][ 'Msg' ] .= " \n [url=https:// " . SSL_SITE_URL . " /torrents.php?torrentid= $ID ] " . $Name . " [/url] " ;
2011-10-27 08:00:15 +00:00
$TorrentAlerts [ $UserID ][ 'Count' ] ++ ;
}
2013-04-17 08:00:58 +00:00
foreach ( $TorrentAlerts as $UserID => $MessageInfo ) {
2013-05-08 08:00:26 +00:00
Misc :: send_pm ( $UserID , 0 , 'Unseeded torrent notification' , $MessageInfo [ 'Count' ] . " of your uploads will be deleted for inactivity soon. Unseeded torrents are deleted after 4 weeks. If you still have the files, you can seed your uploads by ensuring the torrents are in your client and that they aren't stopped. You can view the time that a torrent has been unseeded by clicking on the torrent description line and looking for the \" Last active \" time. For more information, please go [url=https:// " . SSL_SITE_URL . " /wiki.php?action=article&id=663]here[/url]. \n \n The following torrent " . ( $MessageInfo [ 'Count' ] > 1 ? 's' : '' ) . ' will be removed for inactivity:' . $MessageInfo [ 'Msg' ] . " \n \n If you no longer wish to receive these notifications, please disable them in your profile settings. " );
2011-10-27 08:00:15 +00:00
}
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE staff_pm_conversations
SET Status = 'Resolved' , ResolverID = '0'
WHERE Date < NOW () - INTERVAL 1 MONTH
AND Status = 'Open'
AND AssignedToUser IS NULL " );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
}
/************************************************************************* \
//--------------Run twice per month -------------------------------------//
These functions are twice per month , on the 8 th and the 22 nd .
\ *************************************************************************/
2013-04-17 08:00:58 +00:00
if ( $BiWeek != next_biweek () || $_GET [ 'runbiweek' ]) {
2011-03-28 14:21:28 +00:00
echo " Ran bi-weekly functions \n " ;
//------------- Cycle auth keys -----------------------------------------//
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_info
SET AuthKey =
MD5 (
CONCAT (
AuthKey , RAND (), '".db_string(Users::make_secret())."' ,
SHA1 (
CONCAT (
RAND (), RAND (), '".db_string(Users::make_secret())."'
)
2011-03-28 14:21:28 +00:00
)
)
2013-05-31 08:00:59 +00:00
); "
2011-03-28 14:21:28 +00:00
);
//------------- Give out invites! ---------------------------------------//
/*
2013-04-17 08:00:58 +00:00
PUs have a cap of 2 invites . Elites have a cap of 4.
2012-01-13 08:00:27 +00:00
Every month , on the 8 th and the 22 nd , each PU / Elite User gets one invite up to their max .
2011-03-28 14:21:28 +00:00
Then , every month , on the 8 th and the 22 nd , we give out bonus invites like this :
2012-01-13 08:00:27 +00:00
Every Power User or Elite whose total invitee ratio is above 0.75 and total invitee upload is over 2 gigs gets one invite .
Every Elite whose total invitee ratio is above 2.0 and total invitee upload is over 10 gigs gets one more invite .
Every Elite whose total invitee ratio is above 3.0 and total invitee upload is over 20 gigs gets yet one more invite .
2011-03-28 14:21:28 +00:00
This cascades , so if you qualify for the last bonus group , you also qualify for the first two and will receive three bonus invites .
2012-01-13 08:00:27 +00:00
The bonus invites cannot put a user over their cap .
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
*/
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT ID
FROM users_main AS um
JOIN users_info AS ui on ui . UserID = um . ID
WHERE um . Enabled = '1'
AND ui . DisableInvites = '0'
AND (( um . PermissionID = " .POWER. "
AND um . Invites < 2
) OR ( um . PermissionID = " .ELITE. "
AND um . Invites < 4 )
) " );
2011-03-28 14:21:28 +00:00
$UserIDs = $DB -> collect ( 'ID' );
if ( count ( $UserIDs ) > 0 ) {
2013-04-17 08:00:58 +00:00
foreach ( $UserIDs as $UserID ) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'user_info_heavy_' . $UserID );
$Cache -> update_row ( false , array ( 'Invites' => '+1' ));
$Cache -> commit_transaction ( 0 );
}
2013-05-31 08:00:59 +00:00
$DB -> query ( '
UPDATE users_main
SET Invites = Invites + 1
WHERE ID IN ( '.implode(' , ', $UserIDs).' ) ' );
2011-03-28 14:21:28 +00:00
}
$BonusReqs = array (
2013-04-17 08:00:58 +00:00
array ( 0.75 , 2 * 1024 * 1024 * 1024 ),
array ( 2.0 , 10 * 1024 * 1024 * 1024 ),
array ( 3.0 , 20 * 1024 * 1024 * 1024 ));
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Since MySQL doesn't like subselecting from the target table during an update, we must create a temporary table.
2013-05-31 08:00:59 +00:00
$DB -> query ( "
CREATE TEMPORARY TABLE temp_sections_schedule_index
SELECT SUM ( Uploaded ) AS Upload , SUM ( Downloaded ) AS Download , Inviter
FROM users_main AS um
JOIN users_info AS ui ON ui . UserID = um . ID
GROUP BY Inviter " );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
foreach ( $BonusReqs as $BonusReq ) {
list ( $Ratio , $Upload ) = $BonusReq ;
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT ID
FROM users_main AS um
JOIN users_info AS ui ON ui . UserID = um . ID
JOIN temp_sections_schedule_index AS u ON u . Inviter = um . ID
WHERE u . Upload > $Upload AND u . Upload / u . Download > $Ratio
AND um . Enabled = '1'
AND ui . DisableInvites = '0'
AND (( um . PermissionID = " .POWER. "
AND um . Invites < 2
) OR ( um . PermissionID = " .ELITE. "
AND um . Invites < 4 )
) " );
2011-03-28 14:21:28 +00:00
$UserIDs = $DB -> collect ( 'ID' );
if ( count ( $UserIDs ) > 0 ) {
2013-04-17 08:00:58 +00:00
foreach ( $UserIDs as $UserID ) {
2011-03-28 14:21:28 +00:00
$Cache -> begin_transaction ( 'user_info_heavy_' . $UserID );
$Cache -> update_row ( false , array ( 'Invites' => '+1' ));
$Cache -> commit_transaction ( 0 );
}
2013-05-31 08:00:59 +00:00
$DB -> query ( '
UPDATE users_main
SET Invites = Invites + 1
WHERE ID IN ( '.implode(' , ', $UserIDs).' ) ' );
2011-03-28 14:21:28 +00:00
}
}
2013-02-22 08:00:24 +00:00
2013-04-17 08:00:58 +00:00
if ( $BiWeek == 8 ) {
$DB -> query ( 'TRUNCATE TABLE top_snatchers;' );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
INSERT INTO top_snatchers ( UserID )
SELECT uid
FROM xbt_snatched
GROUP BY uid
ORDER BY COUNT ( uid ) DESC
LIMIT 100 ; " );
2012-08-20 08:00:13 +00:00
2011-03-28 14:21:28 +00:00
}
}
echo " ------------------------- \n \n " ;
2013-02-22 08:00:24 +00:00
if ( check_perms ( 'admin_schedule' )) {
2011-03-28 14:21:28 +00:00
echo '<pre>' ;
2012-10-11 08:00:15 +00:00
View :: show_footer ();
2011-03-28 14:21:28 +00:00
}
?>