diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index f3278dcfc1..55eff22d74 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -135,6 +135,7 @@
[Change] Changed behaviour of group_create() function to support specifying additional group columns
[Change] Hide avatar when avatar-type is not allowed (Bug #46785 - Patch by cYbercOsmOnauT and nickvergessen)
[Change] INCLUDEPHP not depending on phpbb_root_path (Bug #45805 - Patch by nickvergessen)
+ [Change] Ability to fetch moderators with get_moderators() even if load_moderators setting is off. (Bug #35955)
[Feature] Add confirmation for deactivating styles (Bug #14304 - Patch by leviatan21)
[Feature] Backported 3.2 captcha plugins.
[Feature] Introduced new ACM plugins:
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index d3244e7111..57f416bee4 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -663,14 +663,7 @@ function get_moderators(&$forum_moderators, $forum_id = false)
{
global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
- // Have we disabled the display of moderators? If so, then return
- // from whence we came ...
- if (!$config['load_moderators'])
- {
- return;
- }
-
- $forum_sql = '';
+ $forum_id_ary = array();
if ($forum_id !== false)
{
@@ -679,13 +672,8 @@ function get_moderators(&$forum_moderators, $forum_id = false)
$forum_id = array($forum_id);
}
- // If we don't have a forum then we can't have a moderator
- if (!sizeof($forum_id))
- {
- return;
- }
-
- $forum_sql = 'AND m.' . $db->sql_in_set('forum_id', $forum_id);
+ // Exchange key/value pair to be able to faster check for the forum id existence
+ $forum_id_ary = array_flip($forum_id);
}
$sql_array = array(
@@ -706,17 +694,25 @@ function get_moderators(&$forum_moderators, $forum_id = false)
),
),
- 'WHERE' => "m.display_on_index = 1 $forum_sql",
+ 'WHERE' => 'm.display_on_index = 1',
);
+ // We query every forum here because for caching we should not have any parameter.
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql, 3600);
while ($row = $db->sql_fetchrow($result))
{
+ $f_id = (int) $row['forum_id'];
+
+ if (!isset($forum_id_ary[$f_id]))
+ {
+ continue;
+ }
+
if (!empty($row['user_id']))
{
- $forum_moderators[$row['forum_id']][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
+ $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
}
else
{
@@ -724,11 +720,11 @@ function get_moderators(&$forum_moderators, $forum_id = false)
if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
{
- $forum_moderators[$row['forum_id']][] = '' . $group_name . '';
+ $forum_moderators[$f_id][] = '' . $group_name . '';
}
else
{
- $forum_moderators[$row['forum_id']][] = '' . $group_name . '';
+ $forum_moderators[$f_id][] = '' . $group_name . '';
}
}
}
diff --git a/phpBB/posting.php b/phpBB/posting.php
index 90d5755003..9f63e43345 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -1183,7 +1183,10 @@ if (sizeof($post_data['poll_options']) && $post_data['poll_title'])
// Forum moderators?
$moderators = array();
-get_moderators($moderators, $forum_id);
+if ($config['load_moderators'])
+{
+ get_moderators($moderators, $forum_id);
+}
// Generate smiley listing
generate_smilies('inline', $forum_id);
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index 507ea18d24..1a2333ac8b 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -135,7 +135,10 @@ if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
else
{
$template->assign_var('S_HAS_SUBFORUM', false);
- get_moderators($moderators, $forum_id);
+ if ($config['load_moderators'])
+ {
+ get_moderators($moderators, $forum_id);
+ }
}
// Dump out the page header and load viewforum template
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index aedf464248..0387ae3a05 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -550,7 +550,10 @@ generate_forum_rules($topic_data);
// Moderators
$forum_moderators = array();
-get_moderators($forum_moderators, $forum_id);
+if ($config['load_moderators'])
+{
+ get_moderators($forum_moderators, $forum_id);
+}
// This is only used for print view so ...
$server_path = (!$view) ? $phpbb_root_path : generate_board_url() . '/';