diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1b5fa1272..bfe8b22b7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
**Merged pull requests:**
+- Simplified gender function [\#1167](https://github.com/torrentpier/torrentpier/pull/1167) ([belomaxorka](https://github.com/belomaxorka))
- Revert "Fixed input types in some cases (#697)" [20ce8ca](https://github.com/torrentpier/torrentpier/commit/20ce8cae9cf6447f5100ab2d8f4a5299254f5412) ([belomaxorka](https://github.com/belomaxorka))
- Revert "Fixed input types in some cases (#693)" [74aa6ff](https://github.com/torrentpier/torrentpier/commit/74aa6ff29991186ffc6484980972d5f74e4d0393) ([belomaxorka](https://github.com/belomaxorka))
- Support simultaneous id & username inputs for browsing profiles [\#1166](https://github.com/torrentpier/torrentpier/pull/1166) ([kovalensky](https://github.com/kovalensky))
diff --git a/library/includes/functions.php b/library/includes/functions.php
index 92be75480..8dd9206d2 100644
--- a/library/includes/functions.php
+++ b/library/includes/functions.php
@@ -1994,30 +1994,25 @@ function get_avatar($user_id, $ext_id, $allow_avatar = true, $height = '', $widt
return $user_avatar;
}
-function gender_image($gender): string
+/**
+ * Returns gender image
+ *
+ * @param int $gender
+ * @return string|null
+ */
+function genderImage(int $gender): ?string
{
global $bb_cfg, $lang, $images;
- $gender = (int)$gender;
- $user_gender = '';
-
if (!$bb_cfg['gender']) {
- return $user_gender;
+ return false;
}
- switch ($gender) {
- case MALE:
- $user_gender = '
';
- break;
- case FEMALE:
- $user_gender = '
';
- break;
- default:
- $user_gender = '
';
- break;
- }
-
- return $user_gender;
+ return match ($gender) {
+ MALE => '
',
+ FEMALE => '
',
+ default => '
',
+ };
}
function is_gold($type): string
diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php
index 9ecb21c7c..3935e77a5 100644
--- a/library/includes/ucp/viewprofile.php
+++ b/library/includes/ucp/viewprofile.php
@@ -97,7 +97,7 @@ $template->assign_vars([
'SKYPE' => $profiledata['user_skype'],
'TWITTER' => $profiledata['user_twitter'],
'USER_POINTS' => $profiledata['user_points'],
- 'GENDER' => ($bb_cfg['gender']) ? $lang['GENDER_SELECT'][$profiledata['user_gender']] : '',
+ 'GENDER' => $bb_cfg['gender'] ? $lang['GENDER_SELECT'][$profiledata['user_gender']] : '',
'BIRTHDAY' => ($bb_cfg['birthday_enabled'] && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? $profiledata['user_birthday'] : '',
'BIRTHDAY_ICON' => user_birthday_icon($profiledata['user_birthday'], $profiledata['user_id']),
'AGE' => ($bb_cfg['birthday_enabled'] && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? birthday_age($profiledata['user_birthday']) : '',
diff --git a/viewtopic.php b/viewtopic.php
index 9c28ec2c1..139edd816 100644
--- a/viewtopic.php
+++ b/viewtopic.php
@@ -707,7 +707,7 @@ for ($i = 0; $i < $total_posts; $i++) {
'POSTER_GUEST' => $poster_guest,
'POSTER_ID' => $poster_id,
'POSTER_AUTHOR' => ($poster_id == $t_data['topic_poster']),
- 'POSTER_GENDER' => $bb_cfg['gender'] ? gender_image($postrow[$i]['user_gender']) : '',
+ 'POSTER_GENDER' => genderImage((int)$postrow[$i]['user_gender']),
'POSTED_AFTER' => $prev_post_time ? delta_time($postrow[$i]['post_time'], $prev_post_time) : '',
'IS_UNREAD' => is_unread($postrow[$i]['post_time'], $topic_id, $forum_id),
'IS_FIRST_POST' => (!$start && $is_first_post),