3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 use Friendica\Core\Logger;
25 $uid = $_REQUEST['puid'] ?? 0;
27 $style = DI::pConfig()->get($uid, 'vier', 'style');
30 $style = DI::config()->get('vier', 'style');
40 $style = \Friendica\Util\Strings::sanitizeFilePathItem($style);
42 foreach (['style', $style] as $file) {
43 $stylecssfile = $THEMEPATH . DIRECTORY_SEPARATOR . $file .'.css';
44 if (file_exists($stylecssfile)) {
45 $stylecss .= file_get_contents($stylecssfile);
46 $stylemodified = filemtime($stylecssfile);
47 if ($stylemodified > $modified) {
48 $modified = $stylemodified;
51 //TODO: use Logger::ERROR?
52 Logger::log('Error: missing file: "' . $stylecssfile .'" (userid: '. $uid .')');
55 $modified = gmdate('r', $modified);
57 $etag = md5($stylecss);
59 // Only send the CSS file if it was changed
60 header('Cache-Control: public');
61 header('ETag: "'.$etag.'"');
62 header('Last-Modified: '.$modified);
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']));
69 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
70 header('HTTP/1.1 304 Not Modified');