mirror of
https://github.com/WhatCD/Gazelle.git
synced 2025-02-20 20:29:03 +00:00
Empty commit
This commit is contained in:
parent
070c899f89
commit
af7e35648f
@ -162,6 +162,12 @@
|
||||
time() < strtotime($LoggedUser['RatioWatchEnds']) &&
|
||||
($LoggedUser['BytesDownloaded']*$LoggedUser['RequiredRatio'])>$LoggedUser['BytesUploaded']
|
||||
);
|
||||
if(!isset($LoggedUser['ID'])) {
|
||||
$Debug->log_var($LightInfo, 'LightInfo');
|
||||
$Debug->log_var($HeavyInfo, 'HeavyInfo');
|
||||
$Debug->log_var($Permissions, 'Permissions');
|
||||
$Debug->log_var($UserStats, 'UserStats');
|
||||
}
|
||||
|
||||
//Load in the permissions
|
||||
$LoggedUser['Permissions'] = get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
|
||||
@ -367,8 +373,8 @@ function user_heavy_info($UserID) {
|
||||
$HeavyInfo['CustomForums'] = null;
|
||||
}
|
||||
|
||||
$HeavyInfo['SiteOptions'] = unserialize($HeavyInfo['SiteOptions']);
|
||||
if(!empty($HeavyInfo['SiteOptions'])) {
|
||||
$HeavyInfo['SiteOptions'] = unserialize($HeavyInfo['SiteOptions']);
|
||||
$HeavyInfo = array_merge($HeavyInfo, $HeavyInfo['SiteOptions']);
|
||||
}
|
||||
unset($HeavyInfo['SiteOptions']);
|
||||
|
@ -832,7 +832,8 @@ CREATE TABLE `torrents` (
|
||||
KEY `last_action` (`last_action`),
|
||||
KEY `Time` (`Time`),
|
||||
KEY `flags` (`flags`),
|
||||
KEY `LastLogged` (`LastLogged`)
|
||||
KEY `LastLogged` (`LastLogged`),
|
||||
KEY `FreeTorrent` (`FreeTorrent`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `torrents_artists` (
|
||||
|
246
sections/ajax/bookmarks.php
Normal file
246
sections/ajax/bookmarks.php
Normal file
@ -0,0 +1,246 @@
|
||||
<?
|
||||
ini_set('memory_limit', -1);
|
||||
//~~~~~~~~~~~ Main bookmarks page ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
|
||||
|
||||
authorize(true);
|
||||
|
||||
function compare($X, $Y){
|
||||
return($Y['count'] - $X['count']);
|
||||
}
|
||||
|
||||
if(!empty($_GET['userid'])) {
|
||||
if(!check_perms('users_override_paranoia')) {
|
||||
error(403);
|
||||
}
|
||||
$UserID = $_GET['userid'];
|
||||
if(!is_number($UserID)) { error(404); }
|
||||
$DB->query("SELECT Username FROM users_main WHERE ID='$UserID'");
|
||||
list($Username) = $DB->next_record();
|
||||
} else {
|
||||
$UserID = $LoggedUser['ID'];
|
||||
}
|
||||
|
||||
$Sneaky = ($UserID != $LoggedUser['ID']);
|
||||
|
||||
$Data = $Cache->get_value('bookmarks_torrent_'.$UserID.'_full');
|
||||
|
||||
if($Data) {
|
||||
$Data = unserialize($Data);
|
||||
list($K, list($TorrentList, $CollageDataList)) = each($Data);
|
||||
} else {
|
||||
// Build the data for the collage and the torrent list
|
||||
$DB->query("SELECT
|
||||
bt.GroupID,
|
||||
tg.WikiImage,
|
||||
tg.CategoryID,
|
||||
bt.Time
|
||||
FROM bookmarks_torrents AS bt
|
||||
JOIN torrents_group AS tg ON tg.ID=bt.GroupID
|
||||
WHERE bt.UserID='$UserID'
|
||||
ORDER BY bt.Time");
|
||||
|
||||
$GroupIDs = $DB->collect('GroupID');
|
||||
$CollageDataList=$DB->to_array('GroupID', MYSQLI_ASSOC);
|
||||
if(count($GroupIDs)>0) {
|
||||
$TorrentList = get_groups($GroupIDs);
|
||||
$TorrentList = $TorrentList['matches'];
|
||||
} else {
|
||||
$TorrentList = array();
|
||||
}
|
||||
}
|
||||
|
||||
$Title = ($Sneaky)?"$Username's bookmarked torrents":'Your bookmarked torrents';
|
||||
|
||||
|
||||
// Loop through the result set, building up $Collage and $TorrentTable
|
||||
// Then we print them.
|
||||
$Collage = array();
|
||||
$TorrentTable = '';
|
||||
|
||||
$NumGroups = 0;
|
||||
$Artists = array();
|
||||
$Tags = array();
|
||||
|
||||
foreach ($TorrentList as $GroupID=>$Group) {
|
||||
list($GroupID, $GroupName, $GroupYear, $GroupRecordLabel, $GroupCatalogueNumber, $TagList, $ReleaseType, $GroupVanityHouse, $Torrents, $GroupArtists) = array_values($Group);
|
||||
list($GroupID2, $Image, $GroupCategoryID, $AddedTime) = array_values($CollageDataList[$GroupID]);
|
||||
|
||||
// Handle stats and stuff
|
||||
$NumGroups++;
|
||||
|
||||
if($GroupArtists) {
|
||||
foreach($GroupArtists as $Artist) {
|
||||
if(!isset($Artists[$Artist['id']])) {
|
||||
$Artists[$Artist['id']] = array('name'=>$Artist['name'], 'count'=>1);
|
||||
} else {
|
||||
$Artists[$Artist['id']]['count']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$TagList = explode(' ',str_replace('_','.',$TagList));
|
||||
|
||||
$TorrentTags = array();
|
||||
foreach($TagList as $Tag) {
|
||||
if(!isset($Tags[$Tag])) {
|
||||
$Tags[$Tag] = array('name'=>$Tag, 'count'=>1);
|
||||
} else {
|
||||
$Tags[$Tag]['count']++;
|
||||
}
|
||||
$TorrentTags[]='<a href="torrents.php?taglist='.$Tag.'">'.$Tag.'</a>';
|
||||
}
|
||||
$PrimaryTag = $TagList[0];
|
||||
$TorrentTags = implode(', ', $TorrentTags);
|
||||
$TorrentTags='<br /><div class="tags">'.$TorrentTags.'</div>';
|
||||
|
||||
$DisplayName = '';
|
||||
if(count($GroupArtists)>0) {
|
||||
$DisplayName = display_artists(array('1'=>$GroupArtists));
|
||||
}
|
||||
$DisplayName .= '<a href="torrents.php?id='.$GroupID.'" title="View Torrent">'.$GroupName.'</a>';
|
||||
if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';}
|
||||
if($GroupVanityHouse) { $DisplayName .= ' [<abbr title="This is a vanity house release">VH</abbr>]'; }
|
||||
|
||||
// Start an output buffer, so we can store this output in $TorrentTable
|
||||
ob_start();
|
||||
if(count($Torrents)>1 || $GroupCategoryID==1) {
|
||||
// Grouped torrents
|
||||
$ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1);
|
||||
$LastRemasterYear = '-';
|
||||
$LastRemasterTitle = '';
|
||||
$LastRemasterRecordLabel = '';
|
||||
$LastRemasterCatalogueNumber = '';
|
||||
$LastMedia = '';
|
||||
|
||||
$EditionID = 0;
|
||||
unset($FirstUnknown);
|
||||
|
||||
foreach ($Torrents as $TorrentID => $Torrent) {
|
||||
|
||||
if ($Torrent['Remastered'] && !$Torrent['RemasterYear']) {
|
||||
$FirstUnknown = !isset($FirstUnknown);
|
||||
}
|
||||
|
||||
if($Torrent['RemasterTitle'] != $LastRemasterTitle || $Torrent['RemasterYear'] != $LastRemasterYear ||
|
||||
$Torrent['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Torrent['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber || $FirstUnknown || $Torrent['Media'] != $LastMedia) {
|
||||
|
||||
$EditionID++;
|
||||
if($Torrent['Remastered'] && $Torrent['RemasterYear'] != 0) {
|
||||
|
||||
$RemasterName = $Torrent['RemasterYear'];
|
||||
$AddExtra = " - ";
|
||||
if($Torrent['RemasterRecordLabel']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterRecordLabel']); $AddExtra=' / '; }
|
||||
if($Torrent['RemasterCatalogueNumber']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterCatalogueNumber']); $AddExtra=' / '; }
|
||||
if($Torrent['RemasterTitle']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterTitle']); $AddExtra=' / '; }
|
||||
$RemasterName .= $AddExtra.display_str($Torrent['Media']);
|
||||
|
||||
} else {
|
||||
$AddExtra = " / ";
|
||||
if (!$Torrent['Remastered']) {
|
||||
$MasterName = "Original Release";
|
||||
if($GroupRecordLabel) { $MasterName .= $AddExtra.$GroupRecordLabel; $AddExtra=' / '; }
|
||||
if($GroupCatalogueNumber) { $MasterName .= $AddExtra.$GroupCatalogueNumber; $AddExtra=' / '; }
|
||||
} else {
|
||||
$MasterName = "Unknown Release(s)";
|
||||
}
|
||||
$MasterName .= $AddExtra.display_str($Torrent['Media']);
|
||||
}
|
||||
}
|
||||
$LastRemasterTitle = $Torrent['RemasterTitle'];
|
||||
$LastRemasterYear = $Torrent['RemasterYear'];
|
||||
$LastRemasterRecordLabel = $Torrent['RemasterRecordLabel'];
|
||||
$LastRemasterCatalogueNumber = $Torrent['RemasterCatalogueNumber'];
|
||||
$LastMedia = $Torrent['Media'];
|
||||
}
|
||||
} else {
|
||||
// Viewing a type that does not require grouping
|
||||
|
||||
list($TorrentID, $Torrent) = each($Torrents);
|
||||
|
||||
$DisplayName = '<a href="torrents.php?id='.$GroupID.'" title="View Torrent">'.$GroupName.'</a>';
|
||||
|
||||
if(!empty($Torrent['FreeTorrent'])) {
|
||||
$DisplayName .=' <strong>Freeleech!</strong>';
|
||||
}
|
||||
}
|
||||
$TorrentTable.=ob_get_clean();
|
||||
|
||||
// Album art
|
||||
|
||||
ob_start();
|
||||
|
||||
$DisplayName = '';
|
||||
if(!empty($GroupArtists)) {
|
||||
$DisplayName.= display_artists(array('1'=>$GroupArtists), false);
|
||||
}
|
||||
$DisplayName .= $GroupName;
|
||||
if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';}
|
||||
$Collage[]=ob_get_clean();
|
||||
|
||||
}
|
||||
|
||||
uasort($Tags, 'compare');
|
||||
$i = 0;
|
||||
foreach ($Tags as $TagName => $Tag) {
|
||||
$i++;
|
||||
if($i>5) { break; }
|
||||
uasort($Artists, 'compare');
|
||||
$i = 0;
|
||||
foreach ($Artists as $ID => $Artist) {
|
||||
$i++;
|
||||
if($i>10) { break; }
|
||||
}
|
||||
}
|
||||
|
||||
$JsonBookmarks = array();
|
||||
foreach ($TorrentList as $Torrent) {
|
||||
$JsonTorrents = array();
|
||||
foreach ($Torrent['Torrents'] as $GroupTorrents) {
|
||||
$JsonTorrents[] = array(
|
||||
'id' => $GroupTorrents['ID'],
|
||||
'groupId' => $GroupTorrents['GroupID'],
|
||||
'media' => $GroupTorrents['Media'],
|
||||
'format' => $GroupTorrents['Format'],
|
||||
'encoding' => $GroupTorrents['Encoding'],
|
||||
'remasterYear' => $GroupTorrents['RemasterYear'],
|
||||
'remastered' => $GroupTorrents['Remastered'],
|
||||
'remasterTitle' => $GroupTorrents['RemasterTitle'],
|
||||
'remasterRecordLabel' => $GroupTorrents['RemasterRecordLabel'],
|
||||
'remasterCatalogueNumber' => $GroupTorrents['RemasterCatalogueNumber'],
|
||||
'scene' => $GroupTorrents['Scene'],
|
||||
'hasLog' => $GroupTorrents['HasLog'],
|
||||
'hasCue' => $GroupTorrents['HasCue'],
|
||||
'logScore' => $GroupTorrents['LogScore'],
|
||||
'fileCount' => $GroupTorrents['FileCount'],
|
||||
'freeTorrent' => $GroupTorrents['FreeTorrent'],
|
||||
'size' => $GroupTorrents['Size'],
|
||||
'leechers' => $GroupTorrents['Leechers'],
|
||||
'seeders' => $GroupTorrents['Seeders'],
|
||||
'snatched' => $GroupTorrents['Snatched'],
|
||||
'time' => $GroupTorrents['Time'],
|
||||
'hasFile' => $GroupTorrents['HasFile']
|
||||
);
|
||||
}
|
||||
$JsonBookmarks[] = array(
|
||||
'id' => $Torrent['ID'],
|
||||
'name' => $Torrent['Name'],
|
||||
'year' => $Torrent['Year'],
|
||||
'recordLabel' => $Torrent['RecordLabel'],
|
||||
'catalogueNumber' => $Torrent['CatalogueNumber'],
|
||||
'tagList' => $Torrent['TagList'],
|
||||
'releaseType' => $Torrent['ReleaseType'],
|
||||
'vanityHouse' => $Torrent['VanityHouse'],
|
||||
'torrents' => $JsonTorrents
|
||||
);
|
||||
}
|
||||
|
||||
print
|
||||
json_encode(
|
||||
array(
|
||||
'status' => 'success',
|
||||
'response' => array(
|
||||
'bookmarks' => $JsonBookmarks
|
||||
)
|
||||
)
|
||||
);
|
||||
?>
|
157
sections/ajax/forum/forum.php
Normal file
157
sections/ajax/forum/forum.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?
|
||||
|
||||
authorize();
|
||||
|
||||
/**********|| Page to show individual forums || ********************************\
|
||||
|
||||
Things to expect in $_GET:
|
||||
ForumID: ID of the forum curently being browsed
|
||||
page: The page the user's on.
|
||||
page = 1 is the same as no page
|
||||
|
||||
********************************************************************************/
|
||||
|
||||
//---------- Things to sort out before it can start printing/generating content
|
||||
|
||||
// Check for lame SQL injection attempts
|
||||
$ForumID = $_GET['forumid'];
|
||||
if(!is_number($ForumID)) {
|
||||
print json_encode(array('status' => 'failure'));
|
||||
die();
|
||||
}
|
||||
|
||||
if (isset($_GET['pp'])) {
|
||||
$PerPage = $_GET['pp'];
|
||||
}
|
||||
else if (isset($LoggedUser['PostsPerPage'])) {
|
||||
$PerPage = $LoggedUser['PostsPerPage'];
|
||||
} else {
|
||||
$PerPage = POSTS_PER_PAGE;
|
||||
}
|
||||
|
||||
list($Page,$Limit) = page_limit(TOPICS_PER_PAGE);
|
||||
|
||||
//---------- Get some data to start processing
|
||||
|
||||
// Caching anything beyond the first page of any given forum is just wasting ram
|
||||
// users are more likely to search then to browse to page 2
|
||||
if($Page==1) {
|
||||
list($Forum,,,$Stickies) = $Cache->get_value('forums_'.$ForumID);
|
||||
}
|
||||
if(!isset($Forum) || !is_array($Forum)) {
|
||||
$DB->query("SELECT
|
||||
t.ID,
|
||||
t.Title,
|
||||
t.AuthorID,
|
||||
author.Username AS AuthorUsername,
|
||||
t.IsLocked,
|
||||
t.IsSticky,
|
||||
t.NumPosts,
|
||||
t.LastPostID,
|
||||
t.LastPostTime,
|
||||
t.LastPostAuthorID,
|
||||
last_author.Username AS LastPostUsername
|
||||
FROM forums_topics AS t
|
||||
LEFT JOIN users_main AS last_author ON last_author.ID = t.LastPostAuthorID
|
||||
LEFT JOIN users_main AS author ON author.ID = t.AuthorID
|
||||
WHERE t.ForumID = '$ForumID'
|
||||
ORDER BY t.IsSticky DESC, t.LastPostTime DESC
|
||||
LIMIT $Limit"); // Can be cached until someone makes a new post
|
||||
$Forum = $DB->to_array('ID',MYSQLI_ASSOC);
|
||||
if($Page==1) {
|
||||
$DB->query("SELECT COUNT(ID) FROM forums_topics WHERE ForumID='$ForumID' AND IsSticky='1'");
|
||||
list($Stickies) = $DB->next_record();
|
||||
$Cache->cache_value('forums_'.$ForumID, array($Forum,'',0,$Stickies), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($Forums[$ForumID])) {
|
||||
print json_encode(array('status' => 'failure'));
|
||||
die();
|
||||
}
|
||||
// Make sure they're allowed to look at the page
|
||||
if (!check_perms('site_moderate_forums')) {
|
||||
if (isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] === 0) { error(403); }
|
||||
}
|
||||
if($LoggedUser['CustomForums'][$ForumID] != 1 && $Forums[$ForumID]['MinClassRead'] > $LoggedUser['Class']) { error(403); }
|
||||
|
||||
$JsonSpecificRules = array();
|
||||
foreach ($Forums[$ForumID]['SpecificRules'] as $ThreadIDs) {
|
||||
$Thread = get_thread_info($ThreadIDs);
|
||||
$JsonSpecificRules[] = array(
|
||||
'threadId' => $ThreadIDs,
|
||||
'thread' => $Thread['Title']
|
||||
);
|
||||
}
|
||||
|
||||
$Pages=get_pages($Page,$Forums[$ForumID]['NumTopics'],TOPICS_PER_PAGE,9);
|
||||
|
||||
if (count($Forum) == 0) {
|
||||
print
|
||||
json_encode(
|
||||
array(
|
||||
'status' => 'success',
|
||||
'forumName' => $Forums[$ForumID]['Name'],
|
||||
'threads' => array()
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
// forums_last_read_topics is a record of the last post a user read in a topic, and what page that was on
|
||||
$DB->query('SELECT
|
||||
l.TopicID,
|
||||
l.PostID,
|
||||
CEIL((SELECT COUNT(ID) FROM forums_posts WHERE forums_posts.TopicID = l.TopicID AND forums_posts.ID<=l.PostID)/'.$PerPage.') AS Page
|
||||
FROM forums_last_read_topics AS l
|
||||
WHERE TopicID IN('.implode(', ', array_keys($Forum)).') AND
|
||||
UserID=\''.$LoggedUser['ID'].'\'');
|
||||
|
||||
// Turns the result set into a multi-dimensional array, with
|
||||
// forums_last_read_topics.TopicID as the key.
|
||||
// This is done here so we get the benefit of the caching, and we
|
||||
// don't have to make a database query for each topic on the page
|
||||
$LastRead = $DB->to_array('TopicID');
|
||||
|
||||
$JsonTopics = array();
|
||||
foreach ($Forum as $Topic) {
|
||||
list($TopicID, $Title, $AuthorID, $AuthorName, $Locked, $Sticky, $PostCount, $LastID, $LastTime, $LastAuthorID, $LastAuthorName) = array_values($Topic);
|
||||
|
||||
// handle read/unread posts - the reason we can't cache the whole page
|
||||
if((!$Locked || $Sticky) && ((empty($LastRead[$TopicID]) || $LastRead[$TopicID]['PostID']<$LastID) && strtotime($LastTime)>$LoggedUser['CatchupTime'])) {
|
||||
$Read = 'unread';
|
||||
} else {
|
||||
$Read = 'read';
|
||||
}
|
||||
|
||||
$JsonTopics[] = array(
|
||||
'topicId' => $TopicID,
|
||||
'title' => $Title,
|
||||
'authorId' => $AuthorID,
|
||||
'authorName' => $AuthorName,
|
||||
'locked' => $Locked,
|
||||
'sticky' => $Sticky,
|
||||
'postCount' => $PostCount,
|
||||
'lastID' => $LastID,
|
||||
'lastTime' => $LastTime,
|
||||
'lastAuthorId' => $LastAuthorID,
|
||||
'lastAuthorName' => $LastAuthorName,
|
||||
'lastReadPage' => $LastRead[$TopicID]['Page'],
|
||||
'lastReadPostId' => $LastRead[$TopicID]['PostID']
|
||||
);
|
||||
}
|
||||
|
||||
print
|
||||
json_encode(
|
||||
array(
|
||||
'status' => 'success',
|
||||
'response' => array(
|
||||
'forumName' => $Forums[$ForumID]['Name'],
|
||||
'specificRules' => $JsonSpecificRules,
|
||||
'currentPage' => intval($Page),
|
||||
'pages' => ceil($Forums[$ForumID]['NumTopics']/TOPICS_PER_PAGE),
|
||||
'threads' => $JsonTopics
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
?>
|
95
sections/ajax/forum/index.php
Normal file
95
sections/ajax/forum/index.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?
|
||||
// Already done in /sections/ajax/index.php
|
||||
//enforce_login();
|
||||
|
||||
authorize(true);
|
||||
|
||||
if (!empty($LoggedUser['DisableForums'])) {
|
||||
print json_encode(array('status' => 'failure'));
|
||||
}
|
||||
else {
|
||||
include(SERVER_ROOT.'/sections/forums/functions.php');
|
||||
//This variable contains all our lovely forum data
|
||||
if(!$Forums = $Cache->get_value('forums_list')) {
|
||||
$DB->query("SELECT
|
||||
f.ID,
|
||||
f.CategoryID,
|
||||
f.Name,
|
||||
f.Description,
|
||||
f.MinClassRead,
|
||||
f.MinClassWrite,
|
||||
f.MinClassCreate,
|
||||
f.NumTopics,
|
||||
f.NumPosts,
|
||||
f.LastPostID,
|
||||
f.LastPostAuthorID,
|
||||
um.Username,
|
||||
f.LastPostTopicID,
|
||||
f.LastPostTime,
|
||||
COUNT(sr.ThreadID) AS SpecificRules,
|
||||
t.Title,
|
||||
t.IsLocked,
|
||||
t.IsSticky
|
||||
FROM forums AS f
|
||||
LEFT JOIN forums_topics as t ON t.ID = f.LastPostTopicID
|
||||
LEFT JOIN users_main AS um ON um.ID=f.LastPostAuthorID
|
||||
LEFT JOIN forums_specific_rules AS sr ON sr.ForumID = f.ID
|
||||
GROUP BY f.ID
|
||||
ORDER BY f.CategoryID, f.Sort");
|
||||
$Forums = $DB->to_array('ID', MYSQLI_ASSOC, false);
|
||||
foreach($Forums as $ForumID => $Forum) {
|
||||
if(count($Forum['SpecificRules'])) {
|
||||
$DB->query("SELECT ThreadID FROM forums_specific_rules WHERE ForumID = ".$ForumID);
|
||||
$ThreadIDs = $DB->collect('ThreadID');
|
||||
$Forums[$ForumID]['SpecificRules'] = $ThreadIDs;
|
||||
}
|
||||
}
|
||||
unset($ForumID, $Forum);
|
||||
$Cache->cache_value('forums_list', $Forums, 0); //Inf cache.
|
||||
}
|
||||
|
||||
if(empty($_GET['type']) || $_GET['type'] == 'main') {
|
||||
include(SERVER_ROOT.'/sections/ajax/forum/main.php');
|
||||
} else {
|
||||
switch($_GET['type']) {
|
||||
case 'viewforum':
|
||||
include(SERVER_ROOT.'/sections/ajax/forum/forum.php');
|
||||
break;
|
||||
case 'viewthread':
|
||||
include(SERVER_ROOT.'/sections/ajax/forum/thread.php');
|
||||
break;
|
||||
default:
|
||||
print json_encode(array('status' => 'failure'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to get basic information on a forum
|
||||
// Uses class CACHE
|
||||
function get_forum_info($ForumID) {
|
||||
global $DB, $Cache;
|
||||
$Forum = $Cache->get_value('ForumInfo_'.$ForumID);
|
||||
if(!$Forum) {
|
||||
$DB->query("SELECT
|
||||
Name,
|
||||
MinClassRead,
|
||||
MinClassWrite,
|
||||
MinClassCreate,
|
||||
COUNT(forums_topics.ID) AS Topics
|
||||
FROM forums
|
||||
LEFT JOIN forums_topics ON forums_topics.ForumID=forums.ID
|
||||
WHERE forums.ID='$ForumID'
|
||||
GROUP BY ForumID");
|
||||
if($DB->record_count() == 0) {
|
||||
return false;
|
||||
}
|
||||
// Makes an array, with $Forum['Name'], etc.
|
||||
$Forum = $DB->next_record(MYSQLI_ASSOC);
|
||||
|
||||
$Cache->cache_value('ForumInfo_'.$ForumID, $Forum, 86400); // Cache for a day
|
||||
}
|
||||
return $Forum;
|
||||
}
|
||||
|
||||
?>
|
93
sections/ajax/forum/main.php
Normal file
93
sections/ajax/forum/main.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?
|
||||
|
||||
authorize();
|
||||
|
||||
if (isset($LoggedUser['PostsPerPage'])) {
|
||||
$PerPage = $LoggedUser['PostsPerPage'];
|
||||
} else {
|
||||
$PerPage = POSTS_PER_PAGE;
|
||||
}
|
||||
|
||||
//We have to iterate here because if one is empty it breaks the query
|
||||
$TopicIDs = array();
|
||||
foreach($Forums as $Forum) {
|
||||
if (!empty($Forum['LastPostTopicID'])) {
|
||||
$TopicIDs[]=$Forum['LastPostTopicID'];
|
||||
}
|
||||
}
|
||||
|
||||
//Now if we have IDs' we run the query
|
||||
if(!empty($TopicIDs)) {
|
||||
$DB->query("SELECT
|
||||
l.TopicID,
|
||||
l.PostID,
|
||||
CEIL((SELECT COUNT(ID) FROM forums_posts WHERE forums_posts.TopicID = l.TopicID AND forums_posts.ID<=l.PostID)/$PerPage) AS Page
|
||||
FROM forums_last_read_topics AS l
|
||||
WHERE TopicID IN(".implode(',',$TopicIDs).") AND
|
||||
UserID='$LoggedUser[ID]'");
|
||||
$LastRead = $DB->to_array('TopicID', MYSQLI_ASSOC);
|
||||
} else {
|
||||
$LastRead = array();
|
||||
}
|
||||
|
||||
$DB->query("SELECT RestrictedForums FROM users_info WHERE UserID = ".$LoggedUser['ID']);
|
||||
list($RestrictedForums) = $DB->next_record();
|
||||
$RestrictedForums = explode(',', $RestrictedForums);
|
||||
$PermittedForums = array_keys($LoggedUser['PermittedForums']);
|
||||
|
||||
$JsonCategories = array();
|
||||
$JsonCategory = array();
|
||||
$JsonForums = array();
|
||||
foreach ($Forums as $Forum) {
|
||||
list($ForumID, $CategoryID, $ForumName, $ForumDescription, $MinRead, $MinWrite, $MinCreate, $NumTopics, $NumPosts, $LastPostID, $LastAuthorID, $LastPostAuthorName, $LastTopicID, $LastTime, $SpecificRules, $LastTopic, $Locked, $Sticky) = array_values($Forum);
|
||||
if ($LoggedUser['CustomForums'][$ForumID] != 1 && ($MinRead>$LoggedUser['Class'] || array_search($ForumID, $RestrictedForums) !== FALSE)) {
|
||||
continue;
|
||||
}
|
||||
$ForumDescription = display_str($ForumDescription);
|
||||
|
||||
if($CategoryID!=$LastCategoryID) {
|
||||
if (!empty($JsonForums) && !empty($JsonCategory)) {
|
||||
$JsonCategory['forums'] = $JsonForums;
|
||||
$JsonCategories[] = $JsonCategory;
|
||||
}
|
||||
$LastCategoryID = $CategoryID;
|
||||
$JsonCategory = array(
|
||||
'categoryID' => $CategoryID,
|
||||
'categoryName' => $ForumCats[$CategoryID]
|
||||
);
|
||||
$JsonForums = array();
|
||||
}
|
||||
|
||||
if((!$Locked || $Sticky) && $LastPostID != 0 && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID) && strtotime($LastTime)>$LoggedUser['CatchupTime'])) {
|
||||
$Read = 'unread';
|
||||
} else {
|
||||
$Read = 'read';
|
||||
}
|
||||
|
||||
$JsonForums[] = array(
|
||||
'forumId' => $ForumID,
|
||||
'forumName' => $ForumName,
|
||||
'forumDescription' => $ForumDescription,
|
||||
'numTopics' => $NumTopics,
|
||||
'numPosts' => $NumPosts,
|
||||
'lastPostId' => $LastPostID,
|
||||
'lastAuthorId' => $LastAuthorID,
|
||||
'lastPostAuthorName' => $LastPostAuthorName,
|
||||
'lastTopicId' => $LastTopicID,
|
||||
'lastTime' => $LastTime,
|
||||
'specificRules' => $SpecificRules,
|
||||
'lastTopic' => $LastTopic,
|
||||
'read' => $Read,
|
||||
'locked' => $Locked,
|
||||
'sticky' => $Sticky
|
||||
);
|
||||
}
|
||||
|
||||
print json_encode(
|
||||
array(
|
||||
'status' => 'success',
|
||||
'response' => array(
|
||||
'categories' => $JsonCategories
|
||||
)
|
||||
)
|
||||
);
|
257
sections/ajax/forum/thread.php
Normal file
257
sections/ajax/forum/thread.php
Normal file
@ -0,0 +1,257 @@
|
||||
<?
|
||||
|
||||
authorize();
|
||||
|
||||
//TODO: Normalize thread_*_info don't need to waste all that ram on things that are already in other caches
|
||||
/**********|| Page to show individual threads || ********************************\
|
||||
|
||||
Things to expect in $_GET:
|
||||
ThreadID: ID of the forum curently being browsed
|
||||
page: The page the user's on.
|
||||
page = 1 is the same as no page
|
||||
|
||||
********************************************************************************/
|
||||
|
||||
//---------- Things to sort out before it can start printing/generating content
|
||||
|
||||
include(SERVER_ROOT.'/classes/class_text.php');
|
||||
$Text = new TEXT;
|
||||
|
||||
// Check for lame SQL injection attempts
|
||||
if(!isset($_GET['threadid']) || !is_number($_GET['threadid'])) {
|
||||
if(isset($_GET['topicid']) && is_number($_GET['topicid'])) {
|
||||
$ThreadID = $_GET['topicid'];
|
||||
}
|
||||
elseif(isset($_GET['postid']) && is_number($_GET['postid'])) {
|
||||
$DB->query("SELECT TopicID FROM forums_posts WHERE ID = $_GET[postid]");
|
||||
list($ThreadID) = $DB->next_record();
|
||||
if($ThreadID) {
|
||||
header("Location: ajax.php?action=forum&type=viewthread&threadid=$ThreadID&postid=$_GET[postid]");
|
||||
die();
|
||||
} else {
|
||||
print json_encode(array('status' => 'failure'));
|
||||
}
|
||||
} else {
|
||||
print json_encode(array('status' => 'failure'));
|
||||
}
|
||||
} else {
|
||||
$ThreadID = $_GET['threadid'];
|
||||
}
|
||||
|
||||
if (isset($_GET['pp'])) {
|
||||
$PerPage = $_GET['pp'];
|
||||
}
|
||||
else if (isset($LoggedUser['PostsPerPage'])) {
|
||||
$PerPage = $LoggedUser['PostsPerPage'];
|
||||
} else {
|
||||
$PerPage = POSTS_PER_PAGE;
|
||||
}
|
||||
|
||||
//---------- Get some data to start processing
|
||||
|
||||
// Thread information, constant across all pages
|
||||
$ThreadInfo = get_thread_info($ThreadID, true, true);
|
||||
$ForumID = $ThreadInfo['ForumID'];
|
||||
|
||||
// Make sure they're allowed to look at the page
|
||||
if(!check_forumperm($ForumID)) {
|
||||
print json_encode(array('status' => 'failure'));
|
||||
}
|
||||
|
||||
//Post links utilize the catalogue & key params to prevent issues with custom posts per page
|
||||
if($ThreadInfo['Posts'] > $PerPage) {
|
||||
if(isset($_GET['post']) && is_number($_GET['post'])) {
|
||||
$PostNum = $_GET['post'];
|
||||
} elseif(isset($_GET['postid']) && is_number($_GET['postid'])) {
|
||||
$DB->query("SELECT COUNT(ID) FROM forums_posts WHERE TopicID = $ThreadID AND ID <= $_GET[postid]");
|
||||
list($PostNum) = $DB->next_record();
|
||||
} else {
|
||||
$PostNum = 1;
|
||||
}
|
||||
} else {
|
||||
$PostNum = 1;
|
||||
}
|
||||
list($Page,$Limit) = page_limit($PerPage, min($ThreadInfo['Posts'],$PostNum));
|
||||
list($CatalogueID,$CatalogueLimit) = catalogue_limit($Page,$PerPage,THREAD_CATALOGUE);
|
||||
|
||||
// Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
|
||||
if(!$Catalogue = $Cache->get_value('thread_'.$ThreadID.'_catalogue_'.$CatalogueID)) {
|
||||
$DB->query("SELECT
|
||||
p.ID,
|
||||
p.AuthorID,
|
||||
p.AddedTime,
|
||||
p.Body,
|
||||
p.EditedUserID,
|
||||
p.EditedTime,
|
||||
ed.Username
|
||||
FROM forums_posts as p
|
||||
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
|
||||
WHERE p.TopicID = '$ThreadID' AND p.ID != '".$ThreadInfo['StickyPostID']."'
|
||||
LIMIT $CatalogueLimit");
|
||||
$Catalogue = $DB->to_array(false,MYSQLI_ASSOC);
|
||||
if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
|
||||
$Cache->cache_value('thread_'.$ThreadID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
|
||||
}
|
||||
}
|
||||
$Thread = catalogue_select($Catalogue,$Page,$PerPage,THREAD_CATALOGUE);
|
||||
|
||||
$LastPost = end($Thread);
|
||||
$LastPost = $LastPost['ID'];
|
||||
reset($Thread);
|
||||
|
||||
//Handle last read
|
||||
if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
|
||||
$DB->query("SELECT PostID From forums_last_read_topics WHERE UserID='$LoggedUser[ID]' AND TopicID='$ThreadID'");
|
||||
list($LastRead) = $DB->next_record();
|
||||
if($LastRead < $LastPost) {
|
||||
$DB->query("INSERT INTO forums_last_read_topics
|
||||
(UserID, TopicID, PostID) VALUES
|
||||
('$LoggedUser[ID]', '".$ThreadID ."', '".db_string($LastPost)."')
|
||||
ON DUPLICATE KEY UPDATE PostID='$LastPost'");
|
||||
}
|
||||
}
|
||||
|
||||
//Handle subscriptions
|
||||
if(($UserSubscriptions = $Cache->get_value('subscriptions_user_'.$LoggedUser['ID'])) === FALSE) {
|
||||
$DB->query("SELECT TopicID FROM users_subscriptions WHERE UserID = '$LoggedUser[ID]'");
|
||||
$UserSubscriptions = $DB->collect(0);
|
||||
$Cache->cache_value('subscriptions_user_'.$LoggedUser['ID'],$UserSubscriptions,0);
|
||||
}
|
||||
|
||||
if(empty($UserSubscriptions)) {
|
||||
$UserSubscriptions = array();
|
||||
}
|
||||
|
||||
if(in_array($ThreadID, $UserSubscriptions)) {
|
||||
$Cache->delete_value('subscriptions_user_new_'.$LoggedUser['ID']);
|
||||
}
|
||||
|
||||
$JsonPoll = array();
|
||||
if ($ThreadInfo['NoPoll'] == 0) {
|
||||
if (!list($Question,$Answers,$Votes,$Featured,$Closed) = $Cache->get_value('polls_'.$ThreadID)) {
|
||||
$DB->query("SELECT Question, Answers, Featured, Closed FROM forums_polls WHERE TopicID='".$ThreadID."'");
|
||||
list($Question, $Answers, $Featured, $Closed) = $DB->next_record(MYSQLI_NUM, array(1));
|
||||
$Answers = unserialize($Answers);
|
||||
$DB->query("SELECT Vote, COUNT(UserID) FROM forums_polls_votes WHERE TopicID='$ThreadID' GROUP BY Vote");
|
||||
$VoteArray = $DB->to_array(false, MYSQLI_NUM);
|
||||
|
||||
$Votes = array();
|
||||
foreach ($VoteArray as $VoteSet) {
|
||||
list($Key,$Value) = $VoteSet;
|
||||
$Votes[$Key] = $Value;
|
||||
}
|
||||
|
||||
foreach(array_keys($Answers) as $i) {
|
||||
if (!isset($Votes[$i])) {
|
||||
$Votes[$i] = 0;
|
||||
}
|
||||
}
|
||||
$Cache->cache_value('polls_'.$ThreadID, array($Question,$Answers,$Votes,$Featured,$Closed), 0);
|
||||
}
|
||||
|
||||
if (!empty($Votes)) {
|
||||
$TotalVotes = array_sum($Votes);
|
||||
$MaxVotes = max($Votes);
|
||||
} else {
|
||||
$TotalVotes = 0;
|
||||
$MaxVotes = 0;
|
||||
}
|
||||
|
||||
$RevealVoters = in_array($ForumID, $ForumsRevealVoters);
|
||||
//Polls lose the you voted arrow thingy
|
||||
$DB->query("SELECT Vote FROM forums_polls_votes WHERE UserID='".$LoggedUser['ID']."' AND TopicID='$ThreadID'");
|
||||
list($UserResponse) = $DB->next_record();
|
||||
if (!empty($UserResponse) && $UserResponse != 0) {
|
||||
$Answers[$UserResponse] = '» '.$Answers[$UserResponse];
|
||||
} else {
|
||||
if(!empty($UserResponse) && $RevealVoters) {
|
||||
$Answers[$UserResponse] = '» '.$Answers[$UserResponse];
|
||||
}
|
||||
}
|
||||
|
||||
$JsonPoll['closed'] = $Closed;
|
||||
$JsonPoll['featured'] = $Featured;
|
||||
$JsonPoll['question'] = $Question;
|
||||
$JsonPoll['maxVotes'] = $MaxVotes;
|
||||
$JsonPoll['totalVotes'] = $TotalVotes;
|
||||
$JsonPollAnswers = array();
|
||||
|
||||
foreach($Answers as $i => $Answer) {
|
||||
if (!empty($Votes[$i]) && $TotalVotes > 0) {
|
||||
$Ratio = $Votes[$i]/$MaxVotes;
|
||||
$Percent = $Votes[$i]/$TotalVotes;
|
||||
} else {
|
||||
$Ratio=0;
|
||||
$Percent=0;
|
||||
}
|
||||
$JsonPollAnswers[] = array(
|
||||
'answer' => $Answer,
|
||||
'ratio' => $Ratio,
|
||||
'percent' => $Percent
|
||||
);
|
||||
}
|
||||
|
||||
if ($UserResponse !== null || $Closed || $ThreadInfo['IsLocked'] || $LoggedUser['Class'] < $Forums[$ForumID]['MinClassWrite']) {
|
||||
$JsonPoll['voted'] = True;
|
||||
} else {
|
||||
$JsonPoll['voted'] = False;
|
||||
}
|
||||
|
||||
$JsonPoll['answers'] = $JsonPollAnswers;
|
||||
}
|
||||
|
||||
//Sqeeze in stickypost
|
||||
if($ThreadInfo['StickyPostID']) {
|
||||
if($ThreadInfo['StickyPostID'] != $Thread[0]['ID']) {
|
||||
array_unshift($Thread, $ThreadInfo['StickyPost']);
|
||||
}
|
||||
if($ThreadInfo['StickyPostID'] != $Thread[count($Thread)-1]['ID']) {
|
||||
$Thread[] = $ThreadInfo['StickyPost'];
|
||||
}
|
||||
}
|
||||
|
||||
$JsonPosts = array();
|
||||
foreach ($Thread as $Key => $Post) {
|
||||
list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
|
||||
list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(user_info($AuthorID));
|
||||
$JsonPosts[] = array(
|
||||
'postId' => $PostID,
|
||||
'addedTime' => $AddedTime,
|
||||
'body' => $Text->full_format($Body),
|
||||
'editedUserId' => $EditedUserID,
|
||||
'editedTime' => $EditedTime,
|
||||
'editedUsername' => $EditedUsername,
|
||||
'author' => array(
|
||||
'authorId' => $AuthorID,
|
||||
'authorName' => $Username,
|
||||
'paranoia' => $Paranoia,
|
||||
'artist' => $Artist,
|
||||
'donor' => $Donor,
|
||||
'warned' => $Warned,
|
||||
'avatar' => $Avatar,
|
||||
'enabled' => $Enabled == 2 ? false : true,
|
||||
'userTitle' => $UserTitle
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
print
|
||||
json_encode(
|
||||
array(
|
||||
'status' => 'success',
|
||||
'response' => array(
|
||||
'forumId' => $ForumID,
|
||||
'forumName' => $Forums[$ForumID]['Name'],
|
||||
'threadId' => $ThreadID,
|
||||
'threadTitle' => $ThreadInfo['Title'],
|
||||
'subscribed' => in_array($ThreadID, $UserSubscriptions),
|
||||
'locked' => $ThreadInfo['IsLocked'],
|
||||
'sticky' => $ThreadInfo['IsSticky'],
|
||||
'currentPage' => intval($Page),
|
||||
'pages' => ceil($ThreadInfo['Posts']/$PerPage),
|
||||
'poll' => $JsonPoll,
|
||||
'posts' => $JsonPosts
|
||||
)
|
||||
)
|
||||
);
|
@ -103,7 +103,7 @@
|
||||
array(
|
||||
'status' => 'success',
|
||||
'response' => array(
|
||||
'currentPage' => $Page,
|
||||
'currentPage' => intval($Page),
|
||||
'pages' => ceil($NumResults/MESSAGES_PER_PAGE),
|
||||
'messages' => $JsonMessages
|
||||
)
|
||||
|
@ -38,6 +38,12 @@
|
||||
case 'torrentgroup':
|
||||
require('torrentgroup.php');
|
||||
break;
|
||||
case 'user':
|
||||
require(SERVER_ROOT.'/sections/ajax/user.php');
|
||||
break;
|
||||
case 'forum':
|
||||
require(SERVER_ROOT.'/sections/ajax/forum/index.php');
|
||||
break;
|
||||
case 'top10':
|
||||
require(SERVER_ROOT.'/sections/ajax/top10/index.php');
|
||||
break;
|
||||
@ -53,6 +59,12 @@
|
||||
case 'index':
|
||||
require(SERVER_ROOT.'/sections/ajax/info.php');
|
||||
break;
|
||||
case 'usersearch':
|
||||
require(SERVER_ROOT.'/sections/ajax/usersearch.php');
|
||||
break;
|
||||
case 'bookmarks':
|
||||
require(SERVER_ROOT.'/sections/ajax/bookmarks.php');
|
||||
break;
|
||||
default:
|
||||
// If they're screwing around with the query string
|
||||
error(403);
|
||||
|
@ -3,34 +3,32 @@
|
||||
|
||||
//authorize(true);
|
||||
|
||||
$UserID == $LoggedUser['ID'];
|
||||
global $DB, $Cache;
|
||||
$HeavyInfo = $Cache->get_value('user_info_heavy_'.$UserID);
|
||||
|
||||
global $DB, $Cache;
|
||||
$HeavyInfo = $Cache->get_value('user_info_heavy_'.$UserID);
|
||||
$DB->query("SELECT
|
||||
m.Username,
|
||||
m.torrent_pass,
|
||||
i.AuthKey,
|
||||
Uploaded AS BytesUploaded,
|
||||
Downloaded AS BytesDownloaded,
|
||||
RequiredRatio,
|
||||
p.Level AS Class
|
||||
FROM users_main AS m
|
||||
INNER JOIN users_info AS i ON i.UserID=m.ID
|
||||
LEFT JOIN permissions AS p ON p.ID=m.PermissionID
|
||||
WHERE m.ID='$UserID'");
|
||||
|
||||
$DB->query("SELECT
|
||||
m.Username,
|
||||
m.torrent_pass,
|
||||
i.AuthKey,
|
||||
Uploaded AS BytesUploaded,
|
||||
Downloaded AS BytesDownloaded,
|
||||
RequiredRatio,
|
||||
p.Level AS Class
|
||||
FROM users_main AS m
|
||||
INNER JOIN users_info AS i ON i.UserID=m.ID
|
||||
LEFT JOIN permissions AS p ON p.ID=m.PermissionID
|
||||
WHERE m.ID='$UserID'");
|
||||
|
||||
list($Username,$torrent_pass,$AuthKey,$Uploaded,$Downloaded,$RequiredRatio,$Class) = $DB->next_record(MYSQLI_NUM, array(9,11));
|
||||
list($Username,$torrent_pass,$AuthKey,$Uploaded,$Downloaded,$RequiredRatio,$Class) = $DB->next_record(MYSQLI_NUM, array(9,11));
|
||||
|
||||
//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
|
||||
if($Uploaded == 0 && $Downloaded == 0) {
|
||||
$Ratio = '0';
|
||||
} elseif($Downloaded == 0) {
|
||||
$Ratio = '-1';}
|
||||
else {
|
||||
$Ratio = number_format(max($Uploaded/$Downloaded-0.005,0), 2); //Subtract .005 to floor to 2 decimals
|
||||
if($Uploaded == 0 && $Downloaded == 0) {
|
||||
$Ratio = '0';
|
||||
} elseif($Downloaded == 0) {
|
||||
$Ratio = '-1';
|
||||
} else {
|
||||
$Ratio = number_format(max($Uploaded/$Downloaded-0.005,0), 2); //Subtract .005 to floor to 2 decimals
|
||||
}
|
||||
|
||||
|
||||
@ -55,5 +53,4 @@
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
?>
|
||||
|
@ -13,6 +13,7 @@
|
||||
'status' => 'failure'
|
||||
)
|
||||
);
|
||||
die();
|
||||
}
|
||||
|
||||
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
|
||||
|
271
sections/ajax/user.php
Normal file
271
sections/ajax/user.php
Normal file
@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
authorize();
|
||||
|
||||
require(SERVER_ROOT.'/sections/requests/functions.php');
|
||||
|
||||
if (empty($_GET['id']) || !is_numeric($_GET['id'])) { error(0); }
|
||||
$UserID = $_GET['id'];
|
||||
|
||||
|
||||
|
||||
if($UserID == $LoggedUser['ID']) {
|
||||
$OwnProfile = true;
|
||||
} else {
|
||||
$OwnProfile = false;
|
||||
}
|
||||
|
||||
// Always view as a normal user.
|
||||
$DB->query("SELECT
|
||||
m.Username,
|
||||
m.Email,
|
||||
m.LastAccess,
|
||||
m.IP,
|
||||
p.Level AS Class,
|
||||
m.Uploaded,
|
||||
m.Downloaded,
|
||||
m.RequiredRatio,
|
||||
m.Enabled,
|
||||
m.Paranoia,
|
||||
m.Invites,
|
||||
m.Title,
|
||||
m.torrent_pass,
|
||||
m.can_leech,
|
||||
i.JoinDate,
|
||||
i.Info,
|
||||
i.Avatar,
|
||||
i.Country,
|
||||
i.Donor,
|
||||
i.Warned,
|
||||
COUNT(posts.id) AS ForumPosts,
|
||||
i.Inviter,
|
||||
i.DisableInvites,
|
||||
inviter.username
|
||||
FROM users_main AS m
|
||||
JOIN users_info AS i ON i.UserID = m.ID
|
||||
LEFT JOIN permissions AS p ON p.ID=m.PermissionID
|
||||
LEFT JOIN users_main AS inviter ON i.Inviter = inviter.ID
|
||||
LEFT JOIN forums_posts AS posts ON posts.AuthorID = m.ID
|
||||
WHERE m.ID = $UserID GROUP BY AuthorID");
|
||||
|
||||
//TODO: Handle this more gracefully.
|
||||
if ($DB->record_count() == 0) { // If user doesn't exist
|
||||
die();
|
||||
//header("Location: log.php?search=User+".$UserID);
|
||||
}
|
||||
|
||||
list($Username, $Email, $LastAccess, $IP, $Class, $Uploaded, $Downloaded, $RequiredRatio, $Enabled, $Paranoia, $Invites, $CustomTitle, $torrent_pass, $DisableLeech, $JoinDate, $Info, $Avatar, $Country, $Donor, $Warned, $ForumPosts, $InviterID, $DisableInvites, $InviterName, $RatioWatchEnds, $RatioWatchDownload) = $DB->next_record(MYSQLI_NUM, array(9,11));
|
||||
|
||||
$Paranoia = unserialize($Paranoia);
|
||||
if(!is_array($Paranoia)) {
|
||||
$Paranoia = array();
|
||||
}
|
||||
$ParanoiaLevel = 0;
|
||||
foreach($Paranoia as $P) {
|
||||
$ParanoiaLevel++;
|
||||
if(strpos($P, '+')) {
|
||||
$ParanoiaLevel++;
|
||||
}
|
||||
}
|
||||
|
||||
// Raw time is better for JSON.
|
||||
//$JoinedDate = time_diff($JoinDate);
|
||||
//$LastAccess = time_diff($LastAccess);
|
||||
|
||||
function check_paranoia_here($Setting) {
|
||||
global $Paranoia, $Class, $UserID;
|
||||
return check_paranoia($Setting, $Paranoia, $Class, $UserID);
|
||||
}
|
||||
|
||||
$Friend = false;
|
||||
$DB->query("SELECT FriendID FROM friends WHERE UserID='$LoggedUser[ID]' AND FriendID='$UserID'");
|
||||
if($DB->record_count() != 0) {
|
||||
$Friend = true;
|
||||
}
|
||||
|
||||
if (check_paranoia_here('requestsfilled_count') || check_paranoia_here('requestsfilled_bounty')) {
|
||||
$DB->query("SELECT COUNT(DISTINCT r.ID), SUM(rv.Bounty) FROM requests AS r LEFT JOIN requests_votes AS rv ON r.ID=rv.RequestID WHERE r.FillerID = ".$UserID);
|
||||
list($RequestsFilled, $TotalBounty) = $DB->next_record();
|
||||
$DB->query("SELECT COUNT(rv.RequestID), SUM(rv.Bounty) FROM requests_votes AS rv WHERE rv.UserID = ".$UserID);
|
||||
list($RequestsVoted, $TotalSpent) = $DB->next_record();
|
||||
|
||||
$DB->query("SELECT COUNT(ID) FROM torrents WHERE UserID='$UserID'");
|
||||
list($Uploads) = $DB->next_record();
|
||||
} else {
|
||||
$RequestsVoted = 0;
|
||||
$TotalSpent = 0;
|
||||
}
|
||||
if(check_paranoia_here('uploads+')) {
|
||||
$DB->query("SELECT COUNT(ID) FROM torrents WHERE UserID='$UserID'");
|
||||
list($Uploads) = $DB->next_record();
|
||||
} else {
|
||||
$Uploads = 0;
|
||||
}
|
||||
|
||||
if (check_paranoia_here('artistsadded')) {
|
||||
$DB->query("SELECT COUNT(ta.ArtistID) FROM torrents_artists AS ta WHERE ta.UserID = ".$UserID);
|
||||
list($ArtistsAdded) = $DB->next_record();
|
||||
} else {
|
||||
$ArtistsAdded = 0;
|
||||
}
|
||||
|
||||
// Do the ranks.
|
||||
include(SERVER_ROOT.'/classes/class_user_rank.php');
|
||||
$Rank = new USER_RANK;
|
||||
|
||||
if (check_paranoia_here('uploaded')) {
|
||||
$UploadedRank = $Rank->get_rank('uploaded', $Uploaded);
|
||||
}
|
||||
if (check_paranoia_here('downloaded')) {
|
||||
$DownloadedRank = $Rank->get_rank('downloaded', $Downloaded);
|
||||
}
|
||||
if (check_paranoia_here('uploads+')) {
|
||||
$UploadsRank = $Rank->get_rank('uploads', $Uploads);
|
||||
}
|
||||
if (check_paranoia_here('requestsfilled_count')) {
|
||||
$RequestRank = $Rank->get_rank('requests', $RequestsFilled);
|
||||
}
|
||||
$PostRank = $Rank->get_rank('posts', $ForumPosts);
|
||||
if (check_paranoia_here('requestsvoted_bounty')) {
|
||||
$BountyRank = $Rank->get_rank('bounty', $TotalSpent);
|
||||
}
|
||||
if (check_paranoia_here('artistsadded')) {
|
||||
$ArtistsRank = $Rank->get_rank('artists', $ArtistsAdded);
|
||||
}
|
||||
|
||||
if($Downloaded == 0) {
|
||||
$Ratio = 1;
|
||||
} elseif($Uploaded == 0) {
|
||||
$Ratio = 0.5;
|
||||
} else {
|
||||
$Ratio = round($Uploaded/$Downloaded, 2);
|
||||
}
|
||||
if (!check_paranoia_here(array('uploaded', 'downloaded', 'uploads+', 'requestsfilled_count', 'requestsvoted_bounty', 'artistsadded'))) {
|
||||
$OverallRank = $Rank->overall_score($UploadedRank, $DownloadedRank, $UploadsRank, $RequestRank, $PostRank, $BountyRank, $ArtistsRank, $Ratio);
|
||||
}
|
||||
|
||||
// Community section
|
||||
$DB->query("SELECT COUNT(x.uid), COUNT(DISTINCT x.fid) FROM xbt_snatched AS x INNER JOIN torrents AS t ON t.ID=x.fid WHERE x.uid='$UserID'");
|
||||
list($Snatched, $UniqueSnatched) = $DB->next_record();
|
||||
|
||||
if (check_paranoia_here(array('torrentcomments', 'torrentcomments+'))) {
|
||||
$DB->query("SELECT COUNT(ID) FROM torrents_comments WHERE AuthorID='$UserID'");
|
||||
list($NumComments) = $DB->next_record();
|
||||
}
|
||||
|
||||
if (check_paranoia_here(array('collages', 'collages+'))) {
|
||||
$DB->query("SELECT COUNT(ID) FROM collages WHERE Deleted='0' AND UserID='$UserID'");
|
||||
list($NumCollages) = $DB->next_record();
|
||||
}
|
||||
|
||||
if (check_paranoia_here(array('collagecontribs', 'collagecontribs+'))) {
|
||||
$DB->query("SELECT COUNT(DISTINCT CollageID) FROM collages_torrents AS ct JOIN collages ON CollageID = ID WHERE Deleted='0' AND ct.UserID='$UserID'");
|
||||
list($NumCollageContribs) = $DB->next_record();
|
||||
}
|
||||
|
||||
if (check_paranoia_here(array('uniquegroups', 'uniquegroups+'))) {
|
||||
$DB->query("SELECT COUNT(DISTINCT GroupID) FROM torrents WHERE UserID = '$UserID'");
|
||||
list($UniqueGroups) = $DB->next_record();
|
||||
}
|
||||
|
||||
if (check_paranoia_here(array('perfectflacs', 'perfectflacs+'))) {
|
||||
$DB->query("SELECT COUNT(ID) FROM torrents WHERE ((LogScore = 100 AND Format = 'FLAC') OR (Media = 'Vinyl' AND Format = 'FLAC') OR (Media = 'WEB' AND Format = 'FLAC') OR (Media = 'DVD' AND Format = 'FLAC') OR (Media = 'Soundboard' AND Format = 'FLAC') OR (Media = 'Cassette' AND Format = 'FLAC') OR (Media = 'SACD' AND Format = 'FLAC') OR (Media = 'Blu-ray' AND Format = 'FLAC') OR (Media = 'DAT' AND Format = 'FLAC')) AND UserID = '$UserID'");
|
||||
list($PerfectFLACs) = $DB->next_record();
|
||||
}
|
||||
|
||||
if (check_paranoia_here('seeding+')) {
|
||||
$DB->query("SELECT COUNT(x.uid) FROM xbt_files_users AS x INNER JOIN torrents AS t ON t.ID=x.fid WHERE x.uid='$UserID' AND x.remaining=0");
|
||||
list($Seeding) = $DB->next_record();
|
||||
}
|
||||
|
||||
if (check_paranoia_here('leeching+')) {
|
||||
$DB->query("SELECT COUNT(x.uid) FROM xbt_files_users AS x INNER JOIN torrents AS t ON t.ID=x.fid WHERE x.uid='$UserID' AND x.remaining>0");
|
||||
list($Leeching) = $DB->next_record();
|
||||
}
|
||||
|
||||
if(check_paranoia_here('invitedcount')) {
|
||||
$DB->query("SELECT COUNT(UserID) FROM users_info WHERE Inviter='$UserID'");
|
||||
list($Invited) = $DB->next_record();
|
||||
}
|
||||
|
||||
if (!$OwnProfile) {
|
||||
unset($torrent_pass);
|
||||
}
|
||||
|
||||
// Run through some paranoia stuff to decide what we can send out.
|
||||
if (!check_paranoia_here('lastseen')) {
|
||||
unset($LastAccess);
|
||||
}
|
||||
if (!check_paranoia_here('uploaded')) {
|
||||
unset($Uploaded);
|
||||
}
|
||||
if (!check_paranoia_here('downloaded')) {
|
||||
unset($Downloaded);
|
||||
}
|
||||
if (isset($RequiredRatio) && !check_paranoia_here('requiredratio')) {
|
||||
unset($RequiredRatio);
|
||||
}
|
||||
if($ParanoiaLevel == 0) {
|
||||
$ParanoiaLevelText = 'Off';
|
||||
} elseif($ParanoiaLevel == 1) {
|
||||
$ParanoiaLevelText = 'Very Low';
|
||||
} elseif($ParanoiaLevel <= 5) {
|
||||
$ParanoiaLevelText = 'Low';
|
||||
} elseif($ParanoiaLevel <= 20) {
|
||||
$ParanoiaLevelText = 'High';
|
||||
} else {
|
||||
$ParanoiaLevelText = 'Very high';
|
||||
}
|
||||
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
print json_encode(array('status' => 'success',
|
||||
'response' => array(
|
||||
'username' => $Username,
|
||||
'avatar' => $Avatar,
|
||||
'isFriend' => $Friend,
|
||||
'stats' => array(
|
||||
'joinedDate' => $JoinDate,
|
||||
'lastAccess' => $LastAccess,
|
||||
'uploaded' => $Uploaded,
|
||||
'downloaded' => $Downloaded,
|
||||
'ratio' => $Ratio,
|
||||
'requiredRatio' => $RequiredRatio
|
||||
),
|
||||
'ranks' => array(
|
||||
'uploaded' => $UploadedRank,
|
||||
'downloaded' => $DownloadedRank,
|
||||
'uploads' => $UploadsRank,
|
||||
'requests' => $RequestRank,
|
||||
'bounty' => $BountyRank,
|
||||
'posts' => $PostRank,
|
||||
'artists' => $ArtistsRank,
|
||||
'overall' => $OverallRank
|
||||
),
|
||||
'personal' => array(
|
||||
'class' => $ClassLevels[$Class]['Name'],
|
||||
'paranoia' => $ParanoiaLevel,
|
||||
'paranoiaText' => $ParanoiaLevelText,
|
||||
'donor' => $Donor,
|
||||
'warned' => ($Warned!='0000-00-00 00:00:00'),
|
||||
'enabled' => ($Enabled == '1' || $Enabled == '0' || !$Enabled),
|
||||
'passkey' => $torrent_pass
|
||||
),
|
||||
'community' => array(
|
||||
'posts' => $ForumPosts,
|
||||
'torrentComments' => $NumComments,
|
||||
'collagesStarted' => $NumCollages,
|
||||
'collagesContrib' => $NumCollageContribs,
|
||||
'requestsFilled' => $RequestsFilled,
|
||||
'requestsVoted' => $RequestsVoted,
|
||||
'uploaded' => $Uploads,
|
||||
'groups' => $UniqueGroups,
|
||||
'seeding' => $Seeding,
|
||||
'leeching' => $Leeching,
|
||||
'snatched' => $Snatched,
|
||||
'invited' => $Invited
|
||||
)
|
||||
)
|
||||
)
|
||||
); // <- He's sad.
|
||||
?>
|
60
sections/ajax/usersearch.php
Normal file
60
sections/ajax/usersearch.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?
|
||||
/**********************************************************************
|
||||
*>>>>>>>>>>>>>>>>>>>>>>>>>>> User search <<<<<<<<<<<<<<<<<<<<<<<<<<<<*
|
||||
**********************************************************************/
|
||||
authorize(true);
|
||||
|
||||
if (!empty($_GET['search'])) {
|
||||
|
||||
$_GET['username'] = $_GET['search'];
|
||||
}
|
||||
|
||||
define('USERS_PER_PAGE', 30);
|
||||
|
||||
if(isset($_GET['username'])){
|
||||
$_GET['username'] = trim($_GET['username']);
|
||||
|
||||
list($Page,$Limit) = page_limit(USERS_PER_PAGE);
|
||||
$DB->query("SELECT SQL_CALC_FOUND_ROWS
|
||||
ID,
|
||||
Username,
|
||||
Enabled,
|
||||
PermissionID,
|
||||
Donor,
|
||||
Warned
|
||||
FROM users_main AS um
|
||||
JOIN users_info AS ui ON ui.UserID=um.ID
|
||||
WHERE Username LIKE '%".db_string($_GET['username'])."%'
|
||||
ORDER BY Username
|
||||
LIMIT $Limit");
|
||||
$Results = $DB->to_array();
|
||||
$DB->query('SELECT FOUND_ROWS();');
|
||||
list($NumResults) = $DB->next_record();
|
||||
|
||||
}
|
||||
|
||||
$JsonUsers = array();
|
||||
foreach($Results as $Result) {
|
||||
list($UserID, $Username, $Enabled, $PermissionID, $Donor, $Warned) = $Result;
|
||||
|
||||
$JsonUsers[] = array(
|
||||
'userId' => $UserID,
|
||||
'username' => $Username,
|
||||
'donor' => $Donor,
|
||||
'warned' => $Warned,
|
||||
'enabled' => ($Enabled == 2 ? false : true),
|
||||
'class' => make_class_string($PermissionID)
|
||||
);
|
||||
}
|
||||
|
||||
print
|
||||
json_encode(
|
||||
array(
|
||||
'status' => 'success',
|
||||
'response' => array(
|
||||
'currentPage' => $Page,
|
||||
'pages' => ceil($NumResults/USERS_PER_PAGE),
|
||||
'results' => $JsonUsers
|
||||
)
|
||||
)
|
||||
);
|
Loading…
Reference in New Issue
Block a user