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-11-08 08:01:03 +00:00
/*
* Use this if your version of pgrep does not support the '-c' option .
* The '-c' option requires procps - ng .
*
* $PCount = chop ( shell_exec ( " /usr/bin/pgrep -f schedule.php | wc -l " ));
*/
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
2013-07-10 00:08:53 +00:00
WHERE u . Enabled = '1'
2013-05-31 08:00:59 +00:00
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>' ;
}
2013-07-10 00:08:53 +00:00
$DB -> query ( "
SELECT NextHour , NextDay , NextBiWeekly
FROM schedule " );
2011-03-28 14:21:28 +00:00
list ( $Hour , $Day , $BiWeek ) = $DB -> next_record ();
2013-09-13 08:00:53 +00:00
$NextHour = next_hour ();
$NextDay = next_day ();
$NextBiWeek = next_biweek ();
2013-07-10 00:08:53 +00:00
$DB -> query ( "
UPDATE schedule
SET
2013-09-13 08:00:53 +00:00
NextHour = $NextHour ,
NextDay = $NextDay ,
NextBiWeekly = $NextBiWeek " );
2011-03-28 14:21:28 +00:00
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-07-10 00:08:53 +00:00
//We use this to control 6 hour freeleeches. They're actually 7 hours, 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
2013-07-10 00:08:53 +00:00
WHERE FreeTorrent = '1'
AND FreeLeechType = '3'
AND Time < '$TimeMinus' " );
2013-04-17 08:00:58 +00:00
while ( list ( $GroupID ) = $DB -> next_record ()) {
2013-07-10 00:08:53 +00:00
$Cache -> delete_value ( " torrents_details_ $GroupID " );
$Cache -> delete_value ( " torrent_group_ $GroupID " );
2011-03-28 14:21:28 +00:00
}
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE torrents
2013-07-10 00:08:53 +00:00
SET FreeTorrent = '0' ,
2013-08-28 23:08:41 +00:00
FreeLeechType = '0'
2013-07-10 00:08:53 +00:00
WHERE FreeTorrent = '1'
AND FreeLeechType = '3'
AND Time < '$TimeMinus' " );
2011-03-28 14:21:28 +00:00
*/
sleep ( 5 );
//------------- Delete unpopular tags -----------------------------------//
2013-07-10 00:08:53 +00:00
$DB -> query ( "
DELETE FROM torrents_tags
2013-10-29 08:01:29 +00:00
WHERE NegativeVotes > 1
AND NegativeVotes > PositiveVotes " );
2011-03-28 14:21:28 +00:00
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 " );
2013-10-29 08:01:29 +00:00
if ( $DB -> has_results ()) {
while ( list ( $UserID ) = $DB -> next_record ()) {
$Cache -> delete_value ( 'users_tokens_' . $UserID [ 0 ]);
}
2011-10-27 08:00:15 +00:00
2013-10-29 08:01:29 +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 )) {
Tracker :: update_tracker ( 'remove_token' , array ( 'info_hash' => rawurlencode ( $InfoHash ), 'userid' => $UserID ));
}
$DB -> query ( "
UPDATE users_freeleeches
SET Expired = TRUE
WHERE Time < '$sqltime' - INTERVAL 4 DAY
AND Expired = FALSE " );
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-09-13 08:00:53 +00:00
if ( $Hour != $NextHour || $_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 ) {
2013-07-10 00:08:53 +00:00
$DB -> query ( "
SELECT COUNT ( uid ) AS Snatches
FROM xbt_snatched " );
2011-03-28 14:21:28 +00:00
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 ( "
2013-07-10 00:08:53 +00:00
SELECT IF ( remaining = 0 , 'Seeding' , 'Leeching' ) AS Type ,
2013-05-31 08:00:59 +00:00
COUNT ( uid )
FROM xbt_files_users
2013-07-10 00:08:53 +00:00
WHERE active = 1
2013-05-31 08:00:59 +00:00
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-07-10 00:08:53 +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-07-10 00:08:53 +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-07-10 00:08:53 +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 ();
2013-07-10 00:08:53 +00:00
$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 )
2013-07-10 00:08:53 +00:00
SELECT uid , COUNT ( DISTINCT fid )
2013-05-31 08:00:59 +00:00
FROM xbt_files_users
2013-07-10 00:08:53 +00:00
WHERE mtime > unix_timestamp ( NOW () - INTERVAL 1 HOUR )
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-07-10 00:08:53 +00:00
JOIN users_torrent_history_temp AS t ON t . UserID = h . UserID
AND t . NumTorrents = h . NumTorrents
SET h . Finished = '0' ,
h . LastTime = UNIX_TIMESTAMP ( NOW ())
WHERE h . Finished = '1'
AND h . Date = UTC_DATE () + 0 " );
2013-06-17 08:01:02 +00:00
// 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 )
2013-07-10 00:08:53 +00:00
SELECT UserID , NumTorrents , UTC_DATE () + 0
2013-05-31 08:00:59 +00:00
FROM users_torrent_history_temp
ON DUPLICATE KEY UPDATE
2013-07-10 00:08:53 +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-07-10 00:08:53 +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 ));
2013-05-31 08:00:59 +00:00
$Criteria [] = array (
2013-07-10 00:08:53 +00:00
'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 ' );
2013-05-31 08:00:59 +00:00
$Criteria [] = array (
2013-07-10 00:08:53 +00:00
'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
2013-07-10 00:08:53 +00:00
WHERE PermissionID = " . $L['From'] . "
AND Warned = '0000-00-00 00:00:00'
AND Uploaded >= '$L[MinUpload]'
2013-10-15 08:01:05 +00:00
AND ( Uploaded / Downloaded >= '$L[MinRatio]' OR ( Uploaded / Downloaded IS NULL ))
2013-07-10 00:08:53 +00:00
AND JoinDate < '$L[MaxTime]'
2013-04-17 08:00:58 +00:00
AND (
SELECT COUNT ( ID )
FROM torrents
2013-07-10 00:08:53 +00:00
WHERE UserID = users_main . ID
2013-04-17 08:00:58 +00:00
) >= '$L[MinUploads]'
2013-07-10 00:08:53 +00:00
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 ) {
2014-05-19 08:00:28 +00:00
$DB -> query ( "
UPDATE users_main
SET PermissionID = " . $L['To'] . "
WHERE ID IN ( " .implode(',', $UserIDs ).')');
2013-04-17 08:00:58 +00:00
foreach ( $UserIDs as $UserID ) {
2013-07-10 00:08:53 +00:00
/* $Cache -> begin_transaction ( " user_info_ $UserID " );
$Cache -> update_row ( false , array ( 'PermissionID' => $L [ 'To' ]));
2011-03-28 14:21:28 +00:00
$Cache -> commit_transaction ( 0 ); */
2013-07-10 00:08:53 +00:00
$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 " );
2014-02-27 08:00:30 +00:00
Misc :: send_pm ( $UserID , 0 , 'You have been promoted to ' . Users :: make_class_string ( $L [ 'To' ]), 'Congratulations on your promotion to ' . Users :: make_class_string ( $L [ 'To' ]) . " ! \n \n To read more about " . SITE_NAME . " 's user classes, read [url= " . site_url () . " wiki.php?action=article&name=userclasses]this wiki article[/url]. " );
2013-02-22 08:00:24 +00:00
}
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
2013-07-10 00:08:53 +00:00
WHERE PermissionID = '$L[To]'
AND ( Uploaded < '$L[MinUpload]'
2013-04-17 08:00:58 +00:00
OR (
SELECT COUNT ( ID )
FROM torrents
2013-07-10 00:08:53 +00:00
WHERE UserID = users_main . ID
2013-05-31 08:00:59 +00:00
) < '$L[MinUploads]' " ;
2011-03-28 14:21:28 +00:00
if ( ! empty ( $L [ 'Extra' ])) {
2013-07-10 00:08:53 +00:00
$Query .= ' OR NOT ' . $L [ 'Extra' ];
2011-03-28 14:21:28 +00:00
}
2013-05-31 08:00:59 +00:00
$Query .= "
)
2013-07-10 00:08:53 +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 ) {
2014-05-19 08:00:28 +00:00
$DB -> query ( "
UPDATE users_main
SET PermissionID = " . $L['From'] . "
WHERE ID IN ( " .implode(',', $UserIDs ).')');
2013-04-17 08:00:58 +00:00
foreach ( $UserIDs as $UserID ) {
2013-07-10 00:08:53 +00:00
/* $Cache -> begin_transaction ( " user_info_ $UserID " );
$Cache -> update_row ( false , array ( 'PermissionID' => $L [ 'From' ]));
2011-03-28 14:21:28 +00:00
$Cache -> commit_transaction ( 0 ); */
2013-07-10 00:08:53 +00:00
$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 " );
2014-02-27 08:00:30 +00:00
Misc :: send_pm ( $UserID , 0 , 'You have been demoted to ' . Users :: make_class_string ( $L [ 'From' ]), " You now only qualify for the \" " . Users :: make_class_string ( $L [ 'From' ]) . " \" user class. \n \n To read more about " . SITE_NAME . " 's user classes, read [url= " . site_url () . " wiki.php?action=article&name=userclasses]this wiki article[/url]. " );
2011-03-28 14:21:28 +00:00
}
}
}
//------------- Expire invites ------------------------------------------//
sleep ( 3 );
2013-07-10 00:08:53 +00:00
$DB -> query ( "
SELECT InviterID
FROM invites
WHERE Expires < '$sqltime' " );
2011-03-28 14:21:28 +00:00
$Users = $DB -> to_array ();
foreach ( $Users as $UserID ) {
list ( $UserID ) = $UserID ;
2013-07-10 00:08:53 +00:00
$DB -> query ( "
SELECT Invites , PermissionID
FROM users_main
WHERE ID = $UserID " );
2012-03-18 08:00:22 +00:00
list ( $Invites , $PermID ) = $DB -> next_record ();
if (( $Invites < 2 && $Classes [ $PermID ][ 'Level' ] <= $Classes [ POWER ][ 'Level' ]) || ( $Invites < 4 && $PermID == ELITE )) {
2013-07-10 00:08:53 +00:00
$DB -> query ( "
UPDATE users_main
SET Invites = Invites + 1
WHERE ID = $UserID " );
$Cache -> begin_transaction ( " user_info_heavy_ $UserID " );
2011-03-28 14:21:28 +00:00
$Cache -> update_row ( false , array ( 'Invites' => '+1' ));
$Cache -> commit_transaction ( 0 );
}
}
2013-07-10 00:08:53 +00:00
$DB -> query ( "
DELETE FROM invites
WHERE Expires < '$sqltime' " );
2011-03-28 14:21:28 +00:00
//------------- 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 );
2013-07-10 00:08:53 +00:00
$DB -> query ( "
DELETE FROM xbt_files_users
WHERE mtime < unix_timestamp ( NOW () - INTERVAL 6 HOUR ) " );
2011-03-28 14:21:28 +00:00
//------------- 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
2013-07-10 00:08:53 +00:00
WHERE ( LastUpdate < '$AgoDays' AND KeepLogged = '1' )
OR ( LastUpdate < '$AgoMins' AND KeepLogged = '0' ) " );
2013-05-27 08:00:58 +00:00
$DB -> query ( "
DELETE FROM users_sessions
2013-07-10 00:08:53 +00:00
WHERE ( LastUpdate < '$AgoDays' AND KeepLogged = '1' )
OR ( LastUpdate < '$AgoMins' AND KeepLogged = '0' ) " );
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 ()) {
2013-07-10 00:08:53 +00:00
$Cache -> begin_transaction ( " users_sessions_ $UserID " );
2011-03-28 14:21:28 +00:00
$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 ------------------------------------//
2013-07-10 00:08:53 +00:00
$DB -> query ( "
UPDATE login_attempts
SET Attempts = Attempts - 1
WHERE Attempts > 0 " );
$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 ---------------------------------//
2013-07-10 00:08:53 +00:00
$DB -> query ( "
SELECT UserID
FROM users_info
WHERE Warned < '$sqltime' " );
2013-04-17 08:00:58 +00:00
while ( list ( $UserID ) = $DB -> next_record ()) {
2014-05-19 08:00:28 +00:00
$Cache -> begin_transaction ( " user_info_ $UserID " );
$Cache -> update_row ( false , array ( 'Warned' => '0000-00-00 00:00:00' ));
$Cache -> commit_transaction ( 2592000 );
2013-04-17 08:00:58 +00:00
}
2013-02-22 08:00:24 +00:00
2013-07-10 00:08:53 +00:00
$DB -> query ( "
UPDATE users_info
SET Warned = '0000-00-00 00:00:00'
WHERE Warned < '$sqltime' " );
2013-04-17 08:00:58 +00:00
2013-07-10 00:08:53 +00:00
// If a user has downloaded more than 10 GiBs while on ratio watch, disable leeching privileges, and send the user a message
2013-04-17 08:00:58 +00:00
2013-04-21 08:00:52 +00:00
$DB -> query ( "
2013-07-28 08:00:53 +00:00
SELECT ID , torrent_pass
2013-04-21 08:00:52 +00:00
FROM users_info AS i
2013-07-10 00:08:53 +00:00
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' " );
2013-07-28 08:00:53 +00:00
$Users = $DB -> to_pair ( 'torrent_pass' , 'ID' );
2012-08-19 08:00:19 +00:00
2013-07-28 08:00:53 +00:00
if ( count ( $Users ) > 0 ) {
2013-04-17 08:00:58 +00:00
$Subject = 'Leeching Disabled' ;
2014-04-03 08:00:54 +00:00
$Message = 'You have downloaded more than 10 GB 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 ' . site_url () . 'wiki.php?action=article&id=110' ;
2013-07-28 08:00:53 +00:00
foreach ( $Users as $TorrentPass => $UserID ) {
2013-04-17 08:00:58 +00:00
Misc :: send_pm ( $UserID , 0 , $Subject , $Message );
2013-07-28 08:00:53 +00:00
Tracker :: update_tracker ( 'update_user' , array ( 'passkey' => $TorrentPass , 'can_leech' => '0' ));
2013-04-17 08:00:58 +00:00
}
2013-04-21 08:00:52 +00:00
$DB -> query ( "
UPDATE users_info AS i
2013-07-10 00:08:53 +00:00
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 )
2013-07-28 08:00:53 +00:00
WHERE m . ID IN ( " . implode(',', $Users ) . ')');
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-09-13 08:00:53 +00:00
if ( ! $NoDaily && $Day != $NextDay || $_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-07-10 00:08:53 +00:00
WHERE Date < DATE ( '".sqltime()."' - INTERVAL 7 DAY ) + 0 " );
2013-06-17 08:01:02 +00:00
// 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 )
2013-07-10 00:08:53 +00:00
SELECT UserID , 0 , UTC_DATE () + 0 , 259200 - SumTime
2011-03-28 14:21:28 +00:00
FROM users_torrent_history_temp
2013-07-10 00:08:53 +00:00
WHERE SumTime < 259200 " );
2013-06-17 08:01:02 +00:00
// Set <Weight> to the time seeding <NumTorrents> torrents
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_torrent_history
2013-07-10 00:08:53 +00:00
SET Weight = NumTorrents * Time " );
2013-06-17 08:01:02 +00:00
// 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 )
2013-07-10 00:08:53 +00:00
SELECT UserID , SUM ( Weight ) / SUM ( Time )
2013-05-31 08:00:59 +00:00
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
2013-07-10 00:08:53 +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-12-10 08:00:51 +00:00
$DB -> query ( " TRUNCATE TABLE users_torrent_history_snatch " );
2013-05-31 08:00:59 +00:00
$DB -> query ( "
2013-07-10 00:08:53 +00:00
INSERT INTO users_torrent_history_snatch ( UserID , NumSnatches )
SELECT xs . uid , COUNT ( DISTINCT xs . fid )
2013-05-31 08:00:59 +00:00
FROM xbt_snatched AS xs
2013-11-17 08:00:47 +00:00
JOIN torrents AS t ON t . 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
2013-07-10 00:08:53 +00:00
// 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
2013-07-10 00:08:53 +00:00
JOIN users_torrent_history_temp AS t ON t . UserID = um . ID
JOIN users_torrent_history_snatch AS s ON s . UserID = um . ID
2013-05-31 08:00:59 +00:00
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
2013-07-10 00:08:53 +00:00
SET RequiredRatio = $Ratio
2013-05-31 08:00:59 +00:00
WHERE Downloaded >= '$Download'
AND Downloaded < '$DownloadBarrier'
2013-07-10 00:08:53 +00:00
AND can_leech = '0'
AND Enabled = '1' " );
2013-05-31 08:00:59 +00:00
*/
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
2013-07-10 00:08:53 +00:00
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
2014-01-10 08:01:11 +00:00
$UserQuery = $DB -> query ( "
2013-04-17 08:00:58 +00:00
SELECT
m . ID ,
torrent_pass
FROM users_info AS i
2013-07-10 00:08:53 +00:00
JOIN users_main AS m ON m . ID = i . UserID
2013-04-17 08:00:58 +00:00
WHERE m . Uploaded / m . Downloaded >= m . RequiredRatio
2013-07-10 00:08:53 +00:00
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
2013-07-10 00:08:53 +00:00
SET ui . RatioWatchEnds = '0000-00-00 00:00:00' ,
ui . RatioWatchDownload = '0' ,
um . can_leech = '1' ,
2013-05-31 08:00:59 +00:00
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 ) {
2013-07-10 00:08:53 +00:00
$Cache -> begin_transaction ( " user_info_heavy_ $UserID " );
$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 );
2014-02-27 08:00:30 +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= " . 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 ( "
2013-07-10 00:08:53 +00:00
SELECT m . ID , torrent_pass
2013-04-17 08:00:58 +00:00
FROM users_info AS i
2013-07-10 00:08:53 +00:00
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' " );
2013-04-17 08:00:58 +00:00
$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
2013-07-10 00:08:53 +00:00
SET ui . RatioWatchEnds = '0000-00-00 00:00:00' ,
ui . RatioWatchDownload = '0' ,
um . can_leech = '1'
2013-05-31 08:00:59 +00:00
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 ) {
2013-07-10 00:08:53 +00:00
$Cache -> begin_transaction ( " user_info_heavy_ $UserID " );
$Cache -> update_row ( false , array ( 'RatioWatchEnds' => '0000-00-00 00:00:00' , 'RatioWatchDownload' => '0' , 'CanLeech' => 1 ));
2013-04-17 08:00:58 +00:00
$Cache -> commit_transaction ( 0 );
2014-02-27 08:00:30 +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= " . site_url () . " rules.php?p=ratio]here[/url]. \n " );
2013-04-17 08:00:58 +00:00
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 );
2014-04-03 08:00:54 +00:00
$DB -> query ( "
2013-07-10 00:08:53 +00:00
SELECT m . ID , m . Downloaded
2013-05-16 08:00:10 +00:00
FROM users_info AS i
2013-07-10 00:08:53 +00:00
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
2013-07-10 00:08:53 +00:00
JOIN users_main AS m ON m . ID = i . UserID
SET i . RatioWatchEnds = '".time_plus(60 * 60 * 24 * 14)."' ,
i . RatioWatchTimes = i . RatioWatchTimes + 1 ,
2013-05-16 08:00:10 +00:00
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 ) {
2013-07-10 00:08:53 +00:00
$Cache -> begin_transaction ( " user_info_heavy_ $UserID " );
$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 );
2014-02-27 08:00:30 +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= " . 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 " ;
2014-04-03 08:00:54 +00:00
}
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-05-16 08:00:10 +00:00
$UserQuery = $DB -> query ( "
SELECT ID , torrent_pass
FROM users_info AS i
2013-07-10 00:08:53 +00:00
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
2013-07-10 00:08:53 +00:00
JOIN users_main AS m ON m . ID = i . UserID
SET m . can_leech = '0' ,
2013-07-31 08:00:50 +00:00
i . AdminComment = CONCAT ( '$sqltime - Leeching ability disabled by ratio watch system - required ratio: ' , m . RequiredRatio , '\n\n' , 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
2014-01-19 08:00:55 +00:00
2013-07-10 00:08:53 +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 ) {
2013-07-10 00:08:53 +00:00
$Cache -> begin_transaction ( " user_info_heavy_ $UserID " );
$Cache -> update_row ( false , array ( 'RatioWatchDownload' => 0 , 'CanLeech' => 0 ));
2011-03-28 14:21:28 +00:00
$Cache -> commit_transaction ( 0 );
2014-04-09 08:00:45 +00:00
Misc :: send_pm ( $UserID , 0 , 'Your downloading privileges have been disabled' , " As you did not raise your ratio in time, your downloading privileges 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
2013-07-10 00:08:53 +00:00
JOIN users_main AS um ON um . ID = ui . UserID
2013-05-31 08:00:59 +00:00
LEFT JOIN users_levels AS ul ON ul . UserID = um . ID AND ul . PermissionID = '".CELEB."'
WHERE um . PermissionID IN ( '".USER."' , '".MEMBER ."' )
2013-07-10 00:08:53 +00:00
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'
2013-05-31 08:00:59 +00:00
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-11-19 08:00:48 +00:00
$Body = " Hi $Username , \n \n It has been almost 4 months since you used your account at " . 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
}
2014-05-19 08:00:28 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( "
SELECT um . ID
FROM users_info AS ui
2013-07-10 00:08:53 +00:00
JOIN users_main AS um ON um . ID = ui . UserID
2013-05-31 08:00:59 +00:00
LEFT JOIN users_levels AS ul ON ul . UserID = um . ID AND ul . PermissionID = '".CELEB."'
WHERE um . PermissionID IN ( '".USER."' , '".MEMBER ."' )
2013-07-10 00:08:53 +00:00
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'
2013-05-31 08:00:59 +00:00
AND ul . UserID IS NULL
GROUP BY um . ID " );
2013-07-10 00:08:53 +00:00
if ( $DB -> has_results ()) {
2013-04-17 08:00:58 +00:00
Tools :: disable_users ( $DB -> collect ( 'ID' ), 'Disabled for inactivity.' , 3 );
2011-03-28 14:21:28 +00:00
}
//------------- Disable unconfirmed users ------------------------------//
sleep ( 10 );
2013-12-23 08:00:59 +00:00
// get a list of user IDs for clearing cache keys
$DB -> query ( "
SELECT UserID
FROM users_info AS ui
JOIN users_main AS um ON um . ID = ui . UserID
WHERE um . LastAccess = '0000-00-00 00:00:00'
AND ui . JoinDate < '".time_minus(60 * 60 * 24 * 7)."'
AND um . Enabled != '2' " );
$UserIDs = $DB -> collect ( 'UserID' );
// disable the users
2013-05-31 08:00:59 +00:00
$DB -> query ( "
UPDATE users_info AS ui
2013-07-10 00:08:53 +00:00
JOIN users_main AS um ON um . ID = ui . UserID
SET um . Enabled = '2' ,
ui . BanDate = '$sqltime' ,
ui . BanReason = '3' ,
2013-09-15 08:00:53 +00:00
ui . AdminComment = CONCAT ( '$sqltime - Disabled for inactivity (never logged in)\n\n' , ui . AdminComment )
2013-07-10 00:08:53 +00:00
WHERE um . LastAccess = '0000-00-00 00:00:00'
AND ui . JoinDate < '".time_minus(60 * 60 * 24 * 7)."'
2013-12-23 08:00:59 +00:00
AND um . Enabled != '2' " );
2013-07-10 00:08:53 +00:00
$Cache -> decrement ( 'stats_user_count' , $DB -> affected_rows ());
2013-02-22 08:00:24 +00:00
2013-12-23 08:00:59 +00:00
// clear the appropriate cache keys
foreach ( $UserIDs as $UserID ) {
$Cache -> delete_value ( " user_info_ $UserID " );
}
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 );
2014-05-19 08:00:28 +00:00
$Query = $DB -> query ( '
2013-11-17 08:00:47 +00:00
SELECT ID
FROM users_main
2013-05-31 08:00:59 +00:00
WHERE PermissionID IN ( '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
2013-07-10 00:08:53 +00:00
AND Uploaded / Downloaded < 0.95
2013-05-31 08:00:59 +00:00
OR PermissionID IN ( '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
2013-07-10 00:08:53 +00:00
AND Uploaded < 25 * 1024 * 1024 * 1024 ' );
2011-03-28 14:21:28 +00:00
echo " demoted 1 \n " ;
2013-02-22 08:00:24 +00:00
2013-05-31 08:00:59 +00:00
$DB -> query ( '
UPDATE users_main
2013-07-10 00:08:53 +00:00
SET PermissionID = '.MEMBER.'
2013-05-31 08:00:59 +00:00
WHERE PermissionID IN ( '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
2013-07-10 00:08:53 +00:00
AND Uploaded / Downloaded < 0.95
2013-05-31 08:00:59 +00:00
OR PermissionID IN ( '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
2013-07-10 00:08:53 +00:00
AND Uploaded < 25 * 1024 * 1024 * 1024 ' );
2014-05-19 08:00:28 +00:00
$DB -> set_query_id ( $Query );
while ( list ( $UserID ) = $DB -> next_record ()) {
/* $Cache -> begin_transaction ( " user_info_ $UserID " );
$Cache -> update_row ( false , array ( 'PermissionID' => MEMBER ));
$Cache -> commit_transaction ( 2592000 ); */
$Cache -> delete_value ( " user_info_ $UserID " );
$Cache -> delete_value ( " user_info_heavy_ $UserID " );
Misc :: send_pm ( $UserID , 0 , 'You have been demoted to ' . Users :: make_class_string ( MEMBER ), " You now only meet the requirements for the \" " . Users :: make_class_string ( MEMBER ) . " \" user class. \n \n To read more about " . SITE_NAME . " 's user classes, read [url= " . site_url () . " wiki.php?action=article&name=userclasses]this wiki article[/url]. " );
}
2011-03-28 14:21:28 +00:00
echo " demoted 2 \n " ;
2013-02-22 08:00:24 +00:00
2014-05-19 08:00:28 +00:00
$Query = $DB -> query ( '
2013-11-17 08:00:47 +00:00
SELECT ID
FROM users_main
2013-05-31 08:00:59 +00:00
WHERE PermissionID IN ( '.MEMBER.' , '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
2013-07-10 00:08:53 +00:00
AND Uploaded / Downloaded < 0.65 ' );
2011-03-28 14:21:28 +00:00
echo " demoted 3 \n " ;
2013-05-31 08:00:59 +00:00
$DB -> query ( '
UPDATE users_main
2013-07-10 00:08:53 +00:00
SET PermissionID = '.USER.'
2013-05-31 08:00:59 +00:00
WHERE PermissionID IN ( '.MEMBER.' , '.POWER.' , '.ELITE.' , '.TORRENT_MASTER.' )
2013-07-10 00:08:53 +00:00
AND Uploaded / Downloaded < 0.65 ' );
2014-05-19 08:00:28 +00:00
$DB -> set_query_id ( $Query );
while ( list ( $UserID ) = $DB -> next_record ()) {
/* $Cache -> begin_transaction ( " user_info_ $UserID " );
$Cache -> update_row ( false , array ( 'PermissionID' => USER ));
$Cache -> commit_transaction ( 2592000 ); */
$Cache -> delete_value ( " user_info_ $UserID " );
$Cache -> delete_value ( " user_info_heavy_ $UserID " );
Misc :: send_pm ( $UserID , 0 , 'You have been demoted to ' . Users :: make_class_string ( USER ), " You now only meet the requirements for the \" " . Users :: make_class_string ( USER ) . " \" user class. \n \n To read more about " . SITE_NAME . " 's user classes, read [url= " . site_url () . " wiki.php?action=article&name=userclasses]this wiki article[/url]. " );
}
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
2013-07-10 00:08:53 +00:00
WHERE t . IsLocked = '0'
AND t . IsSticky = '0'
AND DATEDIFF ( CURDATE (), DATE ( t . LastPostTime )) / 7 > f . AutoLockWeeks
2013-05-31 08:00:59 +00:00
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 );
2013-07-10 00:08:53 +00:00
$DB -> query ( "
UPDATE forums_topics
2013-11-19 08:00:48 +00:00
SET IsLocked = '1'
WHERE ID IN ( $LockIDs ) " );
2011-03-28 14:21:28 +00:00
sleep ( 2 );
2013-07-10 00:08:53 +00:00
$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 ) {
2013-07-10 00:08:53 +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-07-10 00:08:53 +00:00
$Cache -> expire_value ( " thread_ $ID " . '_catalogue_0' , 3600 * 24 * 30 );
$Cache -> expire_value ( " thread_ $ID " . '_info' , 3600 * 24 * 30 );
2013-10-14 08:00:53 +00:00
Forums :: add_topic_note ( $ID , 'Locked automatically by schedule' , 0 );
2013-05-08 08:00:26 +00:00
}
$ForumIDs = array_flip ( array_flip ( $ForumIDs ));
foreach ( $ForumIDs as $ForumID ) {
2013-07-10 00:08:53 +00:00
$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 );
2014-02-11 08:00:44 +00:00
$DB -> query ( "
2013-05-31 08:00:59 +00:00
SELECT
t . ID ,
t . GroupID ,
tg . Name ,
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
2013-11-06 08:00:50 +00:00
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 ) " );
2014-03-20 08:00:47 +00:00
$Torrents = $DB -> to_array ( false , MYSQLI_NUM , false );
2013-11-06 08:00:50 +00:00
echo 'Found ' . count ( $Torrents ) . " inactive torrents to be deleted. \n " ;
2013-02-22 08:00:24 +00:00
2013-11-06 08:00:50 +00:00
$LogEntries = $DeleteNotes = 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
);
2014-03-20 08:00:47 +00:00
$i = 0 ;
2013-11-06 08:00:50 +00:00
foreach ( $Torrents as $Torrent ) {
list ( $ID , $GroupID , $Name , $Format , $Encoding , $UserID , $Media , $InfoHash ) = $Torrent ;
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-11-06 08:00:50 +00:00
$ArtistName = Artists :: display_artists ( Artists :: get_artist ( $GroupID ), false , false , false );
2013-04-17 08:00:58 +00:00
if ( $ArtistName ) {
2013-07-10 00:08:53 +00:00
$Name = " $ArtistName - $Name " ;
2011-03-28 14:21:28 +00:00
}
2013-04-17 08:00:58 +00:00
if ( $Format && $Encoding ) {
2013-07-10 00:08:53 +00:00
$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-11-09 08:00:57 +00:00
$LogEntries [] = db_string ( " Torrent $ID ( $Name ) ( " . strtoupper ( $InfoHash ) . " ) was deleted for inactivity (unseeded) " );
2013-02-22 08:00:24 +00:00
2013-07-10 00:08:53 +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-07-10 00:08:53 +00:00
$Values = " (' " . implode ( " ', ' $sqltime '), (' " , $LogEntries ) . " ', ' $sqltime ') " ;
$DB -> query ( "
INSERT INTO log ( Message , Time )
VALUES $Values " );
2011-03-28 14:21:28 +00:00
echo " \n Deleted $i torrents for inactivity \n " ;
2014-02-11 08:00:44 +00:00
}
2011-03-28 14:21:28 +00:00
2013-07-10 00:08:53 +00:00
$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 ) {
2013-07-10 00:08:53 +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 ) " );
2011-03-28 14:21:28 +00:00
}
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
2013-07-10 00:08:53 +00:00
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
2013-07-10 00:08:53 +00:00
LIMIT 10 ; " );
2011-03-28 14:21:28 +00:00
$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
2013-07-10 00:08:53 +00:00
$DisplayName .= $GroupName ;
2011-03-28 14:21:28 +00:00
2013-04-17 08:00:58 +00:00
if ( $GroupCategoryID == 1 && $GroupYear > 0 ) {
2013-07-10 00:08:53 +00:00
$DisplayName .= " [ $GroupYear ] " ;
2011-03-28 14:21:28 +00:00
}
// append extra info to torrent title
2013-05-31 08:00:59 +00:00
$ExtraInfo = '' ;
$AddExtra = '' ;
2013-07-10 00:08:53 +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-07-10 00:08:53 +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 ;
}
2013-04-17 08:00:58 +00:00
if ( $ExtraInfo != '' ) {
2011-03-28 14:21:28 +00:00
$ExtraInfo = " - [ $ExtraInfo ] " ;
}
2013-07-10 00:08:53 +00:00
$TitleString = " $DisplayName $ExtraInfo " ;
2011-03-28 14:21:28 +00:00
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
2013-07-10 00:08:53 +00:00
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
2013-07-10 00:08:53 +00:00
LIMIT 10 ; " );
2011-03-28 14:21:28 +00:00
$Top10 = $DB -> to_array ();
}
$i = 1 ;
2013-08-28 23:08:41 +00:00
foreach ( $Top10 as $Torrent ) {
2013-04-17 08:00:58 +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
2013-07-10 00:08:53 +00:00
$DisplayName .= $GroupName ;
2011-03-28 14:21:28 +00:00
2013-04-17 08:00:58 +00:00
if ( $GroupCategoryID == 1 && $GroupYear > 0 ) {
2013-08-28 23:08:41 +00:00
$DisplayName .= " [ $GroupYear ] " ;
2011-03-28 14:21:28 +00:00
}
// append extra info to torrent title
2013-04-17 08:00:58 +00:00
$ExtraInfo = '' ;
$AddExtra = '' ;
if ( $Format ) {
2013-07-10 00:08:53 +00:00
$ExtraInfo .= $Format ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $Encoding ) {
2013-07-10 00:08:53 +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-07-10 00:08:53 +00:00
$ExtraInfo .= " { $AddExtra } Log ( $LogScore %) " ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $HasCue ) {
2013-07-10 00:08:53 +00:00
$ExtraInfo .= " { $AddExtra } Cue " ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $Media ) {
2013-07-10 00:08:53 +00:00
$ExtraInfo .= $AddExtra . $Media ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $Scene ) {
2013-07-10 00:08:53 +00:00
$ExtraInfo .= " { $AddExtra } Scene " ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' / ' ;
}
if ( $Year > 0 ) {
2013-07-10 00:08:53 +00:00
$ExtraInfo .= $AddExtra . $Year ;
2013-04-17 08:00:58 +00:00
$AddExtra = ' ' ;
}
if ( $RemasterTitle ) {
2013-07-10 00:08:53 +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 ] " ;
}
2013-07-10 00:08:53 +00:00
$TitleString = " $DisplayName $ExtraInfo " ;
2011-03-28 14:21:28 +00:00
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-07-27 08:00:49 +00:00
( $HistoryID , $i , $TorrentID , '" . db_string($TitleString) . "' , '" . db_string($TagString) . "' ) " );
2011-03-28 14:21:28 +00:00
$i ++ ;
2013-08-28 23:08:41 +00:00
} //foreach ($Top10 as $Torrent)
2014-05-15 08:00:27 +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
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 ) {
2013-07-10 00:08:53 +00:00
$Name = " $ArtistName - $Name " ;
2011-10-27 08:00:15 +00:00
}
2013-04-17 08:00:58 +00:00
if ( $Format && $Encoding ) {
2013-07-10 00:08:53 +00:00
$Name .= " [ $Format / $Encoding ] " ;
2011-10-27 08:00:15 +00:00
}
2014-02-27 08:00:30 +00:00
$TorrentAlerts [ $UserID ][ 'Msg' ] .= " \n [url= " . 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 ) {
2014-02-27 08:00:30 +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= " . 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
2013-08-28 23:08:41 +00:00
Donations :: schedule ();
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-09-13 08:00:53 +00:00
if ( $BiWeek != $NextBiWeek || $_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-07-10 00:08:53 +00:00
Power Users have a cap of 2 invites . Elites have a cap of 4.
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 :
2013-07-10 00:08:53 +00:00
Every Power User or Elite whose total invitee ratio is above 0.75 and total invitee upload is over 2 GBs gets one invite .
Every Elite whose total invitee ratio is above 2.0 and total invitee upload is over 10 GBs gets one more invite .
Every Elite whose total invitee ratio is above 3.0 and total invitee upload is over 20 GBs 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
2013-11-17 08:00:47 +00:00
JOIN users_info AS ui ON ui . UserID = um . ID
2013-07-10 00:08:53 +00:00
WHERE um . Enabled = '1'
2013-05-31 08:00:59 +00:00
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 ) {
2013-07-10 00:08:53 +00:00
$Cache -> begin_transaction ( " user_info_heavy_ $UserID " );
2011-03-28 14:21:28 +00:00
$Cache -> update_row ( false , array ( 'Invites' => '+1' ));
$Cache -> commit_transaction ( 0 );
}
2013-05-31 08:00:59 +00:00
$DB -> query ( '
UPDATE users_main
2013-07-10 00:08:53 +00:00
SET Invites = Invites + 1
2013-05-31 08:00:59 +00:00
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
2013-07-10 00:08:53 +00:00
SELECT SUM ( Uploaded ) AS Upload , SUM ( Downloaded ) AS Download , Inviter
2013-05-31 08:00:59 +00:00
FROM users_main AS um
2013-07-10 00:08:53 +00:00
JOIN users_info AS ui ON ui . UserID = um . ID
2013-05-31 08:00:59 +00:00
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
2013-07-10 00:08:53 +00:00
JOIN users_info AS ui ON ui . UserID = um . ID
2013-05-31 08:00:59 +00:00
JOIN temp_sections_schedule_index AS u ON u . Inviter = um . ID
2013-07-10 00:08:53 +00:00
WHERE u . Upload > $Upload
AND u . Upload / u . Download > $Ratio
2013-05-31 08:00:59 +00:00
AND um . Enabled = '1'
AND ui . DisableInvites = '0'
2013-07-10 00:08:53 +00:00
AND (( um . PermissionID = " .POWER.'
2013-05-31 08:00:59 +00:00
AND um . Invites < 2
2013-07-10 00:08:53 +00:00
) OR ( um . PermissionID = '.ELITE.'
2013-05-31 08:00:59 +00:00
AND um . Invites < 4 )
2013-07-10 00:08:53 +00:00
) ' );
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 ) {
2013-07-10 00:08:53 +00:00
$Cache -> begin_transaction ( " user_info_heavy_ $UserID " );
2011-03-28 14:21:28 +00:00
$Cache -> update_row ( false , array ( 'Invites' => '+1' ));
$Cache -> commit_transaction ( 0 );
}
2013-05-31 08:00:59 +00:00
$DB -> query ( '
UPDATE users_main
2013-07-10 00:08:53 +00:00
SET Invites = Invites + 1
2013-05-31 08:00:59 +00:00
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 ; " );
2013-07-10 00:08:53 +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
}
?>