]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/style.php
196d3776561e165632fcfaa184f55ba206134fd6
[friendica.git] / view / theme / vier / style.php
1 <?php
2 /**
3  * @file view/theme/vier/style.php
4  */
5 use Friendica\Core\Logger;
6 use Friendica\Core\Config;
7 use Friendica\Core\PConfig;
8 use Friendica\Model\Profile;
9
10 $uid = Profile::getThemeUid();
11
12 $style = PConfig::get($uid, 'vier', 'style');
13
14 if (empty($style)) {
15         $style = Config::get('vier', 'style');
16 }
17
18 if (empty($style)) {
19         $style = "plus";
20 }
21
22 $stylecss = '';
23 $modified = '';
24
25 foreach (['style', $style] as $file) {
26         $stylecssfile = $THEMEPATH . DIRECTORY_SEPARATOR . $file .'.css';
27         if (file_exists($stylecssfile)) {
28                 $stylecss .= file_get_contents($stylecssfile);
29                 $stylemodified = filemtime($stylecssfile);
30                 if ($stylemodified > $modified) {
31                         $modified = $stylemodified;
32                 }
33         } else {
34                 //TODO: use Logger::ERROR?
35                 Logger::log('Error: missing file: "' . $stylecssfile .'" (userid: '. $uid .')');
36         }
37 }
38 $modified = gmdate('r', $modified);
39
40 $etag = md5($stylecss);
41
42 // Only send the CSS file if it was changed
43 header('Cache-Control: public');
44 header('ETag: "'.$etag.'"');
45 header('Last-Modified: '.$modified);
46
47 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
48         $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
49         $cached_etag = str_replace(['"', "-gzip"], ['', ''],
50                                 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
51
52         if (($cached_modified == $modified) && ($cached_etag == $etag)) {
53                 header('HTTP/1.1 304 Not Modified');
54                 exit();
55         }
56 }
57 echo $stylecss;