From 54170e1e30e28d2214528830d9dcfe32c1ffbcca Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 2 Jul 2025 20:20:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Use=20an=20array=20for=20t?= =?UTF-8?q?he=20user=20socials?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bl-kernel/admin/views/edit-user.php | 108 +++------------------------- bl-kernel/user.class.php | 4 ++ bl-kernel/users.class.php | 11 ++- 3 files changed, 25 insertions(+), 98 deletions(-) diff --git a/bl-kernel/admin/views/edit-user.php b/bl-kernel/admin/views/edit-user.php index de653be6..f4c8a6ce 100644 --- a/bl-kernel/admin/views/edit-user.php +++ b/bl-kernel/admin/views/edit-user.php @@ -249,104 +249,18 @@ echo Bootstrap::formInputHidden(array(
g('Social Networks')); - echo Bootstrap::formInputText(array( - 'name' => 'twitter', - 'label' => 'Twitter', - 'value' => $user->twitter(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - echo Bootstrap::formInputText(array( - 'name' => 'facebook', - 'label' => 'Facebook', - 'value' => $user->facebook(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'codepen', - 'label' => 'CodePen', - 'value' => $user->codepen(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'instagram', - 'label' => 'Instagram', - 'value' => $user->instagram(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'gitlab', - 'label' => 'GitLab', - 'value' => $user->gitlab(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'github', - 'label' => 'GitHub', - 'value' => $user->github(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'linkedin', - 'label' => 'LinkedIn', - 'value' => $user->linkedin(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'xing', - 'label' => 'Xing', - 'value' => $user->xing(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'telegram', - 'label' => 'Telegram', - 'value' => $user->telegram(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'mastodon', - 'label' => 'Mastodon', - 'value' => $user->mastodon(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); - - echo Bootstrap::formInputText(array( - 'name' => 'vk', - 'label' => 'VK', - 'value' => $user->vk(), - 'class' => '', - 'placeholder' => '', - 'tip' => '' - )); + foreach ($GLOBALS['SOCIAL_NETWORKS'] as $key => $value) { + echo Bootstrap::formInputText(array( + 'name' => Text::cleanUrl($value), + 'label' => $value, + 'value' => $user->getSocialNetwork($value), + 'class' => '', + 'placeholder' => '', + 'tip' => '' + )); + } + echo Bootstrap::cardEnd(); ?>
diff --git a/bl-kernel/user.class.php b/bl-kernel/user.class.php index 07b0962a..3075d7ff 100644 --- a/bl-kernel/user.class.php +++ b/bl-kernel/user.class.php @@ -205,6 +205,10 @@ class User return $this->getValue('vk'); } + public function getSocialNetwork($social) { + return $this->getValue('socials')[Text::cleanUrl($social)]; + } + public function profilePicture() { $filename = $this->getValue('username') . '.png'; diff --git a/bl-kernel/users.class.php b/bl-kernel/users.class.php index d0a2c076..a5eeb679 100644 --- a/bl-kernel/users.class.php +++ b/bl-kernel/users.class.php @@ -26,7 +26,8 @@ class Users extends dbJSON { 'gitlab'=>'', 'linkedin'=>'', 'mastodon'=>'', - 'vk'=>'' + 'vk'=>'', + 'socials' => array() ); function __construct() @@ -128,6 +129,14 @@ class Users extends dbJSON { $row['tokenAuth'] = $this->generateAuthToken(); } + $row['socials'] = array(); + foreach ($GLOBALS['SOCIAL_NETWORKS'] as $key => $social) { + $socialKey = Text::cleanUrl($social); + if (isset($args[$socialKey])) { + $row['socials'][$socialKey] = $args[$socialKey]; + } + } + // Save the database $this->db[$username] = $row; return $this->save();