3 * @copyright Copyright (C) 2020, Friendica
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/php/PHPColors/Color.php';
29 $schemecssfile = false;
32 DI::config()->load('frio');
34 // Default to hard-coded values for empty settings
35 $scheme = DI::config()->get('frio', 'scheme', DI::config()->get('frio', 'schema'));
36 $nav_bg = DI::config()->get('frio', 'nav_bg') ?: '#708fa0';
37 $nav_icon_color = DI::config()->get('frio', 'nav_icon_color') ?: '#ffffff';
38 $link_color = DI::config()->get('frio', 'link_color') ?: '#6fdbe8';
39 $background_color = DI::config()->get('frio', 'background_color') ?: '#ededed';
40 $contentbg_transp = DI::config()->get('frio', 'contentbg_transp') ?: '';
41 $background_image = DI::config()->get('frio', 'background_image') ?: 'img/none.png';
42 $bg_image_option = DI::config()->get('frio', 'bg_image_option') ?: '';
43 $login_bg_image = DI::config()->get('frio', 'login_bg_image') ?: '';
44 $login_bg_color = DI::config()->get('frio', 'login_bg_color') ?: '';
45 $modified = DI::config()->get('frio', 'css_modified') ?: time();
47 if (!$login_bg_image && !$login_bg_color) {
48 $login_bg_image = 'img/login_bg.jpg';
50 $login_bg_color = $login_bg_color ?: '#ededed';
52 // Get the UID of the profile owner.
53 $uid = $_REQUEST['puid'] ?? 0;
55 DI::pConfig()->load($uid, 'frio');
57 // Only override display settings that have actually been set
58 $scheme = DI::pConfig()->get($uid, 'frio', 'scheme', DI::pConfig()->get($uid, 'frio', 'schema')) ?: $scheme;
59 $nav_bg = DI::pConfig()->get($uid, 'frio', 'nav_bg') ?: $nav_bg;
60 $nav_icon_color = DI::pConfig()->get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color;
61 $link_color = DI::pConfig()->get($uid, 'frio', 'link_color') ?: $link_color;
62 $background_color = DI::pConfig()->get($uid, 'frio', 'background_color') ?: $background_color;
63 $contentbg_transp = DI::pConfig()->get($uid, 'frio', 'contentbg_transp') ?: $contentbg_transp;
64 $background_image = DI::pConfig()->get($uid, 'frio', 'background_image') ?: $background_image;
65 $bg_image_option = DI::pConfig()->get($uid, 'frio', 'bg_image_option') ?: $bg_image_option;
66 $modified = DI::pConfig()->get($uid, 'frio', 'css_modified') ?: $modified;
69 // Now load the scheme. If a value is changed above, we'll keep the settings
70 // If not, we'll keep those defined by the scheme
71 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
72 // not --- like the mobile theme does instead.
73 // Allow layouts to over-ride the scheme.
74 if (!empty($_REQUEST['scheme'])) {
75 $scheme = $_REQUEST['scheme'];
78 $scheme = Strings::sanitizeFilePathItem($scheme);
80 if (($scheme) && ($scheme != '---')) {
81 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
82 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
83 require_once $schemefile;
85 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
86 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
90 // If we haven't got a scheme, load the default. We shouldn't touch this - we
91 // should leave it for admins to define for themselves.
92 // default.php and default.css MUST be symlinks to existing scheme files.
94 if (file_exists('view/theme/frio/scheme/default.php')) {
95 $schemefile = 'view/theme/frio/scheme/default.php';
96 require_once $schemefile;
98 if (file_exists('view/theme/frio/scheme/default.css')) {
99 $schemecssfile = 'view/theme/frio/scheme/default.css';
103 $contentbg_transp = ((isset($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(10);
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
190 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
192 // Get the content of the scheme css file and the time of the last file change.
193 if ($schemecssfile) {
194 $css_tpl .= file_get_contents($schemecssfile);
195 $scheme_modified = filemtime($schemecssfile);
198 // We need to check which is the most recent css data.
199 // We will use this time later to decide if we load the cached or fresh css data.
200 if ($scheme_modified > $modified) {
201 $modified = $scheme_modified;
203 // Apply the settings to the css template.
204 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
206 $modified = gmdate('r', $modified);
210 // Set a header for caching.
211 header('Cache-Control: public');
212 header('ETag: "' . $etag . '"');
213 header('Last-Modified: ' . $modified);
215 // Only send the CSS file if it was changed.
216 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
217 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
218 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
219 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
220 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
222 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
223 header('HTTP/1.1 304 Not Modified');