Gazelle/sections/ajax/info.php

118 lines
3.3 KiB
PHP
Raw Normal View History

<?
2012-07-07 08:00:11 +00:00
//calculate ratio
2013-04-19 08:00:55 +00:00
//returns 0 for DNE and -1 for infinity, because we don't want strings being returned for a numeric value in our java
2012-02-10 08:00:19 +00:00
$Ratio = 0;
2012-11-30 08:00:19 +00:00
if ($LoggedUser['BytesUploaded'] == 0 && $LoggedUser['BytesDownloaded'] == 0) {
2012-02-10 08:00:19 +00:00
$Ratio = 0;
2012-11-30 08:00:19 +00:00
} elseif ($LoggedUser['BytesDownloaded'] == 0) {
2012-02-10 08:00:19 +00:00
$Ratio = -1;
2011-10-31 08:00:12 +00:00
} else {
2012-11-30 08:00:19 +00:00
$Ratio = number_format(max($LoggedUser['BytesUploaded'] / $LoggedUser['BytesDownloaded'] - 0.005, 0), 2); //Subtract .005 to floor to 2 decimals
}
2012-06-09 08:00:19 +00:00
$MyNews = $LoggedUser['LastReadNews'];
$CurrentNews = $Cache->get_value('news_latest_id');
if ($CurrentNews === false) {
2013-07-10 00:08:53 +00:00
$DB->query("
SELECT ID
FROM news
ORDER BY Time DESC
LIMIT 1");
if ($DB->record_count() === 1) {
2012-11-30 08:00:19 +00:00
list($CurrentNews) = $DB->next_record();
} else {
$CurrentNews = -1;
}
$Cache->cache_value('news_latest_id', $CurrentNews, 0);
2012-06-09 08:00:19 +00:00
}
2012-11-30 08:00:19 +00:00
$NewMessages = $Cache->get_value('inbox_new_' . $LoggedUser['ID']);
2012-06-09 08:00:19 +00:00
if ($NewMessages === false) {
2013-07-10 00:08:53 +00:00
$DB->query("
SELECT COUNT(UnRead)
FROM pm_conversations_users
WHERE UserID = '" . $LoggedUser['ID'] . "'
AND UnRead = '1'
AND InInbox = '1'");
2012-11-30 08:00:19 +00:00
list($NewMessages) = $DB->next_record();
$Cache->cache_value('inbox_new_' . $LoggedUser['ID'], $NewMessages, 0);
2012-06-09 08:00:19 +00:00
}
if (check_perms('site_torrents_notify')) {
2012-11-30 08:00:19 +00:00
$NewNotifications = $Cache->get_value('notifications_new_' . $LoggedUser['ID']);
if ($NewNotifications === false) {
2013-07-10 00:08:53 +00:00
$DB->query("
SELECT COUNT(UserID)
FROM users_notify_torrents
WHERE UserID = '$LoggedUser[ID]'
AND UnRead = '1'");
2012-11-30 08:00:19 +00:00
list($NewNotifications) = $DB->next_record();
2013-04-19 08:00:55 +00:00
/* if ($NewNotifications && !check_perms('site_torrents_notify')) {
2012-11-30 08:00:19 +00:00
$DB->query("DELETE FROM users_notify_torrents WHERE UserID='$LoggedUser[ID]'");
$DB->query("DELETE FROM users_notify_filters WHERE UserID='$LoggedUser[ID]'");
} */
$Cache->cache_value('notifications_new_' . $LoggedUser['ID'], $NewNotifications, 0);
}
2012-06-09 08:00:19 +00:00
}
2012-07-06 08:00:11 +00:00
// News
$MyNews = $LoggedUser['LastReadNews'];
$CurrentNews = $Cache->get_value('news_latest_id');
if ($CurrentNews === false) {
2013-07-10 00:08:53 +00:00
$DB->query("
SELECT ID
FROM news
ORDER BY Time DESC
LIMIT 1");
if ($DB->record_count() === 1) {
2012-07-06 08:00:11 +00:00
list($CurrentNews) = $DB->next_record();
} else {
$CurrentNews = -1;
}
$Cache->cache_value('news_latest_id', $CurrentNews, 0);
}
// Blog
$MyBlog = $LoggedUser['LastReadBlog'];
$CurrentBlog = $Cache->get_value('blog_latest_id');
if ($CurrentBlog === false) {
2013-07-10 00:08:53 +00:00
$DB->query("
SELECT ID
FROM blog
WHERE Important = 1
ORDER BY Time DESC
LIMIT 1");
if ($DB->record_count() === 1) {
2012-07-06 08:00:11 +00:00
list($CurrentBlog) = $DB->next_record();
} else {
$CurrentBlog = -1;
}
$Cache->cache_value('blog_latest_id', $CurrentBlog, 0);
}
2012-11-30 08:00:19 +00:00
// Subscriptions
2013-08-28 23:08:41 +00:00
$NewSubscriptions = Subscriptions::has_new_subscriptions();
2012-11-30 08:00:19 +00:00
2013-04-24 08:00:23 +00:00
json_die("success", array(
2013-05-14 08:00:34 +00:00
'username' => $LoggedUser['Username'],
2013-10-30 08:01:19 +00:00
'id' => (int)$LoggedUser['ID'],
2013-05-14 08:00:34 +00:00
'authkey' => $LoggedUser['AuthKey'],
'passkey' => $LoggedUser['torrent_pass'],
'notifications' => array(
2013-10-30 08:01:19 +00:00
'messages' => (int)$NewMessages,
'notifications' => (int)$NewNotifications,
2013-05-14 08:00:34 +00:00
'newAnnouncement' => $MyNews < $CurrentNews,
'newBlog' => $MyBlog < $CurrentBlog,
'newSubscriptions' => $NewSubscriptions == 1
),
'userstats' => array(
2013-10-30 08:01:19 +00:00
'uploaded' => (int)$LoggedUser['BytesUploaded'],
'downloaded' => (int)$LoggedUser['BytesDownloaded'],
'ratio' => (float)$Ratio,
'requiredratio' => (float)$LoggedUser['RequiredRatio'],
2013-05-14 08:00:34 +00:00
'class' => $ClassLevels[$LoggedUser['Class']]['Name']
)
2013-04-24 08:00:23 +00:00
));
?>