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