@@ -28,14 +28,15 @@ discard block |
||
28 | 28 | <div id="confirm_buttons">'; |
29 | 29 | |
30 | 30 | // Age restriction in effect? |
31 | - if ($context['show_coppa']) |
|
32 | - echo ' |
|
31 | + if ($context['show_coppa']) { |
|
32 | + echo ' |
|
33 | 33 | <input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button"><br> |
34 | 34 | <br> |
35 | 35 | <input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button">'; |
36 | - else |
|
37 | - echo ' |
|
36 | + } else { |
|
37 | + echo ' |
|
38 | 38 | <input type="submit" name="accept_agreement" value="', $txt['agreement_agree'], '" class="button">'; |
39 | + } |
|
39 | 40 | |
40 | 41 | echo ' |
41 | 42 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
@@ -78,9 +79,10 @@ discard block |
||
78 | 79 | <ul>'; |
79 | 80 | |
80 | 81 | // Cycle through each error and display an error message. |
81 | - foreach ($context['registration_errors'] as $error) |
|
82 | - echo ' |
|
82 | + foreach ($context['registration_errors'] as $error) { |
|
83 | + echo ' |
|
83 | 84 | <li>', $error, '</li>'; |
85 | + } |
|
84 | 86 | |
85 | 87 | echo ' |
86 | 88 | </ul> |
@@ -149,14 +151,15 @@ discard block |
||
149 | 151 | echo ' |
150 | 152 | <dl class="register_form">'; |
151 | 153 | |
152 | - foreach ($context['custom_fields'] as $field) |
|
153 | - if ($field['show_reg'] > 1) |
|
154 | + foreach ($context['custom_fields'] as $field) { |
|
155 | + if ($field['show_reg'] > 1) |
|
154 | 156 | echo ' |
155 | 157 | <dt> |
156 | 158 | <strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['name'], ':</strong> |
157 | 159 | <span class="smalltext">', $field['desc'], '</span> |
158 | 160 | </dt> |
159 | 161 | <dd>', str_replace('name="', 'tabindex="' . $context['tabindex']++ . '" name="', $field['input_html']), '</dd>'; |
162 | + } |
|
160 | 163 | |
161 | 164 | echo ' |
162 | 165 | </dl>'; |
@@ -167,14 +170,15 @@ discard block |
||
167 | 170 | </div><!-- .roundframe -->'; |
168 | 171 | |
169 | 172 | // If we have either of these, show the extra group. |
170 | - if (!empty($context['profile_fields']) || !empty($context['custom_fields'])) |
|
171 | - echo ' |
|
173 | + if (!empty($context['profile_fields']) || !empty($context['custom_fields'])) { |
|
174 | + echo ' |
|
172 | 175 | <div class="title_bar title_top"> |
173 | 176 | <h3 class="titlebg">', $txt['additional_information'], '</h3> |
174 | 177 | </div> |
175 | 178 | <div class="roundframe noup"> |
176 | 179 | <fieldset> |
177 | 180 | <dl class="register_form" id="custom_group">'; |
181 | + } |
|
178 | 182 | |
179 | 183 | if (!empty($context['profile_fields'])) |
180 | 184 | { |
@@ -188,41 +192,45 @@ discard block |
||
188 | 192 | $callback_func = 'template_profile_' . $field['callback_func']; |
189 | 193 | $callback_func(); |
190 | 194 | } |
191 | - } |
|
192 | - else |
|
195 | + } else |
|
193 | 196 | { |
194 | 197 | echo ' |
195 | 198 | <dt> |
196 | 199 | <strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['label'], ':</strong>'; |
197 | 200 | |
198 | 201 | // Does it have any subtext to show? |
199 | - if (!empty($field['subtext'])) |
|
200 | - echo ' |
|
202 | + if (!empty($field['subtext'])) { |
|
203 | + echo ' |
|
201 | 204 | <span class="smalltext">', $field['subtext'], '</span>'; |
205 | + } |
|
202 | 206 | |
203 | 207 | echo ' |
204 | 208 | </dt> |
205 | 209 | <dd>'; |
206 | 210 | |
207 | 211 | // Want to put something infront of the box? |
208 | - if (!empty($field['preinput'])) |
|
209 | - echo ' |
|
212 | + if (!empty($field['preinput'])) { |
|
213 | + echo ' |
|
210 | 214 | ', $field['preinput']; |
215 | + } |
|
211 | 216 | |
212 | 217 | // What type of data are we showing? |
213 | - if ($field['type'] == 'label') |
|
214 | - echo ' |
|
218 | + if ($field['type'] == 'label') { |
|
219 | + echo ' |
|
215 | 220 | ', $field['value']; |
221 | + } |
|
216 | 222 | |
217 | 223 | // Maybe it's a text box - very likely! |
218 | - elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'url'))) |
|
219 | - echo ' |
|
224 | + elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'url'))) { |
|
225 | + echo ' |
|
220 | 226 | <input type="', $field['type'] == 'password' ? 'password' : 'text', '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], '>'; |
227 | + } |
|
221 | 228 | |
222 | 229 | // You "checking" me out? ;) |
223 | - elseif ($field['type'] == 'check') |
|
224 | - echo ' |
|
230 | + elseif ($field['type'] == 'check') { |
|
231 | + echo ' |
|
225 | 232 | <input type="hidden" name="', $key, '" value="0"><input type="checkbox" name="', $key, '" id="', $key, '"', !empty($field['value']) ? ' checked' : '', ' value="1" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], '>'; |
233 | + } |
|
226 | 234 | |
227 | 235 | // Always fun - select boxes! |
228 | 236 | elseif ($field['type'] == 'select') |
@@ -233,14 +241,16 @@ discard block |
||
233 | 241 | if (isset($field['options'])) |
234 | 242 | { |
235 | 243 | // Is this some code to generate the options? |
236 | - if (!is_array($field['options'])) |
|
237 | - $field['options'] = eval($field['options']); |
|
244 | + if (!is_array($field['options'])) { |
|
245 | + $field['options'] = eval($field['options']); |
|
246 | + } |
|
238 | 247 | |
239 | 248 | // Assuming we now have some! |
240 | - if (is_array($field['options'])) |
|
241 | - foreach ($field['options'] as $value => $name) |
|
249 | + if (is_array($field['options'])) { |
|
250 | + foreach ($field['options'] as $value => $name) |
|
242 | 251 | echo ' |
243 | 252 | <option value="', $value, '"', $value == $field['value'] ? ' selected' : '', '>', $name, '</option>'; |
253 | + } |
|
244 | 254 | } |
245 | 255 | |
246 | 256 | echo ' |
@@ -248,9 +258,10 @@ discard block |
||
248 | 258 | } |
249 | 259 | |
250 | 260 | // Something to end with? |
251 | - if (!empty($field['postinput'])) |
|
252 | - echo ' |
|
261 | + if (!empty($field['postinput'])) { |
|
262 | + echo ' |
|
253 | 263 | ', $field['postinput']; |
264 | + } |
|
254 | 265 | |
255 | 266 | echo ' |
256 | 267 | </dd>'; |
@@ -261,25 +272,27 @@ discard block |
||
261 | 272 | // Are there any custom fields? |
262 | 273 | if (!empty($context['custom_fields'])) |
263 | 274 | { |
264 | - foreach ($context['custom_fields'] as $field) |
|
265 | - if ($field['show_reg'] < 2) |
|
275 | + foreach ($context['custom_fields'] as $field) { |
|
276 | + if ($field['show_reg'] < 2) |
|
266 | 277 | echo ' |
267 | 278 | <dt> |
268 | 279 | <strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['name'], ':</strong> |
269 | 280 | <span class="smalltext">', $field['desc'], '</span> |
270 | 281 | </dt> |
271 | 282 | <dd>', $field['input_html'], '</dd>'; |
283 | + } |
|
272 | 284 | } |
273 | 285 | |
274 | 286 | // If we have either of these, close the list like a proper gent. |
275 | - if (!empty($context['profile_fields']) || !empty($context['custom_fields'])) |
|
276 | - echo ' |
|
287 | + if (!empty($context['profile_fields']) || !empty($context['custom_fields'])) { |
|
288 | + echo ' |
|
277 | 289 | </dl> |
278 | 290 | </fieldset> |
279 | 291 | </div><!-- .roundframe -->'; |
292 | + } |
|
280 | 293 | |
281 | - if ($context['visual_verification']) |
|
282 | - echo ' |
|
294 | + if ($context['visual_verification']) { |
|
295 | + echo ' |
|
283 | 296 | <div class="title_bar title_top"> |
284 | 297 | <h3 class="titlebg">', $txt['verification'], '</h3> |
285 | 298 | </div> |
@@ -288,19 +301,21 @@ discard block |
||
288 | 301 | ', template_control_verification($context['visual_verification_id'], 'all'), ' |
289 | 302 | </fieldset> |
290 | 303 | </div>'; |
304 | + } |
|
291 | 305 | |
292 | 306 | echo ' |
293 | 307 | <div id="confirm_buttons" class="flow_auto">'; |
294 | 308 | |
295 | 309 | // Age restriction in effect? |
296 | - if (!$context['require_agreement'] && $context['show_coppa']) |
|
297 | - echo ' |
|
310 | + if (!$context['require_agreement'] && $context['show_coppa']) { |
|
311 | + echo ' |
|
298 | 312 | <input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button"><br> |
299 | 313 | <br> |
300 | 314 | <input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button">'; |
301 | - else |
|
302 | - echo ' |
|
315 | + } else { |
|
316 | + echo ' |
|
303 | 317 | <input type="submit" name="regSubmit" value="', $txt['register'], '" tabindex="', $context['tabindex']++, '" class="button">'; |
318 | + } |
|
304 | 319 | |
305 | 320 | echo ' |
306 | 321 | </div> |
@@ -362,25 +377,28 @@ discard block |
||
362 | 377 | <p>', $context['coppa']['many_options'] ? $txt['coppa_send_to_two_options'] : $txt['coppa_send_to_one_option'], '</p>'; |
363 | 378 | |
364 | 379 | // Can they send by post? |
365 | - if (!empty($context['coppa']['post'])) |
|
366 | - echo ' |
|
380 | + if (!empty($context['coppa']['post'])) { |
|
381 | + echo ' |
|
367 | 382 | <h4>1) ', $txt['coppa_send_by_post'], '</h4> |
368 | 383 | <div class="coppa_contact"> |
369 | 384 | ', $context['coppa']['post'], ' |
370 | 385 | </div>'; |
386 | + } |
|
371 | 387 | |
372 | 388 | // Can they send by fax?? |
373 | - if (!empty($context['coppa']['fax'])) |
|
374 | - echo ' |
|
389 | + if (!empty($context['coppa']['fax'])) { |
|
390 | + echo ' |
|
375 | 391 | <h4>', !empty($context['coppa']['post']) ? '2' : '1', ') ', $txt['coppa_send_by_fax'], '</h4> |
376 | 392 | <div class="coppa_contact"> |
377 | 393 | ', $context['coppa']['fax'], ' |
378 | 394 | </div>'; |
395 | + } |
|
379 | 396 | |
380 | 397 | // Offer an alternative Phone Number? |
381 | - if ($context['coppa']['phone']) |
|
382 | - echo ' |
|
398 | + if ($context['coppa']['phone']) { |
|
399 | + echo ' |
|
383 | 400 | <p>', $context['coppa']['phone'], '</p>'; |
401 | + } |
|
384 | 402 | |
385 | 403 | echo ' |
386 | 404 | </div><!-- #coppa -->'; |
@@ -445,19 +463,20 @@ discard block |
||
445 | 463 | <body style="margin: 1ex;"> |
446 | 464 | <div class="windowbg description" style="text-align: center;">'; |
447 | 465 | |
448 | - if (isBrowser('is_ie') || isBrowser('is_ie11')) |
|
449 | - echo ' |
|
466 | + if (isBrowser('is_ie') || isBrowser('is_ie11')) { |
|
467 | + echo ' |
|
450 | 468 | <object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" type="audio/x-wav"> |
451 | 469 | <param name="AutoStart" value="1"> |
452 | 470 | <param name="FileName" value="', $context['verification_sound_href'], '"> |
453 | 471 | </object>'; |
454 | - else |
|
455 | - echo ' |
|
472 | + } else { |
|
473 | + echo ' |
|
456 | 474 | <audio src="', $context['verification_sound_href'], '" controls> |
457 | 475 | <object type="audio/x-wav" data="', $context['verification_sound_href'], '"> |
458 | 476 | <a href="', $context['verification_sound_href'], '" rel="nofollow">', $context['verification_sound_href'], '</a> |
459 | 477 | </object> |
460 | 478 | </audio>'; |
479 | + } |
|
461 | 480 | |
462 | 481 | echo ' |
463 | 482 | <br> |
@@ -485,11 +504,12 @@ discard block |
||
485 | 504 | </div> |
486 | 505 | <div id="register_screen" class="windowbg2 noup">'; |
487 | 506 | |
488 | - if (!empty($context['registration_done'])) |
|
489 | - echo ' |
|
507 | + if (!empty($context['registration_done'])) { |
|
508 | + echo ' |
|
490 | 509 | <div class="infobox"> |
491 | 510 | ', $context['registration_done'], ' |
492 | 511 | </div>'; |
512 | + } |
|
493 | 513 | |
494 | 514 | echo ' |
495 | 515 | <dl class="register_form" id="admin_register_form"> |
@@ -525,9 +545,10 @@ discard block |
||
525 | 545 | <dd> |
526 | 546 | <select name="group" id="group_select" tabindex="', $context['tabindex']++, '">'; |
527 | 547 | |
528 | - foreach ($context['member_groups'] as $id => $name) |
|
529 | - echo ' |
|
548 | + foreach ($context['member_groups'] as $id => $name) { |
|
549 | + echo ' |
|
530 | 550 | <option value="', $id, '">', $name, '</option>'; |
551 | + } |
|
531 | 552 | |
532 | 553 | echo ' |
533 | 554 | </select> |
@@ -535,8 +556,8 @@ discard block |
||
535 | 556 | } |
536 | 557 | |
537 | 558 | // If there is any field marked as required, show it here! |
538 | - if (!empty($context['custom_fields_required']) && !empty($context['custom_fields'])) |
|
539 | - foreach ($context['custom_fields'] as $field) |
|
559 | + if (!empty($context['custom_fields_required']) && !empty($context['custom_fields'])) { |
|
560 | + foreach ($context['custom_fields'] as $field) |
|
540 | 561 | if ($field['show_reg'] > 1) |
541 | 562 | echo ' |
542 | 563 | <dt> |
@@ -546,6 +567,7 @@ discard block |
||
546 | 567 | <dd> |
547 | 568 | ', str_replace('name="', 'tabindex="' . $context['tabindex']++ . '" name="', $field['input_html']), ' |
548 | 569 | </dd>'; |
570 | + } |
|
549 | 571 | |
550 | 572 | echo ' |
551 | 573 | <dt> |
@@ -582,13 +604,13 @@ discard block |
||
582 | 604 | { |
583 | 605 | global $context, $scripturl, $txt; |
584 | 606 | |
585 | - if (!empty($context['saved_successful'])) |
|
586 | - echo ' |
|
607 | + if (!empty($context['saved_successful'])) { |
|
608 | + echo ' |
|
587 | 609 | <div class="infobox">', $txt['settings_saved'], '</div>'; |
588 | - |
|
589 | - elseif (!empty($context['could_not_save'])) |
|
590 | - echo ' |
|
610 | + } elseif (!empty($context['could_not_save'])) { |
|
611 | + echo ' |
|
591 | 612 | <div class="errorbox">', $txt['admin_agreement_not_saved'], '</div>'; |
613 | + } |
|
592 | 614 | |
593 | 615 | // Just a big box to edit the text file ;) |
594 | 616 | echo ' |
@@ -598,9 +620,10 @@ discard block |
||
598 | 620 | </div>'; |
599 | 621 | |
600 | 622 | // Warning for if the file isn't writable. |
601 | - if (!empty($context['warning'])) |
|
602 | - echo ' |
|
623 | + if (!empty($context['warning'])) { |
|
624 | + echo ' |
|
603 | 625 | <p class="error">', $context['warning'], '</p>'; |
626 | + } |
|
604 | 627 | |
605 | 628 | echo ' |
606 | 629 | <div class="windowbg2 noup" id="registration_agreement">'; |
@@ -617,9 +640,10 @@ discard block |
||
617 | 640 | <strong>', $txt['admin_agreement_select_language'], ':</strong> |
618 | 641 | <select name="agree_lang" onchange="document.getElementById(\'change_reg\').submit();" tabindex="', $context['tabindex']++, '">'; |
619 | 642 | |
620 | - foreach ($context['editable_agreements'] as $file => $name) |
|
621 | - echo ' |
|
643 | + foreach ($context['editable_agreements'] as $file => $name) { |
|
644 | + echo ' |
|
622 | 645 | <option value="', $file, '"', $context['current_agreement'] == $file ? ' selected' : '', '>', $name, '</option>'; |
646 | + } |
|
623 | 647 | |
624 | 648 | echo ' |
625 | 649 | </select> |
@@ -659,9 +683,10 @@ discard block |
||
659 | 683 | { |
660 | 684 | global $context, $scripturl, $txt; |
661 | 685 | |
662 | - if (!empty($context['saved_successful'])) |
|
663 | - echo ' |
|
686 | + if (!empty($context['saved_successful'])) { |
|
687 | + echo ' |
|
664 | 688 | <div class="infobox">', $txt['settings_saved'], '</div>'; |
689 | + } |
|
665 | 690 | |
666 | 691 | echo ' |
667 | 692 | <form id="admin_form_wrapper" action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '"> |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
30 | 31 | |
31 | 32 | // Is this an incoming AJAX check? |
32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
33 | - return RegisterCheckUsername(); |
|
33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
34 | + return RegisterCheckUsername(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // Check if the administrator has it disabled. |
36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
37 | - fatal_lang_error('registration_disabled', false); |
|
38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
39 | + fatal_lang_error('registration_disabled', false); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
45 | + } |
|
42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
43 | - elseif (empty($user_info['is_guest'])) |
|
44 | - redirectexit(); |
|
47 | + elseif (empty($user_info['is_guest'])) { |
|
48 | + redirectexit(); |
|
49 | + } |
|
45 | 50 | |
46 | 51 | loadLanguage('Login'); |
47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
82 | 87 | } |
83 | 88 | } |
84 | 89 | // Make sure they don't squeeze through without agreeing. |
85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
86 | - $current_step = 1; |
|
90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
91 | + $current_step = 1; |
|
92 | + } |
|
87 | 93 | |
88 | 94 | // Show the user the right form. |
89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
91 | 97 | |
92 | 98 | // Kinda need this. |
93 | - if ($context['sub_template'] == 'registration_form') |
|
94 | - loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
99 | + if ($context['sub_template'] == 'registration_form') { |
|
100 | + loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
101 | + } |
|
95 | 102 | |
96 | 103 | // Add the register chain to the link tree. |
97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
100 | 107 | ); |
101 | 108 | |
102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
103 | - if (!isset($_SESSION['register'])) |
|
104 | - $_SESSION['register'] = array( |
|
110 | + if (!isset($_SESSION['register'])) { |
|
111 | + $_SESSION['register'] = array( |
|
105 | 112 | 'timenow' => time(), |
106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
107 | 114 | ); |
108 | - else |
|
109 | - $_SESSION['register']['timenow'] = time(); |
|
115 | + } else { |
|
116 | + $_SESSION['register']['timenow'] = time(); |
|
117 | + } |
|
110 | 118 | |
111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
112 | 120 | if ($context['require_agreement']) |
113 | 121 | { |
114 | 122 | // Have we got a localized one? |
115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
119 | - else |
|
120 | - $context['agreement'] = ''; |
|
123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
127 | + } else { |
|
128 | + $context['agreement'] = ''; |
|
129 | + } |
|
121 | 130 | |
122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
134 | 143 | |
135 | 144 | // Do we have any languages? |
136 | - if (empty($context['languages'])) |
|
137 | - getLanguages(); |
|
145 | + if (empty($context['languages'])) { |
|
146 | + getLanguages(); |
|
147 | + } |
|
138 | 148 | |
139 | 149 | // Try to find our selected language. |
140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
143 | 153 | |
144 | 154 | // Found it! |
145 | - if ($selectedLanguage == $lang['filename']) |
|
146 | - $context['languages'][$key]['selected'] = true; |
|
155 | + if ($selectedLanguage == $lang['filename']) { |
|
156 | + $context['languages'][$key]['selected'] = true; |
|
157 | + } |
|
147 | 158 | } |
148 | 159 | } |
149 | 160 | |
@@ -167,9 +178,10 @@ discard block |
||
167 | 178 | $reg_fields = explode(',', $modSettings['registration_fields']); |
168 | 179 | |
169 | 180 | // We might have had some submissions on this front - go check. |
170 | - foreach ($reg_fields as $field) |
|
171 | - if (isset($_POST[$field])) |
|
181 | + foreach ($reg_fields as $field) { |
|
182 | + if (isset($_POST[$field])) |
|
172 | 183 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
184 | + } |
|
173 | 185 | |
174 | 186 | // Load all the fields in question. |
175 | 187 | setupProfileContext($reg_fields); |
@@ -186,8 +198,9 @@ discard block |
||
186 | 198 | $context['visual_verification_id'] = $verificationOptions['id']; |
187 | 199 | } |
188 | 200 | // Otherwise we have nothing to show. |
189 | - else |
|
190 | - $context['visual_verification'] = false; |
|
201 | + else { |
|
202 | + $context['visual_verification'] = false; |
|
203 | + } |
|
191 | 204 | |
192 | 205 | |
193 | 206 | $context += array( |
@@ -198,8 +211,9 @@ discard block |
||
198 | 211 | |
199 | 212 | // Were there any errors? |
200 | 213 | $context['registration_errors'] = array(); |
201 | - if (!empty($reg_errors)) |
|
202 | - $context['registration_errors'] = $reg_errors; |
|
214 | + if (!empty($reg_errors)) { |
|
215 | + $context['registration_errors'] = $reg_errors; |
|
216 | + } |
|
203 | 217 | |
204 | 218 | createToken('register'); |
205 | 219 | } |
@@ -216,27 +230,32 @@ discard block |
||
216 | 230 | validateToken('register'); |
217 | 231 | |
218 | 232 | // Check to ensure we're forcing SSL for authentication |
219 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
220 | - fatal_lang_error('register_ssl_required'); |
|
233 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
234 | + fatal_lang_error('register_ssl_required'); |
|
235 | + } |
|
221 | 236 | |
222 | 237 | // Start collecting together any errors. |
223 | 238 | $reg_errors = array(); |
224 | 239 | |
225 | 240 | // You can't register if it's disabled. |
226 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
227 | - fatal_lang_error('registration_disabled', false); |
|
241 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
242 | + fatal_lang_error('registration_disabled', false); |
|
243 | + } |
|
228 | 244 | |
229 | 245 | // Well, if you don't agree, you can't register. |
230 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
231 | - redirectexit(); |
|
246 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
247 | + redirectexit(); |
|
248 | + } |
|
232 | 249 | |
233 | 250 | // Make sure they came from *somewhere*, have a session. |
234 | - if (!isset($_SESSION['old_url'])) |
|
235 | - redirectexit('action=signup'); |
|
251 | + if (!isset($_SESSION['old_url'])) { |
|
252 | + redirectexit('action=signup'); |
|
253 | + } |
|
236 | 254 | |
237 | 255 | // If we don't require an agreement, we need a extra check for coppa. |
238 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
239 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
256 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
257 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
258 | + } |
|
240 | 259 | // Are they under age, and under age users are banned? |
241 | 260 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
242 | 261 | { |
@@ -245,8 +264,9 @@ discard block |
||
245 | 264 | } |
246 | 265 | |
247 | 266 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
248 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
249 | - redirectexit('action=signup'); |
|
267 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
268 | + redirectexit('action=signup'); |
|
269 | + } |
|
250 | 270 | // Failing that, check the time on it. |
251 | 271 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
252 | 272 | { |
@@ -266,15 +286,17 @@ discard block |
||
266 | 286 | if (is_array($context['visual_verification'])) |
267 | 287 | { |
268 | 288 | loadLanguage('Errors'); |
269 | - foreach ($context['visual_verification'] as $error) |
|
270 | - $reg_errors[] = $txt['error_' . $error]; |
|
289 | + foreach ($context['visual_verification'] as $error) { |
|
290 | + $reg_errors[] = $txt['error_' . $error]; |
|
291 | + } |
|
271 | 292 | } |
272 | 293 | } |
273 | 294 | |
274 | 295 | foreach ($_POST as $key => $value) |
275 | 296 | { |
276 | - if (!is_array($_POST[$key])) |
|
277 | - $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
297 | + if (!is_array($_POST[$key])) { |
|
298 | + $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
299 | + } |
|
278 | 300 | } |
279 | 301 | |
280 | 302 | // Collect all extra registration fields someone might have filled in. |
@@ -304,12 +326,14 @@ discard block |
||
304 | 326 | $reg_fields = explode(',', $modSettings['registration_fields']); |
305 | 327 | |
306 | 328 | // Website is a little different |
307 | - if (in_array('website', $reg_fields)) |
|
308 | - $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
329 | + if (in_array('website', $reg_fields)) { |
|
330 | + $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
331 | + } |
|
309 | 332 | } |
310 | 333 | |
311 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
312 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
334 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
335 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
336 | + } |
|
313 | 337 | |
314 | 338 | // Needed for isReservedName() and registerMember(). |
315 | 339 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -318,8 +342,9 @@ discard block |
||
318 | 342 | if (isset($_POST['real_name'])) |
319 | 343 | { |
320 | 344 | // Are you already allowed to edit the displayed name? |
321 | - if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) |
|
322 | - $canEditDisplayName = true; |
|
345 | + if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) { |
|
346 | + $canEditDisplayName = true; |
|
347 | + } |
|
323 | 348 | |
324 | 349 | // If you are a guest, will you be allowed to once you register? |
325 | 350 | else |
@@ -343,33 +368,38 @@ discard block |
||
343 | 368 | $_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name'])); |
344 | 369 | |
345 | 370 | // Only set it if we are sure it is good |
346 | - if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
347 | - $possible_strings[] = 'real_name'; |
|
371 | + if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
372 | + $possible_strings[] = 'real_name'; |
|
373 | + } |
|
348 | 374 | } |
349 | 375 | } |
350 | 376 | |
351 | 377 | // Handle a string as a birthdate... |
352 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
353 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
378 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
379 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
380 | + } |
|
354 | 381 | // Or birthdate parts... |
355 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
356 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
382 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
383 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
384 | + } |
|
357 | 385 | |
358 | 386 | // Validate the passed language file. |
359 | 387 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
360 | 388 | { |
361 | 389 | // Do we have any languages? |
362 | - if (empty($context['languages'])) |
|
363 | - getLanguages(); |
|
390 | + if (empty($context['languages'])) { |
|
391 | + getLanguages(); |
|
392 | + } |
|
364 | 393 | |
365 | 394 | // Did we find it? |
366 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
367 | - $_SESSION['language'] = $_POST['lngfile']; |
|
368 | - else |
|
395 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
396 | + $_SESSION['language'] = $_POST['lngfile']; |
|
397 | + } else { |
|
398 | + unset($_POST['lngfile']); |
|
399 | + } |
|
400 | + } else { |
|
369 | 401 | unset($_POST['lngfile']); |
370 | 402 | } |
371 | - else |
|
372 | - unset($_POST['lngfile']); |
|
373 | 403 | |
374 | 404 | // Set the options needed for registration. |
375 | 405 | $regOptions = array( |
@@ -389,22 +419,27 @@ discard block |
||
389 | 419 | ); |
390 | 420 | |
391 | 421 | // Include the additional options that might have been filled in. |
392 | - foreach ($possible_strings as $var) |
|
393 | - if (isset($_POST[$var])) |
|
422 | + foreach ($possible_strings as $var) { |
|
423 | + if (isset($_POST[$var])) |
|
394 | 424 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
395 | - foreach ($possible_ints as $var) |
|
396 | - if (isset($_POST[$var])) |
|
425 | + } |
|
426 | + foreach ($possible_ints as $var) { |
|
427 | + if (isset($_POST[$var])) |
|
397 | 428 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
398 | - foreach ($possible_floats as $var) |
|
399 | - if (isset($_POST[$var])) |
|
429 | + } |
|
430 | + foreach ($possible_floats as $var) { |
|
431 | + if (isset($_POST[$var])) |
|
400 | 432 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
401 | - foreach ($possible_bools as $var) |
|
402 | - if (isset($_POST[$var])) |
|
433 | + } |
|
434 | + foreach ($possible_bools as $var) { |
|
435 | + if (isset($_POST[$var])) |
|
403 | 436 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
437 | + } |
|
404 | 438 | |
405 | 439 | // Registration options are always default options... |
406 | - if (isset($_POST['default_options'])) |
|
407 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
440 | + if (isset($_POST['default_options'])) { |
|
441 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
442 | + } |
|
408 | 443 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
409 | 444 | |
410 | 445 | // Make sure they are clean, dammit! |
@@ -424,12 +459,14 @@ discard block |
||
424 | 459 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
425 | 460 | { |
426 | 461 | // Don't allow overriding of the theme variables. |
427 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
428 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
462 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
463 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
464 | + } |
|
429 | 465 | |
430 | 466 | // Not actually showing it then? |
431 | - if (!$row['show_reg']) |
|
432 | - continue; |
|
467 | + if (!$row['show_reg']) { |
|
468 | + continue; |
|
469 | + } |
|
433 | 470 | |
434 | 471 | // Prepare the value! |
435 | 472 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -438,24 +475,27 @@ discard block |
||
438 | 475 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
439 | 476 | { |
440 | 477 | // Is it too long? |
441 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
442 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
478 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
479 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
480 | + } |
|
443 | 481 | |
444 | 482 | // Any masks to apply? |
445 | 483 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
446 | 484 | { |
447 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
448 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
449 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
450 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
451 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
452 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
485 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
486 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
487 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
488 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
489 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
490 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
491 | + } |
|
453 | 492 | } |
454 | 493 | } |
455 | 494 | |
456 | 495 | // Is this required but not there? |
457 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
458 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
496 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
497 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
498 | + } |
|
459 | 499 | } |
460 | 500 | $smcFunc['db_free_result']($request); |
461 | 501 | |
@@ -463,8 +503,9 @@ discard block |
||
463 | 503 | if (!empty($custom_field_errors)) |
464 | 504 | { |
465 | 505 | loadLanguage('Errors'); |
466 | - foreach ($custom_field_errors as $error) |
|
467 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
506 | + foreach ($custom_field_errors as $error) { |
|
507 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
508 | + } |
|
468 | 509 | } |
469 | 510 | |
470 | 511 | // Lets check for other errors before trying to register the member. |
@@ -509,8 +550,9 @@ discard block |
||
509 | 550 | } |
510 | 551 | |
511 | 552 | // If COPPA has been selected then things get complicated, setup the template. |
512 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
513 | - redirectexit('action=coppa;member=' . $memberID); |
|
553 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
554 | + redirectexit('action=coppa;member=' . $memberID); |
|
555 | + } |
|
514 | 556 | // Basic template variable setup. |
515 | 557 | elseif (!empty($modSettings['registration_method'])) |
516 | 558 | { |
@@ -522,8 +564,7 @@ discard block |
||
522 | 564 | 'sub_template' => 'after', |
523 | 565 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
524 | 566 | ); |
525 | - } |
|
526 | - else |
|
567 | + } else |
|
527 | 568 | { |
528 | 569 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
529 | 570 | |
@@ -543,16 +584,18 @@ discard block |
||
543 | 584 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
544 | 585 | |
545 | 586 | // Logged in users should not bother to activate their accounts |
546 | - if (!empty($user_info['id'])) |
|
547 | - redirectexit(); |
|
587 | + if (!empty($user_info['id'])) { |
|
588 | + redirectexit(); |
|
589 | + } |
|
548 | 590 | |
549 | 591 | loadLanguage('Login'); |
550 | 592 | loadTemplate('Login'); |
551 | 593 | |
552 | 594 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
553 | 595 | { |
554 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
555 | - fatal_lang_error('no_access', false); |
|
596 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
597 | + fatal_lang_error('no_access', false); |
|
598 | + } |
|
556 | 599 | |
557 | 600 | $context['member_id'] = 0; |
558 | 601 | $context['sub_template'] = 'resend'; |
@@ -592,11 +635,13 @@ discard block |
||
592 | 635 | // Change their email address? (they probably tried a fake one first :P.) |
593 | 636 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
594 | 637 | { |
595 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
596 | - fatal_lang_error('no_access', false); |
|
638 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
639 | + fatal_lang_error('no_access', false); |
|
640 | + } |
|
597 | 641 | |
598 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
599 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
642 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
643 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
644 | + } |
|
600 | 645 | |
601 | 646 | // Make sure their email isn't banned. |
602 | 647 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -612,8 +657,9 @@ discard block |
||
612 | 657 | ) |
613 | 658 | ); |
614 | 659 | |
615 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
616 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
660 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
661 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
662 | + } |
|
617 | 663 | $smcFunc['db_free_result']($request); |
618 | 664 | |
619 | 665 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -651,9 +697,9 @@ discard block |
||
651 | 697 | // Quit if this code is not right. |
652 | 698 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
653 | 699 | { |
654 | - if (!empty($row['is_activated'])) |
|
655 | - fatal_lang_error('already_activated', false); |
|
656 | - elseif ($row['validation_code'] == '') |
|
700 | + if (!empty($row['is_activated'])) { |
|
701 | + fatal_lang_error('already_activated', false); |
|
702 | + } elseif ($row['validation_code'] == '') |
|
657 | 703 | { |
658 | 704 | loadLanguage('Profile'); |
659 | 705 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -703,8 +749,9 @@ discard block |
||
703 | 749 | loadTemplate('Register'); |
704 | 750 | |
705 | 751 | // No User ID?? |
706 | - if (!isset($_GET['member'])) |
|
707 | - fatal_lang_error('no_access', false); |
|
752 | + if (!isset($_GET['member'])) { |
|
753 | + fatal_lang_error('no_access', false); |
|
754 | + } |
|
708 | 755 | |
709 | 756 | // Get the user details... |
710 | 757 | $request = $smcFunc['db_query']('', ' |
@@ -717,8 +764,9 @@ discard block |
||
717 | 764 | 'is_coppa' => 5, |
718 | 765 | ) |
719 | 766 | ); |
720 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
721 | - fatal_lang_error('no_access', false); |
|
767 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
768 | + fatal_lang_error('no_access', false); |
|
769 | + } |
|
722 | 770 | list ($username) = $smcFunc['db_fetch_row']($request); |
723 | 771 | $smcFunc['db_free_result']($request); |
724 | 772 | |
@@ -756,8 +804,7 @@ discard block |
||
756 | 804 | echo $data; |
757 | 805 | obExit(false); |
758 | 806 | } |
759 | - } |
|
760 | - else |
|
807 | + } else |
|
761 | 808 | { |
762 | 809 | $context += array( |
763 | 810 | 'page_title' => $txt['coppa_title'], |
@@ -810,8 +857,9 @@ discard block |
||
810 | 857 | { |
811 | 858 | require_once($sourcedir . '/Subs-Graphics.php'); |
812 | 859 | |
813 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
814 | - header('HTTP/1.1 400 Bad Request'); |
|
860 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
861 | + header('HTTP/1.1 400 Bad Request'); |
|
862 | + } |
|
815 | 863 | |
816 | 864 | // Otherwise just show a pre-defined letter. |
817 | 865 | elseif (isset($_REQUEST['letter'])) |
@@ -829,14 +877,13 @@ discard block |
||
829 | 877 | header('Content-Type: image/gif'); |
830 | 878 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
831 | 879 | } |
832 | - } |
|
833 | - |
|
834 | - elseif ($_REQUEST['format'] === '.wav') |
|
880 | + } elseif ($_REQUEST['format'] === '.wav') |
|
835 | 881 | { |
836 | 882 | require_once($sourcedir . '/Subs-Sound.php'); |
837 | 883 | |
838 | - if (!createWaveFile($code)) |
|
839 | - header('HTTP/1.1 400 Bad Request'); |
|
884 | + if (!createWaveFile($code)) { |
|
885 | + header('HTTP/1.1 400 Bad Request'); |
|
886 | + } |
|
840 | 887 | } |
841 | 888 | |
842 | 889 | // We all die one day... |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Activate an account. |
@@ -48,8 +49,9 @@ discard block |
||
48 | 49 | logAction('approve_member', array('member' => $memID), 'admin'); |
49 | 50 | |
50 | 51 | // If we are doing approval, update the stats for the member just in case. |
51 | - if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) |
|
52 | - updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
|
52 | + if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) { |
|
53 | + updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
|
54 | + } |
|
53 | 55 | |
54 | 56 | // Make sure we update the stats too. |
55 | 57 | updateStats('member', false); |
@@ -76,8 +78,9 @@ discard block |
||
76 | 78 | $issueErrors = array(); |
77 | 79 | |
78 | 80 | // Doesn't hurt to be overly cautious. |
79 | - if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) |
|
80 | - fatal_lang_error('no_access', false); |
|
81 | + if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) { |
|
82 | + fatal_lang_error('no_access', false); |
|
83 | + } |
|
81 | 84 | |
82 | 85 | // Get the base (errors related) stuff done. |
83 | 86 | loadLanguage('Errors'); |
@@ -135,16 +138,18 @@ discard block |
||
135 | 138 | |
136 | 139 | // This cannot be empty! |
137 | 140 | $_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : ''; |
138 | - if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) |
|
139 | - $issueErrors[] = 'warning_no_reason'; |
|
141 | + if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) { |
|
142 | + $issueErrors[] = 'warning_no_reason'; |
|
143 | + } |
|
140 | 144 | $_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']); |
141 | 145 | |
142 | 146 | $_POST['warning_level'] = (int) $_POST['warning_level']; |
143 | 147 | $_POST['warning_level'] = max(0, min(100, $_POST['warning_level'])); |
144 | - if ($_POST['warning_level'] < $context['min_allowed']) |
|
145 | - $_POST['warning_level'] = $context['min_allowed']; |
|
146 | - elseif ($_POST['warning_level'] > $context['max_allowed']) |
|
147 | - $_POST['warning_level'] = $context['max_allowed']; |
|
148 | + if ($_POST['warning_level'] < $context['min_allowed']) { |
|
149 | + $_POST['warning_level'] = $context['min_allowed']; |
|
150 | + } elseif ($_POST['warning_level'] > $context['max_allowed']) { |
|
151 | + $_POST['warning_level'] = $context['max_allowed']; |
|
152 | + } |
|
148 | 153 | |
149 | 154 | // Do we actually have to issue them with a PM? |
150 | 155 | $id_notice = 0; |
@@ -152,8 +157,9 @@ discard block |
||
152 | 157 | { |
153 | 158 | $_POST['warn_sub'] = trim($_POST['warn_sub']); |
154 | 159 | $_POST['warn_body'] = trim($_POST['warn_body']); |
155 | - if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) |
|
156 | - $issueErrors[] = 'warning_notify_blank'; |
|
160 | + if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) { |
|
161 | + $issueErrors[] = 'warning_notify_blank'; |
|
162 | + } |
|
157 | 163 | // Send the PM? |
158 | 164 | else |
159 | 165 | { |
@@ -190,8 +196,8 @@ discard block |
||
190 | 196 | if (empty($issueErrors)) |
191 | 197 | { |
192 | 198 | // Log what we've done! |
193 | - if (!$context['user']['is_owner']) |
|
194 | - $smcFunc['db_insert']('', |
|
199 | + if (!$context['user']['is_owner']) { |
|
200 | + $smcFunc['db_insert']('', |
|
195 | 201 | '{db_prefix}log_comments', |
196 | 202 | array( |
197 | 203 | 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255', |
@@ -203,14 +209,14 @@ discard block |
||
203 | 209 | ), |
204 | 210 | array('id_comment') |
205 | 211 | ); |
212 | + } |
|
206 | 213 | |
207 | 214 | // Make the change. |
208 | 215 | updateMemberData($memID, array('warning' => $_POST['warning_level'])); |
209 | 216 | |
210 | 217 | // Leave a lovely message. |
211 | 218 | $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success']; |
212 | - } |
|
213 | - else |
|
219 | + } else |
|
214 | 220 | { |
215 | 221 | // Try to remember some bits. |
216 | 222 | $context['warning_data'] = array( |
@@ -229,8 +235,9 @@ discard block |
||
229 | 235 | { |
230 | 236 | $warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : ''; |
231 | 237 | $context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : ''; |
232 | - if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) |
|
233 | - $issueErrors[] = 'warning_notify_blank'; |
|
238 | + if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) { |
|
239 | + $issueErrors[] = 'warning_notify_blank'; |
|
240 | + } |
|
234 | 241 | |
235 | 242 | if (!empty($_POST['warn_body'])) |
236 | 243 | { |
@@ -254,8 +261,9 @@ discard block |
||
254 | 261 | { |
255 | 262 | // Fill in the suite of errors. |
256 | 263 | $context['post_errors'] = array(); |
257 | - foreach ($issueErrors as $error) |
|
258 | - $context['post_errors'][] = $txt[$error]; |
|
264 | + foreach ($issueErrors as $error) { |
|
265 | + $context['post_errors'][] = $txt[$error]; |
|
266 | + } |
|
259 | 267 | } |
260 | 268 | |
261 | 269 | |
@@ -272,9 +280,10 @@ discard block |
||
272 | 280 | $modSettings['warning_mute'] => $txt['profile_warning_effect_mute'], |
273 | 281 | ); |
274 | 282 | $context['current_level'] = 0; |
275 | - foreach ($context['level_effects'] as $limit => $dummy) |
|
276 | - if ($context['member']['warning'] >= $limit) |
|
283 | + foreach ($context['level_effects'] as $limit => $dummy) { |
|
284 | + if ($context['member']['warning'] >= $limit) |
|
277 | 285 | $context['current_level'] = $limit; |
286 | + } |
|
278 | 287 | |
279 | 288 | $listOptions = array( |
280 | 289 | 'id' => 'view_warnings', |
@@ -337,11 +346,12 @@ discard block |
||
337 | 346 | ' . $warning['reason'] . ' |
338 | 347 | </div>'; |
339 | 348 | |
340 | - if (!empty($warning['id_notice'])) |
|
341 | - $ret .= ' |
|
349 | + if (!empty($warning['id_notice'])) { |
|
350 | + $ret .= ' |
|
342 | 351 | <div class="floatright"> |
343 | 352 | <a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" rel="noopener" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a> |
344 | 353 | </div>'; |
354 | + } |
|
345 | 355 | |
346 | 356 | return $ret; |
347 | 357 | }, |
@@ -413,8 +423,9 @@ discard block |
||
413 | 423 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
414 | 424 | { |
415 | 425 | // If we're not warning for a message skip any that are. |
416 | - if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) |
|
417 | - continue; |
|
426 | + if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) { |
|
427 | + continue; |
|
428 | + } |
|
418 | 429 | |
419 | 430 | $context['notification_templates'][] = array( |
420 | 431 | 'title' => $row['template_title'], |
@@ -424,16 +435,18 @@ discard block |
||
424 | 435 | $smcFunc['db_free_result']($request); |
425 | 436 | |
426 | 437 | // Setup the "default" templates. |
427 | - foreach (array('spamming', 'offence', 'insulting') as $type) |
|
428 | - $context['notification_templates'][] = array( |
|
438 | + foreach (array('spamming', 'offence', 'insulting') as $type) { |
|
439 | + $context['notification_templates'][] = array( |
|
429 | 440 | 'title' => $txt['profile_warning_notify_title_' . $type], |
430 | 441 | 'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]), |
431 | 442 | ); |
443 | + } |
|
432 | 444 | |
433 | 445 | // Replace all the common variables in the templates. |
434 | - foreach ($context['notification_templates'] as $k => $name) |
|
435 | - $context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team'])); |
|
436 | -} |
|
446 | + foreach ($context['notification_templates'] as $k => $name) { |
|
447 | + $context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team'])); |
|
448 | + } |
|
449 | + } |
|
437 | 450 | |
438 | 451 | /** |
439 | 452 | * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning() |
@@ -517,10 +530,11 @@ discard block |
||
517 | 530 | { |
518 | 531 | global $txt, $context, $modSettings, $cur_profile; |
519 | 532 | |
520 | - if (!$context['user']['is_owner']) |
|
521 | - isAllowedTo('profile_remove_any'); |
|
522 | - elseif (!allowedTo('profile_remove_any')) |
|
523 | - isAllowedTo('profile_remove_own'); |
|
533 | + if (!$context['user']['is_owner']) { |
|
534 | + isAllowedTo('profile_remove_any'); |
|
535 | + } elseif (!allowedTo('profile_remove_any')) { |
|
536 | + isAllowedTo('profile_remove_own'); |
|
537 | + } |
|
524 | 538 | |
525 | 539 | // Permissions for removing stuff... |
526 | 540 | $context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum'); |
@@ -547,10 +561,11 @@ discard block |
||
547 | 561 | |
548 | 562 | // @todo Add a way to delete pms as well? |
549 | 563 | |
550 | - if (!$context['user']['is_owner']) |
|
551 | - isAllowedTo('profile_remove_any'); |
|
552 | - elseif (!allowedTo('profile_remove_any')) |
|
553 | - isAllowedTo('profile_remove_own'); |
|
564 | + if (!$context['user']['is_owner']) { |
|
565 | + isAllowedTo('profile_remove_any'); |
|
566 | + } elseif (!allowedTo('profile_remove_any')) { |
|
567 | + isAllowedTo('profile_remove_own'); |
|
568 | + } |
|
554 | 569 | |
555 | 570 | checkSession(); |
556 | 571 | |
@@ -576,8 +591,9 @@ discard block |
||
576 | 591 | list ($another) = $smcFunc['db_fetch_row']($request); |
577 | 592 | $smcFunc['db_free_result']($request); |
578 | 593 | |
579 | - if (empty($another)) |
|
580 | - fatal_lang_error('at_least_one_admin', 'critical'); |
|
594 | + if (empty($another)) { |
|
595 | + fatal_lang_error('at_least_one_admin', 'critical'); |
|
596 | + } |
|
581 | 597 | } |
582 | 598 | |
583 | 599 | // This file is needed for the deleteMembers function. |
@@ -656,8 +672,9 @@ discard block |
||
656 | 672 | ) |
657 | 673 | ); |
658 | 674 | $topicIDs = array(); |
659 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
660 | - $topicIDs[] = $row['id_topic']; |
|
675 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
676 | + $topicIDs[] = $row['id_topic']; |
|
677 | + } |
|
661 | 678 | $smcFunc['db_free_result']($request); |
662 | 679 | |
663 | 680 | // Actually remove the topics. Ignore recycling if we want to perma-delete things... |
@@ -680,8 +697,9 @@ discard block |
||
680 | 697 | // This could take a while... but ya know it's gonna be worth it in the end. |
681 | 698 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
682 | 699 | { |
683 | - if (function_exists('apache_reset_timeout')) |
|
684 | - @apache_reset_timeout(); |
|
700 | + if (function_exists('apache_reset_timeout')) { |
|
701 | + @apache_reset_timeout(); |
|
702 | + } |
|
685 | 703 | |
686 | 704 | removeMessage($row['id_msg']); |
687 | 705 | } |
@@ -689,8 +707,9 @@ discard block |
||
689 | 707 | } |
690 | 708 | |
691 | 709 | // Only delete this poor members account if they are actually being booted out of camp. |
692 | - if (isset($_POST['deleteAccount'])) |
|
693 | - deleteMembers($memID); |
|
710 | + if (isset($_POST['deleteAccount'])) { |
|
711 | + deleteMembers($memID); |
|
712 | + } |
|
694 | 713 | } |
695 | 714 | // Do they need approval to delete? |
696 | 715 | elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum')) |
@@ -741,18 +760,18 @@ discard block |
||
741 | 760 | { |
742 | 761 | foreach ($costs as $duration => $cost) |
743 | 762 | { |
744 | - if ($cost != 0) |
|
745 | - $cost_array[$duration] = $cost; |
|
763 | + if ($cost != 0) { |
|
764 | + $cost_array[$duration] = $cost; |
|
765 | + } |
|
746 | 766 | } |
747 | - } |
|
748 | - else |
|
767 | + } else |
|
749 | 768 | { |
750 | 769 | $cost_array['fixed'] = $costs['fixed']; |
751 | 770 | } |
752 | 771 | |
753 | - if (empty($cost_array)) |
|
754 | - unset($context['subscriptions'][$id]); |
|
755 | - else |
|
772 | + if (empty($cost_array)) { |
|
773 | + unset($context['subscriptions'][$id]); |
|
774 | + } else |
|
756 | 775 | { |
757 | 776 | $context['subscriptions'][$id]['member'] = 0; |
758 | 777 | $context['subscriptions'][$id]['subscribed'] = false; |
@@ -765,13 +784,15 @@ discard block |
||
765 | 784 | foreach ($gateways as $id => $gateway) |
766 | 785 | { |
767 | 786 | $gateways[$id] = new $gateway['display_class'](); |
768 | - if (!$gateways[$id]->gatewayEnabled()) |
|
769 | - unset($gateways[$id]); |
|
787 | + if (!$gateways[$id]->gatewayEnabled()) { |
|
788 | + unset($gateways[$id]); |
|
789 | + } |
|
770 | 790 | } |
771 | 791 | |
772 | 792 | // No gateways yet? |
773 | - if (empty($gateways)) |
|
774 | - fatal_error($txt['paid_admin_not_setup_gateway']); |
|
793 | + if (empty($gateways)) { |
|
794 | + fatal_error($txt['paid_admin_not_setup_gateway']); |
|
795 | + } |
|
775 | 796 | |
776 | 797 | // Get the current subscriptions. |
777 | 798 | $request = $smcFunc['db_query']('', ' |
@@ -786,8 +807,9 @@ discard block |
||
786 | 807 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
787 | 808 | { |
788 | 809 | // The subscription must exist! |
789 | - if (!isset($context['subscriptions'][$row['id_subscribe']])) |
|
790 | - continue; |
|
810 | + if (!isset($context['subscriptions'][$row['id_subscribe']])) { |
|
811 | + continue; |
|
812 | + } |
|
791 | 813 | |
792 | 814 | $context['current'][$row['id_subscribe']] = array( |
793 | 815 | 'id' => $row['id_sublog'], |
@@ -801,8 +823,9 @@ discard block |
||
801 | 823 | 'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'], |
802 | 824 | ); |
803 | 825 | |
804 | - if ($row['status'] == 1) |
|
805 | - $context['subscriptions'][$row['id_subscribe']]['subscribed'] = true; |
|
826 | + if ($row['status'] == 1) { |
|
827 | + $context['subscriptions'][$row['id_subscribe']]['subscribed'] = true; |
|
828 | + } |
|
806 | 829 | } |
807 | 830 | $smcFunc['db_free_result']($request); |
808 | 831 | |
@@ -853,21 +876,25 @@ discard block |
||
853 | 876 | if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id'])) |
854 | 877 | { |
855 | 878 | // Hopefully just one. |
856 | - foreach ($_POST['sub_id'] as $k => $v) |
|
857 | - $ID_SUB = (int) $k; |
|
879 | + foreach ($_POST['sub_id'] as $k => $v) { |
|
880 | + $ID_SUB = (int) $k; |
|
881 | + } |
|
858 | 882 | |
859 | - if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) |
|
860 | - fatal_lang_error('paid_sub_not_active'); |
|
883 | + if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) { |
|
884 | + fatal_lang_error('paid_sub_not_active'); |
|
885 | + } |
|
861 | 886 | |
862 | 887 | // Simplify... |
863 | 888 | $context['sub'] = $context['subscriptions'][$ID_SUB]; |
864 | 889 | $period = 'xx'; |
865 | - if ($context['sub']['flexible']) |
|
866 | - $period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx'; |
|
890 | + if ($context['sub']['flexible']) { |
|
891 | + $period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx'; |
|
892 | + } |
|
867 | 893 | |
868 | 894 | // Check we have a valid cost. |
869 | - if ($context['sub']['flexible'] && $period == 'xx') |
|
870 | - fatal_lang_error('paid_sub_not_active'); |
|
895 | + if ($context['sub']['flexible'] && $period == 'xx') { |
|
896 | + fatal_lang_error('paid_sub_not_active'); |
|
897 | + } |
|
871 | 898 | |
872 | 899 | // Sort out the cost/currency. |
873 | 900 | $context['currency'] = $modSettings['paid_currency_code']; |
@@ -880,8 +907,7 @@ discard block |
||
880 | 907 | $context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]]; |
881 | 908 | // The period value for paypal. |
882 | 909 | $context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1)); |
883 | - } |
|
884 | - else |
|
910 | + } else |
|
885 | 911 | { |
886 | 912 | // Real cost... |
887 | 913 | $context['value'] = $context['sub']['costs']['fixed']; |
@@ -898,13 +924,15 @@ discard block |
||
898 | 924 | foreach ($gateways as $id => $gateway) |
899 | 925 | { |
900 | 926 | $fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done'); |
901 | - if (!empty($fields['form'])) |
|
902 | - $context['gateways'][] = $fields; |
|
927 | + if (!empty($fields['form'])) { |
|
928 | + $context['gateways'][] = $fields; |
|
929 | + } |
|
903 | 930 | } |
904 | 931 | |
905 | 932 | // Bugger?! |
906 | - if (empty($context['gateways'])) |
|
907 | - fatal_error($txt['paid_admin_not_setup_gateway']); |
|
933 | + if (empty($context['gateways'])) { |
|
934 | + fatal_error($txt['paid_admin_not_setup_gateway']); |
|
935 | + } |
|
908 | 936 | |
909 | 937 | // Now we are going to assume they want to take this out ;) |
910 | 938 | $new_data = array($context['sub']['id'], $context['value'], $period, 'prepay'); |
@@ -912,16 +940,19 @@ discard block |
||
912 | 940 | { |
913 | 941 | // What are the details like? |
914 | 942 | $current_pending = array(); |
915 | - if ($context['current'][$context['sub']['id']]['pending_details'] != '') |
|
916 | - $current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true); |
|
943 | + if ($context['current'][$context['sub']['id']]['pending_details'] != '') { |
|
944 | + $current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true); |
|
945 | + } |
|
917 | 946 | // Don't get silly. |
918 | - if (count($current_pending) > 9) |
|
919 | - $current_pending = array(); |
|
947 | + if (count($current_pending) > 9) { |
|
948 | + $current_pending = array(); |
|
949 | + } |
|
920 | 950 | $pending_count = 0; |
921 | 951 | // Only record real pending payments as will otherwise confuse the admin! |
922 | - foreach ($current_pending as $pending) |
|
923 | - if ($pending[3] == 'payback') |
|
952 | + foreach ($current_pending as $pending) { |
|
953 | + if ($pending[3] == 'payback') |
|
924 | 954 | $pending_count++; |
955 | + } |
|
925 | 956 | |
926 | 957 | if (!in_array($new_data, $current_pending)) |
927 | 958 | { |
@@ -966,9 +997,9 @@ discard block |
||
966 | 997 | |
967 | 998 | // Quit. |
968 | 999 | return; |
1000 | + } else { |
|
1001 | + $context['sub_template'] = 'user_subscription'; |
|
1002 | + } |
|
969 | 1003 | } |
970 | - else |
|
971 | - $context['sub_template'] = 'user_subscription'; |
|
972 | -} |
|
973 | 1004 | |
974 | 1005 | ?> |
975 | 1006 | \ No newline at end of file |
@@ -27,9 +27,10 @@ discard block |
||
27 | 27 | <h3 class="catbg"> |
28 | 28 | <span class="floatleft">', $txt['members_list'], '</span>'; |
29 | 29 | |
30 | - if (!isset($context['old_search'])) |
|
31 | - echo ' |
|
30 | + if (!isset($context['old_search'])) { |
|
31 | + echo ' |
|
32 | 32 | <span class="floatright">', $context['letter_links'], '</span>'; |
33 | + } |
|
33 | 34 | echo ' |
34 | 35 | </h3> |
35 | 36 | </div>'; |
@@ -44,20 +45,23 @@ discard block |
||
44 | 45 | foreach ($context['columns'] as $key => $column) |
45 | 46 | { |
46 | 47 | // @TODO maybe find something nicer? |
47 | - if ($key == 'email_address' && !$context['can_send_email']) |
|
48 | - continue; |
|
48 | + if ($key == 'email_address' && !$context['can_send_email']) { |
|
49 | + continue; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // This is a selected column, so underline it or some such. |
51 | - if ($column['selected']) |
|
52 | - echo ' |
|
53 | + if ($column['selected']) { |
|
54 | + echo ' |
|
53 | 55 | <th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', ' selected" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . '> |
54 | 56 | <a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></th>'; |
57 | + } |
|
55 | 58 | |
56 | 59 | // This is just some column... show the link and be done with it. |
57 | - else |
|
58 | - echo ' |
|
60 | + else { |
|
61 | + echo ' |
|
59 | 62 | <th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' style="width: ' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '> |
60 | 63 | ', $column['link'], '</th>'; |
64 | + } |
|
61 | 65 | } |
62 | 66 | |
63 | 67 | echo ' |
@@ -77,9 +81,10 @@ discard block |
||
77 | 81 | </td> |
78 | 82 | <td class="lefttext">', $member['link'], '</td>'; |
79 | 83 | |
80 | - if (!isset($context['disabled_fields']['website'])) |
|
81 | - echo ' |
|
84 | + if (!isset($context['disabled_fields']['website'])) { |
|
85 | + echo ' |
|
82 | 86 | <td class="centertext website_url">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" rel="noopener"><span class="generic_icons www" title="' . $member['website']['title'] . '"></span></a>' : '', '</td>'; |
87 | + } |
|
83 | 88 | |
84 | 89 | // Group and date. |
85 | 90 | echo ' |
@@ -92,32 +97,35 @@ discard block |
||
92 | 97 | <td class="centertext" style="white-space: nowrap; width: 15px">', $member['posts'], '</td> |
93 | 98 | <td class="centertext statsbar" style="width: 120px">'; |
94 | 99 | |
95 | - if (!empty($member['post_percent'])) |
|
96 | - echo ' |
|
100 | + if (!empty($member['post_percent'])) { |
|
101 | + echo ' |
|
97 | 102 | <div class="bar" style="width: ', $member['post_percent'] + 4, 'px;"> |
98 | 103 | <div style="width: ', $member['post_percent'], 'px;"></div> |
99 | 104 | </div>'; |
105 | + } |
|
100 | 106 | |
101 | 107 | echo ' |
102 | 108 | </td>'; |
103 | 109 | } |
104 | 110 | |
105 | 111 | // Show custom fields marked to be shown here |
106 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
107 | - foreach ($context['custom_profile_fields']['columns'] as $key => $column) |
|
112 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
113 | + foreach ($context['custom_profile_fields']['columns'] as $key => $column) |
|
108 | 114 | echo ' |
109 | 115 | <td class="righttext">', $member['options'][$key], '</td>'; |
116 | + } |
|
110 | 117 | |
111 | 118 | echo ' |
112 | 119 | </tr>'; |
113 | 120 | } |
114 | 121 | } |
115 | 122 | // No members? |
116 | - else |
|
117 | - echo ' |
|
123 | + else { |
|
124 | + echo ' |
|
118 | 125 | <tr> |
119 | 126 | <td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td> |
120 | 127 | </tr>'; |
128 | + } |
|
121 | 129 | |
122 | 130 | echo ' |
123 | 131 | </tbody> |
@@ -130,9 +138,10 @@ discard block |
||
130 | 138 | <div class="pagelinks floatleft">', $context['page_index'], '</div>'; |
131 | 139 | |
132 | 140 | // If it is displaying the result of a search show a "search again" link to edit their criteria. |
133 | - if (isset($context['old_search'])) |
|
134 | - echo ' |
|
141 | + if (isset($context['old_search'])) { |
|
142 | + echo ' |
|
135 | 143 | <a class="button" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a>'; |
144 | + } |
|
136 | 145 | echo ' |
137 | 146 | </div> |
138 | 147 | </div><!-- #memberlist -->'; |
@@ -172,12 +181,13 @@ discard block |
||
172 | 181 | <dd> |
173 | 182 | <ul>'; |
174 | 183 | |
175 | - foreach ($context['search_fields'] as $id => $title) |
|
176 | - echo ' |
|
184 | + foreach ($context['search_fields'] as $id => $title) { |
|
185 | + echo ' |
|
177 | 186 | <li> |
178 | 187 | <input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '"', in_array($id, $context['search_defaults']) ? ' checked' : '', '> |
179 | 188 | <label for="fields-', $id, '">', $title, '</label> |
180 | 189 | </li>'; |
190 | + } |
|
181 | 191 | |
182 | 192 | echo ' |
183 | 193 | </ul> |
@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | * @version 2.1 Beta 4 |
18 | 18 | */ |
19 | 19 | |
20 | -if (!defined('SMF')) |
|
20 | +if (!defined('SMF')) { |
|
21 | 21 | die('No direct access...'); |
22 | +} |
|
22 | 23 | |
23 | 24 | /** |
24 | 25 | * Attempt to start the session, unless it already has been. |
@@ -38,8 +39,9 @@ discard block |
||
38 | 39 | { |
39 | 40 | $parsed_url = parse_url($boardurl); |
40 | 41 | |
41 | - if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
42 | - @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
42 | + if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
43 | + @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
44 | + } |
|
43 | 45 | } |
44 | 46 | // @todo Set the session cookie path? |
45 | 47 | |
@@ -47,8 +49,9 @@ discard block |
||
47 | 49 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
48 | 50 | { |
49 | 51 | // Attempt to end the already-started session. |
50 | - if (ini_get('session.auto_start') == 1) |
|
51 | - session_write_close(); |
|
52 | + if (ini_get('session.auto_start') == 1) { |
|
53 | + session_write_close(); |
|
54 | + } |
|
52 | 55 | |
53 | 56 | // This is here to stop people from using bad junky PHPSESSIDs. |
54 | 57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
@@ -63,23 +66,26 @@ discard block |
||
63 | 66 | if (!empty($modSettings['databaseSession_enable'])) |
64 | 67 | { |
65 | 68 | @ini_set('session.serialize_handler', 'php_serialize'); |
66 | - if (ini_get('session.serialize_handler') != 'php_serialize') |
|
67 | - @ini_set('session.serialize_handler', 'php'); |
|
69 | + if (ini_get('session.serialize_handler') != 'php_serialize') { |
|
70 | + @ini_set('session.serialize_handler', 'php'); |
|
71 | + } |
|
68 | 72 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
69 | 73 | @ini_set('session.gc_probability', '1'); |
74 | + } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) { |
|
75 | + @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
70 | 76 | } |
71 | - elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
|
72 | - @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
73 | 77 | |
74 | 78 | // Use cache setting sessions? |
75 | - if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') |
|
76 | - call_integration_hook('integrate_session_handlers'); |
|
79 | + if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') { |
|
80 | + call_integration_hook('integrate_session_handlers'); |
|
81 | + } |
|
77 | 82 | |
78 | 83 | session_start(); |
79 | 84 | |
80 | 85 | // Change it so the cache settings are a little looser than default. |
81 | - if (!empty($modSettings['databaseSession_loose'])) |
|
82 | - header('Cache-Control: private'); |
|
86 | + if (!empty($modSettings['databaseSession_loose'])) { |
|
87 | + header('Cache-Control: private'); |
|
88 | + } |
|
83 | 89 | } |
84 | 90 | |
85 | 91 | // Set the randomly generated code. |
@@ -125,8 +131,9 @@ discard block |
||
125 | 131 | { |
126 | 132 | global $smcFunc; |
127 | 133 | |
128 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
129 | - return ''; |
|
134 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
135 | + return ''; |
|
136 | + } |
|
130 | 137 | |
131 | 138 | // Look for it in the database. |
132 | 139 | $result = $smcFunc['db_query']('', ' |
@@ -155,8 +162,9 @@ discard block |
||
155 | 162 | { |
156 | 163 | global $smcFunc; |
157 | 164 | |
158 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
159 | - return false; |
|
165 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
166 | + return false; |
|
167 | + } |
|
160 | 168 | |
161 | 169 | // First try to update an existing row... |
162 | 170 | $smcFunc['db_query']('', ' |
@@ -171,13 +179,14 @@ discard block |
||
171 | 179 | ); |
172 | 180 | |
173 | 181 | // If that didn't work, try inserting a new one. |
174 | - if ($smcFunc['db_affected_rows']() == 0) |
|
175 | - $smcFunc['db_insert']('ignore', |
|
182 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
183 | + $smcFunc['db_insert']('ignore', |
|
176 | 184 | '{db_prefix}sessions', |
177 | 185 | array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), |
178 | 186 | array($session_id, $data, time()), |
179 | 187 | array('session_id') |
180 | 188 | ); |
189 | + } |
|
181 | 190 | |
182 | 191 | return ($smcFunc['db_affected_rows']() == 0 ? false : true); |
183 | 192 | } |
@@ -192,8 +201,9 @@ discard block |
||
192 | 201 | { |
193 | 202 | global $smcFunc; |
194 | 203 | |
195 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
196 | - return false; |
|
204 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
205 | + return false; |
|
206 | + } |
|
197 | 207 | |
198 | 208 | // Just delete the row... |
199 | 209 | $smcFunc['db_query']('', ' |
@@ -219,8 +229,9 @@ discard block |
||
219 | 229 | global $modSettings, $smcFunc; |
220 | 230 | |
221 | 231 | // Just set to the default or lower? Ignore it for a higher value. (hopefully) |
222 | - if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) |
|
223 | - $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
232 | + if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) { |
|
233 | + $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
234 | + } |
|
224 | 235 | |
225 | 236 | // Clean up after yerself ;). |
226 | 237 | $smcFunc['db_query']('', ' |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | |
256 | 256 | case 'datetime': |
257 | 257 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
258 | - return 'str_to_date('. |
|
259 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
258 | + return 'str_to_date(' . |
|
259 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
260 | 260 | ',\'%Y-%m-%d %h:%i:%s\')'; |
261 | 261 | else |
262 | 262 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | $old_pos = 0; |
461 | 461 | $pos = -1; |
462 | 462 | // Remove the string escape for better runtime |
463 | - $db_string_1 = str_replace('\\\'','',$db_string); |
|
463 | + $db_string_1 = str_replace('\\\'', '', $db_string); |
|
464 | 464 | while (true) |
465 | 465 | { |
466 | 466 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | { |
843 | 843 | $count = count($insertRows); |
844 | 844 | $ai = 0; |
845 | - for($i = 0; $i < $count; $i++) |
|
845 | + for ($i = 0; $i < $count; $i++) |
|
846 | 846 | { |
847 | 847 | $old_id = $smcFunc['db_insert_id'](); |
848 | 848 | |
@@ -868,13 +868,13 @@ discard block |
||
868 | 868 | $count2 = count($indexed_columns); |
869 | 869 | for ($x = 0; $x < $count2; $x++) |
870 | 870 | { |
871 | - $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
|
871 | + $where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x]; |
|
872 | 872 | if (($x + 1) < $count2) |
873 | 873 | $where_string += ' AND '; |
874 | 874 | } |
875 | 875 | |
876 | - $request = $smcFunc['db_query']('',' |
|
877 | - SELECT `'. $keys[0] . '` FROM ' . $table .' |
|
876 | + $request = $smcFunc['db_query']('', ' |
|
877 | + SELECT `'. $keys[0] . '` FROM ' . $table . ' |
|
878 | 878 | WHERE ' . $where_string . ' LIMIT 1', |
879 | 879 | array() |
880 | 880 | ); |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | $return_var = array(); |
904 | 904 | $count = count($insertRows); |
905 | 905 | $start = smf_db_insert_id($table, $keys[0]); |
906 | - for ($i = 0; $i < $count; $i++ ) |
|
906 | + for ($i = 0; $i < $count; $i++) |
|
907 | 907 | $return_var[] = $start + $i; |
908 | 908 | } |
909 | 909 | return $return_var; |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
1037 | 1037 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1038 | 1038 | $error_array[7], $error_array[8]); |
1039 | - mysqli_stmt_execute ($mysql_error_data_prep); |
|
1039 | + mysqli_stmt_execute($mysql_error_data_prep); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | /** |
@@ -1050,7 +1050,7 @@ discard block |
||
1050 | 1050 | */ |
1051 | 1051 | function smf_db_custom_order($field, $array_values, $desc = false) |
1052 | 1052 | { |
1053 | - $return = 'CASE '. $field . ' '; |
|
1053 | + $return = 'CASE ' . $field . ' '; |
|
1054 | 1054 | $count = count($array_values); |
1055 | 1055 | $then = ($desc ? ' THEN -' : ' THEN '); |
1056 | 1056 |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
33 | 34 | global $smcFunc; |
34 | 35 | |
35 | 36 | // Map some database specific functions, only do this once. |
36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
37 | - $smcFunc += array( |
|
37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
38 | + $smcFunc += array( |
|
38 | 39 | 'db_query' => 'smf_db_query', |
39 | 40 | 'db_quote' => 'smf_db_quote', |
40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -63,9 +64,11 @@ discard block |
||
63 | 64 | 'db_error_insert' => 'smf_db_error_insert', |
64 | 65 | 'db_custom_order' => 'smf_db_custom_order', |
65 | 66 | ); |
67 | + } |
|
66 | 68 | |
67 | - if (!empty($db_options['persist'])) |
|
68 | - $db_server = 'p:' . $db_server; |
|
69 | + if (!empty($db_options['persist'])) { |
|
70 | + $db_server = 'p:' . $db_server; |
|
71 | + } |
|
69 | 72 | |
70 | 73 | $connection = mysqli_init(); |
71 | 74 | |
@@ -74,24 +77,27 @@ discard block |
||
74 | 77 | $success = false; |
75 | 78 | |
76 | 79 | if ($connection) { |
77 | - if (!empty($db_options['port'])) |
|
78 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
79 | - else |
|
80 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
80 | + if (!empty($db_options['port'])) { |
|
81 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
82 | + } else { |
|
83 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
84 | + } |
|
81 | 85 | } |
82 | 86 | |
83 | 87 | // Something's wrong, show an error if its fatal (which we assume it is) |
84 | 88 | if ($success === false) |
85 | 89 | { |
86 | - if (!empty($db_options['non_fatal'])) |
|
87 | - return null; |
|
88 | - else |
|
89 | - display_db_error(); |
|
90 | + if (!empty($db_options['non_fatal'])) { |
|
91 | + return null; |
|
92 | + } else { |
|
93 | + display_db_error(); |
|
94 | + } |
|
90 | 95 | } |
91 | 96 | |
92 | 97 | // Select the database, unless told not to |
93 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
94 | - display_db_error(); |
|
98 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
99 | + display_db_error(); |
|
100 | + } |
|
95 | 101 | |
96 | 102 | $smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'', |
97 | 103 | array(), |
@@ -167,34 +173,42 @@ discard block |
||
167 | 173 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
168 | 174 | |
169 | 175 | list ($values, $connection) = $db_callback; |
170 | - if (!is_object($connection)) |
|
171 | - display_db_error(); |
|
176 | + if (!is_object($connection)) { |
|
177 | + display_db_error(); |
|
178 | + } |
|
172 | 179 | |
173 | - if ($matches[1] === 'db_prefix') |
|
174 | - return $db_prefix; |
|
180 | + if ($matches[1] === 'db_prefix') { |
|
181 | + return $db_prefix; |
|
182 | + } |
|
175 | 183 | |
176 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
177 | - return $user_info[$matches[1]]; |
|
184 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
185 | + return $user_info[$matches[1]]; |
|
186 | + } |
|
178 | 187 | |
179 | - if ($matches[1] === 'empty') |
|
180 | - return '\'\''; |
|
188 | + if ($matches[1] === 'empty') { |
|
189 | + return '\'\''; |
|
190 | + } |
|
181 | 191 | |
182 | - if (!isset($matches[2])) |
|
183 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
192 | + if (!isset($matches[2])) { |
|
193 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
194 | + } |
|
184 | 195 | |
185 | - if ($matches[1] === 'literal') |
|
186 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
196 | + if ($matches[1] === 'literal') { |
|
197 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
198 | + } |
|
187 | 199 | |
188 | - if (!isset($values[$matches[2]])) |
|
189 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
200 | + if (!isset($values[$matches[2]])) { |
|
201 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
202 | + } |
|
190 | 203 | |
191 | 204 | $replacement = $values[$matches[2]]; |
192 | 205 | |
193 | 206 | switch ($matches[1]) |
194 | 207 | { |
195 | 208 | case 'int': |
196 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
197 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
209 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
210 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
211 | + } |
|
198 | 212 | return (string) (int) $replacement; |
199 | 213 | break; |
200 | 214 | |
@@ -206,65 +220,73 @@ discard block |
||
206 | 220 | case 'array_int': |
207 | 221 | if (is_array($replacement)) |
208 | 222 | { |
209 | - if (empty($replacement)) |
|
210 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
223 | + if (empty($replacement)) { |
|
224 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
225 | + } |
|
211 | 226 | |
212 | 227 | foreach ($replacement as $key => $value) |
213 | 228 | { |
214 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
215 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
229 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
230 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
231 | + } |
|
216 | 232 | |
217 | 233 | $replacement[$key] = (string) (int) $value; |
218 | 234 | } |
219 | 235 | |
220 | 236 | return implode(', ', $replacement); |
237 | + } else { |
|
238 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
221 | 239 | } |
222 | - else |
|
223 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
224 | 240 | |
225 | 241 | break; |
226 | 242 | |
227 | 243 | case 'array_string': |
228 | 244 | if (is_array($replacement)) |
229 | 245 | { |
230 | - if (empty($replacement)) |
|
231 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
246 | + if (empty($replacement)) { |
|
247 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
248 | + } |
|
232 | 249 | |
233 | - foreach ($replacement as $key => $value) |
|
234 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
250 | + foreach ($replacement as $key => $value) { |
|
251 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
252 | + } |
|
235 | 253 | |
236 | 254 | return implode(', ', $replacement); |
255 | + } else { |
|
256 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | 257 | } |
238 | - else |
|
239 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | 258 | break; |
241 | 259 | |
242 | 260 | case 'date': |
243 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
244 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
245 | - else |
|
246 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
261 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
262 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
263 | + } else { |
|
264 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
265 | + } |
|
247 | 266 | break; |
248 | 267 | |
249 | 268 | case 'time': |
250 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
251 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
252 | - else |
|
253 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
269 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
270 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
271 | + } else { |
|
272 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
273 | + } |
|
254 | 274 | break; |
255 | 275 | |
256 | 276 | case 'datetime': |
257 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
258 | - return 'str_to_date('. |
|
277 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
278 | + return 'str_to_date('. |
|
259 | 279 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
260 | 280 | ',\'%Y-%m-%d %h:%i:%s\')'; |
261 | - else |
|
262 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
281 | + } else { |
|
282 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
283 | + } |
|
263 | 284 | break; |
264 | 285 | |
265 | 286 | case 'float': |
266 | - if (!is_numeric($replacement)) |
|
267 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
287 | + if (!is_numeric($replacement)) { |
|
288 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
289 | + } |
|
268 | 290 | return (string) (float) $replacement; |
269 | 291 | break; |
270 | 292 | |
@@ -278,32 +300,37 @@ discard block |
||
278 | 300 | break; |
279 | 301 | |
280 | 302 | case 'inet': |
281 | - if ($replacement == 'null' || $replacement == '') |
|
282 | - return 'null'; |
|
283 | - if (!isValidIP($replacement)) |
|
284 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
303 | + if ($replacement == 'null' || $replacement == '') { |
|
304 | + return 'null'; |
|
305 | + } |
|
306 | + if (!isValidIP($replacement)) { |
|
307 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
308 | + } |
|
285 | 309 | //we don't use the native support of mysql > 5.6.2 |
286 | 310 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
287 | 311 | |
288 | 312 | case 'array_inet': |
289 | 313 | if (is_array($replacement)) |
290 | 314 | { |
291 | - if (empty($replacement)) |
|
292 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
315 | + if (empty($replacement)) { |
|
316 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
317 | + } |
|
293 | 318 | |
294 | 319 | foreach ($replacement as $key => $value) |
295 | 320 | { |
296 | - if ($replacement == 'null' || $replacement == '') |
|
297 | - $replacement[$key] = 'null'; |
|
298 | - if (!isValidIP($value)) |
|
299 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
321 | + if ($replacement == 'null' || $replacement == '') { |
|
322 | + $replacement[$key] = 'null'; |
|
323 | + } |
|
324 | + if (!isValidIP($value)) { |
|
325 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
326 | + } |
|
300 | 327 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
301 | 328 | } |
302 | 329 | |
303 | 330 | return implode(', ', $replacement); |
331 | + } else { |
|
332 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
304 | 333 | } |
305 | - else |
|
306 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
307 | 334 | break; |
308 | 335 | |
309 | 336 | default: |
@@ -379,22 +406,25 @@ discard block |
||
379 | 406 | // Are we in SSI mode? If so try that username and password first |
380 | 407 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
381 | 408 | { |
382 | - if (empty($db_persist)) |
|
383 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
384 | - else |
|
385 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
409 | + if (empty($db_persist)) { |
|
410 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
411 | + } else { |
|
412 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
413 | + } |
|
386 | 414 | } |
387 | 415 | // Fall back to the regular username and password if need be |
388 | 416 | if (!$db_connection) |
389 | 417 | { |
390 | - if (empty($db_persist)) |
|
391 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
392 | - else |
|
393 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
418 | + if (empty($db_persist)) { |
|
419 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
420 | + } else { |
|
421 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
422 | + } |
|
394 | 423 | } |
395 | 424 | |
396 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
397 | - $db_connection = false; |
|
425 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
426 | + $db_connection = false; |
|
427 | + } |
|
398 | 428 | |
399 | 429 | $connection = $db_connection; |
400 | 430 | } |
@@ -402,18 +432,20 @@ discard block |
||
402 | 432 | // One more query.... |
403 | 433 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
404 | 434 | |
405 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
406 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
435 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
436 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
437 | + } |
|
407 | 438 | |
408 | 439 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
409 | 440 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
410 | 441 | { |
411 | 442 | // Add before LIMIT |
412 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
413 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
414 | - else |
|
415 | - // Append it. |
|
443 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
444 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
445 | + } else { |
|
446 | + // Append it. |
|
416 | 447 | $db_string .= "\n\t\t\tORDER BY null"; |
448 | + } |
|
417 | 449 | } |
418 | 450 | |
419 | 451 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -435,8 +467,9 @@ discard block |
||
435 | 467 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
436 | 468 | |
437 | 469 | // Initialize $db_cache if not already initialized. |
438 | - if (!isset($db_cache)) |
|
439 | - $db_cache = array(); |
|
470 | + if (!isset($db_cache)) { |
|
471 | + $db_cache = array(); |
|
472 | + } |
|
440 | 473 | |
441 | 474 | if (!empty($_SESSION['debug_redirect'])) |
442 | 475 | { |
@@ -464,17 +497,18 @@ discard block |
||
464 | 497 | while (true) |
465 | 498 | { |
466 | 499 | $pos = strpos($db_string_1, '\'', $pos + 1); |
467 | - if ($pos === false) |
|
468 | - break; |
|
500 | + if ($pos === false) { |
|
501 | + break; |
|
502 | + } |
|
469 | 503 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
470 | 504 | |
471 | 505 | while (true) |
472 | 506 | { |
473 | 507 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
474 | 508 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
475 | - if ($pos1 === false) |
|
476 | - break; |
|
477 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
509 | + if ($pos1 === false) { |
|
510 | + break; |
|
511 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
478 | 512 | { |
479 | 513 | $pos = $pos1; |
480 | 514 | break; |
@@ -490,29 +524,35 @@ discard block |
||
490 | 524 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
491 | 525 | |
492 | 526 | // Comments? We don't use comments in our queries, we leave 'em outside! |
493 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
494 | - $fail = true; |
|
527 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
528 | + $fail = true; |
|
529 | + } |
|
495 | 530 | // Trying to change passwords, slow us down, or something? |
496 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
497 | - $fail = true; |
|
498 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
499 | - $fail = true; |
|
531 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
532 | + $fail = true; |
|
533 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
534 | + $fail = true; |
|
535 | + } |
|
500 | 536 | |
501 | - if (!empty($fail) && function_exists('log_error')) |
|
502 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
537 | + if (!empty($fail) && function_exists('log_error')) { |
|
538 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
539 | + } |
|
503 | 540 | } |
504 | 541 | |
505 | - if (empty($db_unbuffered)) |
|
506 | - $ret = @mysqli_query($connection, $db_string); |
|
507 | - else |
|
508 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
542 | + if (empty($db_unbuffered)) { |
|
543 | + $ret = @mysqli_query($connection, $db_string); |
|
544 | + } else { |
|
545 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
546 | + } |
|
509 | 547 | |
510 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
511 | - $ret = smf_db_error($db_string, $connection); |
|
548 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
549 | + $ret = smf_db_error($db_string, $connection); |
|
550 | + } |
|
512 | 551 | |
513 | 552 | // Debugging. |
514 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
515 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
553 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
554 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
555 | + } |
|
516 | 556 | |
517 | 557 | return $ret; |
518 | 558 | } |
@@ -559,12 +599,13 @@ discard block |
||
559 | 599 | // Decide which connection to use |
560 | 600 | $connection = $connection === null ? $db_connection : $connection; |
561 | 601 | |
562 | - if ($type == 'begin') |
|
563 | - return @mysqli_query($connection, 'BEGIN'); |
|
564 | - elseif ($type == 'rollback') |
|
565 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
566 | - elseif ($type == 'commit') |
|
567 | - return @mysqli_query($connection, 'COMMIT'); |
|
602 | + if ($type == 'begin') { |
|
603 | + return @mysqli_query($connection, 'BEGIN'); |
|
604 | + } elseif ($type == 'rollback') { |
|
605 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
606 | + } elseif ($type == 'commit') { |
|
607 | + return @mysqli_query($connection, 'COMMIT'); |
|
608 | + } |
|
568 | 609 | |
569 | 610 | return false; |
570 | 611 | } |
@@ -604,8 +645,9 @@ discard block |
||
604 | 645 | // 2013: Lost connection to server during query. |
605 | 646 | |
606 | 647 | // Log the error. |
607 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
608 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
648 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
649 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
650 | + } |
|
609 | 651 | |
610 | 652 | // Database error auto fixing ;). |
611 | 653 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -614,8 +656,9 @@ discard block |
||
614 | 656 | $old_cache = @$modSettings['cache_enable']; |
615 | 657 | $modSettings['cache_enable'] = '1'; |
616 | 658 | |
617 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
618 | - $db_last_error = max(@$db_last_error, $temp); |
|
659 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
660 | + $db_last_error = max(@$db_last_error, $temp); |
|
661 | + } |
|
619 | 662 | |
620 | 663 | if (@$db_last_error < time() - 3600 * 24 * 3) |
621 | 664 | { |
@@ -631,8 +674,9 @@ discard block |
||
631 | 674 | foreach ($tables as $table) |
632 | 675 | { |
633 | 676 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
634 | - if (trim($table) != '') |
|
635 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
677 | + if (trim($table) != '') { |
|
678 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
679 | + } |
|
636 | 680 | } |
637 | 681 | } |
638 | 682 | |
@@ -641,8 +685,9 @@ discard block |
||
641 | 685 | // Table crashed. Let's try to fix it. |
642 | 686 | elseif ($query_errno == 1016) |
643 | 687 | { |
644 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
645 | - $fix_tables = array('`' . $match[1] . '`'); |
|
688 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
689 | + $fix_tables = array('`' . $match[1] . '`'); |
|
690 | + } |
|
646 | 691 | } |
647 | 692 | // Indexes crashed. Should be easy to fix! |
648 | 693 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -661,13 +706,15 @@ discard block |
||
661 | 706 | |
662 | 707 | // Make a note of the REPAIR... |
663 | 708 | cache_put_data('db_last_error', time(), 600); |
664 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
665 | - updateSettingsFile(array('db_last_error' => time())); |
|
709 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
710 | + updateSettingsFile(array('db_last_error' => time())); |
|
711 | + } |
|
666 | 712 | |
667 | 713 | // Attempt to find and repair the broken table. |
668 | - foreach ($fix_tables as $table) |
|
669 | - $smcFunc['db_query']('', " |
|
714 | + foreach ($fix_tables as $table) { |
|
715 | + $smcFunc['db_query']('', " |
|
670 | 716 | REPAIR TABLE $table", false, false); |
717 | + } |
|
671 | 718 | |
672 | 719 | // And send off an email! |
673 | 720 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -676,11 +723,12 @@ discard block |
||
676 | 723 | |
677 | 724 | // Try the query again...? |
678 | 725 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
679 | - if ($ret !== false) |
|
680 | - return $ret; |
|
726 | + if ($ret !== false) { |
|
727 | + return $ret; |
|
728 | + } |
|
729 | + } else { |
|
730 | + $modSettings['cache_enable'] = $old_cache; |
|
681 | 731 | } |
682 | - else |
|
683 | - $modSettings['cache_enable'] = $old_cache; |
|
684 | 732 | |
685 | 733 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
686 | 734 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -690,22 +738,25 @@ discard block |
||
690 | 738 | // Are we in SSI mode? If so try that username and password first |
691 | 739 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
692 | 740 | { |
693 | - if (empty($db_persist)) |
|
694 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
695 | - else |
|
696 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
741 | + if (empty($db_persist)) { |
|
742 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
743 | + } else { |
|
744 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
745 | + } |
|
697 | 746 | } |
698 | 747 | // Fall back to the regular username and password if need be |
699 | 748 | if (!$db_connection) |
700 | 749 | { |
701 | - if (empty($db_persist)) |
|
702 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
703 | - else |
|
704 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
750 | + if (empty($db_persist)) { |
|
751 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
752 | + } else { |
|
753 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
754 | + } |
|
705 | 755 | } |
706 | 756 | |
707 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
708 | - $db_connection = false; |
|
757 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
758 | + $db_connection = false; |
|
759 | + } |
|
709 | 760 | } |
710 | 761 | |
711 | 762 | if ($db_connection) |
@@ -716,24 +767,27 @@ discard block |
||
716 | 767 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
717 | 768 | |
718 | 769 | $new_errno = mysqli_errno($db_connection); |
719 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
720 | - break; |
|
770 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
771 | + break; |
|
772 | + } |
|
721 | 773 | } |
722 | 774 | |
723 | 775 | // If it failed again, shucks to be you... we're not trying it over and over. |
724 | - if ($ret !== false) |
|
725 | - return $ret; |
|
776 | + if ($ret !== false) { |
|
777 | + return $ret; |
|
778 | + } |
|
726 | 779 | } |
727 | 780 | } |
728 | 781 | // Are they out of space, perhaps? |
729 | 782 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
730 | 783 | { |
731 | - if (!isset($txt)) |
|
732 | - $query_error .= ' - check database storage space.'; |
|
733 | - else |
|
784 | + if (!isset($txt)) { |
|
785 | + $query_error .= ' - check database storage space.'; |
|
786 | + } else |
|
734 | 787 | { |
735 | - if (!isset($txt['mysql_error_space'])) |
|
736 | - loadLanguage('Errors'); |
|
788 | + if (!isset($txt['mysql_error_space'])) { |
|
789 | + loadLanguage('Errors'); |
|
790 | + } |
|
737 | 791 | |
738 | 792 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
739 | 793 | } |
@@ -741,15 +795,17 @@ discard block |
||
741 | 795 | } |
742 | 796 | |
743 | 797 | // Nothing's defined yet... just die with it. |
744 | - if (empty($context) || empty($txt)) |
|
745 | - die($query_error); |
|
798 | + if (empty($context) || empty($txt)) { |
|
799 | + die($query_error); |
|
800 | + } |
|
746 | 801 | |
747 | 802 | // Show an error message, if possible. |
748 | 803 | $context['error_title'] = $txt['database_error']; |
749 | - if (allowedTo('admin_forum')) |
|
750 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
751 | - else |
|
752 | - $context['error_message'] = $txt['try_again']; |
|
804 | + if (allowedTo('admin_forum')) { |
|
805 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
806 | + } else { |
|
807 | + $context['error_message'] = $txt['try_again']; |
|
808 | + } |
|
753 | 809 | |
754 | 810 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
755 | 811 | { |
@@ -781,8 +837,9 @@ discard block |
||
781 | 837 | $return_var = null; |
782 | 838 | |
783 | 839 | // With nothing to insert, simply return. |
784 | - if (empty($data)) |
|
785 | - return; |
|
840 | + if (empty($data)) { |
|
841 | + return; |
|
842 | + } |
|
786 | 843 | |
787 | 844 | // Replace the prefix holder with the actual prefix. |
788 | 845 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -792,23 +849,26 @@ discard block |
||
792 | 849 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
793 | 850 | { |
794 | 851 | $with_returning = true; |
795 | - if ($returnmode == 2) |
|
796 | - $return_var = array(); |
|
852 | + if ($returnmode == 2) { |
|
853 | + $return_var = array(); |
|
854 | + } |
|
797 | 855 | } |
798 | 856 | |
799 | 857 | // Inserting data as a single row can be done as a single array. |
800 | - if (!is_array($data[array_rand($data)])) |
|
801 | - $data = array($data); |
|
858 | + if (!is_array($data[array_rand($data)])) { |
|
859 | + $data = array($data); |
|
860 | + } |
|
802 | 861 | |
803 | 862 | // Create the mold for a single row insert. |
804 | 863 | $insertData = '('; |
805 | 864 | foreach ($columns as $columnName => $type) |
806 | 865 | { |
807 | 866 | // Are we restricting the length? |
808 | - if (strpos($type, 'string-') !== false) |
|
809 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
810 | - else |
|
811 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
867 | + if (strpos($type, 'string-') !== false) { |
|
868 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
869 | + } else { |
|
870 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
871 | + } |
|
812 | 872 | } |
813 | 873 | $insertData = substr($insertData, 0, -2) . ')'; |
814 | 874 | |
@@ -817,8 +877,9 @@ discard block |
||
817 | 877 | |
818 | 878 | // Here's where the variables are injected to the query. |
819 | 879 | $insertRows = array(); |
820 | - foreach ($data as $dataRow) |
|
821 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
880 | + foreach ($data as $dataRow) { |
|
881 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
882 | + } |
|
822 | 883 | |
823 | 884 | // Determine the method of insertion. |
824 | 885 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -837,8 +898,7 @@ discard block |
||
837 | 898 | ), |
838 | 899 | $connection |
839 | 900 | ); |
840 | - } |
|
841 | - else //special way for ignore method with returning |
|
901 | + } else //special way for ignore method with returning |
|
842 | 902 | { |
843 | 903 | $count = count($insertRows); |
844 | 904 | $ai = 0; |
@@ -858,19 +918,21 @@ discard block |
||
858 | 918 | ); |
859 | 919 | $new_id = $smcFunc['db_insert_id'](); |
860 | 920 | |
861 | - if ($last_id != $new_id) //the inserted value was new |
|
921 | + if ($last_id != $new_id) { |
|
922 | + //the inserted value was new |
|
862 | 923 | { |
863 | 924 | $ai = $new_id; |
864 | 925 | } |
865 | - else // the inserted value already exists we need to find the pk |
|
926 | + } else // the inserted value already exists we need to find the pk |
|
866 | 927 | { |
867 | 928 | $where_string = ''; |
868 | 929 | $count2 = count($indexed_columns); |
869 | 930 | for ($x = 0; $x < $count2; $x++) |
870 | 931 | { |
871 | 932 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
872 | - if (($x + 1) < $count2) |
|
873 | - $where_string += ' AND '; |
|
933 | + if (($x + 1) < $count2) { |
|
934 | + $where_string += ' AND '; |
|
935 | + } |
|
874 | 936 | } |
875 | 937 | |
876 | 938 | $request = $smcFunc['db_query']('',' |
@@ -886,25 +948,27 @@ discard block |
||
886 | 948 | } |
887 | 949 | } |
888 | 950 | |
889 | - if ($returnmode == 1) |
|
890 | - $return_var = $ai; |
|
891 | - else if ($returnmode == 2) |
|
892 | - $return_var[] = $ai; |
|
951 | + if ($returnmode == 1) { |
|
952 | + $return_var = $ai; |
|
953 | + } else if ($returnmode == 2) { |
|
954 | + $return_var[] = $ai; |
|
955 | + } |
|
893 | 956 | } |
894 | 957 | } |
895 | 958 | |
896 | 959 | |
897 | 960 | if ($with_returning) |
898 | 961 | { |
899 | - if ($returnmode == 1 && empty($return_var)) |
|
900 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
901 | - else if ($returnmode == 2 && empty($return_var)) |
|
962 | + if ($returnmode == 1 && empty($return_var)) { |
|
963 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
964 | + } else if ($returnmode == 2 && empty($return_var)) |
|
902 | 965 | { |
903 | 966 | $return_var = array(); |
904 | 967 | $count = count($insertRows); |
905 | 968 | $start = smf_db_insert_id($table, $keys[0]); |
906 | - for ($i = 0; $i < $count; $i++ ) |
|
907 | - $return_var[] = $start + $i; |
|
969 | + for ($i = 0; $i < $count; $i++ ) { |
|
970 | + $return_var[] = $start + $i; |
|
971 | + } |
|
908 | 972 | } |
909 | 973 | return $return_var; |
910 | 974 | } |
@@ -922,8 +986,9 @@ discard block |
||
922 | 986 | */ |
923 | 987 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
924 | 988 | { |
925 | - if (empty($log_message)) |
|
926 | - $log_message = $error_message; |
|
989 | + if (empty($log_message)) { |
|
990 | + $log_message = $error_message; |
|
991 | + } |
|
927 | 992 | |
928 | 993 | foreach (debug_backtrace() as $step) |
929 | 994 | { |
@@ -942,12 +1007,14 @@ discard block |
||
942 | 1007 | } |
943 | 1008 | |
944 | 1009 | // A special case - we want the file and line numbers for debugging. |
945 | - if ($error_type == 'return') |
|
946 | - return array($file, $line); |
|
1010 | + if ($error_type == 'return') { |
|
1011 | + return array($file, $line); |
|
1012 | + } |
|
947 | 1013 | |
948 | 1014 | // Is always a critical error. |
949 | - if (function_exists('log_error')) |
|
950 | - log_error($log_message, 'critical', $file, $line); |
|
1015 | + if (function_exists('log_error')) { |
|
1016 | + log_error($log_message, 'critical', $file, $line); |
|
1017 | + } |
|
951 | 1018 | |
952 | 1019 | if (function_exists('fatal_error')) |
953 | 1020 | { |
@@ -955,12 +1022,12 @@ discard block |
||
955 | 1022 | |
956 | 1023 | // Cannot continue... |
957 | 1024 | exit; |
1025 | + } elseif ($error_type) { |
|
1026 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
1027 | + } else { |
|
1028 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
1029 | + } |
|
958 | 1030 | } |
959 | - elseif ($error_type) |
|
960 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
961 | - else |
|
962 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
963 | -} |
|
964 | 1031 | |
965 | 1032 | /** |
966 | 1033 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -977,10 +1044,11 @@ discard block |
||
977 | 1044 | '\\' => '\\\\', |
978 | 1045 | ); |
979 | 1046 | |
980 | - if ($translate_human_wildcards) |
|
981 | - $replacements += array( |
|
1047 | + if ($translate_human_wildcards) { |
|
1048 | + $replacements += array( |
|
982 | 1049 | '*' => '%', |
983 | 1050 | ); |
1051 | + } |
|
984 | 1052 | |
985 | 1053 | return strtr($string, $replacements); |
986 | 1054 | } |
@@ -994,8 +1062,9 @@ discard block |
||
994 | 1062 | */ |
995 | 1063 | function smf_is_resource($result) |
996 | 1064 | { |
997 | - if ($result instanceof mysqli_result) |
|
998 | - return true; |
|
1065 | + if ($result instanceof mysqli_result) { |
|
1066 | + return true; |
|
1067 | + } |
|
999 | 1068 | |
1000 | 1069 | return false; |
1001 | 1070 | } |
@@ -1023,16 +1092,18 @@ discard block |
||
1023 | 1092 | global $db_prefix, $db_connection; |
1024 | 1093 | static $mysql_error_data_prep; |
1025 | 1094 | |
1026 | - if (empty($mysql_error_data_prep)) |
|
1027 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1095 | + if (empty($mysql_error_data_prep)) { |
|
1096 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1028 | 1097 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
1029 | 1098 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?)' |
1030 | 1099 | ); |
1100 | + } |
|
1031 | 1101 | |
1032 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
1033 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1034 | - else |
|
1035 | - $error_array[2] = null; |
|
1102 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1103 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1104 | + } else { |
|
1105 | + $error_array[2] = null; |
|
1106 | + } |
|
1036 | 1107 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
1037 | 1108 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1038 | 1109 | $error_array[7], $error_array[8]); |
@@ -1054,8 +1125,9 @@ discard block |
||
1054 | 1125 | $count = count($array_values); |
1055 | 1126 | $then = ($desc ? ' THEN -' : ' THEN '); |
1056 | 1127 | |
1057 | - for ($i = 0; $i < $count; $i++) |
|
1058 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1128 | + for ($i = 0; $i < $count; $i++) { |
|
1129 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1130 | + } |
|
1059 | 1131 | |
1060 | 1132 | $return .= 'END'; |
1061 | 1133 | return $return; |