requirements.php ➔ display_html_header()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 21 and the first side effect is on line 19.

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.

Loading history...
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
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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