|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PRADO Requirements Checker script |
|
4
|
|
|
* |
|
5
|
|
|
* @author Qiang Xue <[email protected]> |
|
6
|
|
|
* @link https://github.com/pradosoft/prado |
|
7
|
|
|
* @copyright Copyright © 2005-2016 The PRADO Group |
|
8
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9
|
|
|
* @package prado |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* PRADO Requirements Checker script |
|
14
|
|
|
* |
|
15
|
|
|
* This script will check if your system meets the requirements for running PRADO. |
|
16
|
|
|
* It will check if you are running the right version of PHP, if you included |
|
17
|
|
|
* the right libraries and if your php.ini file settings are correct. |
|
18
|
|
|
* |
|
19
|
|
|
* This script is capable of displaying localized messages. |
|
20
|
|
|
* All messages are stored in messages.txt. A localized message file is named as |
|
21
|
|
|
* messsages-<language code>.txt, and it will be used when the client browser |
|
22
|
|
|
* chooses the corresponding language. |
|
23
|
|
|
* The script output uses a template named template.html. |
|
24
|
|
|
* Its localized version is stored in template-<language code>.html. |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array List of requirements (required or not, check item, hint) |
|
29
|
|
|
*/ |
|
30
|
|
|
$requirements = array( |
|
31
|
|
|
array( |
|
32
|
|
|
true, |
|
33
|
|
|
version_compare(PHP_VERSION,"5.3.3",">="), |
|
34
|
|
|
'PHP version check','PHP 5.3.3 or higher required'), |
|
35
|
|
|
array( |
|
36
|
|
|
true, |
|
37
|
|
|
isset($_SERVER["HTTP_ACCEPT"]), |
|
38
|
|
|
'$_SERVER["HTTP_ACCEPT"] check', |
|
39
|
|
|
'HTTP_ACCEPT required'), |
|
40
|
|
|
array( |
|
41
|
|
|
true, |
|
42
|
|
|
isset($_SERVER["SCRIPT_FILENAME"]) && realpath($_SERVER["SCRIPT_FILENAME"])===realpath(__FILE__), |
|
43
|
|
|
'$_SERVER["SCRIPT_FILENAME"] check', |
|
44
|
|
|
'SCRIPT_FILENAME required'), |
|
45
|
|
|
array( |
|
46
|
|
|
true, |
|
47
|
|
|
isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["QUERY_STRING"]), |
|
48
|
|
|
'$_SERVER["REQUEST_URI"] check', |
|
49
|
|
|
'REQUEST_URI required'), |
|
50
|
|
|
array( |
|
51
|
|
|
true, |
|
52
|
|
|
isset($_SERVER["PATH_INFO"]) || strpos($_SERVER["PHP_SELF"],$_SERVER["SCRIPT_NAME"])===0, |
|
53
|
|
|
'$_SERVER["PATH_INFO"] check', |
|
54
|
|
|
'PATH_INFO required'), |
|
55
|
|
|
array( |
|
56
|
|
|
true, |
|
57
|
|
|
class_exists('Reflection',false), |
|
58
|
|
|
'Reflection extension check', |
|
59
|
|
|
'Reflection extension required'), |
|
60
|
|
|
array( |
|
61
|
|
|
true, |
|
62
|
|
|
class_exists("DOMDocument",false), |
|
63
|
|
|
'DOM extension check', |
|
64
|
|
|
'DOM extension required'), |
|
65
|
|
|
array( |
|
66
|
|
|
true, |
|
67
|
|
|
extension_loaded("SPL"), |
|
68
|
|
|
'SPL extension check', |
|
69
|
|
|
'SPL extension required'), |
|
70
|
|
|
array( |
|
71
|
|
|
true, |
|
72
|
|
|
extension_loaded("CType"), |
|
73
|
|
|
'CType extension check', |
|
74
|
|
|
'CType extension required'), |
|
75
|
|
|
array( |
|
76
|
|
|
true, |
|
77
|
|
|
extension_loaded("pcre"), |
|
78
|
|
|
'PCRE extension check', |
|
79
|
|
|
'PCRE extension required'), |
|
80
|
|
|
array( |
|
81
|
|
|
true, |
|
82
|
|
|
extension_loaded("json"), |
|
83
|
|
|
'JSON extension check', |
|
84
|
|
|
'JSON extension required'), |
|
85
|
|
|
array( |
|
86
|
|
|
false, |
|
87
|
|
|
class_exists("PDO",false), |
|
88
|
|
|
'PDO extension check', |
|
89
|
|
|
'PDO extension optional'), |
|
90
|
|
|
array( |
|
91
|
|
|
false, |
|
92
|
|
|
function_exists("iconv"), |
|
93
|
|
|
'ICONV extension check', |
|
94
|
|
|
'ICONV extension optional'), |
|
95
|
|
|
array( |
|
96
|
|
|
false, |
|
97
|
|
|
extension_loaded("zlib"), |
|
98
|
|
|
'Zlib extension check', |
|
99
|
|
|
'Zlib extension optional'), |
|
100
|
|
|
array( |
|
101
|
|
|
false, |
|
102
|
|
|
extension_loaded("sqlite"), |
|
103
|
|
|
'SQLite extension check', |
|
104
|
|
|
'SQLite extension optional deprecated'), |
|
105
|
|
|
array( |
|
106
|
|
|
false, |
|
107
|
|
|
extension_loaded("memcache"), |
|
108
|
|
|
'Memcache extension check', |
|
109
|
|
|
'Memcache extension optional'), |
|
110
|
|
|
array( |
|
111
|
|
|
false, |
|
112
|
|
|
extension_loaded("apc"), |
|
113
|
|
|
'APC extension check', |
|
114
|
|
|
'APC extension optional'), |
|
115
|
|
|
array( |
|
116
|
|
|
false, |
|
117
|
|
|
function_exists('eaccelerator_get'), |
|
118
|
|
|
'eAccelerator extension check', |
|
119
|
|
|
'eAccelerator extension optional'), |
|
120
|
|
|
array( |
|
121
|
|
|
false, |
|
122
|
|
|
function_exists('xcache_isset'), |
|
123
|
|
|
'XCache extension check', |
|
124
|
|
|
'XCache extension optional'), |
|
125
|
|
|
array( |
|
126
|
|
|
false, |
|
127
|
|
|
extension_loaded("mcrypt"), |
|
128
|
|
|
'Mcrypt extension check', |
|
129
|
|
|
'Mcrypt extension optional'), |
|
130
|
|
|
array( |
|
131
|
|
|
false, |
|
132
|
|
|
extension_loaded("mbstring"), |
|
133
|
|
|
'Mbstring extension check', |
|
134
|
|
|
'Mbstring extension optional'), |
|
135
|
|
|
array( |
|
136
|
|
|
false, |
|
137
|
|
|
extension_loaded("hash"), |
|
138
|
|
|
'Hash extension check', |
|
139
|
|
|
'Hash extension optional'), |
|
140
|
|
|
array( |
|
141
|
|
|
false, |
|
142
|
|
|
extension_loaded("xsl"), |
|
143
|
|
|
'XSL extension check', |
|
144
|
|
|
'XSL extension optional'), |
|
145
|
|
|
array( |
|
146
|
|
|
false, |
|
147
|
|
|
extension_loaded("soap"), |
|
148
|
|
|
'SOAP extension check', |
|
149
|
|
|
'SOAP extension optional'), |
|
150
|
|
|
); |
|
151
|
|
|
|
|
152
|
|
|
$results = "<table class=\"result\">\n"; |
|
153
|
|
|
$conclusion = 0; |
|
154
|
|
|
foreach($requirements as $requirement) |
|
155
|
|
|
{ |
|
156
|
|
|
list($required,$expression,$aspect,$hint)=$requirement; |
|
157
|
|
|
//eval('$ret='.$expression.';'); |
|
158
|
|
|
$ret=$expression; |
|
159
|
|
|
if($required) |
|
160
|
|
|
{ |
|
161
|
|
|
if($ret) |
|
162
|
|
|
$ret='passed'; |
|
163
|
|
|
else |
|
164
|
|
|
{ |
|
165
|
|
|
$conclusion=1; |
|
166
|
|
|
$ret='error'; |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
else |
|
170
|
|
|
{ |
|
171
|
|
|
if($ret) |
|
172
|
|
|
$ret='passed'; |
|
173
|
|
|
else |
|
174
|
|
|
{ |
|
175
|
|
|
if($conclusion!==1) |
|
176
|
|
|
$conclusion=2; |
|
177
|
|
|
$ret='warning'; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
$results.="<tr class=\"$ret\"><td class=\"$ret\">".lmessage($aspect)."</td><td class=\"$ret\">".lmessage($hint)."</td></tr>\n"; |
|
181
|
|
|
} |
|
182
|
|
|
$results .= '</table>'; |
|
183
|
|
|
if($conclusion===0) |
|
184
|
|
|
$conclusion=lmessage('all passed'); |
|
185
|
|
|
else if($conclusion===1) |
|
186
|
|
|
$conclusion=lmessage('failed'); |
|
187
|
|
|
else |
|
188
|
|
|
$conclusion=lmessage('passed with warnings'); |
|
189
|
|
|
|
|
190
|
|
|
$tokens = array( |
|
191
|
|
|
'%%Conclusion%%' => $conclusion, |
|
192
|
|
|
'%%Details%%' => $results, |
|
193
|
|
|
'%%Version%%' => $_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.getPradoVersion(), |
|
194
|
|
|
'%%Time%%' => @strftime('%Y-%m-%d %H:%m',time()), |
|
195
|
|
|
); |
|
196
|
|
|
|
|
197
|
|
|
$lang=getPreferredLanguage(); |
|
198
|
|
|
$templateFile=dirname(__FILE__)."/template-$lang.html"; |
|
199
|
|
|
if(!is_file($templateFile)) |
|
200
|
|
|
$templateFile=dirname(__FILE__).'/template.html'; |
|
201
|
|
|
if(($content=@file_get_contents($templateFile))===false) |
|
202
|
|
|
die("Unable to open template file '$templateFile'."); |
|
203
|
|
|
|
|
204
|
|
|
header('Content-Type: text/html; charset=UTF-8'); |
|
205
|
|
|
echo strtr($content,$tokens); |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Returns a localized message according to user preferred language. |
|
209
|
|
|
* @param string message to be translated |
|
210
|
|
|
* @return string translated message |
|
211
|
|
|
*/ |
|
212
|
|
|
function lmessage($token) |
|
213
|
|
|
{ |
|
214
|
|
|
static $messages=null; |
|
215
|
|
|
if($messages===null) |
|
216
|
|
|
{ |
|
217
|
|
|
$lang = getPreferredLanguage(); |
|
218
|
|
|
$msgFile=dirname(__FILE__)."/messages-$lang.txt"; |
|
219
|
|
|
if(!is_file($msgFile)) |
|
220
|
|
|
$msgFile=dirname(__FILE__).'/messages.txt'; |
|
221
|
|
|
if(($entries=@file($msgFile))!==false) |
|
222
|
|
|
{ |
|
223
|
|
|
foreach($entries as $entry) |
|
224
|
|
|
{ |
|
225
|
|
|
@list($code,$message)=explode('=',$entry,2); |
|
226
|
|
|
$messages[trim($code)]=trim($message); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
return isset($messages[$token])?$messages[$token]:$token; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Returns a list of user preferred languages. |
|
235
|
|
|
* The languages are returned as an array. Each array element |
|
236
|
|
|
* represents a single language preference. The languages are ordered |
|
237
|
|
|
* according to user preferences. The first language is the most preferred. |
|
238
|
|
|
* @return array list of user preferred languages. |
|
239
|
|
|
*/ |
|
240
|
|
|
function getUserLanguages() |
|
|
|
|
|
|
241
|
|
|
{ |
|
242
|
|
|
static $languages=null; |
|
243
|
|
|
if($languages===null) |
|
244
|
|
|
{ |
|
245
|
|
|
$languages=array(); |
|
246
|
|
|
foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language) |
|
247
|
|
|
{ |
|
248
|
|
|
$array=explode(';q=',trim($language)); |
|
249
|
|
|
$languages[trim($array[0])]=isset($array[1])?(float)$array[1]:1.0; |
|
250
|
|
|
} |
|
251
|
|
|
arsort($languages); |
|
252
|
|
|
$languages=array_keys($languages); |
|
253
|
|
|
if(empty($languages)) |
|
254
|
|
|
$languages[0]='en'; |
|
255
|
|
|
} |
|
256
|
|
|
return $languages; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Returns the most preferred language by the client user. |
|
261
|
|
|
* @return string the most preferred language by the client user, defaults to English. |
|
262
|
|
|
*/ |
|
263
|
|
|
function getPreferredLanguage() |
|
264
|
|
|
{ |
|
265
|
|
|
static $language=null; |
|
266
|
|
|
if($language===null) |
|
267
|
|
|
{ |
|
268
|
|
|
$langs=getUserLanguages(); |
|
269
|
|
|
$lang=explode('-',$langs[0]); |
|
270
|
|
|
if(empty($lang[0]) || !function_exists('ctype_alpha') || !ctype_alpha($lang[0])) |
|
271
|
|
|
$language='en'; |
|
272
|
|
|
else |
|
273
|
|
|
$language=$lang[0]; |
|
274
|
|
|
} |
|
275
|
|
|
return $language; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @return string Prado version |
|
280
|
|
|
*/ |
|
281
|
|
|
function getPradoVersion() |
|
282
|
|
|
{ |
|
283
|
|
|
$coreFile=dirname(__FILE__).'/../framework/PradoBase.php'; |
|
284
|
|
|
if(is_file($coreFile)) |
|
285
|
|
|
{ |
|
286
|
|
|
$contents=file_get_contents($coreFile); |
|
287
|
|
|
$matches=array(); |
|
288
|
|
|
if(preg_match('/public static function getVersion.*?return \'(.*?)\'/ms',$contents,$matches)>0) |
|
289
|
|
|
return $matches[1]; |
|
290
|
|
|
} |
|
291
|
|
|
return ''; |
|
292
|
|
|
} |
|
293
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: