]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/style.php
wrapping up 2019.12
[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 = $_REQUEST['puid'] ?? 0;
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 $style = \Friendica\Util\Strings::sanitizeFilePathItem($style);
26
27 foreach (['style', $style] as $file) {
28         $stylecssfile = $THEMEPATH . DIRECTORY_SEPARATOR . $file .'.css';
29         if (file_exists($stylecssfile)) {
30                 $stylecss .= file_get_contents($stylecssfile);
31                 $stylemodified = filemtime($stylecssfile);
32                 if ($stylemodified > $modified) {
33                         $modified = $stylemodified;
34                 }
35         } else {
36                 //TODO: use Logger::ERROR?
37                 Logger::log('Error: missing file: "' . $stylecssfile .'" (userid: '. $uid .')');
38         }
39 }
40 $modified = gmdate('r', $modified);
41
42 $etag = md5($stylecss);
43
44 // Only send the CSS file if it was changed
45 header('Cache-Control: public');
46 header('ETag: "'.$etag.'"');
47 header('Last-Modified: '.$modified);
48
49 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
50         $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
51         $cached_etag = str_replace(['"', "-gzip"], ['', ''],
52                                 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
53
54         if (($cached_modified == $modified) && ($cached_etag == $etag)) {
55                 header('HTTP/1.1 304 Not Modified');
56                 exit();
57         }
58 }
59 echo $stylecss;