Skip to content

Commit

Permalink
web: fix PHP warning from showing subscriptions without user login
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpanderson committed Oct 4, 2024
1 parent 370c32a commit 3dec8f8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
2 changes: 2 additions & 0 deletions html/inc/forum.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,8 @@ function is_subscribed($id, $subs) {
return false;
}

// If it's a team forum, user must be member of team to view
//
function is_forum_visible_to_user($forum, $user) {
if ($forum->parent_type == 1) {
if (parse_config(get_config(), "<team_forums_members_only>")) {
Expand Down
68 changes: 39 additions & 29 deletions html/user/forum_forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@
require_once('../inc/forum.inc');
require_once('../inc/pm.inc');

// show a forum.
// $user is null if not logged in
//
function forum_page($forum, $user, $msg=null) {
global $forum_sort_styles;

if (DISABLE_FORUMS) {
if (!$user || !is_admin($user)) {
error_page("Forums are disabled");
}
}
$sort_style = get_int("sort", true);
$start = get_int("start", true);
if (!$start) $start = 0;

$subs = null;
if ($user) {
if (DISABLE_FORUMS && !is_admin($user)) {
error_page("Forums are disabled");
}
BoincForumPrefs::lookup($user);
$subs = BoincSubscription::enum("userid=$user->id");
}
Expand Down Expand Up @@ -90,32 +97,34 @@ function forum_page($forum, $user, $msg=null) {
<td colspan=2>
';

if (user_can_create_thread($user, $forum)) {
show_button(
"forum_post.php?id=$forum->id",
tra("New thread"),
tra("Add a new thread to this forum")
);
}
if ($user) {
if (user_can_create_thread($user, $forum)) {
show_button(
"forum_post.php?id=$forum->id",
tra("New thread"),
tra("Add a new thread to this forum")
);
}

if (is_subscribed(-$forum->id, $subs)) {
BoincNotify::delete_aux(sprintf(
'userid=%d and type=%d and opaque=%d',
$logged_in_user->id,
NOTIFY_SUBSCRIBED_FORUM,
$forum->id
));
show_button_small(
"forum_forum.php?id=$forum->id&action=unsubscribe",
'Unsubscribe',
'Unsubscribe from this forum'
);
} else {
show_button_small(
"forum_forum.php?id=$forum->id&action=subscribe",
'Subscribe',
'Click to get notified when there are new threads in this forum'
);
if (is_subscribed(-$forum->id, $subs)) {
BoincNotify::delete_aux(sprintf(
'userid=%d and type=%d and opaque=%d',
$logged_in_user->id,
NOTIFY_SUBSCRIBED_FORUM,
$forum->id
));
show_button_small(
"forum_forum.php?id=$forum->id&action=unsubscribe",
'Unsubscribe',
'Unsubscribe from this forum'
);
} else {
show_button_small(
"forum_forum.php?id=$forum->id&action=subscribe",
'Subscribe',
'Click to get notified when there are new threads in this forum'
);
}
}

echo '</td>
Expand Down Expand Up @@ -146,7 +155,8 @@ function forum_page($forum, $user, $msg=null) {
// Show the threads for the given forum
// starting from $start,
// using the given $sort_style (as defined in forum.php)
// and using the features for the logged in user in $user.
// $user is logged-in user, or null
// If $user is not null, $subs is list of their subscriptions
//
function show_forum_threads($forum, $start, $sort_style, $user, $subs) {
$page_nav = page_links(
Expand Down

0 comments on commit 3dec8f8

Please sign in to comment.