Added some experimental background options.
This commit is contained in:
parent
d7fc87685d
commit
fd1a2fd76e
7 changed files with 183 additions and 30 deletions
|
@ -67,6 +67,26 @@ body {
|
||||||
&--legacy {
|
&--legacy {
|
||||||
--background-color: #fbeeff;
|
--background-color: #fbeeff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--bg-blend {
|
||||||
|
background-blend-mode: multiply;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*&--bg-slide {
|
||||||
|
}*/
|
||||||
|
|
||||||
|
&--bg-cover {
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--bg-stretch {
|
||||||
|
background-size: 100% 100%;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--bg-tile {
|
||||||
|
background-repeat: repeat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input elements
|
// Input elements
|
||||||
|
|
20
database/2018_10_01_081226_add_background_settings_field.php
Normal file
20
database/2018_10_01_081226_add_background_settings_field.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
namespace Misuzu\DatabaseMigrations\AddBackgroundSettingsField;
|
||||||
|
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
function migrate_up(PDO $conn): void
|
||||||
|
{
|
||||||
|
$conn->exec("
|
||||||
|
ALTER TABLE `msz_users`
|
||||||
|
ADD COLUMN `user_background_settings` TINYINT(4) DEFAULT '0' AFTER `user_about_parser`;
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
function migrate_down(PDO $conn): void
|
||||||
|
{
|
||||||
|
$conn->exec('
|
||||||
|
ALTER TABLE `msz_users`
|
||||||
|
DROP COLUMN `user_background_settings`;
|
||||||
|
');
|
||||||
|
}
|
|
@ -260,6 +260,7 @@ MIG;
|
||||||
tpl_add_function('asset_url', true);
|
tpl_add_function('asset_url', true);
|
||||||
tpl_add_function('vsprintf', true);
|
tpl_add_function('vsprintf', true);
|
||||||
tpl_add_function('perms_check', true);
|
tpl_add_function('perms_check', true);
|
||||||
|
tpl_add_function('bg_settings', true, 'user_background_settings_strings');
|
||||||
|
|
||||||
tpl_add_function('git_commit_hash');
|
tpl_add_function('git_commit_hash');
|
||||||
tpl_add_function('git_branch');
|
tpl_add_function('git_branch');
|
||||||
|
@ -287,7 +288,7 @@ MIG;
|
||||||
|
|
||||||
$getUserDisplayInfo = Database::prepare('
|
$getUserDisplayInfo = Database::prepare('
|
||||||
SELECT
|
SELECT
|
||||||
u.`user_id`, u.`username`,
|
u.`user_id`, u.`username`, u.`user_background_settings`,
|
||||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||||
FROM `msz_users` as u
|
FROM `msz_users` as u
|
||||||
LEFT JOIN `msz_roles` as r
|
LEFT JOIN `msz_roles` as r
|
||||||
|
|
|
@ -156,6 +156,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
switch ($_POST['background']['mode'] ?? '') {
|
switch ($_POST['background']['mode'] ?? '') {
|
||||||
case 'delete':
|
case 'delete':
|
||||||
user_background_delete($settingsUserId);
|
user_background_delete($settingsUserId);
|
||||||
|
user_background_set_settings($settingsUserId, MSZ_USER_BACKGROUND_ATTACHMENT_NONE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'upload':
|
case 'upload':
|
||||||
|
@ -164,12 +165,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($_FILES['background'])
|
if (empty($_POST['background'])
|
||||||
|| !is_array($_FILES['background'])
|
|| !is_array($_POST['background'])) {
|
||||||
|| empty($_FILES['background']['name']['file'])) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($_FILES['background']['name']['file'])) {
|
||||||
if ($_FILES['background']['error']['file'] !== UPLOAD_ERR_OK) {
|
if ($_FILES['background']['error']['file'] !== UPLOAD_ERR_OK) {
|
||||||
$settingsErrors[] = sprintf(
|
$settingsErrors[] = sprintf(
|
||||||
MSZ_TMP_USER_ERROR_STRINGS['avatar']['upload'][$_FILES['background']['error']['file']]
|
MSZ_TMP_USER_ERROR_STRINGS['avatar']['upload'][$_FILES['background']['error']['file']]
|
||||||
|
@ -198,6 +199,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$backgroundProps['max_height']
|
$backgroundProps['max_height']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$backgroundSettings = in_array($_POST['background']['attach'] ?? '', MSZ_USER_BACKGROUND_ATTACHMENTS_NAMES)
|
||||||
|
? array_flip(MSZ_USER_BACKGROUND_ATTACHMENTS_NAMES)[$_POST['background']['attach']]
|
||||||
|
: MSZ_USER_BACKGROUND_ATTACHMENTS[0];
|
||||||
|
|
||||||
|
if (!empty($_POST['background']['attr']['blend'])) {
|
||||||
|
$backgroundSettings |= MSZ_USER_BACKGROUND_ATTRIBUTE_BLEND;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['background']['attr']['slide'])) {
|
||||||
|
$backgroundSettings |= MSZ_USER_BACKGROUND_ATTRIBUTE_SLIDE;
|
||||||
|
}
|
||||||
|
|
||||||
|
user_background_set_settings($settingsUserId, $backgroundSettings);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,11 +350,17 @@ switch ($settingsMode) {
|
||||||
|
|
||||||
$getAccountInfo = Database::prepare(sprintf(
|
$getAccountInfo = Database::prepare(sprintf(
|
||||||
'
|
'
|
||||||
SELECT %s, `email`, `user_about_content`, `user_about_parser`
|
SELECT
|
||||||
|
%1$s, `email`, `user_about_content`, `user_about_parser`,
|
||||||
|
`user_background_settings` & 0x0F as `user_background_attachment`,
|
||||||
|
(`user_background_settings` & %2$d) > 0 as `user_background_attr_blend`,
|
||||||
|
(`user_background_settings` & %3$d) > 0 as `user_background_attr_slide`
|
||||||
FROM `msz_users`
|
FROM `msz_users`
|
||||||
WHERE `user_id` = :user_id
|
WHERE `user_id` = :user_id
|
||||||
',
|
',
|
||||||
pdo_prepare_array($profileFields, true, '`user_%s`')
|
pdo_prepare_array($profileFields, true, '`user_%s`'),
|
||||||
|
MSZ_USER_BACKGROUND_ATTRIBUTE_BLEND,
|
||||||
|
MSZ_USER_BACKGROUND_ATTRIBUTE_SLIDE
|
||||||
));
|
));
|
||||||
$getAccountInfo->bindValue('user_id', $settingsUserId);
|
$getAccountInfo->bindValue('user_id', $settingsUserId);
|
||||||
$accountInfo = $getAccountInfo->execute() ? $getAccountInfo->fetch(PDO::FETCH_ASSOC) : [];
|
$accountInfo = $getAccountInfo->execute() ? $getAccountInfo->fetch(PDO::FETCH_ASSOC) : [];
|
||||||
|
@ -354,6 +376,7 @@ switch ($settingsMode) {
|
||||||
'settings_profile_fields' => $profileFields,
|
'settings_profile_fields' => $profileFields,
|
||||||
'settings_disable_account_options' => $disableAccountOptions,
|
'settings_disable_account_options' => $disableAccountOptions,
|
||||||
'account_info' => $accountInfo,
|
'account_info' => $accountInfo,
|
||||||
|
'background_attachments' => MSZ_USER_BACKGROUND_ATTACHMENTS_NAMES,
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -233,6 +233,77 @@ function user_avatar_set_from_data(int $userId, string $data, array $options = [
|
||||||
|
|
||||||
define('MSZ_USER_BACKGROUND_FORMAT', '%d.msz');
|
define('MSZ_USER_BACKGROUND_FORMAT', '%d.msz');
|
||||||
|
|
||||||
|
// attachment and attributes are to be stored in the same byte
|
||||||
|
// left half is for attributes, right half is for attachments
|
||||||
|
// this makes for 16 possible attachments and 4 possible attributes
|
||||||
|
// since attachments are just an incrementing number and attrs are flags
|
||||||
|
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTACHMENT_NONE', 0);
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTACHMENT_COVER', 1);
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTACHMENT_STRETCH', 2);
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTACHMENT_TILE', 3);
|
||||||
|
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTACHMENTS', [
|
||||||
|
MSZ_USER_BACKGROUND_ATTACHMENT_NONE,
|
||||||
|
MSZ_USER_BACKGROUND_ATTACHMENT_COVER,
|
||||||
|
MSZ_USER_BACKGROUND_ATTACHMENT_STRETCH,
|
||||||
|
MSZ_USER_BACKGROUND_ATTACHMENT_TILE,
|
||||||
|
]);
|
||||||
|
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTACHMENTS_NAMES', [
|
||||||
|
MSZ_USER_BACKGROUND_ATTACHMENT_COVER => 'cover',
|
||||||
|
MSZ_USER_BACKGROUND_ATTACHMENT_STRETCH => 'stretch',
|
||||||
|
MSZ_USER_BACKGROUND_ATTACHMENT_TILE => 'tile',
|
||||||
|
]);
|
||||||
|
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTRIBUTE_BLEND', 0x10);
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTRIBUTE_SLIDE', 0x20);
|
||||||
|
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTRIBUTES', [
|
||||||
|
MSZ_USER_BACKGROUND_ATTRIBUTE_BLEND,
|
||||||
|
MSZ_USER_BACKGROUND_ATTRIBUTE_SLIDE,
|
||||||
|
]);
|
||||||
|
|
||||||
|
define('MSZ_USER_BACKGROUND_ATTRIBUTES_NAMES', [
|
||||||
|
MSZ_USER_BACKGROUND_ATTRIBUTE_BLEND => 'blend',
|
||||||
|
MSZ_USER_BACKGROUND_ATTRIBUTE_SLIDE => 'slide',
|
||||||
|
]);
|
||||||
|
|
||||||
|
function user_background_settings_strings(int $settings, string $format = '%s'): array
|
||||||
|
{
|
||||||
|
$arr = [];
|
||||||
|
|
||||||
|
$attachment = $settings & 0x0F;
|
||||||
|
|
||||||
|
if (array_key_exists($attachment, MSZ_USER_BACKGROUND_ATTACHMENTS_NAMES)) {
|
||||||
|
$arr[] = sprintf($format, MSZ_USER_BACKGROUND_ATTACHMENTS_NAMES[$attachment]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (MSZ_USER_BACKGROUND_ATTRIBUTES_NAMES as $flag => $name) {
|
||||||
|
if (($settings & $flag) > 0) {
|
||||||
|
$arr[] = sprintf($format, $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function user_background_set_settings(int $userId, int $settings): void
|
||||||
|
{
|
||||||
|
if ($userId < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$setAttrs = Database::prepare('
|
||||||
|
UPDATE `msz_users`
|
||||||
|
SET `user_background_settings` = :settings
|
||||||
|
WHERE `user_id` = :user
|
||||||
|
');
|
||||||
|
$setAttrs->bindValue('settings', $settings & 0xFF);
|
||||||
|
$setAttrs->bindValue('user', $userId);
|
||||||
|
$setAttrs->execute();
|
||||||
|
}
|
||||||
|
|
||||||
function user_background_delete(int $userId): void
|
function user_background_delete(int $userId): void
|
||||||
{
|
{
|
||||||
$backgroundFileName = sprintf(MSZ_USER_BACKGROUND_FORMAT, $userId);
|
$backgroundFileName = sprintf(MSZ_USER_BACKGROUND_FORMAT, $userId);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
</style>
|
</style>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
<body class="main">
|
<body class="main{% if current_user.user_background_settings is defined %} {{ current_user.user_background_settings|bg_settings('main--bg-%s')|join(' ') }}{% endif %}">
|
||||||
{% include '_layout/header.twig' %}
|
{% include '_layout/header.twig' %}
|
||||||
|
|
||||||
<div class="main__wrapper">
|
<div class="main__wrapper">
|
||||||
|
|
|
@ -218,6 +218,24 @@
|
||||||
<li class="settings__images__requirement">May not be larger than <strong>{{ background.max_width }}x{{ background.max_height }}</strong>.</li>
|
<li class="settings__images__requirement">May not be larger than <strong>{{ background.max_width }}x{{ background.max_height }}</strong>.</li>
|
||||||
<li class="settings__images__requirement">Animated gif images are <strong>not</strong> allowed.</li>
|
<li class="settings__images__requirement">Animated gif images are <strong>not</strong> allowed.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<select name="background[attach]" class="input__select">
|
||||||
|
{% for key, value in background_attachments %}
|
||||||
|
<option value="{{ value }}"{% if account_info.user_background_attachment == key %} selected{% endif %}>
|
||||||
|
{{ value|capitalize }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="background[attr][blend]"{% if account_info.user_background_attr_blend %} checked{% endif %}>
|
||||||
|
Blend
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="background[attr][slide]"{% if account_info.user_background_attr_slide %} checked{% endif %}>
|
||||||
|
Slide
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue