These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * webtrees: online genealogy |
||
4 | * Copyright (C) 2017 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 | use PDO; |
||
19 | use PDOException; |
||
20 | |||
21 | // This script does not load session.php. |
||
22 | // session.php won’t run until a configuration file and database connection exist... |
||
23 | // This next block of code is a minimal version of session.php |
||
24 | define('WT_WEBTREES', 'webtrees'); |
||
25 | define('WT_BASE_URL', ''); |
||
26 | define('WT_ROOT', ''); |
||
27 | define('WT_DATA_DIR', realpath('data') . DIRECTORY_SEPARATOR); |
||
28 | define('WT_MODULES_DIR', 'modules_v3/'); |
||
29 | |||
30 | require 'vendor/autoload.php'; |
||
31 | |||
32 | define('WT_LOCALE', I18N::init()); |
||
33 | |||
34 | http_response_code(503); |
||
35 | |||
36 | header('Content-Type: text/html; charset=UTF-8'); |
||
37 | // The page which redirected here may have provided an error message. |
||
38 | $messages = ''; |
||
39 | if (Filter::get('message')) { |
||
40 | $messages .= |
||
41 | '<blockquote>' . Filter::escapeHtml(Filter::get('message')) . '</blockquote>'; |
||
42 | } |
||
43 | |||
44 | // If we can't connect to the database at all, give the reason why |
||
45 | $config_ini_php = parse_ini_file('data/config.ini.php'); |
||
46 | if (is_array($config_ini_php) && array_key_exists('dbhost', $config_ini_php) && array_key_exists('dbport', $config_ini_php) && array_key_exists('dbuser', $config_ini_php) && array_key_exists('dbpass', $config_ini_php) && array_key_exists('dbname', $config_ini_php)) { |
||
47 | try { |
||
48 | new PDO('mysql:host=' . $config_ini_php['dbhost'] . ';port=' . $config_ini_php['dbport'] . ';dbname=' . $config_ini_php['dbname'], $config_ini_php['dbuser'], $config_ini_php['dbpass'], [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_AUTOCOMMIT => true]); |
||
49 | } catch (PDOException $ex) { |
||
50 | $messages .= '<p>' . I18N::translate('The database reported the following error message:') . '</p>'; |
||
51 | $messages .= '<blockquote>' . $ex->getMessage() . '</blockquote>'; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | ?> |
||
56 | <!DOCTYPE html> |
||
57 | <html <?= I18N::htmlAttributes() ?>> |
||
58 | <head> |
||
59 | <meta charset="UTF-8"> |
||
60 | <title><?= WT_WEBTREES ?></title> |
||
61 | <meta name="robots" content="noindex,follow"> |
||
62 | <style type="text/css"> |
||
63 | body {color: gray; background-color: white; font: 14px tahoma, arial, helvetica, sans-serif; padding:10px; } |
||
64 | a {color: #81A9CB; font-weight: bold; text-decoration: none;} |
||
65 | a:hover {text-decoration: underline;} |
||
66 | h1 {color: #81A9CB; font-weight:normal; text-align:center;} |
||
67 | li {line-height:2;} |
||
68 | blockquote {color:red;} |
||
69 | .content { border:1px solid gray; padding:15px; margin: 15px; border-radius:15px;} |
||
70 | .good {color: green;} |
||
71 | </style> |
||
72 | </head> |
||
73 | <body> |
||
74 | <h1><?= I18N::translate('This website is temporarily unavailable') ?></h1> |
||
75 | <div class="content"> |
||
76 | <p> |
||
77 | <?= I18N::translate('Oops! The webserver is unable to connect to the database server. It could be busy, undergoing maintenance, or simply broken. You should <a href="index.php">try again</a> in a few minutes or contact the website administrator.') ?> |
||
78 | </p> |
||
79 | <?= $messages ?> |
||
80 | <?= I18N::translate('If you are the website administrator, you should check that:') ?> |
||
81 | <ol> |
||
82 | <li> |
||
83 | <?= /* I18N: [you should check that:] ... */ I18N::translate('the database connection settings in the file “/data/config.ini.php” are still correct') ?> |
||
84 | </li> |
||
85 | <li> |
||
86 | <?= /* I18N: [you should check that:] ... */ I18N::translate('the folder “/data” and the file “/data/config.ini.php” have access permissions that allow the webserver to read them') ?> |
||
87 | </li> |
||
88 | <li> |
||
89 | <?= /* I18N: [you should check that:] ... */ I18N::translate('you can connect to the database using other applications, such as phpmyadmin') ?> |
||
90 | </li> |
||
91 | </ol> |
||
92 | <p class="good"> |
||
93 | <?= I18N::translate('If you cannot resolve the problem yourself, you can ask for help on the forums at <a href="https://webtrees.net">webtrees.net</a>.') ?> |
||
94 | </p> |
||
95 | </div> |
||
96 | </body> |
||
97 | </html> |
||
98 |
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.