This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 | * @title InstallController Class |
||
4 | * |
||
5 | * @author Pierre-Henry Soria <[email protected]> |
||
6 | * @copyright (c) 2012-2019, Pierre-Henry Soria. All Rights Reserved. |
||
7 | * @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
||
8 | * @package PH7 / Install / Controller |
||
9 | */ |
||
10 | |||
11 | namespace PH7; |
||
12 | |||
13 | defined('PH7') or exit('Restricted access'); |
||
14 | |||
15 | // Reset the time limit |
||
16 | @set_time_limit(0); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
17 | |||
18 | class InstallController extends Controller |
||
19 | { |
||
20 | const TOTAL_MEMBERS_SAMPLE = 16; |
||
21 | const TOTAL_AFFILIATES_SAMPLE = 1; |
||
22 | const TOTAL_SUBSCRIBERS_SAMPLE = 1; |
||
23 | |||
24 | /** |
||
25 | * Enable/Disable Modules according to the chosen niche |
||
26 | */ |
||
27 | const SOCIAL_MODS = [ |
||
28 | 'connect' => '0', |
||
29 | 'affiliate' => '0', |
||
30 | 'game' => '1', |
||
31 | 'chat' => '0', |
||
32 | 'chatroulette' => '0', |
||
33 | 'picture' => '1', |
||
34 | 'video' => '1', |
||
35 | 'friend' => '1', |
||
36 | 'hotornot' => '0', |
||
37 | 'forum' => '1', |
||
38 | 'note' => '1', |
||
39 | 'blog' => '1', |
||
40 | 'newsletter' => '0', |
||
41 | 'invite' => '1', |
||
42 | 'webcam' => '1', |
||
43 | 'love-calculator' => '0', |
||
44 | 'mail' => '1', |
||
45 | 'im' => '0', |
||
46 | 'user-dashboard' => '0', |
||
47 | 'cool-profile-page' => '0', |
||
48 | 'related-profile' => '1', |
||
49 | 'birthday' => '1', |
||
50 | 'map' => '1', |
||
51 | 'pwa' => '0', |
||
52 | 'sms-verification' => '0' |
||
53 | ]; |
||
54 | |||
55 | const DATING_MODS = [ |
||
56 | 'connect' => '0', |
||
57 | 'affiliate' => '1', |
||
58 | 'game' => '0', |
||
59 | 'chat' => '1', |
||
60 | 'chatroulette' => '1', |
||
61 | 'picture' => '1', |
||
62 | 'video' => '0', |
||
63 | 'friend' => '0', |
||
64 | 'hotornot' => '1', |
||
65 | 'forum' => '0', |
||
66 | 'note' => '0', |
||
67 | 'blog' => '1', |
||
68 | 'newsletter' => '1', |
||
69 | 'invite' => '0', |
||
70 | 'webcam' => '0', |
||
71 | 'love-calculator' => '1', |
||
72 | 'mail' => '1', |
||
73 | 'im' => '1', |
||
74 | 'user-dashboard' => '1', |
||
75 | 'cool-profile-page' => '1', |
||
76 | 'related-profile' => '1', |
||
77 | 'birthday' => '0', |
||
78 | 'map' => '1', |
||
79 | 'pwa' => '0', |
||
80 | 'sms-verification' => '0' |
||
81 | ]; |
||
82 | |||
83 | /** |
||
84 | * Enable/Disable Site Settings according to the chosen niche |
||
85 | */ |
||
86 | const SOCIAL_SETTINGS = [ |
||
87 | 'socialMediaWidgets' => '1', |
||
88 | 'requireRegistrationAvatar' => '0', |
||
89 | 'isUserAgeRangeField' => '0' |
||
90 | ]; |
||
91 | |||
92 | const DATING_SETTINGS = [ |
||
93 | 'socialMediaWidgets' => '0', |
||
94 | 'requireRegistrationAvatar' => '1', |
||
95 | 'isUserAgeRangeField' => '1' |
||
96 | ]; |
||
97 | |||
98 | |||
99 | /********************* STEP 1 *********************/ |
||
100 | public function index() |
||
101 | { |
||
102 | $aLangs = get_dir_list(PH7_ROOT_INSTALL . Language::LANG_FOLDER_NAME); |
||
103 | $aLangsList = include PH7_ROOT_INSTALL . 'inc/lang_list.inc.php'; |
||
104 | $sLangSelect = ''; |
||
105 | |||
106 | foreach ($aLangs as $sLang) { |
||
107 | $sSel = (empty($_REQUEST['l']) ? $sLang === $this->sCurrentLang ? '" selected="selected' : '' : ($sLang === $_REQUEST['l']) ? '" selected="selected' : ''); |
||
108 | $sLangSelect .= '<option value="?l=' . $sLang . $sSel . '">' . $aLangsList[$sLang] . '</option>'; |
||
109 | } |
||
110 | |||
111 | $this->oView->assign('lang_select', $sLangSelect); |
||
112 | $this->oView->assign('sept_number', 1); |
||
113 | $this->oView->display('index.tpl'); |
||
114 | } |
||
115 | |||
116 | /********************* STEP 2 *********************/ |
||
117 | public function license() |
||
118 | { |
||
119 | if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['license_agreements_submit'])) { |
||
120 | if ($this->isAgreementsAgreed()) { |
||
121 | $_SESSION['step2'] = 1; |
||
122 | |||
123 | redirect(PH7_URL_SLUG_INSTALL . 'config_path'); |
||
124 | } else { |
||
125 | $this->oView->assign('failure', 1); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | $this->oView->assign('sept_number', 2); |
||
130 | $this->oView->display('license.tpl'); |
||
131 | } |
||
132 | |||
133 | /********************* STEP 3 *********************/ |
||
134 | public function config_path() |
||
135 | { |
||
136 | global $LANG; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
137 | |||
138 | if (!empty($_SESSION['step2'])) { |
||
139 | if (empty($_SESSION['val']['path_protected'])) { |
||
140 | // If not set, set a default value for the field used in Smarty tpl |
||
141 | $_SESSION['val']['path_protected'] = PH7_ROOT_PUBLIC . '_protected' . PH7_DS; |
||
142 | } |
||
143 | |||
144 | if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['path_protected'])) { |
||
145 | $_SESSION['val']['path_protected'] = check_ext_start(check_ext_end(trim($_POST['path_protected']))); |
||
146 | |||
147 | if (is_file($_SESSION['val']['path_protected'] . 'app/configs/constants.php')) { |
||
148 | if (is_readable($_SESSION['val']['path_protected'])) { |
||
149 | $sConstantContent = file_get_contents(PH7_ROOT_INSTALL . 'data/configs/constants.php'); |
||
150 | |||
151 | $sConstantContent = str_replace('%path_protected%', addslashes($_SESSION['val']['path_protected']), $sConstantContent); |
||
152 | |||
153 | if (!@file_put_contents(PH7_ROOT_PUBLIC . '_constants.php', $sConstantContent)) { |
||
154 | $aErrors[] = $LANG['no_public_writable']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
155 | } else { |
||
156 | $_SESSION['step3'] = 1; |
||
157 | unset($_SESSION['val']); |
||
158 | |||
159 | redirect(PH7_URL_SLUG_INSTALL . 'config_system'); |
||
160 | } |
||
161 | } else { |
||
162 | $aErrors[] = $LANG['no_protected_readable']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
163 | } |
||
164 | } else { |
||
165 | $aErrors[] = $LANG['no_protected_exist']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
166 | } |
||
167 | } |
||
168 | } else { |
||
169 | redirect(PH7_URL_SLUG_INSTALL . 'license'); |
||
170 | } |
||
171 | |||
172 | $this->oView->assign('sept_number', 3); |
||
173 | $this->oView->assign('errors', @$aErrors); |
||
0 ignored issues
–
show
The variable
$aErrors does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
174 | unset($aErrors); |
||
175 | $this->oView->display('config_path.tpl'); |
||
176 | } |
||
177 | |||
178 | /********************* STEP 4 *********************/ |
||
179 | public function config_system() |
||
180 | { |
||
181 | global $LANG; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
182 | |||
183 | if (!empty($_SESSION['step3']) && is_file(PH7_ROOT_PUBLIC . '_constants.php')) { |
||
184 | session_regenerate_id(true); |
||
185 | |||
186 | if (empty($_SESSION['val'])) { |
||
187 | $_SESSION['db']['type_name'] = Db::DBMS_MYSQL_NAME; |
||
188 | $_SESSION['db']['type'] = Db::DSN_MYSQL_PREFIX; |
||
189 | |||
190 | $_SESSION['db']['hostname'] = DbDefaultConfig::HOSTNAME; |
||
191 | $_SESSION['db']['username'] = DbDefaultConfig::USERNAME; |
||
192 | $_SESSION['db']['name'] = DbDefaultConfig::NAME; |
||
193 | $_SESSION['db']['prefix'] = DbDefaultConfig::PREFIX; |
||
194 | $_SESSION['db']['port'] = DbDefaultConfig::PORT; |
||
195 | $_SESSION['db']['charset'] = DbDefaultConfig::CHARSET; |
||
196 | |||
197 | $_SESSION['val']['bug_report_email'] = ''; |
||
198 | $_SESSION['val']['ffmpeg_path'] = ffmpeg_path(); |
||
199 | } |
||
200 | |||
201 | if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['config_system_submit'])) { |
||
202 | if (filled_out($_POST)) { |
||
203 | foreach ($_POST as $sKey => $sVal) { |
||
204 | $_SESSION['db'][str_replace('db_', '', $sKey)] = trim($sVal); |
||
205 | } |
||
206 | |||
207 | $_SESSION['val']['bug_report_email'] = trim($_POST['bug_report_email']); |
||
208 | $_SESSION['val']['ffmpeg_path'] = trim($_POST['ffmpeg_path']); |
||
209 | |||
210 | if (validate_email($_SESSION['val']['bug_report_email'])) { |
||
211 | try { |
||
212 | require_once PH7_ROOT_INSTALL . 'inc/_db_connect.inc.php'; |
||
213 | @require_once PH7_ROOT_PUBLIC . '_constants.php'; |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
214 | @require_once PH7_PATH_APP . 'configs/constants.php'; |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
215 | |||
216 | // Config File |
||
217 | @chmod(PH7_PATH_APP_CONFIG, 0777); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
218 | $sConfigContent = file_get_contents(PH7_ROOT_INSTALL . 'data/configs/config.ini'); |
||
219 | |||
220 | $sConfigContent = str_replace('%bug_report_email%', $_SESSION['val']['bug_report_email'], $sConfigContent); |
||
221 | $sConfigContent = str_replace('%ffmpeg_path%', clean_string($_SESSION['val']['ffmpeg_path']), $sConfigContent); |
||
222 | |||
223 | $sConfigContent = str_replace('%db_type_name%', $_SESSION['db']['type_name'], $sConfigContent); |
||
224 | $sConfigContent = str_replace('%db_type%', $_SESSION['db']['type'], $sConfigContent); |
||
225 | $sConfigContent = str_replace('%db_hostname%', $_SESSION['db']['hostname'], $sConfigContent); |
||
226 | $sConfigContent = str_replace('%db_username%', clean_string($_SESSION['db']['username']), $sConfigContent); |
||
227 | $sConfigContent = str_replace('%db_password%', clean_string($_SESSION['db']['password']), $sConfigContent); |
||
228 | $sConfigContent = str_replace('%db_name%', clean_string($_SESSION['db']['name']), $sConfigContent); |
||
229 | $sConfigContent = str_replace('%db_prefix%', clean_string($_SESSION['db']['prefix']), $sConfigContent); |
||
230 | $sConfigContent = str_replace('%db_charset%', $_SESSION['db']['charset'], $sConfigContent); |
||
231 | $sConfigContent = str_replace('%db_port%', $_SESSION['db']['port'], $sConfigContent); |
||
232 | |||
233 | $sConfigContent = str_replace('%private_key%', generate_hash(40), $sConfigContent); |
||
234 | $sConfigContent = str_replace('%rand_id%', generate_hash(5), $sConfigContent); |
||
235 | |||
236 | if (!@file_put_contents(PH7_PATH_APP_CONFIG . 'config.ini', $sConfigContent)) { |
||
237 | $aErrors[] = $LANG['no_app_config_writable']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
238 | } else { |
||
239 | if (!( |
||
240 | $DB->getAttribute(\PDO::ATTR_DRIVER_NAME) === Db::DSN_MYSQL_PREFIX && |
||
241 | version_compare($DB->getAttribute(\PDO::ATTR_SERVER_VERSION), PH7_REQUIRED_SQL_VERSION, '>=')) |
||
242 | ) { |
||
243 | $aErrors[] = $LANG['require_mysql_version']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
244 | } else { |
||
245 | ignore_user_abort(true); |
||
246 | |||
247 | $aDumps = [ |
||
248 | /** Game **/ |
||
249 | // We need to install the Game before the "Core SQL" for foreign key reasons |
||
250 | 'pH7_SchemaGame', |
||
251 | 'pH7_DataGame', |
||
252 | /** Core (main SQL schema/data) **/ |
||
253 | 'pH7_Core' |
||
254 | ]; |
||
255 | |||
256 | for ($iFileKey = 0, $iCount = count($aDumps); $iFileKey < $iCount; $iFileKey++) { |
||
257 | exec_query_file( |
||
258 | $DB, |
||
0 ignored issues
–
show
|
|||
259 | PH7_ROOT_INSTALL . 'data/sql/' . $_SESSION['db']['type_name'] . '/' . $aDumps[$iFileKey] . '.sql' |
||
260 | ); |
||
261 | } |
||
262 | |||
263 | // We finalise it by setting the correct permission to the config files |
||
264 | $this->chmodConfigFiles(); |
||
265 | |||
266 | $_SESSION['step4'] = 1; |
||
267 | unset($_SESSION['val']); |
||
268 | |||
269 | redirect(PH7_URL_SLUG_INSTALL . 'config_site'); |
||
270 | } |
||
271 | } |
||
272 | } catch (\PDOException $oE) { |
||
273 | $aErrors[] = $LANG['database_error'] . escape($oE->getMessage()); |
||
0 ignored issues
–
show
The variable
$aErrors does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
274 | } |
||
275 | } else { |
||
276 | $aErrors[] = $LANG['bad_email']; |
||
277 | } |
||
278 | } else { |
||
279 | $aErrors[] = $LANG['all_fields_mandatory']; |
||
280 | } |
||
281 | } |
||
282 | } else { |
||
283 | redirect(PH7_URL_SLUG_INSTALL . 'config_path'); |
||
284 | } |
||
285 | |||
286 | // Assign the sample DB config values to the template |
||
287 | $this->oView->assign('def_db_hostname', DbDefaultConfig::HOSTNAME); |
||
288 | $this->oView->assign('def_db_username', DbDefaultConfig::USERNAME); |
||
289 | $this->oView->assign('def_db_name', DbDefaultConfig::NAME); |
||
290 | $this->oView->assign('def_db_prefix', DbDefaultConfig::PREFIX); |
||
291 | $this->oView->assign('def_db_port', DbDefaultConfig::PORT); |
||
292 | $this->oView->assign('def_db_charset', DbDefaultConfig::CHARSET); |
||
293 | |||
294 | $this->oView->assign('sept_number', 4); |
||
295 | $this->oView->assign('errors', @$aErrors); |
||
296 | unset($aErrors); |
||
297 | |||
298 | $this->oView->display('config_system.tpl'); |
||
299 | } |
||
300 | |||
301 | /********************* STEP 5 *********************/ |
||
302 | public function config_site() |
||
303 | { |
||
304 | global $LANG; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
305 | |||
306 | if (empty($_SESSION['step5'])) { |
||
307 | if (!empty($_SESSION['step4']) && is_file(PH7_ROOT_PUBLIC . '_constants.php')) { |
||
308 | session_regenerate_id(true); |
||
309 | |||
310 | if (empty($_SESSION['val'])) { |
||
311 | $_SESSION['val']['site_name'] = self::DEFAULT_SITE_NAME; |
||
312 | $_SESSION['val']['admin_login_email'] = ''; |
||
313 | $_SESSION['val']['admin_email'] = ''; |
||
314 | $_SESSION['val']['admin_feedback_email'] = ''; |
||
315 | $_SESSION['val']['admin_return_email'] = ''; |
||
316 | $_SESSION['val']['admin_username'] = self::DEFAULT_ADMIN_USERNAME; |
||
317 | $_SESSION['val']['admin_first_name'] = ''; |
||
318 | $_SESSION['val']['admin_last_name'] = ''; |
||
319 | } |
||
320 | |||
321 | if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['config_site_submit'])) { |
||
322 | if (filled_out($_POST)) { |
||
323 | foreach ($_POST as $sKey => $sVal) { |
||
324 | $_SESSION['val'][$sKey] = trim($sVal); |
||
325 | } |
||
326 | |||
327 | if (validate_email($_SESSION['val']['admin_login_email']) && validate_email($_SESSION['val']['admin_email']) && validate_email($_SESSION['val']['admin_feedback_email']) && validate_email($_SESSION['val']['admin_return_email'])) { |
||
328 | if (validate_username($_SESSION['val']['admin_username']) === 0) { |
||
329 | if (validate_password($_SESSION['val']['admin_password']) === 0) { |
||
330 | if (validate_identical($_SESSION['val']['admin_password'], $_SESSION['val']['admin_passwords'])) { |
||
331 | if (!find($_SESSION['val']['admin_password'], $_SESSION['val']['admin_username']) && !find($_SESSION['val']['admin_password'], $_SESSION['val']['admin_first_name']) && !find($_SESSION['val']['admin_password'], $_SESSION['val']['admin_last_name'])) { |
||
332 | if (validate_name($_SESSION['val']['admin_first_name'])) { |
||
333 | if (validate_name($_SESSION['val']['admin_last_name'])) { |
||
334 | $this->initializeClasses(); |
||
335 | |||
336 | try { |
||
337 | ignore_user_abort(true); |
||
338 | require_once PH7_ROOT_INSTALL . 'inc/_db_connect.inc.php'; |
||
339 | |||
340 | $rStmt = $DB->prepare( |
||
0 ignored issues
–
show
|
|||
341 | sprintf(SqlQuery::ADD_ADMIN, $_SESSION['db']['prefix'] . DbTableName::ADMIN) |
||
342 | ); |
||
343 | |||
344 | $sCurrentDate = date('Y-m-d H:i:s'); |
||
345 | $rStmt->execute([ |
||
346 | 'username' => $_SESSION['val']['admin_username'], |
||
347 | 'password' => Framework\Security\Security::hashPwd($_SESSION['val']['admin_password']), |
||
348 | 'email' => $_SESSION['val']['admin_login_email'], |
||
349 | 'firstName' => $_SESSION['val']['admin_first_name'], |
||
350 | 'lastName' => $_SESSION['val']['admin_last_name'], |
||
351 | 'joinDate' => $sCurrentDate, |
||
352 | 'lastActivity' => $sCurrentDate, |
||
353 | 'ip' => client_ip() |
||
354 | ]); |
||
355 | |||
356 | $rStmt = $DB->prepare( |
||
357 | sprintf(SqlQuery::UPDATE_SITE_NAME, $_SESSION['db']['prefix'] . DbTableName::SETTING) |
||
358 | ); |
||
359 | $rStmt->execute(['siteName' => $_SESSION['val']['site_name']]); |
||
360 | |||
361 | $rStmt = $DB->prepare( |
||
362 | sprintf(SqlQuery::UPDATE_ADMIN_EMAIL, $_SESSION['db']['prefix'] . DbTableName::SETTING) |
||
363 | ); |
||
364 | $rStmt->execute(['adminEmail' => $_SESSION['val']['admin_email']]); |
||
365 | |||
366 | $rStmt = $DB->prepare( |
||
367 | sprintf(SqlQuery::UPDATE_FEEDBACK_EMAIL, $_SESSION['db']['prefix'] . DbTableName::SETTING) |
||
368 | ); |
||
369 | $rStmt->execute(['feedbackEmail' => $_SESSION['val']['admin_feedback_email']]); |
||
370 | |||
371 | $rStmt = $DB->prepare( |
||
372 | sprintf(SqlQuery::UPDATE_RETURN_EMAIL, $_SESSION['db']['prefix'] . DbTableName::SETTING) |
||
373 | ); |
||
374 | $rStmt->execute(['returnEmail' => $_SESSION['val']['admin_return_email']]); |
||
375 | |||
376 | if (!empty($_POST['sample_data_request'])) { |
||
377 | $this->populateSampleUserData( |
||
378 | self::TOTAL_MEMBERS_SAMPLE, |
||
379 | self::TOTAL_AFFILIATES_SAMPLE, |
||
380 | self::TOTAL_SUBSCRIBERS_SAMPLE |
||
381 | ); |
||
382 | } |
||
383 | |||
384 | $_SESSION['step5'] = 1; |
||
385 | |||
386 | redirect(PH7_URL_SLUG_INSTALL . 'niche'); |
||
387 | } catch (\PDOException $oE) { |
||
388 | $aErrors[] = $LANG['database_error'] . escape($oE->getMessage()); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
389 | } |
||
390 | } else { |
||
391 | $aErrors[] = $LANG['bad_last_name']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
392 | } |
||
393 | } else { |
||
394 | $aErrors[] = $LANG['bad_first_name']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
395 | } |
||
396 | } else { |
||
397 | $aErrors[] = $LANG['insecure_password']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
398 | } |
||
399 | } else { |
||
400 | $aErrors[] = $LANG['passwords_different']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
401 | } |
||
402 | } elseif (validate_password($_SESSION['val']['admin_password']) === 1) { |
||
403 | $aErrors[] = $LANG['password_too_short']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
404 | } elseif (validate_password($_SESSION['val']['admin_password']) === 2) { |
||
405 | $aErrors[] = $LANG['password_too_long']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
406 | } elseif (validate_password($_SESSION['val']['admin_password']) === 3) { |
||
407 | $aErrors[] = $LANG['password_no_number']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
408 | } elseif (validate_password($_SESSION['val']['admin_password']) === 4) { |
||
409 | $aErrors[] = $LANG['password_no_upper']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
410 | } |
||
411 | } elseif (validate_username($_SESSION['val']['admin_username']) === 1) { |
||
412 | $aErrors[] = $LANG['username_too_short']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
413 | } elseif (validate_username($_SESSION['val']['admin_username']) === 2) { |
||
414 | $aErrors[] = $LANG['username_too_long']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
415 | } elseif (validate_username($_SESSION['val']['admin_username']) === 3) { |
||
416 | $aErrors[] = $LANG['bad_username']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
417 | } |
||
418 | } else { |
||
419 | $aErrors[] = $LANG['bad_email']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
420 | } |
||
421 | } else { |
||
422 | $aErrors[] = $LANG['all_fields_mandatory']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
423 | } |
||
424 | } |
||
425 | } else { |
||
426 | redirect(PH7_URL_SLUG_INSTALL . 'config_system'); |
||
427 | } |
||
428 | } else { |
||
429 | redirect(PH7_URL_SLUG_INSTALL . 'niche'); |
||
430 | } |
||
431 | |||
432 | |||
433 | $this->oView->assign('def_site_name', self::DEFAULT_SITE_NAME); |
||
434 | $this->oView->assign('def_admin_username', self::DEFAULT_ADMIN_USERNAME); |
||
435 | $this->oView->assign('sept_number', 5); |
||
436 | $this->oView->assign('errors', @$aErrors); |
||
0 ignored issues
–
show
The variable
$aErrors does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
437 | unset($aErrors); |
||
438 | $this->oView->display('config_site.tpl'); |
||
439 | } |
||
440 | |||
441 | /********************* STEP 6 *********************/ |
||
442 | public function niche() |
||
443 | { |
||
444 | global $LANG; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
445 | |||
446 | if (empty($_SESSION['step6'])) { |
||
447 | if (!empty($_SESSION['step5']) && is_file(PH7_ROOT_PUBLIC . '_constants.php')) { |
||
448 | session_regenerate_id(true); |
||
449 | |||
450 | if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['niche_submit'])) { |
||
451 | $bUpdateNeeded = false; // Value by default. Don't need to update the DB for the Social-Dating Niche |
||
452 | |||
453 | switch ($_POST['niche_submit']) { |
||
454 | case 'zendate': |
||
455 | $bUpdateNeeded = true; |
||
456 | $sTheme = 'zendate'; |
||
457 | $aModUpdate = self::SOCIAL_MODS; |
||
458 | $aSettingUpdate = self::SOCIAL_SETTINGS; |
||
459 | break; |
||
460 | |||
461 | case 'datelove': |
||
462 | $bUpdateNeeded = true; |
||
463 | $sTheme = 'datelove'; |
||
464 | $aModUpdate = self::DATING_MODS; |
||
465 | $aSettingUpdate = self::DATING_SETTINGS; |
||
466 | break; |
||
467 | |||
468 | // For 'base' niche (template), don't do anything. Just use the default settings already setup in the database |
||
469 | } |
||
470 | |||
471 | if ($bUpdateNeeded) { |
||
472 | $this->initializeClasses(); |
||
473 | |||
474 | try { |
||
475 | require_once PH7_ROOT_INSTALL . 'inc/_db_connect.inc.php'; |
||
476 | |||
477 | // Enable/Disable the modules according to the chosen niche |
||
478 | foreach ($aModUpdate as $sModName => $sStatus) { |
||
0 ignored issues
–
show
The variable
$aModUpdate does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
479 | $this->updateMods($DB, $sModName, $sStatus); |
||
0 ignored issues
–
show
|
|||
480 | } |
||
481 | |||
482 | $this->updateSettings($aSettingUpdate); |
||
0 ignored issues
–
show
The variable
$aSettingUpdate does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
483 | |||
484 | $this->updateTheme($DB, $sTheme); |
||
0 ignored issues
–
show
The variable
$sTheme does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
485 | } catch (\PDOException $oE) { |
||
486 | $aErrors[] = $LANG['database_error'] . escape($oE->getMessage()); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$aErrors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aErrors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
487 | } |
||
488 | } |
||
489 | $_SESSION['step6'] = 1; |
||
490 | |||
491 | redirect(PH7_URL_SLUG_INSTALL . 'finish'); |
||
492 | } |
||
493 | } else { |
||
494 | redirect(PH7_URL_SLUG_INSTALL . 'config_site'); |
||
495 | } |
||
496 | } else { |
||
497 | redirect(PH7_URL_SLUG_INSTALL . 'finish'); |
||
498 | } |
||
499 | |||
500 | $this->oView->assign('sept_number', 6); |
||
501 | $this->oView->assign('errors', @$aErrors); |
||
0 ignored issues
–
show
The variable
$aErrors does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
502 | unset($aErrors); |
||
503 | $this->oView->display('niche.tpl'); |
||
504 | } |
||
505 | |||
506 | /********************* STEP 7 *********************/ |
||
507 | public function finish() |
||
508 | { |
||
509 | $sConstantsPath = PH7_ROOT_PUBLIC . '_constants.php'; |
||
510 | if (is_file($sConstantsPath)) { |
||
511 | @require_once $sConstantsPath; |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
512 | |||
513 | if ($this->canEmailBeSent()) { |
||
514 | $this->sendWelcomeEmail(); |
||
515 | |||
516 | $this->oView->assign('admin_login_email', $_SESSION['val']['admin_login_email']); |
||
517 | $this->oView->assign('admin_username', $_SESSION['val']['admin_username']); |
||
518 | } |
||
519 | |||
520 | $this->removeSessions(); |
||
521 | $this->removeCookies(); |
||
522 | |||
523 | if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['confirm_remove_install'])) { |
||
524 | remove_install_dir(); |
||
525 | clearstatcache(); // We remove the files status cache as the "_install" folder doesn't exist anymore by now. |
||
526 | exit(header('Location: ' . PH7_URL_ROOT)); |
||
527 | } |
||
528 | |||
529 | $this->oView->assign('sept_number', 7); |
||
530 | $this->oView->display('finish.tpl'); |
||
531 | } else { |
||
532 | redirect(PH7_URL_SLUG_INSTALL . 'config_path'); |
||
533 | } |
||
534 | } |
||
535 | |||
536 | /** |
||
537 | * Send an email to say the installation is now done, and give some information... |
||
538 | */ |
||
539 | private function sendWelcomeEmail() |
||
540 | { |
||
541 | global $LANG; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
542 | |||
543 | $aParams = [ |
||
544 | 'to' => $_SESSION['val']['admin_login_email'], |
||
545 | 'subject' => $LANG['title_email_finish_install'], |
||
546 | 'body' => $LANG['content_email_finish_install'] |
||
547 | ]; |
||
548 | |||
549 | send_mail($aParams); |
||
550 | } |
||
551 | |||
552 | /** |
||
553 | * Verify if the email can be sent (has all necessary global variables). |
||
554 | * |
||
555 | * @return bool |
||
556 | */ |
||
557 | private function canEmailBeSent() |
||
558 | { |
||
559 | return !empty($_SESSION['val']['admin_login_email']) && |
||
560 | !empty($_SESSION['val']['admin_username']); |
||
561 | } |
||
562 | |||
563 | /** |
||
564 | * Update module status (enabled/disabled). |
||
565 | * |
||
566 | * @param Db $oDb |
||
567 | * @param string $sModName Module Name. |
||
568 | * @param string $sStatus '1' = Enabled | '0' = Disabled (need to be string because in DB it is an "enum"). |
||
569 | * |
||
570 | * @return int|bool Returns the number of rows on success or FALSE on failure. |
||
571 | */ |
||
572 | private function updateMods(Db $oDb, $sModName, $sStatus) |
||
573 | { |
||
574 | $rStmt = $oDb->prepare( |
||
575 | sprintf(SqlQuery::UPDATE_SYS_MODULE, $_SESSION['db']['prefix'] . DbTableName::SYS_MOD_ENABLED) |
||
576 | ); |
||
577 | |||
578 | return $rStmt->execute(['modName' => $sModName, 'status' => $sStatus]); |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * Set the adequate website's theme for the chosen niche. |
||
583 | * |
||
584 | * @param Db $oDb |
||
585 | * @param string $sThemeName |
||
586 | * |
||
587 | * @return int|bool Returns the number of rows on success or FALSE on failure. |
||
588 | */ |
||
589 | private function updateTheme(Db $oDb, $sThemeName) |
||
590 | { |
||
591 | $rStmt = $oDb->prepare( |
||
592 | sprintf(SqlQuery::UPDATE_THEME, $_SESSION['db']['prefix'] . DbTableName::SETTING) |
||
593 | ); |
||
594 | |||
595 | return $rStmt->execute(['theme' => $sThemeName, 'setting' => 'defaultTemplate']); |
||
596 | } |
||
597 | |||
598 | /** |
||
599 | * @param array $aParams |
||
600 | * |
||
601 | * @return void |
||
602 | */ |
||
603 | private function updateSettings(array $aParams) |
||
604 | { |
||
605 | // Initialize the site's database to get "\PH7\Framework\Mvc\Model\Engine\Db" class working (as it uses that DB and not the installer one) |
||
606 | Framework\Mvc\Router\FrontController::getInstance()->_initializeDatabase(); |
||
607 | |||
608 | foreach ($aParams as $sName => $sValue) { |
||
609 | $sMethodName = ($sName === 'socialMediaWidgets' ? 'setSocialWidgets' : 'setSetting'); |
||
610 | Framework\Mvc\Model\DbConfig::$sMethodName($sValue, $sName); |
||
611 | } |
||
612 | } |
||
613 | |||
614 | /** |
||
615 | * Populates some sample user profiles with Faker library. |
||
616 | * |
||
617 | * @param int $iMemberNumber The number of members to generate. |
||
618 | * @param int $iAffiliateNumber The number of affiliates to generate (usually less than members). |
||
619 | * @param int $iSubscriberNumber The number of subscribers to generate (for newsletter module). |
||
620 | * |
||
621 | * @return void |
||
622 | * |
||
623 | * @throws Framework\Translate\Exception |
||
624 | */ |
||
625 | private function populateSampleUserData($iMemberNumber, $iAffiliateNumber, $iSubscriberNumber) |
||
626 | { |
||
627 | (new Framework\Translate\Lang) |
||
628 | ->setDefaultLang('en_US') |
||
629 | ->init(); |
||
630 | |||
631 | // Initialize the site's database for "UserCoreModel" and "AffiliateCoreModel" classes |
||
632 | Framework\Mvc\Router\FrontController::getInstance()->_initializeDatabase(); |
||
633 | |||
634 | $oUserModel = new UserCoreModel; |
||
635 | $oAffModel = new AffiliateCoreModel; |
||
636 | $oSubscriberModel = new SubscriberCoreModel; |
||
637 | $oFaker = \Faker\Factory::create(); |
||
638 | |||
639 | for ($iProfile = 1; $iProfile <= $iMemberNumber; $iProfile++) { |
||
640 | $sSex = $oFaker->randomElement(['male', 'female']); |
||
641 | $sMatchSex = $oFaker->randomElement(['male', 'female', 'couple']); |
||
642 | $sBirthDate = $oFaker->dateTimeBetween('-60 years', '-18 years')->format('Y-m-d'); |
||
643 | |||
644 | $aUser = []; |
||
645 | $aUser['username'] = $oFaker->userName; |
||
646 | $aUser['email'] = $oFaker->email; |
||
647 | $aUser['first_name'] = $oFaker->firstName; |
||
648 | $aUser['last_name'] = $oFaker->lastName; |
||
649 | $aUser['password'] = $oFaker->password; |
||
650 | $aUser['sex'] = $sSex; |
||
651 | $aUser['match_sex'] = [$sMatchSex]; |
||
652 | $aUser['country'] = $oFaker->countryCode; |
||
653 | $aUser['city'] = $oFaker->city; |
||
654 | $aUser['address'] = $oFaker->streetAddress; |
||
655 | $aUser['zip_code'] = $oFaker->postcode; |
||
656 | $aUser['birth_date'] = $sBirthDate; |
||
657 | $aUser['description'] = $oFaker->paragraph(2); |
||
658 | $aUser['lang'] = $oFaker->locale; |
||
659 | $aUser['ip'] = $oFaker->ipv4; |
||
660 | |||
661 | $oUserModel->add($aUser); |
||
662 | |||
663 | if ($iProfile <= $iAffiliateNumber) { |
||
664 | // Specific data only for affiliates |
||
665 | $aUser['website'] = 'http://pierrehenry.be'; |
||
666 | $aUser['phone'] = $oFaker->phoneNumber; |
||
667 | $aUser['bank_account'] = $oFaker->bankAccountNumber; |
||
668 | $oAffModel->add($aUser); |
||
669 | } |
||
670 | |||
671 | if ($iProfile <= $iSubscriberNumber) { |
||
672 | // Specific data only for subscribers |
||
673 | $aUser['name'] = $oFaker->name; |
||
674 | $aUser['active'] = $iAccountStatus = $oFaker->randomElement( |
||
0 ignored issues
–
show
$iAccountStatus is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
675 | [ |
||
676 | SubscriberCoreModel::ACTIVE_STATUS, |
||
677 | SubscriberCoreModel::INACTIVE_STATUS |
||
678 | ] |
||
679 | ); |
||
680 | $aUser['current_date'] = $oFaker->dateTime()->format('Y-m-d H:i:s'); |
||
681 | $aUser['hash_validation'] = sha1($oFaker->password(20)); |
||
682 | $aUser['affiliated_id'] = 0; |
||
683 | $oSubscriberModel->add($aUser); |
||
684 | } |
||
685 | } |
||
686 | } |
||
687 | |||
688 | /** |
||
689 | * @return bool |
||
690 | */ |
||
691 | private function isAgreementsAgreed() |
||
692 | { |
||
693 | return |
||
694 | !empty($_POST['license_agreed']) && |
||
695 | !empty($_POST['conform_laws_agreed']) && |
||
696 | !empty($_POST['responsibilities_agreed']); |
||
697 | } |
||
698 | |||
699 | /** |
||
700 | * Set the correct permission to the config files. |
||
701 | * |
||
702 | * @return void |
||
703 | */ |
||
704 | private function chmodConfigFiles() |
||
705 | { |
||
706 | @chmod(PH7_PATH_APP_CONFIG . 'config.ini', 0644); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
707 | @chmod(PH7_ROOT_PUBLIC . '_constants.php', 0644); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
708 | } |
||
709 | |||
710 | /** |
||
711 | * Require & Initialize the classes. |
||
712 | * |
||
713 | * @return void |
||
714 | */ |
||
715 | private function initializeClasses() |
||
716 | { |
||
717 | @require_once PH7_ROOT_PUBLIC . '_constants.php'; |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
718 | @require_once PH7_PATH_APP . 'configs/constants.php'; |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
719 | |||
720 | require PH7_PATH_APP . 'includes/helpers/misc.php'; |
||
721 | require PH7_PATH_FRAMEWORK . 'Loader/Autoloader.php'; |
||
722 | require PH7_PATH_FRAMEWORK . 'Error/Debug.class.php'; |
||
723 | |||
724 | Framework\Loader\Autoloader::getInstance()->init(); |
||
725 | |||
726 | // Loading Class ~/protected/app/includes/classes/* (for "DbTableName" class) |
||
727 | require PH7_PATH_APP . 'includes/classes/Loader/Autoloader.php'; |
||
728 | App\Includes\Classes\Loader\Autoloader::getInstance()->init(); |
||
729 | } |
||
730 | |||
731 | private function removeSessions() |
||
732 | { |
||
733 | $_SESSION = []; |
||
734 | session_unset(); |
||
735 | session_destroy(); |
||
736 | } |
||
737 | |||
738 | private function removeCookies() |
||
739 | { |
||
740 | $sCookieName = self::SOFTWARE_PREFIX_COOKIE_NAME . '_install_lang'; |
||
741 | |||
742 | // We are asking the browser to delete the cookie. |
||
743 | setcookie( |
||
744 | $sCookieName, |
||
745 | 0, |
||
746 | 0, |
||
747 | null, |
||
748 | null, |
||
749 | false, |
||
750 | true |
||
751 | ); |
||
752 | |||
753 | // and then, we delete the cookie value locally to avoid using it by mistake in following our script. |
||
754 | unset($_COOKIE[$sCookieName]); |
||
755 | } |
||
756 | |||
757 | /** |
||
758 | * Get the loading HTML <img src="" /> gif image. |
||
759 | * |
||
760 | * @return string |
||
761 | */ |
||
762 | private function loadImg() |
||
0 ignored issues
–
show
|
|||
763 | { |
||
764 | global $LANG; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
765 | |||
766 | return '<div style="text-align:center"><p>' . $LANG['wait_importing_database'] . '</p> |
||
767 | <p><img src="data:image/gif;base64,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" alt="' . $LANG['loading'] . '" /></p> |
||
768 | </div>'; |
||
769 | } |
||
770 | } |
||
771 |
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.