1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * webtrees: online genealogy |
||
4 | * Copyright (C) 2018 webtrees development team |
||
5 | * This program is free software: you can redistribute it and/or modify |
||
6 | * it under the terms of the GNU General Public License as published by |
||
7 | * the Free Software Foundation, either version 3 of the License, or |
||
8 | * (at your option) any later version. |
||
9 | * This program is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU General Public License for more details. |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
15 | */ |
||
16 | namespace Fisharebest\Webtrees; |
||
17 | |||
18 | // This script does not load session.php. |
||
19 | // session.php won’t run until a configuration file and database connection exist... |
||
20 | // This next block of code is a minimal version of session.php |
||
21 | define('WT_WEBTREES', 'webtrees'); |
||
22 | define('WT_BASE_URL', ''); |
||
23 | define('WT_ROOT', ''); |
||
24 | define('WT_DATA_DIR', realpath('data') . DIRECTORY_SEPARATOR); |
||
25 | define('WT_MODULES_DIR', 'modules_v3/'); |
||
26 | |||
27 | require 'vendor/autoload.php'; |
||
28 | |||
29 | Session::start(); |
||
30 | |||
31 | define('WT_LOCALE', I18N::init()); |
||
32 | |||
33 | if (file_exists(WT_DATA_DIR . 'offline.txt')) { |
||
34 | $offline_txt = file_get_contents(WT_DATA_DIR . 'offline.txt'); |
||
35 | } else { |
||
36 | // offline.txt has gone - we're back online! |
||
37 | header('Location: index.php'); |
||
38 | |||
39 | return; |
||
40 | } |
||
41 | |||
42 | http_response_code(503); |
||
43 | header('Content-Type: text/html; charset=UTF-8'); |
||
44 | |||
45 | echo |
||
46 | '<!DOCTYPE html>', |
||
47 | '<html ', I18N::htmlAttributes(), '>', |
||
48 | '<head>', |
||
49 | '<meta charset="UTF-8">', |
||
50 | '<title>', WT_WEBTREES, '</title>', |
||
51 | '<meta name="robots" content="noindex,follow">', |
||
52 | '<style type="text/css"> |
||
53 | body {color: gray; background-color: white; font: 14px tahoma, arial, helvetica, sans-serif; padding:10px; } |
||
54 | a {color: #81A9CB; font-weight: bold; text-decoration: none;} |
||
55 | a:hover {text-decoration: underline;} |
||
56 | h1 {color: #81A9CB; font-weight:normal; text-align:center;} |
||
57 | li {line-height:2;} |
||
58 | blockquote {color:red;} |
||
59 | .content { /*margin:auto; width:800px;*/ border:1px solid gray; padding:15px; border-radius:15px;} |
||
60 | .good {color: green;} |
||
61 | </style>', |
||
62 | '</head><body>', |
||
63 | '<h1>', I18N::translate('This website is temporarily unavailable'), '</h1>', |
||
64 | '<div class="content"><p>'; |
||
65 | |||
66 | if ($offline_txt) { |
||
67 | echo $offline_txt; |
||
68 | } else { |
||
69 | echo I18N::translate('This website is down for maintenance. You should <a href="index.php">try again</a> in a few minutes.'); |
||
70 | } |
||
71 | echo '</p>'; |
||
72 | echo '</div>'; |
||
73 | echo '</body>'; |
||
74 | echo '</html>'; |
||
75 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.