diff --git a/view/theme/frio/config.php b/view/theme/frio/config.php index 3703912d3f..62969badeb 100644 --- a/view/theme/frio/config.php +++ b/view/theme/frio/config.php @@ -24,6 +24,7 @@ use Friendica\Core\Renderer; use Friendica\DI; require_once 'view/theme/frio/php/Image.php'; +require_once 'view/theme/frio/php/scheme.php'; function theme_post(App $a) { @@ -93,14 +94,7 @@ function theme_content(): string } $arr = [ - 'scheme' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'scheme', - DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'schema', - DI::config()->get('frio', 'scheme', - DI::config()->get('frio', 'schema') - ) - ) - ), - + 'scheme' => frio_scheme_get_current_for_user(DI::userSession()->getLocalUserId()), 'share_string' => '', 'scheme_accent' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'scheme_accent' , DI::config()->get('frio', 'scheme_accent')), 'nav_bg' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'nav_bg' , DI::config()->get('frio', 'nav_bg')), @@ -123,8 +117,8 @@ function theme_admin(): string } $arr = [ - 'scheme' => DI::config()->get('frio', 'scheme', DI::config()->get('frio', 'schema')), - 'scheme_accent' => DI::config()->get('frio', 'scheme_accent'), + 'scheme' => frio_scheme_get_current(), + 'scheme_accent' => DI::config()->get('frio', 'scheme_accent') ?: FRIO_SCHEME_ACCENT_BLUE, 'share_string' => '', 'nav_bg' => DI::config()->get('frio', 'nav_bg'), 'nav_icon_color' => DI::config()->get('frio', 'nav_icon_color'), @@ -149,33 +143,15 @@ function frio_form($arr) $scheme_info = get_scheme_info($arr['scheme']); $disable = $scheme_info['overwrites']; - $schemes = [ - 'light' => DI::l10n()->t('Light (Accented)'), - 'dark' => DI::l10n()->t('Dark (Accented)'), - 'black' => DI::l10n()->t('Black (Accented)'), - ]; - - $legacy_schemes = []; - foreach (glob('view/theme/frio/scheme/*.php') ?: [] as $file) { - $scheme = basename($file, '.php'); - if (!in_array($scheme, ['default', 'light', 'dark', 'black'])) { - $scheme_name = ucfirst($scheme); - $legacy_schemes[$scheme] = $scheme_name; - } - } - $background_image_help = '' . DI::l10n()->t('Note') . ': ' . DI::l10n()->t('Check image permissions if all users are allowed to see the image'); $t = Renderer::getMarkupTemplate('theme_settings.tpl'); $ctx = [ '$submit' => DI::l10n()->t('Submit'), '$title' => DI::l10n()->t('Theme settings'), - '$custom' => DI::l10n()->t('Custom'), - '$legacy' => DI::l10n()->t('Legacy'), - '$accented' => DI::l10n()->t('Accented'), - '$scheme' => ['frio_scheme', DI::l10n()->t('Select color scheme'), $arr['scheme'], $schemes, $legacy_schemes], - '$scheme_accent' => !$scheme_info['accented'] ? '' : ['frio_scheme_accent', DI::l10n()->t('Select scheme accent'), $arr['scheme_accent'], ['blue' => DI::l10n()->t('Blue'), 'red' => DI::l10n()->t('Red'), 'purple' => DI::l10n()->t('Purple'), 'green' => DI::l10n()->t('Green'), 'pink' => DI::l10n()->t('Pink')]], - '$share_string' => $arr['scheme'] != '---' ? '' : ['frio_share_string', DI::l10n()->t('Copy or paste schemestring'), $arr['share_string'], DI::l10n()->t('You can copy this string to share your theme with others. Pasting here applies the schemestring'), false, false], + '$scheme' => ['frio_scheme', DI::l10n()->t('Appearance'), $arr['scheme'], frio_scheme_get_list()], + '$scheme_accent' => !$scheme_info['accented'] ? '' : ['frio_scheme_accent', DI::l10n()->t('Accent color'), $arr['scheme_accent'], ['blue' => DI::l10n()->t('Blue'), 'red' => DI::l10n()->t('Red'), 'purple' => DI::l10n()->t('Purple'), 'green' => DI::l10n()->t('Green'), 'pink' => DI::l10n()->t('Pink')]], + '$share_string' => $arr['scheme'] != FRIO_CUSTOM_SCHEME ? '' : ['frio_share_string', DI::l10n()->t('Copy or paste schemestring'), $arr['share_string'], DI::l10n()->t('You can copy this string to share your theme with others. Pasting here applies the schemestring'), false, false], '$nav_bg' => array_key_exists('nav_bg', $disable) ? '' : ['frio_nav_bg', DI::l10n()->t('Navigation bar background color'), $arr['nav_bg'], '', false], '$nav_icon_color' => array_key_exists('nav_icon_color', $disable) ? '' : ['frio_nav_icon_color', DI::l10n()->t('Navigation bar icon color '), $arr['nav_icon_color'], '', false], '$link_color' => array_key_exists('link_color', $disable) ? '' : ['frio_link_color', DI::l10n()->t('Link color'), $arr['link_color'], '', false], diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index 14914288aa..02e073a364 100644 --- a/view/theme/frio/php/default.php +++ b/view/theme/frio/php/default.php @@ -29,6 +29,7 @@ use Friendica\Model\Profile; require_once 'view/theme/frio/theme.php'; require_once 'view/theme/frio/php/frio_boot.php'; +require_once 'view/theme/frio/php/scheme.php'; // $minimal = is_modal(); if (!isset($minimal)) { @@ -59,8 +60,8 @@ $is_singleuser_class = $is_singleuser ? "is-singleuser" : "is-not-singleuser"; // Add the theme color meta // It makes mobile Chrome UI match Frio's top bar color. $uid = Profile::getThemeUid($a); - $scheme = DI::pConfig()->get($uid, 'frio', 'scheme', DI::pConfig()->get($uid, 'frio', 'schema')); - if ($scheme && is_string($scheme) && $scheme != '---') { + $scheme = frio_scheme_get_current_for_user($uid); + if ($scheme != FRIO_CUSTOM_SCHEME) { if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) { $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php'; $scheme_accent = diff --git a/view/theme/frio/php/scheme.php b/view/theme/frio/php/scheme.php index aa6571a4d1..7304d83cd0 100644 --- a/view/theme/frio/php/scheme.php +++ b/view/theme/frio/php/scheme.php @@ -37,15 +37,13 @@ use Friendica\DI; use Friendica\Util\Strings; +require_once 'view/theme/frio/theme.php'; + function get_scheme_info($scheme) { $theme = DI::app()->getCurrentTheme(); $themepath = 'view/theme/' . $theme . '/'; - if (empty($scheme)) { - $scheme = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'scheme', DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'schema', '---')); - } - - $scheme = Strings::sanitizeFilePathItem($scheme); + $scheme = Strings::sanitizeFilePathItem($scheme) ?: FRIO_DEFAULT_SCHEME; $info = [ 'name' => $scheme, @@ -100,3 +98,54 @@ function get_scheme_info($scheme) return $info; } + +function frio_scheme_get_list(): array +{ + $schemes = [ + 'light' => DI::l10n()->t('Light'), + 'dark' => DI::l10n()->t('Dark'), + 'black' => DI::l10n()->t('Black'), + ]; + + foreach (glob('view/theme/frio/scheme/*.php') ?: [] as $file) { + $scheme = basename($file, '.php'); + if (!in_array($scheme, ['default', 'light', 'dark', 'black'])) { + $scheme_info = get_scheme_info($scheme); + $schemes[$scheme] = $scheme_info['name'] ?? ucfirst($scheme); + } + } + + $schemes[FRIO_CUSTOM_SCHEME] = DI::l10n()->t('Custom'); + + return $schemes; +} + +function frio_scheme_get_current() +{ + $available = array_keys(frio_scheme_get_list()); + + $scheme = DI::config()->get('frio', 'scheme') ?: DI::config()->get('frio', 'schema'); + + if (!in_array($scheme, $available)) { + return FRIO_DEFAULT_SCHEME; + } + + return $scheme; +} + +function frio_scheme_get_current_for_user(int $uid) +{ + $available = array_keys(frio_scheme_get_list()); + + $scheme = + DI::pConfig()->get($uid, 'frio', 'scheme') ?: + DI::pConfig()->get($uid, 'frio', 'schema') ?: + DI::config()->get('frio', 'scheme') ?: + DI::config()->get('frio', 'schema'); + + if (!in_array($scheme, $available)) { + return FRIO_DEFAULT_SCHEME; + } + + return $scheme; +} diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index a0cf77932a..d0de2d8262 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -24,10 +24,9 @@ use Friendica\Network\HTTPException\NotModifiedException; use Friendica\Util\Strings; require_once 'view/theme/frio/theme.php'; +require_once 'view/theme/frio/php/scheme.php'; require_once 'view/theme/frio/php/PHPColors/Color.php'; -$scheme = ''; -$schemecss = ''; $schemecssfile = false; $scheme_modified = 0; @@ -35,7 +34,7 @@ $scheme_modified = 0; * This script can be included when the maintenance mode is on, which requires us to avoid any config call and * use the following hardcoded defaults */ -$scheme = null; +$scheme = FRIO_DEFAULT_SCHEME; $scheme_accent = FRIO_SCHEME_ACCENT_BLUE; $nav_bg = '#708fa0'; $nav_icon_color = '#ffffff'; @@ -52,7 +51,7 @@ if (DI::mode()->has(\Friendica\App\Mode::MAINTENANCEDISABLED)) { DI::config()->reload(); // Default to hard-coded values for empty settings - $scheme = DI::config()->get('frio', 'scheme', DI::config()->get('frio', 'schema')); + $scheme = frio_scheme_get_current(); $scheme_accent = DI::config()->get('frio', 'scheme_accent') ?: $scheme_accent; $nav_bg = DI::config()->get('frio', 'nav_bg') ?: $nav_bg; $nav_icon_color = DI::config()->get('frio', 'nav_icon_color') ?: $nav_icon_color; @@ -71,7 +70,7 @@ if (DI::mode()->has(\Friendica\App\Mode::MAINTENANCEDISABLED)) { DI::pConfig()->load($uid, 'frio'); // Only override display settings that have actually been set - $scheme = DI::pConfig()->get($uid, 'frio', 'scheme', DI::pConfig()->get($uid, 'frio', 'schema')) ?: $scheme; + $scheme = frio_scheme_get_current_for_user($uid); $scheme_accent = DI::pConfig()->get($uid, 'frio', 'scheme_accent') ?: $scheme_accent; $nav_bg = DI::pConfig()->get($uid, 'frio', 'nav_bg') ?: $nav_bg; $nav_icon_color = DI::pConfig()->get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color; @@ -89,18 +88,9 @@ if (!$login_bg_image && !$login_bg_color) { } $login_bg_color = $login_bg_color ?: '#ededed'; -// Now load the scheme. If a value is changed above, we'll keep the settings -// If not, we'll keep those defined by the scheme -// Setting $scheme to '' wasn't working for some reason, so we'll check it's -// not --- like the mobile theme does instead. -// Allow layouts to over-ride the scheme. -if (!empty($_REQUEST['scheme'])) { - $scheme = $_REQUEST['scheme']; -} +$scheme = Strings::sanitizeFilePathItem($scheme); -$scheme = Strings::sanitizeFilePathItem($scheme ?? ''); - -if ($scheme && ($scheme != '---')) { +if ($scheme != FRIO_CUSTOM_SCHEME) { if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) { $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php'; require_once $schemefile; @@ -110,19 +100,6 @@ if ($scheme && ($scheme != '---')) { } } -// If we haven't got a scheme, load the default. We shouldn't touch this - we -// should leave it for admins to define for themselves. -// default.php and default.css MUST be symlinks to existing scheme files. -if (!$scheme) { - if (file_exists('view/theme/frio/scheme/default.php')) { - $schemefile = 'view/theme/frio/scheme/default.php'; - require_once $schemefile; - } - if (file_exists('view/theme/frio/scheme/default.css')) { - $schemecssfile = 'view/theme/frio/scheme/default.css'; - } -} - $contentbg_transp = $contentbg_transp != '' ? $contentbg_transp : 100; // Calculate some colors in dependance of existing colors. diff --git a/view/theme/frio/templates/theme_settings.tpl b/view/theme/frio/templates/theme_settings.tpl index 7e53429e3b..0e10070684 100644 --- a/view/theme/frio/templates/theme_settings.tpl +++ b/view/theme/frio/templates/theme_settings.tpl @@ -4,17 +4,9 @@