Gazelle/sections/ajax/info.php

102 lines
3.5 KiB
PHP
Raw Normal View History

<?
//no authorization because this page needs to be accessed to get the authkey
//authorize(true);
//calculate ratio --Gwindow
//returns 0 for DNE and -1 for infiinity, because we dont want strings being returned for a numeric value in our java
2012-02-10 08:00:19 +00:00
$Ratio = 0;
2012-02-04 08:00:25 +00:00
if($LoggedUser['BytesUploaded'] == 0 && $LoggedUser['BytesDownloaded'] == 0) {
2012-02-10 08:00:19 +00:00
$Ratio = 0;
2012-02-04 08:00:25 +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-02-04 08:00:25 +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) {
$DB->query("SELECT ID FROM news ORDER BY Time DESC LIMIT 1");
if ($DB->record_count() == 1) {
list($CurrentNews) = $DB->next_record();
} else {
$CurrentNews = -1;
}
$Cache->cache_value('news_latest_id', $CurrentNews, 0);
}
$NewMessages = $Cache->get_value('inbox_new_'.$LoggedUser['ID']);
if ($NewMessages === false) {
$DB->query("SELECT COUNT(UnRead) FROM pm_conversations_users WHERE UserID='".$LoggedUser['ID']."' AND UnRead = '1' AND InInbox = '1'");
list($NewMessages) = $DB->next_record();
$Cache->cache_value('inbox_new_'.$LoggedUser['ID'], $NewMessages, 0);
}
if (check_perms('site_torrents_notify')) {
$NewNotifications = $Cache->get_value('notifications_new_'.$LoggedUser['ID']);
if ($NewNotifications === false) {
$DB->query("SELECT COUNT(UserID) FROM users_notify_torrents WHERE UserID='$LoggedUser[ID]' AND UnRead='1'");
list($NewNotifications) = $DB->next_record();
/* if($NewNotifications && !check_perms('site_torrents_notify')) {
$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-07-06 08:00:11 +00:00
// News
$MyNews = $LoggedUser['LastReadNews'];
$CurrentNews = $Cache->get_value('news_latest_id');
if ($CurrentNews === false) {
$DB->query("SELECT ID FROM news ORDER BY Time DESC LIMIT 1");
if ($DB->record_count() == 1) {
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) {
$DB->query("SELECT ID FROM blog WHERE Important = 1 ORDER BY Time DESC LIMIT 1");
if ($DB->record_count() == 1) {
list($CurrentBlog) = $DB->next_record();
} else {
$CurrentBlog = -1;
}
$Cache->cache_value('blog_latest_id', $CurrentBlog, 0);
}
print json_encode(
array(
'status' => 'success',
'response' => array(
2012-02-04 08:00:25 +00:00
'username' => $LoggedUser['Username'],
2012-06-09 08:00:19 +00:00
'id' => (int) $LoggedUser['ID'],
2012-02-04 08:00:25 +00:00
'authkey'=> $LoggedUser['AuthKey'],
'passkey'=> $LoggedUser['torrent_pass'],
2012-06-09 08:00:19 +00:00
'notifications' => array(
'messages'=> (int) $NewMessages,
2012-07-06 08:00:11 +00:00
'notifications' => (int) $NewNotifications,
'newAnnouncement' => $MyNews < $CurrentNews,
'newBlog' => $MyBlog < $CurrentBlog
2012-06-09 08:00:19 +00:00
),
'userstats' => array(
2012-02-04 08:00:25 +00:00
'uploaded' => (int) $LoggedUser['BytesUploaded'],
'downloaded' => (int) $LoggedUser['BytesDownloaded'],
2012-02-10 08:00:19 +00:00
'ratio' => (float) $Ratio,
2012-02-04 08:00:25 +00:00
'requiredratio' => (float) $LoggedUser['RequiredRatio'],
'class' => $ClassLevels[$LoggedUser['Class']]['Name']
2012-07-06 08:00:11 +00:00
)
)
)
);
?>