1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* This script checks the server requirements for pH7CMS software. |
4
|
|
|
* |
5
|
|
|
* It was written in order to be standarlone and can be used in different projects. |
6
|
|
|
* If you want to use it in your project, please keep the license and the developer details below in order to have the right to distribute it. |
7
|
|
|
* |
8
|
|
|
* @package Install |
9
|
|
|
* @file requirements |
10
|
|
|
* @author Pierre-Henry Soria |
11
|
|
|
* @email <[email protected]> |
12
|
|
|
* @copyright (c) 2011-2019, Pierre-Henry Soria. All Rights Reserved. |
13
|
|
|
* @license Lesser General Public License (LGPL) (http://www.gnu.org/copyleft/lesser.html) |
14
|
|
|
* @language (PHP) and (HTML5 + CSS) |
15
|
|
|
* @since 2011/10/25 |
16
|
|
|
* @version Last revision: 2017/10/23 |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
defined('PH7') or exit('Restricted access'); |
20
|
|
|
|
21
|
|
|
define('EXTENSION_KEY', 'extension'); |
22
|
|
|
define('CLASS_KEY', 'class'); |
23
|
|
|
define('FUNCTION_KEY', 'function'); |
24
|
|
|
define('DIRECTIVE_KEY', 'directive'); |
25
|
|
|
|
26
|
|
|
$aErrors = array(); |
27
|
|
|
|
28
|
|
|
if (version_compare(PHP_VERSION, PH7_REQUIRED_SERVER_VERSION, '<')) { |
29
|
|
|
$aErrors[] = 'Your current PHP version is ' . PHP_VERSION . '. pH7CMS requires PHP ' . PH7_REQUIRED_SERVER_VERSION . ' or newer.<br /> Please ask your Web host to upgrade PHP to ' . PH7_REQUIRED_SERVER_VERSION . ' or newer.'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$aRequirementsNeeded = array( |
33
|
|
|
EXTENSION_KEY => array( |
34
|
|
|
'pdo_mysql' => 'PDO', |
35
|
|
|
'zip' => 'Zip', |
36
|
|
|
'zlib' => 'Zlib', |
37
|
|
|
'gd' => 'GD', |
38
|
|
|
'mbstring' => 'mbstring', |
39
|
|
|
'exif' => 'exif' |
40
|
|
|
), |
41
|
|
|
CLASS_KEY => array( |
42
|
|
|
'DOMDocument' => 'dom' |
43
|
|
|
), |
44
|
|
|
FUNCTION_KEY => array( |
45
|
|
|
'exif_imagetype' => 'exif', |
46
|
|
|
'curl_init' => 'cURL' |
47
|
|
|
), |
48
|
|
|
DIRECTIVE_KEY => array( |
49
|
|
|
'file_uploads', |
50
|
|
|
'allow_url_fopen' |
51
|
|
|
) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
foreach ($aRequirementsNeeded as $sType => $aRequirements) { |
55
|
|
|
if ($sType === EXTENSION_KEY) { |
56
|
|
|
foreach ($aRequirements as $sExtension => $sExtensionName) { |
57
|
|
|
if (!extension_loaded($sExtension)) { |
58
|
|
|
$aErrors[] = 'Please install "' . $sExtensionName . '" PHP extension.'; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if ($sType === CLASS_KEY) { |
64
|
|
|
foreach ($aRequirements as $sClass => $sClassName) { |
65
|
|
|
if (!class_exists($sClass)) { |
66
|
|
|
$aErrors[] = 'Please install "' . $sClassName . '" PHP extension.'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ($sType === FUNCTION_KEY) { |
72
|
|
|
foreach ($aRequirements as $sFunction => $sFunctionName) { |
73
|
|
|
if (!function_exists($sFunction)) { |
74
|
|
|
$aErrors[] = 'Please install "' . $sFunctionName . '" PHP extension.'; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($sType === DIRECTIVE_KEY) { |
80
|
|
|
foreach ($aRequirements as $sDirective) { |
81
|
|
|
// FILTER_VALIDATE_BOOLEAN filter returns TRUE for "1", "true", "on" and "yes", FALSE otherwise |
|
|
|
|
82
|
|
|
if (filter_var(ini_get($sDirective), FILTER_VALIDATE_BOOLEAN) === false) { |
83
|
|
|
$aErrors[] = $sDirective . ' PHP directive needs to be enabled.'; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$iErrors = !empty($aErrors) ? count($aErrors) : 0; |
90
|
|
|
if ($iErrors > 0) { |
91
|
|
|
display_html_header('Requirements - pH7CMS Installation'); |
92
|
|
|
|
93
|
|
|
printf('<h3 class="error underline italic">You have %d error(s):</h3>', $iErrors); |
94
|
|
|
|
95
|
|
|
for ($iKey = 0; $iKey < $iErrors; $iKey++) { |
96
|
|
|
printf('<p class="error">%d) %s</p>', $iKey + 1, $aErrors[$iKey]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
display_html_footer(); |
100
|
|
|
|
101
|
|
|
exit(1); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
function display_html_header($sPageTitle) |
106
|
|
|
{ |
107
|
|
|
echo '<!DOCTYPE html><html><head><meta charset="utf-8"><title>', $sPageTitle, '</title><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><style>body{background:#EFEFEF;color:#555;font:normal 10pt Arial,Helvetica,sans-serif;margin:0;padding:0}.center{margin-left:auto;margin-right:auto;text-align:center;width:80%}.error{color:red;font-size:13px}.success{color:green}.success,.error{font-weight:bold}.italic{font-style:italic}.underline{text-decoration:underline}</style></head><body><div class="center">'; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
function display_html_footer() |
111
|
|
|
{ |
112
|
|
|
echo '</div></body></html>'; |
113
|
|
|
} |
114
|
|
|
|
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.