Gazelle/sections/torrents/notify.php

302 lines
12 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
2012-10-27 08:00:09 +00:00
if (!check_perms('site_torrents_notify')) {
error(403);
}
2011-03-28 14:21:28 +00:00
define('NOTIFICATIONS_PER_PAGE', 50);
2012-10-27 08:00:09 +00:00
define('NOTIFICATIONS_MAX_SLOWSORT', 10000);
$OrderBys = array(
'time' => array('unt' => 'unt.TorrentID'),
'size' => array('t' => 't.Size'),
'snatches' => array('t' => 't.Snatched'),
'seeders' => array('t' => 't.Seeders'),
'leechers' => array('t' => 't.Leechers'),
'year' => array('tg' => 'tnt.Year'));
if (empty($_GET['order_by']) || !isset($OrderBys[$_GET['order_by']])) {
$_GET['order_by'] = 'time';
}
list($OrderTbl, $OrderCol) = each($OrderBys[$_GET['order_by']]);
2011-03-28 14:21:28 +00:00
2012-10-27 08:00:09 +00:00
if (!empty($_GET['order_way']) && $_GET['order_way'] == 'asc') {
$OrderWay = 'ASC';
} else {
$OrderWay = 'DESC';
}
if (!empty($_GET['filterid']) && is_number($_GET['filterid'])) {
$FilterID = $_GET['filterid'];
} else {
$FilterID = false;
}
list($Page,$Limit) = Format::page_limit(NOTIFICATIONS_PER_PAGE);
2012-06-09 08:00:19 +00:00
2012-10-27 08:00:09 +00:00
// The "order by x" links on columns headers
function header_link($SortKey, $DefaultWay = "desc") {
global $OrderWay;
if ($SortKey == $_GET['order_by']) {
if ($OrderWay == "DESC") {
$NewWay = "asc";
} else {
$NewWay = "desc";
}
} else {
$NewWay = $DefaultWay;
}
return "?action=notify&amp;order_way=".$NewWay."&amp;order_by=".$SortKey."&amp;".Format::get_url(array('page','order_way','order_by'));
}
2012-06-09 08:00:19 +00:00
$UserID = $LoggedUser['ID'];
2012-10-27 08:00:09 +00:00
// Sorting by release year requires joining torrents_group, which is slow. Using a temporary table
// makes it speedy enough as long as there aren't too many records to create
if ($OrderTbl == 'tg') {
$DB->query("SELECT COUNT(*) FROM users_notify_torrents AS unt
JOIN torrents AS t ON t.ID=unt.TorrentID
WHERE unt.UserID=$UserID".
($FilterID
? " AND FilterID=$FilterID"
: ""));
list($TorrentCount) = $DB->next_record();
if ($TorrentCount > NOTIFICATIONS_MAX_SLOWSORT) {
error("Due to performance issues, torrent lists with more than ".number_format(NOTIFICATIONS_MAX_SLOWSORT)." items cannot be ordered by release year.");
}
$DB->query("CREATE TEMPORARY TABLE temp_notify_torrents
(TorrentID int, GroupID int, UnRead tinyint, FilterID int, Year smallint, PRIMARY KEY(GroupID, TorrentID), KEY(Year)) ENGINE=MyISAM");
2012-10-28 08:00:19 +00:00
$DB->query("INSERT IGNORE INTO temp_notify_torrents (TorrentID, GroupID, UnRead, FilterID)
2012-10-27 08:00:09 +00:00
SELECT t.ID, t.GroupID, unt.UnRead, unt.FilterID
FROM users_notify_torrents AS unt JOIN torrents AS t ON t.ID=unt.TorrentID
WHERE unt.UserID=$UserID".
($FilterID
? " AND unt.FilterID=$FilterID"
: ""));
$DB->query("UPDATE temp_notify_torrents AS tnt JOIN torrents_group AS tg ON tnt.GroupID=tg.ID SET tnt.Year=tg.Year");
$DB->query("SELECT TorrentID, GroupID, UnRead, FilterID
FROM temp_notify_torrents AS tnt
ORDER BY $OrderCol $OrderWay, GroupID $OrderWay LIMIT $Limit");
$Results = $DB->to_array(false, MYSQLI_ASSOC, false);
} else {
$DB->query("SELECT SQL_CALC_FOUND_ROWS unt.TorrentID, unt.UnRead, unt.FilterID, t.GroupID
2011-03-28 14:21:28 +00:00
FROM users_notify_torrents AS unt
2012-06-09 08:00:19 +00:00
JOIN torrents AS t ON t.ID = unt.TorrentID
WHERE unt.UserID=$UserID".
2012-10-27 08:00:09 +00:00
($FilterID
? " AND unt.FilterID=$FilterID"
2012-06-09 08:00:19 +00:00
: "")."
2012-10-27 08:00:09 +00:00
ORDER BY $OrderCol $OrderWay LIMIT $Limit");
$Results = $DB->to_array(false, MYSQLI_ASSOC, false);
$DB->query("SELECT FOUND_ROWS()");
list($TorrentCount) = $DB->next_record();
}
2012-06-09 08:00:19 +00:00
2012-10-27 08:00:09 +00:00
$GroupIDs = $FilterIDs = $UnReadIDs = array();
foreach ($Results as $Torrent) {
$GroupIDs[$Torrent['GroupID']] = 1;
$FilterIDs[$Torrent['FilterID']] = 1;
if ($Torrent['UnRead']) {
$UnReadIDs[] = $Torrent['TorrentID'];
}
}
2012-10-11 08:00:15 +00:00
$Pages = Format::get_pages($Page, $TorrentCount, NOTIFICATIONS_PER_PAGE, 9);
2011-03-28 14:21:28 +00:00
2012-10-27 08:00:09 +00:00
if (!empty($GroupIDs)) {
$GroupIDs = array_keys($GroupIDs);
$FilterIDs = array_keys($FilterIDs);
2012-10-11 08:00:15 +00:00
$TorrentGroups = Torrents::get_groups($GroupIDs);
2012-06-09 08:00:19 +00:00
$TorrentGroups = $TorrentGroups['matches'];
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
// Need some extra info that Torrents::get_groups() doesn't return
2012-06-09 08:00:19 +00:00
$DB->query("SELECT ID, CategoryID FROM torrents_group WHERE ID IN (".implode(',', $GroupIDs).")");
$GroupCategoryIDs = $DB->to_array('ID', MYSQLI_ASSOC, false);
2011-03-28 14:21:28 +00:00
2012-10-27 08:00:09 +00:00
// Get the relevant filter labels
$DB->query("SELECT ID, Label, Artists FROM users_notify_filters WHERE ID IN (".implode(',', $FilterIDs).")");
2012-10-30 08:00:18 +00:00
$Filters = $DB->to_array('ID', MYSQLI_ASSOC, array('Artists'));
2012-10-27 08:00:09 +00:00
foreach ($Filters as &$Filter) {
$Filter['Artists'] = explode('|', trim($Filter['Artists'], '|'));
2012-11-02 08:00:18 +00:00
foreach ($Filter['Artists'] as &$FilterArtist) {
$FilterArtist = mb_strtolower($FilterArtist, 'UTF-8');
}
$Filter['Artists'] = array_flip($Filter['Artists']);
2012-10-27 08:00:09 +00:00
}
unset($Filter);
if (!empty($UnReadIDs)) {
//Clear before header but after query so as to not have the alert bar on this page load
$DB->query("UPDATE users_notify_torrents SET UnRead='0' WHERE UserID=".$LoggedUser['ID']." AND TorrentID IN (".implode(',', $UnReadIDs).")");
$Cache->delete_value('notifications_new_'.$LoggedUser['ID']);
}
2012-06-09 08:00:19 +00:00
}
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
View::show_header('My notifications', 'notifications');
2012-10-27 08:00:09 +00:00
2011-03-28 14:21:28 +00:00
?>
2012-08-19 08:00:19 +00:00
<div class="header">
2012-10-27 08:00:09 +00:00
<h2>Latest notifications</h2>
</div>
<div class="linkbox">
<? if($FilterID) { ?>
<a href="torrents.php?action=notify">View all</a>&nbsp;&nbsp;&nbsp;
<? } else { ?>
<a href="torrents.php?action=notify_clear&amp;auth=<?=$LoggedUser['AuthKey']?>">Clear all</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:SuperGroupClear()">Clear selected</a>&nbsp;&nbsp;&nbsp;
<a href="torrents.php?action=notify_catchup&amp;auth=<?=$LoggedUser['AuthKey']?>">Catch up</a>&nbsp;&nbsp;&nbsp;
<? } ?>
<a href="user.php?action=notify">Edit filters</a>&nbsp;&nbsp;&nbsp;
2012-08-19 08:00:19 +00:00
</div>
2012-10-27 08:00:09 +00:00
<? if ($TorrentCount > NOTIFICATIONS_PER_PAGE) { ?>
2011-03-28 14:21:28 +00:00
<div class="linkbox">
<?=$Pages?>
</div>
2012-10-27 08:00:09 +00:00
<?
}
if (empty($Results)) {
?>
2012-09-01 08:00:24 +00:00
<table class="layout border">
2011-03-28 14:21:28 +00:00
<tr class="rowb">
2012-02-09 08:00:20 +00:00
<td colspan="8" class="center">
2011-03-28 14:21:28 +00:00
No new notifications found! <a href="user.php?action=notify">Edit notification filters</a>
</td>
</tr>
</table>
2012-10-27 08:00:09 +00:00
<?
} else {
2011-03-28 14:21:28 +00:00
$FilterGroups = array();
2012-10-27 08:00:09 +00:00
foreach ($Results as $Result) {
if (!isset($FilterGroups[$Result['FilterID']])) {
2011-03-28 14:21:28 +00:00
$FilterGroups[$Result['FilterID']] = array();
2012-10-27 08:00:09 +00:00
$FilterGroups[$Result['FilterID']]['FilterLabel'] = isset($Filters[$Result['FilterID']])
? $Filters[$Result['FilterID']]['Label']
: false;
2011-03-28 14:21:28 +00:00
}
2012-10-27 08:00:09 +00:00
$FilterGroups[$Result['FilterID']][] = $Result;
2011-03-28 14:21:28 +00:00
}
2012-10-27 08:00:09 +00:00
foreach ($FilterGroups as $FilterID => $FilterResults) {
2011-03-28 14:21:28 +00:00
?>
2012-10-27 08:00:09 +00:00
<div class="header">
<h3>
Matches for <?=$FilterResults['FilterLabel'] !== false
? '<a href="torrents.php?action=notify&amp;filterid='.$FilterID.'">'.$FilterResults['FilterLabel'].'</a>'
: 'unknown filter['.$FilterID.']'?>
</h3>
</div>
<div class="notify_filter_links">
<a href="javascript:GroupClear($('#notificationform_<?=$FilterID?>').raw())">Clear selected in filter</a>&nbsp;&nbsp;&nbsp;
<a href="torrents.php?action=notify_clear_filter&amp;filterid=<?=$FilterID?>&amp;auth=<?=$LoggedUser['AuthKey']?>">Clear all in filter</a>&nbsp;&nbsp;&nbsp;
<a href="torrents.php?action=notify_catchup_filter&amp;filterid=<?=$FilterID?>&amp;auth=<?=$LoggedUser['AuthKey']?>">Mark all in filter as read</a>
</div>
2012-09-15 08:00:25 +00:00
<form class="manage_form" name="torrents" id="notificationform_<?=$FilterID?>">
2012-09-01 08:00:24 +00:00
<table class="torrent_table cats checkboxes border">
2011-03-28 14:21:28 +00:00
<tr class="colhead">
2012-09-09 08:00:26 +00:00
<td style="text-align: center"><input type="checkbox" name="toggle" onclick="ToggleBoxes(this.form, this.checked)" /></td>
2011-03-28 14:21:28 +00:00
<td class="small cats_col"></td>
2012-10-27 08:00:09 +00:00
<td style="width:100%;">Name<?=$TorrentCount <= NOTIFICATIONS_MAX_SLOWSORT ? ' / <a href="'.header_link('year').'">Year</a>' : ''?></td>
<td>Files</td>
<td><a href="<?=header_link('time')?>">Time</a></td>
<td><a href="<?=header_link('size')?>">Size</a></td>
<td class="sign"><a href="<?=header_link('snatches')?>"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/snatched.png" alt="Snatches" title="Snatches" /></a></td>
<td class="sign"><a href="<?=header_link('seeders')?>"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/seeders.png" alt="Seeders" title="Seeders" /></a></td>
<td class="sign"><a href="<?=header_link('leechers')?>"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/leechers.png" alt="Leechers" title="Leechers" /></a></td>
2011-03-28 14:21:28 +00:00
</tr>
<?
unset($FilterResults['FilterLabel']);
2012-10-27 08:00:09 +00:00
foreach ($FilterResults as $Result) {
2012-06-09 08:00:19 +00:00
$TorrentID = $Result['TorrentID'];
$GroupID = $Result['GroupID'];
$GroupInfo = $TorrentGroups[$Result['GroupID']];
2012-10-27 08:00:09 +00:00
if (!isset($GroupInfo['Torrents'][$TorrentID]) || !isset($GroupInfo['ID'])) {
// If $GroupInfo['ID'] is unset, the torrent group associated with the torrent doesn't exist
2012-06-09 08:00:19 +00:00
continue;
2011-10-29 08:00:15 +00:00
}
2012-10-16 08:00:18 +00:00
$TorrentInfo = $GroupInfo['Torrents'][$TorrentID];
2012-06-09 08:00:19 +00:00
// generate torrent's title
$DisplayName = '';
2012-10-27 08:00:09 +00:00
if (!empty($GroupInfo['ExtendedArtists'])) {
$MatchingArtists = array();
foreach ($GroupInfo['ExtendedArtists'] as $GroupArtists) {
foreach ($GroupArtists as $GroupArtist) {
2012-11-02 08:00:18 +00:00
if (isset($Filters[$FilterID]['Artists'][mb_strtolower($GroupArtist['name'], 'UTF-8')])) {
$MatchingArtists[] = $GroupArtist['name'];
2012-10-27 08:00:09 +00:00
}
}
}
$MatchingArtistsText = !empty($MatchingArtists)
? 'Caught by filter for '.implode(', ', $MatchingArtists)
: '';
2012-10-11 08:00:15 +00:00
$DisplayName = Artists::display_artists($GroupInfo['ExtendedArtists'], true, true);
2011-03-28 14:21:28 +00:00
}
2012-06-09 08:00:19 +00:00
$DisplayName .= "<a href='torrents.php?id=$GroupID&amp;torrentid=$TorrentID#torrent$TorrentID' title='View Torrent'>".$GroupInfo['Name']."</a>";
2012-10-16 08:00:18 +00:00
$GroupCategoryID = $GroupCategoryIDs[$GroupID]['CategoryID'];
2012-10-27 08:00:09 +00:00
if ($GroupCategoryID == 1) {
if ($GroupInfo['Year'] > 0) {
2012-06-09 08:00:19 +00:00
$DisplayName .= " [$GroupInfo[Year]]";
}
2012-10-27 08:00:09 +00:00
if ($GroupInfo['ReleaseType'] > 0) {
2012-06-09 08:00:19 +00:00
$DisplayName.= " [".$ReleaseTypes[$GroupInfo['ReleaseType']]."]";
}
2012-02-10 08:00:19 +00:00
}
2012-06-09 08:00:19 +00:00
2011-03-28 14:21:28 +00:00
// append extra info to torrent title
2012-10-11 08:00:15 +00:00
$ExtraInfo = Torrents::torrent_info($TorrentInfo, true, true);
2012-06-09 08:00:19 +00:00
$TagLinks = array();
2012-10-27 08:00:09 +00:00
if ($GroupInfo['TagList'] != '') {
2012-06-09 08:00:19 +00:00
$TorrentTags = explode(' ', $GroupInfo['TagList']);
2011-03-28 14:21:28 +00:00
$MainTag = $TorrentTags[0];
foreach ($TorrentTags as $TagKey => $TagName) {
2012-06-09 08:00:19 +00:00
$TagName = str_replace('_', '.', $TagName);
$TagLinks[] = '<a href="torrents.php?taglist='.$TagName.'">'.$TagName.'</a>';
2011-03-28 14:21:28 +00:00
}
$TagLinks = implode(', ', $TagLinks);
2012-06-09 08:00:19 +00:00
$TorrentTags = '<br /><div class="tags">'.$TagLinks.'</div>';
2011-03-28 14:21:28 +00:00
} else {
2012-06-16 08:00:18 +00:00
$TorrentTags = '';
2011-03-28 14:21:28 +00:00
$MainTag = $Categories[$GroupCategoryID-1];
}
// print row
?>
2012-11-04 08:00:20 +00:00
<tr class="torrent<?=$TorrentInfo['IsSnatched'] ? ' snatched_torrent' : ''?>" id="torrent<?=$TorrentID?>"<?=$MatchingArtistsText ? 'title="'.display_str($MatchingArtistsText).'"' : ''?>>
2012-02-09 08:00:20 +00:00
<td style="text-align: center"><input type="checkbox" value="<?=$TorrentID?>" id="clear_<?=$TorrentID?>" /></td>
2012-09-01 08:00:24 +00:00
<td class="center cats_col"><div title="<?=ucfirst(str_replace('_',' ',$MainTag))?>" class="cats_<?=strtolower(str_replace(array('-',' '),array('',''),$Categories[$GroupCategoryID-1])).' tags_'.str_replace('.','_',$MainTag)?>"></div></td>
2011-03-28 14:21:28 +00:00
<td>
<span>
2012-08-14 08:00:18 +00:00
[ <a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>" title="Download">DL</a>
2012-10-27 08:00:09 +00:00
<? if (Torrents::can_use_token($TorrentInfo)) { ?>
2012-09-09 08:00:26 +00:00
| <a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
2011-10-29 08:00:15 +00:00
<? } ?>
2012-08-14 08:00:18 +00:00
| <a href="#" onclick="Clear(<?=$TorrentID?>);return false;" title="Remove from notifications list">CL</a> ]
2011-03-28 14:21:28 +00:00
</span>
2012-06-09 08:00:19 +00:00
<strong><?=$DisplayName?></strong> <?=$ExtraInfo?>
2012-10-27 08:00:09 +00:00
<? if ($Result['UnRead']) {
echo '<strong class="new">New!</strong>';
} ?>
2011-03-28 14:21:28 +00:00
<?=$TorrentTags?>
</td>
2012-06-09 08:00:19 +00:00
<td><?=$TorrentInfo['FileCount']?></td>
<td style="text-align:right" class="nobr"><?=time_diff($TorrentInfo['Time'])?></td>
2012-10-11 08:00:15 +00:00
<td class="nobr" style="text-align:right"><?=Format::get_size($TorrentInfo['Size'])?></td>
2012-06-09 08:00:19 +00:00
<td style="text-align:right"><?=number_format($TorrentInfo['Snatched'])?></td>
<td style="text-align:right"><?=number_format($TorrentInfo['Seeders'])?></td>
<td style="text-align:right"><?=number_format($TorrentInfo['Leechers'])?></td>
2011-03-28 14:21:28 +00:00
</tr>
<?
}
?>
</table>
2012-02-09 08:00:20 +00:00
</form>
2011-03-28 14:21:28 +00:00
<?
}
}
?>
<div class="linkbox">
<?=$Pages?>
</div>
2012-10-11 08:00:15 +00:00
<? View::show_footer(); ?>