3 * @copyright Copyright (C) 2010-2022, the Friendica project
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;
24 use Friendica\Network\HTTPException\NotModifiedException;
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
32 if (DI::mode()->has(\Friendica\App\Mode::MAINTENANCEDISABLED)) {
33 $uid = $_REQUEST['puid'] ?? 0;
35 $style = DI::pConfig()->get($uid, 'vier', 'style', DI::config()->get('vier', 'style', $style));
41 $style = \Friendica\Util\Strings::sanitizeFilePathItem($style);
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;
52 //TODO: use Logger::ERROR?
53 Logger::notice('Error: missing file: "' . $stylecssfile .'" (userid: '. $uid .')');
56 $modified = gmdate('r', $modified);
58 $etag = md5($stylecss);
60 // Only send the CSS file if it was changed
61 header('Cache-Control: public');
62 header('ETag: "'.$etag.'"');
63 header('Last-Modified: '.$modified);
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']));
70 if (($cached_modified == $modified) && ($cached_etag == $etag)) {
71 throw new NotModifiedException();