Skip to content

Commit 2694d4b

Browse files
Preserves buddy list in User properties even if feature is disabled
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
1 parent 8c00abb commit 2694d4b

9 files changed

Lines changed: 23 additions & 10 deletions

File tree

Sources/Actions/AutoSuggest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use SMF\ActionInterface;
1919
use SMF\ActionRouter;
2020
use SMF\ActionTrait;
21+
use SMF\Config;
2122
use SMF\Db\DatabaseApi as Db;
2223
use SMF\IntegrationHook;
2324
use SMF\OutputTypeInterface;
@@ -136,6 +137,11 @@ public function member(): array
136137
],
137138
];
138139

140+
// Can't search for buddies if that feature is disabled.
141+
if (empty(Config::$modSettings['enable_buddylist'])) {
142+
unset($this->search_param['buddies']);
143+
}
144+
139145
// Find the member.
140146
$request = Db::$db->query(
141147
'SELECT id_member, real_name

Sources/Actions/BoardIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function execute(): void
8080

8181
// Set a few minor things.
8282
Utils::$context['show_stats'] = User::$me->allowedTo('view_stats') && !empty(Config::$modSettings['trackStats']);
83-
Utils::$context['show_buddies'] = !empty(User::$me->buddies);
83+
Utils::$context['show_buddies'] = !empty(User::$me->buddies) && !empty(Config::$modSettings['enable_buddylist']);
8484
Utils::$context['show_who'] = User::$me->allowedTo('who_view') && !empty(Config::$modSettings['who_enabled']);
8585

8686
// Retrieve the categories and boards.

Sources/Actions/BuddyListToggle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use SMF\ActionRouter;
2020
use SMF\ActionTrait;
2121
use SMF\Cache\CacheApi;
22+
use SMF\Config;
2223
use SMF\Db\DatabaseApi as Db;
2324
use SMF\ErrorHandler;
2425
use SMF\Routable;
@@ -61,7 +62,7 @@ public function execute(): void
6162
User::$me->isAllowedTo('profile_extra_own');
6263
User::$me->kickIfGuest();
6364

64-
if (empty($this->userReceiver)) {
65+
if (empty($this->userReceiver) || empty(Config::$modSettings['enable_buddylist'])) {
6566
ErrorHandler::fatalLang('no_access', false);
6667
}
6768

Sources/Actions/Display.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ protected function getWhoViewing(): void
861861
$link = '<a href="' . Config::$scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
862862
}
863863

864-
$is_buddy = \in_array($row['id_member'], User::$me->buddies);
864+
$is_buddy = !empty(Config::$modSettings['enable_buddylist']) && \in_array($row['id_member'], User::$me->buddies);
865865

866866
if ($is_buddy) {
867867
$link = '<strong>' . $link . '</strong>';

Sources/Actions/MessageIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ protected function getWhoViewing(): void
870870
$link = '<a href="' . Config::$scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
871871
}
872872

873-
$is_buddy = \in_array($row['id_member'], User::$me->buddies);
873+
$is_buddy = !empty(Config::$modSettings['enable_buddylist']) && \in_array($row['id_member'], User::$me->buddies);
874874

875875
if ($is_buddy) {
876876
$link = '<strong>' . $link . '</strong>';

Sources/Actions/RequestMembers.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use SMF\ActionInterface;
1919
use SMF\ActionRouter;
2020
use SMF\ActionTrait;
21+
use SMF\Config;
2122
use SMF\Db\DatabaseApi as Db;
2223
use SMF\Routable;
2324
use SMF\User;
@@ -65,6 +66,11 @@ public function execute(): void
6566

6667
header('content-type: text/plain; charset=UTF-8');
6768

69+
// Can't search for buddies if that feature is disabled.
70+
if (empty(Config::$modSettings['enable_buddylist'])) {
71+
unset($_REQUEST['buddies']);
72+
}
73+
6874
$request = Db::$db->query(
6975
'SELECT real_name
7076
FROM {db_prefix}members

Sources/Logging.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ public static function getMembersOnlineStats(array $membersOnlineOptions): array
669669
}
670670

671671
// Buddies get counted and highlighted.
672-
$is_buddy = \in_array($row['id_member'], User::$me->buddies);
672+
$is_buddy = !empty(Config::$modSettings['enable_buddylist']) && \in_array($row['id_member'], User::$me->buddies);
673673

674674
if ($is_buddy) {
675675
$membersOnlineStats['num_buddies']++;

Sources/ServerSideIncludes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ public static function whosOnline(string $output_method = 'echo'): ?array
16941694

16951695
$bracketList = [];
16961696

1697-
if (!empty(User::$me->buddies)) {
1697+
if (!empty(Config::$modSettings['enable_buddylist']) && !empty(User::$me->buddies)) {
16981698
$bracketList[] = Lang::getTxt('number_of_buddies', [$return['num_buddies']], file: 'General');
16991699
}
17001700

Sources/User.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,8 @@ public function format(bool $display_custom_fields = false): array
10391039
'username_color' => '<span ' . (!empty($this->group_color) ? 'style="color:' . $this->group_color . ';"' : '') . '>' . $this->username . '</span>',
10401040
'name_color' => '<span ' . (!empty($this->group_color) ? 'style="color:' . $this->group_color . ';"' : '') . '>' . $this->name . '</span>',
10411041
'link_color' => '<a href="' . Config::$scripturl . '?action=profile;u=' . $this->id . '" title="' . Lang::getTxt('view_profile_of_username', ['name' => $this->name], file: 'General') . '" ' . (!empty($this->group_color) ? 'style="color:' . $this->group_color . ';"' : '') . '>' . $this->name . '</a>',
1042-
'is_buddy' => \in_array($this->id, self::$me->buddies),
1043-
'is_reverse_buddy' => \in_array(self::$me->id, $this->buddies),
1042+
'is_buddy' => !empty(Config::$modSettings['enable_buddylist']) && \in_array($this->id, self::$me->buddies),
1043+
'is_reverse_buddy' => !empty(Config::$modSettings['enable_buddylist']) && \in_array(self::$me->id, $this->buddies),
10441044
'buddies' => $this->buddies,
10451045
'title' => !empty(Config::$modSettings['titlesEnable']) ? $this->title : '',
10461046
'blurb' => $this->personal_text,
@@ -3620,7 +3620,7 @@ public static function find(string|array $names, bool $use_wildcards = false, bo
36203620
AND is_activated IN ({array_int:activated})
36213621
LIMIT {int:limit}',
36223622
array_merge($where_params, [
3623-
'buddy_list' => self::$me->buddies,
3623+
'buddy_list' => !empty(Config::$modSettings['enable_buddylist']) ? self::$me->buddies : [],
36243624
'limit' => $max,
36253625
'activated' => [self::ACTIVATED, self::ACTIVATED_BANNED],
36263626
]),
@@ -3946,7 +3946,7 @@ protected function setProperties(): void
39463946
$this->time_offset = (int) ($profile['time_offset'] ?? 0);
39473947

39483948
// Buddies and personal messages.
3949-
$this->buddies = !empty(Config::$modSettings['enable_buddylist']) && !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : [];
3949+
$this->buddies = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : [];
39503950
$this->ignoreusers = !empty($profile['pm_ignore_list']) ? explode(',', $profile['pm_ignore_list']) : [];
39513951
$this->pm_receive_from = (int) ($profile['pm_receive_from'] ?? 0);
39523952
$this->pm_prefs = (int) ($profile['pm_prefs'] ?? 0);

0 commit comments

Comments
 (0)