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