]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/style.php
Update translation fie after adding a string
[friendica.git] / view / theme / vier / style.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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 $uid = $_REQUEST['puid'] ?? 0;
27
28 $style = DI::pConfig()->get($uid, 'vier', 'style');
29
30 if (empty($style)) {
31         $style = DI::config()->get('vier', 'style');
32 }
33
34 if (empty($style)) {
35         $style = "plus";
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                 //TODO: use Logger::ERROR?
53                 Logger::notice('Error: missing file: "' . $stylecssfile .'" (userid: '. $uid .')');
54         }
55 }
56 $modified = gmdate('r', $modified);
57
58 $etag = md5($stylecss);
59
60 // Only send the CSS file if it was changed
61 header('Cache-Control: public');
62 header('ETag: "'.$etag.'"');
63 header('Last-Modified: '.$modified);
64
65 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
66         $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
67         $cached_etag = str_replace(['"', "-gzip"], ['', ''],
68                                 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
69
70         if (($cached_modified == $modified) && ($cached_etag == $etag)) {
71                 throw new NotModifiedException();
72         }
73 }
74 echo $stylecss;