3 * @file view/theme/frio/style.php
7 use Friendica\Util\Strings;
9 require_once 'view/theme/frio/php/PHPColors/Color.php';
13 $schemecssfile = false;
16 DI::config()->load('frio');
18 // Default to hard-coded values for empty settings
19 $scheme = DI::config()->get('frio', 'scheme', DI::config()->get('frio', 'schema'));
20 $nav_bg = DI::config()->get('frio', 'nav_bg') ?: '#708fa0';
21 $nav_icon_color = DI::config()->get('frio', 'nav_icon_color') ?: '#ffffff';
22 $link_color = DI::config()->get('frio', 'link_color') ?: '#6fdbe8';
23 $background_color = DI::config()->get('frio', 'background_color') ?: '#ededed';
24 $contentbg_transp = DI::config()->get('frio', 'contentbg_transp') ?: '';
25 $background_image = DI::config()->get('frio', 'background_image') ?: 'img/none.png';
26 $bg_image_option = DI::config()->get('frio', 'bg_image_option') ?: '';
27 $login_bg_image = DI::config()->get('frio', 'login_bg_image') ?: '';
28 $login_bg_color = DI::config()->get('frio', 'login_bg_color') ?: '';
29 $modified = DI::config()->get('frio', 'css_modified') ?: time();
31 if (!$login_bg_image && !$login_bg_color) {
32 $login_bg_image = 'img/login_bg.jpg';
34 $login_bg_color = $login_bg_color ?: '#ededed';
36 // Get the UID of the profile owner.
37 $uid = $_REQUEST['puid'] ?? 0;
39 DI::pConfig()->load($uid, 'frio');
41 // Only override display settings that have actually been set
42 $scheme = DI::pConfig()->get($uid, 'frio', 'scheme', DI::pConfig()->get($uid, 'frio', 'schema')) ?: $scheme;
43 $nav_bg = DI::pConfig()->get($uid, 'frio', 'nav_bg') ?: $nav_bg;
44 $nav_icon_color = DI::pConfig()->get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color;
45 $link_color = DI::pConfig()->get($uid, 'frio', 'link_color') ?: $link_color;
46 $background_color = DI::pConfig()->get($uid, 'frio', 'background_color') ?: $background_color;
47 $contentbg_transp = DI::pConfig()->get($uid, 'frio', 'contentbg_transp') ?: $contentbg_transp;
48 $background_image = DI::pConfig()->get($uid, 'frio', 'background_image') ?: $background_image;
49 $bg_image_option = DI::pConfig()->get($uid, 'frio', 'bg_image_option') ?: $bg_image_option;
50 $modified = DI::pConfig()->get($uid, 'frio', 'css_modified') ?: $modified;
53 // Now load the scheme. If a value is changed above, we'll keep the settings
54 // If not, we'll keep those defined by the scheme
55 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
56 // not --- like the mobile theme does instead.
57 // Allow layouts to over-ride the scheme.
58 if (!empty($_REQUEST['scheme'])) {
59 $scheme = $_REQUEST['scheme'];
62 $scheme = Strings::sanitizeFilePathItem($scheme);
64 if (($scheme) && ($scheme != '---')) {
65 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
66 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
67 require_once $schemefile;
69 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
70 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
74 // If we haven't got a scheme, load the default. We shouldn't touch this - we
75 // should leave it for admins to define for themselves.
76 // default.php and default.css MUST be symlinks to existing scheme files.
78 if (file_exists('view/theme/frio/scheme/default.php')) {
79 $schemefile = 'view/theme/frio/scheme/default.php';
80 require_once $schemefile;
82 if (file_exists('view/theme/frio/scheme/default.css')) {
83 $schemecssfile = 'view/theme/frio/scheme/default.css';
87 $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100);
89 // Calculate some colors in dependance of existing colors.
90 // Some colors are calculated to don't have too many selection
91 // fields in the theme settings.
92 if (!isset($menu_background_hover_color)) {
93 $mbhc = new Color($nav_bg);
94 $mcolor = $mbhc->getHex();
96 if ($mbhc->isLight($mcolor, 75)) {
98 $menu_background_hover_color = '#' . $mbhc->darken(5);
101 $menu_background_hover_color = '#' . $mbhc->lighten(5);
104 if (!isset($nav_icon_hover_color)) {
105 $nihc = new Color($nav_bg);
107 if ($nihc->isLight()) {
108 $nav_icon_hover_color = '#' . $nihc->darken(10);
110 $nav_icon_hover_color = '#' . $nihc->lighten(10);
113 if (!isset($link_hover_color)) {
114 $lhc = new Color($link_color);
115 $lcolor = $lhc->getHex();
117 if ($lhc->isLight($lcolor, 75)) {
118 $link_hover_color = '#' . $lhc->darken(5);
120 $link_hover_color = '#' . $lhc->lighten(5);
124 // Convert $bg_image_options into css.
125 if (!isset($bg_image_option)) {
126 $bg_image_option = null;
129 switch ($bg_image_option) {
131 $background_size_img = '100%';
132 $background_repeat = 'no-repeat';
135 $background_size_img = 'cover';
136 $background_repeat = 'no-repeat';
139 $background_size_img = 'auto';
140 $background_repeat = 'repeat';
143 $background_size_img = 'contain';
144 $background_repeat = 'repeat';
148 $background_size_img = 'auto';
149 $background_repeat = 'no-repeat';
153 // Convert transparency level from percentage to opacity value.
154 $contentbg_transp = $contentbg_transp / 100;
157 '$nav_bg' => $nav_bg,
158 '$nav_icon_color' => $nav_icon_color,
159 '$nav_icon_hover_color' => $nav_icon_hover_color,
160 '$link_color' => $link_color,
161 '$link_hover_color' => $link_hover_color,
162 '$menu_background_hover_color' => $menu_background_hover_color,
163 '$btn_primary_color' => $nav_icon_color,
164 '$btn_primary_hover_color' => $menu_background_hover_color,
165 '$background_color' => $background_color,
166 '$contentbg_transp' => $contentbg_transp,
167 '$background_image' => $background_image,
168 '$background_size_img' => $background_size_img,
169 '$background_repeat' => $background_repeat,
170 '$login_bg_image' => $login_bg_image,
171 '$login_bg_color' => $login_bg_color
174 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
176 // Get the content of the scheme css file and the time of the last file change.
177 if ($schemecssfile) {
178 $css_tpl .= file_get_contents($schemecssfile);
179 $scheme_modified = filemtime($schemecssfile);
182 // We need to check which is the most recent css data.
183 // We will use this time later to decide if we load the cached or fresh css data.
184 if ($scheme_modified > $modified) {
185 $modified = $scheme_modified;
187 // Apply the settings to the css template.
188 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
190 $modified = gmdate('r', $modified);
194 // Set a header for caching.
195 header('Cache-Control: public');
196 header('ETag: "' . $etag . '"');
197 header('Last-Modified: ' . $modified);
199 // Only send the CSS file if it was changed.
200 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
201 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
202 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
203 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
204 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
206 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
207 header('HTTP/1.1 304 Not Modified');