Gazelle/sections/torrents/notify.php

177 lines
7.5 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
if(!check_perms('site_torrents_notify')) { error(403); }
define('NOTIFICATIONS_PER_PAGE', 50);
2012-10-11 08:00:15 +00:00
list($Page,$Limit) = Format::page_limit(NOTIFICATIONS_PER_PAGE);
2011-03-28 14:21:28 +00:00
2012-06-09 08:00:19 +00:00
$UserID = $LoggedUser['ID'];
$Results = $DB->query("SELECT SQL_CALC_FOUND_ROWS unt.TorrentID, unt.UnRead, unt.FilterID, unf.Label, 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
LEFT JOIN users_notify_filters AS unf ON unf.ID = unt.FilterID
WHERE unt.UserID=$UserID".
((!empty($_GET['filterid']) && is_number($_GET['filterid']))
? " AND unf.ID='$_GET[filterid]'"
: "")."
ORDER BY TorrentID DESC LIMIT $Limit");
$GroupIDs = array_unique($DB->collect('GroupID'));
2011-03-28 14:21:28 +00:00
$DB->query('SELECT FOUND_ROWS()');
list($TorrentCount) = $DB->next_record();
2012-06-09 08:00:19 +00:00
$Debug->log_var($TorrentCount, 'Torrent count');
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-06-09 08:00:19 +00:00
if(count($GroupIDs)) {
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-06-09 08:00:19 +00:00
//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']);
$Cache->delete_value('notifications_new_'.$LoggedUser['ID']);
}
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
View::show_header('My notifications', 'notifications');
2012-06-09 08:00:19 +00:00
$DB->set_query_id($Results);
2011-03-28 14:21:28 +00:00
?>
2012-08-19 08:00:19 +00:00
<div class="header">
<h2>Latest notifications <a href="torrents.php?action=notify_clear&amp;auth=<?=$LoggedUser['AuthKey']?>">(clear all)</a> <a href="javascript:SuperGroupClear()">(clear selected)</a> <a href="user.php?action=notify">(edit filters)</a></h2>
</div>
2011-03-28 14:21:28 +00:00
<div class="linkbox">
<?=$Pages?>
</div>
2012-06-09 08:00:19 +00:00
<? if(!$DB->record_count()) { ?>
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>
<? } else {
$FilterGroups = array();
2012-06-09 08:00:19 +00:00
while($Result = $DB->next_record(MYSQLI_ASSOC)) {
2011-03-28 14:21:28 +00:00
if(!$Result['FilterID']) {
$Result['FilterID'] = 0;
}
if(!isset($FilterGroups[$Result['FilterID']])) {
$FilterGroups[$Result['FilterID']] = array();
2012-06-09 08:00:19 +00:00
$FilterGroups[$Result['FilterID']]['FilterLabel'] = $Result['Label'] ? $Result['Label'] : false;
2011-03-28 14:21:28 +00:00
}
array_push($FilterGroups[$Result['FilterID']], $Result);
}
unset($Result);
2012-06-09 08:00:19 +00:00
$Debug->log_var($FilterGroups, 'Filter groups');
foreach($FilterGroups as $FilterID => $FilterResults) {
2011-03-28 14:21:28 +00:00
?>
2012-06-09 08:00:19 +00:00
<h3>
Matches for <?=$FilterResults['FilterLabel'] !== false
? '<a href="torrents.php?action=notify&amp;filterid='.$FilterID.'">'.$FilterResults['FilterLabel'].'</a>'
: 'unknown filter['.$FilterID.']'?>
<a href="torrents.php?action=notify_cleargroup&amp;filterid=<?=$FilterID?>&amp;auth=<?=$LoggedUser['AuthKey']?>">(clear)</a>
<a href="javascript:GroupClear($('#notificationform_<?=$FilterID?>').raw())">(clear selected)</a>
</h3>
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>
<td style="width:100%;"><strong>Name</strong></td>
<td><strong>Files</strong></td>
<td><strong>Time</strong></td>
<td><strong>Size</strong></td>
<td style="text-align:right"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/snatched.png" alt="Snatches" title="Snatches" /></td>
<td style="text-align:right"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/seeders.png" alt="Seeders" title="Seeders" /></td>
<td style="text-align:right"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/leechers.png" alt="Leechers" title="Leechers" /></td>
</tr>
<?
unset($FilterResults['FilterLabel']);
foreach($FilterResults as $Result) {
2012-06-09 08:00:19 +00:00
$TorrentID = $Result['TorrentID'];
$GroupID = $Result['GroupID'];
$GroupInfo = $TorrentGroups[$Result['GroupID']];
2012-10-16 08:00:18 +00:00
if(!isset($GroupInfo['Torrents'][$TorrentID]) || !isset($GroupInfo['ID'])) {
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 = '';
if(!empty($GroupInfo['ExtendedArtists'])) {
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-06-09 08:00:19 +00:00
if($GroupCategoryID == 1) {
if($GroupInfo['Year'] > 0) {
$DisplayName .= " [$GroupInfo[Year]]";
}
if($GroupInfo['ReleaseType'] > 0) {
$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
$Debug->log_var($ExtraInfo, "Extra torrent info ($TorrentID)");
$TagLinks = array();
if($GroupInfo['TagList'] != '') {
$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-09-01 08:00:24 +00:00
<tr class="torrent" id="torrent<?=$TorrentID?>">
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-06-16 08:00:18 +00:00
<? if (($LoggedUser['FLTokens'] > 0) && ($TorrentInfo['Size'] < 1073741824)
2012-10-16 08:00:18 +00:00
&& !$TorrentInfo['PersonalFL'] && empty($TorrentInfo['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?>
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-09-05 08:00:24 +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(); ?>