Gazelle/sections/userhistory/subscriptions.php

197 lines
6.2 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
/*
User topic subscription page
*/
2013-01-14 08:00:16 +00:00
2013-04-20 08:01:01 +00:00
if (!empty($LoggedUser['DisableForums'])) {
2011-03-28 14:21:28 +00:00
error(403);
}
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
$Text = new TEXT;
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);
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
View::show_header('Subscribed topics','subscriptions,bbcode');
2013-04-20 08:01:01 +00:00
if ($LoggedUser['CustomForums']) {
unset($LoggedUser['CustomForums']['']);
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
2011-10-11 08:00:15 +00:00
$PermittedForums = implode("','", array_keys($LoggedUser['CustomForums'], 1));
2011-03-28 14:21:28 +00:00
}
2011-10-11 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
$ShowUnread = (!isset($_GET['showunread']) && !isset($HeavyInfo['SubscriptionsUnread']) || isset($HeavyInfo['SubscriptionsUnread']) && !!$HeavyInfo['SubscriptionsUnread'] || isset($_GET['showunread']) && !!$_GET['showunread']);
$ShowCollapsed = (!isset($_GET['collapse']) && !isset($HeavyInfo['SubscriptionsCollapse']) || isset($HeavyInfo['SubscriptionsCollapse']) && !!$HeavyInfo['SubscriptionsCollapse'] || isset($_GET['collapse']) && !!$_GET['collapse']);
$sql = 'SELECT
SQL_CALC_FOUND_ROWS
MAX(p.ID) AS ID
2012-09-12 08:00:27 +00:00
FROM (SELECT TopicID
2013-02-22 08:00:24 +00:00
FROM users_subscriptions
2012-09-12 08:00:27 +00:00
WHERE UserID = '.$LoggedUser['ID'].') AS s
LEFT JOIN forums_last_read_topics AS l ON s.TopicID = l.TopicID AND l.UserID = '.$LoggedUser['ID'].'
2013-02-07 08:00:47 +00:00
JOIN forums_topics AS t ON t.ID = s.TopicID
2012-09-12 08:00:27 +00:00
JOIN forums_posts AS p ON t.ID = p.TopicID
JOIN forums AS f ON f.ID = t.ForumID
WHERE p.ID <= IFNULL(l.PostID,t.LastPostID)
2011-10-11 08:00:15 +00:00
AND ((f.MinClassRead <= '.$LoggedUser['Class'];
2013-04-20 08:01:01 +00:00
if (!empty($RestrictedForums)) {
2011-10-11 08:00:15 +00:00
$sql.=' AND f.ID NOT IN (\''.$RestrictedForums.'\')';
}
$sql .= ')';
2013-04-20 08:01:01 +00:00
if (!empty($PermittedForums)) {
2011-10-11 08:00:15 +00:00
$sql.=' OR f.ID IN (\''.$PermittedForums.'\')';
}
2011-10-11 08:00:15 +00:00
$sql .= ')';
2013-04-20 08:01:01 +00:00
if ($ShowUnread) {
2012-04-02 08:00:21 +00:00
$sql .= '
AND IF(l.PostID IS NULL OR (t.IsLocked = \'1\' && t.IsSticky = \'0\'), t.LastPostID, l.PostID) < t.LastPostID';
2013-02-22 08:00:24 +00:00
$sql .= ' OR (t.AuthorID != '.$LoggedUser['ID'].' AND l.PostID IS NULL)';
2012-04-02 08:00:21 +00:00
}
$sql .= '
GROUP BY t.ID
ORDER BY t.LastPostID DESC
LIMIT '.$Limit;
$PostIDs = $DB->query($sql);
$DB->query('SELECT FOUND_ROWS()');
list($NumResults) = $DB->next_record();
2013-04-20 08:01:01 +00:00
if ($NumResults > $PerPage*($Page-1)) {
$DB->set_query_id($PostIDs);
$PostIDs = $DB->collect('ID');
$sql = 'SELECT
f.ID AS ForumID,
f.Name AS ForumName,
p.TopicID,
t.Title,
p.Body,
t.LastPostID,
t.IsLocked,
t.IsSticky,
p.ID,
um.ID,
um.Username,
ui.Avatar,
p.EditedUserID,
p.EditedTime,
ed.Username AS EditedUsername
2011-03-28 14:21:28 +00:00
FROM forums_posts AS p
LEFT JOIN forums_topics AS t ON t.ID = p.TopicID
LEFT JOIN forums AS f ON f.ID = t.ForumID
LEFT JOIN users_main AS um ON um.ID = p.AuthorID
LEFT JOIN users_info AS ui ON ui.UserID = um.ID
LEFT JOIN users_main AS ed ON ed.ID = um.ID
WHERE p.ID IN ('.implode(',',$PostIDs).')
ORDER BY f.Name ASC, t.LastPostID DESC';
$DB->query($sql);
2011-03-28 14:21:28 +00:00
}
?>
<div class="thin">
2012-08-19 08:00:19 +00:00
<div class="header">
<h2><?='Subscribed topics'.($ShowUnread?' with unread posts':'')?></h2>
2011-03-28 14:21:28 +00:00
2012-08-19 08:00:19 +00:00
<div class="linkbox">
2011-03-28 14:21:28 +00:00
<?
2013-04-20 08:01:01 +00:00
if (!$ShowUnread) {
2011-03-28 14:21:28 +00:00
?>
<br /><br />
2013-01-24 08:00:24 +00:00
<a href="userhistory.php?action=subscriptions&amp;showunread=1" class="brackets">Only display topics with unread replies</a>&nbsp;&nbsp;&nbsp;
2011-03-28 14:21:28 +00:00
<?
} else {
?>
<br /><br />
2013-01-24 08:00:24 +00:00
<a href="userhistory.php?action=subscriptions&amp;showunread=0" class="brackets">Show all subscribed topics</a>&nbsp;&nbsp;&nbsp;
2011-03-28 14:21:28 +00:00
<?
}
2013-04-20 08:01:01 +00:00
if ($NumResults) {
2011-03-28 14:21:28 +00:00
?>
2013-01-24 08:00:24 +00:00
<a href="#" onclick="Collapse();return false;" id="collapselink" class="brackets"><?=$ShowCollapsed?'Show':'Hide'?> post bodies</a>&nbsp;&nbsp;&nbsp;
2011-03-28 14:21:28 +00:00
<?
}
?>
2013-01-24 08:00:24 +00:00
<a href="userhistory.php?action=catchup&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Catch up</a>&nbsp;&nbsp;&nbsp;
<a href="userhistory.php?action=posts&amp;userid=<?=$LoggedUser['ID']?>" class="brackets">Go to post history</a>&nbsp;&nbsp;&nbsp;
<a href="userhistory.php?action=quote_notifications" class="brackets">Quote notifications</a>&nbsp;&nbsp;&nbsp;
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 (!$NumResults) {
2011-03-28 14:21:28 +00:00
?>
<div class="center">
2013-04-20 08:01:01 +00:00
No subscribed topics<?=$ShowUnread ? ' with unread posts' : '' ?>
2011-03-28 14:21:28 +00:00
</div>
<?
} else {
?>
<div class="linkbox">
<?
2012-10-11 08:00:15 +00:00
$Pages=Format::get_pages($Page,$NumResults,$PerPage, 11);
2011-03-28 14:21:28 +00:00
echo $Pages;
?>
</div>
<?
2013-04-20 08:01:01 +00:00
while (list($ForumID, $ForumName, $TopicID, $ThreadTitle, $Body, $LastPostID, $Locked, $Sticky, $PostID, $AuthorID, $AuthorName, $AuthorAvatar, $EditedUserID, $EditedTime, $EditedUsername) = $DB->next_record()) {
2011-03-28 14:21:28 +00:00
?>
2013-05-01 08:00:16 +00:00
<table class="forum_post box vertical_margin<?=!Users::has_avatars_enabled() ? ' noavatar' : '' ?>">
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 ?>">
2011-03-28 14:21:28 +00:00
<span style="float:left;">
<a href="forums.php?action=viewforum&amp;forumid=<?=$ForumID?>"><?=$ForumName?></a> &gt;
2012-10-11 08:00:15 +00:00
<a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>" title="<?=display_str($ThreadTitle)?>"><?=Format::cut_string($ThreadTitle, 75)?></a>
2013-05-01 08:00:16 +00:00
<? if ($PostID < $LastPostID && !$Locked) { ?>
2012-09-05 08:00:24 +00:00
<span class="new">(New!)</span>
2013-05-01 08:00:16 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</span>
<span style="float:left;" class="last_read" title="Jump to last read">
<a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID.($PostID?'&amp;postid='.$PostID.'#post'.$PostID:'')?>"></a>
2011-03-28 14:21:28 +00:00
</span>
<span id="bar<?=$PostID ?>" style="float:right;">
2013-02-09 08:01:01 +00:00
<a href="#" onclick="Subscribe(<?=$TopicID?>);return false;" id="subscribelink<?=$TopicID?>" class="brackets">Unsubscribe</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
<tr class="row<?=$ShowCollapsed ? ' hidden' : '' ?>">
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-05-01 08:00:16 +00:00
<?=Users::show_avatar($AuthorAvatar, $AuthorName, $HeavyInfo['DisableAvatars'])?>
2011-03-28 14:21:28 +00:00
</td>
2013-04-20 08:01:01 +00:00
<? } ?>
2012-10-09 08:00:17 +00:00
<td class="body" valign="top">
2011-03-28 14:21:28 +00:00
<div class="content3">
<?=$Text->full_format($Body) ?>
2013-04-20 08:01:01 +00:00
<? if ($EditedUserID) { ?>
2011-03-28 14:21:28 +00:00
<br /><br />
Last edited by
2012-10-11 08:00:15 +00:00
<?=Users::format_username($EditedUserID, false, false, false) ?> <?=time_diff($EditedTime)?>
2013-04-20 08:01:01 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</div>
</td>
</tr>
</table>
2013-04-20 08:01:01 +00:00
<? } // while (list(...)) ?>
2011-03-28 14:21:28 +00:00
<div class="linkbox">
<?=$Pages?>
</div>
2013-04-20 08:01:01 +00:00
<? } // else -- if (empty($NumResults)) ?>
2011-03-28 14:21:28 +00:00
</div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();
2011-03-28 14:21:28 +00:00
?>