3 * @copyright Copyright (C) 2010-2021, 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\Util\Strings;
25 require_once 'view/theme/frio/theme.php';
26 require_once 'view/theme/frio/php/PHPColors/Color.php';
30 $schemecssfile = false;
33 DI::config()->load('frio');
35 // Default to hard-coded values for empty settings
36 $scheme = DI::config()->get('frio', 'scheme', DI::config()->get('frio', 'schema'));
37 $scheme_accent = DI::config()->get('frio', 'scheme_accent') ?: FRIO_SCHEME_ACCENT_BLUE;
38 $nav_bg = DI::config()->get('frio', 'nav_bg') ?: '#708fa0';
39 $nav_icon_color = DI::config()->get('frio', 'nav_icon_color') ?: '#ffffff';
40 $link_color = DI::config()->get('frio', 'link_color') ?: '#6fdbe8';
41 $background_color = DI::config()->get('frio', 'background_color') ?: '#ededed';
42 $contentbg_transp = DI::config()->get('frio', 'contentbg_transp') ?? 100;
43 $background_image = DI::config()->get('frio', 'background_image') ?: 'img/none.png';
44 $bg_image_option = DI::config()->get('frio', 'bg_image_option') ?: '';
45 $login_bg_image = DI::config()->get('frio', 'login_bg_image') ?: '';
46 $login_bg_color = DI::config()->get('frio', 'login_bg_color') ?: '';
47 $modified = DI::config()->get('frio', 'css_modified') ?: time();
49 if (!$login_bg_image && !$login_bg_color) {
50 $login_bg_image = 'img/login_bg.jpg';
52 $login_bg_color = $login_bg_color ?: '#ededed';
54 // Get the UID of the profile owner.
55 $uid = $_REQUEST['puid'] ?? 0;
57 DI::pConfig()->load($uid, 'frio');
59 // Only override display settings that have actually been set
60 $scheme = DI::pConfig()->get($uid, 'frio', 'scheme', DI::pConfig()->get($uid, 'frio', 'schema')) ?: $scheme;
61 $scheme_accent = DI::pConfig()->get($uid, 'frio', 'scheme_accent') ?: $scheme_accent;
62 $nav_bg = DI::pConfig()->get($uid, 'frio', 'nav_bg') ?: $nav_bg;
63 $nav_icon_color = DI::pConfig()->get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color;
64 $link_color = DI::pConfig()->get($uid, 'frio', 'link_color') ?: $link_color;
65 $background_color = DI::pConfig()->get($uid, 'frio', 'background_color') ?: $background_color;
66 $contentbg_transp = DI::pConfig()->get($uid, 'frio', 'contentbg_transp') ?? $contentbg_transp;
67 $background_image = DI::pConfig()->get($uid, 'frio', 'background_image') ?: $background_image;
68 $bg_image_option = DI::pConfig()->get($uid, 'frio', 'bg_image_option') ?: $bg_image_option;
69 $modified = DI::pConfig()->get($uid, 'frio', 'css_modified') ?: $modified;
72 // Now load the scheme. If a value is changed above, we'll keep the settings
73 // If not, we'll keep those defined by the scheme
74 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
75 // not --- like the mobile theme does instead.
76 // Allow layouts to over-ride the scheme.
77 if (!empty($_REQUEST['scheme'])) {
78 $scheme = $_REQUEST['scheme'];
81 $scheme = Strings::sanitizeFilePathItem($scheme);
83 if (($scheme) && ($scheme != '---')) {
84 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
85 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
86 require_once $schemefile;
88 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
89 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
93 // If we haven't got a scheme, load the default. We shouldn't touch this - we
94 // should leave it for admins to define for themselves.
95 // default.php and default.css MUST be symlinks to existing scheme files.
97 if (file_exists('view/theme/frio/scheme/default.php')) {
98 $schemefile = 'view/theme/frio/scheme/default.php';
99 require_once $schemefile;
101 if (file_exists('view/theme/frio/scheme/default.css')) {
102 $schemecssfile = 'view/theme/frio/scheme/default.css';
106 $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100);
108 // Calculate some colors in dependance of existing colors.
109 // Some colors are calculated to don't have too many selection
110 // fields in the theme settings.
111 if (!isset($menu_background_hover_color)) {
112 $mbhc = new Color($nav_bg);
113 $mcolor = $mbhc->getHex();
115 if ($mbhc->isLight($mcolor, 75)) {
117 $menu_background_hover_color = '#' . $mbhc->darken(5);
120 $menu_background_hover_color = '#' . $mbhc->lighten(5);
123 if (!isset($nav_icon_hover_color)) {
124 $nihc = new Color($nav_bg);
126 if ($nihc->isLight()) {
127 $nav_icon_hover_color = '#' . $nihc->darken(10);
129 $nav_icon_hover_color = '#' . $nihc->lighten(20);
132 if (!isset($link_hover_color)) {
133 $lhc = new Color($link_color);
134 $lcolor = $lhc->getHex();
136 if ($lhc->isLight($lcolor, 75)) {
137 $link_hover_color = '#' . $lhc->darken(5);
139 $link_hover_color = '#' . $lhc->lighten(5);
143 // Convert $bg_image_options into css.
144 if (!isset($bg_image_option)) {
145 $bg_image_option = null;
148 switch ($bg_image_option) {
150 $background_size_img = '100%';
151 $background_repeat = 'no-repeat';
154 $background_size_img = 'cover';
155 $background_repeat = 'no-repeat';
158 $background_size_img = 'auto';
159 $background_repeat = 'repeat';
162 $background_size_img = 'contain';
163 $background_repeat = 'repeat';
167 $background_size_img = 'auto';
168 $background_repeat = 'no-repeat';
172 // Convert transparency level from percentage to opacity value.
173 $contentbg_transp = $contentbg_transp / 100;
176 '$nav_bg' => $nav_bg,
177 '$nav_icon_color' => $nav_icon_color,
178 '$nav_icon_hover_color' => $nav_icon_hover_color,
179 '$link_color' => $link_color,
180 '$link_hover_color' => $link_hover_color,
181 '$menu_background_hover_color' => $menu_background_hover_color,
182 '$btn_primary_color' => $nav_icon_color,
183 '$btn_primary_hover_color' => $menu_background_hover_color,
184 '$background_color' => $background_color,
185 '$contentbg_transp' => $contentbg_transp,
186 '$background_image' => $background_image,
187 '$background_size_img' => $background_size_img,
188 '$background_repeat' => $background_repeat,
189 '$login_bg_image' => $login_bg_image,
190 '$login_bg_color' => $login_bg_color,
191 '$font_color_darker' => $font_color_darker ?? '#222',
192 '$font_color' => $font_color ?? '#444',
195 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
197 // Get the content of the scheme css file and the time of the last file change.
198 if ($schemecssfile) {
199 $css_tpl .= file_get_contents($schemecssfile);
200 $scheme_modified = filemtime($schemecssfile);
203 // We need to check which is the most recent css data.
204 // We will use this time later to decide if we load the cached or fresh css data.
205 if ($scheme_modified > $modified) {
206 $modified = $scheme_modified;
208 // Apply the settings to the css template.
209 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
211 $modified = gmdate('r', $modified);
215 // Set a header for caching.
216 header('Cache-Control: public');
217 header('ETag: "' . $etag . '"');
218 header('Last-Modified: ' . $modified);
220 // Only send the CSS file if it was changed.
221 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
222 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
223 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
224 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
225 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
227 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
228 header('HTTP/1.1 304 Not Modified');