Gazelle/sections/ajax/tcomments.php

92 lines
3.0 KiB
PHP
Raw Normal View History

2013-05-28 08:01:02 +00:00
<?php
2012-06-27 08:00:15 +00:00
2013-05-27 08:00:58 +00:00
include(SERVER_ROOT.'/classes/text.class.php');
2012-06-27 08:00:15 +00:00
$Text = new TEXT;
$GroupID=ceil($_GET['id']);
$Results = $Cache->get_value('torrent_comments_'.$GroupID);
2013-05-05 08:00:31 +00:00
if ($Results === false) {
$DB->query("
SELECT
2012-06-27 08:00:15 +00:00
COUNT(c.ID)
2013-05-05 08:00:31 +00:00
FROM torrents_comments as c
WHERE c.GroupID = '$GroupID'");
2012-06-27 08:00:15 +00:00
list($Results) = $DB->next_record();
$Cache->cache_value('torrent_comments_'.$GroupID, $Results, 0);
}
2013-05-05 08:00:31 +00:00
if (isset($_GET['postid']) && is_number($_GET['postid']) && $Results > TORRENT_COMMENTS_PER_PAGE) {
$DB->query("
SELECT COUNT(ID)
FROM torrents_comments
WHERE GroupID = $GroupID
AND ID <= $_GET[postid]");
2012-06-27 08:00:15 +00:00
list($PostNum) = $DB->next_record();
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $PostNum);
2012-06-27 08:00:15 +00:00
} else {
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE, $Results);
2012-06-27 08:00:15 +00:00
}
//Get the cache catalogue
2013-05-05 08:00:31 +00:00
$CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Page - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
$CatalogueLimit = $CatalogueID * THREAD_CATALOGUE . ', ' . THREAD_CATALOGUE;
2012-06-27 08:00:15 +00:00
//---------- Get some data to start processing
// Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
$Catalogue = $Cache->get_value('torrent_comments_'.$GroupID.'_catalogue_'.$CatalogueID);
2013-05-05 08:00:31 +00:00
if ($Catalogue === false) {
$DB->query("
SELECT
2012-06-27 08:00:15 +00:00
c.ID,
c.AuthorID,
c.AddedTime,
c.Body,
c.EditedUserID,
c.EditedTime,
u.Username
2013-05-05 08:00:31 +00:00
FROM torrents_comments as c
2012-06-27 08:00:15 +00:00
LEFT JOIN users_main AS u ON u.ID=c.EditedUserID
2013-05-05 08:00:31 +00:00
WHERE c.GroupID = '$GroupID'
ORDER BY c.ID
LIMIT $CatalogueLimit");
2012-06-27 08:00:15 +00:00
$Catalogue = $DB->to_array(false,MYSQLI_ASSOC);
$Cache->cache_value('torrent_comments_'.$GroupID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
}
//This is a hybrid to reduce the catalogue down to the page elements: We use the page limit % catalogue
2013-05-28 08:01:02 +00:00
$Thread = array_slice($Catalogue, ((TORRENT_COMMENTS_PER_PAGE * $Page - TORRENT_COMMENTS_PER_PAGE) % THREAD_CATALOGUE), TORRENT_COMMENTS_PER_PAGE, true);
2012-06-27 08:00:15 +00:00
//---------- Begin printing
$JsonComments = array();
foreach ($Thread as $Key => $Post) {
list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
2012-10-11 08:00:15 +00:00
list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
2012-06-27 08:00:15 +00:00
$JsonComments[] = array(
'postId' => (int) $PostID,
'addedTime' => $AddedTime,
2012-07-06 08:00:11 +00:00
'bbBody' => $Body,
2012-06-27 08:00:15 +00:00
'body' => $Text->full_format($Body),
'editedUserId' => (int) $EditedUserID,
'editedTime' => $EditedTime,
'editedUsername' => $EditedUsername,
'userinfo' => array(
'authorId' => (int) $AuthorID,
'authorName' => $Username,
'artist' => $Artist == 1,
'donor' => $Donor == 1,
'warned' => ($Warned != '0000-00-00 00:00:00'),
'avatar' => $Avatar,
2013-05-28 08:01:02 +00:00
'enabled' => ($Enabled == 2 ? false : true),
2012-06-27 08:00:15 +00:00
'userTitle' => $UserTitle
)
);
}
2013-04-24 08:00:23 +00:00
json_die("success", array(
2013-05-14 08:00:34 +00:00
'page' => (int) $Page,
'pages' => ceil($Results / TORRENT_COMMENTS_PER_PAGE),
'comments' => $JsonComments
2013-04-24 08:00:23 +00:00
));