</section>
{/if}
- {if $availableStyles|count > 1}
- <section class="section" id="section_style">
- <h2 class="sectionTitle">{lang}wcf.user.styles{/lang}</h2>
+ <section class="section" id="section_style">
+ <h2 class="sectionTitle">{lang}wcf.user.styles{/lang}</h2>
+ {if $availableStyles|count > 1}
<dl>
<dt><label for="styleID">{lang}wcf.user.style{/lang}</label></dt>
<dd>
<small>{lang}wcf.user.style.description{/lang}</small>
</dd>
</dl>
-
- {event name='styleFields'}
- </section>
- {/if}
+ {/if}
+
+ <dl>
+ <dt><label for="colorScheme">{lang}wcf.user.style.colorScheme{/lang}</label></dt>
+ <dd>
+ <select id="colorScheme" name="colorScheme">
+ <option value="system"{if $colorScheme === 'system'} selected{/if}>{lang}wcf.style.setColorScheme.system{/lang}</option>
+ <option value="light"{if $colorScheme === 'light'} selected{/if}>{lang}wcf.style.setColorScheme.light{/lang}</option>
+ <option value="dark"{if $colorScheme === 'dark'} selected{/if}>{lang}wcf.style.setColorScheme.dark{/lang}</option>
+ </select>
+ <small>{lang}wcf.user.style.colorScheme.description{/lang}</small>
+ </dd>
+ </dl>
+
+ {event name='styleFields'}
+ </section>
{if MODULE_TROPHY && $__wcf->getSession()->getPermission('user.profile.trophy.maxUserSpecialTrophies') > 0 && $availableTrophies|count}
<section class="section" id="section_trophy">
<optiontype>boolean</optiontype>
<defaultvalue>1</defaultvalue>
</option>
+ <option name="colorScheme">
+ <categoryname>hidden</categoryname>
+ <optiontype>select</optiontype>
+ <selectoptions>system:wcf.style.setColorScheme.system
+light:wcf.style.setColorScheme.light
+dark:wcf.style.setColorScheme.dark</selectoptions>
+ <defaultvalue>system</defaultvalue>
+ </option>
<option name="timezone">
<categoryname>settings.general.date</categoryname>
<optiontype>timezone</optiontype>
use wcf\system\option\user\UserOptionHandler;
use wcf\system\request\LinkHandler;
use wcf\system\style\StyleHandler;
+use wcf\system\user\command\SetColorScheme;
use wcf\system\user\storage\UserStorageHandler;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
*/
public $specialTrophies = [];
+ public string $colorScheme = 'system';
+
/**
* @inheritDoc
*/
if (isset($_POST['specialTrophies'])) {
$this->specialTrophies = ArrayUtil::toIntegerArray($_POST['specialTrophies']);
}
+ if (isset($_POST['colorScheme'])) {
+ $this->colorScheme = $_POST['colorScheme'];
+ }
}
}
throw new UserInputException('specialTrophies', 'invalid');
}
}
+
+ if ($this->colorScheme !== 'light' && $this->colorScheme !== 'dark') {
+ $this->colorScheme = 'system';
+ }
}
}
$this->specialTrophies = \array_unique(\array_map(static function ($trophy) {
return $trophy->trophyID;
}, (new UserProfile(WCF::getUser()))->getSpecialTrophies()));
+
+ $this->colorScheme = WCF::getUser()->getUserOption('colorScheme');
}
}
}
'trophyIDs' => $this->specialTrophies,
]);
$userProfileAction->executeAction();
+
+ if (WCF::getUser()->getUserOption('colorScheme') !== $this->colorScheme) {
+ $command = new SetColorScheme(WCF::getUser(), $this->colorScheme);
+ $command();
+ }
}
$this->saved();
'languageID' => $this->languageID,
'styleID' => $this->styleID,
'specialTrophies' => $this->specialTrophies,
+ 'colorScheme' => $this->colorScheme,
]);
}
}
--- /dev/null
+<?php
+
+namespace wcf\system\user\command;
+
+use wcf\data\user\User;
+use wcf\data\user\UserAction;
+
+/**
+ * Sets the preferred color scheme of a user.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.0
+ */
+final class SetColorScheme
+{
+ private readonly User $user;
+ private readonly string $colorScheme;
+
+ public function __construct(User $user, string $colorScheme)
+ {
+ $this->user = $user;
+ $this->colorScheme = $colorScheme;
+ }
+
+ public function __invoke(): void
+ {
+ $userAction = new UserAction([$this->user], 'update', [
+ 'options' => [
+ User::getUserOptionID('colorScheme') => $this->colorScheme,
+ ],
+ ]);
+ $userAction->executeAction();
+ }
+}
<item name="wcf.user.style"><![CDATA[Stil]]></item>
<item name="wcf.user.styles"><![CDATA[Stile]]></item>
<item name="wcf.user.style.description"><![CDATA[Stil der Benutzeroberfläche]]></item>
+ <item name="wcf.user.style.colorScheme"><![CDATA[Bevorzugtes Farbschema]]></item>
+ <item name="wcf.user.style.colorScheme.description"><![CDATA[Die automatische Erkennung wendet das Farbschema basierend auf den Präferenzen Ihres Geräts an. Einige Stile verfügen möglicherweise nicht über angepasste Farbschemas.]]></item>
<item name="wcf.user.username.description"><![CDATA[Der Benutzername muss mindestens {REGISTER_USERNAME_MIN_LENGTH} und darf maximal {REGISTER_USERNAME_MAX_LENGTH} Zeichen lang sein.]]></item>
<item name="wcf.user.password.description"><![CDATA[Ein sicheres Kennwort sollte mindestens 10 Zeichen lang sein.]]></item>
<item name="wcf.user.password.strength"><![CDATA[Kennwortstärke]]></item>
<item name="wcf.user.style"><![CDATA[Style]]></item>
<item name="wcf.user.styles"><![CDATA[Styles]]></item>
<item name="wcf.user.style.description"><![CDATA[Forces a specific style instead of the default one.]]></item>
+ <item name="wcf.user.style.colorScheme"><![CDATA[Preferred Color Scheme]]></item>
+ <item name="wcf.user.style.colorScheme.description"><![CDATA[The automatic detection applies the color scheme based on your device’s preferences. Some styles might not offer a custom color scheme.]]></item>
<item name="wcf.user.username.description"><![CDATA[Username must be {REGISTER_USERNAME_MIN_LENGTH} up to {REGISTER_USERNAME_MAX_LENGTH} characters long.]]></item>
<item name="wcf.user.password.description"><![CDATA[A secure password should be at least 10 characters long.]]></item>
<item name="wcf.user.password.strength"><![CDATA[Password Strength]]></item>