2012-07-28 08:00:17 +00:00
|
|
|
<?
|
|
|
|
/*
|
|
|
|
User post history page
|
|
|
|
*/
|
|
|
|
|
2013-04-13 08:00:19 +00:00
|
|
|
function error_out($reason = '') {
|
2013-04-17 08:00:58 +00:00
|
|
|
$error = array('status' => 'failure');
|
|
|
|
if ($reason != '')
|
|
|
|
$error['reason'] = $reason;
|
|
|
|
print $error;
|
|
|
|
die();
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 08:00:19 +00:00
|
|
|
if (!empty($LoggedUser['DisableForums'])) {
|
2013-04-17 08:00:58 +00:00
|
|
|
error_out('You do not have access to the forums!');
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
|
|
|
|
$Text = new TEXT;
|
|
|
|
|
|
|
|
|
|
|
|
$UserID = empty($_GET['userid']) ? $LoggedUser['ID'] : $_GET['userid'];
|
2013-04-13 08:00:19 +00:00
|
|
|
if (!is_number($UserID)) {
|
2013-04-17 08:00:58 +00:00
|
|
|
error_out('User does not exist!');
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($LoggedUser['PostsPerPage'])) {
|
|
|
|
$PerPage = $LoggedUser['PostsPerPage'];
|
|
|
|
} else {
|
|
|
|
$PerPage = POSTS_PER_PAGE;
|
|
|
|
}
|
|
|
|
|
2012-10-11 08:00:15 +00:00
|
|
|
list($Page,$Limit) = Format::page_limit($PerPage);
|
2012-07-28 08:00:17 +00:00
|
|
|
|
2013-05-11 08:00:29 +00:00
|
|
|
$UserInfo = Users::user_info($UserID);
|
|
|
|
extract(array_intersect_key($UserInfo, array_flip(array('Username', 'Enabled', 'Title', 'Avatar', 'Donor', 'Warned'))));
|
2012-07-28 08:00:17 +00:00
|
|
|
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($LoggedUser['CustomForums']) {
|
2012-07-28 08:00:17 +00:00
|
|
|
unset($LoggedUser['CustomForums']['']);
|
|
|
|
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
|
2013-05-15 08:00:54 +00:00
|
|
|
$PermittedForums = implode("','", array_keys($LoggedUser['CustomForums'], 1));
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
$ViewingOwn = ($UserID == $LoggedUser['ID']);
|
|
|
|
$ShowUnread = ($ViewingOwn && (!isset($_GET['showunread']) || !!$_GET['showunread']));
|
|
|
|
$ShowGrouped = ($ViewingOwn && (!isset($_GET['group']) || !!$_GET['group']));
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($ShowGrouped) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql = 'SELECT
|
2013-04-17 08:00:58 +00:00
|
|
|
SQL_CALC_FOUND_ROWS
|
|
|
|
MAX(p.ID) AS ID
|
2012-07-28 08:00:17 +00:00
|
|
|
FROM forums_posts AS p
|
2013-04-17 08:00:58 +00:00
|
|
|
LEFT JOIN forums_topics AS t ON t.ID = p.TopicID';
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($ShowUnread) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql.='
|
2013-04-17 08:00:58 +00:00
|
|
|
LEFT JOIN forums_last_read_topics AS l ON l.TopicID = t.ID AND l.UserID = '.$LoggedUser['ID'];
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
$sql .= '
|
2013-04-17 08:00:58 +00:00
|
|
|
LEFT JOIN forums AS f ON f.ID = t.ForumID
|
2012-07-28 08:00:17 +00:00
|
|
|
WHERE p.AuthorID = '.$UserID.'
|
2013-05-15 08:00:54 +00:00
|
|
|
AND ((f.MinClassRead <= '.$LoggedUser['Class'];
|
2013-04-13 08:00:19 +00:00
|
|
|
if (!empty($RestrictedForums)) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql.='
|
2013-04-17 08:00:58 +00:00
|
|
|
AND f.ID NOT IN (\''.$RestrictedForums.'\')';
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
$sql .= ')';
|
2013-04-13 08:00:19 +00:00
|
|
|
if (!empty($PermittedForums)) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql.='
|
2013-04-17 08:00:58 +00:00
|
|
|
OR f.ID IN (\''.$PermittedForums.'\')';
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
$sql .= ')';
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($ShowUnread) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql .= '
|
2013-04-17 08:00:58 +00:00
|
|
|
AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\')
|
|
|
|
AND (l.PostID<t.LastPostID OR l.PostID IS NULL))';
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
$sql .= '
|
|
|
|
GROUP BY t.ID
|
|
|
|
ORDER BY p.ID DESC LIMIT '.$Limit;
|
|
|
|
$PostIDs = $DB->query($sql);
|
|
|
|
$DB->query("SELECT FOUND_ROWS()");
|
|
|
|
list($Results) = $DB->next_record();
|
|
|
|
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($Results > $PerPage * ($Page - 1)) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$DB->set_query_id($PostIDs);
|
|
|
|
$PostIDs = $DB->collect('ID');
|
|
|
|
$sql = 'SELECT
|
|
|
|
p.ID,
|
|
|
|
p.AddedTime,
|
|
|
|
p.Body,
|
|
|
|
p.EditedUserID,
|
|
|
|
p.EditedTime,
|
|
|
|
ed.Username,
|
|
|
|
p.TopicID,
|
|
|
|
t.Title,
|
|
|
|
t.LastPostID,
|
|
|
|
l.PostID AS LastRead,
|
|
|
|
t.IsLocked,
|
|
|
|
t.IsSticky
|
|
|
|
FROM forums_posts as p
|
2013-04-17 08:00:58 +00:00
|
|
|
LEFT JOIN users_main AS um ON um.ID = p.AuthorID
|
|
|
|
LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID
|
|
|
|
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
|
|
|
|
JOIN forums_topics AS t ON t.ID = p.TopicID
|
|
|
|
JOIN forums AS f ON f.ID = t.ForumID
|
|
|
|
LEFT JOIN forums_last_read_topics AS l ON l.UserID = '.$UserID.' AND l.TopicID = t.ID
|
2012-07-28 08:00:17 +00:00
|
|
|
WHERE p.ID IN ('.implode(',',$PostIDs).')
|
|
|
|
ORDER BY p.ID DESC';
|
|
|
|
$Posts = $DB->query($sql);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$sql = 'SELECT
|
|
|
|
SQL_CALC_FOUND_ROWS';
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($ShowGrouped) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql.=' * FROM (SELECT';
|
|
|
|
}
|
|
|
|
$sql .= '
|
|
|
|
p.ID,
|
|
|
|
p.AddedTime,
|
|
|
|
p.Body,
|
|
|
|
p.EditedUserID,
|
|
|
|
p.EditedTime,
|
|
|
|
ed.Username,
|
|
|
|
p.TopicID,
|
|
|
|
t.Title,
|
|
|
|
t.LastPostID,';
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($UserID == $LoggedUser['ID']) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql .= '
|
|
|
|
l.PostID AS LastRead,';
|
|
|
|
}
|
|
|
|
$sql .= '
|
|
|
|
t.IsLocked,
|
|
|
|
t.IsSticky
|
|
|
|
FROM forums_posts as p
|
2013-04-17 08:00:58 +00:00
|
|
|
LEFT JOIN users_main AS um ON um.ID = p.AuthorID
|
|
|
|
LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID
|
|
|
|
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
|
|
|
|
JOIN forums_topics AS t ON t.ID = p.TopicID
|
|
|
|
JOIN forums AS f ON f.ID = t.ForumID
|
|
|
|
LEFT JOIN forums_last_read_topics AS l ON l.UserID = '.$UserID.' AND l.TopicID = t.ID
|
2012-07-28 08:00:17 +00:00
|
|
|
WHERE p.AuthorID = '.$UserID.'
|
2013-05-15 08:00:54 +00:00
|
|
|
AND ((f.MinClassRead <= '.$LoggedUser['Class'];
|
2012-07-28 08:00:17 +00:00
|
|
|
|
2013-04-13 08:00:19 +00:00
|
|
|
if (!empty($RestrictedForums)) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql.='
|
2013-04-17 08:00:58 +00:00
|
|
|
AND f.ID NOT IN (\''.$RestrictedForums.'\')';
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
2013-05-15 08:00:54 +00:00
|
|
|
$sql .= ')';
|
|
|
|
|
|
|
|
if (!empty($PermittedForums)) {
|
|
|
|
$sql.='
|
|
|
|
OR f.ID IN (\''.$PermittedForums.'\')';
|
|
|
|
}
|
|
|
|
$sql .= ')';
|
2012-07-28 08:00:17 +00:00
|
|
|
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($ShowUnread) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql.='
|
2013-04-17 08:00:58 +00:00
|
|
|
AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\') AND (l.PostID<t.LastPostID OR l.PostID IS NULL)) ';
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql .= '
|
|
|
|
ORDER BY p.ID DESC';
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-13 08:00:19 +00:00
|
|
|
if ($ShowGrouped) {
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql.='
|
|
|
|
) AS sub
|
|
|
|
GROUP BY TopicID ORDER BY ID DESC';
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-07-28 08:00:17 +00:00
|
|
|
$sql.=' LIMIT '.$Limit;
|
|
|
|
$Posts = $DB->query($sql);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-07-28 08:00:17 +00:00
|
|
|
$DB->query("SELECT FOUND_ROWS()");
|
|
|
|
list($Results) = $DB->next_record();
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-07-28 08:00:17 +00:00
|
|
|
$DB->set_query_id($Posts);
|
|
|
|
}
|
|
|
|
|
|
|
|
$JsonResults = array();
|
2013-04-13 08:00:19 +00:00
|
|
|
while (list($PostID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername, $TopicID, $ThreadTitle, $LastPostID, $LastRead, $Locked, $Sticky) = $DB->next_record()) {
|
2013-04-17 08:00:58 +00:00
|
|
|
$JsonResults[] = array(
|
|
|
|
'postId' => (int) $PostID,
|
|
|
|
'topicId' => (int) $TopicID,
|
|
|
|
'threadTitle' => $ThreadTitle,
|
|
|
|
'lastPostId' => (int) $LastPostID,
|
|
|
|
'lastRead' => (int) $LastRead,
|
|
|
|
'locked' => $Locked == 1,
|
|
|
|
'sticky' => $Sticky == 1,
|
|
|
|
'addedTime' => $AddedTime,
|
|
|
|
'body' => $Text->full_format($Body),
|
|
|
|
'bbbody' => $Body,
|
|
|
|
'editedUserId' => (int) $EditedUserID,
|
|
|
|
'editedTime' => $EditedTime,
|
|
|
|
'editedUsername' => $EditedUsername
|
|
|
|
);
|
2012-07-28 08:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print json_encode(
|
2013-04-17 08:00:58 +00:00
|
|
|
array(
|
|
|
|
'status' => 'success',
|
|
|
|
'response' => array(
|
|
|
|
'currentPage' => (int) $Page,
|
|
|
|
'pages' => ceil($Results/$PerPage),
|
|
|
|
'threads' => $JsonResults
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|