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;
17 if ($a->module !== 'install') {
21 // Load frios system config.
22 $scheme = Config::get('frio', 'scheme', Config::get('frio', 'schema'));
23 $nav_bg = Config::get('frio', 'nav_bg', '#708fa0');
24 $nav_icon_color = Config::get('frio', 'nav_icon_color', '#fff');
25 $link_color = Config::get('frio', 'link_color', '#6fdbe8');
26 $background_color = Config::get('frio', 'background_color', '#ededed');
27 $contentbg_transp = Config::get('frio', 'contentbg_transp');
28 $background_image = Config::get('frio', 'background_image', 'img/none.png');
29 $bg_image_option = Config::get('frio', 'bg_image_option');
30 $login_bg_image = Config::get('frio', 'login_bg_image');
31 $login_bg_color = Config::get('frio', 'login_bg_color');
32 $modified = Config::get('frio', 'css_modified');
34 // There is maybe the case that the user did never modify the theme settings.
35 // In this case we store the present time.
36 if (empty($modified)) {
37 Config::set('frio', 'css_modified', time());
40 // Get the UID of the profile owner.
41 $uid = defaults($_REQUEST, 'puid', 0);
43 PConfig::load($uid, 'frio');
45 // Load the profile owners pconfig.
46 $scheme = PConfig::get($uid, 'frio', 'scheme', PConfig::get($uid, 'frio', 'schema'));
47 $nav_bg = PConfig::get($uid, 'frio', 'nav_bg');
48 $nav_icon_color = PConfig::get($uid, 'frio', 'nav_icon_color');
49 $link_color = PConfig::get($uid, 'frio', 'link_color');
50 $background_color = PConfig::get($uid, 'frio', 'background_color');
51 $contentbg_transp = PConfig::get($uid, 'frio', 'contentbg_transp');
52 $background_image = PConfig::get($uid, 'frio', 'background_image');
53 $bg_image_option = PConfig::get($uid, 'frio', 'bg_image_option');
54 $modified = PConfig::get($uid, 'frio', 'css_modified');
56 // There is maybe the case that the user did never modify the theme settings.
57 // In this case we store the present time.
58 if (empty($modified)) {
59 PConfig::set($uid, 'frio', 'css_modified', time());
64 // Now load the scheme. If a value is changed above, we'll keep the settings
65 // If not, we'll keep those defined by the scheme
66 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
67 // not --- like the mobile theme does instead.
68 // Allow layouts to over-ride the scheme.
69 if (!empty($_REQUEST['scheme'])) {
70 $scheme = $_REQUEST['scheme'];
73 $scheme = Strings::sanitizeFilePathItem($scheme);
75 if (($scheme) && ($scheme != '---')) {
76 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
77 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
78 require_once $schemefile;
80 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
81 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
85 // If we haven't got a scheme, load the default. We shouldn't touch this - we
86 // should leave it for admins to define for themselves.
87 // default.php and default.css MUST be symlinks to existing scheme files.
89 if (file_exists('view/theme/frio/scheme/default.php')) {
90 $schemefile = 'view/theme/frio/scheme/default.php';
91 require_once $schemefile;
93 if (file_exists('view/theme/frio/scheme/default.css')) {
94 $schemecssfile = 'view/theme/frio/scheme/default.css';
98 // set a default login bg image if no custom image and no custom bg color are set.
99 if (empty($login_bg_image) && empty($login_bg_color)) {
100 $login_bg_image = 'img/login_bg.jpg';
102 $login_bg_color = (empty($login_bg_color) ? '#ededed' : $login_bg_color);
103 $login_bg_image = (empty($login_bg_image) ? '' : $login_bg_image);
105 $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100);
107 // Calculate some colors in dependance of existing colors.
108 // Some colors are calculated to don't have too many selection
109 // fields in the theme settings.
110 if (!isset($menu_background_hover_color)) {
111 $mbhc = new Color($nav_bg);
112 $mcolor = $mbhc->getHex();
114 if ($mbhc->isLight($mcolor, 75)) {
116 $menu_background_hover_color = '#' . $mbhc->darken(5);
119 $menu_background_hover_color = '#' . $mbhc->lighten(5);
122 if (!isset($nav_icon_hover_color)) {
123 $nihc = new Color($nav_bg);
125 if ($nihc->isLight()) {
126 $nav_icon_hover_color = '#' . $nihc->darken(10);
128 $nav_icon_hover_color = '#' . $nihc->lighten(10);
131 if (!isset($link_hover_color)) {
132 $lhc = new Color($link_color);
133 $lcolor = $lhc->getHex();
135 if ($lhc->isLight($lcolor, 75)) {
136 $link_hover_color = '#' . $lhc->darken(5);
138 $link_hover_color = '#' . $lhc->lighten(5);
142 // Convert $bg_image_options into css.
143 if (!isset($bg_image_option)) {
144 $bg_image_option = null;
147 switch ($bg_image_option) {
149 $background_size_img = '100%';
150 $background_repeat = 'no-repeat';
153 $background_size_img = 'cover';
154 $background_repeat = 'no-repeat';
157 $background_size_img = 'auto';
158 $background_repeat = 'repeat';
161 $background_size_img = 'contain';
162 $background_repeat = 'repeat';
166 $background_size_img = 'auto';
167 $background_repeat = 'no-repeat';
171 // Convert transparency level from percentage to opacity value.
172 $contentbg_transp = $contentbg_transp / 100;
175 '$nav_bg' => $nav_bg,
176 '$nav_icon_color' => $nav_icon_color,
177 '$nav_icon_hover_color' => $nav_icon_hover_color,
178 '$link_color' => $link_color,
179 '$link_hover_color' => $link_hover_color,
180 '$menu_background_hover_color' => $menu_background_hover_color,
181 '$btn_primary_color' => $nav_icon_color,
182 '$btn_primary_hover_color' => $menu_background_hover_color,
183 '$background_color' => $background_color,
184 '$contentbg_transp' => $contentbg_transp,
185 '$background_image' => $background_image,
186 '$background_size_img' => $background_size_img,
187 '$background_repeat' => $background_repeat,
188 '$login_bg_image' => $login_bg_image,
189 '$login_bg_color' => $login_bg_color
192 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
194 // Get the content of the scheme css file and the time of the last file change.
195 if ($schemecssfile) {
196 $css_tpl .= file_get_contents($schemecssfile);
197 $scheme_modified = filemtime($schemecssfile);
200 // We need to check which is the most recent css data.
201 // We will use this time later to decide if we load the cached or fresh css data.
202 if ($scheme_modified > $modified) {
203 $modified = $scheme_modified;
205 // Apply the settings to the css template.
206 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
208 $modified = gmdate('r', $modified);
212 // Set a header for caching.
213 header('Cache-Control: public');
214 header('ETag: "' . $etag . '"');
215 header('Last-Modified: ' . $modified);
217 // Only send the CSS file if it was changed.
218 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
219 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
220 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
221 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
222 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
224 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
225 header('HTTP/1.1 304 Not Modified');