2011-11-26 08:00:20 +00:00
|
|
|
<?
|
|
|
|
|
|
|
|
authorize(true);
|
|
|
|
|
|
|
|
if(!check_perms('site_torrents_notify')) {
|
|
|
|
print
|
|
|
|
json_encode(
|
|
|
|
array(
|
|
|
|
'status' => 'failure'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
define('NOTIFICATIONS_PER_PAGE', 50);
|
|
|
|
list($Page,$Limit) = page_limit(NOTIFICATIONS_PER_PAGE);
|
|
|
|
|
2012-06-16 08:00:18 +00:00
|
|
|
$TokenTorrents = $Cache->get_value('users_tokens_'.$LoggedUser['ID']);
|
2011-11-26 08:00:20 +00:00
|
|
|
if (empty($TokenTorrents)) {
|
2012-06-16 08:00:18 +00:00
|
|
|
$DB->query("SELECT TorrentID FROM users_freeleeches WHERE UserID=$LoggedUser[ID] AND Expired=FALSE");
|
2011-11-26 08:00:20 +00:00
|
|
|
$TokenTorrents = $DB->collect('TorrentID');
|
2012-06-16 08:00:18 +00:00
|
|
|
$Cache->cache_value('users_tokens_'.$LoggedUser['ID'], $TokenTorrents);
|
2011-11-26 08:00:20 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 08:00:18 +00:00
|
|
|
$Results = $DB->query("SELECT SQL_CALC_FOUND_ROWS unt.TorrentID, unt.UnRead, unt.FilterID, unf.Label, t.GroupID
|
2011-11-26 08:00:20 +00:00
|
|
|
FROM users_notify_torrents AS unt
|
2012-06-16 08:00:18 +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=$LoggedUser[ID]".
|
|
|
|
((!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-11-26 08:00:20 +00:00
|
|
|
$DB->query('SELECT FOUND_ROWS()');
|
|
|
|
list($TorrentCount) = $DB->next_record();
|
|
|
|
|
2012-06-16 08:00:18 +00:00
|
|
|
if(count($GroupIDs)) {
|
|
|
|
$TorrentGroups = get_groups($GroupIDs);
|
|
|
|
$TorrentGroups = $TorrentGroups['matches'];
|
|
|
|
|
|
|
|
// Need some extra info that get_groups() doesn't return
|
|
|
|
$DB->query("SELECT ID, CategoryID FROM torrents_group WHERE ID IN (".implode(',', $GroupIDs).")");
|
|
|
|
$GroupCategoryIDs = $DB->to_array('ID', MYSQLI_ASSOC, false);
|
|
|
|
|
|
|
|
// Only clear the alert if they've specified to.
|
|
|
|
if (isset($_GET['clear']) && $_GET['clear'] == "1") {
|
|
|
|
//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-11-26 08:00:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$DB->set_query_id($Results);
|
|
|
|
|
|
|
|
$JsonNotifications = array();
|
|
|
|
$NumNew = 0;
|
|
|
|
|
|
|
|
$FilterGroups = array();
|
2012-06-16 08:00:18 +00:00
|
|
|
while($Result = $DB->next_record(MYSQLI_ASSOC)) {
|
2011-11-26 08:00:20 +00:00
|
|
|
if(!$Result['FilterID']) {
|
|
|
|
$Result['FilterID'] = 0;
|
|
|
|
}
|
|
|
|
if(!isset($FilterGroups[$Result['FilterID']])) {
|
|
|
|
$FilterGroups[$Result['FilterID']] = array();
|
2012-06-16 08:00:18 +00:00
|
|
|
$FilterGroups[$Result['FilterID']]['FilterLabel'] = $Result['Label'] ? $Result['Label'] : false;
|
2011-11-26 08:00:20 +00:00
|
|
|
}
|
|
|
|
array_push($FilterGroups[$Result['FilterID']], $Result);
|
|
|
|
}
|
|
|
|
unset($Result);
|
|
|
|
|
2012-06-16 08:00:18 +00:00
|
|
|
foreach($FilterGroups as $FilterID => $FilterResults) {
|
2011-11-26 08:00:20 +00:00
|
|
|
unset($FilterResults['FilterLabel']);
|
|
|
|
foreach($FilterResults as $Result) {
|
2012-06-16 08:00:18 +00:00
|
|
|
$TorrentID = $Result['TorrentID'];
|
|
|
|
$GroupID = $Result['GroupID'];
|
|
|
|
$GroupCategoryID = $GroupCategoryIDs[$GroupID]['CategoryID'];
|
|
|
|
|
|
|
|
$GroupInfo = $TorrentGroups[$Result['GroupID']];
|
|
|
|
$TorrentInfo = $GroupInfo['Torrents'][$TorrentID];
|
|
|
|
|
|
|
|
if ($Result['UnRead'] == 1) $NumNew++;
|
2011-11-26 08:00:20 +00:00
|
|
|
|
|
|
|
$JsonNotifications[] = array(
|
|
|
|
'torrentId' => (int) $TorrentID,
|
|
|
|
'groupId' => (int) $GroupID,
|
2012-06-16 08:00:18 +00:00
|
|
|
'groupName' => $GroupInfo['Name'],
|
2011-11-26 08:00:20 +00:00
|
|
|
'groupCategoryId' => (int) $GroupCategoryID,
|
2012-06-16 08:00:18 +00:00
|
|
|
'torrentTags' => $GroupInfo['TagList'],
|
|
|
|
'size' => (float) $TorrentInfo['Size'],
|
|
|
|
'fileCount' => (int) $TorrentInfo['FileCount'],
|
|
|
|
'format' => $TorrentInfo['Format'],
|
|
|
|
'encoding' => $TorrentInfo['Encoding'],
|
|
|
|
'media' => $TorrentInfo['Media'],
|
|
|
|
'scene' => $TorrentInfo['Scene'] == 1,
|
|
|
|
'groupYear' => (int) $GroupInfo['Year'],
|
|
|
|
'remasterYear' => (int) $TorrentInfo['RemasterYear'],
|
|
|
|
'remasterTitle' => $TorrentInfo['RemasterTitle'],
|
|
|
|
'snatched' => (int) $TorrentInfo['Snatched'],
|
|
|
|
'seeders' => (int) $TorrentInfo['Seeders'],
|
|
|
|
'leechers' => (int) $TorrentInfo['Leechers'],
|
|
|
|
'notificationTime' => $TorrentInfo['Time'],
|
|
|
|
'hasLog' => $TorrentInfo['HasLog'] == 1,
|
|
|
|
'hasCue' => $TorrentInfo['HasCue'] == 1,
|
|
|
|
'logScore' => (float) $TorrentInfo['LogScore'],
|
|
|
|
'freeTorrent' => $TorrentInfo['FreeTorrent'] == 1,
|
|
|
|
'logInDb' => $TorrentInfo['HasLog'] == 1,
|
|
|
|
'unread' => $Result['UnRead'] == 1
|
2011-11-26 08:00:20 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print
|
|
|
|
json_encode(
|
|
|
|
array(
|
|
|
|
'status' => 'success',
|
|
|
|
'response' => array(
|
|
|
|
'currentPages' => intval($Page),
|
|
|
|
'pages' => ceil($TorrentCount/NOTIFICATIONS_PER_PAGE),
|
|
|
|
'numNew' => $NumNew,
|
|
|
|
'results' => $JsonNotifications
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2012-01-28 08:00:29 +00:00
|
|
|
?>
|