3 * @copyright Copyright (C) 2010-2022, 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/PHPColors/Color.php';
31 $schemecssfile = false;
35 * This script can be included when the maintenance mode is on, which requires us to avoid any config call and
36 * use the following hardcoded defaults
39 $scheme_accent = FRIO_SCHEME_ACCENT_BLUE;
41 $nav_icon_color = '#ffffff';
42 $link_color = '#6fdbe8';
43 $background_color = '#ededed';
44 $contentbg_transp = 100;
45 $background_image = 'img/none.png';
46 $bg_image_option = '';
51 if (DI::mode()->has(\Friendica\App\Mode::MAINTENANCEDISABLED)) {
52 DI::config()->load('frio');
54 // Default to hard-coded values for empty settings
55 $scheme = DI::config()->get('frio', 'scheme', DI::config()->get('frio', 'schema'));
56 $scheme_accent = DI::config()->get('frio', 'scheme_accent') ?: $scheme_accent;
57 $nav_bg = DI::config()->get('frio', 'nav_bg') ?: $nav_bg;
58 $nav_icon_color = DI::config()->get('frio', 'nav_icon_color') ?: $nav_icon_color;
59 $link_color = DI::config()->get('frio', 'link_color') ?: $link_color;
60 $background_color = DI::config()->get('frio', 'background_color') ?: $background_color;
61 $contentbg_transp = DI::config()->get('frio', 'contentbg_transp') ?? $contentbg_transp;
62 $background_image = DI::config()->get('frio', 'background_image') ?: $background_image;
63 $bg_image_option = DI::config()->get('frio', 'bg_image_option') ?: $bg_image_option;
64 $login_bg_image = DI::config()->get('frio', 'login_bg_image') ?: $login_bg_image;
65 $login_bg_color = DI::config()->get('frio', 'login_bg_color') ?: $login_bg_color;
66 $modified = DI::config()->get('frio', 'css_modified') ?: $modified;
68 // Get the UID of the profile owner.
69 $uid = $_REQUEST['puid'] ?? 0;
71 DI::pConfig()->load($uid, 'frio');
73 // Only override display settings that have actually been set
74 $scheme = DI::pConfig()->get($uid, 'frio', 'scheme', DI::pConfig()->get($uid, 'frio', 'schema')) ?: $scheme;
75 $scheme_accent = DI::pConfig()->get($uid, 'frio', 'scheme_accent') ?: $scheme_accent;
76 $nav_bg = DI::pConfig()->get($uid, 'frio', 'nav_bg') ?: $nav_bg;
77 $nav_icon_color = DI::pConfig()->get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color;
78 $link_color = DI::pConfig()->get($uid, 'frio', 'link_color') ?: $link_color;
79 $background_color = DI::pConfig()->get($uid, 'frio', 'background_color') ?: $background_color;
80 $contentbg_transp = DI::pConfig()->get($uid, 'frio', 'contentbg_transp') ?? $contentbg_transp;
81 $background_image = DI::pConfig()->get($uid, 'frio', 'background_image') ?: $background_image;
82 $bg_image_option = DI::pConfig()->get($uid, 'frio', 'bg_image_option') ?: $bg_image_option;
83 $modified = DI::pConfig()->get($uid, 'frio', 'css_modified') ?: $modified;
87 if (!$login_bg_image && !$login_bg_color) {
88 $login_bg_image = 'img/login_bg.jpg';
90 $login_bg_color = $login_bg_color ?: '#ededed';
92 // Now load the scheme. If a value is changed above, we'll keep the settings
93 // If not, we'll keep those defined by the scheme
94 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
95 // not --- like the mobile theme does instead.
96 // Allow layouts to over-ride the scheme.
97 if (!empty($_REQUEST['scheme'])) {
98 $scheme = $_REQUEST['scheme'];
101 $scheme = Strings::sanitizeFilePathItem($scheme ?? '');
103 if ($scheme && ($scheme != '---')) {
104 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
105 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
106 require_once $schemefile;
108 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
109 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
113 // If we haven't got a scheme, load the default. We shouldn't touch this - we
114 // should leave it for admins to define for themselves.
115 // default.php and default.css MUST be symlinks to existing scheme files.
117 if (file_exists('view/theme/frio/scheme/default.php')) {
118 $schemefile = 'view/theme/frio/scheme/default.php';
119 require_once $schemefile;
121 if (file_exists('view/theme/frio/scheme/default.css')) {
122 $schemecssfile = 'view/theme/frio/scheme/default.css';
126 $contentbg_transp = $contentbg_transp != '' ? $contentbg_transp : 100;
128 // Calculate some colors in dependance of existing colors.
129 // Some colors are calculated to don't have too many selection
130 // fields in the theme settings.
131 if (!isset($menu_background_hover_color)) {
132 $mbhc = new Color($nav_bg);
133 $mcolor = $mbhc->getHex();
135 if ($mbhc->isLight($mcolor, 75)) {
137 $menu_background_hover_color = '#' . $mbhc->darken(5);
140 $menu_background_hover_color = '#' . $mbhc->lighten(5);
143 if (!isset($nav_icon_hover_color)) {
144 $nihc = new Color($nav_bg);
146 if ($nihc->isLight()) {
147 $nav_icon_hover_color = '#' . $nihc->darken(10);
149 $nav_icon_hover_color = '#' . $nihc->lighten(20);
152 if (!isset($link_hover_color)) {
153 $lhc = new Color($link_color);
154 $lcolor = $lhc->getHex();
156 if ($lhc->isLight($lcolor, 75)) {
157 $link_hover_color = '#' . $lhc->darken(5);
159 $link_hover_color = '#' . $lhc->lighten(5);
163 // Convert $bg_image_options into css.
164 if (!isset($bg_image_option)) {
165 $bg_image_option = null;
168 switch ($bg_image_option) {
170 $background_size_img = '100%';
171 $background_repeat = 'no-repeat';
174 $background_size_img = 'cover';
175 $background_repeat = 'no-repeat';
178 $background_size_img = 'auto';
179 $background_repeat = 'repeat';
182 $background_size_img = 'contain';
183 $background_repeat = 'repeat';
187 $background_size_img = 'auto';
188 $background_repeat = 'no-repeat';
192 // Convert transparency level from percentage to opacity value.
193 $contentbg_transp = $contentbg_transp / 100;
196 '$nav_bg' => $nav_bg,
197 '$nav_icon_color' => $nav_icon_color,
198 '$nav_icon_hover_color' => $nav_icon_hover_color,
199 '$link_color' => $link_color,
200 '$link_hover_color' => $link_hover_color,
201 '$menu_background_hover_color' => $menu_background_hover_color,
202 '$btn_primary_color' => $nav_icon_color,
203 '$btn_primary_hover_color' => $menu_background_hover_color,
204 '$background_color' => $background_color,
205 '$contentbg_transp' => $contentbg_transp,
206 '$background_image' => $background_image,
207 '$background_size_img' => $background_size_img,
208 '$background_repeat' => $background_repeat,
209 '$login_bg_image' => $login_bg_image,
210 '$login_bg_color' => $login_bg_color,
211 '$font_color_darker' => $font_color_darker ?? '#222',
212 '$font_color' => $font_color ?? '#444',
215 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
217 // Get the content of the scheme css file and the time of the last file change.
218 if ($schemecssfile) {
219 $css_tpl .= file_get_contents($schemecssfile);
220 $scheme_modified = filemtime($schemecssfile);
223 // We need to check which is the most recent css data.
224 // We will use this time later to decide if we load the cached or fresh css data.
225 if ($scheme_modified > $modified) {
226 $modified = $scheme_modified;
228 // Apply the settings to the css template.
229 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
231 $modified = gmdate('r', $modified);
235 // Set a header for caching.
236 header('Cache-Control: public');
237 header('ETag: "' . $etag . '"');
238 header('Last-Modified: ' . $modified);
240 // Only send the CSS file if it was changed.
241 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
242 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
243 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
244 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
245 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
247 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
248 throw new NotModifiedException();