Gazelle/sections/userhistory/post_history.php

292 lines
8.1 KiB
PHP
Raw Permalink Normal View History

2013-05-28 08:01:02 +00:00
<?php
2011-03-28 14:21:28 +00:00
/*
User post history page
*/
2013-04-20 08:01:01 +00:00
if (!empty($LoggedUser['DisableForums'])) {
2011-03-28 14:21:28 +00:00
error(403);
}
$UserID = empty($_GET['userid']) ? $LoggedUser['ID'] : $_GET['userid'];
2013-04-20 08:01:01 +00:00
if (!is_number($UserID)) {
2011-03-28 14:21:28 +00:00
error(0);
}
if (isset($LoggedUser['PostsPerPage'])) {
$PerPage = $LoggedUser['PostsPerPage'];
} else {
$PerPage = POSTS_PER_PAGE;
}
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit($PerPage);
2011-03-28 14:21:28 +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'))));
2011-03-28 14:21:28 +00:00
2013-07-04 08:00:56 +00:00
View::show_header("Post history for $Username", 'subscriptions,comments,bbcode');
2011-03-28 14:21:28 +00:00
$ViewingOwn = ($UserID == $LoggedUser['ID']);
$ShowUnread = ($ViewingOwn && (!isset($_GET['showunread']) || !!$_GET['showunread']));
$ShowGrouped = ($ViewingOwn && (!isset($_GET['group']) || !!$_GET['group']));
2013-04-20 08:01:01 +00:00
if ($ShowGrouped) {
2013-05-15 08:00:54 +00:00
$sql = '
SELECT
SQL_CALC_FOUND_ROWS
MAX(p.ID) AS ID
2011-03-28 14:21:28 +00:00
FROM forums_posts AS p
2013-05-15 08:00:54 +00:00
LEFT JOIN forums_topics AS t ON t.ID = p.TopicID';
2013-04-20 08:01:01 +00:00
if ($ShowUnread) {
2013-07-04 08:00:56 +00:00
$sql .= '
2013-05-15 08:00:54 +00:00
LEFT JOIN forums_last_read_topics AS l ON l.TopicID = t.ID AND l.UserID = '.$LoggedUser['ID'];
2011-03-28 14:21:28 +00:00
}
2013-07-04 08:00:56 +00:00
$sql .= "
2013-05-15 08:00:54 +00:00
LEFT JOIN forums AS f ON f.ID = t.ForumID
2013-07-04 08:00:56 +00:00
WHERE p.AuthorID = $UserID
2013-08-28 23:08:41 +00:00
AND " . Forums::user_forums_sql();
2013-04-20 08:01:01 +00:00
if ($ShowUnread) {
2011-03-28 14:21:28 +00:00
$sql .= '
2013-07-04 08:00:56 +00:00
AND ((t.IsLocked = \'0\' OR t.IsSticky = \'1\')
AND (l.PostID < t.LastPostID OR l.PostID IS NULL))';
2011-03-28 14:21:28 +00:00
}
2013-07-04 08:00:56 +00:00
$sql .= "
2011-03-28 14:21:28 +00:00
GROUP BY t.ID
2013-05-15 08:00:54 +00:00
ORDER BY p.ID DESC
2013-07-04 08:00:56 +00:00
LIMIT $Limit";
2011-03-28 14:21:28 +00:00
$PostIDs = $DB->query($sql);
2013-07-04 08:00:56 +00:00
$DB->query('SELECT FOUND_ROWS()');
2011-03-28 14:21:28 +00:00
list($Results) = $DB->next_record();
2013-05-15 08:00:54 +00:00
if ($Results > $PerPage * ($Page - 1)) {
2011-03-28 14:21:28 +00:00
$DB->set_query_id($PostIDs);
$PostIDs = $DB->collect('ID');
2013-07-04 08:00:56 +00:00
$sql = "
2013-04-20 08:01:01 +00:00
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
2013-11-17 08:00:47 +00:00
FROM forums_posts AS p
2013-04-20 08:01:01 +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
2013-07-04 08:00:56 +00:00
LEFT JOIN forums_last_read_topics AS l ON l.UserID = $UserID
AND l.TopicID = t.ID
WHERE p.ID IN (".implode(',', $PostIDs).')
2011-03-28 14:21:28 +00:00
ORDER BY p.ID DESC';
$Posts = $DB->query($sql);
}
} else {
2013-05-15 08:00:54 +00:00
$sql = '
2013-07-04 08:00:56 +00:00
SELECT
SQL_CALC_FOUND_ROWS';
2013-04-20 08:01:01 +00:00
if ($ShowGrouped) {
2013-07-04 08:00:56 +00:00
$sql .= '
*
FROM (
SELECT';
2011-03-28 14:21:28 +00:00
}
$sql .= '
2013-05-15 08:00:54 +00:00
p.ID,
p.AddedTime,
p.Body,
p.EditedUserID,
p.EditedTime,
ed.Username,
p.TopicID,
t.Title,
t.LastPostID,';
2013-04-20 08:01:01 +00:00
if ($UserID == $LoggedUser['ID']) {
2011-03-28 14:21:28 +00:00
$sql .= '
2013-05-15 08:00:54 +00:00
l.PostID AS LastRead,';
2011-03-28 14:21:28 +00:00
}
2013-07-04 08:00:56 +00:00
$sql .= "
2013-05-15 08:00:54 +00:00
t.IsLocked,
t.IsSticky
2013-11-17 08:00:47 +00:00
FROM forums_posts AS p
2013-04-20 08:01:01 +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
2013-08-28 23:08:41 +00:00
LEFT JOIN forums_last_read_topics AS l ON l.UserID = $UserID AND l.TopicID = t.ID
2013-07-04 08:00:56 +00:00
WHERE p.AuthorID = $UserID
2013-08-28 23:08:41 +00:00
AND " . Forums::user_forums_sql();
2013-04-20 08:01:01 +00:00
if ($ShowUnread) {
2013-07-04 08:00:56 +00:00
$sql .= '
AND ( (t.IsLocked = \'0\' OR t.IsSticky = \'1\')
AND (l.PostID < t.LastPostID OR l.PostID IS NULL)
2013-05-15 08:00:54 +00:00
) ';
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$sql .= '
ORDER BY p.ID DESC';
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
if ($ShowGrouped) {
2013-07-04 08:00:56 +00:00
$sql .= '
) AS sub
2013-05-15 08:00:54 +00:00
GROUP BY TopicID
ORDER BY ID DESC';
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
$sql .= " LIMIT $Limit";
2011-03-28 14:21:28 +00:00
$Posts = $DB->query($sql);
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
$DB->query('SELECT FOUND_ROWS()');
2011-03-28 14:21:28 +00:00
list($Results) = $DB->next_record();
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$DB->set_query_id($Posts);
}
2011-03-28 14:21:28 +00:00
?>
<div class="thin">
2012-08-19 08:00:19 +00:00
<div class="header">
<h2>
2011-03-28 14:21:28 +00:00
<?
2013-04-20 08:01:01 +00:00
if ($ShowGrouped) {
echo 'Grouped '.($ShowUnread ? 'unread ' : '')."post history for <a href=\"user.php?id=$UserID\">$Username</a>";
2011-03-28 14:21:28 +00:00
}
2013-04-20 08:01:01 +00:00
elseif ($ShowUnread) {
2011-03-28 14:21:28 +00:00
echo "Unread post history for <a href=\"user.php?id=$UserID\">$Username</a>";
}
else {
echo "Post history for <a href=\"user.php?id=$UserID\">$Username</a>";
}
?>
2012-08-19 08:00:19 +00:00
</h2>
<div class="linkbox">
2013-04-18 08:00:54 +00:00
<br /><br />
2011-03-28 14:21:28 +00:00
<?
2013-04-18 08:00:54 +00:00
if ($ViewingOwn) {
2013-08-28 23:08:41 +00:00
$UserSubscriptions = Subscriptions::get_subscriptions();
2013-02-22 08:00:24 +00:00
2013-04-18 08:00:54 +00:00
if (!$ShowUnread) {
if ($ShowGrouped) { ?>
2013-02-09 08:01:01 +00:00
<a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=0&amp;group=0" class="brackets">Show all posts</a>&nbsp;&nbsp;&nbsp;
2013-04-18 08:00:54 +00:00
<? } else { ?>
2013-02-09 08:01:01 +00:00
<a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=0&amp;group=1" class="brackets">Show all posts (grouped)</a>&nbsp;&nbsp;&nbsp;
2013-04-18 08:00:54 +00:00
<? } ?>
<a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=1&amp;group=1" class="brackets">Only display posts with unread replies (grouped)</a>&nbsp;&nbsp;&nbsp;
2011-03-28 14:21:28 +00:00
<? } else { ?>
2013-04-18 08:00:54 +00:00
<a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=0&amp;group=0" class="brackets">Show all posts</a>&nbsp;&nbsp;&nbsp;
<? if (!$ShowGrouped) { ?>
<a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=1&amp;group=1" class="brackets">Only display posts with unread replies (grouped)</a>&nbsp;&nbsp;&nbsp;
<? } else { ?>
<a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=1&amp;group=0" class="brackets">Only display posts with unread replies</a>&nbsp;&nbsp;&nbsp;
<? }
2011-03-28 14:21:28 +00:00
}
?>
2013-02-09 08:01:01 +00:00
<a href="userhistory.php?action=subscriptions" class="brackets">Go to subscriptions</a>
2011-03-28 14:21:28 +00:00
<?
2013-04-18 08:00:54 +00:00
} else {
?>
<a href="forums.php?action=search&amp;type=body&amp;user=<?=$Username?>" class="brackets">Search</a>
<?
2011-03-28 14:21:28 +00:00
}
?>
2012-08-19 08:00:19 +00:00
</div>
2011-03-28 14:21:28 +00:00
</div>
<?
2013-04-20 08:01:01 +00:00
if (empty($Results)) {
2011-03-28 14:21:28 +00:00
?>
<div class="center">
2013-04-20 08:01:01 +00:00
No topics<?=$ShowUnread ? ' with unread posts' : '' ?>
2011-03-28 14:21:28 +00:00
</div>
<?
} else {
?>
<div class="linkbox">
<?
2013-05-15 08:00:54 +00:00
$Pages = Format::get_pages($Page, $Results, $PerPage, 11);
2011-03-28 14:21:28 +00:00
echo $Pages;
?>
</div>
<?
2013-08-28 23:08:41 +00:00
$QueryID = $DB->get_query_id();
2013-04-20 08:01:01 +00:00
while (list($PostID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername, $TopicID, $ThreadTitle, $LastPostID, $LastRead, $Locked, $Sticky) = $DB->next_record()) {
2011-03-28 14:21:28 +00:00
?>
2013-05-01 08:00:16 +00:00
<table class="forum_post vertical_margin<?=!Users::has_avatars_enabled() ? ' noavatar' : '' ?>" id="post<?=$PostID ?>">
2012-10-29 08:00:20 +00:00
<colgroup>
2013-05-01 08:00:16 +00:00
<? if (Users::has_avatars_enabled()) { ?>
2012-10-29 08:00:20 +00:00
<col class="col_avatar" />
<? } ?>
<col class="col_post_body" />
</colgroup>
2012-10-09 08:00:17 +00:00
<tr class="colhead_dark">
2013-05-01 08:00:16 +00:00
<td colspan="<?=Users::has_avatars_enabled() ? 2 : 1 ?>">
2013-04-20 08:01:01 +00:00
<span style="float: left;">
2011-03-28 14:21:28 +00:00
<?=time_diff($AddedTime) ?>
2013-11-05 08:01:12 +00:00
in <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;postid=<?=$PostID?>#post<?=$PostID?>" class="tooltip" title="<?=display_str($ThreadTitle)?>"><?=Format::cut_string($ThreadTitle, 75)?></a>
2011-03-28 14:21:28 +00:00
<?
2013-04-20 08:01:01 +00:00
if ($ViewingOwn) {
2013-02-07 08:00:47 +00:00
if ((!$Locked || $Sticky) && (!$LastRead || $LastRead < $LastPostID)) { ?>
2012-09-05 08:00:24 +00:00
<span class="new">(New!)</span>
2011-03-28 14:21:28 +00:00
<?
}
?>
</span>
2013-04-20 08:01:01 +00:00
<? if (!empty($LastRead)) { ?>
2013-08-28 23:08:41 +00:00
<span style="float: left;" class="tooltip last_read" title="Jump to last read">
2011-03-28 14:21:28 +00:00
<a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;postid=<?=$LastRead?>#post<?=$LastRead?>"></a>
</span>
<? }
} else {
?>
</span>
<? }
?>
2013-04-20 08:01:01 +00:00
<span id="bar<?=$PostID ?>" style="float: right;">
<? if ($ViewingOwn && !in_array($TopicID, $UserSubscriptions)) { ?>
2013-08-28 23:08:41 +00:00
<a href="#" onclick="Subscribe(<?=$TopicID?>); $('.subscribelink<?=$TopicID?>').remove(); return false;" class="brackets subscribelink<?=$TopicID?>">Subscribe</a>
2011-03-28 14:21:28 +00:00
&nbsp;
<? } ?>
<a href="#">&uarr;</a>
</span>
</td>
</tr>
<?
2013-04-20 08:01:01 +00:00
if (!$ShowGrouped) {
2011-03-28 14:21:28 +00:00
?>
<tr>
2013-05-01 08:00:16 +00:00
<? if (Users::has_avatars_enabled()) { ?>
2012-10-09 08:00:17 +00:00
<td class="avatar" valign="top">
2013-08-28 23:08:41 +00:00
<?=Users::show_avatar($Avatar, $UserID, $Username, $HeavyInfo['DisableAvatars'])?>
2011-03-28 14:21:28 +00:00
</td>
2013-05-01 08:00:16 +00:00
<? } ?>
2012-10-09 08:00:17 +00:00
<td class="body" valign="top">
2011-03-28 14:21:28 +00:00
<div id="content<?=$PostID?>">
2013-12-12 08:01:01 +00:00
<?=Text::full_format($Body)?>
2013-04-20 08:01:01 +00:00
<? if ($EditedUserID) { ?>
2011-03-28 14:21:28 +00:00
<br />
<br />
2013-04-20 08:01:01 +00:00
<? if (check_perms('site_moderate_forums')) { ?>
2013-08-28 23:08:41 +00:00
<a href="#content<?=$PostID?>" onclick="LoadEdit(<?=$PostID?>, 1);">&laquo;</a>
2013-02-07 08:00:47 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
Last edited by
2013-08-28 23:08:41 +00:00
<?=Users::format_username($EditedUserID, false, false, false) ?> <?=time_diff($EditedTime, 2, true, true)?>
2013-02-22 08:00:24 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</div>
</td>
</tr>
2013-08-28 23:08:41 +00:00
<? }
$DB->set_query_id($QueryID);
2011-03-28 14:21:28 +00:00
?>
</table>
<? } ?>
<div class="linkbox">
<?=$Pages?>
</div>
<? } ?>
</div>
2013-05-21 08:01:09 +00:00
<? View::show_footer(); ?>