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