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') {
18 // Get the UID of the profile owner.
19 $uid = defaults($_REQUEST, 'puid', 0);
21 PConfig::load($uid, 'frio');
23 // Load the profile owners pconfig.
24 $scheme = PConfig::get($uid, 'frio', 'scheme', PConfig::get($uid, 'frio', 'schema'));
25 $nav_bg = PConfig::get($uid, 'frio', 'nav_bg');
26 $nav_icon_color = PConfig::get($uid, 'frio', 'nav_icon_color');
27 $link_color = PConfig::get($uid, 'frio', 'link_color');
28 $background_color = PConfig::get($uid, 'frio', 'background_color');
29 $contentbg_transp = PConfig::get($uid, 'frio', 'contentbg_transp');
30 $background_image = PConfig::get($uid, 'frio', 'background_image');
31 $bg_image_option = PConfig::get($uid, 'frio', 'bg_image_option');
32 $modified = PConfig::get($uid, '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 PConfig::set($uid, 'frio', 'css_modified', time());
42 // Load frios system config.
43 $scheme = Config::get('frio', 'scheme', Config::get('frio', 'schema'));
44 $nav_bg = Config::get('frio', 'nav_bg');
45 $nav_icon_color = Config::get('frio', 'nav_icon_color');
46 $link_color = Config::get('frio', 'link_color');
47 $background_color = Config::get('frio', 'background_color');
48 $contentbg_transp = Config::get('frio', 'contentbg_transp');
49 $background_image = Config::get('frio', 'background_image');
50 $bg_image_option = Config::get('frio', 'bg_image_option');
51 $login_bg_image = Config::get('frio', 'login_bg_image');
52 $login_bg_color = Config::get('frio', 'login_bg_color');
53 $modified = Config::get('frio', 'css_modified');
55 // There is maybe the case that the user did never modify the theme settings.
56 // In this case we store the present time.
57 if (empty($modified)) {
58 Config::set('frio', 'css_modified', time());
63 // Now load the scheme. If a value is changed above, we'll keep the settings
64 // If not, we'll keep those defined by the scheme
65 // Setting $scheme to '' wasn't working for some reason, so we'll check it's
66 // not --- like the mobile theme does instead.
67 // Allow layouts to over-ride the scheme.
68 if (!empty($_REQUEST['scheme'])) {
69 $scheme = $_REQUEST['scheme'];
72 $scheme = Strings::sanitizeFilePathItem($scheme);
74 if (($scheme) && ($scheme != '---')) {
75 if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
76 $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
77 require_once $schemefile;
79 if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
80 $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
84 // If we haven't got a scheme, load the default. We shouldn't touch this - we
85 // should leave it for admins to define for themselves.
86 // default.php and default.css MUST be symlinks to existing scheme files.
88 if (file_exists('view/theme/frio/scheme/default.php')) {
89 $schemefile = 'view/theme/frio/scheme/default.php';
90 require_once $schemefile;
92 if (file_exists('view/theme/frio/scheme/default.css')) {
93 $schemecssfile = 'view/theme/frio/scheme/default.css';
96 //If no scheme was set default to login theme.
97 $nav_bg = (empty($nav_bg) ? Config::get('frio', 'nav_bg') : $nav_bg);
98 $nav_icon_color = (empty($nav_icon_color) ? Config::get('frio', 'nav_icon_color') : $nav_icon_color);
99 $link_color = (empty($link_color) ? Config::get('frio', 'link_color') : $link_color);
100 $background_color = (empty($background_color) ? Config::get('frio', 'background_color') : $background_color);
101 $background_image = (empty($background_image) ? Config::get('frio', 'background_image') : $background_image);
103 //If login theme unset default to master default
104 //Set some defaults - we have to do this after pulling owner settings, and we have to check for each setting
105 //individually. If we don't, we'll have problems if a user has set one, but not all options.
106 $nav_bg = (empty($nav_bg) ? '#708fa0' : $nav_bg);
107 $nav_icon_color = (empty($nav_icon_color) ? '#fff' : $nav_icon_color);
108 $link_color = (empty($link_color) ? '#6fdbe8' : $link_color);
109 $background_color = (empty($background_color) ? '#ededed' : $background_color);
110 // The background image can not be empty. So we use a dummy jpg if no image was set.
111 $background_image = (empty($background_image) ? 'img/none.png' : $background_image);
112 $modified = (empty($modified) ? time() : $modified);
115 // set a default login bg image if no custom image and no custom bg color are set.
116 if (empty($login_bg_image) && empty($login_bg_color)) {
117 $login_bg_image = 'img/login_bg.jpg';
119 $login_bg_color = (empty($login_bg_color) ? '#ededed' : $login_bg_color);
120 $login_bg_image = (empty($login_bg_image) ? '' : $login_bg_image);
122 $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100);
124 // Calculate some colors in dependance of existing colors.
125 // Some colors are calculated to don't have too many selection
126 // fields in the theme settings.
127 if (!isset($menu_background_hover_color)) {
128 $mbhc = new Color($nav_bg);
129 $mcolor = $mbhc->getHex();
131 if ($mbhc->isLight($mcolor, 75)) {
133 $menu_background_hover_color = '#' . $mbhc->darken(5);
136 $menu_background_hover_color = '#' . $mbhc->lighten(5);
139 if (!isset($nav_icon_hover_color)) {
140 $nihc = new Color($nav_bg);
142 if ($nihc->isLight()) {
143 $nav_icon_hover_color = '#' . $nihc->darken(10);
145 $nav_icon_hover_color = '#' . $nihc->lighten(10);
148 if (!isset($link_hover_color)) {
149 $lhc = new Color($link_color);
150 $lcolor = $lhc->getHex();
152 if ($lhc->isLight($lcolor, 75)) {
153 $link_hover_color = '#' . $lhc->darken(5);
155 $link_hover_color = '#' . $lhc->lighten(5);
159 // Convert $bg_image_options into css.
160 if (!isset($bg_image_option)) {
161 $bg_image_option = null;
164 switch ($bg_image_option) {
166 $background_size_img = '100%';
167 $background_repeat = 'no-repeat';
170 $background_size_img = 'cover';
171 $background_repeat = 'no-repeat';
174 $background_size_img = 'auto';
175 $background_repeat = 'repeat';
178 $background_size_img = 'contain';
179 $background_repeat = 'repeat';
183 $background_size_img = 'auto';
184 $background_repeat = 'no-repeat';
188 // Convert transparency level from percentage to opacity value.
189 $contentbg_transp = $contentbg_transp / 100;
192 '$nav_bg' => $nav_bg,
193 '$nav_icon_color' => $nav_icon_color,
194 '$nav_icon_hover_color' => $nav_icon_hover_color,
195 '$link_color' => $link_color,
196 '$link_hover_color' => $link_hover_color,
197 '$menu_background_hover_color' => $menu_background_hover_color,
198 '$btn_primary_color' => $nav_icon_color,
199 '$btn_primary_hover_color' => $menu_background_hover_color,
200 '$background_color' => $background_color,
201 '$contentbg_transp' => $contentbg_transp,
202 '$background_image' => $background_image,
203 '$background_size_img' => $background_size_img,
204 '$background_repeat' => $background_repeat,
205 '$login_bg_image' => $login_bg_image,
206 '$login_bg_color' => $login_bg_color
209 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
211 // Get the content of the scheme css file and the time of the last file change.
212 if ($schemecssfile) {
213 $css_tpl .= file_get_contents($schemecssfile);
214 $scheme_modified = filemtime($schemecssfile);
217 // We need to check which is the most recent css data.
218 // We will use this time later to decide if we load the cached or fresh css data.
219 if ($scheme_modified > $modified) {
220 $modified = $scheme_modified;
222 // Apply the settings to the css template.
223 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
225 $modified = gmdate('r', $modified);
229 // Set a header for caching.
230 header('Cache-Control: public');
231 header('ETag: "' . $etag . '"');
232 header('Last-Modified: ' . $modified);
234 // Only send the CSS file if it was changed.
235 /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
236 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
237 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
238 $cached_etag = str_replace(['"', '-gzip'], ['', ''],
239 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
241 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
242 header('HTTP/1.1 304 Not Modified');