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/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 $nav_bg = DI::config()->get('frio', 'nav_bg') ?: '#708fa0';
38 $nav_icon_color = DI::config()->get('frio', 'nav_icon_color') ?: '#ffffff';
39 $link_color = DI::config()->get('frio', 'link_color') ?: '#6fdbe8';
40 $background_color = DI::config()->get('frio', 'background_color') ?: '#ededed';
41 $contentbg_transp = DI::config()->get('frio', 'contentbg_transp') ?? 100;
42 $background_image = DI::config()->get('frio', 'background_image') ?: 'img/none.png';
43 $bg_image_option = DI::config()->get('frio', 'bg_image_option') ?: '';
44 $login_bg_image = DI::config()->get('frio', 'login_bg_image') ?: '';
45 $login_bg_color = DI::config()->get('frio', 'login_bg_color') ?: '';
46 $modified = DI::config()->get('frio', 'css_modified') ?: time();
48 if (!$login_bg_image && !$login_bg_color) {
49 $login_bg_image = 'img/login_bg.jpg';
51 $login_bg_color = $login_bg_color ?: '#ededed';
53 // Get the UID of the profile owner.
54 $uid = $_REQUEST['puid'] ?? 0;
56 DI::pConfig()->load($uid, 'frio');
58 // Only override display settings that have actually been set
59 $scheme = DI::pConfig()->get($uid, 'frio', 'scheme', DI::pConfig()->get($uid, 'frio', 'schema')) ?: $scheme;
60 $nav_bg = DI::pConfig()->get($uid, 'frio', 'nav_bg') ?: $nav_bg;
61 $nav_icon_color = DI::pConfig()->get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color;
62 $link_color = DI::pConfig()->get($uid, 'frio', 'link_color') ?: $link_color;
63 $background_color = DI::pConfig()->get($uid, 'frio', 'background_color') ?: $background_color;
64 $contentbg_transp = DI::pConfig()->get($uid, 'frio', 'contentbg_transp') ?? $contentbg_transp;
65 $background_image = DI::pConfig()->get($uid, 'frio', 'background_image') ?: $background_image;
66 $bg_image_option = DI::pConfig()->get($uid, 'frio', 'bg_image_option') ?: $bg_image_option;
67 $modified = DI::pConfig()->get($uid, 'frio', 'css_modified') ?: $modified;
70 // Now load the scheme. If a value is changed above, we'll keep the settings
71 // If not, we'll keep those defined by the scheme
72 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
73 // not --- like the mobile theme does instead.
74 // Allow layouts to over-ride the scheme.
75 if (!empty($_REQUEST['scheme'])) {
76 $scheme = $_REQUEST['scheme'];
79 $scheme = Strings::sanitizeFilePathItem($scheme);
81 if (($scheme) && ($scheme != '---')) {
82 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
83 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
84 require_once $schemefile;
86 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
87 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
91 // If we haven't got a scheme, load the default. We shouldn't touch this - we
92 // should leave it for admins to define for themselves.
93 // default.php and default.css MUST be symlinks to existing scheme files.
95 if (file_exists('view/theme/frio/scheme/default.php')) {
96 $schemefile = 'view/theme/frio/scheme/default.php';
97 require_once $schemefile;
99 if (file_exists('view/theme/frio/scheme/default.css')) {
100 $schemecssfile = 'view/theme/frio/scheme/default.css';
104 $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100);
106 // Calculate some colors in dependance of existing colors.
107 // Some colors are calculated to don't have too many selection
108 // fields in the theme settings.
109 if (!isset($menu_background_hover_color)) {
110 $mbhc = new Color($nav_bg);
111 $mcolor = $mbhc->getHex();
113 if ($mbhc->isLight($mcolor, 75)) {
115 $menu_background_hover_color = '#' . $mbhc->darken(5);
118 $menu_background_hover_color = '#' . $mbhc->lighten(5);
121 if (!isset($nav_icon_hover_color)) {
122 $nihc = new Color($nav_bg);
124 if ($nihc->isLight()) {
125 $nav_icon_hover_color = '#' . $nihc->darken(10);
127 $nav_icon_hover_color = '#' . $nihc->lighten(20);
130 if (!isset($link_hover_color)) {
131 $lhc = new Color($link_color);
132 $lcolor = $lhc->getHex();
134 if ($lhc->isLight($lcolor, 75)) {
135 $link_hover_color = '#' . $lhc->darken(5);
137 $link_hover_color = '#' . $lhc->lighten(5);
141 // Convert $bg_image_options into css.
142 if (!isset($bg_image_option)) {
143 $bg_image_option = null;
146 switch ($bg_image_option) {
148 $background_size_img = '100%';
149 $background_repeat = 'no-repeat';
152 $background_size_img = 'cover';
153 $background_repeat = 'no-repeat';
156 $background_size_img = 'auto';
157 $background_repeat = 'repeat';
160 $background_size_img = 'contain';
161 $background_repeat = 'repeat';
165 $background_size_img = 'auto';
166 $background_repeat = 'no-repeat';
170 // Convert transparency level from percentage to opacity value.
171 $contentbg_transp = $contentbg_transp / 100;
174 '$nav_bg' => $nav_bg,
175 '$nav_icon_color' => $nav_icon_color,
176 '$nav_icon_hover_color' => $nav_icon_hover_color,
177 '$link_color' => $link_color,
178 '$link_hover_color' => $link_hover_color,
179 '$menu_background_hover_color' => $menu_background_hover_color,
180 '$btn_primary_color' => $nav_icon_color,
181 '$btn_primary_hover_color' => $menu_background_hover_color,
182 '$background_color' => $background_color,
183 '$contentbg_transp' => $contentbg_transp,
184 '$background_image' => $background_image,
185 '$background_size_img' => $background_size_img,
186 '$background_repeat' => $background_repeat,
187 '$login_bg_image' => $login_bg_image,
188 '$login_bg_color' => $login_bg_color,
189 '$font_color_darker' => $font_color_darker ?? '#555',
190 '$font_color' => $font_color ?? '#777',
193 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
195 // Get the content of the scheme css file and the time of the last file change.
196 if ($schemecssfile) {
197 $css_tpl .= file_get_contents($schemecssfile);
198 $scheme_modified = filemtime($schemecssfile);
201 // We need to check which is the most recent css data.
202 // We will use this time later to decide if we load the cached or fresh css data.
203 if ($scheme_modified > $modified) {
204 $modified = $scheme_modified;
206 // Apply the settings to the css template.
207 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
209 $modified = gmdate('r', $modified);
213 // Set a header for caching.
214 header('Cache-Control: public');
215 header('ETag: "' . $etag . '"');
216 header('Last-Modified: ' . $modified);
218 // Only send the CSS file if it was changed.
219 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
220 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
221 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
222 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
223 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
225 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
226 header('HTTP/1.1 304 Not Modified');