1 | <?php |
||
2 | /** |
||
3 | * An overview of the server requirements and if they are met |
||
4 | * similar to how it's checked during installation |
||
5 | * |
||
6 | * @see ElggInstaller::checkPHP() |
||
7 | */ |
||
8 | |||
9 | use Elgg\Database\DbConfig; |
||
10 | use Elgg\Http\Request; |
||
11 | use Elgg\Router\RewriteTester; |
||
12 | |||
13 | $icon_ok = elgg_view_icon('check'); |
||
14 | $icon_warning = elgg_view_icon('exclamation-triangle'); |
||
15 | $icon_error = elgg_view_icon('times'); |
||
16 | |||
17 | $view_module = function($icon, $title, $value = '', $subtext = '') { |
||
18 | $body = elgg_format_element('strong', [], $title); |
||
19 | if (!elgg_is_empty($value)) { |
||
20 | $body .= elgg_format_element('span', ['class' => 'mlm'], $value); |
||
21 | } |
||
22 | |||
23 | if (!elgg_is_empty($subtext)) { |
||
24 | $body .= elgg_format_element('div', ['class' => 'elgg-subtext'], $subtext); |
||
25 | } |
||
26 | |||
27 | return elgg_view_image_block($icon, $body, ['class' => 'elgg-admin-information-row']); |
||
28 | }; |
||
29 | |||
30 | // php version |
||
31 | $icon = $icon_ok; |
||
32 | $title = elgg_echo('admin:server:label:php_version'); |
||
33 | $value = PHP_VERSION; |
||
34 | $subtext = ''; |
||
35 | |||
36 | if (version_compare(PHP_VERSION, \ElggInstaller::PHP_MINIMAL_VERSION, '<')) { |
||
37 | $icon = $icon_error; |
||
38 | $subtext = elgg_echo('admin:server:label:php_version:required_version', [\ElggInstaller::PHP_MINIMAL_VERSION]); |
||
39 | } |
||
40 | |||
41 | echo $view_module($icon, $title, $value, $subtext); |
||
42 | |||
43 | // php required extensions |
||
44 | $extensions = get_loaded_extensions(); |
||
45 | $requiredExtensions = [ |
||
46 | 'pdo_mysql', |
||
47 | 'json', |
||
48 | 'xml', |
||
49 | 'gd', |
||
50 | ]; |
||
51 | foreach ($requiredExtensions as $extension) { |
||
52 | $icon = $icon_ok; |
||
53 | $title = elgg_echo('admin:server:requirements:php_extension', [$extension]); |
||
54 | $value = elgg_echo('status:enabled'); |
||
55 | $subtext = ''; |
||
56 | |||
57 | if (!in_array($extension, $extensions)) { |
||
58 | $icon = $icon_error; |
||
59 | $value = elgg_echo('status:unavailable'); |
||
60 | $subtext = elgg_echo('admin:server:requirements:php_extension:required'); |
||
61 | } |
||
62 | |||
63 | echo $view_module($icon, $title, $value, $subtext); |
||
64 | } |
||
65 | |||
66 | // php recommended extensions |
||
67 | $recommendedExtensions = [ |
||
68 | 'mbstring', |
||
69 | ]; |
||
70 | foreach ($recommendedExtensions as $extension) { |
||
71 | $icon = $icon_ok; |
||
72 | $title = elgg_echo('admin:server:requirements:php_extension', [$extension]); |
||
73 | $value = elgg_echo('status:enabled'); |
||
74 | $subtext = ''; |
||
75 | |||
76 | if (!in_array($extension, $extensions)) { |
||
77 | $icon = $icon_warning; |
||
78 | $value = elgg_echo('status:unavailable'); |
||
79 | $subtext = elgg_echo('admin:server:requirements:php_extension:recommended'); |
||
80 | } |
||
81 | |||
82 | echo $view_module($icon, $title, $value, $subtext); |
||
83 | } |
||
84 | |||
85 | // php ini |
||
86 | if (empty(ini_get('session.gc_probability')) || empty(ini_get('session.gc_divisor'))) { |
||
87 | $title = elgg_echo('admin:server:requirements:gc'); |
||
88 | $subtext = elgg_echo('admin:server:requirements:gc:info'); |
||
89 | echo $view_module($icon_warning, $title, elgg_echo('status:disabled'), $subtext); |
||
90 | } |
||
91 | |||
92 | // db server information |
||
93 | $db = _elgg_services()->db; |
||
94 | $version = $db->getServerVersion(); |
||
95 | $min_version = $db->isMariaDB() ? \ElggInstaller::MARIADB_MINIMAL_VERSION : \ElggInstaller::MYSQL_MINIMAL_VERSION; |
||
96 | $server = $db->isMariaDB() ? 'mariadb' : $db->getConnection(DbConfig::READ_WRITE)->getDatabasePlatform()->getName(); |
||
0 ignored issues
–
show
|
|||
97 | $subtext = ''; |
||
98 | $icon = $icon_ok; |
||
99 | |||
100 | if (!in_array($server, ['mysql', 'mariadb']) || version_compare($version ?: '0', $min_version, '<')) { |
||
101 | $subtext = elgg_echo('admin:server:requirements:database:server:required_version', [$min_version]); |
||
102 | $icon = $icon_error; |
||
103 | } |
||
104 | |||
105 | echo $view_module($icon, elgg_echo('admin:server:requirements:database:server'), "{$server} v{$version}", $subtext); |
||
106 | |||
107 | // db client information |
||
108 | $client_parts = explode('\\', get_class($db->getConnection(DbConfig::READ_WRITE)->getDriver())); |
||
109 | $client_parts = array_slice($client_parts, 3); |
||
110 | $client = implode(' ', $client_parts); |
||
111 | |||
112 | $subtext = ''; |
||
113 | $icon = $icon_ok; |
||
114 | |||
115 | if ($client !== 'PDO MySQL Driver') { |
||
116 | $subtext = elgg_echo('admin:server:requirements:database:client:required'); |
||
117 | $icon = $icon_error; |
||
118 | } |
||
119 | |||
120 | echo $view_module($icon, elgg_echo('admin:server:requirements:database:client'), $client, $subtext); |
||
121 | |||
122 | // rewrite test |
||
123 | $url = elgg_http_add_url_query_elements(Request::REWRITE_TEST_TOKEN, [ |
||
124 | Request::REWRITE_TEST_TOKEN => 1, |
||
125 | ]); |
||
126 | $url = elgg_normalize_site_url($url); |
||
127 | |||
128 | $tester = new RewriteTester(); |
||
129 | |||
130 | $icon = $icon_ok; |
||
131 | $title = elgg_echo('admin:server:requirements:rewrite'); |
||
132 | $value = elgg_echo('ok'); |
||
133 | $subtext = ''; |
||
134 | |||
135 | if (!$tester->runRewriteTest($url)) { |
||
136 | $icon = $icon_error; |
||
137 | $value = elgg_echo('error'); |
||
138 | $subtext = elgg_echo('admin:server:requirements:rewrite:fail'); |
||
139 | } |
||
140 | |||
141 | echo $view_module($icon, $title, $value, $subtext); |
||
142 | |||
143 | $icon = _elgg_services()->imageService->hasWebPSupport() ? $icon_ok : $icon_error; |
||
144 | echo $view_module($icon, elgg_echo('admin:server:requirements:webp')); |
||
145 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.