3 * @file view/theme/frio/style.php
6 use Friendica\Core\Config;
7 use Friendica\Core\PConfig;
9 require_once 'view/theme/frio/php/PHPColors/Color.php';
12 $schemecssfile = false;
15 if ($a->module !== 'install') {
16 // Get the UID of the profile owner.
17 $uid = defaults($_REQUEST, 'puid', 0);
19 PConfig::load($uid, 'frio');
21 // Load the profile owners pconfig.
22 $scheme = PConfig::get($uid, 'frio', 'scheme', PConfig::get($uid, 'frio', 'schema'));
23 \Friendica\Core\Logger::alert($scheme);
24 $nav_bg = PConfig::get($uid, 'frio', 'nav_bg');
25 $nav_icon_color = PConfig::get($uid, 'frio', 'nav_icon_color');
26 $link_color = PConfig::get($uid, 'frio', 'link_color');
27 $background_color = PConfig::get($uid, 'frio', 'background_color');
28 $contentbg_transp = PConfig::get($uid, 'frio', 'contentbg_transp');
29 $background_image = PConfig::get($uid, 'frio', 'background_image');
30 $bg_image_option = PConfig::get($uid, 'frio', 'bg_image_option');
31 $modified = PConfig::get($uid, 'frio', 'css_modified');
33 // There is maybe the case that the user did never modify the theme settings.
34 // In this case we store the present time.
35 if (empty($modified)) {
36 PConfig::set($uid, 'frio', 'css_modified', time());
41 // Load frios system config.
42 $scheme = Config::get('frio', 'scheme', Config::get('frio', 'schema'));
43 $nav_bg = Config::get('frio', 'nav_bg');
44 $nav_icon_color = Config::get('frio', 'nav_icon_color');
45 $link_color = Config::get('frio', 'link_color');
46 $background_color = Config::get('frio', 'background_color');
47 $contentbg_transp = Config::get('frio', 'contentbg_transp');
48 $background_image = Config::get('frio', 'background_image');
49 $bg_image_option = Config::get('frio', 'bg_image_option');
50 $login_bg_image = Config::get('frio', 'login_bg_image');
51 $login_bg_color = Config::get('frio', 'login_bg_color');
52 $modified = Config::get('frio', 'css_modified');
54 // There is maybe the case that the user did never modify the theme settings.
55 // In this case we store the present time.
56 if (empty($modified)) {
57 Config::set('frio', 'css_modified', time());
62 // Now load the scheme. If a value is changed above, we'll keep the settings
63 // If not, we'll keep those defined by the scheme
64 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
65 // not --- like the mobile theme does instead.
66 // Allow layouts to over-ride the scheme.
67 if (!empty($_REQUEST['scheme'])) {
68 $scheme = $_REQUEST['scheme'];
72 $scheme = !empty($scheme) ? basename($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 some defaults - we have to do this after pulling owner settings, and we have to check for each setting
99 //individually. If we don't, we'll have problems if a user has set one, but not all options.
100 $nav_bg = (empty($nav_bg) ? '#708fa0' : $nav_bg);
101 $nav_icon_color = (empty($nav_icon_color) ? '#fff' : $nav_icon_color);
102 $link_color = (empty($link_color) ? '#6fdbe8' : $link_color);
103 $background_color = (empty($background_color) ? '#ededed' : $background_color);
104 // The background image can not be empty. So we use a dummy jpg if no image was set.
105 $background_image = (empty($background_image) ? 'img/none.jpg' : $background_image);
106 $modified = (empty($modified) ? time() : $modified);
109 // set a default login bg image if no custom image and no custom bg color are set.
110 if (empty($login_bg_image) && empty($login_bg_color)) {
111 $login_bg_image = 'img/login_bg.jpg';
113 $login_bg_color = (empty($login_bg_color) ? '#ededed' : $login_bg_color);
114 $login_bg_image = (empty($login_bg_image) ? '' : $login_bg_image);
116 $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100);
118 // Calculate some colors in dependance of existing colors.
119 // Some colors are calculated to don't have too many selection
120 // fields in the theme settings.
121 if (!isset($menu_background_hover_color)) {
122 $mbhc = new Color($nav_bg);
123 $mcolor = $mbhc->getHex();
125 if ($mbhc->isLight($mcolor, 75)) {
127 $menu_background_hover_color = '#' . $mbhc->darken(5);
130 $menu_background_hover_color = '#' . $mbhc->lighten(5);
133 if (!isset($nav_icon_hover_color)) {
134 $nihc = new Color($nav_bg);
136 if ($nihc->isLight()) {
137 $nav_icon_hover_color = '#' . $nihc->darken(10);
139 $nav_icon_hover_color = '#' . $nihc->lighten(10);
142 if (!isset($link_hover_color)) {
143 $lhc = new Color($link_color);
144 $lcolor = $lhc->getHex();
146 if ($lhc->isLight($lcolor, 75)) {
147 $link_hover_color = '#' . $lhc->darken(5);
149 $link_hover_color = '#' . $lhc->lighten(5);
153 // Convert $bg_image_options into css.
154 if (!isset($bg_image_option)) {
155 $bg_image_option = null;
158 switch ($bg_image_option) {
160 $background_size_img = '100%';
161 $background_repeat = 'no-repeat';
164 $background_size_img = 'cover';
165 $background_repeat = 'no-repeat';
168 $background_size_img = 'auto';
169 $background_repeat = 'repeat';
172 $background_size_img = 'contain';
173 $background_repeat = 'repeat';
177 $background_size_img = 'auto';
178 $background_repeat = 'no-repeat';
182 // Convert transparency level from percentage to opacity value.
183 $contentbg_transp = $contentbg_transp / 100;
186 '$nav_bg' => $nav_bg,
187 '$nav_icon_color' => $nav_icon_color,
188 '$nav_icon_hover_color' => $nav_icon_hover_color,
189 '$link_color' => $link_color,
190 '$link_hover_color' => $link_hover_color,
191 '$menu_background_hover_color' => $menu_background_hover_color,
192 '$btn_primary_color' => $nav_icon_color,
193 '$btn_primary_hover_color' => $menu_background_hover_color,
194 '$background_color' => $background_color,
195 '$contentbg_transp' => $contentbg_transp,
196 '$background_image' => $background_image,
197 '$background_size_img' => $background_size_img,
198 '$background_repeat' => $background_repeat,
199 '$login_bg_image' => $login_bg_image,
200 '$login_bg_color' => $login_bg_color
203 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
205 // Get the content of the scheme css file and the time of the last file change.
206 if ($schemecssfile) {
207 $css_tpl .= file_get_contents($schemecssfile);
208 $scheme_modified = filemtime($schemecssfile);
211 // We need to check which is the most recent css data.
212 // We will use this time later to decide if we load the cached or fresh css data.
213 if ($scheme_modified > $modified) {
214 $modified = $scheme_modified;
216 // Apply the settings to the css template.
217 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
219 $modified = gmdate('r', $modified);
223 // Set a header for caching.
224 header('Cache-Control: public');
225 header('ETag: "' . $etag . '"');
226 header('Last-Modified: ' . $modified);
228 // Only send the CSS file if it was changed.
229 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
230 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
231 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
232 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
233 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
235 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
236 header('HTTP/1.1 304 Not Modified');