3 * @copyright Copyright (C) 2010-2024, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Network\HTTPException\NotModifiedException;
24 use Friendica\Util\Strings;
26 require_once 'view/theme/frio/theme.php';
27 require_once 'view/theme/frio/php/scheme.php';
28 require_once 'view/theme/frio/php/PHPColors/Color.php';
30 $schemecssfile = false;
34 * This script can be included when the maintenance mode is on, which requires us to avoid any config call and
35 * use the following hardcoded defaults
37 $scheme = FRIO_DEFAULT_SCHEME;
38 $scheme_accent = FRIO_SCHEME_ACCENT_BLUE;
40 $nav_icon_color = '#ffffff';
41 $link_color = '#6fdbe8';
42 $background_color = '#ededed';
43 $contentbg_transp = 100;
44 $background_image = 'img/none.png';
45 $bg_image_option = '';
50 if (DI::mode()->has(\Friendica\App\Mode::MAINTENANCEDISABLED)) {
51 DI::config()->reload();
53 // Default to hard-coded values for empty settings
54 $scheme = frio_scheme_get_current();
55 $scheme_accent = DI::config()->get('frio', 'scheme_accent') ?: $scheme_accent;
56 $nav_bg = DI::config()->get('frio', 'nav_bg') ?: $nav_bg;
57 $nav_icon_color = DI::config()->get('frio', 'nav_icon_color') ?: $nav_icon_color;
58 $link_color = DI::config()->get('frio', 'link_color') ?: $link_color;
59 $background_color = DI::config()->get('frio', 'background_color') ?: $background_color;
60 $contentbg_transp = DI::config()->get('frio', 'contentbg_transp') ?? $contentbg_transp;
61 $background_image = DI::config()->get('frio', 'background_image') ?: $background_image;
62 $bg_image_option = DI::config()->get('frio', 'bg_image_option') ?: $bg_image_option;
63 $login_bg_image = DI::config()->get('frio', 'login_bg_image') ?: $login_bg_image;
64 $login_bg_color = DI::config()->get('frio', 'login_bg_color') ?: $login_bg_color;
65 $modified = DI::config()->get('frio', 'css_modified') ?: $modified;
67 // Get the UID of the profile owner.
68 $uid = $_REQUEST['puid'] ?? 0;
70 DI::pConfig()->load($uid, 'frio');
72 // Only override display settings that have actually been set
73 $scheme = frio_scheme_get_current_for_user($uid);
74 $scheme_accent = DI::pConfig()->get($uid, 'frio', 'scheme_accent') ?: $scheme_accent;
75 $nav_bg = DI::pConfig()->get($uid, 'frio', 'nav_bg') ?: $nav_bg;
76 $nav_icon_color = DI::pConfig()->get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color;
77 $link_color = DI::pConfig()->get($uid, 'frio', 'link_color') ?: $link_color;
78 $background_color = DI::pConfig()->get($uid, 'frio', 'background_color') ?: $background_color;
79 $contentbg_transp = DI::pConfig()->get($uid, 'frio', 'contentbg_transp') ?? $contentbg_transp;
80 $background_image = DI::pConfig()->get($uid, 'frio', 'background_image') ?: $background_image;
81 $bg_image_option = DI::pConfig()->get($uid, 'frio', 'bg_image_option') ?: $bg_image_option;
82 $modified = DI::pConfig()->get($uid, 'frio', 'css_modified') ?: $modified;
86 if (!$login_bg_image && !$login_bg_color) {
87 $login_bg_image = 'img/login_bg.jpg';
89 $login_bg_color = $login_bg_color ?: '#ededed';
91 $scheme = Strings::sanitizeFilePathItem($scheme);
93 if ($scheme != FRIO_CUSTOM_SCHEME) {
94 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
95 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
96 require_once $schemefile;
98 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
99 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
103 $contentbg_transp = $contentbg_transp != '' ? $contentbg_transp : 100;
105 // Calculate some colors in dependance of existing colors.
106 // Some colors are calculated to don't have too many selection
107 // fields in the theme settings.
108 if (!isset($menu_background_hover_color)) {
109 $mbhc = new Color($nav_bg);
110 $mcolor = $mbhc->getHex();
112 if ($mbhc->isLight($mcolor, 75)) {
114 $menu_background_hover_color = '#' . $mbhc->darken(5);
117 $menu_background_hover_color = '#' . $mbhc->lighten(5);
120 if (!isset($nav_icon_hover_color)) {
121 $nihc = new Color($nav_bg);
123 if ($nihc->isLight()) {
124 $nav_icon_hover_color = '#' . $nihc->darken(10);
126 $nav_icon_hover_color = '#' . $nihc->lighten(20);
129 if (!isset($link_hover_color)) {
130 $lhc = new Color($link_color);
131 $lcolor = $lhc->getHex();
133 if ($lhc->isLight($lcolor, 75)) {
134 $link_hover_color = '#' . $lhc->darken(5);
136 $link_hover_color = '#' . $lhc->lighten(5);
140 // Convert $bg_image_options into css.
141 if (!isset($bg_image_option)) {
142 $bg_image_option = null;
145 switch ($bg_image_option) {
147 $background_size_img = '100%';
148 $background_repeat = 'no-repeat';
151 $background_size_img = 'cover';
152 $background_repeat = 'no-repeat';
155 $background_size_img = 'auto';
156 $background_repeat = 'repeat';
159 $background_size_img = 'contain';
160 $background_repeat = 'repeat';
164 $background_size_img = 'auto';
165 $background_repeat = 'no-repeat';
169 // Convert transparency level from percentage to opacity value.
170 $contentbg_transp = $contentbg_transp / 100;
173 '$nav_bg' => $nav_bg,
174 '$nav_icon_color' => $nav_icon_color,
175 '$nav_icon_hover_color' => $nav_icon_hover_color,
176 '$link_color' => $link_color,
177 '$link_hover_color' => $link_hover_color,
178 '$menu_background_hover_color' => $menu_background_hover_color,
179 '$btn_primary_color' => $nav_icon_color,
180 '$btn_primary_hover_color' => $menu_background_hover_color,
181 '$background_color' => $background_color,
182 '$contentbg_transp' => $contentbg_transp,
183 '$background_image' => $background_image,
184 '$background_size_img' => $background_size_img,
185 '$background_repeat' => $background_repeat,
186 '$login_bg_image' => $login_bg_image,
187 '$login_bg_color' => $login_bg_color,
188 '$font_color_darker' => $font_color_darker ?? '#222',
189 '$font_color_lighter' => $font_color_lighter ?? '#aaa',
190 '$font_color' => $font_color ?? '#444',
193 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
194 $css_tpl .= file_get_contents('view/theme/frio/css/dropzone.min.frio.css');
196 // Get the content of the scheme css file and the time of the last file change.
197 if ($schemecssfile) {
198 $css_tpl .= file_get_contents($schemecssfile);
199 $scheme_modified = filemtime($schemecssfile);
202 // We need to check which is the most recent css data.
203 // We will use this time later to decide if we load the cached or fresh css data.
204 if ($scheme_modified > $modified) {
205 $modified = $scheme_modified;
207 // Apply the settings to the css template.
208 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
210 $modified = gmdate('r', $modified);
214 // Set a header for caching.
215 header('Cache-Control: public');
216 header('ETag: "' . $etag . '"');
217 header('Last-Modified: ' . $modified);
219 // Only send the CSS file if it was changed.
220 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
221 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
222 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
223 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
224 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
226 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
227 throw new NotModifiedException();