From d052d1df505d8a7389001a890cd4b54825c55b50 Mon Sep 17 00:00:00 2001 From: Git Date: Sat, 29 Oct 2011 08:00:15 +0000 Subject: [PATCH] Empty commit --- classes/class_debug.php | 160 ++++++++++++++++--------- classes/script_start.php | 74 ++++++++++-- design/privatefooter.php | 1 + gazelle.sql | 5 +- sections/artist/artist.php | 12 +- sections/bookmarks/torrents.php | 17 +-- sections/collages/collage.php | 19 +-- sections/schedule/index.php | 6 +- sections/tools/managers/tokens.php | 110 +---------------- sections/tools/misc/analysis.php | 4 +- sections/torrents/browse2.php | 24 ++-- sections/torrents/details.php | 7 +- sections/torrents/download.php | 30 +++-- sections/torrents/notify.php | 22 +++- sections/upload/upload.php | 2 +- sections/user/edit.php | 2 +- sections/user/user.php | 4 +- sections/userhistory/token_history.php | 8 +- static/styles/mono/style.css | 8 +- 19 files changed, 282 insertions(+), 233 deletions(-) diff --git a/classes/class_debug.php b/classes/class_debug.php index 466f0b71..98d8a513 100644 --- a/classes/class_debug.php +++ b/classes/class_debug.php @@ -9,27 +9,28 @@ class DEBUG { public $Errors = array(); public $Flags = array(); - + private $LoggedVars = array(); + public function profile($Automatic='') { global $ScriptStartTime; $Reason = array(); - + if (!empty($Automatic)) { $Reason[] = $Automatic; } - + $Micro = (microtime(true)-$ScriptStartTime)*1000; - if ($Micro > MAX_TIME && !defined('TIME_EXCEPTION')) { + if ($Micro > MAX_TIME && !defined('TIME_EXCEPTION')) { $Reason[] = number_format($Micro, 3).' ms'; } - + $Errors = count($this->get_errors()); - if ($Errors > MAX_ERRORS && !defined('ERROR_EXCEPTION')) { + if ($Errors > MAX_ERRORS && !defined('ERROR_EXCEPTION')) { $Reason[] = $Errors.' PHP Errors'; } /* $Queries = count($this->get_queries()); - if ($Queries > MAX_QUERIES && !defined('QUERY_EXCEPTION')) { + if ($Queries > MAX_QUERIES && !defined('QUERY_EXCEPTION')) { $Reason[] = $Queries.' Queries'; } */ @@ -37,20 +38,20 @@ public function profile($Automatic='') { if ($Ram > MAX_MEMORY && !defined('MEMORY_EXCEPTION')) { $Reason[] = get_size($Ram).' Ram Used'; } - + if (isset($_REQUEST['profile'])) { global $LoggedUser; $Reason[] = 'Requested by '.$LoggedUser['Username']; } - + if (isset($Reason[0])) { $this->analysis(implode(', ', $Reason)); return true; } - + return false; } - + public function analysis($Message, $Report='', $Time=43200) { global $Cache, $Document; if (empty($Report)) { @@ -58,7 +59,7 @@ public function analysis($Message, $Report='', $Time=43200) { } $Identifier = make_secret(5); $Cache->cache_value( - 'analysis_'.$Identifier, + 'analysis_'.$Identifier, array( 'url' => $_SERVER['REQUEST_URI'], 'message' => $Report, @@ -66,25 +67,36 @@ public function analysis($Message, $Report='', $Time=43200) { 'queries' => $this->get_queries(), 'flags' => $this->get_flags(), 'includes' => $this->get_includes(), - 'cache' => $this->get_cache_keys() + 'cache' => $this->get_cache_keys(), + 'vars' => $this->get_logged_vars() ), $Time ); send_irc('PRIVMSG '.LAB_CHAN.' :'.$Message.' '.$Document.' '.' http://'.NONSSL_SITE_URL.'/tools.php?action=analysis&case='.$Identifier.' http://'.NONSSL_SITE_URL.$_SERVER['REQUEST_URI']); } - + + public function log_var($Var, $VarName = FALSE) { + $BackTrace = debug_backtrace(); + $ID = uniqid(); + if(!$VarName) { + $VarName = $ID; + } + $File = array('path' => substr($BackTrace[0]['file'], strlen(SERVER_ROOT)), 'line' => $BackTrace[0]['line']); + $this->LoggedVars[$ID] = array($VarName => array('bt' => $File, 'data' => $Var)); + } + public function set_flag($Event) { global $ScriptStartTime; $this->Flags[] = array($Event,(microtime(true)-$ScriptStartTime)*1000,memory_get_usage(true)); } - + //This isn't in the constructor because $this is not available, and the function cannot be made static public function handle_errors() { //error_reporting(E_ALL ^ E_STRICT | E_WARNING | E_DEPRECATED | E_ERROR | E_PARSE); //E_STRICT disabled error_reporting(E_WARNING | E_ERROR | E_PARSE); set_error_handler(array($this, 'php_error_handler')); } - + protected function format_args($Array) { $LastKey = -1; $Return = array(); @@ -110,30 +122,30 @@ protected function format_args($Array) { } return implode(', ', $Return); } - + public function php_error_handler($Level, $Error, $File, $Line) { //Who added this, it's still something to pay attention to... if (stripos('Undefined index', $Error) !== false) { //return true; } - + $Steps = 1; //Steps to go up in backtrace, default one $Call = ''; $Args = ''; $Tracer = debug_backtrace(); - + //This is in case something in this function goes wrong and we get stuck with an infinite loop if (isset($Tracer[$Steps]['function'], $Tracer[$Steps]['class']) && $Tracer[$Steps]['function'] == 'php_error_handler' && $Tracer[$Steps]['class'] == 'DEBUG') { return true; } - + //If this error was thrown, we return the function which threw it if (isset($Tracer[$Steps]['function']) && $Tracer[$Steps]['function'] == 'trigger_error') { $Steps++; $File = $Tracer[$Steps]['file']; $Line = $Tracer[$Steps]['line']; } - + //At this time ONLY Array strict typing is fully supported. //Allow us to abuse strict typing (IE: function test(Array)) if (preg_match('/^Argument (\d+) passed to \S+ must be an (array), (array|string|integer|double|object) given, called in (\S+) on line (\d+) and defined$/', $Error, $Matches)) { @@ -141,17 +153,17 @@ public function php_error_handler($Level, $Error, $File, $Line) { $File = $Matches[4]; $Line = $Matches[5]; } - + //Lets not be repetative if (($Tracer[$Steps]['function'] == 'include' || $Tracer[$Steps]['function'] == 'require' ) && isset($Tracer[$Steps]['args'][0]) && $Tracer[$Steps]['args'][0] == $File) { unset($Tracer[$Steps]['args']); } - + //Class if (isset($Tracer[$Steps]['class'])) { $Call .= $Tracer[$Steps]['class'].'::'; } - + //Function & args if (isset($Tracer[$Steps]['function'])) { $Call .= $Tracer[$Steps]['function']; @@ -159,7 +171,7 @@ public function php_error_handler($Level, $Error, $File, $Line) { $Args = $this->format_args($Tracer[$Steps]['args']); } } - + //Shorten the path & we're done $File = str_replace(SERVER_ROOT, '', $File); $Error = str_replace(SERVER_ROOT, '', $Error); @@ -172,13 +184,13 @@ public function php_error_handler($Level, $Error, $File, $Line) { */ return true; } - + /* Data wrappers */ - + public function get_flags() { return $this->Flags; } - + public function get_errors($Light=false) { //Because the cache can't take some of these variables if ($Light) { @@ -192,7 +204,7 @@ public function get_errors($Light=false) { public function get_constants() { return get_defined_constants(true); } - + public function get_classes() { foreach (get_declared_classes() as $Class) { $Classes[$Class]['Vars'] = get_class_vars($Class); @@ -200,18 +212,18 @@ public function get_classes() { } return $Classes; } - + public function get_extensions() { foreach (get_loaded_extensions() as $Extension) { $Extensions[$Extension]['Functions'] = get_extension_funcs($Extension); } return $Extensions; } - + public function get_includes() { return get_included_files(); } - + public function get_cache_time() { global $Cache; return $Cache->Time; @@ -221,27 +233,31 @@ public function get_cache_keys() { global $Cache; return array_keys($Cache->CacheHits); } - + public function get_sphinx_queries() { global $SS; return $SS->Queries; } - + public function get_sphinx_time() { global $SS; return $SS->Time; } - + public function get_queries() { global $DB; return $DB->Queries; } - + public function get_query_time() { global $DB; return $DB->Time; } + public function get_logged_vars() { + return $this->LoggedVars; + } + /* Output Formatting */ public function include_table($Includes=false) { @@ -254,7 +270,7 @@ public function include_table($Includes=false) { (View) Includes: - + @@ -265,7 +281,7 @@ public function include_table($Includes=false) { } ?> -(View) Classes: - + - + - + (View) Constants: - + - @@ -373,13 +389,13 @@ public function cache_table($CacheKeys=false) { - + - @@ -401,21 +417,21 @@ public function error_table($Errors=false) { - + - + -(View) - + - + -(View) - + - + -LoggedVars)) { + return; + } + $Vars = $this->LoggedVars; + } + $Header = ' '.number_format(count($Vars)).' '.$Header.':'; + +?> + + + + +
(View)
+ + $Var) { + list($Key, $Data) = each($Var); + $Size = count($Data['data']); +?> + + + + + + +query("SELECT SiteOptions FROM users_info WHERE UserID = $UserID"); + list($SiteOptions) = $DB->next_record(MYSQLI_NUM,false); + $SiteOptions = unserialize($SiteOptions); + + // Get HeavyInfo + $HeavyInfo = user_heavy_info($UserID); + + // Insert new/replace old options + $SiteOptions = array_merge($SiteOptions, $NewOptions); + $HeavyInfo = array_merge($HeavyInfo, $NewOptions); + + // Update DB + $DB->query("UPDATE users_info SET SiteOptions = '".db_string(serialize($SiteOptions))."' WHERE UserID = $UserID"); + + // Update cache + $Cache->cache_value('user_info_heavy_'.$UserID, $HeavyInfo, 0); + + // Update $LoggedUser if the options are changed for the current + if($LoggedUser['ID'] == $UserID) { + $LoggedUser = array_merge($LoggedUser, $NewOptions); + $LoggedUser['ID'] = $UserID; // We don't want to allow userid switching + } +} + function get_permissions($PermissionID) { global $DB, $Cache; $Permission = $Cache->get_value('perm_'.$PermissionID); @@ -1519,6 +1566,9 @@ function get_artists($GroupIDs, $Escape = array()) { $Results = array(); $DBs = array(); foreach($GroupIDs as $GroupID) { + if(!is_number($GroupID)) { + continue; + } $Artists = $Cache->get_value('groups_artists_'.$GroupID, true); if(is_array($Artists)) { $Results[$GroupID] = $Artists; @@ -1808,6 +1858,7 @@ function torrent_info($Data) { if(!empty($Data['Scene'])) { $Info[]='Scene'; } if($Data['FreeTorrent'] == '1') { $Info[]='Freeleech!'; } if($Data['FreeTorrent'] == '2') { $Info[]='Neutral Leech!'; } + if($Data['PersonalFL'] == 1) { $Info[]='Personal Freeleech!'; } return implode(' / ', $Info); } @@ -1907,14 +1958,17 @@ function disable_users($UserIDs, $AdminComment, $BanReason = 1) { * @param $Action The action to send * @param $Updates An associative array of key->value pairs to send to the tracker */ -function update_tracker($Action, $Updates) { +function update_tracker($Action, $Updates, $ToIRC = false) { + global $Cache; //Build request $Get = '/update?action='.$Action; foreach($Updates as $Key => $Value) { $Get .= '&'.$Key.'='.$Value; } - send_irc('PRIVMSG #tracker :'.$Get); + if($ToIRC != false) { + send_irc('PRIVMSG #tracker :'.$Get); + } $Path = TRACKER_SECRET.$Get; $Return = ""; @@ -1956,7 +2010,10 @@ function update_tracker($Action, $Updates) { if($Return != "success") { send_irc("PRIVMSG #tracker :{$Attempts} {$Err} {$Get}"); - send_irc("PRIVMSG ".ADMIN_CHAN." :Failed to update ocelot: ".$Err." : ".$Get); + if($Cache->get_value('ocelot_error_reported') === false) { + send_irc("PRIVMSG ".ADMIN_CHAN." :Failed to update ocelot: ".$Err." : ".$Get); + $Cache->cache_value('ocelot_error_reported', true); + } } return ($Return == "success"); } @@ -2008,7 +2065,7 @@ function in_array_partial($Needle, $Haystack) { * @param int $FreeLeechType 0 = Unknown, 1 = Staff picks, 2 = Perma-FL (Toolbox, etc.), 3 = Vanity House */ function freeleech_torrents($TorrentIDs, $FreeNeutral = 1, $FreeLeechType = 0) { - global $DB; + global $DB, $Cache; if(!is_array($TorrentIDs)) { $TorrentIDs = array($TorrentIDs); @@ -2022,6 +2079,7 @@ function freeleech_torrents($TorrentIDs, $FreeNeutral = 1, $FreeLeechType = 0) { foreach($Torrents as $Torrent) { list($TorrentID, $GroupID, $InfoHash) = $Torrent; update_tracker('update_torrent', array('info_hash' => rawurlencode($InfoHash), 'freetorrent' => $FreeNeutral)); + $Cache->delete_value('torrent_download_'.$TorrentID); } foreach($GroupIDs as $GroupID) { diff --git a/design/privatefooter.php b/design/privatefooter.php index ff033365..1e466523 100644 --- a/design/privatefooter.php +++ b/design/privatefooter.php @@ -39,6 +39,7 @@ $Debug->sphinx_table(); $Debug->query_table(); $Debug->cache_table(); +$Debug->vars_table(); ?> diff --git a/gazelle.sql b/gazelle.sql index b6f71e1a..a8d68624 100644 --- a/gazelle.sql +++ b/gazelle.sql @@ -1441,13 +1441,12 @@ CREATE TABLE `xbt_files_users` ( `timespent` bigint(20) NOT NULL, `useragent` varchar(51) NOT NULL, `connectable` tinyint(4) NOT NULL DEFAULT '1', - `peer_id` binary(20) DEFAULT NULL, + `peer_id` binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', `fid` int(11) NOT NULL, `ipa` int(12) unsigned NOT NULL, `mtime` int(11) NOT NULL, `ip` varchar(15) NOT NULL DEFAULT '', - UNIQUE KEY `uid_2` (`uid`,`fid`,`ipa`), - KEY `uid` (`uid`), + PRIMARY KEY (`uid`,`fid`,`peer_id`), KEY `remaining_idx` (`remaining`), KEY `fid_idx` (`fid`), KEY `mtime_idx` (`mtime`) diff --git a/sections/artist/artist.php b/sections/artist/artist.php index cf975cb1..adeee81a 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -286,6 +286,11 @@ function compare($X, $Y){ $FirstUnknown = !isset($FirstUnknown); } + + if (in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent'])) { + $Torrent['PersonalFL'] = 1; + } + $Torrent['Seeders'] = (int)$Torrent['Seeders']; $Torrent['Leechers'] = (int)$Torrent['Leechers']; $Torrent['Snatched'] = (int)$Torrent['Snatched']; @@ -339,12 +344,11 @@ function compare($X, $Y){ - [ + [ 0) && ($Torrent['Size'] < 1073741824) && !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> - FL | - - ] + | FL + ]   »  diff --git a/sections/bookmarks/torrents.php b/sections/bookmarks/torrents.php index db94bfce..68bac2b5 100644 --- a/sections/bookmarks/torrents.php +++ b/sections/bookmarks/torrents.php @@ -149,6 +149,10 @@ function compare($X, $Y){ $FirstUnknown = !isset($FirstUnknown); } + if (in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent'])) { + $Torrent['PersonalFL'] = 1; + } + if($Torrent['RemasterTitle'] != $LastRemasterTitle || $Torrent['RemasterYear'] != $LastRemasterYear || $Torrent['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Torrent['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber || $FirstUnknown || $Torrent['Media'] != $LastMedia) { @@ -192,12 +196,12 @@ function compare($X, $Y){ ?> - [ + [ DL 0) && ($Torrent['Size'] < 1073741824) && !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> - FL | + | FL - DL] + | RP ]   »  @@ -229,13 +233,12 @@ function compare($X, $Y){ - [ + [ DL 0) && ($Torrent['Size'] < 1073741824) && !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> - FL | + | FL - DL - | RP] + | RP ] diff --git a/sections/collages/collage.php b/sections/collages/collage.php index de91e9d9..32bffd0a 100644 --- a/sections/collages/collage.php +++ b/sections/collages/collage.php @@ -186,6 +186,10 @@ function compare($X, $Y){ $FirstUnknown = !isset($FirstUnknown); } + if (in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent'])) { + $Torrent['PersonalFL'] = 1; + } + if($Torrent['RemasterTitle'] != $LastRemasterTitle || $Torrent['RemasterYear'] != $LastRemasterYear || $Torrent['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Torrent['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber || $FirstUnknown || $Torrent['Media'] != $LastMedia) { $EditionID++; @@ -228,12 +232,12 @@ function compare($X, $Y){ - [ + [ DL 0) && ($Torrent['Size'] < 1073741824) && !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> - FL | - - DL] + | FL + + | RP ]   »  @@ -265,12 +269,11 @@ function compare($X, $Y){ - [ + [ DL 0) && ($Torrent['Size'] < 1073741824) && !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> - FL | - - DL + | FL + | RP] diff --git a/sections/schedule/index.php b/sections/schedule/index.php index de16aca2..fd996f17 100644 --- a/sections/schedule/index.php +++ b/sections/schedule/index.php @@ -81,7 +81,7 @@ function next_hour() { //------------- Expire old FL Tokens and clear cache where needed ------// $sqltime = sqltime(); -$DB->query("SELECT DISTINCT UserID from users_freeleeches WHERE Expired = FALSE AND Time < '$sqltime' - INTERVAL 2 DAY"); +$DB->query("SELECT DISTINCT UserID from users_freeleeches WHERE Expired = FALSE AND Time < '$sqltime' - INTERVAL 4 DAY"); while (list($UserID) = $DB->next_record()) { $Cache->delete_value('users_tokens_'.$UserID[0]); } @@ -89,11 +89,11 @@ function next_hour() { $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 2 DAY"); + WHERE uf.Expired = FALSE AND uf.Time < '$sqltime' - INTERVAL 4 DAY"); while (list($UserID,$InfoHash) = $DB->next_record()) { update_tracker('remove_token', array('info_hash' => rawurlencode($InfoHash), 'userid' => $UserID)); } -$DB->query("UPDATE users_freeleeches SET Expired = True WHERE Time < '$sqltime' - INTERVAL 2 DAY"); +$DB->query("UPDATE users_freeleeches SET Expired = True WHERE Time < '$sqltime' - INTERVAL 4 DAY"); diff --git a/sections/tools/managers/tokens.php b/sections/tools/managers/tokens.php index 9a3d8acc..51a56747 100644 --- a/sections/tools/managers/tokens.php +++ b/sections/tools/managers/tokens.php @@ -43,23 +43,9 @@ } $where = ""; -} elseif (isset($_REQUEST['expire'])) { - $Tokens = $_REQUEST['tokens']; - foreach ($Tokens as $Token) { - list($UserID, $TorrentID) = explode(',', $Token); - - if (empty($UserID) || empty($TorrentID) || !is_number($UserID)) { continue; } - $DB->query("SELECT info_hash FROM torrents where ID = $TorrentID"); - - if (list($InfoHash) = $DB->next_record()) { - $DB->query("UPDATE users_freeleeches SET Expired=TRUE WHERE UserID=$UserID AND TorrentID=$TorrentID"); - $Cache->delete_value('users_tokens_'.$UserID); - update_tracker('remove_token', array('info_hash' => rawurlencode($InfoHash), 'userid' => $UserID)); - } - } } -if (empty($_GET['showabusers'])) { + show_header('Add tokens sitewide'); ?> @@ -89,100 +75,6 @@ = $Ratio "; - if (!$Expired) { - $SQL .= "AND fl.Expired = 0 "; - } - $SQL .= "ORDER BY fl.Downloaded/t.Size - LIMIT $Limit"; - $DB->query($SQL); - $Pages = get_pages($Page, $DB->record_count(), 50); - $Abuses = $DB->to_array(); -?> -

Freeleech token abusers

- - - -
- - - - - - - - - - - - - - - -$Name"; - } - if($Format && $Encoding) { - $Name.=' ['.$Format.' / '.$Encoding.']'; - } -?> - - - - - - - - - - - - - - - - - - - -
UserTorrentSizeTransferredRatioExpired
-
- -
-
- - - - -
-
- \ No newline at end of file diff --git a/sections/tools/misc/analysis.php b/sections/tools/misc/analysis.php index b2e39f9d..02167a9b 100644 --- a/sections/tools/misc/analysis.php +++ b/sections/tools/misc/analysis.php @@ -16,4 +16,6 @@ $Debug->class_table(); $Debug->extension_table(); $Debug->constant_table(); -show_footer(); ?> \ No newline at end of file +$Debug->vars_table($Analysis['vars']); +show_footer(); +?> diff --git a/sections/torrents/browse2.php b/sections/torrents/browse2.php index 09d7bb9b..6cdf9ea3 100644 --- a/sections/torrents/browse2.php +++ b/sections/torrents/browse2.php @@ -841,6 +841,10 @@ function header_link($SortKey,$DefaultWay="desc") { if ($Data['Remastered'] && !$Data['RemasterYear']) { $FirstUnknown = !isset($FirstUnknown); } + + if (in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent'])) { + $Data['PersonalFL'] = 1; + } if($CategoryID == 1 && ($Data['RemasterTitle'] != $LastRemasterTitle || $Data['RemasterYear'] != $LastRemasterYear || $Data['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Data['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber) || $FirstUnknown || $Data['Media'] != $LastMedia) { @@ -886,13 +890,12 @@ function header_link($SortKey,$DefaultWay="desc") { - [ - 0) && ($Data['Size'] < 1073741824) + [ + 0) && $Data['HasFile'] && ($Data['Size'] < 1073741824) && !in_array($TorrentID, $TokenTorrents) && empty($Data['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> - FL | - - - | RP] + | FL + + | RP ] » @@ -926,12 +929,11 @@ function header_link($SortKey,$DefaultWay="desc") { - [ - 0) && ($Data['Size'] < 1073741824) + [ DL + 0) && $Data['HasFile'] && ($Data['Size'] < 1073741824) && !in_array($TorrentID, $TokenTorrents) && empty($Data['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> - FL | - - DL + | FL + | RP] diff --git a/sections/torrents/details.php b/sections/torrents/details.php index a8690b9f..3d012bd3 100644 --- a/sections/torrents/details.php +++ b/sections/torrents/details.php @@ -426,12 +426,11 @@ function filelist($Str) { - [ + [ 0) && $HasFile && ($Size < 1073741824) && !in_array($TorrentID, $TokenTorrents) && ($FreeTorrent == '0') && ($LoggedUser['CanLeech'] == '1')) { ?> - FL | - - + | FL + | RP | ED diff --git a/sections/torrents/download.php b/sections/torrents/download.php index 57c2d309..c7115121 100644 --- a/sections/torrents/download.php +++ b/sections/torrents/download.php @@ -28,7 +28,7 @@ if (!is_number($TorrentID)){ error(0); } $Info = $Cache->get_value('torrent_download_'.$TorrentID); -if(!is_array($Info) || !array_key_exists('PlainArtists', $Info) || !array_key_exists('info_hash', $Info)) { +if(!is_array($Info) || !array_key_exists('PlainArtists', $Info) || empty($Info[10])) { $DB->query("SELECT t.Media, t.Format, @@ -97,16 +97,26 @@ error("An error has occured. Please try again."); } - $DB->query("INSERT INTO users_freeleeches (UserID, TorrentID, Time) VALUES ($UserID, $TorrentID, NOW()) - ON DUPLICATE KEY UPDATE Time=VALUES(Time), Expired=FALSE"); - $DB->query("UPDATE users_main SET FLTokens = FLTokens - 1 WHERE ID=$UserID"); + // We need to fetch and check this again here because of people + // double-clicking the FL link while waiting for a tracker response. + $TokenTorrents = $Cache->get_value('users_tokens_'.$UserID); + if (empty($TokenTorrents)) { + $DB->query("SELECT TorrentID FROM users_freeleeches WHERE UserID=$UserID AND Expired=FALSE"); + $TokenTorrents = $DB->collect('TorrentID'); + } - $Cache->begin_transaction('user_info_heavy_'.$UserID); - $Cache->update_row(false, array('FLTokens'=>($FLTokens - 1))); - $Cache->commit_transaction(0); - - $TokenTorrents[] = $TorrentID; - $Cache->cache_value('users_tokens_'.$UserID, $TokenTorrents); + if (!in_array($TorrentID, $TokenTorrents)) { + $DB->query("INSERT INTO users_freeleeches (UserID, TorrentID, Time) VALUES ($UserID, $TorrentID, NOW()) + ON DUPLICATE KEY UPDATE Time=VALUES(Time), Expired=FALSE"); + $DB->query("UPDATE users_main SET FLTokens = FLTokens - 1 WHERE ID=$UserID"); + + $Cache->begin_transaction('user_info_heavy_'.$UserID); + $Cache->update_row(false, array('FLTokens'=>($FLTokens - 1))); + $Cache->commit_transaction(0); + + $TokenTorrents[] = $TorrentID; + $Cache->cache_value('users_tokens_'.$UserID, $TokenTorrents); + } } } diff --git a/sections/torrents/notify.php b/sections/torrents/notify.php index 111c0b97..849e7160 100644 --- a/sections/torrents/notify.php +++ b/sections/torrents/notify.php @@ -4,6 +4,13 @@ define('NOTIFICATIONS_PER_PAGE', 50); list($Page,$Limit) = page_limit(NOTIFICATIONS_PER_PAGE); +$TokenTorrents = $Cache->get_value('users_tokens_'.$UserID); +if (empty($TokenTorrents)) { + $DB->query("SELECT TorrentID FROM users_freeleeches WHERE UserID=$UserID AND Expired=FALSE"); + $TokenTorrents = $DB->collect('TorrentID'); + $Cache->cache_value('users_tokens_'.$UserID, $TokenTorrents); +} + $Results = $DB->query("SELECT SQL_CALC_FOUND_ROWS t.ID, g.ID, @@ -27,6 +34,7 @@ t.HasLog, t.HasCue, t.LogScore, + t.FreeTorrent, tln.TorrentID AS LogInDB, unt.UnRead, unt.FilterID, @@ -98,7 +106,7 @@ foreach($FilterResults as $Result) { list($TorrentID, $GroupID, $GroupName, $GroupCategoryID, $TorrentTags, $Size, $FileCount, $Format, $Encoding, $Media, $Scene, $RemasterYear, $GroupYear, $RemasterYear, $RemasterTitle, $Snatched, $Seeders, - $Leechers, $NotificationTime, $HasLog, $HasCue, $LogScore, $LogInDB, $UnRead) = $Result; + $Leechers, $NotificationTime, $HasLog, $HasCue, $LogScore, $FreeTorrent, $LogInDB, $UnRead) = $Result; // generate torrent's title $DisplayName=''; @@ -108,6 +116,10 @@ $DisplayName = display_artists($Artists, true, true); } + if (in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent'])) { + $Data['PersonalFL'] = 1; + } + $DisplayName.= "".$GroupName.""; if($GroupCategoryID==1 && $GroupYear>0) { @@ -150,8 +162,12 @@
- [DL | - CL] + [DL + 0) && ($Size < 1073741824) + && !in_array($TorrentID, $TokenTorrents) && empty($FreeTorrent) && ($LoggedUser['CanLeech'] == '1')) { ?> + | FL + + | CL] New!'; } ?> diff --git a/sections/upload/upload.php b/sections/upload/upload.php index 1b12cc57..6c317622 100644 --- a/sections/upload/upload.php +++ b/sections/upload/upload.php @@ -83,7 +83,7 @@ ?>

Do not upload

-

The following releases are currently forbidden from being uploaded from the site. Do not upload them unless your torrent meets a condition specified in the comment. +

The following releases are currently forbidden from being uploaded to the site. Do not upload them unless your torrent meets a condition specified in the comment. (Show) diff --git a/sections/user/edit.php b/sections/user/edit.php index 8cc8669f..7e4e43fc 100644 --- a/sections/user/edit.php +++ b/sections/user/edit.php @@ -224,7 +224,7 @@ function checked($Checked) { Unseeded torrent alerts /> - + diff --git a/sections/user/user.php b/sections/user/user.php index 7258db3e..1ddc8ac6 100644 --- a/sections/user/user.php +++ b/sections/user/user.php @@ -221,8 +221,8 @@ function check_paranoia_here($Setting) {

  • Required ratio:
  • - 0) && ($OwnProfile || check_perms('users_mod'))) { ?> -
  • Tokens:
  • + +
  • Tokens:
  • diff --git a/sections/userhistory/token_history.php b/sections/userhistory/token_history.php index 1fa4c7b7..3156756f 100644 --- a/sections/userhistory/token_history.php +++ b/sections/userhistory/token_history.php @@ -56,8 +56,12 @@ WHERE f.UserID = $UserID ORDER BY f.Time DESC LIMIT $Limit"); - $Tokens = $DB->to_array(); -$Pages=get_pages($Page, $DB->record_count(), 25, 9); +$Tokens = $DB->to_array(); + +$DB->query("SELECT FOUND_ROWS()"); +list($NumResults) = $DB->next_record(); +$Pages=get_pages($Page, $NumResults, 25); + ?>

    Freeleech token history for

    diff --git a/static/styles/mono/style.css b/static/styles/mono/style.css index 046b385e..e05758a7 100644 --- a/static/styles/mono/style.css +++ b/static/styles/mono/style.css @@ -1123,13 +1123,17 @@ div.pad ul,div.body ul,table.torrent_table blockquote>ul,div.pad ol,div.body ol white-space: pre-wrap; } -#debug_database td.query { +table.debug_table td.debug_data { padding: 0; } -#debug_database td.query>div { +table.debug_table td.debug_data>div, table.debug_table td.debug_data>pre { overflow: auto; padding: 8px; + max-height: 400px; +} + +table.debug_table td.debug_query_data>div { width: 796px; }