Gazelle/sections/ajax/notifications.php

108 lines
3.2 KiB
PHP
Raw Normal View History

2013-05-28 08:01:02 +00:00
<?php
2013-05-05 08:00:31 +00:00
if (!check_perms('site_torrents_notify')) {
2013-05-14 08:00:34 +00:00
json_die("failure");
2011-11-26 08:00:20 +00:00
}
define('NOTIFICATIONS_PER_PAGE', 50);
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit(NOTIFICATIONS_PER_PAGE);
2011-11-26 08:00:20 +00:00
2013-05-05 08:00:31 +00:00
$Results = $DB->query("
2013-05-29 08:00:51 +00:00
SELECT
SQL_CALC_FOUND_ROWS
2013-05-05 08:00:31 +00:00
unt.TorrentID,
unt.UnRead,
unt.FilterID,
unf.Label,
t.GroupID
2011-11-26 08:00:20 +00:00
FROM users_notify_torrents AS unt
2013-05-05 08:00:31 +00:00
JOIN torrents AS t ON t.ID = unt.TorrentID
LEFT JOIN users_notify_filters AS unf ON unf.ID = unt.FilterID
2012-06-16 08:00:18 +00:00
WHERE unt.UserID=$LoggedUser[ID]".
((!empty($_GET['filterid']) && is_number($_GET['filterid']))
? " AND unf.ID='$_GET[filterid]'"
2013-05-05 08:00:31 +00:00
: '')."
ORDER BY TorrentID DESC
LIMIT $Limit");
2012-06-16 08:00:18 +00:00
$GroupIDs = array_unique($DB->collect('GroupID'));
2011-11-26 08:00:20 +00:00
$DB->query('SELECT FOUND_ROWS()');
list($TorrentCount) = $DB->next_record();
2013-05-05 08:00:31 +00:00
if (count($GroupIDs)) {
2012-10-11 08:00:15 +00:00
$TorrentGroups = Torrents::get_groups($GroupIDs);
2013-05-05 08:00:31 +00:00
$DB->query("
UPDATE users_notify_torrents
2013-09-13 08:00:53 +00:00
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();
2013-05-05 08:00:31 +00:00
while ($Result = $DB->next_record(MYSQLI_ASSOC)) {
if (!$Result['FilterID']) {
2011-11-26 08:00:20 +00:00
$Result['FilterID'] = 0;
}
2013-05-05 08:00:31 +00:00
if (!isset($FilterGroups[$Result['FilterID']])) {
2011-11-26 08:00:20 +00:00
$FilterGroups[$Result['FilterID']] = array();
2013-05-29 08:00:51 +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);
2013-05-05 08:00:31 +00:00
foreach ($FilterGroups as $FilterID => $FilterResults) {
2011-11-26 08:00:20 +00:00
unset($FilterResults['FilterLabel']);
2013-05-05 08:00:31 +00:00
foreach ($FilterResults as $Result) {
2012-06-16 08:00:18 +00:00
$TorrentID = $Result['TorrentID'];
2013-02-25 21:16:55 +00:00
// $GroupID = $Result['GroupID'];
2012-06-16 08:00:18 +00:00
$GroupInfo = $TorrentGroups[$Result['GroupID']];
2013-02-25 21:16:55 +00:00
extract(Torrents::array_group($GroupInfo)); // all group data
2012-06-16 08:00:18 +00:00
$TorrentInfo = $GroupInfo['Torrents'][$TorrentID];
2013-05-05 08:00:31 +00:00
if ($Result['UnRead'] == 1) {
$NumNew++;
}
2013-02-22 08:00:24 +00:00
2011-11-26 08:00:20 +00:00
$JsonNotifications[] = array(
'torrentId' => (int) $TorrentID,
'groupId' => (int) $GroupID,
2013-02-25 21:16:55 +00:00
'groupName' => $GroupName,
2011-11-26 08:00:20 +00:00
'groupCategoryId' => (int) $GroupCategoryID,
2013-02-25 21:16:55 +00:00
'wikiImage' => $WikiImage,
'torrentTags' => $TagList,
2012-06-16 08:00:18 +00:00
'size' => (float) $TorrentInfo['Size'],
'fileCount' => (int) $TorrentInfo['FileCount'],
'format' => $TorrentInfo['Format'],
'encoding' => $TorrentInfo['Encoding'],
'media' => $TorrentInfo['Media'],
'scene' => $TorrentInfo['Scene'] == 1,
2013-02-25 21:16:55 +00:00
'groupYear' => (int) $GroupYear,
2012-06-16 08:00:18 +00:00
'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
);
}
}
2013-04-24 08:00:23 +00:00
json_die("success", array(
2013-05-14 08:00:34 +00:00
'currentPages' => intval($Page),
'pages' => ceil($TorrentCount / NOTIFICATIONS_PER_PAGE),
'numNew' => $NumNew,
'results' => $JsonNotifications
2013-05-05 08:00:31 +00:00
));