mirror of
https://github.com/WhatCD/Gazelle.git
synced 2025-01-18 12:11:36 +00:00
Improved method for dealing with restricted forums
Exclude restricted forums from searches Exclude restricted forums from post history Exclude restricted forums from subscriptions
This commit is contained in:
parent
7630c3567c
commit
c58f94a36f
@ -345,7 +345,8 @@ function user_heavy_info($UserID) {
|
||||
i.DisableRequests,
|
||||
i.SiteOptions,
|
||||
i.DownloadAlt,
|
||||
i.LastReadNews
|
||||
i.LastReadNews,
|
||||
i.RestrictedForums
|
||||
FROM users_main AS m
|
||||
INNER JOIN users_info AS i ON i.UserID=m.ID
|
||||
WHERE m.ID='$UserID'");
|
||||
@ -355,6 +356,13 @@ function user_heavy_info($UserID) {
|
||||
$HeavyInfo['CustomPermissions'] = unserialize($HeavyInfo['CustomPermissions']);
|
||||
}
|
||||
|
||||
if (!empty($HeavyInfo['RestrictedForums'])) {
|
||||
$HeavyInfo['CustomForums'] = array_fill_keys(explode(',', $HeavyInfo['RestrictedForums']), 0);
|
||||
} else {
|
||||
$HeavyInfo['CustomForums'] = null;
|
||||
}
|
||||
unset($HeavyInfo['RestrictedForums']);
|
||||
|
||||
if(!empty($HeavyInfo['SiteOptions'])) {
|
||||
$HeavyInfo['SiteOptions'] = unserialize($HeavyInfo['SiteOptions']);
|
||||
$HeavyInfo = array_merge($HeavyInfo, $HeavyInfo['SiteOptions']);
|
||||
|
@ -117,6 +117,10 @@
|
||||
//Subscriptions
|
||||
$NewSubscriptions = $Cache->get_value('subscriptions_user_new_'.$LoggedUser['ID']);
|
||||
if($NewSubscriptions === FALSE) {
|
||||
if($LoggedUser['CustomForums']) {
|
||||
unset($LoggedUser['CustomForums']['']);
|
||||
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
|
||||
}
|
||||
$DB->query("SELECT COUNT(s.TopicID)
|
||||
FROM users_subscriptions AS s
|
||||
JOIN forums_last_read_topics AS l ON s.UserID = l.UserID AND s.TopicID = l.TopicID
|
||||
@ -124,7 +128,9 @@
|
||||
JOIN forums AS f ON t.ForumID = f.ID
|
||||
WHERE f.MinClassRead <= ".$LoggedUser['Class']."
|
||||
AND l.PostID < t.LastPostID
|
||||
AND s.UserID = ".$LoggedUser['ID']);
|
||||
AND s.UserID = ".$LoggedUser['ID'].
|
||||
(!empty($RestrictedForums) ? "
|
||||
AND f.ID NOT IN ('".$RestrictedForums."')" : ""));
|
||||
list($NewSubscriptions) = $DB->next_record();
|
||||
$Cache->cache_value('subscriptions_user_new_'.$LoggedUser['ID'], $NewSubscriptions, 0);
|
||||
}
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
********************************************************************************/
|
||||
|
||||
include(SERVER_ROOT.'/sections/forums/functions.php');
|
||||
|
||||
//---------- Things to sort out before it can start printing/generating content
|
||||
|
||||
// Check for lame SQL injection attempts
|
||||
@ -61,7 +59,6 @@
|
||||
}
|
||||
|
||||
if(!isset($Forums[$ForumID])) { error(404); }
|
||||
|
||||
// Make sure they're allowed to look at the page
|
||||
if (!check_perms('site_moderate_forums')) {
|
||||
$DB->query("SELECT RestrictedForums FROM users_info WHERE UserID = ".$LoggedUser['ID']);
|
||||
|
@ -41,3 +41,14 @@ function get_thread_info($ThreadID, $Return = true, $SelectiveCache = false) {
|
||||
return $ThreadInfo;
|
||||
}
|
||||
}
|
||||
|
||||
function check_forumperm($ForumID) {
|
||||
global $LoggedUser, $Forums;
|
||||
if($Forums[$ForumID]['MinClassRead'] > $LoggedUser['Class'] && (!isset($LoggedUser['CustomForums'][$ForumID]) || $LoggedUser['CustomForums'][$ForumID] == 0)) {
|
||||
return false;
|
||||
}
|
||||
if(isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
error(403);
|
||||
}
|
||||
|
||||
include(SERVER_ROOT.'/sections/forums/functions.php');
|
||||
//This variable contains all our lovely forum data
|
||||
if(!$Forums = $Cache->get_value('forums_list')) {
|
||||
$DB->query("SELECT
|
||||
|
@ -83,7 +83,7 @@
|
||||
$Columns = 0;
|
||||
|
||||
foreach($Forums as $Forum) {
|
||||
if ($Forum['MinClassRead'] > $LoggedUser['Class']) {
|
||||
if (!check_forumperm($Forum['ID'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -143,6 +143,10 @@
|
||||
// Break search string down into individual words
|
||||
$Words = explode(' ', db_string($Search));
|
||||
|
||||
if($LoggedUser['CustomForums']) {
|
||||
unset($LoggedUser['CustomForums']['']);
|
||||
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
|
||||
}
|
||||
if($Type == 'body') {
|
||||
|
||||
$sql = "SELECT SQL_CALC_FOUND_ROWS
|
||||
@ -162,6 +166,9 @@
|
||||
JOIN forums AS f ON f.ID=t.ForumID
|
||||
WHERE
|
||||
f.MinClassRead<='$LoggedUser[Class]' AND ";
|
||||
if(!empty($RestrictedForums)) {
|
||||
$sql.="f.ID NOT IN ('".$RestrictedForums."') AND ";
|
||||
}
|
||||
|
||||
//In tests, this is significantly faster than LOCATE
|
||||
$sql .= "p.Body LIKE '%";
|
||||
@ -194,6 +201,9 @@
|
||||
JOIN forums AS f ON f.ID=t.ForumID
|
||||
WHERE
|
||||
f.MinClassRead<='$LoggedUser[Class]' AND ";
|
||||
if(!empty($RestrictedForums)) {
|
||||
$sql.="f.ID NOT IN ('".$RestrictedForums."') AND ";
|
||||
}
|
||||
$sql .= "t.Title LIKE '%";
|
||||
$sql .= implode("%' AND t.Title LIKE '%", $Words);
|
||||
$sql .= "%' ";
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?
|
||||
authorize();
|
||||
include(SERVER_ROOT.'/sections/forums/functions.php');
|
||||
|
||||
//TODO: Remove all the stupid queries that could get their information just as easily from the cache
|
||||
/*********************************************************************\
|
||||
|
@ -12,7 +12,6 @@
|
||||
//---------- Things to sort out before it can start printing/generating content
|
||||
|
||||
include(SERVER_ROOT.'/classes/class_text.php');
|
||||
include(SERVER_ROOT.'/sections/forums/functions.php');
|
||||
|
||||
$Text = new TEXT;
|
||||
|
||||
@ -42,13 +41,9 @@
|
||||
$ForumID = $ThreadInfo['ForumID'];
|
||||
|
||||
// Make sure they're allowed to look at the page
|
||||
if (!check_perms('site_moderate_forums')) {
|
||||
$DB->query("SELECT RestrictedForums FROM users_info WHERE UserID = ".$LoggedUser['ID']);
|
||||
list($RestrictedForums) = $DB->next_record();
|
||||
$RestrictedForums = explode(',', $RestrictedForums);
|
||||
if (array_search($ForumID, $RestrictedForums) !== FALSE) { error(403); }
|
||||
if($Forums[$ForumID]['MinClassRead'] > $LoggedUser['Class'] || (isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] == 0)) {
|
||||
error(403);
|
||||
}
|
||||
if($Forums[$ForumID]['MinClassRead'] > $LoggedUser['Class']) { error(403); }
|
||||
|
||||
//Post links utilize the catalogue & key params to prevent issues with custom posts per page
|
||||
if($ThreadInfo['Posts'] > $PerPage) {
|
||||
|
@ -440,7 +440,6 @@ function next_hour() {
|
||||
WHERE m.Uploaded/m.Downloaded < m.RequiredRatio
|
||||
AND i.RatioWatchEnds='0000-00-00 00:00:00'
|
||||
AND m.Enabled='1'
|
||||
AND m.Downloaded > 100<<30
|
||||
AND m.can_leech='1'");
|
||||
$OnRatioWatch = $DB->collect('ID');
|
||||
|
||||
@ -625,9 +624,9 @@ function next_hour() {
|
||||
JOIN torrents_group AS tg ON tg.ID = t.GroupID
|
||||
LEFT JOIN artists_group AS ag ON ag.ArtistID = tg.ArtistID
|
||||
WHERE t.last_action < '".time_minus(3600*24*28)."'
|
||||
AND t.last_action != 0");
|
||||
// OR t.Time < '".time_minus(3600*24*2)."'
|
||||
// AND t.last_action = 0");
|
||||
AND t.last_action != 0
|
||||
OR t.Time < '".time_minus(3600*24*2)."'
|
||||
AND t.last_action = 0");
|
||||
$TorrentIDs = $DB->to_array();
|
||||
|
||||
$LogEntries = array();
|
||||
|
@ -60,7 +60,7 @@
|
||||
$DisableRequests = (isset($_POST['DisableRequests']))? 1 : 0;
|
||||
$DisableLeech = (isset($_POST['DisableLeech'])) ? 0 : 1;
|
||||
|
||||
$RestrictedForums = db_string($_POST['RestrictedForums']);
|
||||
$RestrictedForums = db_string(trim($_POST['RestrictedForums']));
|
||||
$EnableUser = (int)$_POST['UserStatus'];
|
||||
$ResetRatioWatch = (isset($_POST['ResetRatioWatch']))? 1 : 0;
|
||||
$ResetPasskey = (isset($_POST['ResetPasskey']))? 1 : 0;
|
||||
@ -338,6 +338,11 @@
|
||||
if ($RestrictedForums != db_string($Cur['RestrictedForums']) && check_perms('users_mod')) {
|
||||
$UpdateSet[]="RestrictedForums='$RestrictedForums'";
|
||||
$EditSummary[]="restricted forum(s): $RestrictedForums";
|
||||
if(empty($RestrictedForums)) {
|
||||
$HeavyUpdates['CustomForums'] = null;
|
||||
} else {
|
||||
$HeavyUpdates['CustomForums'] = array_fill_keys(explode(',', $RestrictedForums), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if ($DisableAvatar!=$Cur['DisableAvatar'] && check_perms('users_disable_any')) {
|
||||
|
@ -52,6 +52,10 @@
|
||||
|
||||
show_header('Post history for '.$Username,'subscriptions,comments,bbcode');
|
||||
|
||||
if($LoggedUser['CustomForums']) {
|
||||
unset($LoggedUser['CustomForums']['']);
|
||||
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
|
||||
}
|
||||
$ViewingOwn = ($UserID == $LoggedUser['ID']);
|
||||
$ShowUnread = ($ViewingOwn && (!isset($_GET['showunread']) || !!$_GET['showunread']));
|
||||
$ShowGrouped = ($ViewingOwn && (!isset($_GET['group']) || !!$_GET['group']));
|
||||
@ -69,6 +73,10 @@
|
||||
LEFT JOIN forums AS f ON f.ID = t.ForumID
|
||||
WHERE p.AuthorID = '.$UserID.'
|
||||
AND f.MinClassRead <= '.$LoggedUser['Class'];
|
||||
if(!empty($RestrictedForums)) {
|
||||
$sql.='
|
||||
AND f.ID NOT IN (\''.$RestrictedForums.'\')';
|
||||
}
|
||||
if($ShowUnread) {
|
||||
$sql .= '
|
||||
AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\')
|
||||
@ -141,6 +149,11 @@
|
||||
WHERE p.AuthorID = '.$UserID.'
|
||||
AND f.MinClassRead <= '.$LoggedUser['Class'];
|
||||
|
||||
if(!empty($RestrictedForums)) {
|
||||
$sql.='
|
||||
AND f.ID NOT IN (\''.$RestrictedForums.'\')';
|
||||
}
|
||||
|
||||
if($ShowUnread) {
|
||||
$sql.='
|
||||
AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\') AND (l.PostID<t.LastPostID OR l.PostID IS NULL)) ';
|
||||
|
@ -18,76 +18,68 @@
|
||||
list($Page,$Limit) = page_limit($PerPage);
|
||||
|
||||
show_header('Subscribed topics','subscriptions,bbcode');
|
||||
if(($UserSubscriptions = $Cache->get_value('subscriptions_user_'.$LoggedUser['ID'])) === FALSE) {
|
||||
$DB->query('SELECT TopicID FROM users_subscriptions WHERE UserID = '.$LoggedUser['ID']);
|
||||
if($UserSubscriptions = $DB->collect(0)) {
|
||||
$Cache->cache_value('subscriptions_user_'.$LoggedUser['ID'],$UserSubscriptions,0);
|
||||
}
|
||||
|
||||
if($LoggedUser['CustomForums']) {
|
||||
unset($LoggedUser['CustomForums']['']);
|
||||
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
|
||||
}
|
||||
$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']);
|
||||
if(!empty($UserSubscriptions)) {
|
||||
$sql = "SELECT
|
||||
SQL_CALC_FOUND_ROWS
|
||||
MAX(p.ID) AS ID
|
||||
$sql = 'SELECT
|
||||
SQL_CALC_FOUND_ROWS
|
||||
MAX(p.ID) AS ID
|
||||
FROM forums_posts AS p
|
||||
LEFT JOIN forums_topics AS t ON t.ID = p.TopicID
|
||||
JOIN users_subscriptions AS s ON s.TopicID = t.ID
|
||||
LEFT JOIN forums AS f ON f.ID = t.ForumID
|
||||
LEFT JOIN forums_last_read_topics AS l ON p.TopicID = l.TopicID AND l.UserID = s.UserID
|
||||
WHERE s.UserID = '.$LoggedUser['ID'].'
|
||||
AND p.ID <= IFNULL(l.PostID,t.LastPostID)
|
||||
AND f.MinClassRead <= '.$LoggedUser['Class'];
|
||||
if(!empty($RestrictedForums)) {
|
||||
$sql.='
|
||||
AND f.ID NOT IN (\''.$RestrictedForums.'\')';
|
||||
}
|
||||
if($ShowUnread) {
|
||||
$sql .= '
|
||||
AND IF(l.PostID IS NULL OR (t.IsLocked = \'1\' && t.IsSticky = \'0\'), t.LastPostID, l.PostID) < t.LastPostID';
|
||||
}
|
||||
$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();
|
||||
|
||||
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
|
||||
FROM forums_posts AS p
|
||||
LEFT JOIN forums_last_read_topics AS l ON l.UserID = ".$LoggedUser['ID']." AND p.TopicID = l.TopicID
|
||||
LEFT JOIN forums_topics AS t ON t.ID = p.TopicID
|
||||
LEFT JOIN forums AS f ON f.ID = t.ForumID
|
||||
WHERE t.ID IN (".implode(',',$UserSubscriptions).")
|
||||
AND p.ID <= IF(l.PostID IS NULL
|
||||
OR l.PostID>t.LastPostID,
|
||||
t.LastPostID,
|
||||
l.PostID)
|
||||
AND f.MinClassRead<=".$LoggedUser['Class'];
|
||||
if($ShowUnread) {
|
||||
$sql .= "
|
||||
AND IF(l.PostID IS NULL OR (t.IsLocked = '1' && t.IsSticky = '0'), t.LastPostID, l.PostID)<t.LastPostID";
|
||||
}
|
||||
$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();
|
||||
|
||||
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,
|
||||
IFNULL((SELECT COUNT(ID)
|
||||
FROM forums_posts
|
||||
WHERE forums_posts.TopicID=p.TopicID
|
||||
AND forums_posts.ID <= p.ID),1)
|
||||
AS LastReadNum,
|
||||
um.ID,
|
||||
um.Username,
|
||||
ui.Avatar,
|
||||
p.EditedUserID,
|
||||
p.EditedTime,
|
||||
ed.Username AS EditedUsername
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
$NumResults = 0;
|
||||
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);
|
||||
}
|
||||
?>
|
||||
<div class="thin">
|
||||
@ -131,7 +123,7 @@
|
||||
?>
|
||||
</div>
|
||||
<?
|
||||
while(list($ForumID, $ForumName, $TopicID, $ThreadTitle, $Body, $LastPostID, $Locked, $Sticky, $PostID, $LastReadNum, $AuthorID, $AuthorName, $AuthorAvatar, $EditedUserID, $EditedTime, $EditedUsername) = $DB->next_record()){
|
||||
while(list($ForumID, $ForumName, $TopicID, $ThreadTitle, $Body, $LastPostID, $Locked, $Sticky, $PostID, $AuthorID, $AuthorName, $AuthorAvatar, $EditedUserID, $EditedTime, $EditedUsername) = $DB->next_record()){
|
||||
?>
|
||||
<table class='forum_post box vertical_margin<?=$HeavyInfo['DisableAvatars'] ? ' noavatar' : ''?>'>
|
||||
<tr class='colhead_dark'>
|
||||
@ -144,7 +136,7 @@
|
||||
<? } ?>
|
||||
</span>
|
||||
<span style="float:left;" class="last_read" title="Jump to last read">
|
||||
<a href="forums.php?action=viewthread&threadid=<?=$TopicID.($PostID?'&post='.$LastReadNum.'#post'.$PostID:'')?>"></a>
|
||||
<a href="forums.php?action=viewthread&threadid=<?=$TopicID.($PostID?'&postid='.$PostID.'#post'.$PostID:'')?>"></a>
|
||||
</span>
|
||||
<span id="bar<?=$PostID ?>" style="float:right;">
|
||||
<a href="#" onclick="Subscribe(<?=$TopicID?>);return false;" id="subscribelink<?=$TopicID?>">[Unsubscribe]</a>
|
||||
|
Loading…
Reference in New Issue
Block a user