3 * @file view/theme/frio/style.php
6 use Friendica\Core\Config;
7 use Friendica\Core\PConfig;
9 use Friendica\Util\Strings;
11 require_once 'view/theme/frio/php/PHPColors/Color.php';
15 $schemecssfile = false;
20 // Default to hard-coded values for empty settings
21 $scheme = Config::get('frio', 'scheme', Config::get('frio', 'schema'));
22 $nav_bg = Config::get('frio', 'nav_bg') ?: '#708fa0';
23 $nav_icon_color = Config::get('frio', 'nav_icon_color') ?: '#ffffff';
24 $link_color = Config::get('frio', 'link_color') ?: '#6fdbe8';
25 $background_color = Config::get('frio', 'background_color') ?: '#ededed';
26 $contentbg_transp = Config::get('frio', 'contentbg_transp') ?: '';
27 $background_image = Config::get('frio', 'background_image') ?: 'img/none.png';
28 $bg_image_option = Config::get('frio', 'bg_image_option') ?: '';
29 $login_bg_image = Config::get('frio', 'login_bg_image') ?: '';
30 $login_bg_color = Config::get('frio', 'login_bg_color') ?: '';
31 $modified = Config::get('frio', 'css_modified') ?: time();
33 if (!$login_bg_image && !$login_bg_color) {
34 $login_bg_image = 'img/login_bg.jpg';
36 $login_bg_color = $login_bg_color ?: '#ededed';
38 // Get the UID of the profile owner.
39 $uid = $_REQUEST['puid'] ?? 0;
41 DI::pConfig()->load($uid, 'frio');
43 // Only override display settings that have actually been set
44 $scheme = PConfig::get($uid, 'frio', 'scheme', PConfig::get($uid, 'frio', 'schema')) ?: $scheme;
45 $nav_bg = PConfig::get($uid, 'frio', 'nav_bg') ?: $nav_bg;
46 $nav_icon_color = PConfig::get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color;
47 $link_color = PConfig::get($uid, 'frio', 'link_color') ?: $link_color;
48 $background_color = PConfig::get($uid, 'frio', 'background_color') ?: $background_color;
49 $contentbg_transp = PConfig::get($uid, 'frio', 'contentbg_transp') ?: $contentbg_transp;
50 $background_image = PConfig::get($uid, 'frio', 'background_image') ?: $background_image;
51 $bg_image_option = PConfig::get($uid, 'frio', 'bg_image_option') ?: $bg_image_option;
52 $modified = PConfig::get($uid, 'frio', 'css_modified') ?: $modified;
55 // Now load the scheme. If a value is changed above, we'll keep the settings
56 // If not, we'll keep those defined by the scheme
57 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
58 // not --- like the mobile theme does instead.
59 // Allow layouts to over-ride the scheme.
60 if (!empty($_REQUEST['scheme'])) {
61 $scheme = $_REQUEST['scheme'];
64 $scheme = Strings::sanitizeFilePathItem($scheme);
66 if (($scheme) && ($scheme != '---')) {
67 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
68 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
69 require_once $schemefile;
71 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
72 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
76 // If we haven't got a scheme, load the default. We shouldn't touch this - we
77 // should leave it for admins to define for themselves.
78 // default.php and default.css MUST be symlinks to existing scheme files.
80 if (file_exists('view/theme/frio/scheme/default.php')) {
81 $schemefile = 'view/theme/frio/scheme/default.php';
82 require_once $schemefile;
84 if (file_exists('view/theme/frio/scheme/default.css')) {
85 $schemecssfile = 'view/theme/frio/scheme/default.css';
89 $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100);
91 // Calculate some colors in dependance of existing colors.
92 // Some colors are calculated to don't have too many selection
93 // fields in the theme settings.
94 if (!isset($menu_background_hover_color)) {
95 $mbhc = new Color($nav_bg);
96 $mcolor = $mbhc->getHex();
98 if ($mbhc->isLight($mcolor, 75)) {
100 $menu_background_hover_color = '#' . $mbhc->darken(5);
103 $menu_background_hover_color = '#' . $mbhc->lighten(5);
106 if (!isset($nav_icon_hover_color)) {
107 $nihc = new Color($nav_bg);
109 if ($nihc->isLight()) {
110 $nav_icon_hover_color = '#' . $nihc->darken(10);
112 $nav_icon_hover_color = '#' . $nihc->lighten(10);
115 if (!isset($link_hover_color)) {
116 $lhc = new Color($link_color);
117 $lcolor = $lhc->getHex();
119 if ($lhc->isLight($lcolor, 75)) {
120 $link_hover_color = '#' . $lhc->darken(5);
122 $link_hover_color = '#' . $lhc->lighten(5);
126 // Convert $bg_image_options into css.
127 if (!isset($bg_image_option)) {
128 $bg_image_option = null;
131 switch ($bg_image_option) {
133 $background_size_img = '100%';
134 $background_repeat = 'no-repeat';
137 $background_size_img = 'cover';
138 $background_repeat = 'no-repeat';
141 $background_size_img = 'auto';
142 $background_repeat = 'repeat';
145 $background_size_img = 'contain';
146 $background_repeat = 'repeat';
150 $background_size_img = 'auto';
151 $background_repeat = 'no-repeat';
155 // Convert transparency level from percentage to opacity value.
156 $contentbg_transp = $contentbg_transp / 100;
159 '$nav_bg' => $nav_bg,
160 '$nav_icon_color' => $nav_icon_color,
161 '$nav_icon_hover_color' => $nav_icon_hover_color,
162 '$link_color' => $link_color,
163 '$link_hover_color' => $link_hover_color,
164 '$menu_background_hover_color' => $menu_background_hover_color,
165 '$btn_primary_color' => $nav_icon_color,
166 '$btn_primary_hover_color' => $menu_background_hover_color,
167 '$background_color' => $background_color,
168 '$contentbg_transp' => $contentbg_transp,
169 '$background_image' => $background_image,
170 '$background_size_img' => $background_size_img,
171 '$background_repeat' => $background_repeat,
172 '$login_bg_image' => $login_bg_image,
173 '$login_bg_color' => $login_bg_color
176 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
178 // Get the content of the scheme css file and the time of the last file change.
179 if ($schemecssfile) {
180 $css_tpl .= file_get_contents($schemecssfile);
181 $scheme_modified = filemtime($schemecssfile);
184 // We need to check which is the most recent css data.
185 // We will use this time later to decide if we load the cached or fresh css data.
186 if ($scheme_modified > $modified) {
187 $modified = $scheme_modified;
189 // Apply the settings to the css template.
190 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
192 $modified = gmdate('r', $modified);
196 // Set a header for caching.
197 header('Cache-Control: public');
198 header('ETag: "' . $etag . '"');
199 header('Last-Modified: ' . $modified);
201 // Only send the CSS file if it was changed.
202 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
203 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
204 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
205 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
206 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
208 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
209 header('HTTP/1.1 304 Not Modified');