2 require_once 'view/theme/frio/php/PHPColors/Color.php';
4 use Friendica\Core\PConfig;
7 $schemecssfile = false;
11 // Get the UID of the profile owner.
12 $uid = get_theme_uid();
14 PConfig::load($uid, 'frio');
16 // Load the profile owners pconfig.
17 $schema = PConfig::get($uid, "frio", "schema");
18 $nav_bg = PConfig::get($uid, "frio", "nav_bg");
19 $nav_icon_color = PConfig::get($uid, "frio", "nav_icon_color");
20 $link_color = PConfig::get($uid, "frio", "link_color");
21 $bgcolor = PConfig::get($uid, "frio", "background_color");
22 $contentbg_transp = PConfig::get($uid, "frio", "contentbg_transp");
23 $background_image = PConfig::get($uid, "frio", "background_image");
24 $bg_image_option = PConfig::get($uid, "frio", "bg_image_option");
25 $modified = PConfig::get($uid, "frio", "css_modified");
27 // There is maybe the case that the user did never modify the theme settings.
28 // In this case we store the present time.
29 if (empty($modified)) {
30 PConfig::set($uid, 'frio', 'css_modified', time());
35 // Now load the scheme. If a value is changed above, we'll keep the settings
36 // If not, we'll keep those defined by the schema
37 // Setting $schema to '' wasn't working for some reason, so we'll check it's
38 // not --- like the mobile theme does instead.
39 // Allow layouts to over-ride the schema.
40 if ($_REQUEST['schema']) {
41 $schema = $_REQUEST['schema'];
43 if (($schema) && ($schema != '---')) {
44 if (file_exists('view/theme/frio/schema/' . $schema . '.php')) {
45 $schemefile = 'view/theme/frio/schema/' . $schema . '.php';
46 require_once $schemefile;
48 if (file_exists('view/theme/frio/schema/' . $schema . '.css')) {
49 $schemecssfile = 'view/theme/frio/schema/' . $schema . '.css';
53 // If we haven't got a schema, load the default. We shouldn't touch this - we
54 // should leave it for admins to define for themselves.
55 // default.php and default.css MUST be symlinks to existing schema files.
57 if(file_exists('view/theme/frio/schema/default.php')) {
58 $schemefile = 'view/theme/frio/schema/default.php';
59 require_once $schemefile;
61 if(file_exists('view/theme/frio/schema/default.css')) {
62 $schemecssfile = 'view/theme/frio/schema/default.css';
66 //Set some defaults - we have to do this after pulling owner settings, and we have to check for each setting
67 //individually. If we don't, we'll have problems if a user has set one, but not all options.
68 $nav_bg = (empty($nav_bg) ? "#708fa0" : $nav_bg);
69 $nav_icon_color = (empty($nav_icon_color) ? "#fff" : $nav_icon_color);
70 $link_color = (empty($link_color) ? "#6fdbe8" : $link_color);
71 $bgcolor = (empty($bgcolor) ? "#ededed" : $bgcolor);
72 $background_image = (empty($background_image) ? '' : $background_image);
73 $modified = (empty($modified) ? time() : $modified);
75 $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != "") ? $contentbg_transp : 100);
77 // Calculate some colors in dependance of existing colors.
78 // Some colors are calculated to don't have too many selection
79 // fields in the theme settings.
80 if (! $menu_background_hover_color) {
81 $mbhc = new Color($nav_bg);
82 $mcolor = $mbhc->getHex();
84 if ($mbhc->isLight($mcolor, 75)) {
86 $menu_background_hover_color = '#' . $mbhc->darken(5);
89 $menu_background_hover_color = '#' . $mbhc->lighten(5);
92 if (! $nav_icon_hover_color) {
93 $nihc = new Color($nav_bg);
95 if ($nihc->isLight()) {
96 $nav_icon_hover_color = '#' . $nihc->darken(10);
98 $nav_icon_hover_color = '#' . $nihc->lighten(10);
101 if (! $link_hover_color) {
102 $lhc = new Color($link_color);
103 $lcolor = $lhc->getHex();
105 if ($lhc->isLight($lcolor, 75)) {
106 $link_hover_color = '#' . $lhc->darken(5);
108 $link_hover_color = '#' . $lhc->lighten(5);
113 // Convert $bg_image_options into css.
114 switch ($bg_image_option) {
116 $background_size_img = "100%";
119 $background_size_img ="cover";
122 $background_size_img = "auto";
125 $background_size_img = "contain";
129 $background_size_img = "auto";
133 // Convert transparency level from percentage to opacity value.
134 $contentbg_transp = $contentbg_transp / 100;
137 '$nav_bg' => $nav_bg,
138 '$nav_icon_color' => $nav_icon_color,
139 '$nav_icon_hover_color' => $nav_icon_hover_color,
140 '$link_color' => $link_color,
141 '$link_hover_color' => $link_hover_color,
142 '$menu_background_hover_color' => $menu_background_hover_color,
143 '$btn_primary_color' => $nav_icon_color,
144 '$btn_primary_hover_color' => $menu_background_hover_color,
145 '$bgcolor' => $bgcolor,
146 '$contentbg_transp' => $contentbg_transp,
147 '$background_image' => $background_image,
148 '$background_size_img' => $background_size_img,
151 $css_tpl = file_get_contents('view/theme/frio/css/style.css');
153 // Get the content of the scheme css file and the time of the last file change.
154 if ($schemecssfile) {
155 $css_tpl .= file_get_contents($schemecssfile);
156 $scheme_modified = filemtime($schemecssfile);
159 // We need to check which is the most recent css data.
160 // We will use this time later to decide if we load the cached or fresh css data.
161 if ($scheme_modified > $modified) {
162 $modified = $scheme_modified;
164 // Apply the settings to the css template.
165 $css = str_replace(array_keys($options), array_values($options), $css_tpl);
167 $modified = gmdate('r', $modified);
171 // Set a header for caching.
172 header('Cache-Control: public');
173 header('ETag: "'.$etag.'"');
174 header('Last-Modified: '.$modified);
176 // Only send the CSS file if it was changed.
177 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
178 $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
179 $cached_etag = str_replace(array('"', "-gzip"), array('', ''),
180 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
182 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
183 header('HTTP/1.1 304 Not Modified');