]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/style.php
Happy New Year 2023!
[friendica.git] / view / theme / vier / style.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 use Friendica\Core\Logger;
23 use Friendica\DI;
24 use Friendica\Network\HTTPException\NotModifiedException;
25
26 /*
27  * This script can be included when the maintenance mode is on, which requires us to avoid any config call and
28  * use the following hardcoded default
29  */
30 $style = 'plus';
31
32 if (DI::mode()->has(\Friendica\App\Mode::MAINTENANCEDISABLED)) {
33         $uid = $_REQUEST['puid'] ?? 0;
34
35         $style = DI::pConfig()->get($uid, 'vier', 'style', DI::config()->get('vier', 'style', $style));
36 }
37
38 $stylecss = '';
39 $modified = '';
40
41 $style = \Friendica\Util\Strings::sanitizeFilePathItem($style);
42
43 foreach (['style', $style] as $file) {
44         $stylecssfile = $THEMEPATH . DIRECTORY_SEPARATOR . $file .'.css';
45         if (file_exists($stylecssfile)) {
46                 $stylecss .= file_get_contents($stylecssfile);
47                 $stylemodified = filemtime($stylecssfile);
48                 if ($stylemodified > $modified) {
49                         $modified = $stylemodified;
50                 }
51         } else {
52                 Logger::warning('Missing CSS file', ['file' => $stylecssfile, 'uid' => $uid]);
53         }
54 }
55 $modified = gmdate('r', $modified);
56
57 $etag = md5($stylecss);
58
59 // Only send the CSS file if it was changed
60 header('Cache-Control: public');
61 header('ETag: "'.$etag.'"');
62 header('Last-Modified: '.$modified);
63
64 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
65         $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
66         $cached_etag = str_replace(['"', "-gzip"], ['', ''],
67                                 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
68
69         if (($cached_modified == $modified) && ($cached_etag == $etag)) {
70                 throw new NotModifiedException();
71         }
72 }
73 echo $stylecss;