2013-08-28 23:08:41 +00:00
< ?
2011-03-28 14:21:28 +00:00
/*
2013-08-28 23:08:41 +00:00
User subscription page
2011-03-28 14:21:28 +00:00
*/
2013-01-14 08:00:16 +00:00
2011-03-28 14:21:28 +00:00
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-08-28 23:08:41 +00:00
View :: show_header ( 'Subscriptions' , 'subscriptions,bbcode' );
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' ]);
2012-04-02 08:00:21 +00:00
2013-08-28 23:08:41 +00:00
// The monster sql query:
/*
* Fields :
* Page ( artist , collages , requests , torrents or forums )
* PageID ( ArtistID , CollageID , RequestID , GroupID , TopicID )
* PostID ( of the last read post )
* ForumID
* ForumName
* Name ( for artists and collages ; carries the topic title for forum subscriptions )
* LastPost ( PostID of the last post )
* LastPostTime
* LastReadBody
* LastReadEditedTime
* LastReadUserID
* LastReadUsername
* LastReadAvatar
* LastReadEditedUserID
*/
$DB -> query ( "
( SELECT
SQL_CALC_FOUND_ROWS
s . Page ,
s . PageID ,
lr . PostID ,
null AS ForumID ,
null AS ForumName ,
IF ( s . Page = 'artist' , a . Name , co . Name ) AS Name ,
c . ID AS LastPost ,
c . AddedTime AS LastPostTime ,
c_lr . Body AS LastReadBody ,
c_lr . EditedTime AS LastReadEditedTime ,
um . ID AS LastReadUserID ,
um . Username AS LastReadUsername ,
ui . Avatar AS LastReadAvatar ,
c_lr . EditedUserID AS LastReadEditedUserID
FROM users_subscriptions_comments AS s
LEFT JOIN users_comments_last_read AS lr ON lr . UserID = $LoggedUser [ ID ] AND lr . Page = s . Page AND lr . PageID = s . PageID
LEFT JOIN artists_group AS a ON s . Page = 'artist' AND a . ArtistID = s . PageID
LEFT JOIN collages AS co ON s . Page = 'collages' AND co . ID = s . PageID
LEFT JOIN comments AS c ON c . ID = ( SELECT MAX ( ID ) FROM comments WHERE Page = s . Page AND PageID = s . PageID )
LEFT JOIN comments AS c_lr ON c_lr . ID = lr . PostID
LEFT JOIN users_main AS um ON um . ID = c_lr . AuthorID
LEFT JOIN users_info AS ui ON ui . UserID = um . ID
WHERE s . UserID = $LoggedUser [ ID ] AND s . Page IN ( 'artist' , 'collages' , 'requests' , 'torrents' ) AND ( s . Page != 'collages' OR co . Deleted = '0' ) " . ( $ShowUnread ? ' AND c.ID > IF(lr.PostID IS NULL, 0, lr.PostID)' : '') . "
GROUP BY s . PageID )
UNION ALL
( SELECT 'forums' , s . TopicID , lr . PostID , f . ID , f . Name , t . Title , p . ID , p . AddedTime , p_lr . Body , p_lr . EditedTime , um . ID , um . Username , ui . Avatar , p_lr . EditedUserID
FROM users_subscriptions AS s
LEFT JOIN forums_last_read_topics AS lr ON lr . UserID = $LoggedUser [ ID ] AND s . TopicID = lr . TopicID
LEFT JOIN forums_topics AS t ON t . ID = s . TopicID
LEFT JOIN forums AS f ON f . ID = t . ForumID
LEFT JOIN forums_posts AS p ON p . ID = ( SELECT MAX ( ID ) FROM forums_posts WHERE TopicID = s . TopicID )
LEFT JOIN forums_posts AS p_lr ON p_lr . ID = lr . PostID
LEFT JOIN users_main AS um ON um . ID = p_lr . AuthorID
LEFT JOIN users_info AS ui ON ui . UserID = um . ID
WHERE s . UserID = $LoggedUser [ ID ] " .
( $ShowUnread ? " AND p.ID > IF(t.IsLocked = '1' AND t.IsSticky = '0' " . " , p.ID, IF(lr.PostID IS NULL, 0, lr.PostID)) " : '' ) .
' AND ' . Forums :: user_forums_sql () . "
GROUP BY t . ID )
ORDER BY LastPostTime DESC
LIMIT $Limit " );
$Results = $DB -> to_array ( false , MYSQLI_ASSOC , false );
2011-05-15 12:06:04 +00:00
$DB -> query ( 'SELECT FOUND_ROWS()' );
list ( $NumResults ) = $DB -> next_record ();
2013-08-28 23:08:41 +00:00
$Debug -> log_var ( $Results , 'Results' );
$TorrentGroups = $Requests = array ();
foreach ( $Results as $Result ) {
if ( $Result [ 'Page' ] == 'torrents' ) {
$TorrentGroups [] = $Result [ 'PageID' ];
} elseif ( $Result [ 'Page' ] == 'requests' ) {
$Requests [] = $Result [ 'PageID' ];
}
2011-03-28 14:21:28 +00:00
}
2013-08-28 23:08:41 +00:00
$TorrentGroups = Torrents :: get_groups ( $TorrentGroups , true , true , false );
$Requests = Requests :: get_requests ( $Requests );
include ( SERVER_ROOT . '/classes/text.class.php' ); // Text formatting class
$Text = new TEXT ;
2011-03-28 14:21:28 +00:00
?>
< div class = " thin " >
2012-08-19 08:00:19 +00:00
< div class = " header " >
2013-08-28 23:08:41 +00:00
< h2 > Subscriptions < ? = $ShowUnread ? ' with unread posts' . ( $NumResults ? ' (' . $NumResults . ' new)' : '' ) : '' ?> </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-08-28 23:08:41 +00:00
< a href = " userhistory.php?action=subscriptions&showunread=1 " class = " brackets " > Only display subscriptions with unread replies </ a >& nbsp ; & nbsp ; & nbsp ;
2011-03-28 14:21:28 +00:00
< ?
} else {
?>
< br />< br />
2013-08-28 23:08:41 +00:00
< a href = " userhistory.php?action=subscriptions&showunread=0 " class = " brackets " > Show all subscriptions </ 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-08-28 23:08:41 +00:00
< a href = " # " onclick = " Collapse(); return false; " id = " collapselink " class = " brackets " >< ? = $ShowCollapsed ? 'Show' : 'Hide' ?> post bodies</a>
2011-03-28 14:21:28 +00:00
< ?
}
?>
2013-01-24 08:00:24 +00:00
< a href = " userhistory.php?action=catchup&auth=<?= $LoggedUser['AuthKey'] ?> " class = " brackets " > Catch up </ a >& nbsp ; & nbsp ; & nbsp ;
< a href = " userhistory.php?action=posts&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-08-28 23:08:41 +00:00
No subscriptions < ? = $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 , $NumResults , $PerPage , 11 );
2011-03-28 14:21:28 +00:00
echo $Pages ;
?>
</ div >
< ?
2013-08-28 23:08:41 +00:00
foreach ( $Results as $Result ) {
switch ( $Result [ 'Page' ]) {
case 'artist' :
$Links = 'Artist: <a href="artist.php?id=' . $Result [ 'PageID' ] . '">' . display_str ( $Result [ 'Name' ]) . '</a>' ;
$JumpLink = 'artist.php?id=' . $Result [ 'PageID' ] . '&postid=' . $Result [ 'PostID' ] . '#post' . $Result [ 'PostID' ];
break ;
case 'collages' :
$Links = 'Collage: <a href="collages.php?id=' . $Result [ 'PageID' ] . '">' . display_str ( $Result [ 'Name' ]) . '</a>' ;
2013-10-16 08:01:00 +00:00
$JumpLink = 'collages.php?action=comments&collageid=' . $Result [ 'PageID' ] . '&postid=' . $Result [ 'PostID' ] . '#post' . $Result [ 'PostID' ];
2013-08-28 23:08:41 +00:00
break ;
case 'requests' :
2013-09-13 08:00:53 +00:00
if ( ! isset ( $Requests [ $Result [ 'PageID' ]])) {
continue ;
2013-08-28 23:08:41 +00:00
}
2013-09-13 08:00:53 +00:00
$Request = $Requests [ $Result [ 'PageID' ]];
2013-08-28 23:08:41 +00:00
$CategoryName = $Categories [ $CategoryID - 1 ];
$Links = 'Request: ' ;
2013-09-15 08:00:53 +00:00
if ( $CategoryName == 'Music' || $CategoryName == 'Audiobooks' || $CategoryName == 'Comedy' ) {
2013-09-13 08:00:53 +00:00
$Links .= ( $CategoryName == 'Music' ? Artists :: display_artists ( Requests :: get_artists ( $Result [ 'PageID' ])) : '' ) . '<a href="requests.php?action=view&id=' . $Result [ 'PageID' ] . '" dir="ltr">' . $Request [ 'Title' ] . " [ " . $Request [ 'Year' ] . " ]</a> " ;
2013-08-28 23:08:41 +00:00
} else {
2013-09-13 08:00:53 +00:00
$Links .= '<a href="requests.php?action=view&id=' . $Result [ 'PageID' ] . '">' . $Request [ 'Title' ] . " </a> " ;
2013-08-28 23:08:41 +00:00
}
$JumpLink = 'requests.php?action=view&id=' . $Result [ 'PageID' ] . '&postid=' . $Result [ 'PostID' ] . '#post' . $Result [ 'PostID' ];
break ;
case 'torrents' :
2013-09-13 08:00:53 +00:00
if ( ! isset ( $TorrentGroups [ $Result [ 'PageID' ]])) {
continue ;
2013-08-28 23:08:41 +00:00
}
2013-09-13 08:00:53 +00:00
$GroupInfo = $TorrentGroups [ $Result [ 'PageID' ]];
2013-08-28 23:08:41 +00:00
$Links = 'Torrent: ' . Artists :: display_artists ( $GroupInfo [ 'ExtendedArtists' ]) . '<a href="torrents.php?id=' . $GroupInfo [ 'ID' ] . '" dir="ltr">' . $GroupInfo [ 'Name' ] . '</a>' ;
2013-09-15 08:00:53 +00:00
if ( $GroupInfo [ 'Year' ] > 0 ) {
2013-08-28 23:08:41 +00:00
$Links .= " [ " . $GroupInfo [ 'Year' ] . " ] " ;
}
if ( $GroupInfo [ 'ReleaseType' ] > 0 ) {
$Links .= " [ " . $ReleaseTypes [ $GroupInfo [ 'ReleaseType' ]] . " ] " ;
}
$JumpLink = 'torrents.php?id=' . $GroupInfo [ 'ID' ] . '&postid=' . $Result [ 'PostID' ] . '#post' . $Result [ 'PostID' ];
break ;
case 'forums' :
$Links = 'Forums: <a href="forums.php?action=viewforum&forumid=' . $Result [ 'ForumID' ] . '">' . display_str ( $Result [ 'ForumName' ]) . '</a> > ' .
'<a href="forums.php?action=viewthread&threadid=' . $Result [ 'PageID' ] . '" title="' . display_str ( $Result [ 'Name' ]) . '">' . Format :: cut_string ( $Result [ 'Name' ], 75 ) . '</a>' ;
$JumpLink = 'forums.php?action=viewthread&threadid=' . $Result [ 'PageID' ] . '&postid=' . $Result [ 'PostID' ] . '#post' . $Result [ 'PostID' ];
break ;
default :
error ( 0 );
}
2011-03-28 14:21:28 +00:00
?>
2013-08-28 23:08:41 +00:00
< table class = " forum_post box vertical_margin<?=(!Users::has_avatars_enabled() ? ' noavatar' : '')?> " >
2013-09-06 08:00:41 +00:00
< colgroup >
< ? if ( Users :: has_avatars_enabled ()) { ?>
< col class = " col_avatar " />
< ? } ?>
< col class = " col_post_body " />
</ colgroup >
2013-08-28 23:08:41 +00:00
< tr class = " colhead_dark notify_<?= $Result['Page'] ?> " >
2013-05-01 08:00:16 +00:00
< td colspan = " <?=Users::has_avatars_enabled() ? 2 : 1 ?> " >
2013-08-28 23:08:41 +00:00
< span style = " float:left; " >
< ? = $Links . ( $Result [ 'PostID' ] < $Result [ 'LastPost' ] ? ' <span class="new">(New!)</span>' : '' ) ?>
2011-03-28 14:21:28 +00:00
</ span >
2013-08-28 23:08:41 +00:00
< span style = " float: left; " class = " tooltip last_read " title = " Jump to last read " >
< a href = " <?= $JumpLink ?> " ></ a >
2011-03-28 14:21:28 +00:00
</ span >
2013-08-28 23:08:41 +00:00
< ? if ( $Result [ 'Page' ] == 'forums' ) { ?>
< span id = " bar<?= $Result['PostID'] ?> " style = " float:right; " >
< a href = " # " onclick = " Subscribe(<?= $Result['PageID'] ?>); return false; " id = " subscribelink<?= $Result['PageID'] ?> " class = " brackets " > Unsubscribe </ a >
< ? } else { ?>
< span id = " bar_<?= $Result['Page'] . $Result['PostID'] ?> " style = " float:right; " >
< a href = " # " onclick = " SubscribeComments('<?= $Result['Page'] ?>', <?= $Result['PageID'] ?>); return false; " id = " subscribelink_<?= $Result['Page'] . $Result['PageID'] ?> " class = " brackets " > Unsubscribe </ a >
< ? } ?>
2011-03-28 14:21:28 +00:00
& nbsp ;
< a href = " # " >& uarr ; </ a >
</ span >
</ td >
</ tr >
2013-08-28 23:08:41 +00:00
< ? if ( ! empty ( $Result [ 'LastReadBody' ])) { // if a user is subscribed to a topic/comments but hasn't accessed the site ever, LastReadBody will be null - in this case we don't display a post. ?>
2013-04-20 08:01:01 +00:00
< tr class = " row<?= $ShowCollapsed ? ' hidden' : '' ?> " >
2013-08-28 23:08:41 +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 ( $Result [ 'LastReadAvatar' ], $Result [ 'LastReadUsername' ], $HeavyInfo [ 'DisableAvatars' ]) ?>
2011-03-28 14:21:28 +00:00
</ td >
2013-08-28 23:08:41 +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 " >
2013-08-28 23:08:41 +00:00
< ? = $Text -> full_format ( $Result [ 'LastReadBody' ]) ?>
< ? if ( $Result [ 'LastReadEditedUserID' ]) { ?>
2011-03-28 14:21:28 +00:00
< br />< br />
2013-08-28 23:08:41 +00:00
Last edited by < ? = Users :: format_username ( $Result [ 'LastReadEditedUserID' ], false , false , false ) ?> <?=time_diff($Result['LastReadEditedTime'])?>
< ? } ?>
2011-03-28 14:21:28 +00:00
</ div >
</ td >
</ tr >
2013-08-28 23:08:41 +00:00
< ? } ?>
2011-03-28 14:21:28 +00:00
</ table >
2013-08-28 23:08:41 +00:00
< ? } ?>
2011-03-28 14:21:28 +00:00
< div class = " linkbox " >
< ? = $Pages ?>
</ div >
2013-08-28 23:08:41 +00:00
< ? } ?>
2011-03-28 14:21:28 +00:00
</ div >
< ?
2012-10-11 08:00:15 +00:00
View :: show_footer ();